@@ -80,7 +80,6 @@ typedef struct {
80
80
int8_t interface_id ;
81
81
int8_t coap_service_id ;
82
82
int8_t coap_nmkp_virtual_service_id ;
83
- int8_t br_service_id ;
84
83
int8_t backbone_interface_id ;
85
84
int8_t br_bb_service_id ;
86
85
bool pbbr_started :1 ;
@@ -146,7 +145,7 @@ static thread_pbbr_t *thread_border_router_find_by_service(int8_t service_id)
146
145
{
147
146
thread_pbbr_t * this = NULL ;
148
147
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 ||
150
149
cur_br -> br_bb_service_id == service_id || cur_br -> coap_nmkp_virtual_service_id == service_id ) {
151
150
this = cur_br ;
152
151
break ;
@@ -547,17 +546,17 @@ static int thread_pbbr_bb_ans_cb(int8_t service_id, uint8_t source_address[16],
547
546
// If delayed DUA registration entry is present send duplicate error code to DUA.response
548
547
return 0 ;
549
548
}
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 )
551
550
{
552
551
uint8_t payload [2 + 16 + 2 + 4 + 2 ];
553
552
uint8_t * ptr ;
554
553
555
- if (!br_addr || !address ) {
554
+ if (!br_addr || !address_ptr ) {
556
555
return -1 ;
557
556
}
558
557
559
558
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 );
561
560
ptr = thread_meshcop_tlv_data_write_uint32 (ptr , TMFCOP_TLV_TIMEOUT , timeout );
562
561
563
562
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
573
572
(void )source_port ;
574
573
575
574
uint16_t addr_len ;
575
+ uint16_t session_id ;
576
576
uint8_t * addr_data_ptr ;
577
577
uint32_t timeout_value ;
578
578
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
595
595
timeout_value = this -> mlr_timeout ;
596
596
597
597
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);
600
598
601
599
// check if we are not primary bbr respond status 5
602
600
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
605
603
bbr_status = THREAD_BBR_STATUS_NOT_PRIMARY_BBR ;
606
604
goto send_response ;
607
605
}
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
+ }
608
620
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
611
624
tr_err ("Invalid /n/mr message" );
612
625
response_code = COAP_MSG_CODE_RESPONSE_BAD_REQUEST ;
613
626
goto send_response ;
614
627
}
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
+ }
620
642
621
643
// 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 );
623
645
624
646
send_response :
625
647
0 commit comments