2011-06-19 13:54:49 +02:00
|
|
|
/* 6LoWPAN ND header file */
|
|
|
|
|
|
|
|
#ifndef SIXLOWND_H
|
|
|
|
#define SIXLOWND_H
|
|
|
|
|
2010-10-14 13:14:16 +02:00
|
|
|
#include <stdint.h>
|
2011-01-18 11:02:48 +01:00
|
|
|
#include "vtimer.h"
|
2011-06-18 23:33:27 +02:00
|
|
|
#include "sixlowpan.h"
|
|
|
|
#include "sixlowip.h"
|
2010-10-14 13:14:16 +02:00
|
|
|
|
2010-11-08 10:33:23 +01:00
|
|
|
/* router solicitation */
|
2010-11-09 22:20:26 +01:00
|
|
|
#define RTR_SOL_LEN 4
|
2010-11-08 10:33:23 +01:00
|
|
|
#define RTR_SOL_INTERVAL 4
|
2010-11-09 22:20:26 +01:00
|
|
|
#define RTR_SOL_MAX 3
|
|
|
|
/* router advertisment */
|
|
|
|
#define RTR_ADV_M_FLAG 0
|
|
|
|
#define RTR_ADV_O_FLAG 0
|
|
|
|
#define RTR_ADV_MAX 3
|
|
|
|
#define RTR_ADV_MAX_INTERVAL 600
|
|
|
|
#define RTR_ADV_LEN 12
|
2010-11-22 12:52:56 +01:00
|
|
|
/* neighbour solicitation */
|
|
|
|
#define NBR_SOL_LEN 20
|
|
|
|
/* neighbour advertisement */
|
|
|
|
#define NBR_ADV_LEN 20
|
2011-01-24 22:41:32 +01:00
|
|
|
#define NBR_ADV_FLAG_R 0x80
|
|
|
|
#define NBR_ADV_FLAG_S 0x40
|
|
|
|
#define NBR_ADV_FLAG_O 0x20
|
2010-11-09 22:20:26 +01:00
|
|
|
/* icmp message types rfc4861 4.*/
|
|
|
|
#define ICMP_RTR_ADV 134
|
2010-11-22 12:52:56 +01:00
|
|
|
#define ICMP_RTR_SOL 133
|
|
|
|
#define ICMP_NBR_ADV 136
|
|
|
|
#define ICMP_NBR_SOL 135
|
2010-11-09 22:20:26 +01:00
|
|
|
/* stllao option rfc4861 4.6.1 */
|
|
|
|
#define OPT_STLLAO_LEN 16
|
|
|
|
#define OPT_SLLAO_TYPE 1
|
2010-11-22 12:52:56 +01:00
|
|
|
#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
|
2011-01-18 11:02:48 +01:00
|
|
|
#define OPT_PI_FLAG_A 0x40
|
|
|
|
#define OPT_PI_FLAG_L 0x80
|
|
|
|
#define OPT_PI_VLIFETIME_INFINITE 0xffffffff
|
2010-11-09 22:20:26 +01:00
|
|
|
/* mtu option rfc4861 4.6.4 */
|
|
|
|
#define OPT_MTU_TYPE 5
|
|
|
|
#define OPT_MTU_LEN 1
|
|
|
|
#define OPT_MTU_HDR_LEN 8
|
2010-11-22 12:52:56 +01:00
|
|
|
/* 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
|
2011-06-22 11:49:29 +02:00
|
|
|
#define OPT_ARO_STATE_SUCCESS 0
|
|
|
|
#define OPT_ARO_STATE_DUP_ADDR 1
|
|
|
|
#define OPT_ARO_STATE_NBR_CACHE_FULL 2
|
2011-01-18 11:02:48 +01:00
|
|
|
/* 6lowpan context option */
|
|
|
|
#define OPT_6CO_TYPE 32
|
2011-06-14 18:25:05 +02:00
|
|
|
#define OPT_6CO_MIN_LEN 2
|
|
|
|
#define OPT_6CO_MAX_LEN 3
|
2011-06-18 23:33:47 +02:00
|
|
|
#define OPT_6CO_HDR_LEN 8
|
2011-06-14 18:25:05 +02:00
|
|
|
#define OPT_6CO_LTIME 5 // geeigneten Wert finden
|
2011-06-14 19:21:50 +02:00
|
|
|
#define OPT_6CO_FLAG_C 0x10
|
|
|
|
#define OPT_6CO_FLAG_CID 0x0F
|
2011-06-22 15:25:42 +02:00
|
|
|
#define OPT_6CO_FLAG_C_VALUE_SET 1
|
|
|
|
#define OPT_6CO_FLAG_C_VALUE_UNSET 0
|
2011-01-18 11:02:48 +01:00
|
|
|
/* authoritative border router option */
|
|
|
|
#define OPT_ABRO_TYPE 33
|
2011-06-14 18:25:05 +02:00
|
|
|
#define OPT_ABRO_LEN 3
|
|
|
|
#define OPT_ABRO_HDR_LEN 24
|
2011-06-18 23:33:27 +02:00
|
|
|
/* authoritive border router cache size */
|
|
|
|
#define ABR_CACHE_SIZE 2
|
2011-01-18 11:02:48 +01:00
|
|
|
/* neighbor cache size */
|
|
|
|
#define NBR_CACHE_SIZE 8
|
2011-01-24 22:41:32 +01:00
|
|
|
#define NBR_CACHE_TYPE_GC 1
|
|
|
|
#define NBR_CACHE_TYPE_REG 2
|
|
|
|
#define NBR_CACHE_TYPE_TEN 3
|
|
|
|
#define NBR_CACHE_LTIME_TEN 20
|
2011-01-18 11:02:48 +01:00
|
|
|
/* neighbor status values */
|
|
|
|
#define NBR_STATUS_INCOMPLETE 0
|
|
|
|
#define NBR_STATUS_REACHABLE 1
|
|
|
|
#define NBR_STATUS_STALE 2
|
|
|
|
#define NBR_STATUS_DELAY 3
|
|
|
|
#define NBR_STATUS_PROBE 4
|
|
|
|
/* default router list size */
|
|
|
|
#define DEF_RTR_LST_SIZE 3 // geeigneten wert finden
|
|
|
|
|
2011-01-24 22:41:32 +01:00
|
|
|
extern unsigned int nd_nbr_cache_rem_pid;
|
|
|
|
|
2011-01-18 11:02:48 +01:00
|
|
|
enum option_types_t {
|
|
|
|
OPT_SLLAO = 1,
|
|
|
|
OPT_TLLAO,
|
|
|
|
OPT_PI,
|
|
|
|
OPT_MTU,
|
|
|
|
OPT_ARO,
|
|
|
|
OPT_6CO,
|
|
|
|
OPT_ABRO,
|
|
|
|
OPT_DAR,
|
|
|
|
OPT_DAC,
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct __attribute__ ((packed)) opt_buf_t {
|
|
|
|
uint8_t type;
|
|
|
|
uint8_t length;
|
|
|
|
} opt_buf_t;
|
2010-10-17 16:05:14 +02:00
|
|
|
|
2010-11-30 10:21:29 +01:00
|
|
|
typedef struct __attribute__ ((packed)) opt_stllao_t {
|
2011-01-18 11:02:48 +01:00
|
|
|
uint8_t type;
|
|
|
|
uint8_t length;
|
2010-11-22 12:52:56 +01:00
|
|
|
} opt_stllao_t;
|
2010-10-17 16:05:14 +02:00
|
|
|
|
2010-11-30 10:21:29 +01:00
|
|
|
typedef struct __attribute__ ((packed)) opt_mtu_t {
|
2010-11-08 10:33:23 +01:00
|
|
|
uint8_t type;
|
|
|
|
uint8_t length;
|
|
|
|
uint16_t reserved;
|
|
|
|
uint32_t mtu;
|
2010-11-22 12:52:56 +01:00
|
|
|
} opt_mtu_t;
|
2010-11-08 10:33:23 +01:00
|
|
|
|
2010-11-30 10:21:29 +01:00
|
|
|
typedef struct __attribute__ ((packed)) opt_pi_t {
|
2010-11-08 10:33:23 +01:00
|
|
|
uint8_t type;
|
|
|
|
uint8_t length;
|
|
|
|
uint8_t prefix_length;
|
2010-11-22 12:52:56 +01:00
|
|
|
uint8_t l_a_reserved1;
|
|
|
|
uint32_t val_ltime;
|
|
|
|
uint32_t pref_ltime;
|
|
|
|
uint32_t reserved2;
|
|
|
|
ipv6_addr_t addr;
|
|
|
|
} opt_pi_t;
|
|
|
|
|
2010-11-30 10:21:29 +01:00
|
|
|
typedef struct __attribute__ ((packed)) opt_aro_t {
|
2010-11-22 12:52:56 +01:00
|
|
|
uint8_t type;
|
|
|
|
uint8_t length;
|
|
|
|
uint8_t status;
|
2010-11-08 10:33:23 +01:00
|
|
|
uint8_t reserved1;
|
2010-11-22 12:52:56 +01:00
|
|
|
uint16_t reserved2;
|
|
|
|
uint16_t reg_ltime;
|
|
|
|
ieee_802154_long_t eui64;
|
|
|
|
} opt_aro_t;
|
|
|
|
|
2011-06-18 23:33:47 +02:00
|
|
|
typedef struct __attribute__ ((packed)) opt_6co_hdr_t {
|
2011-06-14 18:25:05 +02:00
|
|
|
uint8_t type;
|
|
|
|
uint8_t length;
|
|
|
|
uint8_t c_length;
|
2011-06-14 19:21:50 +02:00
|
|
|
uint8_t c_flags;
|
2011-06-18 23:33:27 +02:00
|
|
|
uint16_t reserved;
|
2011-06-14 18:25:05 +02:00
|
|
|
uint16_t val_ltime;
|
2011-06-18 23:33:47 +02:00
|
|
|
} opt_6co_hdr_t;
|
2011-06-14 18:25:05 +02:00
|
|
|
|
|
|
|
typedef struct __attribute__ ((packed)) opt_abro_t {
|
|
|
|
uint8_t type;
|
|
|
|
uint8_t length;
|
|
|
|
uint16_t version;
|
|
|
|
uint32_t reserved;
|
|
|
|
ipv6_addr_t addr;
|
|
|
|
} opt_abro_t;
|
|
|
|
|
2011-01-18 11:02:48 +01:00
|
|
|
typedef struct __attribute__ ((packed)) plist_t {
|
2010-11-22 12:52:56 +01:00
|
|
|
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;
|
2011-01-18 11:02:48 +01:00
|
|
|
uint8_t infinite;
|
|
|
|
} plist_t;
|
2010-11-22 12:52:56 +01:00
|
|
|
|
2010-11-30 10:21:29 +01:00
|
|
|
struct __attribute__ ((packed)) rtr_adv_t {
|
2010-11-08 10:33:23 +01:00
|
|
|
uint8_t hoplimit;
|
|
|
|
uint8_t autoconfig_flags;
|
|
|
|
uint16_t router_lifetime;
|
|
|
|
uint32_t reachable_time;
|
|
|
|
uint32_t retrans_timer;
|
|
|
|
};
|
2010-10-17 16:05:14 +02:00
|
|
|
|
2010-11-30 10:21:29 +01:00
|
|
|
struct __attribute__ ((packed)) nbr_sol_t {
|
2010-11-22 12:52:56 +01:00
|
|
|
uint32_t reserved;
|
|
|
|
ipv6_addr_t tgtaddr;
|
|
|
|
};
|
|
|
|
|
2011-01-24 22:41:32 +01:00
|
|
|
struct __attribute__ ((packed)) nbr_adv_t {
|
|
|
|
uint8_t rso;
|
|
|
|
uint8_t reserved[3];
|
|
|
|
ipv6_addr_t tgtaddr;
|
|
|
|
};
|
|
|
|
|
2011-06-18 23:33:27 +02:00
|
|
|
/* authoritive border router cache - draft-draft-ietf-6lowpan-nd-17 */
|
|
|
|
typedef struct __attribute__((packed)) abr_cache_t {
|
|
|
|
uint16_t version;
|
|
|
|
ipv6_addr_t abr_addr;
|
2011-06-24 02:23:47 +02:00
|
|
|
uint8_t contexts[LOWPAN_CONTEXT_MAX];
|
2011-06-18 23:33:27 +02:00
|
|
|
uint8_t contexts_num;
|
|
|
|
} abr_cache_t;
|
2010-11-22 12:52:56 +01:00
|
|
|
|
2011-01-18 11:02:48 +01:00
|
|
|
/* neighbor cache - rfc4861 5.1. */
|
|
|
|
typedef struct __attribute__ ((packed)) nbr_cache_t {
|
2011-01-24 22:41:32 +01:00
|
|
|
uint8_t type;
|
2011-01-18 11:02:48 +01:00
|
|
|
uint8_t state;
|
|
|
|
uint8_t isrouter;
|
|
|
|
ipv6_addr_t addr;
|
|
|
|
ieee_802154_long_t laddr;
|
2011-01-24 22:41:32 +01:00
|
|
|
ieee_802154_short_t saddr;
|
|
|
|
vtimer_t ltime;
|
2011-01-18 11:02:48 +01:00
|
|
|
} nbr_cache_t;
|
|
|
|
|
|
|
|
/* default router list - rfc4861 5.1. */
|
|
|
|
typedef struct __attribute__ ((packed)) def_rtr_lst_t {
|
|
|
|
ipv6_addr_t addr;
|
|
|
|
vtimer_t inval_timer;
|
|
|
|
} def_rtr_lst_t;
|
|
|
|
|
|
|
|
void init_rtr_sol(uint8_t sllao);
|
2010-11-22 12:52:56 +01:00
|
|
|
void recv_rtr_sol(void);
|
2011-05-16 14:26:42 +02:00
|
|
|
void recv_rtr_adv(void);
|
2011-01-18 11:02:48 +01:00
|
|
|
void init_rtr_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8_t pi,
|
|
|
|
uint8_t sixco, uint8_t abro);
|
|
|
|
uint8_t plist_search(ipv6_addr_t *addr);
|
|
|
|
uint8_t plist_cmp(ipv6_addr_t *addr1, ipv6_addr_t *addr2);
|
2011-06-24 14:39:24 +02:00
|
|
|
int8_t plist_add(ipv6_addr_t *addr, uint8_t size, uint32_t val_ltime,
|
2010-11-22 12:52:56 +01:00
|
|
|
uint32_t pref_ltime, uint8_t adv_opt, uint8_t l_a_reserved1);
|
2011-01-18 11:02:48 +01:00
|
|
|
void set_llao(opt_stllao_t *sllao, uint8_t type, uint8_t length);
|
2011-06-18 23:33:27 +02:00
|
|
|
abr_cache_t *abr_update_cache(
|
2011-06-22 15:25:42 +02:00
|
|
|
uint16_t version, ipv6_addr_t *abr_addr,
|
2011-06-24 02:23:47 +02:00
|
|
|
uint8_t *contexts, uint8_t contexts_num);
|
|
|
|
void abr_remove_context(uint8_t context);
|
2011-01-18 11:02:48 +01:00
|
|
|
nbr_cache_t * nbr_cache_search(ipv6_addr_t *ipaddr);
|
2011-06-22 11:49:29 +02:00
|
|
|
uint8_t nbr_cache_add(ipv6_addr_t *ipaddr, ieee_802154_long_t *laddr,
|
2011-01-24 22:41:32 +01:00
|
|
|
uint8_t isrouter, uint8_t state, uint8_t type,
|
|
|
|
uint16_t ltime, ieee_802154_short_t *saddr);
|
|
|
|
void nbr_cache_auto_rem(void);
|
|
|
|
void nbr_cache_rem(ipv6_addr_t *addr);
|
2010-11-30 10:21:29 +01:00
|
|
|
uint16_t icmpv6_csum(uint8_t proto);
|
|
|
|
uint16_t csum(uint16_t sum, uint8_t *buf, uint16_t len);
|
2011-01-18 11:02:48 +01:00
|
|
|
def_rtr_lst_t * def_rtr_lst_search(ipv6_addr_t *ipaddr);
|
|
|
|
void def_rtr_lst_add(ipv6_addr_t *ipaddr, uint32_t rtr_ltime);
|
|
|
|
void def_rtr_lst_rem(def_rtr_lst_t *entry);
|
|
|
|
void init_nbr_sol(ipv6_addr_t *src, ipv6_addr_t *dest, ipv6_addr_t *targ,
|
|
|
|
uint8_t slloa, uint8_t aro);
|
2011-05-16 14:26:42 +02:00
|
|
|
void init_nbr_adv(ipv6_addr_t *src, ipv6_addr_t *dst, ipv6_addr_t *tgt,
|
|
|
|
uint8_t rso, uint8_t sllao, uint8_t aro, uint8_t aro_state);
|
2011-06-24 02:23:47 +02:00
|
|
|
void recv_nbr_adv(void);
|
2011-01-24 22:41:32 +01:00
|
|
|
void recv_nbr_sol(void);
|
2011-06-19 13:54:49 +02:00
|
|
|
#endif /* SIXLOWND_H*/
|