diff --git a/sys/net/include/sixlowpan/ip.h b/sys/net/include/sixlowpan/ip.h index 6f231a0c93..9b84c401bb 100644 --- a/sys/net/include/sixlowpan/ip.h +++ b/sys/net/include/sixlowpan/ip.h @@ -92,7 +92,7 @@ ipv6_hdr_t *ipv6_get_buf(void); * is going to try to find a route */ int ipv6_sendto(const ipv6_addr_t *dest, uint8_t next_header, - const uint8_t *payload, uint16_t payload_length); + const uint8_t *payload, uint16_t payload_length); /** * @brief Determines if node is a router. @@ -375,7 +375,7 @@ void ipv6_iface_print_addrs(void); * * @param next_hop function that returns the next hop to reach dest */ -void ipv6_iface_set_routing_provider(ipv6_addr_t *(*next_hop)(ipv6_addr_t* dest)); +void ipv6_iface_set_routing_provider(ipv6_addr_t *(*next_hop)(ipv6_addr_t *dest)); /** * @brief Calculates the IPv6 upper-layer checksum. diff --git a/sys/net/network_layer/sixlowpan/icmp.c b/sys/net/network_layer/sixlowpan/icmp.c index 0125430ea2..ffb2ed425a 100644 --- a/sys/net/network_layer/sixlowpan/icmp.c +++ b/sys/net/network_layer/sixlowpan/icmp.c @@ -1570,7 +1570,7 @@ void def_rtr_lst_rem(ndp_default_router_list_t *entry) /* prefix list functions */ int plist_add(ipv6_addr_t *addr, uint8_t size, uint32_t val_ltime, - uint32_t pref_ltime, uint8_t adv_opt, uint8_t l_a_reserved1) + uint32_t pref_ltime, uint8_t adv_opt, uint8_t l_a_reserved1) { if (prefix_count == OPT_PI_LIST_LEN) { return SIXLOWERROR_ARRAYFULL; diff --git a/sys/net/network_layer/sixlowpan/icmp.h b/sys/net/network_layer/sixlowpan/icmp.h index 297b18e060..6cb502d3fe 100644 --- a/sys/net/network_layer/sixlowpan/icmp.h +++ b/sys/net/network_layer/sixlowpan/icmp.h @@ -54,7 +54,7 @@ void recv_nbr_sol(void); void nbr_cache_auto_rem(void); int plist_add(ipv6_addr_t *addr, uint8_t size, uint32_t val_ltime, - uint32_t pref_ltime, uint8_t adv_opt, uint8_t l_a_reserved1); + uint32_t pref_ltime, uint8_t adv_opt, uint8_t l_a_reserved1); ndp_a6br_cache_t *abr_add_context(uint16_t version, ipv6_addr_t *abr_addr, uint8_t cid); diff --git a/sys/net/network_layer/sixlowpan/ip.c b/sys/net/network_layer/sixlowpan/ip.c index 65553676fb..e6071d341e 100644 --- a/sys/net/network_layer/sixlowpan/ip.c +++ b/sys/net/network_layer/sixlowpan/ip.c @@ -54,7 +54,7 @@ uint8_t iface_addr_list_count = 0; int udp_packet_handler_pid = 0; int tcp_packet_handler_pid = 0; int rpl_process_pid = 0; -ipv6_addr_t *(*ip_get_next_hop)(ipv6_addr_t*) = 0; +ipv6_addr_t *(*ip_get_next_hop)(ipv6_addr_t *) = 0; /* registered upper layer threads */ int sixlowip_reg[SIXLOWIP_MAX_REGISTERED]; @@ -100,7 +100,7 @@ uint8_t *get_payload_buf(uint8_t ext_len) } int ipv6_sendto(const ipv6_addr_t *dest, uint8_t next_header, - const uint8_t *payload, uint16_t payload_length) + const uint8_t *payload, uint16_t payload_length) { uint8_t *p_ptr; uint16_t packet_length; @@ -296,7 +296,8 @@ void ipv6_process(void) (ipv6_buf->destaddr.uint8[15] != myaddr.uint8[15])) { packet_length = IPV6_HDR_LEN + ipv6_buf->length; - ipv6_addr_t* dest; + ipv6_addr_t *dest; + if (ip_get_next_hop == NULL) { dest = &ipv6_buf->destaddr; } @@ -320,10 +321,12 @@ void ipv6_process(void) switch (*nextheader) { case (IPV6_PROTO_NUM_ICMPV6): { icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len); + /* checksum test*/ - if (ipv6_csum(ipv6_buf, (uint8_t*) icmp_buf, ipv6_buf->length, IPV6_PROTO_NUM_ICMPV6) != 0xffff) { + if (ipv6_csum(ipv6_buf, (uint8_t *) icmp_buf, ipv6_buf->length, IPV6_PROTO_NUM_ICMPV6) != 0xffff) { printf("ERROR: wrong checksum\n"); } + icmpv6_demultiplex(icmp_buf); break; } @@ -695,9 +698,11 @@ void ipv6_register_next_header_handler(uint8_t next_header, int pid) 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; @@ -705,7 +710,8 @@ void ipv6_register_next_header_handler(uint8_t next_header, int pid) } /* register routing function */ -void ipv6_iface_set_routing_provider(ipv6_addr_t *(*next_hop)(ipv6_addr_t* dest)) { +void ipv6_iface_set_routing_provider(ipv6_addr_t *(*next_hop)(ipv6_addr_t *dest)) +{ ip_get_next_hop = next_hop; } @@ -718,9 +724,9 @@ uint16_t ipv6_csum(ipv6_hdr_t *ipv6_header, uint8_t *buf, uint16_t len, uint8_t { uint16_t sum = 0; DEBUG("Calculate checksum over src: %s, dst: %s, len: %04X, buf: %p, proto: %u\n", - ipv6_addr_to_str(addr_str, &ipv6_header->srcaddr), - ipv6_addr_to_str(addr_str, &ipv6_header->destaddr), - len, buf, proto); + ipv6_addr_to_str(addr_str, &ipv6_header->srcaddr), + ipv6_addr_to_str(addr_str, &ipv6_header->destaddr), + len, buf, proto); sum = len + proto; sum = csum(sum, (uint8_t *)&ipv6_header->srcaddr, 2 * sizeof(ipv6_addr_t)); sum = csum(sum, buf, len); diff --git a/sys/net/network_layer/sixlowpan/lowpan.c b/sys/net/network_layer/sixlowpan/lowpan.c index 08cd658440..1af050f709 100644 --- a/sys/net/network_layer/sixlowpan/lowpan.c +++ b/sys/net/network_layer/sixlowpan/lowpan.c @@ -180,8 +180,9 @@ void sixlowpan_lowpan_sendto(const ieee_802154_long_t *dest, } /* check if packet needs to be fragmented */ - DEBUG("sixlowpan_lowpan_sendto(%s, data, %" PRIu16 "): send_packet_length: %" PRIu16 ", header_size: %" PRIu16 "\n", - sixlowpan_mac_802154_long_addr_to_str(addr_str, dest), data_len, send_packet_length, header_size); + DEBUG("sixlowpan_lowpan_sendto(%s, data, %"PRIu16"): send_packet_length: %"PRIu16", header_size: %"PRIu16"\n", + sixlowpan_mac_802154_long_addr_to_str(addr_str, dest), data_len, send_packet_length, header_size); + if (send_packet_length + header_size > PAYLOAD_SIZE - IEEE_802154_MAX_HDR_LEN) { uint8_t fragbuf[send_packet_length + header_size]; uint8_t remaining; @@ -642,7 +643,7 @@ void check_timeout(void) while (temp_buf != NULL) { if ((timex_uint64(now) - timex_uint64(temp_buf->timestamp)) >= LOWPAN_REAS_BUF_TIMEOUT) { printf("TIMEOUT!cur_time: %" PRIu64 ", temp_buf: %" PRIu64 "\n", timex_uint64(now), - timex_uint64(temp_buf->timestamp)); + timex_uint64(temp_buf->timestamp)); temp_buf = collect_garbage(temp_buf); } else { @@ -786,6 +787,7 @@ void lowpan_read(uint8_t *data, uint8_t length, ieee_802154_long_t *s_laddr, else { lowpan_reas_buf_t *current_buf = get_packet_frag_buf(length, 0, s_laddr, d_laddr); + if (current_buf && current_buf->packet) { /* Copy packet bytes into corresponding packet space area */ memcpy(current_buf->packet, data, length); @@ -795,6 +797,7 @@ void lowpan_read(uint8_t *data, uint8_t length, ieee_802154_long_t *s_laddr, else { DEBUG("ERROR: no memory left in packet buffer!\n"); } + if (thread_getstatus(transfer_pid) == STATUS_SLEEPING) { thread_wakeup(transfer_pid); } @@ -1676,7 +1679,7 @@ void lowpan_init(transceiver_type_t trans, uint8_t r_addr, ipv6_addr_set_by_eui64(&tmp, prefix); DEBUG("%s, %d: set unique address to %s, according to prefix %s\n", __FILE__, __LINE__, ipv6_addr_to_str(addr_str, &tmp), ipv6_addr_to_str(addr_str, prefix)); ipv6_iface_add_addr(&tmp, IPV6_ADDR_TYPE_GLOBAL, - NDP_ADDR_STATE_PREFERRED, 0, 0); + NDP_ADDR_STATE_PREFERRED, 0, 0); } DEBUG("%s, %d: set link local prefix to %s\n", __FILE__, __LINE__, ipv6_addr_to_str(addr_str, &lladdr)); diff --git a/sys/net/network_layer/sixlowpan/mac.c b/sys/net/network_layer/sixlowpan/mac.c index dd7969b1ae..34c71cba6b 100644 --- a/sys/net/network_layer/sixlowpan/mac.c +++ b/sys/net/network_layer/sixlowpan/mac.c @@ -138,12 +138,13 @@ void sixlowpan_mac_init_802154_long_addr(ieee_802154_long_t *laddr) laddr->uint8[7] = sixlowpan_mac_get_radio_address(); } -char *sixlowpan_mac_802154_long_addr_to_str(char *addr_str, const ieee_802154_long_t *laddr) { - sprintf(addr_str, - "%02x:%02x:%02x:%02x", - laddr->uint16[0], laddr->uint16[1], - laddr->uint16[2], laddr->uint16[3]); - return addr_str; +char *sixlowpan_mac_802154_long_addr_to_str(char *addr_str, const ieee_802154_long_t *laddr) +{ + sprintf(addr_str, + "%02x:%02x:%02x:%02x", + laddr->uint16[0], laddr->uint16[1], + laddr->uint16[2], laddr->uint16[3]); + return addr_str; } void recv_ieee802154_frame(void) @@ -238,9 +239,9 @@ void sixlowpan_mac_send_ieee802154_frame(const ieee_802154_long_t *addr, memcpy(&buf[hdrlen], frame.payload, frame.payload_len); /* set FCS */ /* RSSI = 0 */ - buf[frame.payload_len+hdrlen] = 0; + buf[frame.payload_len + hdrlen] = 0; /* FCS Valid = 1 / LQI Correlation Value = 0 */ - buf[frame.payload_len+hdrlen+1] = 0x80; + buf[frame.payload_len + hdrlen + 1] = 0x80; 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); p.length = hdrlen + frame.payload_len + IEEE_802154_FCS_LEN; diff --git a/sys/net/routing/rpl/etx_beaconing.c b/sys/net/routing/rpl/etx_beaconing.c index 991413873a..cc16ddfb5d 100644 --- a/sys/net/routing/rpl/etx_beaconing.c +++ b/sys/net/routing/rpl/etx_beaconing.c @@ -195,7 +195,7 @@ void etx_beacon(void) packet->length = p_length; sixlowpan_mac_send_ieee802154_frame(&empty_addr, &etx_send_buf[0], - ETX_DATA_MAXLEN + ETX_PKT_HDR_LEN, 1); + ETX_DATA_MAXLEN + ETX_PKT_HDR_LEN, 1); DEBUG("sent beacon!\n"); etx_set_packets_received(); cur_round++; @@ -457,7 +457,7 @@ void etx_update(etx_neighbor_t *candidate) /* * Calculate the current ETX value for my link to this candidate. */ - if (d_f *d_r != 0) { + if (d_f * d_r != 0) { candidate->cur_etx = 1 / (d_f * d_r); } else { diff --git a/sys/net/routing/rpl/rpl.c b/sys/net/routing/rpl/rpl.c index 24b42d5fb6..ae7bc13131 100644 --- a/sys/net/routing/rpl/rpl.c +++ b/sys/net/routing/rpl/rpl.c @@ -88,23 +88,28 @@ static uint8_t *get_rpl_send_payload_buf(uint8_t ext_len) return &(rpl_send_buffer[IPV6_HDR_LEN + ext_len]); } -static icmpv6_hdr_t *get_rpl_send_icmpv6_buf(uint8_t ext_len) { +static icmpv6_hdr_t *get_rpl_send_icmpv6_buf(uint8_t ext_len) +{ return ((icmpv6_hdr_t *) &(rpl_send_buffer[IPV6_HDR_LEN + ext_len])); } -static struct rpl_dio_t *get_rpl_send_dio_buf(void) { +static struct rpl_dio_t *get_rpl_send_dio_buf(void) +{ return ((struct rpl_dio_t *) &(rpl_send_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN])); } -static struct rpl_dao_t *get_rpl_send_dao_buf(void) { +static struct rpl_dao_t *get_rpl_send_dao_buf(void) +{ return ((struct rpl_dao_t *) &(rpl_send_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN])); } -static struct rpl_dao_ack_t *get_rpl_send_dao_ack_buf(void) { +static struct rpl_dao_ack_t *get_rpl_send_dao_ack_buf(void) +{ return ((struct rpl_dao_ack_t *) &(rpl_send_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN])); } -static struct rpl_dis_t *get_rpl_send_dis_buf(void) { +static struct rpl_dis_t *get_rpl_send_dis_buf(void) +{ return ((struct rpl_dis_t *) &(rpl_send_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN])); } @@ -129,20 +134,24 @@ static ipv6_hdr_t *get_rpl_ipv6_buf(void) return ((ipv6_hdr_t *) &(rpl_buffer[0])); } -static struct rpl_dio_t *get_rpl_dio_buf(void) { +static struct rpl_dio_t *get_rpl_dio_buf(void) +{ return ((struct rpl_dio_t *) &(rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN])); } -static struct rpl_dao_t *get_rpl_dao_buf(void) { +static struct rpl_dao_t *get_rpl_dao_buf(void) +{ return ((struct rpl_dao_t *) &(rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN])); } -static struct rpl_dao_ack_t *get_rpl_dao_ack_buf(void) { +static struct rpl_dao_ack_t *get_rpl_dao_ack_buf(void) +{ return ((struct rpl_dao_ack_t *) &(buffer[(LL_HDR_LEN + IPV6_HDR_LEN + ICMPV6_HDR_LEN)])); } -static struct rpl_dis_t *get_rpl_dis_buf(void) { - return ((struct rpl_dis_t *) & (rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN])); +static struct rpl_dis_t *get_rpl_dis_buf(void) +{ + return ((struct rpl_dis_t *) &(rpl_buffer[IPV6_HDR_LEN + ICMPV6_HDR_LEN])); } static rpl_opt_t *get_rpl_opt_buf(uint8_t rpl_msg_len) @@ -345,6 +354,7 @@ void send_DIS(ipv6_addr_t *destination) void send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, uint8_t start_index) { DEBUG("Send DAO\n"); + if (i_am_root) { return; } @@ -364,6 +374,7 @@ void send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, mutex_unlock(&rpl_send_mutex); return; } + destination = &my_dodag->my_preferred_parent->addr; } @@ -664,6 +675,7 @@ void recv_rpl_dio(void) else { DEBUG("Cannot access DODAG because of DIO with infinite rank\n"); } + return; } @@ -694,7 +706,7 @@ void recv_rpl_dio(void) reset_trickletimer(); } - /* We are root, all done! */ + /* We are root, all done!*/ if (my_dodag->my_rank == ROOT_RANK) { if (rpl_dio_buf->rank != INFINITE_RANK) { trickle_increment_counter(); @@ -924,7 +936,7 @@ void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_ icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len); icmp_send_buf->checksum = 0; - icmp_send_buf->checksum = ~ipv6_csum(ipv6_send_buf, (uint8_t*) icmp_send_buf, ipv6_send_buf->length, IPV6_PROTO_NUM_ICMPV6); + icmp_send_buf->checksum = ~ipv6_csum(ipv6_send_buf, (uint8_t *) icmp_send_buf, ipv6_send_buf->length, IPV6_PROTO_NUM_ICMPV6); /* The packet was "assembled" in rpl.c. Therefore rpl_send_buf was used. * Therefore memcpy is not needed because the payload is at the diff --git a/sys/net/routing/rpl/rpl_dodag.c b/sys/net/routing/rpl/rpl_dodag.c index cad23b33ca..5c356f7d3c 100644 --- a/sys/net/routing/rpl/rpl_dodag.c +++ b/sys/net/routing/rpl/rpl_dodag.c @@ -222,6 +222,7 @@ void rpl_delete_worst_parent(void) void rpl_delete_all_parents(void) { rpl_dodag_t *my_dodag = rpl_get_my_dodag(); + if (my_dodag != NULL) { my_dodag->my_preferred_parent = NULL; } diff --git a/sys/net/routing/rpl/trickle.c b/sys/net/routing/rpl/trickle.c index be0b88d167..eb98dcc4af 100644 --- a/sys/net/routing/rpl/trickle.c +++ b/sys/net/routing/rpl/trickle.c @@ -166,11 +166,13 @@ void trickle_interval_over(void) timex_normalize(&I_time); vtimer_remove(&trickle_t_timer); + if (vtimer_set_wakeup(&trickle_t_timer, t_time, timer_over_pid) != 0) { puts("[ERROR] setting Wakeup"); } vtimer_remove(&trickle_I_timer); + if (vtimer_set_wakeup(&trickle_I_timer, I_time, interval_over_pid) != 0) { puts("[ERROR] setting Wakeup"); }