Skip to content

Commit d4db17a

Browse files
author
Tero Heinonen
authored
Move thread commercial code to own file (#1470)
Separate thread 1.2 code from 1.1 code.
1 parent 34b7f96 commit d4db17a

15 files changed

+662
-322
lines changed

source/6LoWPAN/Thread/thread_bootstrap.c

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "6LoWPAN/Thread/thread_border_router_api_internal.h"
4646
#include "6LoWPAN/Thread/thread_beacon.h"
4747
#include "6LoWPAN/Thread/thread_nvm_store.h"
48+
#include "6LoWPAN/Thread/thread_commercial_bootstrap.h"
4849
#include "6LoWPAN/MAC/mac_helper.h"
4950
#include "6LoWPAN/Thread/thread_mle_message_handler.h"
5051
#include "mac_api.h"
@@ -88,11 +89,6 @@ static void thread_neighbor_remove(int8_t interface_id, mle_neigh_table_entry_t
8889
static void thread_bootsrap_network_join_start(struct protocol_interface_info_entry *cur_interface, discovery_response_list_t *nwk_info);
8990
static int8_t thread_child_keep_alive(int8_t interface_id, const uint8_t *mac64);
9091

91-
static int stringlen(const char *s, int n)
92-
{
93-
char *end = memchr(s, 0, n);
94-
return end?end-s:n;
95-
}
9692

9793
int thread_bootstrap_reset_child_info(protocol_interface_info_entry_t *cur, mle_neigh_table_entry_t *child)
9894
{
@@ -1942,33 +1938,7 @@ static void thread_network_select_by_steering_data(device_configuration_s *devic
19421938

19431939
static void thread_network_select(struct protocol_interface_info_entry *interface_prt, device_configuration_s *device_configuration_ptr, thread_nwk_discovery_response_list_t *discover_response)
19441940
{
1945-
discovery_response_list_t *discovered_network_ptr = NULL;
1946-
1947-
if (thread_info(interface_prt)->version == THREAD_VERSION_1_2 && thread_info(interface_prt)->ccm_ptr) {
1948-
/* If we have domain certificate, search for domain to join */
1949-
if (thread_info(interface_prt)->ccm_ptr->domain_certificate_ptr) {
1950-
ns_list_foreach_safe(discovery_response_list_t, cur_class, discover_response) {
1951-
if ((stringlen((const char*) cur_class->thread_domain, 16)) &&
1952-
(!memcmp(cur_class->thread_domain, thread_info(interface_prt)->ccm_ptr->domain_name, stringlen((const char*) cur_class->thread_domain, 16))))
1953-
{
1954-
discovered_network_ptr = cur_class;
1955-
break;
1956-
}
1957-
}
1958-
}
1959-
1960-
/* No domain, use device certificate*/
1961-
if (!discovered_network_ptr) {
1962-
ns_list_foreach_safe(discovery_response_list_t, cur_class, discover_response) {
1963-
if (cur_class->ccm_supported)
1964-
{
1965-
discovered_network_ptr = cur_class;
1966-
break;
1967-
}
1968-
}
1969-
}
1970-
}
1971-
1941+
discovery_response_list_t *discovered_network_ptr = thread_commercial_bootstrap_network_select(interface_prt, discover_response);
19721942

19731943
/* If network found */
19741944
if (discovered_network_ptr) {
@@ -2169,17 +2139,7 @@ static void thread_bootsrap_network_join_start(struct protocol_interface_info_en
21692139
tr_debug("Start commission with %s", trace_ipv6(parentLLAddress));
21702140
cur_interface->bootsrap_state_machine_cnt = 0;
21712141

2172-
if (thread_info(cur_interface)->version == THREAD_VERSION_1_2 && thread_info(cur_interface)->ccm_ptr) {
2173-
if (thread_info(cur_interface)->ccm_ptr->domain_certificate_ptr && nwk_info->nmk_port) {
2174-
thread_joiner_application_nmkp_commission_start(cur_interface->id, parentLLAddress, nwk_info->nmk_port, thread_bootstrap_joiner_application_commission_done_cb);
2175-
} else if (thread_info(cur_interface)->ccm_ptr->device_certificate_ptr && nwk_info->ae_port) {
2176-
thread_joiner_application_ae_commission_start(cur_interface->id, parentLLAddress, nwk_info->ae_port, thread_bootstrap_joiner_application_commission_done_cb);
2177-
} else if (nwk_info->joiner_port) {
2178-
thread_joiner_application_pskd_commission_start(cur_interface->id, parentLLAddress, nwk_info->joiner_port, nwk_info->pan_id, nwk_info->extented_pan_id, nwk_info->channel, thread_bootstrap_joiner_application_commission_done_cb);
2179-
} else {
2180-
return;
2181-
}
2182-
} else {
2142+
if (0 > thread_commercial_bootstrap_commission_start(cur_interface, parentLLAddress, nwk_info, thread_bootstrap_joiner_application_commission_done_cb)) {
21832143
thread_joiner_application_pskd_commission_start(cur_interface->id, parentLLAddress, nwk_info->joiner_port, nwk_info->pan_id, nwk_info->extented_pan_id, nwk_info->channel, thread_bootstrap_joiner_application_commission_done_cb);
21842144
}
21852145
ns_dyn_mem_free(nwk_info);

source/6LoWPAN/Thread/thread_commercial.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "6LoWPAN/Thread/thread_management_internal.h"
2525
#include "6LoWPAN/Thread/thread_management_server.h"
2626
#include "6LoWPAN/Thread/thread_address_registration_client.h"
27+
#include "6LoWPAN/Thread/thread_discovery.h"
28+
#include "6LoWPAN/Thread/thread_commercial_bootstrap.h"
2729
#include "6LoWPAN/MAC/mac_helper.h"
2830
#include "NWK_INTERFACE/Include/protocol.h"
2931
#include "Common_Protocols/ipv6.h"
@@ -49,11 +51,6 @@ typedef struct thread_commercial_info {
4951
bool update_needed:1;
5052
} thread_commercial_info_t;
5153

52-
static int stringlen(const char *s, int n)
53-
{
54-
char *end = memchr(s, 0, n);
55-
return end?end-s:n;
56-
}
5754

5855
static int thread_commercial_dua_registration_cb(int8_t service_id, uint8_t source_address[static 16], uint16_t source_port, sn_coap_hdr_s *response_ptr)
5956
{
@@ -746,6 +743,7 @@ bool thread_commercial_joining_enabled(int8_t interface_id)
746743
uint8_t thread_commercial_discover_response_len(protocol_interface_info_entry_t *cur)
747744
{
748745
uint8_t length = 0;
746+
uint8_t domain_name_len;
749747
// AE port
750748
if (!cur || !cur->thread_info->commercial_info) {
751749
return 0;
@@ -761,8 +759,9 @@ uint8_t thread_commercial_discover_response_len(protocol_interface_info_entry_t
761759
if (cur->thread_info->version == THREAD_VERSION_1_2 && thread_info(cur)->ccm_ptr) {
762760
// Calculate also following optional TLV's:
763761
// Thread domain name TLV
764-
if (stringlen((const char *)thread_info(cur)->ccm_ptr->domain_name, 16)) {
765-
length += (stringlen((const char *)thread_info(cur)->ccm_ptr->domain_name, 16)) + 2;
762+
domain_name_len = thread_commercial_bootstrap_domain_name_length_get(cur);
763+
if (domain_name_len) {
764+
length += domain_name_len + 2;
766765
}
767766
// AE steering data
768767
// NMKP Steering Data
@@ -785,8 +784,8 @@ uint8_t *thread_commercial_discover_response_write(protocol_interface_info_entry
785784
/* Thread 1.2 CCM add-ons */
786785
if (cur->thread_info->version == THREAD_VERSION_1_2 && thread_info(cur)->ccm_ptr) {
787786
// Thread domain name TLV
788-
if (stringlen((const char *)thread_info(cur)->ccm_ptr->domain_name, 16)) {
789-
ptr = thread_meshcop_tlv_data_write(ptr, MESHCOP_TLV_DOMAIN_NAME, stringlen((const char *)thread_info(cur)->ccm_ptr->domain_name, 16), thread_info(cur)->ccm_ptr->domain_name);
787+
if (thread_commercial_bootstrap_domain_name_length_get(cur)) {
788+
ptr = thread_meshcop_tlv_data_write(ptr, MESHCOP_TLV_DOMAIN_NAME, thread_commercial_bootstrap_domain_name_length_get(cur), thread_commercial_bootstrap_domain_name_ptr_get(cur));
790789
}
791790
// Build also following optional TLV's, when supported:
792791
// AE steering data

source/6LoWPAN/Thread/thread_commercial_bbr.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "6LoWPAN/Thread/thread_joiner_application.h"
2424
#include "6LoWPAN/Thread/thread_management_internal.h"
2525
#include "6LoWPAN/Thread/thread_address_registration_client.h"
26+
#include "6LoWPAN/Thread/thread_discovery.h"
27+
#include "6LoWPAN/Thread/thread_commercial_bootstrap.h"
2628
#include "NWK_INTERFACE/Include/protocol.h"
2729
#include "Common_Protocols/ipv6.h"
2830

@@ -757,12 +759,7 @@ static int thread_commercial_bbr_pbbr_start(thread_pbbr_t *this)
757759
// create secure service for Network master key provisioning
758760
this->coap_nmkp_virtual_service_id = coap_service_initialize(this->interface_id, THREAD_MANAGEMENT_PORT, COAP_SERVICE_OPTIONS_SECURE | COAP_SERVICE_OPTIONS_VIRTUAL_SOCKET, thread_pbbr_pskd_security_start_cb, NULL);
759761
// SET certificates
760-
if (cur->thread_info->ccm_ptr && cur->thread_info->ccm_ptr->domain_certificate_ptr) {
761-
if(0 > coap_service_certificate_set(this->coap_nmkp_virtual_service_id, cur->thread_info->ccm_ptr->domain_certificate_ptr, cur->thread_info->ccm_ptr->domain_certificate_len,
762-
cur->thread_info->ccm_ptr->domain_pk_ptr, cur->thread_info->ccm_ptr->domain_pk_len)) {
763-
tr_debug("pBBR certificate set failed");
764-
}
765-
}
762+
thread_commercial_bootstrap_domain_certificate_enable(cur, this->coap_nmkp_virtual_service_id);
766763
coap_service_register_uri(this->coap_nmkp_virtual_service_id, THREAD_URI_BBR_NMKP_REQ, COAP_SERVICE_ACCESS_POST_ALLOWED, thread_pbbr_nmkp_req_recv_cb);
767764
coap_service_virtual_socket_set_cb(this->coap_nmkp_virtual_service_id, thread_pbbr_nmkp_virtual_socket_send_cb);
768765
// Set the partition weight to be 72

0 commit comments

Comments
 (0)