Ethernet test for ECE 4180 and others to find your IP address and do a simple HTTP GET request over port 80.

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Committer:
mkersh3
Date:
Thu Apr 04 05:26:09 2013 +0000
Revision:
0:e7ca326e76ee
Ethernet Test for ECE4180 and others to find their IP Address and do a simple HTTP GET request over port 80.

Who changed what in which revision?

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