diff --git a/sys/include/net/nanocoap.h b/sys/include/net/nanocoap.h index 1d9be7a6f143..c6af7e96d1b7 100644 --- a/sys/include/net/nanocoap.h +++ b/sys/include/net/nanocoap.h @@ -230,13 +230,6 @@ typedef struct { BITFIELD(opt_crit, CONFIG_NANOCOAP_NOPTS_MAX); /**< unhandled critical option */ #ifdef MODULE_GCOAP uint32_t observe_value; /**< observe value */ - /** - * @brief transport the packet was received over - * @see @ref gcoap_socket_type_t for values. - * @note @ref gcoap_socket_type_t can not be used, as this would - * cyclically include the @ref net_gcoap header. - */ - uint32_t tl_type; #endif } coap_pkt_t; @@ -344,6 +337,16 @@ const char *coap_request_ctx_get_path(const coap_request_ctx_t *ctx); */ void *coap_request_ctx_get_context(const coap_request_ctx_t *ctx); +/** + * @brief Get transport the packet was received over + * @see @ref gcoap_socket_type_t for values. + * + * @param[in] ctx The request context + * + * @return Transport Layer type of the request + */ +uint32_t coap_request_ctx_get_tl_type(const coap_request_ctx_t *ctx); + /** * @brief Block1 helper struct */ diff --git a/sys/net/application_layer/gcoap/gcoap.c b/sys/net/application_layer/gcoap/gcoap.c index c6fa2e4f1090..5995c0a4f224 100644 --- a/sys/net/application_layer/gcoap/gcoap.c +++ b/sys/net/application_layer/gcoap/gcoap.c @@ -684,13 +684,12 @@ static size_t _handle_req(gcoap_socket_t *sock, coap_pkt_t *pdu, uint8_t *buf, return -1; } - pdu->tl_type = (uint32_t)sock->type; - ssize_t pdu_len; char *offset; coap_request_ctx_t ctx = { .resource = resource, + .tl_type = (uint32_t)sock->type, }; if (coap_get_proxy_uri(pdu, &offset) > 0) { @@ -899,7 +898,7 @@ static ssize_t _well_known_core_handler(coap_pkt_t* pdu, uint8_t *buf, size_t le plen += gcoap_get_resource_list_tl(pdu->payload, (size_t)pdu->payload_len, COAP_FORMAT_LINK, - (gcoap_socket_type_t)pdu->tl_type); + (gcoap_socket_type_t)coap_request_ctx_get_tl_type(ctx)); return plen; } diff --git a/sys/net/application_layer/nanocoap/nanocoap.c b/sys/net/application_layer/nanocoap/nanocoap.c index f3cb7741bdfc..ea96670c4e38 100644 --- a/sys/net/application_layer/nanocoap/nanocoap.c +++ b/sys/net/application_layer/nanocoap/nanocoap.c @@ -1246,3 +1246,13 @@ void *coap_request_ctx_get_context(const coap_request_ctx_t *ctx) { return ctx->context; } + +uint32_t coap_request_ctx_get_tl_type(const coap_request_ctx_t *ctx) +{ +#ifdef MODULE_GCOAP + return ctx->tl_type; +#else + (void)ctx; + return 0; +#endif +} diff --git a/sys/net/application_layer/nanocoap/nanocoap_internal.h b/sys/net/application_layer/nanocoap/nanocoap_internal.h index 04922e152a7a..e858d890ee70 100644 --- a/sys/net/application_layer/nanocoap/nanocoap_internal.h +++ b/sys/net/application_layer/nanocoap/nanocoap_internal.h @@ -32,6 +32,15 @@ struct _coap_request_ctx { const coap_resource_t *resource; /**< resource of the request */ void *context; /**< request context, needed to supply the remote for the forward proxy */ +#if defined(MODULE_GCOAP) || DOXYGEN + /** + * @brief transport the packet was received over + * @see @ref gcoap_socket_type_t for values. + * @note @ref gcoap_socket_type_t can not be used, as this would + * cyclically include the @ref net_gcoap header. + */ + uint32_t tl_type; +#endif }; #ifdef __cplusplus