Skip to content

Commit 5a1f295

Browse files
authored
Merge pull request ARMmbed#1738 from ARMmbed/master_merge_to_koli
Master merge to koli
2 parents 03bc696 + abee481 commit 5a1f295

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+791
-389
lines changed

source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan_interface.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ static int8_t set_6lowpan_nwk_down(protocol_interface_info_entry_t *cur)
9191
}
9292
#endif
9393
}
94-
uint16_t pan_id = cur->mac_parameters->pan_id;
94+
if (cur->lowpan_info & INTERFACE_NWK_BOOTSRAP_PANA_AUTHENTICATION) {
95+
pana_reset_values(cur->mac_parameters->pan_id);
96+
}
97+
9598
if (cur->interface_mode == INTERFACE_UP) {
9699
if (cur->mac_api) {
97100
mlme_reset_t reset;
@@ -109,9 +112,6 @@ static int8_t set_6lowpan_nwk_down(protocol_interface_info_entry_t *cur)
109112
reassembly_interface_reset(cur->id);
110113

111114
icmp_nd_routers_init();
112-
if (cur->lowpan_info & INTERFACE_NWK_BOOTSRAP_PANA_AUTHENTICATION) {
113-
pana_reset_values(pan_id);
114-
}
115115

116116
if (cur->pana_sec_info_temp) {
117117
ns_dyn_mem_free(cur->pana_sec_info_temp);

source/6LoWPAN/MAC/mac_helper.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,10 @@ static uint8_t mac_helper_header_security_aux_header_length(uint8_t keyIdmode) {
767767
switch (keyIdmode) {
768768
case MAC_KEY_ID_MODE_SRC8_IDX:
769769
header_length += 4; //64-bit key source first part
770+
/* fall through */
770771
case MAC_KEY_ID_MODE_SRC4_IDX:
771772
header_length += 4; //32-bit key source inline
773+
/* fall through */
772774
case MAC_KEY_ID_MODE_IDX:
773775
header_length += 1;
774776
break;

source/6LoWPAN/Thread/thread_address_registration_client.c

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,62 +58,55 @@
5858

5959
static bool enabled = false;
6060
static uint32_t addr_notificastion_timer;
61+
static uint32_t mlr_timer;
6162

6263
void thread_address_registration_init()
6364
{
6465
enabled = true;
6566
addr_notificastion_timer = THREAD_PROACTIVE_AN_INTERVAL;
67+
mlr_timer = 0;
6668
}
6769

6870
void thread_address_registration_deinit()
6971
{
7072
enabled = false;
7173
}
7274

73-
void thread_address_registration_timer_set(protocol_interface_info_entry_t *interface, uint16_t seconds)
75+
void thread_address_registration_timer_set(protocol_interface_info_entry_t *interface, uint16_t dua_delay_seconds, uint16_t mlr_refresh_seconds)
7476
{
7577
(void)interface;
76-
addr_notificastion_timer = seconds;
77-
/* trigger multicast registrations */
78-
ns_list_foreach(if_group_entry_t, cur, &interface->ip_groups) {
79-
if (addr_ipv6_multicast_scope(cur->group) < IPV6_SCOPE_ADMIN_LOCAL) {
80-
continue;
81-
}
82-
if (addr_ipv6_equal(cur->group, ADDR_SITE_LOCAL_ALL_ROUTERS)) {
83-
continue;
84-
}
85-
cur->mld_timer = seconds;
78+
if (dua_delay_seconds != 0) {
79+
addr_notificastion_timer = dua_delay_seconds;
80+
}
81+
if (mlr_refresh_seconds != 0) {
82+
mlr_timer = mlr_refresh_seconds;
8683
}
8784

88-
}
85+
}
8986
void thread_address_registration_timer(protocol_interface_info_entry_t *interface, uint16_t seconds)
9087
{
88+
uint32_t mlr_timeout;
89+
uint32_t delay_timer;
9190
if (!enabled || !thread_extension_version_check(interface->thread_info->version)) {
9291
return;
9392
}
9493

94+
if (0 != thread_extension_primary_bbr_get(interface, NULL, NULL, &mlr_timeout, &delay_timer)) {
95+
// BBR not present
96+
return;
97+
}
9598
/* Update multicast addresses */
96-
ns_list_foreach(if_group_entry_t, cur, &interface->ip_groups) {
97-
if (addr_ipv6_multicast_scope(cur->group) < IPV6_SCOPE_ADMIN_LOCAL) {
98-
continue;
99-
}
100-
101-
if (cur->mld_timer > seconds) {
102-
cur->mld_timer -= seconds;
103-
} else {
104-
cur->mld_timer = 0;
105-
}
106-
107-
if (cur->mld_timer < 2) {
108-
// Renew the multicast address
109-
thread_extension_mcast_subscrition_change(interface, cur, true);
110-
}
99+
if (mlr_timer > seconds) {
100+
mlr_timer -= seconds;
101+
} else {
102+
mlr_timer = mlr_timeout - randLIB_get_random_in_range(30,50);
103+
thread_extension_mcast_subscrition_change(interface);
111104
}
112105
/* Update global scope addresses (children's as well) */
113106
if (addr_notificastion_timer > seconds) {
114107
addr_notificastion_timer -= seconds;
115108
} else {
116-
addr_notificastion_timer = THREAD_PROACTIVE_AN_INTERVAL + randLIB_get_random_in_range(0,60);
109+
addr_notificastion_timer = THREAD_PROACTIVE_AN_INTERVAL + randLIB_get_random_in_range(0, delay_timer/1000);
117110
thread_extension_address_registration_trigger(interface);
118111
}
119112

source/6LoWPAN/Thread/thread_address_registration_client.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
void thread_address_registration_init(void);
3737
void thread_address_registration_deinit(void);
3838

39-
void thread_address_registration_timer_set(protocol_interface_info_entry_t *interface, uint16_t seconds);
39+
void thread_address_registration_timer_set(protocol_interface_info_entry_t *interface, uint16_t dua_delay_seconds, uint16_t mlr_refresh_seconds);
4040
void thread_address_registration_timer(protocol_interface_info_entry_t *interface, uint16_t seconds);
4141
#else
4242

4343
#define thread_address_registration_init(void)
4444
#define thread_address_registration_deinit(void)
4545

46-
#define thread_address_registration_timer_set(interface, seconds);
46+
#define thread_address_registration_timer_set(interface, dua_delay_seconds, mlr_refresh_seconds);
4747
#define thread_address_registration_timer(interface, seconds);
4848

4949
#endif

source/6LoWPAN/Thread/thread_bbr_api.c

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ static bool thread_bbr_activated(thread_bbr_t *this, uint32_t seconds)
738738
return true;
739739
}
740740
// We will try to become router. This is done only in 120 seconds intervals if failed
741-
thread_router_bootstrap_router_id_request(cur, 0);
741+
thread_router_bootstrap_router_id_request(cur, THREAD_BBR_ROUTER_ID_REQUEST_STATUS);
742742
this->router_upgrade_delay_timer = 120;
743743
return false;
744744
}
@@ -755,8 +755,8 @@ bool thread_bbr_routing_enabled(protocol_interface_info_entry_t *cur)
755755

756756
void thread_bbr_network_data_update_notify(protocol_interface_info_entry_t *cur)
757757
{
758-
(void) cur;
759758
thread_mdns_network_data_update_notify();
759+
thread_extension_bbr_route_update(cur);
760760
}
761761
#endif /* HAVE_THREAD_BORDER_ROUTER*/
762762

@@ -943,7 +943,7 @@ void thread_bbr_seconds_timer(int8_t interface_id, uint32_t seconds)
943943
#endif // HAVE_THREAD_ROUTER
944944

945945
#ifdef HAVE_THREAD_BORDER_ROUTER
946-
static int thread_bbr_na_send(int8_t interface_id, const uint8_t target[static 16])
946+
int thread_bbr_na_send(int8_t interface_id, const uint8_t target[static 16])
947947
{
948948
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
949949
if (!cur) {
@@ -955,18 +955,18 @@ static int thread_bbr_na_send(int8_t interface_id, const uint8_t target[static 1
955955
return 0;
956956

957957
}
958-
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) {
959-
(void) mleid_ptr;
958+
959+
int thread_bbr_nd_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr, uint32_t lifetime, void *info)
960+
{
960961
thread_bbr_t *this = thread_bbr_find_by_interface(interface_id);
961962
if (!this || this->backbone_interface_id < 0) {
962-
tr_err("bbr not ready");
963963
return -1;
964964
}
965965
ipv6_route_t *route = ipv6_route_add_with_info(addr_data_ptr, 128, interface_id, NULL, ROUTE_THREAD_PROXIED_HOST, info, 0, lifetime, 0);
966966
// We are using route info field to store sequence number
967967
if (!route) {
968968
// Direct route to host allows ND proxying to work
969-
tr_err("out of resources");
969+
tr_err("bbr out of resources");
970970
return -2;
971971
}
972972
// send NA
@@ -975,14 +975,44 @@ int thread_bbr_nd_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr,
975975
return 0;
976976
}
977977

978-
int thread_bbr_nd_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr) {
979-
ipv6_route_t *route = ipv6_route_choose_next_hop(addr_data_ptr, interface_id, NULL);
980-
if (!route || route->prefix_len < 128 || !route->on_link || route->info.source != ROUTE_THREAD_PROXIED_HOST ) {
981-
//Not found
978+
int thread_bbr_dua_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr, uint32_t lifetime, const uint8_t *mleid_ptr)
979+
{
980+
thread_bbr_t *this = thread_bbr_find_by_interface(interface_id);
981+
if (!this || this->backbone_interface_id < 0) {
982982
return -1;
983983
}
984-
//TODO get information to route to parameters eq mleid, timeout
984+
thread_pbbr_dua_info_t *map = ns_dyn_mem_alloc(sizeof(thread_pbbr_dua_info_t));
985+
if (!map) {
986+
goto error;
987+
}
988+
memcpy(map->mleid_ptr, mleid_ptr, 8);
989+
map->last_contact_time = protocol_core_monotonic_time;
990+
991+
// We are using route info field to store BBR MLEID map
992+
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);
993+
if (!route) {
994+
// Direct route to host allows ND proxying to work
995+
ns_dyn_mem_free(map);
996+
goto error;
997+
}
998+
// Route info autofreed
999+
route->info_autofree = true;
1000+
// send NA
1001+
thread_bbr_na_send(this->backbone_interface_id, addr_data_ptr);
1002+
9851003
return 0;
1004+
error:
1005+
tr_err("out of resources");
1006+
return -2;
1007+
}
1008+
1009+
struct ipv6_route *thread_bbr_dua_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr) {
1010+
ipv6_route_t *route = ipv6_route_choose_next_hop(addr_data_ptr, interface_id, NULL);
1011+
if (!route || route->prefix_len < 128 || !route->on_link || route->info.source != ROUTE_THREAD_PROXIED_DUA_HOST ) {
1012+
//Not found
1013+
return NULL;
1014+
}
1015+
return route;
9861016
}
9871017

9881018
int thread_bbr_proxy_state_update(int8_t caller_interface_id , int8_t handler_interface_id, bool status)

source/6LoWPAN/Thread/thread_bbr_api_internal.h

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
#include "net_interface.h"
3838
#ifdef HAVE_THREAD_ROUTER
39+
struct ipv6_route;
40+
3941
/**
4042
* \brief Initialize Thread Commissioner relay for BBR and Routers
4143
*
@@ -98,23 +100,39 @@ void thread_bbr_network_data_update_notify(protocol_interface_info_entry_t *cur)
98100
/**
99101
* \brief Add new nd entry to bbr
100102
*
103+
* \param interface_id addr_data_ptr lifetime info
104+
*/
105+
int thread_bbr_nd_entry_add(int8_t interface_id, const uint8_t *addr_data_ptr, uint32_t lifetime, void *info);
106+
107+
/**
108+
* \brief Add new dua entry to bbr
109+
*
110+
* \param interface_id addr_data_ptr lifetime info mleid_ptr
111+
*/
112+
int thread_bbr_dua_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr, uint32_t lifetime, const uint8_t *mleid_ptr);
113+
114+
/**
115+
* \brief Send na
116+
*
101117
* \param interface_id addr_data_ptr lifetime info mleid_ptr
102118
*/
103-
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);
119+
int thread_bbr_na_send(int8_t interface_id, const uint8_t target[static 16]);
104120

105121
/**
106-
* \brief Find if bbr has nd entry
122+
* \brief Find if bbr has dua entry
107123
*
108124
* \param interface_id addr_data_ptr
109125
*/
110-
int thread_bbr_nd_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr);
126+
struct ipv6_route *thread_bbr_dua_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr);
111127

112128
#else
113129
#define thread_bbr_proxy_state_update(caller_interface_id , handler_interface_id, status) (NULL)
114130
#define thread_bbr_routing_enabled(cur) false
115131
#define thread_bbr_network_data_update_notify(cur)
116-
#define thread_bbr_nd_entry_add(interface_id, addr_data_ptr, lifetime, info, mleid_ptr) (0)
117-
#define thread_bbr_nd_entry_find(interface_id, addr_data_ptr) (0)
132+
#define thread_bbr_nd_entry_add(interface_id, addr_data_ptr, lifetime, info) (0)
133+
#define thread_bbr_dua_entry_add(interface_id, addr_data_ptr, lifetime, mleid_ptr) (0)
134+
#define thread_bbr_dua_entry_find(interface_id, addr_data_ptr) (NULL)
135+
#define thread_bbr_na_send(interface_id, target) (0)
118136
#endif //HAVE_THREAD_BORDER_ROUTER
119137

120138

source/6LoWPAN/Thread/thread_bootstrap.c

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#include "6LoWPAN/Thread/thread_network_synch.h"
6565
#include "6LoWPAN/Thread/thread_joiner_application.h"
6666
#include "6LoWPAN/Thread/thread_extension.h"
67+
#include "6LoWPAN/Thread/thread_extension_bbr.h"
6768
#include "6LoWPAN/Thread/thread_management_client.h"
6869
#include "6LoWPAN/Thread/thread_address_registration_client.h"
6970
#include "6LoWPAN/Thread/thread_joiner_application.h"
@@ -287,45 +288,31 @@ bool thread_check_is_this_my_parent(protocol_interface_info_entry_t *cur, mac_ne
287288
bool thread_bootstrap_request_network_data(protocol_interface_info_entry_t *cur, thread_leader_data_t *leaderData, uint16_t short_address)
288289
{
289290
bool requestNetworkdata = false;
290-
thread_leader_data_t *leadeInfo = thread_info(cur)->thread_leader_data;
291+
thread_leader_data_t *leaderInfo = thread_info(cur)->thread_leader_data;
291292

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

296-
if (thread_info(cur)->thread_leader_data->partitionId != leaderData->partitionId) {
297+
if (!thread_partition_match(cur, leaderData)) {
297298
tr_debug("Learn new Network Data");
298299
requestNetworkdata = true;
299-
thread_info(cur)->thread_leader_data->dataVersion = leaderData->dataVersion - 1;
300-
thread_info(cur)->thread_leader_data->stableDataVersion = leaderData->stableDataVersion - 1;
300+
thread_partition_info_update(cur, leaderData);
301301
}
302-
else if (common_serial_number_greater_8(leaderData->dataVersion, leadeInfo->dataVersion)) {
302+
else if (common_serial_number_greater_8(leaderData->dataVersion, leaderInfo->dataVersion)) {
303303
requestNetworkdata = true;
304304

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

308308
}
309309

310-
// Version number is updated when new network data is learned to avoid synchronization problems
311-
thread_info(cur)->thread_leader_data->leaderRouterId = leaderData->leaderRouterId;
312-
thread_info(cur)->thread_leader_data->partitionId = leaderData->partitionId;
313310
if (requestNetworkdata) {
314311
thread_bootstrap_parent_network_data_request(cur, true);
315312
}
316313
return true;
317314
}
318315

319-
bool thread_instance_id_matches(protocol_interface_info_entry_t *cur, thread_leader_data_t *leaderData)
320-
{
321-
if (thread_info(cur)->thread_leader_data) {
322-
if (thread_info(cur)->thread_leader_data->partitionId == leaderData->partitionId) {
323-
return true;
324-
}
325-
}
326-
return false;
327-
}
328-
329316
static int thread_router_check_previous_partition_info(protocol_interface_info_entry_t *cur, thread_leader_data_t *leaderData, mle_tlv_info_t *routeTlv)
330317
{
331318
if (!routeTlv || !routeTlv->dataPtr || !routeTlv->tlvLen || !leaderData) {
@@ -428,8 +415,7 @@ int thread_leader_data_validation(protocol_interface_info_entry_t *cur, thread_l
428415
if (!thread_info(cur)->thread_leader_data) {
429416
return -1;
430417
}
431-
if ((thread_info(cur)->thread_leader_data->partitionId != leaderData->partitionId) ||
432-
(thread_info(cur)->thread_leader_data->weighting != leaderData->weighting)) {
418+
if (!thread_partition_match(cur, leaderData)) {
433419
uint8_t routers_in_route_tlv = thread_get_router_count_from_route_tlv(routeTlv);
434420
//partition checks
435421
return thread_bootstrap_partition_process(cur,routers_in_route_tlv,leaderData, routeTlv);
@@ -722,6 +708,8 @@ int thread_configuration_thread_activate(protocol_interface_info_entry_t *cur, l
722708

723709
thread_extension_activate(cur);
724710

711+
thread_extension_bbr_route_update(cur);
712+
725713
blacklist_clear();
726714

727715
blacklist_params_set(
@@ -2293,6 +2281,7 @@ void thread_bootstrap_stop(protocol_interface_info_entry_t *cur)
22932281
ipv6_route_table_remove_info(cur->id, ROUTE_THREAD, NULL);
22942282
ipv6_route_table_remove_info(cur->id, ROUTE_THREAD_BORDER_ROUTER, NULL);
22952283
ipv6_route_table_remove_info(cur->id, ROUTE_THREAD_PROXIED_HOST, NULL);
2284+
ipv6_route_table_remove_info(cur->id, ROUTE_THREAD_PROXIED_DUA_HOST, NULL);
22962285
thread_leader_service_leader_data_free(cur->thread_info);
22972286
thread_bootstrap_all_nodes_multicast_unregister(cur);
22982287
thread_data_base_init(cur->thread_info, cur->id);

source/6LoWPAN/Thread/thread_bootstrap.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ int thread_parent_discover_start(int8_t interface_id, uint8_t *mac64 );
125125

126126
bool thread_device_synch_timeout(int8_t interface_id, uint16_t msgId, bool usedAllRetries);
127127
bool thread_link_request_timeout(int8_t interface_id, uint16_t msgId, bool usedAllRetries);
128-
bool thread_instance_id_matches(struct protocol_interface_info_entry *cur, struct thread_leader_data_s *leaderData);
129128
int thread_leader_data_validation(struct protocol_interface_info_entry *cur, struct thread_leader_data_s *leaderData, struct mle_tlv_info_s *routeTlv);
130129
uint8_t thread_calculate_link_margin(int8_t dbm, uint8_t compLinkMarginFromParent);
131130
uint8_t thread_compute_link_margin(int8_t rssi);

0 commit comments

Comments
 (0)