Stripped down version of Segundos NetService library (http://mbed.org/users/segundo/libraries/NetServices ). I have removed all NetServices, and all functions which had been disabled. Use this version when you need only pure TCP or UDP functions - this library compiles faster.

Dependencies:   lwip lwip-sys

Dependents:   christmasLights device_server pop3demo device_server_udp ... more

Committer:
hlipka
Date:
Mon Jan 10 21:03:11 2011 +0000
Revision:
0:8b387bed54c2
initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hlipka 0:8b387bed54c2 1 /*
hlipka 0:8b387bed54c2 2 * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
hlipka 0:8b387bed54c2 3 * Copyright (c) 2003-2004 Leon Woestenberg <leon.woestenberg@axon.tv>
hlipka 0:8b387bed54c2 4 * Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands.
hlipka 0:8b387bed54c2 5 * All rights reserved.
hlipka 0:8b387bed54c2 6 *
hlipka 0:8b387bed54c2 7 * Redistribution and use in source and binary forms, with or without modification,
hlipka 0:8b387bed54c2 8 * are permitted provided that the following conditions are met:
hlipka 0:8b387bed54c2 9 *
hlipka 0:8b387bed54c2 10 * 1. Redistributions of source code must retain the above copyright notice,
hlipka 0:8b387bed54c2 11 * this list of conditions and the following disclaimer.
hlipka 0:8b387bed54c2 12 * 2. Redistributions in binary form must reproduce the above copyright notice,
hlipka 0:8b387bed54c2 13 * this list of conditions and the following disclaimer in the documentation
hlipka 0:8b387bed54c2 14 * and/or other materials provided with the distribution.
hlipka 0:8b387bed54c2 15 * 3. The name of the author may not be used to endorse or promote products
hlipka 0:8b387bed54c2 16 * derived from this software without specific prior written permission.
hlipka 0:8b387bed54c2 17 *
hlipka 0:8b387bed54c2 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
hlipka 0:8b387bed54c2 19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
hlipka 0:8b387bed54c2 20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
hlipka 0:8b387bed54c2 21 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
hlipka 0:8b387bed54c2 22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
hlipka 0:8b387bed54c2 23 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
hlipka 0:8b387bed54c2 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
hlipka 0:8b387bed54c2 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
hlipka 0:8b387bed54c2 26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
hlipka 0:8b387bed54c2 27 * OF SUCH DAMAGE.
hlipka 0:8b387bed54c2 28 *
hlipka 0:8b387bed54c2 29 * This file is part of the lwIP TCP/IP stack.
hlipka 0:8b387bed54c2 30 *
hlipka 0:8b387bed54c2 31 * Author: Adam Dunkels <adam@sics.se>
hlipka 0:8b387bed54c2 32 *
hlipka 0:8b387bed54c2 33 */
hlipka 0:8b387bed54c2 34
hlipka 0:8b387bed54c2 35 #ifndef __NETIF_ETHARP_H__
hlipka 0:8b387bed54c2 36 #define __NETIF_ETHARP_H__
hlipka 0:8b387bed54c2 37
hlipka 0:8b387bed54c2 38 #include "lwip/opt.h"
hlipka 0:8b387bed54c2 39
hlipka 0:8b387bed54c2 40 #if LWIP_ARP || LWIP_ETHERNET /* don't build if not configured for use in lwipopts.h */
hlipka 0:8b387bed54c2 41
hlipka 0:8b387bed54c2 42 #include "lwip/pbuf.h"
hlipka 0:8b387bed54c2 43 #include "lwip/ip_addr.h"
hlipka 0:8b387bed54c2 44 #include "lwip/netif.h"
hlipka 0:8b387bed54c2 45 #include "lwip/ip.h"
hlipka 0:8b387bed54c2 46
hlipka 0:8b387bed54c2 47 #ifdef __cplusplus
hlipka 0:8b387bed54c2 48 extern "C" {
hlipka 0:8b387bed54c2 49 #endif
hlipka 0:8b387bed54c2 50
hlipka 0:8b387bed54c2 51 #ifndef ETHARP_HWADDR_LEN
hlipka 0:8b387bed54c2 52 #define ETHARP_HWADDR_LEN 6
hlipka 0:8b387bed54c2 53 #endif
hlipka 0:8b387bed54c2 54
hlipka 0:8b387bed54c2 55 #ifdef PACK_STRUCT_USE_INCLUDES
hlipka 0:8b387bed54c2 56 # include "arch/bpstruct.h"
hlipka 0:8b387bed54c2 57 #endif
hlipka 0:8b387bed54c2 58 PACK_STRUCT_BEGIN
hlipka 0:8b387bed54c2 59 struct eth_addr {
hlipka 0:8b387bed54c2 60 PACK_STRUCT_FIELD(u8_t addr[ETHARP_HWADDR_LEN]);
hlipka 0:8b387bed54c2 61 } PACK_STRUCT_STRUCT;
hlipka 0:8b387bed54c2 62 PACK_STRUCT_END
hlipka 0:8b387bed54c2 63 #ifdef PACK_STRUCT_USE_INCLUDES
hlipka 0:8b387bed54c2 64 # include "arch/epstruct.h"
hlipka 0:8b387bed54c2 65 #endif
hlipka 0:8b387bed54c2 66
hlipka 0:8b387bed54c2 67 #ifdef PACK_STRUCT_USE_INCLUDES
hlipka 0:8b387bed54c2 68 # include "arch/bpstruct.h"
hlipka 0:8b387bed54c2 69 #endif
hlipka 0:8b387bed54c2 70 PACK_STRUCT_BEGIN
hlipka 0:8b387bed54c2 71 /* Ethernet header */
hlipka 0:8b387bed54c2 72 struct eth_hdr {
hlipka 0:8b387bed54c2 73 #if ETH_PAD_SIZE
hlipka 0:8b387bed54c2 74 PACK_STRUCT_FIELD(u8_t padding[ETH_PAD_SIZE]);
hlipka 0:8b387bed54c2 75 #endif
hlipka 0:8b387bed54c2 76 PACK_STRUCT_FIELD(struct eth_addr dest);
hlipka 0:8b387bed54c2 77 PACK_STRUCT_FIELD(struct eth_addr src);
hlipka 0:8b387bed54c2 78 PACK_STRUCT_FIELD(u16_t type);
hlipka 0:8b387bed54c2 79 } PACK_STRUCT_STRUCT;
hlipka 0:8b387bed54c2 80 PACK_STRUCT_END
hlipka 0:8b387bed54c2 81 #ifdef PACK_STRUCT_USE_INCLUDES
hlipka 0:8b387bed54c2 82 # include "arch/epstruct.h"
hlipka 0:8b387bed54c2 83 #endif
hlipka 0:8b387bed54c2 84
hlipka 0:8b387bed54c2 85 #define SIZEOF_ETH_HDR (14 + ETH_PAD_SIZE)
hlipka 0:8b387bed54c2 86
hlipka 0:8b387bed54c2 87 #if ETHARP_SUPPORT_VLAN
hlipka 0:8b387bed54c2 88
hlipka 0:8b387bed54c2 89 #ifdef PACK_STRUCT_USE_INCLUDES
hlipka 0:8b387bed54c2 90 # include "arch/bpstruct.h"
hlipka 0:8b387bed54c2 91 #endif
hlipka 0:8b387bed54c2 92 PACK_STRUCT_BEGIN
hlipka 0:8b387bed54c2 93 /* VLAN header inserted between ethernet header and payload
hlipka 0:8b387bed54c2 94 * if 'type' in ethernet header is ETHTYPE_VLAN.
hlipka 0:8b387bed54c2 95 * See IEEE802.Q */
hlipka 0:8b387bed54c2 96 struct eth_vlan_hdr {
hlipka 0:8b387bed54c2 97 PACK_STRUCT_FIELD(u16_t tpid);
hlipka 0:8b387bed54c2 98 PACK_STRUCT_FIELD(u16_t prio_vid);
hlipka 0:8b387bed54c2 99 } PACK_STRUCT_STRUCT;
hlipka 0:8b387bed54c2 100 PACK_STRUCT_END
hlipka 0:8b387bed54c2 101 #ifdef PACK_STRUCT_USE_INCLUDES
hlipka 0:8b387bed54c2 102 # include "arch/epstruct.h"
hlipka 0:8b387bed54c2 103 #endif
hlipka 0:8b387bed54c2 104
hlipka 0:8b387bed54c2 105 #define SIZEOF_VLAN_HDR 4
hlipka 0:8b387bed54c2 106 #define VLAN_ID(vlan_hdr) (htons((vlan_hdr)->prio_vid) & 0xFFF)
hlipka 0:8b387bed54c2 107
hlipka 0:8b387bed54c2 108 #endif /* ETHARP_SUPPORT_VLAN */
hlipka 0:8b387bed54c2 109
hlipka 0:8b387bed54c2 110 #ifdef PACK_STRUCT_USE_INCLUDES
hlipka 0:8b387bed54c2 111 # include "arch/bpstruct.h"
hlipka 0:8b387bed54c2 112 #endif
hlipka 0:8b387bed54c2 113 PACK_STRUCT_BEGIN
hlipka 0:8b387bed54c2 114 /* the ARP message, see RFC 826 ("Packet format") */
hlipka 0:8b387bed54c2 115 struct etharp_hdr {
hlipka 0:8b387bed54c2 116 PACK_STRUCT_FIELD(u16_t hwtype);
hlipka 0:8b387bed54c2 117 PACK_STRUCT_FIELD(u16_t proto);
hlipka 0:8b387bed54c2 118 PACK_STRUCT_FIELD(u8_t hwlen);
hlipka 0:8b387bed54c2 119 PACK_STRUCT_FIELD(u8_t protolen);
hlipka 0:8b387bed54c2 120 PACK_STRUCT_FIELD(u16_t opcode);
hlipka 0:8b387bed54c2 121 PACK_STRUCT_FIELD(struct eth_addr shwaddr);
hlipka 0:8b387bed54c2 122 PACK_STRUCT_FIELD(struct ip_addr2 sipaddr);
hlipka 0:8b387bed54c2 123 PACK_STRUCT_FIELD(struct eth_addr dhwaddr);
hlipka 0:8b387bed54c2 124 PACK_STRUCT_FIELD(struct ip_addr2 dipaddr);
hlipka 0:8b387bed54c2 125 } PACK_STRUCT_STRUCT;
hlipka 0:8b387bed54c2 126 PACK_STRUCT_END
hlipka 0:8b387bed54c2 127 #ifdef PACK_STRUCT_USE_INCLUDES
hlipka 0:8b387bed54c2 128 # include "arch/epstruct.h"
hlipka 0:8b387bed54c2 129 #endif
hlipka 0:8b387bed54c2 130
hlipka 0:8b387bed54c2 131 #define SIZEOF_ETHARP_HDR 28
hlipka 0:8b387bed54c2 132 #define SIZEOF_ETHARP_PACKET (SIZEOF_ETH_HDR + SIZEOF_ETHARP_HDR)
hlipka 0:8b387bed54c2 133
hlipka 0:8b387bed54c2 134 /* 5 seconds period */
hlipka 0:8b387bed54c2 135 #define ARP_TMR_INTERVAL 5000
hlipka 0:8b387bed54c2 136
hlipka 0:8b387bed54c2 137 #define ETHTYPE_ARP 0x0806
hlipka 0:8b387bed54c2 138 #define ETHTYPE_IP 0x0800
hlipka 0:8b387bed54c2 139 #define ETHTYPE_VLAN 0x8100
hlipka 0:8b387bed54c2 140 #define ETHTYPE_PPPOEDISC 0x8863 /* PPP Over Ethernet Discovery Stage */
hlipka 0:8b387bed54c2 141 #define ETHTYPE_PPPOE 0x8864 /* PPP Over Ethernet Session Stage */
hlipka 0:8b387bed54c2 142
hlipka 0:8b387bed54c2 143 /* MEMCPY-like macro to copy to/from struct eth_addr's that are local variables
hlipka 0:8b387bed54c2 144 * or known to be 32-bit aligned within the protocol header. */
hlipka 0:8b387bed54c2 145 #ifndef ETHADDR32_COPY
hlipka 0:8b387bed54c2 146 #define ETHADDR32_COPY(src, dst) SMEMCPY(src, dst, ETHARP_HWADDR_LEN)
hlipka 0:8b387bed54c2 147 #endif
hlipka 0:8b387bed54c2 148
hlipka 0:8b387bed54c2 149 /* MEMCPY-like macro to copy to/from struct eth_addr's that are no local
hlipka 0:8b387bed54c2 150 * variables and known to be 16-bit aligned within the protocol header. */
hlipka 0:8b387bed54c2 151 #ifndef ETHADDR16_COPY
hlipka 0:8b387bed54c2 152 #define ETHADDR16_COPY(src, dst) SMEMCPY(src, dst, ETHARP_HWADDR_LEN)
hlipka 0:8b387bed54c2 153 #endif
hlipka 0:8b387bed54c2 154
hlipka 0:8b387bed54c2 155 #if LWIP_ARP /* don't build if not configured for use in lwipopts.h */
hlipka 0:8b387bed54c2 156
hlipka 0:8b387bed54c2 157 /* ARP message types (opcodes) */
hlipka 0:8b387bed54c2 158 #define ARP_REQUEST 1
hlipka 0:8b387bed54c2 159 #define ARP_REPLY 2
hlipka 0:8b387bed54c2 160
hlipka 0:8b387bed54c2 161 /* Define this to 1 and define LWIP_ARP_FILTER_NETIF_FN(pbuf, netif, type)
hlipka 0:8b387bed54c2 162 * to a filter function that returns the correct netif when using multiple
hlipka 0:8b387bed54c2 163 * netifs on one hardware interface where the netif's low-level receive
hlipka 0:8b387bed54c2 164 * routine cannot decide for the correct netif (e.g. when mapping multiple
hlipka 0:8b387bed54c2 165 * IP addresses to one hardware interface).
hlipka 0:8b387bed54c2 166 */
hlipka 0:8b387bed54c2 167 #ifndef LWIP_ARP_FILTER_NETIF
hlipka 0:8b387bed54c2 168 #define LWIP_ARP_FILTER_NETIF 0
hlipka 0:8b387bed54c2 169 #endif
hlipka 0:8b387bed54c2 170
hlipka 0:8b387bed54c2 171 #if ARP_QUEUEING
hlipka 0:8b387bed54c2 172 /* struct for queueing outgoing packets for unknown address
hlipka 0:8b387bed54c2 173 * defined here to be accessed by memp.h
hlipka 0:8b387bed54c2 174 */
hlipka 0:8b387bed54c2 175 struct etharp_q_entry {
hlipka 0:8b387bed54c2 176 struct etharp_q_entry *next;
hlipka 0:8b387bed54c2 177 struct pbuf *p;
hlipka 0:8b387bed54c2 178 };
hlipka 0:8b387bed54c2 179 #endif /* ARP_QUEUEING */
hlipka 0:8b387bed54c2 180
hlipka 0:8b387bed54c2 181 #define etharp_init() /* Compatibility define, not init needed. */
hlipka 0:8b387bed54c2 182 void etharp_tmr(void);
hlipka 0:8b387bed54c2 183 s8_t etharp_find_addr(struct netif *netif, ip_addr_t *ipaddr,
hlipka 0:8b387bed54c2 184 struct eth_addr **eth_ret, ip_addr_t **ip_ret);
hlipka 0:8b387bed54c2 185 err_t etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr);
hlipka 0:8b387bed54c2 186 err_t etharp_query(struct netif *netif, ip_addr_t *ipaddr, struct pbuf *q);
hlipka 0:8b387bed54c2 187 err_t etharp_request(struct netif *netif, ip_addr_t *ipaddr);
hlipka 0:8b387bed54c2 188 /* For Ethernet network interfaces, we might want to send "gratuitous ARP";
hlipka 0:8b387bed54c2 189 * this is an ARP packet sent by a node in order to spontaneously cause other
hlipka 0:8b387bed54c2 190 * nodes to update an entry in their ARP cache.
hlipka 0:8b387bed54c2 191 * From RFC 3220 "IP Mobility Support for IPv4" section 4.6. */
hlipka 0:8b387bed54c2 192 #define etharp_gratuitous(netif) etharp_request((netif), &(netif)->ip_addr)
hlipka 0:8b387bed54c2 193
hlipka 0:8b387bed54c2 194 #if ETHARP_SUPPORT_STATIC_ENTRIES
hlipka 0:8b387bed54c2 195 err_t etharp_add_static_entry(ip_addr_t *ipaddr, struct eth_addr *ethaddr);
hlipka 0:8b387bed54c2 196 err_t etharp_remove_static_entry(ip_addr_t *ipaddr);
hlipka 0:8b387bed54c2 197 #endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
hlipka 0:8b387bed54c2 198
hlipka 0:8b387bed54c2 199 #if LWIP_AUTOIP
hlipka 0:8b387bed54c2 200 err_t etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,
hlipka 0:8b387bed54c2 201 const struct eth_addr *ethdst_addr,
hlipka 0:8b387bed54c2 202 const struct eth_addr *hwsrc_addr, const ip_addr_t *ipsrc_addr,
hlipka 0:8b387bed54c2 203 const struct eth_addr *hwdst_addr, const ip_addr_t *ipdst_addr,
hlipka 0:8b387bed54c2 204 const u16_t opcode);
hlipka 0:8b387bed54c2 205 #endif /* LWIP_AUTOIP */
hlipka 0:8b387bed54c2 206
hlipka 0:8b387bed54c2 207 #endif /* LWIP_ARP */
hlipka 0:8b387bed54c2 208
hlipka 0:8b387bed54c2 209 err_t ethernet_input(struct pbuf *p, struct netif *netif);
hlipka 0:8b387bed54c2 210
hlipka 0:8b387bed54c2 211 #define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETHARP_HWADDR_LEN) == 0)
hlipka 0:8b387bed54c2 212
hlipka 0:8b387bed54c2 213 extern const struct eth_addr ethbroadcast, ethzero;
hlipka 0:8b387bed54c2 214
hlipka 0:8b387bed54c2 215 #ifdef __cplusplus
hlipka 0:8b387bed54c2 216 }
hlipka 0:8b387bed54c2 217 #endif
hlipka 0:8b387bed54c2 218
hlipka 0:8b387bed54c2 219 #endif /* LWIP_ARP || LWIP_ETHERNET */
hlipka 0:8b387bed54c2 220
hlipka 0:8b387bed54c2 221 #endif /* __NETIF_ARP_H__ */