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
25#ifndef PPP_MSG_H
26#define PPP_MSG_H
27
28#include <sys/types.h>
29#include <machine/types.h>
30
31
32// current version of the pppconfd api
33#define CURRENT_VERSION 1
34
35/* local socket path */
36#define PPP_PATH 	"/var/run/pppconfd\0"
37
38
39/* PPP message paquets */
40struct ppp_msg_hdr {
41    u_int16_t 		m_flags; 	// special flags
42    u_int16_t 		m_type; 	// type of the message
43    u_int32_t 		m_result; 	// error code of notification message
44    u_int32_t 		m_cookie;	// user param
45    u_int32_t 		m_link;		// link for this message
46    u_int32_t 		m_len;		// len of the following data
47};
48
49struct ppp_msg {
50    u_int16_t 		m_flags; 	// special flags
51    u_int16_t 		m_type; 	// type of the message
52    u_int32_t 		m_result; 	// error code of notification message
53    u_int32_t 		m_cookie;	// user param, or error num for event
54    u_int32_t 		m_link;		// link for this message
55    u_int32_t 		m_len;		// len of the following data
56    u_char 		m_data[1];	// msg data sent or received
57};
58
59#define PPP_MSG_MAX_DATA_LEN		(64 * 1024)	/* arbitrary limit... 64K */
60#define PPP_MSG_MAX_SERVICEID_LEN	 64			/* arbitrary limit... 64 bytes */
61
62/* codes for ppp messages */
63enum {
64    /* API client commands */
65    PPP_VERSION = 1,
66    PPP_STATUS,
67    PPP_CONNECT,
68    PPP_DISCONNECT = 5,
69    PPP_GETOPTION,
70    PPP_SETOPTION,
71    PPP_ENABLE_EVENT,
72    PPP_DISABLE_EVENT,
73    PPP_EVENT,
74    PPP_GETNBLINKS,
75    PPP_GETLINKBYINDEX,
76    PPP_GETLINKBYSERVICEID,
77    PPP_GETLINKBYIFNAME,
78    PPP_SUSPEND,
79    PPP_RESUME,
80    PPP_EXTENDEDSTATUS,
81    PPP_GETCONNECTDATA
82};
83
84// flags
85
86/* When USE_SERVICEID is set, m_link contains the serviceID length
87   serviceID string is put after m_len field
88   and m_len still contains the data lenght, excluding serviceID string */
89#define USE_SERVICEID	0x8000
90
91/* flags specific to the message type.
92   They will be interpreted differently depending on the type field of the message */
93#define FLAG_TYPE0	0x0001
94#define FLAG_TYPE1	0x0002
95#define FLAG_TYPE2	0x0004
96
97/* PPP_CONNECT message specific flags */
98#define CONNECT_ARBITRATED_FLAG		FLAG_TYPE0	/* connection will be arbitrated with other clients */
99#define CONNECT_AUTOCLOSE_FLAG		FLAG_TYPE1 	/* connection will be disconnected when socket is gone */
100
101/* PPP_DISCONNECT message specific flags */
102#define DISCONNECT_ARBITRATED_FLAG	FLAG_TYPE0	/* disconnection will be arbitrated with other clients */
103
104
105/* macro to access real data base on header flags */
106#define MSG_DATAOFF(msg)	(((struct ppp_msg_hdr *)msg)->m_flags & USE_SERVICEID ?                                     ((struct ppp_msg_hdr *)msg)->m_link : 0)
107
108// struct for an option
109struct ppp_opt_hdr {
110    u_int32_t 		o_type;
111};
112
113struct ppp_opt {
114    u_int32_t 		o_type;
115    u_char 		o_data[1];
116};
117
118
119/* codes for options management */
120enum {
121
122    PPP_OPT_DEV_NAME = 1,		// string
123    PPP_OPT_DEV_SPEED,			// 4 bytes
124    PPP_OPT_DEV_CONNECTSCRIPT,		// string
125
126    PPP_OPT_COMM_IDLETIMER,		// 4 bytes
127    PPP_OPT_COMM_REMOTEADDR,		// string
128
129    PPP_OPT_AUTH_PROTO,			// 4 bytes
130    PPP_OPT_AUTH_NAME,			// string
131    PPP_OPT_AUTH_PASSWD,		// string
132
133    PPP_OPT_LCP_HDRCOMP,		// 4 bytes
134    PPP_OPT_LCP_MRU,			// 4 bytes
135    PPP_OPT_LCP_MTU,			// 4 bytes
136    PPP_OPT_LCP_RCACCM,			// 4 bytes
137    PPP_OPT_LCP_TXACCM,			// 4 bytes
138
139    PPP_OPT_IPCP_HDRCOMP,		// 4 bytes
140    PPP_OPT_IPCP_LOCALADDR,		// 4 bytes
141    PPP_OPT_IPCP_REMOTEADDR,		// 4 bytes
142
143    PPP_OPT_LOGFILE,			// string
144    PPP_OPT_RESERVED,			// 4 bytes
145    PPP_OPT_COMM_REMINDERTIMER,		// 4 bytes
146    PPP_OPT_ALERTENABLE,		// 4 bytes
147
148    PPP_OPT_LCP_ECHO,			// struct ppp_opt_echo
149
150    PPP_OPT_COMM_CONNECTDELAY,		// 4 bytes
151    PPP_OPT_COMM_SESSIONTIMER,		// 4 bytes
152    PPP_OPT_COMM_TERMINALMODE,		// 4 bytes
153    PPP_OPT_COMM_TERMINALSCRIPT,	// string. Additionnal connection script, once modem is connected
154    PPP_OPT_RESERVED1,			// place holder
155
156    PPP_OPT_RESERVED2,			// place holder
157    PPP_OPT_DEV_CONNECTSPEED,		// 4 bytes, actual connection speed
158    PPP_OPT_SERVICEID,			// string, name of the associated service in the cache
159    PPP_OPT_IFNAME,			// string, name of the associated interface (ppp0, ...)
160
161    PPP_OPT_DEV_DIALMODE,		// 4 bytes, dial mode, applies to modem connection
162    PPP_OPT_DIALONDEMAND		// 4 bytes, is service configured for DialOnDemand ?
163};
164
165// options values
166
167// PPP_LCP_OPT_HDRCOMP -- option ppp addr/ctrl compression
168enum {
169    PPP_LCP_HDRCOMP_NONE = 0,
170    PPP_LCP_HDRCOMP_ADDR = 1,
171    PPP_LCP_HDRCOMP_PROTO = 2
172};
173
174enum {
175    PPP_COMM_TERM_NONE = 0,
176    PPP_COMM_TERM_SCRIPT,
177    PPP_COMM_TERM_WINDOW
178};
179
180enum {
181    PPP_ALERT_ERRORS = 2,		// disconnection causes
182    PPP_ALERT_PASSWORDS = 8,		// password and CCL Ask
183
184    PPP_ALERT_DISABLEALL = 0,
185    PPP_ALERT_ENABLEALL = 0xFFFFFFFF
186};
187
188
189enum {
190    PPP_IPCP_HDRCOMP_NONE = 0,
191    PPP_IPCP_HDRCOMP_VJ
192};
193
194// PPP_LCP_OPT_RCACCM -- option receive control asynchronous character map
195enum {
196    PPP_LCP_ACCM_NONE = 0,
197    PPP_LCP_ACCM_XONXOFF = 0x000A0000,
198    PPP_LCP_ACCM_ALL = 0xFFFFFFFF
199};
200
201// PPP_OPT_AUTH
202enum {
203    PPP_AUTH_NONE = 0,
204    PPP_AUTH_PAPCHAP,
205    PPP_AUTH_PAP,
206    PPP_AUTH_CHAP
207};
208
209// PPP_OPT_DEV_DIALMODE
210enum {
211    PPP_DEV_WAITFORDIALTONE = 0,
212    PPP_DEV_IGNOREDIALTONE,
213    PPP_DEV_MANUALDIAL
214};
215
216// state machine
217enum {
218    PPP_IDLE = 0,
219    PPP_INITIALIZE,
220    PPP_CONNECTLINK,
221    PPP_STATERESERVED,
222    PPP_DORMANT=3,
223    PPP_ESTABLISH=4,
224    PPP_AUTHENTICATE,
225    PPP_CALLBACK,
226    PPP_NETWORK,
227    PPP_RUNNING,
228    PPP_TERMINATE,
229    PPP_DISCONNECTLINK,
230    PPP_HOLDOFF,
231    PPP_ONHOLD,
232    PPP_WAITONBUSY,
233	PPP_WAITING
234};
235
236// events
237enum {
238    PPP_EVT_DISCONNECTED = 1,
239    PPP_EVT_CONNSCRIPT_STARTED,
240    PPP_EVT_CONNSCRIPT_FINISHED,
241    PPP_EVT_TERMSCRIPT_STARTED,
242    PPP_EVT_TERMSCRIPT_FINISHED,
243    PPP_EVT_LOWERLAYER_UP,
244    PPP_EVT_LOWERLAYER_DOWN,
245    PPP_EVT_LCP_UP,
246    PPP_EVT_LCP_DOWN,
247    PPP_EVT_IPCP_UP,
248    PPP_EVT_IPCP_DOWN,
249    PPP_EVT_AUTH_STARTED,
250    PPP_EVT_AUTH_FAILED,
251    PPP_EVT_AUTH_SUCCEDED,
252    PPP_EVT_CONN_STARTED,
253    PPP_EVT_CONN_FAILED,
254    PPP_EVT_CONN_SUCCEDED,
255    PPP_EVT_DISC_STARTED,
256    PPP_EVT_DISC_FINISHED,
257    PPP_EVT_STOPPED,
258    PPP_EVT_CONTINUED,
259    PPP_EVT_REQUEST_INSTALL,
260    PPP_EVT_REQUEST_UNINSTALL,
261};
262
263struct ppp_opt_echo {		// 0 for the following value will cancel echo option
264    u_int16_t 	interval;	// delay in seconds between echo requests
265    u_int16_t 	failure;	// # of failure before declaring the link down
266};
267
268struct ppp_status {
269    // connection stats
270    u_int32_t 		status;
271    union {
272        struct connected {
273            u_int32_t 		timeElapsed;
274            u_int32_t 		timeRemaining;
275            // bytes stats
276            u_int32_t 		inBytes;
277            u_int32_t 		inPackets;
278            u_int32_t 		inErrors;
279            u_int32_t 		outBytes;
280            u_int32_t 		outPackets;
281            u_int32_t 		outErrors;
282        } run;
283        struct disconnected {
284            u_int32_t 		lastDiscCause;
285        } disc;
286        struct waitonbusy {
287            u_int32_t 		timeRemaining;
288        } busy;
289    } s;
290};
291
292enum {
293    // from 0 to 255, we use bsd error codes from errno.h
294
295    // ppp speficic error codes
296    PPP_ERR_GEN_ERROR	= 256,
297    PPP_ERR_CONNSCRIPTFAILED,
298    PPP_ERR_TERMSCRIPTFAILED,
299    PPP_ERR_LCPFAILED,
300    PPP_ERR_AUTHFAILED,
301    PPP_ERR_IDLETIMEOUT,
302    PPP_ERR_SESSIONTIMEOUT,
303    PPP_ERR_LOOPBACK,
304    PPP_ERR_PEERDEAD,
305    PPP_ERR_DISCSCRIPTFAILED,
306    PPP_ERR_DISCBYPEER,
307    PPP_ERR_DISCBYDEVICE,
308    PPP_ERR_NODEVICE,
309
310    // modem specific error codes
311    PPP_ERR_MOD_NOCARRIER	= 512,
312    PPP_ERR_MOD_BUSY,
313    PPP_ERR_MOD_NODIALTONE,
314    PPP_ERR_MOD_ERROR,
315    PPP_ERR_MOD_HANGUP,
316    PPP_ERR_MOD_NOANSWER,
317    PPP_ERR_MOD_NONUMBER,
318    PPP_ERR_MOD_BADSCRIPT
319};
320
321#endif /* PPP_MSG_H */
322
323