diff --git a/sys/net/rpl/etx_beaconing.c b/sys/net/rpl/etx_beaconing.c index 0462d58d99c311c26d7c9d52c4c60021b512fe59..f6e4d9bbd0d1a0bba2575627e27da861e8af39ae 100644 --- a/sys/net/rpl/etx_beaconing.c +++ b/sys/net/rpl/etx_beaconing.c @@ -19,7 +19,7 @@ #include "ieee802154/ieee802154_frame.h" //prototytpes -static uint8_t etx_count_packet_tx(etx_neighbor_t * candidate); +static uint8_t etx_count_packet_tx(etx_neighbor_t *candidate); static void etx_set_packets_received(void); static bool etx_equal_id(ipv6_addr_t *id1, ipv6_addr_t *id2); @@ -89,37 +89,42 @@ transceiver_command_t tcmd; msg_t mesg; //RPL-address -static ipv6_addr_t * own_address; +static ipv6_addr_t *own_address; -static etx_probe_t * etx_get_send_buf(void) { - return ((etx_probe_t *) &(etx_send_buf[0])); +static etx_probe_t *etx_get_send_buf(void) +{ + return ((etx_probe_t *) & (etx_send_buf[0])); } -static etx_probe_t * etx_get_rec_buf(void) { - return ((etx_probe_t *) &(etx_rec_buf[0])); +static etx_probe_t *etx_get_rec_buf(void) +{ + return ((etx_probe_t *) & (etx_rec_buf[0])); } -void show_candidates(void) { - etx_neighbor_t * candidate; +void show_candidates(void) +{ + etx_neighbor_t *candidate; etx_neighbor_t *end; for (candidate = &candidates[0], end = candidates - + ETX_MAX_CANDIDATE_NEIGHBORS; candidate < end; - candidate++) { + + ETX_MAX_CANDIDATE_NEIGHBORS; candidate < end; + candidate++) { if (candidate->used == 0) { break; } + printf("Candidates Addr:%d\n" - "\t cur_etx:%f\n" - "\t packets_rx:%d\n" - "\t packets_tx:%d\n" - "\t used:%d\n", candidate->addr.uint8[ETX_IPV6_LAST_BYTE], - candidate->cur_etx, candidate->packets_rx, - etx_count_packet_tx(candidate), - candidate->used); + "\t cur_etx:%f\n" + "\t packets_rx:%d\n" + "\t packets_tx:%d\n" + "\t used:%d\n", candidate->addr.uint8[ETX_IPV6_LAST_BYTE], + candidate->cur_etx, candidate->packets_rx, + etx_count_packet_tx(candidate), + candidate->used); } } -void etx_init_beaconing(ipv6_addr_t * address) { +void etx_init_beaconing(ipv6_addr_t *address) +{ mutex_init(&etx_mutex); own_address = address; //set code @@ -127,29 +132,30 @@ void etx_init_beaconing(ipv6_addr_t * address) { etx_send_buf[0] = ETX_PKT_OPTVAL; etx_beacon_pid = thread_create(etx_beacon_buf, ETX_BEACON_STACKSIZE, - PRIORITY_MAIN - 1, CREATE_STACKTEST, - etx_beacon, "etx_beacon"); + PRIORITY_MAIN - 1, CREATE_STACKTEST, + etx_beacon, "etx_beacon"); etx_radio_pid = thread_create(etx_radio_buf, ETX_RADIO_STACKSIZE, - PRIORITY_MAIN - 1, CREATE_STACKTEST, - etx_radio, "etx_radio"); + PRIORITY_MAIN - 1, CREATE_STACKTEST, + etx_radio, "etx_radio"); etx_clock_pid = thread_create(etx_clock_buf, ETX_CLOCK_STACKSIZE, - PRIORITY_MAIN - 1, CREATE_STACKTEST, - etx_clock, "etx_clock"); + PRIORITY_MAIN - 1, CREATE_STACKTEST, + etx_clock, "etx_clock"); //register at transceiver transceiver_register(TRANSCEIVER_CC1100, etx_radio_pid); puts("...[DONE]"); } -void etx_beacon(void) { +void etx_beacon(void) +{ /* * Sends a message every ETX_INTERVAL +/- a jitter-value (default is 10%) . * A correcting variable is needed to stay at a base interval of * ETX_INTERVAL between the wakeups. It takes the old jittervalue in account * and modifies the time to wait accordingly. */ - etx_probe_t * packet = etx_get_send_buf(); + etx_probe_t *packet = etx_get_send_buf(); uint8_t p_length = 0; /* @@ -165,47 +171,55 @@ void etx_beacon(void) { mutex_lock(&etx_mutex); //Build etx packet p_length = 0; + for (uint8_t i = 0; i < ETX_BEST_CANDIDATES; i++) { if (candidates[i].used != 0) { packet->data[i * ETX_TUPLE_SIZE] = - candidates[i].addr.uint8[ETX_IPV6_LAST_BYTE]; + candidates[i].addr.uint8[ETX_IPV6_LAST_BYTE]; packet->data[i * ETX_TUPLE_SIZE + ETX_PKT_REC_OFFSET] = - etx_count_packet_tx(&candidates[i]); + etx_count_packet_tx(&candidates[i]); p_length = p_length + ETX_PKT_HDR_LEN; } } + packet->length = p_length; 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++; + if (cur_round == ETX_WINDOW) { if (reached_window != 1) { //first round is through reached_window = 1; } + cur_round = 0; } - mutex_unlock(&etx_mutex); + + mutex_unlock(&etx_mutex, 0); } } -etx_neighbor_t * etx_find_candidate(ipv6_addr_t * address) { +etx_neighbor_t *etx_find_candidate(ipv6_addr_t *address) +{ /* * find the candidate with address address and returns it, or returns NULL * if no candidate having this address was found. */ for (uint8_t i = 0; i < ETX_MAX_CANDIDATE_NEIGHBORS; i++) { if (candidates[i].used - && (etx_equal_id(&candidates[i].addr, address))) { + && (etx_equal_id(&candidates[i].addr, address))) { return &candidates[i]; } } + return NULL ; } -void etx_clock(void) { +void etx_clock(void) +{ /* * Manages the etx_beacon thread to wake up every full second +- jitter */ @@ -217,7 +231,7 @@ void etx_clock(void) { * That is why they are multiplied by 1000 when used for hwtimer_wait. */ uint8_t jittercorrection = ETX_DEF_JIT_CORRECT; - uint8_t jitter = (uint8_t) (rand() % ETX_JITTER_MOD); + uint8_t jitter = (uint8_t)(rand() % ETX_JITTER_MOD); while (true) { thread_wakeup(etx_beacon_pid); @@ -227,32 +241,37 @@ void etx_clock(void) { * for now. */ vtimer_usleep( - ((ETX_INTERVAL - ETX_MAX_JITTER)*MS)+ jittercorrection*MS + jitter*MS - ETX_CLOCK_ADJUST); + ((ETX_INTERVAL - ETX_MAX_JITTER)*MS) + jittercorrection * MS + jitter * MS - ETX_CLOCK_ADJUST); //hwtimer_wait( // HWTIMER_TICKS(((ETX_INTERVAL - ETX_MAX_JITTER)*MS) + jittercorrection*MS + jitter*MS - ETX_CLOCK_ADJUST)); jittercorrection = (ETX_MAX_JITTER) - jitter; - jitter = (uint8_t) (rand() % ETX_JITTER_MOD); + jitter = (uint8_t)(rand() % ETX_JITTER_MOD); } } -double etx_get_metric(ipv6_addr_t * address) { - etx_neighbor_t * candidate = etx_find_candidate(address); - if (candidate != NULL ) { +double etx_get_metric(ipv6_addr_t *address) +{ + etx_neighbor_t *candidate = etx_find_candidate(address); + + if (candidate != NULL) { if (etx_count_packet_tx(candidate) > 0) { //this means the current etx_value is not outdated return candidate->cur_etx; - } else { + } + else { //The last time I received a packet is too long ago to give a //good estimate of the etx value return 0; } } + return 0; } -etx_neighbor_t * etx_add_candidate(ipv6_addr_t * address) { +etx_neighbor_t *etx_add_candidate(ipv6_addr_t *address) +{ DEBUG("add candidate\n"); /* * Pre-Condition: etx_add_candidate should only be called when the @@ -275,16 +294,17 @@ etx_neighbor_t * etx_add_candidate(ipv6_addr_t * address) { * Returns the pointer to the candidate if it was added, or a NULL-pointer * otherwise. */ - etx_neighbor_t * candidate; - etx_neighbor_t * end; + etx_neighbor_t *candidate; + etx_neighbor_t *end; for (candidate = &candidates[0], end = candidates - + ETX_MAX_CANDIDATE_NEIGHBORS; candidate < end; - candidate++) { + + ETX_MAX_CANDIDATE_NEIGHBORS; candidate < end; + candidate++) { if (candidate->used) { //skip continue; - } else { + } + else { //We still have a free place add the new candidate memset(candidate, 0, sizeof(*candidate)); candidate->addr = *address; @@ -294,27 +314,31 @@ etx_neighbor_t * etx_add_candidate(ipv6_addr_t * address) { return candidate; } } + return NULL ; } -void etx_handle_beacon(ipv6_addr_t * candidate_address) { +void etx_handle_beacon(ipv6_addr_t *candidate_address) +{ /* * Handle the ETX probe that has been received and update all infos. * If the candidate address is unknown, try to add it to my struct. */ DEBUG( - "ETX beacon package received with following values:\n" - "\tPackage Option:%x\n" - "\t Data Length:%u\n" - "\tSource Address:%d\n\n", etx_rec_buf[ETX_PKT_OPT], etx_rec_buf[ETX_PKT_LEN], - candidate_address->uint8[ETX_IPV6_LAST_BYTE]); - - etx_neighbor_t* candidate = etx_find_candidate(candidate_address); - if (candidate == NULL ) { + "ETX beacon package received with following values:\n" + "\tPackage Option:%x\n" + "\t Data Length:%u\n" + "\tSource Address:%d\n\n", etx_rec_buf[ETX_PKT_OPT], etx_rec_buf[ETX_PKT_LEN], + candidate_address->uint8[ETX_IPV6_LAST_BYTE]); + + etx_neighbor_t *candidate = etx_find_candidate(candidate_address); + + if (candidate == NULL) { //Candidate was not found in my list, I should add it candidate = etx_add_candidate(candidate_address); - if (candidate == NULL ) { + + if (candidate == NULL) { puts("[ERROR] Candidate could not get added"); puts("Increase the constant ETX_MAX_CANDIDATE_NEIHGBORS"); return; @@ -327,18 +351,18 @@ void etx_handle_beacon(ipv6_addr_t * candidate_address) { // If i find my address in this probe, update the packet_rx value for // this candidate. - etx_probe_t * rec_pkt = etx_get_rec_buf(); + etx_probe_t *rec_pkt = etx_get_rec_buf(); for (uint8_t i = 0; i < rec_pkt->length / ETX_TUPLE_SIZE; i++) { DEBUG("\tIPv6 short Addr:%u\n" - "\tPackets f. Addr:%u\n\n", rec_pkt->data[i * ETX_TUPLE_SIZE], - rec_pkt->data[i * ETX_TUPLE_SIZE + ETX_PKT_REC_OFFSET]); + "\tPackets f. Addr:%u\n\n", rec_pkt->data[i * ETX_TUPLE_SIZE], + rec_pkt->data[i * ETX_TUPLE_SIZE + ETX_PKT_REC_OFFSET]); if (rec_pkt->data[i * ETX_TUPLE_SIZE] - == own_address->uint8[ETX_IPV6_LAST_BYTE]) { + == own_address->uint8[ETX_IPV6_LAST_BYTE]) { candidate->packets_rx = rec_pkt->data[i * ETX_TUPLE_SIZE - + ETX_PKT_REC_OFFSET]; + + ETX_PKT_REC_OFFSET]; } } @@ -346,7 +370,8 @@ void etx_handle_beacon(ipv6_addr_t * candidate_address) { etx_update(candidate); } -void etx_radio(void) { +void etx_radio(void) +{ msg_t m; radio_packet_t *p; @@ -362,8 +387,9 @@ void etx_radio(void) { while (1) { msg_receive(&m); + if (m.type == PKT_PENDING) { - p = (radio_packet_t*) m.content.ptr; + p = (radio_packet_t *) m.content.ptr; read_802154_frame(p->data, &frame, p->length); @@ -378,7 +404,7 @@ void etx_radio(void) { //handle the beacon mutex_lock(&etx_mutex); etx_handle_beacon(&candidate_addr); - mutex_unlock(&etx_mutex); + mutex_unlock(&etx_mutex, 1); } p->processing--; @@ -392,7 +418,8 @@ void etx_radio(void) { } } -void etx_update(etx_neighbor_t * candidate) { +void etx_update(etx_neighbor_t *candidate) +{ DEBUG("update!\n"); /* * Update the current ETX value of a candidate @@ -400,7 +427,7 @@ void etx_update(etx_neighbor_t * candidate) { double d_f; double d_r; - if (reached_window != 1 || candidate == NULL ) { + if (reached_window != 1 || candidate == NULL) { //We will wait at least ETX_WINDOW beacons until we decide to //calculate an ETX value, so that we have a good estimate return; @@ -419,24 +446,26 @@ 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 { + } + else { candidate->cur_etx = 0; } DEBUG( - "Estimated ETX Metric is %f for candidate w/ addr %d\n" - "Estimated PDR_forward is %f\n" - "Estimated PDR_backwrd is %f\n" - "\n" - "Received Packets: %d\n" - "Sent Packets : %d\n\n", - candidate->cur_etx, candidate->addr.uint8[ETX_IPV6_LAST_BYTE], - d_f, d_r, candidate->packets_rx, etx_count_packet_tx(candidate)); + "Estimated ETX Metric is %f for candidate w/ addr %d\n" + "Estimated PDR_forward is %f\n" + "Estimated PDR_backwrd is %f\n" + "\n" + "Received Packets: %d\n" + "Sent Packets : %d\n\n", + candidate->cur_etx, candidate->addr.uint8[ETX_IPV6_LAST_BYTE], + d_f, d_r, candidate->packets_rx, etx_count_packet_tx(candidate)); } -static uint8_t etx_count_packet_tx(etx_neighbor_t * candidate) { +static uint8_t etx_count_packet_tx(etx_neighbor_t *candidate) +{ /* * Counts the number of packets that were received for this candidate * in the last ETX_WINDOW intervals. @@ -444,38 +473,46 @@ static uint8_t etx_count_packet_tx(etx_neighbor_t * candidate) { DEBUG("counting packets"); uint8_t pkt_count = 0; DEBUG("["); + for (uint8_t i = 0; i < ETX_WINDOW; i++) { if (i != cur_round) { pkt_count = pkt_count + candidate->packets_tx[i]; - DEBUG("%d",candidate->packets_tx[i]); + DEBUG("%d", candidate->packets_tx[i]); + if (i < ETX_WINDOW - 1) { DEBUG(","); } - } else { + } + else { //Check if I received something for the current round if (candidate->tx_cur_round == 0) { //Didn't receive a packet, zero the field and don't add candidate->packets_tx[i] = 0; - DEBUG("%d!",candidate->packets_tx[i]); + DEBUG("%d!", candidate->packets_tx[i]); + if (i < ETX_WINDOW - 1) { DEBUG(","); } - } else { + } + else { //Add 1 and set field pkt_count = pkt_count + 1; candidate->packets_tx[i] = 1; - DEBUG("%d!",candidate->packets_tx[i]); + DEBUG("%d!", candidate->packets_tx[i]); + if (i < ETX_WINDOW - 1) { DEBUG(","); } } } } + DEBUG("]\n"); return pkt_count; } -static void etx_set_packets_received(void) { +static void etx_set_packets_received(void) +{ /* * Set for all candidates if they received a packet this round or not */ @@ -489,12 +526,14 @@ static void etx_set_packets_received(void) { } } -bool etx_equal_id(ipv6_addr_t *id1, ipv6_addr_t *id2){ - for(uint8_t i=0;i<4;i++){ - if(id1->uint32[i] != id2->uint32[i]){ +bool etx_equal_id(ipv6_addr_t *id1, ipv6_addr_t *id2) +{ + for (uint8_t i = 0; i < 4; i++) { + if (id1->uint32[i] != id2->uint32[i]) { return false; } } + return true; } diff --git a/sys/net/rpl/etx_beaconing.h b/sys/net/rpl/etx_beaconing.h index 063190a5a606719a92efd58af3328bd50ce1a206..de353bb9d32e9a99acc9e64f3b928cc64f20b115 100644 --- a/sys/net/rpl/etx_beaconing.h +++ b/sys/net/rpl/etx_beaconing.h @@ -16,13 +16,13 @@ #include <debug.h> #if ENABLE_DEBUG - #define ETX_BEACON_STACKSIZE (4500) - #define ETX_RADIO_STACKSIZE (4500) - #define ETX_CLOCK_STACKSIZE (500) +#define ETX_BEACON_STACKSIZE (4500) +#define ETX_RADIO_STACKSIZE (4500) +#define ETX_CLOCK_STACKSIZE (500) #else - #define ETX_BEACON_STACKSIZE (2500) //TODO optimize, maybe 2000 is enough - #define ETX_RADIO_STACKSIZE (2500) //TODO optimize, maybe 2000 is enough - #define ETX_CLOCK_STACKSIZE (500) //TODO optimize, maybe 250 is enough +#define ETX_BEACON_STACKSIZE (2500) //TODO optimize, maybe 2000 is enough +#define ETX_RADIO_STACKSIZE (2500) //TODO optimize, maybe 2000 is enough +#define ETX_CLOCK_STACKSIZE (500) //TODO optimize, maybe 250 is enough #endif //[option|length|ipaddr.|packetcount] with up to 15 ipaddr|packetcount pairs @@ -36,9 +36,9 @@ * In my tests, the maximum count of neighbors was around 30-something */ #if ENABLE_DEBUG - #define ETX_MAX_CANDIDATE_NEIGHBORS (15) //Stacksizes are huge in debug mode, so memory is rare +#define ETX_MAX_CANDIDATE_NEIGHBORS (15) //Stacksizes are huge in debug mode, so memory is rare #else - #define ETX_MAX_CANDIDATE_NEIGHBORS (40) +#define ETX_MAX_CANDIDATE_NEIGHBORS (40) #endif //ETX Interval parameters #define MS (1000) @@ -86,7 +86,7 @@ * information. * The information processed shall not exceed the value set in Option Length. */ -typedef struct __attribute__((packed)) etx_probe_t{ +typedef struct __attribute__((packed)) etx_probe_t { uint8_t code; uint8_t length; uint8_t data[30]; @@ -102,11 +102,11 @@ typedef struct etx_neighbor_t { } etx_neighbor_t; //prototypes -void etx_init_beaconing(ipv6_addr_t * address); +void etx_init_beaconing(ipv6_addr_t *address); void etx_beacon(void); void etx_clock(void); -double etx_get_metric(ipv6_addr_t * address); -void etx_update(etx_neighbor_t * neighbor); +double etx_get_metric(ipv6_addr_t *address); +void etx_update(etx_neighbor_t *neighbor); void etx_radio(void); #define ETX_PKT_OPT (0) //Position of Option-Type-Byte diff --git a/sys/net/rpl/of0.c b/sys/net/rpl/of0.c index 2890bf22c431217c964cb1b7ae3b7440d4121bb3..3cca85e196f291669d3f07d48c0cee5945b22811 100644 --- a/sys/net/rpl/of0.c +++ b/sys/net/rpl/of0.c @@ -1,5 +1,5 @@ /** - * Objective function 0 for RPL implementation + * Objective function 0 for RPL implementation * * Copyright (C) 2013 INRIA. * @@ -7,10 +7,10 @@ * Public License. See the file LICENSE in the top level directory for more * details. * - * @ingroup rpl + * @ingroup rpl * @{ - * @file of0.c - * @brief RPL objective function 0 + * @file of0.c + * @brief RPL objective function 0 * @author Eric Engel <eric.engel@fu-berlin.de> * @} */ diff --git a/sys/net/rpl/of_mrhof.c b/sys/net/rpl/of_mrhof.c index 66f04f7c6ab6e87363fa9c6b3a11411e5d1fe2b1..8c6fec2b742228c46d7d63359a43a70fb695755f 100644 --- a/sys/net/rpl/of_mrhof.c +++ b/sys/net/rpl/of_mrhof.c @@ -9,33 +9,37 @@ static uint16_t calc_rank(rpl_parent_t *, uint16_t); static rpl_parent_t *which_parent(rpl_parent_t *, rpl_parent_t *); static rpl_dodag_t *which_dodag(rpl_dodag_t *, rpl_dodag_t *); static void reset(rpl_dodag_t *); -static uint16_t calc_path_cost(rpl_parent_t * parent); +static uint16_t calc_path_cost(rpl_parent_t *parent); uint16_t cur_min_path_cost = MAX_PATH_COST; -rpl_parent_t * cur_preferred_parent = NULL; +rpl_parent_t *cur_preferred_parent = NULL; rpl_of_t rpl_of_mrhof = { - 0x1, - calc_rank, - which_parent, - which_dodag, - reset, - NULL - }; - -rpl_of_t * rpl_get_of_mrhof(void) { + 0x1, + calc_rank, + which_parent, + which_dodag, + reset, + NULL +}; + +rpl_of_t *rpl_get_of_mrhof(void) +{ return &rpl_of_mrhof; } -void reset(rpl_dodag_t *dodag) { +void reset(rpl_dodag_t *dodag) +{ } -static uint16_t calc_path_cost(rpl_parent_t * parent) { +static uint16_t calc_path_cost(rpl_parent_t *parent) +{ puts("calc_pathcost"); + /* * Calculates the path cost through the parent, for now, only for ETX */ - if (parent == NULL ) { + if (parent == NULL) { // Shouldn't ever happen since this function is supposed to be always // run with a parent. If it does happen, we can assume a root called it. puts("[WARNING] calc_path_cost called without parent!"); @@ -44,6 +48,7 @@ static uint16_t calc_path_cost(rpl_parent_t * parent) { double etx_value = etx_get_metric(&(parent->addr)); printf("Metric for parent returned: %f", etx_value); + if (etx_value != 0) { /* * (ETX_for_link_to_neighbor * 128) + Rank_of_that_neighbor @@ -60,14 +65,16 @@ static uint16_t calc_path_cost(rpl_parent_t * parent) { } if (etx_value * ETX_RANK_MULTIPLIER + parent->rank - < parent->rank) { + < parent->rank) { //Overflow return MAX_PATH_COST; } + //TODO runden return etx_value * ETX_RANK_MULTIPLIER - + parent->rank; - } else { + + parent->rank; + } + else { // IMPLEMENT HANDLING OF OTHER METRICS HERE // if it is 0, it hasn't been computed, thus we cannot compute a path // cost @@ -75,8 +82,10 @@ static uint16_t calc_path_cost(rpl_parent_t * parent) { } } -static uint16_t calc_rank(rpl_parent_t * parent, uint16_t base_rank) { +static uint16_t calc_rank(rpl_parent_t *parent, uint16_t base_rank) +{ puts("calc_rank"); + /* * Return the rank for this node. * @@ -84,7 +93,7 @@ static uint16_t calc_rank(rpl_parent_t * parent, uint16_t base_rank) { * putation will always be assumed to be done for the ETX metric. * Baserank is pretty much only used to find out if a node is a root or not. */ - if (parent == NULL ) { + if (parent == NULL) { if (base_rank == 0) { //No parent, no rank, a root node would have a rank != 0 return INFINITE_RANK; @@ -97,7 +106,8 @@ static uint16_t calc_rank(rpl_parent_t * parent, uint16_t base_rank) { * (see rpl.c, function global_repair), we can assume this node is root. */ return DEFAULT_MIN_HOP_RANK_INCREASE; - } else { + } + else { /* * We have a parent and are a non-root node, calculate the path cost for * the parent and choose the maximum of that value and the advertised @@ -107,19 +117,22 @@ static uint16_t calc_rank(rpl_parent_t * parent, uint16_t base_rank) { if (calculated_pcost < MAX_PATH_COST) { if ((parent->rank + parent->dodag->minhoprankincrease) - > calculated_pcost) { + > calculated_pcost) { return parent->rank + parent->dodag->minhoprankincrease; - } else { + } + else { return calculated_pcost; } - } else { + } + else { //Path costs are greater than allowed return INFINITE_RANK; } } } -static rpl_parent_t * which_parent(rpl_parent_t * p1, rpl_parent_t * p2) { +static rpl_parent_t *which_parent(rpl_parent_t *p1, rpl_parent_t *p2) +{ puts("which_parent"); /* * Return the parent with the lowest path cost. @@ -130,12 +143,12 @@ static rpl_parent_t * which_parent(rpl_parent_t * p1, rpl_parent_t * p2) { uint16_t path_p1 = calc_path_cost(p1); uint16_t path_p2 = calc_path_cost(p2); - if(cur_preferred_parent != NULL){ + if (cur_preferred_parent != NULL) { //test if the parent from which we got this path is still active - if(cur_preferred_parent->used != 0){ + if (cur_preferred_parent->used != 0) { // Test, if the current best path is better than both parents given - if(cur_min_path_cost < path_p1 + PARENT_SWITCH_THRESHOLD - && cur_min_path_cost < path_p2 + PARENT_SWITCH_THRESHOLD){ + if (cur_min_path_cost < path_p1 + PARENT_SWITCH_THRESHOLD + && cur_min_path_cost < path_p2 + PARENT_SWITCH_THRESHOLD) { return cur_preferred_parent; } } @@ -149,12 +162,14 @@ static rpl_parent_t * which_parent(rpl_parent_t * p1, rpl_parent_t * p2) { cur_preferred_parent = p1; return p1; } + cur_min_path_cost = path_p2; cur_preferred_parent = p2; return p2; } //Not used yet, as the implementation only makes use of one dodag for now. -static rpl_dodag_t * which_dodag(rpl_dodag_t *d1, rpl_dodag_t *d2) { +static rpl_dodag_t *which_dodag(rpl_dodag_t *d1, rpl_dodag_t *d2) +{ return d1; } diff --git a/sys/net/rpl/rpl.c b/sys/net/rpl/rpl.c index 49f76f26742e6c7e751f0069a4e50184b9832757..1f05effd3b68f93127d3fa8759cd882ff37cfd78 100644 --- a/sys/net/rpl/rpl.c +++ b/sys/net/rpl/rpl.c @@ -1,5 +1,5 @@ /** - * RPL implementation + * RPL implementation * * Copyright (C) 2013 INRIA. * @@ -7,10 +7,10 @@ * Public License. See the file LICENSE in the top level directory for more * details. * - * @ingroup rpl + * @ingroup rpl * @{ - * @file rpl.c - * @brief basic RPL functions + * @file rpl.c + * @brief basic RPL functions * @author Eric Engel <eric.engel@fu-berlin.de> * @} */ @@ -71,7 +71,7 @@ static rpl_opt_transit_t *rpl_opt_transit_buf; /* SEND BUFFERS */ static ipv6_hdr_t *get_rpl_send_ipv6_buf(void) { - return ((ipv6_hdr_t *)&(rpl_send_buffer[0])); + return ((ipv6_hdr_t *) & (rpl_send_buffer[0])); } static uint8_t *get_rpl_send_payload_buf(uint8_t ext_len) @@ -79,95 +79,86 @@ static uint8_t *get_rpl_send_payload_buf(uint8_t ext_len) return &(rpl_send_buffer[IPV6_HDR_LEN + ext_len]); } -static struct icmpv6_hdr_t *get_rpl_send_icmpv6_buf(uint8_t ext_len) -{ - return ((struct icmpv6_hdr_t *)&(rpl_send_buffer[IPV6_HDR_LEN + ext_len])); +static struct icmpv6_hdr_t *get_rpl_send_icmpv6_buf(uint8_t ext_len) { + return ((struct icmpv6_hdr_t *) & (rpl_send_buffer[IPV6_HDR_LEN + ext_len])); } -static struct rpl_dio_t *get_rpl_send_dio_buf(void) -{ - return ((struct rpl_dio_t *)&(rpl_send_buffer[IPV6HDR_ICMPV6HDR_LEN])); +static struct rpl_dio_t *get_rpl_send_dio_buf(void) { + return ((struct rpl_dio_t *) & (rpl_send_buffer[IPV6HDR_ICMPV6HDR_LEN])); } -static struct rpl_dao_t *get_rpl_send_dao_buf(void) -{ - return ((struct rpl_dao_t *)&(rpl_send_buffer[IPV6HDR_ICMPV6HDR_LEN])); +static struct rpl_dao_t *get_rpl_send_dao_buf(void) { + return ((struct rpl_dao_t *) & (rpl_send_buffer[IPV6HDR_ICMPV6HDR_LEN])); } -static struct rpl_dao_ack_t *get_rpl_send_dao_ack_buf(void) -{ - return ((struct rpl_dao_ack_t *)&(rpl_send_buffer[IPV6HDR_ICMPV6HDR_LEN])); +static struct rpl_dao_ack_t *get_rpl_send_dao_ack_buf(void) { + return ((struct rpl_dao_ack_t *) & (rpl_send_buffer[IPV6HDR_ICMPV6HDR_LEN])); } -static struct rpl_dis_t *get_rpl_send_dis_buf(void) -{ - return ((struct rpl_dis_t *)&(rpl_send_buffer[IPV6HDR_ICMPV6HDR_LEN])); +static struct rpl_dis_t *get_rpl_send_dis_buf(void) { + return ((struct rpl_dis_t *) & (rpl_send_buffer[IPV6HDR_ICMPV6HDR_LEN])); } static rpl_opt_dodag_conf_t *get_rpl_send_opt_dodag_conf_buf(uint8_t rpl_msg_len) { - return ((rpl_opt_dodag_conf_t *)&(rpl_send_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len])); + return ((rpl_opt_dodag_conf_t *) & (rpl_send_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len])); } static rpl_opt_target_t *get_rpl_send_opt_target_buf(uint8_t rpl_msg_len) { - return ((rpl_opt_target_t *)&(rpl_send_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len])); + return ((rpl_opt_target_t *) & (rpl_send_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len])); } static rpl_opt_transit_t *get_rpl_send_opt_transit_buf(uint8_t rpl_msg_len) { - return ((rpl_opt_transit_t *)&(rpl_send_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len])); + return ((rpl_opt_transit_t *) & (rpl_send_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len])); } /* RECEIVE BUFFERS */ static ipv6_hdr_t *get_rpl_ipv6_buf(void) { - return ((ipv6_hdr_t *)&(rpl_buffer[0])); + return ((ipv6_hdr_t *) & (rpl_buffer[0])); } -static struct rpl_dio_t *get_rpl_dio_buf(void) -{ - return ((struct rpl_dio_t *)&(rpl_buffer[IPV6HDR_ICMPV6HDR_LEN])); +static struct rpl_dio_t *get_rpl_dio_buf(void) { + return ((struct rpl_dio_t *) & (rpl_buffer[IPV6HDR_ICMPV6HDR_LEN])); } -static struct rpl_dao_t *get_rpl_dao_buf(void) -{ - return ((struct rpl_dao_t *)&(rpl_buffer[IPV6HDR_ICMPV6HDR_LEN])); +static struct rpl_dao_t *get_rpl_dao_buf(void) { + return ((struct rpl_dao_t *) & (rpl_buffer[IPV6HDR_ICMPV6HDR_LEN])); } -static struct rpl_dao_ack_t *get_rpl_dao_ack_buf(void) -{ - return ((struct rpl_dao_ack_t *)&(buffer[LLHDR_ICMPV6HDR_LEN])); +static struct rpl_dao_ack_t *get_rpl_dao_ack_buf(void) { + return ((struct rpl_dao_ack_t *) & (buffer[LLHDR_ICMPV6HDR_LEN])); } -static struct rpl_dis_t *get_rpl_dis_buf(void) -{ - return ((struct rpl_dis_t *)&(rpl_buffer[IPV6HDR_ICMPV6HDR_LEN])); +static struct rpl_dis_t *get_rpl_dis_buf(void) { + return ((struct rpl_dis_t *) & (rpl_buffer[IPV6HDR_ICMPV6HDR_LEN])); } static rpl_opt_t *get_rpl_opt_buf(uint8_t rpl_msg_len) { - return ((rpl_opt_t *)&(rpl_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len])); + return ((rpl_opt_t *) & (rpl_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len])); } static rpl_opt_dodag_conf_t *get_rpl_opt_dodag_conf_buf(uint8_t rpl_msg_len) { - return ((rpl_opt_dodag_conf_t *)&(rpl_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len])); + return ((rpl_opt_dodag_conf_t *) & (rpl_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len])); } static rpl_opt_solicited_t *get_rpl_opt_solicited_buf(uint8_t rpl_msg_len) { - return ((rpl_opt_solicited_t *)&(rpl_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len])); + return ((rpl_opt_solicited_t *) & (rpl_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len])); } static rpl_opt_target_t *get_rpl_opt_target_buf(uint8_t rpl_msg_len) { - return ((rpl_opt_target_t *)&(rpl_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len])); + return ((rpl_opt_target_t *) & (rpl_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len])); } static rpl_opt_transit_t *get_rpl_opt_transit_buf(uint8_t rpl_msg_len) { - return ((rpl_opt_transit_t *)&(rpl_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len])); + return ((rpl_opt_transit_t *) & (rpl_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len])); } /* find implemented OF via objective code point */ @@ -210,7 +201,7 @@ uint8_t rpl_init(transceiver_type_t trans, uint16_t rpl_address) set_rpl_process_pid(rpl_process_pid); /* initialize ETX-calculation if needed */ - if(RPL_DEFAULT_OCP == 1){ + if (RPL_DEFAULT_OCP == 1) { DEBUG("INIT ETX BEACONING\n"); etx_init_beaconing(&my_address); } @@ -236,7 +227,7 @@ void rpl_init_root(void) dodag = rpl_new_dodag(RPL_DEFAULT_INSTANCE, &my_address); if (dodag != NULL) { - dodag->of = (struct rpl_of_t*) rpl_get_of_for_ocp(RPL_DEFAULT_OCP); + dodag->of = (struct rpl_of_t *) rpl_get_of_for_ocp(RPL_DEFAULT_OCP); dodag->instance = inst; dodag->mop = RPL_DEFAULT_MOP; dodag->dtsn = 1; @@ -474,7 +465,7 @@ void rpl_process(void) ipv6_buf = get_ipv6_buf(); memcpy(&rpl_buffer, ipv6_buf, ipv6_buf->length + IPV6_HDR_LEN); - switch(*code) { + switch (*code) { case (ICMP_CODE_DIS): { recv_rpl_dis(); mutex_unlock(&rpl_recv_mutex); @@ -530,11 +521,11 @@ void recv_rpl_dio(void) } } else if (my_inst->id != dio_inst->id) { - /* TODO: Add support support for several instances. */ + /* TODO: Add support support for several instances. */ - /* At the moment, nodes can only join one instance, this is - * the instance they join first. - * Instances cannot be switched later on. */ + /* At the moment, nodes can only join one instance, this is + * the instance they join first. + * Instances cannot be switched later on. */ DEBUG("Ignoring instance - we are %d and got %d\n", my_inst->id, dio_inst->id); return; @@ -553,14 +544,14 @@ void recv_rpl_dio(void) uint8_t has_dodag_conf_opt = 0; - /* Parse until all options are consumed. - * ipv6_buf->length contains the packet length minus ipv6 and - * icmpv6 header, so only ICMPV6_HDR_LEN remains to be - * subtracted. */ + /* Parse until all options are consumed. + * ipv6_buf->length contains the packet length minus ipv6 and + * icmpv6 header, so only ICMPV6_HDR_LEN remains to be + * subtracted. */ while (len < (ipv6_buf->length - ICMPV6_HDR_LEN)) { rpl_opt_buf = get_rpl_opt_buf(len); - switch(rpl_opt_buf->type) { + switch (rpl_opt_buf->type) { case (RPL_OPT_PAD1): { len += 1; @@ -598,7 +589,7 @@ void recv_rpl_dio(void) dio_dodag.minhoprankincrease = rpl_opt_dodag_conf_buf->MinHopRankIncrease; dio_dodag.default_lifetime = rpl_opt_dodag_conf_buf->default_lifetime; dio_dodag.lifetime_unit = rpl_opt_dodag_conf_buf->lifetime_unit; - dio_dodag.of = (struct rpl_of_t*) rpl_get_of_for_ocp(rpl_opt_dodag_conf_buf->ocp); + dio_dodag.of = (struct rpl_of_t *) rpl_get_of_for_ocp(rpl_opt_dodag_conf_buf->ocp); len += RPL_OPT_DODAG_CONF_LEN + 2; break; } @@ -682,7 +673,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(); @@ -736,7 +727,7 @@ void recv_rpl_dis(void) while (len < (ipv6_buf->length - ICMPV6_HDR_LEN)) { rpl_opt_buf = get_rpl_opt_buf(len); - switch(rpl_opt_buf->type) { + switch (rpl_opt_buf->type) { case (RPL_OPT_PAD1): { len += 1; break; @@ -805,7 +796,7 @@ void recv_rpl_dao(void) while (len < (ipv6_buf->length - ICMPV6_HDR_LEN)) { rpl_opt_buf = get_rpl_opt_buf(len); - switch(rpl_opt_buf->type) { + switch (rpl_opt_buf->type) { case (RPL_OPT_PAD1): { len += 1; @@ -919,7 +910,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)) { - lowpan_init((ieee_802154_long_t *)&(ipv6_send_buf->destaddr.uint16[4]), (uint8_t *)ipv6_send_buf); + lowpan_init((ieee_802154_long_t *) & (ipv6_send_buf->destaddr.uint16[4]), (uint8_t *)ipv6_send_buf); } else { /* find appropriate next hop before sending */ @@ -940,7 +931,7 @@ void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_ } } - lowpan_init((ieee_802154_long_t *)&(next_hop->uint16[4]), (uint8_t *)ipv6_send_buf); + lowpan_init((ieee_802154_long_t *) & (next_hop->uint16[4]), (uint8_t *)ipv6_send_buf); } } diff --git a/sys/net/rpl/rpl.h b/sys/net/rpl/rpl.h index b15c35d668c29fcf72ab1398c5d280b58a3e3da5..67f14877b2c959ee711131b4cb4dd820c42bf05e 100644 --- a/sys/net/rpl/rpl.h +++ b/sys/net/rpl/rpl.h @@ -1,5 +1,5 @@ /** - * RPL constants and prototypes + * RPL constants and prototypes * * Copyright (C) 2013 INRIA. * @@ -7,7 +7,7 @@ * Public License. See the file LICENSE in the top level directory for more * details. * - * @ingroup rpl + * @ingroup rpl * @{ * @file rpl.h * @brief RPL header diff --git a/sys/net/rpl/rpl_dodag.c b/sys/net/rpl/rpl_dodag.c index d80e9fb94163753ec526a9023367ebdd1e2f5915..fb254272baadc658375674648645b5620cc79162 100644 --- a/sys/net/rpl/rpl_dodag.c +++ b/sys/net/rpl/rpl_dodag.c @@ -1,5 +1,5 @@ /** - * RPL dodag implementation + * RPL dodag implementation * * Copyright (C) 2013 INRIA. * @@ -7,10 +7,10 @@ * Public License. See the file LICENSE in the top level directory for more * details. * - * @ingroup rpl + * @ingroup rpl * @{ * @file rpl_dodag.c - * @brief RPL dodag functions + * @brief RPL dodag functions * @author Eric Engel <eric.engel@fu-berlin.de> * @} */ @@ -179,7 +179,7 @@ void rpl_delete_parent(rpl_parent_t *parent) rpl_dodag_t *my_dodag = rpl_get_my_dodag(); if ((my_dodag != NULL) && rpl_equal_id(&my_dodag->my_preferred_parent->addr, - &parent->addr)) { + &parent->addr)) { my_dodag->my_preferred_parent = NULL; } @@ -275,7 +275,7 @@ void rpl_parent_update(rpl_parent_t *parent) } if (rpl_calc_rank(old_rank, my_dodag->minhoprankincrease) != - rpl_calc_rank(my_dodag->my_rank, my_dodag->minhoprankincrease)) { + rpl_calc_rank(my_dodag->my_rank, my_dodag->minhoprankincrease)) { if (my_dodag->my_rank < my_dodag->min_rank) { my_dodag->min_rank = my_dodag->my_rank; } @@ -348,7 +348,7 @@ void rpl_global_repair(rpl_dodag_t *dodag, ipv6_addr_t *p_addr, uint16_t rank) else { /* Calc new Rank */ my_dodag->my_rank = my_dodag->of->calc_rank(my_dodag->my_preferred_parent, - my_dodag->my_rank); + my_dodag->my_rank); my_dodag->min_rank = my_dodag->my_rank; reset_trickletimer(); delay_dao(); diff --git a/sys/net/rpl/rpl_dodag.h b/sys/net/rpl/rpl_dodag.h index a4ad7e0ace8dd471974255fa29daca35fd88a4f3..a21b004fb43843bfaf4638e4b2f35b8326dbcac7 100644 --- a/sys/net/rpl/rpl_dodag.h +++ b/sys/net/rpl/rpl_dodag.h @@ -1,5 +1,5 @@ /** - * RPL dodag prototypes + * RPL dodag prototypes * * Copyright (C) 2013 INRIA. * @@ -7,10 +7,10 @@ * Public License. See the file LICENSE in the top level directory for more * details. * - * @ingroup rpl + * @ingroup rpl * @{ * @file rpl_dodag.h - * @brief RPL dodag header + * @brief RPL dodag header * @author Eric Engel <eric.engel@fu-berlin.de> * @} */ diff --git a/sys/net/rpl/rpl_structs.h b/sys/net/rpl/rpl_structs.h index 2eec2bc649f26a65ad1714b96948c912ddd3b676..80e374fe33fe8682cb01757e708ecbcef07dc653 100644 --- a/sys/net/rpl/rpl_structs.h +++ b/sys/net/rpl/rpl_structs.h @@ -1,5 +1,5 @@ /** - * RPL data structs + * RPL data structs * * Copyright (C) 2013 INRIA. * @@ -7,7 +7,7 @@ * Public License. See the file LICENSE in the top level directory for more * details. * - * @ingroup rpl + * @ingroup rpl * @{ * @file rpl_structs.h * @brief RPL data structs @@ -219,12 +219,12 @@ struct rpl_dodag_t; typedef struct { ipv6_addr_t addr; uint16_t rank; - uint8_t dtsn; + uint8_t dtsn; struct rpl_dodag_t *dodag; - uint16_t lifetime; - double link_metric; - uint8_t link_metric_type; - uint8_t used; + uint16_t lifetime; + double link_metric; + uint8_t link_metric_type; + uint8_t used; } rpl_parent_t; struct rpl_of_t; @@ -264,13 +264,13 @@ typedef struct rpl_dodag_t { typedef struct rpl_of_t { uint16_t ocp; - uint16_t (*calc_rank)(rpl_parent_t * parent, uint16_t base_rank); + uint16_t (*calc_rank)(rpl_parent_t *parent, uint16_t base_rank); rpl_parent_t *(*which_parent)(rpl_parent_t *, rpl_parent_t *); rpl_dodag_t *(*which_dodag)(rpl_dodag_t *, rpl_dodag_t *); void (*reset)(rpl_dodag_t *); void (*parent_state_callback)(rpl_parent_t *, int, int); - void (*init) (void); //OF specific init function - void (*process_dio) (void); //DIO processing callback (acc. to OF0 spec, chpt 5) + void (*init)(void); //OF specific init function + void (*process_dio)(); //DIO processing callback (acc. to OF0 spec, chpt 5) } rpl_of_t; typedef struct { diff --git a/sys/net/rpl/trickle.c b/sys/net/rpl/trickle.c index 69473445abc1cb8ed404bc39c83c137ec1cd8972..31281d04dbdbb6c79c4430fd6234e18941b907cc 100644 --- a/sys/net/rpl/trickle.c +++ b/sys/net/rpl/trickle.c @@ -7,7 +7,7 @@ * Public License. See the file LICENSE in the top level directory for more * details. * - * @ingroup rpl + * @ingroup rpl * @{ * @file trickle.c * @brief Trickle implementation @@ -25,9 +25,9 @@ #include "rpl/rpl.h" //TODO in pointer umwandeln, speicher mit malloc holen -char * timer_over_buf; -char * interval_over_buf; -char * dao_delay_over_buf; +char *timer_over_buf; +char *interval_over_buf; +char *dao_delay_over_buf; char routing_table_buf[RT_STACKSIZE]; int timer_over_pid; int interval_over_pid; @@ -71,18 +71,23 @@ void reset_trickletimer(void) void init_trickle(void) { - timer_over_buf = calloc(TRICKLE_TIMER_STACKSIZE,sizeof(char)); - if(timer_over_buf == NULL){ + timer_over_buf = calloc(TRICKLE_TIMER_STACKSIZE, sizeof(char)); + + if (timer_over_buf == NULL) { puts("[ERROR] Could not allocate enough memory for timer_over_buf!"); return; } - interval_over_buf = calloc(TRICKLE_INTERVAL_STACKSIZE,sizeof(char)); - if(interval_over_buf == NULL){ + + interval_over_buf = calloc(TRICKLE_INTERVAL_STACKSIZE, sizeof(char)); + + if (interval_over_buf == NULL) { puts("[ERROR] Could not allocate enough memory for interval_over_buf!"); return; } - dao_delay_over_buf = calloc(DAO_DELAY_STACKSIZE,sizeof(char)); - if(dao_delay_over_buf == NULL){ + + dao_delay_over_buf = calloc(DAO_DELAY_STACKSIZE, sizeof(char)); + + if (dao_delay_over_buf == NULL) { puts("[ERROR] Could not allocate enough memory for interval_over_buf!"); return; } diff --git a/sys/net/rpl/trickle.h b/sys/net/rpl/trickle.h index 72ec98dfc043565cc0e300594f4677df3e899839..5f2172004249e947404d9ccb1cb8d55245b91556 100644 --- a/sys/net/rpl/trickle.h +++ b/sys/net/rpl/trickle.h @@ -7,10 +7,10 @@ * Public License. See the file LICENSE in the top level directory for more * details. * - * @ingroup rpl + * @ingroup rpl * @{ * @file trickle.h - * @brief Trickle + * @brief Trickle * @author Eric Engel <eric.engel@fu-berlin.de> * @} */ diff --git a/sys/net/sixlowpan/border.c b/sys/net/sixlowpan/border.c index 72ab711055fef251b61640ff47751364f1d5652b..ff37c7420e8beff532a0bf1e4a60fe33331b70b4 100644 --- a/sys/net/sixlowpan/border.c +++ b/sys/net/sixlowpan/border.c @@ -1,5 +1,5 @@ /** - * 6lowpan border router implementation + * 6lowpan border router implementation * * Copyright (C) 2013 INRIA. * @@ -10,7 +10,7 @@ * @ingroup sixlowpan * @{ * @file sixlowborder.c - * @brief constraint node implementation for a 6lowpan border router + * @brief constraint node implementation for a 6lowpan border router * @author Martin Lenders <mlenders@inf.fu-berlin.de> * @author Oliver Hahm <oliver.hahm@inria.fr> * @} @@ -19,12 +19,12 @@ #include <stdint.h> #include <string.h> #include <stdio.h> -#include <mutex.h> -#include <thread.h> -#include <msg.h> -#include <posix_io.h> -#include <board_uart0.h> +#include "mutex.h" +#include "thread.h" +#include "msg.h" +#include "posix_io.h" +#include "board_uart0.h" #include "sixlowpan/error.h" #include "bordermultiplex.h" @@ -86,7 +86,7 @@ void serial_reader_f(void) bytes = readpacket(get_serial_in_buffer(0), BORDER_BUFFER_SIZE); if (bytes < 0) { - switch(bytes) { + switch (bytes) { case (-SIXLOWERROR_ARRAYFULL): { printf("ERROR: Array was full\n"); break; @@ -139,9 +139,9 @@ uint8_t border_initialize(transceiver_type_t trans, ipv6_addr_t *border_router_a * -- for now */ if (border_router_addr->uint16[4] != HTONS(IEEE_802154_PAN_ID ^ 0x0200) || - border_router_addr->uint16[5] != HTONS(0x00FF) || - border_router_addr->uint16[6] != HTONS(0xFE00) - ) { + border_router_addr->uint16[5] != HTONS(0x00FF) || + border_router_addr->uint16[6] != HTONS(0xFE00) + ) { return SIXLOWERROR_ADDRESS; } @@ -169,7 +169,7 @@ void border_send_ipv6_over_lowpan(ipv6_hdr_t *packet, uint8_t aro_flag, uint8_t memset(buffer, 0, BUFFER_SIZE); memcpy(buffer + LL_HDR_LEN, packet, offset); - lowpan_init((ieee_802154_long_t *)&(packet->destaddr.uint16[4]), (uint8_t *)packet); + lowpan_init((ieee_802154_long_t *) & (packet->destaddr.uint16[4]), (uint8_t *)packet); } void border_process_lowpan(void) diff --git a/sys/net/sixlowpan/border.h b/sys/net/sixlowpan/border.h index c3252660f637ae76ae67f4b56d06f619a3a8344d..7828295ea9f043cbf91943c39f6100578eed6eb7 100644 --- a/sys/net/sixlowpan/border.h +++ b/sys/net/sixlowpan/border.h @@ -10,7 +10,7 @@ * @ingroup sixlowpan * @{ * @file sixlowborder.h - * @brief header for 6lowpan border router + * @brief header for 6lowpan border router * @author Martin Lenders <mlenders@inf.fu-berlin.de> * @author Oliver Hahm <oliver.hahm@inria.fr> * @} @@ -22,8 +22,9 @@ #define _SIXLOWPAN_BORDER_H #include <stdint.h> -#include <mutex.h> -#include <transceiver.h> + +#include "mutex.h" +#include "transceiver.h" #include "ip.h" #include "semaphore.h" diff --git a/sys/net/sixlowpan/bordermultiplex.c b/sys/net/sixlowpan/bordermultiplex.c index 02ca89b568dd757167138c45fc434ce3e3bbf1ed..ae3d29fbd9102a9670cf449a5c20979248583cc0 100644 --- a/sys/net/sixlowpan/bordermultiplex.c +++ b/sys/net/sixlowpan/bordermultiplex.c @@ -19,7 +19,7 @@ #include <stdio.h> #include <string.h> -#include <board_uart0.h> +#include "board_uart0.h" #include "sixlowpan/error.h" #include "flowcontrol.h" @@ -36,7 +36,7 @@ void demultiplex(border_packet_t *packet, int len) { - switch(packet->type) { + switch (packet->type) { case (BORDER_PACKET_RAW_TYPE): { fputs(((char *)packet) + sizeof(border_packet_t), stdin); break; @@ -45,7 +45,7 @@ void demultiplex(border_packet_t *packet, int len) case (BORDER_PACKET_L3_TYPE): { border_l3_header_t *l3_header_buf = (border_l3_header_t *)packet; - switch(l3_header_buf->ethertype) { + 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)); border_send_ipv6_over_lowpan(ipv6_buf, 1, 1); @@ -63,7 +63,7 @@ void demultiplex(border_packet_t *packet, int len) case (BORDER_PACKET_CONF_TYPE): { border_conf_header_t *conf_header_buf = (border_conf_header_t *)packet; - switch(conf_header_buf->conftype) { + switch (conf_header_buf->conftype) { case (BORDER_CONF_CONTEXT): { border_context_packet_t *context = (border_context_packet_t *)packet; ipv6_addr_t target_addr; @@ -148,7 +148,7 @@ int readpacket(uint8_t *packet_buf, size_t size) if (esc) { esc = 0; - switch(byte) { + switch (byte) { case (END_ESC): { *line_buf_ptr++ = END; continue; @@ -184,7 +184,7 @@ int writepacket(uint8_t *packet_buf, size_t size) return -1; } - switch(*byte_ptr) { + switch (*byte_ptr) { case (END): { *byte_ptr = END_ESC; uart0_putc(ESC); diff --git a/sys/net/sixlowpan/bordermultiplex.h b/sys/net/sixlowpan/bordermultiplex.h index c5d5dc7068be9553d77f25caa0c3c82526cef5a5..c284953b3076421c48736fa3d8fb74788f92723e 100644 --- a/sys/net/sixlowpan/bordermultiplex.h +++ b/sys/net/sixlowpan/bordermultiplex.h @@ -1,5 +1,5 @@ /** - * 6lowpan border router multiplexer + * 6lowpan border router multiplexer * * Copyright (C) 2013 INRIA. * @@ -9,7 +9,7 @@ * * @ingroup sixlowpan * @{ - * @file bordermultiplex.h + * @file bordermultiplex.h * @brief data structs for border router multiplexing * @author Martin Lenders <mlenders@inf.fu-berlin.de> * @author Oliver Hahm <oliver.hahm@inria.fr> diff --git a/sys/net/sixlowpan/flowcontrol.c b/sys/net/sixlowpan/flowcontrol.c index 38ef21696979343258e489959dfc3e3dec252ee0..62627d57f7cd4191e59716b5173a02f2ad3e6ff1 100644 --- a/sys/net/sixlowpan/flowcontrol.c +++ b/sys/net/sixlowpan/flowcontrol.c @@ -1,5 +1,5 @@ /** - * 6lowpan border router flow control + * 6lowpan border router flow control * * Copyright (C) 2013 INRIA. * @@ -10,7 +10,7 @@ * @ingroup sixlowpan * @{ * @file flowcontrol.c - * @brief flowcontrol for constraint node border router implementation + * @brief flowcontrol for constraint node border router implementation * @author Martin Lenders <mlenders@inf.fu-berlin.de> * @author Oliver Hahm <oliver.hahm@inria.fr> * @} @@ -181,8 +181,8 @@ void flowcontrol_deliver_from_uart(border_packet_t *packet, int len) slot = &(slwin_stat.recv_win[packet->seq_num % BORDER_RWS]); if (!in_window(packet->seq_num, - slwin_stat.next_exp, - slwin_stat.next_exp + BORDER_RWS - 1)) { + slwin_stat.next_exp, + slwin_stat.next_exp + BORDER_RWS - 1)) { return; } diff --git a/sys/net/sixlowpan/flowcontrol.h b/sys/net/sixlowpan/flowcontrol.h index f4fb350ce3b33b367af49098657788a0a2e6dd1b..f17a80c48e48db029d4f0ed0f23566fd8f553c08 100644 --- a/sys/net/sixlowpan/flowcontrol.h +++ b/sys/net/sixlowpan/flowcontrol.h @@ -1,5 +1,5 @@ /** - * 6lowpan border router flow control + * 6lowpan border router flow control * * Copyright (C) 2013 INRIA. * @@ -20,7 +20,8 @@ #define _SIXLOWPAN_FLOWCONTROL_H #include <stdint.h> -#include <vtimer.h> + +#include "vtimer.h" #include "semaphore.h" #include "ip.h" diff --git a/sys/net/sixlowpan/icmp.c b/sys/net/sixlowpan/icmp.c index ad72164dc1df7ba5d9264b211e345021443cbfc0..0082e134addb9268c411b04e547fc11adc306f66 100644 --- a/sys/net/sixlowpan/icmp.c +++ b/sys/net/sixlowpan/icmp.c @@ -1,5 +1,5 @@ /* - * 6lowpan neighbor discovery + * 6lowpan neighbor discovery * * Copyright (C) 2013 INRIA. * @@ -10,7 +10,7 @@ * @ingroup sixlowpan * @{ * @file sixlownd.c - * @brief 6lowpan neighbor discovery functions + * @brief 6lowpan neighbor discovery functions * @author Stephan Zeisberg <zeisberg@mi.fu-berlin.de> * @author Martin Lenders <mlenders@inf.fu-berlin.de> * @author Oliver Gesch <oliver.gesch@googlemail.com> @@ -21,6 +21,8 @@ #include <stdlib.h> #include <string.h> +#include "vtimer.h" +#include "mutex.h" #include "sixlowpan/error.h" #include "ip.h" @@ -29,8 +31,6 @@ #include "lowpan.h" #include "serialnumber.h" #include "sys/net/net_help/net_help.h" -#include "vtimer.h" -#include "mutex.h" #define ENABLE_DEBUG (0) #include "debug.h" @@ -94,81 +94,75 @@ int min(int a, int b) } } -static struct para_prob_t *get_para_prob_buf(uint8_t ext_len) -{ - return ((struct para_prob_t *)&(buffer[LLHDR_ICMPV6HDR_LEN + ext_len])); +static struct para_prob_t *get_para_prob_buf(uint8_t ext_len) { + return ((struct para_prob_t *) & (buffer[LLHDR_ICMPV6HDR_LEN + ext_len])); } -static struct echo_req_t *get_echo_req_buf(uint8_t ext_len) -{ - return ((struct echo_req_t *)&(buffer[LLHDR_ICMPV6HDR_LEN + ext_len])); +static struct echo_req_t *get_echo_req_buf(uint8_t ext_len) { + return ((struct echo_req_t *) & (buffer[LLHDR_ICMPV6HDR_LEN + ext_len])); } -static struct echo_repl_t *get_echo_repl_buf(uint8_t ext_len) -{ - return ((struct echo_repl_t *)&(buffer[LLHDR_ICMPV6HDR_LEN + ext_len])); +static struct echo_repl_t *get_echo_repl_buf(uint8_t ext_len) { + return ((struct echo_repl_t *) & (buffer[LLHDR_ICMPV6HDR_LEN + ext_len])); } -static struct rtr_adv_t *get_rtr_adv_buf(uint8_t ext_len) -{ - return ((struct rtr_adv_t *)&(buffer[LLHDR_ICMPV6HDR_LEN + ext_len])); +static struct rtr_adv_t *get_rtr_adv_buf(uint8_t ext_len) { + return ((struct rtr_adv_t *) & (buffer[LLHDR_ICMPV6HDR_LEN + ext_len])); } -static struct nbr_sol_t *get_nbr_sol_buf(uint8_t ext_len) -{ - return ((struct nbr_sol_t *)&(buffer[LLHDR_ICMPV6HDR_LEN + ext_len])); +static struct nbr_sol_t *get_nbr_sol_buf(uint8_t ext_len) { + return ((struct nbr_sol_t *) & (buffer[LLHDR_ICMPV6HDR_LEN + ext_len])); } -static struct nbr_adv_t *get_nbr_adv_buf(uint8_t ext_len) -{ - return ((struct nbr_adv_t *)&(buffer[LLHDR_ICMPV6HDR_LEN + ext_len])); +static struct nbr_adv_t *get_nbr_adv_buf(uint8_t ext_len) { + return ((struct nbr_adv_t *) & (buffer[LLHDR_ICMPV6HDR_LEN + ext_len])); } static opt_buf_t *get_opt_buf(uint8_t ext_len, uint8_t opt_len) { - return ((opt_buf_t *)&(buffer[LLHDR_ICMPV6HDR_LEN + - ext_len + opt_len])); + return ((opt_buf_t *) & (buffer[LLHDR_ICMPV6HDR_LEN + + ext_len + opt_len])); } static opt_stllao_t *get_opt_stllao_buf(uint8_t ext_len, uint8_t opt_len) { - return ((opt_stllao_t *)&(buffer[LLHDR_ICMPV6HDR_LEN + + return ((opt_stllao_t *) & (buffer[LLHDR_ICMPV6HDR_LEN + ext_len + opt_len])); } static opt_mtu_t *get_opt_mtu_buf(uint8_t ext_len, uint8_t opt_len) { - return ((opt_mtu_t *)&(buffer[LLHDR_ICMPV6HDR_LEN + - ext_len + opt_len])); + return ((opt_mtu_t *) & (buffer[LLHDR_ICMPV6HDR_LEN + + ext_len + opt_len])); } static opt_abro_t *get_opt_abro_buf(uint8_t ext_len, uint8_t opt_len) { - return ((opt_abro_t *)&(buffer[LLHDR_ICMPV6HDR_LEN + - ext_len + opt_len])); + return ((opt_abro_t *) & (buffer[LLHDR_ICMPV6HDR_LEN + + ext_len + opt_len])); } static opt_6co_hdr_t *get_opt_6co_hdr_buf(uint8_t ext_len, uint8_t opt_len) { - return ((opt_6co_hdr_t *)&(buffer[LLHDR_ICMPV6HDR_LEN + - ext_len + opt_len])); + return ((opt_6co_hdr_t *) & (buffer[LLHDR_ICMPV6HDR_LEN + + ext_len + opt_len])); } static uint8_t *get_opt_6co_prefix_buf(uint8_t ext_len, uint8_t opt_len) { - return ((uint8_t *)&(buffer[LLHDR_ICMPV6HDR_LEN + ext_len + opt_len])); + return ((uint8_t *) & (buffer[LLHDR_ICMPV6HDR_LEN + ext_len + opt_len])); } static opt_pi_t *get_opt_pi_buf(uint8_t ext_len, uint8_t opt_len) { - return ((opt_pi_t *)&(buffer[LLHDR_ICMPV6HDR_LEN + ext_len + - opt_len])); + return ((opt_pi_t *) & (buffer[LLHDR_ICMPV6HDR_LEN + ext_len + + opt_len])); } static opt_aro_t *get_opt_aro_buf(uint8_t ext_len, uint8_t opt_len) { - return ((opt_aro_t *)&(buffer[LLHDR_ICMPV6HDR_LEN + ext_len + - opt_len])); + return ((opt_aro_t *) & (buffer[LLHDR_ICMPV6HDR_LEN + ext_len + + opt_len])); } void init_echo_req(ipv6_addr_t *destaddr, uint16_t id, uint16_t seq, char *data, size_t data_len) @@ -176,8 +170,8 @@ void init_echo_req(ipv6_addr_t *destaddr, uint16_t id, uint16_t seq, char *data, ipv6_buf = get_ipv6_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); - + char *echo_data_buf = ((char *)echo_buf) + sizeof(struct echo_req_t); + packet_length = 0; icmp_buf->type = ICMP_ECHO_REQ; @@ -187,26 +181,26 @@ void init_echo_req(ipv6_addr_t *destaddr, uint16_t id, uint16_t seq, char *data, ipv6_buf->flowlabel = 0; ipv6_buf->nextheader = PROTO_NUM_ICMPV6; ipv6_buf->hoplimit = 0xff; - - memcpy(&ipv6_buf->destaddr, destaddr, sizeof (ipv6_addr_t)); + + memcpy(&ipv6_buf->destaddr, destaddr, sizeof(ipv6_addr_t)); ipv6_get_saddr(&ipv6_buf->srcaddr, &ipv6_buf->destaddr); echo_buf->id = id; echo_buf->seq = seq; - + memcpy(echo_data_buf, data, data_len); packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + ipv6_ext_hdr_len + ECHO_REQ_LEN + data_len; - ipv6_buf->length = packet_length-IPV6_HDR_LEN; + ipv6_buf->length = packet_length - IPV6_HDR_LEN; icmp_buf->checksum = 0; icmp_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6); - + #ifdef ENABLE_DEBUG printf("INFO: send echo request to: "); ipv6_print_addr(&ipv6_buf->destaddr); #endif - lowpan_init((ieee_802154_long_t *)&(ipv6_buf->destaddr.uint16[4]), + lowpan_init((ieee_802154_long_t *) & (ipv6_buf->destaddr.uint16[4]), (uint8_t *)ipv6_buf); } @@ -215,8 +209,8 @@ void init_echo_repl(ipv6_addr_t *destaddr, uint16_t id, uint16_t seq, char *data ipv6_buf = get_ipv6_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); - + char *echo_data_buf = ((char *)echo_buf) + sizeof(struct echo_repl_t); + packet_length = 0; icmp_buf->type = ICMP_ECHO_REPL; @@ -226,26 +220,26 @@ void init_echo_repl(ipv6_addr_t *destaddr, uint16_t id, uint16_t seq, char *data ipv6_buf->flowlabel = 0; ipv6_buf->nextheader = PROTO_NUM_ICMPV6; ipv6_buf->hoplimit = 0xff; - - memcpy(&ipv6_buf->destaddr, destaddr, sizeof (ipv6_addr_t)); + + memcpy(&ipv6_buf->destaddr, destaddr, sizeof(ipv6_addr_t)); ipv6_get_saddr(&ipv6_buf->srcaddr, &ipv6_buf->destaddr); echo_buf->id = id; echo_buf->seq = seq; - + memcpy(echo_data_buf, data, data_len); packet_length = IPV6_HDR_LEN + ICMPV6_HDR_LEN + ipv6_ext_hdr_len + ECHO_REPL_LEN + data_len; - - ipv6_buf->length = packet_length-IPV6_HDR_LEN; + + ipv6_buf->length = packet_length - IPV6_HDR_LEN; icmp_buf->checksum = 0; icmp_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6); - + #ifdef ENABLE_DEBUG printf("INFO: send echo request to: "); ipv6_print_addr(&ipv6_buf->destaddr); #endif - lowpan_init((ieee_802154_long_t *)&(ipv6_buf->destaddr.uint16[4]), + lowpan_init((ieee_802154_long_t *) & (ipv6_buf->destaddr.uint16[4]), (uint8_t *)ipv6_buf); } @@ -292,7 +286,7 @@ void init_rtr_sol(uint8_t sllao) printf("INFO: send router solicitation to: "); ipv6_print_addr(&ipv6_buf->destaddr); #endif - lowpan_init((ieee_802154_long_t *)&(ipv6_buf->destaddr.uint16[4]), + lowpan_init((ieee_802154_long_t *) & (ipv6_buf->destaddr.uint16[4]), (uint8_t *)ipv6_buf); } @@ -300,43 +294,49 @@ void recv_echo_req(void) { ipv6_buf = get_ipv6_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); + 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); + ipv6_ext_hdr_len + ECHO_REQ_LEN); #ifdef ENABLE_DEBUG printf("INFO: received echo request from: "); ipv6_print_addr(&ipv6_buf->srcaddr); printf("\n"); printf("id = 0x%04x, seq = %d\n", echo_buf->id, echo_buf->seq); + for (int i = 0; i < data_len; i++) { printf("%02x ", echo_data_buf[i]); - if ((i+1) % 16 || i == data_len-1) { + + if ((i + 1) % 16 || i == data_len - 1) { printf("\n"); } } + #endif init_echo_repl(&ipv6_buf->srcaddr, echo_buf->id, echo_buf->seq, - echo_data_buf, data_len); + echo_data_buf, data_len); } void recv_echo_repl(void) { ipv6_buf = get_ipv6_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); + 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); + ipv6_ext_hdr_len + ECHO_REPL_LEN); #ifdef ENABLE_DEBUG printf("INFO: received echo reply from: "); ipv6_print_addr(&ipv6_buf->srcaddr); printf("\n"); printf("id = 0x%04x, seq = %d\n", echo_buf->id, echo_buf->seq); + for (int i = 0; i < data_len; i++) { printf("%02x ", echo_data_buf[i]); - if ((i+1) % 16 || i == data_len-1) { + + if ((i + 1) % 16 || i == data_len - 1) { printf("\n"); } } + #endif } @@ -387,7 +387,7 @@ void recv_rtr_sol(void) printf("INFO: send router advertisment to: "); ipv6_print_addr(&ipv6_buf->destaddr); #endif - lowpan_init((ieee_802154_long_t *)&(ipv6_buf->destaddr.uint16[4]), + lowpan_init((ieee_802154_long_t *) & (ipv6_buf->destaddr.uint16[4]), (uint8_t *)ipv6_buf); } @@ -416,7 +416,7 @@ void get_opt_6co_flags(uint8_t *compression_flag, uint8_t *cid, uint8_t flags) lowpan_context_t *abr_get_context(abr_cache_t *abr, uint8_t cid); -void init_rtr_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8_t pi, +void init_rtr_adv(ipv6_addr_t *addr, uint8_t sllao, uint8_t mtu, uint8_t pi, uint8_t sixco, uint8_t abro) { lowpan_context_t *contexts = NULL; @@ -632,7 +632,7 @@ void recv_rtr_adv(void) while (packet_length > IPV6HDR_ICMPV6HDR_LEN + opt_hdr_len) { opt_buf = get_opt_buf(ipv6_ext_hdr_len, opt_hdr_len); - switch(opt_buf->type) { + switch (opt_buf->type) { case (OPT_SLLAO_TYPE): { break; } @@ -647,8 +647,8 @@ void recv_rtr_adv(void) /* crazy condition, read 5.5.3a-b-c for further information */ if (ipv6_prefix_ll_match(&opt_pi_buf->addr) || - (HTONL(opt_pi_buf->pref_ltime) > - HTONL(opt_pi_buf->val_ltime))) { + (HTONL(opt_pi_buf->pref_ltime) > + HTONL(opt_pi_buf->val_ltime))) { break; } else { @@ -684,8 +684,8 @@ void recv_rtr_adv(void) /* 7200 = 2hours in seconds */ if (HTONL(opt_pi_buf->val_ltime) > 7200 || - HTONL(opt_pi_buf->val_ltime) > - get_remaining_time(&(addr_list_ptr->val_ltime))) { + HTONL(opt_pi_buf->val_ltime) > + get_remaining_time(&(addr_list_ptr->val_ltime))) { set_remaining_time(&(addr_list_ptr->val_ltime), HTONL(opt_pi_buf->val_ltime)); } else { @@ -867,18 +867,18 @@ void recv_nbr_sol(void) while (packet_length > IPV6HDR_ICMPV6HDR_LEN + opt_hdr_len) { opt_buf = get_opt_buf(ipv6_ext_hdr_len, opt_hdr_len); - switch(opt_buf->type) { + switch (opt_buf->type) { case (OPT_SLLAO_TYPE): { opt_stllao_buf = get_opt_stllao_buf(ipv6_ext_hdr_len, opt_hdr_len); llao = (uint8_t *)opt_stllao_buf; if (llao != NULL && - !(ipv6_addr_unspec_match(&ipv6_buf->srcaddr))) { + !(ipv6_addr_unspec_match(&ipv6_buf->srcaddr))) { nbr_entry = nbr_cache_search(&(ipv6_buf->srcaddr)); if (nbr_entry != NULL) { - switch(opt_stllao_buf->length) { + switch (opt_stllao_buf->length) { case (1): { if (memcmp(&llao[2], &(nbr_entry->saddr), 2) == 0) { nbr_entry->isrouter = 0; @@ -910,7 +910,7 @@ void recv_nbr_sol(void) } } else { - switch(opt_stllao_buf->length) { + switch (opt_stllao_buf->length) { case (1): { nbr_cache_add(&ipv6_buf->srcaddr, NULL , 0, NBR_STATUS_STALE, @@ -943,12 +943,12 @@ void recv_nbr_sol(void) /* 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)) && - sllao_set == 1) { + sllao_set == 1) { opt_aro_buf = get_opt_aro_buf(ipv6_ext_hdr_len, opt_hdr_len); if ((opt_aro_buf->length == 2) && - (opt_aro_buf->status == 0)) { + (opt_aro_buf->status == 0)) { /* check neighbor cache for duplicates */ nbr_entry = nbr_cache_search(&(ipv6_buf->srcaddr)); @@ -961,7 +961,7 @@ void recv_nbr_sol(void) } else { if (memcmp(&(nbr_entry->addr.uint16[4]), - &(opt_aro_buf->eui64.uint16[0]), 8) == 0) { + &(opt_aro_buf->eui64.uint16[0]), 8) == 0) { /* update neighbor cache entry */ if (opt_aro_buf->reg_ltime == 0) { /* delete neighbor cache entry */ @@ -1004,7 +1004,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_sol_node_mcast_match(&ipv6_buf->destaddr)) { memcpy(&(ipv6_buf->destaddr.uint8[0]), &(ipv6_buf->srcaddr.uint8[0]), 16); memcpy(&(ipv6_buf->srcaddr.uint8[0]), @@ -1093,7 +1093,7 @@ void recv_nbr_adv(void) while (packet_length > IPV6HDR_ICMPV6HDR_LEN + opt_hdr_len) { opt_buf = get_opt_buf(ipv6_ext_hdr_len, opt_hdr_len); - switch(opt_buf->type) { + switch (opt_buf->type) { case (OPT_TLLAO_TYPE): { llao = (uint8_t *)get_opt_stllao_buf(ipv6_ext_hdr_len, opt_hdr_len); @@ -1148,8 +1148,8 @@ void recv_nbr_adv(void) } else { if ((nbr_adv_buf->rso & NBR_ADV_FLAG_O) || - (!(nbr_adv_buf->rso & NBR_ADV_FLAG_O) && llao != 0 && - !new_ll)) { + (!(nbr_adv_buf->rso & NBR_ADV_FLAG_O) && llao != 0 && + !new_ll)) { if (llao != 0) { memcpy(&nbr_entry->laddr, &llao[2], 8); } @@ -1179,7 +1179,7 @@ void set_llao(opt_stllao_t *sllao, uint8_t type, uint8_t length) uint8_t *llao = (uint8_t *)sllao; /* get link layer address */ - switch(length) { + switch (length) { case (1): { memcpy(&llao[2], &(iface.saddr), 2); memset(&llao[4], 0, 4); @@ -1294,7 +1294,7 @@ void nbr_cache_auto_rem(void) for (i = 0; i < NBR_CACHE_SIZE; i++) { if (get_remaining_time(&(nbr_cache[i].ltime)) == 0 && - nbr_cache[i].type == NBR_CACHE_TYPE_TEN) { + nbr_cache[i].type == NBR_CACHE_TYPE_TEN) { memmove(&(nbr_cache[i]), &(nbr_cache[nbr_count]), sizeof(nbr_cache_t)); memset(&(nbr_cache[nbr_count]), 0, sizeof(nbr_cache_t)); @@ -1364,9 +1364,9 @@ abr_cache_t *abr_get_version(uint16_t version, ipv6_addr_t *abr_addr) for (i = 0; i < ABR_CACHE_SIZE; i++) { if (abr_cache[i].version == version && - memcmp(&(abr_cache[i].abr_addr.uint8[0]), - &(abr_addr->uint8[0]), 16 - ) == 0) { + memcmp(&(abr_cache[i].abr_addr.uint8[0]), + &(abr_addr->uint8[0]), 16 + ) == 0) { return &(abr_cache[i]); } } @@ -1424,7 +1424,7 @@ def_rtr_lst_t *def_rtr_lst_search(ipv6_addr_t *ipaddr) for (i = 0; i < DEF_RTR_LST_SIZE; i++) { if (memcmp(&def_rtr_lst[i].addr.uint8[0], - &(ipaddr->uint8[0]), 16) == 0) { + &(ipaddr->uint8[0]), 16) == 0) { return &def_rtr_lst[i]; } } diff --git a/sys/net/sixlowpan/icmp.h b/sys/net/sixlowpan/icmp.h index 9d906e9a5a36d5d0820f9f750728a53add69d435..e635dcfc68a7fda875352f2cfd0d7b8cde7c72a3 100644 --- a/sys/net/sixlowpan/icmp.h +++ b/sys/net/sixlowpan/icmp.h @@ -274,7 +274,7 @@ uint16_t icmpv6_csum(uint8_t proto); def_rtr_lst_t *def_rtr_lst_search(ipv6_addr_t *ipaddr); void def_rtr_lst_add(ipv6_addr_t *ipaddr, uint32_t rtr_ltime); void def_rtr_lst_rem(def_rtr_lst_t *entry); -void init_para_prob(ipv6_addr_t *src, ipv6_addr_t *dest, uint8_t code, +void init_para_prob(ipv6_addr_t *src, ipv6_addr_t *dest, uint8_t code, uint32_t pointer, uint8_t *packet, uint8_t packet_len); void init_nbr_sol(ipv6_addr_t *src, ipv6_addr_t *dest, ipv6_addr_t *targ, uint8_t slloa, uint8_t aro); diff --git a/sys/net/sixlowpan/ip.c b/sys/net/sixlowpan/ip.c index 8c70c4aa01ce56bf1d65e041494ac567e91ab2d0..2fc1f2d8e1090a69236352321bf1ea5d841a7b81 100644 --- a/sys/net/sixlowpan/ip.c +++ b/sys/net/sixlowpan/ip.c @@ -1,5 +1,5 @@ /** - * IPv6 implementation + * IPv6 implementation * * Copyright (C) 2013 INRIA. * @@ -10,7 +10,7 @@ * @ingroup sixlowpan * @{ * @file sixlowip.c - * @brief 6lowpan IP layer functions + * @brief 6lowpan IP layer functions * @author Stephan Zeisberg <zeisberg@mi.fu-berlin.de> * @author Martin Lenders <mlenders@inf.fu-berlin.de> * @author Eric Engel <eric.engel@fu-berlin.de> @@ -20,13 +20,16 @@ #include <stdio.h> #include <string.h> -#include <vtimer.h> -#include <mutex.h> + +#include "vtimer.h" +#include "mutex.h" #include "msg.h" + #include "ip.h" #include "mac.h" #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" @@ -55,11 +58,10 @@ uint8_t *get_payload_buf_send(uint8_t ext_len) ipv6_hdr_t *get_ipv6_buf(void) { - return ((ipv6_hdr_t *)&(buffer[LL_HDR_LEN])); + return ((ipv6_hdr_t *) & (buffer[LL_HDR_LEN])); } -struct icmpv6_hdr_t *get_icmpv6_buf(uint8_t ext_len) -{ +struct icmpv6_hdr_t *get_icmpv6_buf(uint8_t ext_len) { return ((struct icmpv6_hdr_t *) & (buffer[LLHDR_IPV6HDR_LEN + ext_len])); } @@ -105,13 +107,13 @@ void sixlowpan_send(ipv6_addr_t *addr, uint8_t *payload, uint16_t p_len, packet_length = IPV6_HDR_LEN + p_len; - lowpan_init((ieee_802154_long_t *)&(ipv6_buf->destaddr.uint16[4]), + lowpan_init((ieee_802154_long_t *) & (ipv6_buf->destaddr.uint16[4]), (uint8_t *)ipv6_buf); } int icmpv6_demultiplex(const struct icmpv6_hdr_t *hdr) { - switch(hdr->type) { + switch (hdr->type) { case (ICMP_ECHO_REQ): { puts("INFO: packet type: icmp echo request"); /* processing echo request */ @@ -193,14 +195,14 @@ void ipv6_process(void) nextheader = &ipv6_buf->nextheader; if ((ipv6_get_addr_match(&myaddr, &ipv6_buf->destaddr) >= 112) && - (ipv6_buf->destaddr.uint8[15] != myaddr.uint8[15])) { + (ipv6_buf->destaddr.uint8[15] != myaddr.uint8[15])) { memcpy(get_ipv6_buf_send(), get_ipv6_buf(), IPV6_HDR_LEN + ipv6_buf->length); - lowpan_init((ieee_802154_long_t *)&(ipv6_buf->destaddr.uint16[4]), + lowpan_init((ieee_802154_long_t *) & (ipv6_buf->destaddr.uint16[4]), (uint8_t *)get_ipv6_buf_send()); } else { - switch(*nextheader) { + switch (*nextheader) { case (PROTO_NUM_ICMPV6): { /* checksum test*/ if (icmpv6_csum(PROTO_NUM_ICMPV6) != 0xffff) { @@ -277,7 +279,7 @@ void ipv6_iface_add_addr(ipv6_addr_t *addr, uint8_t state, uint32_t val_ltime, /* 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) { + type == ADDR_TYPE_GLOBAL || type == ADDR_TYPE_UNICAST) { ipv6_addr_t sol_node_mcast_addr; ipv6_set_sol_node_mcast_addr(addr, &sol_node_mcast_addr); @@ -294,7 +296,7 @@ addr_list_t *ipv6_iface_addr_match(ipv6_addr_t *addr) for (i = 0; i < iface_addr_list_count; i++) { if (memcmp(&(iface.addr_list[i].addr.uint8[0]), - &(addr->uint8[0]), 16) == 0) { + &(addr->uint8[0]), 16) == 0) { return &(iface.addr_list[i]); } } @@ -308,7 +310,7 @@ addr_list_t *ipv6_iface_addr_prefix_eq(ipv6_addr_t *addr) for (i = 0; i < iface_addr_list_count; i++) { if (memcmp(&(iface.addr_list[i].addr.uint8[0]), - &(addr->uint8[0]), 8) == 0) { + &(addr->uint8[0]), 8) == 0) { return &(iface.addr_list[i]); } } @@ -405,7 +407,7 @@ 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))) { + ipv6_prefix_ll_match(&(iface.addr_list[j].addr))) { itmp = j; } } @@ -490,9 +492,9 @@ uint8_t ipv6_prefix_mcast_match(ipv6_addr_t *addr) uint8_t ipv6_addr_unspec_match(ipv6_addr_t *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)) { + (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; } @@ -503,10 +505,10 @@ uint8_t ipv6_addr_sol_node_mcast_match(ipv6_addr_t *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)) { + (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; } diff --git a/sys/net/sixlowpan/ip.h b/sys/net/sixlowpan/ip.h index 355c00dde88bf120b0911d560c4e827b0640c449..db948544cd706db5544762ac8b26db686fc90fe9 100644 --- a/sys/net/sixlowpan/ip.h +++ b/sys/net/sixlowpan/ip.h @@ -24,8 +24,9 @@ #define _SIXLOWPAN_IP_H #include <stdint.h> -#include <timex.h> -#include <mutex.h> + +#include "timex.h" +#include "mutex.h" /* set maximum transmission unit */ #define MTU 256 diff --git a/sys/net/sixlowpan/lowpan.c b/sys/net/sixlowpan/lowpan.c index 8d42d950b6766edacd0d24c3b9b6fa14a1d390ea..af506e5bef485cd6d1905fe6c743ad18eeaf48a6 100644 --- a/sys/net/sixlowpan/lowpan.c +++ b/sys/net/sixlowpan/lowpan.c @@ -10,7 +10,7 @@ * @ingroup sixlowpan * @{ * @file sixlowpan.c - * @brief 6lowpan functions + * @brief 6lowpan functions * @author Stephan Zeisberg <zeisberg@mi.fu-berlin.de> * @author Martin Lenders <mlenders@inf.fu-berlin.de> * @author Oliver Gesch <oliver.gesch@googlemail.com> @@ -18,7 +18,6 @@ * @} */ -#include "ip.h" #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -31,12 +30,14 @@ #include "mutex.h" #include "hwtimer.h" #include "msg.h" +#include "transceiver.h" + #include "mac.h" #include "lowpan.h" #include "border.h" #include "ip.h" #include "icmp.h" -#include "transceiver.h" + #include "sys/net/ieee802154/ieee802154_frame.h" #include "sys/net/destiny/in.h" #include "sys/net/net_help/net_help.h" @@ -207,7 +208,7 @@ void printFIFOBuffers(void) while (temp_buffer != NULL) { printLongLocalAddr(&temp_buffer->s_laddr); printf("Ident.: %i, Packet Size: %i/%i, Timestamp: %li\n", - temp_buffer->ident_no, temp_buffer->current_packet_size, + temp_buffer->ident_no, temp_buffer->current_packet_size, temp_buffer->packet_size, temp_buffer->timestamp); temp_interval = temp_buffer->interval_list_head; @@ -353,10 +354,10 @@ lowpan_reas_buf_t *get_packet_frag_buf(uint16_t datagram_size, while (current_buf != NULL) { if (((ll_get_addr_match(¤t_buf->s_laddr, s_laddr)) == 64) && - ((ll_get_addr_match(¤t_buf->d_laddr, d_laddr)) == 64) && - (current_buf->packet_size == datagram_size) && - (current_buf->ident_no == datagram_tag) && - current_buf->interval_list_head != NULL) { + ((ll_get_addr_match(¤t_buf->d_laddr, d_laddr)) == 64) && + (current_buf->packet_size == datagram_size) && + (current_buf->ident_no == datagram_tag) && + current_buf->interval_list_head != NULL) { /* Found buffer for current packet fragment */ timex_t now; vtimer_now(&now); @@ -378,8 +379,8 @@ uint8_t isInInterval(uint8_t start1, uint8_t end1, uint8_t start2, uint8_t end2) /* 0: Interval 1 and 2 are not overlapping or the same */ if (((start1 < start2) && (start2 <= end1)) || - ((start2 < start1) && (start1 <= end2)) || - ((start1 == start2) && (end1 == end2))) { + ((start2 < start1) && (start1 <= end2)) || + ((start1 == start2) && (end1 == end2))) { return 1; } else { @@ -505,7 +506,7 @@ lowpan_reas_buf_t *collect_garbage(lowpan_reas_buf_t *current_buf) return return_buf; } -void handle_packet_fragment(uint8_t *data, uint8_t datagram_offset, +void handle_packet_fragment(uint8_t *data, uint8_t datagram_offset, uint16_t datagram_size, uint16_t datagram_tag, ieee_802154_long_t *s_laddr, ieee_802154_long_t *d_laddr, uint8_t hdr_length, @@ -516,8 +517,8 @@ void handle_packet_fragment(uint8_t *data, uint8_t datagram_offset, current_buf = get_packet_frag_buf(datagram_size, datagram_tag, s_laddr, d_laddr); if ((current_buf != NULL) && (handle_packet_frag_interval(current_buf, - datagram_offset, - frag_size) == 1)) { + datagram_offset, + frag_size) == 1)) { /* Copy fragment bytes into corresponding packet space area */ memcpy(current_buf->packet + datagram_offset, data + hdr_length, frag_size); current_buf->current_packet_size += frag_size; @@ -633,7 +634,7 @@ void lowpan_read(uint8_t *data, uint8_t length, ieee_802154_long_t *s_laddr, /* get 16-bit datagram tag */ datagram_tag = (((uint16_t)(data[2] << 8)) | data[3]); - switch(data[0] & 0xf8) { + switch (data[0] & 0xf8) { /* First Fragment */ case (0xc0): { datagram_offset = 0; @@ -665,7 +666,7 @@ void lowpan_read(uint8_t *data, uint8_t length, ieee_802154_long_t *s_laddr, /* Regular Packet */ else { lowpan_reas_buf_t *current_buf = get_packet_frag_buf(length, 0, s_laddr, - d_laddr); + d_laddr); /* Copy packet bytes into corresponding packet space area */ memcpy(current_buf->packet, data, length); current_buf->current_packet_size += length; @@ -711,12 +712,12 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra, tc = (tc >> 2) | (tc << 6); if ((ipv6_buf->flowlabel == 0) && - (ipv6_buf->trafficclass_flowlabel & 0x0f) == 0) { + (ipv6_buf->trafficclass_flowlabel & 0x0f) == 0) { /* flowlabel is elided */ lowpan_iphc[0] |= LOWPAN_IPHC_FL_C; if (((ipv6_buf->version_trafficclass & 0x0f) == 0) && - ((ipv6_buf->trafficclass_flowlabel & 0xf0) == 0)) { + ((ipv6_buf->trafficclass_flowlabel & 0xf0) == 0)) { /* traffic class is elided */ lowpan_iphc[0] |= LOWPAN_IPHC_TC_C; } @@ -729,7 +730,7 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra, else { /* flowlabel not compressible */ if (((ipv6_buf->version_trafficclass & 0x0f) == 0) && - ((ipv6_buf->trafficclass_flowlabel & 0xf0) == 0)) { + ((ipv6_buf->trafficclass_flowlabel & 0xf0) == 0)) { /* traffic class is elided */ lowpan_iphc[0] |= LOWPAN_IPHC_TC_C; /* ECN + 2-bit Pad + Flow Label (3 bytes), DSCP is elided */ @@ -752,7 +753,7 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra, hdr_pos++; /* HLIM: Hop Limit: */ - switch(ipv6_buf->hoplimit) { + switch (ipv6_buf->hoplimit) { case (1): { /* 01: The Hop Limit field is compressed and the hop limit is 1. */ lowpan_iphc[0] |= 0x01; @@ -782,7 +783,7 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra, /* CID: Context Identifier Extension: */ if ((lowpan_context_lookup(&ipv6_buf->srcaddr) != NULL) || - (lowpan_context_lookup(&ipv6_buf->destaddr) != NULL)) { + (lowpan_context_lookup(&ipv6_buf->destaddr) != NULL)) { lowpan_iphc[1] |= LOWPAN_IPHC_CID; memmove(&ipv6_hdr_fields[1], &ipv6_hdr_fields[0], hdr_pos); hdr_pos++; @@ -805,9 +806,9 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra, lowpan_iphc[1] |= 0x30; } else if ((ipv6_buf->srcaddr.uint16[4] == 0) && - (ipv6_buf->srcaddr.uint16[5] == 0) && - (ipv6_buf->srcaddr.uint16[6] == 0) && - ((ipv6_buf->srcaddr.uint8[14]) & 0x80) == 0) { + (ipv6_buf->srcaddr.uint16[5] == 0) && + (ipv6_buf->srcaddr.uint16[6] == 0) && + ((ipv6_buf->srcaddr.uint8[14]) & 0x80) == 0) { /* 49-bit of interface identifier are 0, so we can compress * source address-iid to 16-bit */ memcpy(&ipv6_hdr_fields[hdr_pos], &ipv6_buf->srcaddr.uint16[7], 2); @@ -832,9 +833,9 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra, lowpan_iphc[1] |= 0x30; } else if ((ipv6_buf->srcaddr.uint16[4] == 0) && - (ipv6_buf->srcaddr.uint16[5] == 0) && - (ipv6_buf->srcaddr.uint16[6] == 0) && - ((ipv6_buf->srcaddr.uint8[14]) & 0x80) == 0) { + (ipv6_buf->srcaddr.uint16[5] == 0) && + (ipv6_buf->srcaddr.uint16[6] == 0) && + ((ipv6_buf->srcaddr.uint8[14]) & 0x80) == 0) { /* 49-bit of interface identifier are 0, so we can compress * source address-iid to 16-bit */ memcpy(&ipv6_hdr_fields[hdr_pos], &ipv6_buf->srcaddr.uint16[7], 2); @@ -864,24 +865,24 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra, /* just another cool if condition */ if ((ipv6_buf->destaddr.uint8[1] == 2) && - (ipv6_buf->destaddr.uint16[1] == 0) && - (ipv6_buf->destaddr.uint16[2] == 0) && - (ipv6_buf->destaddr.uint16[3] == 0) && - (ipv6_buf->destaddr.uint16[4] == 0) && - (ipv6_buf->destaddr.uint16[5] == 0) && - (ipv6_buf->destaddr.uint16[6] == 0) && - (ipv6_buf->destaddr.uint8[14] == 0)) { + (ipv6_buf->destaddr.uint16[1] == 0) && + (ipv6_buf->destaddr.uint16[2] == 0) && + (ipv6_buf->destaddr.uint16[3] == 0) && + (ipv6_buf->destaddr.uint16[4] == 0) && + (ipv6_buf->destaddr.uint16[5] == 0) && + (ipv6_buf->destaddr.uint16[6] == 0) && + (ipv6_buf->destaddr.uint8[14] == 0)) { /* 11: 8 bits. The address takes the form FF02::00XX. */ lowpan_iphc[1] |= 0x03; ipv6_hdr_fields[hdr_pos] = ipv6_buf->destaddr.uint8[15]; hdr_pos++; } else if ((ipv6_buf->destaddr.uint16[1] == 0) && - (ipv6_buf->destaddr.uint16[2] == 0) && - (ipv6_buf->destaddr.uint16[3] == 0) && - (ipv6_buf->destaddr.uint16[4] == 0) && - (ipv6_buf->destaddr.uint16[5] == 0) && - (ipv6_buf->destaddr.uint8[12] == 0)) { + (ipv6_buf->destaddr.uint16[2] == 0) && + (ipv6_buf->destaddr.uint16[3] == 0) && + (ipv6_buf->destaddr.uint16[4] == 0) && + (ipv6_buf->destaddr.uint16[5] == 0) && + (ipv6_buf->destaddr.uint8[12] == 0)) { /* 10: 32 bits. The address takes the form FFXX::00XX:XXXX. */ lowpan_iphc[1] |= 0x02; /* copy second and last 3 byte */ @@ -891,10 +892,10 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra, hdr_pos += 3; } else if ((ipv6_buf->destaddr.uint16[1] == 0) && - (ipv6_buf->destaddr.uint16[2] == 0) && - (ipv6_buf->destaddr.uint16[3] == 0) && - (ipv6_buf->destaddr.uint16[4] == 0) && - (ipv6_buf->destaddr.uint8[10] == 0)) { + (ipv6_buf->destaddr.uint16[2] == 0) && + (ipv6_buf->destaddr.uint16[3] == 0) && + (ipv6_buf->destaddr.uint16[4] == 0) && + (ipv6_buf->destaddr.uint8[10] == 0)) { /* 01: 48 bits. The address takes the form FFXX::00XX:XXXX:XXXX */ lowpan_iphc[1] |= 0x01; /* copy second and last 5 byte */ @@ -922,9 +923,9 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra, lowpan_iphc[1] |= 0x03; } else if ((ipv6_buf->destaddr.uint16[4] == 0) && - (ipv6_buf->destaddr.uint16[5] == 0) && - (ipv6_buf->destaddr.uint16[6] == 0) && - ((ipv6_buf->destaddr.uint8[14]) & 0x80) == 0) { + (ipv6_buf->destaddr.uint16[5] == 0) && + (ipv6_buf->destaddr.uint16[6] == 0) && + ((ipv6_buf->destaddr.uint8[14]) & 0x80) == 0) { /* 49-bit of interface identifier are 0, so we can compress * source address-iid to 16-bit */ memcpy(&ipv6_hdr_fields[hdr_pos], &ipv6_buf->destaddr.uint16[7], 2); @@ -948,9 +949,9 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra, lowpan_iphc[1] |= 0x03; } else if ((ipv6_buf->destaddr.uint16[4] == 0) && - (ipv6_buf->destaddr.uint16[5] == 0) && - (ipv6_buf->destaddr.uint16[6] == 0) && - ((ipv6_buf->destaddr.uint8[14]) & 0x80) == 0) { + (ipv6_buf->destaddr.uint16[5] == 0) && + (ipv6_buf->destaddr.uint16[6] == 0) && + ((ipv6_buf->destaddr.uint8[14]) & 0x80) == 0) { /* 49-bit of interface identifier are 0, so we can compress * source address-iid to 16-bit */ memcpy(&ipv6_hdr_fields[hdr_pos], &ipv6_buf->destaddr.uint16[7], 2); @@ -1076,7 +1077,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length, /* HLIM: Hop Limit: */ if (lowpan_iphc[0] & 0x03) { - switch(lowpan_iphc[0] & 0x03) { + switch (lowpan_iphc[0] & 0x03) { case (0x01): { ipv6_buf->hoplimit = 1; break; @@ -1121,7 +1122,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length, return; } - switch(((lowpan_iphc[1] & LOWPAN_IPHC_SAM) >> 4) & 0x03) { + switch (((lowpan_iphc[1] & LOWPAN_IPHC_SAM) >> 4) & 0x03) { case (0x01): { /* 64-bits */ memcpy(&(ipv6_buf->srcaddr.uint8[8]), &ipv6_hdr_fields[hdr_pos], 8); @@ -1163,7 +1164,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length, mutex_unlock(&lowpan_context_mutex); } else { - switch(((lowpan_iphc[1] & LOWPAN_IPHC_SAM) >> 4) & 0x03) { + switch (((lowpan_iphc[1] & LOWPAN_IPHC_SAM) >> 4) & 0x03) { case (0x01): { /* 64-bits */ memcpy(&(ipv6_buf->srcaddr.uint8[0]), &ll_prefix[0], 2); @@ -1227,7 +1228,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length, } else { /* If M=1 and DAC=0: */ - switch(lowpan_iphc[1] & 0x03) { + switch (lowpan_iphc[1] & 0x03) { case (0x01): { m_prefix[1] = ipv6_hdr_fields[hdr_pos]; hdr_pos++; @@ -1244,7 +1245,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length, break; } - switch(lowpan_iphc[1] & 0x03) { + switch (lowpan_iphc[1] & 0x03) { case (0x01): { memcpy(&(ipv6_buf->destaddr.uint8[0]), &m_prefix[0], 2); memset(&(ipv6_buf->destaddr.uint8[2]), 0, 9); @@ -1296,7 +1297,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length, return; } - switch((lowpan_iphc[1] & LOWPAN_IPHC_DAM) & 0x03) { + switch ((lowpan_iphc[1] & LOWPAN_IPHC_DAM) & 0x03) { case (0x01): { memcpy(&(ipv6_buf->destaddr.uint8[8]), &ipv6_hdr_fields[hdr_pos], 8); /* By draft-ietf-6lowpan-hc-15 3.1.1. Bits covered by context information are always used. */ @@ -1329,7 +1330,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length, mutex_unlock(&lowpan_context_mutex); } else { - switch((lowpan_iphc[1] & LOWPAN_IPHC_DAM) & 0x03) { + switch ((lowpan_iphc[1] & LOWPAN_IPHC_DAM) & 0x03) { case (0x01): { memcpy(&(ipv6_buf->destaddr.uint8[0]), &ll_prefix[0], 2); memset(&(ipv6_buf->destaddr.uint8[2]), 0, 6); @@ -1441,7 +1442,7 @@ lowpan_context_t *lowpan_context_lookup(ipv6_addr_t *addr) for (i = 0; i < lowpan_context_len(); i++) { if (contexts[i].length > 0 && memcmp((void *)addr, &(contexts[i].prefix), - contexts[i].length) == 0) { + contexts[i].length) == 0) { /* longer prefixes are always prefered */ if (context == NULL || context->length < contexts[i].length) { context = &contexts[i]; diff --git a/sys/net/sixlowpan/lowpan.h b/sys/net/sixlowpan/lowpan.h index 58024ccf2d8abab4493b190ba320d28700c013b8..5b9393b3263865e73decfdf8fa5f95266928c653 100644 --- a/sys/net/sixlowpan/lowpan.h +++ b/sys/net/sixlowpan/lowpan.h @@ -10,7 +10,7 @@ * @ingroup sixlowpan * @{ * @file sixlowpan.h - * @brief 6lowpan header + * @brief 6lowpan header * @author Stephan Zeisberg <zeisberg@mi.fu-berlin.de> * @author Martin Lenders <mlenders@inf.fu-berlin.de> * @author Oliver Gesch <oliver.gesch@googlemail.com> @@ -118,7 +118,7 @@ void sixlowpan_init(transceiver_type_t trans, uint8_t r_addr, int as_border); * @param[in] prefix the address prefix to advertise * @param[in] r_addr phy layer address */ -void sixlowpan_adhoc_init(transceiver_type_t trans, ipv6_addr_t *prefix, +void sixlowpan_adhoc_init(transceiver_type_t trans, ipv6_addr_t *prefix, uint8_t r_addr); void lowpan_init(ieee_802154_long_t *addr, uint8_t *data); void lowpan_read(uint8_t *data, uint8_t length, ieee_802154_long_t *s_laddr, diff --git a/sys/net/sixlowpan/mac.c b/sys/net/sixlowpan/mac.c index 507c214cc70947a865a1df80e70f0e06911b1296..d7ecd1c030e05d79d698c365a89efc4b48eaa339 100644 --- a/sys/net/sixlowpan/mac.c +++ b/sys/net/sixlowpan/mac.c @@ -9,8 +9,8 @@ * * @ingroup sixlowpan * @{ - * @file sixlowmac.c - * @brief 6lowpan link layer functions + * @file sixlowmac.c + * @brief 6lowpan link layer functions * @author Stephan Zeisberg <zeisberg@mi.fu-berlin.de> * @author Martin Lenders <mlenders@inf.fu-berlin.de> * @author Eric Engel <eric.engel@fu-berlin.de> @@ -21,20 +21,21 @@ #include <stdlib.h> +#include <stdint.h> #include <string.h> -#include <inttypes.h> -#include "mac.h" -#include "ip.h" -#include "icmp.h" -#include "lowpan.h" -#include <ltc4150.h> -#include <hwtimer.h> +#include "ltc4150.h" +#include "hwtimer.h" #include "thread.h" #include "msg.h" #include "radio/radio.h" #include "transceiver.h" #include "vtimer.h" + +#include "mac.h" +#include "ip.h" +#include "icmp.h" +#include "lowpan.h" #include "sys/net/ieee802154/ieee802154_frame.h" #include "sys/net/net_help/net_help.h" diff --git a/sys/net/sixlowpan/mac.h b/sys/net/sixlowpan/mac.h index 85f4a1fb935ba47903e7f6662e975db5b7261d06..e3e0cbc870bf75a5025578155bbc345fc0062416 100644 --- a/sys/net/sixlowpan/mac.h +++ b/sys/net/sixlowpan/mac.h @@ -23,9 +23,11 @@ #include <stdio.h> #include <stdint.h> -#include "ip.h" + #include "radio/radio.h" -#include <transceiver.h> +#include "transceiver.h" + +#include "ip.h" #define RADIO_STACK_SIZE (MINIMUM_STACK_SIZE + 256) #define RADIO_RCV_BUF_SIZE (64) diff --git a/sys/net/sixlowpan/semaphore.c b/sys/net/sixlowpan/semaphore.c index 67ac13ca1dece33517dc35dc8f2f115699aa1376..6e2e837d53e07ab54604148074d068656370d77e 100644 --- a/sys/net/sixlowpan/semaphore.c +++ b/sys/net/sixlowpan/semaphore.c @@ -1,5 +1,5 @@ /** - * Semaphore implemenation + * Semaphore implemenation * * Copyright (C) 2013 INRIA. * @@ -16,8 +16,6 @@ * @} */ -#include <mutex.h> - #include "semaphore.h" void sem_init(sem_t *sem, int8_t value) diff --git a/sys/net/sixlowpan/semaphore.h b/sys/net/sixlowpan/semaphore.h index 6394e603628df1edcab72c8ccb7af5786bb3afa8..3acb650b473dfd5dfe1f96d37e06e8ae62a596ee 100644 --- a/sys/net/sixlowpan/semaphore.h +++ b/sys/net/sixlowpan/semaphore.h @@ -20,7 +20,8 @@ #define _SIXLOWPAN_SEMAPHORE_H #include <stdint.h> -#include <mutex.h> + +#include "mutex.h" typedef struct sem_t { int8_t value; diff --git a/sys/net/sixlowpan/serialnumber.c b/sys/net/sixlowpan/serialnumber.c index b1fad78016be70d064234890aeba15f33d0b34e8..f774b76627d4612017d5995af9468f43af29539d 100644 --- a/sys/net/sixlowpan/serialnumber.c +++ b/sys/net/sixlowpan/serialnumber.c @@ -1,5 +1,5 @@ /** - * serial number arithmetics (corresponding RFC1982) for version field in ABRO + * serial number arithmetics (corresponding RFC1982) for version field in ABRO * * Copyright (C) 2013 INRIA. * @@ -10,7 +10,7 @@ * @ingroup sixlowpan * @{ * @file serialnumber.c - * @brief serial number arithmetics (corresponding RFC1982) for version field in ABRO + * @brief serial number arithmetics (corresponding RFC1982) for version field in ABRO * @author Martin Lenders <mlenders@inf.fu-berlin.de> * @author Oliver Hahm <oliver.hahm@inria.fr> * @}