Donatien Garnier / lwip_bleedingedge

Fork of lwip by mbed official

Committer:
donatien
Date:
Wed Mar 12 20:22:30 2014 +0000
Revision:
15:e5bb25d5506f
Parent:
4:f71f5d9d5846
Child:
16:a61070aa2e98
PPP race condition fix; Reinit of PPP protocols properly; Backports from 1.4.1

Who changed what in which revision?

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