Send 4.04 if URI is not found (#34)

If coap service library receives confirmable request to URI that is not
registered, it must send response COAP_MSG_CODE_RESPONSE_NOT_FOUND.
pull/3240/head
Tero Heinonen 2016-10-04 09:42:29 +03:00 committed by GitHub
parent 301458ae8d
commit 0e4af1a4d2
3 changed files with 24 additions and 8 deletions

View File

@ -4,6 +4,7 @@
#include <string.h>
#include "nsdynmemLIB.h"
#include "coap_service_api_internal.h"
#include "coap_message_handler.h"
#include "sn_coap_protocol.h"
#include "ns_types.h"
@ -202,13 +203,11 @@ int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t
sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, coap_message);
return -1;
}
/* Request received */
if (coap_message->msg_code > 0 && coap_message->msg_code < 32) {
//TODO Sorry
coap_transaction_t *transaction_ptr = transaction_create();
if (transaction_ptr) {
transaction_ptr->service_id = coap_service_id_find_by_socket(socket_id);
transaction_ptr->msg_id = coap_message->msg_id;
transaction_ptr->client_request = false;// this is server transaction
memcpy(transaction_ptr->remote_address, source_addr_ptr, 16);
@ -224,8 +223,8 @@ int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t
}else{
//TODO: handle error case
}
/* Response received */
} else {
//response find by MSG id
coap_transaction_t *this = NULL;
if( coap_message->token_ptr ){
this = transaction_find_client_by_token(coap_message->token_ptr);
@ -242,6 +241,7 @@ int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t
sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, coap_message);
transaction_delete(this);
}
return 0;
}

View File

@ -21,6 +21,7 @@
#include "coap_connection_handler.h"
#include "net_interface.h"
#include "coap_service_api_internal.h"
#include "coap_message_handler.h"
static int16_t coap_service_coap_msg_process(int8_t socket_id, uint8_t source_addr_ptr[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len);
static int16_t coap_msg_process_callback(int8_t socket_id, sn_coap_hdr_s *coap_message, coap_transaction_t *transaction_ptr);
@ -130,7 +131,7 @@ static uint8_t coap_tx_function(uint8_t *data_ptr, uint16_t data_len, sn_nsdl_ad
return -1;
}
tr_debug("Service %d, CoAP TX Function", transaction_ptr->service_id);
tr_debug("Service %d, CoAP TX Function - mid: %d", transaction_ptr->service_id, common_read_16_bit(data_ptr + 2));
this = service_find(transaction_ptr->service_id);
if (!this) {
@ -176,10 +177,16 @@ static int16_t coap_msg_process_callback(int8_t socket_id, sn_coap_hdr_s *coap_m
if( !coap_message ){
return -1;
}
// Message is request find correct handle
// Message is request, find correct handle
this = service_find_by_uri(socket_id, coap_message->uri_path_ptr, coap_message->uri_path_len);
if (!this) {
tr_warn("not registered uri %.*s", coap_message->uri_path_len, coap_message->uri_path_ptr);
tr_debug("not registered uri %.*s", coap_message->uri_path_len, coap_message->uri_path_ptr);
if (coap_message->msg_type == COAP_MSG_TYPE_CONFIRMABLE) {
coap_message_handler_response_send(coap_service_handle, transaction_ptr->service_id, COAP_SERVICE_OPTIONS_NONE, coap_message,
COAP_MSG_CODE_RESPONSE_NOT_FOUND, COAP_CT_NONE, NULL, 0);
return 0;
}
return -1;
}
@ -471,3 +478,10 @@ uint32_t coap_service_get_internal_timer_ticks(void)
{
return coap_ticks;
}
uint16_t coap_service_id_find_by_socket(int8_t socket_id)
{
coap_service_t *this = service_find_by_socket(socket_id);
return this ? this->service_id:0;
}

View File

@ -22,4 +22,6 @@
uint32_t coap_service_get_internal_timer_ticks(void);
uint16_t coap_service_id_find_by_socket(int8_t socket_id);
#endif