Skip to content

Commit

Permalink
address entry removal updated (ARMmbed#2013)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakvenugopal authored Mar 15, 2019
1 parent a8e3e73 commit 5fa004c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
42 changes: 27 additions & 15 deletions source/6LoWPAN/Thread/thread_extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static int thread_extension_dua_registration_cb(int8_t service_id, uint8_t sourc
(void) source_port;

uint16_t addr_len;
uint8_t *bbr_status;
uint8_t bbr_status;
uint8_t *addr_data_ptr = NULL;

protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(thread_management_client_get_interface_id_by_service_id(service_id));
Expand All @@ -112,28 +112,30 @@ static int thread_extension_dua_registration_cb(int8_t service_id, uint8_t sourc
return -2;
}

if (1 > thread_meshcop_tlv_find(response_ptr->payload_ptr, response_ptr->payload_len, TMFCOP_TLV_STATUS, &bbr_status)) {
return -3;
}

if (*bbr_status == 0) {
// registration successful
if (1 > thread_meshcop_tlv_data_get_uint8(response_ptr->payload_ptr, response_ptr->payload_len, TMFCOP_TLV_STATUS, &bbr_status)) {
return 0;
}

addr_len = thread_meshcop_tlv_find(response_ptr->payload_ptr, response_ptr->payload_len, TMFCOP_TLV_TARGET_EID, &addr_data_ptr);

if (addr_len < 16) {
tr_warn("Invalid target eid in DUA.rsp cb message");
return -4;
return 0;
}

// registration unsuccessful
// processing for ourselves - if we have the address re register
if_address_entry_t *addr_entry = addr_get_entry(cur, addr_data_ptr);
if (addr_entry) {
cur->dad_failures++;
thread_extension_dua_address_generate(cur, addr_data_ptr, 64);
// Own processing
if (bbr_status == THREAD_EXTENSION_ST_DUA_SUCCESS) {
addr_entry->preferred_lifetime = 0xffffffff;
} else if (bbr_status == THREAD_EXTENSION_ST_DUA_DUPLICATE) {
cur->dad_failures++;
thread_extension_dua_address_generate(cur, addr_data_ptr, 64);
} else if (bbr_status == THREAD_EXTENSION_ST_DUA_INVALID) {
addr_delete(cur, addr_data_ptr);
} else {
addr_entry->preferred_lifetime = 0;
}
return 0;
}

Expand All @@ -142,20 +144,30 @@ static int thread_extension_dua_registration_cb(int8_t service_id, uint8_t sourc
uint16_t nce_short_addr;
uint8_t destination_address[16] = {0};

if (bbr_status == THREAD_EXTENSION_ST_DUA_SUCCESS) {
// registration successful
return 0;
}

neighbour_entry = ipv6_neighbour_lookup(&cur->ipv6_neighbour_cache, addr_data_ptr);
if (!neighbour_entry) {
return 0;
}

nce_short_addr = common_read_16_bit(neighbour_entry->ll_address + 2);
if (!thread_addr_is_child(cur->thread_info->routerShortAddress, nce_short_addr)) {
ipv6_neighbour_entry_remove(&cur->ipv6_neighbour_cache, neighbour_entry);
return 0;
}
thread_addr_write_mesh_local_16(destination_address, nce_short_addr, cur->thread_info);

thread_extension_addr_ntf_send(cur, destination_address, addr_data_ptr, *bbr_status);
if (bbr_status == THREAD_EXTENSION_ST_DUA_DUPLICATE || bbr_status == THREAD_EXTENSION_ST_DUA_INVALID) {
// remove invalid or duplicate child entry
ipv6_neighbour_entry_remove(&cur->ipv6_neighbour_cache, neighbour_entry);
}

thread_addr_write_mesh_local_16(destination_address, nce_short_addr, cur->thread_info);

ipv6_neighbour_entry_remove(&cur->ipv6_neighbour_cache, neighbour_entry);
thread_extension_addr_ntf_send(cur, destination_address, addr_data_ptr, bbr_status);

return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions source/6LoWPAN/Thread/thread_extension_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ typedef struct discovery_additional_info {
*/

#define THREAD_EXTENSION_ST_DUA_SUCCESS 0
#define THREAD_EXTENSION_ST_DUA_INVALID 2
#define THREAD_EXTENSION_ST_DUA_DUPLICATE 3
#define THREAD_EXTENSION_ST_DUA_INVALID 2 //Fatal
#define THREAD_EXTENSION_ST_DUA_DUPLICATE 3 //Fatal
#define THREAD_EXTENSION_ST_DUA_NO_RESOURCES 4
#define THREAD_EXTENSION_ST_DUA_BBR_NOT_PRIMARY 5
#define THREAD_EXTENSION_ST_DUA_GENERAL_FAILURE 6
Expand Down

0 comments on commit 5fa004c

Please sign in to comment.