1 /*
2  * Layer Two Tunnelling Protocol Daemon
3  * Copyright (C) 1998 Adtran, Inc.
4  * Copyright (C) 2002 Jeff McAdams
5  *
6  * Mark Spencer
7  *
8  * This software is distributed under the terms
9  * of the GPL, which you should have received
10  * along with this source.
11  *
12  * Attribute Value Pair structures and
13  * definitions
14  */
15 
16 #include "common.h"
17 
18 struct avp_hdr
19 {
20     _u16 length;
21     _u16 vendorid;
22     _u16 attr;
23 };
24 
25 struct avp
26 {
27     int num;                    /* Number of AVP */
28     int m;                      /* Set M? */
29     int (*handler) (struct tunnel *, struct call *, void *, int);
30     /* This should handle the AVP
31        taking a tunnel, call, the data,
32        and the length of the AVP as
33        parameters.  Should return 0
34        upon success */
35     char *description;          /* A name, for debugging */
36 };
37 
38 extern int handle_avps (struct buffer *buf, struct tunnel *t, struct call *c);
39 
40 extern char *msgtypes[];
41 
42 #define VENDOR_ID 0             /* We don't have any extensions
43                                    so we shoouldn't have to
44                                    worry about this */
45 
46 /*
47  * Macros to extract information from length field of AVP
48  */
49 
50 #define AMBIT(len) (len & 0x8000)       /* Mandatory bit: If this is
51                                            set on an unknown AVP,
52                                            we MUST terminate */
53 
54 #define AHBIT(len) (len & 0x4000)       /* Hidden bit: Specifies
55                                            information hiding */
56 
57 #define AZBITS(len) (len & 0x3C00)      /* Reserved bits:  We must
58                                            drop anything with any
59                                            of these set.  */
60 
61 #define ALENGTH(len) (len & 0x03FF)     /* Length:  Lenth of AVP */
62 
63 #define MAXTIME 300             /* time to wait before checking
64                                    Ns and Nr, in ms */
65 
66 #define MBIT 0x8000             /* for setting */
67 #define HBIT 0x4000             /* Set on hidden avp's */
68 
69 #define ASYNC_FRAMING 2
70 #define SYNC_FRAMING 1
71 
72 #define ANALOG_BEARER 2
73 #define DIGITAL_BEARER 1
74 
75 #define VENDOR_ERROR 6
76 
77 #define ERROR_RESERVED 3
78 #define ERROR_LENGTH 2
79 #define ERROR_NOTEXIST 1
80 #define ERROR_NORES 4
81 #define ERROR_INVALID 6
82 #define RESULT_CLEAR 1
83 #define RESULT_ERROR 2
84 #define RESULT_EXISTS 3
85 extern void encrypt_avp (struct buffer *, _u16, struct tunnel *);
86 extern int decrypt_avp (char *, struct tunnel *);
87 extern int message_type_avp (struct tunnel *, struct call *, void *, int);
88 extern int protocol_version_avp (struct tunnel *, struct call *, void *, int);
89 extern int framing_caps_avp (struct tunnel *, struct call *, void *, int);
90 extern int bearer_caps_avp (struct tunnel *, struct call *, void *, int);
91 extern int firmware_rev_avp (struct tunnel *, struct call *, void *, int);
92 extern int hostname_avp (struct tunnel *, struct call *, void *, int);
93 extern int vendor_avp (struct tunnel *, struct call *, void *, int);
94 extern int assigned_tunnel_avp (struct tunnel *, struct call *, void *, int);
95 extern int receive_window_size_avp (struct tunnel *, struct call *, void *,
96                                     int);
97 extern int result_code_avp (struct tunnel *, struct call *, void *, int);
98 extern int assigned_call_avp (struct tunnel *, struct call *, void *, int);
99 extern int call_serno_avp (struct tunnel *, struct call *, void *, int);
100 extern int bearer_type_avp (struct tunnel *, struct call *, void *, int);
101 extern int call_physchan_avp (struct tunnel *, struct call *, void *, int);
102 extern int dialed_number_avp (struct tunnel *, struct call *, void *, int);
103 extern int dialing_number_avp (struct tunnel *, struct call *, void *, int);
104 extern int sub_address_avp (struct tunnel *, struct call *, void *, int);
105 extern int frame_type_avp (struct tunnel *, struct call *, void *, int);
106 extern int rx_speed_avp (struct tunnel *, struct call *, void *, int);
107 extern int tx_speed_avp (struct tunnel *, struct call *, void *, int);
108 extern int packet_delay_avp (struct tunnel *, struct call *, void *, int);
109 extern int ignore_avp (struct tunnel *, struct call *, void *, int);
110 extern int seq_reqd_avp (struct tunnel *, struct call *, void *, int);
111 extern int challenge_avp (struct tunnel *, struct call *, void *, int);
112 extern int chalresp_avp (struct tunnel *, struct call *, void *, int);
113 extern int rand_vector_avp (struct tunnel *, struct call *, void *, int);
114 
115 extern int add_challenge_avp (struct buffer *, char *, int);
116 extern int add_avp_rws (struct buffer *, _u16);
117 extern int add_tunnelid_avp (struct buffer *, _u16);
118 extern int add_vendor_avp (struct buffer *);
119 extern int add_hostname_avp (struct buffer *);
120 extern int add_firmware_avp (struct buffer *);
121 extern int add_bearer_caps_avp (struct buffer *buf, _u16 caps);
122 extern int add_frame_caps_avp (struct buffer *buf, _u16 caps);
123 extern int add_protocol_avp (struct buffer *buf);
124 extern int add_message_type_avp (struct buffer *buf, _u16 type);
125 extern int add_result_code_avp (struct buffer *buf, _u16, _u16, char *, int);
126 extern int add_bearer_avp (struct buffer *, int);
127 extern int add_frame_avp (struct buffer *, int);
128 extern int add_rxspeed_avp (struct buffer *, int);
129 extern int add_txspeed_avp (struct buffer *, int);
130 extern int add_serno_avp (struct buffer *, unsigned int);
131 #ifdef TEST_HIDDEN
132 extern int add_callid_avp (struct buffer *, _u16, struct tunnel *);
133 #else
134 extern int add_callid_avp (struct buffer *, _u16);
135 #endif
136 extern int add_ppd_avp (struct buffer *, _u16);
137 extern int add_seqreqd_avp (struct buffer *);
138 extern int add_chalresp_avp (struct buffer *, char *, int);
139 extern int add_randvect_avp (struct buffer *, char *, int);
140 extern int add_minbps_avp (struct buffer *buf, int speed);      /* jz: needed for outgoing call */
141 extern int add_maxbps_avp (struct buffer *buf, int speed);      /* jz: needed for outgoing call */
142 extern int add_number_avp (struct buffer *buf, char *no);       /* jz: needed for outgoing call */
143