Skip to content

Commit

Permalink
Merge pull request ARMmbed#1738 from ARMmbed/master_merge_to_koli
Browse files Browse the repository at this point in the history
Master merge to koli
  • Loading branch information
juhhei01 committed Jun 29, 2018
2 parents 03bc696 + abee481 commit 5a1f295
Show file tree
Hide file tree
Showing 49 changed files with 791 additions and 389 deletions.
Expand Up @@ -91,7 +91,10 @@ static int8_t set_6lowpan_nwk_down(protocol_interface_info_entry_t *cur)
}
#endif
}
uint16_t pan_id = cur->mac_parameters->pan_id;
if (cur->lowpan_info & INTERFACE_NWK_BOOTSRAP_PANA_AUTHENTICATION) {
pana_reset_values(cur->mac_parameters->pan_id);
}

if (cur->interface_mode == INTERFACE_UP) {
if (cur->mac_api) {
mlme_reset_t reset;
Expand All @@ -109,9 +112,6 @@ static int8_t set_6lowpan_nwk_down(protocol_interface_info_entry_t *cur)
reassembly_interface_reset(cur->id);

icmp_nd_routers_init();
if (cur->lowpan_info & INTERFACE_NWK_BOOTSRAP_PANA_AUTHENTICATION) {
pana_reset_values(pan_id);
}

if (cur->pana_sec_info_temp) {
ns_dyn_mem_free(cur->pana_sec_info_temp);
Expand Down
2 changes: 2 additions & 0 deletions source/6LoWPAN/MAC/mac_helper.c
Expand Up @@ -767,8 +767,10 @@ static uint8_t mac_helper_header_security_aux_header_length(uint8_t keyIdmode) {
switch (keyIdmode) {
case MAC_KEY_ID_MODE_SRC8_IDX:
header_length += 4; //64-bit key source first part
/* fall through */
case MAC_KEY_ID_MODE_SRC4_IDX:
header_length += 4; //32-bit key source inline
/* fall through */
case MAC_KEY_ID_MODE_IDX:
header_length += 1;
break;
Expand Down
49 changes: 21 additions & 28 deletions source/6LoWPAN/Thread/thread_address_registration_client.c
Expand Up @@ -58,62 +58,55 @@

static bool enabled = false;
static uint32_t addr_notificastion_timer;
static uint32_t mlr_timer;

void thread_address_registration_init()
{
enabled = true;
addr_notificastion_timer = THREAD_PROACTIVE_AN_INTERVAL;
mlr_timer = 0;
}

void thread_address_registration_deinit()
{
enabled = false;
}

void thread_address_registration_timer_set(protocol_interface_info_entry_t *interface, uint16_t seconds)
void thread_address_registration_timer_set(protocol_interface_info_entry_t *interface, uint16_t dua_delay_seconds, uint16_t mlr_refresh_seconds)
{
(void)interface;
addr_notificastion_timer = seconds;
/* trigger multicast registrations */
ns_list_foreach(if_group_entry_t, cur, &interface->ip_groups) {
if (addr_ipv6_multicast_scope(cur->group) < IPV6_SCOPE_ADMIN_LOCAL) {
continue;
}
if (addr_ipv6_equal(cur->group, ADDR_SITE_LOCAL_ALL_ROUTERS)) {
continue;
}
cur->mld_timer = seconds;
if (dua_delay_seconds != 0) {
addr_notificastion_timer = dua_delay_seconds;
}
if (mlr_refresh_seconds != 0) {
mlr_timer = mlr_refresh_seconds;
}

}
}
void thread_address_registration_timer(protocol_interface_info_entry_t *interface, uint16_t seconds)
{
uint32_t mlr_timeout;
uint32_t delay_timer;
if (!enabled || !thread_extension_version_check(interface->thread_info->version)) {
return;
}

if (0 != thread_extension_primary_bbr_get(interface, NULL, NULL, &mlr_timeout, &delay_timer)) {
// BBR not present
return;
}
/* Update multicast addresses */
ns_list_foreach(if_group_entry_t, cur, &interface->ip_groups) {
if (addr_ipv6_multicast_scope(cur->group) < IPV6_SCOPE_ADMIN_LOCAL) {
continue;
}

if (cur->mld_timer > seconds) {
cur->mld_timer -= seconds;
} else {
cur->mld_timer = 0;
}

if (cur->mld_timer < 2) {
// Renew the multicast address
thread_extension_mcast_subscrition_change(interface, cur, true);
}
if (mlr_timer > seconds) {
mlr_timer -= seconds;
} else {
mlr_timer = mlr_timeout - randLIB_get_random_in_range(30,50);
thread_extension_mcast_subscrition_change(interface);
}
/* Update global scope addresses (children's as well) */
if (addr_notificastion_timer > seconds) {
addr_notificastion_timer -= seconds;
} else {
addr_notificastion_timer = THREAD_PROACTIVE_AN_INTERVAL + randLIB_get_random_in_range(0,60);
addr_notificastion_timer = THREAD_PROACTIVE_AN_INTERVAL + randLIB_get_random_in_range(0, delay_timer/1000);
thread_extension_address_registration_trigger(interface);
}

Expand Down
4 changes: 2 additions & 2 deletions source/6LoWPAN/Thread/thread_address_registration_client.h
Expand Up @@ -36,14 +36,14 @@
void thread_address_registration_init(void);
void thread_address_registration_deinit(void);

void thread_address_registration_timer_set(protocol_interface_info_entry_t *interface, uint16_t seconds);
void thread_address_registration_timer_set(protocol_interface_info_entry_t *interface, uint16_t dua_delay_seconds, uint16_t mlr_refresh_seconds);
void thread_address_registration_timer(protocol_interface_info_entry_t *interface, uint16_t seconds);
#else

#define thread_address_registration_init(void)
#define thread_address_registration_deinit(void)

#define thread_address_registration_timer_set(interface, seconds);
#define thread_address_registration_timer_set(interface, dua_delay_seconds, mlr_refresh_seconds);
#define thread_address_registration_timer(interface, seconds);

#endif
Expand Down
54 changes: 42 additions & 12 deletions source/6LoWPAN/Thread/thread_bbr_api.c
Expand Up @@ -738,7 +738,7 @@ static bool thread_bbr_activated(thread_bbr_t *this, uint32_t seconds)
return true;
}
// We will try to become router. This is done only in 120 seconds intervals if failed
thread_router_bootstrap_router_id_request(cur, 0);
thread_router_bootstrap_router_id_request(cur, THREAD_BBR_ROUTER_ID_REQUEST_STATUS);
this->router_upgrade_delay_timer = 120;
return false;
}
Expand All @@ -755,8 +755,8 @@ bool thread_bbr_routing_enabled(protocol_interface_info_entry_t *cur)

void thread_bbr_network_data_update_notify(protocol_interface_info_entry_t *cur)
{
(void) cur;
thread_mdns_network_data_update_notify();
thread_extension_bbr_route_update(cur);
}
#endif /* HAVE_THREAD_BORDER_ROUTER*/

Expand Down Expand Up @@ -943,7 +943,7 @@ void thread_bbr_seconds_timer(int8_t interface_id, uint32_t seconds)
#endif // HAVE_THREAD_ROUTER

#ifdef HAVE_THREAD_BORDER_ROUTER
static int thread_bbr_na_send(int8_t interface_id, const uint8_t target[static 16])
int thread_bbr_na_send(int8_t interface_id, const uint8_t target[static 16])
{
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
if (!cur) {
Expand All @@ -955,18 +955,18 @@ static int thread_bbr_na_send(int8_t interface_id, const uint8_t target[static 1
return 0;

}
int thread_bbr_nd_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr, uint32_t lifetime, void *info, const uint8_t *mleid_ptr) {
(void) mleid_ptr;

int thread_bbr_nd_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr, uint32_t lifetime, void *info)
{
thread_bbr_t *this = thread_bbr_find_by_interface(interface_id);
if (!this || this->backbone_interface_id < 0) {
tr_err("bbr not ready");
return -1;
}
ipv6_route_t *route = ipv6_route_add_with_info(addr_data_ptr, 128, interface_id, NULL, ROUTE_THREAD_PROXIED_HOST, info, 0, lifetime, 0);
// We are using route info field to store sequence number
if (!route) {
// Direct route to host allows ND proxying to work
tr_err("out of resources");
tr_err("bbr out of resources");
return -2;
}
// send NA
Expand All @@ -975,14 +975,44 @@ int thread_bbr_nd_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr,
return 0;
}

int thread_bbr_nd_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr) {
ipv6_route_t *route = ipv6_route_choose_next_hop(addr_data_ptr, interface_id, NULL);
if (!route || route->prefix_len < 128 || !route->on_link || route->info.source != ROUTE_THREAD_PROXIED_HOST ) {
//Not found
int thread_bbr_dua_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr, uint32_t lifetime, const uint8_t *mleid_ptr)
{
thread_bbr_t *this = thread_bbr_find_by_interface(interface_id);
if (!this || this->backbone_interface_id < 0) {
return -1;
}
//TODO get information to route to parameters eq mleid, timeout
thread_pbbr_dua_info_t *map = ns_dyn_mem_alloc(sizeof(thread_pbbr_dua_info_t));
if (!map) {
goto error;
}
memcpy(map->mleid_ptr, mleid_ptr, 8);
map->last_contact_time = protocol_core_monotonic_time;

// We are using route info field to store BBR MLEID map
ipv6_route_t *route = ipv6_route_add_with_info(addr_data_ptr, 128, interface_id, NULL, ROUTE_THREAD_PROXIED_DUA_HOST, map, 0, lifetime, 0);
if (!route) {
// Direct route to host allows ND proxying to work
ns_dyn_mem_free(map);
goto error;
}
// Route info autofreed
route->info_autofree = true;
// send NA
thread_bbr_na_send(this->backbone_interface_id, addr_data_ptr);

return 0;
error:
tr_err("out of resources");
return -2;
}

struct ipv6_route *thread_bbr_dua_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr) {
ipv6_route_t *route = ipv6_route_choose_next_hop(addr_data_ptr, interface_id, NULL);
if (!route || route->prefix_len < 128 || !route->on_link || route->info.source != ROUTE_THREAD_PROXIED_DUA_HOST ) {
//Not found
return NULL;
}
return route;
}

int thread_bbr_proxy_state_update(int8_t caller_interface_id , int8_t handler_interface_id, bool status)
Expand Down
28 changes: 23 additions & 5 deletions source/6LoWPAN/Thread/thread_bbr_api_internal.h
Expand Up @@ -36,6 +36,8 @@

#include "net_interface.h"
#ifdef HAVE_THREAD_ROUTER
struct ipv6_route;

/**
* \brief Initialize Thread Commissioner relay for BBR and Routers
*
Expand Down Expand Up @@ -98,23 +100,39 @@ void thread_bbr_network_data_update_notify(protocol_interface_info_entry_t *cur)
/**
* \brief Add new nd entry to bbr
*
* \param interface_id addr_data_ptr lifetime info
*/
int thread_bbr_nd_entry_add(int8_t interface_id, const uint8_t *addr_data_ptr, uint32_t lifetime, void *info);

/**
* \brief Add new dua entry to bbr
*
* \param interface_id addr_data_ptr lifetime info mleid_ptr
*/
int thread_bbr_dua_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr, uint32_t lifetime, const uint8_t *mleid_ptr);

/**
* \brief Send na
*
* \param interface_id addr_data_ptr lifetime info mleid_ptr
*/
int thread_bbr_nd_entry_add(int8_t interface_id, const uint8_t *addr_data_ptr, uint32_t lifetime, void *info, const uint8_t *mleid_ptr);
int thread_bbr_na_send(int8_t interface_id, const uint8_t target[static 16]);

/**
* \brief Find if bbr has nd entry
* \brief Find if bbr has dua entry
*
* \param interface_id addr_data_ptr
*/
int thread_bbr_nd_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr);
struct ipv6_route *thread_bbr_dua_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr);

#else
#define thread_bbr_proxy_state_update(caller_interface_id , handler_interface_id, status) (NULL)
#define thread_bbr_routing_enabled(cur) false
#define thread_bbr_network_data_update_notify(cur)
#define thread_bbr_nd_entry_add(interface_id, addr_data_ptr, lifetime, info, mleid_ptr) (0)
#define thread_bbr_nd_entry_find(interface_id, addr_data_ptr) (0)
#define thread_bbr_nd_entry_add(interface_id, addr_data_ptr, lifetime, info) (0)
#define thread_bbr_dua_entry_add(interface_id, addr_data_ptr, lifetime, mleid_ptr) (0)
#define thread_bbr_dua_entry_find(interface_id, addr_data_ptr) (NULL)
#define thread_bbr_na_send(interface_id, target) (0)
#endif //HAVE_THREAD_BORDER_ROUTER


Expand Down
31 changes: 10 additions & 21 deletions source/6LoWPAN/Thread/thread_bootstrap.c
Expand Up @@ -64,6 +64,7 @@
#include "6LoWPAN/Thread/thread_network_synch.h"
#include "6LoWPAN/Thread/thread_joiner_application.h"
#include "6LoWPAN/Thread/thread_extension.h"
#include "6LoWPAN/Thread/thread_extension_bbr.h"
#include "6LoWPAN/Thread/thread_management_client.h"
#include "6LoWPAN/Thread/thread_address_registration_client.h"
#include "6LoWPAN/Thread/thread_joiner_application.h"
Expand Down Expand Up @@ -287,45 +288,31 @@ bool thread_check_is_this_my_parent(protocol_interface_info_entry_t *cur, mac_ne
bool thread_bootstrap_request_network_data(protocol_interface_info_entry_t *cur, thread_leader_data_t *leaderData, uint16_t short_address)
{
bool requestNetworkdata = false;
thread_leader_data_t *leadeInfo = thread_info(cur)->thread_leader_data;
thread_leader_data_t *leaderInfo = thread_info(cur)->thread_leader_data;

if (thread_info(cur)->thread_endnode_parent->shortAddress != short_address) {
return false;
}

if (thread_info(cur)->thread_leader_data->partitionId != leaderData->partitionId) {
if (!thread_partition_match(cur, leaderData)) {
tr_debug("Learn new Network Data");
requestNetworkdata = true;
thread_info(cur)->thread_leader_data->dataVersion = leaderData->dataVersion - 1;
thread_info(cur)->thread_leader_data->stableDataVersion = leaderData->stableDataVersion - 1;
thread_partition_info_update(cur, leaderData);
}
else if (common_serial_number_greater_8(leaderData->dataVersion, leadeInfo->dataVersion)) {
else if (common_serial_number_greater_8(leaderData->dataVersion, leaderInfo->dataVersion)) {
requestNetworkdata = true;

} else if (common_serial_number_greater_8(leaderData->stableDataVersion, leadeInfo->stableDataVersion)) {
} else if (common_serial_number_greater_8(leaderData->stableDataVersion, leaderInfo->stableDataVersion)) {
requestNetworkdata = true;

}

// Version number is updated when new network data is learned to avoid synchronization problems
thread_info(cur)->thread_leader_data->leaderRouterId = leaderData->leaderRouterId;
thread_info(cur)->thread_leader_data->partitionId = leaderData->partitionId;
if (requestNetworkdata) {
thread_bootstrap_parent_network_data_request(cur, true);
}
return true;
}

bool thread_instance_id_matches(protocol_interface_info_entry_t *cur, thread_leader_data_t *leaderData)
{
if (thread_info(cur)->thread_leader_data) {
if (thread_info(cur)->thread_leader_data->partitionId == leaderData->partitionId) {
return true;
}
}
return false;
}

static int thread_router_check_previous_partition_info(protocol_interface_info_entry_t *cur, thread_leader_data_t *leaderData, mle_tlv_info_t *routeTlv)
{
if (!routeTlv || !routeTlv->dataPtr || !routeTlv->tlvLen || !leaderData) {
Expand Down Expand Up @@ -428,8 +415,7 @@ int thread_leader_data_validation(protocol_interface_info_entry_t *cur, thread_l
if (!thread_info(cur)->thread_leader_data) {
return -1;
}
if ((thread_info(cur)->thread_leader_data->partitionId != leaderData->partitionId) ||
(thread_info(cur)->thread_leader_data->weighting != leaderData->weighting)) {
if (!thread_partition_match(cur, leaderData)) {
uint8_t routers_in_route_tlv = thread_get_router_count_from_route_tlv(routeTlv);
//partition checks
return thread_bootstrap_partition_process(cur,routers_in_route_tlv,leaderData, routeTlv);
Expand Down Expand Up @@ -722,6 +708,8 @@ int thread_configuration_thread_activate(protocol_interface_info_entry_t *cur, l

thread_extension_activate(cur);

thread_extension_bbr_route_update(cur);

blacklist_clear();

blacklist_params_set(
Expand Down Expand Up @@ -2293,6 +2281,7 @@ void thread_bootstrap_stop(protocol_interface_info_entry_t *cur)
ipv6_route_table_remove_info(cur->id, ROUTE_THREAD, NULL);
ipv6_route_table_remove_info(cur->id, ROUTE_THREAD_BORDER_ROUTER, NULL);
ipv6_route_table_remove_info(cur->id, ROUTE_THREAD_PROXIED_HOST, NULL);
ipv6_route_table_remove_info(cur->id, ROUTE_THREAD_PROXIED_DUA_HOST, NULL);
thread_leader_service_leader_data_free(cur->thread_info);
thread_bootstrap_all_nodes_multicast_unregister(cur);
thread_data_base_init(cur->thread_info, cur->id);
Expand Down
1 change: 0 additions & 1 deletion source/6LoWPAN/Thread/thread_bootstrap.h
Expand Up @@ -125,7 +125,6 @@ int thread_parent_discover_start(int8_t interface_id, uint8_t *mac64 );

bool thread_device_synch_timeout(int8_t interface_id, uint16_t msgId, bool usedAllRetries);
bool thread_link_request_timeout(int8_t interface_id, uint16_t msgId, bool usedAllRetries);
bool thread_instance_id_matches(struct protocol_interface_info_entry *cur, struct thread_leader_data_s *leaderData);
int thread_leader_data_validation(struct protocol_interface_info_entry *cur, struct thread_leader_data_s *leaderData, struct mle_tlv_info_s *routeTlv);
uint8_t thread_calculate_link_margin(int8_t dbm, uint8_t compLinkMarginFromParent);
uint8_t thread_compute_link_margin(int8_t rssi);
Expand Down

0 comments on commit 5a1f295

Please sign in to comment.