simple tester example >>> osc destination & receive

Dependencies:   mbed

Fork of myOSC_test by Alvaro Cassinelli

Committer:
sfjmt
Date:
Tue Aug 06 10:12:56 2013 +0000
Revision:
2:44f1e5803762
Parent:
0:f76708a93fb3
revision_01

Who changed what in which revision?

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