wip

Dependents:   EthernetInterface_vz

Fork of lwip by VZTECH

Committer:
mbed_official
Date:
Fri Jun 22 09:25:39 2012 +0000
Revision:
0:51ac1d130fd4
Child:
4:f71f5d9d5846
Initial import from lwip-1.4.0: http://download.savannah.gnu.org/releases/lwip/lwip-1.4.0.zip

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