Ethernetwebsoc

Dependencies:   C12832_lcd LM75B WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip

Committer:
GordonSin
Date:
Fri May 31 04:09:54 2013 +0000
Revision:
0:0ed2a7c7190c
31/5/2013;

Who changed what in which revision?

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