Skip to content

Commit

Permalink
Wi-sun New key index activate.
Browse files Browse the repository at this point in the history
Delayed default key index activate after first config message confirmation.

Change-Id: Ibcfbe82ad651f6ad4570180cade192406d566d8d
  • Loading branch information
Juha Heiskanen committed Dec 9, 2019
1 parent 0aead93 commit 6919ba1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
33 changes: 29 additions & 4 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1465,8 +1465,13 @@ static void ws_bootstrap_asynch_ind(struct protocol_interface_info_entry *cur, c
static void ws_bootstrap_asynch_confirm(struct protocol_interface_info_entry *interface, uint8_t asynch_message)
{
ws_stats_update(interface, STATS_WS_ASYNCH_TX, 1);
(void)interface;
(void)asynch_message;
if (interface->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
if (asynch_message == WS_FT_PAN_CONF && interface->ws_info->pending_key_index_info.state == PENDING_KEY_INDEX_ACTIVATE) {
interface->ws_info->pending_key_index_info.state = NO_PENDING_PROCESS;
tr_info("Activate new default key %u", interface->ws_info->pending_key_index_info.index + 1);
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);
}
}
}

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

static void ws_bootstrap_nw_key_index_set(protocol_interface_info_entry_t *cur, uint8_t index)
{
// Set send key

if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
if (cur->mac_parameters->mac_default_key_index != 0 && cur->mac_parameters->mac_default_key_index != index + 1) {
tr_info("New Pending key Request %u", index + 1);
cur->ws_info->pending_key_index_info.state = PENDING_KEY_INDEX_ADVERTISMENT;
cur->ws_info->pending_key_index_info.index = index;
return;
}
}

mac_helper_security_auto_request_key_index_set(cur, index, index + 1);
}

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

async_req.security.SecurityLevel = mac_helper_default_security_level_get(cur);
async_req.security.KeyIdMode = mac_helper_default_security_key_id_mode_get(cur);
async_req.security.KeyIndex = mac_helper_default_key_index_get(cur);
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER && cur->ws_info->pending_key_index_info.state == PENDING_KEY_INDEX_ADVERTISMENT) {
async_req.security.KeyIndex = cur->ws_info->pending_key_index_info.index + 1;
cur->ws_info->pending_key_index_info.state = PENDING_KEY_INDEX_ACTIVATE;
} else {
async_req.security.KeyIndex = mac_helper_default_key_index_get(cur);
}

ws_llc_asynch_request(cur, &async_req);
}

Expand All @@ -2680,6 +2700,11 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
break;
case WS_DISCOVERY_START:
tr_info("Discovery start");

//Clear Pending Key Index State
cur->ws_info->pending_key_index_info.state = NO_PENDING_PROCESS;
cur->mac_parameters->mac_default_key_index = 0;

// All trickle timers stopped to allow entry from any state
cur->ws_info->trickle_pa_running = false;
cur->ws_info->trickle_pc_running = false;
Expand Down
3 changes: 3 additions & 0 deletions source/6LoWPAN/ws/ws_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ int8_t ws_common_allocate_and_init(protocol_interface_info_entry_t *cur)
cur->ws_info->fhss_bc_dwell_interval = WS_FHSS_BC_DWELL_INTERVAL;
cur->ws_info->fhss_uc_channel_function = WS_DH1CF;
cur->ws_info->fhss_bc_channel_function = WS_DH1CF;

cur->ws_info->pending_key_index_info.state = NO_PENDING_PROCESS;

for (uint8_t n = 0; n < 8; n++) {
cur->ws_info->fhss_channel_mask[n] = 0xffffffff;
}
Expand Down
10 changes: 10 additions & 0 deletions source/6LoWPAN/ws/ws_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ typedef struct ws_nud_table_entry {
ns_list_link_t link;
} ws_nud_table_entry_t;

#define NO_PENDING_PROCESS 0
#define PENDING_KEY_INDEX_ADVERTISMENT 1
#define PENDING_KEY_INDEX_ACTIVATE 2

typedef struct {
unsigned state: 2;
uint8_t index;
} ws_pending_key_index_t;

typedef NS_LIST_HEAD(ws_nud_table_entry_t, link) ws_nud_table_list_t;

typedef struct ws_info_s {
Expand Down Expand Up @@ -88,6 +97,7 @@ typedef struct ws_info_s {
bool trickle_pcs_running: 1;
bool trickle_pc_running: 1;
bool fhss_owner: 1;
ws_pending_key_index_t pending_key_index_info;
// default fhss parameters for this device
uint8_t fhss_uc_dwell_interval;
uint8_t fhss_bc_dwell_interval;
Expand Down
1 change: 1 addition & 0 deletions source/NWK_INTERFACE/protocol_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ static protocol_interface_info_entry_t *protocol_core_interface_6lowpan_entry_ge
entry->mac_parameters->mac_prev_key_attribute_id = 0;
entry->mac_parameters->mac_default_key_attribute_id = 1;
entry->mac_parameters->mac_next_key_attribute_id = 2;
entry->mac_parameters->mac_default_key_index = 0;

entry->beacon_cb = beacon_received;

Expand Down

0 comments on commit 6919ba1

Please sign in to comment.