Skip to content

Commit c8a99cb

Browse files
Juha Heiskanenjuhhei01
authored andcommitted
MLE service Update and integrate new features
Added support to allocate and delete Framecounter storage list for neighbors Added support to update, delete and request framecounter info Integrated frame counter allocate and frame counter storage use by new API. Removed MLE frame counter storage from mle_table_entry Change-Id: I7fae11d3c47a5db3fbfc2b35a21d8b42df395b8b
1 parent 66636b8 commit c8a99cb

17 files changed

+447
-60
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
11641164
mle_neigh_entry_frame_counter_update(entry_temp, mle_msg->data_ptr, mle_msg->data_length, cur, security_headers->KeyIndex);
11651165
// If MLE frame counter was invalid update its value since three way handshake is complete
11661166
if (security_headers->invalid_frame_counter) {
1167-
entry_temp->mle_frame_counter = security_headers->frameCounter;
1167+
mle_service_frame_counter_table_add(interface_id, entry_temp->attribute_index, security_headers->frameCounter);
11681168
}
11691169
break;
11701170

@@ -1687,6 +1687,10 @@ int8_t arm_6lowpan_bootstarp_bootstrap_set(int8_t interface_id, net_6lowpan_mode
16871687
return -1;
16881688
}
16891689

1690+
if (mle_service_frame_counter_table_allocate(interface_id, buffer.device_decription_table_size)) {
1691+
return -1;
1692+
}
1693+
16901694
if (!etx_storage_list_allocate(cur->id, buffer.device_decription_table_size)) {
16911695
return -1;
16921696
}

source/6LoWPAN/Thread/thread_bootstrap.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
#include "Service_Libs/etx/etx.h"
9393
#include "Service_Libs/nd_proxy/nd_proxy.h"
9494
#include "Service_Libs/blacklist/blacklist.h"
95+
#include "Service_Libs/mle_service/mle_service_api.h"
9596
#include "6LoWPAN/MAC/mac_data_poll.h"
9697
#include "6LoWPAN/lowpan_adaptation_interface.h"
9798

@@ -156,6 +157,10 @@ int8_t thread_mle_class_init(int8_t interface_id)
156157
return -1;
157158
}
158159

160+
if (mle_service_frame_counter_table_allocate(interface_id, buffer.device_decription_table_size)) {
161+
return -1;
162+
}
163+
159164
if (!etx_storage_list_allocate(cur->id, buffer.device_decription_table_size)) {
160165
return -1;
161166
}

source/6LoWPAN/Thread/thread_host_bootstrap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ static bool thread_parent_discover_timeout_cb(int8_t interface_id, uint16_t msgI
165165
entry_temp->short_adr = parent->shortAddress;
166166
entry_temp->priorityFlag = true;
167167
entry_temp->holdTime = 90;
168-
entry_temp->mle_frame_counter = parent->mleFrameCounter;
168+
169+
mle_service_frame_counter_table_add(interface_id, entry_temp->attribute_index, parent->mleFrameCounter);
169170

170171
thread_management_key_sets_calc(cur, linkConfiguration, cur->thread_info->thread_attach_scanned_parent->keySequence);
171172
thread_calculate_key_guard_timer(cur, linkConfiguration, true);

source/6LoWPAN/Thread/thread_mle_message_handler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ static void thread_parse_accept(protocol_interface_info_entry_t *cur, mle_messag
462462

463463
entry_temp->threadNeighbor = true;
464464
entry_temp->short_adr = shortAddress;
465-
entry_temp->mle_frame_counter = mleFrameCounter;
465+
mle_service_frame_counter_table_add(cur->id, entry_temp->attribute_index, mleFrameCounter);
466466
// Set full data as REED needs full data and SED will not make links
467467
entry_temp->mode |= MLE_THREAD_REQ_FULL_DATA_SET;
468468
mlme_device_descriptor_t device_desc;

source/6LoWPAN/Thread/thread_network_synch.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,13 @@ void thread_dynamic_storage_child_info_store(int8_t interface_id, mle_neigh_tabl
167167
return;
168168
}
169169

170+
uint32_t mle_frame_counter = mle_service_frame_counter_get(interface_id, child->attribute_index);
171+
170172
thread_sync_child_info_t *child_info = thread_dynamic_storage_child_info_find(interface_id, child);
171173
if (child_info) {
172174
child_info->mode = child->mode;
173175
child_info->short_addr = child->short_adr;
174-
child_info->mle_frame_counter = child->mle_frame_counter;
176+
child_info->mle_frame_counter = mle_frame_counter;
175177
child_info->mac_frame_counter = 0;
176178
memcpy(child_info->long_addr, child->mac64, 8);
177179
return;
@@ -182,7 +184,7 @@ void thread_dynamic_storage_child_info_store(int8_t interface_id, mle_neigh_tabl
182184
if (child_info) {
183185
child_info->mode = child->mode;
184186
child_info->short_addr = child->short_adr;
185-
child_info->mle_frame_counter = child->mle_frame_counter;
187+
child_info->mle_frame_counter = mle_frame_counter;
186188
child_info->mac_frame_counter = 0;
187189
memcpy(child_info->long_addr, child->mac64, 8);
188190
}
@@ -265,7 +267,7 @@ void thread_dynamic_storage_build_mle_table(int8_t interface_id)
265267
mle_neigh_table_entry_t *entry = mle_class_get_entry_by_mac64(interface_id, 64, mac64, true, &new_entry_created);
266268
if (entry) {
267269
entry->short_adr = storeEntry->networ_dynamic_data_parameters.children[i].short_addr;
268-
entry->mle_frame_counter = storeEntry->networ_dynamic_data_parameters.children[i].mle_frame_counter;
270+
mle_service_frame_counter_table_add(interface_id, entry->attribute_index, storeEntry->networ_dynamic_data_parameters.children[i].mle_frame_counter);
269271
entry->mode = storeEntry->networ_dynamic_data_parameters.children[i].mode;
270272
entry->threadNeighbor = true;
271273

source/6LoWPAN/Thread/thread_router_bootstrap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ static void thread_router_synch_receive_cb(int8_t interface_id, mle_message_t *m
365365
entry_temp->short_adr = shortAddress;
366366

367367
//when allocating neighbour entry, use MLE Frame counter if present to validate further advertisements from the neighbour
368-
entry_temp->mle_frame_counter = mleFrameCounter;
368+
mle_service_frame_counter_table_add(cur->id, entry_temp->attribute_index, mleFrameCounter);
369369
if (entry_temp->timeout_rx) {
370370
mle_entry_timeout_refresh(entry_temp);
371371
} else {
@@ -1331,7 +1331,7 @@ void thread_router_bootstrap_child_id_handler(protocol_interface_info_entry_t *c
13311331
entry_temp->mode = req->mode;
13321332
entry_temp->threadNeighbor = true;
13331333
entry_temp->handshakeReady = 1;
1334-
entry_temp->mle_frame_counter = req->mleFrameCounter;
1334+
mle_service_frame_counter_table_add(cur->id, entry_temp->attribute_index, req->mleFrameCounter);
13351335

13361336
if (req->shortAddressReq) {
13371337
if (!thread_child_id_request(cur, entry_temp)) {

source/MLE/mle.c

Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,29 @@ static void mle_table_remove_free_indirect_table(int8_t interface_id, mle_neigh_
129129
lowpan_adaptation_indirect_free_messages_from_queues_by_address(cur_interface, entry_ptr->mac64, ADDR_802_15_4_LONG);
130130
}
131131

132+
static void mle_table_entry_delete(mle_table_class_t *mle_table_class, mle_neigh_table_entry_t *cur)
133+
{
134+
//Remove from list
135+
ns_list_remove(&mle_table_class->mle_table, cur);
136+
//Free Indirect Queue
137+
mle_table_remove_free_indirect_table(mle_table_class->interfaceId, cur);
138+
//Call Remove callback
139+
mle_table_class->remove_cb(mle_table_class->interfaceId, cur);
140+
141+
topo_trace(TOPOLOGY_MLE, entry->ext64, TOPO_REMOVE);
142+
//Removes ETX neighbor
143+
etx_neighbor_remove(mle_table_class->interfaceId, cur->attribute_index);
144+
//Remove MLE frame counter info
145+
mle_service_frame_counter_table_delete(mle_table_class->interfaceId, cur->attribute_index);
146+
//Add to free list
147+
ns_list_add_to_start(&mle_table_class->free_enty_list, cur);
148+
}
149+
150+
132151
static void mle_table_class_list_free(mle_table_class_t *mle_table_class) {
133152

134153
ns_list_foreach_safe(mle_neigh_table_entry_t, cur, &mle_table_class->mle_table) {
135-
ns_list_remove(&mle_table_class->mle_table, cur);
136-
//Clean Indirect queue
137-
mle_table_remove_free_indirect_table(mle_table_class->interfaceId, cur);
138-
//Call Remove callback
139-
mle_table_class->remove_cb(mle_table_class->interfaceId, cur);
140-
//Removes ETX neighbor
141-
etx_neighbor_remove(mle_table_class->interfaceId, cur->attribute_index);
142-
ns_list_add_to_start(&mle_table_class->free_enty_list, cur);
154+
mle_table_entry_delete(mle_table_class, cur);
143155
}
144156
topo_trace(TOPOLOGY_MLE, NULL, TOPO_CLEAR);
145157
}
@@ -331,7 +343,7 @@ int8_t mle_class_set_new_key_pending(int8_t interface_id)
331343
}
332344

333345
ns_list_foreach_safe(mle_neigh_table_entry_t, cur, &mle_class_ptr->mle_table) {
334-
cur->new_key_pending = true;
346+
mle_service_frame_counter_table_new_key_pending(interface_id, cur->attribute_index);
335347
}
336348

337349
return 0;
@@ -521,9 +533,6 @@ static mle_neigh_table_entry_t *mle_class_get_free_entry(mle_neigh_table_list_t
521533
mle_entry->mode = MLE_FFD_DEV | MLE_RX_ON_IDLE;
522534
mle_entry->holdTime = 7;
523535
mle_entry->last_contact_time = protocol_core_monotonic_time;
524-
mle_entry->mle_frame_counter = 0;
525-
mle_entry->last_key_sequence = 0;
526-
mle_entry->new_key_pending = false;
527536
mle_entry->medium_ttl_challenge = false;
528537
}
529538

@@ -577,18 +586,8 @@ int8_t mle_class_remove_entry(int8_t interface_id, mle_neigh_table_entry_t *entr
577586
if (!mle_class_neighbor_validate(&mle_class_ptr->mle_table, entry)) {
578587
return -2;
579588
}
580-
//Remove from list
581-
ns_list_remove(&mle_class_ptr->mle_table, entry);
582-
//Free Indirect Queue
583-
mle_table_remove_free_indirect_table(mle_class_ptr->interfaceId, entry);
584-
//Call Remove callback
585-
mle_class_ptr->remove_cb(mle_class_ptr->interfaceId, entry);
586-
topo_trace(TOPOLOGY_MLE, entry->ext64, TOPO_REMOVE);
587589

588-
//Removes ETX neighbor
589-
etx_neighbor_remove(interface_id, entry->attribute_index);
590-
//Add to free list
591-
ns_list_add_to_start(&mle_class_ptr->free_enty_list, entry);
590+
mle_table_entry_delete(mle_class_ptr, entry);
592591
return 0;
593592
}
594593

@@ -604,19 +603,7 @@ int8_t mle_class_remove_neighbour(int8_t interface_id, const uint8_t *address, a
604603
if (!entry) {
605604
return -2;
606605
}
607-
//Remove from list
608-
ns_list_remove(&mle_class_ptr->mle_table, entry);
609-
//Free Indirect Queue
610-
mle_table_remove_free_indirect_table(mle_class_ptr->interfaceId, entry);
611-
//Call Remove callback
612-
mle_class_ptr->remove_cb(mle_class_ptr->interfaceId, entry);
613-
614-
topo_trace(TOPOLOGY_MLE, entry->ext64, TOPO_REMOVE);
615-
616-
//Removes ETX neighbor
617-
etx_neighbor_remove(interface_id, entry->attribute_index);
618-
//Add to free list
619-
ns_list_add_to_start(&mle_class_ptr->free_enty_list, entry);
606+
mle_table_entry_delete(mle_class_ptr, entry);
620607

621608
return 0;
622609

@@ -682,17 +669,7 @@ static void mle_class_table_ttl(uint16_t ticks, mle_table_class_t *mle_class_ptr
682669

683670
if (remove_entry) {
684671
//Silence delete
685-
//Remove from list
686-
ns_list_remove(&mle_class_ptr->mle_table, cur);
687-
//Free Indirect Queue
688-
mle_table_remove_free_indirect_table(mle_class_ptr->interfaceId, cur);
689-
mle_class_ptr->remove_cb(mle_class_ptr->interfaceId, cur);
690-
topo_trace(TOPOLOGY_MLE, cur->ext64, TOPO_REMOVE);
691-
//Removes ETX neighbor
692-
etx_neighbor_remove(mle_class_ptr->interfaceId, cur->attribute_index);
693-
//Add to free list
694-
ns_list_add_to_start(&mle_class_ptr->free_enty_list, cur);
695-
672+
mle_table_entry_delete(mle_class_ptr, cur);
696673
}
697674
} // for each entry
698675

source/MLE/mle.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,13 @@ typedef struct mle_neigh_table_entry_t {
148148
uint8_t attribute_index;
149149
uint16_t ttl; /*!< destination TTL * 4 seconds */
150150
uint32_t last_contact_time; /*!< monotonic time - hard to define "contact"; used for Thread Leasequery replies */
151-
uint32_t mle_frame_counter;
152151
uint16_t timeout_rx;
153152
uint16_t holdTime;
154153
uint16_t link_margin;
155154
uint8_t mac64[8]; /*!< MAC64 */
156155
uint8_t mlEid[8];
157156
uint16_t short_adr;
158157
uint8_t mode;
159-
uint32_t last_key_sequence;
160-
unsigned new_key_pending:1;
161158
unsigned link_q_adv_sent: 1;
162159
unsigned priority_child_flag: 1; /* Is using our node as preferred parent */
163160
unsigned second_priority_flag: 1; /* Is secondary parent */

source/Service_Libs/mle_service/mle_service.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "Service_Libs/mle_service/mle_service_security.h"
3636
#include "Service_Libs/mle_service/mle_service_buffer.h"
3737
#include "Service_Libs/mle_service/mle_service_interface.h"
38+
#include "Service_Libs/mle_service/mle_service_frame_counter_table.h"
3839
#include "MLE/mle.h"
3940
#include "MLE/mle_tlv.h"
4041
#include "mac_common_defines.h"
@@ -654,6 +655,15 @@ static int mle_service_build_packet_send(service_instance_t *srv_ptr, mle_securi
654655
return 0;
655656
}
656657

658+
static mle_neighbor_security_counter_info_t *mle_service_get_neighbour_info(int8_t interface_id, uint8_t *ll64)
659+
{
660+
mle_neigh_table_entry_t *neighbour = mle_class_discover_entry_by_ll64(interface_id,ll64);
661+
if (!neighbour) {
662+
return NULL;
663+
}
664+
return mle_service_counter_info_get(interface_id, neighbour->attribute_index);
665+
}
666+
657667
static void mle_service_socket_callback(void *cb)
658668
{
659669
socket_buffer_callback_t *cb_buf = cb;
@@ -729,7 +739,7 @@ static void mle_service_socket_callback(void *cb)
729739

730740

731741
/* MLE neighbour table frame counter check */
732-
mle_neigh_table_entry_t *neighbour = NULL;
742+
mle_neighbor_security_counter_info_t *neighbour = NULL;
733743
uint32_t keySeq;
734744
if (securityHeader.KeyIdMode == MAC_KEY_ID_MODE_SRC4_IDX) {
735745
keySeq = common_read_32_bit(securityHeader.Keysource);
@@ -738,7 +748,7 @@ static void mle_service_socket_callback(void *cb)
738748
}
739749

740750
if (mle_service->mle_frame_counter_check_enabled) {
741-
neighbour = mle_class_discover_entry_by_ll64(service_handler->interface_id,buf->src_sa.address);
751+
neighbour = mle_service_get_neighbour_info(service_handler->interface_id,buf->src_sa.address);
742752
if (neighbour){
743753
//key pending is set - incoming frame counter will be reset when new sequence is heard or lower framecounter is heard
744754
if (neighbour->new_key_pending) {

source/Service_Libs/mle_service/mle_service_api.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ uint8_t retrans_max; /*!< Define max packet TX count */
132132
uint8_t delay; /*!< 100ms Ticks for random delay */
133133
} mle_message_timeout_params_t;
134134

135+
135136
/**
136137
* MLE service message receiver handler call back function pointer
137138
*
@@ -719,6 +720,69 @@ void mle_service_set_fragmented_msg_ll_security(bool value);
719720
*/
720721
void mle_service_set_accept_invalid_frame_counter(bool value);
721722

723+
724+
/**
725+
* Commands MLE service to allocate mle frame counter table for giving neighbor count.
726+
*
727+
* \param interface_id Interface ID
728+
* \param table_size Table size
729+
*
730+
* \return 0 Allocate OK
731+
* \return -1 Allocate Fail
732+
*
733+
*/
734+
int mle_service_frame_counter_table_allocate(int8_t interface_id, uint8_t table_size);
735+
736+
/**
737+
* Commands MLE service to free mle frame counter table
738+
*
739+
* \param interface_id Interface ID
740+
*
741+
* \return 0 Free OK
742+
* \return -1 Free Fail
743+
*
744+
*/
745+
int mle_service_frame_counter_table_free(int8_t interface_id);
746+
747+
/**
748+
* Commands MLE service to add / Update frame counter to neighbor
749+
*
750+
* \param interface_id Interface ID
751+
* \param attribute_index Attribute index for neighbor
752+
* \param frame_counter MLE frame counter
753+
*
754+
*/
755+
void mle_service_frame_counter_table_add(int8_t interface_id, uint8_t attribute_index, uint32_t frame_counter);
756+
757+
/**
758+
* Commands MLE service get mle frame counter for neighbor
759+
*
760+
* \param interface_id Interface ID
761+
* \param attribute_index Attribute index for neighbor
762+
*
763+
* \return Stored Frame Counter, may return 0 if unknow attribute
764+
*
765+
*/
766+
uint32_t mle_service_frame_counter_get(int8_t interface_id, uint8_t attribute_index);
767+
768+
/**
769+
* Commands MLE service frame counter new key pending state activate
770+
*
771+
* \param interface_id Interface ID
772+
* \param attribute_index Attribute index for neighbor
773+
*
774+
*/
775+
void mle_service_frame_counter_table_new_key_pending(int8_t interface_id, uint8_t attribute_index);
776+
777+
/**
778+
* Commands MLE service frame counter info delete
779+
*
780+
* \param interface_id Interface ID
781+
* \param attribute_index Attribute index for neighbor
782+
*
783+
*/
784+
void mle_service_frame_counter_table_delete(int8_t interface_id, uint8_t attribute_index);
785+
722786
#ifdef MLE_TEST
723787
/**
724788
* Set callback for MLE receiving packet filtering.

0 commit comments

Comments
 (0)