Skip to content

Commit b425f4b

Browse files
author
Juha Heiskanen
committed
Adapatation neighbor validation update:
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.
1 parent 06255ee commit b425f4b

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

source/6LoWPAN/adaptation_interface.c

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#ifdef HAVE_RPL
4444
#include "RPL/rpl_data.h"
4545
#endif
46-
#include "6LoWPAN/ws/ws_common.h"
4746
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
4847
#include "6LoWPAN/Thread/thread_common.h"
4948
#include "6LoWPAN/ws/ws_common.h"
@@ -613,40 +612,35 @@ buffer_t * lowpan_adaptation_data_process_tx_preprocess(protocol_interface_info_
613612
{
614613
mac_neighbor_table_entry_t *neigh_entry_ptr = NULL;
615614

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

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

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

629-
//Validate neighbour
630-
if (!buf->options.ll_security_bypass_tx && neigh_entry_ptr) {
631+
//Validate neighbour
632+
if (!buf->options.ll_security_bypass_tx && neigh_entry_ptr) {
631633

632-
if (neigh_entry_ptr->connected_device || neigh_entry_ptr->trusted_device) {
634+
if (neigh_entry_ptr->connected_device || neigh_entry_ptr->trusted_device) {
633635

634-
} else {
635-
//tr_warn("Drop TX to unassociated %s", trace_sockaddr(&buf->dst_sa, true));
636+
} else {
637+
//tr_warn("Drop TX to unassociated %s", trace_sockaddr(&buf->dst_sa, true));
638+
goto tx_error_handler;
639+
}
640+
} else if (ws_info(cur) && !neigh_entry_ptr) {
641+
//Do not accept to send unknow device
636642
goto tx_error_handler;
637643
}
638-
}
639-
640-
//Check indirect
641-
642-
643-
if (addr_check_broadcast(buf->dst_sa.address, buf->dst_sa.addr_type) == eOK) {
644-
buf->dst_sa.addr_type = ADDR_802_15_4_SHORT;
645-
buf->dst_sa.address[2] = 0xff;
646-
buf->dst_sa.address[3] = 0xff;
647-
buf->link_specific.ieee802_15_4.indirectTxProcess = false;
648-
buf->link_specific.ieee802_15_4.requestAck = false;
649-
} else {
650644
buf->link_specific.ieee802_15_4.requestAck = true;
651645
buf->link_specific.ieee802_15_4.indirectTxProcess = lowpan_adaptation_indirect_data_request(neigh_entry_ptr);
652646
}

test/nanostack/unittest/6LoWPAN/adaptation_interface/test_adaptation_interface.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "common_functions_stub.h"
4040
#include "thread_common_stub.h"
4141
#include "mac_neighbor_table_stub.h"
42+
#include "6LoWPAN/ws/ws_common.h"
4243

4344

4445
static int mcps_data_req_cnt = 0;
@@ -183,6 +184,18 @@ bool test_lowpan_adapatation_data_process_tx_preprocess()
183184
return false;
184185
}
185186

187+
//TEST Unknow neighbor and wi-sun stack
188+
address_stub.uint8_value = 2;
189+
buf.dst_sa.addr_type = ADDR_802_15_4_SHORT;
190+
buf.options.ll_security_bypass_tx = false;
191+
socket_stub.buffer_ptr = &buf;
192+
ws_info_t test_info;
193+
entry.ws_info = &test_info;
194+
if (lowpan_adaptation_data_process_tx_preprocess(&entry, &buf)) {
195+
return false;
196+
}
197+
198+
entry.ws_info = NULL;
186199
mac_neighbor_table_entry_t neighbor;
187200
memset(&neighbor, 0, sizeof(mac_neighbor_table_entry_t));
188201
mac_neighbor_table_stub.test_neigh = &neighbor;

0 commit comments

Comments
 (0)