Michiel Berckvens / Mbed 2 deprecated ProjectHTTP

Dependencies:   DS1307 TextLCD mbed

Committer:
Michielber
Date:
Thu Dec 04 10:36:40 2014 +0000
Revision:
0:f615d151a72c
Berckvens Michiel & Basteyns Jonas 4/12/2014

Who changed what in which revision?

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