Tomato 1.26 beta (1786)
[tomato.git] / release / src / router / pptp-client / pptp_msg.h
blob064f37bf2ce28f54b478b4eec28c532aa5e35100
1 /* pptp.h: packet structures and magic constants for the PPTP protocol
2 * C. Scott Ananian <cananian@alumni.princeton.edu>
4 * $Id: pptp_msg.h,v 1.1.1.1 2002/07/25 06:52:39 honor Exp $
5 */
7 #ifndef INC_PPTP_H
8 #define INC_PPTP_H
10 /* Grab definitions of int16, int32, etc. */
11 #include <sys/types.h>
12 /* define "portable" htons, etc. */
13 #define hton8(x) (x)
14 #define ntoh8(x) (x)
15 #define hton16(x) htons(x)
16 #define ntoh16(x) ntohs(x)
17 #define hton32(x) htonl(x)
18 #define ntoh32(x) ntohl(x)
20 /* PPTP magic numbers: ----------------------------------------- */
22 #define PPTP_MAGIC 0x1A2B3C4D /* Magic cookie for PPTP datagrams */
23 #define PPTP_PORT 1723 /* PPTP TCP port number */
24 #define PPTP_PROTO 47 /* PPTP IP protocol number */
26 /* Control Connection Message Types: --------------------------- */
28 #define PPTP_MESSAGE_CONTROL 1
29 #define PPTP_MESSAGE_MANAGE 2
31 /* Control Message Types: -------------------------------------- */
33 /* (Control Connection Management) */
34 #define PPTP_START_CTRL_CONN_RQST 1
35 #define PPTP_START_CTRL_CONN_RPLY 2
36 #define PPTP_STOP_CTRL_CONN_RQST 3
37 #define PPTP_STOP_CTRL_CONN_RPLY 4
38 #define PPTP_ECHO_RQST 5
39 #define PPTP_ECHO_RPLY 6
41 /* (Call Management) */
42 #define PPTP_OUT_CALL_RQST 7
43 #define PPTP_OUT_CALL_RPLY 8
44 #define PPTP_IN_CALL_RQST 9
45 #define PPTP_IN_CALL_RPLY 10
46 #define PPTP_IN_CALL_CONNECT 11
47 #define PPTP_CALL_CLEAR_RQST 12
48 #define PPTP_CALL_CLEAR_NTFY 13
50 /* (Error Reporting) */
51 #define PPTP_WAN_ERR_NTFY 14
53 /* (PPP Session Control) */
54 #define PPTP_SET_LINK_INFO 15
56 /* PPTP version information: --------------------------------------*/
57 #define PPTP_VERSION_STRING "1.00"
58 #define PPTP_VERSION 0x100
59 #define PPTP_FIRMWARE_STRING "0.01"
60 #define PPTP_FIRMWARE_VERSION 0x001
62 /* PPTP capabilities: ---------------------------------------------*/
64 /* (Framing capabilities for msg sender) */
65 #define PPTP_FRAME_ASYNC 1
66 #define PPTP_FRAME_SYNC 2
67 #define PPTP_FRAME_ANY 3
69 /* (Bearer capabilities for msg sender) */
70 #define PPTP_BEARER_ANALOG 1
71 #define PPTP_BEARER_DIGITAL 2
72 #define PPTP_BEARER_ANY 3
74 /* PPTP error codes: ----------------------------------------------*/
76 /* (General Error Codes) */
77 static const struct {
78 const char *name, *desc;
79 } pptp_general_errors[] = {
81 #define PPTP_GENERAL_ERROR_NONE 0
82 { "(None)", "No general error" },
83 #define PPTP_GENERAL_ERROR_NOT_CONNECTED 1
84 { "(Not-Connected)", "No control connection exists yet for this "
85 "PAC-PNS pair" },
86 #define PPTP_GENERAL_ERROR_BAD_FORMAT 2
87 { "(Bad-Format)", "Length is wrong or Magic Cookie value is incorrect" },
88 #define PPTP_GENERAL_ERROR_BAD_VALUE 3
89 { "(Bad-Value)", "One of the field values was out of range or "
90 "reserved field was non-zero" },
91 #define PPTP_GENERAL_ERROR_NO_RESOURCE 4
92 { "(No-Resource)", "Insufficient resources to handle this command now" },
93 #define PPTP_GENERAL_ERROR_BAD_CALLID 5
94 { "(Bad-Call ID)", "The Call ID is invalid in this context" },
95 #define PPTP_GENERAL_ERROR_PAC_ERROR 6
96 { "(PAC-Error)", "A generic vendor-specific error occured in the PAC" }
99 /* (Reasons to close a connection) */
100 #define PPTP_STOP_NONE 1 /* no good reason */
101 #define PPTP_STOP_PROTOCOL 2 /* can't support peer's protocol version */
102 #define PPTP_STOP_LOCAL_SHUTDOWN 3 /* requester is being shut down */
104 /* PPTP datagram structures (all data in network byte order): ----------*/
106 struct pptp_header {
107 u_int16_t length; /* message length in octets, including header */
108 u_int16_t pptp_type; /* PPTP message type. 1 for control message. */
109 u_int32_t magic; /* this should be PPTP_MAGIC. */
110 u_int16_t ctrl_type; /* Control message type (0-15) */
111 u_int16_t reserved0; /* reserved. MUST BE ZERO. */
114 struct pptp_start_ctrl_conn { /* for control message types 1 and 2 */
115 struct pptp_header header;
117 u_int16_t version; /* PPTP protocol version. = PPTP_VERSION */
118 u_int8_t result_code; /* these two fields should be zero on rqst msg*/
119 u_int8_t error_code; /* 0 unless result_code==2 (General Error) */
120 u_int32_t framing_cap; /* Framing capabilities */
121 u_int32_t bearer_cap; /* Bearer Capabilities */
122 u_int16_t max_channels; /* Maximum Channels (=0 for PNS, PAC ignores) */
123 u_int16_t firmware_rev; /* Firmware or Software Revision */
124 u_int8_t hostname[64]; /* Host Name (64 octets, zero terminated) */
125 u_int8_t vendor[64]; /* Vendor string (64 octets, zero term.) */
126 /* MS says that end of hostname/vendor fields should be filled with */
127 /* octets of value 0, but Win95 PPTP driver doesn't do this. */
130 struct pptp_stop_ctrl_conn { /* for control message types 3 and 4 */
131 struct pptp_header header;
133 u_int8_t reason_result; /* reason for rqst, result for rply */
134 u_int8_t error_code; /* MUST be 0, unless rply result==2 (general err)*/
135 u_int16_t reserved1; /* MUST be 0 */
138 struct pptp_echo_rqst { /* for control message type 5 */
139 struct pptp_header header;
140 u_int32_t identifier; /* arbitrary value set by sender which is used */
141 /* to match up reply and request */
144 struct pptp_echo_rply { /* for control message type 6 */
145 struct pptp_header header;
146 u_int32_t identifier; /* should correspond to id of rqst */
147 u_int8_t result_code;
148 u_int8_t error_code; /* =0, unless result_code==2 (general error) */
149 u_int16_t reserved1; /* MUST BE ZERO */
152 struct pptp_out_call_rqst { /* for control message type 7 */
153 struct pptp_header header;
154 u_int16_t call_id; /* Call ID (unique id used to multiplex data) */
155 u_int16_t call_sernum; /* Call Serial Number (used for logging) */
156 u_int32_t bps_min; /* Minimum BPS (lowest acceptable line speed) */
157 u_int32_t bps_max; /* Maximum BPS (highest acceptable line speed) */
158 u_int32_t bearer; /* Bearer type */
159 u_int32_t framing; /* Framing type */
160 u_int16_t recv_size; /* Recv. Window Size (no. of buffered packets) */
161 u_int16_t delay; /* Packet Processing Delay (in 1/10 sec) */
162 u_int16_t phone_len; /* Phone Number Length (num. of valid digits) */
163 u_int16_t reserved1; /* MUST BE ZERO */
164 u_int8_t phone_num[64]; /* Phone Number (64 octets, null term.) */
165 u_int8_t subaddress[64]; /* Subaddress (64 octets, null term.) */
168 struct pptp_out_call_rply { /* for control message type 8 */
169 struct pptp_header header;
170 u_int16_t call_id; /* Call ID (used to multiplex data over tunnel)*/
171 u_int16_t call_id_peer; /* Peer's Call ID (call_id of pptp_out_call_rqst)*/
172 u_int8_t result_code; /* Result Code (1 is no errors) */
173 u_int8_t error_code; /* Error Code (=0 unless result_code==2) */
174 u_int16_t cause_code; /* Cause Code (addt'l failure information) */
175 u_int32_t speed; /* Connect Speed (in BPS) */
176 u_int16_t recv_size; /* Recv. Window Size (no. of buffered packets) */
177 u_int16_t delay; /* Packet Processing Delay (in 1/10 sec) */
178 u_int32_t channel; /* Physical Channel ID (for logging) */
181 struct pptp_in_call_rqst { /* for control message type 9 */
182 struct pptp_header header;
183 u_int16_t call_id; /* Call ID (unique id used to multiplex data) */
184 u_int16_t call_sernum; /* Call Serial Number (used for logging) */
185 u_int32_t bearer; /* Bearer type */
186 u_int32_t channel; /* Physical Channel ID (for logging) */
187 u_int16_t dialed_len; /* Dialed Number Length (# of valid digits) */
188 u_int16_t dialing_len; /* Dialing Number Length (# of valid digits) */
189 u_int8_t dialed_num[64]; /* Dialed Number (64 octets, zero term.) */
190 u_int8_t dialing_num[64]; /* Dialing Number (64 octets, zero term.) */
191 u_int8_t subaddress[64]; /* Subaddress (64 octets, zero term.) */
194 struct pptp_in_call_rply { /* for control message type 10 */
195 struct pptp_header header;
196 u_int16_t call_id; /* Call ID (used to multiplex data over tunnel)*/
197 u_int16_t call_id_peer; /* Peer's Call ID (call_id of pptp_out_call_rqst)*/
198 u_int8_t result_code; /* Result Code (1 is no errors) */
199 u_int8_t error_code; /* Error Code (=0 unless result_code==2) */
200 u_int16_t recv_size; /* Recv. Window Size (no. of buffered packets) */
201 u_int16_t delay; /* Packet Processing Delay (in 1/10 sec) */
202 u_int16_t reserved1; /* MUST BE ZERO */
205 struct pptp_in_call_connect { /* for control message type 11 */
206 struct pptp_header header;
207 u_int16_t call_id_peer; /* Peer's Call ID (call_id of pptp_out_call_rqst)*/
208 u_int16_t reserved1; /* MUST BE ZERO */
209 u_int32_t speed; /* Connect Speed (in BPS) */
210 u_int16_t recv_size; /* Recv. Window Size (no. of buffered packets) */
211 u_int16_t delay; /* Packet Processing Delay (in 1/10 sec) */
212 u_int32_t framing; /* Framing type */
215 struct pptp_call_clear_rqst { /* for control message type 12 */
216 struct pptp_header header;
217 u_int16_t call_id; /* Call ID (used to multiplex data over tunnel)*/
218 u_int16_t reserved1; /* MUST BE ZERO */
221 struct pptp_call_clear_ntfy { /* for control message type 13 */
222 struct pptp_header header;
223 u_int16_t call_id; /* Call ID (used to multiplex data over tunnel)*/
224 u_int8_t result_code; /* Result Code */
225 u_int8_t error_code; /* Error Code (=0 unless result_code==2) */
226 u_int16_t cause_code; /* Cause Code (for ISDN, is Q.931 cause code) */
227 u_int16_t reserved1; /* MUST BE ZERO */
228 u_int8_t call_stats[128]; /* Call Statistics: 128 octets, ascii, 0-term */
231 struct pptp_wan_err_ntfy { /* for control message type 14 */
232 struct pptp_header header;
233 u_int16_t call_id_peer; /* Peer's Call ID (call_id of pptp_out_call_rqst)*/
234 u_int16_t reserved1; /* MUST BE ZERO */
235 u_int32_t crc_errors; /* CRC errors */
236 u_int32_t frame_errors; /* Framing errors */
237 u_int32_t hard_errors; /* Hardware overruns */
238 u_int32_t buff_errors; /* Buffer overruns */
239 u_int32_t time_errors; /* Time-out errors */
240 u_int32_t align_errors; /* Alignment errors */
243 struct pptp_set_link_info { /* for control message type 15 */
244 struct pptp_header header;
245 u_int16_t call_id_peer; /* Peer's Call ID (call_id of pptp_out_call_rqst) */
246 u_int16_t reserved1; /* MUST BE ZERO */
247 u_int32_t send_accm; /* Send ACCM (for PPP packets; default 0xFFFFFFFF)*/
248 u_int32_t recv_accm; /* Receive ACCM (for PPP pack.;default 0xFFFFFFFF)*/
251 /* helpful #defines: -------------------------------------------- */
252 #define pptp_isvalid_ctrl(header, type, length) \
253 (!( ( ntoh16(((struct pptp_header *)header)->length) < (length) ) || \
254 ( ntoh16(((struct pptp_header *)header)->pptp_type) !=(type) ) || \
255 ( ntoh32(((struct pptp_header *)header)->magic) !=PPTP_MAGIC) || \
256 ( ntoh16(((struct pptp_header *)header)->ctrl_type) > PPTP_SET_LINK_INFO) || \
257 ( ntoh16(((struct pptp_header *)header)->reserved0) !=0 ) ))
259 #define PPTP_HEADER_CTRL(type) \
260 { hton16(PPTP_CTRL_SIZE(type)), \
261 hton16(PPTP_MESSAGE_CONTROL), \
262 hton32(PPTP_MAGIC), \
263 hton16(type), 0 }
265 #define PPTP_CTRL_SIZE(type) ( \
266 (type==PPTP_START_CTRL_CONN_RQST)?sizeof(struct pptp_start_ctrl_conn): \
267 (type==PPTP_START_CTRL_CONN_RPLY)?sizeof(struct pptp_start_ctrl_conn): \
268 (type==PPTP_STOP_CTRL_CONN_RQST )?sizeof(struct pptp_stop_ctrl_conn): \
269 (type==PPTP_STOP_CTRL_CONN_RPLY )?sizeof(struct pptp_stop_ctrl_conn): \
270 (type==PPTP_ECHO_RQST )?sizeof(struct pptp_echo_rqst): \
271 (type==PPTP_ECHO_RPLY )?sizeof(struct pptp_echo_rply): \
272 (type==PPTP_OUT_CALL_RQST )?sizeof(struct pptp_out_call_rqst): \
273 (type==PPTP_OUT_CALL_RPLY )?sizeof(struct pptp_out_call_rply): \
274 (type==PPTP_IN_CALL_RQST )?sizeof(struct pptp_in_call_rqst): \
275 (type==PPTP_IN_CALL_RPLY )?sizeof(struct pptp_in_call_rply): \
276 (type==PPTP_IN_CALL_CONNECT )?sizeof(struct pptp_in_call_connect): \
277 (type==PPTP_CALL_CLEAR_RQST )?sizeof(struct pptp_call_clear_rqst): \
278 (type==PPTP_CALL_CLEAR_NTFY )?sizeof(struct pptp_call_clear_ntfy): \
279 (type==PPTP_WAN_ERR_NTFY )?sizeof(struct pptp_wan_err_ntfy): \
280 (type==PPTP_SET_LINK_INFO )?sizeof(struct pptp_set_link_info): \
282 #define max(a,b) (((a)>(b))?(a):(b))
283 #define PPTP_CTRL_SIZE_MAX ( \
284 max(sizeof(struct pptp_start_ctrl_conn), \
285 max(sizeof(struct pptp_echo_rqst), \
286 max(sizeof(struct pptp_echo_rply), \
287 max(sizeof(struct pptp_out_call_rqst), \
288 max(sizeof(struct pptp_out_call_rply), \
289 max(sizeof(struct pptp_in_call_rqst), \
290 max(sizeof(struct pptp_in_call_rply), \
291 max(sizeof(struct pptp_in_call_connect), \
292 max(sizeof(struct pptp_call_clear_rqst), \
293 max(sizeof(struct pptp_call_clear_ntfy), \
294 max(sizeof(struct pptp_wan_err_ntfy), \
295 max(sizeof(struct pptp_set_link_info), 0)))))))))))))
298 /* gre header structure: -------------------------------------------- */
300 #define PPTP_GRE_PROTO 0x880B
301 #define PPTP_GRE_VER 0x1
303 #define PPTP_GRE_FLAG_C 0x80
304 #define PPTP_GRE_FLAG_R 0x40
305 #define PPTP_GRE_FLAG_K 0x20
306 #define PPTP_GRE_FLAG_S 0x10
307 #define PPTP_GRE_FLAG_A 0x80
309 #define PPTP_GRE_IS_C(f) ((f)&PPTP_GRE_FLAG_C)
310 #define PPTP_GRE_IS_R(f) ((f)&PPTP_GRE_FLAG_R)
311 #define PPTP_GRE_IS_K(f) ((f)&PPTP_GRE_FLAG_K)
312 #define PPTP_GRE_IS_S(f) ((f)&PPTP_GRE_FLAG_S)
313 #define PPTP_GRE_IS_A(f) ((f)&PPTP_GRE_FLAG_A)
315 struct pptp_gre_header {
316 u_int8_t flags; /* bitfield */
317 u_int8_t ver; /* should be PPTP_GRE_VER (enhanced GRE) */
318 u_int16_t protocol; /* should be PPTP_GRE_PROTO (ppp-encaps) */
319 u_int16_t payload_len; /* size of ppp payload, not inc. gre header */
320 u_int16_t call_id; /* peer's call_id for this session */
321 u_int32_t seq; /* sequence number. Present if S==1 */
322 u_int32_t ack; /* seq number of highest packet recieved by */
323 /* sender in this session */
326 #endif /* INC_PPTP_H */