Library for Bert van Dam's book "ARM MICROCONTROLLERS" For all chapters with internet.

Dependencies:   mbed

Committer:
ICTFBI
Date:
Fri Oct 16 14:28:26 2015 +0000
Revision:
0:4edb816d21e1
Pre-update 16-10-15

Who changed what in which revision?

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