LwIP with PPP & Ethernet integration

Dependents:   NetworkingCoreLib

This is the mbed port of the LwIP stack: http://savannah.nongnu.org/projects/lwip/

It includes contributed content from NXP's port for LPCxxxx devices: http://www.lpcware.com/content/project/lightweight-ip-lwip-networking-stack

Licence

LwIP is licenced under the BSD licence:

Copyright (c) 2001-2004 Swedish Institute of Computer Science. 
All rights reserved. 
Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met: 
1. Redistributions of source code must retain the above copyright notice, 
this list of conditions and the following disclaimer. 
2. Redistributions in binary form must reproduce the above copyright notice, 
this list of conditions and the following disclaimer in the documentation 
and/or other materials provided with the distribution. 
3. The name of the author may not be used to endorse or promote products 
derived from this software without specific prior written permission. 
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
OF SUCH DAMAGE.
Committer:
donatien
Date:
Fri May 25 08:56:35 2012 +0000
Revision:
2:1a87f74b8e3b
Parent:
0:8e01dca41002
Removed compilation of EMAC driver when using PPP

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:8e01dca41002 1 /*****************************************************************************
donatien 0:8e01dca41002 2 * ppp.h - Network Point to Point Protocol header file.
donatien 0:8e01dca41002 3 *
donatien 0:8e01dca41002 4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
donatien 0:8e01dca41002 5 * portions Copyright (c) 1997 Global Election Systems Inc.
donatien 0:8e01dca41002 6 *
donatien 0:8e01dca41002 7 * The authors hereby grant permission to use, copy, modify, distribute,
donatien 0:8e01dca41002 8 * and license this software and its documentation for any purpose, provided
donatien 0:8e01dca41002 9 * that existing copyright notices are retained in all copies and that this
donatien 0:8e01dca41002 10 * notice and the following disclaimer are included verbatim in any
donatien 0:8e01dca41002 11 * distributions. No written agreement, license, or royalty fee is required
donatien 0:8e01dca41002 12 * for any of the authorized uses.
donatien 0:8e01dca41002 13 *
donatien 0:8e01dca41002 14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
donatien 0:8e01dca41002 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
donatien 0:8e01dca41002 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
donatien 0:8e01dca41002 17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
donatien 0:8e01dca41002 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
donatien 0:8e01dca41002 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
donatien 0:8e01dca41002 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
donatien 0:8e01dca41002 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
donatien 0:8e01dca41002 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
donatien 0:8e01dca41002 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
donatien 0:8e01dca41002 24 *
donatien 0:8e01dca41002 25 ******************************************************************************
donatien 0:8e01dca41002 26 * REVISION HISTORY
donatien 0:8e01dca41002 27 *
donatien 0:8e01dca41002 28 * 03-01-01 Marc Boucher <marc@mbsi.ca>
donatien 0:8e01dca41002 29 * Ported to lwIP.
donatien 0:8e01dca41002 30 * 97-11-05 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc.
donatien 0:8e01dca41002 31 * Original derived from BSD codes.
donatien 0:8e01dca41002 32 *****************************************************************************/
donatien 0:8e01dca41002 33
donatien 0:8e01dca41002 34 #ifndef PPP_H
donatien 0:8e01dca41002 35 #define PPP_H
donatien 0:8e01dca41002 36
donatien 0:8e01dca41002 37 #include "lwip/opt.h"
donatien 0:8e01dca41002 38
donatien 0:8e01dca41002 39 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
donatien 0:8e01dca41002 40
donatien 0:8e01dca41002 41 #include "lwip/def.h"
donatien 0:8e01dca41002 42 #include "lwip/sio.h"
donatien 0:8e01dca41002 43 #include "lwip/stats.h"
donatien 0:8e01dca41002 44 #include "lwip/mem.h"
donatien 0:8e01dca41002 45 #include "lwip/netif.h"
donatien 0:8e01dca41002 46 #include "lwip/sys.h"
donatien 0:8e01dca41002 47 #include "lwip/timers.h"
donatien 0:8e01dca41002 48
donatien 0:8e01dca41002 49 /** Some defines for code we skip compared to the original pppd.
donatien 0:8e01dca41002 50 * These are just here to minimise the use of the ugly "#if 0". */
donatien 0:8e01dca41002 51 #define PPP_ADDITIONAL_CALLBACKS 0
donatien 0:8e01dca41002 52
donatien 0:8e01dca41002 53 /** Some error checks to test for unsupported code */
donatien 0:8e01dca41002 54 #if CBCP_SUPPORT
donatien 0:8e01dca41002 55 #error "CBCP is not supported in lwIP PPP"
donatien 0:8e01dca41002 56 #endif
donatien 0:8e01dca41002 57 #if CCP_SUPPORT
donatien 0:8e01dca41002 58 #error "CCP is not supported in lwIP PPP"
donatien 0:8e01dca41002 59 #endif
donatien 0:8e01dca41002 60
donatien 0:8e01dca41002 61 /*
donatien 0:8e01dca41002 62 * pppd.h - PPP daemon global declarations.
donatien 0:8e01dca41002 63 *
donatien 0:8e01dca41002 64 * Copyright (c) 1989 Carnegie Mellon University.
donatien 0:8e01dca41002 65 * All rights reserved.
donatien 0:8e01dca41002 66 *
donatien 0:8e01dca41002 67 * Redistribution and use in source and binary forms are permitted
donatien 0:8e01dca41002 68 * provided that the above copyright notice and this paragraph are
donatien 0:8e01dca41002 69 * duplicated in all such forms and that any documentation,
donatien 0:8e01dca41002 70 * advertising materials, and other materials related to such
donatien 0:8e01dca41002 71 * distribution and use acknowledge that the software was developed
donatien 0:8e01dca41002 72 * by Carnegie Mellon University. The name of the
donatien 0:8e01dca41002 73 * University may not be used to endorse or promote products derived
donatien 0:8e01dca41002 74 * from this software without specific prior written permission.
donatien 0:8e01dca41002 75 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
donatien 0:8e01dca41002 76 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
donatien 0:8e01dca41002 77 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
donatien 0:8e01dca41002 78 *
donatien 0:8e01dca41002 79 */
donatien 0:8e01dca41002 80 /*
donatien 0:8e01dca41002 81 * ppp_defs.h - PPP definitions.
donatien 0:8e01dca41002 82 *
donatien 0:8e01dca41002 83 * Copyright (c) 1994 The Australian National University.
donatien 0:8e01dca41002 84 * All rights reserved.
donatien 0:8e01dca41002 85 *
donatien 0:8e01dca41002 86 * Permission to use, copy, modify, and distribute this software and its
donatien 0:8e01dca41002 87 * documentation is hereby granted, provided that the above copyright
donatien 0:8e01dca41002 88 * notice appears in all copies. This software is provided without any
donatien 0:8e01dca41002 89 * warranty, express or implied. The Australian National University
donatien 0:8e01dca41002 90 * makes no representations about the suitability of this software for
donatien 0:8e01dca41002 91 * any purpose.
donatien 0:8e01dca41002 92 *
donatien 0:8e01dca41002 93 * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
donatien 0:8e01dca41002 94 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
donatien 0:8e01dca41002 95 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
donatien 0:8e01dca41002 96 * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
donatien 0:8e01dca41002 97 * OF SUCH DAMAGE.
donatien 0:8e01dca41002 98 *
donatien 0:8e01dca41002 99 * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
donatien 0:8e01dca41002 100 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
donatien 0:8e01dca41002 101 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
donatien 0:8e01dca41002 102 * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
donatien 0:8e01dca41002 103 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
donatien 0:8e01dca41002 104 * OR MODIFICATIONS.
donatien 0:8e01dca41002 105 */
donatien 0:8e01dca41002 106
donatien 0:8e01dca41002 107 #define TIMEOUT(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t)*1000, (f), (a)); } while(0)
donatien 0:8e01dca41002 108 #define UNTIMEOUT(f, a) sys_untimeout((f), (a))
donatien 0:8e01dca41002 109
donatien 0:8e01dca41002 110
donatien 0:8e01dca41002 111 #ifndef __u_char_defined
donatien 0:8e01dca41002 112
donatien 0:8e01dca41002 113 /* Type definitions for BSD code. */
donatien 0:8e01dca41002 114 typedef unsigned long u_long;
donatien 0:8e01dca41002 115 typedef unsigned int u_int;
donatien 0:8e01dca41002 116 typedef unsigned short u_short;
donatien 0:8e01dca41002 117 typedef unsigned char u_char;
donatien 0:8e01dca41002 118
donatien 0:8e01dca41002 119 #endif
donatien 0:8e01dca41002 120
donatien 0:8e01dca41002 121 /*
donatien 0:8e01dca41002 122 * Constants and structures defined by the internet system,
donatien 0:8e01dca41002 123 * Per RFC 790, September 1981, and numerous additions.
donatien 0:8e01dca41002 124 */
donatien 0:8e01dca41002 125
donatien 0:8e01dca41002 126 /*
donatien 0:8e01dca41002 127 * The basic PPP frame.
donatien 0:8e01dca41002 128 */
donatien 0:8e01dca41002 129 #define PPP_HDRLEN 4 /* octets for standard ppp header */
donatien 0:8e01dca41002 130 #define PPP_FCSLEN 2 /* octets for FCS */
donatien 0:8e01dca41002 131
donatien 0:8e01dca41002 132
donatien 0:8e01dca41002 133 /*
donatien 0:8e01dca41002 134 * Significant octet values.
donatien 0:8e01dca41002 135 */
donatien 0:8e01dca41002 136 #define PPP_ALLSTATIONS 0xff /* All-Stations broadcast address */
donatien 0:8e01dca41002 137 #define PPP_UI 0x03 /* Unnumbered Information */
donatien 0:8e01dca41002 138 #define PPP_FLAG 0x7e /* Flag Sequence */
donatien 0:8e01dca41002 139 #define PPP_ESCAPE 0x7d /* Asynchronous Control Escape */
donatien 0:8e01dca41002 140 #define PPP_TRANS 0x20 /* Asynchronous transparency modifier */
donatien 0:8e01dca41002 141
donatien 0:8e01dca41002 142 /*
donatien 0:8e01dca41002 143 * Protocol field values.
donatien 0:8e01dca41002 144 */
donatien 0:8e01dca41002 145 #define PPP_IP 0x21 /* Internet Protocol */
donatien 0:8e01dca41002 146 #define PPP_AT 0x29 /* AppleTalk Protocol */
donatien 0:8e01dca41002 147 #define PPP_VJC_COMP 0x2d /* VJ compressed TCP */
donatien 0:8e01dca41002 148 #define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */
donatien 0:8e01dca41002 149 #define PPP_COMP 0xfd /* compressed packet */
donatien 0:8e01dca41002 150 #define PPP_IPCP 0x8021 /* IP Control Protocol */
donatien 0:8e01dca41002 151 #define PPP_ATCP 0x8029 /* AppleTalk Control Protocol */
donatien 0:8e01dca41002 152 #define PPP_CCP 0x80fd /* Compression Control Protocol */
donatien 0:8e01dca41002 153 #define PPP_LCP 0xc021 /* Link Control Protocol */
donatien 0:8e01dca41002 154 #define PPP_PAP 0xc023 /* Password Authentication Protocol */
donatien 0:8e01dca41002 155 #define PPP_LQR 0xc025 /* Link Quality Report protocol */
donatien 0:8e01dca41002 156 #define PPP_CHAP 0xc223 /* Cryptographic Handshake Auth. Protocol */
donatien 0:8e01dca41002 157 #define PPP_CBCP 0xc029 /* Callback Control Protocol */
donatien 0:8e01dca41002 158
donatien 0:8e01dca41002 159 /*
donatien 0:8e01dca41002 160 * Values for FCS calculations.
donatien 0:8e01dca41002 161 */
donatien 0:8e01dca41002 162 #define PPP_INITFCS 0xffff /* Initial FCS value */
donatien 0:8e01dca41002 163 #define PPP_GOODFCS 0xf0b8 /* Good final FCS value */
donatien 0:8e01dca41002 164 #define PPP_FCS(fcs, c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff])
donatien 0:8e01dca41002 165
donatien 0:8e01dca41002 166 /*
donatien 0:8e01dca41002 167 * Extended asyncmap - allows any character to be escaped.
donatien 0:8e01dca41002 168 */
donatien 0:8e01dca41002 169 typedef u_char ext_accm[32];
donatien 0:8e01dca41002 170
donatien 0:8e01dca41002 171 /*
donatien 0:8e01dca41002 172 * What to do with network protocol (NP) packets.
donatien 0:8e01dca41002 173 */
donatien 0:8e01dca41002 174 enum NPmode {
donatien 0:8e01dca41002 175 NPMODE_PASS, /* pass the packet through */
donatien 0:8e01dca41002 176 NPMODE_DROP, /* silently drop the packet */
donatien 0:8e01dca41002 177 NPMODE_ERROR, /* return an error */
donatien 0:8e01dca41002 178 NPMODE_QUEUE /* save it up for later. */
donatien 0:8e01dca41002 179 };
donatien 0:8e01dca41002 180
donatien 0:8e01dca41002 181 /*
donatien 0:8e01dca41002 182 * Inline versions of get/put char/short/long.
donatien 0:8e01dca41002 183 * Pointer is advanced; we assume that both arguments
donatien 0:8e01dca41002 184 * are lvalues and will already be in registers.
donatien 0:8e01dca41002 185 * cp MUST be u_char *.
donatien 0:8e01dca41002 186 */
donatien 0:8e01dca41002 187 #define GETCHAR(c, cp) { \
donatien 0:8e01dca41002 188 (c) = *(cp)++; \
donatien 0:8e01dca41002 189 }
donatien 0:8e01dca41002 190 #define PUTCHAR(c, cp) { \
donatien 0:8e01dca41002 191 *(cp)++ = (u_char) (c); \
donatien 0:8e01dca41002 192 }
donatien 0:8e01dca41002 193
donatien 0:8e01dca41002 194
donatien 0:8e01dca41002 195 #define GETSHORT(s, cp) { \
donatien 0:8e01dca41002 196 (s) = *(cp); (cp)++; (s) <<= 8; \
donatien 0:8e01dca41002 197 (s) |= *(cp); (cp)++; \
donatien 0:8e01dca41002 198 }
donatien 0:8e01dca41002 199 #define PUTSHORT(s, cp) { \
donatien 0:8e01dca41002 200 *(cp)++ = (u_char) ((s) >> 8); \
donatien 0:8e01dca41002 201 *(cp)++ = (u_char) (s & 0xff); \
donatien 0:8e01dca41002 202 }
donatien 0:8e01dca41002 203
donatien 0:8e01dca41002 204 #define GETLONG(l, cp) { \
donatien 0:8e01dca41002 205 (l) = *(cp); (cp)++; (l) <<= 8; \
donatien 0:8e01dca41002 206 (l) |= *(cp); (cp)++; (l) <<= 8; \
donatien 0:8e01dca41002 207 (l) |= *(cp); (cp)++; (l) <<= 8; \
donatien 0:8e01dca41002 208 (l) |= *(cp); (cp)++; \
donatien 0:8e01dca41002 209 }
donatien 0:8e01dca41002 210 #define PUTLONG(l, cp) { \
donatien 0:8e01dca41002 211 *(cp)++ = (u_char) ((l) >> 24); \
donatien 0:8e01dca41002 212 *(cp)++ = (u_char) ((l) >> 16); \
donatien 0:8e01dca41002 213 *(cp)++ = (u_char) ((l) >> 8); \
donatien 0:8e01dca41002 214 *(cp)++ = (u_char) (l); \
donatien 0:8e01dca41002 215 }
donatien 0:8e01dca41002 216
donatien 0:8e01dca41002 217
donatien 0:8e01dca41002 218 #define INCPTR(n, cp) ((cp) += (n))
donatien 0:8e01dca41002 219 #define DECPTR(n, cp) ((cp) -= (n))
donatien 0:8e01dca41002 220
donatien 0:8e01dca41002 221 #define BCMP(s0, s1, l) memcmp((u_char *)(s0), (u_char *)(s1), (l))
donatien 0:8e01dca41002 222 #define BCOPY(s, d, l) MEMCPY((d), (s), (l))
donatien 0:8e01dca41002 223 #define BZERO(s, n) memset(s, 0, n)
donatien 0:8e01dca41002 224
donatien 0:8e01dca41002 225 #if PPP_DEBUG
donatien 0:8e01dca41002 226 #define PRINTMSG(m, l) { m[l] = '\0'; LWIP_DEBUGF(LOG_INFO, ("Remote message: %s\n", m)); }
donatien 0:8e01dca41002 227 #else /* PPP_DEBUG */
donatien 0:8e01dca41002 228 #define PRINTMSG(m, l)
donatien 0:8e01dca41002 229 #endif /* PPP_DEBUG */
donatien 0:8e01dca41002 230
donatien 0:8e01dca41002 231 /*
donatien 0:8e01dca41002 232 * MAKEHEADER - Add PPP Header fields to a packet.
donatien 0:8e01dca41002 233 */
donatien 0:8e01dca41002 234 #define MAKEHEADER(p, t) { \
donatien 0:8e01dca41002 235 PUTCHAR(PPP_ALLSTATIONS, p); \
donatien 0:8e01dca41002 236 PUTCHAR(PPP_UI, p); \
donatien 0:8e01dca41002 237 PUTSHORT(t, p); }
donatien 0:8e01dca41002 238
donatien 0:8e01dca41002 239 /*************************
donatien 0:8e01dca41002 240 *** PUBLIC DEFINITIONS ***
donatien 0:8e01dca41002 241 *************************/
donatien 0:8e01dca41002 242
donatien 0:8e01dca41002 243 /* Error codes. */
donatien 0:8e01dca41002 244 #define PPPERR_NONE 0 /* No error. */
donatien 0:8e01dca41002 245 #define PPPERR_PARAM -1 /* Invalid parameter. */
donatien 0:8e01dca41002 246 #define PPPERR_OPEN -2 /* Unable to open PPP session. */
donatien 0:8e01dca41002 247 #define PPPERR_DEVICE -3 /* Invalid I/O device for PPP. */
donatien 0:8e01dca41002 248 #define PPPERR_ALLOC -4 /* Unable to allocate resources. */
donatien 0:8e01dca41002 249 #define PPPERR_USER -5 /* User interrupt. */
donatien 0:8e01dca41002 250 #define PPPERR_CONNECT -6 /* Connection lost. */
donatien 0:8e01dca41002 251 #define PPPERR_AUTHFAIL -7 /* Failed authentication challenge. */
donatien 0:8e01dca41002 252 #define PPPERR_PROTOCOL -8 /* Failed to meet protocol. */
donatien 0:8e01dca41002 253
donatien 0:8e01dca41002 254 /*
donatien 0:8e01dca41002 255 * PPP IOCTL commands.
donatien 0:8e01dca41002 256 */
donatien 0:8e01dca41002 257 /*
donatien 0:8e01dca41002 258 * Get the up status - 0 for down, non-zero for up. The argument must
donatien 0:8e01dca41002 259 * point to an int.
donatien 0:8e01dca41002 260 */
donatien 0:8e01dca41002 261 #define PPPCTLG_UPSTATUS 100 /* Get the up status - 0 down else up */
donatien 0:8e01dca41002 262 #define PPPCTLS_ERRCODE 101 /* Set the error code */
donatien 0:8e01dca41002 263 #define PPPCTLG_ERRCODE 102 /* Get the error code */
donatien 0:8e01dca41002 264 #define PPPCTLG_FD 103 /* Get the fd associated with the ppp */
donatien 0:8e01dca41002 265
donatien 0:8e01dca41002 266 /************************
donatien 0:8e01dca41002 267 *** PUBLIC DATA TYPES ***
donatien 0:8e01dca41002 268 ************************/
donatien 0:8e01dca41002 269
donatien 0:8e01dca41002 270 /*
donatien 0:8e01dca41002 271 * The following struct gives the addresses of procedures to call
donatien 0:8e01dca41002 272 * for a particular protocol.
donatien 0:8e01dca41002 273 */
donatien 0:8e01dca41002 274 struct protent {
donatien 0:8e01dca41002 275 u_short protocol; /* PPP protocol number */
donatien 0:8e01dca41002 276 /* Initialization procedure */
donatien 0:8e01dca41002 277 void (*init) (int unit);
donatien 0:8e01dca41002 278 /* Process a received packet */
donatien 0:8e01dca41002 279 void (*input) (int unit, u_char *pkt, int len);
donatien 0:8e01dca41002 280 /* Process a received protocol-reject */
donatien 0:8e01dca41002 281 void (*protrej) (int unit);
donatien 0:8e01dca41002 282 /* Lower layer has come up */
donatien 0:8e01dca41002 283 void (*lowerup) (int unit);
donatien 0:8e01dca41002 284 /* Lower layer has gone down */
donatien 0:8e01dca41002 285 void (*lowerdown) (int unit);
donatien 0:8e01dca41002 286 /* Open the protocol */
donatien 0:8e01dca41002 287 void (*open) (int unit);
donatien 0:8e01dca41002 288 /* Close the protocol */
donatien 0:8e01dca41002 289 void (*close) (int unit, char *reason);
donatien 0:8e01dca41002 290 #if PPP_ADDITIONAL_CALLBACKS
donatien 0:8e01dca41002 291 /* Print a packet in readable form */
donatien 0:8e01dca41002 292 int (*printpkt) (u_char *pkt, int len,
donatien 0:8e01dca41002 293 void (*printer) (void *, char *, ...),
donatien 0:8e01dca41002 294 void *arg);
donatien 0:8e01dca41002 295 /* Process a received data packet */
donatien 0:8e01dca41002 296 void (*datainput) (int unit, u_char *pkt, int len);
donatien 0:8e01dca41002 297 #endif /* PPP_ADDITIONAL_CALLBACKS */
donatien 0:8e01dca41002 298 int enabled_flag; /* 0 if protocol is disabled */
donatien 0:8e01dca41002 299 char *name; /* Text name of protocol */
donatien 0:8e01dca41002 300 #if PPP_ADDITIONAL_CALLBACKS
donatien 0:8e01dca41002 301 /* Check requested options, assign defaults */
donatien 0:8e01dca41002 302 void (*check_options) (u_long);
donatien 0:8e01dca41002 303 /* Configure interface for demand-dial */
donatien 0:8e01dca41002 304 int (*demand_conf) (int unit);
donatien 0:8e01dca41002 305 /* Say whether to bring up link for this pkt */
donatien 0:8e01dca41002 306 int (*active_pkt) (u_char *pkt, int len);
donatien 0:8e01dca41002 307 #endif /* PPP_ADDITIONAL_CALLBACKS */
donatien 0:8e01dca41002 308 };
donatien 0:8e01dca41002 309
donatien 0:8e01dca41002 310 /*
donatien 0:8e01dca41002 311 * The following structure records the time in seconds since
donatien 0:8e01dca41002 312 * the last NP packet was sent or received.
donatien 0:8e01dca41002 313 */
donatien 0:8e01dca41002 314 struct ppp_idle {
donatien 0:8e01dca41002 315 u_short xmit_idle; /* seconds since last NP packet sent */
donatien 0:8e01dca41002 316 u_short recv_idle; /* seconds since last NP packet received */
donatien 0:8e01dca41002 317 };
donatien 0:8e01dca41002 318
donatien 0:8e01dca41002 319 struct ppp_settings {
donatien 0:8e01dca41002 320
donatien 0:8e01dca41002 321 u_int disable_defaultip : 1; /* Don't use hostname for default IP addrs */
donatien 0:8e01dca41002 322 u_int auth_required : 1; /* Peer is required to authenticate */
donatien 0:8e01dca41002 323 u_int explicit_remote : 1; /* remote_name specified with remotename opt */
donatien 0:8e01dca41002 324 u_int refuse_pap : 1; /* Don't wanna auth. ourselves with PAP */
donatien 0:8e01dca41002 325 u_int refuse_chap : 1; /* Don't wanna auth. ourselves with CHAP */
donatien 0:8e01dca41002 326 u_int usehostname : 1; /* Use hostname for our_name */
donatien 0:8e01dca41002 327 u_int usepeerdns : 1; /* Ask peer for DNS adds */
donatien 0:8e01dca41002 328
donatien 0:8e01dca41002 329 u_short idle_time_limit; /* Shut down link if idle for this long */
donatien 0:8e01dca41002 330 int maxconnect; /* Maximum connect time (seconds) */
donatien 0:8e01dca41002 331
donatien 0:8e01dca41002 332 char user [MAXNAMELEN + 1]; /* Username for PAP */
donatien 0:8e01dca41002 333 char passwd [MAXSECRETLEN + 1]; /* Password for PAP, secret for CHAP */
donatien 0:8e01dca41002 334 char our_name [MAXNAMELEN + 1]; /* Our name for authentication purposes */
donatien 0:8e01dca41002 335 char remote_name[MAXNAMELEN + 1]; /* Peer's name for authentication */
donatien 0:8e01dca41002 336 };
donatien 0:8e01dca41002 337
donatien 0:8e01dca41002 338 struct ppp_addrs {
donatien 0:8e01dca41002 339 ip_addr_t our_ipaddr, his_ipaddr, netmask, dns1, dns2;
donatien 0:8e01dca41002 340 };
donatien 0:8e01dca41002 341
donatien 0:8e01dca41002 342 /*****************************
donatien 0:8e01dca41002 343 *** PUBLIC DATA STRUCTURES ***
donatien 0:8e01dca41002 344 *****************************/
donatien 0:8e01dca41002 345
donatien 0:8e01dca41002 346 /* Buffers for outgoing packets. */
donatien 0:8e01dca41002 347 extern u_char outpacket_buf[NUM_PPP][PPP_MRU+PPP_HDRLEN];
donatien 0:8e01dca41002 348
donatien 0:8e01dca41002 349 extern struct ppp_settings ppp_settings;
donatien 0:8e01dca41002 350
donatien 0:8e01dca41002 351 extern struct protent *ppp_protocols[]; /* Table of pointers to supported protocols */
donatien 0:8e01dca41002 352
donatien 0:8e01dca41002 353
donatien 0:8e01dca41002 354 /***********************
donatien 0:8e01dca41002 355 *** PUBLIC FUNCTIONS ***
donatien 0:8e01dca41002 356 ***********************/
donatien 0:8e01dca41002 357
donatien 0:8e01dca41002 358 /* Initialize the PPP subsystem. */
donatien 0:8e01dca41002 359 void pppInit(void);
donatien 0:8e01dca41002 360
donatien 0:8e01dca41002 361 /* Warning: Using PPPAUTHTYPE_ANY might have security consequences.
donatien 0:8e01dca41002 362 * RFC 1994 says:
donatien 0:8e01dca41002 363 *
donatien 0:8e01dca41002 364 * In practice, within or associated with each PPP server, there is a
donatien 0:8e01dca41002 365 * database which associates "user" names with authentication
donatien 0:8e01dca41002 366 * information ("secrets"). It is not anticipated that a particular
donatien 0:8e01dca41002 367 * named user would be authenticated by multiple methods. This would
donatien 0:8e01dca41002 368 * make the user vulnerable to attacks which negotiate the least secure
donatien 0:8e01dca41002 369 * method from among a set (such as PAP rather than CHAP). If the same
donatien 0:8e01dca41002 370 * secret was used, PAP would reveal the secret to be used later with
donatien 0:8e01dca41002 371 * CHAP.
donatien 0:8e01dca41002 372 *
donatien 0:8e01dca41002 373 * Instead, for each user name there should be an indication of exactly
donatien 0:8e01dca41002 374 * one method used to authenticate that user name. If a user needs to
donatien 0:8e01dca41002 375 * make use of different authentication methods under different
donatien 0:8e01dca41002 376 * circumstances, then distinct user names SHOULD be employed, each of
donatien 0:8e01dca41002 377 * which identifies exactly one authentication method.
donatien 0:8e01dca41002 378 *
donatien 0:8e01dca41002 379 */
donatien 0:8e01dca41002 380 enum pppAuthType {
donatien 0:8e01dca41002 381 PPPAUTHTYPE_NONE,
donatien 0:8e01dca41002 382 PPPAUTHTYPE_ANY,
donatien 0:8e01dca41002 383 PPPAUTHTYPE_PAP,
donatien 0:8e01dca41002 384 PPPAUTHTYPE_CHAP
donatien 0:8e01dca41002 385 };
donatien 0:8e01dca41002 386
donatien 0:8e01dca41002 387 void pppSetAuth(enum pppAuthType authType, const char *user, const char *passwd);
donatien 0:8e01dca41002 388
donatien 0:8e01dca41002 389 /*
donatien 0:8e01dca41002 390 * Open a new PPP connection using the given serial I/O device.
donatien 0:8e01dca41002 391 * This initializes the PPP control block but does not
donatien 0:8e01dca41002 392 * attempt to negotiate the LCP session.
donatien 0:8e01dca41002 393 * Return a new PPP connection descriptor on success or
donatien 0:8e01dca41002 394 * an error code (negative) on failure.
donatien 0:8e01dca41002 395 */
donatien 0:8e01dca41002 396 int pppOverSerialOpen(sio_fd_t fd, void (*linkStatusCB)(void *ctx, int errCode, void *arg), void *linkStatusCtx);
donatien 0:8e01dca41002 397
donatien 0:8e01dca41002 398 /*
donatien 0:8e01dca41002 399 * Open a new PPP Over Ethernet (PPPOE) connection.
donatien 0:8e01dca41002 400 */
donatien 0:8e01dca41002 401 int pppOverEthernetOpen(struct netif *ethif, const char *service_name, const char *concentrator_name, void (*linkStatusCB)(void *ctx, int errCode, void *arg), void *linkStatusCtx);
donatien 0:8e01dca41002 402
donatien 0:8e01dca41002 403 /* for source code compatibility */
donatien 0:8e01dca41002 404 #define pppOpen(fd,cb,ls) pppOverSerialOpen(fd,cb,ls)
donatien 0:8e01dca41002 405
donatien 0:8e01dca41002 406 /*
donatien 0:8e01dca41002 407 * Close a PPP connection and release the descriptor.
donatien 0:8e01dca41002 408 * Any outstanding packets in the queues are dropped.
donatien 0:8e01dca41002 409 * Return 0 on success, an error code on failure.
donatien 0:8e01dca41002 410 */
donatien 0:8e01dca41002 411 int pppClose(int pd);
donatien 0:8e01dca41002 412
donatien 0:8e01dca41002 413 /*
donatien 0:8e01dca41002 414 * Indicate to the PPP process that the line has disconnected.
donatien 0:8e01dca41002 415 */
donatien 0:8e01dca41002 416 void pppSigHUP(int pd);
donatien 0:8e01dca41002 417
donatien 0:8e01dca41002 418 /*
donatien 0:8e01dca41002 419 * Get and set parameters for the given connection.
donatien 0:8e01dca41002 420 * Return 0 on success, an error code on failure.
donatien 0:8e01dca41002 421 */
donatien 0:8e01dca41002 422 int pppIOCtl(int pd, int cmd, void *arg);
donatien 0:8e01dca41002 423
donatien 0:8e01dca41002 424 /*
donatien 0:8e01dca41002 425 * Return the Maximum Transmission Unit for the given PPP connection.
donatien 0:8e01dca41002 426 */
donatien 0:8e01dca41002 427 u_short pppMTU(int pd);
donatien 0:8e01dca41002 428
donatien 0:8e01dca41002 429 /*
donatien 0:8e01dca41002 430 * Write n characters to a ppp link.
donatien 0:8e01dca41002 431 * RETURN: >= 0 Number of characters written, -1 Failed to write to device.
donatien 0:8e01dca41002 432 */
donatien 0:8e01dca41002 433 int pppWrite(int pd, const u_char *s, int n);
donatien 0:8e01dca41002 434
donatien 0:8e01dca41002 435 void pppInProcOverEthernet(int pd, struct pbuf *pb);
donatien 0:8e01dca41002 436
donatien 0:8e01dca41002 437 struct pbuf *pppSingleBuf(struct pbuf *p);
donatien 0:8e01dca41002 438
donatien 0:8e01dca41002 439 void pppLinkTerminated(int pd);
donatien 0:8e01dca41002 440
donatien 0:8e01dca41002 441 void pppLinkDown(int pd);
donatien 0:8e01dca41002 442
donatien 0:8e01dca41002 443 void pppos_input(int pd, u_char* data, int len);
donatien 0:8e01dca41002 444
donatien 0:8e01dca41002 445 /* Configure i/f transmit parameters */
donatien 0:8e01dca41002 446 void ppp_send_config (int, u16_t, u32_t, int, int);
donatien 0:8e01dca41002 447 /* Set extended transmit ACCM */
donatien 0:8e01dca41002 448 void ppp_set_xaccm (int, ext_accm *);
donatien 0:8e01dca41002 449 /* Configure i/f receive parameters */
donatien 0:8e01dca41002 450 void ppp_recv_config (int, int, u32_t, int, int);
donatien 0:8e01dca41002 451 /* Find out how long link has been idle */
donatien 0:8e01dca41002 452 int get_idle_time (int, struct ppp_idle *);
donatien 0:8e01dca41002 453
donatien 0:8e01dca41002 454 /* Configure VJ TCP header compression */
donatien 0:8e01dca41002 455 int sifvjcomp (int, int, u8_t, u8_t);
donatien 0:8e01dca41002 456 /* Configure i/f down (for IP) */
donatien 0:8e01dca41002 457 int sifup (int);
donatien 0:8e01dca41002 458 /* Set mode for handling packets for proto */
donatien 0:8e01dca41002 459 int sifnpmode (int u, int proto, enum NPmode mode);
donatien 0:8e01dca41002 460 /* Configure i/f down (for IP) */
donatien 0:8e01dca41002 461 int sifdown (int);
donatien 0:8e01dca41002 462 /* Configure IP addresses for i/f */
donatien 0:8e01dca41002 463 int sifaddr (int, u32_t, u32_t, u32_t, u32_t, u32_t);
donatien 0:8e01dca41002 464 /* Reset i/f IP addresses */
donatien 0:8e01dca41002 465 int cifaddr (int, u32_t, u32_t);
donatien 0:8e01dca41002 466 /* Create default route through i/f */
donatien 0:8e01dca41002 467 int sifdefaultroute (int, u32_t, u32_t);
donatien 0:8e01dca41002 468 /* Delete default route through i/f */
donatien 0:8e01dca41002 469 int cifdefaultroute (int, u32_t, u32_t);
donatien 0:8e01dca41002 470
donatien 0:8e01dca41002 471 /* Get appropriate netmask for address */
donatien 0:8e01dca41002 472 u32_t GetMask (u32_t);
donatien 0:8e01dca41002 473
donatien 0:8e01dca41002 474 #if LWIP_NETIF_STATUS_CALLBACK
donatien 0:8e01dca41002 475 void ppp_set_netif_statuscallback(int pd, netif_status_callback_fn status_callback);
donatien 0:8e01dca41002 476 #endif /* LWIP_NETIF_STATUS_CALLBACK */
donatien 0:8e01dca41002 477 #if LWIP_NETIF_LINK_CALLBACK
donatien 0:8e01dca41002 478 void ppp_set_netif_linkcallback(int pd, netif_status_callback_fn link_callback);
donatien 0:8e01dca41002 479 #endif /* LWIP_NETIF_LINK_CALLBACK */
donatien 0:8e01dca41002 480
donatien 0:8e01dca41002 481 #endif /* PPP_SUPPORT */
donatien 0:8e01dca41002 482
donatien 0:8e01dca41002 483 #endif /* PPP_H */