Skip to content

Commit

Permalink
Added filter callback for MLE messages (ARMmbed#1638)
Browse files Browse the repository at this point in the history
Added test API to set callback to filter received MLE messages.
  • Loading branch information
Tero Heinonen authored Apr 6, 2018
1 parent 9f85599 commit 564d3fe
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
8 changes: 8 additions & 0 deletions nanostack/net_test_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define NET_TEST_API_H_

#include "ns_types.h"
#include "Service_Libs/mle_service/mle_service_api.h"

/**
* \brief Makes TCP protocol drop given number of packets from a particular state (TX side).
Expand Down Expand Up @@ -56,4 +57,11 @@ int8_t arm_nwk_test_tcp_drop_rx(int state, uint8_t count);
*/
void arm_nwk_test_tcp_drop_reset(void);

/**
* \brief Set callback for MLE message receiving filter.
*
* Testing API for setting MLE receive callback for message filtering purposes.
*/
void arm_nwk_test_mle_receive_filter_set(mle_service_filter_cb *response_filter_cb);

#endif //NET_TEST_API_H_
20 changes: 19 additions & 1 deletion source/Service_Libs/mle_service/mle_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ typedef struct {

mle_service_class_t *mle_service = NULL;

#ifdef MLE_TEST
static mle_service_filter_cb *receive_filter_cb = NULL;
#endif

static uint8_t *mle_security_aux_header_write(uint8_t *ptr, const mle_security_header_t *auxHeader);
static void mle_security_aux_ccm_nonce_set(uint8_t *noncePtr, uint8_t *mac64, uint32_t securityFrameCounter, uint8_t securityLevel);
static uint8_t mle_security_aux_header_size(uint8_t keyIdMode);
Expand Down Expand Up @@ -802,6 +806,13 @@ static void mle_service_socket_callback(void *cb)
mle_msg.dbm = buf->options.dbm;
mle_msg.lqi = buf->options.lqi;

#ifdef MLE_TEST
if (receive_filter_cb) {
if (!receive_filter_cb(service_handler->interface_id, &mle_msg, &securityHeader)) {
goto error_handler;
}
}
#endif
if (security_bypass) {
/* Security by pass message handler call */
service_handler->recv_security_bypass_cb(service_handler->interface_id, &mle_msg);
Expand All @@ -812,7 +823,7 @@ static void mle_service_socket_callback(void *cb)
}
}

error_handler:
error_handler:
if (buf) {
buffer_free(buf);
}
Expand Down Expand Up @@ -1497,3 +1508,10 @@ void mle_service_set_accept_invalid_frame_counter(bool value)
}
}

#ifdef MLE_TEST
void mle_service_receive_filter_cb_set(mle_service_filter_cb *filter_cb)
{
receive_filter_cb = filter_cb;
}

#endif
25 changes: 25 additions & 0 deletions source/Service_Libs/mle_service/mle_service_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,21 @@ typedef uint8_t * (mle_service_security_notify_cb)(int8_t interface_id, mle_secu
*/
typedef bool (mle_service_message_timeout_cb)(int8_t interface_id, uint16_t msgId, bool usedAllRetries);

/**
* A callback for receive MLE message filtering
*
* This function will be called when MLE message is received. Only for testing purposes.
*
* \param interface_id define interface id for receiver
* \param mle_msg received MLE message
* \param security_headers messages security parameters
*
* \return true continue MLE packet processing
* \return false drop MLE packet
*
*/
typedef bool (mle_service_filter_cb)(int8_t interface_id, mle_message_t *mle_msg, mle_security_header_t *security_headers);

/*
* Initialise server instance.
* Creates and shares socket for other mle services.
Expand Down Expand Up @@ -704,4 +719,14 @@ void mle_service_set_fragmented_msg_ll_security(bool value);
*/
void mle_service_set_accept_invalid_frame_counter(bool value);

#ifdef MLE_TEST
/**
* Set callback for MLE receiving packet filtering.
*
* If this is set, all received MLE messages will be passed to given callback.
*/
void mle_service_receive_filter_cb_set(mle_service_filter_cb *filter_cb);
#else
#define mle_service_receive_filter_cb_set(filter_cb) ((void) 0)
#endif /* MLE_TEST */
#endif /* MLE_SERVICE_API_H_ */
1 change: 1 addition & 0 deletions source/configs/generic.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@
#define HAVE_DHCPV6_SERVER
#define TCP_TEST
#define THREAD_THCI_SUPPORT
#define MLE_TEST
6 changes: 6 additions & 0 deletions source/libNET/src/net_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <string.h>
#include "nsdynmemLIB.h"
#include "NWK_INTERFACE/Include/protocol.h"
#include "Service_Libs/mle_service/mle_service_api.h"

#include "net_test_api.h"
#include "Common_Protocols/tcp.h"
Expand Down Expand Up @@ -76,3 +77,8 @@ int8_t arm_nwk_test_tcp_drop_rx(int state, uint8_t count)
void arm_nwk_test_tcp_drop_reset() {
tcp_test_drop_reset();
}

void arm_nwk_test_mle_receive_filter_set(mle_service_filter_cb *response_filter_cb)
{
mle_service_receive_filter_cb_set(response_filter_cb);
}

0 comments on commit 564d3fe

Please sign in to comment.