Skip to content

Commit 0aef534

Browse files
author
Mika Leppänen
committed
Added support for fourth network key to MAC helper and WS bootstrap
Added also clearing of MAC send frame counter when new key is activated.
1 parent d861208 commit 0aef534

File tree

6 files changed

+148
-85
lines changed

6 files changed

+148
-85
lines changed

source/6LoWPAN/MAC/mac_helper.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,32 @@ int8_t mac_helper_security_prev_key_set(protocol_interface_info_entry_t *interfa
394394

395395
}
396396

397+
int8_t mac_helper_security_key_to_descriptor_set(protocol_interface_info_entry_t *interface, const uint8_t *key, uint8_t id, uint8_t descriptor)
398+
{
399+
if (id == 0) {
400+
return -1;
401+
}
402+
403+
mac_helper_keytable_descriptor_set(interface->mac_api, key, id, descriptor);
404+
return 0;
405+
}
406+
407+
int8_t mac_helper_security_key_descriptor_clear(protocol_interface_info_entry_t *interface, uint8_t descriptor)
408+
{
409+
if (interface->mac_api) {
410+
mlme_set_t set_req;
411+
mlme_key_descriptor_entry_t key_description;
412+
memset(&key_description, 0, sizeof(mlme_key_descriptor_entry_t));
413+
414+
set_req.attr = macKeyTable;
415+
set_req.value_pointer = &key_description;
416+
set_req.value_size = sizeof(mlme_key_descriptor_entry_t);
417+
set_req.attr_index = descriptor;
418+
interface->mac_api->mlme_req(interface->mac_api, MLME_SET, &set_req);
419+
return 0;
420+
}
421+
return -1;
422+
}
397423

398424
void mac_helper_security_key_swap_next_to_default(protocol_interface_info_entry_t *interface)
399425
{

source/6LoWPAN/MAC/mac_helper.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ int8_t mac_helper_security_next_key_set(struct protocol_interface_info_entry *in
7575

7676
int8_t mac_helper_security_prev_key_set(struct protocol_interface_info_entry *interface, uint8_t *key, uint8_t id, uint8_t keyid_mode);
7777

78+
int8_t mac_helper_security_key_to_descriptor_set(struct protocol_interface_info_entry *interface, const uint8_t *key, uint8_t id, uint8_t descriptor);
79+
80+
int8_t mac_helper_security_key_descriptor_clear(struct protocol_interface_info_entry *interface, uint8_t descriptor);
81+
7882
void mac_helper_security_key_swap_next_to_default(struct protocol_interface_info_entry *interface);
7983

8084
int8_t mac_helper_security_pairwisekey_set(struct protocol_interface_info_entry *interface, const uint8_t *key, const uint8_t *mac_64, uint8_t key_attribute);

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,11 @@ static uint16_t ws_bootstrap_routing_cost_calculate(protocol_interface_info_entr
8585
static uint16_t ws_bootstrap_rank_get(protocol_interface_info_entry_t *cur);
8686
static uint16_t ws_bootstrap_min_rank_inc_get(protocol_interface_info_entry_t *cur);
8787

88-
static void ws_bootstrap_nw_key_insert(protocol_interface_info_entry_t *cur, uint8_t operation, uint8_t index, uint8_t *key);
88+
static void ws_bootstrap_mac_security_enable(protocol_interface_info_entry_t *cur);
89+
static void ws_bootstrap_nw_key_set(protocol_interface_info_entry_t *cur, uint8_t operation, uint8_t index, uint8_t *key);
90+
static void ws_bootstrap_nw_key_clear(protocol_interface_info_entry_t *cur, uint8_t slot);
8991
static void ws_bootstrap_nw_key_index_set(protocol_interface_info_entry_t *cur, uint8_t index);
92+
static void ws_bootstrap_nw_frame_counter_set(protocol_interface_info_entry_t *cur, uint32_t counter);
9093
static void ws_bootstrap_authentication_completed(protocol_interface_info_entry_t *cur, bool success);
9194
static void ws_bootstrap_pan_version_increment(protocol_interface_info_entry_t *cur);
9295
static ws_nud_table_entry_t *ws_nud_entry_discover(protocol_interface_info_entry_t *cur, void *neighbor);
@@ -1547,7 +1550,7 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
15471550
ret_val = -4;
15481551
goto init_fail;
15491552
}
1550-
if (ws_pae_controller_cb_register(cur, &ws_bootstrap_authentication_completed, &ws_bootstrap_nw_key_insert, &ws_bootstrap_nw_key_index_set, &ws_bootstrap_pan_version_increment) < 0) {
1553+
if (ws_pae_controller_cb_register(cur, &ws_bootstrap_authentication_completed, &ws_bootstrap_nw_key_set, &ws_bootstrap_nw_key_clear, &ws_bootstrap_nw_key_index_set, &ws_bootstrap_nw_frame_counter_set, &ws_bootstrap_pan_version_increment) < 0) {
15511554
ret_val = -4;
15521555
goto init_fail;
15531556
}
@@ -1692,6 +1695,7 @@ static void ws_bootstrap_fhss_activate(protocol_interface_info_entry_t *cur)
16921695
tr_debug("MAC init");
16931696
mac_helper_pib_boolean_set(cur, macRxOnWhenIdle, true);
16941697
cur->lowpan_info &= ~INTERFACE_NWK_CONF_MAC_RX_OFF_IDLE;
1698+
ws_bootstrap_mac_security_enable(cur);
16951699
ws_bootstrap_mac_activate(cur, cur->ws_info->fhss_uc_fixed_channel, cur->ws_info->network_pan_id, true);
16961700
return;
16971701
}
@@ -1987,33 +1991,34 @@ static void ws_bootstrap_start_authentication(protocol_interface_info_entry_t *c
19871991
ws_pae_controller_authenticate(cur);
19881992
}
19891993

1990-
static void ws_bootstrap_nw_key_insert(protocol_interface_info_entry_t *cur, uint8_t operation, uint8_t index, uint8_t *key)
1994+
static void ws_bootstrap_mac_security_enable(protocol_interface_info_entry_t *cur)
19911995
{
1992-
switch (operation) {
1993-
case 0:
1994-
mac_helper_security_key_clean(cur);
1995-
mac_helper_default_security_level_set(cur, AES_SECURITY_LEVEL_ENC_MIC64);
1996-
mac_helper_default_security_key_id_mode_set(cur, MAC_KEY_ID_MODE_IDX);
1997-
break;
1998-
case 1:
1999-
mac_helper_security_default_recv_key_set(cur, key, index + 1, MAC_KEY_ID_MODE_IDX);
2000-
break;
2001-
case 2:
2002-
mac_helper_security_prev_key_set(cur, key, index + 1, MAC_KEY_ID_MODE_IDX);
2003-
break;
2004-
case 3:
2005-
mac_helper_security_next_key_set(cur, key, index + 1, MAC_KEY_ID_MODE_IDX);
2006-
break;
2007-
default:
2008-
break;
2009-
}
1996+
mac_helper_default_security_level_set(cur, AES_SECURITY_LEVEL_ENC_MIC64);
1997+
mac_helper_default_security_key_id_mode_set(cur, MAC_KEY_ID_MODE_IDX);
1998+
}
1999+
2000+
static void ws_bootstrap_nw_key_set(protocol_interface_info_entry_t *cur, uint8_t slot, uint8_t index, uint8_t *key)
2001+
{
2002+
mac_helper_security_key_to_descriptor_set(cur, key, index + 1, slot);
2003+
}
2004+
2005+
static void ws_bootstrap_nw_key_clear(protocol_interface_info_entry_t *cur, uint8_t slot)
2006+
{
2007+
mac_helper_security_key_descriptor_clear(cur, slot);
20102008
}
20112009

20122010
static void ws_bootstrap_nw_key_index_set(protocol_interface_info_entry_t *cur, uint8_t index)
20132011
{
2012+
// Set send key
20142013
mac_helper_security_auto_request_key_index_set(cur, index + 1);
20152014
}
20162015

2016+
static void ws_bootstrap_nw_frame_counter_set(protocol_interface_info_entry_t *cur, uint32_t counter)
2017+
{
2018+
// Set frame counter
2019+
mac_helper_link_frame_counter_set(cur->id, counter);
2020+
}
2021+
20172022
static void ws_bootstrap_authentication_completed(protocol_interface_info_entry_t *cur, bool success)
20182023
{
20192024
if (success) {

source/6LoWPAN/ws/ws_pae_auth.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ void ws_pae_auth_start(protocol_interface_info_entry_t *interface_ptr)
272272
ws_pae_auth_gtk_key_insert(pae_auth);
273273
index = sec_prot_keys_gtk_install_order_first_index_get(pae_auth->gtks);
274274
ws_pae_auth_active_gtk_set(pae_auth, index);
275+
} else {
276+
ws_pae_auth_active_gtk_set(pae_auth, index);
275277
}
276278

277279
// Inserts keys and updates GTK hash on stack
@@ -631,7 +633,7 @@ static void ws_pae_auth_gtk_key_insert(pae_auth_t *pae_auth)
631633
// Authenticator keys are always fresh
632634
sec_prot_keys_gtk_status_all_fresh_set(pae_auth->gtks);
633635

634-
tr_info("GTK install new index: %i, lifetime: %"PRIu32"", install_index, lifetime);
636+
tr_info("GTK install new index: %i, lifetime: %"PRIu32" system time: %"PRIu32"", install_index, lifetime, protocol_core_monotonic_time / 10);
635637
}
636638

637639
static int8_t ws_pae_auth_new_gtk_activate(pae_auth_t *pae_auth)

0 commit comments

Comments
 (0)