Skip to content

Commit d4c95f2

Browse files
author
Arto Kinnunen
authored
Clear COAP retransmissions in partition change (ARMmbed#1872)
-Delete old COAP transactions when partition is changed to prevent possible COAP retransmissions. - Combine coap_service_ids to share service id from thread_management_server. - Thread BR does not update RLOC if publish has failed
1 parent bf36b91 commit d4c95f2

28 files changed

+206
-85
lines changed

source/6LoWPAN/Thread/thread_bbr_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ static bool thread_bbr_activated(thread_bbr_t *this, uint32_t seconds)
734734
return true;
735735
}
736736

737-
if (cur->thread_info->routerIdReqCoapID) {
737+
if (cur->thread_info->routerIdRequested) {
738738
// Router id reguest pending we need to wait for response
739739
return false;
740740
}

source/6LoWPAN/Thread/thread_bootstrap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,7 +1647,7 @@ void thread_bootstrap_attached_finish(protocol_interface_info_entry_t *cur)
16471647
cur->lowpan_info |= INTERFACE_NWK_BOOTSRAP_ADDRESS_REGISTER_READY;
16481648
cur->lowpan_info &= ~INTERFACE_NWK_ROUTER_DEVICE;
16491649
cur->bootsrap_state_machine_cnt = 10;
1650-
cur->thread_info->routerIdReqCoapID = 0;
1650+
cur->thread_info->routerIdRequested = false;
16511651
cur->thread_info->networkDataRequested = false;
16521652
clear_power_state(ICMP_ACTIVE);
16531653

@@ -2044,7 +2044,7 @@ void thread_discover_native_commissioner_response(protocol_interface_info_entry_
20442044
interface->lowpan_info |= INTERFACE_NWK_BOOTSRAP_ADDRESS_REGISTER_READY;
20452045
interface->lowpan_info &= ~INTERFACE_NWK_ROUTER_DEVICE;
20462046

2047-
interface->thread_info->routerIdReqCoapID = 0;
2047+
interface->thread_info->routerIdRequested = false;
20482048
interface->thread_info->networkDataRequested = false;
20492049

20502050
interface->bootsrap_state_machine_cnt = 10;

source/6LoWPAN/Thread/thread_border_router_api.c

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "NWK_INTERFACE/Include/protocol.h"
4343
#include "6LoWPAN/Thread/thread_config.h"
4444
#include "6LoWPAN/Thread/thread_common.h"
45+
#include "6LoWPAN/Thread/thread_extension_bbr.h"
4546
#include "6LoWPAN/Thread/thread_network_data_lib.h"
4647
#include "6LoWPAN/Thread/thread_network_data_storage.h"
4748
#include "6LoWPAN/Thread/thread_management_client.h"
@@ -591,6 +592,15 @@ void thread_border_router_network_data_update_notify(protocol_interface_info_ent
591592

592593
thread_border_router_network_data_appl_callback(cur);
593594
}
595+
596+
void thread_border_router_old_partition_data_clean(int8_t interface_id)
597+
{
598+
thread_border_router_t *this = thread_border_router_find_by_interface(interface_id);
599+
if (this) {
600+
coap_service_request_delete_by_service_id(this->coap_service_id);
601+
}
602+
thread_extension_bbr_old_partition_data_clean(interface_id);
603+
}
594604
#endif // HAVE_THREAD_ROUTER
595605

596606
/*External APIs*/
@@ -837,7 +847,6 @@ int thread_border_router_dns_search_list_option_set(int8_t interface_id, uint8_t
837847
static void thread_tmf_client_network_data_set_cb(int8_t interface_id, int8_t status, uint8_t *data_ptr, uint16_t data_len)
838848
{
839849
protocol_interface_info_entry_t *cur;
840-
(void) status;
841850
(void) data_len;
842851
(void) data_ptr;
843852

@@ -846,7 +855,7 @@ static void thread_tmf_client_network_data_set_cb(int8_t interface_id, int8_t st
846855
return;
847856
}
848857

849-
cur->thread_info->localServerDataBase.publish_active = false;
858+
cur->thread_info->localServerDataBase.publish_coap_req_id = 0;
850859

851860
tr_debug("BR a/sd response status: %s, addr: %x",status?"Fail":"OK", cur->thread_info->localServerDataBase.registered_rloc16);
852861

@@ -855,9 +864,11 @@ static void thread_tmf_client_network_data_set_cb(int8_t interface_id, int8_t st
855864
thread_border_router_publish(cur->id);
856865
}
857866

858-
// always update RLOC to new one. If COAP response fails then resubmit timer will trigger new a/sd
859-
cur->thread_info->localServerDataBase.registered_rloc16 = mac_helper_mac16_address_get(cur);
860-
cur->thread_info->localServerDataBase.release_old_address = false;
867+
if (status == 0) {
868+
// If request was successful, then update RLOC to new one.
869+
cur->thread_info->localServerDataBase.registered_rloc16 = mac_helper_mac16_address_get(cur);
870+
cur->thread_info->localServerDataBase.release_old_address = false;
871+
}
861872
}
862873
#endif
863874

@@ -884,21 +895,20 @@ int thread_border_router_publish(int8_t interface_id)
884895
rloc16 = mac_helper_mac16_address_get(cur);
885896
tr_debug("Border router old: %x, new: %x", cur->thread_info->localServerDataBase.registered_rloc16, rloc16);
886897

887-
if (cur->thread_info->localServerDataBase.publish_active) {
898+
if (cur->thread_info->localServerDataBase.publish_coap_req_id) {
888899
if (rloc16 != cur->thread_info->localServerDataBase.registered_rloc16) {
889900
/*
890-
* Device short address has changed, cancel previous a/sd and a/as requests
901+
* Device short address has changed, cancel previous a/sd requests
891902
* and start resubmit timer
892903
* */
893-
tr_debug("address changed, kill pending reuqests");
894-
thread_management_client_pending_coap_request_kill(cur->id);
904+
tr_debug("RLOC changed, kill pending a/sd request");
905+
thread_management_client_coap_message_delete(cur->id, cur->thread_info->localServerDataBase.publish_coap_req_id);
895906
thread_border_router_resubmit_timer_set(interface_id, 5);
896-
return 0;
897907
} else {
898908
cur->thread_info->localServerDataBase.publish_pending = true;
899909
tr_debug("Activate pending status for publish");
900-
return 0;
901910
}
911+
return 0;
902912
}
903913

904914
//Allocate Memory for Data
@@ -926,8 +936,10 @@ int thread_border_router_publish(int8_t interface_id)
926936
if (payload_ptr) {
927937
ns_dyn_mem_free(payload_ptr);
928938
}
929-
if (ret_val == 0) {
930-
cur->thread_info->localServerDataBase.publish_active = true;
939+
if (ret_val > 0) {
940+
// a/sd request successful, save coap request id
941+
cur->thread_info->localServerDataBase.publish_coap_req_id = (uint16_t)ret_val;
942+
ret_val = 0 ;
931943
}
932944

933945
thread_border_router_resubmit_timer_set(interface_id, -1);

source/6LoWPAN/Thread/thread_border_router_api_internal.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,22 @@ void thread_border_router_network_data_appl_callback(protocol_interface_info_ent
8585
*
8686
*/
8787
void thread_border_router_network_data_update_notify(protocol_interface_info_entry_t *cur);
88+
89+
/**
90+
* \brief Clear data related to old partition.
91+
*
92+
* \param interface_id Network interface ID.
93+
*/
94+
void thread_border_router_old_partition_data_clean(int8_t interface_id);
95+
8896
#else
8997
#define thread_border_router_init(interface_id)
9098
#define thread_border_router_delete(interface_id)
9199
#define thread_border_router_seconds_timer(interface_id, tics)
92100
#define thread_border_router_resubmit_timer_set(interface_id, seconds)
93101
#define thread_border_router_network_data_appl_callback(cur)
94102
#define thread_border_router_network_data_update_notify(cur)
103+
#define thread_border_router_old_partition_data_clean(interface_id)
95104

96105
#endif
97106
#endif /* THREAD_BORDER_ROUTER_API_INTERNAL_H_ */

source/6LoWPAN/Thread/thread_common.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
#include "6LoWPAN/Bootstraps/protocol_6lowpan_interface.h"
4545
#include "6LoWPAN/Thread/thread_common.h"
4646
#include "6LoWPAN/Thread/thread_beacon.h"
47+
#include "6LoWPAN/Thread/thread_diagnostic.h"
48+
#include "6LoWPAN/Thread/thread_extension_bbr.h"
4749
#include "6LoWPAN/Thread/thread_leader_service.h"
4850
#include "6LoWPAN/Thread/thread_routing.h"
4951
#include "DHCPv6_client/dhcpv6_client_api.h"
@@ -60,6 +62,7 @@
6062
#include "6LoWPAN/Thread/thread_management_internal.h"
6163
#include "6LoWPAN/Thread/thread_management_client.h"
6264
#include "6LoWPAN/Thread/thread_management_server.h"
65+
#include "6LoWPAN/Thread/thread_resolution_server.h"
6366
#include "6LoWPAN/Thread/thread_resolution_client.h"
6467
#include "6LoWPAN/Thread/thread_address_registration_client.h"
6568
#include "6LoWPAN/Thread/thread_resolution_client.h"
@@ -259,9 +262,11 @@ int8_t thread_bootstrap_down(protocol_interface_info_entry_t *cur)
259262
thread_leader_mleid_rloc_map_to_nvm_write(cur);
260263
thread_bootstrap_stop(cur);
261264
mle_service_interface_unregister(cur->id);
265+
thread_diagnostic_delete(cur->id); // delete before thread_management_server_delete as they share same coap_service id
266+
thread_management_client_delete(cur->id); // delete before thread_management_server_delete as they share same coap_service id
267+
thread_nd_service_disable(cur->id); // delete before thread_management_server_delete as they share same coap_service id
262268
thread_management_server_delete(cur->id);
263269
thread_joiner_application_deinit(cur->id);
264-
thread_management_client_delete(cur->id);
265270
//free network Data
266271
thread_network_data_free_and_clean(&cur->thread_info->networkDataStorage);
267272
//free local also here
@@ -452,7 +457,7 @@ void thread_data_base_init(thread_info_t *thread_info, int8_t interfaceId)
452457
thread_leader_commissioner_create(thread_info);
453458
thread_info->rfc6775 = false;
454459
thread_info->threadPrivatePrefixInfo.ulaValid = false;
455-
thread_info->routerIdReqCoapID = 0;
460+
thread_info->routerIdRequested = false;
456461
thread_info->networkDataRequested = false;
457462
thread_info->proactive_an_timer = 0;
458463

@@ -2063,10 +2068,16 @@ void thread_mcast_group_change(struct protocol_interface_info_entry *interface,
20632068
}
20642069
}
20652070

2071+
static void thread_old_partition_data_clean(int8_t interface_id)
2072+
{
2073+
thread_management_client_old_partition_data_clean(interface_id);
2074+
thread_border_router_old_partition_data_clean(interface_id);
2075+
}
2076+
20662077
void thread_partition_data_purge(protocol_interface_info_entry_t *cur)
20672078
{
20682079
/* Partition has been changed. Wipe out data related to old partition */
2069-
thread_management_client_pending_coap_request_kill(cur->id);
2080+
thread_old_partition_data_clean(cur->id);
20702081

20712082
/* Reset previous routing information */
20722083
thread_routing_reset(&cur->thread_info->routing);

source/6LoWPAN/Thread/thread_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ typedef struct thread_info_s {
309309
uint16_t routerShortAddress;
310310
uint16_t reedJitterTimer;
311311
uint16_t reedMergeAdvTimer;
312-
uint16_t routerIdReqCoapID; // COAP msg id of RouterID request
313312
int16_t childUpdateReqTimer;
314313
uint16_t childUpdateReqMsgId;
315314
uint16_t proactive_an_timer;
@@ -323,6 +322,7 @@ typedef struct thread_info_s {
323322
bool rfc6775: 1;
324323
bool requestFullNetworkData: 1;
325324
bool leaderCab: 1;
325+
bool routerIdRequested: 1;
326326
bool releaseRouterId: 1;
327327
bool networkSynch: 1;
328328
bool networkDataRequested: 1;

source/6LoWPAN/Thread/thread_diagnostic.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "nsdynmemLIB.h"
3636
#include "net_interface.h"
3737
#include "thread_management_if.h"
38+
#include "thread_management_server.h"
3839
#include "thread_common.h"
3940
#include "thread_joiner_application.h"
4041
#include "thread_leader_service.h"
@@ -543,7 +544,7 @@ int thread_diagnostic_init(int8_t interface_id)
543544

544545
this->interface_id = interface_id;
545546

546-
this->coap_service_id = coap_service_initialize(this->interface_id, THREAD_MANAGEMENT_PORT, COAP_SERVICE_OPTIONS_NONE, NULL, NULL);
547+
this->coap_service_id = thread_management_server_service_id_get(interface_id);
547548
if (this->coap_service_id < 0) {
548549
tr_error("Thread diagnostic init failed");
549550
ns_dyn_mem_free(this);
@@ -567,8 +568,9 @@ int thread_diagnostic_delete(int8_t interface_id)
567568
if (!this) {
568569
return -1;
569570
}
570-
571-
coap_service_delete(this->coap_service_id);
571+
coap_service_unregister_uri(this->coap_service_id, THREAD_URI_DIAGNOSTIC_REQUEST);
572+
coap_service_unregister_uri(this->coap_service_id, THREAD_URI_DIAGNOSTIC_RESET);
573+
coap_service_unregister_uri(this->coap_service_id, THREAD_URI_DIAGNOSTIC_QUERY);
572574
ns_list_remove(&instance_list, this);
573575
ns_dyn_mem_free(this);
574576
return 0;

source/6LoWPAN/Thread/thread_extension.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ void thread_extension_addr_ntf_send(struct protocol_interface_info_entry *cur, u
342342
ptr = thread_tmfcop_tlv_data_write(ptr, TMFCOP_TLV_TARGET_EID, 16, addr_data_ptr);
343343
ptr = thread_tmfcop_tlv_data_write_uint8(ptr, TMFCOP_TLV_STATUS, bbr_status);
344344

345-
coap_service_request_send(thread_management_client_service_id_get(cur->id), COAP_REQUEST_OPTIONS_ADDRESS_SHORT,
345+
coap_service_request_send(thread_management_server_service_id_get(cur->id), COAP_REQUEST_OPTIONS_ADDRESS_SHORT,
346346
destination_address, THREAD_MANAGEMENT_PORT,
347347
COAP_MSG_TYPE_NON_CONFIRMABLE, COAP_MSG_CODE_REQUEST_POST,
348348
THREAD_URI_BBR_DOMAIN_ADDRESS_NOTIFICATION, COAP_CT_OCTET_STREAM,
@@ -475,7 +475,7 @@ static void thread_extension_dua_registration_send(protocol_interface_info_entry
475475
ptr = thread_tmfcop_tlv_data_write(ptr, TMFCOP_TLV_TARGET_EID, 16, address);
476476
ptr = thread_tmfcop_tlv_data_write(ptr, TMFCOP_TLV_ML_EID, 8, ml_eid);
477477

478-
coap_service_request_send(thread_management_client_service_id_get(cur->id), COAP_REQUEST_OPTIONS_NONE,
478+
coap_service_request_send(thread_management_server_service_id_get(cur->id), COAP_REQUEST_OPTIONS_NONE,
479479
dst_addr, THREAD_MANAGEMENT_PORT,
480480
COAP_MSG_TYPE_CONFIRMABLE, COAP_MSG_CODE_REQUEST_POST,
481481
THREAD_URI_BBR_DOMAIN_ADDRESS_REGISTRATION, COAP_CT_OCTET_STREAM,
@@ -516,7 +516,7 @@ void thread_extension_init(int8_t interface_id, int8_t coap_service_id)
516516

517517
void thread_extension_mtd_service_register(protocol_interface_info_entry_t *cur)
518518
{
519-
coap_service_register_uri(thread_management_client_service_id_get(cur->id), THREAD_URI_BBR_DOMAIN_ADDRESS_NOTIFICATION, COAP_SERVICE_ACCESS_POST_ALLOWED, thread_extension_mtd_dua_ntf_cb);
519+
coap_service_register_uri(thread_management_server_service_id_get(cur->id), THREAD_URI_BBR_DOMAIN_ADDRESS_NOTIFICATION, COAP_SERVICE_ACCESS_POST_ALLOWED, thread_extension_mtd_dua_ntf_cb);
520520
}
521521

522522
static int thread_extension_mlr_req_send(protocol_interface_info_entry_t *cur, const uint8_t br_addr[16], const uint8_t *address, uint8_t address_len)
@@ -527,7 +527,7 @@ static int thread_extension_mlr_req_send(protocol_interface_info_entry_t *cur, c
527527
}
528528
tr_debug("thread MLR.req send");
529529

530-
coap_service_request_send(thread_management_client_service_id_get(cur->id), COAP_REQUEST_OPTIONS_NONE, br_addr, THREAD_MANAGEMENT_PORT,
530+
coap_service_request_send(thread_management_server_service_id_get(cur->id), COAP_REQUEST_OPTIONS_NONE, br_addr, THREAD_MANAGEMENT_PORT,
531531
COAP_MSG_TYPE_CONFIRMABLE, COAP_MSG_CODE_REQUEST_POST, THREAD_URI_BBR_MCAST_LISTENER_REPORT, COAP_CT_OCTET_STREAM, address, address_len, thread_comercial_mlr_cb);
532532
return 0;
533533
}

source/6LoWPAN/Thread/thread_extension_bbr.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,5 +1455,12 @@ int thread_extension_bbr_sequence_number_set(int8_t interface_id, uint8_t seq_nu
14551455
return 0;
14561456
}
14571457

1458+
void thread_extension_bbr_old_partition_data_clean(int8_t interface_id)
1459+
{
1460+
thread_pbbr_t *this = thread_bbr_find_by_interface(interface_id);
1461+
if (this) {
1462+
coap_service_request_delete_by_service_id(this->coap_service_id);
1463+
}
1464+
}
14581465

14591466
#endif //HAVE_THREAD_BORDER_ROUTER && HAVE_THREAD_V2

source/6LoWPAN/Thread/thread_extension_bbr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ int thread_extension_bbr_timeout_set(int8_t interface_id, uint32_t timeout_a, ui
5757
int thread_extension_bbr_address_set(int8_t interface_id, const uint8_t *addr_ptr, uint16_t port);
5858
void thread_extension_bbr_route_update(protocol_interface_info_entry_t *cur);
5959
int thread_extension_bbr_prefix_set(int8_t interface_id, uint8_t *prefix);
60+
void thread_extension_bbr_old_partition_data_clean(int8_t interface_id);
6061

6162

6263
#else
@@ -70,6 +71,7 @@ int thread_extension_bbr_prefix_set(int8_t interface_id, uint8_t *prefix);
7071
#define thread_extension_bbr_route_update(cur)
7172
#define thread_extension_bbr_sequence_number_set(interface_id, seq_number) (-1)
7273
#define thread_extension_bbr_prefix_set(interface_id, prefix) 0
74+
#define thread_extension_bbr_old_partition_data_clean(interface_id)
7375
#endif
7476

7577
#ifdef __cplusplus

0 commit comments

Comments
 (0)