From e2bb8fd523418708202593a4c2b79f4fee39e2c3 Mon Sep 17 00:00:00 2001 From: Matteo Zella Date: Thu, 21 May 2026 04:01:24 +0200 Subject: [PATCH] Expose CoAP processing functions --- src/coap/coapclient.c | 5 ++--- src/coap/coapclient.h | 8 ++++++++ src/coap/coapserver.c | 5 ++--- src/coap/coapserver.h | 8 ++++++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/coap/coapclient.c b/src/coap/coapclient.c index a4c8238..cb7990f 100755 --- a/src/coap/coapclient.c +++ b/src/coap/coapclient.c @@ -39,7 +39,6 @@ static void recv_fn(void*); #endif int write_option( uint8_t *buf, uint16_t buf_len, coap_option_t this_option, coap_option_t *last_option, const uint8_t* option_buf, uint32_t option_len, uint32_t *written_len ); -void process_response(uint8_t* data, uint16_t len, struct sockaddr_in6 *from); void coap_option_map(uint32_t val, uint8_t *map); int coapclient_stop() @@ -264,14 +263,14 @@ static void recv_fn(void* arg) DPRINTF("coapclient.Socket.recvfrom - Got %u-byte response from ",len); osal_print_formatted_ip(&from); - process_response(data, len, &from ); + coapclient_process_response(data, len, &from ); } #if defined(OSAL_LINUX) return NULL; #endif } -void process_response(uint8_t* data, uint16_t len, struct sockaddr_in6 *from) +void coapclient_process_response(uint8_t* data, uint16_t len, struct sockaddr_in6 *from) { uint8_t* cur = data; coap_header_t *hdr; diff --git a/src/coap/coapclient.h b/src/coap/coapclient.h index 154f1c8..b0a003c 100755 --- a/src/coap/coapclient.h +++ b/src/coap/coapclient.h @@ -78,4 +78,12 @@ int coapclient_request(const osal_sockaddr_t *to, const coap_uri_seg_t *query, uint32_t query_cnt, const void *body, uint16_t body_len); +/** + * @brief process a response for the CoAP client + * + * @param data response data + * @param len response data length + * @param from response sender + */ +void coapclient_process_response(uint8_t* data, uint16_t len, struct sockaddr_in6 *from); #endif diff --git a/src/coap/coapserver.c b/src/coap/coapserver.c index 7ee6a1e..da8b3a2 100755 --- a/src/coap/coapserver.c +++ b/src/coap/coapserver.c @@ -33,7 +33,6 @@ static osal_basetype_t m_sockfd = 0; static bool m_server_opened = false; static recv_handler_t m_recv_handler = NULL; -void process_datagram(void *data, uint16_t len, struct sockaddr_in6 *from ); void send_internal_response(const struct sockaddr_in6 *from, uint16_t tx_id, uint8_t token_length, uint8_t *token, uint16_t status); #if defined(OSAL_LINUX) @@ -129,7 +128,7 @@ static void recv_thread(void* arg) ((uint16_t)from.sin6_addr.s6_addr[14] << 8) | from.sin6_addr.s6_addr[15], from.sin6_scope_id, ntohs(from.sin6_port)); - process_datagram(data, len, &from ); + coapserver_process_datagram(data, len, &from ); } #if defined(OSAL_LINUX) return NULL; @@ -207,7 +206,7 @@ int coapserver_response(const struct sockaddr_in6 *to, return 0; } -void process_datagram(void *data, uint16_t len, struct sockaddr_in6 *from ) +void coapserver_process_datagram(uint8_t* data, uint16_t len, struct sockaddr_in6 *from ) { uint8_t* cur = data; uint16_t buf_used = 0; diff --git a/src/coap/coapserver.h b/src/coap/coapserver.h index 4713094..0636d61 100755 --- a/src/coap/coapserver.h +++ b/src/coap/coapserver.h @@ -105,4 +105,12 @@ int coapserver_response(const struct sockaddr_in6 *to, uint16_t status, const void* body, uint16_t body_len); +/** + * @brief process a datagram for the CoAP server + * + * @param data datagram data + * @param len datagram data length + * @param from datagram sender + */ +void coapserver_process_datagram(uint8_t* data, uint16_t len, struct sockaddr_in6 *from); #endif