mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Refactor ip.h
This commit is contained in:
parent
b1d6e7d639
commit
0e1baea34e
@ -40,7 +40,7 @@ void init_transport_layer(void)
|
||||
int udp_thread_pid = thread_create(udp_stack_buffer, UDP_STACK_SIZE,
|
||||
PRIORITY_MAIN, CREATE_STACKTEST,
|
||||
udp_packet_handler,"udp_packet_handler");
|
||||
set_udp_packet_handler_pid(udp_thread_pid);
|
||||
ipv6_register_next_header_handler(IPV6_PROTO_NUM_UDP, udp_thread_pid);
|
||||
|
||||
/* TCP */
|
||||
timex_t now;
|
||||
@ -55,7 +55,7 @@ void init_transport_layer(void)
|
||||
int tcp_thread_pid = thread_create(tcp_stack_buffer, TCP_STACK_SIZE,
|
||||
PRIORITY_MAIN, CREATE_STACKTEST,
|
||||
tcp_packet_handler, "tcp_packet_handler");
|
||||
set_tcp_packet_handler_pid(tcp_thread_pid);
|
||||
ipv6_register_next_header_handler(IPV6_PROTO_NUM_TCP, tcp_thread_pid);
|
||||
|
||||
thread_create(tcp_timer_stack, TCP_TIMER_STACKSIZE, PRIORITY_MAIN + 1,
|
||||
CREATE_STACKTEST, tcp_general_timer, "tcp_general_timer");
|
||||
|
@ -13,7 +13,8 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Protocols (RFC 1700)
|
||||
* Protocols (RFC 1700) TODO: may be deleted due to some double definition
|
||||
* in sys/net/sixlowpan/include/sixlowpan/ip.h
|
||||
*/
|
||||
#define IPPROTO_IP (0) /* dummy for IP */
|
||||
#define IPPROTO_HOPOPTS (0) /* IP6 hop-by-hop options */
|
||||
|
@ -100,12 +100,13 @@ void print_tcp_cb(tcp_cb_t *cb)
|
||||
void print_tcp_status(int in_or_out, ipv6_hdr_t *ipv6_header,
|
||||
tcp_hdr_t *tcp_header, socket_t *tcp_socket)
|
||||
{
|
||||
char addr_str[IPV6_MAX_ADDR_STR_LEN];
|
||||
printf("--- %s TCP packet: ---\n",
|
||||
(in_or_out == INC_PACKET ? "Incoming" : "Outgoing"));
|
||||
printf("IPv6 Source:");
|
||||
ipv6_print_addr(&ipv6_header->srcaddr);
|
||||
printf("IPv6 Dest:");
|
||||
ipv6_print_addr(&ipv6_header->destaddr);
|
||||
printf("IPv6 Source: %s\n",
|
||||
ipv6_addr_to_str(addr_str, &ipv6_header->srcaddr));
|
||||
printf("IPv6 Dest: %s\n",
|
||||
ipv6_addr_to_str(addr_str, &ipv6_header->destaddr));
|
||||
printf("TCP Length: %x\n", ipv6_header->length - TCP_HDR_LEN);
|
||||
printf("Source Port: %x, Dest. Port: %x\n",
|
||||
NTOHS(tcp_header->src_port), NTOHS(tcp_header->dst_port));
|
||||
@ -124,12 +125,17 @@ void print_tcp_status(int in_or_out, ipv6_hdr_t *ipv6_header,
|
||||
|
||||
void print_socket(socket_t *current_socket)
|
||||
{
|
||||
char addr_str[IPV6_MAX_ADDR_STR_LEN];
|
||||
printf("Domain: %i, Type: %i, Protocol: %i \n",
|
||||
current_socket->domain,
|
||||
current_socket->type,
|
||||
current_socket->protocol);
|
||||
ipv6_print_addr(¤t_socket->local_address.sin6_addr);
|
||||
ipv6_print_addr(¤t_socket->foreign_address.sin6_addr);
|
||||
printf("Local address: %s\n",
|
||||
ipv6_addr_to_str(addr_str,
|
||||
¤t_socket->local_address.sin6_addr));
|
||||
printf("Foreign address: %s\n",
|
||||
ipv6_addr_to_str(addr_str,
|
||||
¤t_socket->foreign_address.sin6_addr));
|
||||
printf("Local Port: %u, Foreign Port: %u\n",
|
||||
NTOHS(current_socket->local_address.sin6_port),
|
||||
NTOHS(current_socket->foreign_address.sin6_port));
|
||||
@ -294,11 +300,11 @@ socket_internal_t *get_udp_socket(ipv6_hdr_t *ipv6_header, udp_hdr_t *udp_header
|
||||
bool is_four_touple(socket_internal_t *current_socket, ipv6_hdr_t *ipv6_header,
|
||||
tcp_hdr_t *tcp_header)
|
||||
{
|
||||
return ((ipv6_get_addr_match(¤t_socket->socket_values.local_address.sin6_addr,
|
||||
&ipv6_header->destaddr) == 128) &&
|
||||
return (ipv6_addr_is_equal(¤t_socket->socket_values.local_address.sin6_addr,
|
||||
&ipv6_header->destaddr) &&
|
||||
(current_socket->socket_values.local_address.sin6_port == tcp_header->dst_port) &&
|
||||
(ipv6_get_addr_match(¤t_socket->socket_values.foreign_address.sin6_addr,
|
||||
&ipv6_header->srcaddr) == 128) &&
|
||||
ipv6_addr_is_equal(¤t_socket->socket_values.foreign_address.sin6_addr,
|
||||
&ipv6_header->srcaddr) &&
|
||||
(current_socket->socket_values.foreign_address.sin6_port == tcp_header->src_port));
|
||||
}
|
||||
|
||||
@ -470,15 +476,15 @@ int send_tcp(socket_internal_t *current_socket, tcp_hdr_t *current_tcp_packet,
|
||||
return -1;
|
||||
}
|
||||
|
||||
sixlowpan_send(¤t_tcp_socket->foreign_address.sin6_addr,
|
||||
(uint8_t *)(current_tcp_packet), compressed_size,
|
||||
IPPROTO_TCP);
|
||||
ipv6_sendto(¤t_tcp_socket->foreign_address.sin6_addr,
|
||||
IPPROTO_TCP, (uint8_t *)(current_tcp_packet),
|
||||
compressed_size);
|
||||
return 1;
|
||||
#else
|
||||
switch_tcp_packet_byte_order(current_tcp_packet);
|
||||
sixlowpan_send(¤t_tcp_socket->foreign_address.sin6_addr,
|
||||
(uint8_t *)(current_tcp_packet),
|
||||
header_length * 4 + payload_length, IPPROTO_TCP);
|
||||
ipv6_sendto(¤t_tcp_socket->foreign_address.sin6_addr,
|
||||
IPPROTO_TCP, (uint8_t *)(current_tcp_packet),
|
||||
header_length * 4 + payload_length);
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
@ -516,7 +522,7 @@ int connect(int socket, sockaddr6_t *addr, uint32_t addrlen)
|
||||
current_int_tcp_socket->recv_pid = thread_getpid();
|
||||
|
||||
/* Local address information */
|
||||
ipv6_get_saddr(&src_addr, &addr->sin6_addr);
|
||||
ipv6_iface_get_best_src_addr(&src_addr, &addr->sin6_addr);
|
||||
set_socket_address(¤t_tcp_socket->local_address, PF_INET6,
|
||||
HTONS(get_free_source_port(IPPROTO_TCP)), 0, &src_addr);
|
||||
|
||||
@ -979,7 +985,7 @@ int32_t sendto(int s, const void *msg, uint32_t len, int flags,
|
||||
uint8_t *payload = &send_buffer[IPV6_HDR_LEN + UDP_HDR_LEN];
|
||||
|
||||
memcpy(&(temp_ipv6_header->destaddr), &to->sin6_addr, 16);
|
||||
ipv6_get_saddr(&(temp_ipv6_header->srcaddr), &(temp_ipv6_header->destaddr));
|
||||
ipv6_iface_get_best_src_addr(&(temp_ipv6_header->srcaddr), &(temp_ipv6_header->destaddr));
|
||||
|
||||
current_udp_packet->src_port = get_free_source_port(IPPROTO_UDP);
|
||||
current_udp_packet->dst_port = to->sin6_port;
|
||||
@ -992,8 +998,9 @@ int32_t sendto(int s, const void *msg, uint32_t len, int flags,
|
||||
current_udp_packet->checksum = ~udp_csum(temp_ipv6_header,
|
||||
current_udp_packet);
|
||||
|
||||
sixlowpan_send(&to->sin6_addr, (uint8_t *)(current_udp_packet),
|
||||
current_udp_packet->length, IPPROTO_UDP);
|
||||
ipv6_sendto(&to->sin6_addr, IPPROTO_UDP,
|
||||
(uint8_t *)(current_udp_packet),
|
||||
current_udp_packet->length);
|
||||
return current_udp_packet->length;
|
||||
}
|
||||
else {
|
||||
|
@ -37,10 +37,10 @@ socket_internal_t *get_tcp_socket_by_context(ipv6_hdr_t *current_ipv6_header,
|
||||
temp_socket = getSocket(i);
|
||||
|
||||
if ((temp_socket != NULL) &&
|
||||
(ipv6_get_addr_match(&temp_socket->socket_values.foreign_address.sin6_addr,
|
||||
¤t_ipv6_header->srcaddr) == 128) &&
|
||||
(ipv6_get_addr_match(&temp_socket->socket_values.local_address.sin6_addr,
|
||||
¤t_ipv6_header->destaddr) == 128) &&
|
||||
ipv6_addr_is_equal(&temp_socket->socket_values.foreign_address.sin6_addr,
|
||||
¤t_ipv6_header->srcaddr) &&
|
||||
ipv6_addr_is_equal(&temp_socket->socket_values.local_address.sin6_addr,
|
||||
¤t_ipv6_header->destaddr) &&
|
||||
(temp_socket->socket_values.tcp_control.tcp_context.context_id ==
|
||||
current_context)) {
|
||||
return temp_socket;
|
||||
|
@ -382,8 +382,8 @@ void etx_radio(void)
|
||||
ipv6_addr_t ll_address;
|
||||
ipv6_addr_t candidate_addr;
|
||||
|
||||
ipv6_set_ll_prefix(&ll_address);
|
||||
ipv6_get_saddr(&candidate_addr, &ll_address);
|
||||
ipv6_addr_set_link_local_prefix(&ll_address);
|
||||
ipv6_iface_get_best_src_addr(&candidate_addr, &ll_address);
|
||||
|
||||
while (1) {
|
||||
msg_receive(&m);
|
||||
|
@ -197,9 +197,9 @@ uint8_t rpl_init(transceiver_type_t trans, uint16_t rpl_address)
|
||||
sixlowpan_lowpan_init(trans, rpl_address, 0);
|
||||
/* need link local prefix to query _our_ corresponding address */
|
||||
ipv6_addr_t ll_address;
|
||||
ipv6_set_ll_prefix(&ll_address);
|
||||
ipv6_get_saddr(&my_address, &ll_address);
|
||||
set_rpl_process_pid(rpl_process_pid);
|
||||
ipv6_addr_set_link_local_prefix(&ll_address);
|
||||
ipv6_iface_get_best_src_addr(&my_address, &ll_address);
|
||||
ipv6_register_rpl_handler(rpl_process_pid);
|
||||
|
||||
/* initialize ETX-calculation if needed */
|
||||
if (RPL_DEFAULT_OCP == 1) {
|
||||
@ -275,7 +275,7 @@ void send_DIO(ipv6_addr_t *destination)
|
||||
|
||||
icmp_send_buf->type = ICMP_RPL_CONTROL;
|
||||
icmp_send_buf->code = ICMP_CODE_DIO;
|
||||
icmp_send_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6);
|
||||
icmp_send_buf->checksum = ~icmpv6_csum(IPV6_PROTO_NUM_ICMPV6);
|
||||
|
||||
rpl_send_dio_buf = get_rpl_send_dio_buf();
|
||||
memset(rpl_send_dio_buf, 0, sizeof(*rpl_send_dio_buf));
|
||||
@ -309,7 +309,7 @@ void send_DIO(ipv6_addr_t *destination)
|
||||
|
||||
|
||||
uint16_t plen = ICMPV6_HDR_LEN + DIO_BASE_LEN + opt_hdr_len;
|
||||
rpl_send(destination, (uint8_t *)icmp_send_buf, plen, PROTO_NUM_ICMPV6, NULL);
|
||||
rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6, NULL);
|
||||
mutex_unlock(&rpl_send_mutex);
|
||||
}
|
||||
|
||||
@ -320,12 +320,12 @@ void send_DIS(ipv6_addr_t *destination)
|
||||
|
||||
icmp_send_buf->type = ICMP_RPL_CONTROL;
|
||||
icmp_send_buf->code = ICMP_CODE_DIS;
|
||||
icmp_send_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6);
|
||||
icmp_send_buf->checksum = ~icmpv6_csum(IPV6_PROTO_NUM_ICMPV6);
|
||||
|
||||
rpl_send_dis_buf = get_rpl_send_dis_buf();
|
||||
|
||||
uint16_t plen = ICMPV6_HDR_LEN + DIS_BASE_LEN;
|
||||
rpl_send(destination, (uint8_t *)icmp_send_buf, plen, PROTO_NUM_ICMPV6, NULL);
|
||||
rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6, NULL);
|
||||
mutex_unlock(&rpl_send_mutex);
|
||||
}
|
||||
|
||||
@ -352,7 +352,7 @@ void send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime,
|
||||
|
||||
icmp_send_buf->type = ICMP_RPL_CONTROL;
|
||||
icmp_send_buf->code = ICMP_CODE_DAO;
|
||||
icmp_send_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6);
|
||||
icmp_send_buf->checksum = ~icmpv6_csum(IPV6_PROTO_NUM_ICMPV6);
|
||||
|
||||
if (my_dodag == NULL) {
|
||||
mutex_unlock(&rpl_send_mutex);
|
||||
@ -416,7 +416,7 @@ void send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime,
|
||||
opt_len += RPL_OPT_TRANSIT_LEN + 2;
|
||||
|
||||
uint16_t plen = ICMPV6_HDR_LEN + DAO_BASE_LEN + opt_len;
|
||||
rpl_send(destination, (uint8_t *)icmp_send_buf, plen, PROTO_NUM_ICMPV6, NULL);
|
||||
rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6, NULL);
|
||||
mutex_unlock(&rpl_send_mutex);
|
||||
|
||||
if (continue_index > 1) {
|
||||
@ -426,7 +426,8 @@ void send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime,
|
||||
|
||||
void send_DAO_ACK(ipv6_addr_t *destination)
|
||||
{
|
||||
ipv6_print_addr(destination);
|
||||
char addr_str[IPV6_MAX_ADDR_STR_LEN];
|
||||
printf("%s\n", ipv6_addr_to_str(addr_str, destination));
|
||||
rpl_dodag_t *my_dodag;
|
||||
my_dodag = rpl_get_my_dodag();
|
||||
|
||||
@ -439,7 +440,7 @@ void send_DAO_ACK(ipv6_addr_t *destination)
|
||||
|
||||
icmp_send_buf->type = ICMP_RPL_CONTROL;
|
||||
icmp_send_buf->code = ICMP_CODE_DAO_ACK;
|
||||
icmp_send_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6);
|
||||
icmp_send_buf->checksum = ~icmpv6_csum(IPV6_PROTO_NUM_ICMPV6);
|
||||
|
||||
rpl_send_dao_ack_buf = get_rpl_send_dao_ack_buf();
|
||||
rpl_send_dao_ack_buf->rpl_instanceid = my_dodag->instance->id;
|
||||
@ -448,7 +449,7 @@ void send_DAO_ACK(ipv6_addr_t *destination)
|
||||
rpl_send_dao_ack_buf->status = 0;
|
||||
|
||||
uint16_t plen = ICMPV6_HDR_LEN + DIS_BASE_LEN;
|
||||
rpl_send(destination, (uint8_t *)icmp_send_buf, plen, PROTO_NUM_ICMPV6, NULL);
|
||||
rpl_send(destination, (uint8_t *)icmp_send_buf, plen, IPV6_PROTO_NUM_ICMPV6, NULL);
|
||||
mutex_unlock(&rpl_send_mutex);
|
||||
}
|
||||
|
||||
@ -463,7 +464,7 @@ void rpl_process(void)
|
||||
uint8_t *code;
|
||||
code = ((uint8_t *)m_recv.content.ptr);
|
||||
/* differentiate packet types */
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = ipv6_get_buf();
|
||||
memcpy(&rpl_buffer, ipv6_buf, ipv6_buf->length + IPV6_HDR_LEN);
|
||||
|
||||
switch (*code) {
|
||||
@ -637,8 +638,9 @@ void recv_rpl_dio(void)
|
||||
}
|
||||
|
||||
if (rpl_dio_buf->rank != INFINITE_RANK) {
|
||||
char addr_str[IPV6_MAX_ADDR_STR_LEN];
|
||||
DEBUG("Will join DODAG\n");
|
||||
ipv6_print_addr(&dio_dodag.dodag_id);
|
||||
printf("%s", ipv6_addr_to_str(addr_str, &dio_dodag.dodag_id));
|
||||
rpl_join_dodag(&dio_dodag, &ipv6_buf->srcaddr, rpl_dio_buf->rank);
|
||||
}
|
||||
else {
|
||||
@ -898,7 +900,7 @@ void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_
|
||||
ipv6_send_buf->length = p_len;
|
||||
|
||||
memcpy(&(ipv6_send_buf->destaddr), destination, 16);
|
||||
ipv6_get_saddr(&(ipv6_send_buf->srcaddr), &(ipv6_send_buf->destaddr));
|
||||
ipv6_iface_get_best_src_addr(&(ipv6_send_buf->srcaddr), &(ipv6_send_buf->destaddr));
|
||||
|
||||
/* The packet was "assembled" in rpl.c. Therefore rpl_send_buf was used.
|
||||
* Therefore memcpy is not needed because the payload is at the
|
||||
@ -910,7 +912,7 @@ void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_
|
||||
|
||||
packet_length = IPV6_HDR_LEN + p_len;
|
||||
|
||||
if (ipv6_prefix_mcast_match(&ipv6_send_buf->destaddr)) {
|
||||
if (ipv6_addr_is_multicast(&ipv6_send_buf->destaddr)) {
|
||||
sixlowpan_lowpan_sendto((ieee_802154_long_t *) &(ipv6_send_buf->destaddr.uint16[4]),
|
||||
(uint8_t *)ipv6_send_buf,
|
||||
packet_length);
|
||||
|
@ -140,7 +140,7 @@ void trickle_increment_counter(void)
|
||||
void trickle_timer_over(void)
|
||||
{
|
||||
ipv6_addr_t mcast;
|
||||
ipv6_set_all_nds_mcast_addr(&mcast);
|
||||
ipv6_addr_set_all_nodes_addr(&mcast);
|
||||
|
||||
while (1) {
|
||||
thread_sleep();
|
||||
|
@ -120,8 +120,8 @@ void serial_reader_f(void)
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t sixlowpan_lowpan_border_init(transceiver_type_t trans,
|
||||
const ipv6_addr_t *border_router_addr)
|
||||
uint8_t sixlowpan_lowpan_border_init(transceiver_type_t trans,
|
||||
const ipv6_addr_t *border_router_addr)
|
||||
{
|
||||
ipv6_addr_t addr;
|
||||
|
||||
@ -170,8 +170,8 @@ void border_process_lowpan(void)
|
||||
msg_receive(&m);
|
||||
ipv6_buf = (ipv6_hdr_t *)m.content.ptr;
|
||||
|
||||
if (ipv6_buf->nextheader == PROTO_NUM_ICMPV6) {
|
||||
struct icmpv6_hdr_t *icmp_buf = (struct icmpv6_hdr_t *)(((uint8_t *)ipv6_buf) + IPV6_HDR_LEN);
|
||||
if (ipv6_buf->nextheader == IPV6_PROTO_NUM_ICMPV6) {
|
||||
icmpv6_hdr_t *icmp_buf = (icmpv6_hdr_t *)(((uint8_t *)ipv6_buf) + IPV6_HDR_LEN);
|
||||
|
||||
if (icmp_buf->type == ICMP_REDIRECT) {
|
||||
continue;
|
||||
|
@ -48,7 +48,7 @@ void demultiplex(border_packet_t *packet, int len)
|
||||
switch (l3_header_buf->ethertype) {
|
||||
case (BORDER_ETHERTYPE_IPV6): {
|
||||
ipv6_hdr_t *ipv6_buf = (ipv6_hdr_t *)(((unsigned char *)packet) + sizeof(border_l3_header_t));
|
||||
ipv6_send_buf(ipv6_buf);
|
||||
ipv6_send_bytes(ipv6_buf);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ void demultiplex(border_packet_t *packet, int len)
|
||||
case (BORDER_CONF_CONTEXT): {
|
||||
border_context_packet_t *context = (border_context_packet_t *)packet;
|
||||
ipv6_addr_t target_addr;
|
||||
ipv6_set_all_nds_mcast_addr(&target_addr);
|
||||
ipv6_addr_set_all_nodes_addr(&target_addr);
|
||||
mutex_lock(&lowpan_context_mutex);
|
||||
lowpan_context_update(
|
||||
context->context.cid,
|
||||
|
@ -80,7 +80,7 @@ typedef struct __attribute__((packed)) {
|
||||
} context;
|
||||
} border_context_packet_t;
|
||||
|
||||
#define BORDER_BUFFER_SIZE (sizeof(border_l3_header_t) + MTU)
|
||||
#define BORDER_BUFFER_SIZE (sizeof(border_l3_header_t) + IPV6_MTU)
|
||||
|
||||
void demultiplex(border_packet_t *packet, int len);
|
||||
void multiplex_send_ipv6_over_uart(ipv6_hdr_t *packet);
|
||||
|
@ -35,8 +35,11 @@
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
|
||||
#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)
|
||||
#define ND_HOPLIMIT (0xFF)
|
||||
|
||||
/* extern variables */
|
||||
uint8_t opt_hdr_len = 0;
|
||||
uint8_t ipv6_ext_hdr_len = 0;
|
||||
|
||||
/* counter */
|
||||
@ -57,7 +60,7 @@ static uint8_t *llao;
|
||||
addr_list_t *addr_list_ptr;
|
||||
|
||||
static ipv6_hdr_t *ipv6_buf;
|
||||
static struct icmpv6_hdr_t *icmp_buf;
|
||||
static icmpv6_hdr_t *icmp_buf;
|
||||
static struct rtr_adv_t *rtr_adv_buf;
|
||||
static struct nbr_sol_t *nbr_sol_buf;
|
||||
static struct nbr_adv_t *nbr_adv_buf;
|
||||
@ -77,6 +80,7 @@ def_rtr_lst_t *def_rtr_entry;
|
||||
//ipv6_addr_t tmpaddr;
|
||||
|
||||
uint8_t recvd_cids[LOWPAN_CONTEXT_MAX];
|
||||
uint8_t icmpv6_opt_hdr_len = 0;
|
||||
uint8_t recvd_cids_len = 0;
|
||||
plist_t *recvd_prefixes[OPT_PI_LIST_LEN];
|
||||
uint8_t recvd_pref_len = 0;
|
||||
@ -169,7 +173,7 @@ void init_echo_req(ipv6_addr_t *destaddr, uint16_t id, uint16_t seq, char *data,
|
||||
{
|
||||
uint16_t packet_length;
|
||||
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = ipv6_get_buf();
|
||||
icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len);
|
||||
struct echo_req_t *echo_buf = get_echo_req_buf(ipv6_ext_hdr_len);
|
||||
char *echo_data_buf = ((char *)echo_buf) + sizeof(struct echo_req_t);
|
||||
@ -179,11 +183,11 @@ void init_echo_req(ipv6_addr_t *destaddr, uint16_t id, uint16_t seq, char *data,
|
||||
ipv6_buf->version_trafficclass = IPV6_VER;
|
||||
ipv6_buf->trafficclass_flowlabel = 0;
|
||||
ipv6_buf->flowlabel = 0;
|
||||
ipv6_buf->nextheader = PROTO_NUM_ICMPV6;
|
||||
ipv6_buf->nextheader = IPV6_PROTO_NUM_ICMPV6;
|
||||
ipv6_buf->hoplimit = 0xff;
|
||||
|
||||
memcpy(&ipv6_buf->destaddr, destaddr, sizeof(ipv6_addr_t));
|
||||
ipv6_get_saddr(&ipv6_buf->srcaddr, &ipv6_buf->destaddr);
|
||||
ipv6_iface_get_best_src_addr(&ipv6_buf->srcaddr, &ipv6_buf->destaddr);
|
||||
echo_buf->id = id;
|
||||
echo_buf->seq = seq;
|
||||
|
||||
@ -194,11 +198,12 @@ void init_echo_req(ipv6_addr_t *destaddr, uint16_t id, uint16_t seq, char *data,
|
||||
ipv6_buf->length = packet_length - IPV6_HDR_LEN;
|
||||
|
||||
icmp_buf->checksum = 0;
|
||||
icmp_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6);
|
||||
icmp_buf->checksum = ~icmpv6_csum(IPV6_PROTO_NUM_ICMPV6);
|
||||
|
||||
#ifdef ENABLE_DEBUG
|
||||
printf("INFO: send echo request to: ");
|
||||
ipv6_print_addr(&ipv6_buf->destaddr);
|
||||
char addr_str[IPV6_MAX_ADDR_STR_LEN];
|
||||
printf("INFO: send echo request to: %s\n",
|
||||
ipv6_addr_to_str(addr_str, &ipv6_buf->destaddr));
|
||||
#endif
|
||||
sixlowpan_lowpan_sendto((ieee_802154_long_t *) & (ipv6_buf->destaddr.uint16[4]),
|
||||
(uint8_t *)ipv6_buf,
|
||||
@ -209,7 +214,7 @@ void init_echo_repl(ipv6_addr_t *destaddr, uint16_t id, uint16_t seq, char *data
|
||||
{
|
||||
uint16_t packet_length;
|
||||
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = ipv6_get_buf();
|
||||
icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len);
|
||||
struct echo_repl_t *echo_buf = get_echo_repl_buf(ipv6_ext_hdr_len);
|
||||
char *echo_data_buf = ((char *)echo_buf) + sizeof(struct echo_repl_t);
|
||||
@ -219,11 +224,11 @@ void init_echo_repl(ipv6_addr_t *destaddr, uint16_t id, uint16_t seq, char *data
|
||||
ipv6_buf->version_trafficclass = IPV6_VER;
|
||||
ipv6_buf->trafficclass_flowlabel = 0;
|
||||
ipv6_buf->flowlabel = 0;
|
||||
ipv6_buf->nextheader = PROTO_NUM_ICMPV6;
|
||||
ipv6_buf->nextheader = IPV6_PROTO_NUM_ICMPV6;
|
||||
ipv6_buf->hoplimit = 0xff;
|
||||
|
||||
memcpy(&ipv6_buf->destaddr, destaddr, sizeof(ipv6_addr_t));
|
||||
ipv6_get_saddr(&ipv6_buf->srcaddr, &ipv6_buf->destaddr);
|
||||
ipv6_iface_get_best_src_addr(&ipv6_buf->srcaddr, &ipv6_buf->destaddr);
|
||||
echo_buf->id = id;
|
||||
echo_buf->seq = seq;
|
||||
|
||||
@ -234,11 +239,12 @@ void init_echo_repl(ipv6_addr_t *destaddr, uint16_t id, uint16_t seq, char *data
|
||||
ipv6_buf->length = packet_length - IPV6_HDR_LEN;
|
||||
|
||||
icmp_buf->checksum = 0;
|
||||
icmp_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6);
|
||||
icmp_buf->checksum = ~icmpv6_csum(IPV6_PROTO_NUM_ICMPV6);
|
||||
|
||||
#ifdef ENABLE_DEBUG
|
||||
printf("INFO: send echo request to: ");
|
||||
ipv6_print_addr(&ipv6_buf->destaddr);
|
||||
char addr_str[IPV6_MAX_ADDR_STR_LEN];
|
||||
printf("INFO: send echo request to: %s\n",
|
||||
ipv6_addr_to_str(addr_str, &ipv6_buf->destaddr));
|
||||
#endif
|
||||
sixlowpan_lowpan_sendto((ieee_802154_long_t *) & (ipv6_buf->destaddr.uint16[4]),
|
||||
(uint8_t *)ipv6_buf,
|
||||
@ -250,7 +256,7 @@ void init_rtr_sol(uint8_t sllao)
|
||||
{
|
||||
uint16_t packet_length;
|
||||
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = ipv6_get_buf();
|
||||
icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len);
|
||||
|
||||
icmp_buf->type = ICMP_RTR_SOL;
|
||||
@ -258,20 +264,20 @@ void init_rtr_sol(uint8_t sllao)
|
||||
ipv6_buf->version_trafficclass = IPV6_VER;
|
||||
ipv6_buf->trafficclass_flowlabel = 0;
|
||||
ipv6_buf->flowlabel = 0;
|
||||
ipv6_buf->nextheader = PROTO_NUM_ICMPV6;
|
||||
ipv6_buf->nextheader = IPV6_PROTO_NUM_ICMPV6;
|
||||
ipv6_buf->hoplimit = ND_HOPLIMIT;
|
||||
|
||||
ipv6_set_all_rtrs_mcast_addr(&ipv6_buf->destaddr);
|
||||
//iface_find_src_ipaddr(&ipv6_buf->srcaddr, ADDR_STATE_PREFERRED,
|
||||
/* ADDR_TYPE_MULTICAST); */
|
||||
ipv6_addr_set_all_routers_addr(&ipv6_buf->destaddr);
|
||||
//iface_find_src_ipaddr(&ipv6_buf->srcaddr, NDP_ADDR_STATE_PREFERRED,
|
||||
/* IPV6_ADDR_TYPE_MULTICAST); */
|
||||
|
||||
ipv6_get_saddr(&(ipv6_buf->srcaddr), &(ipv6_buf->destaddr));
|
||||
ipv6_iface_get_best_src_addr(&(ipv6_buf->srcaddr), &(ipv6_buf->destaddr));
|
||||
|
||||
opt_hdr_len = RTR_SOL_LEN;
|
||||
icmpv6_opt_hdr_len = RTR_SOL_LEN;
|
||||
ipv6_buf->length = HTONS(ICMPV6_HDR_LEN + RTR_SOL_LEN + OPT_STLLAO_MAX_LEN);
|
||||
|
||||
if (sllao == OPT_SLLAO) {
|
||||
opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, opt_hdr_len);
|
||||
opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len);
|
||||
set_llao(opt_stllao_buf, OPT_SLLAO_TYPE, 2);
|
||||
packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + ipv6_ext_hdr_len +
|
||||
RTR_SOL_LEN + OPT_STLLAO_MAX_LEN;
|
||||
@ -282,11 +288,12 @@ void init_rtr_sol(uint8_t sllao)
|
||||
}
|
||||
|
||||
icmp_buf->checksum = 0;
|
||||
icmp_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6);
|
||||
icmp_buf->checksum = ~icmpv6_csum(IPV6_PROTO_NUM_ICMPV6);
|
||||
|
||||
#if ENABLE_DEBUG
|
||||
printf("INFO: send router solicitation to: ");
|
||||
ipv6_print_addr(&ipv6_buf->destaddr);
|
||||
char addr_str[IPV6_MAX_ADDR_STR_LEN];
|
||||
printf("INFO: send router solicitation to: %s\n",
|
||||
ipv6_addr_to_str(addr_str, &ipv6_buf->destaddr));
|
||||
#endif
|
||||
sixlowpan_lowpan_sendto((ieee_802154_long_t *) & (ipv6_buf->destaddr.uint16[4]),
|
||||
(uint8_t *)ipv6_buf,
|
||||
@ -295,14 +302,15 @@ void init_rtr_sol(uint8_t sllao)
|
||||
|
||||
void recv_echo_req(void)
|
||||
{
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = ipv6_get_buf();
|
||||
struct echo_req_t *echo_buf = get_echo_req_buf(ipv6_ext_hdr_len);
|
||||
char *echo_data_buf = ((char *)echo_buf) + sizeof(struct echo_repl_t);
|
||||
size_t data_len = ipv6_buf->length - (IPV6_HDR_LEN + ICMPV6_HDR_LEN +
|
||||
ipv6_ext_hdr_len + ECHO_REQ_LEN);
|
||||
#ifdef ENABLE_DEBUG
|
||||
printf("INFO: received echo request from: ");
|
||||
ipv6_print_addr(&ipv6_buf->srcaddr);
|
||||
char addr_str[IPV6_MAX_ADDR_STR_LEN];
|
||||
printf("INFO: received echo request from: %s\n",
|
||||
ipv6_addr_to_str(addr_str, &ipv6_buf->srcaddr));
|
||||
printf("\n");
|
||||
printf("id = 0x%04x, seq = %d\n", echo_buf->id, echo_buf->seq);
|
||||
|
||||
@ -321,14 +329,15 @@ void recv_echo_req(void)
|
||||
|
||||
void recv_echo_repl(void)
|
||||
{
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = ipv6_get_buf();
|
||||
struct echo_repl_t *echo_buf = get_echo_repl_buf(ipv6_ext_hdr_len);
|
||||
char *echo_data_buf = ((char *)echo_buf) + sizeof(struct echo_repl_t);
|
||||
size_t data_len = ipv6_buf->length - (IPV6_HDR_LEN + ICMPV6_HDR_LEN +
|
||||
ipv6_ext_hdr_len + ECHO_REPL_LEN);
|
||||
#ifdef ENABLE_DEBUG
|
||||
printf("INFO: received echo reply from: ");
|
||||
ipv6_print_addr(&ipv6_buf->srcaddr);
|
||||
char addr_str[IPV6_MAX_ADDR_STR_LEN];
|
||||
printf("INFO: received echo reply from: %s\n",
|
||||
ipv6_addr_to_str(addr_str, &ipv6_buf->srcaddr));
|
||||
printf("\n");
|
||||
printf("id = 0x%04x, seq = %d\n", echo_buf->id, echo_buf->seq);
|
||||
|
||||
@ -345,14 +354,14 @@ void recv_echo_repl(void)
|
||||
|
||||
void recv_rtr_sol(void)
|
||||
{
|
||||
opt_hdr_len = RTR_SOL_LEN;
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
icmpv6_opt_hdr_len = RTR_SOL_LEN;
|
||||
ipv6_buf = ipv6_get_buf();
|
||||
|
||||
/* check if source option is set*/
|
||||
if (opt_stllao_buf->type == OPT_SLLAO_TYPE) {
|
||||
opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, opt_hdr_len);
|
||||
opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len);
|
||||
llao = (uint8_t *)opt_stllao_buf;
|
||||
opt_hdr_len += (opt_stllao_buf->length) << 3;
|
||||
icmpv6_opt_hdr_len += (opt_stllao_buf->length) << 3;
|
||||
}
|
||||
|
||||
if (llao != NULL) {
|
||||
@ -387,8 +396,9 @@ void recv_rtr_sol(void)
|
||||
}
|
||||
|
||||
#if ENABLE_DEBUG
|
||||
printf("INFO: send router advertisment to: ");
|
||||
ipv6_print_addr(&ipv6_buf->destaddr);
|
||||
char addr_str[IPV6_MAX_ADDR_STR_LEN];
|
||||
printf("INFO: send router advertisment to: %s\n",
|
||||
ipv6_addr_to_str(addr_str, &ipv6_buf->destaddr));
|
||||
#endif
|
||||
sixlowpan_lowpan_sendto((ieee_802154_long_t *) & (ipv6_buf->destaddr.uint16[4]),
|
||||
(uint8_t *)ipv6_buf,
|
||||
@ -427,24 +437,24 @@ void init_rtr_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8_t pi,
|
||||
lowpan_context_t *contexts = NULL;
|
||||
|
||||
abr_cache_t *msg_abr = NULL;
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = ipv6_get_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 = PROTO_NUM_ICMPV6;
|
||||
ipv6_buf->nextheader = IPV6_PROTO_NUM_ICMPV6;
|
||||
ipv6_buf->hoplimit = ND_HOPLIMIT;
|
||||
|
||||
if (addr == NULL) {
|
||||
/* not solicited */
|
||||
ipv6_set_all_nds_mcast_addr(&ipv6_buf->destaddr);
|
||||
ipv6_addr_set_all_nodes_addr(&ipv6_buf->destaddr);
|
||||
}
|
||||
else {
|
||||
memcpy(&ipv6_buf->destaddr, addr, 16);
|
||||
}
|
||||
|
||||
ipv6_get_saddr(&(ipv6_buf->srcaddr), &(ipv6_buf->destaddr));
|
||||
ipv6_iface_get_best_src_addr(&(ipv6_buf->srcaddr), &(ipv6_buf->destaddr));
|
||||
|
||||
icmp_buf->type = ICMP_RTR_ADV;
|
||||
icmp_buf->code = 0;
|
||||
@ -458,26 +468,26 @@ void init_rtr_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8_t pi,
|
||||
rtr_adv_buf->router_lifetime = HTONS(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;
|
||||
icmpv6_opt_hdr_len = RTR_ADV_LEN;
|
||||
|
||||
packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + RTR_ADV_LEN;
|
||||
|
||||
if (sllao == OPT_SLLAO) {
|
||||
/* set link layer address option */
|
||||
opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, opt_hdr_len);
|
||||
opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len);
|
||||
set_llao(opt_stllao_buf, OPT_SLLAO_TYPE, 2);
|
||||
opt_hdr_len += OPT_STLLAO_MAX_LEN;
|
||||
icmpv6_opt_hdr_len += OPT_STLLAO_MAX_LEN;
|
||||
packet_length += OPT_STLLAO_MAX_LEN;
|
||||
}
|
||||
|
||||
if (mtu == OPT_MTU) {
|
||||
/* set MTU options */
|
||||
opt_mtu_buf = get_opt_mtu_buf(ipv6_ext_hdr_len, opt_hdr_len);
|
||||
opt_mtu_buf = get_opt_mtu_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len);
|
||||
opt_mtu_buf->type = OPT_MTU_TYPE;
|
||||
opt_mtu_buf->length = OPT_MTU_LEN;
|
||||
opt_mtu_buf->reserved = 0;
|
||||
opt_mtu_buf->mtu = HTONL(1500);
|
||||
opt_hdr_len += OPT_MTU_HDR_LEN;
|
||||
icmpv6_opt_hdr_len += OPT_MTU_HDR_LEN;
|
||||
packet_length += OPT_MTU_HDR_LEN;
|
||||
}
|
||||
|
||||
@ -487,7 +497,7 @@ void init_rtr_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8_t pi,
|
||||
/* set authoritive border router option */
|
||||
if (abr_count > 0) {
|
||||
msg_abr = abr_get_most_current();
|
||||
opt_abro_buf = get_opt_abro_buf(ipv6_ext_hdr_len, opt_hdr_len);
|
||||
opt_abro_buf = get_opt_abro_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len);
|
||||
opt_abro_buf->type = OPT_ABRO_TYPE;
|
||||
opt_abro_buf->length = OPT_ABRO_LEN;
|
||||
opt_abro_buf->version = HTONS(msg_abr->version);
|
||||
@ -523,7 +533,7 @@ void init_rtr_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8_t pi,
|
||||
}
|
||||
|
||||
for (int i = 0; i < contexts_len; i++) {
|
||||
opt_6co_hdr_buf = get_opt_6co_hdr_buf(ipv6_ext_hdr_len, opt_hdr_len);
|
||||
opt_6co_hdr_buf = get_opt_6co_hdr_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len);
|
||||
opt_6co_hdr_buf->type = OPT_6CO_TYPE;
|
||||
|
||||
if (contexts[i].length > 64) {
|
||||
@ -538,21 +548,21 @@ void init_rtr_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8_t pi,
|
||||
opt_6co_hdr_buf->reserved = 0;
|
||||
opt_6co_hdr_buf->val_ltime = HTONS(contexts[i].lifetime);
|
||||
|
||||
opt_hdr_len += OPT_6CO_HDR_LEN;
|
||||
icmpv6_opt_hdr_len += OPT_6CO_HDR_LEN;
|
||||
packet_length += OPT_6CO_HDR_LEN;
|
||||
/* attach prefixes */
|
||||
opt_6co_prefix_buf = get_opt_6co_prefix_buf(ipv6_ext_hdr_len, opt_hdr_len);
|
||||
opt_6co_prefix_buf = get_opt_6co_prefix_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len);
|
||||
|
||||
if (opt_6co_hdr_buf->c_length > 64) {
|
||||
memset((void *)opt_6co_prefix_buf, 0, 16);
|
||||
memcpy((void *)opt_6co_prefix_buf, (void *) & (contexts[i].prefix.uint8[0]), opt_6co_hdr_buf->c_length / 8);
|
||||
opt_hdr_len += 16;
|
||||
icmpv6_opt_hdr_len += 16;
|
||||
packet_length += 16;
|
||||
}
|
||||
else {
|
||||
memset((void *)opt_6co_prefix_buf, 0, 8);
|
||||
memcpy((void *)opt_6co_prefix_buf, (void *) & (contexts[i].prefix.uint8[0]), opt_6co_hdr_buf->c_length / 8);
|
||||
opt_hdr_len += 8;
|
||||
icmpv6_opt_hdr_len += 8;
|
||||
packet_length += 8;
|
||||
}
|
||||
|
||||
@ -569,7 +579,7 @@ void init_rtr_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8_t pi,
|
||||
/* set prefix option */
|
||||
for (int i = 0; i < OPT_PI_LIST_LEN; i++) {
|
||||
if (plist[i].inuse && plist[i].adv) {
|
||||
opt_pi_buf = get_opt_pi_buf(ipv6_ext_hdr_len, opt_hdr_len);
|
||||
opt_pi_buf = get_opt_pi_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len);
|
||||
memcpy(&(opt_pi_buf->addr.uint8[0]), &(plist[i].addr.uint8[0]), 16);
|
||||
opt_pi_buf->type = OPT_PI_TYPE;
|
||||
opt_pi_buf->length = OPT_PI_LEN;
|
||||
@ -579,7 +589,7 @@ void init_rtr_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8_t pi,
|
||||
opt_pi_buf->pref_ltime = HTONL(plist[i].pref_ltime);
|
||||
opt_pi_buf->reserved2 = 0;
|
||||
packet_length += OPT_PI_HDR_LEN;
|
||||
opt_hdr_len += OPT_PI_HDR_LEN;
|
||||
icmpv6_opt_hdr_len += OPT_PI_HDR_LEN;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -588,7 +598,7 @@ void init_rtr_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8_t pi,
|
||||
|
||||
/* calculate checksum */
|
||||
icmp_buf->checksum = 0;
|
||||
icmp_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6);
|
||||
icmp_buf->checksum = ~icmpv6_csum(IPV6_PROTO_NUM_ICMPV6);
|
||||
}
|
||||
|
||||
void recv_rtr_adv(void)
|
||||
@ -599,9 +609,9 @@ void recv_rtr_adv(void)
|
||||
uint16_t packet_length;
|
||||
ipv6_addr_t abro_addr;
|
||||
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = ipv6_get_buf();
|
||||
packet_length = IPV6_HDR_LEN + ipv6_buf->length;
|
||||
opt_hdr_len = RTR_ADV_LEN;
|
||||
icmpv6_opt_hdr_len = RTR_ADV_LEN;
|
||||
rtr_adv_buf = get_rtr_adv_buf(ipv6_ext_hdr_len);
|
||||
ipv6_addr_t newaddr;
|
||||
recvd_cids_len = 0;
|
||||
@ -636,8 +646,8 @@ void recv_rtr_adv(void)
|
||||
mutex_lock(&lowpan_context_mutex);
|
||||
|
||||
/* read options */
|
||||
while (packet_length > IPV6HDR_ICMPV6HDR_LEN + opt_hdr_len) {
|
||||
opt_buf = get_opt_buf(ipv6_ext_hdr_len, opt_hdr_len);
|
||||
while (packet_length > IPV6HDR_ICMPV6HDR_LEN + icmpv6_opt_hdr_len) {
|
||||
opt_buf = get_opt_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len);
|
||||
|
||||
switch (opt_buf->type) {
|
||||
case (OPT_SLLAO_TYPE): {
|
||||
@ -650,10 +660,10 @@ void recv_rtr_adv(void)
|
||||
|
||||
/* rfc 4862 section 5.5.3 */
|
||||
case (OPT_PI_TYPE): {
|
||||
opt_pi_buf = get_opt_pi_buf(ipv6_ext_hdr_len, opt_hdr_len);
|
||||
opt_pi_buf = get_opt_pi_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len);
|
||||
|
||||
/* crazy condition, read 5.5.3a-b-c for further information */
|
||||
if (ipv6_prefix_ll_match(&opt_pi_buf->addr) ||
|
||||
if (ipv6_addr_is_link_local(&opt_pi_buf->addr) ||
|
||||
(HTONL(opt_pi_buf->pref_ltime) >
|
||||
HTONL(opt_pi_buf->val_ltime))) {
|
||||
break;
|
||||
@ -671,16 +681,17 @@ void recv_rtr_adv(void)
|
||||
/* 5.5.3d */
|
||||
if (opt_pi_buf->val_ltime != 0) {
|
||||
/* iid will also be added here */
|
||||
ipv6_init_addr_prefix(&newaddr, &opt_pi_buf->addr);
|
||||
ipv6_addr_set_by_eui64(&newaddr,
|
||||
&opt_pi_buf->addr);
|
||||
/* add into address list
|
||||
* TODO: duplicate address detection is not
|
||||
* implementet yet, so all new addresse will
|
||||
* be added with state PREFFERED */
|
||||
ipv6_iface_add_addr(&newaddr,
|
||||
ADDR_STATE_PREFERRED,
|
||||
IPV6_ADDR_TYPE_UNICAST,
|
||||
NDP_ADDR_STATE_PREFERRED,
|
||||
opt_pi_buf->val_ltime,
|
||||
opt_pi_buf->pref_ltime,
|
||||
ADDR_CONFIGURED_AUTO);
|
||||
opt_pi_buf->pref_ltime);
|
||||
printf("INFO: added address to interface\n");
|
||||
trigger_ns = 1;
|
||||
}
|
||||
@ -711,14 +722,14 @@ void recv_rtr_adv(void)
|
||||
uint8_t comp;
|
||||
uint8_t num;
|
||||
|
||||
opt_6co_hdr_buf = get_opt_6co_hdr_buf(ipv6_ext_hdr_len, opt_hdr_len);
|
||||
opt_6co_hdr_buf = get_opt_6co_hdr_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len);
|
||||
|
||||
get_opt_6co_flags(&comp, &num, opt_6co_hdr_buf->c_flags);
|
||||
|
||||
ipv6_addr_t prefix;
|
||||
memset(&prefix, 0, 16);
|
||||
|
||||
opt_6co_prefix_buf = get_opt_6co_prefix_buf(ipv6_ext_hdr_len, opt_hdr_len + OPT_6CO_HDR_LEN);
|
||||
opt_6co_prefix_buf = get_opt_6co_prefix_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len + OPT_6CO_HDR_LEN);
|
||||
|
||||
memcpy(&prefix, opt_6co_prefix_buf, opt_6co_hdr_buf->c_length);
|
||||
|
||||
@ -735,7 +746,7 @@ void recv_rtr_adv(void)
|
||||
}
|
||||
|
||||
case (OPT_ABRO_TYPE): {
|
||||
opt_abro_buf = get_opt_abro_buf(ipv6_ext_hdr_len, opt_hdr_len);
|
||||
opt_abro_buf = get_opt_abro_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len);
|
||||
abro_found = 1;
|
||||
abro_version = HTONS(opt_abro_buf->version);
|
||||
memcpy(&(abro_addr), &(opt_abro_buf->addr), sizeof(ipv6_addr_t));
|
||||
@ -747,7 +758,7 @@ void recv_rtr_adv(void)
|
||||
}
|
||||
|
||||
/* multiplied with 8 because options length is in units of 8 bytes */
|
||||
opt_hdr_len += (opt_buf->length * 8);
|
||||
icmpv6_opt_hdr_len += (opt_buf->length * 8);
|
||||
}
|
||||
|
||||
if (abro_found) {
|
||||
@ -771,8 +782,9 @@ void recv_rtr_adv(void)
|
||||
* if new address was configured, set src to newaddr(gp16) */
|
||||
init_nbr_sol(&newaddr, &(ipv6_buf->srcaddr), &(ipv6_buf->srcaddr), OPT_SLLAO, OPT_ARO);
|
||||
#if ENABLE_DEBUG
|
||||
printf("INFO: send neighbor solicitation to: ");
|
||||
ipv6_print_addr(&(ipv6_buf->destaddr));
|
||||
char addr_str[IPV6_MAX_ADDR_STR_LEN];
|
||||
printf("INFO: send neighbor solicitation to: %s\n",
|
||||
ipv6_addr_to_str(addr_str, &(ipv6_buf->destaddr)));
|
||||
#endif
|
||||
sixlowpan_lowpan_sendto((ieee_802154_long_t *) & (ipv6_buf->destaddr.uint16[4]),
|
||||
(uint8_t *)ipv6_buf,
|
||||
@ -785,15 +797,15 @@ void init_nbr_sol(ipv6_addr_t *src, ipv6_addr_t *dest, ipv6_addr_t *targ,
|
||||
{
|
||||
uint16_t packet_length;
|
||||
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = ipv6_get_buf();
|
||||
ipv6_buf->version_trafficclass = IPV6_VER;
|
||||
ipv6_buf->trafficclass_flowlabel = 0;
|
||||
ipv6_buf->flowlabel = 0;
|
||||
ipv6_buf->nextheader = PROTO_NUM_ICMPV6;
|
||||
ipv6_buf->nextheader = IPV6_PROTO_NUM_ICMPV6;
|
||||
ipv6_buf->hoplimit = ND_HOPLIMIT;
|
||||
|
||||
if (dest == NULL) {
|
||||
ipv6_set_sol_node_mcast_addr(targ, &(ipv6_buf->destaddr));
|
||||
ipv6_addr_set_solicited_node_addr(&(ipv6_buf->destaddr), targ);
|
||||
}
|
||||
else {
|
||||
memcpy(&(ipv6_buf->destaddr.uint8[0]), &(dest->uint8[0]), 16);
|
||||
@ -807,13 +819,13 @@ void init_nbr_sol(ipv6_addr_t *src, ipv6_addr_t *dest, ipv6_addr_t *targ,
|
||||
nbr_sol_buf = get_nbr_sol_buf(ipv6_ext_hdr_len);
|
||||
nbr_sol_buf->reserved = 0;
|
||||
memcpy(&(nbr_sol_buf->tgtaddr), targ, 16);
|
||||
opt_hdr_len = NBR_SOL_LEN;
|
||||
icmpv6_opt_hdr_len = NBR_SOL_LEN;
|
||||
|
||||
packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + NBR_SOL_LEN;
|
||||
|
||||
if (ipv6_iface_addr_match(targ) == NULL) {
|
||||
if (src == NULL) {
|
||||
ipv6_get_saddr(&(ipv6_buf->srcaddr), &(ipv6_buf->destaddr));
|
||||
ipv6_iface_get_best_src_addr(&(ipv6_buf->srcaddr), &(ipv6_buf->destaddr));
|
||||
}
|
||||
else {
|
||||
memcpy(&(ipv6_buf->srcaddr), src, 16);
|
||||
@ -821,9 +833,9 @@ void init_nbr_sol(ipv6_addr_t *src, ipv6_addr_t *dest, ipv6_addr_t *targ,
|
||||
|
||||
if (sllao == OPT_SLLAO) {
|
||||
/* set sllao option */
|
||||
opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, opt_hdr_len);
|
||||
opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len);
|
||||
set_llao(opt_stllao_buf, OPT_SLLAO_TYPE, 1);
|
||||
opt_hdr_len += OPT_STLLAO_MIN_LEN;
|
||||
icmpv6_opt_hdr_len += OPT_STLLAO_MIN_LEN;
|
||||
|
||||
packet_length += OPT_STLLAO_MIN_LEN;
|
||||
}
|
||||
@ -831,14 +843,14 @@ void init_nbr_sol(ipv6_addr_t *src, ipv6_addr_t *dest, ipv6_addr_t *targ,
|
||||
|
||||
if (aro == OPT_ARO) {
|
||||
/* set aro option */
|
||||
opt_aro_buf = get_opt_aro_buf(ipv6_ext_hdr_len, opt_hdr_len);
|
||||
opt_aro_buf = get_opt_aro_buf(ipv6_ext_hdr_len, icmpv6_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;
|
||||
memcpy(&(opt_aro_buf->eui64), sixlowpan_mac_get_eui64(src), 8);
|
||||
opt_hdr_len += OPT_ARO_HDR_LEN;
|
||||
icmpv6_opt_hdr_len += OPT_ARO_HDR_LEN;
|
||||
|
||||
packet_length += OPT_ARO_HDR_LEN;
|
||||
}
|
||||
@ -846,14 +858,14 @@ void init_nbr_sol(ipv6_addr_t *src, ipv6_addr_t *dest, ipv6_addr_t *targ,
|
||||
ipv6_buf->length = HTONS(packet_length - IPV6_HDR_LEN);
|
||||
|
||||
icmp_buf->checksum = 0;
|
||||
icmp_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6);
|
||||
icmp_buf->checksum = ~icmpv6_csum(IPV6_PROTO_NUM_ICMPV6);
|
||||
}
|
||||
|
||||
void recv_nbr_sol(void)
|
||||
{
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = ipv6_get_buf();
|
||||
llao = NULL;
|
||||
opt_hdr_len = NBR_SOL_LEN;
|
||||
icmpv6_opt_hdr_len = NBR_SOL_LEN;
|
||||
|
||||
uint8_t send_na = 0;
|
||||
uint8_t sllao_set = 0;
|
||||
@ -864,29 +876,29 @@ void recv_nbr_sol(void)
|
||||
* option condition is that a sllao option is set. thus that we don't
|
||||
* know which option comes first we need to this here */
|
||||
|
||||
while (packet_length > IPV6HDR_ICMPV6HDR_LEN + opt_hdr_len) {
|
||||
opt_buf = get_opt_buf(ipv6_ext_hdr_len, opt_hdr_len);
|
||||
while (packet_length > IPV6HDR_ICMPV6HDR_LEN + icmpv6_opt_hdr_len) {
|
||||
opt_buf = get_opt_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len);
|
||||
|
||||
if (opt_buf->type == OPT_SLLAO_TYPE) {
|
||||
sllao_set = 1;
|
||||
}
|
||||
|
||||
opt_hdr_len += (opt_buf->length * 8);
|
||||
icmpv6_opt_hdr_len += (opt_buf->length * 8);
|
||||
}
|
||||
|
||||
opt_hdr_len = NBR_SOL_LEN;
|
||||
icmpv6_opt_hdr_len = NBR_SOL_LEN;
|
||||
|
||||
while (packet_length > IPV6HDR_ICMPV6HDR_LEN + opt_hdr_len) {
|
||||
opt_buf = get_opt_buf(ipv6_ext_hdr_len, opt_hdr_len);
|
||||
while (packet_length > IPV6HDR_ICMPV6HDR_LEN + icmpv6_opt_hdr_len) {
|
||||
opt_buf = get_opt_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len);
|
||||
|
||||
switch (opt_buf->type) {
|
||||
case (OPT_SLLAO_TYPE): {
|
||||
opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len,
|
||||
opt_hdr_len);
|
||||
icmpv6_opt_hdr_len);
|
||||
llao = (uint8_t *)opt_stllao_buf;
|
||||
|
||||
if (llao != NULL &&
|
||||
!(ipv6_addr_unspec_match(&ipv6_buf->srcaddr))) {
|
||||
!(ipv6_addr_is_unspecified(&ipv6_buf->srcaddr))) {
|
||||
nbr_entry = nbr_cache_search(&(ipv6_buf->srcaddr));
|
||||
|
||||
if (nbr_entry != NULL) {
|
||||
@ -954,10 +966,10 @@ void recv_nbr_sol(void)
|
||||
case (OPT_ARO_TYPE): {
|
||||
/* check if sllao option is set, and if address src address
|
||||
* isn't unspecified - draft-ietf-6lowpan-nd-15#section-6.5 */
|
||||
if (!(ipv6_addr_unspec_match(&ipv6_buf->srcaddr)) &&
|
||||
if (!(ipv6_addr_is_unspecified(&ipv6_buf->srcaddr)) &&
|
||||
sllao_set == 1) {
|
||||
opt_aro_buf = get_opt_aro_buf(ipv6_ext_hdr_len,
|
||||
opt_hdr_len);
|
||||
icmpv6_opt_hdr_len);
|
||||
|
||||
if ((opt_aro_buf->length == 2) &&
|
||||
(opt_aro_buf->status == 0)) {
|
||||
@ -1004,7 +1016,7 @@ void recv_nbr_sol(void)
|
||||
break;
|
||||
}
|
||||
|
||||
opt_hdr_len += (opt_buf->length * 8);
|
||||
icmpv6_opt_hdr_len += (opt_buf->length * 8);
|
||||
}
|
||||
|
||||
addr_list_t *alist_targ, *alist_dest;
|
||||
@ -1016,7 +1028,7 @@ void recv_nbr_sol(void)
|
||||
alist_dest = ipv6_iface_addr_match(&(ipv6_buf->destaddr));
|
||||
|
||||
if ((memcmp(&(alist_targ->addr), &(alist_dest->addr), 16) == 0) ||
|
||||
ipv6_addr_sol_node_mcast_match(&ipv6_buf->destaddr)) {
|
||||
ipv6_addr_is_solicited_node(&ipv6_buf->destaddr)) {
|
||||
memcpy(&(ipv6_buf->destaddr.uint8[0]),
|
||||
&(ipv6_buf->srcaddr.uint8[0]), 16);
|
||||
memcpy(&(ipv6_buf->srcaddr.uint8[0]),
|
||||
@ -1031,8 +1043,9 @@ void recv_nbr_sol(void)
|
||||
init_nbr_adv(&(ipv6_buf->srcaddr), &(ipv6_buf->destaddr),
|
||||
&(alist_targ->addr), flags, 0, OPT_ARO, aro_state);
|
||||
#if ENABLE_DEBUG
|
||||
printf("INFO: send neighbor advertisment to: ");
|
||||
ipv6_print_addr(&ipv6_buf->destaddr);
|
||||
char addr_str[IPV6_MAX_ADDR_STR_LEN];
|
||||
printf("INFO: send neighbor advertisment to: %s\n",
|
||||
ipv6_addr_to_str(addr_str, &ipv6_buf->destaddr));
|
||||
#endif
|
||||
sixlowpan_lowpan_sendto((ieee_802154_long_t *) & (ipv6_buf->destaddr.uint16[4]),
|
||||
(uint8_t *)ipv6_buf,
|
||||
@ -1045,11 +1058,11 @@ void init_nbr_adv(ipv6_addr_t *src, ipv6_addr_t *dst, ipv6_addr_t *tgt,
|
||||
{
|
||||
uint16_t packet_length;
|
||||
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = ipv6_get_buf();
|
||||
ipv6_buf->version_trafficclass = IPV6_VER;
|
||||
ipv6_buf->trafficclass_flowlabel = 0;
|
||||
ipv6_buf->flowlabel = 0;
|
||||
ipv6_buf->nextheader = PROTO_NUM_ICMPV6;
|
||||
ipv6_buf->nextheader = IPV6_PROTO_NUM_ICMPV6;
|
||||
ipv6_buf->hoplimit = ND_HOPLIMIT;
|
||||
|
||||
ipv6_ext_hdr_len = 0;
|
||||
@ -1070,23 +1083,23 @@ void init_nbr_adv(ipv6_addr_t *src, ipv6_addr_t *dst, ipv6_addr_t *tgt,
|
||||
|
||||
if (sllao == OPT_SLLAO) {
|
||||
/* set sllao option */
|
||||
opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, opt_hdr_len);
|
||||
opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len);
|
||||
set_llao(opt_stllao_buf, OPT_SLLAO_TYPE, 1);
|
||||
opt_hdr_len += OPT_STLLAO_MIN_LEN;
|
||||
icmpv6_opt_hdr_len += OPT_STLLAO_MIN_LEN;
|
||||
|
||||
packet_length += OPT_STLLAO_MIN_LEN;
|
||||
}
|
||||
|
||||
if (aro == OPT_ARO) {
|
||||
/* set aro option */
|
||||
opt_aro_buf = get_opt_aro_buf(ipv6_ext_hdr_len, opt_hdr_len);
|
||||
opt_aro_buf = get_opt_aro_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len);
|
||||
opt_aro_buf->type = OPT_ARO_TYPE;
|
||||
opt_aro_buf->length = OPT_ARO_LEN;
|
||||
opt_aro_buf->status = 0; /* TODO */
|
||||
opt_aro_buf->reserved1 = 0;
|
||||
opt_aro_buf->reserved2 = 0;
|
||||
memcpy(&(opt_aro_buf->eui64), sixlowpan_mac_get_eui64(dst), 8);
|
||||
opt_hdr_len += OPT_ARO_HDR_LEN;
|
||||
icmpv6_opt_hdr_len += OPT_ARO_HDR_LEN;
|
||||
|
||||
packet_length += OPT_ARO_HDR_LEN;
|
||||
}
|
||||
@ -1094,27 +1107,27 @@ void init_nbr_adv(ipv6_addr_t *src, ipv6_addr_t *dst, ipv6_addr_t *tgt,
|
||||
ipv6_buf->length = HTONS(packet_length - IPV6_HDR_LEN);
|
||||
|
||||
icmp_buf->checksum = 0;
|
||||
icmp_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6);
|
||||
icmp_buf->checksum = ~icmpv6_csum(IPV6_PROTO_NUM_ICMPV6);
|
||||
}
|
||||
|
||||
void recv_nbr_adv(void)
|
||||
{
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = ipv6_get_buf();
|
||||
uint16_t packet_length = IPV6_HDR_LEN + ipv6_buf->length;
|
||||
opt_hdr_len = NBR_ADV_LEN;
|
||||
icmpv6_opt_hdr_len = NBR_ADV_LEN;
|
||||
llao = NULL;
|
||||
nbr_entry = NULL;
|
||||
int8_t new_ll = -1;
|
||||
nbr_adv_buf = get_nbr_adv_buf(ipv6_ext_hdr_len);
|
||||
|
||||
/* check if options are present */
|
||||
while (packet_length > IPV6HDR_ICMPV6HDR_LEN + opt_hdr_len) {
|
||||
opt_buf = get_opt_buf(ipv6_ext_hdr_len, opt_hdr_len);
|
||||
while (packet_length > IPV6HDR_ICMPV6HDR_LEN + icmpv6_opt_hdr_len) {
|
||||
opt_buf = get_opt_buf(ipv6_ext_hdr_len, icmpv6_opt_hdr_len);
|
||||
|
||||
switch (opt_buf->type) {
|
||||
case (OPT_TLLAO_TYPE): {
|
||||
llao = (uint8_t *)get_opt_stllao_buf(ipv6_ext_hdr_len,
|
||||
opt_hdr_len);
|
||||
icmpv6_opt_hdr_len);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1123,7 +1136,7 @@ void recv_nbr_adv(void)
|
||||
}
|
||||
}
|
||||
|
||||
opt_hdr_len += (opt_buf->length * 8);
|
||||
icmpv6_opt_hdr_len += (opt_buf->length * 8);
|
||||
}
|
||||
|
||||
addr_list_t *addr;
|
||||
@ -1219,7 +1232,7 @@ void set_llao(opt_stllao_t *sllao, uint8_t type, uint8_t length)
|
||||
|
||||
uint16_t icmpv6_csum(uint8_t proto)
|
||||
{
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = ipv6_get_buf();
|
||||
uint16_t sum;
|
||||
uint16_t len = NTOHS(ipv6_buf->length);
|
||||
sum = len + proto;
|
||||
@ -1236,13 +1249,13 @@ void init_para_prob(ipv6_addr_t *src, ipv6_addr_t *dest, uint8_t code, uint32_t
|
||||
uint16_t packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + PARA_PROB_LEN;
|
||||
struct para_prob_t *para_prob_buf;
|
||||
|
||||
memcpy(&(ipv6_buf[packet_length]), packet, min(MTU - packet_length, packet_len));
|
||||
memcpy(&(ipv6_buf[packet_length]), packet, min(IPV6_MTU - packet_length, packet_len));
|
||||
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = ipv6_get_buf();
|
||||
ipv6_buf->version_trafficclass = IPV6_VER;
|
||||
ipv6_buf->trafficclass_flowlabel = 0;
|
||||
ipv6_buf->flowlabel = 0;
|
||||
ipv6_buf->nextheader = PROTO_NUM_ICMPV6;
|
||||
ipv6_buf->nextheader = IPV6_PROTO_NUM_ICMPV6;
|
||||
ipv6_buf->hoplimit = ND_HOPLIMIT;
|
||||
|
||||
ipv6_ext_hdr_len = 0;
|
||||
@ -1257,12 +1270,12 @@ void init_para_prob(ipv6_addr_t *src, ipv6_addr_t *dest, uint8_t code, uint32_t
|
||||
|
||||
para_prob_buf->pointer = pointer;
|
||||
|
||||
packet_length += min(MTU - packet_length, packet_len);
|
||||
packet_length += min(IPV6_MTU - packet_length, packet_len);
|
||||
|
||||
ipv6_buf->length = HTONS(packet_length - IPV6_HDR_LEN);
|
||||
|
||||
icmp_buf->checksum = 0;
|
||||
icmp_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6);
|
||||
icmp_buf->checksum = ~icmpv6_csum(IPV6_PROTO_NUM_ICMPV6);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "sixlowpan/icmp.h"
|
||||
#include "sixlowpan/ndp.h"
|
||||
|
||||
#include "../ip.h" /* TODO: remove if not needed anymore */
|
||||
#include "../icmp.h" /* TODO: remove if not needed anymore */
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,6 @@
|
||||
/**
|
||||
* 6LoWPAN constants, data structs, and prototypes for network layer
|
||||
* sixlowpan/ip.h - 6LoWPAN constants, data structs, and prototypes
|
||||
* for network layer
|
||||
*
|
||||
* Copyright (C) 2013 INRIA.
|
||||
*
|
||||
@ -9,16 +10,332 @@
|
||||
*
|
||||
* @ingroup sixlowpan
|
||||
* @{
|
||||
* @file sixlowpan/ip.h
|
||||
* @file
|
||||
* @brief 6LoWPAN network layer header
|
||||
* @author Stephan Zeisberg <zeisberg@mi.fu-berlin.de>
|
||||
* @author Martin Lenders <mlenders@inf.fu-berlin.de>
|
||||
* @author Eric Engel <eric.engel@fu-berlin.de>
|
||||
* @author Oliver Gesch <oliver.gesch@googlemail.com>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifndef SIXLOWPAN_IP_H
|
||||
#define SIXLOWPAN_IP_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "sixlowpan/types.h"
|
||||
|
||||
/**
|
||||
* @brief IPv6 maximum transmission unit.
|
||||
*/
|
||||
#define IPV6_MTU (256)
|
||||
|
||||
/**
|
||||
* @brief Maximum length of a IPv6 address represented as string.
|
||||
*/
|
||||
#define IPV6_MAX_ADDR_STR_LEN (40)
|
||||
|
||||
/**
|
||||
* @brief L4 protocol number for TCP.
|
||||
*/
|
||||
#define IPV6_PROTO_NUM_TCP (6)
|
||||
|
||||
/**
|
||||
* @brief L4 protocol number for UDP.
|
||||
*/
|
||||
#define IPV6_PROTO_NUM_UDP (17)
|
||||
|
||||
/**
|
||||
* @brief L4 protocol number for ICMPv6.
|
||||
*/
|
||||
#define IPV6_PROTO_NUM_ICMPV6 (58)
|
||||
|
||||
/**
|
||||
* @brief L4 protocol number for no L4 protocol in IPv6.
|
||||
*/
|
||||
#define IPV6_PROTO_NUM_NONE (59)
|
||||
|
||||
/**
|
||||
* @brief L4 protocol number for IPv6 destination options.
|
||||
*/
|
||||
#define IPV6_PROTO_NUM_IPV6_OPTS (60)
|
||||
|
||||
/**
|
||||
* @brief Get IPv6 send/receive buffer.
|
||||
*
|
||||
* @return Pointer to IPv6 header in send/receive bouffer.
|
||||
* @note To be deleted in later releases. Here only because it is
|
||||
* used by the rpl module.
|
||||
*/
|
||||
ipv6_hdr_t *ipv6_get_buf(void);
|
||||
|
||||
/**
|
||||
* @brief Send IPv6 packet to dest.
|
||||
*
|
||||
* @param[in] dest Destination of this packet.
|
||||
* @param[in] next_header Next header ID of payload.
|
||||
* @param[in] payload Payload of the packet.
|
||||
* @param[in] payload_length Length of payload.
|
||||
*/
|
||||
void ipv6_sendto(const ipv6_addr_t *dest, uint8_t next_header,
|
||||
const uint8_t *payload, uint16_t payload_length);
|
||||
|
||||
/**
|
||||
* @brief Determines if node is a router.
|
||||
*
|
||||
* @return 1 if node is router, 0 otherwise.
|
||||
*/
|
||||
uint8_t ipv6_is_router(void);
|
||||
|
||||
/**
|
||||
* @brief Registers a handler thread for incoming IP packets.
|
||||
*
|
||||
* @param[in] pid PID of handler thread.
|
||||
*
|
||||
* @return 0 on success, ENOMEN if maximum number of registrable
|
||||
* threads is exceeded.
|
||||
*/
|
||||
uint8_t ipv6_register_packet_handler(int pid);
|
||||
|
||||
/**
|
||||
* @brief Registers a handler thread for L4 protocol.
|
||||
*
|
||||
* @param[in] next_header Next header ID of the L4 protocol.
|
||||
* @param[in] pid PID of the handler thread
|
||||
*/
|
||||
void ipv6_register_next_header_handler(uint8_t next_header, int pid);
|
||||
|
||||
/**
|
||||
* @brief Registers a handler thread for RPL options
|
||||
*
|
||||
* @param[in] pid PID of the handler thread.
|
||||
*/
|
||||
void ipv6_register_rpl_handler(int pid);
|
||||
|
||||
/**
|
||||
* @brief Sets the first 64 bit of *ipv6_addr* to link local prefix.
|
||||
*
|
||||
* @param[in,out] ipv6_addr The address to set.
|
||||
*/
|
||||
void ipv6_addr_set_link_local_prefix(ipv6_addr_t *ipv6_addr);
|
||||
|
||||
/**
|
||||
* @brief Sets IPv6 address *out* according to the remaining
|
||||
* parameters.
|
||||
*
|
||||
* @param[out] out The resulting address.
|
||||
* @param[in] addr0 The first 16 bit of the new address.
|
||||
* @param[in] addr1 The second 16 bit of the new address.
|
||||
* @param[in] addr2 The third 16 bit of the new address.
|
||||
* @param[in] addr3 The fourth 16 bit of the new address.
|
||||
* @param[in] addr4 The fifth 16 bit of the new address.
|
||||
* @param[in] addr5 The sixth 16 bit of the new address.
|
||||
* @param[in] addr6 The seventh 16 bit of the new address.
|
||||
* @param[in] addr7 The eighth 16 bit of the new address.
|
||||
*/
|
||||
void ipv6_addr_init(ipv6_addr_t *out, uint16_t addr0, uint16_t addr1,
|
||||
uint16_t addr2, uint16_t addr3, uint16_t addr4,
|
||||
uint16_t addr5, uint16_t addr6, uint16_t addr7);
|
||||
|
||||
/**
|
||||
* @brief Sets IPv6 address *out* using the given *prefix* and this
|
||||
* nodes EUI-64 (i. e. interface must be initialized).
|
||||
*
|
||||
* @param[out] out Address to be set.
|
||||
* @param[in] prefix 64-bit network prefix to be used for *out*
|
||||
* (only the first 64 bit of the ipv6_addr_t type
|
||||
* are copied to *out*)
|
||||
*/
|
||||
void ipv6_addr_set_by_eui64(ipv6_addr_t *out,
|
||||
const ipv6_addr_t *prefix);
|
||||
|
||||
/**
|
||||
* @brief Sets IPv6 address *out* with the first *bits* bit taken
|
||||
* from *prefix* and the remaining bits to 0.
|
||||
*
|
||||
* @param[out] out Prefix to be set.
|
||||
* @param[in] prefix Address to take prefix from.
|
||||
* @param[in] bits Bits to be copied from *prefix* to *out*
|
||||
* (set to 128 when greater than 128).
|
||||
*/
|
||||
void ipv6_addr_init_prefix(ipv6_addr_t *out, const ipv6_addr_t *prefix,
|
||||
uint8_t bits);
|
||||
|
||||
/**
|
||||
* @brief Set *ipv6_addr* to the loopback address.
|
||||
*
|
||||
* @see <a href="http://tools.ietf.org/html/rfc4291">
|
||||
* RFC 4291
|
||||
* </a>
|
||||
*
|
||||
* @param[out] ipv6_addr Is set to the loopback address.
|
||||
*/
|
||||
void ipv6_addr_set_loopback_addr(ipv6_addr_t *ipv6_addr);
|
||||
|
||||
/**
|
||||
* @brief Set *ipv6_addr* to a link-local all routers multicast
|
||||
* address (ff02::/16 prefix).
|
||||
*
|
||||
* @see <a href="http://tools.ietf.org/html/rfc4291">
|
||||
* RFC 4291
|
||||
* </a>
|
||||
*
|
||||
* @param[out] ipv6_addr Is set to a link-local all routers multicast
|
||||
* address.
|
||||
*/
|
||||
void ipv6_addr_set_all_routers_addr(ipv6_addr_t *ipv6_addr);
|
||||
|
||||
/**
|
||||
* @brief Set *ipv6_addr* to a link-local all nodes multicast address
|
||||
* (ff02::/16 prefix).
|
||||
*
|
||||
* @see <a href="http://tools.ietf.org/html/rfc4291">
|
||||
* RFC 4291
|
||||
* </a>
|
||||
*
|
||||
* @param[out] ipv6_addr Is set to a link-local all nodes multicast
|
||||
* address.
|
||||
*/
|
||||
void ipv6_addr_set_all_nodes_addr(ipv6_addr_t *ipv6_addr);
|
||||
|
||||
/**
|
||||
* @brief Set *ipv6_addr_out* to the solicited-node multicast address
|
||||
* computed from *ipv6_addr_in*.
|
||||
*
|
||||
* @see <a href="http://tools.ietf.org/html/rfc4291">
|
||||
* RFC 4291
|
||||
* </a>
|
||||
*
|
||||
* @param[out] ipv6_addr_out Is set to solicited-node address of
|
||||
* this node.
|
||||
* @param[in] ipv6_addr_in The IPv6 address the solicited-node
|
||||
* address.
|
||||
*/
|
||||
void ipv6_addr_set_solicited_node_addr(ipv6_addr_t *ipv6_addr_out,
|
||||
const ipv6_addr_t *ipv6_addr_in);
|
||||
|
||||
/**
|
||||
* @brief Converts IPv6 address into string (unabbrivated notation).
|
||||
* Note that addr_str must allocate at least
|
||||
* IPV6_MAX_ADDR_STR_LEN byte (40 byte).
|
||||
*
|
||||
* @param[out] addr_str The IPv6 address as string. Must allocate
|
||||
* at least IPV6_MAX_ADDR_STR_LEN byte (40
|
||||
* byte).
|
||||
* @param[in] ipv6_addr IPv6 address to be converted.
|
||||
*
|
||||
* @return Pointer to addr_str.
|
||||
*/
|
||||
char *ipv6_addr_to_str(char *addr_str, const ipv6_addr_t *ipv6_addr);
|
||||
|
||||
/**
|
||||
* @brief Checks if two IPv6 addresses are equal.
|
||||
*
|
||||
* @param[in] a An IPv6 address.
|
||||
* @param[in] b Another IPv6 address.
|
||||
*
|
||||
* @return 1 if *a* and *b* are equal, 0 otherwise.
|
||||
*/
|
||||
int ipv6_addr_is_equal(const ipv6_addr_t *a, const ipv6_addr_t *b);
|
||||
|
||||
/**
|
||||
* @brief Checks if *ipv6_addr* is unspecified (all zero).
|
||||
*
|
||||
* @see <a href="http://tools.ietf.org/html/rfc4291">
|
||||
* RFC 4291
|
||||
* </a>
|
||||
*
|
||||
* @param[in] ipv6_addr An IPv6 address.
|
||||
*
|
||||
* @return 1 if *ipv6_addr* is unspecified address, 0 otherwise.
|
||||
*/
|
||||
int ipv6_addr_is_unspecified(const ipv6_addr_t *ipv6_addr);
|
||||
|
||||
/**
|
||||
* @brief Check if *ipv6_addr* is a link-local address.
|
||||
*
|
||||
* @see <a href="http://tools.ietf.org/html/rfc4291">
|
||||
* RFC 4291
|
||||
* </a>
|
||||
*
|
||||
* @param[in] ipv6_addr An IPv6 address.
|
||||
*
|
||||
* @return 1 if *ipv6_addr* is link-local address, 0 otherwise.
|
||||
*/
|
||||
int ipv6_addr_is_link_local(const ipv6_addr_t *ipv6_addr);
|
||||
|
||||
/**
|
||||
* @brief Check if *ipv6_addr* is a multicast address.
|
||||
*
|
||||
* @see <a href="http://tools.ietf.org/html/rfc4291">
|
||||
* RFC 4291
|
||||
* </a>
|
||||
*
|
||||
* @param[in] ipv6_addr An IPv6 address.
|
||||
*
|
||||
* @return 1 if *ipv6_addr* is multicast address, 0 otherwise.
|
||||
*/
|
||||
int ipv6_addr_is_multicast(const ipv6_addr_t *ipv6_addr);
|
||||
|
||||
/**
|
||||
* @brief Check if *ipv6_addr* is solicited-node multicast address.
|
||||
*
|
||||
* @see <a href="http://tools.ietf.org/html/rfc4291">
|
||||
* RFC 4291
|
||||
* </a>
|
||||
*
|
||||
* @param[in] ipv6_addr An IPv6 address.
|
||||
*
|
||||
* @return 1 if *ipv6_addr* is solicited-node multicast address,
|
||||
* 0 otherwise.
|
||||
*/
|
||||
int ipv6_addr_is_solicited_node(const ipv6_addr_t *ipv6_addr);
|
||||
|
||||
/*
|
||||
* TODO to wrap sixlowpan initialisations
|
||||
* int ipv6_iface_init(transceiver_type_t trans, ..);
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Add an IPv6 address to this nodes interface.
|
||||
*
|
||||
* @see <a href="http://tools.ietf.org/html/rfc4862">
|
||||
* RFC 4862
|
||||
* </a>
|
||||
*
|
||||
* @param[in] addr Address to be added to the interface.
|
||||
* @param[in] type Type of this address.
|
||||
* @param[in] state Initial state of the address.
|
||||
* @param[in] val_ltime Valid lifetime of this address in seconds.
|
||||
* @param[in] pref_ltime Preferred lifetime of this address in
|
||||
* seconds.
|
||||
*/
|
||||
void ipv6_iface_add_addr(const ipv6_addr_t *addr, ipv6_addr_type_t type,
|
||||
ndp_addr_state_t state, uint32_t val_ltime,
|
||||
uint32_t pref_ltime);
|
||||
|
||||
/**
|
||||
* @brief Tries to determine best suitable source address attached to
|
||||
* the interface of this node based on the given destination
|
||||
* address. The use-case for this function is to find a
|
||||
* suitable address for the source address field of an IPv6
|
||||
* address upon sending. *src* may be empty (all zero) if there
|
||||
* is no suitable address attached to the interface.
|
||||
*
|
||||
* @param[out] src The best source address for this node (may be
|
||||
* all zero if ther is none).
|
||||
* @param[in] dest The destination address for a packet we search
|
||||
* the source address for.
|
||||
*/
|
||||
void ipv6_iface_get_best_src_addr(ipv6_addr_t *src,
|
||||
const ipv6_addr_t *dest);
|
||||
|
||||
/**
|
||||
* @brief Print all addresses attached to the interface to stdout.
|
||||
*/
|
||||
void ipv6_iface_print_addrs(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* SIXLOWPAN_IP_H */
|
||||
|
@ -160,7 +160,8 @@ typedef enum __attribute__((packed))
|
||||
{
|
||||
LOWPAN_IPHC_DISABLE = 0, ///< header compression disabled
|
||||
LOWPAN_IPHC_ENABLE = 1 ///< header compression enabled
|
||||
} sixlowpan_lowpan_iphc_status_t;
|
||||
}
|
||||
sixlowpan_lowpan_iphc_status_t;
|
||||
|
||||
/**
|
||||
* @brief Data type to represent an 6LoWPAN frame as byte stream.
|
||||
@ -190,7 +191,7 @@ void sixlowpan_lowpan_init(transceiver_type_t trans, uint8_t r_addr,
|
||||
* @param[in] r_addr PHY layer address.
|
||||
*/
|
||||
void sixlowpan_lowpan_adhoc_init(transceiver_type_t trans,
|
||||
const ipv6_addr_t *prefix,
|
||||
const ipv6_addr_t *prefix,
|
||||
uint8_t r_addr);
|
||||
|
||||
/**
|
||||
@ -207,17 +208,17 @@ void sixlowpan_lowpan_adhoc_init(transceiver_type_t trans,
|
||||
* address.
|
||||
*/
|
||||
uint8_t sixlowpan_lowpan_border_init(transceiver_type_t trans,
|
||||
const ipv6_addr_t *border_router_addr);
|
||||
const ipv6_addr_t *border_router_addr);
|
||||
|
||||
/**
|
||||
* @brief Send data via 6LoWPAN to destination node dest.
|
||||
*
|
||||
* @param[in] dest EUI-64 of destination node.
|
||||
* @param[in] data Data to send to destination node (may be
|
||||
* @param[in] data Data to send to destination node (may be
|
||||
* manipulated).
|
||||
* @param[in] data_len Length of data.
|
||||
*/
|
||||
void sixlowpan_lowpan_sendto(const ieee_802154_long_t *dest,
|
||||
void sixlowpan_lowpan_sendto(const ieee_802154_long_t *dest,
|
||||
uint8_t *data, uint16_t data_len);
|
||||
|
||||
/**
|
||||
@ -228,6 +229,19 @@ void sixlowpan_lowpan_sendto(const ieee_802154_long_t *dest,
|
||||
void sixlowpan_lowpan_set_iphc_status(
|
||||
sixlowpan_lowpan_iphc_status_t status);
|
||||
|
||||
/**
|
||||
* @brief Initialize 6LoWPAN neighbor discovery (i.e. send
|
||||
* router advertisement with Source Link-Layer Address Option)
|
||||
*
|
||||
* @see <a href="http://tools.ietf.org/html/rfc4861">
|
||||
* RFC 4861
|
||||
* </a>, <a href="http://tools.ietf.org/html/rfc6775">
|
||||
* RFC 6775
|
||||
* </a>
|
||||
*
|
||||
*/
|
||||
void sixlowpan_lowpan_bootstrapping(void);
|
||||
|
||||
/**
|
||||
* @brief Registers a thread to read received 6LoWPAN frames. The
|
||||
* 6LoWPAN frames are delivered as sixlowpan_lowpan_frame_t
|
||||
|
@ -15,7 +15,6 @@
|
||||
* @author Martin Lenders <mlenders@inf.fu-berlin.de>
|
||||
* @author Eric Engel <eric.engel@fu-berlin.de>
|
||||
* @author Oliver Gesch <oliver.gesch@googlemail.com>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifndef SIXLOWPAN_TYPES_H
|
||||
@ -46,5 +45,69 @@ typedef union __attribute__((packed)) {
|
||||
uint32_t uint32[4]; ///< devided by 4 32-bit words.
|
||||
} ipv6_addr_t;
|
||||
|
||||
/**
|
||||
* @brief Data type to represent IPv6 address types.
|
||||
*
|
||||
* @see <a href="http://tools.ietf.org/html/rfc4291">
|
||||
* RFC 4291
|
||||
* </a>
|
||||
*/
|
||||
typedef enum __attribute__((packed)) {
|
||||
IPV6_ADDR_TYPE_NONE, ///< address has no type/is invalid.
|
||||
IPV6_ADDR_TYPE_UNICAST, ///< address is an unicast address.
|
||||
IPV6_ADDR_TYPE_MULTICAST, ///< address is a multicast address.
|
||||
IPV6_ADDR_TYPE_ANYCAST, ///< address is an anycast address.
|
||||
IPV6_ADDR_TYPE_SOLICITED_NODE, ///< address is a solicitated node
|
||||
///< multicast address.
|
||||
IPV6_ADDR_TYPE_LOOPBACK, ///< address is a loopback address.
|
||||
IPV6_ADDR_TYPE_LINK_LOCAL, ///< address is a link-local address.
|
||||
IPV6_ADDR_TYPE_GLOBAL ///< address is a global address.
|
||||
} ipv6_addr_type_t;
|
||||
|
||||
/**
|
||||
* @brief Data type to represent an IPv6 packet header
|
||||
*
|
||||
* @see <a href="http://tools.ietf.org/html/rfc2460">
|
||||
* RFC 2460
|
||||
* </a>
|
||||
*/
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t version_trafficclass; ///< Version field + first 4 bit of Traffic Class.
|
||||
uint8_t trafficclass_flowlabel; ///< last 4 bit of Traffic Class
|
||||
///< and first 4 bit of Flow Label.
|
||||
uint16_t flowlabel; ///< last 16 bit of Flow Label.
|
||||
uint16_t length; ///< payload length of this packet.
|
||||
uint8_t nextheader; ///< type of next header in this packet.
|
||||
uint8_t hoplimit; ///< hop limit for this packet.
|
||||
ipv6_addr_t srcaddr; ///< source address of this packet.
|
||||
ipv6_addr_t destaddr; ///< destination address of this packet.
|
||||
} ipv6_hdr_t;
|
||||
|
||||
/**
|
||||
* @brief Data type to represent an ICMPv6 packet header.
|
||||
*
|
||||
* @see <a href="http://tools.ietf.org/html/rfc4443">
|
||||
* RFC 4443
|
||||
* </a>
|
||||
*/
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t type; ///< Type of the ICMPv6 message.
|
||||
uint8_t code; ///< Code of the ICMPv6 message.
|
||||
uint16_t checksum; ///< Checksum of the ICMPv6 message.
|
||||
} icmpv6_hdr_t;
|
||||
|
||||
/**
|
||||
* @brief Data type to represent address types according to
|
||||
* <a href="http://tools.ietf.org/hmtl/rfc4862">RFC 4862</a>.
|
||||
*/
|
||||
typedef enum __attribute__((packed)) {
|
||||
NDP_ADDR_STATE_TENTATIVE, ///< tentative address, uniqueness to be verified.
|
||||
NDP_ADDR_STATE_PREFERRED, ///< preferred address, for unrestricted use.
|
||||
NDP_ADDR_STATE_DEPRECATED, ///< deprecated address, use discouraged.
|
||||
NDP_ADDR_STATE_ANY ///< addresses of this state are always permitted.
|
||||
} ndp_addr_state_t;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* SIXLOWPAN_TYPES_H */
|
||||
|
@ -31,17 +31,20 @@
|
||||
#include "icmp.h"
|
||||
#include "lowpan.h"
|
||||
|
||||
#include "sys/net/destiny/in.h"
|
||||
#include "sys/net/destiny/socket.h"
|
||||
#include "sys/net/net_help/net_help.h"
|
||||
#include "sys/net/net_help/msg_help.h"
|
||||
|
||||
#define IP_PKT_RECV_BUF_SIZE (64)
|
||||
#define LLHDR_IPV6HDR_LEN (LL_HDR_LEN + IPV6_HDR_LEN)
|
||||
|
||||
uint8_t ip_send_buffer[BUFFER_SIZE];
|
||||
uint8_t buffer[BUFFER_SIZE];
|
||||
msg_t msg_queue[IP_PKT_RECV_BUF_SIZE];
|
||||
ipv6_hdr_t *ipv6_buf;
|
||||
struct icmpv6_hdr_t *icmp_buf;
|
||||
icmpv6_hdr_t *icmp_buf;
|
||||
uint8_t *nextheader;
|
||||
|
||||
uint8_t iface_addr_list_count = 0;
|
||||
int udp_packet_handler_pid = 0;
|
||||
int tcp_packet_handler_pid = 0;
|
||||
@ -50,22 +53,22 @@ int rpl_process_pid = 0;
|
||||
/* registered upper layer threads */
|
||||
int sixlowip_reg[SIXLOWIP_MAX_REGISTERED];
|
||||
|
||||
void ipv6_send_buf(ipv6_hdr_t *buffer)
|
||||
void ipv6_send_bytes(ipv6_hdr_t *bytes)
|
||||
{
|
||||
uint16_t offset = IPV6_HDR_LEN + HTONS(buffer->length);
|
||||
uint16_t offset = IPV6_HDR_LEN + HTONS(bytes->length);
|
||||
|
||||
buffer->flowlabel = HTONS(buffer->flowlabel);
|
||||
buffer->length = HTONS(buffer->length);
|
||||
bytes->flowlabel = HTONS(bytes->flowlabel);
|
||||
bytes->length = HTONS(bytes->length);
|
||||
|
||||
memset(buffer, 0, BUFFER_SIZE);
|
||||
memcpy(buffer + LL_HDR_LEN, buffer, offset);
|
||||
memset(bytes, 0, BUFFER_SIZE);
|
||||
memcpy(bytes + LL_HDR_LEN, bytes, offset);
|
||||
|
||||
sixlowpan_lowpan_sendto((ieee_802154_long_t *) & (buffer->destaddr.uint16[4]),
|
||||
(uint8_t *)buffer,
|
||||
sixlowpan_lowpan_sendto((ieee_802154_long_t *) & (bytes->destaddr.uint16[4]),
|
||||
(uint8_t *)bytes,
|
||||
offset);
|
||||
}
|
||||
|
||||
ipv6_hdr_t *get_ipv6_buf_send(void)
|
||||
ipv6_hdr_t *ipv6_get_buf_send(void)
|
||||
{
|
||||
return ((ipv6_hdr_t *) & (ip_send_buffer[LL_HDR_LEN]));
|
||||
}
|
||||
@ -75,13 +78,14 @@ uint8_t *get_payload_buf_send(uint8_t ext_len)
|
||||
return &(ip_send_buffer[LLHDR_IPV6HDR_LEN + ext_len]);
|
||||
}
|
||||
|
||||
ipv6_hdr_t *get_ipv6_buf(void)
|
||||
ipv6_hdr_t *ipv6_get_buf(void)
|
||||
{
|
||||
return ((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]));
|
||||
icmpv6_hdr_t *get_icmpv6_buf(uint8_t ext_len)
|
||||
{
|
||||
return ((icmpv6_hdr_t *) & (buffer[LLHDR_IPV6HDR_LEN + ext_len]));
|
||||
}
|
||||
|
||||
uint8_t *get_payload_buf(uint8_t ext_len)
|
||||
@ -89,49 +93,41 @@ uint8_t *get_payload_buf(uint8_t ext_len)
|
||||
return &(buffer[LLHDR_IPV6HDR_LEN + ext_len]);
|
||||
}
|
||||
|
||||
void sixlowpan_bootstrapping(void)
|
||||
{
|
||||
|
||||
init_rtr_sol(OPT_SLLAO);
|
||||
}
|
||||
|
||||
void sixlowpan_send(ipv6_addr_t *addr, uint8_t *payload, uint16_t p_len,
|
||||
uint8_t next_header)
|
||||
void ipv6_sendto(const ipv6_addr_t *dest, uint8_t next_header,
|
||||
const uint8_t *payload, uint16_t payload_length)
|
||||
{
|
||||
uint8_t *p_ptr;
|
||||
uint16_t packet_length;
|
||||
|
||||
if (next_header == IPPROTO_TCP) {
|
||||
if (next_header == IPV6_PROTO_NUM_TCP) {
|
||||
p_ptr = get_payload_buf_send(ipv6_ext_hdr_len);
|
||||
ipv6_buf = get_ipv6_buf_send();
|
||||
ipv6_buf = ipv6_get_buf_send();
|
||||
}
|
||||
else {
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = ipv6_get_buf();
|
||||
p_ptr = get_payload_buf(ipv6_ext_hdr_len);
|
||||
}
|
||||
|
||||
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 = next_header;
|
||||
ipv6_buf->hoplimit = MULTIHOP_HOPLIMIT;
|
||||
ipv6_buf->length = p_len;
|
||||
ipv6_buf->length = payload_length;
|
||||
|
||||
memcpy(&(ipv6_buf->destaddr), addr, 16);
|
||||
ipv6_get_saddr(&(ipv6_buf->srcaddr), &(ipv6_buf->destaddr));
|
||||
memcpy(&(ipv6_buf->destaddr), dest, 16);
|
||||
ipv6_iface_get_best_src_addr(&(ipv6_buf->srcaddr), &(ipv6_buf->destaddr));
|
||||
|
||||
memcpy(p_ptr, payload, p_len);
|
||||
memcpy(p_ptr, payload, payload_length);
|
||||
|
||||
packet_length = IPV6_HDR_LEN + p_len;
|
||||
packet_length = IPV6_HDR_LEN + payload_length;
|
||||
|
||||
sixlowpan_lowpan_sendto((ieee_802154_long_t *) & (ipv6_buf->destaddr.uint16[4]),
|
||||
(uint8_t *)ipv6_buf, packet_length);
|
||||
}
|
||||
|
||||
/* Register an upper layer thread */
|
||||
uint8_t sixlowip_register(int pid)
|
||||
uint8_t ipv6_register_packet_handler(int pid)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
@ -149,7 +145,7 @@ uint8_t sixlowip_register(int pid)
|
||||
}
|
||||
}
|
||||
|
||||
int icmpv6_demultiplex(const struct icmpv6_hdr_t *hdr)
|
||||
int icmpv6_demultiplex(const icmpv6_hdr_t *hdr)
|
||||
{
|
||||
switch (hdr->type) {
|
||||
case (ICMP_ECHO_REQ): {
|
||||
@ -216,6 +212,35 @@ int icmpv6_demultiplex(const struct icmpv6_hdr_t *hdr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t ipv6_get_addr_match(const ipv6_addr_t *src,
|
||||
const ipv6_addr_t *dst)
|
||||
{
|
||||
uint8_t val = 0, xor;
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
/* if bytes are equal add 8 */
|
||||
if (src->uint8[i] == dst->uint8[i]) {
|
||||
val += 8;
|
||||
}
|
||||
else {
|
||||
xor = src->uint8[i] ^ dst->uint8[i];
|
||||
|
||||
/* while bits from byte equal add 1 */
|
||||
for (int j = 0; j < 8; j++) {
|
||||
if ((xor & 0x80) == 0) {
|
||||
val++;
|
||||
xor = xor << 1;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
void ipv6_process(void)
|
||||
{
|
||||
msg_t m_recv_lowpan, m_send_lowpan;
|
||||
@ -224,8 +249,8 @@ void ipv6_process(void)
|
||||
uint8_t i;
|
||||
uint16_t packet_length;
|
||||
|
||||
ipv6_init_address(&myaddr, 0xabcd, 0x0, 0x0, 0x0, 0x3612, 0x00ff, 0xfe00,
|
||||
sixlowpan_mac_get_radio_address());
|
||||
ipv6_addr_init(&myaddr, 0xabcd, 0x0, 0x0, 0x0, 0x3612, 0x00ff, 0xfe00,
|
||||
sixlowpan_mac_get_radio_address());
|
||||
|
||||
while (1) {
|
||||
msg_receive(&m_recv_lowpan);
|
||||
@ -238,9 +263,9 @@ void ipv6_process(void)
|
||||
if ((ipv6_get_addr_match(&myaddr, &ipv6_buf->destaddr) >= 112) &&
|
||||
(ipv6_buf->destaddr.uint8[15] != myaddr.uint8[15])) {
|
||||
packet_length = IPV6_HDR_LEN + ipv6_buf->length;
|
||||
memcpy(get_ipv6_buf_send(), get_ipv6_buf(), packet_length);
|
||||
memcpy(ipv6_get_buf_send(), ipv6_get_buf(), packet_length);
|
||||
sixlowpan_lowpan_sendto((ieee_802154_long_t *) & (ipv6_buf->destaddr.uint16[4]),
|
||||
(uint8_t *)get_ipv6_buf_send(),
|
||||
(uint8_t *)ipv6_get_buf_send(),
|
||||
packet_length);
|
||||
}
|
||||
else {
|
||||
@ -253,9 +278,9 @@ void ipv6_process(void)
|
||||
}
|
||||
|
||||
switch (*nextheader) {
|
||||
case (PROTO_NUM_ICMPV6): {
|
||||
case (IPV6_PROTO_NUM_ICMPV6): {
|
||||
/* checksum test*/
|
||||
if (icmpv6_csum(PROTO_NUM_ICMPV6) != 0xffff) {
|
||||
if (icmpv6_csum(IPV6_PROTO_NUM_ICMPV6) != 0xffff) {
|
||||
printf("ERROR: wrong checksum\n");
|
||||
}
|
||||
|
||||
@ -264,7 +289,7 @@ void ipv6_process(void)
|
||||
break;
|
||||
}
|
||||
|
||||
case (IPPROTO_TCP): {
|
||||
case (IPV6_PROTO_NUM_TCP): {
|
||||
if (tcp_packet_handler_pid != 0) {
|
||||
m_send.content.ptr = (char *) ipv6_buf;
|
||||
msg_send_receive(&m_send, &m_recv, tcp_packet_handler_pid);
|
||||
@ -276,7 +301,7 @@ void ipv6_process(void)
|
||||
break;
|
||||
}
|
||||
|
||||
case (IPPROTO_UDP): {
|
||||
case (IPV6_PROTO_NUM_UDP): {
|
||||
if (udp_packet_handler_pid != 0) {
|
||||
m_send.content.ptr = (char *) ipv6_buf;
|
||||
msg_send_receive(&m_send, &m_recv, udp_packet_handler_pid);
|
||||
@ -288,7 +313,7 @@ void ipv6_process(void)
|
||||
break;
|
||||
}
|
||||
|
||||
case (PROTO_NUM_NONE): {
|
||||
case (IPV6_PROTO_NUM_NONE): {
|
||||
printf("INFO: Packet with no Header following the IPv6 Header received.\n");
|
||||
break;
|
||||
}
|
||||
@ -302,10 +327,11 @@ void ipv6_process(void)
|
||||
}
|
||||
}
|
||||
|
||||
void ipv6_iface_add_addr(ipv6_addr_t *addr, uint8_t state, uint32_t val_ltime,
|
||||
uint32_t pref_ltime, uint8_t type)
|
||||
void ipv6_iface_add_addr(const ipv6_addr_t *addr, ipv6_addr_type_t type,
|
||||
ndp_addr_state_t state, uint32_t val_ltime,
|
||||
uint32_t pref_ltime)
|
||||
{
|
||||
if (ipv6_addr_unspec_match(addr) == 128) {
|
||||
if (ipv6_addr_is_unspecified(addr) == 128) {
|
||||
printf("ERROR: unspecified address (::) can't be assigned to interface.\n");
|
||||
return;
|
||||
}
|
||||
@ -328,19 +354,21 @@ void ipv6_iface_add_addr(ipv6_addr_t *addr, uint8_t state, uint32_t val_ltime,
|
||||
iface_addr_list_count++;
|
||||
|
||||
/* Register to Solicited-Node multicast address according to RFC 4291 */
|
||||
if (type == ADDR_TYPE_ANYCAST || type == ADDR_TYPE_LINK_LOCAL ||
|
||||
type == ADDR_TYPE_GLOBAL || type == ADDR_TYPE_UNICAST) {
|
||||
if (type == IPV6_ADDR_TYPE_ANYCAST || type == IPV6_ADDR_TYPE_LINK_LOCAL ||
|
||||
type == IPV6_ADDR_TYPE_GLOBAL || type == IPV6_ADDR_TYPE_UNICAST) {
|
||||
ipv6_addr_t sol_node_mcast_addr;
|
||||
ipv6_set_sol_node_mcast_addr(addr, &sol_node_mcast_addr);
|
||||
ipv6_addr_set_solicited_node_addr(&sol_node_mcast_addr, addr);
|
||||
|
||||
if (ipv6_iface_addr_match(&sol_node_mcast_addr) == NULL) {
|
||||
ipv6_iface_add_addr(&sol_node_mcast_addr, state, val_ltime, pref_ltime, ADDR_TYPE_SOL_NODE_MCAST);
|
||||
ipv6_iface_add_addr(&sol_node_mcast_addr,
|
||||
IPV6_ADDR_TYPE_SOLICITED_NODE,
|
||||
state, val_ltime, pref_ltime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addr_list_t *ipv6_iface_addr_match(ipv6_addr_t *addr)
|
||||
addr_list_t *ipv6_iface_addr_match(const ipv6_addr_t *addr)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -371,80 +399,92 @@ addr_list_t *ipv6_iface_addr_prefix_eq(ipv6_addr_t *addr)
|
||||
void ipv6_iface_print_addrs(void)
|
||||
{
|
||||
for (int i = 0; i < iface_addr_list_count; i++) {
|
||||
ipv6_print_addr(&(iface.addr_list[i].addr));
|
||||
char addr_str[IPV6_MAX_ADDR_STR_LEN];
|
||||
printf("%s\n", ipv6_addr_to_str(addr_str,
|
||||
&(iface.addr_list[i].addr)));
|
||||
}
|
||||
}
|
||||
|
||||
void ipv6_init_addr_prefix(ipv6_addr_t *inout, ipv6_addr_t *prefix)
|
||||
void ipv6_addr_set_by_eui64(ipv6_addr_t *out, const ipv6_addr_t *prefix)
|
||||
{
|
||||
inout->uint16[0] = prefix->uint16[0];
|
||||
inout->uint16[1] = prefix->uint16[1];
|
||||
inout->uint16[2] = prefix->uint16[2];
|
||||
inout->uint16[3] = prefix->uint16[3];
|
||||
out->uint16[0] = prefix->uint16[0];
|
||||
out->uint16[1] = prefix->uint16[1];
|
||||
out->uint16[2] = prefix->uint16[2];
|
||||
out->uint16[3] = prefix->uint16[3];
|
||||
|
||||
memcpy(&(inout->uint8[8]), &(iface.laddr.uint8[0]), 8);
|
||||
memcpy(&(out->uint8[8]), &(iface.laddr.uint8[0]), 8);
|
||||
}
|
||||
|
||||
void ipv6_set_prefix(ipv6_addr_t *inout, const ipv6_addr_t *prefix)
|
||||
void ipv6_addr_init_prefix(ipv6_addr_t *out, const ipv6_addr_t *prefix,
|
||||
uint8_t bits)
|
||||
{
|
||||
inout->uint16[0] = prefix->uint16[0];
|
||||
inout->uint16[1] = prefix->uint16[1];
|
||||
inout->uint16[2] = prefix->uint16[2];
|
||||
inout->uint16[3] = prefix->uint16[3];
|
||||
inout->uint16[4] = 0;
|
||||
inout->uint16[5] = 0;
|
||||
inout->uint16[6] = 0;
|
||||
inout->uint16[7] = 0;
|
||||
if (bits > 128) {
|
||||
bits = 128;
|
||||
}
|
||||
|
||||
uint8_t bytes = bits / 8, mask;
|
||||
|
||||
if (bits % 8) {
|
||||
mask = 0xff << (bits - (bytes * 8));
|
||||
}
|
||||
else {
|
||||
mask = 0x00;
|
||||
}
|
||||
|
||||
bytes++;
|
||||
memset(out, 0, 16);
|
||||
memcpy(out, prefix, bytes);
|
||||
out->uint8[bytes] = prefix->uint8[bytes] & mask;
|
||||
}
|
||||
|
||||
void ipv6_set_all_rtrs_mcast_addr(ipv6_addr_t *ipaddr)
|
||||
void ipv6_addr_set_all_routers_addr(ipv6_addr_t *ipv6_addr)
|
||||
{
|
||||
ipaddr->uint16[0] = HTONS(0xff02);
|
||||
ipaddr->uint16[1] = 0;
|
||||
ipaddr->uint16[2] = 0;
|
||||
ipaddr->uint16[3] = 0;
|
||||
ipaddr->uint16[4] = 0;
|
||||
ipaddr->uint16[5] = 0;
|
||||
ipaddr->uint16[6] = 0;
|
||||
ipaddr->uint16[7] = HTONS(0x0002);
|
||||
ipv6_addr->uint16[0] = HTONS(0xff02);
|
||||
ipv6_addr->uint16[1] = 0;
|
||||
ipv6_addr->uint16[2] = 0;
|
||||
ipv6_addr->uint16[3] = 0;
|
||||
ipv6_addr->uint16[4] = 0;
|
||||
ipv6_addr->uint16[5] = 0;
|
||||
ipv6_addr->uint16[6] = 0;
|
||||
ipv6_addr->uint16[7] = HTONS(0x0002);
|
||||
}
|
||||
|
||||
void ipv6_set_all_nds_mcast_addr(ipv6_addr_t *ipaddr)
|
||||
void ipv6_addr_set_all_nodes_addr(ipv6_addr_t *ipv6_addr)
|
||||
{
|
||||
ipaddr->uint16[0] = HTONS(0xff02);
|
||||
ipaddr->uint16[1] = 0;
|
||||
ipaddr->uint16[2] = 0;
|
||||
ipaddr->uint16[3] = 0;
|
||||
ipaddr->uint16[4] = 0;
|
||||
ipaddr->uint16[5] = 0;
|
||||
ipaddr->uint16[6] = 0;
|
||||
ipaddr->uint16[7] = HTONS(0x0001);
|
||||
ipv6_addr->uint16[0] = HTONS(0xff02);
|
||||
ipv6_addr->uint16[1] = 0;
|
||||
ipv6_addr->uint16[2] = 0;
|
||||
ipv6_addr->uint16[3] = 0;
|
||||
ipv6_addr->uint16[4] = 0;
|
||||
ipv6_addr->uint16[5] = 0;
|
||||
ipv6_addr->uint16[6] = 0;
|
||||
ipv6_addr->uint16[7] = HTONS(0x0001);
|
||||
}
|
||||
|
||||
void ipv6_set_loaddr(ipv6_addr_t *ipaddr)
|
||||
void ipv6_addr_set_loopback_addr(ipv6_addr_t *ipv6_addr)
|
||||
{
|
||||
ipaddr->uint16[0] = 0;
|
||||
ipaddr->uint16[1] = 0;
|
||||
ipaddr->uint16[2] = 0;
|
||||
ipaddr->uint16[3] = 0;
|
||||
ipaddr->uint16[4] = 0;
|
||||
ipaddr->uint16[5] = 0;
|
||||
ipaddr->uint16[6] = 0;
|
||||
ipaddr->uint16[7] = HTONS(0x0001);
|
||||
ipv6_addr->uint16[0] = 0;
|
||||
ipv6_addr->uint16[1] = 0;
|
||||
ipv6_addr->uint16[2] = 0;
|
||||
ipv6_addr->uint16[3] = 0;
|
||||
ipv6_addr->uint16[4] = 0;
|
||||
ipv6_addr->uint16[5] = 0;
|
||||
ipv6_addr->uint16[6] = 0;
|
||||
ipv6_addr->uint16[7] = HTONS(0x0001);
|
||||
}
|
||||
|
||||
void ipv6_get_saddr(ipv6_addr_t *src, ipv6_addr_t *dst)
|
||||
void ipv6_iface_get_best_src_addr(ipv6_addr_t *src, const ipv6_addr_t *dest)
|
||||
{
|
||||
/* try to find best match if dest is not mcast or link local */
|
||||
int8_t itmp = -1;
|
||||
uint8_t tmp = 0;
|
||||
uint8_t bmatch = 0;
|
||||
|
||||
if (!(ipv6_prefix_ll_match(dst)) && !(ipv6_prefix_mcast_match(dst))) {
|
||||
if (!(ipv6_addr_is_link_local(dest)) && !(ipv6_addr_is_multicast(dest))) {
|
||||
for (int i = 0; i < IFACE_ADDR_LIST_LEN; i++) {
|
||||
if (iface.addr_list[i].state == ADDR_STATE_PREFERRED) {
|
||||
if (!(ipv6_prefix_ll_match(&(iface.addr_list[i].addr)))) {
|
||||
tmp = ipv6_get_addr_match(dst, &(iface.addr_list[i].addr));
|
||||
if (iface.addr_list[i].state == NDP_ADDR_STATE_PREFERRED) {
|
||||
if (!(ipv6_addr_is_link_local(&(iface.addr_list[i].addr)))) {
|
||||
tmp = ipv6_get_addr_match(dest, &(iface.addr_list[i].addr));
|
||||
|
||||
if (tmp >= bmatch) {
|
||||
bmatch = tmp;
|
||||
@ -456,8 +496,8 @@ void ipv6_get_saddr(ipv6_addr_t *src, ipv6_addr_t *dst)
|
||||
}
|
||||
else {
|
||||
for (int j = 0; j < IFACE_ADDR_LIST_LEN; j++) {
|
||||
if ((iface.addr_list[j].state == ADDR_STATE_PREFERRED) &&
|
||||
ipv6_prefix_ll_match(&(iface.addr_list[j].addr))) {
|
||||
if ((iface.addr_list[j].state == NDP_ADDR_STATE_PREFERRED) &&
|
||||
ipv6_addr_is_link_local(&(iface.addr_list[j].addr))) {
|
||||
itmp = j;
|
||||
}
|
||||
}
|
||||
@ -471,132 +511,88 @@ void ipv6_get_saddr(ipv6_addr_t *src, ipv6_addr_t *dst)
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ipv6_get_addr_match(ipv6_addr_t *src, ipv6_addr_t *dst)
|
||||
int ipv6_addr_is_equal(const ipv6_addr_t *a, const ipv6_addr_t *b)
|
||||
{
|
||||
uint8_t val = 0, xor;
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
/* if bytes are equal add 8 */
|
||||
if (src->uint8[i] == dst->uint8[i]) {
|
||||
val += 8;
|
||||
}
|
||||
else {
|
||||
xor = src->uint8[i] ^ dst->uint8[i];
|
||||
|
||||
/* while bits from byte equal add 1 */
|
||||
for (int j = 0; j < 8; j++) {
|
||||
if ((xor & 0x80) == 0) {
|
||||
val++;
|
||||
xor = xor << 1;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return val;
|
||||
return ipv6_get_addr_match(a, b) == 128;
|
||||
}
|
||||
|
||||
void ipv6_set_ll_prefix(ipv6_addr_t *ipaddr)
|
||||
void ipv6_addr_set_link_local_prefix(ipv6_addr_t *ipv6_addr)
|
||||
{
|
||||
ipaddr->uint16[0] = HTONS(0xfe80);
|
||||
ipaddr->uint16[1] = 0;
|
||||
ipaddr->uint16[2] = 0;
|
||||
ipaddr->uint16[3] = 0;
|
||||
ipv6_addr->uint16[0] = HTONS(0xfe80);
|
||||
ipv6_addr->uint16[1] = 0;
|
||||
ipv6_addr->uint16[2] = 0;
|
||||
ipv6_addr->uint16[3] = 0;
|
||||
}
|
||||
|
||||
void ipv6_init_address(ipv6_addr_t *addr, uint16_t addr0, uint16_t addr1,
|
||||
uint16_t addr2, uint16_t addr3, uint16_t addr4,
|
||||
uint16_t addr5, uint16_t addr6, uint16_t addr7)
|
||||
void ipv6_addr_init(ipv6_addr_t *out, uint16_t addr0, uint16_t addr1,
|
||||
uint16_t addr2, uint16_t addr3, uint16_t addr4,
|
||||
uint16_t addr5, uint16_t addr6, uint16_t addr7)
|
||||
{
|
||||
addr->uint16[0] = HTONS(addr0);
|
||||
addr->uint16[1] = HTONS(addr1);
|
||||
addr->uint16[2] = HTONS(addr2);
|
||||
addr->uint16[3] = HTONS(addr3);
|
||||
addr->uint16[4] = HTONS(addr4);
|
||||
addr->uint16[5] = HTONS(addr5);
|
||||
addr->uint16[6] = HTONS(addr6);
|
||||
addr->uint16[7] = HTONS(addr7);
|
||||
out->uint16[0] = HTONS(addr0);
|
||||
out->uint16[1] = HTONS(addr1);
|
||||
out->uint16[2] = HTONS(addr2);
|
||||
out->uint16[3] = HTONS(addr3);
|
||||
out->uint16[4] = HTONS(addr4);
|
||||
out->uint16[5] = HTONS(addr5);
|
||||
out->uint16[6] = HTONS(addr6);
|
||||
out->uint16[7] = HTONS(addr7);
|
||||
}
|
||||
|
||||
uint8_t ipv6_prefix_ll_match(ipv6_addr_t *addr)
|
||||
int ipv6_addr_is_link_local(const ipv6_addr_t *addr)
|
||||
{
|
||||
if (addr->uint8[0] == 0xfe && addr->uint8[1] == 0x80) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return addr->uint8[0] == 0xfe && addr->uint8[0] == 0x80;
|
||||
}
|
||||
|
||||
uint8_t ipv6_prefix_mcast_match(ipv6_addr_t *addr)
|
||||
int ipv6_addr_is_multicast(const ipv6_addr_t *addr)
|
||||
{
|
||||
if (addr->uint8[0] == 0xff && addr->uint8[1] == 0x02) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return addr->uint8[0] == 0xff;
|
||||
}
|
||||
|
||||
uint8_t ipv6_addr_unspec_match(ipv6_addr_t *addr)
|
||||
int ipv6_addr_is_unspecified(const ipv6_addr_t *ipv6_addr)
|
||||
{
|
||||
if ((addr->uint16[0] == 0) && (addr->uint16[1] == 0) &&
|
||||
(addr->uint16[2] == 0) && (addr->uint16[3] == 0) &&
|
||||
(addr->uint16[4] == 0) && (addr->uint16[5] == 0) &&
|
||||
(addr->uint16[6] == 0) && (addr->uint16[7] == 0)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return (ipv6_addr->uint32[0] == 0) && (ipv6_addr->uint32[1] == 0) &&
|
||||
(ipv6_addr->uint32[2] == 0) && (ipv6_addr->uint32[3] == 0);
|
||||
}
|
||||
|
||||
uint8_t ipv6_addr_sol_node_mcast_match(ipv6_addr_t *addr)
|
||||
int ipv6_addr_is_solicited_node(const ipv6_addr_t *ipv6_addr)
|
||||
{
|
||||
/* note: cool if-condition*/
|
||||
if ((addr->uint8[0] == 0xFF) && (addr->uint8[1] == 0x02) &&
|
||||
(addr->uint16[1] == 0x00) && (addr->uint16[2] == 0x00) &&
|
||||
(addr->uint16[3] == 0x00) && (addr->uint16[4] == 0x00) &&
|
||||
(addr->uint8[10] == 0x00) && (addr->uint8[11] == 0x01) &&
|
||||
(addr->uint8[12] == 0xFF)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return (ipv6_addr->uint8[0] == 0xFF) &&
|
||||
(ipv6_addr->uint8[1] == 0x02) &&
|
||||
(ipv6_addr->uint16[1] == 0x00) &&
|
||||
(ipv6_addr->uint16[2] == 0x00) &&
|
||||
(ipv6_addr->uint16[3] == 0x00) &&
|
||||
(ipv6_addr->uint16[4] == 0x00) &&
|
||||
(ipv6_addr->uint8[10] == 0x00) &&
|
||||
(ipv6_addr->uint8[11] == 0x01) &&
|
||||
(ipv6_addr->uint8[12] == 0xFF);
|
||||
}
|
||||
|
||||
void ipv6_set_sol_node_mcast_addr(ipv6_addr_t *addr_in, ipv6_addr_t *addr_out)
|
||||
void ipv6_addr_set_solicited_node_addr(ipv6_addr_t *ipv6_addr_out,
|
||||
const ipv6_addr_t *ipv6_addr_in)
|
||||
{
|
||||
/* copy only the last 24-bit of the ip-address that is beeing resolved */
|
||||
addr_out->uint16[0] = HTONS(0xff02);
|
||||
addr_out->uint16[1] = 0;
|
||||
addr_out->uint16[2] = 0;
|
||||
addr_out->uint16[3] = 0;
|
||||
addr_out->uint16[4] = 0;
|
||||
addr_out->uint16[5] = HTONS(0x0001);
|
||||
addr_out->uint8[12] = 0xff;
|
||||
addr_out->uint8[13] = addr_in->uint8[13];
|
||||
addr_out->uint16[7] = addr_in->uint16[7];
|
||||
ipv6_addr_out->uint16[0] = HTONS(0xff02);
|
||||
ipv6_addr_out->uint16[1] = 0;
|
||||
ipv6_addr_out->uint16[2] = 0;
|
||||
ipv6_addr_out->uint16[3] = 0;
|
||||
ipv6_addr_out->uint16[4] = 0;
|
||||
ipv6_addr_out->uint16[5] = HTONS(0x0001);
|
||||
ipv6_addr_out->uint8[12] = 0xff;
|
||||
ipv6_addr_out->uint8[13] = ipv6_addr_in->uint8[13];
|
||||
ipv6_addr_out->uint16[7] = ipv6_addr_in->uint16[7];
|
||||
}
|
||||
|
||||
void ipv6_print_addr(ipv6_addr_t *ipaddr)
|
||||
char *ipv6_addr_to_str(char *addr_str, const ipv6_addr_t *ipv6_addr)
|
||||
{
|
||||
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],
|
||||
((uint8_t *)ipaddr)[6], ((uint8_t *)ipaddr)[7], ((uint8_t *)ipaddr)[8],
|
||||
((uint8_t *)ipaddr)[9], ((uint8_t *)ipaddr)[10], ((uint8_t *)ipaddr)[11],
|
||||
((uint8_t *)ipaddr)[12], ((uint8_t *)ipaddr)[13], ((uint8_t *)ipaddr)[14],
|
||||
((uint8_t *)ipaddr)[15]);
|
||||
sprintf(addr_str,
|
||||
"%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
|
||||
ipv6_addr->uint16[0], ipv6_addr->uint16[1],
|
||||
ipv6_addr->uint16[2], ipv6_addr->uint16[3],
|
||||
ipv6_addr->uint16[4], ipv6_addr->uint16[5],
|
||||
ipv6_addr->uint16[6], ipv6_addr->uint16[7]);
|
||||
return addr_str;
|
||||
}
|
||||
|
||||
uint8_t ipv6_next_hdr_unknown(uint8_t next_hdr)
|
||||
{
|
||||
return next_hdr == PROTO_NUM_ICMPV6 ||
|
||||
next_hdr == PROTO_NUM_NONE;
|
||||
}
|
||||
|
||||
|
||||
uint32_t get_remaining_time(timex_t *t)
|
||||
{
|
||||
timex_t now;
|
||||
@ -618,8 +614,8 @@ void ipv6_init_iface_as_router(void)
|
||||
{
|
||||
ipv6_addr_t addr;
|
||||
|
||||
ipv6_set_all_rtrs_mcast_addr(&addr);
|
||||
ipv6_iface_add_addr(&addr, ADDR_STATE_PREFERRED, 0, 0, ADDR_TYPE_MULTICAST);
|
||||
ipv6_addr_set_all_routers_addr(&addr);
|
||||
ipv6_iface_add_addr(&addr, NDP_ADDR_STATE_PREFERRED, 0, 0, IPV6_ADDR_TYPE_MULTICAST);
|
||||
}
|
||||
|
||||
|
||||
@ -627,7 +623,7 @@ uint8_t ipv6_is_router(void)
|
||||
{
|
||||
ipv6_addr_t addr;
|
||||
|
||||
ipv6_set_all_rtrs_mcast_addr(&addr);
|
||||
ipv6_addr_set_all_routers_addr(&addr);
|
||||
|
||||
if (ipv6_iface_addr_match(&addr) != NULL) {
|
||||
return 1;
|
||||
@ -646,7 +642,22 @@ void set_udp_packet_handler_pid(int pid)
|
||||
udp_packet_handler_pid = pid;
|
||||
}
|
||||
|
||||
void set_rpl_process_pid(int pid)
|
||||
void ipv6_register_next_header_handler(uint8_t next_header, int pid)
|
||||
{
|
||||
switch (next_header) {
|
||||
case (IPV6_PROTO_NUM_TCP):
|
||||
set_tcp_packet_handler_pid(pid);
|
||||
break;
|
||||
case (IPV6_PROTO_NUM_UDP):
|
||||
set_udp_packet_handler_pid(pid);
|
||||
break;
|
||||
default:
|
||||
/* TODO */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ipv6_register_rpl_handler(int pid)
|
||||
{
|
||||
rpl_process_pid = pid;
|
||||
}
|
||||
|
@ -28,99 +28,39 @@
|
||||
#include "timex.h"
|
||||
#include "mutex.h"
|
||||
|
||||
#include "sixlowpan/ip.h"
|
||||
#include "sixlowpan/types.h"
|
||||
|
||||
/* set maximum transmission unit */
|
||||
#define MTU 256
|
||||
/* IPv6 field values */
|
||||
#define IPV6_VER 0x60
|
||||
#define PROTO_NUM_ICMPV6 58
|
||||
#define PROTO_NUM_NONE 59
|
||||
#define ND_HOPLIMIT 0xFF
|
||||
#define SIXLOWPAN_IPV6_LL_ADDR_LEN 8
|
||||
#define IPV6_VER (0x60)
|
||||
/* size of global buffer */
|
||||
#define BUFFER_SIZE (LL_HDR_LEN + MTU)
|
||||
#define BUFFER_SIZE (LL_HDR_LEN + IPV6_MTU)
|
||||
|
||||
#define MULTIHOP_HOPLIMIT 64
|
||||
|
||||
#define IP_PKT_RECV_BUF_SIZE 64
|
||||
#define MULTIHOP_HOPLIMIT (64)
|
||||
|
||||
#define SIXLOWIP_MAX_REGISTERED (4)
|
||||
|
||||
#define DEBUGLINE printf("%s:%d\n",__FILE__,__LINE__)
|
||||
|
||||
/* extern variables */
|
||||
extern uint8_t ipv6_ext_hdr_len;
|
||||
extern uint8_t opt_hdr_len;
|
||||
extern uint8_t packet_dispatch;
|
||||
extern uint8_t iface_addr_list_count;
|
||||
extern mutex_t buf_mutex;
|
||||
|
||||
extern double start;
|
||||
|
||||
/* base header lengths */
|
||||
#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)
|
||||
#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)
|
||||
#define LL_HDR_LEN (0x4)
|
||||
#define ICMPV6_HDR_LEN (0x4)
|
||||
#define IPV6_HDR_LEN (0x28)
|
||||
|
||||
#define IFACE_ADDR_LIST_LEN 10 // maybe to much
|
||||
/* rfc 4862 section 2. address states */
|
||||
#define ADDR_STATE_TENTATIVE 0
|
||||
#define ADDR_STATE_PREFERRED 1
|
||||
#define ADDR_STATE_DEPRECATED 2
|
||||
/* addresses with this state are always permitted */
|
||||
#define ADDR_STATE_ANY 4
|
||||
/* how the address is configured */
|
||||
#define ADDR_CONFIGURED_AUTO 1
|
||||
#define ADDR_CONFIGURED_MANUAL 2
|
||||
/* address types */
|
||||
#define ADDR_TYPE_NONE 0
|
||||
#define ADDR_TYPE_UNICAST 1
|
||||
#define ADDR_TYPE_MULTICAST 2
|
||||
#define ADDR_TYPE_ANYCAST 3
|
||||
#define ADDR_TYPE_SOL_NODE_MCAST 4
|
||||
#define ADDR_TYPE_LOOPBACK 5
|
||||
#define ADDR_TYPE_LINK_LOCAL 6
|
||||
#define ADDR_TYPE_GLOBAL 7
|
||||
/* dispatch types */
|
||||
#define DISPATCH_TYPE_IPV6 0x41
|
||||
#define DISPATCH_TYPE_LOWPAN_HC1 0x42
|
||||
/* compression types */
|
||||
#define COMPRESSION_TYPE_NONE
|
||||
#define IFACE_ADDR_LIST_LEN (10) // maybe to much
|
||||
|
||||
/* buffer */
|
||||
extern uint8_t buffer[BUFFER_SIZE];
|
||||
|
||||
extern int sixlowip_reg[SIXLOWIP_MAX_REGISTERED];
|
||||
|
||||
/* ipv6 extension header length */
|
||||
|
||||
struct __attribute__((packed)) icmpv6_hdr_t {
|
||||
uint8_t type;
|
||||
uint8_t code;
|
||||
uint16_t checksum;
|
||||
};
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t version_trafficclass;
|
||||
uint8_t trafficclass_flowlabel;
|
||||
uint16_t flowlabel;
|
||||
uint16_t length;
|
||||
uint8_t nextheader;
|
||||
uint8_t hoplimit;
|
||||
ipv6_addr_t srcaddr;
|
||||
ipv6_addr_t destaddr;
|
||||
} ipv6_hdr_t;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t state;
|
||||
ipv6_addr_t addr;
|
||||
ipv6_addr_type_t type;
|
||||
ndp_addr_state_t state;
|
||||
timex_t val_ltime;
|
||||
timex_t pref_ltime;
|
||||
uint8_t type;
|
||||
ipv6_addr_t addr;
|
||||
} addr_list_t;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
@ -134,45 +74,18 @@ typedef struct __attribute__((packed)) {
|
||||
|
||||
extern iface_t iface;
|
||||
|
||||
void ipv6_send_buf(ipv6_hdr_t *buffer);
|
||||
/* function prototypes */
|
||||
struct icmpv6_hdr_t *get_icmpv6_buf(uint8_t ext_len);
|
||||
ipv6_hdr_t *get_ipv6_buf(void);
|
||||
void ipv6_send_bytes(ipv6_hdr_t *bytes);
|
||||
icmpv6_hdr_t *get_icmpv6_buf(uint8_t ext_len);
|
||||
uint8_t *get_payload_buf(uint8_t ext_len);
|
||||
uint8_t *get_payload_buf_send(uint8_t ext_len);
|
||||
|
||||
int icmpv6_demultiplex(const struct icmpv6_hdr_t *hdr);
|
||||
int icmpv6_demultiplex(const icmpv6_hdr_t *hdr);
|
||||
void ipv6_init_iface_as_router(void);
|
||||
uint8_t ipv6_is_router(void);
|
||||
void ipv6_set_ll_prefix(ipv6_addr_t *ipaddr);
|
||||
void ipv6_set_all_rtrs_mcast_addr(ipv6_addr_t *ipaddr);
|
||||
void ipv6_set_all_nds_mcast_addr(ipv6_addr_t *ipaddr);
|
||||
void ipv6_set_loaddr(ipv6_addr_t *ipaddr);
|
||||
void ipv6_set_sol_node_mcast_addr(ipv6_addr_t *addr_in, ipv6_addr_t *addr_out);
|
||||
void sixlowpan_bootstrapping(void);
|
||||
void sixlowpan_send(ipv6_addr_t *addr, uint8_t *payload, uint16_t p_len, uint8_t next_header);
|
||||
void ipv6_print_addr(ipv6_addr_t *ipaddr);
|
||||
void ipv6_process(void);
|
||||
void ipv6_get_saddr(ipv6_addr_t *src, ipv6_addr_t *dst);
|
||||
uint8_t ipv6_get_addr_match(ipv6_addr_t *src, ipv6_addr_t *dst);
|
||||
uint8_t ipv6_prefix_mcast_match(ipv6_addr_t *addr);
|
||||
uint8_t ipv6_prefix_ll_match(ipv6_addr_t *addr);
|
||||
void ipv6_iface_add_addr(ipv6_addr_t *addr, uint8_t state, uint32_t val_ltime,
|
||||
uint32_t pref_ltime, uint8_t type);
|
||||
addr_list_t *ipv6_iface_addr_prefix_eq(ipv6_addr_t *addr);
|
||||
addr_list_t *ipv6_iface_addr_match(ipv6_addr_t *addr);
|
||||
void ipv6_iface_print_addrs(void);
|
||||
void ipv6_init_addr_prefix(ipv6_addr_t *inout, ipv6_addr_t *prefix);
|
||||
void ipv6_init_address(ipv6_addr_t *addr, uint16_t addr0, uint16_t addr1,
|
||||
uint16_t addr2, uint16_t addr3, uint16_t addr4,
|
||||
uint16_t addr5, uint16_t addr6, uint16_t addr7);
|
||||
addr_list_t *ipv6_iface_addr_match(const ipv6_addr_t *addr);
|
||||
uint32_t get_remaining_time(timex_t *t);
|
||||
void set_remaining_time(timex_t *t, uint32_t time);
|
||||
void ipv6_set_prefix(ipv6_addr_t *inout, const ipv6_addr_t *prefix);
|
||||
uint8_t ipv6_addr_unspec_match(ipv6_addr_t *addr);
|
||||
uint8_t ipv6_addr_sol_node_mcast_match(ipv6_addr_t *addr);
|
||||
uint8_t ipv6_next_hdr_unrec(uint8_t next_hdr);
|
||||
void set_tcp_packet_handler_pid(int pid);
|
||||
void set_udp_packet_handler_pid(int pid);
|
||||
void set_rpl_process_pid(int pid);
|
||||
|
||||
#endif /* _SIXLOWPAN_IP_H*/
|
||||
|
@ -48,9 +48,12 @@
|
||||
#define CON_STACKSIZE (KERNEL_CONF_STACKSIZE_IDLE)
|
||||
#define LOWPAN_TRANSFER_BUF_STACKSIZE (KERNEL_CONF_STACKSIZE_IDLE)
|
||||
|
||||
#define SIXLOWPAN_MAX_REGISTERED (4)
|
||||
#define SIXLOWPAN_MAX_REGISTERED (4)
|
||||
|
||||
#define LOWPAN_REAS_BUF_TIMEOUT (15 * 1000 * 1000) /* TODO: Set back to 3 * 1000 * (1000) */
|
||||
#define LOWPAN_REAS_BUF_TIMEOUT (15 * 1000 * 1000)
|
||||
/* TODO: Set back to 3 * 1000 * (1000) */
|
||||
|
||||
#define IPV6_LL_ADDR_LEN (8)
|
||||
|
||||
typedef struct lowpan_interval_list_t {
|
||||
uint8_t start;
|
||||
@ -79,7 +82,7 @@ typedef struct lowpan_reas_buf_t {
|
||||
struct lowpan_reas_buf_t *next;
|
||||
} lowpan_reas_buf_t;
|
||||
|
||||
uint8_t packet_dispatch;
|
||||
extern mutex_t lowpan_context_mutex;
|
||||
uint16_t tag;
|
||||
uint8_t header_size = 0;
|
||||
uint8_t max_frame = 0;
|
||||
@ -110,7 +113,6 @@ unsigned int transfer_pid = 0;
|
||||
iface_t iface;
|
||||
ipv6_addr_t lladdr;
|
||||
ieee_802154_long_t laddr;
|
||||
mutex_t buf_mutex;
|
||||
mutex_t lowpan_context_mutex;
|
||||
|
||||
/* registered upper layer threads */
|
||||
@ -141,7 +143,7 @@ lowpan_context_t *lowpan_context_lookup(ipv6_addr_t *addr);
|
||||
void lowpan_ipv6_set_dispatch(uint8_t *data);
|
||||
|
||||
/* deliver packet to mac*/
|
||||
void sixlowpan_lowpan_sendto(const ieee_802154_long_t *dest,
|
||||
void sixlowpan_lowpan_sendto(const ieee_802154_long_t *dest,
|
||||
uint8_t *data, uint16_t data_len)
|
||||
{
|
||||
uint8_t mcast = 0;
|
||||
@ -151,7 +153,7 @@ void sixlowpan_lowpan_sendto(const ieee_802154_long_t *dest,
|
||||
|
||||
memcpy(&laddr.uint8[0], &dest->uint8[0], 8);
|
||||
|
||||
if (ipv6_prefix_mcast_match(&ipv6_buf->destaddr)) {
|
||||
if (ipv6_addr_is_multicast(&ipv6_buf->destaddr)) {
|
||||
/* send broadcast */
|
||||
mcast = 1;
|
||||
}
|
||||
@ -314,7 +316,7 @@ void lowpan_transfer(void)
|
||||
mutex_unlock(&fifo_mutex);
|
||||
|
||||
if ((current_buf->packet)[0] == SIXLOWPAN_IPV6_DISPATCH) {
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = ipv6_get_buf();
|
||||
memcpy(ipv6_buf, (current_buf->packet) + 1, current_buf->packet_size - 1);
|
||||
m_send.content.ptr = (char *)ipv6_buf;
|
||||
packet_length = current_buf->packet_size - 1;
|
||||
@ -326,7 +328,7 @@ void lowpan_transfer(void)
|
||||
&(current_buf->s_laddr),
|
||||
&(current_buf->d_laddr));
|
||||
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = ipv6_get_buf();
|
||||
m_send.content.ptr = (char *) ipv6_buf;
|
||||
msg_send_receive(&m_send, &m_recv, ip_process_pid);
|
||||
}
|
||||
@ -392,8 +394,8 @@ lowpan_reas_buf_t *new_packet_buffer(uint16_t datagram_size,
|
||||
new_buf->packet = malloc(datagram_size);
|
||||
|
||||
if (new_buf->packet != NULL) {
|
||||
memcpy(&new_buf->s_laddr, s_laddr, SIXLOWPAN_IPV6_LL_ADDR_LEN);
|
||||
memcpy(&new_buf->d_laddr, d_laddr, SIXLOWPAN_IPV6_LL_ADDR_LEN);
|
||||
memcpy(&new_buf->s_laddr, s_laddr, IPV6_LL_ADDR_LEN);
|
||||
memcpy(&new_buf->d_laddr, d_laddr, IPV6_LL_ADDR_LEN);
|
||||
|
||||
new_buf->ident_no = datagram_tag;
|
||||
new_buf->packet_size = datagram_size;
|
||||
@ -897,7 +899,7 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra,
|
||||
}
|
||||
|
||||
/* SAC: Source Address Compression */
|
||||
if (ipv6_addr_unspec_match(&(ipv6_buf->srcaddr))) {
|
||||
if (ipv6_addr_is_unspecified(&(ipv6_buf->srcaddr))) {
|
||||
/* SAC = 1 and SAM = 00 */
|
||||
lowpan_iphc[1] |= SIXLOWPAN_IPHC2_SAC;
|
||||
}
|
||||
@ -932,7 +934,7 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra,
|
||||
lowpan_iphc[1] |= 0x10;
|
||||
}
|
||||
}
|
||||
else if (ipv6_prefix_ll_match(&ipv6_buf->srcaddr)) {
|
||||
else if (ipv6_addr_is_link_local(&ipv6_buf->srcaddr)) {
|
||||
/* 0: Source address compression uses stateless compression.*/
|
||||
if (memcmp(&(ipv6_buf->srcaddr.uint8[8]), &(iface.laddr.uint8[0]), 8) == 0) {
|
||||
/* 0 bits. The address is derived using context information
|
||||
@ -966,7 +968,7 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra,
|
||||
}
|
||||
|
||||
/* M: Multicast Compression */
|
||||
if (ipv6_prefix_mcast_match(&ipv6_buf->destaddr)) {
|
||||
if (ipv6_addr_is_multicast(&ipv6_buf->destaddr)) {
|
||||
/* 1: Destination address is a multicast address. */
|
||||
lowpan_iphc[1] |= SIXLOWPAN_IPHC2_M;
|
||||
|
||||
@ -1049,7 +1051,7 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra,
|
||||
lowpan_iphc[1] |= 0x01;
|
||||
}
|
||||
}
|
||||
else if (ipv6_prefix_ll_match(&ipv6_buf->destaddr)) {
|
||||
else if (ipv6_addr_is_link_local(&ipv6_buf->destaddr)) {
|
||||
if (memcmp(&(ipv6_buf->destaddr.uint8[8]), &(dest->uint8[0]), 8) == 0) {
|
||||
/* 0 bits. The address is derived using context information
|
||||
* and possibly the link-layer addresses.*/
|
||||
@ -1087,7 +1089,7 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra,
|
||||
comp_buf[1] = lowpan_iphc[1];
|
||||
|
||||
/*uint8_t *ptr;
|
||||
if (ipv6_buf->nextheader == IPPROTO_TCP)
|
||||
if (ipv6_buf->nextheader == IPV6_PROTO_NUM_TCP)
|
||||
{
|
||||
ptr = get_payload_buf_send(ipv6_ext_hdr_len);
|
||||
}
|
||||
@ -1116,7 +1118,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
|
||||
uint8_t m_prefix[2] = {0xff, 0x02};
|
||||
lowpan_context_t *con = NULL;
|
||||
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = ipv6_get_buf();
|
||||
|
||||
lowpan_iphc[0] = ipv6_hdr_fields[0];
|
||||
lowpan_iphc[1] = ipv6_hdr_fields[1];
|
||||
@ -1601,8 +1603,8 @@ void lowpan_context_auto_remove(void)
|
||||
|
||||
void init_reas_bufs(lowpan_reas_buf_t *buf)
|
||||
{
|
||||
memset(&buf->s_laddr, 0, SIXLOWPAN_IPV6_LL_ADDR_LEN);
|
||||
memset(&buf->d_laddr, 0, SIXLOWPAN_IPV6_LL_ADDR_LEN);
|
||||
memset(&buf->s_laddr, 0, IPV6_LL_ADDR_LEN);
|
||||
memset(&buf->d_laddr, 0, IPV6_LL_ADDR_LEN);
|
||||
buf->ident_no = 0;
|
||||
buf->timestamp = 0;
|
||||
buf->packet_size = 0;
|
||||
@ -1626,8 +1628,6 @@ void sixlowpan_lowpan_init(transceiver_type_t trans, uint8_t r_addr,
|
||||
sixlowpan_mac_set_radio_address(r_addr);
|
||||
sixlowpan_mac_init_802154_short_addr(&(iface.saddr));
|
||||
sixlowpan_mac_init_802154_long_addr(&(iface.laddr));
|
||||
/* init global buffer mutex */
|
||||
mutex_init(&buf_mutex);
|
||||
|
||||
/* init lowpan context mutex */
|
||||
mutex_init(&lowpan_context_mutex);
|
||||
@ -1638,20 +1638,20 @@ void sixlowpan_lowpan_init(transceiver_type_t trans, uint8_t r_addr,
|
||||
local_address = r_addr;
|
||||
|
||||
/* init link-local address */
|
||||
ipv6_set_ll_prefix(&lladdr);
|
||||
ipv6_addr_set_link_local_prefix(&lladdr);
|
||||
|
||||
memcpy(&(lladdr.uint8[8]), &(iface.laddr.uint8[0]), 8);
|
||||
ipv6_iface_add_addr(&lladdr, ADDR_STATE_PREFERRED, 0, 0,
|
||||
ADDR_TYPE_LINK_LOCAL);
|
||||
ipv6_set_loaddr(&tmp);
|
||||
ipv6_iface_add_addr(&tmp, ADDR_STATE_PREFERRED, 0, 0,
|
||||
ADDR_TYPE_LOOPBACK);
|
||||
ipv6_set_all_nds_mcast_addr(&tmp);
|
||||
ipv6_iface_add_addr(&tmp, ADDR_STATE_PREFERRED, 0, 0,
|
||||
ADDR_TYPE_LOOPBACK);
|
||||
ipv6_iface_add_addr(&lladdr, IPV6_ADDR_TYPE_LINK_LOCAL,
|
||||
NDP_ADDR_STATE_PREFERRED, 0, 0);
|
||||
ipv6_addr_set_loopback_addr(&tmp);
|
||||
ipv6_iface_add_addr(&tmp, IPV6_ADDR_TYPE_LOOPBACK,
|
||||
NDP_ADDR_STATE_PREFERRED, 0, 0);
|
||||
ipv6_addr_set_all_nodes_addr(&tmp);
|
||||
ipv6_iface_add_addr(&tmp, IPV6_ADDR_TYPE_LOOPBACK,
|
||||
NDP_ADDR_STATE_PREFERRED, 0, 0);
|
||||
|
||||
ipv6_iface_add_addr(&lladdr, ADDR_STATE_PREFERRED, 0, 0,
|
||||
ADDR_CONFIGURED_AUTO);
|
||||
ipv6_iface_add_addr(&lladdr, IPV6_ADDR_TYPE_LINK_LOCAL,
|
||||
NDP_ADDR_STATE_PREFERRED, 0, 0);
|
||||
|
||||
if (as_border) {
|
||||
ip_process_pid = thread_create(ip_process_buf, IP_PROCESS_STACKSIZE,
|
||||
@ -1681,15 +1681,22 @@ void sixlowpan_lowpan_init(transceiver_type_t trans, uint8_t r_addr,
|
||||
|
||||
}
|
||||
|
||||
void sixlowpan_lowpan_adhoc_init(transceiver_type_t trans,
|
||||
void sixlowpan_lowpan_adhoc_init(transceiver_type_t trans,
|
||||
const ipv6_addr_t *prefix,
|
||||
uint8_t r_addr)
|
||||
{
|
||||
/* init network prefix */
|
||||
ipv6_addr_t save_prefix;
|
||||
ipv6_set_prefix(&save_prefix, prefix);
|
||||
plist_add(&save_prefix, 64, OPT_PI_VLIFETIME_INFINITE, 0, 1,
|
||||
ipv6_addr_init_prefix(&save_prefix, prefix, 64);
|
||||
plist_add(&save_prefix, 64, OPT_PI_VLIFETIME_INFINITE, 0, 1,
|
||||
OPT_PI_FLAG_A);
|
||||
ipv6_init_iface_as_router();
|
||||
sixlowpan_lowpan_init(trans, r_addr, 0);
|
||||
}
|
||||
|
||||
void sixlowpan_lowpan_bootstrapping(void)
|
||||
{
|
||||
|
||||
init_rtr_sol(OPT_SLLAO);
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,9 @@
|
||||
#ifndef _SIXLOWPAN_LOWPAN_H
|
||||
#define _SIXLOWPAN_LOWPAN_H
|
||||
|
||||
#include "mutex.h"
|
||||
#include "vtimer.h"
|
||||
|
||||
#include "sixlowpan/lowpan.h"
|
||||
|
||||
#define LOWPAN_CONTEXT_MAX (16)
|
||||
|
@ -184,8 +184,8 @@ void set_ieee802154_frame_values(ieee802154_frame_t *frame)
|
||||
}
|
||||
|
||||
void sixlowpan_mac_send_ieee802154_frame(const ieee_802154_long_t *addr,
|
||||
const uint8_t *payload,
|
||||
uint8_t length, uint8_t mcast)
|
||||
const uint8_t *payload,
|
||||
uint8_t length, uint8_t mcast)
|
||||
{
|
||||
uint16_t daddr;
|
||||
/* TODO: check if dedicated response struct is necessary */
|
||||
@ -217,9 +217,6 @@ void sixlowpan_mac_send_ieee802154_frame(const ieee_802154_long_t *addr,
|
||||
memcpy(&buf[hdrlen], frame.payload, frame.payload_len);
|
||||
DEBUG("IEEE802.15.4 frame - FCF: %02X %02X DPID: %02X SPID: %02X DSN: %02X\n", buf[0], buf[1], frame->dest_pan_id, frame->src_pan_id, frame->seq_nr);
|
||||
|
||||
/* mutex unlock */
|
||||
mutex_unlock(&buf_mutex);
|
||||
|
||||
p.length = hdrlen + frame.payload_len;
|
||||
|
||||
if (mcast == 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user