Skip to content

Commit

Permalink
Merge pull request ARMmbed#1789 from ARMmbed/iotthd-2693
Browse files Browse the repository at this point in the history
Drop Packet to unknown neighbour before push MAC
  • Loading branch information
Juha Heiskanen authored Aug 20, 2018
2 parents 06255ee + 90c6a8a commit 931a17d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
40 changes: 17 additions & 23 deletions source/6LoWPAN/adaptation_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#ifdef HAVE_RPL
#include "RPL/rpl_data.h"
#endif
#include "6LoWPAN/ws/ws_common.h"
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
#include "6LoWPAN/Thread/thread_common.h"
#include "6LoWPAN/ws/ws_common.h"
Expand Down Expand Up @@ -613,40 +612,35 @@ buffer_t * lowpan_adaptation_data_process_tx_preprocess(protocol_interface_info_
{
mac_neighbor_table_entry_t *neigh_entry_ptr = NULL;


//Validate is link known and set indirect, datareq and security key id mode
if (buf->dst_sa.addr_type == ADDR_NONE) {
goto tx_error_handler;
}

/* If MLE is enabled, we will talk if we have an MLE association */
if (buf->dst_sa.addr_type == ADDR_802_15_4_LONG ) {
neigh_entry_ptr = mac_neighbor_table_address_discover(mac_neighbor_info(cur), buf->dst_sa.address + 2, buf->dst_sa.addr_type);
if (addr_check_broadcast(buf->dst_sa.address, buf->dst_sa.addr_type) == eOK ) {
buf->dst_sa.addr_type = ADDR_802_15_4_SHORT;
buf->dst_sa.address[2] = 0xff;
buf->dst_sa.address[3] = 0xff;
buf->link_specific.ieee802_15_4.indirectTxProcess = false;
buf->link_specific.ieee802_15_4.requestAck = false;
} else {

} else if(buf->dst_sa.addr_type == ADDR_802_15_4_SHORT && (common_read_16_bit(buf->dst_sa.address + 2)) != 0xffff) {
neigh_entry_ptr = mac_neighbor_table_address_discover(mac_neighbor_info(cur), buf->dst_sa.address + 2, buf->dst_sa.addr_type);
}

//Validate neighbour
if (!buf->options.ll_security_bypass_tx && neigh_entry_ptr) {
//Validate neighbour
if (!buf->options.ll_security_bypass_tx && neigh_entry_ptr) {

if (neigh_entry_ptr->connected_device || neigh_entry_ptr->trusted_device) {
if (neigh_entry_ptr->connected_device || neigh_entry_ptr->trusted_device) {

} else {
//tr_warn("Drop TX to unassociated %s", trace_sockaddr(&buf->dst_sa, true));
} else {
//tr_warn("Drop TX to unassociated %s", trace_sockaddr(&buf->dst_sa, true));
goto tx_error_handler;
}
} else if (ws_info(cur) && !neigh_entry_ptr) {
//Do not accept to send unknow device
goto tx_error_handler;
}
}

//Check indirect


if (addr_check_broadcast(buf->dst_sa.address, buf->dst_sa.addr_type) == eOK) {
buf->dst_sa.addr_type = ADDR_802_15_4_SHORT;
buf->dst_sa.address[2] = 0xff;
buf->dst_sa.address[3] = 0xff;
buf->link_specific.ieee802_15_4.indirectTxProcess = false;
buf->link_specific.ieee802_15_4.requestAck = false;
} else {
buf->link_specific.ieee802_15_4.requestAck = true;
buf->link_specific.ieee802_15_4.indirectTxProcess = lowpan_adaptation_indirect_data_request(neigh_entry_ptr);
}
Expand Down
1 change: 0 additions & 1 deletion source/MAC/IEEE802_15_4/mac_mcps_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,6 @@ static int8_t mac_data_sap_rx_handler(mac_pre_parsed_frame_t *buf, protocol_inte
if (buf->fcf_dsn.securityEnabled) {
status = mac_data_interface_decrypt_packet(buf, &data_ind->Key);
if (status != MLME_SUCCESS) {
tr_debug("Decrypt fail, %d", status);
mcps_comm_status_indication_generate(status, buf, mac);
goto DROP_PACKET;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "common_functions_stub.h"
#include "thread_common_stub.h"
#include "mac_neighbor_table_stub.h"
#include "6LoWPAN/ws/ws_common.h"


static int mcps_data_req_cnt = 0;
Expand Down Expand Up @@ -183,6 +184,18 @@ bool test_lowpan_adapatation_data_process_tx_preprocess()
return false;
}

//TEST Unknow neighbor and wi-sun stack
address_stub.uint8_value = 2;
buf.dst_sa.addr_type = ADDR_802_15_4_SHORT;
buf.options.ll_security_bypass_tx = false;
socket_stub.buffer_ptr = &buf;
ws_info_t test_info;
entry.ws_info = &test_info;
if (lowpan_adaptation_data_process_tx_preprocess(&entry, &buf)) {
return false;
}

entry.ws_info = NULL;
mac_neighbor_table_entry_t neighbor;
memset(&neighbor, 0, sizeof(mac_neighbor_table_entry_t));
mac_neighbor_table_stub.test_neigh = &neighbor;
Expand Down

0 comments on commit 931a17d

Please sign in to comment.