@@ -82,20 +82,77 @@ typedef struct thread_extension_info {
82
82
bool update_needed :1 ;
83
83
} thread_extension_info_t ;
84
84
85
+ #ifdef HAVE_THREAD_ROUTER
86
+ static int thread_extension_joiner_router_init (protocol_interface_info_entry_t * cur );
87
+ #else
88
+ #define thread_extension_joiner_router_init (cur )
89
+ #endif
85
90
86
91
static int thread_extension_dua_registration_cb (int8_t service_id , uint8_t source_address [static 16 ], uint16_t source_port , sn_coap_hdr_s * response_ptr )
87
92
{
88
- (void ) service_id ;
89
93
(void ) source_address ;
90
94
(void ) source_port ;
91
- (void ) response_ptr ;
95
+
96
+ uint16_t addr_len ;
97
+ uint8_t * bbr_status ;
98
+ uint8_t * addr_data_ptr = NULL ;
99
+
100
+ protocol_interface_info_entry_t * cur = protocol_stack_interface_info_get_by_id (thread_management_client_get_interface_id_by_service_id (service_id ));
101
+
102
+ if (!cur ) {
103
+ return -1 ;
104
+ }
92
105
93
106
if (!response_ptr ) {
94
107
tr_warn ("DUA.resp failed" );
108
+ return -2 ;
109
+ }
110
+
111
+ if (1 > thread_meshcop_tlv_find (response_ptr -> payload_ptr , response_ptr -> payload_len , TMFCOP_TLV_STATUS , & bbr_status )) {
112
+ return -3 ;
113
+ }
114
+
115
+ if (* bbr_status == 0 ) {
116
+ // registration successful
117
+ return 0 ;
118
+ }
119
+
120
+ addr_len = thread_meshcop_tlv_find (response_ptr -> payload_ptr , response_ptr -> payload_len , TMFCOP_TLV_TARGET_EID , & addr_data_ptr );
121
+
122
+ if (addr_len < 16 ) {
123
+ tr_warn ("Invalid target eid in DUA.rsp cb message" );
124
+ return -4 ;
125
+ }
126
+
127
+ // registration unsuccessful
128
+ ipv6_neighbour_t * neighbour_entry ;
129
+ uint16_t nce_short_addr ;
130
+ uint8_t payload [16 + 1 ]; // Target eid + Status
131
+ uint8_t * ptr ;
132
+ uint8_t destination_address [16 ] = {0 };
133
+
134
+ neighbour_entry = ipv6_neighbour_lookup (& cur -> ipv6_neighbour_cache , addr_data_ptr );
135
+ if (!neighbour_entry ) {
95
136
return 0 ;
96
137
}
97
- // TODO update registration information of BBR
98
- // TODO in case of failure Retry the registrations after a certain period;
138
+
139
+ nce_short_addr = common_read_16_bit (neighbour_entry -> ll_address + 2 );
140
+ if (!thread_addr_is_child (cur -> thread_info -> routerShortAddress ,nce_short_addr )) {
141
+ return 0 ;
142
+ }
143
+ thread_addr_write_mesh_local_16 (destination_address , nce_short_addr , cur -> thread_info );
144
+
145
+ ptr = payload ;
146
+ ptr = thread_tmfcop_tlv_data_write (ptr , TMFCOP_TLV_TARGET_EID , 16 , addr_data_ptr );
147
+ ptr = thread_tmfcop_tlv_data_write_uint8 (ptr , TMFCOP_TLV_STATUS , * bbr_status );
148
+
149
+ coap_service_request_send (service_id , COAP_REQUEST_OPTIONS_ADDRESS_SHORT ,
150
+ destination_address , THREAD_MANAGEMENT_PORT ,
151
+ COAP_MSG_TYPE_NON_CONFIRMABLE , COAP_MSG_CODE_REQUEST_POST ,
152
+ THREAD_URI_BBR_DOMAIN_ADDRESS_NOTIFICATION , COAP_CT_OCTET_STREAM ,
153
+ payload , ptr - payload , NULL );
154
+
155
+ ipv6_neighbour_entry_remove (& cur -> ipv6_neighbour_cache , neighbour_entry );
99
156
100
157
return 0 ;
101
158
}
@@ -111,6 +168,17 @@ static int thread_comercial_mlr_cb(int8_t service_id, uint8_t source_address[sta
111
168
return 0 ;
112
169
}
113
170
171
+ static int thread_extension_mtd_dua_ntf_cb (int8_t service_id , uint8_t source_address [static 16 ], uint16_t source_port , sn_coap_hdr_s * response_ptr )
172
+ {
173
+ (void ) service_id ;
174
+ (void ) source_address ;
175
+ (void ) source_port ;
176
+ (void ) response_ptr ;
177
+
178
+ tr_debug ("Thread MTD n/dn callback" );
179
+
180
+ return 0 ;
181
+ }
114
182
115
183
static int thread_extension_primary_bbr_update_needed (struct protocol_interface_info_entry * cur , uint16_t rloc , uint8_t seq )
116
184
{
@@ -330,6 +398,11 @@ void thread_extension_init(int8_t interface_id, int8_t coap_service_id)
330
398
cur -> thread_info -> extension_info -> coap_service_id = coap_service_id ;
331
399
}
332
400
401
+ void thread_extension_mtd_service_register (protocol_interface_info_entry_t * cur )
402
+ {
403
+ 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 );
404
+ }
405
+
333
406
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 )
334
407
{
335
408
@@ -647,6 +720,22 @@ void thread_extension_discover_response_tlv_write(uint16_t *data, uint8_t versio
647
720
}
648
721
}
649
722
723
+ int thread_extension_service_init (protocol_interface_info_entry_t * cur )
724
+ {
725
+ if (!cur -> thread_info -> extension_info || !cur -> thread_info -> extension_info -> coap_service_id ) {
726
+ return -1 ;
727
+ }
728
+
729
+ if (cur -> thread_info -> thread_device_mode == THREAD_DEVICE_MODE_END_DEVICE ||
730
+ cur -> thread_info -> thread_device_mode == THREAD_DEVICE_MODE_SLEEPY_END_DEVICE ) {
731
+ thread_extension_mtd_service_register (cur );
732
+ } else if (cur -> thread_info -> thread_device_mode == THREAD_DEVICE_MODE_ROUTER ) {
733
+ thread_extension_joiner_router_init (cur );
734
+ }
735
+
736
+ return 0 ;
737
+ }
738
+
650
739
#ifdef HAVE_THREAD_ROUTER
651
740
static int thread_extension_relay_tx_cb (int8_t service_id , uint8_t source_address [16 ], uint16_t source_port , sn_coap_hdr_s * request_ptr )
652
741
{
@@ -772,12 +861,11 @@ static void thread_extension_joiner_router_deinit(protocol_interface_info_entry_
772
861
return ;
773
862
}
774
863
775
- int thread_extension_joiner_router_init (int8_t interface_id )
864
+ static int thread_extension_joiner_router_init (protocol_interface_info_entry_t * cur )
776
865
{
777
- protocol_interface_info_entry_t * cur = protocol_stack_interface_info_get_by_id (interface_id );
778
866
int8_t securityLinkLayer = 0 ;
779
867
780
- if (!cur || ! cur -> thread_info -> extension_info ) {
868
+ if (!cur -> thread_info -> extension_info ) {
781
869
return -1 ;
782
870
}
783
871
0 commit comments