Skip to content

Commit

Permalink
Adapatation neighbor validation update:
Browse files Browse the repository at this point in the history
Drop a packet if neighbor is unknow and wi-sun stack is enabled.

Simplify that that broadcast address check is done only 1 time.

Updated Unit test code for new feature.
  • Loading branch information
Juha Heiskanen committed Aug 20, 2018
1 parent 06255ee commit b425f4b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 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
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 b425f4b

Please sign in to comment.