From c941fe6242e1a9bda9d2ae841dd3a6105a04aa13 Mon Sep 17 00:00:00 2001 From: Arto Kinnunen Date: Wed, 31 Oct 2018 10:26:57 +0200 Subject: [PATCH] Adjust COAP callback return values (#1886) Return -1 when COAP service does not need to send response and transaction can be deleted. --- source/6LoWPAN/Thread/thread_extension_bbr.c | 27 +++++++++----------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/source/6LoWPAN/Thread/thread_extension_bbr.c b/source/6LoWPAN/Thread/thread_extension_bbr.c index 4cfa393cefb..5706c043361 100644 --- a/source/6LoWPAN/Thread/thread_extension_bbr.c +++ b/source/6LoWPAN/Thread/thread_extension_bbr.c @@ -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; } @@ -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; @@ -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); @@ -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) @@ -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)) { @@ -463,7 +462,7 @@ 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); @@ -471,7 +470,7 @@ static int thread_pbbr_nmkp_req_recv_cb(int8_t service_id, uint8_t source_addres 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); @@ -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; @@ -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) @@ -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 @@ -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);