Skip to content

Commit 76f7725

Browse files
author
Mika Tervonen
authored
Primary BBR fixes from interop (ARMmbed#1512)
Add support for multible address add support for commissioner deregister and permanent register Removed extra coap service and started using the correct
1 parent 12ed5ab commit 76f7725

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

source/6LoWPAN/Thread/thread_extension_bbr.c

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ typedef struct {
8080
int8_t interface_id;
8181
int8_t coap_service_id;
8282
int8_t coap_nmkp_virtual_service_id;
83-
int8_t br_service_id;
8483
int8_t backbone_interface_id;
8584
int8_t br_bb_service_id;
8685
bool pbbr_started:1;
@@ -146,7 +145,7 @@ static thread_pbbr_t *thread_border_router_find_by_service(int8_t service_id)
146145
{
147146
thread_pbbr_t *this = NULL;
148147
ns_list_foreach(thread_pbbr_t, cur_br, &pbbr_instance_list) {
149-
if (cur_br->coap_service_id == service_id || cur_br->br_service_id == service_id ||
148+
if (cur_br->coap_service_id == service_id ||
150149
cur_br->br_bb_service_id == service_id || cur_br->coap_nmkp_virtual_service_id == service_id) {
151150
this = cur_br;
152151
break;
@@ -547,17 +546,17 @@ static int thread_pbbr_bb_ans_cb(int8_t service_id, uint8_t source_address[16],
547546
// If delayed DUA registration entry is present send duplicate error code to DUA.response
548547
return 0;
549548
}
550-
static int thread_extension_bbr_bmlr_req_send(int8_t service_id, const uint8_t br_addr[16], const uint8_t address[16], uint32_t timeout)
549+
static int thread_extension_bbr_bmlr_req_send(int8_t service_id, const uint8_t br_addr[16], const uint8_t *address_ptr, uint8_t addr_len, uint32_t timeout)
551550
{
552551
uint8_t payload[2 + 16 + 2 + 4 + 2];
553552
uint8_t *ptr;
554553

555-
if (!br_addr || !address) {
554+
if (!br_addr || !address_ptr) {
556555
return -1;
557556
}
558557

559558
ptr = payload;
560-
ptr = thread_meshcop_tlv_data_write(ptr, TMFCOP_TLV_IPV6_ADDRESS, 16, address);
559+
ptr = thread_meshcop_tlv_data_write(ptr, TMFCOP_TLV_IPV6_ADDRESS, addr_len, address_ptr);
561560
ptr = thread_meshcop_tlv_data_write_uint32(ptr, TMFCOP_TLV_TIMEOUT, timeout);
562561

563562
tr_debug("thread BMLR.ntf send; timeout: %"PRIu32, timeout);
@@ -573,6 +572,7 @@ static int thread_extension_bbr_mlr_cb(int8_t service_id, uint8_t source_address
573572
(void)source_port;
574573

575574
uint16_t addr_len;
575+
uint16_t session_id;
576576
uint8_t *addr_data_ptr;
577577
uint32_t timeout_value;
578578
uint8_t bbr_rloc_addr[16];
@@ -595,8 +595,6 @@ static int thread_extension_bbr_mlr_cb(int8_t service_id, uint8_t source_address
595595
timeout_value = this->mlr_timeout;
596596

597597
addr_len = thread_meshcop_tlv_find(request_ptr->payload_ptr, request_ptr->payload_len, TMFCOP_TLV_IPV6_ADDRESS, &addr_data_ptr);
598-
//TODO in future check if commissioner
599-
//thread_meshcop_tlv_data_get_uint32(request_ptr->payload_ptr, request_ptr->payload_len, TMFCOP_TLV_TIMEOUT, &timeout_value);
600598

601599
// check if we are not primary bbr respond status 5
602600
if (0 != thread_extension_primary_bbr_get(cur, bbr_rloc_addr, NULL, NULL, NULL) ||
@@ -605,21 +603,45 @@ static int thread_extension_bbr_mlr_cb(int8_t service_id, uint8_t source_address
605603
bbr_status = THREAD_BBR_STATUS_NOT_PRIMARY_BBR;
606604
goto send_response;
607605
}
606+
if (2 <= thread_meshcop_tlv_data_get_uint16(request_ptr->payload_ptr, request_ptr->payload_len, MESHCOP_TLV_COMMISSIONER_SESSION_ID, &session_id)) {
607+
//check if commissioner
608+
// Session id present must be valid
609+
tr_info("message from commissioner");
610+
if (cur->thread_info->registered_commissioner.session_id != session_id) {
611+
tr_warn("Invalid commissioner session id");
612+
bbr_status = THREAD_BBR_STATUS_NOT_SPECIFIED;
613+
goto send_response;
614+
}
615+
thread_meshcop_tlv_data_get_uint32(request_ptr->payload_ptr, request_ptr->payload_len, TMFCOP_TLV_TIMEOUT, &timeout_value);
616+
if (timeout_value == 0xffffffff) {
617+
tr_info("Store multicast address to NVM");
618+
}
619+
}
608620

609-
// TODO this can have multiple address please process all
610-
if ( addr_len != 16) {
621+
if ( addr_len < 16 ||
622+
addr_len % 16 != 0 ) {
623+
// Address must be more than 16 and can be multible
611624
tr_err("Invalid /n/mr message");
612625
response_code = COAP_MSG_CODE_RESPONSE_BAD_REQUEST;
613626
goto send_response;
614627
}
615-
616-
tr_debug("Multicast address: %s Timeout value: %"PRIu32, trace_ipv6(addr_data_ptr),timeout_value);
617-
618-
// TODO do not decrease the timeout value, but only applies if commissioner support added
619-
multicast_fwd_add(this->interface_id, addr_data_ptr, timeout_value);
628+
int16_t remaining = addr_len;
629+
uint8_t *addr_ptr = addr_data_ptr;
630+
while (remaining > 0) {
631+
//Go through all addresses
632+
if (timeout_value == 0) {
633+
tr_debug("Multicast address: %s delete", trace_ipv6(addr_ptr));
634+
addr_multicast_fwd_remove(cur, addr_ptr);
635+
} else {
636+
tr_debug("Multicast address: %s Timeout value: %"PRIu32, trace_ipv6(addr_ptr),timeout_value);
637+
multicast_fwd_add(this->interface_id, addr_ptr, timeout_value);
638+
}
639+
addr_ptr += 16;
640+
remaining -= 16;
641+
}
620642

621643
// send BMLR.ntf message to backend
622-
thread_extension_bbr_bmlr_req_send(this->br_service_id, this->pbbr_multicast_address, addr_data_ptr, timeout_value);
644+
thread_extension_bbr_bmlr_req_send(this->br_bb_service_id, this->pbbr_multicast_address, addr_data_ptr, addr_len, timeout_value);
623645

624646
send_response:
625647

0 commit comments

Comments
 (0)