Skip to content

Commit a43f6ad

Browse files
Juha Heiskanenjuhhei01
authored andcommitted
Mac helper API update:
mac_helper_device_description_write() mle_neigh_table_entry_t replaced by generic standard mlme_device_descriptor_t. Added new function: mac_helper_device_description_write() which will help to use updated mac_helper_device_description_write(). Integrated new API changes to code.
1 parent 14792db commit a43f6ad

File tree

10 files changed

+64
-32
lines changed

10 files changed

+64
-32
lines changed

source/6LoWPAN/MAC/mac_helper.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "net_nwk_scan.h"
2626
#include "ns_trace.h"
2727
#include "common_functions.h"
28-
#include "MLE/mle_tlv.h"
2928
#include "mac_api.h"
3029

3130
#define TRACE_GROUP "MACh"
@@ -830,7 +829,16 @@ void mac_helper_devicetable_remove(mac_api_t *mac_api, uint8_t attribute_index)
830829
mac_api->mlme_req(mac_api,MLME_SET , &set_req);
831830
}
832831

833-
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)
832+
void mac_helper_device_description_write(protocol_interface_info_entry_t *cur, mlme_device_descriptor_t *device_desc, uint8_t *mac64, uint16_t mac16, uint32_t frame_counter, bool exempt)
833+
{
834+
memcpy(device_desc->ExtAddress, mac64, 8);
835+
device_desc->ShortAddress = mac16;
836+
device_desc->PANId = mac_helper_panid_get(cur);
837+
device_desc->Exempt = exempt;
838+
device_desc->FrameCounter = frame_counter;
839+
}
840+
841+
void mac_helper_devicetable_set(const mlme_device_descriptor_t *device_desc, protocol_interface_info_entry_t *cur, uint8_t attribute_index, uint8_t keyID)
834842
{
835843
if (!cur->mac_api) {
836844
return;
@@ -841,18 +849,10 @@ void mac_helper_devicetable_set(mle_neigh_table_entry_t *entry_temp, protocol_in
841849
return;
842850
}
843851

844-
mlme_device_descriptor_t device_desc;
845852
mlme_set_t set_req;
846-
device_desc.FrameCounter = frame_counter;
847-
device_desc.Exempt = false;
848-
device_desc.ShortAddress = entry_temp->short_adr;
849-
memcpy(device_desc.ExtAddress, entry_temp->mac64, 8);
850-
device_desc.PANId = mac_helper_panid_get(cur);
851-
852-
853853
set_req.attr = macDeviceTable;
854-
set_req.attr_index = entry_temp->attribute_index;
855-
set_req.value_pointer = (void*)&device_desc;
854+
set_req.attr_index = attribute_index;
855+
set_req.value_pointer = (void*)device_desc;
856856
set_req.value_size = sizeof(mlme_device_descriptor_t);
857857
tr_debug("Register Device");
858858
cur->mac_api->mlme_req(cur->mac_api,MLME_SET , &set_req);

source/6LoWPAN/MAC/mac_helper.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ struct protocol_interface_info_entry;
2929
struct ns_sockaddr;
3030
struct buffer;
3131
struct mac_api_s;
32-
struct mle_neigh_table_entry_t;
3332

3433

3534
void mac_create_scan_request(mac_scan_type_t type, struct channel_list_s *chanlist, uint8_t scan_duration, struct mlme_scan_s *request);
@@ -110,7 +109,9 @@ int8_t mac_helper_link_frame_counter_set(int8_t interface_id, uint32_t seq_ptr);
110109

111110
void mac_helper_devicetable_remove(struct mac_api_s *mac_api, uint8_t attribute_index);
112111

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);
112+
void mac_helper_device_description_write(struct protocol_interface_info_entry *cur, mlme_device_descriptor_t *device_desc, uint8_t *mac64, uint16_t mac16, uint32_t frame_counter, bool exempt);
113+
114+
void mac_helper_devicetable_set(const mlme_device_descriptor_t *device_dec, struct protocol_interface_info_entry *cur, uint8_t attribute_index, uint8_t keyID);
114115

115116
int8_t mac_helper_mac_mlme_max_retry_set(int8_t interface_id, uint8_t mac_retry_set);
116117

source/6LoWPAN/MAC/mac_pairwise_key.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,9 @@ int mac_pairwise_key_add(int8_t interface_id, uint32_t valid_life_time, const ui
281281
return -1;
282282
}
283283

284-
//Set device descriptor
285-
mac_helper_devicetable_set(mle_entry, interface, 0, interface->mac_parameters->mac_default_key_index);
284+
mlme_device_descriptor_t device_desc;
285+
mac_helper_device_description_write(interface, &device_desc, mle_entry->mac64, mle_entry->short_adr,0, false);
286+
mac_helper_devicetable_set(&device_desc, interface,mle_entry->attribute_index, interface->mac_parameters->mac_default_key_index);
286287

287288
//set key descriptor
288289
if (mac_helper_security_pairwisekey_set(interface, key, eui64, key_desc->key_decriptor_attribute) != 0) {

source/6LoWPAN/Thread/thread_host_bootstrap.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ static bool thread_parent_discover_timeout_cb(int8_t interface_id, uint16_t msgI
172172
thread_management_key_sets_calc(cur, linkConfiguration, cur->thread_info->thread_attach_scanned_parent->keySequence);
173173
thread_calculate_key_guard_timer(cur, linkConfiguration, true);
174174

175-
mac_helper_devicetable_set(entry_temp, cur, parent->linLayerFrameCounter, mac_helper_default_key_index_get(cur));
175+
mlme_device_descriptor_t device_desc;
176+
mac_helper_device_description_write(cur, &device_desc, entry_temp->mac64, entry_temp->short_adr,parent->linLayerFrameCounter, false);
177+
mac_helper_devicetable_set(&device_desc, cur,entry_temp->attribute_index, mac_helper_default_key_index_get(cur));
176178
mle_entry_timeout_update(entry_temp, THREAD_DEFAULT_LINK_LIFETIME);
177179

178180
if (cur->thread_info->thread_device_mode == THREAD_DEVICE_MODE_SLEEPY_END_DEVICE) {
@@ -343,7 +345,10 @@ static int thread_end_device_synch_response_validate(protocol_interface_info_ent
343345

344346
mac_helper_coordinator_address_set(cur, ADDR_802_15_4_SHORT, shortAddress);
345347
mle_entry_timeout_update(entry_temp, thread_info(cur)->host_link_timeout);
346-
mac_helper_devicetable_set(entry_temp, cur, llFrameCounter, securityHeader->KeyIndex);
348+
349+
mlme_device_descriptor_t device_desc;
350+
mac_helper_device_description_write(cur, &device_desc, entry_temp->mac64, entry_temp->short_adr,llFrameCounter, false);
351+
mac_helper_devicetable_set(&device_desc, cur, entry_temp->attribute_index, securityHeader->KeyIndex);
347352

348353
thread_info(cur)->thread_attached_state = THREAD_STATE_CONNECTED;
349354
thread_bootstrap_update_ml16_address(cur, address16);
@@ -832,7 +837,10 @@ static void thread_mle_child_request_receive_cb(int8_t interface_id, mle_message
832837

833838
mac_helper_coordinator_address_set(cur, ADDR_802_15_4_SHORT, shortAddress);
834839
mle_entry_timeout_update(entry_temp, thread_info(cur)->host_link_timeout);
835-
mac_helper_devicetable_set(entry_temp, cur, scan_result->linLayerFrameCounter, security_headers->KeyIndex);
840+
841+
mlme_device_descriptor_t device_desc;
842+
mac_helper_device_description_write(cur, &device_desc, entry_temp->mac64, entry_temp->short_adr,scan_result->linLayerFrameCounter, false);
843+
mac_helper_devicetable_set(&device_desc, cur, entry_temp->attribute_index, security_headers->KeyIndex);
836844

837845
thread_info(cur)->thread_attached_state = THREAD_STATE_CONNECTED;
838846

@@ -941,7 +949,9 @@ void thread_endevice_synch_start(protocol_interface_info_entry_t *cur)
941949
mle_entry_timeout_update(entry_temp, 20);
942950

943951
// Add the parent to the MAC table (for e.g. secured/fragmented Child Update Response)
944-
mac_helper_devicetable_set(entry_temp, cur, 0, cur->mac_parameters->mac_default_key_index);
952+
mlme_device_descriptor_t device_desc;
953+
mac_helper_device_description_write(cur, &device_desc, entry_temp->mac64, entry_temp->short_adr,0, false);
954+
mac_helper_devicetable_set(&device_desc, cur, entry_temp->attribute_index, cur->mac_parameters->mac_default_key_index);
945955
}
946956
}
947957

source/6LoWPAN/Thread/thread_mle_message_handler.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,9 @@ static void thread_parse_accept(protocol_interface_info_entry_t *cur, mle_messag
456456
entry_temp->mle_frame_counter = mleFrameCounter;
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;
459-
460-
mac_helper_devicetable_set(entry_temp, cur, llFrameCounter, security_headers->KeyIndex);
459+
mlme_device_descriptor_t device_desc;
460+
mac_helper_device_description_write(cur, &device_desc, entry_temp->mac64, entry_temp->short_adr,llFrameCounter, false);
461+
mac_helper_devicetable_set(&device_desc, cur, entry_temp->attribute_index, security_headers->KeyIndex);
461462

462463
if (entry_temp->timeout_rx) {
463464
mle_entry_timeout_refresh(entry_temp);

source/6LoWPAN/Thread/thread_network_synch.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,9 @@ void thread_dynamic_storage_build_mle_table(int8_t interface_id)
272272

273273
if (cur && cur->mac_parameters) {
274274
// 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);
275+
mlme_device_descriptor_t device_desc;
276+
mac_helper_device_description_write(cur, &device_desc, entry->mac64, entry->short_adr,storeEntry->networ_dynamic_data_parameters.children[i].mac_frame_counter, false);
277+
mac_helper_devicetable_set(&device_desc, cur, entry->attribute_index, cur->mac_parameters->mac_default_key_index);
276278
}
277279
}
278280
}

source/6LoWPAN/Thread/thread_router_bootstrap.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ static void thread_router_synch_receive_cb(int8_t interface_id, mle_message_t *m
361361
//Free Response
362362
mle_service_msg_free(messageId);
363363
entry_temp->threadNeighbor = true;
364-
mac_helper_devicetable_set(entry_temp, cur, llFrameCounter, security_headers->KeyIndex);
365364
entry_temp->short_adr = shortAddress;
365+
366366
//when allocating neighbour entry, use MLE Frame counter if present to validate further advertisements from the neighbour
367367
entry_temp->mle_frame_counter = mleFrameCounter;
368368
if (entry_temp->timeout_rx) {
@@ -388,7 +388,9 @@ static void thread_router_synch_receive_cb(int8_t interface_id, mle_message_t *m
388388
thread_routing_update_link_margin(cur, entry_temp->short_adr, linkMargin, linkMarginfronNeigh);
389389
}
390390

391-
mac_helper_devicetable_set(entry_temp, cur, llFrameCounter, security_headers->KeyIndex);
391+
mlme_device_descriptor_t device_desc;
392+
mac_helper_device_description_write(cur, &device_desc, entry_temp->mac64, entry_temp->short_adr,llFrameCounter, false);
393+
mac_helper_devicetable_set(&device_desc, cur, entry_temp->attribute_index, security_headers->KeyIndex);
392394

393395
//Copy Leader Data
394396
*cur->thread_info->thread_leader_data = leaderData;
@@ -1340,7 +1342,9 @@ void thread_router_bootstrap_child_id_handler(protocol_interface_info_entry_t *c
13401342
}
13411343
}
13421344
if (new_neigbour) {
1343-
mac_helper_devicetable_set(entry_temp, cur, req->frameCounter, req->keyId);
1345+
mlme_device_descriptor_t device_desc;
1346+
mac_helper_device_description_write(cur, &device_desc, entry_temp->mac64, entry_temp->short_adr,req->frameCounter, false);
1347+
mac_helper_devicetable_set(&device_desc, cur, entry_temp->attribute_index, req->keyId);
13441348
} else {
13451349
// in get response handler this will update the short address from MLE table
13461350
mlme_get_t get_req;
@@ -1863,7 +1867,9 @@ void thread_router_bootstrap_mle_receive_cb(int8_t interface_id, mle_message_t *
18631867

18641868
entry_temp->threadNeighbor = true;
18651869
entry_temp->short_adr = shortAddress;
1866-
mac_helper_devicetable_set(entry_temp, cur, llFrameCounter, security_headers->KeyIndex);
1870+
mlme_device_descriptor_t device_desc;
1871+
mac_helper_device_description_write(cur, &device_desc, entry_temp->mac64, entry_temp->short_adr,llFrameCounter, false);
1872+
mac_helper_devicetable_set(&device_desc, cur, entry_temp->attribute_index, security_headers->KeyIndex);
18671873
if (entry_temp->timeout_rx) {
18681874
mle_entry_timeout_refresh(entry_temp);
18691875
} else {

source/MLE/mle.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,9 @@ bool mle_neigh_entry_frame_counter_update(mle_neigh_table_entry_t *entry_temp, u
787787
} else {
788788
frame_counter = common_read_32_bit(mle_tlv_info.dataPtr);
789789
}
790-
791-
mac_helper_devicetable_set(entry_temp, cur, frame_counter, key_id);
790+
mlme_device_descriptor_t device_desc;
791+
mac_helper_device_description_write(cur, &device_desc, entry_temp->mac64, entry_temp->short_adr,frame_counter, false);
792+
mac_helper_devicetable_set(&device_desc, cur, entry_temp->attribute_index, key_id);
792793
return true;
793794
}
794795

test/nanostack/unittest/6lp_mac/mac_helper/test_mac_helper.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,14 +853,18 @@ bool test_mac_helper_devicetable_set()
853853
api.mlme_req = &mlme_req;
854854
entry.mac_api = &api;
855855

856+
mlme_device_descriptor_t device_desc;
857+
mac_helper_device_description_write(&entry, &device_desc, entry_temp.mac64, entry_temp.short_adr,10, false);
858+
856859
entry.mac_parameters->SecurityEnabled = false;
857860

858-
mac_helper_devicetable_set(&entry_temp, &entry, 10, 1);
861+
862+
mac_helper_devicetable_set(&device_desc, &entry, entry_temp.attribute_index, 1);
859863

860864
entry.mac_parameters->SecurityEnabled = true;
861865
entry.mac_parameters->mac_default_key_index = 2;
862866

863-
mac_helper_devicetable_set(&entry_temp, &entry, 10, 1);
867+
mac_helper_devicetable_set(&device_desc, &entry, entry_temp.attribute_index, 1);
864868

865869

866870
return true;

test/nanostack/unittest/stub/mac_helper_stub.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,16 @@ void mac_helper_devicetable_remove(struct mac_api_s *mac_api, uint8_t attribute_
244244

245245
}
246246

247-
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)
247+
void mac_helper_device_description_write(struct protocol_interface_info_entry *cur, mlme_device_descriptor_t *device_desc, uint8_t *mac64, uint16_t mac16, uint32_t frame_counter, bool exempt)
248248
{
249249

250250
}
251+
252+
void mac_helper_devicetable_set(const mlme_device_descriptor_t *device_dec, protocol_interface_info_entry_t *cur, uint8_t attribute_index, uint8_t keyID)
253+
{
254+
255+
}
256+
251257
int8_t mac_helper_mac_mlme_max_retry_set(int8_t interface_id, uint8_t mac_retry_set)
252258
{
253259

0 commit comments

Comments
 (0)