hattori&ide

Dependencies:   mbed

Committer:
hattori_atsushi
Date:
Sun Dec 18 08:16:01 2022 +0000
Revision:
0:f77369cabd75
hattori

Who changed what in which revision?

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