Skip to content

Commit b69ba04

Browse files
author
Arto Kinnunen
authored
Allow MLE entry forced saving to MAC (#1600)
New MLE entries are not saved to MAC layer if key indexes were not matching. When new MLE entry is created then make forced save to MAC.
1 parent 0e85099 commit b69ba04

File tree

14 files changed

+125
-94
lines changed

14 files changed

+125
-94
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ static int mle_router_accept_request_build(protocol_interface_info_entry_t *cur,
758758

759759
static void protocol_6lowpan_link_reject_handler(protocol_interface_info_entry_t *cur, uint8_t *ll64)
760760
{
761-
mle_neigh_table_entry_t *entry_temp = mle_class_get_entry_by_ll64(cur->id, 0, ll64, false);
761+
mle_neigh_table_entry_t *entry_temp = mle_class_get_entry_by_ll64(cur->id, 0, ll64, false, NULL);
762762
tr_debug("MLE link reject");
763763
if (entry_temp) {
764764
mle_class_remove_entry(cur->id, entry_temp);
@@ -1081,7 +1081,7 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
10811081
mle_6lowpan_data->link_req_token_bucket--;
10821082
} else {
10831083
//Update only old information based on link request
1084-
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, false);
1084+
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, false, NULL);
10851085
if (entry_temp) {
10861086
mle_neigh_time_and_mode_update(entry_temp,mle_msg->data_ptr, mle_msg->data_length);
10871087
mle_neigh_entry_update_by_mle_tlv_list(interface_id, entry_temp, mle_msg->data_ptr, mle_msg->data_length, cur->mac, own_mac16);
@@ -1118,12 +1118,12 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
11181118

11191119
tr_debug("Accept & Request");
11201120

1121-
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, false);
1121+
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, false, NULL);
11221122

11231123
if (!entry_temp) {
11241124
// If there is space for neighbors try to allocate new entry
11251125
if (mle_6lowpan_neighbor_limit_check(interface_id, mle_msg, true)) {
1126-
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, true);
1126+
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, true, NULL);
11271127
}
11281128
}
11291129

@@ -1185,7 +1185,7 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
11851185
mode = *t_ptr;
11861186
}
11871187

1188-
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, false);
1188+
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, false, NULL);
11891189
if (!entry_temp) {
11901190
if ((mode & MLE_DEV_MASK) == MLE_FFD_DEV) {
11911191
// If there is space for neighbors synchronizes to new router
@@ -2787,7 +2787,7 @@ bool lowpan_neighbour_data_clean(int8_t interface_id, const uint8_t *link_local_
27872787
{
27882788
bool return_value = false;
27892789
#ifndef NO_MLE
2790-
mle_neigh_table_entry_t * neigh_entry = mle_class_get_entry_by_ll64(interface_id, 0, link_local_address, false);
2790+
mle_neigh_table_entry_t * neigh_entry = mle_class_get_entry_by_ll64(interface_id, 0, link_local_address, false, NULL);
27912791
if (neigh_entry) {
27922792
//Remove entry
27932793
if (neigh_entry->priorityFlag) {

source/6LoWPAN/MAC/mac_helper.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,13 +831,13 @@ void mac_helper_devicetable_remove(mac_api_t *mac_api, uint8_t attribute_index)
831831
mac_api->mlme_req(mac_api,MLME_SET , &set_req);
832832
}
833833

834-
void mac_helper_devicetable_set(mle_neigh_table_entry_t *entry_temp, protocol_interface_info_entry_t *cur, uint32_t frame_counter, uint8_t keyID)
834+
void mac_helper_devicetable_set(mle_neigh_table_entry_t *entry_temp, protocol_interface_info_entry_t *cur, uint32_t frame_counter, uint8_t keyID, bool force_set)
835835
{
836836
if (!cur->mac_api) {
837837
return;
838838
}
839839

840-
if (cur->mac_parameters->SecurityEnabled && cur->mac_parameters->mac_default_key_index != keyID) {
840+
if (!force_set && cur->mac_parameters->SecurityEnabled && cur->mac_parameters->mac_default_key_index != keyID) {
841841
tr_debug("Do not set counter by index %u != %u", cur->mac_parameters->mac_default_key_index, keyID);
842842
return;
843843
}

source/6LoWPAN/MAC/mac_helper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ int8_t mac_helper_link_frame_counter_set(int8_t interface_id, uint32_t seq_ptr);
110110

111111
void mac_helper_devicetable_remove(struct mac_api_s *mac_api, uint8_t attribute_index);
112112

113-
void mac_helper_devicetable_set(struct mle_neigh_table_entry_t *entry_temp, struct protocol_interface_info_entry *cur, uint32_t frame_counter, uint8_t keyID);
113+
void mac_helper_devicetable_set(struct mle_neigh_table_entry_t *entry_temp, struct protocol_interface_info_entry *cur, uint32_t frame_counter, uint8_t keyID, bool force_set);
114114

115115
int8_t mac_helper_mac_mlme_max_retry_set(int8_t interface_id, uint8_t mac_retry_set);
116116

source/6LoWPAN/MAC/mac_pairwise_key.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ int mac_pairwise_key_interface_unregister(int8_t interface_id)
252252
int mac_pairwise_key_add(int8_t interface_id, uint32_t valid_life_time, const uint8_t eui64[static 8], const uint8_t key[static 16])
253253
{
254254
protocol_interface_info_entry_t *interface = protocol_stack_interface_info_get_by_id(interface_id);
255+
bool new_entry_created;
256+
255257
if (!interface || !interface->mac_api) {
256258
return -1;
257259
}
@@ -264,7 +266,7 @@ int mac_pairwise_key_add(int8_t interface_id, uint32_t valid_life_time, const ui
264266
}
265267

266268
//Allocate mle entry
267-
mle_neigh_table_entry_t *mle_entry = mle_class_get_entry_by_mac64(interface_id, 0, eui64, true);
269+
mle_neigh_table_entry_t *mle_entry = mle_class_get_entry_by_mac64(interface_id, 0, eui64, true, &new_entry_created);
268270
if (!mle_entry) {
269271
return -1;
270272
}
@@ -282,7 +284,7 @@ int mac_pairwise_key_add(int8_t interface_id, uint32_t valid_life_time, const ui
282284
}
283285

284286
//Set device descriptor
285-
mac_helper_devicetable_set(mle_entry, interface, 0, interface->mac_parameters->mac_default_key_index);
287+
mac_helper_devicetable_set(mle_entry, interface, 0, interface->mac_parameters->mac_default_key_index, new_entry_created);
286288

287289
//set key descriptor
288290
if (mac_helper_security_pairwisekey_set(interface, key, eui64, key_desc->key_decriptor_attribute) != 0) {
@@ -308,7 +310,7 @@ int mac_pairwise_key_del(int8_t interface_id, const uint8_t eui64[static 8])
308310
return -1;
309311
}
310312
//Get from mle
311-
mle_neigh_table_entry_t *mle_entry = mle_class_get_entry_by_mac64(interface_id, 0, eui64, true);
313+
mle_neigh_table_entry_t *mle_entry = mle_class_get_entry_by_mac64(interface_id, 0, eui64, true, NULL);
312314
if (!mle_entry) {
313315
return -1;
314316
}

source/6LoWPAN/Thread/thread_host_bootstrap.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ static void thread_merge_prepare(protocol_interface_info_entry_t *cur)
131131
static bool thread_parent_discover_timeout_cb(int8_t interface_id, uint16_t msgId, bool usedAllRetries)
132132
{
133133
protocol_interface_info_entry_t *cur;
134+
bool new_entry_created;
134135

135136
cur = protocol_stack_interface_info_get_by_id(interface_id);
136137
if (!cur) {
@@ -156,7 +157,7 @@ static bool thread_parent_discover_timeout_cb(int8_t interface_id, uint16_t msgI
156157
memcpy(&ll64[8], parent->mac64 , 8);
157158
ll64[8] ^= 2;
158159

159-
entry_temp = mle_class_get_entry_by_ll64(interface_id, parent->linkMarginToParent,ll64, true);
160+
entry_temp = mle_class_get_entry_by_ll64(interface_id, parent->linkMarginToParent,ll64, true, &new_entry_created);
160161
if (entry_temp == NULL) {
161162
return false;
162163
}
@@ -169,7 +170,7 @@ static bool thread_parent_discover_timeout_cb(int8_t interface_id, uint16_t msgI
169170
thread_management_key_sets_calc(cur, linkConfiguration, cur->thread_info->thread_attach_scanned_parent->keySequence);
170171
thread_calculate_key_guard_timer(cur, linkConfiguration, true);
171172

172-
mac_helper_devicetable_set(entry_temp, cur, parent->linLayerFrameCounter, mac_helper_default_key_index_get(cur));
173+
mac_helper_devicetable_set(entry_temp, cur, parent->linLayerFrameCounter, mac_helper_default_key_index_get(cur), new_entry_created);
173174
mle_entry_timeout_update(entry_temp, THREAD_DEFAULT_LINK_LIFETIME);
174175

175176
if (cur->thread_info->thread_device_mode == THREAD_DEVICE_MODE_SLEEPY_END_DEVICE) {
@@ -292,6 +293,7 @@ static int thread_end_device_synch_response_validate(protocol_interface_info_ent
292293
uint32_t llFrameCounter;
293294
thread_leader_data_t leaderData;
294295
mle_neigh_table_entry_t *entry_temp;
296+
bool new_entry_created;
295297

296298
tr_debug("Validate Link Synch Response");
297299
//Check First Status
@@ -322,7 +324,7 @@ static int thread_end_device_synch_response_validate(protocol_interface_info_ent
322324
}
323325

324326
//Update parent link information
325-
entry_temp = mle_class_get_entry_by_ll64(cur->id, linkMargin, src_address, true);
327+
entry_temp = mle_class_get_entry_by_ll64(cur->id, linkMargin, src_address, true, &new_entry_created);
326328

327329
if (!entry_temp) {
328330
tr_debug("Neighbor allocate fail");
@@ -340,7 +342,7 @@ static int thread_end_device_synch_response_validate(protocol_interface_info_ent
340342

341343
mac_helper_coordinator_address_set(cur, ADDR_802_15_4_SHORT, shortAddress);
342344
mle_entry_timeout_update(entry_temp, thread_info(cur)->host_link_timeout);
343-
mac_helper_devicetable_set(entry_temp, cur, llFrameCounter, securityHeader->KeyIndex);
345+
mac_helper_devicetable_set(entry_temp, cur, llFrameCounter, securityHeader->KeyIndex, new_entry_created);
344346

345347
thread_info(cur)->thread_attached_state = THREAD_STATE_CONNECTED;
346348
thread_bootstrap_update_ml16_address(cur, address16);
@@ -757,6 +759,7 @@ static void thread_mle_child_request_receive_cb(int8_t interface_id, mle_message
757759
uint64_t pending_timestamp = 0;
758760
uint64_t active_timestamp;
759761
thread_scanned_parent_t *scan_result = thread_info(cur)->thread_attach_scanned_parent;
762+
bool new_entry_created;
760763

761764
tr_info("Received Child ID Response");
762765

@@ -772,7 +775,7 @@ static void thread_mle_child_request_receive_cb(int8_t interface_id, mle_message
772775
thread_merge_prepare(cur);
773776

774777
// Create entry for new parent
775-
entry_temp = mle_class_get_entry_by_ll64(cur->id, thread_compute_link_margin(mle_msg->dbm), mle_msg->packet_src_address, true);
778+
entry_temp = mle_class_get_entry_by_ll64(cur->id, thread_compute_link_margin(mle_msg->dbm), mle_msg->packet_src_address, true, &new_entry_created);
776779
if (entry_temp == NULL) {
777780
// todo: what to do here?
778781
return;
@@ -829,7 +832,7 @@ static void thread_mle_child_request_receive_cb(int8_t interface_id, mle_message
829832

830833
mac_helper_coordinator_address_set(cur, ADDR_802_15_4_SHORT, shortAddress);
831834
mle_entry_timeout_update(entry_temp, thread_info(cur)->host_link_timeout);
832-
mac_helper_devicetable_set(entry_temp, cur, scan_result->linLayerFrameCounter, security_headers->KeyIndex);
835+
mac_helper_devicetable_set(entry_temp, cur, scan_result->linLayerFrameCounter, security_headers->KeyIndex, new_entry_created);
833836

834837
thread_info(cur)->thread_attached_state = THREAD_STATE_CONNECTED;
835838

@@ -924,9 +927,10 @@ void thread_endevice_synch_start(protocol_interface_info_entry_t *cur)
924927
{
925928
if (cur->thread_info->thread_endnode_parent) {
926929
mle_neigh_table_entry_t *entry_temp;
930+
bool new_entry_created;
927931

928932
// Add the parent to the MLE neighbor table
929-
entry_temp = mle_class_get_entry_by_mac64(cur->id, 64, cur->thread_info->thread_endnode_parent->mac64, true);
933+
entry_temp = mle_class_get_entry_by_mac64(cur->id, 64, cur->thread_info->thread_endnode_parent->mac64, true, &new_entry_created);
930934

931935
if (entry_temp) {
932936
entry_temp->short_adr = cur->thread_info->thread_endnode_parent->shortAddress;
@@ -938,7 +942,7 @@ void thread_endevice_synch_start(protocol_interface_info_entry_t *cur)
938942
mle_entry_timeout_update(entry_temp, 20);
939943

940944
// Add the parent to the MAC table (for e.g. secured/fragmented Child Update Response)
941-
mac_helper_devicetable_set(entry_temp, cur, 0, cur->mac_parameters->mac_default_key_index);
945+
mac_helper_devicetable_set(entry_temp, cur, 0, cur->mac_parameters->mac_default_key_index, new_entry_created);
942946
}
943947
}
944948

@@ -996,7 +1000,7 @@ static bool thread_child_id_req_timeout(int8_t interface_id, uint16_t msgId, boo
9961000
memcpy(&ll64[8], scanned_parent->mac64 , 8);
9971001
ll64[8] ^= 2;
9981002

999-
entry_temp = mle_class_get_entry_by_ll64(cur->id, scanned_parent->linkMarginToParent, ll64, false);
1003+
entry_temp = mle_class_get_entry_by_ll64(cur->id, scanned_parent->linkMarginToParent, ll64, false, NULL);
10001004
if (entry_temp) {
10011005
mle_class_remove_entry(cur->id, entry_temp);
10021006
}

source/6LoWPAN/Thread/thread_mle_message_handler.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void thread_general_mle_receive_cb(int8_t interface_id, mle_message_t *mle_msg,
102102
case MLE_COMMAND_REJECT: {
103103
mle_neigh_table_entry_t *entry_temp;
104104
tr_warn("Reject Link");
105-
entry_temp = mle_class_get_entry_by_ll64(cur->id, linkMargin, mle_msg->packet_src_address, false);
105+
entry_temp = mle_class_get_entry_by_ll64(cur->id, linkMargin, mle_msg->packet_src_address, false, NULL);
106106
if (entry_temp) {
107107
mle_class_remove_entry(cur->id, entry_temp);
108108
}
@@ -336,7 +336,7 @@ static void thread_parse_advertisement(protocol_interface_info_entry_t *cur, mle
336336
}
337337

338338
// Get MLE entry
339-
entry_temp = mle_class_get_entry_by_ll64(cur->id, linkMargin, mle_msg->packet_src_address, false);
339+
entry_temp = mle_class_get_entry_by_ll64(cur->id, linkMargin, mle_msg->packet_src_address, false, NULL);
340340

341341
if ((security_headers->KeyIdMode == MAC_KEY_ID_MODE_SRC4_IDX)
342342
&& (thread_instance_id_matches(cur, &leaderData))) {
@@ -409,7 +409,7 @@ static void thread_parse_accept(protocol_interface_info_entry_t *cur, mle_messag
409409
uint16_t messageId;
410410
uint8_t linkMarginfronNeigh;
411411
mle_neigh_table_entry_t *entry_temp;
412-
bool createNew;
412+
bool createNew, new_entry_created;
413413

414414
tr_info("MLE LINK ACCEPT");
415415

@@ -435,7 +435,7 @@ static void thread_parse_accept(protocol_interface_info_entry_t *cur, mle_messag
435435
/* Call to determine whether or not we should create a new link */
436436
createNew = thread_bootstrap_link_create_check(cur, shortAddress);
437437

438-
entry_temp = mle_class_get_entry_by_ll64(cur->id, linkMargin, mle_msg->packet_src_address, createNew);
438+
entry_temp = mle_class_get_entry_by_ll64(cur->id, linkMargin, mle_msg->packet_src_address, createNew, &new_entry_created);
439439

440440
if (!entry_temp) {
441441
thread_link_reject_send(cur, mle_msg->packet_src_address);
@@ -457,7 +457,7 @@ static void thread_parse_accept(protocol_interface_info_entry_t *cur, mle_messag
457457
// Set full data as REED needs full data and SED will not make links
458458
entry_temp->mode |= MLE_THREAD_REQ_FULL_DATA_SET;
459459

460-
mac_helper_devicetable_set(entry_temp, cur, llFrameCounter, security_headers->KeyIndex);
460+
mac_helper_devicetable_set(entry_temp, cur, llFrameCounter, security_headers->KeyIndex, new_entry_created);
461461

462462
if (entry_temp->timeout_rx) {
463463
mle_entry_timeout_refresh(entry_temp);
@@ -551,7 +551,7 @@ static void thread_parse_data_response(protocol_interface_info_entry_t *cur, mle
551551
return;
552552
}
553553

554-
entry_temp = mle_class_get_entry_by_ll64(cur->id, linkMargin, mle_msg->packet_src_address, false);
554+
entry_temp = mle_class_get_entry_by_ll64(cur->id, linkMargin, mle_msg->packet_src_address, false, NULL);
555555

556556
if(cur->thread_info->thread_device_mode == THREAD_DEVICE_MODE_ROUTER ||
557557
cur->thread_info->thread_device_mode == THREAD_DEVICE_MODE_FULL_END_DEVICE) {
@@ -700,7 +700,7 @@ static void thread_host_child_update_request_process(protocol_interface_info_ent
700700
bool data_request_needed = false;
701701

702702
tr_debug("Child update request");
703-
entry_temp = mle_class_get_entry_by_ll64(cur->id, linkMargin, mle_msg->packet_src_address, false);
703+
entry_temp = mle_class_get_entry_by_ll64(cur->id, linkMargin, mle_msg->packet_src_address, false, NULL);
704704

705705
if (!thread_leader_data_parse(mle_msg->data_ptr, mle_msg->data_length, &leaderData) ||
706706
!entry_temp ||
@@ -771,7 +771,7 @@ static void thread_parse_child_update_response(protocol_interface_info_entry_t *
771771

772772
//mle_service_buffer_find
773773
leader_data_received = thread_leader_data_parse(mle_msg->data_ptr, mle_msg->data_length, &leaderData);
774-
entry_temp = mle_class_get_entry_by_ll64(cur->id, linkMargin, mle_msg->packet_src_address, false);
774+
entry_temp = mle_class_get_entry_by_ll64(cur->id, linkMargin, mle_msg->packet_src_address, false, NULL);
775775

776776
if (mle_tlv_read_8_bit_tlv(MLE_TYPE_STATUS, mle_msg->data_ptr, mle_msg->data_length, &status) &&
777777
status == 1 && thread_check_is_this_my_parent(cur, entry_temp)) {

source/6LoWPAN/Thread/thread_network_synch.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ void thread_dynamic_storage_build_mle_table(int8_t interface_id)
238238
tr_debug("Dynamic storage: building MLE table.");
239239

240240
thread_network_dynamic_data_entry_t *storeEntry = thread_network_synch_find(interface_id);
241+
bool new_entry_created;
241242

242243
if (!storeEntry) {
243244
storeEntry = thread_network_synch_create(interface_id);
@@ -261,7 +262,7 @@ void thread_dynamic_storage_build_mle_table(int8_t interface_id)
261262
}
262263
uint8_t *mac64 = storeEntry->networ_dynamic_data_parameters.children[i].long_addr;
263264
tr_debug("Child: %04x, %s", storeEntry->networ_dynamic_data_parameters.children[i].short_addr, trace_array(mac64, 8));
264-
mle_neigh_table_entry_t *entry = mle_class_get_entry_by_mac64(interface_id, 64, mac64, true);
265+
mle_neigh_table_entry_t *entry = mle_class_get_entry_by_mac64(interface_id, 64, mac64, true, &new_entry_created);
265266
if (entry) {
266267
entry->short_adr = storeEntry->networ_dynamic_data_parameters.children[i].short_addr;
267268
entry->mle_frame_counter = storeEntry->networ_dynamic_data_parameters.children[i].mle_frame_counter;
@@ -272,7 +273,7 @@ void thread_dynamic_storage_build_mle_table(int8_t interface_id)
272273

273274
if (cur && cur->mac_parameters) {
274275
// Set MAC layer frame counter for the child
275-
mac_helper_devicetable_set(entry, cur, storeEntry->networ_dynamic_data_parameters.children[i].mac_frame_counter, cur->mac_parameters->mac_default_key_index);
276+
mac_helper_devicetable_set(entry, cur, storeEntry->networ_dynamic_data_parameters.children[i].mac_frame_counter, cur->mac_parameters->mac_default_key_index, new_entry_created);
276277
}
277278
}
278279
}

0 commit comments

Comments
 (0)