diff --git a/sys/include/net/nanocoap.h b/sys/include/net/nanocoap.h index 2c3a3a93fa2b..37d39ca6ddfc 100644 --- a/sys/include/net/nanocoap.h +++ b/sys/include/net/nanocoap.h @@ -352,6 +352,10 @@ struct _coap_request_ctx { #endif }; +/* forward declarations */ +static inline uint8_t *coap_hdr_data_ptr(const coap_hdr_t *hdr); +static inline size_t coap_hdr_get_token_len(const coap_hdr_t *hdr); + /** * @brief Get resource path associated with a CoAP request * @@ -548,28 +552,9 @@ static inline unsigned coap_get_id(const coap_pkt_t *pkt) */ static inline unsigned coap_get_token_len(const coap_pkt_t *pkt) { - uint8_t tkl = pkt->hdr->ver_t_tkl & 0xf; - - if (!IS_USED(MODULE_NANOCOAP_TOKEN_EXT)) { - return tkl; - } - - void *ext = pkt->hdr + 1; - switch (tkl) { - case 13: - return tkl + *(uint8_t *)ext; - case 14: - return tkl + 255 + byteorder_bebuftohs(ext); - case 15: - assert(0); - /* fall-through */ - default: - return tkl; - } + return coap_hdr_get_token_len(pkt->hdr); } -static inline uint8_t *coap_hdr_data_ptr(const coap_hdr_t *hdr); - /** * @brief Get pointer to a message's token *