testing of combination of LCS and LAN

Dependencies:   mbed

Committer:
damir
Date:
Wed Jan 14 13:29:55 2015 +0000
Revision:
0:a7a6a692162f
Test of LAN

Who changed what in which revision?

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