Skip to content

Commit

Permalink
Adjust COAP callback return values (ARMmbed#1886)
Browse files Browse the repository at this point in the history
Return -1 when COAP service does not need to send response and
transaction can be deleted.
  • Loading branch information
Arto Kinnunen authored Oct 31, 2018
1 parent 7ef4775 commit c941fe6
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions source/6LoWPAN/Thread/thread_extension_bbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ static duplicate_dua_tr_t *thread_border_router_dup_tr_create(int8_t interface_i

static void thread_border_router_dup_tr_delete(duplicate_dua_tr_t *this)
{

if (!this) {
return;
}
Expand Down Expand Up @@ -209,7 +208,7 @@ static duplicate_dua_tr_t *thread_border_router_dup_tr_find(int8_t interface_id,
* DUA Registration Sequence Number TLV
* Network Name TLV
*/
static void thread_border_router_bb_ans_send(thread_pbbr_t *this, uint8_t *destination_addr_ptr, uint8_t *target_eid_ptr, uint8_t *ml_eid_ptr, uint32_t last_transaction_time, uint8_t *network_name_ptr, uint16_t *rloc_ptr)
static int thread_border_router_bb_ans_send(thread_pbbr_t *this, uint8_t *destination_addr_ptr, uint8_t *target_eid_ptr, uint8_t *ml_eid_ptr, uint32_t last_transaction_time, uint8_t *network_name_ptr, uint16_t *rloc_ptr)
{
uint8_t *payload_ptr, *ptr;
sn_coap_msg_type_e coap_msg_type = COAP_MSG_TYPE_CONFIRMABLE;
Expand All @@ -219,7 +218,7 @@ static void thread_border_router_bb_ans_send(thread_pbbr_t *this, uint8_t *desti
payload_ptr = ptr = ns_dyn_mem_alloc(64);
if (!payload_ptr) {
tr_error("BB_ANS.ntf alloc failed!");
return;
return -1;
}

ptr = thread_meshcop_tlv_data_write(ptr, TMFCOP_TLV_TARGET_EID, 16, target_eid_ptr);
Expand All @@ -239,7 +238,7 @@ static void thread_border_router_bb_ans_send(thread_pbbr_t *this, uint8_t *desti

ns_dyn_mem_free(payload_ptr);

return;
return 0;
}

static void thread_border_router_bb_qry_send(thread_pbbr_t *this, const uint8_t *target_eid_ptr, uint16_t *rloc_ptr)
Expand Down Expand Up @@ -331,7 +330,7 @@ static int thread_pbbr_data_req_recv_cb(int8_t service_id, uint8_t source_addres

if (0 == request_tlv_len) {
//error handling
return 0;
return -1;
}

if (thread_meshcop_tlv_list_type_available(request_tlv_ptr, request_tlv_len, MESHCOP_TLV_REGISTRAR_IPV6_ADDRESS)) {
Expand Down Expand Up @@ -463,15 +462,15 @@ static int thread_pbbr_nmkp_req_recv_cb(int8_t service_id, uint8_t source_addres
}
cur = protocol_stack_interface_info_get_by_id(this->interface_id);
if (!cur) {
return 0;
return -1;
}
len = 3 + 10; // state,timestamp
len += thread_joiner_application_active_config_length(this->interface_id,NULL,0,NULL,0);
// TODO implement processing
payload_ptr = ns_dyn_mem_temporary_alloc(len);
if (!payload_ptr) {
tr_error("out of resources");
return 0;
return -1;
}
ptr = payload_ptr;
ptr = thread_meshcop_tlv_data_write_uint8(ptr, MESHCOP_TLV_STATE, 1);
Expand Down Expand Up @@ -510,18 +509,18 @@ static int thread_pbbr_bb_qry_cb(int8_t service_id, uint8_t source_address[16],
}
if (addr_interface_address_compare(backbone_if, source_address) == 0) {
// Received from own address no need to process
return 0;
return -1;
}

addr_len = thread_meshcop_tlv_find(request_ptr->payload_ptr, request_ptr->payload_len, TMFCOP_TLV_TARGET_EID, &addr_data_ptr);
if (addr_len < 16) {
tr_warn("Invalid BB_QRY.ntf message");
return 0;
return -1;
}
ipv6_route_t *route = ipv6_route_choose_next_hop(addr_data_ptr, this->interface_id, NULL);
if (!route || route->prefix_len < 128 || !route->on_link || route->info.source != ROUTE_THREAD_PROXIED_DUA_HOST || !route->info.info) {
//address not in mesh
return 0;
return -1;
}
if (thread_meshcop_tlv_data_get_uint16(request_ptr->payload_ptr, request_ptr->payload_len, TMFCOP_TLV_RLOC16, &rloc) > 1) {
rloc_ptr = &rloc;
Expand All @@ -531,9 +530,7 @@ static int thread_pbbr_bb_qry_cb(int8_t service_id, uint8_t source_address[16],
uint8_t *ml_eid_ptr = ((thread_pbbr_dua_info_t *)route->info.info)->mleid_ptr;

// This address is valid in our MESH
thread_border_router_bb_ans_send(this, source_address, addr_data_ptr, ml_eid_ptr, last_transaction_time, link_configuration_ptr->name, rloc_ptr);

return 0;
return thread_border_router_bb_ans_send(this, source_address, addr_data_ptr, ml_eid_ptr, last_transaction_time, link_configuration_ptr->name, rloc_ptr);
}

static void thread_pbbr_pro_bb_ntf_process(protocol_interface_info_entry_t *cur, uint8_t* network_name_ptr, uint8_t network_name_len, uint8_t *ml_eid_ptr, uint8_t *addr_data_ptr, uint32_t last_transaction_time)
Expand Down Expand Up @@ -593,7 +590,7 @@ static int thread_pbbr_dua_duplicate_address_detection(int8_t service_id, uint8_
if (!route || route->prefix_len != 128 || !route->on_link || route->info.source != ROUTE_THREAD_PROXIED_DUA_HOST) {
// Not found
tr_debug("route not found");
return 0;
return -1;
}

// We have pending request and received answer
Expand Down Expand Up @@ -641,7 +638,7 @@ static int thread_pbbr_bb_ans_cb(int8_t service_id, uint8_t source_address[16],
}
if (addr_interface_address_compare(backbone_if, source_address) == 0) {
// Received from own address no need to process
return 0;
return -1;
}
addr_len = thread_meshcop_tlv_find(request_ptr->payload_ptr, request_ptr->payload_len, TMFCOP_TLV_TARGET_EID, &addr_data_ptr);
ml_eid_len = thread_meshcop_tlv_find(request_ptr->payload_ptr, request_ptr->payload_len, TMFCOP_TLV_ML_EID, &ml_eid_ptr);
Expand Down

0 comments on commit c941fe6

Please sign in to comment.