Xbee test 2

Dependencies:   XBee mbed

Committer:
takashiyamanoue
Date:
Sat Jul 21 04:08:27 2012 +0000
Revision:
0:ffac63d6a7f0
xbee test 2

Who changed what in which revision?

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