1/*
2 * pptpdefs.h
3 *
4 * PPTP structs and defines
5 *
6 * $Id: pptpdefs.h,v 1.3 2005/08/02 09:51:18 quozl Exp $
7 */
8
9#ifndef _PPTPD_PPTPDEFS_H
10#define _PPTPD_PPTPDEFS_H
11
12/* define "portable" htons, etc, copied to make Ananian's gre stuff work. */
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)
19
20#include <sys/types.h>
21
22/* PPTP ctrl message port */
23#define PPTP_PORT			1723
24
25/* PPTP gre prototype */
26#define PPTP_PROTO			47
27
28/* PPTP version */
29#define PPTP_VERSION			0x0100
30#define	PPTP_FIRMWARE_VERSION		0x0001
31
32/* Hostname and Vendor */
33#define PPTP_HOSTNAME			"local"
34#define PPTP_VENDOR			"linux"
35
36#define MAX_HOSTNAME_SIZE		64
37#define MAX_VENDOR_SIZE			64
38
39/* Magic Cookie */
40#define PPTP_MAGIC_COOKIE		0x1a2b3c4d
41
42/* Message types */
43#define PPTP_CTRL_MESSAGE		1
44
45/* Maximum size of any PPTP control packet we will get */
46#define PPTP_MAX_CTRL_PCKT_SIZE		220
47
48/* Control Connection Management */
49#define START_CTRL_CONN_RQST		1
50#define START_CTRL_CONN_RPLY		2
51#define STOP_CTRL_CONN_RQST		3
52#define STOP_CTRL_CONN_RPLY		4
53#define ECHO_RQST			5
54#define ECHO_RPLY			6
55
56/* Call Management */
57#define OUT_CALL_RQST			7
58#define OUT_CALL_RPLY			8
59#define IN_CALL_RQST			9
60#define IN_CALL_RPLY			10
61#define IN_CALL_CONN			11
62#define CALL_CLR_RQST			12
63#define CALL_DISCONN_NTFY		13
64
65/* Error Reporting */
66#define WAN_ERR_NTFY			14
67
68/* PPP Session Control */
69#define SET_LINK_INFO			15
70
71/* how long before a link is idle? (seconds) */
72#define IDLE_WAIT			60
73
74/* how long should we wait for an echo reply? (seconds) */
75#define MAX_ECHO_WAIT			60
76
77/* how long to wait for ppp to begin negotiation (seconds) */
78#define PPP_WAIT			30
79
80#define RESERVED			0x0000
81
82/* Start Control Connection Reply */
83#define ASYNCHRONOUS_FRAMING		0x00000001
84#define SYNCHRONOUS_FRAMING		0x00000002
85#define ANALOG_ACCESS			0x00000001
86#define DIGITAL_ACCESS			0x00000002
87
88/* Our properties - we don't actually have any physical serial i/f's and only want
89 * one call per client!
90 */
91#define OUR_FRAMING			0x00000000
92#define OUR_BEARER			0x00000000
93#define MAX_CHANNELS			0x0001
94
95/* Out Call Reply Defines */
96#define PCKT_RECV_WINDOW_SIZE		0x0001
97#define PCKT_PROCESS_DELAY		0x0000
98#define CHANNEL_ID			0x00000000
99
100/* ERROR CODES */
101#define NO_ERROR			0x00
102
103/* CALL_CLEAR RESULT CODES */
104#define LOST_CARRIER			0x01
105#define ADMIN_SHUTDOWN			0x03
106#define CALL_CLEAR_REQUEST		0x04
107
108/* RESULT CODES */
109#define CONNECTED			0x01
110#define DISCONNECTED			0x01
111#define GENERAL_ERROR			0x02	/* also for ERROR CODES, CALL CLEAR */
112#define NO_CARRIER			0x03
113#define BUSY				0x04
114#define NO_DIAL_TONE			0x05
115#define TIME_OUT			0x06
116#define DO_NOT_ACCEPT			0x07
117
118/* CTRL CLOSE CODES */
119#define GENERAL_STOP_CTRL		0x01
120#define STOP_PROTOCOL			0x02
121#define STOP_LOCAL_SHUTDOWN		0x03
122
123/* PPTP CTRL structs */
124
125struct pptp_header {
126	u_int16_t length;		/* pptp message length incl header */
127	u_int16_t pptp_type;		/* pptp message type */
128	u_int32_t magic;		/* magic cookie */
129	u_int16_t ctrl_type;		/* control message type */
130	u_int16_t reserved0;		/* reserved */
131};
132
133struct pptp_start_ctrl_conn_rqst {
134	struct pptp_header header;	/* pptp header */
135	u_int16_t version;		/* pptp protocol version */
136	u_int16_t reserved1;		/* reserved */
137	u_int32_t framing_cap;		/* framing capabilities */
138	u_int32_t bearer_cap;		/* bearer capabilities */
139	u_int16_t max_channels;		/* maximum channels */
140	u_int16_t firmware_rev;		/* firmware revision */
141	u_int8_t hostname[MAX_HOSTNAME_SIZE];	/* hostname */
142	u_int8_t vendor[MAX_VENDOR_SIZE];	/* vendor */
143};
144
145struct pptp_start_ctrl_conn_rply {
146	struct pptp_header header;	/* pptp header */
147	u_int16_t version;		/* pptp protocol version */
148	u_int8_t result_code;		/* result code */
149	u_int8_t error_code;		/* error code */
150	u_int32_t framing_cap;		/* framing capabilities */
151	u_int32_t bearer_cap;		/* bearer capabilities */
152	u_int16_t max_channels;		/* maximum channels */
153	u_int16_t firmware_rev;		/* firmware revision */
154	u_int8_t hostname[MAX_HOSTNAME_SIZE];	/* hostname */
155	u_int8_t vendor[MAX_VENDOR_SIZE];	/* vendor */
156};
157
158struct pptp_stop_ctrl_conn_rqst {
159	struct pptp_header header;	/* header */
160	u_int8_t reason;		/* reason for closing */
161	u_int8_t reserved1;		/* reserved */
162	u_int16_t reserved2;		/* reserved */
163};
164
165struct pptp_stop_ctrl_conn_rply {
166	struct pptp_header header;	/* header */
167	u_int8_t result_code;		/* result code */
168	u_int8_t error_code;		/* error code */
169	u_int16_t reserved1;		/* reserved */
170};
171
172struct pptp_echo_rqst {
173	struct pptp_header header;	/* header */
174	u_int32_t identifier;		/* value to match rply with rqst */
175};
176
177struct pptp_echo_rply {
178	struct pptp_header header;	/* header */
179	u_int32_t identifier;		/* identifier of echo rqst */
180	u_int8_t result_code;		/* result code */
181	u_int8_t error_code;		/* error code */
182	u_int16_t reserved1;		/* reserved */
183};
184
185struct pptp_out_call_rqst {
186	struct pptp_header header;	/* header */
187	u_int16_t call_id;		/* unique identifier to PAC-PNS pair */
188	u_int16_t call_serial;		/* session identifier */
189	u_int32_t min_bps;		/* minimum line speed */
190	u_int32_t max_bps;		/* maximum line speed */
191	u_int32_t bearer_type;		/* bearer type */
192	u_int32_t framing_type;		/* framing type */
193	u_int16_t pckt_recv_size;	/* packet recv window size */
194	u_int16_t pckt_delay;		/* packet processing delay */
195	u_int16_t phone_len;		/* phone number length */
196	u_int16_t reserved1;		/* reserved */
197	u_int8_t phone_num[64];		/* phone number */
198	u_int8_t subaddress[64];	/* additional dialing info */
199};
200
201struct pptp_out_call_rply {
202	struct pptp_header header;	/* header */
203	u_int16_t call_id;		/* unique identifier to PAC-PNS pair */
204	u_int16_t call_id_peer;		/* set to call_id of the call rqst */
205	u_int8_t result_code;		/* result code */
206	u_int8_t error_code;		/* error code */
207	u_int16_t cause_code;		/* additional failure information */
208	u_int32_t speed;		/* actual connection speed */
209	u_int16_t pckt_recv_size;	/* packet recv window size */
210	u_int16_t pckt_delay;		/* packet processing delay */
211	u_int32_t channel_id;		/* physical channel ID */
212};
213
214struct pptp_in_call_rqst {
215	struct pptp_header header;	/* header */
216	u_int16_t call_id;		/* unique identifier for tunnel */
217	u_int16_t call_serial;		/* session identifier */
218	u_int32_t bearer_type;		/* bearer capability */
219	u_int32_t channel_id;		/* channel ID */
220	u_int16_t dialed_len;		/* dialed length */
221	u_int16_t dialing_len;		/* dialing length */
222	u_int8_t dialed_num[64];	/* number that was dialed by the caller */
223	u_int8_t dialing_num[64];	/* the number from which the call was placed */
224	u_int8_t subaddress[64];	/* additional dialing information */
225};
226
227struct pptp_in_call_rply {
228	struct pptp_header header;	/* header */
229	u_int16_t call_id;		/* unique identifier for the tunnel */
230	u_int16_t peers_call_id;	/* set to rcvd call ID */
231	u_int8_t result_code;		/* result code */
232	u_int8_t error_code;		/* error code */
233	u_int16_t pckt_recv_size;	/* packet recv window size */
234	u_int16_t pckt_delay;		/* packet transmit delay */
235	u_int16_t reserved1;		/* reserved */
236};
237
238struct pptp_in_call_connect {
239	struct pptp_header header;	/* header */
240	u_int16_t peers_call_id;	/* set to rcvd call ID */
241	u_int16_t reserved1;		/* reserved */
242	u_int32_t speed;		/* connect speed */
243	u_int16_t pckt_recv_size;	/* packet rcvd window size */
244	u_int16_t pckt_delay;		/* packet transmit delay */
245	u_int32_t framing_type;		/* framing type */
246};
247
248struct pptp_call_clr_rqst {
249	struct pptp_header header;	/* header */
250	u_int16_t call_id;		/* call ID assigned by the PNS */
251	u_int16_t reserved1;		/* reserved */
252};
253
254struct pptp_call_disconn_ntfy {
255	struct pptp_header header;	/* header */
256	u_int16_t call_id;		/* call ID assigned by the PAC */
257	u_int8_t result_code;		/* result code */
258	u_int8_t error_code;		/* error code */
259	u_int16_t cause_code;		/* additional disconnect info */
260	u_int16_t reserved1;		/* reserved */
261	u_int8_t call_stats[128];	/* vendor specific call stats */
262};
263
264struct pptp_wan_err_ntfy {
265	struct pptp_header header;	/* header */
266	u_int16_t peers_call_id;	/* call ID assigned by PNS */
267	u_int16_t reserved1;		/* reserved */
268	u_int32_t crc_errors;		/* # of PPP frames rcvd with CRC errors */
269	u_int32_t framing_errors;	/* # of improperly framed PPP pckts */
270	u_int32_t hardware_overruns;	/* # of receive buffer overruns */
271	u_int32_t buff_overruns;	/* # of buffer overruns */
272	u_int32_t timeout_errors;	/* # of timeouts */
273	u_int32_t align_errors;		/* # of alignment errors */
274};
275
276struct pptp_set_link_info {
277	struct pptp_header header;
278	u_int16_t peers_call_id;	/* call ID assigned by PAC */
279	u_int16_t reserved1;		/* reserved */
280	u_int32_t send_accm;		/* send ACCM value the client should use */
281	u_int32_t recv_accm;		/* recv ACCM value the client should use */
282};
283
284/* GRE and PPP structs */
285
286/* Copied from C. S. Ananian */
287
288#define HDLC_FLAG		0x7E
289#define HDLC_ESCAPE		0x7D
290
291#define PPTP_GRE_PROTO		0x880B
292#define PPTP_GRE_VER		0x1
293
294#define PPTP_GRE_FLAG_C		0x80
295#define PPTP_GRE_FLAG_R		0x40
296#define PPTP_GRE_FLAG_K		0x20
297#define PPTP_GRE_FLAG_S		0x10
298#define PPTP_GRE_FLAG_A		0x80
299
300#define PPTP_GRE_IS_C(f)	((f)&PPTP_GRE_FLAG_C)
301#define PPTP_GRE_IS_R(f)	((f)&PPTP_GRE_FLAG_R)
302#define PPTP_GRE_IS_K(f)	((f)&PPTP_GRE_FLAG_K)
303#define PPTP_GRE_IS_S(f)	((f)&PPTP_GRE_FLAG_S)
304#define PPTP_GRE_IS_A(f)	((f)&PPTP_GRE_FLAG_A)
305
306struct pptp_gre_header {
307	u_int8_t flags;		/* bitfield */
308	u_int8_t ver;		/* should be PPTP_GRE_VER (enhanced GRE) */
309	u_int16_t protocol;	/* should be PPTP_GRE_PROTO (ppp-encaps) */
310	u_int16_t payload_len;	/* size of ppp payload, not inc. gre header */
311	u_int16_t call_id;	/* peer's call_id for this session */
312	u_int32_t seq;		/* sequence number.  Present if S==1 */
313	u_int32_t ack;		/* seq number of highest packet recieved by */
314	/* sender in this session */
315};
316
317/* For our call ID pairs */
318#define PNS_VALUE 0
319#define PAC_VALUE 1
320
321#define GET_VALUE(which, where) ((which ## _VALUE) ? ((where) & 0xffff) : ((where) >> 16))
322
323#define NOTE_VALUE(which, where, what) ((which ## _VALUE) \
324					  ? ((where) = ((where) & 0xffff0000) | (what)) \
325					  : ((where) = ((where) & 0xffff) | ((what) << 16)))
326
327#endif	/* !_PPTPD_PPTPDEFS_H */
328