Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 684efef

Browse files
author
Mika Tervonen
committed
Fix MLR message handling
Respond to MLR message with address TLV if failure Check that address is multicast scope Add correct scope for Commissioner session ID in MLR message
1 parent b691b78 commit 684efef

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

source/6LoWPAN/Thread/thread_extension_bbr.c

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ static int thread_extension_bbr_mlr_cb(int8_t service_id, uint8_t source_address
672672
uint32_t timeout_value;
673673
uint8_t bbr_rloc_addr[16];
674674
uint8_t bbr_status = THREAD_BBR_STATUS_SUCCESS;
675-
uint8_t payload[4];
675+
uint8_t payload[4 + 18];
676676
uint8_t *ptr;
677677

678678
tr_info("Thread BBR MLR.ntf receive");
@@ -703,7 +703,7 @@ static int thread_extension_bbr_mlr_cb(int8_t service_id, uint8_t source_address
703703
}
704704

705705
//check if commissioner
706-
if (2 <= thread_meshcop_tlv_data_get_uint16(request_ptr->payload_ptr, request_ptr->payload_len, MESHCOP_TLV_COMMISSIONER_SESSION_ID, &session_id)) {
706+
if (2 <= thread_meshcop_tlv_data_get_uint16(request_ptr->payload_ptr, request_ptr->payload_len, TMFCOP_TLV_COMMISSIONER_SESSION_ID, &session_id)) {
707707
// Session id present must be valid
708708
tr_info("message from commissioner");
709709
if (cur->thread_info->registered_commissioner.session_id != session_id) {
@@ -712,32 +712,45 @@ static int thread_extension_bbr_mlr_cb(int8_t service_id, uint8_t source_address
712712
goto send_response;
713713
}
714714
thread_meshcop_tlv_data_get_uint32(request_ptr->payload_ptr, request_ptr->payload_len, TMFCOP_TLV_TIMEOUT, &timeout_value);
715-
if (timeout_value == 0xffffffff) {
716-
tr_info("Store multicast address to NVM");
717-
}
718715
}
719716

717+
int16_t remaining = addr_len;
718+
uint8_t *addr_ptr = addr_data_ptr;
719+
uint8_t *invalid_addr_ptr = NULL;
720+
720721
if ( addr_len < 16 ||
721722
addr_len % 16 != 0 ) {
722723
// Address must be more than 16 and can be multible
723724
tr_err("Invalid /n/mr message");
724-
response_code = COAP_MSG_CODE_RESPONSE_BAD_REQUEST;
725+
if(addr_len >= 16) {
726+
invalid_addr_ptr = addr_ptr;
727+
}
728+
bbr_status = THREAD_BBR_STATUS_TARGET_EID_NOT_VALID;
725729
goto send_response;
726730
}
727731

728-
int16_t remaining = addr_len;
729-
uint8_t *addr_ptr = addr_data_ptr;
730-
731732
while (remaining > 0) {
732733
//Go through all addresses
733-
if (timeout_value == 0) {
734-
//tr_debug("Multicast address: %s delete", trace_ipv6(addr_ptr));
735-
addr_multicast_fwd_remove(cur, addr_ptr);
734+
if (!addr_is_ipv6_multicast(addr_ptr)) {
735+
bbr_status = THREAD_BBR_STATUS_TARGET_EID_NOT_VALID;
736+
if (!invalid_addr_ptr) {
737+
invalid_addr_ptr = addr_ptr;
738+
}
736739
} else {
737-
//tr_debug("Multicast address: %s Timeout value: %"PRIu32, trace_ipv6(addr_ptr),timeout_value);
738-
multicast_fwd_add(this->interface_id, addr_ptr, timeout_value);
739-
// send BMLR.ntf message to backend
740-
thread_extension_bbr_bmlr_req_send(this->br_bb_service_id, this->pbbr_multicast_address, addr_data_ptr, 16, timeout_value);
740+
if (timeout_value == 0) {
741+
//tr_debug("Multicast address: %s delete", trace_ipv6(addr_ptr));
742+
addr_multicast_fwd_remove(cur, addr_ptr);
743+
// TODO remove address from NVM
744+
tr_info("delete multicast address from NVM");
745+
} else {
746+
//tr_debug("Multicast address: %s Timeout value: %"PRIu32, trace_ipv6(addr_ptr),timeout_value);
747+
multicast_fwd_add(this->interface_id, addr_ptr, timeout_value);
748+
if (timeout_value == 0xffffffff) {
749+
tr_info("Store multicast address to NVM");
750+
}
751+
// send BMLR.ntf message to backend
752+
thread_extension_bbr_bmlr_req_send(this->br_bb_service_id, this->pbbr_multicast_address, addr_data_ptr, 16, timeout_value);
753+
}
741754
}
742755
addr_ptr += 16;
743756
remaining -= 16;
@@ -748,6 +761,9 @@ static int thread_extension_bbr_mlr_cb(int8_t service_id, uint8_t source_address
748761

749762
if (request_ptr->msg_type == COAP_MSG_TYPE_CONFIRMABLE) {
750763
ptr = thread_tmfcop_tlv_data_write_uint8(ptr, TMFCOP_TLV_STATUS, bbr_status);
764+
if (invalid_addr_ptr) {
765+
ptr = thread_meshcop_tlv_data_write(ptr, TMFCOP_TLV_IPV6_ADDRESS, 16, invalid_addr_ptr);
766+
}
751767
coap_service_response_send(this->coap_service_id, COAP_REQUEST_OPTIONS_NONE, request_ptr, response_code, COAP_CT_OCTET_STREAM, payload, ptr -payload);
752768
return 0;
753769
}

source/6LoWPAN/Thread/thread_extension_constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ typedef struct discovery_additional_info {
106106
#define TMFCOP_TLV_NETWORK_NAME 12
107107
#define TMFCOP_TLV_SEQUENCE_NUMBER 13
108108
#define TMFCOP_TLV_IPV6_ADDRESS 14
109+
#define TMFCOP_TLV_COMMISSIONER_SESSION_ID 15
109110

110111
#define THREAD_CONTENT_FORMAT_AUDITNONCE (sn_coap_content_format_e)65000
111112
#define THREAD_CONTENT_FORMAT_PKCS10 (sn_coap_content_format_e)65003

0 commit comments

Comments
 (0)