Skip to content

Commit abdce23

Browse files
author
Arto Kinnunen
authored
Organize Thread code (#1471)
Move Thread 1.2 specific code to thread_commercial file.
1 parent d4db17a commit abdce23

8 files changed

+29
-7
lines changed

source/6LoWPAN/Thread/thread_address_registration_client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void thread_address_registration_timer_set(protocol_interface_info_entry_t *inte
6363
}
6464
void thread_address_registration_timer(protocol_interface_info_entry_t *interface, uint16_t seconds)
6565
{
66-
if (!enabled || interface->thread_info->version < THREAD_VERSION_1_2) {
66+
if (!enabled || !thread_commercial_version_check(interface->thread_info->version)) {
6767
return;
6868
}
6969

source/6LoWPAN/Thread/thread_bbr_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ void thread_bbr_seconds_timer(int8_t interface_id, uint32_t seconds)
916916
thread_bbr_status_check(this,seconds);
917917
}
918918

919-
if (thread_version < THREAD_VERSION_1_2) {
919+
if (!thread_commercial_version_check(thread_version)) {
920920
return;
921921
}
922922
thread_commercial_bbr_seconds_timer(interface_id, seconds);

source/6LoWPAN/Thread/thread_commercial.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,23 @@ void thread_commercial_activate(protocol_interface_info_entry_t *cur)
544544
}
545545
}
546546

547+
bool thread_commercial_security_policy_enabled(uint8_t securityPolicy)
548+
{
549+
if (securityPolicy & SECURITY_POLICY_CCM_ENABLED) {
550+
return true;
551+
}
552+
553+
return false;
554+
}
555+
556+
bool thread_commercial_version_check(uint8_t version)
557+
{
558+
if (version >= THREAD_VERSION_1_2) {
559+
return true;
560+
}
561+
562+
return false;
563+
}
547564

548565
#ifdef HAVE_THREAD_ROUTER
549566
static int thread_commercial_relay_tx_cb(int8_t service_id, uint8_t source_address[16], uint16_t source_port, sn_coap_hdr_s *request_ptr)

source/6LoWPAN/Thread/thread_commercial.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ void thread_commercial_mcast_subscrition_change(protocol_interface_info_entry_t
2929
void thread_commercial_address_registration_trigger(protocol_interface_info_entry_t *interface);
3030
void thread_commercial_route_set(protocol_interface_info_entry_t *cur);
3131
void thread_commercial_activate(protocol_interface_info_entry_t *cur);
32+
bool thread_commercial_security_policy_enabled(uint8_t securityPolicy);
33+
bool thread_commercial_version_check(uint8_t version);
3234
#ifdef HAVE_THREAD_ROUTER
3335
int thread_commercial_joiner_router_init(int8_t interface_id);
3436
bool thread_commercial_joining_enabled(int8_t interface_id);
@@ -56,6 +58,8 @@ uint8_t *thread_commercial_discover_response_write(protocol_interface_info_entry
5658
#define thread_commercial_address_registration_change(interface)
5759
#define thread_commercial_route_set(cur)
5860
#define thread_commercial_activate(cur)
61+
#define thread_commercial_security_policy_enabled(securityPolicy) (false)
62+
#define thread_commercial_version_check(version) (false)
5963
#define thread_commercial_joiner_router_init(interface_id)
6064
#define thread_commercial_joining_enabled(interface_id) false
6165
#define thread_commercial_discover_response_len(cur) 0

source/6LoWPAN/Thread/thread_discovery.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ static int thread_discovery_response_send(thread_discovery_class_t *class, threa
537537
*ptr++ = MLE_TYPE_DISCOVERY;
538538
*ptr++ = message_length;
539539
uint16_t discover_response_tlv = thread_discover_tlv_get(class->version, (linkConfiguration->securityPolicy & SECURITY_POLICY_NATIVE_COMMISSIONING_ALLOWED),
540-
(linkConfiguration->securityPolicy & SECURITY_POLICY_CCM_ENABLED));
540+
thread_commercial_security_policy_enabled(linkConfiguration->securityPolicy));
541541

542542
ptr = thread_meshcop_tlv_data_write_uint16(ptr, MESHCOP_TLV_DISCOVERY_RESPONSE, discover_response_tlv);
543543
ptr = thread_meshcop_tlv_data_write(ptr, MESHCOP_TLV_XPANID, 8, linkConfiguration->extented_pan_id);
@@ -956,7 +956,7 @@ static void thread_discovery_response_msg_handler(thread_discovery_class_t * dis
956956
}
957957

958958
if (discovery_class->discovery_request->joiner_flag && (!joiner_port_valid || steerin_data_length == 0)) {
959-
if (discovery_class->interface->thread_info->version == THREAD_VERSION_1_2) {
959+
if (thread_commercial_version_check(discovery_class->interface->thread_info->version)) {
960960
if (!discovery_class->interface->thread_info->ccm_ptr) {
961961
tr_debug("Dropped, no joiner info or CCM network");
962962
}

source/6LoWPAN/Thread/thread_host_bootstrap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ static bool thread_host_prefer_parent_response(protocol_interface_info_entry_t *
408408
{
409409
(void) connectivity;
410410

411-
if (thread_info(cur)->version < THREAD_VERSION_1_2){
411+
if (!thread_commercial_version_check(thread_info(cur)->version)) {
412412
return false;
413413
}
414414

source/6LoWPAN/Thread/thread_network_data_storage.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "ip6string.h"
2020
#include "6LoWPAN/Thread/thread_common.h"
2121
#include "6LoWPAN/Thread/thread_config.h"
22+
#include "6LoWPAN/Thread/thread_commercial.h"
2223
#include "6LoWPAN/Thread/thread_joiner_application.h"
2324
#include "6LoWPAN/Thread/thread_network_data_lib.h"
2425
#include "6LoWPAN/Thread/thread_network_data_storage.h"
@@ -1931,7 +1932,7 @@ uint8_t thread_nd_context_id_allocate(thread_network_data_cache_entry_t *network
19311932

19321933
//Allocate Free context id starting from number 1 for Thread 1.1
19331934
// Starting for 2 for Thread commercial.
1934-
if (thread_version > THREAD_VERSION_1_2) {
1935+
if (thread_commercial_version_check(thread_version)) {
19351936
tempId = 2;
19361937
} else {
19371938
tempId = 1;

source/6LoWPAN/Thread/thread_router_bootstrap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2578,7 +2578,7 @@ bool thread_router_bootstrap_routing_allowed(struct protocol_interface_info_entr
25782578
return true;
25792579
}
25802580

2581-
return !(cur->thread_info->version < THREAD_VERSION_1_2 && !(link_conf_ptr->securityPolicy & SECURITY_POLICY_ALL_ROUTERS_JOIN_ALLOWED));
2581+
return !(!thread_commercial_version_check(cur->thread_info->version) && !(link_conf_ptr->securityPolicy & SECURITY_POLICY_ALL_ROUTERS_JOIN_ALLOWED));
25822582
}
25832583

25842584
void thread_router_bootstrap_address_change_notify_send(protocol_interface_info_entry_t *cur)

0 commit comments

Comments
 (0)