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