Skip to content

Commit 6919ba1

Browse files
author
Juha Heiskanen
committed
Wi-sun New key index activate.
Delayed default key index activate after first config message confirmation. Change-Id: Ibcfbe82ad651f6ad4570180cade192406d566d8d
1 parent 0aead93 commit 6919ba1

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,8 +1465,13 @@ static void ws_bootstrap_asynch_ind(struct protocol_interface_info_entry *cur, c
14651465
static void ws_bootstrap_asynch_confirm(struct protocol_interface_info_entry *interface, uint8_t asynch_message)
14661466
{
14671467
ws_stats_update(interface, STATS_WS_ASYNCH_TX, 1);
1468-
(void)interface;
1469-
(void)asynch_message;
1468+
if (interface->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
1469+
if (asynch_message == WS_FT_PAN_CONF && interface->ws_info->pending_key_index_info.state == PENDING_KEY_INDEX_ACTIVATE) {
1470+
interface->ws_info->pending_key_index_info.state = NO_PENDING_PROCESS;
1471+
tr_info("Activate new default key %u", interface->ws_info->pending_key_index_info.index + 1);
1472+
mac_helper_security_auto_request_key_index_set(interface, interface->ws_info->pending_key_index_info.index, interface->ws_info->pending_key_index_info.index + 1);
1473+
}
1474+
}
14701475
}
14711476

14721477
uint32_t ws_time_from_last_unicast_traffic(uint32_t current_time_stamp, ws_neighbor_class_entry_t *ws_neighbor)
@@ -2410,7 +2415,16 @@ static void ws_bootstrap_nw_key_clear(protocol_interface_info_entry_t *cur, uint
24102415

24112416
static void ws_bootstrap_nw_key_index_set(protocol_interface_info_entry_t *cur, uint8_t index)
24122417
{
2413-
// Set send key
2418+
2419+
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
2420+
if (cur->mac_parameters->mac_default_key_index != 0 && cur->mac_parameters->mac_default_key_index != index + 1) {
2421+
tr_info("New Pending key Request %u", index + 1);
2422+
cur->ws_info->pending_key_index_info.state = PENDING_KEY_INDEX_ADVERTISMENT;
2423+
cur->ws_info->pending_key_index_info.index = index;
2424+
return;
2425+
}
2426+
}
2427+
24142428
mac_helper_security_auto_request_key_index_set(cur, index, index + 1);
24152429
}
24162430

@@ -2660,7 +2674,13 @@ static void ws_bootstrap_pan_config(protocol_interface_info_entry_t *cur)
26602674

26612675
async_req.security.SecurityLevel = mac_helper_default_security_level_get(cur);
26622676
async_req.security.KeyIdMode = mac_helper_default_security_key_id_mode_get(cur);
2663-
async_req.security.KeyIndex = mac_helper_default_key_index_get(cur);
2677+
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER && cur->ws_info->pending_key_index_info.state == PENDING_KEY_INDEX_ADVERTISMENT) {
2678+
async_req.security.KeyIndex = cur->ws_info->pending_key_index_info.index + 1;
2679+
cur->ws_info->pending_key_index_info.state = PENDING_KEY_INDEX_ACTIVATE;
2680+
} else {
2681+
async_req.security.KeyIndex = mac_helper_default_key_index_get(cur);
2682+
}
2683+
26642684
ws_llc_asynch_request(cur, &async_req);
26652685
}
26662686

@@ -2680,6 +2700,11 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
26802700
break;
26812701
case WS_DISCOVERY_START:
26822702
tr_info("Discovery start");
2703+
2704+
//Clear Pending Key Index State
2705+
cur->ws_info->pending_key_index_info.state = NO_PENDING_PROCESS;
2706+
cur->mac_parameters->mac_default_key_index = 0;
2707+
26832708
// All trickle timers stopped to allow entry from any state
26842709
cur->ws_info->trickle_pa_running = false;
26852710
cur->ws_info->trickle_pc_running = false;

source/6LoWPAN/ws/ws_common.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ int8_t ws_common_allocate_and_init(protocol_interface_info_entry_t *cur)
316316
cur->ws_info->fhss_bc_dwell_interval = WS_FHSS_BC_DWELL_INTERVAL;
317317
cur->ws_info->fhss_uc_channel_function = WS_DH1CF;
318318
cur->ws_info->fhss_bc_channel_function = WS_DH1CF;
319+
320+
cur->ws_info->pending_key_index_info.state = NO_PENDING_PROCESS;
321+
319322
for (uint8_t n = 0; n < 8; n++) {
320323
cur->ws_info->fhss_channel_mask[n] = 0xffffffff;
321324
}

source/6LoWPAN/ws/ws_common.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ typedef struct ws_nud_table_entry {
6060
ns_list_link_t link;
6161
} ws_nud_table_entry_t;
6262

63+
#define NO_PENDING_PROCESS 0
64+
#define PENDING_KEY_INDEX_ADVERTISMENT 1
65+
#define PENDING_KEY_INDEX_ACTIVATE 2
66+
67+
typedef struct {
68+
unsigned state: 2;
69+
uint8_t index;
70+
} ws_pending_key_index_t;
71+
6372
typedef NS_LIST_HEAD(ws_nud_table_entry_t, link) ws_nud_table_list_t;
6473

6574
typedef struct ws_info_s {
@@ -88,6 +97,7 @@ typedef struct ws_info_s {
8897
bool trickle_pcs_running: 1;
8998
bool trickle_pc_running: 1;
9099
bool fhss_owner: 1;
100+
ws_pending_key_index_t pending_key_index_info;
91101
// default fhss parameters for this device
92102
uint8_t fhss_uc_dwell_interval;
93103
uint8_t fhss_bc_dwell_interval;

source/NWK_INTERFACE/protocol_core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ static protocol_interface_info_entry_t *protocol_core_interface_6lowpan_entry_ge
603603
entry->mac_parameters->mac_prev_key_attribute_id = 0;
604604
entry->mac_parameters->mac_default_key_attribute_id = 1;
605605
entry->mac_parameters->mac_next_key_attribute_id = 2;
606+
entry->mac_parameters->mac_default_key_index = 0;
606607

607608
entry->beacon_cb = beacon_received;
608609

0 commit comments

Comments
 (0)