HTTPClient using static IP

Dependencies:   mbed

Committer:
mr_q
Date:
Mon May 30 11:53:37 2011 +0000
Revision:
0:d8f2f7d5f31b
v0.01 Draft

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mr_q 0:d8f2f7d5f31b 1 /*****************************************************************************
mr_q 0:d8f2f7d5f31b 2 * ppp_oe.c - PPP Over Ethernet implementation for lwIP.
mr_q 0:d8f2f7d5f31b 3 *
mr_q 0:d8f2f7d5f31b 4 * Copyright (c) 2006 by Marc Boucher, Services Informatiques (MBSI) inc.
mr_q 0:d8f2f7d5f31b 5 *
mr_q 0:d8f2f7d5f31b 6 * The authors hereby grant permission to use, copy, modify, distribute,
mr_q 0:d8f2f7d5f31b 7 * and license this software and its documentation for any purpose, provided
mr_q 0:d8f2f7d5f31b 8 * that existing copyright notices are retained in all copies and that this
mr_q 0:d8f2f7d5f31b 9 * notice and the following disclaimer are included verbatim in any
mr_q 0:d8f2f7d5f31b 10 * distributions. No written agreement, license, or royalty fee is required
mr_q 0:d8f2f7d5f31b 11 * for any of the authorized uses.
mr_q 0:d8f2f7d5f31b 12 *
mr_q 0:d8f2f7d5f31b 13 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
mr_q 0:d8f2f7d5f31b 14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
mr_q 0:d8f2f7d5f31b 15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
mr_q 0:d8f2f7d5f31b 16 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
mr_q 0:d8f2f7d5f31b 17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
mr_q 0:d8f2f7d5f31b 18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
mr_q 0:d8f2f7d5f31b 19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
mr_q 0:d8f2f7d5f31b 20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
mr_q 0:d8f2f7d5f31b 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
mr_q 0:d8f2f7d5f31b 22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mr_q 0:d8f2f7d5f31b 23 *
mr_q 0:d8f2f7d5f31b 24 ******************************************************************************
mr_q 0:d8f2f7d5f31b 25 * REVISION HISTORY
mr_q 0:d8f2f7d5f31b 26 *
mr_q 0:d8f2f7d5f31b 27 * 06-01-01 Marc Boucher <marc@mbsi.ca>
mr_q 0:d8f2f7d5f31b 28 * Ported to lwIP.
mr_q 0:d8f2f7d5f31b 29 *****************************************************************************/
mr_q 0:d8f2f7d5f31b 30
mr_q 0:d8f2f7d5f31b 31
mr_q 0:d8f2f7d5f31b 32
mr_q 0:d8f2f7d5f31b 33 /* based on NetBSD: if_pppoe.c,v 1.64 2006/01/31 23:50:15 martin Exp */
mr_q 0:d8f2f7d5f31b 34
mr_q 0:d8f2f7d5f31b 35 /*-
mr_q 0:d8f2f7d5f31b 36 * Copyright (c) 2002 The NetBSD Foundation, Inc.
mr_q 0:d8f2f7d5f31b 37 * All rights reserved.
mr_q 0:d8f2f7d5f31b 38 *
mr_q 0:d8f2f7d5f31b 39 * This code is derived from software contributed to The NetBSD Foundation
mr_q 0:d8f2f7d5f31b 40 * by Martin Husemann <martin@NetBSD.org>.
mr_q 0:d8f2f7d5f31b 41 *
mr_q 0:d8f2f7d5f31b 42 * Redistribution and use in source and binary forms, with or without
mr_q 0:d8f2f7d5f31b 43 * modification, are permitted provided that the following conditions
mr_q 0:d8f2f7d5f31b 44 * are met:
mr_q 0:d8f2f7d5f31b 45 * 1. Redistributions of source code must retain the above copyright
mr_q 0:d8f2f7d5f31b 46 * notice, this list of conditions and the following disclaimer.
mr_q 0:d8f2f7d5f31b 47 * 2. Redistributions in binary form must reproduce the above copyright
mr_q 0:d8f2f7d5f31b 48 * notice, this list of conditions and the following disclaimer in the
mr_q 0:d8f2f7d5f31b 49 * documentation and/or other materials provided with the distribution.
mr_q 0:d8f2f7d5f31b 50 * 3. All advertising materials mentioning features or use of this software
mr_q 0:d8f2f7d5f31b 51 * must display the following acknowledgement:
mr_q 0:d8f2f7d5f31b 52 * This product includes software developed by the NetBSD
mr_q 0:d8f2f7d5f31b 53 * Foundation, Inc. and its contributors.
mr_q 0:d8f2f7d5f31b 54 * 4. Neither the name of The NetBSD Foundation nor the names of its
mr_q 0:d8f2f7d5f31b 55 * contributors may be used to endorse or promote products derived
mr_q 0:d8f2f7d5f31b 56 * from this software without specific prior written permission.
mr_q 0:d8f2f7d5f31b 57 *
mr_q 0:d8f2f7d5f31b 58 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
mr_q 0:d8f2f7d5f31b 59 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
mr_q 0:d8f2f7d5f31b 60 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
mr_q 0:d8f2f7d5f31b 61 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
mr_q 0:d8f2f7d5f31b 62 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
mr_q 0:d8f2f7d5f31b 63 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
mr_q 0:d8f2f7d5f31b 64 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
mr_q 0:d8f2f7d5f31b 65 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
mr_q 0:d8f2f7d5f31b 66 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
mr_q 0:d8f2f7d5f31b 67 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mr_q 0:d8f2f7d5f31b 68 * POSSIBILITY OF SUCH DAMAGE.
mr_q 0:d8f2f7d5f31b 69 */
mr_q 0:d8f2f7d5f31b 70
mr_q 0:d8f2f7d5f31b 71 #include "lwip/opt.h"
mr_q 0:d8f2f7d5f31b 72
mr_q 0:d8f2f7d5f31b 73 #if PPPOE_SUPPORT /* don't build if not configured for use in lwipopts.h */
mr_q 0:d8f2f7d5f31b 74
mr_q 0:d8f2f7d5f31b 75 #include "netif/ppp_oe.h"
mr_q 0:d8f2f7d5f31b 76
mr_q 0:d8f2f7d5f31b 77 #include "ppp.h"
mr_q 0:d8f2f7d5f31b 78 #include "pppdebug.h"
mr_q 0:d8f2f7d5f31b 79
mr_q 0:d8f2f7d5f31b 80 #include "lwip/timers.h"
mr_q 0:d8f2f7d5f31b 81 #include "lwip/memp.h"
mr_q 0:d8f2f7d5f31b 82
mr_q 0:d8f2f7d5f31b 83 #include <string.h>
mr_q 0:d8f2f7d5f31b 84 #include <stdio.h>
mr_q 0:d8f2f7d5f31b 85
mr_q 0:d8f2f7d5f31b 86
mr_q 0:d8f2f7d5f31b 87 /* Add a 16 bit unsigned value to a buffer pointed to by PTR */
mr_q 0:d8f2f7d5f31b 88 #define PPPOE_ADD_16(PTR, VAL) \
mr_q 0:d8f2f7d5f31b 89 *(PTR)++ = (u8_t)((VAL) / 256); \
mr_q 0:d8f2f7d5f31b 90 *(PTR)++ = (u8_t)((VAL) % 256)
mr_q 0:d8f2f7d5f31b 91
mr_q 0:d8f2f7d5f31b 92 /* Add a complete PPPoE header to the buffer pointed to by PTR */
mr_q 0:d8f2f7d5f31b 93 #define PPPOE_ADD_HEADER(PTR, CODE, SESS, LEN) \
mr_q 0:d8f2f7d5f31b 94 *(PTR)++ = PPPOE_VERTYPE; \
mr_q 0:d8f2f7d5f31b 95 *(PTR)++ = (CODE); \
mr_q 0:d8f2f7d5f31b 96 PPPOE_ADD_16(PTR, SESS); \
mr_q 0:d8f2f7d5f31b 97 PPPOE_ADD_16(PTR, LEN)
mr_q 0:d8f2f7d5f31b 98
mr_q 0:d8f2f7d5f31b 99 #define PPPOE_DISC_TIMEOUT (5*1000) /* base for quick timeout calculation */
mr_q 0:d8f2f7d5f31b 100 #define PPPOE_SLOW_RETRY (60*1000) /* persistent retry interval */
mr_q 0:d8f2f7d5f31b 101 #define PPPOE_DISC_MAXPADI 4 /* retry PADI four times (quickly) */
mr_q 0:d8f2f7d5f31b 102 #define PPPOE_DISC_MAXPADR 2 /* retry PADR twice */
mr_q 0:d8f2f7d5f31b 103
mr_q 0:d8f2f7d5f31b 104 #ifdef PPPOE_SERVER
mr_q 0:d8f2f7d5f31b 105 #error "PPPOE_SERVER is not yet supported under lwIP!"
mr_q 0:d8f2f7d5f31b 106 /* from if_spppsubr.c */
mr_q 0:d8f2f7d5f31b 107 #define IFF_PASSIVE IFF_LINK0 /* wait passively for connection */
mr_q 0:d8f2f7d5f31b 108 #endif
mr_q 0:d8f2f7d5f31b 109
mr_q 0:d8f2f7d5f31b 110 #ifndef PPPOE_ERRORSTRING_LEN
mr_q 0:d8f2f7d5f31b 111 #define PPPOE_ERRORSTRING_LEN 64
mr_q 0:d8f2f7d5f31b 112 #endif
mr_q 0:d8f2f7d5f31b 113 static char pppoe_error_tmp[PPPOE_ERRORSTRING_LEN];
mr_q 0:d8f2f7d5f31b 114
mr_q 0:d8f2f7d5f31b 115
mr_q 0:d8f2f7d5f31b 116 /* input routines */
mr_q 0:d8f2f7d5f31b 117 static void pppoe_dispatch_disc_pkt(struct netif *, struct pbuf *);
mr_q 0:d8f2f7d5f31b 118
mr_q 0:d8f2f7d5f31b 119 /* management routines */
mr_q 0:d8f2f7d5f31b 120 static int pppoe_do_disconnect(struct pppoe_softc *);
mr_q 0:d8f2f7d5f31b 121 static void pppoe_abort_connect(struct pppoe_softc *);
mr_q 0:d8f2f7d5f31b 122 static void pppoe_clear_softc(struct pppoe_softc *, const char *);
mr_q 0:d8f2f7d5f31b 123
mr_q 0:d8f2f7d5f31b 124 /* internal timeout handling */
mr_q 0:d8f2f7d5f31b 125 static void pppoe_timeout(void *);
mr_q 0:d8f2f7d5f31b 126
mr_q 0:d8f2f7d5f31b 127 /* sending actual protocol controll packets */
mr_q 0:d8f2f7d5f31b 128 static err_t pppoe_send_padi(struct pppoe_softc *);
mr_q 0:d8f2f7d5f31b 129 static err_t pppoe_send_padr(struct pppoe_softc *);
mr_q 0:d8f2f7d5f31b 130 #ifdef PPPOE_SERVER
mr_q 0:d8f2f7d5f31b 131 static err_t pppoe_send_pado(struct pppoe_softc *);
mr_q 0:d8f2f7d5f31b 132 static err_t pppoe_send_pads(struct pppoe_softc *);
mr_q 0:d8f2f7d5f31b 133 #endif
mr_q 0:d8f2f7d5f31b 134 static err_t pppoe_send_padt(struct netif *, u_int, const u8_t *);
mr_q 0:d8f2f7d5f31b 135
mr_q 0:d8f2f7d5f31b 136 /* internal helper functions */
mr_q 0:d8f2f7d5f31b 137 static struct pppoe_softc * pppoe_find_softc_by_session(u_int, struct netif *);
mr_q 0:d8f2f7d5f31b 138 static struct pppoe_softc * pppoe_find_softc_by_hunique(u8_t *, size_t, struct netif *);
mr_q 0:d8f2f7d5f31b 139
mr_q 0:d8f2f7d5f31b 140 /** linked list of created pppoe interfaces */
mr_q 0:d8f2f7d5f31b 141 static struct pppoe_softc *pppoe_softc_list;
mr_q 0:d8f2f7d5f31b 142
mr_q 0:d8f2f7d5f31b 143 err_t
mr_q 0:d8f2f7d5f31b 144 pppoe_create(struct netif *ethif, int pd, void (*linkStatusCB)(int pd, int up), struct pppoe_softc **scptr)
mr_q 0:d8f2f7d5f31b 145 {
mr_q 0:d8f2f7d5f31b 146 struct pppoe_softc *sc;
mr_q 0:d8f2f7d5f31b 147
mr_q 0:d8f2f7d5f31b 148 sc = (struct pppoe_softc *)memp_malloc(MEMP_PPPOE_IF);
mr_q 0:d8f2f7d5f31b 149 if (sc == NULL) {
mr_q 0:d8f2f7d5f31b 150 *scptr = NULL;
mr_q 0:d8f2f7d5f31b 151 return ERR_MEM;
mr_q 0:d8f2f7d5f31b 152 }
mr_q 0:d8f2f7d5f31b 153 memset(sc, 0, sizeof(struct pppoe_softc));
mr_q 0:d8f2f7d5f31b 154
mr_q 0:d8f2f7d5f31b 155 /* changed to real address later */
mr_q 0:d8f2f7d5f31b 156 MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
mr_q 0:d8f2f7d5f31b 157
mr_q 0:d8f2f7d5f31b 158 sc->sc_pd = pd;
mr_q 0:d8f2f7d5f31b 159 sc->sc_linkStatusCB = linkStatusCB;
mr_q 0:d8f2f7d5f31b 160 sc->sc_ethif = ethif;
mr_q 0:d8f2f7d5f31b 161
mr_q 0:d8f2f7d5f31b 162 /* put the new interface at the head of the list */
mr_q 0:d8f2f7d5f31b 163 sc->next = pppoe_softc_list;
mr_q 0:d8f2f7d5f31b 164 pppoe_softc_list = sc;
mr_q 0:d8f2f7d5f31b 165
mr_q 0:d8f2f7d5f31b 166 *scptr = sc;
mr_q 0:d8f2f7d5f31b 167
mr_q 0:d8f2f7d5f31b 168 return ERR_OK;
mr_q 0:d8f2f7d5f31b 169 }
mr_q 0:d8f2f7d5f31b 170
mr_q 0:d8f2f7d5f31b 171 err_t
mr_q 0:d8f2f7d5f31b 172 pppoe_destroy(struct netif *ifp)
mr_q 0:d8f2f7d5f31b 173 {
mr_q 0:d8f2f7d5f31b 174 struct pppoe_softc *sc, *prev = NULL;
mr_q 0:d8f2f7d5f31b 175
mr_q 0:d8f2f7d5f31b 176 for (sc = pppoe_softc_list; sc != NULL; prev = sc, sc = sc->next) {
mr_q 0:d8f2f7d5f31b 177 if (sc->sc_ethif == ifp) {
mr_q 0:d8f2f7d5f31b 178 break;
mr_q 0:d8f2f7d5f31b 179 }
mr_q 0:d8f2f7d5f31b 180 }
mr_q 0:d8f2f7d5f31b 181
mr_q 0:d8f2f7d5f31b 182 if(!(sc && (sc->sc_ethif == ifp))) {
mr_q 0:d8f2f7d5f31b 183 return ERR_IF;
mr_q 0:d8f2f7d5f31b 184 }
mr_q 0:d8f2f7d5f31b 185
mr_q 0:d8f2f7d5f31b 186 sys_untimeout(pppoe_timeout, sc);
mr_q 0:d8f2f7d5f31b 187 if (prev == NULL) {
mr_q 0:d8f2f7d5f31b 188 /* remove sc from the head of the list */
mr_q 0:d8f2f7d5f31b 189 pppoe_softc_list = sc->next;
mr_q 0:d8f2f7d5f31b 190 } else {
mr_q 0:d8f2f7d5f31b 191 /* remove sc from the list */
mr_q 0:d8f2f7d5f31b 192 prev->next = sc->next;
mr_q 0:d8f2f7d5f31b 193 }
mr_q 0:d8f2f7d5f31b 194
mr_q 0:d8f2f7d5f31b 195 #ifdef PPPOE_TODO
mr_q 0:d8f2f7d5f31b 196 if (sc->sc_concentrator_name) {
mr_q 0:d8f2f7d5f31b 197 mem_free(sc->sc_concentrator_name);
mr_q 0:d8f2f7d5f31b 198 }
mr_q 0:d8f2f7d5f31b 199 if (sc->sc_service_name) {
mr_q 0:d8f2f7d5f31b 200 mem_free(sc->sc_service_name);
mr_q 0:d8f2f7d5f31b 201 }
mr_q 0:d8f2f7d5f31b 202 #endif /* PPPOE_TODO */
mr_q 0:d8f2f7d5f31b 203 memp_free(MEMP_PPPOE_IF, sc);
mr_q 0:d8f2f7d5f31b 204
mr_q 0:d8f2f7d5f31b 205 return ERR_OK;
mr_q 0:d8f2f7d5f31b 206 }
mr_q 0:d8f2f7d5f31b 207
mr_q 0:d8f2f7d5f31b 208 /*
mr_q 0:d8f2f7d5f31b 209 * Find the interface handling the specified session.
mr_q 0:d8f2f7d5f31b 210 * Note: O(number of sessions open), this is a client-side only, mean
mr_q 0:d8f2f7d5f31b 211 * and lean implementation, so number of open sessions typically should
mr_q 0:d8f2f7d5f31b 212 * be 1.
mr_q 0:d8f2f7d5f31b 213 */
mr_q 0:d8f2f7d5f31b 214 static struct pppoe_softc *
mr_q 0:d8f2f7d5f31b 215 pppoe_find_softc_by_session(u_int session, struct netif *rcvif)
mr_q 0:d8f2f7d5f31b 216 {
mr_q 0:d8f2f7d5f31b 217 struct pppoe_softc *sc;
mr_q 0:d8f2f7d5f31b 218
mr_q 0:d8f2f7d5f31b 219 if (session == 0) {
mr_q 0:d8f2f7d5f31b 220 return NULL;
mr_q 0:d8f2f7d5f31b 221 }
mr_q 0:d8f2f7d5f31b 222
mr_q 0:d8f2f7d5f31b 223 for (sc = pppoe_softc_list; sc != NULL; sc = sc->next) {
mr_q 0:d8f2f7d5f31b 224 if (sc->sc_state == PPPOE_STATE_SESSION
mr_q 0:d8f2f7d5f31b 225 && sc->sc_session == session) {
mr_q 0:d8f2f7d5f31b 226 if (sc->sc_ethif == rcvif) {
mr_q 0:d8f2f7d5f31b 227 return sc;
mr_q 0:d8f2f7d5f31b 228 } else {
mr_q 0:d8f2f7d5f31b 229 return NULL;
mr_q 0:d8f2f7d5f31b 230 }
mr_q 0:d8f2f7d5f31b 231 }
mr_q 0:d8f2f7d5f31b 232 }
mr_q 0:d8f2f7d5f31b 233 return NULL;
mr_q 0:d8f2f7d5f31b 234 }
mr_q 0:d8f2f7d5f31b 235
mr_q 0:d8f2f7d5f31b 236 /* Check host unique token passed and return appropriate softc pointer,
mr_q 0:d8f2f7d5f31b 237 * or NULL if token is bogus. */
mr_q 0:d8f2f7d5f31b 238 static struct pppoe_softc *
mr_q 0:d8f2f7d5f31b 239 pppoe_find_softc_by_hunique(u8_t *token, size_t len, struct netif *rcvif)
mr_q 0:d8f2f7d5f31b 240 {
mr_q 0:d8f2f7d5f31b 241 struct pppoe_softc *sc, *t;
mr_q 0:d8f2f7d5f31b 242
mr_q 0:d8f2f7d5f31b 243 if (pppoe_softc_list == NULL) {
mr_q 0:d8f2f7d5f31b 244 return NULL;
mr_q 0:d8f2f7d5f31b 245 }
mr_q 0:d8f2f7d5f31b 246
mr_q 0:d8f2f7d5f31b 247 if (len != sizeof sc) {
mr_q 0:d8f2f7d5f31b 248 return NULL;
mr_q 0:d8f2f7d5f31b 249 }
mr_q 0:d8f2f7d5f31b 250 MEMCPY(&t, token, len);
mr_q 0:d8f2f7d5f31b 251
mr_q 0:d8f2f7d5f31b 252 for (sc = pppoe_softc_list; sc != NULL; sc = sc->next) {
mr_q 0:d8f2f7d5f31b 253 if (sc == t) {
mr_q 0:d8f2f7d5f31b 254 break;
mr_q 0:d8f2f7d5f31b 255 }
mr_q 0:d8f2f7d5f31b 256 }
mr_q 0:d8f2f7d5f31b 257
mr_q 0:d8f2f7d5f31b 258 if (sc == NULL) {
mr_q 0:d8f2f7d5f31b 259 PPPDEBUG(LOG_DEBUG, ("pppoe: alien host unique tag, no session found\n"));
mr_q 0:d8f2f7d5f31b 260 return NULL;
mr_q 0:d8f2f7d5f31b 261 }
mr_q 0:d8f2f7d5f31b 262
mr_q 0:d8f2f7d5f31b 263 /* should be safe to access *sc now */
mr_q 0:d8f2f7d5f31b 264 if (sc->sc_state < PPPOE_STATE_PADI_SENT || sc->sc_state >= PPPOE_STATE_SESSION) {
mr_q 0:d8f2f7d5f31b 265 printf("%c%c%"U16_F": host unique tag found, but it belongs to a connection in state %d\n",
mr_q 0:d8f2f7d5f31b 266 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, sc->sc_state);
mr_q 0:d8f2f7d5f31b 267 return NULL;
mr_q 0:d8f2f7d5f31b 268 }
mr_q 0:d8f2f7d5f31b 269 if (sc->sc_ethif != rcvif) {
mr_q 0:d8f2f7d5f31b 270 printf("%c%c%"U16_F": wrong interface, not accepting host unique\n",
mr_q 0:d8f2f7d5f31b 271 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num);
mr_q 0:d8f2f7d5f31b 272 return NULL;
mr_q 0:d8f2f7d5f31b 273 }
mr_q 0:d8f2f7d5f31b 274 return sc;
mr_q 0:d8f2f7d5f31b 275 }
mr_q 0:d8f2f7d5f31b 276
mr_q 0:d8f2f7d5f31b 277 static void
mr_q 0:d8f2f7d5f31b 278 pppoe_linkstatus_up(struct pppoe_softc *sc)
mr_q 0:d8f2f7d5f31b 279 {
mr_q 0:d8f2f7d5f31b 280 sc->sc_linkStatusCB(sc->sc_pd, 1);
mr_q 0:d8f2f7d5f31b 281 }
mr_q 0:d8f2f7d5f31b 282
mr_q 0:d8f2f7d5f31b 283 /* analyze and handle a single received packet while not in session state */
mr_q 0:d8f2f7d5f31b 284 static void
mr_q 0:d8f2f7d5f31b 285 pppoe_dispatch_disc_pkt(struct netif *netif, struct pbuf *pb)
mr_q 0:d8f2f7d5f31b 286 {
mr_q 0:d8f2f7d5f31b 287 u16_t tag, len;
mr_q 0:d8f2f7d5f31b 288 u16_t session, plen;
mr_q 0:d8f2f7d5f31b 289 struct pppoe_softc *sc;
mr_q 0:d8f2f7d5f31b 290 const char *err_msg;
mr_q 0:d8f2f7d5f31b 291 char devname[6];
mr_q 0:d8f2f7d5f31b 292 u8_t *ac_cookie;
mr_q 0:d8f2f7d5f31b 293 u16_t ac_cookie_len;
mr_q 0:d8f2f7d5f31b 294 #ifdef PPPOE_SERVER
mr_q 0:d8f2f7d5f31b 295 u8_t *hunique;
mr_q 0:d8f2f7d5f31b 296 size_t hunique_len;
mr_q 0:d8f2f7d5f31b 297 #endif
mr_q 0:d8f2f7d5f31b 298 struct pppoehdr *ph;
mr_q 0:d8f2f7d5f31b 299 struct pppoetag pt;
mr_q 0:d8f2f7d5f31b 300 int off, err, errortag;
mr_q 0:d8f2f7d5f31b 301 struct eth_hdr *ethhdr;
mr_q 0:d8f2f7d5f31b 302
mr_q 0:d8f2f7d5f31b 303 pb = pppSingleBuf(pb);
mr_q 0:d8f2f7d5f31b 304
mr_q 0:d8f2f7d5f31b 305 strcpy(devname, "pppoe"); /* as long as we don't know which instance */
mr_q 0:d8f2f7d5f31b 306 err_msg = NULL;
mr_q 0:d8f2f7d5f31b 307 errortag = 0;
mr_q 0:d8f2f7d5f31b 308 if (pb->len < sizeof(*ethhdr)) {
mr_q 0:d8f2f7d5f31b 309 goto done;
mr_q 0:d8f2f7d5f31b 310 }
mr_q 0:d8f2f7d5f31b 311 ethhdr = (struct eth_hdr *)pb->payload;
mr_q 0:d8f2f7d5f31b 312 off = sizeof(*ethhdr);
mr_q 0:d8f2f7d5f31b 313
mr_q 0:d8f2f7d5f31b 314 ac_cookie = NULL;
mr_q 0:d8f2f7d5f31b 315 ac_cookie_len = 0;
mr_q 0:d8f2f7d5f31b 316 #ifdef PPPOE_SERVER
mr_q 0:d8f2f7d5f31b 317 hunique = NULL;
mr_q 0:d8f2f7d5f31b 318 hunique_len = 0;
mr_q 0:d8f2f7d5f31b 319 #endif
mr_q 0:d8f2f7d5f31b 320 session = 0;
mr_q 0:d8f2f7d5f31b 321 if (pb->len - off < PPPOE_HEADERLEN) {
mr_q 0:d8f2f7d5f31b 322 printf("pppoe: packet too short: %d\n", pb->len);
mr_q 0:d8f2f7d5f31b 323 goto done;
mr_q 0:d8f2f7d5f31b 324 }
mr_q 0:d8f2f7d5f31b 325
mr_q 0:d8f2f7d5f31b 326 ph = (struct pppoehdr *) (ethhdr + 1);
mr_q 0:d8f2f7d5f31b 327 if (ph->vertype != PPPOE_VERTYPE) {
mr_q 0:d8f2f7d5f31b 328 printf("pppoe: unknown version/type packet: 0x%x\n", ph->vertype);
mr_q 0:d8f2f7d5f31b 329 goto done;
mr_q 0:d8f2f7d5f31b 330 }
mr_q 0:d8f2f7d5f31b 331 session = ntohs(ph->session);
mr_q 0:d8f2f7d5f31b 332 plen = ntohs(ph->plen);
mr_q 0:d8f2f7d5f31b 333 off += sizeof(*ph);
mr_q 0:d8f2f7d5f31b 334
mr_q 0:d8f2f7d5f31b 335 if (plen + off > pb->len) {
mr_q 0:d8f2f7d5f31b 336 printf("pppoe: packet content does not fit: data available = %d, packet size = %u\n",
mr_q 0:d8f2f7d5f31b 337 pb->len - off, plen);
mr_q 0:d8f2f7d5f31b 338 goto done;
mr_q 0:d8f2f7d5f31b 339 }
mr_q 0:d8f2f7d5f31b 340 if(pb->tot_len == pb->len) {
mr_q 0:d8f2f7d5f31b 341 pb->tot_len = pb->len = (u16_t)off + plen; /* ignore trailing garbage */
mr_q 0:d8f2f7d5f31b 342 }
mr_q 0:d8f2f7d5f31b 343 tag = 0;
mr_q 0:d8f2f7d5f31b 344 len = 0;
mr_q 0:d8f2f7d5f31b 345 sc = NULL;
mr_q 0:d8f2f7d5f31b 346 while (off + sizeof(pt) <= pb->len) {
mr_q 0:d8f2f7d5f31b 347 MEMCPY(&pt, (u8_t*)pb->payload + off, sizeof(pt));
mr_q 0:d8f2f7d5f31b 348 tag = ntohs(pt.tag);
mr_q 0:d8f2f7d5f31b 349 len = ntohs(pt.len);
mr_q 0:d8f2f7d5f31b 350 if (off + sizeof(pt) + len > pb->len) {
mr_q 0:d8f2f7d5f31b 351 printf("pppoe: tag 0x%x len 0x%x is too long\n", tag, len);
mr_q 0:d8f2f7d5f31b 352 goto done;
mr_q 0:d8f2f7d5f31b 353 }
mr_q 0:d8f2f7d5f31b 354 switch (tag) {
mr_q 0:d8f2f7d5f31b 355 case PPPOE_TAG_EOL:
mr_q 0:d8f2f7d5f31b 356 goto breakbreak;
mr_q 0:d8f2f7d5f31b 357 case PPPOE_TAG_SNAME:
mr_q 0:d8f2f7d5f31b 358 break; /* ignored */
mr_q 0:d8f2f7d5f31b 359 case PPPOE_TAG_ACNAME:
mr_q 0:d8f2f7d5f31b 360 break; /* ignored */
mr_q 0:d8f2f7d5f31b 361 case PPPOE_TAG_HUNIQUE:
mr_q 0:d8f2f7d5f31b 362 if (sc != NULL) {
mr_q 0:d8f2f7d5f31b 363 break;
mr_q 0:d8f2f7d5f31b 364 }
mr_q 0:d8f2f7d5f31b 365 #ifdef PPPOE_SERVER
mr_q 0:d8f2f7d5f31b 366 hunique = (u8_t*)pb->payload + off + sizeof(pt);
mr_q 0:d8f2f7d5f31b 367 hunique_len = len;
mr_q 0:d8f2f7d5f31b 368 #endif
mr_q 0:d8f2f7d5f31b 369 sc = pppoe_find_softc_by_hunique((u8_t*)pb->payload + off + sizeof(pt), len, netif);
mr_q 0:d8f2f7d5f31b 370 if (sc != NULL) {
mr_q 0:d8f2f7d5f31b 371 snprintf(devname, sizeof(devname), "%c%c%"U16_F, sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num);
mr_q 0:d8f2f7d5f31b 372 }
mr_q 0:d8f2f7d5f31b 373 break;
mr_q 0:d8f2f7d5f31b 374 case PPPOE_TAG_ACCOOKIE:
mr_q 0:d8f2f7d5f31b 375 if (ac_cookie == NULL) {
mr_q 0:d8f2f7d5f31b 376 ac_cookie = (u8_t*)pb->payload + off + sizeof(pt);
mr_q 0:d8f2f7d5f31b 377 ac_cookie_len = len;
mr_q 0:d8f2f7d5f31b 378 }
mr_q 0:d8f2f7d5f31b 379 break;
mr_q 0:d8f2f7d5f31b 380 case PPPOE_TAG_SNAME_ERR:
mr_q 0:d8f2f7d5f31b 381 err_msg = "SERVICE NAME ERROR";
mr_q 0:d8f2f7d5f31b 382 errortag = 1;
mr_q 0:d8f2f7d5f31b 383 break;
mr_q 0:d8f2f7d5f31b 384 case PPPOE_TAG_ACSYS_ERR:
mr_q 0:d8f2f7d5f31b 385 err_msg = "AC SYSTEM ERROR";
mr_q 0:d8f2f7d5f31b 386 errortag = 1;
mr_q 0:d8f2f7d5f31b 387 break;
mr_q 0:d8f2f7d5f31b 388 case PPPOE_TAG_GENERIC_ERR:
mr_q 0:d8f2f7d5f31b 389 err_msg = "GENERIC ERROR";
mr_q 0:d8f2f7d5f31b 390 errortag = 1;
mr_q 0:d8f2f7d5f31b 391 break;
mr_q 0:d8f2f7d5f31b 392 }
mr_q 0:d8f2f7d5f31b 393 if (err_msg) {
mr_q 0:d8f2f7d5f31b 394 if (errortag && len) {
mr_q 0:d8f2f7d5f31b 395 u16_t error_len = LWIP_MIN(len, sizeof(pppoe_error_tmp)-1);
mr_q 0:d8f2f7d5f31b 396 strncpy(pppoe_error_tmp, (char*)pb->payload + off + sizeof(pt), error_len);
mr_q 0:d8f2f7d5f31b 397 pppoe_error_tmp[error_len-1] = '\0';
mr_q 0:d8f2f7d5f31b 398 printf("%s: %s: %s\n", devname, err_msg, pppoe_error_tmp);
mr_q 0:d8f2f7d5f31b 399 } else {
mr_q 0:d8f2f7d5f31b 400 printf("%s: %s\n", devname, err_msg);
mr_q 0:d8f2f7d5f31b 401 }
mr_q 0:d8f2f7d5f31b 402 if (errortag) {
mr_q 0:d8f2f7d5f31b 403 goto done;
mr_q 0:d8f2f7d5f31b 404 }
mr_q 0:d8f2f7d5f31b 405 }
mr_q 0:d8f2f7d5f31b 406 off += sizeof(pt) + len;
mr_q 0:d8f2f7d5f31b 407 }
mr_q 0:d8f2f7d5f31b 408
mr_q 0:d8f2f7d5f31b 409 breakbreak:;
mr_q 0:d8f2f7d5f31b 410 switch (ph->code) {
mr_q 0:d8f2f7d5f31b 411 case PPPOE_CODE_PADI:
mr_q 0:d8f2f7d5f31b 412 #ifdef PPPOE_SERVER
mr_q 0:d8f2f7d5f31b 413 /*
mr_q 0:d8f2f7d5f31b 414 * got service name, concentrator name, and/or host unique.
mr_q 0:d8f2f7d5f31b 415 * ignore if we have no interfaces with IFF_PASSIVE|IFF_UP.
mr_q 0:d8f2f7d5f31b 416 */
mr_q 0:d8f2f7d5f31b 417 if (LIST_EMPTY(&pppoe_softc_list)) {
mr_q 0:d8f2f7d5f31b 418 goto done;
mr_q 0:d8f2f7d5f31b 419 }
mr_q 0:d8f2f7d5f31b 420 LIST_FOREACH(sc, &pppoe_softc_list, sc_list) {
mr_q 0:d8f2f7d5f31b 421 if (!(sc->sc_sppp.pp_if.if_flags & IFF_UP)) {
mr_q 0:d8f2f7d5f31b 422 continue;
mr_q 0:d8f2f7d5f31b 423 }
mr_q 0:d8f2f7d5f31b 424 if (!(sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE)) {
mr_q 0:d8f2f7d5f31b 425 continue;
mr_q 0:d8f2f7d5f31b 426 }
mr_q 0:d8f2f7d5f31b 427 if (sc->sc_state == PPPOE_STATE_INITIAL) {
mr_q 0:d8f2f7d5f31b 428 break;
mr_q 0:d8f2f7d5f31b 429 }
mr_q 0:d8f2f7d5f31b 430 }
mr_q 0:d8f2f7d5f31b 431 if (sc == NULL) {
mr_q 0:d8f2f7d5f31b 432 /* printf("pppoe: free passive interface is not found\n"); */
mr_q 0:d8f2f7d5f31b 433 goto done;
mr_q 0:d8f2f7d5f31b 434 }
mr_q 0:d8f2f7d5f31b 435 if (hunique) {
mr_q 0:d8f2f7d5f31b 436 if (sc->sc_hunique) {
mr_q 0:d8f2f7d5f31b 437 mem_free(sc->sc_hunique);
mr_q 0:d8f2f7d5f31b 438 }
mr_q 0:d8f2f7d5f31b 439 sc->sc_hunique = mem_malloc(hunique_len);
mr_q 0:d8f2f7d5f31b 440 if (sc->sc_hunique == NULL) {
mr_q 0:d8f2f7d5f31b 441 goto done;
mr_q 0:d8f2f7d5f31b 442 }
mr_q 0:d8f2f7d5f31b 443 sc->sc_hunique_len = hunique_len;
mr_q 0:d8f2f7d5f31b 444 MEMCPY(sc->sc_hunique, hunique, hunique_len);
mr_q 0:d8f2f7d5f31b 445 }
mr_q 0:d8f2f7d5f31b 446 MEMCPY(&sc->sc_dest, eh->ether_shost, sizeof sc->sc_dest);
mr_q 0:d8f2f7d5f31b 447 sc->sc_state = PPPOE_STATE_PADO_SENT;
mr_q 0:d8f2f7d5f31b 448 pppoe_send_pado(sc);
mr_q 0:d8f2f7d5f31b 449 break;
mr_q 0:d8f2f7d5f31b 450 #endif /* PPPOE_SERVER */
mr_q 0:d8f2f7d5f31b 451 case PPPOE_CODE_PADR:
mr_q 0:d8f2f7d5f31b 452 #ifdef PPPOE_SERVER
mr_q 0:d8f2f7d5f31b 453 /*
mr_q 0:d8f2f7d5f31b 454 * get sc from ac_cookie if IFF_PASSIVE
mr_q 0:d8f2f7d5f31b 455 */
mr_q 0:d8f2f7d5f31b 456 if (ac_cookie == NULL) {
mr_q 0:d8f2f7d5f31b 457 /* be quiet if there is not a single pppoe instance */
mr_q 0:d8f2f7d5f31b 458 printf("pppoe: received PADR but not includes ac_cookie\n");
mr_q 0:d8f2f7d5f31b 459 goto done;
mr_q 0:d8f2f7d5f31b 460 }
mr_q 0:d8f2f7d5f31b 461 sc = pppoe_find_softc_by_hunique(ac_cookie, ac_cookie_len, netif);
mr_q 0:d8f2f7d5f31b 462 if (sc == NULL) {
mr_q 0:d8f2f7d5f31b 463 /* be quiet if there is not a single pppoe instance */
mr_q 0:d8f2f7d5f31b 464 if (!LIST_EMPTY(&pppoe_softc_list)) {
mr_q 0:d8f2f7d5f31b 465 printf("pppoe: received PADR but could not find request for it\n");
mr_q 0:d8f2f7d5f31b 466 }
mr_q 0:d8f2f7d5f31b 467 goto done;
mr_q 0:d8f2f7d5f31b 468 }
mr_q 0:d8f2f7d5f31b 469 if (sc->sc_state != PPPOE_STATE_PADO_SENT) {
mr_q 0:d8f2f7d5f31b 470 printf("%c%c%"U16_F": received unexpected PADR\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num);
mr_q 0:d8f2f7d5f31b 471 goto done;
mr_q 0:d8f2f7d5f31b 472 }
mr_q 0:d8f2f7d5f31b 473 if (hunique) {
mr_q 0:d8f2f7d5f31b 474 if (sc->sc_hunique) {
mr_q 0:d8f2f7d5f31b 475 mem_free(sc->sc_hunique);
mr_q 0:d8f2f7d5f31b 476 }
mr_q 0:d8f2f7d5f31b 477 sc->sc_hunique = mem_malloc(hunique_len);
mr_q 0:d8f2f7d5f31b 478 if (sc->sc_hunique == NULL) {
mr_q 0:d8f2f7d5f31b 479 goto done;
mr_q 0:d8f2f7d5f31b 480 }
mr_q 0:d8f2f7d5f31b 481 sc->sc_hunique_len = hunique_len;
mr_q 0:d8f2f7d5f31b 482 MEMCPY(sc->sc_hunique, hunique, hunique_len);
mr_q 0:d8f2f7d5f31b 483 }
mr_q 0:d8f2f7d5f31b 484 pppoe_send_pads(sc);
mr_q 0:d8f2f7d5f31b 485 sc->sc_state = PPPOE_STATE_SESSION;
mr_q 0:d8f2f7d5f31b 486 pppoe_linkstatus_up(sc); /* notify upper layers */
mr_q 0:d8f2f7d5f31b 487 break;
mr_q 0:d8f2f7d5f31b 488 #else
mr_q 0:d8f2f7d5f31b 489 /* ignore, we are no access concentrator */
mr_q 0:d8f2f7d5f31b 490 goto done;
mr_q 0:d8f2f7d5f31b 491 #endif /* PPPOE_SERVER */
mr_q 0:d8f2f7d5f31b 492 case PPPOE_CODE_PADO:
mr_q 0:d8f2f7d5f31b 493 if (sc == NULL) {
mr_q 0:d8f2f7d5f31b 494 /* be quiet if there is not a single pppoe instance */
mr_q 0:d8f2f7d5f31b 495 if (pppoe_softc_list != NULL) {
mr_q 0:d8f2f7d5f31b 496 printf("pppoe: received PADO but could not find request for it\n");
mr_q 0:d8f2f7d5f31b 497 }
mr_q 0:d8f2f7d5f31b 498 goto done;
mr_q 0:d8f2f7d5f31b 499 }
mr_q 0:d8f2f7d5f31b 500 if (sc->sc_state != PPPOE_STATE_PADI_SENT) {
mr_q 0:d8f2f7d5f31b 501 printf("%c%c%"U16_F": received unexpected PADO\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num);
mr_q 0:d8f2f7d5f31b 502 goto done;
mr_q 0:d8f2f7d5f31b 503 }
mr_q 0:d8f2f7d5f31b 504 if (ac_cookie) {
mr_q 0:d8f2f7d5f31b 505 sc->sc_ac_cookie_len = ac_cookie_len;
mr_q 0:d8f2f7d5f31b 506 MEMCPY(sc->sc_ac_cookie, ac_cookie, ac_cookie_len);
mr_q 0:d8f2f7d5f31b 507 }
mr_q 0:d8f2f7d5f31b 508 MEMCPY(&sc->sc_dest, ethhdr->src.addr, sizeof(sc->sc_dest.addr));
mr_q 0:d8f2f7d5f31b 509 sys_untimeout(pppoe_timeout, sc);
mr_q 0:d8f2f7d5f31b 510 sc->sc_padr_retried = 0;
mr_q 0:d8f2f7d5f31b 511 sc->sc_state = PPPOE_STATE_PADR_SENT;
mr_q 0:d8f2f7d5f31b 512 if ((err = pppoe_send_padr(sc)) != 0) {
mr_q 0:d8f2f7d5f31b 513 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": failed to send PADR, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err));
mr_q 0:d8f2f7d5f31b 514 }
mr_q 0:d8f2f7d5f31b 515 sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padr_retried), pppoe_timeout, sc);
mr_q 0:d8f2f7d5f31b 516 break;
mr_q 0:d8f2f7d5f31b 517 case PPPOE_CODE_PADS:
mr_q 0:d8f2f7d5f31b 518 if (sc == NULL) {
mr_q 0:d8f2f7d5f31b 519 goto done;
mr_q 0:d8f2f7d5f31b 520 }
mr_q 0:d8f2f7d5f31b 521 sc->sc_session = session;
mr_q 0:d8f2f7d5f31b 522 sys_untimeout(pppoe_timeout, sc);
mr_q 0:d8f2f7d5f31b 523 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": session 0x%x connected\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, session));
mr_q 0:d8f2f7d5f31b 524 sc->sc_state = PPPOE_STATE_SESSION;
mr_q 0:d8f2f7d5f31b 525 pppoe_linkstatus_up(sc); /* notify upper layers */
mr_q 0:d8f2f7d5f31b 526 break;
mr_q 0:d8f2f7d5f31b 527 case PPPOE_CODE_PADT:
mr_q 0:d8f2f7d5f31b 528 if (sc == NULL) {
mr_q 0:d8f2f7d5f31b 529 goto done;
mr_q 0:d8f2f7d5f31b 530 }
mr_q 0:d8f2f7d5f31b 531 pppoe_clear_softc(sc, "received PADT");
mr_q 0:d8f2f7d5f31b 532 break;
mr_q 0:d8f2f7d5f31b 533 default:
mr_q 0:d8f2f7d5f31b 534 if(sc) {
mr_q 0:d8f2f7d5f31b 535 printf("%c%c%"U16_F": unknown code (0x%"X16_F") session = 0x%"X16_F"\n",
mr_q 0:d8f2f7d5f31b 536 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num,
mr_q 0:d8f2f7d5f31b 537 (u16_t)ph->code, session);
mr_q 0:d8f2f7d5f31b 538 } else {
mr_q 0:d8f2f7d5f31b 539 printf("pppoe: unknown code (0x%"X16_F") session = 0x%"X16_F"\n", (u16_t)ph->code, session);
mr_q 0:d8f2f7d5f31b 540 }
mr_q 0:d8f2f7d5f31b 541 break;
mr_q 0:d8f2f7d5f31b 542 }
mr_q 0:d8f2f7d5f31b 543
mr_q 0:d8f2f7d5f31b 544 done:
mr_q 0:d8f2f7d5f31b 545 pbuf_free(pb);
mr_q 0:d8f2f7d5f31b 546 return;
mr_q 0:d8f2f7d5f31b 547 }
mr_q 0:d8f2f7d5f31b 548
mr_q 0:d8f2f7d5f31b 549 void
mr_q 0:d8f2f7d5f31b 550 pppoe_disc_input(struct netif *netif, struct pbuf *p)
mr_q 0:d8f2f7d5f31b 551 {
mr_q 0:d8f2f7d5f31b 552 /* avoid error messages if there is not a single pppoe instance */
mr_q 0:d8f2f7d5f31b 553 if (pppoe_softc_list != NULL) {
mr_q 0:d8f2f7d5f31b 554 pppoe_dispatch_disc_pkt(netif, p);
mr_q 0:d8f2f7d5f31b 555 } else {
mr_q 0:d8f2f7d5f31b 556 pbuf_free(p);
mr_q 0:d8f2f7d5f31b 557 }
mr_q 0:d8f2f7d5f31b 558 }
mr_q 0:d8f2f7d5f31b 559
mr_q 0:d8f2f7d5f31b 560 void
mr_q 0:d8f2f7d5f31b 561 pppoe_data_input(struct netif *netif, struct pbuf *pb)
mr_q 0:d8f2f7d5f31b 562 {
mr_q 0:d8f2f7d5f31b 563 u16_t session, plen;
mr_q 0:d8f2f7d5f31b 564 struct pppoe_softc *sc;
mr_q 0:d8f2f7d5f31b 565 struct pppoehdr *ph;
mr_q 0:d8f2f7d5f31b 566 #ifdef PPPOE_TERM_UNKNOWN_SESSIONS
mr_q 0:d8f2f7d5f31b 567 u8_t shost[ETHER_ADDR_LEN];
mr_q 0:d8f2f7d5f31b 568 #endif
mr_q 0:d8f2f7d5f31b 569
mr_q 0:d8f2f7d5f31b 570 #ifdef PPPOE_TERM_UNKNOWN_SESSIONS
mr_q 0:d8f2f7d5f31b 571 MEMCPY(shost, ((struct eth_hdr *)pb->payload)->src.addr, sizeof(shost));
mr_q 0:d8f2f7d5f31b 572 #endif
mr_q 0:d8f2f7d5f31b 573 if (pbuf_header(pb, -(int)sizeof(struct eth_hdr)) != 0) {
mr_q 0:d8f2f7d5f31b 574 /* bail out */
mr_q 0:d8f2f7d5f31b 575 PPPDEBUG(LOG_ERR, ("pppoe_data_input: pbuf_header failed\n"));
mr_q 0:d8f2f7d5f31b 576 LINK_STATS_INC(link.lenerr);
mr_q 0:d8f2f7d5f31b 577 goto drop;
mr_q 0:d8f2f7d5f31b 578 }
mr_q 0:d8f2f7d5f31b 579
mr_q 0:d8f2f7d5f31b 580 pb = pppSingleBuf (pb);
mr_q 0:d8f2f7d5f31b 581
mr_q 0:d8f2f7d5f31b 582 if (pb->len <= PPPOE_HEADERLEN) {
mr_q 0:d8f2f7d5f31b 583 printf("pppoe (data): dropping too short packet: %d bytes\n", pb->len);
mr_q 0:d8f2f7d5f31b 584 goto drop;
mr_q 0:d8f2f7d5f31b 585 }
mr_q 0:d8f2f7d5f31b 586
mr_q 0:d8f2f7d5f31b 587 if (pb->len < sizeof(*ph)) {
mr_q 0:d8f2f7d5f31b 588 printf("pppoe_data_input: could not get PPPoE header\n");
mr_q 0:d8f2f7d5f31b 589 goto drop;
mr_q 0:d8f2f7d5f31b 590 }
mr_q 0:d8f2f7d5f31b 591 ph = (struct pppoehdr *)pb->payload;
mr_q 0:d8f2f7d5f31b 592
mr_q 0:d8f2f7d5f31b 593 if (ph->vertype != PPPOE_VERTYPE) {
mr_q 0:d8f2f7d5f31b 594 printf("pppoe (data): unknown version/type packet: 0x%x\n", ph->vertype);
mr_q 0:d8f2f7d5f31b 595 goto drop;
mr_q 0:d8f2f7d5f31b 596 }
mr_q 0:d8f2f7d5f31b 597 if (ph->code != 0) {
mr_q 0:d8f2f7d5f31b 598 goto drop;
mr_q 0:d8f2f7d5f31b 599 }
mr_q 0:d8f2f7d5f31b 600
mr_q 0:d8f2f7d5f31b 601 session = ntohs(ph->session);
mr_q 0:d8f2f7d5f31b 602 sc = pppoe_find_softc_by_session(session, netif);
mr_q 0:d8f2f7d5f31b 603 if (sc == NULL) {
mr_q 0:d8f2f7d5f31b 604 #ifdef PPPOE_TERM_UNKNOWN_SESSIONS
mr_q 0:d8f2f7d5f31b 605 printf("pppoe: input for unknown session 0x%x, sending PADT\n", session);
mr_q 0:d8f2f7d5f31b 606 pppoe_send_padt(netif, session, shost);
mr_q 0:d8f2f7d5f31b 607 #endif
mr_q 0:d8f2f7d5f31b 608 goto drop;
mr_q 0:d8f2f7d5f31b 609 }
mr_q 0:d8f2f7d5f31b 610
mr_q 0:d8f2f7d5f31b 611 plen = ntohs(ph->plen);
mr_q 0:d8f2f7d5f31b 612
mr_q 0:d8f2f7d5f31b 613 if (pbuf_header(pb, -(int)(PPPOE_HEADERLEN)) != 0) {
mr_q 0:d8f2f7d5f31b 614 /* bail out */
mr_q 0:d8f2f7d5f31b 615 PPPDEBUG(LOG_ERR, ("pppoe_data_input: pbuf_header PPPOE_HEADERLEN failed\n"));
mr_q 0:d8f2f7d5f31b 616 LINK_STATS_INC(link.lenerr);
mr_q 0:d8f2f7d5f31b 617 goto drop;
mr_q 0:d8f2f7d5f31b 618 }
mr_q 0:d8f2f7d5f31b 619
mr_q 0:d8f2f7d5f31b 620 PPPDEBUG(LOG_DEBUG, ("pppoe_data_input: %c%c%"U16_F": pkthdr.len=%d, pppoe.len=%d\n",
mr_q 0:d8f2f7d5f31b 621 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num,
mr_q 0:d8f2f7d5f31b 622 pb->len, plen));
mr_q 0:d8f2f7d5f31b 623
mr_q 0:d8f2f7d5f31b 624 if (pb->len < plen) {
mr_q 0:d8f2f7d5f31b 625 goto drop;
mr_q 0:d8f2f7d5f31b 626 }
mr_q 0:d8f2f7d5f31b 627
mr_q 0:d8f2f7d5f31b 628 pppInProcOverEthernet(sc->sc_pd, pb);
mr_q 0:d8f2f7d5f31b 629
mr_q 0:d8f2f7d5f31b 630 return;
mr_q 0:d8f2f7d5f31b 631
mr_q 0:d8f2f7d5f31b 632 drop:
mr_q 0:d8f2f7d5f31b 633 pbuf_free(pb);
mr_q 0:d8f2f7d5f31b 634 }
mr_q 0:d8f2f7d5f31b 635
mr_q 0:d8f2f7d5f31b 636 static err_t
mr_q 0:d8f2f7d5f31b 637 pppoe_output(struct pppoe_softc *sc, struct pbuf *pb)
mr_q 0:d8f2f7d5f31b 638 {
mr_q 0:d8f2f7d5f31b 639 struct eth_hdr *ethhdr;
mr_q 0:d8f2f7d5f31b 640 u16_t etype;
mr_q 0:d8f2f7d5f31b 641 err_t res;
mr_q 0:d8f2f7d5f31b 642
mr_q 0:d8f2f7d5f31b 643 if (!sc->sc_ethif) {
mr_q 0:d8f2f7d5f31b 644 pbuf_free(pb);
mr_q 0:d8f2f7d5f31b 645 return ERR_IF;
mr_q 0:d8f2f7d5f31b 646 }
mr_q 0:d8f2f7d5f31b 647
mr_q 0:d8f2f7d5f31b 648 ethhdr = (struct eth_hdr *)pb->payload;
mr_q 0:d8f2f7d5f31b 649 etype = sc->sc_state == PPPOE_STATE_SESSION ? ETHTYPE_PPPOE : ETHTYPE_PPPOEDISC;
mr_q 0:d8f2f7d5f31b 650 ethhdr->type = htons(etype);
mr_q 0:d8f2f7d5f31b 651 MEMCPY(ethhdr->dest.addr, sc->sc_dest.addr, sizeof(ethhdr->dest.addr));
mr_q 0:d8f2f7d5f31b 652 MEMCPY(ethhdr->src.addr, ((struct eth_addr *)sc->sc_ethif->hwaddr)->addr, sizeof(ethhdr->src.addr));
mr_q 0:d8f2f7d5f31b 653
mr_q 0:d8f2f7d5f31b 654 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F" (%x) state=%d, session=0x%x output -> %02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F", len=%d\n",
mr_q 0:d8f2f7d5f31b 655 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, etype,
mr_q 0:d8f2f7d5f31b 656 sc->sc_state, sc->sc_session,
mr_q 0:d8f2f7d5f31b 657 sc->sc_dest.addr[0], sc->sc_dest.addr[1], sc->sc_dest.addr[2], sc->sc_dest.addr[3], sc->sc_dest.addr[4], sc->sc_dest.addr[5],
mr_q 0:d8f2f7d5f31b 658 pb->tot_len));
mr_q 0:d8f2f7d5f31b 659
mr_q 0:d8f2f7d5f31b 660 res = sc->sc_ethif->linkoutput(sc->sc_ethif, pb);
mr_q 0:d8f2f7d5f31b 661
mr_q 0:d8f2f7d5f31b 662 pbuf_free(pb);
mr_q 0:d8f2f7d5f31b 663
mr_q 0:d8f2f7d5f31b 664 return res;
mr_q 0:d8f2f7d5f31b 665 }
mr_q 0:d8f2f7d5f31b 666
mr_q 0:d8f2f7d5f31b 667 static err_t
mr_q 0:d8f2f7d5f31b 668 pppoe_send_padi(struct pppoe_softc *sc)
mr_q 0:d8f2f7d5f31b 669 {
mr_q 0:d8f2f7d5f31b 670 struct pbuf *pb;
mr_q 0:d8f2f7d5f31b 671 u8_t *p;
mr_q 0:d8f2f7d5f31b 672 int len;
mr_q 0:d8f2f7d5f31b 673 #ifdef PPPOE_TODO
mr_q 0:d8f2f7d5f31b 674 int l1 = 0, l2 = 0; /* XXX: gcc */
mr_q 0:d8f2f7d5f31b 675 #endif /* PPPOE_TODO */
mr_q 0:d8f2f7d5f31b 676
mr_q 0:d8f2f7d5f31b 677 if (sc->sc_state >PPPOE_STATE_PADI_SENT) {
mr_q 0:d8f2f7d5f31b 678 PPPDEBUG(LOG_ERR, ("ERROR: pppoe_send_padi in state %d", sc->sc_state));
mr_q 0:d8f2f7d5f31b 679 }
mr_q 0:d8f2f7d5f31b 680
mr_q 0:d8f2f7d5f31b 681 /* calculate length of frame (excluding ethernet header + pppoe header) */
mr_q 0:d8f2f7d5f31b 682 len = 2 + 2 + 2 + 2 + sizeof sc; /* service name tag is required, host unique is send too */
mr_q 0:d8f2f7d5f31b 683 #ifdef PPPOE_TODO
mr_q 0:d8f2f7d5f31b 684 if (sc->sc_service_name != NULL) {
mr_q 0:d8f2f7d5f31b 685 l1 = (int)strlen(sc->sc_service_name);
mr_q 0:d8f2f7d5f31b 686 len += l1;
mr_q 0:d8f2f7d5f31b 687 }
mr_q 0:d8f2f7d5f31b 688 if (sc->sc_concentrator_name != NULL) {
mr_q 0:d8f2f7d5f31b 689 l2 = (int)strlen(sc->sc_concentrator_name);
mr_q 0:d8f2f7d5f31b 690 len += 2 + 2 + l2;
mr_q 0:d8f2f7d5f31b 691 }
mr_q 0:d8f2f7d5f31b 692 #endif /* PPPOE_TODO */
mr_q 0:d8f2f7d5f31b 693 LWIP_ASSERT("sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff",
mr_q 0:d8f2f7d5f31b 694 sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff);
mr_q 0:d8f2f7d5f31b 695
mr_q 0:d8f2f7d5f31b 696 /* allocate a buffer */
mr_q 0:d8f2f7d5f31b 697 pb = pbuf_alloc(PBUF_LINK, (u16_t)(sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len), PBUF_RAM);
mr_q 0:d8f2f7d5f31b 698 if (!pb) {
mr_q 0:d8f2f7d5f31b 699 return ERR_MEM;
mr_q 0:d8f2f7d5f31b 700 }
mr_q 0:d8f2f7d5f31b 701 LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len);
mr_q 0:d8f2f7d5f31b 702
mr_q 0:d8f2f7d5f31b 703 p = (u8_t*)pb->payload + sizeof (struct eth_hdr);
mr_q 0:d8f2f7d5f31b 704 /* fill in pkt */
mr_q 0:d8f2f7d5f31b 705 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADI, 0, (u16_t)len);
mr_q 0:d8f2f7d5f31b 706 PPPOE_ADD_16(p, PPPOE_TAG_SNAME);
mr_q 0:d8f2f7d5f31b 707 #ifdef PPPOE_TODO
mr_q 0:d8f2f7d5f31b 708 if (sc->sc_service_name != NULL) {
mr_q 0:d8f2f7d5f31b 709 PPPOE_ADD_16(p, l1);
mr_q 0:d8f2f7d5f31b 710 MEMCPY(p, sc->sc_service_name, l1);
mr_q 0:d8f2f7d5f31b 711 p += l1;
mr_q 0:d8f2f7d5f31b 712 } else
mr_q 0:d8f2f7d5f31b 713 #endif /* PPPOE_TODO */
mr_q 0:d8f2f7d5f31b 714 {
mr_q 0:d8f2f7d5f31b 715 PPPOE_ADD_16(p, 0);
mr_q 0:d8f2f7d5f31b 716 }
mr_q 0:d8f2f7d5f31b 717 #ifdef PPPOE_TODO
mr_q 0:d8f2f7d5f31b 718 if (sc->sc_concentrator_name != NULL) {
mr_q 0:d8f2f7d5f31b 719 PPPOE_ADD_16(p, PPPOE_TAG_ACNAME);
mr_q 0:d8f2f7d5f31b 720 PPPOE_ADD_16(p, l2);
mr_q 0:d8f2f7d5f31b 721 MEMCPY(p, sc->sc_concentrator_name, l2);
mr_q 0:d8f2f7d5f31b 722 p += l2;
mr_q 0:d8f2f7d5f31b 723 }
mr_q 0:d8f2f7d5f31b 724 #endif /* PPPOE_TODO */
mr_q 0:d8f2f7d5f31b 725 PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE);
mr_q 0:d8f2f7d5f31b 726 PPPOE_ADD_16(p, sizeof(sc));
mr_q 0:d8f2f7d5f31b 727 MEMCPY(p, &sc, sizeof sc);
mr_q 0:d8f2f7d5f31b 728
mr_q 0:d8f2f7d5f31b 729 /* send pkt */
mr_q 0:d8f2f7d5f31b 730 return pppoe_output(sc, pb);
mr_q 0:d8f2f7d5f31b 731 }
mr_q 0:d8f2f7d5f31b 732
mr_q 0:d8f2f7d5f31b 733 static void
mr_q 0:d8f2f7d5f31b 734 pppoe_timeout(void *arg)
mr_q 0:d8f2f7d5f31b 735 {
mr_q 0:d8f2f7d5f31b 736 int retry_wait, err;
mr_q 0:d8f2f7d5f31b 737 struct pppoe_softc *sc = (struct pppoe_softc*)arg;
mr_q 0:d8f2f7d5f31b 738
mr_q 0:d8f2f7d5f31b 739 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": timeout\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
mr_q 0:d8f2f7d5f31b 740
mr_q 0:d8f2f7d5f31b 741 switch (sc->sc_state) {
mr_q 0:d8f2f7d5f31b 742 case PPPOE_STATE_PADI_SENT:
mr_q 0:d8f2f7d5f31b 743 /*
mr_q 0:d8f2f7d5f31b 744 * We have two basic ways of retrying:
mr_q 0:d8f2f7d5f31b 745 * - Quick retry mode: try a few times in short sequence
mr_q 0:d8f2f7d5f31b 746 * - Slow retry mode: we already had a connection successfully
mr_q 0:d8f2f7d5f31b 747 * established and will try infinitely (without user
mr_q 0:d8f2f7d5f31b 748 * intervention)
mr_q 0:d8f2f7d5f31b 749 * We only enter slow retry mode if IFF_LINK1 (aka autodial)
mr_q 0:d8f2f7d5f31b 750 * is not set.
mr_q 0:d8f2f7d5f31b 751 */
mr_q 0:d8f2f7d5f31b 752
mr_q 0:d8f2f7d5f31b 753 /* initialize for quick retry mode */
mr_q 0:d8f2f7d5f31b 754 retry_wait = PPPOE_DISC_TIMEOUT * (1 + sc->sc_padi_retried);
mr_q 0:d8f2f7d5f31b 755
mr_q 0:d8f2f7d5f31b 756 sc->sc_padi_retried++;
mr_q 0:d8f2f7d5f31b 757 if (sc->sc_padi_retried >= PPPOE_DISC_MAXPADI) {
mr_q 0:d8f2f7d5f31b 758 #if 0
mr_q 0:d8f2f7d5f31b 759 if ((sc->sc_sppp.pp_if.if_flags & IFF_LINK1) == 0) {
mr_q 0:d8f2f7d5f31b 760 /* slow retry mode */
mr_q 0:d8f2f7d5f31b 761 retry_wait = PPPOE_SLOW_RETRY;
mr_q 0:d8f2f7d5f31b 762 } else
mr_q 0:d8f2f7d5f31b 763 #endif
mr_q 0:d8f2f7d5f31b 764 {
mr_q 0:d8f2f7d5f31b 765 pppoe_abort_connect(sc);
mr_q 0:d8f2f7d5f31b 766 return;
mr_q 0:d8f2f7d5f31b 767 }
mr_q 0:d8f2f7d5f31b 768 }
mr_q 0:d8f2f7d5f31b 769 if ((err = pppoe_send_padi(sc)) != 0) {
mr_q 0:d8f2f7d5f31b 770 sc->sc_padi_retried--;
mr_q 0:d8f2f7d5f31b 771 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": failed to transmit PADI, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err));
mr_q 0:d8f2f7d5f31b 772 }
mr_q 0:d8f2f7d5f31b 773 sys_timeout(retry_wait, pppoe_timeout, sc);
mr_q 0:d8f2f7d5f31b 774 break;
mr_q 0:d8f2f7d5f31b 775
mr_q 0:d8f2f7d5f31b 776 case PPPOE_STATE_PADR_SENT:
mr_q 0:d8f2f7d5f31b 777 sc->sc_padr_retried++;
mr_q 0:d8f2f7d5f31b 778 if (sc->sc_padr_retried >= PPPOE_DISC_MAXPADR) {
mr_q 0:d8f2f7d5f31b 779 MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
mr_q 0:d8f2f7d5f31b 780 sc->sc_state = PPPOE_STATE_PADI_SENT;
mr_q 0:d8f2f7d5f31b 781 sc->sc_padr_retried = 0;
mr_q 0:d8f2f7d5f31b 782 if ((err = pppoe_send_padi(sc)) != 0) {
mr_q 0:d8f2f7d5f31b 783 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": failed to send PADI, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err));
mr_q 0:d8f2f7d5f31b 784 }
mr_q 0:d8f2f7d5f31b 785 sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padi_retried), pppoe_timeout, sc);
mr_q 0:d8f2f7d5f31b 786 return;
mr_q 0:d8f2f7d5f31b 787 }
mr_q 0:d8f2f7d5f31b 788 if ((err = pppoe_send_padr(sc)) != 0) {
mr_q 0:d8f2f7d5f31b 789 sc->sc_padr_retried--;
mr_q 0:d8f2f7d5f31b 790 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": failed to send PADR, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err));
mr_q 0:d8f2f7d5f31b 791 }
mr_q 0:d8f2f7d5f31b 792 sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padr_retried), pppoe_timeout, sc);
mr_q 0:d8f2f7d5f31b 793 break;
mr_q 0:d8f2f7d5f31b 794 case PPPOE_STATE_CLOSING:
mr_q 0:d8f2f7d5f31b 795 pppoe_do_disconnect(sc);
mr_q 0:d8f2f7d5f31b 796 break;
mr_q 0:d8f2f7d5f31b 797 default:
mr_q 0:d8f2f7d5f31b 798 return; /* all done, work in peace */
mr_q 0:d8f2f7d5f31b 799 }
mr_q 0:d8f2f7d5f31b 800 }
mr_q 0:d8f2f7d5f31b 801
mr_q 0:d8f2f7d5f31b 802 /* Start a connection (i.e. initiate discovery phase) */
mr_q 0:d8f2f7d5f31b 803 int
mr_q 0:d8f2f7d5f31b 804 pppoe_connect(struct pppoe_softc *sc)
mr_q 0:d8f2f7d5f31b 805 {
mr_q 0:d8f2f7d5f31b 806 int err;
mr_q 0:d8f2f7d5f31b 807
mr_q 0:d8f2f7d5f31b 808 if (sc->sc_state != PPPOE_STATE_INITIAL) {
mr_q 0:d8f2f7d5f31b 809 return EBUSY;
mr_q 0:d8f2f7d5f31b 810 }
mr_q 0:d8f2f7d5f31b 811
mr_q 0:d8f2f7d5f31b 812 #ifdef PPPOE_SERVER
mr_q 0:d8f2f7d5f31b 813 /* wait PADI if IFF_PASSIVE */
mr_q 0:d8f2f7d5f31b 814 if ((sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE)) {
mr_q 0:d8f2f7d5f31b 815 return 0;
mr_q 0:d8f2f7d5f31b 816 }
mr_q 0:d8f2f7d5f31b 817 #endif
mr_q 0:d8f2f7d5f31b 818 /* save state, in case we fail to send PADI */
mr_q 0:d8f2f7d5f31b 819 sc->sc_state = PPPOE_STATE_PADI_SENT;
mr_q 0:d8f2f7d5f31b 820 sc->sc_padr_retried = 0;
mr_q 0:d8f2f7d5f31b 821 err = pppoe_send_padi(sc);
mr_q 0:d8f2f7d5f31b 822 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": failed to send PADI, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err));
mr_q 0:d8f2f7d5f31b 823 sys_timeout(PPPOE_DISC_TIMEOUT, pppoe_timeout, sc);
mr_q 0:d8f2f7d5f31b 824 return err;
mr_q 0:d8f2f7d5f31b 825 }
mr_q 0:d8f2f7d5f31b 826
mr_q 0:d8f2f7d5f31b 827 /* disconnect */
mr_q 0:d8f2f7d5f31b 828 void
mr_q 0:d8f2f7d5f31b 829 pppoe_disconnect(struct pppoe_softc *sc)
mr_q 0:d8f2f7d5f31b 830 {
mr_q 0:d8f2f7d5f31b 831 if (sc->sc_state < PPPOE_STATE_SESSION) {
mr_q 0:d8f2f7d5f31b 832 return;
mr_q 0:d8f2f7d5f31b 833 }
mr_q 0:d8f2f7d5f31b 834 /*
mr_q 0:d8f2f7d5f31b 835 * Do not call pppoe_disconnect here, the upper layer state
mr_q 0:d8f2f7d5f31b 836 * machine gets confused by this. We must return from this
mr_q 0:d8f2f7d5f31b 837 * function and defer disconnecting to the timeout handler.
mr_q 0:d8f2f7d5f31b 838 */
mr_q 0:d8f2f7d5f31b 839 sc->sc_state = PPPOE_STATE_CLOSING;
mr_q 0:d8f2f7d5f31b 840 sys_timeout(20, pppoe_timeout, sc);
mr_q 0:d8f2f7d5f31b 841 }
mr_q 0:d8f2f7d5f31b 842
mr_q 0:d8f2f7d5f31b 843 static int
mr_q 0:d8f2f7d5f31b 844 pppoe_do_disconnect(struct pppoe_softc *sc)
mr_q 0:d8f2f7d5f31b 845 {
mr_q 0:d8f2f7d5f31b 846 int err;
mr_q 0:d8f2f7d5f31b 847
mr_q 0:d8f2f7d5f31b 848 if (sc->sc_state < PPPOE_STATE_SESSION) {
mr_q 0:d8f2f7d5f31b 849 err = EBUSY;
mr_q 0:d8f2f7d5f31b 850 } else {
mr_q 0:d8f2f7d5f31b 851 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": disconnecting\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
mr_q 0:d8f2f7d5f31b 852 err = pppoe_send_padt(sc->sc_ethif, sc->sc_session, (const u8_t *)&sc->sc_dest);
mr_q 0:d8f2f7d5f31b 853 }
mr_q 0:d8f2f7d5f31b 854
mr_q 0:d8f2f7d5f31b 855 /* cleanup softc */
mr_q 0:d8f2f7d5f31b 856 sc->sc_state = PPPOE_STATE_INITIAL;
mr_q 0:d8f2f7d5f31b 857 MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
mr_q 0:d8f2f7d5f31b 858 sc->sc_ac_cookie_len = 0;
mr_q 0:d8f2f7d5f31b 859 #ifdef PPPOE_SERVER
mr_q 0:d8f2f7d5f31b 860 if (sc->sc_hunique) {
mr_q 0:d8f2f7d5f31b 861 mem_free(sc->sc_hunique);
mr_q 0:d8f2f7d5f31b 862 sc->sc_hunique = NULL;
mr_q 0:d8f2f7d5f31b 863 }
mr_q 0:d8f2f7d5f31b 864 sc->sc_hunique_len = 0;
mr_q 0:d8f2f7d5f31b 865 #endif
mr_q 0:d8f2f7d5f31b 866 sc->sc_session = 0;
mr_q 0:d8f2f7d5f31b 867
mr_q 0:d8f2f7d5f31b 868 sc->sc_linkStatusCB(sc->sc_pd, 0); /* notify upper layers */
mr_q 0:d8f2f7d5f31b 869
mr_q 0:d8f2f7d5f31b 870 return err;
mr_q 0:d8f2f7d5f31b 871 }
mr_q 0:d8f2f7d5f31b 872
mr_q 0:d8f2f7d5f31b 873 /* Connection attempt aborted */
mr_q 0:d8f2f7d5f31b 874 static void
mr_q 0:d8f2f7d5f31b 875 pppoe_abort_connect(struct pppoe_softc *sc)
mr_q 0:d8f2f7d5f31b 876 {
mr_q 0:d8f2f7d5f31b 877 printf("%c%c%"U16_F": could not establish connection\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num);
mr_q 0:d8f2f7d5f31b 878 sc->sc_state = PPPOE_STATE_CLOSING;
mr_q 0:d8f2f7d5f31b 879
mr_q 0:d8f2f7d5f31b 880 sc->sc_linkStatusCB(sc->sc_pd, 0); /* notify upper layers */
mr_q 0:d8f2f7d5f31b 881
mr_q 0:d8f2f7d5f31b 882 /* clear connection state */
mr_q 0:d8f2f7d5f31b 883 MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
mr_q 0:d8f2f7d5f31b 884 sc->sc_state = PPPOE_STATE_INITIAL;
mr_q 0:d8f2f7d5f31b 885 }
mr_q 0:d8f2f7d5f31b 886
mr_q 0:d8f2f7d5f31b 887 /* Send a PADR packet */
mr_q 0:d8f2f7d5f31b 888 static err_t
mr_q 0:d8f2f7d5f31b 889 pppoe_send_padr(struct pppoe_softc *sc)
mr_q 0:d8f2f7d5f31b 890 {
mr_q 0:d8f2f7d5f31b 891 struct pbuf *pb;
mr_q 0:d8f2f7d5f31b 892 u8_t *p;
mr_q 0:d8f2f7d5f31b 893 size_t len;
mr_q 0:d8f2f7d5f31b 894 #ifdef PPPOE_TODO
mr_q 0:d8f2f7d5f31b 895 size_t l1 = 0; /* XXX: gcc */
mr_q 0:d8f2f7d5f31b 896 #endif /* PPPOE_TODO */
mr_q 0:d8f2f7d5f31b 897
mr_q 0:d8f2f7d5f31b 898 if (sc->sc_state != PPPOE_STATE_PADR_SENT) {
mr_q 0:d8f2f7d5f31b 899 return ERR_CONN;
mr_q 0:d8f2f7d5f31b 900 }
mr_q 0:d8f2f7d5f31b 901
mr_q 0:d8f2f7d5f31b 902 len = 2 + 2 + 2 + 2 + sizeof(sc); /* service name, host unique */
mr_q 0:d8f2f7d5f31b 903 #ifdef PPPOE_TODO
mr_q 0:d8f2f7d5f31b 904 if (sc->sc_service_name != NULL) { /* service name tag maybe empty */
mr_q 0:d8f2f7d5f31b 905 l1 = strlen(sc->sc_service_name);
mr_q 0:d8f2f7d5f31b 906 len += l1;
mr_q 0:d8f2f7d5f31b 907 }
mr_q 0:d8f2f7d5f31b 908 #endif /* PPPOE_TODO */
mr_q 0:d8f2f7d5f31b 909 if (sc->sc_ac_cookie_len > 0) {
mr_q 0:d8f2f7d5f31b 910 len += 2 + 2 + sc->sc_ac_cookie_len; /* AC cookie */
mr_q 0:d8f2f7d5f31b 911 }
mr_q 0:d8f2f7d5f31b 912 LWIP_ASSERT("sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff",
mr_q 0:d8f2f7d5f31b 913 sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff);
mr_q 0:d8f2f7d5f31b 914 pb = pbuf_alloc(PBUF_LINK, (u16_t)(sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len), PBUF_RAM);
mr_q 0:d8f2f7d5f31b 915 if (!pb) {
mr_q 0:d8f2f7d5f31b 916 return ERR_MEM;
mr_q 0:d8f2f7d5f31b 917 }
mr_q 0:d8f2f7d5f31b 918 LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len);
mr_q 0:d8f2f7d5f31b 919 p = (u8_t*)pb->payload + sizeof (struct eth_hdr);
mr_q 0:d8f2f7d5f31b 920 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADR, 0, len);
mr_q 0:d8f2f7d5f31b 921 PPPOE_ADD_16(p, PPPOE_TAG_SNAME);
mr_q 0:d8f2f7d5f31b 922 #ifdef PPPOE_TODO
mr_q 0:d8f2f7d5f31b 923 if (sc->sc_service_name != NULL) {
mr_q 0:d8f2f7d5f31b 924 PPPOE_ADD_16(p, l1);
mr_q 0:d8f2f7d5f31b 925 MEMCPY(p, sc->sc_service_name, l1);
mr_q 0:d8f2f7d5f31b 926 p += l1;
mr_q 0:d8f2f7d5f31b 927 } else
mr_q 0:d8f2f7d5f31b 928 #endif /* PPPOE_TODO */
mr_q 0:d8f2f7d5f31b 929 {
mr_q 0:d8f2f7d5f31b 930 PPPOE_ADD_16(p, 0);
mr_q 0:d8f2f7d5f31b 931 }
mr_q 0:d8f2f7d5f31b 932 if (sc->sc_ac_cookie_len > 0) {
mr_q 0:d8f2f7d5f31b 933 PPPOE_ADD_16(p, PPPOE_TAG_ACCOOKIE);
mr_q 0:d8f2f7d5f31b 934 PPPOE_ADD_16(p, sc->sc_ac_cookie_len);
mr_q 0:d8f2f7d5f31b 935 MEMCPY(p, sc->sc_ac_cookie, sc->sc_ac_cookie_len);
mr_q 0:d8f2f7d5f31b 936 p += sc->sc_ac_cookie_len;
mr_q 0:d8f2f7d5f31b 937 }
mr_q 0:d8f2f7d5f31b 938 PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE);
mr_q 0:d8f2f7d5f31b 939 PPPOE_ADD_16(p, sizeof(sc));
mr_q 0:d8f2f7d5f31b 940 MEMCPY(p, &sc, sizeof sc);
mr_q 0:d8f2f7d5f31b 941
mr_q 0:d8f2f7d5f31b 942 return pppoe_output(sc, pb);
mr_q 0:d8f2f7d5f31b 943 }
mr_q 0:d8f2f7d5f31b 944
mr_q 0:d8f2f7d5f31b 945 /* send a PADT packet */
mr_q 0:d8f2f7d5f31b 946 static err_t
mr_q 0:d8f2f7d5f31b 947 pppoe_send_padt(struct netif *outgoing_if, u_int session, const u8_t *dest)
mr_q 0:d8f2f7d5f31b 948 {
mr_q 0:d8f2f7d5f31b 949 struct pbuf *pb;
mr_q 0:d8f2f7d5f31b 950 struct eth_hdr *ethhdr;
mr_q 0:d8f2f7d5f31b 951 err_t res;
mr_q 0:d8f2f7d5f31b 952 u8_t *p;
mr_q 0:d8f2f7d5f31b 953
mr_q 0:d8f2f7d5f31b 954 pb = pbuf_alloc(PBUF_LINK, sizeof(struct eth_hdr) + PPPOE_HEADERLEN, PBUF_RAM);
mr_q 0:d8f2f7d5f31b 955 if (!pb) {
mr_q 0:d8f2f7d5f31b 956 return ERR_MEM;
mr_q 0:d8f2f7d5f31b 957 }
mr_q 0:d8f2f7d5f31b 958 LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len);
mr_q 0:d8f2f7d5f31b 959
mr_q 0:d8f2f7d5f31b 960 ethhdr = (struct eth_hdr *)pb->payload;
mr_q 0:d8f2f7d5f31b 961 ethhdr->type = PP_HTONS(ETHTYPE_PPPOEDISC);
mr_q 0:d8f2f7d5f31b 962 MEMCPY(ethhdr->dest.addr, dest, sizeof(ethhdr->dest.addr));
mr_q 0:d8f2f7d5f31b 963 MEMCPY(ethhdr->src.addr, ((struct eth_addr *)outgoing_if->hwaddr)->addr, sizeof(ethhdr->src.addr));
mr_q 0:d8f2f7d5f31b 964
mr_q 0:d8f2f7d5f31b 965 p = (u8_t*)(ethhdr + 1);
mr_q 0:d8f2f7d5f31b 966 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADT, session, 0);
mr_q 0:d8f2f7d5f31b 967
mr_q 0:d8f2f7d5f31b 968 res = outgoing_if->linkoutput(outgoing_if, pb);
mr_q 0:d8f2f7d5f31b 969
mr_q 0:d8f2f7d5f31b 970 pbuf_free(pb);
mr_q 0:d8f2f7d5f31b 971
mr_q 0:d8f2f7d5f31b 972 return res;
mr_q 0:d8f2f7d5f31b 973 }
mr_q 0:d8f2f7d5f31b 974
mr_q 0:d8f2f7d5f31b 975 #ifdef PPPOE_SERVER
mr_q 0:d8f2f7d5f31b 976 static err_t
mr_q 0:d8f2f7d5f31b 977 pppoe_send_pado(struct pppoe_softc *sc)
mr_q 0:d8f2f7d5f31b 978 {
mr_q 0:d8f2f7d5f31b 979 struct pbuf *pb;
mr_q 0:d8f2f7d5f31b 980 u8_t *p;
mr_q 0:d8f2f7d5f31b 981 size_t len;
mr_q 0:d8f2f7d5f31b 982
mr_q 0:d8f2f7d5f31b 983 if (sc->sc_state != PPPOE_STATE_PADO_SENT) {
mr_q 0:d8f2f7d5f31b 984 return ERR_CONN;
mr_q 0:d8f2f7d5f31b 985 }
mr_q 0:d8f2f7d5f31b 986
mr_q 0:d8f2f7d5f31b 987 /* calc length */
mr_q 0:d8f2f7d5f31b 988 len = 0;
mr_q 0:d8f2f7d5f31b 989 /* include ac_cookie */
mr_q 0:d8f2f7d5f31b 990 len += 2 + 2 + sizeof(sc);
mr_q 0:d8f2f7d5f31b 991 /* include hunique */
mr_q 0:d8f2f7d5f31b 992 len += 2 + 2 + sc->sc_hunique_len;
mr_q 0:d8f2f7d5f31b 993 pb = pbuf_alloc(PBUF_LINK, sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len, PBUF_RAM);
mr_q 0:d8f2f7d5f31b 994 if (!pb) {
mr_q 0:d8f2f7d5f31b 995 return ERR_MEM;
mr_q 0:d8f2f7d5f31b 996 }
mr_q 0:d8f2f7d5f31b 997 LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len);
mr_q 0:d8f2f7d5f31b 998 p = (u8_t*)pb->payload + sizeof (struct eth_hdr);
mr_q 0:d8f2f7d5f31b 999 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADO, 0, len);
mr_q 0:d8f2f7d5f31b 1000 PPPOE_ADD_16(p, PPPOE_TAG_ACCOOKIE);
mr_q 0:d8f2f7d5f31b 1001 PPPOE_ADD_16(p, sizeof(sc));
mr_q 0:d8f2f7d5f31b 1002 MEMCPY(p, &sc, sizeof(sc));
mr_q 0:d8f2f7d5f31b 1003 p += sizeof(sc);
mr_q 0:d8f2f7d5f31b 1004 PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE);
mr_q 0:d8f2f7d5f31b 1005 PPPOE_ADD_16(p, sc->sc_hunique_len);
mr_q 0:d8f2f7d5f31b 1006 MEMCPY(p, sc->sc_hunique, sc->sc_hunique_len);
mr_q 0:d8f2f7d5f31b 1007 return pppoe_output(sc, pb);
mr_q 0:d8f2f7d5f31b 1008 }
mr_q 0:d8f2f7d5f31b 1009
mr_q 0:d8f2f7d5f31b 1010 static err_t
mr_q 0:d8f2f7d5f31b 1011 pppoe_send_pads(struct pppoe_softc *sc)
mr_q 0:d8f2f7d5f31b 1012 {
mr_q 0:d8f2f7d5f31b 1013 struct pbuf *pb;
mr_q 0:d8f2f7d5f31b 1014 u8_t *p;
mr_q 0:d8f2f7d5f31b 1015 size_t len, l1 = 0; /* XXX: gcc */
mr_q 0:d8f2f7d5f31b 1016
mr_q 0:d8f2f7d5f31b 1017 if (sc->sc_state != PPPOE_STATE_PADO_SENT) {
mr_q 0:d8f2f7d5f31b 1018 return ERR_CONN;
mr_q 0:d8f2f7d5f31b 1019 }
mr_q 0:d8f2f7d5f31b 1020
mr_q 0:d8f2f7d5f31b 1021 sc->sc_session = mono_time.tv_sec % 0xff + 1;
mr_q 0:d8f2f7d5f31b 1022 /* calc length */
mr_q 0:d8f2f7d5f31b 1023 len = 0;
mr_q 0:d8f2f7d5f31b 1024 /* include hunique */
mr_q 0:d8f2f7d5f31b 1025 len += 2 + 2 + 2 + 2 + sc->sc_hunique_len; /* service name, host unique*/
mr_q 0:d8f2f7d5f31b 1026 if (sc->sc_service_name != NULL) { /* service name tag maybe empty */
mr_q 0:d8f2f7d5f31b 1027 l1 = strlen(sc->sc_service_name);
mr_q 0:d8f2f7d5f31b 1028 len += l1;
mr_q 0:d8f2f7d5f31b 1029 }
mr_q 0:d8f2f7d5f31b 1030 pb = pbuf_alloc(PBUF_LINK, sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len, PBUF_RAM);
mr_q 0:d8f2f7d5f31b 1031 if (!pb) {
mr_q 0:d8f2f7d5f31b 1032 return ERR_MEM;
mr_q 0:d8f2f7d5f31b 1033 }
mr_q 0:d8f2f7d5f31b 1034 LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len);
mr_q 0:d8f2f7d5f31b 1035 p = (u8_t*)pb->payload + sizeof (struct eth_hdr);
mr_q 0:d8f2f7d5f31b 1036 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADS, sc->sc_session, len);
mr_q 0:d8f2f7d5f31b 1037 PPPOE_ADD_16(p, PPPOE_TAG_SNAME);
mr_q 0:d8f2f7d5f31b 1038 if (sc->sc_service_name != NULL) {
mr_q 0:d8f2f7d5f31b 1039 PPPOE_ADD_16(p, l1);
mr_q 0:d8f2f7d5f31b 1040 MEMCPY(p, sc->sc_service_name, l1);
mr_q 0:d8f2f7d5f31b 1041 p += l1;
mr_q 0:d8f2f7d5f31b 1042 } else {
mr_q 0:d8f2f7d5f31b 1043 PPPOE_ADD_16(p, 0);
mr_q 0:d8f2f7d5f31b 1044 }
mr_q 0:d8f2f7d5f31b 1045 PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE);
mr_q 0:d8f2f7d5f31b 1046 PPPOE_ADD_16(p, sc->sc_hunique_len);
mr_q 0:d8f2f7d5f31b 1047 MEMCPY(p, sc->sc_hunique, sc->sc_hunique_len);
mr_q 0:d8f2f7d5f31b 1048 return pppoe_output(sc, pb);
mr_q 0:d8f2f7d5f31b 1049 }
mr_q 0:d8f2f7d5f31b 1050 #endif
mr_q 0:d8f2f7d5f31b 1051
mr_q 0:d8f2f7d5f31b 1052 err_t
mr_q 0:d8f2f7d5f31b 1053 pppoe_xmit(struct pppoe_softc *sc, struct pbuf *pb)
mr_q 0:d8f2f7d5f31b 1054 {
mr_q 0:d8f2f7d5f31b 1055 u8_t *p;
mr_q 0:d8f2f7d5f31b 1056 size_t len;
mr_q 0:d8f2f7d5f31b 1057
mr_q 0:d8f2f7d5f31b 1058 /* are we ready to process data yet? */
mr_q 0:d8f2f7d5f31b 1059 if (sc->sc_state < PPPOE_STATE_SESSION) {
mr_q 0:d8f2f7d5f31b 1060 /*sppp_flush(&sc->sc_sppp.pp_if);*/
mr_q 0:d8f2f7d5f31b 1061 pbuf_free(pb);
mr_q 0:d8f2f7d5f31b 1062 return ERR_CONN;
mr_q 0:d8f2f7d5f31b 1063 }
mr_q 0:d8f2f7d5f31b 1064
mr_q 0:d8f2f7d5f31b 1065 len = pb->tot_len;
mr_q 0:d8f2f7d5f31b 1066
mr_q 0:d8f2f7d5f31b 1067 /* make room for Ethernet header - should not fail */
mr_q 0:d8f2f7d5f31b 1068 if (pbuf_header(pb, sizeof(struct eth_hdr) + PPPOE_HEADERLEN) != 0) {
mr_q 0:d8f2f7d5f31b 1069 /* bail out */
mr_q 0:d8f2f7d5f31b 1070 PPPDEBUG(LOG_ERR, ("pppoe: %c%c%"U16_F": pppoe_xmit: could not allocate room for header\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
mr_q 0:d8f2f7d5f31b 1071 LINK_STATS_INC(link.lenerr);
mr_q 0:d8f2f7d5f31b 1072 pbuf_free(pb);
mr_q 0:d8f2f7d5f31b 1073 return ERR_BUF;
mr_q 0:d8f2f7d5f31b 1074 }
mr_q 0:d8f2f7d5f31b 1075
mr_q 0:d8f2f7d5f31b 1076 p = (u8_t*)pb->payload + sizeof(struct eth_hdr);
mr_q 0:d8f2f7d5f31b 1077 PPPOE_ADD_HEADER(p, 0, sc->sc_session, len);
mr_q 0:d8f2f7d5f31b 1078
mr_q 0:d8f2f7d5f31b 1079 return pppoe_output(sc, pb);
mr_q 0:d8f2f7d5f31b 1080 }
mr_q 0:d8f2f7d5f31b 1081
mr_q 0:d8f2f7d5f31b 1082 #if 0 /*def PFIL_HOOKS*/
mr_q 0:d8f2f7d5f31b 1083 static int
mr_q 0:d8f2f7d5f31b 1084 pppoe_ifattach_hook(void *arg, struct pbuf **mp, struct netif *ifp, int dir)
mr_q 0:d8f2f7d5f31b 1085 {
mr_q 0:d8f2f7d5f31b 1086 struct pppoe_softc *sc;
mr_q 0:d8f2f7d5f31b 1087 int s;
mr_q 0:d8f2f7d5f31b 1088
mr_q 0:d8f2f7d5f31b 1089 if (mp != (struct pbuf **)PFIL_IFNET_DETACH) {
mr_q 0:d8f2f7d5f31b 1090 return 0;
mr_q 0:d8f2f7d5f31b 1091 }
mr_q 0:d8f2f7d5f31b 1092
mr_q 0:d8f2f7d5f31b 1093 LIST_FOREACH(sc, &pppoe_softc_list, sc_list) {
mr_q 0:d8f2f7d5f31b 1094 if (sc->sc_ethif != ifp) {
mr_q 0:d8f2f7d5f31b 1095 continue;
mr_q 0:d8f2f7d5f31b 1096 }
mr_q 0:d8f2f7d5f31b 1097 if (sc->sc_sppp.pp_if.if_flags & IFF_UP) {
mr_q 0:d8f2f7d5f31b 1098 sc->sc_sppp.pp_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
mr_q 0:d8f2f7d5f31b 1099 printf("%c%c%"U16_F": ethernet interface detached, going down\n",
mr_q 0:d8f2f7d5f31b 1100 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num);
mr_q 0:d8f2f7d5f31b 1101 }
mr_q 0:d8f2f7d5f31b 1102 sc->sc_ethif = NULL;
mr_q 0:d8f2f7d5f31b 1103 pppoe_clear_softc(sc, "ethernet interface detached");
mr_q 0:d8f2f7d5f31b 1104 }
mr_q 0:d8f2f7d5f31b 1105
mr_q 0:d8f2f7d5f31b 1106 return 0;
mr_q 0:d8f2f7d5f31b 1107 }
mr_q 0:d8f2f7d5f31b 1108 #endif
mr_q 0:d8f2f7d5f31b 1109
mr_q 0:d8f2f7d5f31b 1110 static void
mr_q 0:d8f2f7d5f31b 1111 pppoe_clear_softc(struct pppoe_softc *sc, const char *message)
mr_q 0:d8f2f7d5f31b 1112 {
mr_q 0:d8f2f7d5f31b 1113 LWIP_UNUSED_ARG(message);
mr_q 0:d8f2f7d5f31b 1114
mr_q 0:d8f2f7d5f31b 1115 /* stop timer */
mr_q 0:d8f2f7d5f31b 1116 sys_untimeout(pppoe_timeout, sc);
mr_q 0:d8f2f7d5f31b 1117 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": session 0x%x terminated, %s\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, sc->sc_session, message));
mr_q 0:d8f2f7d5f31b 1118
mr_q 0:d8f2f7d5f31b 1119 /* fix our state */
mr_q 0:d8f2f7d5f31b 1120 sc->sc_state = PPPOE_STATE_INITIAL;
mr_q 0:d8f2f7d5f31b 1121
mr_q 0:d8f2f7d5f31b 1122 /* notify upper layers */
mr_q 0:d8f2f7d5f31b 1123 sc->sc_linkStatusCB(sc->sc_pd, 0);
mr_q 0:d8f2f7d5f31b 1124
mr_q 0:d8f2f7d5f31b 1125 /* clean up softc */
mr_q 0:d8f2f7d5f31b 1126 MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
mr_q 0:d8f2f7d5f31b 1127 sc->sc_ac_cookie_len = 0;
mr_q 0:d8f2f7d5f31b 1128 sc->sc_session = 0;
mr_q 0:d8f2f7d5f31b 1129 }
mr_q 0:d8f2f7d5f31b 1130
mr_q 0:d8f2f7d5f31b 1131 #endif /* PPPOE_SUPPORT */
mr_q 0:d8f2f7d5f31b 1132