Skip to content

Commit 17e27a4

Browse files
MTD status check added (#2010)
check for status TLV is address registration response to MTD added.
1 parent a0e893b commit 17e27a4

File tree

3 files changed

+40
-36
lines changed

3 files changed

+40
-36
lines changed

source/6LoWPAN/Thread/thread_extension.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static int thread_extension_mtd_dua_ntf_cb(int8_t service_id, uint8_t source_add
179179
(void) response_ptr;
180180
uint16_t addr_len;
181181
uint8_t *addr_data_ptr;
182-
182+
uint8_t dua_status = THREAD_EXTENSION_ST_DUA_SUCCESS;
183183
tr_debug("Thread MTD n/dn callback");
184184

185185
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(thread_management_client_get_interface_id_by_service_id(service_id));
@@ -189,12 +189,17 @@ static int thread_extension_mtd_dua_ntf_cb(int8_t service_id, uint8_t source_add
189189
addr_len = thread_meshcop_tlv_find(response_ptr->payload_ptr, response_ptr->payload_len, TMFCOP_TLV_TARGET_EID, &addr_data_ptr);
190190

191191
if (addr_len < 16) {
192-
tr_warn("Invalid target eid in DUA.rsp cb message");
192+
tr_warn("Invalid target eid in DUA.ntf cb message");
193193
return -2;
194194
}
195-
// generate new dua address
196-
cur->dad_failures++;
197-
thread_extension_dua_address_generate(cur, addr_data_ptr, 64);
195+
196+
thread_tmfcop_tlv_data_get_uint8(response_ptr->payload_ptr, response_ptr->payload_len, TMFCOP_TLV_STATUS, &dua_status);
197+
198+
if (dua_status == THREAD_EXTENSION_ST_DUA_DUPLICATE) {
199+
// generate new dua address
200+
cur->dad_failures++;
201+
thread_extension_dua_address_generate(cur, addr_data_ptr, 64);
202+
}
198203

199204
return 0;
200205
}

source/6LoWPAN/Thread/thread_extension_bbr.c

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -108,26 +108,6 @@ static NS_LIST_DEFINE(duplicate_dua_tr_list, duplicate_dua_tr_t, link);
108108
#define THREAD_BBR_DUA_DAD_QUERY_TIMEOUT 1 // wait period for Duplicate Address Detection
109109
#define THREAD_BBR_DUA_DAD_REPEATS 2 // multicast repeated as part of DUA
110110

111-
/*
112-
0 – Successful registration
113-
1 – Registration rejected: Registration Sequence Number is not newer
114-
2 – Registration rejected: Target EID is not a valid DUA
115-
3 – Registration rejected: DUA is already in use by another Device
116-
4 – Registration rejected: BBR resource shortage
117-
5 – Registration rejected: BBR is not Primary at this moment
118-
6 – Registration failure: Reason(s) not further specified
119-
7 – Registration failure: Backbone Link not operational
120-
*/
121-
#define THREAD_BBR_STATUS_SUCCESS 0
122-
#define THREAD_BBR_STATUS_SEQ_NUMBER_OLD 1
123-
#define THREAD_BBR_STATUS_TARGET_EID_NOT_VALID 2
124-
#define THREAD_BBR_STATUS_DUA_ALREADY_IN_USE 3
125-
#define THREAD_BBR_STATUS_RESOURCE_SHORTAGE 4
126-
#define THREAD_BBR_STATUS_NOT_PRIMARY_BBR 5
127-
#define THREAD_BBR_STATUS_NOT_SPECIFIED 6
128-
#define THREAD_BBR_STATUS_BB_LINK_NOT_OPERATIONAL 7
129-
130-
131111
static void thread_border_router_multicast_store_add(thread_pbbr_t *this, uint8_t *destination_addr_ptr);
132112
static void thread_border_router_multicast_store_del(thread_pbbr_t *this, uint8_t *destination_addr_ptr);
133113
static void thread_border_router_multicast_store_activate(thread_pbbr_t *this);
@@ -766,7 +746,7 @@ static int thread_extension_bbr_mlr_cb(int8_t service_id, uint8_t source_address
766746
uint8_t *invalid_addr_ptr = NULL;
767747
uint32_t timeout_value;
768748
uint8_t bbr_rloc_addr[16];
769-
uint8_t bbr_status = THREAD_BBR_STATUS_SUCCESS;
749+
uint8_t bbr_status = THREAD_EXTENSION_ST_DUA_SUCCESS;
770750
uint8_t payload[4 + 18];
771751
uint8_t *ptr;
772752

@@ -793,7 +773,7 @@ static int thread_extension_bbr_mlr_cb(int8_t service_id, uint8_t source_address
793773
if (0 != thread_extension_primary_bbr_get(cur, bbr_rloc_addr, NULL, NULL, NULL) ||
794774
!addr_get_entry(cur, bbr_rloc_addr)) {
795775
// Primary BBR not present or I am not BBR
796-
bbr_status = THREAD_BBR_STATUS_NOT_PRIMARY_BBR;
776+
bbr_status = THREAD_EXTENSION_ST_DUA_BBR_NOT_PRIMARY;
797777
goto send_response;
798778
}
799779

@@ -803,7 +783,7 @@ static int thread_extension_bbr_mlr_cb(int8_t service_id, uint8_t source_address
803783
tr_info("message from commissioner");
804784
if (cur->thread_info->registered_commissioner.session_id != session_id) {
805785
tr_warn("Invalid commissioner session id");
806-
bbr_status = THREAD_BBR_STATUS_NOT_SPECIFIED;
786+
bbr_status = THREAD_EXTENSION_ST_DUA_GENERAL_FAILURE;
807787
goto send_response;
808788
}
809789
thread_meshcop_tlv_data_get_uint32(request_ptr->payload_ptr, request_ptr->payload_len, TMFCOP_TLV_TIMEOUT, &timeout_value);
@@ -819,15 +799,15 @@ static int thread_extension_bbr_mlr_cb(int8_t service_id, uint8_t source_address
819799
if (addr_len >= 16) {
820800
invalid_addr_ptr = addr_ptr;
821801
}
822-
bbr_status = THREAD_BBR_STATUS_TARGET_EID_NOT_VALID;
802+
bbr_status = THREAD_EXTENSION_ST_DUA_INVALID;
823803
goto send_response;
824804
}
825805

826806
while (remaining > 0) {
827807
//Go through all addresses
828808
if (!addr_is_ipv6_multicast(addr_ptr)) {
829809
tr_err("Invalid /n/mr not multicast address");
830-
bbr_status = THREAD_BBR_STATUS_TARGET_EID_NOT_VALID;
810+
bbr_status = THREAD_EXTENSION_ST_DUA_INVALID;
831811
if (!invalid_addr_ptr) {
832812
invalid_addr_ptr = addr_ptr;
833813
}
@@ -887,7 +867,7 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
887867
uint8_t bbr_rloc_addr[16];
888868
uint8_t *ptr;
889869
bool entry_keep_alive = false;
890-
uint8_t bbr_status = THREAD_BBR_STATUS_SUCCESS;
870+
uint8_t bbr_status = THREAD_EXTENSION_ST_DUA_SUCCESS;
891871

892872
tr_info("Thread BBR DUA.req received");
893873

@@ -916,7 +896,7 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
916896
if (0 == thread_extension_primary_bbr_get(cur, bbr_rloc_addr, NULL, NULL, NULL) &&
917897
!addr_get_entry(cur, bbr_rloc_addr)) {
918898
// Primary pBBR present and I am not the pBBR
919-
bbr_status = THREAD_BBR_STATUS_NOT_PRIMARY_BBR;
899+
bbr_status = THREAD_EXTENSION_ST_DUA_BBR_NOT_PRIMARY;
920900
goto send_response;
921901
}
922902

@@ -925,14 +905,14 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
925905

926906
if (addr_len < 16 || ml_eid_len < 8) {
927907
tr_err("Invalid /n/dr message");
928-
bbr_status = THREAD_BBR_STATUS_NOT_SPECIFIED;
908+
bbr_status = THREAD_EXTENSION_ST_DUA_GENERAL_FAILURE;
929909
goto send_response;
930910
}
931911

932912
if (!bitsequal(addr_data_ptr, this->domain_prefix, 64)) {
933913
// Prefix did not match
934914
tr_warn("Registration failed invalid address");
935-
bbr_status = THREAD_BBR_STATUS_TARGET_EID_NOT_VALID;
915+
bbr_status = THREAD_EXTENSION_ST_DUA_INVALID;
936916
goto send_response;
937917
}
938918

@@ -943,15 +923,15 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
943923

944924
// new device has generated duplicate dua
945925
if (route != NULL && route->info.info != NULL && memcmp(((thread_pbbr_dua_info_t *)route->info.info)->mleid_ptr, ml_eid_ptr, 8) != 0) {
946-
bbr_status = THREAD_BBR_STATUS_DUA_ALREADY_IN_USE;
926+
bbr_status = THREAD_EXTENSION_ST_DUA_DUPLICATE;
947927
goto send_response;
948928
}
949929
if (route != NULL && route->info.info != NULL && memcmp(((thread_pbbr_dua_info_t *)route->info.info)->mleid_ptr, ml_eid_ptr, 8) == 0) {
950930
((thread_pbbr_dua_info_t *)route->info.info)->last_contact_time = protocol_core_monotonic_time;
951931
entry_keep_alive = true;
952932
}
953933
if (thread_bbr_dua_entry_add(this->interface_id, addr_data_ptr, this->dua_timeout * 2, ml_eid_ptr) != 0) {
954-
bbr_status = THREAD_BBR_STATUS_RESOURCE_SHORTAGE;
934+
bbr_status = THREAD_EXTENSION_ST_DUA_NO_RESOURCES;
955935
goto send_response;
956936
}
957937
/*if (route && memcmp(route->info.next_hop_addr, ml_addr,16) != 0) {

source/6LoWPAN/Thread/thread_extension_constants.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,25 @@ typedef struct discovery_additional_info {
140140
#define THREAD_EXTENSION_SECURITY_POLICY_NCR_DISABLED 0x40
141141
#define THREAD_EXTENSION_SECURITY_POLICY_VR_VALUE 0x07
142142

143+
/**
144+
* Thread 1.2 Status TLV in DUA.rsp message.
145+
* /
146+
0 – Successful registration
147+
2 – Registration rejected: Target EID is not a valid DUA; e.g. incorrect Domain Prefix
148+
3 – Registration rejected: DUA is already in use by another Device
149+
4 – Registration rejected: BBR resource shortage
150+
5 – Registration rejected: BBR is not Primary at this moment
151+
6 – Registration failure: Reason(s) not further specified
152+
*/
153+
154+
#define THREAD_EXTENSION_ST_DUA_SUCCESS 0
155+
#define THREAD_EXTENSION_ST_DUA_INVALID 2
156+
#define THREAD_EXTENSION_ST_DUA_DUPLICATE 3
157+
#define THREAD_EXTENSION_ST_DUA_NO_RESOURCES 4
158+
#define THREAD_EXTENSION_ST_DUA_BBR_NOT_PRIMARY 5
159+
#define THREAD_EXTENSION_ST_DUA_GENERAL_FAILURE 6
160+
161+
143162
#define THREAD_VERSION_1_2 3
144163

145164
#endif /* THREAD_EXTENSION_CONSTANTS_H_ */

0 commit comments

Comments
 (0)