Skip to content

Commit 883eb46

Browse files
author
Arto Kinnunen
authored
Add callback for CoAP message prevalidation (ARMmbed#1918)
Set message prevalidation callback to CoAP Service
1 parent 59bbe31 commit 883eb46

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

source/6LoWPAN/Thread/thread_management_server.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
#include "thread_management_server.h"
6767
#include "mac_api.h"
6868
#include "6LoWPAN/MAC/mac_data_poll.h"
69+
#include "Common_Protocols/ipv6_constants.h"
70+
#include "Core/include/address.h"
6971
#include "mlme.h"
7072

7173
#ifdef HAVE_THREAD
@@ -1118,6 +1120,36 @@ static int thread_management_server_announce_begin_cb(int8_t service_id, uint8_t
11181120
return 0;
11191121
}
11201122

1123+
static int coap_msg_prevalidate_cb(int8_t interface_id, uint8_t source_address[static 16], uint16_t source_port, uint8_t local_address[static 16], uint16_t local_port, char *coap_uri)
1124+
{
1125+
protocol_interface_info_entry_t *cur;
1126+
uint_fast8_t local_addr_scope;
1127+
1128+
(void) source_address;
1129+
(void) source_port;
1130+
(void) coap_uri;
1131+
1132+
cur = protocol_stack_interface_info_get_by_id(interface_id);
1133+
1134+
if (!cur) {
1135+
tr_error("No interface");
1136+
return -1;
1137+
}
1138+
1139+
if (local_port != THREAD_MANAGEMENT_PORT) {
1140+
// Message not sent to THREAD_MANAGEMENT_PORT, let it come through
1141+
return 0;
1142+
}
1143+
1144+
/* check our address scope */
1145+
local_addr_scope = addr_ipv6_scope(local_address, cur);
1146+
if (local_addr_scope > IPV6_SCOPE_REALM_LOCAL) {
1147+
return 1;
1148+
}
1149+
1150+
return 0;
1151+
}
1152+
11211153
/**
11221154
* Public interface functions
11231155
*/
@@ -1162,6 +1194,7 @@ int thread_management_server_init(int8_t interface_id)
11621194
ns_dyn_mem_free(this);
11631195
return -3;
11641196
}
1197+
coap_service_msg_prevalidate_callback_set(this->coap_service_id, coap_msg_prevalidate_cb);
11651198
#ifdef HAVE_THREAD_ROUTER
11661199
if (thread_leader_service_init(interface_id, this->coap_service_id) != 0) {
11671200
tr_error("Thread leader service init failed");

test/nanostack/unittest/stub/coap_service_api_stub.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,9 @@ void coap_service_request_delete_by_service_id(int8_t service_id)
100100
{
101101
}
102102

103+
int8_t coap_service_msg_prevalidate_callback_set(int8_t service_id, coap_service_msg_prevalidate_cb *msg_prevalidate_cb)
104+
{
105+
return 0;
106+
}
107+
103108
#endif

0 commit comments

Comments
 (0)