From 6859de785564862d8267676fc16d9a9afb5f6552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cenk=20G=C3=BCndo=C4=9Fan?= Date: Fri, 17 Apr 2020 13:45:27 +0200 Subject: [PATCH] nanocoap: export coap_opt_get_uint() --- sys/include/net/nanocoap.h | 14 ++++++++++++++ sys/net/application_layer/nanocoap/nanocoap.c | 7 +++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/sys/include/net/nanocoap.h b/sys/include/net/nanocoap.h index b35bdfa3d6..a6612fd918 100644 --- a/sys/include/net/nanocoap.h +++ b/sys/include/net/nanocoap.h @@ -446,6 +446,20 @@ static inline void coap_hdr_set_type(coap_hdr_t *hdr, unsigned type) */ unsigned coap_get_content_type(coap_pkt_t *pkt); +/** + * @brief Get a uint32 option value + * + * @param[in] pkt packet to read from + * @param[in] optnum absolute option number + * @param[out] value the parsed option value + * + * @return 0 if the option was found and the value was parsed correctly + * @return -ENOENT if the option was not found in @p pkt + * @return -ENOSPC if option length is greater than 4 octets + * @return -EBADMSG if option value is invalid + */ +int coap_opt_get_uint(const coap_pkt_t *pkt, uint16_t optnum, uint32_t *value); + /** * @brief Read a full option as null terminated string into the target buffer * diff --git a/sys/net/application_layer/nanocoap/nanocoap.c b/sys/net/application_layer/nanocoap/nanocoap.c index 6d642ef12d..7498e38c35 100644 --- a/sys/net/application_layer/nanocoap/nanocoap.c +++ b/sys/net/application_layer/nanocoap/nanocoap.c @@ -42,7 +42,6 @@ /** @} */ static int _decode_value(unsigned val, uint8_t **pkt_pos_ptr, uint8_t *pkt_end); -int coap_get_option_uint(coap_pkt_t *pkt, unsigned opt_num, uint32_t *target); static uint32_t _decode_uint(uint8_t *pkt_pos, unsigned nbytes); static size_t _encode_uint(uint32_t *val); @@ -135,7 +134,7 @@ int coap_parse(coap_pkt_t *pkt, uint8_t *buf, size_t len) } #ifdef MODULE_GCOAP - if (coap_get_option_uint(pkt, COAP_OPT_OBSERVE, &pkt->observe_value) != 0) { + if (coap_opt_get_uint(pkt, COAP_OPT_OBSERVE, &pkt->observe_value) != 0) { pkt->observe_value = UINT32_MAX; } #endif @@ -224,7 +223,7 @@ ssize_t coap_opt_get_opaque(const coap_pkt_t *pkt, unsigned opt_num, uint8_t **v return len; } -int coap_get_option_uint(coap_pkt_t *pkt, unsigned opt_num, uint32_t *target) +int coap_opt_get_uint(const coap_pkt_t *pkt, uint16_t opt_num, uint32_t *target) { assert(target); @@ -246,7 +245,7 @@ int coap_get_option_uint(coap_pkt_t *pkt, unsigned opt_num, uint32_t *target) return -EBADMSG; } } - return -1; + return -ENOENT; } uint8_t *coap_iterate_option(const coap_pkt_t *pkt, uint8_t **optpos,