Onenet
Dependents: K64F_eCompass_OneNET_JW
lwip/include/netif/ppp_oe.h@0:b2805b6888dc, 2016-06-20 (annotated)
- Committer:
- robert_jw
- Date:
- Mon Jun 20 01:40:20 2016 +0000
- Revision:
- 0:b2805b6888dc
ADS
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
robert_jw | 0:b2805b6888dc | 1 | /***************************************************************************** |
robert_jw | 0:b2805b6888dc | 2 | * ppp_oe.h - PPP Over Ethernet implementation for lwIP. |
robert_jw | 0:b2805b6888dc | 3 | * |
robert_jw | 0:b2805b6888dc | 4 | * Copyright (c) 2006 by Marc Boucher, Services Informatiques (MBSI) inc. |
robert_jw | 0:b2805b6888dc | 5 | * |
robert_jw | 0:b2805b6888dc | 6 | * The authors hereby grant permission to use, copy, modify, distribute, |
robert_jw | 0:b2805b6888dc | 7 | * and license this software and its documentation for any purpose, provided |
robert_jw | 0:b2805b6888dc | 8 | * that existing copyright notices are retained in all copies and that this |
robert_jw | 0:b2805b6888dc | 9 | * notice and the following disclaimer are included verbatim in any |
robert_jw | 0:b2805b6888dc | 10 | * distributions. No written agreement, license, or royalty fee is required |
robert_jw | 0:b2805b6888dc | 11 | * for any of the authorized uses. |
robert_jw | 0:b2805b6888dc | 12 | * |
robert_jw | 0:b2805b6888dc | 13 | * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR |
robert_jw | 0:b2805b6888dc | 14 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
robert_jw | 0:b2805b6888dc | 15 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
robert_jw | 0:b2805b6888dc | 16 | * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
robert_jw | 0:b2805b6888dc | 17 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
robert_jw | 0:b2805b6888dc | 18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
robert_jw | 0:b2805b6888dc | 19 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
robert_jw | 0:b2805b6888dc | 20 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
robert_jw | 0:b2805b6888dc | 21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
robert_jw | 0:b2805b6888dc | 22 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
robert_jw | 0:b2805b6888dc | 23 | * |
robert_jw | 0:b2805b6888dc | 24 | ****************************************************************************** |
robert_jw | 0:b2805b6888dc | 25 | * REVISION HISTORY |
robert_jw | 0:b2805b6888dc | 26 | * |
robert_jw | 0:b2805b6888dc | 27 | * 06-01-01 Marc Boucher <marc@mbsi.ca> |
robert_jw | 0:b2805b6888dc | 28 | * Ported to lwIP. |
robert_jw | 0:b2805b6888dc | 29 | *****************************************************************************/ |
robert_jw | 0:b2805b6888dc | 30 | |
robert_jw | 0:b2805b6888dc | 31 | |
robert_jw | 0:b2805b6888dc | 32 | |
robert_jw | 0:b2805b6888dc | 33 | /* based on NetBSD: if_pppoe.c,v 1.64 2006/01/31 23:50:15 martin Exp */ |
robert_jw | 0:b2805b6888dc | 34 | |
robert_jw | 0:b2805b6888dc | 35 | /*- |
robert_jw | 0:b2805b6888dc | 36 | * Copyright (c) 2002 The NetBSD Foundation, Inc. |
robert_jw | 0:b2805b6888dc | 37 | * All rights reserved. |
robert_jw | 0:b2805b6888dc | 38 | * |
robert_jw | 0:b2805b6888dc | 39 | * This code is derived from software contributed to The NetBSD Foundation |
robert_jw | 0:b2805b6888dc | 40 | * by Martin Husemann <martin@NetBSD.org>. |
robert_jw | 0:b2805b6888dc | 41 | * |
robert_jw | 0:b2805b6888dc | 42 | * Redistribution and use in source and binary forms, with or without |
robert_jw | 0:b2805b6888dc | 43 | * modification, are permitted provided that the following conditions |
robert_jw | 0:b2805b6888dc | 44 | * are met: |
robert_jw | 0:b2805b6888dc | 45 | * 1. Redistributions of source code must retain the above copyright |
robert_jw | 0:b2805b6888dc | 46 | * notice, this list of conditions and the following disclaimer. |
robert_jw | 0:b2805b6888dc | 47 | * 2. Redistributions in binary form must reproduce the above copyright |
robert_jw | 0:b2805b6888dc | 48 | * notice, this list of conditions and the following disclaimer in the |
robert_jw | 0:b2805b6888dc | 49 | * documentation and/or other materials provided with the distribution. |
robert_jw | 0:b2805b6888dc | 50 | * 3. All advertising materials mentioning features or use of this software |
robert_jw | 0:b2805b6888dc | 51 | * must display the following acknowledgement: |
robert_jw | 0:b2805b6888dc | 52 | * This product includes software developed by the NetBSD |
robert_jw | 0:b2805b6888dc | 53 | * Foundation, Inc. and its contributors. |
robert_jw | 0:b2805b6888dc | 54 | * 4. Neither the name of The NetBSD Foundation nor the names of its |
robert_jw | 0:b2805b6888dc | 55 | * contributors may be used to endorse or promote products derived |
robert_jw | 0:b2805b6888dc | 56 | * from this software without specific prior written permission. |
robert_jw | 0:b2805b6888dc | 57 | * |
robert_jw | 0:b2805b6888dc | 58 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
robert_jw | 0:b2805b6888dc | 59 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
robert_jw | 0:b2805b6888dc | 60 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
robert_jw | 0:b2805b6888dc | 61 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
robert_jw | 0:b2805b6888dc | 62 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
robert_jw | 0:b2805b6888dc | 63 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
robert_jw | 0:b2805b6888dc | 64 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
robert_jw | 0:b2805b6888dc | 65 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
robert_jw | 0:b2805b6888dc | 66 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
robert_jw | 0:b2805b6888dc | 67 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
robert_jw | 0:b2805b6888dc | 68 | * POSSIBILITY OF SUCH DAMAGE. |
robert_jw | 0:b2805b6888dc | 69 | */ |
robert_jw | 0:b2805b6888dc | 70 | #ifndef PPP_OE_H |
robert_jw | 0:b2805b6888dc | 71 | #define PPP_OE_H |
robert_jw | 0:b2805b6888dc | 72 | |
robert_jw | 0:b2805b6888dc | 73 | #include "lwip/opt.h" |
robert_jw | 0:b2805b6888dc | 74 | |
robert_jw | 0:b2805b6888dc | 75 | #if PPPOE_SUPPORT > 0 |
robert_jw | 0:b2805b6888dc | 76 | |
robert_jw | 0:b2805b6888dc | 77 | #include "netif/etharp.h" |
robert_jw | 0:b2805b6888dc | 78 | |
robert_jw | 0:b2805b6888dc | 79 | #ifdef PACK_STRUCT_USE_INCLUDES |
robert_jw | 0:b2805b6888dc | 80 | # include "arch/bpstruct.h" |
robert_jw | 0:b2805b6888dc | 81 | #endif |
robert_jw | 0:b2805b6888dc | 82 | PACK_STRUCT_BEGIN |
robert_jw | 0:b2805b6888dc | 83 | struct pppoehdr { |
robert_jw | 0:b2805b6888dc | 84 | PACK_STRUCT_FIELD(u8_t vertype); |
robert_jw | 0:b2805b6888dc | 85 | PACK_STRUCT_FIELD(u8_t code); |
robert_jw | 0:b2805b6888dc | 86 | PACK_STRUCT_FIELD(u16_t session); |
robert_jw | 0:b2805b6888dc | 87 | PACK_STRUCT_FIELD(u16_t plen); |
robert_jw | 0:b2805b6888dc | 88 | } PACK_STRUCT_STRUCT; |
robert_jw | 0:b2805b6888dc | 89 | PACK_STRUCT_END |
robert_jw | 0:b2805b6888dc | 90 | #ifdef PACK_STRUCT_USE_INCLUDES |
robert_jw | 0:b2805b6888dc | 91 | # include "arch/epstruct.h" |
robert_jw | 0:b2805b6888dc | 92 | #endif |
robert_jw | 0:b2805b6888dc | 93 | |
robert_jw | 0:b2805b6888dc | 94 | #ifdef PACK_STRUCT_USE_INCLUDES |
robert_jw | 0:b2805b6888dc | 95 | # include "arch/bpstruct.h" |
robert_jw | 0:b2805b6888dc | 96 | #endif |
robert_jw | 0:b2805b6888dc | 97 | PACK_STRUCT_BEGIN |
robert_jw | 0:b2805b6888dc | 98 | struct pppoetag { |
robert_jw | 0:b2805b6888dc | 99 | PACK_STRUCT_FIELD(u16_t tag); |
robert_jw | 0:b2805b6888dc | 100 | PACK_STRUCT_FIELD(u16_t len); |
robert_jw | 0:b2805b6888dc | 101 | } PACK_STRUCT_STRUCT; |
robert_jw | 0:b2805b6888dc | 102 | PACK_STRUCT_END |
robert_jw | 0:b2805b6888dc | 103 | #ifdef PACK_STRUCT_USE_INCLUDES |
robert_jw | 0:b2805b6888dc | 104 | # include "arch/epstruct.h" |
robert_jw | 0:b2805b6888dc | 105 | #endif |
robert_jw | 0:b2805b6888dc | 106 | |
robert_jw | 0:b2805b6888dc | 107 | |
robert_jw | 0:b2805b6888dc | 108 | #define PPPOE_STATE_INITIAL 0 |
robert_jw | 0:b2805b6888dc | 109 | #define PPPOE_STATE_PADI_SENT 1 |
robert_jw | 0:b2805b6888dc | 110 | #define PPPOE_STATE_PADR_SENT 2 |
robert_jw | 0:b2805b6888dc | 111 | #define PPPOE_STATE_SESSION 3 |
robert_jw | 0:b2805b6888dc | 112 | #define PPPOE_STATE_CLOSING 4 |
robert_jw | 0:b2805b6888dc | 113 | /* passive */ |
robert_jw | 0:b2805b6888dc | 114 | #define PPPOE_STATE_PADO_SENT 1 |
robert_jw | 0:b2805b6888dc | 115 | |
robert_jw | 0:b2805b6888dc | 116 | #define PPPOE_HEADERLEN sizeof(struct pppoehdr) |
robert_jw | 0:b2805b6888dc | 117 | #define PPPOE_VERTYPE 0x11 /* VER=1, TYPE = 1 */ |
robert_jw | 0:b2805b6888dc | 118 | |
robert_jw | 0:b2805b6888dc | 119 | #define PPPOE_TAG_EOL 0x0000 /* end of list */ |
robert_jw | 0:b2805b6888dc | 120 | #define PPPOE_TAG_SNAME 0x0101 /* service name */ |
robert_jw | 0:b2805b6888dc | 121 | #define PPPOE_TAG_ACNAME 0x0102 /* access concentrator name */ |
robert_jw | 0:b2805b6888dc | 122 | #define PPPOE_TAG_HUNIQUE 0x0103 /* host unique */ |
robert_jw | 0:b2805b6888dc | 123 | #define PPPOE_TAG_ACCOOKIE 0x0104 /* AC cookie */ |
robert_jw | 0:b2805b6888dc | 124 | #define PPPOE_TAG_VENDOR 0x0105 /* vendor specific */ |
robert_jw | 0:b2805b6888dc | 125 | #define PPPOE_TAG_RELAYSID 0x0110 /* relay session id */ |
robert_jw | 0:b2805b6888dc | 126 | #define PPPOE_TAG_SNAME_ERR 0x0201 /* service name error */ |
robert_jw | 0:b2805b6888dc | 127 | #define PPPOE_TAG_ACSYS_ERR 0x0202 /* AC system error */ |
robert_jw | 0:b2805b6888dc | 128 | #define PPPOE_TAG_GENERIC_ERR 0x0203 /* gerneric error */ |
robert_jw | 0:b2805b6888dc | 129 | |
robert_jw | 0:b2805b6888dc | 130 | #define PPPOE_CODE_PADI 0x09 /* Active Discovery Initiation */ |
robert_jw | 0:b2805b6888dc | 131 | #define PPPOE_CODE_PADO 0x07 /* Active Discovery Offer */ |
robert_jw | 0:b2805b6888dc | 132 | #define PPPOE_CODE_PADR 0x19 /* Active Discovery Request */ |
robert_jw | 0:b2805b6888dc | 133 | #define PPPOE_CODE_PADS 0x65 /* Active Discovery Session confirmation */ |
robert_jw | 0:b2805b6888dc | 134 | #define PPPOE_CODE_PADT 0xA7 /* Active Discovery Terminate */ |
robert_jw | 0:b2805b6888dc | 135 | |
robert_jw | 0:b2805b6888dc | 136 | #ifndef ETHERMTU |
robert_jw | 0:b2805b6888dc | 137 | #define ETHERMTU 1500 |
robert_jw | 0:b2805b6888dc | 138 | #endif |
robert_jw | 0:b2805b6888dc | 139 | |
robert_jw | 0:b2805b6888dc | 140 | /* two byte PPP protocol discriminator, then IP data */ |
robert_jw | 0:b2805b6888dc | 141 | #define PPPOE_MAXMTU (ETHERMTU-PPPOE_HEADERLEN-2) |
robert_jw | 0:b2805b6888dc | 142 | |
robert_jw | 0:b2805b6888dc | 143 | #ifndef PPPOE_MAX_AC_COOKIE_LEN |
robert_jw | 0:b2805b6888dc | 144 | #define PPPOE_MAX_AC_COOKIE_LEN 64 |
robert_jw | 0:b2805b6888dc | 145 | #endif |
robert_jw | 0:b2805b6888dc | 146 | |
robert_jw | 0:b2805b6888dc | 147 | struct pppoe_softc { |
robert_jw | 0:b2805b6888dc | 148 | struct pppoe_softc *next; |
robert_jw | 0:b2805b6888dc | 149 | struct netif *sc_ethif; /* ethernet interface we are using */ |
robert_jw | 0:b2805b6888dc | 150 | int sc_pd; /* ppp unit number */ |
robert_jw | 0:b2805b6888dc | 151 | void (*sc_linkStatusCB)(int pd, int up); |
robert_jw | 0:b2805b6888dc | 152 | |
robert_jw | 0:b2805b6888dc | 153 | int sc_state; /* discovery phase or session connected */ |
robert_jw | 0:b2805b6888dc | 154 | struct eth_addr sc_dest; /* hardware address of concentrator */ |
robert_jw | 0:b2805b6888dc | 155 | u16_t sc_session; /* PPPoE session id */ |
robert_jw | 0:b2805b6888dc | 156 | |
robert_jw | 0:b2805b6888dc | 157 | #ifdef PPPOE_TODO |
robert_jw | 0:b2805b6888dc | 158 | char *sc_service_name; /* if != NULL: requested name of service */ |
robert_jw | 0:b2805b6888dc | 159 | char *sc_concentrator_name; /* if != NULL: requested concentrator id */ |
robert_jw | 0:b2805b6888dc | 160 | #endif /* PPPOE_TODO */ |
robert_jw | 0:b2805b6888dc | 161 | u8_t sc_ac_cookie[PPPOE_MAX_AC_COOKIE_LEN]; /* content of AC cookie we must echo back */ |
robert_jw | 0:b2805b6888dc | 162 | size_t sc_ac_cookie_len; /* length of cookie data */ |
robert_jw | 0:b2805b6888dc | 163 | #ifdef PPPOE_SERVER |
robert_jw | 0:b2805b6888dc | 164 | u8_t *sc_hunique; /* content of host unique we must echo back */ |
robert_jw | 0:b2805b6888dc | 165 | size_t sc_hunique_len; /* length of host unique */ |
robert_jw | 0:b2805b6888dc | 166 | #endif |
robert_jw | 0:b2805b6888dc | 167 | int sc_padi_retried; /* number of PADI retries already done */ |
robert_jw | 0:b2805b6888dc | 168 | int sc_padr_retried; /* number of PADR retries already done */ |
robert_jw | 0:b2805b6888dc | 169 | }; |
robert_jw | 0:b2805b6888dc | 170 | |
robert_jw | 0:b2805b6888dc | 171 | |
robert_jw | 0:b2805b6888dc | 172 | #define pppoe_init() /* compatibility define, no initialization needed */ |
robert_jw | 0:b2805b6888dc | 173 | |
robert_jw | 0:b2805b6888dc | 174 | err_t pppoe_create(struct netif *ethif, int pd, void (*linkStatusCB)(int pd, int up), struct pppoe_softc **scptr); |
robert_jw | 0:b2805b6888dc | 175 | err_t pppoe_destroy(struct netif *ifp); |
robert_jw | 0:b2805b6888dc | 176 | |
robert_jw | 0:b2805b6888dc | 177 | int pppoe_connect(struct pppoe_softc *sc); |
robert_jw | 0:b2805b6888dc | 178 | void pppoe_disconnect(struct pppoe_softc *sc); |
robert_jw | 0:b2805b6888dc | 179 | |
robert_jw | 0:b2805b6888dc | 180 | void pppoe_disc_input(struct netif *netif, struct pbuf *p); |
robert_jw | 0:b2805b6888dc | 181 | void pppoe_data_input(struct netif *netif, struct pbuf *p); |
robert_jw | 0:b2805b6888dc | 182 | |
robert_jw | 0:b2805b6888dc | 183 | err_t pppoe_xmit(struct pppoe_softc *sc, struct pbuf *pb); |
robert_jw | 0:b2805b6888dc | 184 | |
robert_jw | 0:b2805b6888dc | 185 | /** used in ppp.c */ |
robert_jw | 0:b2805b6888dc | 186 | #define PPPOE_HDRLEN (sizeof(struct eth_hdr) + PPPOE_HEADERLEN) |
robert_jw | 0:b2805b6888dc | 187 | |
robert_jw | 0:b2805b6888dc | 188 | #endif /* PPPOE_SUPPORT */ |
robert_jw | 0:b2805b6888dc | 189 | |
robert_jw | 0:b2805b6888dc | 190 | #endif /* PPP_OE_H */ |