hattori&ide

Dependencies:   mbed

Committer:
hattori_atsushi
Date:
Sun Dec 18 08:16:01 2022 +0000
Revision:
0:f77369cabd75
hattori

Who changed what in which revision?

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