创建mbed

Dependencies:   EthernetInterface SDFileSystem mbed-rtos mbed

Committer:
sunyiming
Date:
Tue Mar 06 08:53:46 2018 +0000
Revision:
1:6465a3f5c58a
??OK

Who changed what in which revision?

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