diff --git a/sys/net/sixlowpan/sixlowip.c b/sys/net/sixlowpan/sixlowip.c index d49b90cdd7..35d2e69a1e 100644 --- a/sys/net/sixlowpan/sixlowip.c +++ b/sys/net/sixlowpan/sixlowip.c @@ -4,21 +4,33 @@ #include "drivers/cc110x/cc1100.h" #include "radio/radio.h" -#define ipv6_buf ((struct ipv6_hdr*)&buffer[LL_HDR_LEN]) + +struct ipv6_hdr_t* ipv6_buf; + +struct ipv6_hdr_t* get_ipv6_buf(void){ + return ((struct ipv6_hdr_t*)&(buffer[LL_HDR_LEN])); +} + +struct icmpv6_hdr_t* get_icmpv6_buf(uint8_t ext_len){ + return ((struct icmpv6_hdr_t*)&(buffer[LLHDR_IPV6HDR_LEN + ext_len])); +} + void bootstrapping(void){ #ifdef SIXLOWPAN_NODE /* create link-local address based on eui-64 */ + ipv6_buf = get_ipv6_buf(); RADIO.set_address(5); create_link_local_prefix(&ipv6_buf->srcaddr); set_eui64(&ipv6_buf->srcaddr); print6addr(&ipv6_buf->srcaddr); /* send router solicitation */ - send_rtr_sol(); +// send_rtr_sol(); + send_rtr_adv(&ipv6_buf->destaddr); #endif } -void set_eui64(ipv6_addr *ipaddr){ +void set_eui64(ipv6_addr_t *ipaddr){ uint16_t radio_driver_addr = RADIO.get_address(); ipaddr->uint8[8] = ((uint8_t) (OUI >> 16)) | 0x2 ; @@ -31,11 +43,11 @@ void set_eui64(ipv6_addr *ipaddr){ ipaddr->uint8[15] = (uint8_t) radio_driver_addr; } -link_layer_addr* get_eui(ipv6_addr *ipaddr){ - return ((link_layer_addr *) &(ipaddr->uint8[8])); +ieee_802154_long_t* get_eui(ipv6_addr_t *ipaddr){ + return ((ieee_802154_long_t *) &(ipaddr->uint8[8])); } -void create_all_routers_mcast_addr(ipv6_addr *ipaddr){ +void create_all_routers_mcast_addr(ipv6_addr_t *ipaddr){ ipaddr->uint16[0] = HTONS(0xff02); ipaddr->uint16[1] = 0; ipaddr->uint16[2] = 0; @@ -46,7 +58,7 @@ void create_all_routers_mcast_addr(ipv6_addr *ipaddr){ ipaddr->uint16[7] = HTONS(0x0002); } -void create_all_nodes_mcast_addr(ipv6_addr *ipaddr){ +void create_all_nodes_mcast_addr(ipv6_addr_t *ipaddr){ ipaddr->uint16[0] = HTONS(0xff02); ipaddr->uint16[1] = 0; ipaddr->uint16[2] = 0; @@ -57,14 +69,14 @@ void create_all_nodes_mcast_addr(ipv6_addr *ipaddr){ ipaddr->uint16[7] = HTONS(0x0001); } -void create_link_local_prefix(ipv6_addr *ipaddr){ +void create_link_local_prefix(ipv6_addr_t *ipaddr){ ipaddr->uint16[0] = HTONS(0xfe80); ipaddr->uint16[1] = 0; ipaddr->uint16[2] = 0; ipaddr->uint16[3] = 0; } -void print6addr(ipv6_addr *ipaddr){ +void print6addr(ipv6_addr_t *ipaddr){ printf("%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n", ((uint8_t *)ipaddr)[0], ((uint8_t *)ipaddr)[1], ((uint8_t *)ipaddr)[2], ((uint8_t *)ipaddr)[3], ((uint8_t *)ipaddr)[4], ((uint8_t *)ipaddr)[5], diff --git a/sys/net/sixlowpan/sixlowip.h b/sys/net/sixlowpan/sixlowip.h index ad7ca45871..80d192276b 100644 --- a/sys/net/sixlowpan/sixlowip.h +++ b/sys/net/sixlowpan/sixlowip.h @@ -5,85 +5,70 @@ #include -#define MSBA2_SENSOR_NODE 1 - /* set maximum transmission unit */ -#ifdef MSBA2_SENSOR_NODE #define MTU 0x3A -#else -#define MTU 0x0 -#endif - /* IPv6 field values */ #define IPV6_VER 0x60 #define ICMPV6_NXT_HDR 0x3A #define ND_HOPLIMIT 0xFF - #define SIXLOWPAN_IPV6_LL_ADDR_LEN 8 - /* size of global buffer */ #define BUFFER_SIZE (LL_HDR_LEN + MTU) - +/* board specific configurations*/ #define MSBA2_OUI 0x005BA2 // 24bit OUI #define R8BIT 0xA2 // random 8bit - -#ifdef MSBA2_SENSOR_NODE #define OUI 0x005BA2 -#else -#define OUI 0x0 -#endif - +/* radio driver */ #define RADIO_CONF radio_cc1100 #define RADIO RADIO_CONF #define MULTIHOP_HOPLIMIT 64 +/* globals */ +uint8_t buffer[BUFFER_SIZE]; extern uint8_t ipv6_ext_hdr_len; - +extern uint8_t opt_hdr_len; +extern uint16_t packet_length; /* base header lengths */ -#ifdef MSBA2_SENSOR_NODE - #define LL_HDR_LEN 0x4 -#else - #define LL_HDR_LEN 0x0 -#endif /* MSBA2_SENSOR_NODE */ +#define LL_HDR_LEN 0x4 #define ICMPV6_HDR_LEN 0x4 #define IPV6_HDR_LEN 0x28 -#define LLHDR_IPV6HDR_LEN (LL_HDR_LEN + IPV6_HDR_LEN + ipv6_ext_hdr_len) -#define LLHDR_ICMPV6HDR_LEN (LL_HDR_LEN + IPV6_HDR_LEN + ipv6_ext_hdr_len + ICMPV6_HDR_LEN) -#define IPV6HDR_ICMPV6HDR_LEN (IPV6_HDR_LEN + ipv6_ext_hdr_len + ICMPV6_HDR_LEN) - -/* global buffer*/ -uint8_t buffer[BUFFER_SIZE]; -/* packet length*/ -extern uint16_t packet_length; +#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) /* ipv6 extension header length */ -typedef union ipv6_addr{ +typedef union ipv6_addr_t{ uint8_t uint8[16]; uint16_t uint16[8]; -} ipv6_addr; +} ipv6_addr_t; -struct icmpv6_hdr{ +struct icmpv6_hdr_t{ uint8_t type; uint8_t code; uint16_t checksum; }; -struct ipv6_hdr{ +struct ipv6_hdr_t{ uint8_t version_trafficclass; uint8_t trafficclass_flowlabel; uint16_t flowlabel; uint16_t length; uint8_t nextheader; uint8_t hoplimit; - ipv6_addr srcaddr; - ipv6_addr destaddr; + ipv6_addr_t srcaddr; + ipv6_addr_t destaddr; }; -typedef struct link_layer_addr{ +/* link layer addressing */ +typedef struct ieee_802154_long_t { uint8_t uint8[8]; -} link_layer_addr; +} ieee_802154_long_t; + +typedef struct ieee_802154_short_t { + uint8_t uint8[2]; +} ieee_802154_short_t; #define HTONS(a) (uint16_t)((((uint16_t) (a)) << 8) | (((uint16_t) (a)) >> 8)) #define HTONL(a) ((((uint32_t) (a) & 0xff000000) >> 24) | \ @@ -92,11 +77,15 @@ typedef struct link_layer_addr{ (((uint32_t) (a) & 0x000000ff) << 24)) /* function prototypes */ -void create_link_local_prefix(ipv6_addr *ipaddr); -void create_all_routers_mcast_addr(ipv6_addr *ipaddr); -void set_eui64(ipv6_addr *ipaddr); -link_layer_addr* get_eui(ipv6_addr *ipaddr); +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); void bootstrapping(void); -void print6addr(ipv6_addr *ipaddr); +void print6addr(ipv6_addr_t *ipaddr); #endif /* SIXLOWIP_H*/ diff --git a/sys/net/sixlowpan/sixlowmac.c b/sys/net/sixlowpan/sixlowmac.c index b3087d7cd2..7b2059d426 100644 --- a/sys/net/sixlowpan/sixlowmac.c +++ b/sys/net/sixlowpan/sixlowmac.c @@ -5,13 +5,13 @@ #include "drivers/cc110x/cc1100.h" #include "radio/radio.h" -#define ipv6_buf ((struct ipv6_hdr*)&buffer[LL_HDR_LEN]) +#define ipv6_buf ((struct ipv6_hdr_t*)&buffer[LL_HDR_LEN]) /* TODO: payload pointer, payload length */ void send(void){ RADIO.send(get_radio_address(get_eui(&ipv6_buf->destaddr)),NULL,NULL,NULL,NULL); } -uint16_t get_radio_address(link_layer_addr *lla){ +uint16_t get_radio_address(ieee_802154_long_t *lla){ return ((lla->uint8[6] << 8) + lla->uint8[7]); } diff --git a/sys/net/sixlowpan/sixlowmac.h b/sys/net/sixlowpan/sixlowmac.h index 47362c0af2..c73ab1c926 100644 --- a/sys/net/sixlowpan/sixlowmac.h +++ b/sys/net/sixlowpan/sixlowmac.h @@ -7,7 +7,7 @@ #include #include "sixlowip.h" -uint16_t get_radio_address(link_layer_addr *lla); +uint16_t get_radio_address(ieee_802154_long_t *lla); void send(void); diff --git a/sys/net/sixlowpan/sixlownd.c b/sys/net/sixlowpan/sixlownd.c index 16feac338d..f9bb596588 100644 --- a/sys/net/sixlowpan/sixlownd.c +++ b/sys/net/sixlowpan/sixlownd.c @@ -5,29 +5,64 @@ #include uint8_t rtr_sol_count; -uint8_t option_field_length; +uint8_t opt_hdr_len = 0; uint8_t ipv6_ext_hdr_len = 0; uint16_t packet_length; -#define ipv6_buf ((struct ipv6_hdr*)&buffer[LL_HDR_LEN]) -#define icmp_buf ((struct icmpv6_hdr*)&buffer[LLHDR_IPV6HDR_LEN]) -/* fields after icmp header*/ -#define rtr_adv_buf ((struct rtr_adv*)&buffer[LLHDR_ICMPV6HDR_LEN]) -#define iph_llh_buf &buffer[LL_HDR_LEN + IPV6_HDR_LEN] -/* neighbour discovery options rfc4861 4.6 */ -#define opt_stllao_buf ((struct opt_stllao*)&buffer[LLHDR_IPV6HDR_LEN + option_field_length]) -#define opt_mtu_buf ((struct opt_mtu*)&buffer[LLHDR_IPV6HDR_LEN + option_field_length]) -#define opt_pi_buf ((struct opt_pi*)&buffer[LLHDR_IPV6HDR_LEN + option_field_length]) +struct rtr_adv_t* get_rtr_adv_buf(uint8_t ext_len){ + return ((struct rtr_adv_t*)&(buffer[LLHDR_ICMPV6HDR_LEN + ext_len])); +} + +struct nbr_sol_t* get_nbr_sol_buf(uint8_t ext_len){ + return ((struct nbr_sol_t*)&(buffer[LLHDR_ICMPV6HDR_LEN + ext_len])); +} + +struct opt_stllao_t* get_opt_stllao_buf(uint8_t ext_len, uint8_t opt_len){ + return ((struct opt_stllao_t*)&(buffer[LLHDR_ICMPV6HDR_LEN + + ext_len + opt_len])); +} + +struct opt_mtu_t* get_opt_mtu_buf(uint8_t ext_len, uint8_t opt_len){ + return ((struct opt_mtu_t*)&(buffer[LLHDR_ICMPV6HDR_LEN + + ext_len + opt_len])); +} + +struct opt_pi_t* get_opt_pi_buf(uint8_t ext_len, uint8_t opt_len){ + return ((struct opt_pi_t*)&(buffer[LLHDR_ICMPV6HDR_LEN + + ext_len + opt_len])); +} + +struct opt_aro_t* get_opt_aro_buf(uint8_t ext_len, uint8_t opt_len){ + return ((struct opt_aro_t*)&(buffer[LLHDR_ICMPV6HDR_LEN + + ext_len + opt_len])); +} + +/* data stuctures */ +// TODO: prefix list size initialwert herausfinden +pfx_elem_t plist[OPT_PI_LIST_LEN]; + +/* pointer */ +static pfx_elem_t *pelem; +static uint8_t *llao; + +static struct ipv6_hdr_t *ipv6_buf; +static struct icmpv6_hdr_t *icmp_buf; +static struct rtr_adv_t *rtr_adv_buf; +static struct nbr_sol_t *nbr_sol_buf; +static struct opt_stllao_t *opt_stllao_buf; +static struct opt_mtu_t *opt_mtu_buf; +static struct opt_pi_t *opt_pi_buf; +static struct opt_aro_t *opt_aro_buf; + /* send router solicitation message - RFC4861 section 4.1 */ void send_rtr_sol(void){ - //uint8_t ipv6_ext_hdr_len = 0; + ipv6_buf = get_ipv6_buf(); + icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len); if(rtr_sol_count < RTR_SOL_MAX){ packet_length = 0; - icmp_buf->type = ICMP_RTR_SOL; icmp_buf->code = 0; - ipv6_buf->version_trafficclass = IPV6_VER; ipv6_buf->trafficclass_flowlabel = 0; ipv6_buf->flowlabel = 0; @@ -35,13 +70,16 @@ void send_rtr_sol(void){ ipv6_buf->hoplimit = ND_HOPLIMIT; create_all_routers_mcast_addr(&ipv6_buf->destaddr); - + print6addr(&ipv6_buf->destaddr); - - /* set payload length */ + + opt_hdr_len = RTR_SOL_LEN; ipv6_buf->length = ICMPV6_HDR_LEN + RTR_SOL_LEN + OPT_STLLAO_LEN; - set_llao(&buffer[LLHDR_ICMPV6HDR_LEN + RTR_SOL_LEN], OPT_SLLAO_TYPE); + + opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, opt_hdr_len); + set_llao((uint8_t*)opt_stllao_buf, OPT_SLLAO_TYPE); icmp_buf->checksum = 0; + icmp_buf->checksum = ~chksum_calc(ICMPV6_NXT_HDR); printf("%x\n",icmp_buf->checksum); @@ -52,48 +90,58 @@ void send_rtr_sol(void){ } void recv_rtr_sol(void){ - option_field_length = RTR_SOL_LEN; - uint8_t *llao; + opt_hdr_len = RTR_SOL_LEN; /* get link layer address option from buf */ if(opt_stllao_buf->type == OPT_STLLAO_LEN){ - llao = opt_stllao_buf; + llao = (uint8_t*)opt_stllao_buf; } if(llao != NULL){ // TODO: Neighbor lookup } - send_rtr_adv(); + //send_rtr_adv(); } -void send_rtr_adv(ipv6_addr *addr){ +void send_rtr_adv(ipv6_addr_t *addr){ + ipv6_buf = get_ipv6_buf(); + icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len); + ipv6_buf->version_trafficclass = IPV6_VER; ipv6_buf->trafficclass_flowlabel = 0; ipv6_buf->flowlabel = 0; ipv6_buf->nextheader = ICMPV6_NXT_HDR; ipv6_buf->hoplimit = ND_HOPLIMIT; - // not solicited + /* not solicited */ create_all_nodes_mcast_addr(&ipv6_buf->destaddr); icmp_buf->type = ICMP_RTR_ADV; icmp_buf->code = 0; - //TODO: gethoplimit func, set current ttl + //TODO: gethoplimit func, set current ttl + + rtr_adv_buf = get_rtr_adv_buf(ipv6_ext_hdr_len); rtr_adv_buf->hoplimit = MULTIHOP_HOPLIMIT; - // set M and O flag, last 6 bits are zero + /* set M and O flag, last 6 bits are zero */ rtr_adv_buf->autoconfig_flags = (RTR_ADV_M_FLAG << 7) | (RTR_ADV_O_FLAG << 6); rtr_adv_buf->router_lifetime = RTR_ADV_MAX_INTERVAL * RTR_ADV_MAX; rtr_adv_buf->reachable_time = 0; rtr_adv_buf->retrans_timer = 0; - + opt_hdr_len = RTR_ADV_LEN; + + /* set link layer address option */ + opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, opt_hdr_len); set_llao((uint8_t *)opt_stllao_buf,OPT_STLLAO_LEN); + opt_hdr_len += OPT_STLLAO_LEN; /* set MTU options */ + opt_mtu_buf = get_opt_mtu_buf(ipv6_ext_hdr_len, opt_hdr_len); opt_mtu_buf->type = OPT_MTU_TYPE; opt_mtu_buf->length = OPT_MTU_LEN; opt_mtu_buf->reserved = 0; - // 1500 octets mtu + /* 1500 octets mtu */ opt_mtu_buf->mtu = HTONL(1500); + opt_hdr_len += OPT_MTU_HDR_LEN; /* set packet length */ packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + @@ -101,15 +149,115 @@ void send_rtr_adv(ipv6_addr *addr){ /* set payload length field */ /* set prefix option */ -// for(){ -// -// } + opt_pi_buf = get_opt_pi_buf(ipv6_ext_hdr_len, opt_hdr_len); + for(int i=0;iaddr = plist[i].addr; + opt_pi_buf->type = OPT_PI_TYPE; + opt_pi_buf->length = OPT_PI_LEN; + opt_pi_buf->prefix_length = plist[i].length; + opt_pi_buf->l_a_reserved1 = plist[i].l_a_reserved1; + opt_pi_buf->val_ltime = HTONL(pelem->val_ltime); + opt_pi_buf->pref_ltime = HTONL(pelem->val_ltime); + opt_pi_buf->reserved2 = 0; + packet_length += OPT_PI_HDR_LEN; + opt_hdr_len += OPT_PI_HDR_LEN; + } + } ipv6_buf->length = packet_length - IPV6_HDR_LEN; /* calculate checksum */ icmp_buf->checksum = 0; icmp_buf->checksum = ~chksum_calc(ICMPV6_NXT_HDR); + printf("%x\n",icmp_buf->checksum); +} + +void send_nbr_sol(ipv6_addr_t *src, ipv6_addr_t *dest, ipv6_addr_t *targ){ + ipv6_ext_hdr_len = 0; + ipv6_buf = get_ipv6_buf(); + ipv6_buf->version_trafficclass = IPV6_VER; + ipv6_buf->trafficclass_flowlabel = 0; + ipv6_buf->flowlabel = 0; + ipv6_buf->nextheader = ICMPV6_NXT_HDR; + ipv6_buf->hoplimit = ND_HOPLIMIT; + + if(src == NULL){ + // TODO: src auswaehlen + } else{ + ipv6_buf->srcaddr = *src; + } + if(dest == NULL){ + // TODO: solicited knoten erstellen + } else{ + ipv6_buf->destaddr = *dest; + } + + icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len); + icmp_buf->type = ICMP_NBR_SOL; + icmp_buf->code = 0; + + nbr_sol_buf = get_nbr_sol_buf(ipv6_ext_hdr_len); + nbr_sol_buf->reserved = 0; + nbr_sol_buf->tgtaddr = *targ; + opt_hdr_len = NBR_SOL_LEN; + + /* set sllao option */ + opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, opt_hdr_len); + set_llao((uint8_t*)opt_stllao_buf, OPT_SLLAO_TYPE); + opt_hdr_len += OPT_STLLAO_LEN; + + /* set aro option */ + opt_aro_buf = get_opt_aro_buf(ipv6_ext_hdr_len, opt_hdr_len); + opt_aro_buf->type = OPT_ARO_TYPE; + opt_aro_buf->length = OPT_ARO_LEN; + opt_aro_buf->status = 0; + opt_aro_buf->reserved1 = 0; + opt_aro_buf->reserved2 = 0; + opt_aro_buf->eui64 = *get_eui(src); + opt_hdr_len += OPT_ARO_HDR_LEN; + + packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + NBR_SOL_LEN + + OPT_STLLAO_LEN + OPT_ARO_HDR_LEN; + ipv6_buf->length = packet_length - IPV6_HDR_LEN; +} + +void pfx_add(ipv6_addr_t *addr, uint8_t size, uint32_t val_ltime, + uint32_t pref_ltime, uint8_t adv_opt, uint8_t l_a_reserved1){ + if(pfx_chk_list(addr,size) == 1){ + pelem->inuse = 1; + pelem->length = size; + pelem->adv = adv_opt; + pelem->l_a_reserved1 = l_a_reserved1; + pelem->val_ltime = val_ltime; + pelem->pref_ltime = pref_ltime; + pelem->addr = *addr; + } +} + +uint8_t pfx_chk_list(ipv6_addr_t *addr, uint8_t size){ + pelem = NULL; + for(int i=0 ; i < size ; i++){ + if(plist[i].inuse){ + if(pfx_cmp(&plist[i].addr, addr)){ + *pelem = plist[i]; + return 0; + } + } else { + *pelem = plist[i]; + } + } + if(pelem){ + return 1; + } + return 2; +} + +uint8_t pfx_cmp(ipv6_addr_t *addr1, ipv6_addr_t *addr2){ + if(memcmp(addr1, addr2, 8) == 0){ + return 1; + } + return 0; } /* link-layer address option - RFC4861 section 4.6.1/ RFC4944 8. */ @@ -118,12 +266,13 @@ void set_llao(uint8_t *llao, uint8_t type){ if(OPT_STLLAO_LEN == 16){ // 802.15.4 long address llao[1] = 2; - } else + } else{ // 16-bit short address llao[1] = 1; + } // get link layer address - link_layer_addr *mac = get_eui(&ipv6_buf->srcaddr); - //get_link_layer_addr_from_ipaddr(&ipv6_buf->srcaddr,&mac); + ieee_802154_long_t *mac = get_eui(&ipv6_buf->srcaddr); + //get_ieee_802154_long_t_from_ipaddr(&ipv6_buf->srcaddr,&mac); memcpy(&llao[2], mac, SIXLOWPAN_IPV6_LL_ADDR_LEN); // padding (all zeros) - 48bit @@ -135,9 +284,10 @@ void set_llao(uint8_t *llao, uint8_t type){ uint16_t chksum_calc(uint8_t type){ uint16_t length = ipv6_buf->length; uint16_t sum = length + type; - - uint8_t *addrptr = (uint8_t)&ipv6_buf->srcaddr; - uint16_t addr_fields_length = (2 * sizeof(ipv6_addr)); + + /* address field chksum */ + uint8_t *addrptr = (uint8_t*)&ipv6_buf->srcaddr; + uint16_t addr_fields_length = (2 * sizeof(ipv6_addr_t)); while(addr_fields_length > 1){ sum += (addrptr[0] << 8) + addrptr[1]; addrptr += 2; @@ -147,7 +297,8 @@ uint16_t chksum_calc(uint8_t type){ sum += (addrptr[0] << 8) + 0; } - uint8_t *bufptr = iph_llh_buf; + /* header chksum */ + uint8_t *bufptr = (uint8_t*) get_icmpv6_buf(0); while(length > 1){ sum += (bufptr[0] << 8) + bufptr[1]; bufptr += 2; diff --git a/sys/net/sixlowpan/sixlownd.h b/sys/net/sixlowpan/sixlownd.h index c503fdf644..f0dbc759fa 100644 --- a/sys/net/sixlowpan/sixlownd.h +++ b/sys/net/sixlowpan/sixlownd.h @@ -10,47 +10,78 @@ #define RTR_ADV_MAX 3 #define RTR_ADV_MAX_INTERVAL 600 #define RTR_ADV_LEN 12 +/* neighbour solicitation */ +#define NBR_SOL_LEN 20 +/* neighbour advertisement */ +#define NBR_ADV_LEN 20 /* icmp message types rfc4861 4.*/ #define ICMP_RTR_ADV 134 -#define ICMP_RTR_SOL 133 +#define ICMP_RTR_SOL 133 +#define ICMP_NBR_ADV 136 +#define ICMP_NBR_SOL 135 /* stllao option rfc4861 4.6.1 */ #define OPT_STLLAO_LEN 16 #define OPT_SLLAO_TYPE 1 -#define OPT_TLLAO_TYPE 2 +#define OPT_TLLAO_TYPE 2 +/* prefix info option rfc 4.6.2 */ +#define OPT_PI_LIST_LEN 5 //TODO: initalwert suchen +#define OPT_PI_TYPE 3 +#define OPT_PI_LEN 4 +#define OPT_PI_HDR_LEN 32 /* mtu option rfc4861 4.6.4 */ #define OPT_MTU_TYPE 5 #define OPT_MTU_LEN 1 #define OPT_MTU_HDR_LEN 8 +/* aro - address registration option draft-ietf-6lowpan-nd-14 4.2 */ +#define OPT_ARO_TYPE 31 // TBD1 +#define OPT_ARO_LEN 2 +#define OPT_ARO_HDR_LEN 16 +#define OPT_ARO_LTIME 300 // geeigneten wert finden -typedef struct opt_stllao { +typedef struct opt_stllao_t { uint8_t type; uint8_t length; -} opt_stllao; +} opt_stllao_t; -typedef struct opt_mtu { +typedef struct opt_mtu_t { uint8_t type; uint8_t length; uint16_t reserved; uint32_t mtu; -} opt_mtu; +} opt_mtu_t; -typedef struct opt_pi { +typedef struct opt_pi_t { uint8_t type; uint8_t length; uint8_t prefix_length; + uint8_t l_a_reserved1; + uint32_t val_ltime; + uint32_t pref_ltime; + uint32_t reserved2; + ipv6_addr_t addr; +} opt_pi_t; + +typedef struct opt_aro_t { + uint8_t type; + uint8_t length; + uint8_t status; uint8_t reserved1; - uint32_t valid_lifetime; - uint32_t preferred_lifetime; - ipv6_addr prefix; -} opt_pi; + uint16_t reserved2; + uint16_t reg_ltime; + ieee_802154_long_t eui64; +} opt_aro_t; -typedef struct prefix_list { - ipv6_addr prefix; - uint8_t inuse; - uint8_t advertisment; -} prefix_list; +typedef struct pfx_elem_t { + uint8_t inuse; + uint8_t adv; + ipv6_addr_t addr; + uint8_t length; + uint8_t l_a_reserved1; + uint32_t val_ltime; + uint32_t pref_ltime; +} pfx_elem_t; -struct rtr_adv { +struct rtr_adv_t { uint8_t hoplimit; uint8_t autoconfig_flags; uint16_t router_lifetime; @@ -58,5 +89,25 @@ struct rtr_adv { uint32_t retrans_timer; }; +struct nbr_sol_t { + uint32_t reserved; + ipv6_addr_t tgtaddr; +}; + +/* function prototypes */ +struct rtr_adv_t* get_rtr_adv_buf(uint8_t ext_len); +struct nbr_sol_t* get_nbr_sol_buf(uint8_t ext_len); +struct opt_stllao_t* get_opt_stllao_buf(uint8_t ext_len, uint8_t opt_len); +struct opt_mtu_t* get_opt_mtu_buf(uint8_t ext_len, uint8_t opt_len); +struct opt_pi_t* get_opt_pi_buf(uint8_t ext_len, uint8_t opt_len); +struct opt_aro_t* get_opt_aro_buf(uint8_t ext_len, uint8_t opt_len); + void send_rtr_sol(void); +void recv_rtr_sol(void); +void send_rtr_adv(ipv6_addr_t *addr); uint16_t chksum_calc(uint8_t type); +uint8_t pfx_chk_list(ipv6_addr_t *addr, uint8_t size); +uint8_t pfx_cmp(ipv6_addr_t *addr1, ipv6_addr_t *addr2); +void pfx_add(ipv6_addr_t *addr, uint8_t size, uint32_t val_ltime, + uint32_t pref_ltime, uint8_t adv_opt, uint8_t l_a_reserved1); +void set_llao(uint8_t *llao, uint8_t type); diff --git a/sys/net/sixlowpan/sixlowpan.c b/sys/net/sixlowpan/sixlowpan.c index 7a099c0f69..7cc04a0e30 100644 --- a/sys/net/sixlowpan/sixlowpan.c +++ b/sys/net/sixlowpan/sixlowpan.c @@ -1,41 +1,14 @@ /* 6LoWPAN layer 3 implementation */ #include -#include "drivers/cc110x/cc1100.h" #include "sixlowmac.h" +#include "sixlowip.h" + +#include "drivers/cc110x/cc1100.h" +#include "radio/radio.h" -static void output(void){ - - // TODO - // 1. get dest addr from function param - // 2. get pointer to packet buffer - // 3. if dest is null send broadcast - // 4. hc1 or hc1x header compression - // 5. check if ip-packet is to large to fit into a single mac-packet - // if no, fragment the packet - // frag1 dispatch + header - // fragn dispatch - // set fragments into queue and send it -} - -/* convert 48-bit MAC address to IPv6 modified EUI-64 Identifier*/ -static eui64 get_eui64_from_mac(void){ - mac_addr maddr; - eui64 ident; - - init_mac_address(maddr); - - /* change bit 7 from oui1 to 1 */ - ident.oui1 = (maddr.oui_1 >> 8) | 0x2; - ident.oui2 = (maddr.oui_1 << 8) | maddr.oui_2; - ident.pattern = MAC_TO_EUI64_PTRN; - ident.ext_ident_1 = maddr.ext_ident_1; - ident.ext_ident_2 = maddr.ext_ident_1; - - return ident; -} - -static void set_6lowpan_address(uint64_t prefix){ - + +void sixlowpan_init(radio_t *rd){ + }