1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24#ifndef __L2TP_H__
25#define __L2TP_H__
26
27#include <netinet/in.h>
28#include "../L2TP-extension/l2tpk.h"
29
30#define L2TP_NKE	"L2TP.kext"
31#define L2TP_NKE_ID	"com.apple.nke.l2tp"
32
33/* L2TP exit codes */
34#define EXIT_L2TP_NOSERVER  		1
35#define EXIT_L2TP_NOANSWER  		2
36#define EXIT_L2TP_PROTOCOLERROR 	5
37#define EXIT_L2TP_NETWORKCHANGED 	6
38#define EXIT_L2TP_NOSHAREDSECRET 	7
39#define EXIT_L2TP_NOCERTIFICATE 	8
40#if TARGET_OS_EMBEDDED
41#define EXIT_L2TP_NOEDGE			9
42#endif
43
44/* AVP flags */
45#define L2TP_AVP_FLAGS_M		0x8000
46#define L2TP_AVP_FLAGS_H		0x4000
47#define L2TP_AVP_FLAGS_RESERVED		0x3C00
48#define L2TP_AVP_LEN_MASK		0x03FF
49
50/* misc masks */
51#define L2TP_AVP_CAPS_MASK		0x00000003
52#define L2TP_CNTL_MSG_HDR_SIZE 12
53
54#define L2TP_AVP_HDR_SIZE 		6		/* size of L2TP AVP header */
55
56#define MAX_HOST_NAME_SIZE		64
57#define MAX_VENDOR_NAME_SIZE		64
58#define MAX_CALLED_NUM_SIZE		128
59#define MAX_CALLING_NUM_SIZE		128
60#define MAX_SUB_ADDR_SIZE		128
61#define MAX_ERROR_MSG_SIZE		256
62#define MAX_ADVISORY_MSG_SIZE		256
63
64
65/* generic results codes */
66#define L2TP_RESULT_SUCCESS	1
67#define L2TP_RESULT_ERROR	2
68
69/*outgoing call result codes */
70#define L2TP_OUTGOING_CALL_RESULT_CONNECTED	1
71#define L2TP_OUTGOING_CALL_RESULT_ERROR		2
72#define L2TP_OUTGOING_CALL_RESULT_NOCARRIER	3
73#define L2TP_OUTGOING_CALL_RESULT_BUSY		4
74#define L2TP_OUTGOING_CALL_RESULT_NODIALTONE	5
75#define L2TP_OUTGOING_CALL_RESULT_TIMEOUT	6
76#define L2TP_OUTGOING_CALL_RESULT_DONOTACCEPT	7
77
78/* define l2tp control messages */
79
80/* Control Connection Management */
81#define ZLB_ACK			0	/* used internally to indicate ZLB ack */
82
83#define L2TP_SCCRQ		1	/* Start-Control-Connection-Request */
84#define L2TP_SCCRP		2	/* Start-Control-Connection-Reply */
85#define L2TP_SCCCN		3	/* Start-Control-Connection-Connected */
86#define L2TP_StopCCN		4	/* Stop-Control-Connection-Notification */
87#define L2TP_HELLO		6	/* Hello */
88
89/* Call Management */
90#define L2TP_OCRQ		7	/* Outgoing-Call-Request */
91#define L2TP_OCRP		8	/* Outgoing-Call-Reply */
92#define L2TP_OCCN		9	/* Outgoing-Call-Connected */
93#define L2TP_ICRQ		10	/* Incoming-Call-Request */
94#define L2TP_ICRP		11	/* Incoming-Call-Reply */
95#define L2TP_ICCN		12	/* Incoming-Call-Connected */
96#define L2TP_CDN		14	/* Call-Disconnect-Notify */
97
98/* Error Reporting */
99#define L2TP_WEN		15	/* WAN-Error-Notify */
100
101/* PPP Session Control */
102#define L2TP_SLI		16	/* Set-Link-Info */
103
104
105#define L2TP_PROTOCOL_VERSION	0x0100	/* L2TP version number */
106#define L2TP_VENDOR_ID 		63  	/* from RFC1700 */
107
108/* define framing capabilities */
109#define L2TP_SYNC_FRAMING	1
110#define L2TP_ASYNC_FRAMING	2
111
112/* define bearer capabilities */
113#define L2TP_DIGITAL_ACCESS	1
114#define L2TP_ANALOG_ACCESS	2
115
116/* result codes for CDN message */
117#define L2TP_CALLRESULT_CARRIERLOSS	1
118#define L2TP_CALLRESULT_ERRORCODE	2
119#define L2TP_CALLRESULT_ADMIN		3
120#define L2TP_CALLRESULT_TEMPRESOURCE	4
121#define L2TP_CALLRESULT_PERMRESOURCE	5
122#define L2TP_CALLRESULT_INVALIDDEST	6
123#define L2TP_CALLRESULT_NOCARRIER	7
124#define L2TP_CALLRESULT_BUSY		8
125#define L2TP_CALLRESULT_NODIALTONE	9
126#define L2TP_CALLRESULT_TIMEOUT	10
127#define L2TP_CALLRESULT_BADFRAMING	11
128
129/* result codes for StopCCN */
130#define L2TP_CCNRESULT_GENERAL		1
131#define L2TP_CCNRESULT_GENERALERROR	2
132#define L2TP_CCNRESULT_ALREADYEXISTS	3
133#define L2TP_CCNRESULT_NOTAUTHORIZED	4
134#define L2TP_CCNRESULT_UNSUPPORTEDVERS	5
135#define L2TP_CCNRESULT_SHUTDOWN		6
136#define L2TP_CCNRESULT_FSMERROR		7
137
138#define MAX_CNTL_BUFFER_SIZE 		1500	/* should be far more than needed */
139
140struct l2tp_parameters {
141	/* parameters used for control and call connection establishment */
142	u_int16_t	tunnel_id;
143	u_int16_t	protocol_vers;
144	u_int16_t	firmware_rev;
145	u_int16_t	window_size;
146	u_int16_t	session_id;
147	u_int16_t	seq_required;
148	/*u_int16_t	proxy_authen_type; */
149	/*u_int16_t	proxy_authen_id; */
150	u_int32_t	framing_type;
151	u_int32_t	tx_connect_speed;
152	u_int32_t	rx_connect_speed;
153	u_int32_t	call_serial_num;
154	u_int32_t	bearer_type;
155	u_int32_t	phys_channel_id;
156	u_int32_t	framing_caps;
157	u_int32_t	bearer_caps;
158	u_int32_t	tie_breaker[2];
159	u_int8_t	host_name[MAX_HOST_NAME_SIZE];
160	u_int8_t	vendor_name[MAX_VENDOR_NAME_SIZE];
161	u_int8_t	called_number[MAX_CALLED_NUM_SIZE];
162	u_int8_t	calling_number[MAX_CALLING_NUM_SIZE];
163	u_int8_t	sub_address[MAX_SUB_ADDR_SIZE];
164	/*u_int8_t	challenge[MAX_CHALLENGE_SIZE]; */
165	/*u_int8_t	challenge_resp[MAX_CHALLENGE_RESP_SIZE]; */
166	/*u_int8_t	priv_group_id[MAX_PRIV_GROUP_ID_SIZE]; */
167	/*u_int8_t	init_rcvd_confreq[MAX_CONFREQ_SIZE]; */
168	/*u_int8_t	last_sent_confreq[MAX_CONFREQ_SIZE]; */
169	/*u_int8_t	last_rcvd_confreq[MAX_CONFREQ_SIZE]; */
170	/*u_int8_t	proxy_authen_name[MAX_PROXY_AUTHEN_NAME]; */
171	/*u_int8_t	proxy_authen_challenge[MAX_PROXY_AUTHEN_CHALLENGE]; */
172	/*u_int8_t	proxy_authen_resp[MAX_PROXY_AUTHEN_RES]; */
173	/* Result Code */
174	u_int16_t	result_code;
175	u_int16_t	error_code;
176	u_int8_t	error_message[MAX_ERROR_MSG_SIZE];
177	/* Cause Code */
178	u_int16_t	cause_code;
179	u_int8_t	cause_message;
180	u_int8_t	advisory_message[MAX_ADVISORY_MSG_SIZE];
181	/* SLI */
182	u_int32_t	send_accm;
183	u_int32_t	recv_accm;
184	/* WEN */
185	u_int32_t	crc_errors;
186	u_int32_t	framing_errors;
187	u_int32_t	hardware_overruns;
188	u_int32_t	buffer_overruns;
189	u_int32_t	timeout_errors;
190	u_int32_t	alignment_errors;
191};
192
193
194/*-----------------------------
195 * function prototypes
196-----------------------------*/
197int l2tp_outgoing_call(int fd, struct sockaddr *peer_address, struct l2tp_parameters *our_params, struct l2tp_parameters *peer_params, int recv_timeout);
198int l2tp_incoming_call(int fd, struct l2tp_parameters *our_params, struct l2tp_parameters *peer_params, int recv_timeout);
199int l2tp_data_in(int fd);
200int l2tp_send_hello(int fd, struct l2tp_parameters *our_params);
201int l2tp_send_hello_trigger(int fd, struct sockaddr *peer_address);
202int l2tp_send_SCCRQ(int fd, struct sockaddr *peer_address, struct l2tp_parameters *our_params);
203int l2tp_send_CDN(int fd, struct l2tp_parameters *our_params, struct l2tp_parameters *peer_params);
204int l2tp_send_StopCCN(int fd, struct l2tp_parameters *our_params);
205void l2tp_reset_timers(int fd, int connect_mode);
206int l2tp_set_flag(int fd, int set, u_int32_t flag);
207int l2tp_set_baudrate(int fd, u_int32_t baudrate);
208int l2tp_recv(int fd, u_int8_t* buf, int len, int *outlen, struct sockaddr *from, int timeout, char *text);
209
210int l2tp_set_ouraddress(int fd, struct sockaddr *addr);
211int l2tp_set_peeraddress(int fd, struct sockaddr *addr);
212int l2tp_set_delegated_process(int fd, int pid);
213int l2tp_new_tunnelid(int fd, u_int16_t *tunnelid);
214int l2tp_set_ourparams(int fd, struct l2tp_parameters *our_params);
215int l2tp_set_peerparams(int fd, struct l2tp_parameters *peer_params);
216int l2tp_change_peeraddress(int fd, struct sockaddr *peer);
217
218#endif
219