|
66 | 66 | #include "thread_management_server.h"
|
67 | 67 | #include "mac_api.h"
|
68 | 68 | #include "6LoWPAN/MAC/mac_data_poll.h"
|
| 69 | +#include "Common_Protocols/ipv6_constants.h" |
| 70 | +#include "Core/include/address.h" |
69 | 71 | #include "mlme.h"
|
70 | 72 |
|
71 | 73 | #ifdef HAVE_THREAD
|
@@ -1118,6 +1120,36 @@ static int thread_management_server_announce_begin_cb(int8_t service_id, uint8_t
|
1118 | 1120 | return 0;
|
1119 | 1121 | }
|
1120 | 1122 |
|
| 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 | + |
1121 | 1153 | /**
|
1122 | 1154 | * Public interface functions
|
1123 | 1155 | */
|
@@ -1162,6 +1194,7 @@ int thread_management_server_init(int8_t interface_id)
|
1162 | 1194 | ns_dyn_mem_free(this);
|
1163 | 1195 | return -3;
|
1164 | 1196 | }
|
| 1197 | + coap_service_msg_prevalidate_callback_set(this->coap_service_id, coap_msg_prevalidate_cb); |
1165 | 1198 | #ifdef HAVE_THREAD_ROUTER
|
1166 | 1199 | if (thread_leader_service_init(interface_id, this->coap_service_id) != 0) {
|
1167 | 1200 | tr_error("Thread leader service init failed");
|
|
0 commit comments