Skip to content

Commit

Permalink
Ignore ns_monitor when receiving Ack (ARMmbed#2417)
Browse files Browse the repository at this point in the history
* Ignore ns_monitor when receiving Ack

* Fixed NS monitor unit tests
  • Loading branch information
Jarkko Paso authored Aug 17, 2020
1 parent 3323f36 commit 62d8586
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 27 deletions.
6 changes: 0 additions & 6 deletions source/MAC/IEEE802_15_4/mac_mcps_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2351,12 +2351,6 @@ void mcps_sap_pre_parsed_frame_buffer_free(mac_pre_parsed_frame_t *buf)

mac_pre_parsed_frame_t *mcps_sap_pre_parsed_frame_buffer_get(const uint8_t *data_ptr, uint16_t frame_length)
{
// check that system has enough space to handle the new packet
if (!ns_monitor_packet_allocation_allowed()) {
// stack can not handle new packets for routing
return NULL;
}

mac_pre_parsed_frame_t *buffer = ns_dyn_mem_temporary_alloc(sizeof(mac_pre_parsed_frame_t) + frame_length);

if (buffer) {
Expand Down
9 changes: 8 additions & 1 deletion source/MAC/IEEE802_15_4/mac_pd_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "MAC/IEEE802_15_4/mac_mcps_sap.h"
#include "MAC/IEEE802_15_4/mac_cca_threshold.h"
#include "MAC/rf_driver_storage.h"
#include "Core/include/ns_monitor.h"
#include "ns_trace.h"

#define TRACE_GROUP "mPDs"
Expand Down Expand Up @@ -904,11 +905,17 @@ static int8_t mac_pd_sap_generate_edfe_response(protocol_interface_rf_mac_setup_

static mac_pre_parsed_frame_t *mac_pd_sap_allocate_receive_buffer(protocol_interface_rf_mac_setup_s *rf_ptr, const mac_fcf_sequence_t *fcf_read, arm_pd_sap_generic_ind_t *pd_data_ind)
{
// Unless receiving Ack, check that system has enough space to handle the new packet
if (fcf_read->frametype != FC_ACK_FRAME) {
if (!ns_monitor_packet_allocation_allowed()) {
// stack can not handle new packets for routing
return NULL;
}
}
mac_pre_parsed_frame_t *buffer = mcps_sap_pre_parsed_frame_buffer_get(pd_data_ind->data_ptr, pd_data_ind->data_len);
if (!buffer) {
return NULL;
}

//Copy Pre Parsed values
buffer->fcf_dsn = *fcf_read;
buffer->timestamp = mac_pd_sap_get_phy_rx_time(rf_ptr);
Expand Down
20 changes: 0 additions & 20 deletions test/nanostack/unittest/mac/mac_mcps_sap/test_mac_mcps_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2194,26 +2194,6 @@ bool test_mcps_sap_pre_parsed_frame_buffer_get()
if (memcmp(mac_header_message_start_pointer(buf), buffer, 8) != 0) {
return false;
}
ns_dyn_mem_free(buf);

// Test that if dynamic memory is low, then allocation fails
nsdynmemlib_stub.returnCounter = 1;
ns_monitor_stub.return_bool = false;

buf = mcps_sap_pre_parsed_frame_buffer_get(buffer, 8);
if (buf) {
return false;
}

// Test that allocation succeeds when there is enough heap
nsdynmemlib_stub.returnCounter = 1;
ns_monitor_stub.return_bool = true;

buf = mcps_sap_pre_parsed_frame_buffer_get(buffer, 8);
if (!buf || buf->frameLength != 8) {
return false;
}

ns_dyn_mem_free(buf);
return true;
}
Expand Down
1 change: 1 addition & 0 deletions test/nanostack/unittest/mac/mac_pd_sap/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ TEST_SRC_FILES = \
../../stub/buffer_dyn_stub.c \
../../stub/fhss_config_stub.c \
../../stub/sw_mac_stub.c \
../../stub/ns_monitor_stub.c \

include ../../MakefileWorker.mk

Expand Down
23 changes: 23 additions & 0 deletions test/nanostack/unittest/mac/mac_pd_sap/test_mac_pd_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "nsdynmemLIB_stub.h"
#include "fhss_config_stub.h"
#include "sw_mac_stub.h"
#include "ns_monitor_stub.h"
#include <string.h>

static int8_t tx_return = -1;
Expand Down Expand Up @@ -438,7 +439,29 @@ bool test_mac_pd_sap_data_cb()
return false;
}

// Test when ns monitor don't allow reception
ns_monitor_stub.return_bool = false;
mac_mcps_sap_stub.pre_parsed = frame_buf;
nsdynmemlib_stub.returnCounter = 2;
fcf.frametype = FC_DATA_FRAME;
mac_header_helper_functions_stub.fcf = fcf;
phy_message.message.generic_data_ind.data_len = 32;
ret = mac_pd_sap_data_cb(&rf_ptr, &phy_message);
if (ret != -3) {
return false;
}

// Test when ns monitor allows Ack reception
ns_monitor_stub.return_bool = false;
mac_mcps_sap_stub.pre_parsed = frame_buf;
nsdynmemlib_stub.returnCounter = 2;
fcf.frametype = FC_ACK_FRAME;
mac_header_helper_functions_stub.fcf = fcf;
phy_message.message.generic_data_ind.data_len = 32;
ret = mac_pd_sap_data_cb(&rf_ptr, &phy_message);
if (ret != -1) {
return false;
}

//Test MAC15_4_PD_SAP_DATA_TX_CONFIRM
phy_message.id = MAC15_4_PD_SAP_DATA_TX_CONFIRM;
Expand Down

0 comments on commit 62d8586

Please sign in to comment.