Skip to content

Commit 1444c2f

Browse files
author
Mika Tervonen
committed
Add POC code for storing multicast address
This code is only usable in interop and testing. Full NVM is needed later Add validity check when active that if network data is lost pbbr is reset
1 parent 684efef commit 1444c2f

File tree

1 file changed

+63
-4
lines changed

1 file changed

+63
-4
lines changed

source/6LoWPAN/Thread/thread_extension_bbr.c

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ static NS_LIST_DEFINE(duplicate_dua_tr_list, duplicate_dua_tr_t, link);
124124
#define THREAD_BBR_STATUS_NOT_SPECIFIED 6
125125
#define THREAD_BBR_STATUS_BB_LINK_NOT_OPERATIONAL 7
126126

127+
128+
static void thread_border_router_multicast_store_add(thread_pbbr_t *this, uint8_t *destination_addr_ptr);
129+
static void thread_border_router_multicast_store_del(thread_pbbr_t *this, uint8_t *destination_addr_ptr);
130+
static void thread_border_router_multicast_store_activate(thread_pbbr_t *this);
131+
127132
static int stringlen(const char *s, int n)
128133
{
129134
char *end = memchr(s, 0, n);
@@ -195,7 +200,6 @@ static duplicate_dua_tr_t *thread_border_router_dup_tr_find(int8_t interface_id,
195200
return this;
196201
}
197202

198-
199203
/*
200204
* Target EID TLV
201205
* ML-EID TLV
@@ -652,7 +656,7 @@ static int thread_extension_bbr_bmlr_req_send(int8_t service_id, const uint8_t b
652656
ptr = thread_meshcop_tlv_data_write(ptr, TMFCOP_TLV_IPV6_ADDRESS, addr_len, address_ptr);
653657
ptr = thread_meshcop_tlv_data_write_uint32(ptr, TMFCOP_TLV_TIMEOUT, timeout);
654658

655-
tr_debug("thread BMLR.ntf send; timeout: %"PRIu32, timeout);
659+
tr_debug("thread BMLR.ntf send %s; timeout: %"PRIu32, trace_ipv6(address_ptr), timeout);
656660

657661
coap_service_request_send(service_id, COAP_REQUEST_OPTIONS_NONE, br_addr, THREAD_MANAGEMENT_PORT,
658662
COAP_MSG_TYPE_NON_CONFIRMABLE, COAP_MSG_CODE_REQUEST_POST, THREAD_URI_BBR_BMLR_NTF, COAP_CT_OCTET_STREAM, payload, ptr - payload, NULL);
@@ -732,6 +736,7 @@ static int thread_extension_bbr_mlr_cb(int8_t service_id, uint8_t source_address
732736
while (remaining > 0) {
733737
//Go through all addresses
734738
if (!addr_is_ipv6_multicast(addr_ptr)) {
739+
tr_err("Invalid /n/mr not multicast address");
735740
bbr_status = THREAD_BBR_STATUS_TARGET_EID_NOT_VALID;
736741
if (!invalid_addr_ptr) {
737742
invalid_addr_ptr = addr_ptr;
@@ -741,12 +746,12 @@ static int thread_extension_bbr_mlr_cb(int8_t service_id, uint8_t source_address
741746
//tr_debug("Multicast address: %s delete", trace_ipv6(addr_ptr));
742747
addr_multicast_fwd_remove(cur, addr_ptr);
743748
// TODO remove address from NVM
744-
tr_info("delete multicast address from NVM");
749+
thread_border_router_multicast_store_del(this, addr_ptr);
745750
} else {
746751
//tr_debug("Multicast address: %s Timeout value: %"PRIu32, trace_ipv6(addr_ptr),timeout_value);
747752
multicast_fwd_add(this->interface_id, addr_ptr, timeout_value);
748753
if (timeout_value == 0xffffffff) {
749-
tr_info("Store multicast address to NVM");
754+
thread_border_router_multicast_store_add(this, addr_ptr);
750755
}
751756
// send BMLR.ntf message to backend
752757
thread_extension_bbr_bmlr_req_send(this->br_bb_service_id, this->pbbr_multicast_address, addr_data_ptr, 16, timeout_value);
@@ -892,6 +897,51 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
892897
coap_service_response_send(this->coap_service_id, COAP_REQUEST_OPTIONS_NONE, request_ptr, response_code, COAP_CT_OCTET_STREAM, payload, ptr - payload);
893898
return 0;
894899
}
900+
901+
902+
/*POC for multicast NVM*/
903+
#define MULTICAST_ADDRESS_STORE_AMOUNT 3
904+
905+
typedef struct {
906+
uint8_t addr[16];
907+
} multicast_addr_t;
908+
static multicast_addr_t multicast_store[MULTICAST_ADDRESS_STORE_AMOUNT] = {0};
909+
910+
static void thread_border_router_multicast_store_add(thread_pbbr_t *this, uint8_t *destination_addr_ptr)
911+
{
912+
(void)this;
913+
tr_info("Store multicast address to NVM");
914+
for(int n = 0; n < MULTICAST_ADDRESS_STORE_AMOUNT;n++) {
915+
if (memcmp(multicast_store[n].addr, ADDR_UNSPECIFIED,16) == 0) {
916+
memcpy(multicast_store[n].addr,destination_addr_ptr,16);
917+
break;
918+
}
919+
}
920+
}
921+
922+
static void thread_border_router_multicast_store_del(thread_pbbr_t *this, uint8_t *destination_addr_ptr)
923+
{
924+
(void)this;
925+
tr_info("delete multicast address from NVM");
926+
for(int n = 0; n < MULTICAST_ADDRESS_STORE_AMOUNT;n++) {
927+
if (memcmp(multicast_store[n].addr, destination_addr_ptr,16) == 0) {
928+
memcpy(multicast_store[n].addr,ADDR_UNSPECIFIED,16);
929+
}
930+
}
931+
}
932+
933+
static void thread_border_router_multicast_store_activate(thread_pbbr_t *this)
934+
{
935+
(void)this;
936+
for(int n = 0; n < MULTICAST_ADDRESS_STORE_AMOUNT;n++) {
937+
if (memcmp(multicast_store[n].addr, ADDR_UNSPECIFIED,16) != 0) {
938+
multicast_fwd_add(this->interface_id, multicast_store[n].addr, 0xffffffff);
939+
thread_extension_bbr_bmlr_req_send(this->br_bb_service_id, this->pbbr_multicast_address, multicast_store[n].addr, 16, 0xffffffff);
940+
}
941+
}
942+
}
943+
944+
895945
static bool thread_extension_bbr_downgrade_to_secondary(struct protocol_interface_info_entry *cur)
896946
{
897947
uint16_t rloc16 = mac_helper_mac16_address_get(cur);
@@ -1021,6 +1071,7 @@ static int thread_extension_bbr_pbbr_start(thread_pbbr_t *this)
10211071
// Register Primary BBR backbone multicast address
10221072
multicast_add_address(this->pbbr_multicast_address, false);
10231073
this->pbbr_started = true;
1074+
thread_border_router_multicast_store_activate(this);
10241075

10251076
// Register Backbone commercial features
10261077
coap_service_register_uri(this->br_bb_service_id, THREAD_URI_BBR_BB_QRY_NTF, COAP_SERVICE_ACCESS_POST_ALLOWED, thread_pbbr_bb_qry_cb);
@@ -1237,6 +1288,14 @@ void thread_extension_bbr_seconds_timer(int8_t interface_id, uint32_t seconds)
12371288
tr_info("pbbr downgraded");
12381289
thread_extension_bbr_pbbr_stop(this);
12391290
}
1291+
uint8_t bbr_rloc_addr[16];
1292+
// If there is no pBBR or I am not pBBR reset
1293+
if (0 != thread_extension_primary_bbr_get(cur, bbr_rloc_addr, NULL, NULL, NULL) ||
1294+
!addr_get_entry(cur,bbr_rloc_addr)) {
1295+
tr_info("pbbr stop network data not correct");
1296+
thread_extension_bbr_pbbr_stop(this);
1297+
}
1298+
12401299

12411300
}
12421301
// Check secondary state if we need to drop

0 commit comments

Comments
 (0)