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