SNMP agent attached to SPI slave

Dependencies:   mbed

Committer:
lorcansmith
Date:
Mon Aug 13 15:07:40 2012 +0000
Revision:
0:2a53a4c3238c
v1.1 release includes ioAlarm traps

Who changed what in which revision?

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