Skip to content

Commit

Permalink
Merge pull request ARMmbed#1815 from ARMmbed/iotthd-2745
Browse files Browse the repository at this point in the history
Primary Parent Update Hook for Wi-sun.
  • Loading branch information
Juha Heiskanen authored Sep 11, 2018
2 parents 98b0e23 + 5a37354 commit 4a1d595
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
10 changes: 8 additions & 2 deletions source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
#include "6LoWPAN/Fragmentation/cipv6_fragmenter.h"
#include "Service_Libs/etx/etx.h"
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
#include "6LoWPAN/ws/ws_bootstrap.h"


#define TRACE_GROUP_LOWPAN "6lo"
Expand Down Expand Up @@ -473,7 +474,6 @@ void protocol_6lowpan_neighbor_priority_update(protocol_interface_info_entry_t *
}

#ifdef HAVE_RPL
#ifndef NO_MLE

uint16_t protocol_6lowpan_neighbor_priority_set(int8_t interface_id, addrtype_t addr_type, const uint8_t *addr_ptr)
{
Expand All @@ -486,9 +486,12 @@ uint16_t protocol_6lowpan_neighbor_priority_set(int8_t interface_id, addrtype_t
mac_neighbor_table_entry_t * entry = mac_neighbor_table_address_discover(mac_neighbor_info(cur), addr_ptr + PAN_ID_LEN, addr_type);

if (entry) {

bool new_primary = false;
etx_storage_t *etx_entry = etx_storage_entry_get(interface_id, entry->index);
// If primary parent has changed clears priority from previous parent
if (entry->link_role != PRIORITY_PARENT_NEIGHBOUR) {
new_primary = true;
protocol_6lowpan_neighbor_priority_clear_all(interface_id, PRIORITY_1ST);
}
entry->link_role = PRIORITY_PARENT_NEIGHBOUR;
Expand All @@ -501,6 +504,10 @@ uint16_t protocol_6lowpan_neighbor_priority_set(int8_t interface_id, addrtype_t
if (etx_entry) {
protocol_stats_update(STATS_ETX_1ST_PARENT, etx_entry->etx >> 4);
}

if (new_primary) {
ws_primary_parent_update(cur, entry);
}
return 1;
} else {
return 0;
Expand Down Expand Up @@ -557,7 +564,6 @@ void protocol_6lowpan_neighbor_priority_clear_all(int8_t interface_id, neighbor_
}
}

#endif
#endif

#endif
Expand Down
16 changes: 13 additions & 3 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,6 @@ static void ws_bootstrap_primary_parent_set(struct protocol_interface_info_entry
// Update LLC to follow updated fhss settings
ws_bootstrap_llc_hopping_update(cur,&fhss_configuration);

// set neighbor as priority parent clear if there is others
protocol_6lowpan_neighbor_priority_clear_all(cur->id, PRIORITY_1ST);
neighbor_info->neighbor->link_role = PRIORITY_PARENT_NEIGHBOUR;

}
/* \return 0x0100 to 0xFFFF ETX value (8 bit fraction)
Expand Down Expand Up @@ -765,6 +762,9 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
cur->bootsrap_state_machine_cnt = randLIB_get_random_in_range(10 ,20);
// enable frequency hopping for unicast channel and start listening first neighbour
ws_bootstrap_primary_parent_set(cur, &neighbor_info);
// set neighbor as priority parent clear if there is others
protocol_6lowpan_neighbor_priority_clear_all(cur->id, PRIORITY_1ST);
neighbor_info.neighbor->link_role = PRIORITY_PARENT_NEIGHBOUR;
} else if (neighbor_info.neighbor->link_role == PRIORITY_PARENT_NEIGHBOUR) {
// RPL priority parent configuration we must update FHSS data
ws_bootstrap_primary_parent_set(cur, &neighbor_info);
Expand Down Expand Up @@ -1858,4 +1858,14 @@ void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t s
}
}

void ws_primary_parent_update(protocol_interface_info_entry_t *interface, mac_neighbor_table_entry_t *neighbor)
{
if (interface->ws_info) {
llc_neighbour_req_t neighbor_info;
neighbor_info.neighbor = neighbor;
neighbor_info.ws_neighbor = ws_neighbor_class_entry_get(&interface->ws_info->neighbor_storage, neighbor->index);
ws_bootstrap_primary_parent_set(interface, &neighbor_info);
}
}

#endif //HAVE_WS
3 changes: 3 additions & 0 deletions source/6LoWPAN/ws/ws_bootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t s

void ws_bootstrap_trickle_timer(protocol_interface_info_entry_t *cur, uint16_t ticks);

void ws_primary_parent_update(protocol_interface_info_entry_t *interface, mac_neighbor_table_entry_t *neighbor);

#else

#define ws_bootstrap_init(interface_id, bootstrap_mode) (-1)
#define ws_bootstrap_state_machine(cur)
#define ws_bootstrap_restart(cur)
#define ws_primary_parent_update(interface, neighbor)

#endif //HAVE_WS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ TEST_SRC_FILES = \
../../stub/adaptation_interface_stub.c \
../../stub/security_lib_stub.c \
../../stub/net_load_balance_stub.c \
../../stub/ws_bootstrap_stub.c \
../../stub/etx_stub.c \

include ../../MakefileWorker.mk
Expand Down
5 changes: 5 additions & 0 deletions test/nanostack/unittest/stub/ws_bootstrap_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,8 @@ void ws_bootstrap_configuration_trickle_reset(protocol_interface_info_entry_t *c
{

}

void ws_primary_parent_update(protocol_interface_info_entry_t *interface, mac_neighbor_table_entry_t *neighbor)
{

}

0 comments on commit 4a1d595

Please sign in to comment.