Integrating the ublox LISA C200 modem

Fork of SprintUSBModemHTTPClientTest by Donatien Garnier

Committer:
sam_grove
Date:
Thu Sep 26 00:44:20 2013 -0500
Revision:
5:3f93dd1d4cb3
Exported program and replaced contents of the repo with the source
to build and debug using keil mdk. Libs NOT upto date are lwip, lwip-sys
and socket. these have newer versions under mbed_official but were starting
from a know working point

Who changed what in which revision?

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