2010-10-12 21:42:03 +02:00
|
|
|
/* 6LoWPAN IP header file */
|
|
|
|
|
2010-10-17 16:03:48 +02:00
|
|
|
#ifndef SIXLOWIP_H
|
|
|
|
#define SIXLOWIP_H
|
|
|
|
|
2010-10-12 21:42:03 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2010-10-14 13:10:52 +02:00
|
|
|
/* set maximum transmission unit */
|
2011-01-07 13:02:27 +01:00
|
|
|
#define MTU 1280
|
2010-11-09 22:20:26 +01:00
|
|
|
/* IPv6 field values */
|
|
|
|
#define IPV6_VER 0x60
|
|
|
|
#define ICMPV6_NXT_HDR 0x3A
|
|
|
|
#define ND_HOPLIMIT 0xFF
|
2010-10-17 16:03:48 +02:00
|
|
|
#define SIXLOWPAN_IPV6_LL_ADDR_LEN 8
|
|
|
|
/* size of global buffer */
|
2010-11-09 22:20:26 +01:00
|
|
|
#define BUFFER_SIZE (LL_HDR_LEN + MTU)
|
2010-11-22 12:52:56 +01:00
|
|
|
/* board specific configurations*/
|
2010-10-19 23:06:47 +02:00
|
|
|
#define MSBA2_OUI 0x005BA2 // 24bit OUI
|
|
|
|
#define R8BIT 0xA2 // random 8bit
|
|
|
|
#define OUI 0x005BA2
|
2010-11-22 12:52:56 +01:00
|
|
|
/* radio driver */
|
2010-10-19 23:06:47 +02:00
|
|
|
#define RADIO_CONF radio_cc1100
|
|
|
|
#define RADIO RADIO_CONF
|
|
|
|
|
2010-11-09 22:20:26 +01:00
|
|
|
#define MULTIHOP_HOPLIMIT 64
|
2010-10-19 23:06:47 +02:00
|
|
|
|
2011-01-07 23:38:42 +01:00
|
|
|
#define IP_PKT_RECV_BUF_SIZE 64
|
|
|
|
|
|
|
|
/* extern variables */
|
2010-10-17 16:03:48 +02:00
|
|
|
extern uint8_t ipv6_ext_hdr_len;
|
2010-11-22 12:52:56 +01:00
|
|
|
extern uint8_t opt_hdr_len;
|
|
|
|
extern uint16_t packet_length;
|
2011-01-07 23:38:42 +01:00
|
|
|
|
2010-11-09 22:20:26 +01:00
|
|
|
/* base header lengths */
|
2010-11-22 12:52:56 +01:00
|
|
|
#define LL_HDR_LEN 0x4
|
2010-11-09 22:20:26 +01:00
|
|
|
#define ICMPV6_HDR_LEN 0x4
|
|
|
|
#define IPV6_HDR_LEN 0x28
|
2010-11-22 12:52:56 +01:00
|
|
|
#define LLHDR_IPV6HDR_LEN (LL_HDR_LEN + IPV6_HDR_LEN)
|
|
|
|
#define LLHDR_ICMPV6HDR_LEN (LL_HDR_LEN + IPV6_HDR_LEN + ICMPV6_HDR_LEN)
|
|
|
|
#define IPV6HDR_ICMPV6HDR_LEN (IPV6_HDR_LEN + ipv6_ext_hdr_len + ICMPV6_HDR_LEN)
|
2010-10-14 13:10:52 +02:00
|
|
|
|
2010-11-30 10:21:29 +01:00
|
|
|
/* buffer */
|
|
|
|
uint8_t buffer[BUFFER_SIZE];
|
|
|
|
|
|
|
|
|
2010-10-14 13:10:52 +02:00
|
|
|
/* ipv6 extension header length */
|
2010-10-12 21:42:03 +02:00
|
|
|
|
2010-11-30 10:21:29 +01:00
|
|
|
typedef union __attribute__ ((packed)) ipv6_addr_t{
|
2010-10-14 13:10:52 +02:00
|
|
|
uint8_t uint8[16];
|
|
|
|
uint16_t uint16[8];
|
2010-11-30 10:21:29 +01:00
|
|
|
uint32_t uint32[4];
|
2010-11-22 12:52:56 +01:00
|
|
|
} ipv6_addr_t;
|
2010-10-12 21:42:03 +02:00
|
|
|
|
2010-11-30 10:21:29 +01:00
|
|
|
struct __attribute__ ((packed)) icmpv6_hdr_t{
|
2010-10-12 21:42:03 +02:00
|
|
|
uint8_t type;
|
|
|
|
uint8_t code;
|
|
|
|
uint16_t checksum;
|
2010-10-14 13:10:52 +02:00
|
|
|
};
|
2010-10-12 21:42:03 +02:00
|
|
|
|
2010-11-30 10:21:29 +01:00
|
|
|
struct __attribute__ ((packed)) ipv6_hdr_t{
|
2010-10-12 21:42:03 +02:00
|
|
|
uint8_t version_trafficclass;
|
|
|
|
uint8_t trafficclass_flowlabel;
|
|
|
|
uint16_t flowlabel;
|
|
|
|
uint16_t length;
|
|
|
|
uint8_t nextheader;
|
|
|
|
uint8_t hoplimit;
|
2010-11-22 12:52:56 +01:00
|
|
|
ipv6_addr_t srcaddr;
|
|
|
|
ipv6_addr_t destaddr;
|
2010-10-14 13:10:52 +02:00
|
|
|
};
|
2010-10-17 16:03:48 +02:00
|
|
|
|
2010-11-22 12:52:56 +01:00
|
|
|
/* link layer addressing */
|
2010-12-13 11:14:41 +01:00
|
|
|
typedef union __attribute__ ((packed)) ieee_802154_long_t {
|
|
|
|
uint8_t uint8[8];
|
|
|
|
uint16_t uint16[4];
|
2010-11-22 12:52:56 +01:00
|
|
|
} ieee_802154_long_t;
|
|
|
|
|
2010-12-13 11:14:41 +01:00
|
|
|
typedef union __attribute__ ((packed)) ieee_802154_short_t {
|
2010-11-22 12:52:56 +01:00
|
|
|
uint8_t uint8[2];
|
2010-12-13 11:14:41 +01:00
|
|
|
uint16_t uint16[1];
|
2010-11-22 12:52:56 +01:00
|
|
|
} ieee_802154_short_t;
|
2010-10-17 16:03:48 +02:00
|
|
|
|
2011-01-07 23:38:42 +01:00
|
|
|
typedef struct __attribute__ ((packed)) iface_t {
|
|
|
|
ieee_802154_short_t saddr;
|
|
|
|
ieee_802154_long_t laddr;
|
|
|
|
ipv6_addr_t ipaddr;
|
|
|
|
} iface_t;
|
|
|
|
|
|
|
|
extern iface_t iface;
|
|
|
|
|
2010-11-30 10:21:29 +01:00
|
|
|
//#define HTONS(a) (uint16_t)((((uint16_t) (a)) << 8) | (((uint16_t) (a)) >> 8))
|
|
|
|
#define HTONS(a) ((((uint16_t) (a) >> 8) & 0xff) | ((((uint16_t) (a)) & 0xff) << 8))
|
2010-11-08 10:33:23 +01:00
|
|
|
#define HTONL(a) ((((uint32_t) (a) & 0xff000000) >> 24) | \
|
|
|
|
(((uint32_t) (a) & 0x00ff0000) >> 8) | \
|
|
|
|
(((uint32_t) (a) & 0x0000ff00) << 8) | \
|
|
|
|
(((uint32_t) (a) & 0x000000ff) << 24))
|
2010-10-17 16:03:48 +02:00
|
|
|
|
2010-11-09 22:20:26 +01:00
|
|
|
/* function prototypes */
|
2010-11-22 12:52:56 +01:00
|
|
|
struct icmpv6_hdr_t* get_icmpv6_buf(uint8_t ext_len);
|
|
|
|
struct ipv6_hdr_t* get_ipv6_buf(void);
|
|
|
|
|
|
|
|
void create_link_local_prefix(ipv6_addr_t *ipaddr);
|
|
|
|
void create_all_routers_mcast_addr(ipv6_addr_t *ipaddr);
|
|
|
|
void create_all_nodes_mcast_addr(ipv6_addr_t *ipaddr);
|
|
|
|
void set_eui64(ipv6_addr_t *ipaddr);
|
|
|
|
ieee_802154_long_t* get_eui(ipv6_addr_t *ipaddr);
|
2011-01-07 13:02:27 +01:00
|
|
|
void bootstrapping(uint8_t *addr);
|
2010-11-22 12:52:56 +01:00
|
|
|
void print6addr(ipv6_addr_t *ipaddr);
|
2011-01-07 23:38:42 +01:00
|
|
|
void ip_process(void);
|
2010-10-19 23:06:47 +02:00
|
|
|
|
|
|
|
#endif /* SIXLOWIP_H*/
|