2011-06-22 21:09:06 +02:00
|
|
|
/* 6LoWPAN Edge Router header file */
|
|
|
|
|
|
|
|
#ifndef SIXLOWEDGE_H
|
|
|
|
#define SIXLOWEDGE_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2011-07-05 04:24:13 +02:00
|
|
|
#include <mutex.h>
|
2011-07-11 18:26:12 +02:00
|
|
|
#include <vtimer.h>
|
2011-06-22 21:09:06 +02:00
|
|
|
#include "sixlowip.h"
|
|
|
|
#include "sixlowpan.h"
|
|
|
|
#include "sixlownd.h"
|
2011-07-11 18:26:12 +02:00
|
|
|
#include "semaphore.h"
|
|
|
|
|
|
|
|
#define EDGE_SWS 8
|
|
|
|
#define EDGE_RWS 8
|
|
|
|
#define EDGE_SL_TIMEOUT 500 // microseconds, maybe smaller
|
2011-06-22 21:09:06 +02:00
|
|
|
|
2011-07-05 04:24:13 +02:00
|
|
|
#define EDGE_HEADER_LENGTH 2
|
2011-06-22 21:09:06 +02:00
|
|
|
|
2011-07-05 04:24:13 +02:00
|
|
|
/* packet types of uart-packets */
|
2011-07-09 19:01:40 +02:00
|
|
|
#define EDGE_PACKET_RAW_TYPE 0
|
|
|
|
#define EDGE_PACKET_ACK_TYPE 1
|
|
|
|
#define EDGE_PACKET_CONF_TYPE 2
|
2011-07-05 04:24:13 +02:00
|
|
|
#define EDGE_PACKET_L3_TYPE 3
|
2011-06-22 21:09:06 +02:00
|
|
|
|
2011-07-11 18:26:12 +02:00
|
|
|
/* configuration types */
|
|
|
|
#define EDGE_CONF_SYN 0
|
|
|
|
#define EDGE_CONF_SYNACK 1
|
|
|
|
#define EDGE_CONF_CONTEXT 2
|
|
|
|
#define EDGE_CONF_IPADDR 3
|
|
|
|
|
2011-06-22 21:09:06 +02:00
|
|
|
/* ethertypes for L3 packets */
|
|
|
|
#define EDGE_ETHERTYPE_IPV6 0x86DD
|
|
|
|
|
|
|
|
extern uint16_t abro_version;
|
2011-07-11 18:26:12 +02:00
|
|
|
extern int tun_fd;
|
2011-06-22 21:09:06 +02:00
|
|
|
|
2011-07-05 04:24:13 +02:00
|
|
|
typedef struct __attribute__ ((packed)) edge_packet_t {
|
|
|
|
uint8_t reserved;
|
2011-06-22 21:09:06 +02:00
|
|
|
uint8_t type;
|
|
|
|
uint8_t seq_num;
|
|
|
|
} edge_packet_t;
|
|
|
|
|
2011-07-05 04:24:13 +02:00
|
|
|
typedef struct __attribute__ ((packed)) edge_l3_header_t {
|
|
|
|
uint8_t reserved;
|
2011-06-22 21:09:06 +02:00
|
|
|
uint8_t type;
|
|
|
|
uint8_t seq_num;
|
|
|
|
uint16_t ethertype;
|
|
|
|
} edge_l3_header_t;
|
|
|
|
|
2011-07-11 18:26:12 +02:00
|
|
|
typedef struct __attribute__ ((packed)) edge_conf_header_t {
|
|
|
|
uint8_t reserved;
|
|
|
|
uint8_t type;
|
|
|
|
uint8_t seq_num;
|
|
|
|
uint8_t conftype;
|
|
|
|
} edge_conf_header_t;
|
|
|
|
|
|
|
|
typedef struct __attribute__ ((packed)) edge_addr_packet_t {
|
|
|
|
uint8_t reserved;
|
|
|
|
uint8_t type;
|
|
|
|
uint8_t seq_num;
|
|
|
|
uint8_t conftype;
|
|
|
|
ipv6_addr_t addr;
|
|
|
|
} edge_addr_packet_t;
|
|
|
|
|
|
|
|
typedef struct __attribute__ ((packed)) edge_context_packet_t {
|
|
|
|
uint8_t reserved;
|
|
|
|
uint8_t type;
|
|
|
|
uint8_t seq_num;
|
|
|
|
uint8_t conftype;
|
|
|
|
struct edge_context_t {
|
|
|
|
uint16_t abro_version;
|
|
|
|
uint8_t num;
|
|
|
|
ipv6_addr_t prefix;
|
|
|
|
uint8_t length;
|
|
|
|
uint8_t comp;
|
|
|
|
uint16_t lifetime;
|
|
|
|
} context;
|
|
|
|
} edge_context_packet_t;
|
|
|
|
|
2011-07-05 04:24:13 +02:00
|
|
|
#define EDGE_BUFFER_SIZE (sizeof (edge_l3_header_t) + MTU)
|
|
|
|
|
2011-07-11 18:26:12 +02:00
|
|
|
typedef struct slwin_stat_t {
|
|
|
|
/* Sender state */
|
|
|
|
uint8_t last_ack;
|
|
|
|
uint8_t last_frame;
|
|
|
|
sem_t send_win_not_full;
|
|
|
|
struct send_slot {
|
|
|
|
vtimer_t timeout;
|
|
|
|
uint8_t frame[EDGE_BUFFER_SIZE];
|
|
|
|
size_t frame_len;
|
|
|
|
} send_win[EDGE_SWS];
|
|
|
|
|
|
|
|
/* Receiver state */
|
|
|
|
uint8_t next_exp;
|
|
|
|
struct recv_slot {
|
|
|
|
int8_t received;
|
|
|
|
uint8_t frame[EDGE_BUFFER_SIZE];
|
|
|
|
size_t frame_len;
|
|
|
|
} recv_win[EDGE_RWS];
|
|
|
|
} slwin_stat_t;
|
|
|
|
|
2011-06-22 21:09:06 +02:00
|
|
|
uint8_t edge_initialize(transceiver_type_t trans,ipv6_addr_t *edge_router_addr);
|
2011-07-05 04:24:13 +02:00
|
|
|
void edge_send_ipv6_over_uart(struct ipv6_hdr_t *packet);
|
2011-07-11 18:26:12 +02:00
|
|
|
void edge_send_over_uart(edge_packet_t *packet, int len);
|
2011-07-09 19:06:28 +02:00
|
|
|
void edge_send_ipv6_over_lowpan(struct ipv6_hdr_t *packet, uint8_t aro_flag, uint8_t sixco_flag);
|
2011-06-22 21:09:06 +02:00
|
|
|
void edge_process_lowpan(void);
|
2011-07-11 18:26:12 +02:00
|
|
|
// to be removed
|
|
|
|
void edge_process_uart(void);
|
|
|
|
|
|
|
|
void slwin_init();
|
2011-06-22 21:09:06 +02:00
|
|
|
|
|
|
|
abr_cache_t *get_edge_router_info();
|
|
|
|
|
|
|
|
lowpan_context_t *edge_define_context(uint8_t cid, ipv6_addr_t *prefix, uint8_t prefix_len, uint16_t lifetime);
|
|
|
|
lowpan_context_t *edge_alloc_context(ipv6_addr_t *prefix, uint8_t prefix_len, uint16_t lifetime);
|
|
|
|
|
|
|
|
#endif /* SIXLOWEDGE_H*/
|