Skip to content

Commit 62d8586

Browse files
author
Jarkko Paso
authored
Ignore ns_monitor when receiving Ack (ARMmbed#2417)
* Ignore ns_monitor when receiving Ack * Fixed NS monitor unit tests
1 parent 3323f36 commit 62d8586

File tree

5 files changed

+32
-27
lines changed

5 files changed

+32
-27
lines changed

source/MAC/IEEE802_15_4/mac_mcps_sap.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2351,12 +2351,6 @@ void mcps_sap_pre_parsed_frame_buffer_free(mac_pre_parsed_frame_t *buf)
23512351

23522352
mac_pre_parsed_frame_t *mcps_sap_pre_parsed_frame_buffer_get(const uint8_t *data_ptr, uint16_t frame_length)
23532353
{
2354-
// check that system has enough space to handle the new packet
2355-
if (!ns_monitor_packet_allocation_allowed()) {
2356-
// stack can not handle new packets for routing
2357-
return NULL;
2358-
}
2359-
23602354
mac_pre_parsed_frame_t *buffer = ns_dyn_mem_temporary_alloc(sizeof(mac_pre_parsed_frame_t) + frame_length);
23612355

23622356
if (buffer) {

source/MAC/IEEE802_15_4/mac_pd_sap.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "MAC/IEEE802_15_4/mac_mcps_sap.h"
3737
#include "MAC/IEEE802_15_4/mac_cca_threshold.h"
3838
#include "MAC/rf_driver_storage.h"
39+
#include "Core/include/ns_monitor.h"
3940
#include "ns_trace.h"
4041

4142
#define TRACE_GROUP "mPDs"
@@ -904,11 +905,17 @@ static int8_t mac_pd_sap_generate_edfe_response(protocol_interface_rf_mac_setup_
904905

905906
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)
906907
{
908+
// Unless receiving Ack, check that system has enough space to handle the new packet
909+
if (fcf_read->frametype != FC_ACK_FRAME) {
910+
if (!ns_monitor_packet_allocation_allowed()) {
911+
// stack can not handle new packets for routing
912+
return NULL;
913+
}
914+
}
907915
mac_pre_parsed_frame_t *buffer = mcps_sap_pre_parsed_frame_buffer_get(pd_data_ind->data_ptr, pd_data_ind->data_len);
908916
if (!buffer) {
909917
return NULL;
910918
}
911-
912919
//Copy Pre Parsed values
913920
buffer->fcf_dsn = *fcf_read;
914921
buffer->timestamp = mac_pd_sap_get_phy_rx_time(rf_ptr);

test/nanostack/unittest/mac/mac_mcps_sap/test_mac_mcps_sap.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,26 +2194,6 @@ bool test_mcps_sap_pre_parsed_frame_buffer_get()
21942194
if (memcmp(mac_header_message_start_pointer(buf), buffer, 8) != 0) {
21952195
return false;
21962196
}
2197-
ns_dyn_mem_free(buf);
2198-
2199-
// Test that if dynamic memory is low, then allocation fails
2200-
nsdynmemlib_stub.returnCounter = 1;
2201-
ns_monitor_stub.return_bool = false;
2202-
2203-
buf = mcps_sap_pre_parsed_frame_buffer_get(buffer, 8);
2204-
if (buf) {
2205-
return false;
2206-
}
2207-
2208-
// Test that allocation succeeds when there is enough heap
2209-
nsdynmemlib_stub.returnCounter = 1;
2210-
ns_monitor_stub.return_bool = true;
2211-
2212-
buf = mcps_sap_pre_parsed_frame_buffer_get(buffer, 8);
2213-
if (!buf || buf->frameLength != 8) {
2214-
return false;
2215-
}
2216-
22172197
ns_dyn_mem_free(buf);
22182198
return true;
22192199
}

test/nanostack/unittest/mac/mac_pd_sap/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ TEST_SRC_FILES = \
2727
../../stub/buffer_dyn_stub.c \
2828
../../stub/fhss_config_stub.c \
2929
../../stub/sw_mac_stub.c \
30+
../../stub/ns_monitor_stub.c \
3031

3132
include ../../MakefileWorker.mk
3233

test/nanostack/unittest/mac/mac_pd_sap/test_mac_pd_sap.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "nsdynmemLIB_stub.h"
3434
#include "fhss_config_stub.h"
3535
#include "sw_mac_stub.h"
36+
#include "ns_monitor_stub.h"
3637
#include <string.h>
3738

3839
static int8_t tx_return = -1;
@@ -438,7 +439,29 @@ bool test_mac_pd_sap_data_cb()
438439
return false;
439440
}
440441

442+
// Test when ns monitor don't allow reception
443+
ns_monitor_stub.return_bool = false;
444+
mac_mcps_sap_stub.pre_parsed = frame_buf;
445+
nsdynmemlib_stub.returnCounter = 2;
446+
fcf.frametype = FC_DATA_FRAME;
447+
mac_header_helper_functions_stub.fcf = fcf;
448+
phy_message.message.generic_data_ind.data_len = 32;
449+
ret = mac_pd_sap_data_cb(&rf_ptr, &phy_message);
450+
if (ret != -3) {
451+
return false;
452+
}
441453

454+
// Test when ns monitor allows Ack reception
455+
ns_monitor_stub.return_bool = false;
456+
mac_mcps_sap_stub.pre_parsed = frame_buf;
457+
nsdynmemlib_stub.returnCounter = 2;
458+
fcf.frametype = FC_ACK_FRAME;
459+
mac_header_helper_functions_stub.fcf = fcf;
460+
phy_message.message.generic_data_ind.data_len = 32;
461+
ret = mac_pd_sap_data_cb(&rf_ptr, &phy_message);
462+
if (ret != -1) {
463+
return false;
464+
}
442465

443466
//Test MAC15_4_PD_SAP_DATA_TX_CONFIRM
444467
phy_message.id = MAC15_4_PD_SAP_DATA_TX_CONFIRM;

0 commit comments

Comments
 (0)