Example self-announcing webserver which controls a servo through a smallHTML userinterface.

Dependencies:   mbed

Committer:
dirkx
Date:
Sat Aug 14 15:56:01 2010 +0000
Revision:
0:a259777c45a3

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dirkx 0:a259777c45a3 1 /*****************************************************************************
dirkx 0:a259777c45a3 2 * ppp.c - Network Point to Point Protocol program file.
dirkx 0:a259777c45a3 3 *
dirkx 0:a259777c45a3 4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
dirkx 0:a259777c45a3 5 * portions Copyright (c) 1997 by Global Election Systems Inc.
dirkx 0:a259777c45a3 6 *
dirkx 0:a259777c45a3 7 * The authors hereby grant permission to use, copy, modify, distribute,
dirkx 0:a259777c45a3 8 * and license this software and its documentation for any purpose, provided
dirkx 0:a259777c45a3 9 * that existing copyright notices are retained in all copies and that this
dirkx 0:a259777c45a3 10 * notice and the following disclaimer are included verbatim in any
dirkx 0:a259777c45a3 11 * distributions. No written agreement, license, or royalty fee is required
dirkx 0:a259777c45a3 12 * for any of the authorized uses.
dirkx 0:a259777c45a3 13 *
dirkx 0:a259777c45a3 14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
dirkx 0:a259777c45a3 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
dirkx 0:a259777c45a3 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
dirkx 0:a259777c45a3 17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
dirkx 0:a259777c45a3 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
dirkx 0:a259777c45a3 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
dirkx 0:a259777c45a3 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
dirkx 0:a259777c45a3 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
dirkx 0:a259777c45a3 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
dirkx 0:a259777c45a3 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dirkx 0:a259777c45a3 24 *
dirkx 0:a259777c45a3 25 ******************************************************************************
dirkx 0:a259777c45a3 26 * REVISION HISTORY
dirkx 0:a259777c45a3 27 *
dirkx 0:a259777c45a3 28 * 03-01-01 Marc Boucher <marc@mbsi.ca>
dirkx 0:a259777c45a3 29 * Ported to lwIP.
dirkx 0:a259777c45a3 30 * 97-11-05 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
dirkx 0:a259777c45a3 31 * Original.
dirkx 0:a259777c45a3 32 *****************************************************************************/
dirkx 0:a259777c45a3 33
dirkx 0:a259777c45a3 34 /*
dirkx 0:a259777c45a3 35 * ppp_defs.h - PPP definitions.
dirkx 0:a259777c45a3 36 *
dirkx 0:a259777c45a3 37 * if_pppvar.h - private structures and declarations for PPP.
dirkx 0:a259777c45a3 38 *
dirkx 0:a259777c45a3 39 * Copyright (c) 1994 The Australian National University.
dirkx 0:a259777c45a3 40 * All rights reserved.
dirkx 0:a259777c45a3 41 *
dirkx 0:a259777c45a3 42 * Permission to use, copy, modify, and distribute this software and its
dirkx 0:a259777c45a3 43 * documentation is hereby granted, provided that the above copyright
dirkx 0:a259777c45a3 44 * notice appears in all copies. This software is provided without any
dirkx 0:a259777c45a3 45 * warranty, express or implied. The Australian National University
dirkx 0:a259777c45a3 46 * makes no representations about the suitability of this software for
dirkx 0:a259777c45a3 47 * any purpose.
dirkx 0:a259777c45a3 48 *
dirkx 0:a259777c45a3 49 * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
dirkx 0:a259777c45a3 50 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
dirkx 0:a259777c45a3 51 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
dirkx 0:a259777c45a3 52 * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
dirkx 0:a259777c45a3 53 * OF SUCH DAMAGE.
dirkx 0:a259777c45a3 54 *
dirkx 0:a259777c45a3 55 * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
dirkx 0:a259777c45a3 56 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
dirkx 0:a259777c45a3 57 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
dirkx 0:a259777c45a3 58 * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
dirkx 0:a259777c45a3 59 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
dirkx 0:a259777c45a3 60 * OR MODIFICATIONS.
dirkx 0:a259777c45a3 61 */
dirkx 0:a259777c45a3 62
dirkx 0:a259777c45a3 63 /*
dirkx 0:a259777c45a3 64 * if_ppp.h - Point-to-Point Protocol definitions.
dirkx 0:a259777c45a3 65 *
dirkx 0:a259777c45a3 66 * Copyright (c) 1989 Carnegie Mellon University.
dirkx 0:a259777c45a3 67 * All rights reserved.
dirkx 0:a259777c45a3 68 *
dirkx 0:a259777c45a3 69 * Redistribution and use in source and binary forms are permitted
dirkx 0:a259777c45a3 70 * provided that the above copyright notice and this paragraph are
dirkx 0:a259777c45a3 71 * duplicated in all such forms and that any documentation,
dirkx 0:a259777c45a3 72 * advertising materials, and other materials related to such
dirkx 0:a259777c45a3 73 * distribution and use acknowledge that the software was developed
dirkx 0:a259777c45a3 74 * by Carnegie Mellon University. The name of the
dirkx 0:a259777c45a3 75 * University may not be used to endorse or promote products derived
dirkx 0:a259777c45a3 76 * from this software without specific prior written permission.
dirkx 0:a259777c45a3 77 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
dirkx 0:a259777c45a3 78 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
dirkx 0:a259777c45a3 79 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
dirkx 0:a259777c45a3 80 */
dirkx 0:a259777c45a3 81
dirkx 0:a259777c45a3 82 #include "lwip/opt.h"
dirkx 0:a259777c45a3 83
dirkx 0:a259777c45a3 84 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
dirkx 0:a259777c45a3 85
dirkx 0:a259777c45a3 86 #include "lwip/ip.h" /* for ip_input() */
dirkx 0:a259777c45a3 87
dirkx 0:a259777c45a3 88 #include "ppp.h"
dirkx 0:a259777c45a3 89 #include "pppdebug.h"
dirkx 0:a259777c45a3 90
dirkx 0:a259777c45a3 91 #include "randm.h"
dirkx 0:a259777c45a3 92 #include "fsm.h"
dirkx 0:a259777c45a3 93 #if PAP_SUPPORT
dirkx 0:a259777c45a3 94 #include "pap.h"
dirkx 0:a259777c45a3 95 #endif /* PAP_SUPPORT */
dirkx 0:a259777c45a3 96 #if CHAP_SUPPORT
dirkx 0:a259777c45a3 97 #include "chap.h"
dirkx 0:a259777c45a3 98 #endif /* CHAP_SUPPORT */
dirkx 0:a259777c45a3 99 #include "ipcp.h"
dirkx 0:a259777c45a3 100 #include "lcp.h"
dirkx 0:a259777c45a3 101 #include "magic.h"
dirkx 0:a259777c45a3 102 #include "auth.h"
dirkx 0:a259777c45a3 103 #if VJ_SUPPORT
dirkx 0:a259777c45a3 104 #include "vj.h"
dirkx 0:a259777c45a3 105 #endif /* VJ_SUPPORT */
dirkx 0:a259777c45a3 106 #if PPPOE_SUPPORT
dirkx 0:a259777c45a3 107 #include "netif/ppp_oe.h"
dirkx 0:a259777c45a3 108 #endif /* PPPOE_SUPPORT */
dirkx 0:a259777c45a3 109
dirkx 0:a259777c45a3 110 #include "lwip/tcpip.h"
dirkx 0:a259777c45a3 111 #include "lwip/api.h"
dirkx 0:a259777c45a3 112 #include "lwip/snmp.h"
dirkx 0:a259777c45a3 113
dirkx 0:a259777c45a3 114 #include <string.h>
dirkx 0:a259777c45a3 115
dirkx 0:a259777c45a3 116 /*************************/
dirkx 0:a259777c45a3 117 /*** LOCAL DEFINITIONS ***/
dirkx 0:a259777c45a3 118 /*************************/
dirkx 0:a259777c45a3 119
dirkx 0:a259777c45a3 120 /** PPP_INPROC_MULTITHREADED==1 call pppInput using tcpip_callback().
dirkx 0:a259777c45a3 121 * Set this to 0 if pppInProc is called inside tcpip_thread or with NO_SYS==1.
dirkx 0:a259777c45a3 122 * Default is 1 for NO_SYS==0 (multithreaded) and 0 for NO_SYS==1 (single-threaded).
dirkx 0:a259777c45a3 123 */
dirkx 0:a259777c45a3 124 #ifndef PPP_INPROC_MULTITHREADED
dirkx 0:a259777c45a3 125 #define PPP_INPROC_MULTITHREADED (NO_SYS==0)
dirkx 0:a259777c45a3 126 #endif
dirkx 0:a259777c45a3 127
dirkx 0:a259777c45a3 128 /** PPP_INPROC_OWNTHREAD==1: start a dedicated RX thread per PPP session.
dirkx 0:a259777c45a3 129 * Default is 0: call pppos_input() for received raw characters, charcater
dirkx 0:a259777c45a3 130 * reception is up to the port */
dirkx 0:a259777c45a3 131 #ifndef PPP_INPROC_OWNTHREAD
dirkx 0:a259777c45a3 132 #define PPP_INPROC_OWNTHREAD PPP_INPROC_MULTITHREADED
dirkx 0:a259777c45a3 133 #endif
dirkx 0:a259777c45a3 134
dirkx 0:a259777c45a3 135 #if PPP_INPROC_OWNTHREAD && !PPP_INPROC_MULTITHREADED
dirkx 0:a259777c45a3 136 #error "PPP_INPROC_OWNTHREAD needs PPP_INPROC_MULTITHREADED==1"
dirkx 0:a259777c45a3 137 #endif
dirkx 0:a259777c45a3 138
dirkx 0:a259777c45a3 139 /*
dirkx 0:a259777c45a3 140 * The basic PPP frame.
dirkx 0:a259777c45a3 141 */
dirkx 0:a259777c45a3 142 #define PPP_ADDRESS(p) (((u_char *)(p))[0])
dirkx 0:a259777c45a3 143 #define PPP_CONTROL(p) (((u_char *)(p))[1])
dirkx 0:a259777c45a3 144 #define PPP_PROTOCOL(p) ((((u_char *)(p))[2] << 8) + ((u_char *)(p))[3])
dirkx 0:a259777c45a3 145
dirkx 0:a259777c45a3 146 /* PPP packet parser states. Current state indicates operation yet to be
dirkx 0:a259777c45a3 147 * completed. */
dirkx 0:a259777c45a3 148 typedef enum {
dirkx 0:a259777c45a3 149 PDIDLE = 0, /* Idle state - waiting. */
dirkx 0:a259777c45a3 150 PDSTART, /* Process start flag. */
dirkx 0:a259777c45a3 151 PDADDRESS, /* Process address field. */
dirkx 0:a259777c45a3 152 PDCONTROL, /* Process control field. */
dirkx 0:a259777c45a3 153 PDPROTOCOL1, /* Process protocol field 1. */
dirkx 0:a259777c45a3 154 PDPROTOCOL2, /* Process protocol field 2. */
dirkx 0:a259777c45a3 155 PDDATA /* Process data byte. */
dirkx 0:a259777c45a3 156 } PPPDevStates;
dirkx 0:a259777c45a3 157
dirkx 0:a259777c45a3 158 #define ESCAPE_P(accm, c) ((accm)[(c) >> 3] & pppACCMMask[c & 0x07])
dirkx 0:a259777c45a3 159
dirkx 0:a259777c45a3 160 /************************/
dirkx 0:a259777c45a3 161 /*** LOCAL DATA TYPES ***/
dirkx 0:a259777c45a3 162 /************************/
dirkx 0:a259777c45a3 163
dirkx 0:a259777c45a3 164 /** RX buffer size: this may be configured smaller! */
dirkx 0:a259777c45a3 165 #ifndef PPPOS_RX_BUFSIZE
dirkx 0:a259777c45a3 166 #define PPPOS_RX_BUFSIZE (PPP_MRU + PPP_HDRLEN)
dirkx 0:a259777c45a3 167 #endif
dirkx 0:a259777c45a3 168
dirkx 0:a259777c45a3 169 typedef struct PPPControlRx_s {
dirkx 0:a259777c45a3 170 /** unit number / ppp descriptor */
dirkx 0:a259777c45a3 171 int pd;
dirkx 0:a259777c45a3 172 /** the rx file descriptor */
dirkx 0:a259777c45a3 173 sio_fd_t fd;
dirkx 0:a259777c45a3 174 /** receive buffer - encoded data is stored here */
dirkx 0:a259777c45a3 175 u_char rxbuf[PPPOS_RX_BUFSIZE];
dirkx 0:a259777c45a3 176
dirkx 0:a259777c45a3 177 /* The input packet. */
dirkx 0:a259777c45a3 178 struct pbuf *inHead, *inTail;
dirkx 0:a259777c45a3 179
dirkx 0:a259777c45a3 180 #if PPPOS_SUPPORT
dirkx 0:a259777c45a3 181 u16_t inProtocol; /* The input protocol code. */
dirkx 0:a259777c45a3 182 u16_t inFCS; /* Input Frame Check Sequence value. */
dirkx 0:a259777c45a3 183 #endif /* PPPOS_SUPPORT */
dirkx 0:a259777c45a3 184 PPPDevStates inState; /* The input process state. */
dirkx 0:a259777c45a3 185 char inEscaped; /* Escape next character. */
dirkx 0:a259777c45a3 186 ext_accm inACCM; /* Async-Ctl-Char-Map for input. */
dirkx 0:a259777c45a3 187 } PPPControlRx;
dirkx 0:a259777c45a3 188
dirkx 0:a259777c45a3 189 /*
dirkx 0:a259777c45a3 190 * PPP interface control block.
dirkx 0:a259777c45a3 191 */
dirkx 0:a259777c45a3 192 typedef struct PPPControl_s {
dirkx 0:a259777c45a3 193 PPPControlRx rx;
dirkx 0:a259777c45a3 194 char openFlag; /* True when in use. */
dirkx 0:a259777c45a3 195 #if PPPOE_SUPPORT
dirkx 0:a259777c45a3 196 struct netif *ethif;
dirkx 0:a259777c45a3 197 struct pppoe_softc *pppoe_sc;
dirkx 0:a259777c45a3 198 #endif /* PPPOE_SUPPORT */
dirkx 0:a259777c45a3 199 int if_up; /* True when the interface is up. */
dirkx 0:a259777c45a3 200 int errCode; /* Code indicating why interface is down. */
dirkx 0:a259777c45a3 201 #if PPPOS_SUPPORT
dirkx 0:a259777c45a3 202 sio_fd_t fd; /* File device ID of port. */
dirkx 0:a259777c45a3 203 #endif /* PPPOS_SUPPORT */
dirkx 0:a259777c45a3 204 u16_t mtu; /* Peer's mru */
dirkx 0:a259777c45a3 205 int pcomp; /* Does peer accept protocol compression? */
dirkx 0:a259777c45a3 206 int accomp; /* Does peer accept addr/ctl compression? */
dirkx 0:a259777c45a3 207 u_long lastXMit; /* Time of last transmission. */
dirkx 0:a259777c45a3 208 ext_accm outACCM; /* Async-Ctl-Char-Map for output. */
dirkx 0:a259777c45a3 209 #if PPPOS_SUPPORT && VJ_SUPPORT
dirkx 0:a259777c45a3 210 int vjEnabled; /* Flag indicating VJ compression enabled. */
dirkx 0:a259777c45a3 211 struct vjcompress vjComp; /* Van Jacobson compression header. */
dirkx 0:a259777c45a3 212 #endif /* PPPOS_SUPPORT && VJ_SUPPORT */
dirkx 0:a259777c45a3 213
dirkx 0:a259777c45a3 214 struct netif netif;
dirkx 0:a259777c45a3 215
dirkx 0:a259777c45a3 216 struct ppp_addrs addrs;
dirkx 0:a259777c45a3 217
dirkx 0:a259777c45a3 218 void (*linkStatusCB)(void *ctx, int errCode, void *arg);
dirkx 0:a259777c45a3 219 void *linkStatusCtx;
dirkx 0:a259777c45a3 220
dirkx 0:a259777c45a3 221 } PPPControl;
dirkx 0:a259777c45a3 222
dirkx 0:a259777c45a3 223
dirkx 0:a259777c45a3 224 /*
dirkx 0:a259777c45a3 225 * Ioctl definitions.
dirkx 0:a259777c45a3 226 */
dirkx 0:a259777c45a3 227
dirkx 0:a259777c45a3 228 struct npioctl {
dirkx 0:a259777c45a3 229 int protocol; /* PPP procotol, e.g. PPP_IP */
dirkx 0:a259777c45a3 230 enum NPmode mode;
dirkx 0:a259777c45a3 231 };
dirkx 0:a259777c45a3 232
dirkx 0:a259777c45a3 233
dirkx 0:a259777c45a3 234
dirkx 0:a259777c45a3 235 /***********************************/
dirkx 0:a259777c45a3 236 /*** LOCAL FUNCTION DECLARATIONS ***/
dirkx 0:a259777c45a3 237 /***********************************/
dirkx 0:a259777c45a3 238 #if PPPOS_SUPPORT
dirkx 0:a259777c45a3 239 #if PPP_INPROC_OWNTHREAD
dirkx 0:a259777c45a3 240 static void pppInputThread(void *arg);
dirkx 0:a259777c45a3 241 #endif /* PPP_INPROC_OWNTHREAD */
dirkx 0:a259777c45a3 242 static void pppDrop(PPPControlRx *pcrx);
dirkx 0:a259777c45a3 243 static void pppInProc(PPPControlRx *pcrx, u_char *s, int l);
dirkx 0:a259777c45a3 244 #endif /* PPPOS_SUPPORT */
dirkx 0:a259777c45a3 245
dirkx 0:a259777c45a3 246
dirkx 0:a259777c45a3 247 /******************************/
dirkx 0:a259777c45a3 248 /*** PUBLIC DATA STRUCTURES ***/
dirkx 0:a259777c45a3 249 /******************************/
dirkx 0:a259777c45a3 250 u_long subnetMask;
dirkx 0:a259777c45a3 251
dirkx 0:a259777c45a3 252 static PPPControl pppControl[NUM_PPP] MEM_POSITION; /* The PPP interface control blocks. */
dirkx 0:a259777c45a3 253
dirkx 0:a259777c45a3 254 /*
dirkx 0:a259777c45a3 255 * PPP Data Link Layer "protocol" table.
dirkx 0:a259777c45a3 256 * One entry per supported protocol.
dirkx 0:a259777c45a3 257 * The last entry must be NULL.
dirkx 0:a259777c45a3 258 */
dirkx 0:a259777c45a3 259 struct protent *ppp_protocols[] = {
dirkx 0:a259777c45a3 260 &lcp_protent,
dirkx 0:a259777c45a3 261 #if PAP_SUPPORT
dirkx 0:a259777c45a3 262 &pap_protent,
dirkx 0:a259777c45a3 263 #endif /* PAP_SUPPORT */
dirkx 0:a259777c45a3 264 #if CHAP_SUPPORT
dirkx 0:a259777c45a3 265 &chap_protent,
dirkx 0:a259777c45a3 266 #endif /* CHAP_SUPPORT */
dirkx 0:a259777c45a3 267 #if CBCP_SUPPORT
dirkx 0:a259777c45a3 268 &cbcp_protent,
dirkx 0:a259777c45a3 269 #endif /* CBCP_SUPPORT */
dirkx 0:a259777c45a3 270 &ipcp_protent,
dirkx 0:a259777c45a3 271 #if CCP_SUPPORT
dirkx 0:a259777c45a3 272 &ccp_protent,
dirkx 0:a259777c45a3 273 #endif /* CCP_SUPPORT */
dirkx 0:a259777c45a3 274 NULL
dirkx 0:a259777c45a3 275 };
dirkx 0:a259777c45a3 276
dirkx 0:a259777c45a3 277
dirkx 0:a259777c45a3 278 /*
dirkx 0:a259777c45a3 279 * Buffers for outgoing packets. This must be accessed only from the appropriate
dirkx 0:a259777c45a3 280 * PPP task so that it doesn't need to be protected to avoid collisions.
dirkx 0:a259777c45a3 281 */
dirkx 0:a259777c45a3 282 u_char outpacket_buf[NUM_PPP][PPP_MRU+PPP_HDRLEN] MEM_POSITION;
dirkx 0:a259777c45a3 283
dirkx 0:a259777c45a3 284
dirkx 0:a259777c45a3 285 /*****************************/
dirkx 0:a259777c45a3 286 /*** LOCAL DATA STRUCTURES ***/
dirkx 0:a259777c45a3 287 /*****************************/
dirkx 0:a259777c45a3 288
dirkx 0:a259777c45a3 289 #if PPPOS_SUPPORT
dirkx 0:a259777c45a3 290 /*
dirkx 0:a259777c45a3 291 * FCS lookup table as calculated by genfcstab.
dirkx 0:a259777c45a3 292 * @todo: smaller, slower implementation for lower memory footprint?
dirkx 0:a259777c45a3 293 */
dirkx 0:a259777c45a3 294 static const u_short fcstab[256] = {
dirkx 0:a259777c45a3 295 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
dirkx 0:a259777c45a3 296 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
dirkx 0:a259777c45a3 297 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
dirkx 0:a259777c45a3 298 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
dirkx 0:a259777c45a3 299 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
dirkx 0:a259777c45a3 300 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
dirkx 0:a259777c45a3 301 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
dirkx 0:a259777c45a3 302 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
dirkx 0:a259777c45a3 303 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
dirkx 0:a259777c45a3 304 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
dirkx 0:a259777c45a3 305 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
dirkx 0:a259777c45a3 306 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
dirkx 0:a259777c45a3 307 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
dirkx 0:a259777c45a3 308 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
dirkx 0:a259777c45a3 309 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
dirkx 0:a259777c45a3 310 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
dirkx 0:a259777c45a3 311 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
dirkx 0:a259777c45a3 312 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
dirkx 0:a259777c45a3 313 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
dirkx 0:a259777c45a3 314 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
dirkx 0:a259777c45a3 315 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
dirkx 0:a259777c45a3 316 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
dirkx 0:a259777c45a3 317 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
dirkx 0:a259777c45a3 318 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
dirkx 0:a259777c45a3 319 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
dirkx 0:a259777c45a3 320 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
dirkx 0:a259777c45a3 321 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
dirkx 0:a259777c45a3 322 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
dirkx 0:a259777c45a3 323 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
dirkx 0:a259777c45a3 324 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
dirkx 0:a259777c45a3 325 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
dirkx 0:a259777c45a3 326 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
dirkx 0:a259777c45a3 327 };
dirkx 0:a259777c45a3 328
dirkx 0:a259777c45a3 329 /* PPP's Asynchronous-Control-Character-Map. The mask array is used
dirkx 0:a259777c45a3 330 * to select the specific bit for a character. */
dirkx 0:a259777c45a3 331 static u_char pppACCMMask[] = {
dirkx 0:a259777c45a3 332 0x01,
dirkx 0:a259777c45a3 333 0x02,
dirkx 0:a259777c45a3 334 0x04,
dirkx 0:a259777c45a3 335 0x08,
dirkx 0:a259777c45a3 336 0x10,
dirkx 0:a259777c45a3 337 0x20,
dirkx 0:a259777c45a3 338 0x40,
dirkx 0:a259777c45a3 339 0x80
dirkx 0:a259777c45a3 340 };
dirkx 0:a259777c45a3 341
dirkx 0:a259777c45a3 342 /** Wake up the task blocked in reading from serial line (if any) */
dirkx 0:a259777c45a3 343 static void
dirkx 0:a259777c45a3 344 pppRecvWakeup(int pd)
dirkx 0:a259777c45a3 345 {
dirkx 0:a259777c45a3 346 PPPDEBUG(LOG_DEBUG, ("pppRecvWakeup: unit %d\n", pd));
dirkx 0:a259777c45a3 347 sio_read_abort(pppControl[pd].fd);
dirkx 0:a259777c45a3 348 }
dirkx 0:a259777c45a3 349 #endif /* PPPOS_SUPPORT */
dirkx 0:a259777c45a3 350
dirkx 0:a259777c45a3 351 void
dirkx 0:a259777c45a3 352 pppLinkTerminated(int pd)
dirkx 0:a259777c45a3 353 {
dirkx 0:a259777c45a3 354 PPPDEBUG(LOG_DEBUG, ("pppLinkTerminated: unit %d\n", pd));
dirkx 0:a259777c45a3 355
dirkx 0:a259777c45a3 356 #if PPPOE_SUPPORT
dirkx 0:a259777c45a3 357 if (pppControl[pd].ethif) {
dirkx 0:a259777c45a3 358 pppoe_disconnect(pppControl[pd].pppoe_sc);
dirkx 0:a259777c45a3 359 } else
dirkx 0:a259777c45a3 360 #endif /* PPPOE_SUPPORT */
dirkx 0:a259777c45a3 361 {
dirkx 0:a259777c45a3 362 #if PPPOS_SUPPORT
dirkx 0:a259777c45a3 363 PPPControl* pc;
dirkx 0:a259777c45a3 364 pppRecvWakeup(pd);
dirkx 0:a259777c45a3 365 pc = &pppControl[pd];
dirkx 0:a259777c45a3 366 pppDrop(&pc->rx); /* bug fix #17726 */
dirkx 0:a259777c45a3 367
dirkx 0:a259777c45a3 368 PPPDEBUG(LOG_DEBUG, ("pppLinkTerminated: unit %d: linkStatusCB=%p errCode=%d\n", pd, pc->linkStatusCB, pc->errCode));
dirkx 0:a259777c45a3 369 if (pc->linkStatusCB) {
dirkx 0:a259777c45a3 370 pc->linkStatusCB(pc->linkStatusCtx, pc->errCode ? pc->errCode : PPPERR_PROTOCOL, NULL);
dirkx 0:a259777c45a3 371 }
dirkx 0:a259777c45a3 372
dirkx 0:a259777c45a3 373 pc->openFlag = 0;/**/
dirkx 0:a259777c45a3 374 #endif /* PPPOS_SUPPORT */
dirkx 0:a259777c45a3 375 }
dirkx 0:a259777c45a3 376 PPPDEBUG(LOG_DEBUG, ("pppLinkTerminated: finished.\n"));
dirkx 0:a259777c45a3 377 }
dirkx 0:a259777c45a3 378
dirkx 0:a259777c45a3 379 void
dirkx 0:a259777c45a3 380 pppLinkDown(int pd)
dirkx 0:a259777c45a3 381 {
dirkx 0:a259777c45a3 382 PPPDEBUG(LOG_DEBUG, ("pppLinkDown: unit %d\n", pd));
dirkx 0:a259777c45a3 383
dirkx 0:a259777c45a3 384 #if PPPOE_SUPPORT
dirkx 0:a259777c45a3 385 if (pppControl[pd].ethif) {
dirkx 0:a259777c45a3 386 pppoe_disconnect(pppControl[pd].pppoe_sc);
dirkx 0:a259777c45a3 387 } else
dirkx 0:a259777c45a3 388 #endif /* PPPOE_SUPPORT */
dirkx 0:a259777c45a3 389 {
dirkx 0:a259777c45a3 390 #if PPPOS_SUPPORT
dirkx 0:a259777c45a3 391 pppRecvWakeup(pd);
dirkx 0:a259777c45a3 392 #endif /* PPPOS_SUPPORT */
dirkx 0:a259777c45a3 393 }
dirkx 0:a259777c45a3 394 }
dirkx 0:a259777c45a3 395
dirkx 0:a259777c45a3 396 /** Initiate LCP open request */
dirkx 0:a259777c45a3 397 static void
dirkx 0:a259777c45a3 398 pppStart(int pd)
dirkx 0:a259777c45a3 399 {
dirkx 0:a259777c45a3 400 PPPDEBUG(LOG_DEBUG, ("pppStart: unit %d\n", pd));
dirkx 0:a259777c45a3 401 lcp_lowerup(pd);
dirkx 0:a259777c45a3 402 lcp_open(pd); /* Start protocol */
dirkx 0:a259777c45a3 403 PPPDEBUG(LOG_DEBUG, ("pppStart: finished\n"));
dirkx 0:a259777c45a3 404 }
dirkx 0:a259777c45a3 405
dirkx 0:a259777c45a3 406 /** LCP close request */
dirkx 0:a259777c45a3 407 static void
dirkx 0:a259777c45a3 408 pppStop(int pd)
dirkx 0:a259777c45a3 409 {
dirkx 0:a259777c45a3 410 PPPDEBUG(LOG_DEBUG, ("pppStop: unit %d\n", pd));
dirkx 0:a259777c45a3 411 lcp_close(pd, "User request");
dirkx 0:a259777c45a3 412 }
dirkx 0:a259777c45a3 413
dirkx 0:a259777c45a3 414 /** Called when carrier/link is lost */
dirkx 0:a259777c45a3 415 static void
dirkx 0:a259777c45a3 416 pppHup(int pd)
dirkx 0:a259777c45a3 417 {
dirkx 0:a259777c45a3 418 PPPDEBUG(LOG_DEBUG, ("pppHupCB: unit %d\n", pd));
dirkx 0:a259777c45a3 419 lcp_lowerdown(pd);
dirkx 0:a259777c45a3 420 link_terminated(pd);
dirkx 0:a259777c45a3 421 }
dirkx 0:a259777c45a3 422
dirkx 0:a259777c45a3 423 /***********************************/
dirkx 0:a259777c45a3 424 /*** PUBLIC FUNCTION DEFINITIONS ***/
dirkx 0:a259777c45a3 425 /***********************************/
dirkx 0:a259777c45a3 426 /* Initialize the PPP subsystem. */
dirkx 0:a259777c45a3 427
dirkx 0:a259777c45a3 428 struct ppp_settings ppp_settings;
dirkx 0:a259777c45a3 429
dirkx 0:a259777c45a3 430 void
dirkx 0:a259777c45a3 431 pppInit(void)
dirkx 0:a259777c45a3 432 {
dirkx 0:a259777c45a3 433 struct protent *protp;
dirkx 0:a259777c45a3 434 int i, j;
dirkx 0:a259777c45a3 435
dirkx 0:a259777c45a3 436 memset(&ppp_settings, 0, sizeof(ppp_settings));
dirkx 0:a259777c45a3 437 ppp_settings.usepeerdns = 1;
dirkx 0:a259777c45a3 438 pppSetAuth(PPPAUTHTYPE_NONE, NULL, NULL);
dirkx 0:a259777c45a3 439
dirkx 0:a259777c45a3 440 magicInit();
dirkx 0:a259777c45a3 441
dirkx 0:a259777c45a3 442 subnetMask = htonl(0xffffff00);
dirkx 0:a259777c45a3 443
dirkx 0:a259777c45a3 444 for (i = 0; i < NUM_PPP; i++) {
dirkx 0:a259777c45a3 445 /* Initialize each protocol to the standard option set. */
dirkx 0:a259777c45a3 446 for (j = 0; (protp = ppp_protocols[j]) != NULL; ++j) {
dirkx 0:a259777c45a3 447 (*protp->init)(i);
dirkx 0:a259777c45a3 448 }
dirkx 0:a259777c45a3 449 }
dirkx 0:a259777c45a3 450
dirkx 0:a259777c45a3 451 #if PPPOE_SUPPORT
dirkx 0:a259777c45a3 452 pppoe_init();
dirkx 0:a259777c45a3 453 #endif /* PPPOE_SUPPORT */
dirkx 0:a259777c45a3 454 }
dirkx 0:a259777c45a3 455
dirkx 0:a259777c45a3 456 void
dirkx 0:a259777c45a3 457 pppSetAuth(enum pppAuthType authType, const char *user, const char *passwd)
dirkx 0:a259777c45a3 458 {
dirkx 0:a259777c45a3 459 switch(authType) {
dirkx 0:a259777c45a3 460 case PPPAUTHTYPE_NONE:
dirkx 0:a259777c45a3 461 default:
dirkx 0:a259777c45a3 462 #ifdef LWIP_PPP_STRICT_PAP_REJECT
dirkx 0:a259777c45a3 463 ppp_settings.refuse_pap = 1;
dirkx 0:a259777c45a3 464 #else /* LWIP_PPP_STRICT_PAP_REJECT */
dirkx 0:a259777c45a3 465 /* some providers request pap and accept an empty login/pw */
dirkx 0:a259777c45a3 466 ppp_settings.refuse_pap = 0;
dirkx 0:a259777c45a3 467 #endif /* LWIP_PPP_STRICT_PAP_REJECT */
dirkx 0:a259777c45a3 468 ppp_settings.refuse_chap = 1;
dirkx 0:a259777c45a3 469 break;
dirkx 0:a259777c45a3 470
dirkx 0:a259777c45a3 471 case PPPAUTHTYPE_ANY:
dirkx 0:a259777c45a3 472 /* Warning: Using PPPAUTHTYPE_ANY might have security consequences.
dirkx 0:a259777c45a3 473 * RFC 1994 says:
dirkx 0:a259777c45a3 474 *
dirkx 0:a259777c45a3 475 * In practice, within or associated with each PPP server, there is a
dirkx 0:a259777c45a3 476 * database which associates "user" names with authentication
dirkx 0:a259777c45a3 477 * information ("secrets"). It is not anticipated that a particular
dirkx 0:a259777c45a3 478 * named user would be authenticated by multiple methods. This would
dirkx 0:a259777c45a3 479 * make the user vulnerable to attacks which negotiate the least secure
dirkx 0:a259777c45a3 480 * method from among a set (such as PAP rather than CHAP). If the same
dirkx 0:a259777c45a3 481 * secret was used, PAP would reveal the secret to be used later with
dirkx 0:a259777c45a3 482 * CHAP.
dirkx 0:a259777c45a3 483 *
dirkx 0:a259777c45a3 484 * Instead, for each user name there should be an indication of exactly
dirkx 0:a259777c45a3 485 * one method used to authenticate that user name. If a user needs to
dirkx 0:a259777c45a3 486 * make use of different authentication methods under different
dirkx 0:a259777c45a3 487 * circumstances, then distinct user names SHOULD be employed, each of
dirkx 0:a259777c45a3 488 * which identifies exactly one authentication method.
dirkx 0:a259777c45a3 489 *
dirkx 0:a259777c45a3 490 */
dirkx 0:a259777c45a3 491 ppp_settings.refuse_pap = 0;
dirkx 0:a259777c45a3 492 ppp_settings.refuse_chap = 0;
dirkx 0:a259777c45a3 493 break;
dirkx 0:a259777c45a3 494
dirkx 0:a259777c45a3 495 case PPPAUTHTYPE_PAP:
dirkx 0:a259777c45a3 496 ppp_settings.refuse_pap = 0;
dirkx 0:a259777c45a3 497 ppp_settings.refuse_chap = 1;
dirkx 0:a259777c45a3 498 break;
dirkx 0:a259777c45a3 499
dirkx 0:a259777c45a3 500 case PPPAUTHTYPE_CHAP:
dirkx 0:a259777c45a3 501 ppp_settings.refuse_pap = 1;
dirkx 0:a259777c45a3 502 ppp_settings.refuse_chap = 0;
dirkx 0:a259777c45a3 503 break;
dirkx 0:a259777c45a3 504 }
dirkx 0:a259777c45a3 505
dirkx 0:a259777c45a3 506 if(user) {
dirkx 0:a259777c45a3 507 strncpy(ppp_settings.user, user, sizeof(ppp_settings.user)-1);
dirkx 0:a259777c45a3 508 ppp_settings.user[sizeof(ppp_settings.user)-1] = '\0';
dirkx 0:a259777c45a3 509 } else {
dirkx 0:a259777c45a3 510 ppp_settings.user[0] = '\0';
dirkx 0:a259777c45a3 511 }
dirkx 0:a259777c45a3 512
dirkx 0:a259777c45a3 513 if(passwd) {
dirkx 0:a259777c45a3 514 strncpy(ppp_settings.passwd, passwd, sizeof(ppp_settings.passwd)-1);
dirkx 0:a259777c45a3 515 ppp_settings.passwd[sizeof(ppp_settings.passwd)-1] = '\0';
dirkx 0:a259777c45a3 516 } else {
dirkx 0:a259777c45a3 517 ppp_settings.passwd[0] = '\0';
dirkx 0:a259777c45a3 518 }
dirkx 0:a259777c45a3 519 }
dirkx 0:a259777c45a3 520
dirkx 0:a259777c45a3 521 #if PPPOS_SUPPORT
dirkx 0:a259777c45a3 522 /** Open a new PPP connection using the given I/O device.
dirkx 0:a259777c45a3 523 * This initializes the PPP control block but does not
dirkx 0:a259777c45a3 524 * attempt to negotiate the LCP session. If this port
dirkx 0:a259777c45a3 525 * connects to a modem, the modem connection must be
dirkx 0:a259777c45a3 526 * established before calling this.
dirkx 0:a259777c45a3 527 * Return a new PPP connection descriptor on success or
dirkx 0:a259777c45a3 528 * an error code (negative) on failure.
dirkx 0:a259777c45a3 529 *
dirkx 0:a259777c45a3 530 * pppOpen() is directly defined to this function.
dirkx 0:a259777c45a3 531 */
dirkx 0:a259777c45a3 532 int
dirkx 0:a259777c45a3 533 pppOverSerialOpen(sio_fd_t fd, void (*linkStatusCB)(void *ctx, int errCode, void *arg), void *linkStatusCtx)
dirkx 0:a259777c45a3 534 {
dirkx 0:a259777c45a3 535 PPPControl *pc;
dirkx 0:a259777c45a3 536 int pd;
dirkx 0:a259777c45a3 537
dirkx 0:a259777c45a3 538 if (linkStatusCB == NULL) {
dirkx 0:a259777c45a3 539 /* PPP is single-threaded: without a callback,
dirkx 0:a259777c45a3 540 * there is no way to know when the link is up. */
dirkx 0:a259777c45a3 541 return PPPERR_PARAM;
dirkx 0:a259777c45a3 542 }
dirkx 0:a259777c45a3 543
dirkx 0:a259777c45a3 544 /* Find a free PPP session descriptor. */
dirkx 0:a259777c45a3 545 for (pd = 0; pd < NUM_PPP && pppControl[pd].openFlag != 0; pd++);
dirkx 0:a259777c45a3 546
dirkx 0:a259777c45a3 547 if (pd >= NUM_PPP) {
dirkx 0:a259777c45a3 548 pd = PPPERR_OPEN;
dirkx 0:a259777c45a3 549 } else {
dirkx 0:a259777c45a3 550 pc = &pppControl[pd];
dirkx 0:a259777c45a3 551 /* @todo: is this correct or do I overwrite something? */
dirkx 0:a259777c45a3 552 memset(pc, 0, sizeof(PPPControl));
dirkx 0:a259777c45a3 553 pc->rx.pd = pd;
dirkx 0:a259777c45a3 554 pc->rx.fd = fd;
dirkx 0:a259777c45a3 555
dirkx 0:a259777c45a3 556 pc->openFlag = 1;
dirkx 0:a259777c45a3 557 pc->fd = fd;
dirkx 0:a259777c45a3 558
dirkx 0:a259777c45a3 559 #if VJ_SUPPORT
dirkx 0:a259777c45a3 560 vj_compress_init(&pc->vjComp);
dirkx 0:a259777c45a3 561 #endif /* VJ_SUPPORT */
dirkx 0:a259777c45a3 562
dirkx 0:a259777c45a3 563 /*
dirkx 0:a259777c45a3 564 * Default the in and out accm so that escape and flag characters
dirkx 0:a259777c45a3 565 * are always escaped.
dirkx 0:a259777c45a3 566 */
dirkx 0:a259777c45a3 567 pc->rx.inACCM[15] = 0x60; /* no need to protect since RX is not running */
dirkx 0:a259777c45a3 568 pc->outACCM[15] = 0x60;
dirkx 0:a259777c45a3 569
dirkx 0:a259777c45a3 570 pc->linkStatusCB = linkStatusCB;
dirkx 0:a259777c45a3 571 pc->linkStatusCtx = linkStatusCtx;
dirkx 0:a259777c45a3 572
dirkx 0:a259777c45a3 573 /*
dirkx 0:a259777c45a3 574 * Start the connection and handle incoming events (packet or timeout).
dirkx 0:a259777c45a3 575 */
dirkx 0:a259777c45a3 576 PPPDEBUG(LOG_INFO, ("pppOverSerialOpen: unit %d: Connecting\n", pd));
dirkx 0:a259777c45a3 577 pppStart(pd);
dirkx 0:a259777c45a3 578 #if PPP_INPROC_OWNTHREAD
dirkx 0:a259777c45a3 579 sys_thread_new(PPP_THREAD_NAME, pppInputThread, (void*)&pc->rx, PPP_THREAD_STACKSIZE, PPP_THREAD_PRIO);
dirkx 0:a259777c45a3 580 #endif
dirkx 0:a259777c45a3 581 }
dirkx 0:a259777c45a3 582
dirkx 0:a259777c45a3 583 return pd;
dirkx 0:a259777c45a3 584 }
dirkx 0:a259777c45a3 585 #endif /* PPPOS_SUPPORT */
dirkx 0:a259777c45a3 586
dirkx 0:a259777c45a3 587 #if PPPOE_SUPPORT
dirkx 0:a259777c45a3 588 static void pppOverEthernetLinkStatusCB(int pd, int up);
dirkx 0:a259777c45a3 589
dirkx 0:a259777c45a3 590 void
dirkx 0:a259777c45a3 591 pppOverEthernetClose(int pd)
dirkx 0:a259777c45a3 592 {
dirkx 0:a259777c45a3 593 PPPControl* pc = &pppControl[pd];
dirkx 0:a259777c45a3 594
dirkx 0:a259777c45a3 595 /* *TJL* There's no lcp_deinit */
dirkx 0:a259777c45a3 596 lcp_close(pd, NULL);
dirkx 0:a259777c45a3 597
dirkx 0:a259777c45a3 598 pppoe_destroy(&pc->netif);
dirkx 0:a259777c45a3 599 }
dirkx 0:a259777c45a3 600
dirkx 0:a259777c45a3 601 int pppOverEthernetOpen(struct netif *ethif, const char *service_name, const char *concentrator_name, void (*linkStatusCB)(void *ctx, int errCode, void *arg), void *linkStatusCtx)
dirkx 0:a259777c45a3 602 {
dirkx 0:a259777c45a3 603 PPPControl *pc;
dirkx 0:a259777c45a3 604 int pd;
dirkx 0:a259777c45a3 605
dirkx 0:a259777c45a3 606 LWIP_UNUSED_ARG(service_name);
dirkx 0:a259777c45a3 607 LWIP_UNUSED_ARG(concentrator_name);
dirkx 0:a259777c45a3 608
dirkx 0:a259777c45a3 609 if (linkStatusCB == NULL) {
dirkx 0:a259777c45a3 610 /* PPP is single-threaded: without a callback,
dirkx 0:a259777c45a3 611 * there is no way to know when the link is up. */
dirkx 0:a259777c45a3 612 return PPPERR_PARAM;
dirkx 0:a259777c45a3 613 }
dirkx 0:a259777c45a3 614
dirkx 0:a259777c45a3 615 /* Find a free PPP session descriptor. Critical region? */
dirkx 0:a259777c45a3 616 for (pd = 0; pd < NUM_PPP && pppControl[pd].openFlag != 0; pd++);
dirkx 0:a259777c45a3 617 if (pd >= NUM_PPP) {
dirkx 0:a259777c45a3 618 pd = PPPERR_OPEN;
dirkx 0:a259777c45a3 619 } else {
dirkx 0:a259777c45a3 620 pc = &pppControl[pd];
dirkx 0:a259777c45a3 621 memset(pc, 0, sizeof(PPPControl));
dirkx 0:a259777c45a3 622 pc->openFlag = 1;
dirkx 0:a259777c45a3 623 pc->ethif = ethif;
dirkx 0:a259777c45a3 624
dirkx 0:a259777c45a3 625 pc->linkStatusCB = linkStatusCB;
dirkx 0:a259777c45a3 626 pc->linkStatusCtx = linkStatusCtx;
dirkx 0:a259777c45a3 627
dirkx 0:a259777c45a3 628 lcp_wantoptions[pd].mru = PPPOE_MAXMTU;
dirkx 0:a259777c45a3 629 lcp_wantoptions[pd].neg_asyncmap = 0;
dirkx 0:a259777c45a3 630 lcp_wantoptions[pd].neg_pcompression = 0;
dirkx 0:a259777c45a3 631 lcp_wantoptions[pd].neg_accompression = 0;
dirkx 0:a259777c45a3 632
dirkx 0:a259777c45a3 633 lcp_allowoptions[pd].mru = PPPOE_MAXMTU;
dirkx 0:a259777c45a3 634 lcp_allowoptions[pd].neg_asyncmap = 0;
dirkx 0:a259777c45a3 635 lcp_allowoptions[pd].neg_pcompression = 0;
dirkx 0:a259777c45a3 636 lcp_allowoptions[pd].neg_accompression = 0;
dirkx 0:a259777c45a3 637
dirkx 0:a259777c45a3 638 if(pppoe_create(ethif, pd, pppOverEthernetLinkStatusCB, &pc->pppoe_sc) != ERR_OK) {
dirkx 0:a259777c45a3 639 pc->openFlag = 0;
dirkx 0:a259777c45a3 640 return PPPERR_OPEN;
dirkx 0:a259777c45a3 641 }
dirkx 0:a259777c45a3 642
dirkx 0:a259777c45a3 643 pppoe_connect(pc->pppoe_sc);
dirkx 0:a259777c45a3 644 }
dirkx 0:a259777c45a3 645
dirkx 0:a259777c45a3 646 return pd;
dirkx 0:a259777c45a3 647 }
dirkx 0:a259777c45a3 648 #endif /* PPPOE_SUPPORT */
dirkx 0:a259777c45a3 649
dirkx 0:a259777c45a3 650
dirkx 0:a259777c45a3 651 /* Close a PPP connection and release the descriptor.
dirkx 0:a259777c45a3 652 * Any outstanding packets in the queues are dropped.
dirkx 0:a259777c45a3 653 * Return 0 on success, an error code on failure. */
dirkx 0:a259777c45a3 654 int
dirkx 0:a259777c45a3 655 pppClose(int pd)
dirkx 0:a259777c45a3 656 {
dirkx 0:a259777c45a3 657 PPPControl *pc = &pppControl[pd];
dirkx 0:a259777c45a3 658 int st = 0;
dirkx 0:a259777c45a3 659
dirkx 0:a259777c45a3 660 PPPDEBUG(LOG_DEBUG, ("pppClose() called\n"));
dirkx 0:a259777c45a3 661
dirkx 0:a259777c45a3 662 /* Disconnect */
dirkx 0:a259777c45a3 663 #if PPPOE_SUPPORT
dirkx 0:a259777c45a3 664 if(pc->ethif) {
dirkx 0:a259777c45a3 665 PPPDEBUG(LOG_DEBUG, ("pppClose: unit %d kill_link -> pppStop\n", pd));
dirkx 0:a259777c45a3 666 pc->errCode = PPPERR_USER;
dirkx 0:a259777c45a3 667 /* This will leave us at PHASE_DEAD. */
dirkx 0:a259777c45a3 668 pppStop(pd);
dirkx 0:a259777c45a3 669 } else
dirkx 0:a259777c45a3 670 #endif /* PPPOE_SUPPORT */
dirkx 0:a259777c45a3 671 {
dirkx 0:a259777c45a3 672 #if PPPOS_SUPPORT
dirkx 0:a259777c45a3 673 PPPDEBUG(LOG_DEBUG, ("pppClose: unit %d kill_link -> pppStop\n", pd));
dirkx 0:a259777c45a3 674 pc->errCode = PPPERR_USER;
dirkx 0:a259777c45a3 675 /* This will leave us at PHASE_DEAD. */
dirkx 0:a259777c45a3 676 pppStop(pd);
dirkx 0:a259777c45a3 677 pppRecvWakeup(pd);
dirkx 0:a259777c45a3 678 #endif /* PPPOS_SUPPORT */
dirkx 0:a259777c45a3 679 }
dirkx 0:a259777c45a3 680
dirkx 0:a259777c45a3 681 return st;
dirkx 0:a259777c45a3 682 }
dirkx 0:a259777c45a3 683
dirkx 0:a259777c45a3 684 /* This function is called when carrier is lost on the PPP channel. */
dirkx 0:a259777c45a3 685 void
dirkx 0:a259777c45a3 686 pppSigHUP(int pd)
dirkx 0:a259777c45a3 687 {
dirkx 0:a259777c45a3 688 #if PPPOE_SUPPORT
dirkx 0:a259777c45a3 689 PPPControl *pc = &pppControl[pd];
dirkx 0:a259777c45a3 690 if(pc->ethif) {
dirkx 0:a259777c45a3 691 PPPDEBUG(LOG_DEBUG, ("pppSigHUP: unit %d sig_hup -> pppHupCB\n", pd));
dirkx 0:a259777c45a3 692 pppHup(pd);
dirkx 0:a259777c45a3 693 } else
dirkx 0:a259777c45a3 694 #endif /* PPPOE_SUPPORT */
dirkx 0:a259777c45a3 695 {
dirkx 0:a259777c45a3 696 #if PPPOS_SUPPORT
dirkx 0:a259777c45a3 697 PPPDEBUG(LOG_DEBUG, ("pppSigHUP: unit %d sig_hup -> pppHupCB\n", pd));
dirkx 0:a259777c45a3 698 pppHup(pd);
dirkx 0:a259777c45a3 699 pppRecvWakeup(pd);
dirkx 0:a259777c45a3 700 #endif /* PPPOS_SUPPORT */
dirkx 0:a259777c45a3 701 }
dirkx 0:a259777c45a3 702 }
dirkx 0:a259777c45a3 703
dirkx 0:a259777c45a3 704 #if PPPOS_SUPPORT
dirkx 0:a259777c45a3 705 static void
dirkx 0:a259777c45a3 706 nPut(PPPControl *pc, struct pbuf *nb)
dirkx 0:a259777c45a3 707 {
dirkx 0:a259777c45a3 708 struct pbuf *b;
dirkx 0:a259777c45a3 709 int c = 0;
dirkx 0:a259777c45a3 710
dirkx 0:a259777c45a3 711 for(b = nb; b != NULL; b = b->next) {
dirkx 0:a259777c45a3 712 if((c = sio_write(pc->fd, (u8_t*)b->payload, b->len)) != b->len) {
dirkx 0:a259777c45a3 713 PPPDEBUG(LOG_WARNING,
dirkx 0:a259777c45a3 714 ("PPP nPut: incomplete sio_write(fd:%d, len:%d, c: 0x%"X8_F") c = %d\n", (size_t)pc->fd, b->len, c, c));
dirkx 0:a259777c45a3 715 LINK_STATS_INC(link.err);
dirkx 0:a259777c45a3 716 pc->lastXMit = 0; /* prepend PPP_FLAG to next packet */
dirkx 0:a259777c45a3 717 snmp_inc_ifoutdiscards(&pc->netif);
dirkx 0:a259777c45a3 718 pbuf_free(nb);
dirkx 0:a259777c45a3 719 return;
dirkx 0:a259777c45a3 720 }
dirkx 0:a259777c45a3 721 }
dirkx 0:a259777c45a3 722
dirkx 0:a259777c45a3 723 snmp_add_ifoutoctets(&pc->netif, nb->tot_len);
dirkx 0:a259777c45a3 724 snmp_inc_ifoutucastpkts(&pc->netif);
dirkx 0:a259777c45a3 725 pbuf_free(nb);
dirkx 0:a259777c45a3 726 LINK_STATS_INC(link.xmit);
dirkx 0:a259777c45a3 727 }
dirkx 0:a259777c45a3 728
dirkx 0:a259777c45a3 729 /*
dirkx 0:a259777c45a3 730 * pppAppend - append given character to end of given pbuf. If outACCM
dirkx 0:a259777c45a3 731 * is not NULL and the character needs to be escaped, do so.
dirkx 0:a259777c45a3 732 * If pbuf is full, append another.
dirkx 0:a259777c45a3 733 * Return the current pbuf.
dirkx 0:a259777c45a3 734 */
dirkx 0:a259777c45a3 735 static struct pbuf *
dirkx 0:a259777c45a3 736 pppAppend(u_char c, struct pbuf *nb, ext_accm *outACCM)
dirkx 0:a259777c45a3 737 {
dirkx 0:a259777c45a3 738 struct pbuf *tb = nb;
dirkx 0:a259777c45a3 739
dirkx 0:a259777c45a3 740 /* Make sure there is room for the character and an escape code.
dirkx 0:a259777c45a3 741 * Sure we don't quite fill the buffer if the character doesn't
dirkx 0:a259777c45a3 742 * get escaped but is one character worth complicating this? */
dirkx 0:a259777c45a3 743 /* Note: We assume no packet header. */
dirkx 0:a259777c45a3 744 if (nb && (PBUF_POOL_BUFSIZE - nb->len) < 2) {
dirkx 0:a259777c45a3 745 tb = pbuf_alloc(PBUF_RAW, 0, PBUF_POOL);
dirkx 0:a259777c45a3 746 if (tb) {
dirkx 0:a259777c45a3 747 nb->next = tb;
dirkx 0:a259777c45a3 748 } else {
dirkx 0:a259777c45a3 749 LINK_STATS_INC(link.memerr);
dirkx 0:a259777c45a3 750 }
dirkx 0:a259777c45a3 751 nb = tb;
dirkx 0:a259777c45a3 752 }
dirkx 0:a259777c45a3 753
dirkx 0:a259777c45a3 754 if (nb) {
dirkx 0:a259777c45a3 755 if (outACCM && ESCAPE_P(*outACCM, c)) {
dirkx 0:a259777c45a3 756 *((u_char*)nb->payload + nb->len++) = PPP_ESCAPE;
dirkx 0:a259777c45a3 757 *((u_char*)nb->payload + nb->len++) = c ^ PPP_TRANS;
dirkx 0:a259777c45a3 758 } else {
dirkx 0:a259777c45a3 759 *((u_char*)nb->payload + nb->len++) = c;
dirkx 0:a259777c45a3 760 }
dirkx 0:a259777c45a3 761 }
dirkx 0:a259777c45a3 762
dirkx 0:a259777c45a3 763 return tb;
dirkx 0:a259777c45a3 764 }
dirkx 0:a259777c45a3 765 #endif /* PPPOS_SUPPORT */
dirkx 0:a259777c45a3 766
dirkx 0:a259777c45a3 767 #if PPPOE_SUPPORT
dirkx 0:a259777c45a3 768 static err_t
dirkx 0:a259777c45a3 769 pppnetifOutputOverEthernet(int pd, struct pbuf *p)
dirkx 0:a259777c45a3 770 {
dirkx 0:a259777c45a3 771 PPPControl *pc = &pppControl[pd];
dirkx 0:a259777c45a3 772 struct pbuf *pb;
dirkx 0:a259777c45a3 773 u_short protocol = PPP_IP;
dirkx 0:a259777c45a3 774 int i=0;
dirkx 0:a259777c45a3 775 u16_t tot_len;
dirkx 0:a259777c45a3 776
dirkx 0:a259777c45a3 777 /* @todo: try to use pbuf_header() here! */
dirkx 0:a259777c45a3 778 pb = pbuf_alloc(PBUF_LINK, PPPOE_HDRLEN + sizeof(protocol), PBUF_RAM);
dirkx 0:a259777c45a3 779 if(!pb) {
dirkx 0:a259777c45a3 780 LINK_STATS_INC(link.memerr);
dirkx 0:a259777c45a3 781 LINK_STATS_INC(link.proterr);
dirkx 0:a259777c45a3 782 snmp_inc_ifoutdiscards(&pc->netif);
dirkx 0:a259777c45a3 783 return ERR_MEM;
dirkx 0:a259777c45a3 784 }
dirkx 0:a259777c45a3 785
dirkx 0:a259777c45a3 786 pbuf_header(pb, -(s16_t)PPPOE_HDRLEN);
dirkx 0:a259777c45a3 787
dirkx 0:a259777c45a3 788 pc->lastXMit = sys_jiffies();
dirkx 0:a259777c45a3 789
dirkx 0:a259777c45a3 790 if (!pc->pcomp || protocol > 0xFF) {
dirkx 0:a259777c45a3 791 *((u_char*)pb->payload + i++) = (protocol >> 8) & 0xFF;
dirkx 0:a259777c45a3 792 }
dirkx 0:a259777c45a3 793 *((u_char*)pb->payload + i) = protocol & 0xFF;
dirkx 0:a259777c45a3 794
dirkx 0:a259777c45a3 795 pbuf_chain(pb, p);
dirkx 0:a259777c45a3 796 tot_len = pb->tot_len;
dirkx 0:a259777c45a3 797
dirkx 0:a259777c45a3 798 if(pppoe_xmit(pc->pppoe_sc, pb) != ERR_OK) {
dirkx 0:a259777c45a3 799 LINK_STATS_INC(link.err);
dirkx 0:a259777c45a3 800 snmp_inc_ifoutdiscards(&pc->netif);
dirkx 0:a259777c45a3 801 return PPPERR_DEVICE;
dirkx 0:a259777c45a3 802 }
dirkx 0:a259777c45a3 803
dirkx 0:a259777c45a3 804 snmp_add_ifoutoctets(&pc->netif, tot_len);
dirkx 0:a259777c45a3 805 snmp_inc_ifoutucastpkts(&pc->netif);
dirkx 0:a259777c45a3 806 LINK_STATS_INC(link.xmit);
dirkx 0:a259777c45a3 807 return ERR_OK;
dirkx 0:a259777c45a3 808 }
dirkx 0:a259777c45a3 809 #endif /* PPPOE_SUPPORT */
dirkx 0:a259777c45a3 810
dirkx 0:a259777c45a3 811 /* Send a packet on the given connection. */
dirkx 0:a259777c45a3 812 static err_t
dirkx 0:a259777c45a3 813 pppnetifOutput(struct netif *netif, struct pbuf *pb, ip_addr_t *ipaddr)
dirkx 0:a259777c45a3 814 {
dirkx 0:a259777c45a3 815 int pd = (int)(size_t)netif->state;
dirkx 0:a259777c45a3 816 PPPControl *pc = &pppControl[pd];
dirkx 0:a259777c45a3 817 #if PPPOS_SUPPORT
dirkx 0:a259777c45a3 818 u_short protocol = PPP_IP;
dirkx 0:a259777c45a3 819 u_int fcsOut = PPP_INITFCS;
dirkx 0:a259777c45a3 820 struct pbuf *headMB = NULL, *tailMB = NULL, *p;
dirkx 0:a259777c45a3 821 u_char c;
dirkx 0:a259777c45a3 822 #endif /* PPPOS_SUPPORT */
dirkx 0:a259777c45a3 823
dirkx 0:a259777c45a3 824 LWIP_UNUSED_ARG(ipaddr);
dirkx 0:a259777c45a3 825
dirkx 0:a259777c45a3 826 /* Validate parameters. */
dirkx 0:a259777c45a3 827 /* We let any protocol value go through - it can't hurt us
dirkx 0:a259777c45a3 828 * and the peer will just drop it if it's not accepting it. */
dirkx 0:a259777c45a3 829 if (pd < 0 || pd >= NUM_PPP || !pc->openFlag || !pb) {
dirkx 0:a259777c45a3 830 PPPDEBUG(LOG_WARNING, ("pppnetifOutput[%d]: bad parms prot=%d pb=%p\n",
dirkx 0:a259777c45a3 831 pd, PPP_IP, pb));
dirkx 0:a259777c45a3 832 LINK_STATS_INC(link.opterr);
dirkx 0:a259777c45a3 833 LINK_STATS_INC(link.drop);
dirkx 0:a259777c45a3 834 snmp_inc_ifoutdiscards(netif);
dirkx 0:a259777c45a3 835 return ERR_ARG;
dirkx 0:a259777c45a3 836 }
dirkx 0:a259777c45a3 837
dirkx 0:a259777c45a3 838 /* Check that the link is up. */
dirkx 0:a259777c45a3 839 if (lcp_phase[pd] == PHASE_DEAD) {
dirkx 0:a259777c45a3 840 PPPDEBUG(LOG_ERR, ("pppnetifOutput[%d]: link not up\n", pd));
dirkx 0:a259777c45a3 841 LINK_STATS_INC(link.rterr);
dirkx 0:a259777c45a3 842 LINK_STATS_INC(link.drop);
dirkx 0:a259777c45a3 843 snmp_inc_ifoutdiscards(netif);
dirkx 0:a259777c45a3 844 return ERR_RTE;
dirkx 0:a259777c45a3 845 }
dirkx 0:a259777c45a3 846
dirkx 0:a259777c45a3 847 #if PPPOE_SUPPORT
dirkx 0:a259777c45a3 848 if(pc->ethif) {
dirkx 0:a259777c45a3 849 return pppnetifOutputOverEthernet(pd, pb);
dirkx 0:a259777c45a3 850 }
dirkx 0:a259777c45a3 851 #endif /* PPPOE_SUPPORT */
dirkx 0:a259777c45a3 852
dirkx 0:a259777c45a3 853 #if PPPOS_SUPPORT
dirkx 0:a259777c45a3 854 /* Grab an output buffer. */
dirkx 0:a259777c45a3 855 headMB = pbuf_alloc(PBUF_RAW, 0, PBUF_POOL);
dirkx 0:a259777c45a3 856 if (headMB == NULL) {
dirkx 0:a259777c45a3 857 PPPDEBUG(LOG_WARNING, ("pppnetifOutput[%d]: first alloc fail\n", pd));
dirkx 0:a259777c45a3 858 LINK_STATS_INC(link.memerr);
dirkx 0:a259777c45a3 859 LINK_STATS_INC(link.drop);
dirkx 0:a259777c45a3 860 snmp_inc_ifoutdiscards(netif);
dirkx 0:a259777c45a3 861 return ERR_MEM;
dirkx 0:a259777c45a3 862 }
dirkx 0:a259777c45a3 863
dirkx 0:a259777c45a3 864 #if VJ_SUPPORT
dirkx 0:a259777c45a3 865 /*
dirkx 0:a259777c45a3 866 * Attempt Van Jacobson header compression if VJ is configured and
dirkx 0:a259777c45a3 867 * this is an IP packet.
dirkx 0:a259777c45a3 868 */
dirkx 0:a259777c45a3 869 if (protocol == PPP_IP && pc->vjEnabled) {
dirkx 0:a259777c45a3 870 switch (vj_compress_tcp(&pc->vjComp, pb)) {
dirkx 0:a259777c45a3 871 case TYPE_IP:
dirkx 0:a259777c45a3 872 /* No change...
dirkx 0:a259777c45a3 873 protocol = PPP_IP_PROTOCOL; */
dirkx 0:a259777c45a3 874 break;
dirkx 0:a259777c45a3 875 case TYPE_COMPRESSED_TCP:
dirkx 0:a259777c45a3 876 protocol = PPP_VJC_COMP;
dirkx 0:a259777c45a3 877 break;
dirkx 0:a259777c45a3 878 case TYPE_UNCOMPRESSED_TCP:
dirkx 0:a259777c45a3 879 protocol = PPP_VJC_UNCOMP;
dirkx 0:a259777c45a3 880 break;
dirkx 0:a259777c45a3 881 default:
dirkx 0:a259777c45a3 882 PPPDEBUG(LOG_WARNING, ("pppnetifOutput[%d]: bad IP packet\n", pd));
dirkx 0:a259777c45a3 883 LINK_STATS_INC(link.proterr);
dirkx 0:a259777c45a3 884 LINK_STATS_INC(link.drop);
dirkx 0:a259777c45a3 885 snmp_inc_ifoutdiscards(netif);
dirkx 0:a259777c45a3 886 pbuf_free(headMB);
dirkx 0:a259777c45a3 887 return ERR_VAL;
dirkx 0:a259777c45a3 888 }
dirkx 0:a259777c45a3 889 }
dirkx 0:a259777c45a3 890 #endif /* VJ_SUPPORT */
dirkx 0:a259777c45a3 891
dirkx 0:a259777c45a3 892 tailMB = headMB;
dirkx 0:a259777c45a3 893
dirkx 0:a259777c45a3 894 /* Build the PPP header. */
dirkx 0:a259777c45a3 895 if ((sys_jiffies() - pc->lastXMit) >= PPP_MAXIDLEFLAG) {
dirkx 0:a259777c45a3 896 tailMB = pppAppend(PPP_FLAG, tailMB, NULL);
dirkx 0:a259777c45a3 897 }
dirkx 0:a259777c45a3 898
dirkx 0:a259777c45a3 899 pc->lastXMit = sys_jiffies();
dirkx 0:a259777c45a3 900 if (!pc->accomp) {
dirkx 0:a259777c45a3 901 fcsOut = PPP_FCS(fcsOut, PPP_ALLSTATIONS);
dirkx 0:a259777c45a3 902 tailMB = pppAppend(PPP_ALLSTATIONS, tailMB, &pc->outACCM);
dirkx 0:a259777c45a3 903 fcsOut = PPP_FCS(fcsOut, PPP_UI);
dirkx 0:a259777c45a3 904 tailMB = pppAppend(PPP_UI, tailMB, &pc->outACCM);
dirkx 0:a259777c45a3 905 }
dirkx 0:a259777c45a3 906 if (!pc->pcomp || protocol > 0xFF) {
dirkx 0:a259777c45a3 907 c = (protocol >> 8) & 0xFF;
dirkx 0:a259777c45a3 908 fcsOut = PPP_FCS(fcsOut, c);
dirkx 0:a259777c45a3 909 tailMB = pppAppend(c, tailMB, &pc->outACCM);
dirkx 0:a259777c45a3 910 }
dirkx 0:a259777c45a3 911 c = protocol & 0xFF;
dirkx 0:a259777c45a3 912 fcsOut = PPP_FCS(fcsOut, c);
dirkx 0:a259777c45a3 913 tailMB = pppAppend(c, tailMB, &pc->outACCM);
dirkx 0:a259777c45a3 914
dirkx 0:a259777c45a3 915 /* Load packet. */
dirkx 0:a259777c45a3 916 for(p = pb; p; p = p->next) {
dirkx 0:a259777c45a3 917 int n;
dirkx 0:a259777c45a3 918 u_char *sPtr;
dirkx 0:a259777c45a3 919
dirkx 0:a259777c45a3 920 sPtr = (u_char*)p->payload;
dirkx 0:a259777c45a3 921 n = p->len;
dirkx 0:a259777c45a3 922 while (n-- > 0) {
dirkx 0:a259777c45a3 923 c = *sPtr++;
dirkx 0:a259777c45a3 924
dirkx 0:a259777c45a3 925 /* Update FCS before checking for special characters. */
dirkx 0:a259777c45a3 926 fcsOut = PPP_FCS(fcsOut, c);
dirkx 0:a259777c45a3 927
dirkx 0:a259777c45a3 928 /* Copy to output buffer escaping special characters. */
dirkx 0:a259777c45a3 929 tailMB = pppAppend(c, tailMB, &pc->outACCM);
dirkx 0:a259777c45a3 930 }
dirkx 0:a259777c45a3 931 }
dirkx 0:a259777c45a3 932
dirkx 0:a259777c45a3 933 /* Add FCS and trailing flag. */
dirkx 0:a259777c45a3 934 c = ~fcsOut & 0xFF;
dirkx 0:a259777c45a3 935 tailMB = pppAppend(c, tailMB, &pc->outACCM);
dirkx 0:a259777c45a3 936 c = (~fcsOut >> 8) & 0xFF;
dirkx 0:a259777c45a3 937 tailMB = pppAppend(c, tailMB, &pc->outACCM);
dirkx 0:a259777c45a3 938 tailMB = pppAppend(PPP_FLAG, tailMB, NULL);
dirkx 0:a259777c45a3 939
dirkx 0:a259777c45a3 940 /* If we failed to complete the packet, throw it away. */
dirkx 0:a259777c45a3 941 if (!tailMB) {
dirkx 0:a259777c45a3 942 PPPDEBUG(LOG_WARNING,
dirkx 0:a259777c45a3 943 ("pppnetifOutput[%d]: Alloc err - dropping proto=%d\n",
dirkx 0:a259777c45a3 944 pd, protocol));
dirkx 0:a259777c45a3 945 pbuf_free(headMB);
dirkx 0:a259777c45a3 946 LINK_STATS_INC(link.memerr);
dirkx 0:a259777c45a3 947 LINK_STATS_INC(link.drop);
dirkx 0:a259777c45a3 948 snmp_inc_ifoutdiscards(netif);
dirkx 0:a259777c45a3 949 return ERR_MEM;
dirkx 0:a259777c45a3 950 }
dirkx 0:a259777c45a3 951
dirkx 0:a259777c45a3 952 /* Send it. */
dirkx 0:a259777c45a3 953 PPPDEBUG(LOG_INFO, ("pppnetifOutput[%d]: proto=0x%"X16_F"\n", pd, protocol));
dirkx 0:a259777c45a3 954
dirkx 0:a259777c45a3 955 nPut(pc, headMB);
dirkx 0:a259777c45a3 956 #endif /* PPPOS_SUPPORT */
dirkx 0:a259777c45a3 957
dirkx 0:a259777c45a3 958 return ERR_OK;
dirkx 0:a259777c45a3 959 }
dirkx 0:a259777c45a3 960
dirkx 0:a259777c45a3 961 /* Get and set parameters for the given connection.
dirkx 0:a259777c45a3 962 * Return 0 on success, an error code on failure. */
dirkx 0:a259777c45a3 963 int
dirkx 0:a259777c45a3 964 pppIOCtl(int pd, int cmd, void *arg)
dirkx 0:a259777c45a3 965 {
dirkx 0:a259777c45a3 966 PPPControl *pc = &pppControl[pd];
dirkx 0:a259777c45a3 967 int st = 0;
dirkx 0:a259777c45a3 968
dirkx 0:a259777c45a3 969 if (pd < 0 || pd >= NUM_PPP) {
dirkx 0:a259777c45a3 970 st = PPPERR_PARAM;
dirkx 0:a259777c45a3 971 } else {
dirkx 0:a259777c45a3 972 switch(cmd) {
dirkx 0:a259777c45a3 973 case PPPCTLG_UPSTATUS: /* Get the PPP up status. */
dirkx 0:a259777c45a3 974 if (arg) {
dirkx 0:a259777c45a3 975 *(int *)arg = (int)(pc->if_up);
dirkx 0:a259777c45a3 976 } else {
dirkx 0:a259777c45a3 977 st = PPPERR_PARAM;
dirkx 0:a259777c45a3 978 }
dirkx 0:a259777c45a3 979 break;
dirkx 0:a259777c45a3 980 case PPPCTLS_ERRCODE: /* Set the PPP error code. */
dirkx 0:a259777c45a3 981 if (arg) {
dirkx 0:a259777c45a3 982 pc->errCode = *(int *)arg;
dirkx 0:a259777c45a3 983 } else {
dirkx 0:a259777c45a3 984 st = PPPERR_PARAM;
dirkx 0:a259777c45a3 985 }
dirkx 0:a259777c45a3 986 break;
dirkx 0:a259777c45a3 987 case PPPCTLG_ERRCODE: /* Get the PPP error code. */
dirkx 0:a259777c45a3 988 if (arg) {
dirkx 0:a259777c45a3 989 *(int *)arg = (int)(pc->errCode);
dirkx 0:a259777c45a3 990 } else {
dirkx 0:a259777c45a3 991 st = PPPERR_PARAM;
dirkx 0:a259777c45a3 992 }
dirkx 0:a259777c45a3 993 break;
dirkx 0:a259777c45a3 994 #if PPPOS_SUPPORT
dirkx 0:a259777c45a3 995 case PPPCTLG_FD: /* Get the fd associated with the ppp */
dirkx 0:a259777c45a3 996 if (arg) {
dirkx 0:a259777c45a3 997 *(sio_fd_t *)arg = pc->fd;
dirkx 0:a259777c45a3 998 } else {
dirkx 0:a259777c45a3 999 st = PPPERR_PARAM;
dirkx 0:a259777c45a3 1000 }
dirkx 0:a259777c45a3 1001 break;
dirkx 0:a259777c45a3 1002 #endif /* PPPOS_SUPPORT */
dirkx 0:a259777c45a3 1003 default:
dirkx 0:a259777c45a3 1004 st = PPPERR_PARAM;
dirkx 0:a259777c45a3 1005 break;
dirkx 0:a259777c45a3 1006 }
dirkx 0:a259777c45a3 1007 }
dirkx 0:a259777c45a3 1008
dirkx 0:a259777c45a3 1009 return st;
dirkx 0:a259777c45a3 1010 }
dirkx 0:a259777c45a3 1011
dirkx 0:a259777c45a3 1012 /*
dirkx 0:a259777c45a3 1013 * Return the Maximum Transmission Unit for the given PPP connection.
dirkx 0:a259777c45a3 1014 */
dirkx 0:a259777c45a3 1015 u_short
dirkx 0:a259777c45a3 1016 pppMTU(int pd)
dirkx 0:a259777c45a3 1017 {
dirkx 0:a259777c45a3 1018 PPPControl *pc = &pppControl[pd];
dirkx 0:a259777c45a3 1019 u_short st;
dirkx 0:a259777c45a3 1020
dirkx 0:a259777c45a3 1021 /* Validate parameters. */
dirkx 0:a259777c45a3 1022 if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) {
dirkx 0:a259777c45a3 1023 st = 0;
dirkx 0:a259777c45a3 1024 } else {
dirkx 0:a259777c45a3 1025 st = pc->mtu;
dirkx 0:a259777c45a3 1026 }
dirkx 0:a259777c45a3 1027
dirkx 0:a259777c45a3 1028 return st;
dirkx 0:a259777c45a3 1029 }
dirkx 0:a259777c45a3 1030
dirkx 0:a259777c45a3 1031 #if PPPOE_SUPPORT
dirkx 0:a259777c45a3 1032 int
dirkx 0:a259777c45a3 1033 pppWriteOverEthernet(int pd, const u_char *s, int n)
dirkx 0:a259777c45a3 1034 {
dirkx 0:a259777c45a3 1035 PPPControl *pc = &pppControl[pd];
dirkx 0:a259777c45a3 1036 struct pbuf *pb;
dirkx 0:a259777c45a3 1037
dirkx 0:a259777c45a3 1038 /* skip address & flags */
dirkx 0:a259777c45a3 1039 s += 2;
dirkx 0:a259777c45a3 1040 n -= 2;
dirkx 0:a259777c45a3 1041
dirkx 0:a259777c45a3 1042 LWIP_ASSERT("PPPOE_HDRLEN + n <= 0xffff", PPPOE_HDRLEN + n <= 0xffff);
dirkx 0:a259777c45a3 1043 pb = pbuf_alloc(PBUF_LINK, (u16_t)(PPPOE_HDRLEN + n), PBUF_RAM);
dirkx 0:a259777c45a3 1044 if(!pb) {
dirkx 0:a259777c45a3 1045 LINK_STATS_INC(link.memerr);
dirkx 0:a259777c45a3 1046 LINK_STATS_INC(link.proterr);
dirkx 0:a259777c45a3 1047 snmp_inc_ifoutdiscards(&pc->netif);
dirkx 0:a259777c45a3 1048 return PPPERR_ALLOC;
dirkx 0:a259777c45a3 1049 }
dirkx 0:a259777c45a3 1050
dirkx 0:a259777c45a3 1051 pbuf_header(pb, -(s16_t)PPPOE_HDRLEN);
dirkx 0:a259777c45a3 1052
dirkx 0:a259777c45a3 1053 pc->lastXMit = sys_jiffies();
dirkx 0:a259777c45a3 1054
dirkx 0:a259777c45a3 1055 MEMCPY(pb->payload, s, n);
dirkx 0:a259777c45a3 1056
dirkx 0:a259777c45a3 1057 if(pppoe_xmit(pc->pppoe_sc, pb) != ERR_OK) {
dirkx 0:a259777c45a3 1058 LINK_STATS_INC(link.err);
dirkx 0:a259777c45a3 1059 snmp_inc_ifoutdiscards(&pc->netif);
dirkx 0:a259777c45a3 1060 return PPPERR_DEVICE;
dirkx 0:a259777c45a3 1061 }
dirkx 0:a259777c45a3 1062
dirkx 0:a259777c45a3 1063 snmp_add_ifoutoctets(&pc->netif, (u16_t)n);
dirkx 0:a259777c45a3 1064 snmp_inc_ifoutucastpkts(&pc->netif);
dirkx 0:a259777c45a3 1065 LINK_STATS_INC(link.xmit);
dirkx 0:a259777c45a3 1066 return PPPERR_NONE;
dirkx 0:a259777c45a3 1067 }
dirkx 0:a259777c45a3 1068 #endif /* PPPOE_SUPPORT */
dirkx 0:a259777c45a3 1069
dirkx 0:a259777c45a3 1070 /*
dirkx 0:a259777c45a3 1071 * Write n characters to a ppp link.
dirkx 0:a259777c45a3 1072 * RETURN: >= 0 Number of characters written
dirkx 0:a259777c45a3 1073 * -1 Failed to write to device
dirkx 0:a259777c45a3 1074 */
dirkx 0:a259777c45a3 1075 int
dirkx 0:a259777c45a3 1076 pppWrite(int pd, const u_char *s, int n)
dirkx 0:a259777c45a3 1077 {
dirkx 0:a259777c45a3 1078 PPPControl *pc = &pppControl[pd];
dirkx 0:a259777c45a3 1079 #if PPPOS_SUPPORT
dirkx 0:a259777c45a3 1080 u_char c;
dirkx 0:a259777c45a3 1081 u_int fcsOut;
dirkx 0:a259777c45a3 1082 struct pbuf *headMB, *tailMB;
dirkx 0:a259777c45a3 1083 #endif /* PPPOS_SUPPORT */
dirkx 0:a259777c45a3 1084
dirkx 0:a259777c45a3 1085 #if PPPOE_SUPPORT
dirkx 0:a259777c45a3 1086 if(pc->ethif) {
dirkx 0:a259777c45a3 1087 return pppWriteOverEthernet(pd, s, n);
dirkx 0:a259777c45a3 1088 }
dirkx 0:a259777c45a3 1089 #endif /* PPPOE_SUPPORT */
dirkx 0:a259777c45a3 1090
dirkx 0:a259777c45a3 1091 #if PPPOS_SUPPORT
dirkx 0:a259777c45a3 1092 headMB = pbuf_alloc(PBUF_RAW, 0, PBUF_POOL);
dirkx 0:a259777c45a3 1093 if (headMB == NULL) {
dirkx 0:a259777c45a3 1094 LINK_STATS_INC(link.memerr);
dirkx 0:a259777c45a3 1095 LINK_STATS_INC(link.proterr);
dirkx 0:a259777c45a3 1096 snmp_inc_ifoutdiscards(&pc->netif);
dirkx 0:a259777c45a3 1097 return PPPERR_ALLOC;
dirkx 0:a259777c45a3 1098 }
dirkx 0:a259777c45a3 1099
dirkx 0:a259777c45a3 1100 tailMB = headMB;
dirkx 0:a259777c45a3 1101
dirkx 0:a259777c45a3 1102 /* If the link has been idle, we'll send a fresh flag character to
dirkx 0:a259777c45a3 1103 * flush any noise. */
dirkx 0:a259777c45a3 1104 if ((sys_jiffies() - pc->lastXMit) >= PPP_MAXIDLEFLAG) {
dirkx 0:a259777c45a3 1105 tailMB = pppAppend(PPP_FLAG, tailMB, NULL);
dirkx 0:a259777c45a3 1106 }
dirkx 0:a259777c45a3 1107 pc->lastXMit = sys_jiffies();
dirkx 0:a259777c45a3 1108
dirkx 0:a259777c45a3 1109 fcsOut = PPP_INITFCS;
dirkx 0:a259777c45a3 1110 /* Load output buffer. */
dirkx 0:a259777c45a3 1111 while (n-- > 0) {
dirkx 0:a259777c45a3 1112 c = *s++;
dirkx 0:a259777c45a3 1113
dirkx 0:a259777c45a3 1114 /* Update FCS before checking for special characters. */
dirkx 0:a259777c45a3 1115 fcsOut = PPP_FCS(fcsOut, c);
dirkx 0:a259777c45a3 1116
dirkx 0:a259777c45a3 1117 /* Copy to output buffer escaping special characters. */
dirkx 0:a259777c45a3 1118 tailMB = pppAppend(c, tailMB, &pc->outACCM);
dirkx 0:a259777c45a3 1119 }
dirkx 0:a259777c45a3 1120
dirkx 0:a259777c45a3 1121 /* Add FCS and trailing flag. */
dirkx 0:a259777c45a3 1122 c = ~fcsOut & 0xFF;
dirkx 0:a259777c45a3 1123 tailMB = pppAppend(c, tailMB, &pc->outACCM);
dirkx 0:a259777c45a3 1124 c = (~fcsOut >> 8) & 0xFF;
dirkx 0:a259777c45a3 1125 tailMB = pppAppend(c, tailMB, &pc->outACCM);
dirkx 0:a259777c45a3 1126 tailMB = pppAppend(PPP_FLAG, tailMB, NULL);
dirkx 0:a259777c45a3 1127
dirkx 0:a259777c45a3 1128 /* If we failed to complete the packet, throw it away.
dirkx 0:a259777c45a3 1129 * Otherwise send it. */
dirkx 0:a259777c45a3 1130 if (!tailMB) {
dirkx 0:a259777c45a3 1131 PPPDEBUG(LOG_WARNING,
dirkx 0:a259777c45a3 1132 ("pppWrite[%d]: Alloc err - dropping pbuf len=%d\n", pd, headMB->len));
dirkx 0:a259777c45a3 1133 /*"pppWrite[%d]: Alloc err - dropping %d:%.*H", pd, headMB->len, LWIP_MIN(headMB->len * 2, 40), headMB->payload)); */
dirkx 0:a259777c45a3 1134 pbuf_free(headMB);
dirkx 0:a259777c45a3 1135 LINK_STATS_INC(link.memerr);
dirkx 0:a259777c45a3 1136 LINK_STATS_INC(link.proterr);
dirkx 0:a259777c45a3 1137 snmp_inc_ifoutdiscards(&pc->netif);
dirkx 0:a259777c45a3 1138 return PPPERR_ALLOC;
dirkx 0:a259777c45a3 1139 }
dirkx 0:a259777c45a3 1140
dirkx 0:a259777c45a3 1141 PPPDEBUG(LOG_INFO, ("pppWrite[%d]: len=%d\n", pd, headMB->len));
dirkx 0:a259777c45a3 1142 /* "pppWrite[%d]: %d:%.*H", pd, headMB->len, LWIP_MIN(headMB->len * 2, 40), headMB->payload)); */
dirkx 0:a259777c45a3 1143 nPut(pc, headMB);
dirkx 0:a259777c45a3 1144 #endif /* PPPOS_SUPPORT */
dirkx 0:a259777c45a3 1145
dirkx 0:a259777c45a3 1146 return PPPERR_NONE;
dirkx 0:a259777c45a3 1147 }
dirkx 0:a259777c45a3 1148
dirkx 0:a259777c45a3 1149 /*
dirkx 0:a259777c45a3 1150 * ppp_send_config - configure the transmit characteristics of
dirkx 0:a259777c45a3 1151 * the ppp interface.
dirkx 0:a259777c45a3 1152 */
dirkx 0:a259777c45a3 1153 void
dirkx 0:a259777c45a3 1154 ppp_send_config( int unit, u16_t mtu, u32_t asyncmap, int pcomp, int accomp)
dirkx 0:a259777c45a3 1155 {
dirkx 0:a259777c45a3 1156 PPPControl *pc = &pppControl[unit];
dirkx 0:a259777c45a3 1157 int i;
dirkx 0:a259777c45a3 1158
dirkx 0:a259777c45a3 1159 pc->mtu = mtu;
dirkx 0:a259777c45a3 1160 pc->pcomp = pcomp;
dirkx 0:a259777c45a3 1161 pc->accomp = accomp;
dirkx 0:a259777c45a3 1162
dirkx 0:a259777c45a3 1163 /* Load the ACCM bits for the 32 control codes. */
dirkx 0:a259777c45a3 1164 for (i = 0; i < 32/8; i++) {
dirkx 0:a259777c45a3 1165 pc->outACCM[i] = (u_char)((asyncmap >> (8 * i)) & 0xFF);
dirkx 0:a259777c45a3 1166 }
dirkx 0:a259777c45a3 1167 PPPDEBUG(LOG_INFO, ("ppp_send_config[%d]: outACCM=%X %X %X %X\n",
dirkx 0:a259777c45a3 1168 unit,
dirkx 0:a259777c45a3 1169 pc->outACCM[0], pc->outACCM[1], pc->outACCM[2], pc->outACCM[3]));
dirkx 0:a259777c45a3 1170 }
dirkx 0:a259777c45a3 1171
dirkx 0:a259777c45a3 1172
dirkx 0:a259777c45a3 1173 /*
dirkx 0:a259777c45a3 1174 * ppp_set_xaccm - set the extended transmit ACCM for the interface.
dirkx 0:a259777c45a3 1175 */
dirkx 0:a259777c45a3 1176 void
dirkx 0:a259777c45a3 1177 ppp_set_xaccm(int unit, ext_accm *accm)
dirkx 0:a259777c45a3 1178 {
dirkx 0:a259777c45a3 1179 SMEMCPY(pppControl[unit].outACCM, accm, sizeof(ext_accm));
dirkx 0:a259777c45a3 1180 PPPDEBUG(LOG_INFO, ("ppp_set_xaccm[%d]: outACCM=%X %X %X %X\n",
dirkx 0:a259777c45a3 1181 unit,
dirkx 0:a259777c45a3 1182 pppControl[unit].outACCM[0],
dirkx 0:a259777c45a3 1183 pppControl[unit].outACCM[1],
dirkx 0:a259777c45a3 1184 pppControl[unit].outACCM[2],
dirkx 0:a259777c45a3 1185 pppControl[unit].outACCM[3]));
dirkx 0:a259777c45a3 1186 }
dirkx 0:a259777c45a3 1187
dirkx 0:a259777c45a3 1188
dirkx 0:a259777c45a3 1189 /*
dirkx 0:a259777c45a3 1190 * ppp_recv_config - configure the receive-side characteristics of
dirkx 0:a259777c45a3 1191 * the ppp interface.
dirkx 0:a259777c45a3 1192 */
dirkx 0:a259777c45a3 1193 void
dirkx 0:a259777c45a3 1194 ppp_recv_config( int unit, int mru, u32_t asyncmap, int pcomp, int accomp)
dirkx 0:a259777c45a3 1195 {
dirkx 0:a259777c45a3 1196 PPPControl *pc = &pppControl[unit];
dirkx 0:a259777c45a3 1197 int i;
dirkx 0:a259777c45a3 1198 SYS_ARCH_DECL_PROTECT(lev);
dirkx 0:a259777c45a3 1199
dirkx 0:a259777c45a3 1200 LWIP_UNUSED_ARG(accomp);
dirkx 0:a259777c45a3 1201 LWIP_UNUSED_ARG(pcomp);
dirkx 0:a259777c45a3 1202 LWIP_UNUSED_ARG(mru);
dirkx 0:a259777c45a3 1203
dirkx 0:a259777c45a3 1204 /* Load the ACCM bits for the 32 control codes. */
dirkx 0:a259777c45a3 1205 SYS_ARCH_PROTECT(lev);
dirkx 0:a259777c45a3 1206 for (i = 0; i < 32 / 8; i++) {
dirkx 0:a259777c45a3 1207 /* @todo: does this work? ext_accm has been modified from pppd! */
dirkx 0:a259777c45a3 1208 pc->rx.inACCM[i] = (u_char)(asyncmap >> (i * 8));
dirkx 0:a259777c45a3 1209 }
dirkx 0:a259777c45a3 1210 SYS_ARCH_UNPROTECT(lev);
dirkx 0:a259777c45a3 1211 PPPDEBUG(LOG_INFO, ("ppp_recv_config[%d]: inACCM=%X %X %X %X\n",
dirkx 0:a259777c45a3 1212 unit,
dirkx 0:a259777c45a3 1213 pc->rx.inACCM[0], pc->rx.inACCM[1], pc->rx.inACCM[2], pc->rx.inACCM[3]));
dirkx 0:a259777c45a3 1214 }
dirkx 0:a259777c45a3 1215
dirkx 0:a259777c45a3 1216 #if 0
dirkx 0:a259777c45a3 1217 /*
dirkx 0:a259777c45a3 1218 * ccp_test - ask kernel whether a given compression method
dirkx 0:a259777c45a3 1219 * is acceptable for use. Returns 1 if the method and parameters
dirkx 0:a259777c45a3 1220 * are OK, 0 if the method is known but the parameters are not OK
dirkx 0:a259777c45a3 1221 * (e.g. code size should be reduced), or -1 if the method is unknown.
dirkx 0:a259777c45a3 1222 */
dirkx 0:a259777c45a3 1223 int
dirkx 0:a259777c45a3 1224 ccp_test( int unit, int opt_len, int for_transmit, u_char *opt_ptr)
dirkx 0:a259777c45a3 1225 {
dirkx 0:a259777c45a3 1226 return 0; /* XXX Currently no compression. */
dirkx 0:a259777c45a3 1227 }
dirkx 0:a259777c45a3 1228
dirkx 0:a259777c45a3 1229 /*
dirkx 0:a259777c45a3 1230 * ccp_flags_set - inform kernel about the current state of CCP.
dirkx 0:a259777c45a3 1231 */
dirkx 0:a259777c45a3 1232 void
dirkx 0:a259777c45a3 1233 ccp_flags_set(int unit, int isopen, int isup)
dirkx 0:a259777c45a3 1234 {
dirkx 0:a259777c45a3 1235 /* XXX */
dirkx 0:a259777c45a3 1236 }
dirkx 0:a259777c45a3 1237
dirkx 0:a259777c45a3 1238 /*
dirkx 0:a259777c45a3 1239 * ccp_fatal_error - returns 1 if decompression was disabled as a
dirkx 0:a259777c45a3 1240 * result of an error detected after decompression of a packet,
dirkx 0:a259777c45a3 1241 * 0 otherwise. This is necessary because of patent nonsense.
dirkx 0:a259777c45a3 1242 */
dirkx 0:a259777c45a3 1243 int
dirkx 0:a259777c45a3 1244 ccp_fatal_error(int unit)
dirkx 0:a259777c45a3 1245 {
dirkx 0:a259777c45a3 1246 /* XXX */
dirkx 0:a259777c45a3 1247 return 0;
dirkx 0:a259777c45a3 1248 }
dirkx 0:a259777c45a3 1249 #endif
dirkx 0:a259777c45a3 1250
dirkx 0:a259777c45a3 1251 /*
dirkx 0:a259777c45a3 1252 * get_idle_time - return how long the link has been idle.
dirkx 0:a259777c45a3 1253 */
dirkx 0:a259777c45a3 1254 int
dirkx 0:a259777c45a3 1255 get_idle_time(int u, struct ppp_idle *ip)
dirkx 0:a259777c45a3 1256 {
dirkx 0:a259777c45a3 1257 /* XXX */
dirkx 0:a259777c45a3 1258 LWIP_UNUSED_ARG(u);
dirkx 0:a259777c45a3 1259 LWIP_UNUSED_ARG(ip);
dirkx 0:a259777c45a3 1260
dirkx 0:a259777c45a3 1261 return 0;
dirkx 0:a259777c45a3 1262 }
dirkx 0:a259777c45a3 1263
dirkx 0:a259777c45a3 1264
dirkx 0:a259777c45a3 1265 /*
dirkx 0:a259777c45a3 1266 * Return user specified netmask, modified by any mask we might determine
dirkx 0:a259777c45a3 1267 * for address `addr' (in network byte order).
dirkx 0:a259777c45a3 1268 * Here we scan through the system's list of interfaces, looking for
dirkx 0:a259777c45a3 1269 * any non-point-to-point interfaces which might appear to be on the same
dirkx 0:a259777c45a3 1270 * network as `addr'. If we find any, we OR in their netmask to the
dirkx 0:a259777c45a3 1271 * user-specified netmask.
dirkx 0:a259777c45a3 1272 */
dirkx 0:a259777c45a3 1273 u32_t
dirkx 0:a259777c45a3 1274 GetMask(u32_t addr)
dirkx 0:a259777c45a3 1275 {
dirkx 0:a259777c45a3 1276 u32_t mask, nmask;
dirkx 0:a259777c45a3 1277
dirkx 0:a259777c45a3 1278 htonl(addr);
dirkx 0:a259777c45a3 1279 if (IP_CLASSA(addr)) { /* determine network mask for address class */
dirkx 0:a259777c45a3 1280 nmask = IP_CLASSA_NET;
dirkx 0:a259777c45a3 1281 } else if (IP_CLASSB(addr)) {
dirkx 0:a259777c45a3 1282 nmask = IP_CLASSB_NET;
dirkx 0:a259777c45a3 1283 } else {
dirkx 0:a259777c45a3 1284 nmask = IP_CLASSC_NET;
dirkx 0:a259777c45a3 1285 }
dirkx 0:a259777c45a3 1286
dirkx 0:a259777c45a3 1287 /* class D nets are disallowed by bad_ip_adrs */
dirkx 0:a259777c45a3 1288 mask = subnetMask | htonl(nmask);
dirkx 0:a259777c45a3 1289
dirkx 0:a259777c45a3 1290 /* XXX
dirkx 0:a259777c45a3 1291 * Scan through the system's network interfaces.
dirkx 0:a259777c45a3 1292 * Get each netmask and OR them into our mask.
dirkx 0:a259777c45a3 1293 */
dirkx 0:a259777c45a3 1294
dirkx 0:a259777c45a3 1295 return mask;
dirkx 0:a259777c45a3 1296 }
dirkx 0:a259777c45a3 1297
dirkx 0:a259777c45a3 1298 /*
dirkx 0:a259777c45a3 1299 * sifvjcomp - config tcp header compression
dirkx 0:a259777c45a3 1300 */
dirkx 0:a259777c45a3 1301 int
dirkx 0:a259777c45a3 1302 sifvjcomp(int pd, int vjcomp, u8_t cidcomp, u8_t maxcid)
dirkx 0:a259777c45a3 1303 {
dirkx 0:a259777c45a3 1304 #if PPPOS_SUPPORT && VJ_SUPPORT
dirkx 0:a259777c45a3 1305 PPPControl *pc = &pppControl[pd];
dirkx 0:a259777c45a3 1306
dirkx 0:a259777c45a3 1307 pc->vjEnabled = vjcomp;
dirkx 0:a259777c45a3 1308 pc->vjComp.compressSlot = cidcomp;
dirkx 0:a259777c45a3 1309 pc->vjComp.maxSlotIndex = maxcid;
dirkx 0:a259777c45a3 1310 PPPDEBUG(LOG_INFO, ("sifvjcomp: VJ compress enable=%d slot=%d max slot=%d\n",
dirkx 0:a259777c45a3 1311 vjcomp, cidcomp, maxcid));
dirkx 0:a259777c45a3 1312 #else /* PPPOS_SUPPORT && VJ_SUPPORT */
dirkx 0:a259777c45a3 1313 LWIP_UNUSED_ARG(pd);
dirkx 0:a259777c45a3 1314 LWIP_UNUSED_ARG(vjcomp);
dirkx 0:a259777c45a3 1315 LWIP_UNUSED_ARG(cidcomp);
dirkx 0:a259777c45a3 1316 LWIP_UNUSED_ARG(maxcid);
dirkx 0:a259777c45a3 1317 #endif /* PPPOS_SUPPORT && VJ_SUPPORT */
dirkx 0:a259777c45a3 1318
dirkx 0:a259777c45a3 1319 return 0;
dirkx 0:a259777c45a3 1320 }
dirkx 0:a259777c45a3 1321
dirkx 0:a259777c45a3 1322 /*
dirkx 0:a259777c45a3 1323 * pppnetifNetifInit - netif init callback
dirkx 0:a259777c45a3 1324 */
dirkx 0:a259777c45a3 1325 static err_t
dirkx 0:a259777c45a3 1326 pppnetifNetifInit(struct netif *netif)
dirkx 0:a259777c45a3 1327 {
dirkx 0:a259777c45a3 1328 netif->name[0] = 'p';
dirkx 0:a259777c45a3 1329 netif->name[1] = 'p';
dirkx 0:a259777c45a3 1330 netif->output = pppnetifOutput;
dirkx 0:a259777c45a3 1331 netif->mtu = pppMTU((int)(size_t)netif->state);
dirkx 0:a259777c45a3 1332 netif->flags = NETIF_FLAG_POINTTOPOINT | NETIF_FLAG_LINK_UP;
dirkx 0:a259777c45a3 1333 #if LWIP_NETIF_HOSTNAME
dirkx 0:a259777c45a3 1334 /* @todo: Initialize interface hostname */
dirkx 0:a259777c45a3 1335 /* netif_set_hostname(netif, "lwip"); */
dirkx 0:a259777c45a3 1336 #endif /* LWIP_NETIF_HOSTNAME */
dirkx 0:a259777c45a3 1337 return ERR_OK;
dirkx 0:a259777c45a3 1338 }
dirkx 0:a259777c45a3 1339
dirkx 0:a259777c45a3 1340
dirkx 0:a259777c45a3 1341 /*
dirkx 0:a259777c45a3 1342 * sifup - Config the interface up and enable IP packets to pass.
dirkx 0:a259777c45a3 1343 */
dirkx 0:a259777c45a3 1344 int
dirkx 0:a259777c45a3 1345 sifup(int pd)
dirkx 0:a259777c45a3 1346 {
dirkx 0:a259777c45a3 1347 PPPControl *pc = &pppControl[pd];
dirkx 0:a259777c45a3 1348 int st = 1;
dirkx 0:a259777c45a3 1349
dirkx 0:a259777c45a3 1350 if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) {
dirkx 0:a259777c45a3 1351 st = 0;
dirkx 0:a259777c45a3 1352 PPPDEBUG(LOG_WARNING, ("sifup[%d]: bad parms\n", pd));
dirkx 0:a259777c45a3 1353 } else {
dirkx 0:a259777c45a3 1354 netif_remove(&pc->netif);
dirkx 0:a259777c45a3 1355 if (netif_add(&pc->netif, &pc->addrs.our_ipaddr, &pc->addrs.netmask,
dirkx 0:a259777c45a3 1356 &pc->addrs.his_ipaddr, (void *)(size_t)pd, pppnetifNetifInit, ip_input)) {
dirkx 0:a259777c45a3 1357 netif_set_up(&pc->netif);
dirkx 0:a259777c45a3 1358 pc->if_up = 1;
dirkx 0:a259777c45a3 1359 pc->errCode = PPPERR_NONE;
dirkx 0:a259777c45a3 1360
dirkx 0:a259777c45a3 1361 PPPDEBUG(LOG_DEBUG, ("sifup: unit %d: linkStatusCB=%p errCode=%d\n", pd, pc->linkStatusCB, pc->errCode));
dirkx 0:a259777c45a3 1362 if (pc->linkStatusCB) {
dirkx 0:a259777c45a3 1363 pc->linkStatusCB(pc->linkStatusCtx, pc->errCode, &pc->addrs);
dirkx 0:a259777c45a3 1364 }
dirkx 0:a259777c45a3 1365 } else {
dirkx 0:a259777c45a3 1366 st = 0;
dirkx 0:a259777c45a3 1367 PPPDEBUG(LOG_ERR, ("sifup[%d]: netif_add failed\n", pd));
dirkx 0:a259777c45a3 1368 }
dirkx 0:a259777c45a3 1369 }
dirkx 0:a259777c45a3 1370
dirkx 0:a259777c45a3 1371 return st;
dirkx 0:a259777c45a3 1372 }
dirkx 0:a259777c45a3 1373
dirkx 0:a259777c45a3 1374 /*
dirkx 0:a259777c45a3 1375 * sifnpmode - Set the mode for handling packets for a given NP.
dirkx 0:a259777c45a3 1376 */
dirkx 0:a259777c45a3 1377 int
dirkx 0:a259777c45a3 1378 sifnpmode(int u, int proto, enum NPmode mode)
dirkx 0:a259777c45a3 1379 {
dirkx 0:a259777c45a3 1380 LWIP_UNUSED_ARG(u);
dirkx 0:a259777c45a3 1381 LWIP_UNUSED_ARG(proto);
dirkx 0:a259777c45a3 1382 LWIP_UNUSED_ARG(mode);
dirkx 0:a259777c45a3 1383 return 0;
dirkx 0:a259777c45a3 1384 }
dirkx 0:a259777c45a3 1385
dirkx 0:a259777c45a3 1386 /*
dirkx 0:a259777c45a3 1387 * sifdown - Config the interface down and disable IP.
dirkx 0:a259777c45a3 1388 */
dirkx 0:a259777c45a3 1389 int
dirkx 0:a259777c45a3 1390 sifdown(int pd)
dirkx 0:a259777c45a3 1391 {
dirkx 0:a259777c45a3 1392 PPPControl *pc = &pppControl[pd];
dirkx 0:a259777c45a3 1393 int st = 1;
dirkx 0:a259777c45a3 1394
dirkx 0:a259777c45a3 1395 if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) {
dirkx 0:a259777c45a3 1396 st = 0;
dirkx 0:a259777c45a3 1397 PPPDEBUG(LOG_WARNING, ("sifdown[%d]: bad parms\n", pd));
dirkx 0:a259777c45a3 1398 } else {
dirkx 0:a259777c45a3 1399 pc->if_up = 0;
dirkx 0:a259777c45a3 1400 /* make sure the netif status callback is called */
dirkx 0:a259777c45a3 1401 netif_set_down(&pc->netif);
dirkx 0:a259777c45a3 1402 netif_remove(&pc->netif);
dirkx 0:a259777c45a3 1403 PPPDEBUG(LOG_DEBUG, ("sifdown: unit %d: linkStatusCB=%p errCode=%d\n", pd, pc->linkStatusCB, pc->errCode));
dirkx 0:a259777c45a3 1404 if (pc->linkStatusCB) {
dirkx 0:a259777c45a3 1405 pc->linkStatusCB(pc->linkStatusCtx, PPPERR_CONNECT, NULL);
dirkx 0:a259777c45a3 1406 }
dirkx 0:a259777c45a3 1407 }
dirkx 0:a259777c45a3 1408 return st;
dirkx 0:a259777c45a3 1409 }
dirkx 0:a259777c45a3 1410
dirkx 0:a259777c45a3 1411 /**
dirkx 0:a259777c45a3 1412 * sifaddr - Config the interface IP addresses and netmask.
dirkx 0:a259777c45a3 1413 * @param pd Interface unit ???
dirkx 0:a259777c45a3 1414 * @param o Our IP address ???
dirkx 0:a259777c45a3 1415 * @param h His IP address ???
dirkx 0:a259777c45a3 1416 * @param m IP subnet mask ???
dirkx 0:a259777c45a3 1417 * @param ns1 Primary DNS
dirkx 0:a259777c45a3 1418 * @param ns2 Secondary DNS
dirkx 0:a259777c45a3 1419 */
dirkx 0:a259777c45a3 1420 int
dirkx 0:a259777c45a3 1421 sifaddr( int pd, u32_t o, u32_t h, u32_t m, u32_t ns1, u32_t ns2)
dirkx 0:a259777c45a3 1422 {
dirkx 0:a259777c45a3 1423 PPPControl *pc = &pppControl[pd];
dirkx 0:a259777c45a3 1424 int st = 1;
dirkx 0:a259777c45a3 1425
dirkx 0:a259777c45a3 1426 if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) {
dirkx 0:a259777c45a3 1427 st = 0;
dirkx 0:a259777c45a3 1428 PPPDEBUG(LOG_WARNING, ("sifup[%d]: bad parms\n", pd));
dirkx 0:a259777c45a3 1429 } else {
dirkx 0:a259777c45a3 1430 SMEMCPY(&pc->addrs.our_ipaddr, &o, sizeof(o));
dirkx 0:a259777c45a3 1431 SMEMCPY(&pc->addrs.his_ipaddr, &h, sizeof(h));
dirkx 0:a259777c45a3 1432 SMEMCPY(&pc->addrs.netmask, &m, sizeof(m));
dirkx 0:a259777c45a3 1433 SMEMCPY(&pc->addrs.dns1, &ns1, sizeof(ns1));
dirkx 0:a259777c45a3 1434 SMEMCPY(&pc->addrs.dns2, &ns2, sizeof(ns2));
dirkx 0:a259777c45a3 1435 }
dirkx 0:a259777c45a3 1436 return st;
dirkx 0:a259777c45a3 1437 }
dirkx 0:a259777c45a3 1438
dirkx 0:a259777c45a3 1439 /**
dirkx 0:a259777c45a3 1440 * cifaddr - Clear the interface IP addresses, and delete routes
dirkx 0:a259777c45a3 1441 * through the interface if possible.
dirkx 0:a259777c45a3 1442 * @param pd Interface unit ???
dirkx 0:a259777c45a3 1443 * @param o Our IP address ???
dirkx 0:a259777c45a3 1444 * @param h IP broadcast address ???
dirkx 0:a259777c45a3 1445 */
dirkx 0:a259777c45a3 1446 int
dirkx 0:a259777c45a3 1447 cifaddr( int pd, u32_t o, u32_t h)
dirkx 0:a259777c45a3 1448 {
dirkx 0:a259777c45a3 1449 PPPControl *pc = &pppControl[pd];
dirkx 0:a259777c45a3 1450 int st = 1;
dirkx 0:a259777c45a3 1451
dirkx 0:a259777c45a3 1452 LWIP_UNUSED_ARG(o);
dirkx 0:a259777c45a3 1453 LWIP_UNUSED_ARG(h);
dirkx 0:a259777c45a3 1454 if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) {
dirkx 0:a259777c45a3 1455 st = 0;
dirkx 0:a259777c45a3 1456 PPPDEBUG(LOG_WARNING, ("sifup[%d]: bad parms\n", pd));
dirkx 0:a259777c45a3 1457 } else {
dirkx 0:a259777c45a3 1458 IP4_ADDR(&pc->addrs.our_ipaddr, 0,0,0,0);
dirkx 0:a259777c45a3 1459 IP4_ADDR(&pc->addrs.his_ipaddr, 0,0,0,0);
dirkx 0:a259777c45a3 1460 IP4_ADDR(&pc->addrs.netmask, 255,255,255,0);
dirkx 0:a259777c45a3 1461 IP4_ADDR(&pc->addrs.dns1, 0,0,0,0);
dirkx 0:a259777c45a3 1462 IP4_ADDR(&pc->addrs.dns2, 0,0,0,0);
dirkx 0:a259777c45a3 1463 }
dirkx 0:a259777c45a3 1464 return st;
dirkx 0:a259777c45a3 1465 }
dirkx 0:a259777c45a3 1466
dirkx 0:a259777c45a3 1467 /*
dirkx 0:a259777c45a3 1468 * sifdefaultroute - assign a default route through the address given.
dirkx 0:a259777c45a3 1469 */
dirkx 0:a259777c45a3 1470 int
dirkx 0:a259777c45a3 1471 sifdefaultroute(int pd, u32_t l, u32_t g)
dirkx 0:a259777c45a3 1472 {
dirkx 0:a259777c45a3 1473 PPPControl *pc = &pppControl[pd];
dirkx 0:a259777c45a3 1474 int st = 1;
dirkx 0:a259777c45a3 1475
dirkx 0:a259777c45a3 1476 LWIP_UNUSED_ARG(l);
dirkx 0:a259777c45a3 1477 LWIP_UNUSED_ARG(g);
dirkx 0:a259777c45a3 1478
dirkx 0:a259777c45a3 1479 if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) {
dirkx 0:a259777c45a3 1480 st = 0;
dirkx 0:a259777c45a3 1481 PPPDEBUG(LOG_WARNING, ("sifup[%d]: bad parms\n", pd));
dirkx 0:a259777c45a3 1482 } else {
dirkx 0:a259777c45a3 1483 netif_set_default(&pc->netif);
dirkx 0:a259777c45a3 1484 }
dirkx 0:a259777c45a3 1485
dirkx 0:a259777c45a3 1486 /* TODO: check how PPP handled the netMask, previously not set by ipSetDefault */
dirkx 0:a259777c45a3 1487
dirkx 0:a259777c45a3 1488 return st;
dirkx 0:a259777c45a3 1489 }
dirkx 0:a259777c45a3 1490
dirkx 0:a259777c45a3 1491 /*
dirkx 0:a259777c45a3 1492 * cifdefaultroute - delete a default route through the address given.
dirkx 0:a259777c45a3 1493 */
dirkx 0:a259777c45a3 1494 int
dirkx 0:a259777c45a3 1495 cifdefaultroute(int pd, u32_t l, u32_t g)
dirkx 0:a259777c45a3 1496 {
dirkx 0:a259777c45a3 1497 PPPControl *pc = &pppControl[pd];
dirkx 0:a259777c45a3 1498 int st = 1;
dirkx 0:a259777c45a3 1499
dirkx 0:a259777c45a3 1500 LWIP_UNUSED_ARG(l);
dirkx 0:a259777c45a3 1501 LWIP_UNUSED_ARG(g);
dirkx 0:a259777c45a3 1502
dirkx 0:a259777c45a3 1503 if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) {
dirkx 0:a259777c45a3 1504 st = 0;
dirkx 0:a259777c45a3 1505 PPPDEBUG(LOG_WARNING, ("sifup[%d]: bad parms\n", pd));
dirkx 0:a259777c45a3 1506 } else {
dirkx 0:a259777c45a3 1507 netif_set_default(NULL);
dirkx 0:a259777c45a3 1508 }
dirkx 0:a259777c45a3 1509
dirkx 0:a259777c45a3 1510 return st;
dirkx 0:a259777c45a3 1511 }
dirkx 0:a259777c45a3 1512
dirkx 0:a259777c45a3 1513 /**********************************/
dirkx 0:a259777c45a3 1514 /*** LOCAL FUNCTION DEFINITIONS ***/
dirkx 0:a259777c45a3 1515 /**********************************/
dirkx 0:a259777c45a3 1516
dirkx 0:a259777c45a3 1517 #if PPPOS_SUPPORT && PPP_INPROC_OWNTHREAD
dirkx 0:a259777c45a3 1518 /* The main PPP process function. This implements the state machine according
dirkx 0:a259777c45a3 1519 * to section 4 of RFC 1661: The Point-To-Point Protocol. */
dirkx 0:a259777c45a3 1520 static void
dirkx 0:a259777c45a3 1521 pppInputThread(void *arg)
dirkx 0:a259777c45a3 1522 {
dirkx 0:a259777c45a3 1523 int count;
dirkx 0:a259777c45a3 1524 PPPControlRx *pcrx = arg;
dirkx 0:a259777c45a3 1525
dirkx 0:a259777c45a3 1526 while (lcp_phase[pcrx->pd] != PHASE_DEAD) {
dirkx 0:a259777c45a3 1527 count = sio_read(pcrx->fd, pcrx->rxbuf, PPPOS_RX_BUFSIZE);
dirkx 0:a259777c45a3 1528 if(count > 0) {
dirkx 0:a259777c45a3 1529 pppInProc(pcrx, pcrx->rxbuf, count);
dirkx 0:a259777c45a3 1530 } else {
dirkx 0:a259777c45a3 1531 /* nothing received, give other tasks a chance to run */
dirkx 0:a259777c45a3 1532 sys_msleep(1);
dirkx 0:a259777c45a3 1533 }
dirkx 0:a259777c45a3 1534 }
dirkx 0:a259777c45a3 1535 }
dirkx 0:a259777c45a3 1536 #endif /* PPPOS_SUPPORT && PPP_INPROC_OWNTHREAD */
dirkx 0:a259777c45a3 1537
dirkx 0:a259777c45a3 1538 #if PPPOE_SUPPORT
dirkx 0:a259777c45a3 1539
dirkx 0:a259777c45a3 1540 void
dirkx 0:a259777c45a3 1541 pppOverEthernetInitFailed(int pd)
dirkx 0:a259777c45a3 1542 {
dirkx 0:a259777c45a3 1543 PPPControl* pc;
dirkx 0:a259777c45a3 1544
dirkx 0:a259777c45a3 1545 pppHup(pd);
dirkx 0:a259777c45a3 1546 pppStop(pd);
dirkx 0:a259777c45a3 1547
dirkx 0:a259777c45a3 1548 pc = &pppControl[pd];
dirkx 0:a259777c45a3 1549 pppoe_destroy(&pc->netif);
dirkx 0:a259777c45a3 1550 pc->openFlag = 0;
dirkx 0:a259777c45a3 1551
dirkx 0:a259777c45a3 1552 if(pc->linkStatusCB) {
dirkx 0:a259777c45a3 1553 pc->linkStatusCB(pc->linkStatusCtx, pc->errCode ? pc->errCode : PPPERR_PROTOCOL, NULL);
dirkx 0:a259777c45a3 1554 }
dirkx 0:a259777c45a3 1555 }
dirkx 0:a259777c45a3 1556
dirkx 0:a259777c45a3 1557 static void
dirkx 0:a259777c45a3 1558 pppOverEthernetLinkStatusCB(int pd, int up)
dirkx 0:a259777c45a3 1559 {
dirkx 0:a259777c45a3 1560 if(up) {
dirkx 0:a259777c45a3 1561 PPPDEBUG(LOG_INFO, ("pppOverEthernetLinkStatusCB: unit %d: Connecting\n", pd));
dirkx 0:a259777c45a3 1562 pppStart(pd);
dirkx 0:a259777c45a3 1563 } else {
dirkx 0:a259777c45a3 1564 pppOverEthernetInitFailed(pd);
dirkx 0:a259777c45a3 1565 }
dirkx 0:a259777c45a3 1566 }
dirkx 0:a259777c45a3 1567 #endif /* PPPOE_SUPPORT */
dirkx 0:a259777c45a3 1568
dirkx 0:a259777c45a3 1569 struct pbuf *
dirkx 0:a259777c45a3 1570 pppSingleBuf(struct pbuf *p)
dirkx 0:a259777c45a3 1571 {
dirkx 0:a259777c45a3 1572 struct pbuf *q, *b;
dirkx 0:a259777c45a3 1573 u_char *pl;
dirkx 0:a259777c45a3 1574
dirkx 0:a259777c45a3 1575 if(p->tot_len == p->len) {
dirkx 0:a259777c45a3 1576 return p;
dirkx 0:a259777c45a3 1577 }
dirkx 0:a259777c45a3 1578
dirkx 0:a259777c45a3 1579 q = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM);
dirkx 0:a259777c45a3 1580 if(!q) {
dirkx 0:a259777c45a3 1581 PPPDEBUG(LOG_ERR,
dirkx 0:a259777c45a3 1582 ("pppSingleBuf: unable to alloc new buf (%d)\n", p->tot_len));
dirkx 0:a259777c45a3 1583 return p; /* live dangerously */
dirkx 0:a259777c45a3 1584 }
dirkx 0:a259777c45a3 1585
dirkx 0:a259777c45a3 1586 for(b = p, pl = (u_char*) q->payload; b != NULL; b = b->next) {
dirkx 0:a259777c45a3 1587 MEMCPY(pl, b->payload, b->len);
dirkx 0:a259777c45a3 1588 pl += b->len;
dirkx 0:a259777c45a3 1589 }
dirkx 0:a259777c45a3 1590
dirkx 0:a259777c45a3 1591 pbuf_free(p);
dirkx 0:a259777c45a3 1592
dirkx 0:a259777c45a3 1593 return q;
dirkx 0:a259777c45a3 1594 }
dirkx 0:a259777c45a3 1595
dirkx 0:a259777c45a3 1596 struct pppInputHeader {
dirkx 0:a259777c45a3 1597 int unit;
dirkx 0:a259777c45a3 1598 u16_t proto;
dirkx 0:a259777c45a3 1599 };
dirkx 0:a259777c45a3 1600
dirkx 0:a259777c45a3 1601 /*
dirkx 0:a259777c45a3 1602 * Pass the processed input packet to the appropriate handler.
dirkx 0:a259777c45a3 1603 * This function and all handlers run in the context of the tcpip_thread
dirkx 0:a259777c45a3 1604 */
dirkx 0:a259777c45a3 1605 static void
dirkx 0:a259777c45a3 1606 pppInput(void *arg)
dirkx 0:a259777c45a3 1607 {
dirkx 0:a259777c45a3 1608 struct pbuf *nb = (struct pbuf *)arg;
dirkx 0:a259777c45a3 1609 u16_t protocol;
dirkx 0:a259777c45a3 1610 int pd;
dirkx 0:a259777c45a3 1611
dirkx 0:a259777c45a3 1612 pd = ((struct pppInputHeader *)nb->payload)->unit;
dirkx 0:a259777c45a3 1613 protocol = ((struct pppInputHeader *)nb->payload)->proto;
dirkx 0:a259777c45a3 1614
dirkx 0:a259777c45a3 1615 if(pbuf_header(nb, -(int)sizeof(struct pppInputHeader))) {
dirkx 0:a259777c45a3 1616 LWIP_ASSERT("pbuf_header failed\n", 0);
dirkx 0:a259777c45a3 1617 goto drop;
dirkx 0:a259777c45a3 1618 }
dirkx 0:a259777c45a3 1619
dirkx 0:a259777c45a3 1620 LINK_STATS_INC(link.recv);
dirkx 0:a259777c45a3 1621 snmp_inc_ifinucastpkts(&pppControl[pd].netif);
dirkx 0:a259777c45a3 1622 snmp_add_ifinoctets(&pppControl[pd].netif, nb->tot_len);
dirkx 0:a259777c45a3 1623
dirkx 0:a259777c45a3 1624 /*
dirkx 0:a259777c45a3 1625 * Toss all non-LCP packets unless LCP is OPEN.
dirkx 0:a259777c45a3 1626 * Until we get past the authentication phase, toss all packets
dirkx 0:a259777c45a3 1627 * except LCP, LQR and authentication packets.
dirkx 0:a259777c45a3 1628 */
dirkx 0:a259777c45a3 1629 if((lcp_phase[pd] <= PHASE_AUTHENTICATE) && (protocol != PPP_LCP)) {
dirkx 0:a259777c45a3 1630 if(!((protocol == PPP_LQR) || (protocol == PPP_PAP) || (protocol == PPP_CHAP)) ||
dirkx 0:a259777c45a3 1631 (lcp_phase[pd] != PHASE_AUTHENTICATE)) {
dirkx 0:a259777c45a3 1632 PPPDEBUG(LOG_INFO, ("pppInput: discarding proto 0x%"X16_F" in phase %d\n", protocol, lcp_phase[pd]));
dirkx 0:a259777c45a3 1633 goto drop;
dirkx 0:a259777c45a3 1634 }
dirkx 0:a259777c45a3 1635 }
dirkx 0:a259777c45a3 1636
dirkx 0:a259777c45a3 1637 switch(protocol) {
dirkx 0:a259777c45a3 1638 case PPP_VJC_COMP: /* VJ compressed TCP */
dirkx 0:a259777c45a3 1639 #if PPPOS_SUPPORT && VJ_SUPPORT
dirkx 0:a259777c45a3 1640 PPPDEBUG(LOG_INFO, ("pppInput[%d]: vj_comp in pbuf len=%d\n", pd, nb->len));
dirkx 0:a259777c45a3 1641 /*
dirkx 0:a259777c45a3 1642 * Clip off the VJ header and prepend the rebuilt TCP/IP header and
dirkx 0:a259777c45a3 1643 * pass the result to IP.
dirkx 0:a259777c45a3 1644 */
dirkx 0:a259777c45a3 1645 if ((vj_uncompress_tcp(&nb, &pppControl[pd].vjComp) >= 0) && (pppControl[pd].netif.input)) {
dirkx 0:a259777c45a3 1646 pppControl[pd].netif.input(nb, &pppControl[pd].netif);
dirkx 0:a259777c45a3 1647 return;
dirkx 0:a259777c45a3 1648 }
dirkx 0:a259777c45a3 1649 /* Something's wrong so drop it. */
dirkx 0:a259777c45a3 1650 PPPDEBUG(LOG_WARNING, ("pppInput[%d]: Dropping VJ compressed\n", pd));
dirkx 0:a259777c45a3 1651 #else /* PPPOS_SUPPORT && VJ_SUPPORT */
dirkx 0:a259777c45a3 1652 /* No handler for this protocol so drop the packet. */
dirkx 0:a259777c45a3 1653 PPPDEBUG(LOG_INFO, ("pppInput[%d]: drop VJ Comp in %d:%s\n", pd, nb->len, nb->payload));
dirkx 0:a259777c45a3 1654 #endif /* PPPOS_SUPPORT && VJ_SUPPORT */
dirkx 0:a259777c45a3 1655 break;
dirkx 0:a259777c45a3 1656
dirkx 0:a259777c45a3 1657 case PPP_VJC_UNCOMP: /* VJ uncompressed TCP */
dirkx 0:a259777c45a3 1658 #if PPPOS_SUPPORT && VJ_SUPPORT
dirkx 0:a259777c45a3 1659 PPPDEBUG(LOG_INFO, ("pppInput[%d]: vj_un in pbuf len=%d\n", pd, nb->len));
dirkx 0:a259777c45a3 1660 /*
dirkx 0:a259777c45a3 1661 * Process the TCP/IP header for VJ header compression and then pass
dirkx 0:a259777c45a3 1662 * the packet to IP.
dirkx 0:a259777c45a3 1663 */
dirkx 0:a259777c45a3 1664 if ((vj_uncompress_uncomp(nb, &pppControl[pd].vjComp) >= 0) && pppControl[pd].netif.input) {
dirkx 0:a259777c45a3 1665 pppControl[pd].netif.input(nb, &pppControl[pd].netif);
dirkx 0:a259777c45a3 1666 return;
dirkx 0:a259777c45a3 1667 }
dirkx 0:a259777c45a3 1668 /* Something's wrong so drop it. */
dirkx 0:a259777c45a3 1669 PPPDEBUG(LOG_WARNING, ("pppInput[%d]: Dropping VJ uncompressed\n", pd));
dirkx 0:a259777c45a3 1670 #else /* PPPOS_SUPPORT && VJ_SUPPORT */
dirkx 0:a259777c45a3 1671 /* No handler for this protocol so drop the packet. */
dirkx 0:a259777c45a3 1672 PPPDEBUG((LOG_INFO,
dirkx 0:a259777c45a3 1673 "pppInput[%d]: drop VJ UnComp in %d:.*H\n",
dirkx 0:a259777c45a3 1674 pd, nb->len, LWIP_MIN(nb->len * 2, 40), nb->payload));
dirkx 0:a259777c45a3 1675 #endif /* PPPOS_SUPPORT && VJ_SUPPORT */
dirkx 0:a259777c45a3 1676 break;
dirkx 0:a259777c45a3 1677
dirkx 0:a259777c45a3 1678 case PPP_IP: /* Internet Protocol */
dirkx 0:a259777c45a3 1679 PPPDEBUG(LOG_INFO, ("pppInput[%d]: ip in pbuf len=%d\n", pd, nb->len));
dirkx 0:a259777c45a3 1680 if (pppControl[pd].netif.input) {
dirkx 0:a259777c45a3 1681 pppControl[pd].netif.input(nb, &pppControl[pd].netif);
dirkx 0:a259777c45a3 1682 return;
dirkx 0:a259777c45a3 1683 }
dirkx 0:a259777c45a3 1684 break;
dirkx 0:a259777c45a3 1685
dirkx 0:a259777c45a3 1686 default: {
dirkx 0:a259777c45a3 1687 struct protent *protp;
dirkx 0:a259777c45a3 1688 int i;
dirkx 0:a259777c45a3 1689
dirkx 0:a259777c45a3 1690 /*
dirkx 0:a259777c45a3 1691 * Upcall the proper protocol input routine.
dirkx 0:a259777c45a3 1692 */
dirkx 0:a259777c45a3 1693 for (i = 0; (protp = ppp_protocols[i]) != NULL; ++i) {
dirkx 0:a259777c45a3 1694 if (protp->protocol == protocol && protp->enabled_flag) {
dirkx 0:a259777c45a3 1695 PPPDEBUG(LOG_INFO, ("pppInput[%d]: %s len=%d\n", pd, protp->name, nb->len));
dirkx 0:a259777c45a3 1696 nb = pppSingleBuf(nb);
dirkx 0:a259777c45a3 1697 (*protp->input)(pd, (u_char*)nb->payload, nb->len);
dirkx 0:a259777c45a3 1698 PPPDEBUG(LOG_DETAIL, ("pppInput[%d]: packet processed\n", pd));
dirkx 0:a259777c45a3 1699 goto out;
dirkx 0:a259777c45a3 1700 }
dirkx 0:a259777c45a3 1701 }
dirkx 0:a259777c45a3 1702
dirkx 0:a259777c45a3 1703 /* No handler for this protocol so reject the packet. */
dirkx 0:a259777c45a3 1704 PPPDEBUG(LOG_INFO, ("pppInput[%d]: rejecting unsupported proto 0x%"X16_F" len=%d\n", pd, protocol, nb->len));
dirkx 0:a259777c45a3 1705 if (pbuf_header(nb, sizeof(protocol))) {
dirkx 0:a259777c45a3 1706 LWIP_ASSERT("pbuf_header failed\n", 0);
dirkx 0:a259777c45a3 1707 goto drop;
dirkx 0:a259777c45a3 1708 }
dirkx 0:a259777c45a3 1709 #if BYTE_ORDER == LITTLE_ENDIAN
dirkx 0:a259777c45a3 1710 protocol = htons(protocol);
dirkx 0:a259777c45a3 1711 SMEMCPY(nb->payload, &protocol, sizeof(protocol));
dirkx 0:a259777c45a3 1712 #endif /* BYTE_ORDER == LITTLE_ENDIAN */
dirkx 0:a259777c45a3 1713 lcp_sprotrej(pd, (u_char*) nb->payload, nb->len);
dirkx 0:a259777c45a3 1714 }
dirkx 0:a259777c45a3 1715 break;
dirkx 0:a259777c45a3 1716 }
dirkx 0:a259777c45a3 1717
dirkx 0:a259777c45a3 1718 drop:
dirkx 0:a259777c45a3 1719 LINK_STATS_INC(link.drop);
dirkx 0:a259777c45a3 1720 snmp_inc_ifindiscards(&pppControl[pd].netif);
dirkx 0:a259777c45a3 1721
dirkx 0:a259777c45a3 1722 out:
dirkx 0:a259777c45a3 1723 pbuf_free(nb);
dirkx 0:a259777c45a3 1724 return;
dirkx 0:a259777c45a3 1725 }
dirkx 0:a259777c45a3 1726
dirkx 0:a259777c45a3 1727 #if PPPOS_SUPPORT
dirkx 0:a259777c45a3 1728 /*
dirkx 0:a259777c45a3 1729 * Drop the input packet.
dirkx 0:a259777c45a3 1730 */
dirkx 0:a259777c45a3 1731 static void
dirkx 0:a259777c45a3 1732 pppDrop(PPPControlRx *pcrx)
dirkx 0:a259777c45a3 1733 {
dirkx 0:a259777c45a3 1734 if (pcrx->inHead != NULL) {
dirkx 0:a259777c45a3 1735 #if 0
dirkx 0:a259777c45a3 1736 PPPDEBUG(LOG_INFO, ("pppDrop: %d:%.*H\n", pcrx->inHead->len, min(60, pcrx->inHead->len * 2), pcrx->inHead->payload));
dirkx 0:a259777c45a3 1737 #endif
dirkx 0:a259777c45a3 1738 PPPDEBUG(LOG_INFO, ("pppDrop: pbuf len=%d, addr %p\n", pcrx->inHead->len, (void*)pcrx->inHead));
dirkx 0:a259777c45a3 1739 if (pcrx->inTail && (pcrx->inTail != pcrx->inHead)) {
dirkx 0:a259777c45a3 1740 pbuf_free(pcrx->inTail);
dirkx 0:a259777c45a3 1741 }
dirkx 0:a259777c45a3 1742 pbuf_free(pcrx->inHead);
dirkx 0:a259777c45a3 1743 pcrx->inHead = NULL;
dirkx 0:a259777c45a3 1744 pcrx->inTail = NULL;
dirkx 0:a259777c45a3 1745 }
dirkx 0:a259777c45a3 1746 #if VJ_SUPPORT
dirkx 0:a259777c45a3 1747 vj_uncompress_err(&pppControl[pcrx->pd].vjComp);
dirkx 0:a259777c45a3 1748 #endif /* VJ_SUPPORT */
dirkx 0:a259777c45a3 1749
dirkx 0:a259777c45a3 1750 LINK_STATS_INC(link.drop);
dirkx 0:a259777c45a3 1751 snmp_inc_ifindiscards(&pppControl[pcrx->pd].netif);
dirkx 0:a259777c45a3 1752 }
dirkx 0:a259777c45a3 1753
dirkx 0:a259777c45a3 1754 /** Pass received raw characters to PPPoS to be decoded. This function is
dirkx 0:a259777c45a3 1755 * thread-safe and can be called from a dedicated RX-thread or from a main-loop.
dirkx 0:a259777c45a3 1756 *
dirkx 0:a259777c45a3 1757 * @param pd PPP descriptor index, returned by pppOpen()
dirkx 0:a259777c45a3 1758 * @param data received data
dirkx 0:a259777c45a3 1759 * @param len length of received data
dirkx 0:a259777c45a3 1760 */
dirkx 0:a259777c45a3 1761 void
dirkx 0:a259777c45a3 1762 pppos_input(int pd, u_char* data, int len)
dirkx 0:a259777c45a3 1763 {
dirkx 0:a259777c45a3 1764 pppInProc(&pppControl[pd].rx, data, len);
dirkx 0:a259777c45a3 1765 }
dirkx 0:a259777c45a3 1766
dirkx 0:a259777c45a3 1767 /**
dirkx 0:a259777c45a3 1768 * Process a received octet string.
dirkx 0:a259777c45a3 1769 */
dirkx 0:a259777c45a3 1770 static void
dirkx 0:a259777c45a3 1771 pppInProc(PPPControlRx *pcrx, u_char *s, int l)
dirkx 0:a259777c45a3 1772 {
dirkx 0:a259777c45a3 1773 struct pbuf *nextNBuf;
dirkx 0:a259777c45a3 1774 u_char curChar;
dirkx 0:a259777c45a3 1775 u_char escaped;
dirkx 0:a259777c45a3 1776 SYS_ARCH_DECL_PROTECT(lev);
dirkx 0:a259777c45a3 1777
dirkx 0:a259777c45a3 1778 PPPDEBUG(LOG_DEBUG, ("pppInProc[%d]: got %d bytes\n", pcrx->pd, l));
dirkx 0:a259777c45a3 1779 while (l-- > 0) {
dirkx 0:a259777c45a3 1780 curChar = *s++;
dirkx 0:a259777c45a3 1781
dirkx 0:a259777c45a3 1782 SYS_ARCH_PROTECT(lev);
dirkx 0:a259777c45a3 1783 escaped = ESCAPE_P(pcrx->inACCM, curChar);
dirkx 0:a259777c45a3 1784 SYS_ARCH_UNPROTECT(lev);
dirkx 0:a259777c45a3 1785 /* Handle special characters. */
dirkx 0:a259777c45a3 1786 if (escaped) {
dirkx 0:a259777c45a3 1787 /* Check for escape sequences. */
dirkx 0:a259777c45a3 1788 /* XXX Note that this does not handle an escaped 0x5d character which
dirkx 0:a259777c45a3 1789 * would appear as an escape character. Since this is an ASCII ']'
dirkx 0:a259777c45a3 1790 * and there is no reason that I know of to escape it, I won't complicate
dirkx 0:a259777c45a3 1791 * the code to handle this case. GLL */
dirkx 0:a259777c45a3 1792 if (curChar == PPP_ESCAPE) {
dirkx 0:a259777c45a3 1793 pcrx->inEscaped = 1;
dirkx 0:a259777c45a3 1794 /* Check for the flag character. */
dirkx 0:a259777c45a3 1795 } else if (curChar == PPP_FLAG) {
dirkx 0:a259777c45a3 1796 /* If this is just an extra flag character, ignore it. */
dirkx 0:a259777c45a3 1797 if (pcrx->inState <= PDADDRESS) {
dirkx 0:a259777c45a3 1798 /* ignore it */;
dirkx 0:a259777c45a3 1799 /* If we haven't received the packet header, drop what has come in. */
dirkx 0:a259777c45a3 1800 } else if (pcrx->inState < PDDATA) {
dirkx 0:a259777c45a3 1801 PPPDEBUG(LOG_WARNING,
dirkx 0:a259777c45a3 1802 ("pppInProc[%d]: Dropping incomplete packet %d\n",
dirkx 0:a259777c45a3 1803 pcrx->pd, pcrx->inState));
dirkx 0:a259777c45a3 1804 LINK_STATS_INC(link.lenerr);
dirkx 0:a259777c45a3 1805 pppDrop(pcrx);
dirkx 0:a259777c45a3 1806 /* If the fcs is invalid, drop the packet. */
dirkx 0:a259777c45a3 1807 } else if (pcrx->inFCS != PPP_GOODFCS) {
dirkx 0:a259777c45a3 1808 PPPDEBUG(LOG_INFO,
dirkx 0:a259777c45a3 1809 ("pppInProc[%d]: Dropping bad fcs 0x%"X16_F" proto=0x%"X16_F"\n",
dirkx 0:a259777c45a3 1810 pcrx->pd, pcrx->inFCS, pcrx->inProtocol));
dirkx 0:a259777c45a3 1811 /* Note: If you get lots of these, check for UART frame errors or try different baud rate */
dirkx 0:a259777c45a3 1812 LINK_STATS_INC(link.chkerr);
dirkx 0:a259777c45a3 1813 pppDrop(pcrx);
dirkx 0:a259777c45a3 1814 /* Otherwise it's a good packet so pass it on. */
dirkx 0:a259777c45a3 1815 } else {
dirkx 0:a259777c45a3 1816 /* Trim off the checksum. */
dirkx 0:a259777c45a3 1817 if(pcrx->inTail->len >= 2) {
dirkx 0:a259777c45a3 1818 pcrx->inTail->len -= 2;
dirkx 0:a259777c45a3 1819
dirkx 0:a259777c45a3 1820 pcrx->inTail->tot_len = pcrx->inTail->len;
dirkx 0:a259777c45a3 1821 if (pcrx->inTail != pcrx->inHead) {
dirkx 0:a259777c45a3 1822 pbuf_cat(pcrx->inHead, pcrx->inTail);
dirkx 0:a259777c45a3 1823 }
dirkx 0:a259777c45a3 1824 } else {
dirkx 0:a259777c45a3 1825 pcrx->inTail->tot_len = pcrx->inTail->len;
dirkx 0:a259777c45a3 1826 if (pcrx->inTail != pcrx->inHead) {
dirkx 0:a259777c45a3 1827 pbuf_cat(pcrx->inHead, pcrx->inTail);
dirkx 0:a259777c45a3 1828 }
dirkx 0:a259777c45a3 1829
dirkx 0:a259777c45a3 1830 pbuf_realloc(pcrx->inHead, pcrx->inHead->tot_len - 2);
dirkx 0:a259777c45a3 1831 }
dirkx 0:a259777c45a3 1832
dirkx 0:a259777c45a3 1833 /* Dispatch the packet thereby consuming it. */
dirkx 0:a259777c45a3 1834 #if PPP_INPROC_MULTITHREADED
dirkx 0:a259777c45a3 1835 if(tcpip_callback_with_block(pppInput, pcrx->inHead, 0) != ERR_OK) {
dirkx 0:a259777c45a3 1836 PPPDEBUG(LOG_ERR, ("pppInProc[%d]: tcpip_callback() failed, dropping packet\n", pcrx->pd));
dirkx 0:a259777c45a3 1837 pbuf_free(pcrx->inHead);
dirkx 0:a259777c45a3 1838 LINK_STATS_INC(link.drop);
dirkx 0:a259777c45a3 1839 snmp_inc_ifindiscards(&pppControl[pcrx->pd].netif);
dirkx 0:a259777c45a3 1840 }
dirkx 0:a259777c45a3 1841 #else /* PPP_INPROC_MULTITHREADED */
dirkx 0:a259777c45a3 1842 pppInput(pcrx->inHead);
dirkx 0:a259777c45a3 1843 #endif /* PPP_INPROC_MULTITHREADED */
dirkx 0:a259777c45a3 1844 pcrx->inHead = NULL;
dirkx 0:a259777c45a3 1845 pcrx->inTail = NULL;
dirkx 0:a259777c45a3 1846 }
dirkx 0:a259777c45a3 1847
dirkx 0:a259777c45a3 1848 /* Prepare for a new packet. */
dirkx 0:a259777c45a3 1849 pcrx->inFCS = PPP_INITFCS;
dirkx 0:a259777c45a3 1850 pcrx->inState = PDADDRESS;
dirkx 0:a259777c45a3 1851 pcrx->inEscaped = 0;
dirkx 0:a259777c45a3 1852 /* Other characters are usually control characters that may have
dirkx 0:a259777c45a3 1853 * been inserted by the physical layer so here we just drop them. */
dirkx 0:a259777c45a3 1854 } else {
dirkx 0:a259777c45a3 1855 PPPDEBUG(LOG_WARNING,
dirkx 0:a259777c45a3 1856 ("pppInProc[%d]: Dropping ACCM char <%d>\n", pcrx->pd, curChar));
dirkx 0:a259777c45a3 1857 }
dirkx 0:a259777c45a3 1858 /* Process other characters. */
dirkx 0:a259777c45a3 1859 } else {
dirkx 0:a259777c45a3 1860 /* Unencode escaped characters. */
dirkx 0:a259777c45a3 1861 if (pcrx->inEscaped) {
dirkx 0:a259777c45a3 1862 pcrx->inEscaped = 0;
dirkx 0:a259777c45a3 1863 curChar ^= PPP_TRANS;
dirkx 0:a259777c45a3 1864 }
dirkx 0:a259777c45a3 1865
dirkx 0:a259777c45a3 1866 /* Process character relative to current state. */
dirkx 0:a259777c45a3 1867 switch(pcrx->inState) {
dirkx 0:a259777c45a3 1868 case PDIDLE: /* Idle state - waiting. */
dirkx 0:a259777c45a3 1869 /* Drop the character if it's not 0xff
dirkx 0:a259777c45a3 1870 * we would have processed a flag character above. */
dirkx 0:a259777c45a3 1871 if (curChar != PPP_ALLSTATIONS) {
dirkx 0:a259777c45a3 1872 break;
dirkx 0:a259777c45a3 1873 }
dirkx 0:a259777c45a3 1874
dirkx 0:a259777c45a3 1875 /* Fall through */
dirkx 0:a259777c45a3 1876 case PDSTART: /* Process start flag. */
dirkx 0:a259777c45a3 1877 /* Prepare for a new packet. */
dirkx 0:a259777c45a3 1878 pcrx->inFCS = PPP_INITFCS;
dirkx 0:a259777c45a3 1879
dirkx 0:a259777c45a3 1880 /* Fall through */
dirkx 0:a259777c45a3 1881 case PDADDRESS: /* Process address field. */
dirkx 0:a259777c45a3 1882 if (curChar == PPP_ALLSTATIONS) {
dirkx 0:a259777c45a3 1883 pcrx->inState = PDCONTROL;
dirkx 0:a259777c45a3 1884 break;
dirkx 0:a259777c45a3 1885 }
dirkx 0:a259777c45a3 1886 /* Else assume compressed address and control fields so
dirkx 0:a259777c45a3 1887 * fall through to get the protocol... */
dirkx 0:a259777c45a3 1888 case PDCONTROL: /* Process control field. */
dirkx 0:a259777c45a3 1889 /* If we don't get a valid control code, restart. */
dirkx 0:a259777c45a3 1890 if (curChar == PPP_UI) {
dirkx 0:a259777c45a3 1891 pcrx->inState = PDPROTOCOL1;
dirkx 0:a259777c45a3 1892 break;
dirkx 0:a259777c45a3 1893 }
dirkx 0:a259777c45a3 1894 #if 0
dirkx 0:a259777c45a3 1895 else {
dirkx 0:a259777c45a3 1896 PPPDEBUG((LOG_WARNING,
dirkx 0:a259777c45a3 1897 "pppInProc[%d]: Invalid control <%d>\n", pcrx->pd, curChar));
dirkx 0:a259777c45a3 1898 pcrx->inState = PDSTART;
dirkx 0:a259777c45a3 1899 }
dirkx 0:a259777c45a3 1900 #endif
dirkx 0:a259777c45a3 1901 case PDPROTOCOL1: /* Process protocol field 1. */
dirkx 0:a259777c45a3 1902 /* If the lower bit is set, this is the end of the protocol
dirkx 0:a259777c45a3 1903 * field. */
dirkx 0:a259777c45a3 1904 if (curChar & 1) {
dirkx 0:a259777c45a3 1905 pcrx->inProtocol = curChar;
dirkx 0:a259777c45a3 1906 pcrx->inState = PDDATA;
dirkx 0:a259777c45a3 1907 } else {
dirkx 0:a259777c45a3 1908 pcrx->inProtocol = (u_int)curChar << 8;
dirkx 0:a259777c45a3 1909 pcrx->inState = PDPROTOCOL2;
dirkx 0:a259777c45a3 1910 }
dirkx 0:a259777c45a3 1911 break;
dirkx 0:a259777c45a3 1912 case PDPROTOCOL2: /* Process protocol field 2. */
dirkx 0:a259777c45a3 1913 pcrx->inProtocol |= curChar;
dirkx 0:a259777c45a3 1914 pcrx->inState = PDDATA;
dirkx 0:a259777c45a3 1915 break;
dirkx 0:a259777c45a3 1916 case PDDATA: /* Process data byte. */
dirkx 0:a259777c45a3 1917 /* Make space to receive processed data. */
dirkx 0:a259777c45a3 1918 if (pcrx->inTail == NULL || pcrx->inTail->len == PBUF_POOL_BUFSIZE) {
dirkx 0:a259777c45a3 1919 if(pcrx->inTail) {
dirkx 0:a259777c45a3 1920 pcrx->inTail->tot_len = pcrx->inTail->len;
dirkx 0:a259777c45a3 1921 if (pcrx->inTail != pcrx->inHead) {
dirkx 0:a259777c45a3 1922 pbuf_cat(pcrx->inHead, pcrx->inTail);
dirkx 0:a259777c45a3 1923 }
dirkx 0:a259777c45a3 1924 }
dirkx 0:a259777c45a3 1925 /* If we haven't started a packet, we need a packet header. */
dirkx 0:a259777c45a3 1926 nextNBuf = pbuf_alloc(PBUF_RAW, 0, PBUF_POOL);
dirkx 0:a259777c45a3 1927 if (nextNBuf == NULL) {
dirkx 0:a259777c45a3 1928 /* No free buffers. Drop the input packet and let the
dirkx 0:a259777c45a3 1929 * higher layers deal with it. Continue processing
dirkx 0:a259777c45a3 1930 * the received pbuf chain in case a new packet starts. */
dirkx 0:a259777c45a3 1931 PPPDEBUG(LOG_ERR, ("pppInProc[%d]: NO FREE MBUFS!\n", pcrx->pd));
dirkx 0:a259777c45a3 1932 LINK_STATS_INC(link.memerr);
dirkx 0:a259777c45a3 1933 pppDrop(pcrx);
dirkx 0:a259777c45a3 1934 pcrx->inState = PDSTART; /* Wait for flag sequence. */
dirkx 0:a259777c45a3 1935 break;
dirkx 0:a259777c45a3 1936 }
dirkx 0:a259777c45a3 1937 if (pcrx->inHead == NULL) {
dirkx 0:a259777c45a3 1938 struct pppInputHeader *pih = (struct pppInputHeader*) nextNBuf->payload;
dirkx 0:a259777c45a3 1939
dirkx 0:a259777c45a3 1940 pih->unit = pcrx->pd;
dirkx 0:a259777c45a3 1941 pih->proto = pcrx->inProtocol;
dirkx 0:a259777c45a3 1942
dirkx 0:a259777c45a3 1943 nextNBuf->len += sizeof(*pih);
dirkx 0:a259777c45a3 1944
dirkx 0:a259777c45a3 1945 pcrx->inHead = nextNBuf;
dirkx 0:a259777c45a3 1946 }
dirkx 0:a259777c45a3 1947 pcrx->inTail = nextNBuf;
dirkx 0:a259777c45a3 1948 }
dirkx 0:a259777c45a3 1949 /* Load character into buffer. */
dirkx 0:a259777c45a3 1950 ((u_char*)pcrx->inTail->payload)[pcrx->inTail->len++] = curChar;
dirkx 0:a259777c45a3 1951 break;
dirkx 0:a259777c45a3 1952 }
dirkx 0:a259777c45a3 1953
dirkx 0:a259777c45a3 1954 /* update the frame check sequence number. */
dirkx 0:a259777c45a3 1955 pcrx->inFCS = PPP_FCS(pcrx->inFCS, curChar);
dirkx 0:a259777c45a3 1956 }
dirkx 0:a259777c45a3 1957 } /* while (l-- > 0), all bytes processed */
dirkx 0:a259777c45a3 1958
dirkx 0:a259777c45a3 1959 avRandomize();
dirkx 0:a259777c45a3 1960 }
dirkx 0:a259777c45a3 1961 #endif /* PPPOS_SUPPORT */
dirkx 0:a259777c45a3 1962
dirkx 0:a259777c45a3 1963 #if PPPOE_SUPPORT
dirkx 0:a259777c45a3 1964 void
dirkx 0:a259777c45a3 1965 pppInProcOverEthernet(int pd, struct pbuf *pb)
dirkx 0:a259777c45a3 1966 {
dirkx 0:a259777c45a3 1967 struct pppInputHeader *pih;
dirkx 0:a259777c45a3 1968 u16_t inProtocol;
dirkx 0:a259777c45a3 1969
dirkx 0:a259777c45a3 1970 if(pb->len < sizeof(inProtocol)) {
dirkx 0:a259777c45a3 1971 PPPDEBUG(LOG_ERR, ("pppInProcOverEthernet: too small for protocol field\n"));
dirkx 0:a259777c45a3 1972 goto drop;
dirkx 0:a259777c45a3 1973 }
dirkx 0:a259777c45a3 1974
dirkx 0:a259777c45a3 1975 inProtocol = (((u8_t *)pb->payload)[0] << 8) | ((u8_t*)pb->payload)[1];
dirkx 0:a259777c45a3 1976
dirkx 0:a259777c45a3 1977 /* make room for pppInputHeader - should not fail */
dirkx 0:a259777c45a3 1978 if (pbuf_header(pb, sizeof(*pih) - sizeof(inProtocol)) != 0) {
dirkx 0:a259777c45a3 1979 PPPDEBUG(LOG_ERR, ("pppInProcOverEthernet: could not allocate room for header\n"));
dirkx 0:a259777c45a3 1980 goto drop;
dirkx 0:a259777c45a3 1981 }
dirkx 0:a259777c45a3 1982
dirkx 0:a259777c45a3 1983 pih = pb->payload;
dirkx 0:a259777c45a3 1984
dirkx 0:a259777c45a3 1985 pih->unit = pd;
dirkx 0:a259777c45a3 1986 pih->proto = inProtocol;
dirkx 0:a259777c45a3 1987
dirkx 0:a259777c45a3 1988 /* Dispatch the packet thereby consuming it. */
dirkx 0:a259777c45a3 1989 pppInput(pb);
dirkx 0:a259777c45a3 1990 return;
dirkx 0:a259777c45a3 1991
dirkx 0:a259777c45a3 1992 drop:
dirkx 0:a259777c45a3 1993 LINK_STATS_INC(link.drop);
dirkx 0:a259777c45a3 1994 snmp_inc_ifindiscards(&pppControl[pd].netif);
dirkx 0:a259777c45a3 1995 pbuf_free(pb);
dirkx 0:a259777c45a3 1996 return;
dirkx 0:a259777c45a3 1997 }
dirkx 0:a259777c45a3 1998 #endif /* PPPOE_SUPPORT */
dirkx 0:a259777c45a3 1999
dirkx 0:a259777c45a3 2000 #if LWIP_NETIF_STATUS_CALLBACK
dirkx 0:a259777c45a3 2001 /** Set the status callback of a PPP's netif
dirkx 0:a259777c45a3 2002 *
dirkx 0:a259777c45a3 2003 * @param pd The PPP descriptor returned by pppOpen()
dirkx 0:a259777c45a3 2004 * @param status_callback pointer to the status callback function
dirkx 0:a259777c45a3 2005 *
dirkx 0:a259777c45a3 2006 * @see netif_set_status_callback
dirkx 0:a259777c45a3 2007 */
dirkx 0:a259777c45a3 2008 void
dirkx 0:a259777c45a3 2009 ppp_set_netif_statuscallback(int pd, netif_status_callback_fn status_callback)
dirkx 0:a259777c45a3 2010 {
dirkx 0:a259777c45a3 2011 netif_set_status_callback(&pppControl[pd].netif, status_callback);
dirkx 0:a259777c45a3 2012 }
dirkx 0:a259777c45a3 2013 #endif /* LWIP_NETIF_STATUS_CALLBACK */
dirkx 0:a259777c45a3 2014
dirkx 0:a259777c45a3 2015 #if LWIP_NETIF_LINK_CALLBACK
dirkx 0:a259777c45a3 2016 /** Set the link callback of a PPP's netif
dirkx 0:a259777c45a3 2017 *
dirkx 0:a259777c45a3 2018 * @param pd The PPP descriptor returned by pppOpen()
dirkx 0:a259777c45a3 2019 * @param link_callback pointer to the link callback function
dirkx 0:a259777c45a3 2020 *
dirkx 0:a259777c45a3 2021 * @see netif_set_link_callback
dirkx 0:a259777c45a3 2022 */
dirkx 0:a259777c45a3 2023 void
dirkx 0:a259777c45a3 2024 ppp_set_netif_linkcallback(int pd, netif_status_callback_fn link_callback)
dirkx 0:a259777c45a3 2025 {
dirkx 0:a259777c45a3 2026 netif_set_link_callback(&pppControl[pd].netif, link_callback);
dirkx 0:a259777c45a3 2027 }
dirkx 0:a259777c45a3 2028 #endif /* LWIP_NETIF_LINK_CALLBACK */
dirkx 0:a259777c45a3 2029
dirkx 0:a259777c45a3 2030 #endif /* PPP_SUPPORT */