Skip to content

Commit 6d288ce

Browse files
author
Juha Heiskanen
committed
MAC security update:
Device table get verify now PAN-id field also which is new parameter. MAC security by pass from unknow device only accetp from configured PAN-id Wi-sun LLC drop Data packet from different PAN-id. WS-eapol target set after Mac start which set a proper PAN-id to device. Change-Id: I0132a02f259abcdf0989747428a0968a07ab9555
1 parent c870b76 commit 6d288ce

File tree

8 files changed

+41
-32
lines changed

8 files changed

+41
-32
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,6 +2716,11 @@ void ws_bootstrap_network_scan_process(protocol_interface_info_entry_t *cur)
27162716
tr_info("selected parent:%s panid %u", trace_array(selected_parent_ptr->addr, 8), selected_parent_ptr->pan_id);
27172717

27182718
// Add EAPOL neighbour
2719+
cur->ws_info->network_pan_id = selected_parent_ptr->pan_id;
2720+
cur->ws_info->pan_information = selected_parent_ptr->pan_information;
2721+
cur->ws_info->pan_information.pan_version = 0; // This is learned from actual configuration
2722+
2723+
ws_bootstrap_fhss_activate(cur);
27192724
llc_neighbour_req_t neighbor_info;
27202725
if (!ws_bootstrap_neighbor_info_request(cur, selected_parent_ptr->addr, &neighbor_info, true)) {
27212726
return;
@@ -2724,12 +2729,6 @@ void ws_bootstrap_network_scan_process(protocol_interface_info_entry_t *cur)
27242729
ws_neighbor_class_neighbor_unicast_time_info_update(neighbor_info.ws_neighbor, &selected_parent_ptr->ws_utt, selected_parent_ptr->timestamp);
27252730
ws_neighbor_class_neighbor_unicast_schedule_set(neighbor_info.ws_neighbor, &selected_parent_ptr->ws_us);
27262731

2727-
cur->ws_info->network_pan_id = selected_parent_ptr->pan_id;
2728-
cur->ws_info->pan_information = selected_parent_ptr->pan_information;
2729-
cur->ws_info->pan_information.pan_version = 0; // This is learned from actual configuration
2730-
2731-
ws_bootstrap_fhss_activate(cur);
2732-
27332732
ws_pae_controller_set_target(cur, selected_parent_ptr->pan_id, selected_parent_ptr->addr); // temporary!!! store since auth
27342733
ws_bootstrap_event_authentication_start(cur);
27352734
return;

source/6LoWPAN/ws/ws_llc_data_service.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,11 @@ static void ws_llc_mac_indication_cb(const mac_api_t *api, const mcps_data_ind_t
514514
return;
515515
}
516516

517+
if (interface->mac_parameters->pan_id != 0xffff && data->SrcPANId != interface->mac_parameters->pan_id) {
518+
//Drop wrong PAN-id messages in this phase.
519+
return;
520+
}
521+
517522
mpx_user_t *user_cb;
518523
mac_payload_IE_t mpx_ie;
519524
mpx_ie.id = MAC_PAYLOAD_MPX_IE_GROUP_ID;

source/MAC/IEEE802_15_4/mac_mcps_sap.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -572,9 +572,9 @@ static uint8_t mac_data_interface_decrypt_packet(mac_pre_parsed_frame_t *b, mlme
572572
} else {
573573

574574
if (!b->neigh_info) {
575-
if (rf_mac_setup->mac_security_bypass_unknow_device && (b->fcf_dsn.SrcAddrMode == MAC_ADDR_MODE_64_BIT
576-
&& security_params->SecurityLevel > AES_SECURITY_LEVEL_ENC)) {
577-
security_by_pass = true;
575+
if (SrcPANId == rf_mac_setup->pan_id && rf_mac_setup->mac_security_bypass_unknow_device &&
576+
(b->fcf_dsn.SrcAddrMode == MAC_ADDR_MODE_64_BIT && security_params->SecurityLevel > AES_SECURITY_LEVEL_ENC)) {
577+
security_by_pass = true;//Accept by pass only from same PAN-ID
578578
} else {
579579
return MLME_UNSUPPORTED_SECURITY;
580580
}
@@ -723,7 +723,7 @@ static int8_t mac_data_sap_rx_handler(mac_pre_parsed_frame_t *buf, protocol_inte
723723
/* Parse security part */
724724
mac_header_security_components_read(buf, &data_ind->Key);
725725

726-
buf->neigh_info = mac_sec_mib_device_description_get(rf_mac_setup, data_ind->SrcAddr, data_ind->SrcAddrMode);
726+
buf->neigh_info = mac_sec_mib_device_description_get(rf_mac_setup, data_ind->SrcAddr, data_ind->SrcAddrMode, data_ind->SrcPANId);
727727
if (buf->fcf_dsn.securityEnabled) {
728728
status = mac_data_interface_decrypt_packet(buf, &data_ind->Key);
729729
if (status != MLME_SUCCESS) {
@@ -846,7 +846,8 @@ static int8_t mac_command_sap_rx_handler(mac_pre_parsed_frame_t *buf, protocol_i
846846
//Read address and pan-id
847847
mac_header_get_src_address(&buf->fcf_dsn, mac_header_message_start_pointer(buf), temp_src_address);
848848
uint8_t address_mode = buf->fcf_dsn.SrcAddrMode;
849-
buf->neigh_info = mac_sec_mib_device_description_get(rf_mac_setup, temp_src_address, address_mode);
849+
uint16_t pan_id = mac_header_get_src_panid(&buf->fcf_dsn, mac_header_message_start_pointer(buf), rf_mac_setup->pan_id);
850+
buf->neigh_info = mac_sec_mib_device_description_get(rf_mac_setup, temp_src_address, address_mode, pan_id);
850851
//Decrypt Packet if secured
851852
if (buf->fcf_dsn.securityEnabled) {
852853
mac_header_security_components_read(buf, &security_params);
@@ -1082,10 +1083,11 @@ static int8_t mac_ack_sap_rx_handler(mac_pre_parsed_frame_t *buf, protocol_inter
10821083
memset(SrcAddr, 0, 8);
10831084
memset(&key, 0, sizeof(mlme_security_t));
10841085
mac_header_get_src_address(&buf->fcf_dsn, mac_header_message_start_pointer(buf), SrcAddr);
1086+
uint16_t pan_id = mac_header_get_src_panid(&buf->fcf_dsn, mac_header_message_start_pointer(buf), rf_mac_setup->pan_id);
10851087
/* Parse security part */
10861088
mac_header_security_components_read(buf, &key);
10871089

1088-
buf->neigh_info = mac_sec_mib_device_description_get(rf_mac_setup, SrcAddr, buf->fcf_dsn.SrcAddrMode);
1090+
buf->neigh_info = mac_sec_mib_device_description_get(rf_mac_setup, SrcAddr, buf->fcf_dsn.SrcAddrMode, pan_id);
10891091
if (buf->fcf_dsn.securityEnabled) {
10901092
uint8_t status = mac_data_interface_decrypt_packet(buf, &key);
10911093
if (status != MLME_SUCCESS) {
@@ -1276,7 +1278,7 @@ static bool mac_frame_security_parameters_init(ccm_globals_t *ccm_ptr, protocol_
12761278
} else {
12771279
//Discover device descriptor only unicast packet which need ack
12781280
if (buffer->fcf_dsn.DstAddrMode && buffer->fcf_dsn.ackRequested) {
1279-
device_description = mac_sec_mib_device_description_get(rf_ptr, buffer->DstAddr, buffer->fcf_dsn.DstAddrMode);
1281+
device_description = mac_sec_mib_device_description_get(rf_ptr, buffer->DstAddr, buffer->fcf_dsn.DstAddrMode, buffer->DstPANId);
12801282
if (!device_description) {
12811283
buffer->status = MLME_UNAVAILABLE_KEY;
12821284
return false;

source/MAC/IEEE802_15_4/mac_pd_sap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ static int8_t mac_data_interface_tx_done_cb(protocol_interface_rf_mac_setup_s *r
429429

430430
if (rf_ptr->mac_ack_tx_active) {
431431
//Accept direct non crypted acks and crypted only if neighbor is at list
432-
if (rf_ptr->ack_tx_possible || mac_sec_mib_device_description_get(rf_ptr, rf_ptr->enhanced_ack_buffer.DstAddr, rf_ptr->enhanced_ack_buffer.fcf_dsn.DstAddrMode)) {
432+
if (rf_ptr->ack_tx_possible || mac_sec_mib_device_description_get(rf_ptr, rf_ptr->enhanced_ack_buffer.DstAddr, rf_ptr->enhanced_ack_buffer.fcf_dsn.DstAddrMode, rf_ptr->enhanced_ack_buffer.DstPANId)) {
433433
return PHY_TX_ALLOWED;
434434
}
435435

@@ -772,7 +772,7 @@ static int8_t mac_pd_sap_generate_ack(protocol_interface_rf_mac_setup_s *rf_ptr,
772772
return -1;
773773
}
774774

775-
if (rf_ptr->enhanced_ack_buffer.aux_header.securityLevel == 0 || mac_sec_mib_device_description_get(rf_ptr, rf_ptr->enhanced_ack_buffer.DstAddr, rf_ptr->enhanced_ack_buffer.fcf_dsn.DstAddrMode)) {
775+
if (rf_ptr->enhanced_ack_buffer.aux_header.securityLevel == 0 || mac_sec_mib_device_description_get(rf_ptr, rf_ptr->enhanced_ack_buffer.DstAddr, rf_ptr->enhanced_ack_buffer.fcf_dsn.DstAddrMode, rf_ptr->enhanced_ack_buffer.DstPANId)) {
776776
rf_ptr->ack_tx_possible = true;
777777
} else {
778778
rf_ptr->ack_tx_possible = false;

source/MAC/IEEE802_15_4/mac_security_mib.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static void mac_sec_mib_frame_counter_key_buffer_free(protocol_interface_rf_mac_
115115
rf_mac_setup->secFrameCounterPerKey = false;
116116
}
117117

118-
static mlme_device_descriptor_t *mac_sec_mib_device_description_get_by_mac16(protocol_interface_rf_mac_setup_s *rf_mac_setup, uint16_t mac16)
118+
static mlme_device_descriptor_t *mac_sec_mib_device_description_get_by_mac16(protocol_interface_rf_mac_setup_s *rf_mac_setup, uint16_t mac16, uint16_t pan_id)
119119
{
120120

121121
mlme_device_descriptor_t *device_table = rf_mac_setup->device_description_table;
@@ -124,7 +124,7 @@ static mlme_device_descriptor_t *mac_sec_mib_device_description_get_by_mac16(pro
124124
}
125125

126126
for (int i = 0; i < rf_mac_setup->device_description_table_size; i++) {
127-
if (device_table->ShortAddress == mac16) {
127+
if ((pan_id == 0xffff || device_table->PANId == pan_id) && device_table->ShortAddress == mac16) {
128128
return device_table;
129129
}
130130
device_table++;
@@ -133,7 +133,7 @@ static mlme_device_descriptor_t *mac_sec_mib_device_description_get_by_mac16(pro
133133
return NULL;
134134
}
135135

136-
static mlme_device_descriptor_t *mac_sec_mib_device_description_get_by_mac64(protocol_interface_rf_mac_setup_s *rf_mac_setup, const uint8_t *mac64)
136+
static mlme_device_descriptor_t *mac_sec_mib_device_description_get_by_mac64(protocol_interface_rf_mac_setup_s *rf_mac_setup, const uint8_t *mac64, uint16_t pan_id)
137137
{
138138

139139
mlme_device_descriptor_t *device_table = rf_mac_setup->device_description_table;
@@ -142,8 +142,10 @@ static mlme_device_descriptor_t *mac_sec_mib_device_description_get_by_mac64(pro
142142
}
143143

144144
for (int i = 0; i < rf_mac_setup->device_description_table_size; i++) {
145-
if (memcmp(device_table->ExtAddress, mac64, 8) == 0) {
146-
return device_table;
145+
if ((pan_id == 0xffff || device_table->PANId == pan_id)) {
146+
if (memcmp(device_table->ExtAddress, mac64, 8) == 0) {
147+
return device_table;
148+
}
147149
}
148150
device_table++;
149151
}
@@ -365,14 +367,14 @@ mlme_device_descriptor_t *mac_sec_mib_device_description_get_attribute_index(pro
365367
return rf_mac_setup->device_description_table + attribute_index;
366368
}
367369

368-
mlme_device_descriptor_t *mac_sec_mib_device_description_get(protocol_interface_rf_mac_setup_s *rf_mac_setup, const uint8_t *address, uint8_t type)
370+
mlme_device_descriptor_t *mac_sec_mib_device_description_get(protocol_interface_rf_mac_setup_s *rf_mac_setup, const uint8_t *address, uint8_t type, uint16_t pan_id)
369371
{
370372
if (rf_mac_setup) {
371373
if (type == MAC_ADDR_MODE_16_BIT) {
372374
uint16_t short_id = common_read_16_bit(address);
373-
return mac_sec_mib_device_description_get_by_mac16(rf_mac_setup, short_id);
375+
return mac_sec_mib_device_description_get_by_mac16(rf_mac_setup, short_id, pan_id);
374376
} else if (type == MAC_ADDR_MODE_64_BIT) {
375-
return mac_sec_mib_device_description_get_by_mac64(rf_mac_setup, address);
377+
return mac_sec_mib_device_description_get_by_mac64(rf_mac_setup, address, pan_id);
376378
}
377379
}
378380

source/MAC/IEEE802_15_4/mac_security_mib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ int8_t mac_sec_mib_key_description_set(uint8_t atribute_index, mlme_key_descript
5151

5252
mlme_device_descriptor_t *mac_sec_mib_device_description_get_attribute_index(struct protocol_interface_rf_mac_setup *rf_mac_setup, uint8_t attribute_index);
5353

54-
mlme_device_descriptor_t *mac_sec_mib_device_description_get(struct protocol_interface_rf_mac_setup *rf_mac_setup, const uint8_t *address, uint8_t type);
54+
mlme_device_descriptor_t *mac_sec_mib_device_description_get(struct protocol_interface_rf_mac_setup *rf_mac_setup, const uint8_t *address, uint8_t type, uint16_t pan_id);
5555

5656
uint8_t mac_mib_device_descption_attribute_get_by_descriptor(struct protocol_interface_rf_mac_setup *rf_mac_setup, mlme_device_descriptor_t *descriptor);
5757

test/nanostack/unittest/mac/mac_security_mib/test_mac_security_mib.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,21 +250,21 @@ bool test_mac_sec_mib_device_description_get_attribute_index()
250250

251251
bool test_mac_sec_mib_device_description_get()
252252
{
253-
if (mac_sec_mib_device_description_get(NULL, NULL, 0)) {
253+
if (mac_sec_mib_device_description_get(NULL, NULL, 0, 1)) {
254254
return false;
255255
}
256256
protocol_interface_rf_mac_setup_s setup;
257257
memset(&setup, 0, sizeof(protocol_interface_rf_mac_setup_s));
258258

259259
uint8_t mac16[2];
260260
memset(mac16, 0, 2);
261-
if (mac_sec_mib_device_description_get(&setup, &mac16, MAC_ADDR_MODE_16_BIT)) {
261+
if (mac_sec_mib_device_description_get(&setup, &mac16, MAC_ADDR_MODE_16_BIT, 1)) {
262262
return false;
263263
}
264264

265265
uint8_t mac64[8];
266266
memset(mac64, 0, 8);
267-
if (mac_sec_mib_device_description_get(&setup, &mac64, MAC_ADDR_MODE_64_BIT)) {
267+
if (mac_sec_mib_device_description_get(&setup, &mac64, MAC_ADDR_MODE_64_BIT, 1)) {
268268
return false;
269269
}
270270

@@ -279,26 +279,27 @@ bool test_mac_sec_mib_device_description_get()
279279

280280
mac16[0] = 0;
281281
mac16[1] = 0;
282-
if (mac_sec_mib_device_description_get(&setup, &mac16, MAC_ADDR_MODE_16_BIT)) {
282+
if (mac_sec_mib_device_description_get(&setup, &mac16, MAC_ADDR_MODE_16_BIT, 1)) {
283283
return false;
284284
}
285285

286-
if (mac_sec_mib_device_description_get(&setup, &mac64, MAC_ADDR_MODE_64_BIT)) {
286+
if (mac_sec_mib_device_description_get(&setup, &mac64, MAC_ADDR_MODE_64_BIT, 1)) {
287287
return false;
288288
}
289289

290290
mlme_device_descriptor_t *device_table = setup.device_description_table;
291291
device_table++;
292292
device_table->ShortAddress = 16;
293+
device_table->PANId = 1;
293294
common_functions_stub.uint16_value = 16;
294-
if (!mac_sec_mib_device_description_get(&setup, &mac16, MAC_ADDR_MODE_16_BIT)) {
295+
if (!mac_sec_mib_device_description_get(&setup, &mac16, MAC_ADDR_MODE_16_BIT, 1)) {
295296
return false;
296297
}
297298
common_functions_stub.uint16_value = 0;
298299

299300
memset(&device_table->ExtAddress, 1, 8);
300301
memset(&mac64, 1, 8);
301-
if (!mac_sec_mib_device_description_get(&setup, &mac64, MAC_ADDR_MODE_64_BIT)) {
302+
if (!mac_sec_mib_device_description_get(&setup, &mac64, MAC_ADDR_MODE_64_BIT, 1)) {
302303
return false;
303304
}
304305

test/nanostack/unittest/stub/mac_security_mib_stub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ mlme_device_descriptor_t *mac_sec_mib_device_description_get_attribute_index(pro
6161
return mac_security_mib_stub.device_ptr;
6262
}
6363

64-
mlme_device_descriptor_t *mac_sec_mib_device_description_get(protocol_interface_rf_mac_setup_s *rf_mac_setup, const uint8_t *address, uint8_t type)
64+
mlme_device_descriptor_t *mac_sec_mib_device_description_get(protocol_interface_rf_mac_setup_s *rf_mac_setup, const uint8_t *address, uint8_t type, uint16_t pan_id)
6565
{
6666
return mac_security_mib_stub.device_ptr;
6767
}

0 commit comments

Comments
 (0)