From 655e84c040caa9b148870173f0342f1616cd8f78 Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Wed, 16 Mar 2016 11:34:44 +0100 Subject: [PATCH] net.[hc]: Changed interface for coap_handle_message() The local endpoint object, peer address and data buffer address and length now are passed as arguments to coap_handle_message(). This change reverts a previous attempt to provide a more concise interface for this function that hides the actual implementation-specific data. As the DTLS implementation needs to deal with this implementation- specific parts, it has to be made explicit, either by making the packet abstraction public or passing the relevant parameters explicitely to coap_handle_message(). As this has worked smoothly before, this approach has been taken. This change breaks the LWIP implementation (for now). It will be fixed when integrating the DTLS code with LWIP in this branch. --- include/coap/net.h | 4 +++- src/net.c | 38 +++++++++++++------------------------- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/include/coap/net.h b/include/coap/net.h index fbc432b3..5fe5fabe 100644 --- a/include/coap/net.h +++ b/include/coap/net.h @@ -392,7 +392,9 @@ int coap_read(coap_context_t *context); * error. */ int coap_handle_message(coap_context_t *ctx, - coap_packet_t *packet); + const coap_endpoint_t *local_interface, + const coap_address_t *remote, + unsigned char *msg, size_t msg_len); /** * Calculates a unique transaction id from given arguments @p peer and @p pdu. diff --git a/src/net.c b/src/net.c index cbcbc8fb..56041d9e 100644 --- a/src/net.c +++ b/src/net.c @@ -664,7 +664,6 @@ coap_send(coap_context_t *context, } } finish: - coap_dtls_free_session(session); return id; } @@ -889,25 +888,18 @@ coap_read_endpoint(coap_context_t *ctx, coap_endpoint_t *endpoint) { warn("coap_read: recvfrom"); } else { if (bytes_read > 0) { + unsigned char *data; + size_t data_len; + coap_address_t remote; + + coap_packet_get_memmapped(packet, &data, &data_len); + coap_packet_copy_source(packet, &remote); + if (is_dtls(endpoint)) { - unsigned char *data; - size_t data_len; - coap_address_t remote; - - coap_packet_get_memmapped(packet, &data, &data_len); - coap_packet_copy_source(packet, &remote); - - { - unsigned char buf[200]; - size_t s = coap_print_addr(&remote, buf, sizeof(buf)); - coap_log(LOG_DEBUG, "#### %.*s\n", s, buf); - } result = coap_dtls_handle_message(ctx, endpoint, &remote, data, data_len); } else { - result = coap_handle_message(ctx, packet); + result = coap_handle_message(ctx, endpoint, &remote, data, data_len); } - } else { - debug("##### no data ######\n"); } } @@ -934,19 +926,15 @@ coap_read(coap_context_t *ctx) { int coap_handle_message(coap_context_t *ctx, - coap_packet_t *packet) { - /* const coap_address_t *remote, */ - /* unsigned char *msg, size_t msg_len) { */ - unsigned char *msg; - size_t msg_len; + const coap_endpoint_t *local_interface, + const coap_address_t *remote, + unsigned char *msg, size_t msg_len) { coap_queue_t *node; /* the negated result code */ enum result_t { RESULT_OK, RESULT_ERR_EARLY, RESULT_ERR }; int result = RESULT_ERR_EARLY; - coap_packet_get_memmapped(packet, &msg, &msg_len); - if (msg_len < sizeof(coap_hdr_t)) { debug("coap_handle_message: discarded invalid frame\n" ); goto error_early; @@ -982,8 +970,8 @@ coap_handle_message(coap_context_t *ctx, coap_ticks(&node->t); - coap_packet_populate_endpoint(packet, &node->local_if); - coap_packet_copy_source(packet, &node->remote); + node->local_if = *local_interface; + node->remote = *remote; /* and add new node to receive queue */ coap_transaction_id(&node->remote, node->pdu, &node->id);