Example program with HTTPServer and sensor data streaming over TCPSockets, using Donatien Garnier's Net APIs and services code on top of LWIP. Files StreamServer.h and .cpp encapsulate streaming over TCPSockets. Broadcast is done by sendToAll(), and all incoming data is echoed back to the client. Echo code can be replaced with some remote control of the streaming interface. See main() that shows how to periodically send some data to all subscribed clients. To subscribe, a client should open a socket at <mbed_ip> port 123. I used few lines in TCL code to set up a quick sink for the data. HTTP files are served on port 80 concurrently to the streaming.

Dependencies:   mbed

Committer:
iva2k
Date:
Sat Jun 12 06:01:50 2010 +0000
Revision:
0:e614f7875b60

        

Who changed what in which revision?

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