1 /*****************************************************************************
\r
2 * ppp.h - Network Point to Point Protocol header file.
\r
4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
\r
5 * portions Copyright (c) 1997 Global Election Systems Inc.
\r
7 * The authors hereby grant permission to use, copy, modify, distribute,
\r
8 * and license this software and its documentation for any purpose, provided
\r
9 * that existing copyright notices are retained in all copies and that this
\r
10 * notice and the following disclaimer are included verbatim in any
\r
11 * distributions. No written agreement, license, or royalty fee is required
\r
12 * for any of the authorized uses.
\r
14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
\r
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
\r
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
\r
17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
\r
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
\r
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
\r
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
\r
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
25 ******************************************************************************
\r
28 * 03-01-01 Marc Boucher <marc@mbsi.ca>
\r
30 * 97-11-05 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc.
\r
31 * Original derived from BSD codes.
\r
32 *****************************************************************************/
\r
37 #include "lwip/opt.h"
\r
40 #include "lwip/sio.h"
\r
41 #include "lwip/api.h"
\r
42 #include "lwip/sockets.h"
\r
43 #include "lwip/stats.h"
\r
44 #include "lwip/mem.h"
\r
45 #include "lwip/tcpip.h"
\r
46 #include "lwip/netif.h"
\r
49 * pppd.h - PPP daemon global declarations.
\r
51 * Copyright (c) 1989 Carnegie Mellon University.
\r
52 * All rights reserved.
\r
54 * Redistribution and use in source and binary forms are permitted
\r
55 * provided that the above copyright notice and this paragraph are
\r
56 * duplicated in all such forms and that any documentation,
\r
57 * advertising materials, and other materials related to such
\r
58 * distribution and use acknowledge that the software was developed
\r
59 * by Carnegie Mellon University. The name of the
\r
60 * University may not be used to endorse or promote products derived
\r
61 * from this software without specific prior written permission.
\r
62 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
\r
63 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
\r
64 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
\r
68 * ppp_defs.h - PPP definitions.
\r
70 * Copyright (c) 1994 The Australian National University.
\r
71 * All rights reserved.
\r
73 * Permission to use, copy, modify, and distribute this software and its
\r
74 * documentation is hereby granted, provided that the above copyright
\r
75 * notice appears in all copies. This software is provided without any
\r
76 * warranty, express or implied. The Australian National University
\r
77 * makes no representations about the suitability of this software for
\r
80 * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
\r
81 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
\r
82 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
\r
83 * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
\r
86 * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
\r
87 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
\r
88 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
\r
89 * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
\r
90 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
\r
94 #define TIMEOUT(f, a, t) sys_untimeout((f), (a)), sys_timeout((t)*1000, (f), (a))
\r
95 #define UNTIMEOUT(f, a) sys_untimeout((f), (a))
\r
98 # ifndef __u_char_defined
\r
100 /* Type definitions for BSD code. */
\r
101 typedef unsigned long u_long;
\r
102 typedef unsigned int u_int;
\r
103 typedef unsigned short u_short;
\r
104 typedef unsigned char u_char;
\r
109 * Constants and structures defined by the internet system,
\r
110 * Per RFC 790, September 1981, and numerous additions.
\r
114 * The basic PPP frame.
\r
116 #define PPP_HDRLEN 4 /* octets for standard ppp header */
\r
117 #define PPP_FCSLEN 2 /* octets for FCS */
\r
121 * Significant octet values.
\r
123 #define PPP_ALLSTATIONS 0xff /* All-Stations broadcast address */
\r
124 #define PPP_UI 0x03 /* Unnumbered Information */
\r
125 #define PPP_FLAG 0x7e /* Flag Sequence */
\r
126 #define PPP_ESCAPE 0x7d /* Asynchronous Control Escape */
\r
127 #define PPP_TRANS 0x20 /* Asynchronous transparency modifier */
\r
130 * Protocol field values.
\r
132 #define PPP_IP 0x21 /* Internet Protocol */
\r
133 #define PPP_AT 0x29 /* AppleTalk Protocol */
\r
134 #define PPP_VJC_COMP 0x2d /* VJ compressed TCP */
\r
135 #define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */
\r
136 #define PPP_COMP 0xfd /* compressed packet */
\r
137 #define PPP_IPCP 0x8021 /* IP Control Protocol */
\r
138 #define PPP_ATCP 0x8029 /* AppleTalk Control Protocol */
\r
139 #define PPP_CCP 0x80fd /* Compression Control Protocol */
\r
140 #define PPP_LCP 0xc021 /* Link Control Protocol */
\r
141 #define PPP_PAP 0xc023 /* Password Authentication Protocol */
\r
142 #define PPP_LQR 0xc025 /* Link Quality Report protocol */
\r
143 #define PPP_CHAP 0xc223 /* Cryptographic Handshake Auth. Protocol */
\r
144 #define PPP_CBCP 0xc029 /* Callback Control Protocol */
\r
147 * Values for FCS calculations.
\r
149 #define PPP_INITFCS 0xffff /* Initial FCS value */
\r
150 #define PPP_GOODFCS 0xf0b8 /* Good final FCS value */
\r
151 #define PPP_FCS(fcs, c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff])
\r
154 * Extended asyncmap - allows any character to be escaped.
\r
156 typedef u_char ext_accm[32];
\r
159 * What to do with network protocol (NP) packets.
\r
162 NPMODE_PASS, /* pass the packet through */
\r
163 NPMODE_DROP, /* silently drop the packet */
\r
164 NPMODE_ERROR, /* return an error */
\r
165 NPMODE_QUEUE /* save it up for later. */
\r
169 * Inline versions of get/put char/short/long.
\r
170 * Pointer is advanced; we assume that both arguments
\r
171 * are lvalues and will already be in registers.
\r
172 * cp MUST be u_char *.
\r
174 #define GETCHAR(c, cp) { \
\r
177 #define PUTCHAR(c, cp) { \
\r
178 *(cp)++ = (u_char) (c); \
\r
182 #define GETSHORT(s, cp) { \
\r
183 (s) = *(cp); (cp)++; (s) << 8; \
\r
184 (s) |= *(cp); (cp)++; \
\r
186 #define PUTSHORT(s, cp) { \
\r
187 *(cp)++ = (u_char) ((s) >> 8); \
\r
188 *(cp)++ = (u_char) (s); \
\r
191 #define GETLONG(l, cp) { \
\r
192 (l) = *(cp); (cp)++; (l) << 8; \
\r
193 (l) |= *(cp); (cp)++; (l) <<= 8; \
\r
194 (l) |= *(cp); (cp)++; (l) <<= 8; \
\r
195 (l) |= *(cp); (cp)++; \
\r
197 #define PUTLONG(l, cp) { \
\r
198 *(cp)++ = (u_char) ((l) >> 24); \
\r
199 *(cp)++ = (u_char) ((l) >> 16); \
\r
200 *(cp)++ = (u_char) ((l) >> 8); \
\r
201 *(cp)++ = (u_char) (l); \
\r
205 #define INCPTR(n, cp) ((cp) += (n))
\r
206 #define DECPTR(n, cp) ((cp) -= (n))
\r
208 #define BCMP(s0, s1, l) memcmp((u_char *)(s0), (u_char *)(s1), (l))
\r
209 #define BCOPY(s, d, l) memcpy((d), (s), (l))
\r
210 #define BZERO(s, n) memset(s, 0, n)
\r
212 #define PRINTMSG(m, l) { m[l] = '\0'; ppp_trace(LOG_INFO, "Remote message: %s\n", m); }
\r
214 #define PRINTMSG(m, l)
\r
218 * MAKEHEADER - Add PPP Header fields to a packet.
\r
220 #define MAKEHEADER(p, t) { \
\r
221 PUTCHAR(PPP_ALLSTATIONS, p); \
\r
222 PUTCHAR(PPP_UI, p); \
\r
225 /*************************
\r
226 *** PUBLIC DEFINITIONS ***
\r
227 *************************/
\r
230 #define PPPERR_NONE 0 /* No error. */
\r
231 #define PPPERR_PARAM -1 /* Invalid parameter. */
\r
232 #define PPPERR_OPEN -2 /* Unable to open PPP session. */
\r
233 #define PPPERR_DEVICE -3 /* Invalid I/O device for PPP. */
\r
234 #define PPPERR_ALLOC -4 /* Unable to allocate resources. */
\r
235 #define PPPERR_USER -5 /* User interrupt. */
\r
236 #define PPPERR_CONNECT -6 /* Connection lost. */
\r
237 #define PPPERR_AUTHFAIL -7 /* Failed authentication challenge. */
\r
238 #define PPPERR_PROTOCOL -8 /* Failed to meet protocol. */
\r
241 * PPP IOCTL commands.
\r
244 * Get the up status - 0 for down, non-zero for up. The argument must
\r
247 #define PPPCTLG_UPSTATUS 100 /* Get the up status - 0 down else up */
\r
248 #define PPPCTLS_ERRCODE 101 /* Set the error code */
\r
249 #define PPPCTLG_ERRCODE 102 /* Get the error code */
\r
250 #define PPPCTLG_FD 103 /* Get the fd associated with the ppp */
\r
252 /************************
\r
253 *** PUBLIC DATA TYPES ***
\r
254 ************************/
\r
257 * The following struct gives the addresses of procedures to call
\r
258 * for a particular protocol.
\r
261 u_short protocol; /* PPP protocol number */
\r
262 /* Initialization procedure */
\r
263 void (*init) (int unit);
\r
264 /* Process a received packet */
\r
265 void (*input) (int unit, u_char *pkt, int len);
\r
266 /* Process a received protocol-reject */
\r
267 void (*protrej) (int unit);
\r
268 /* Lower layer has come up */
\r
269 void (*lowerup) (int unit);
\r
270 /* Lower layer has gone down */
\r
271 void (*lowerdown) (int unit);
\r
272 /* Open the protocol */
\r
273 void (*open) (int unit);
\r
274 /* Close the protocol */
\r
275 void (*close) (int unit, char *reason);
\r
277 /* Print a packet in readable form */
\r
278 int (*printpkt) (u_char *pkt, int len,
\r
279 void (*printer) (void *, char *, ...),
\r
281 /* Process a received data packet */
\r
282 void (*datainput) (int unit, u_char *pkt, int len);
\r
284 int enabled_flag; /* 0 iff protocol is disabled */
\r
285 char *name; /* Text name of protocol */
\r
287 /* Check requested options, assign defaults */
\r
288 void (*check_options) (u_long);
\r
289 /* Configure interface for demand-dial */
\r
290 int (*demand_conf) (int unit);
\r
291 /* Say whether to bring up link for this pkt */
\r
292 int (*active_pkt) (u_char *pkt, int len);
\r
297 * The following structure records the time in seconds since
\r
298 * the last NP packet was sent or received.
\r
301 u_short xmit_idle; /* seconds since last NP packet sent */
\r
302 u_short recv_idle; /* seconds since last NP packet received */
\r
305 struct ppp_settings {
\r
307 u_int disable_defaultip : 1; /* Don't use hostname for default IP addrs */
\r
308 u_int auth_required : 1; /* Peer is required to authenticate */
\r
309 u_int explicit_remote : 1; /* remote_name specified with remotename opt */
\r
310 u_int refuse_pap : 1; /* Don't wanna auth. ourselves with PAP */
\r
311 u_int refuse_chap : 1; /* Don't wanna auth. ourselves with CHAP */
\r
312 u_int usehostname : 1; /* Use hostname for our_name */
\r
313 u_int usepeerdns : 1; /* Ask peer for DNS adds */
\r
315 u_short idle_time_limit; /* Shut down link if idle for this long */
\r
316 int maxconnect; /* Maximum connect time (seconds) */
\r
318 char user[MAXNAMELEN + 1];/* Username for PAP */
\r
319 char passwd[MAXSECRETLEN + 1]; /* Password for PAP, secret for CHAP */
\r
320 char our_name[MAXNAMELEN + 1]; /* Our name for authentication purposes */
\r
321 char remote_name[MAXNAMELEN + 1]; /* Peer's name for authentication */
\r
325 struct ip_addr our_ipaddr, his_ipaddr, netmask, dns1, dns2;
\r
328 /*****************************
\r
329 *** PUBLIC DATA STRUCTURES ***
\r
330 *****************************/
\r
331 /* Buffers for outgoing packets. */
\r
332 extern u_char outpacket_buf[NUM_PPP][PPP_MRU+PPP_HDRLEN];
\r
334 extern struct ppp_settings ppp_settings;
\r
336 extern struct protent *ppp_protocols[];/* Table of pointers to supported protocols */
\r
339 /***********************
\r
340 *** PUBLIC FUNCTIONS ***
\r
341 ***********************/
\r
343 /* Initialize the PPP subsystem. */
\r
344 void pppInit(void);
\r
346 /* Warning: Using PPPAUTHTYPE_ANY might have security consequences.
\r
349 * In practice, within or associated with each PPP server, there is a
\r
350 * database which associates "user" names with authentication
\r
351 * information ("secrets"). It is not anticipated that a particular
\r
352 * named user would be authenticated by multiple methods. This would
\r
353 * make the user vulnerable to attacks which negotiate the least secure
\r
354 * method from among a set (such as PAP rather than CHAP). If the same
\r
355 * secret was used, PAP would reveal the secret to be used later with
\r
358 * Instead, for each user name there should be an indication of exactly
\r
359 * one method used to authenticate that user name. If a user needs to
\r
360 * make use of different authentication methods under different
\r
361 * circumstances, then distinct user names SHOULD be employed, each of
\r
362 * which identifies exactly one authentication method.
\r
372 void pppSetAuth(enum pppAuthType authType, const char *user, const char *passwd);
\r
375 * Open a new PPP connection using the given I/O device.
\r
376 * This initializes the PPP control block but does not
\r
377 * attempt to negotiate the LCP session.
\r
378 * Return a new PPP connection descriptor on success or
\r
379 * an error code (negative) on failure.
\r
381 int pppOpen(sio_fd_t fd, void (*linkStatusCB)(void *ctx, int errCode, void *arg), void *linkStatusCtx);
\r
384 * Close a PPP connection and release the descriptor.
\r
385 * Any outstanding packets in the queues are dropped.
\r
386 * Return 0 on success, an error code on failure.
\r
388 int pppClose(int pd);
\r
391 * Indicate to the PPP process that the line has disconnected.
\r
393 void pppSigHUP(int pd);
\r
396 * Get and set parameters for the given connection.
\r
397 * Return 0 on success, an error code on failure.
\r
399 int pppIOCtl(int pd, int cmd, void *arg);
\r
402 * Return the Maximum Transmission Unit for the given PPP connection.
\r
404 u_int pppMTU(int pd);
\r
407 * Write n characters to a ppp link.
\r
408 * RETURN: >= 0 Number of characters written
\r
409 * -1 Failed to write to device
\r
411 int pppWrite(int pd, const u_char *s, int n);
\r
413 void pppMainWakeup(int pd);
\r
415 /* Configure i/f transmit parameters */
\r
416 void ppp_send_config (int, int, u32_t, int, int);
\r
417 /* Set extended transmit ACCM */
\r
418 void ppp_set_xaccm (int, ext_accm *);
\r
419 /* Configure i/f receive parameters */
\r
420 void ppp_recv_config (int, int, u32_t, int, int);
\r
421 /* Find out how long link has been idle */
\r
422 int get_idle_time (int, struct ppp_idle *);
\r
424 /* Configure VJ TCP header compression */
\r
425 int sifvjcomp (int, int, int, int);
\r
426 /* Configure i/f down (for IP) */
\r
428 /* Set mode for handling packets for proto */
\r
429 int sifnpmode (int u, int proto, enum NPmode mode);
\r
430 /* Configure i/f down (for IP) */
\r
431 int sifdown (int);
\r
432 /* Configure IP addresses for i/f */
\r
433 int sifaddr (int, u32_t, u32_t, u32_t, u32_t, u32_t);
\r
434 /* Reset i/f IP addresses */
\r
435 int cifaddr (int, u32_t, u32_t);
\r
436 /* Create default route through i/f */
\r
437 int sifdefaultroute (int, u32_t, u32_t);
\r
438 /* Delete default route through i/f */
\r
439 int cifdefaultroute (int, u32_t, u32_t);
\r
441 /* Get appropriate netmask for address */
\r
442 u32_t GetMask (u32_t);
\r
444 #endif /* PPP_SUPPORT */
\r