Version of http://mbed.org/cookbook/NetServicesTribute with setting set the same for LPC2368

Dependents:   UDPSocketExample 24LCxx_I2CApp WeatherPlatform_pachube HvZServerLib ... more

Committer:
simon
Date:
Tue Nov 23 14:15:36 2010 +0000
Revision:
0:350011bf8be7
Experimental version for testing UDP

Who changed what in which revision?

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