diff --git a/sys/include/net/nanocoap.h b/sys/include/net/nanocoap.h index df5d0fec12..c782ea2345 100644 --- a/sys/include/net/nanocoap.h +++ b/sys/include/net/nanocoap.h @@ -628,6 +628,16 @@ uint8_t *coap_find_option(coap_pkt_t *pkt, unsigned opt_num); */ unsigned coap_get_content_type(coap_pkt_t *pkt); +/** + * @brief Get the Accept option value from a packet if present + * + * @param[in] pkt packet to work on + * + * @returns the packet's Accept option value if included, + * COAP_FORMAT_NONE otherwise + */ +unsigned coap_get_accept(coap_pkt_t *pkt); + /** * @brief Get a uint32 option value * diff --git a/sys/net/application_layer/nanocoap/nanocoap.c b/sys/net/application_layer/nanocoap/nanocoap.c index 23ec4084d0..937b40568f 100644 --- a/sys/net/application_layer/nanocoap/nanocoap.c +++ b/sys/net/application_layer/nanocoap/nanocoap.c @@ -280,9 +280,9 @@ uint8_t *coap_iterate_option(coap_pkt_t *pkt, uint8_t **optpos, } } -unsigned coap_get_content_type(coap_pkt_t *pkt) +static unsigned _get_content_format(coap_pkt_t *pkt, unsigned int opt_num) { - uint8_t *opt_pos = coap_find_option(pkt, COAP_OPT_CONTENT_FORMAT); + uint8_t *opt_pos = coap_find_option(pkt, opt_num); unsigned content_type = COAP_FORMAT_NONE; if (opt_pos) { uint16_t delta; @@ -302,6 +302,16 @@ unsigned coap_get_content_type(coap_pkt_t *pkt) return content_type; } +unsigned coap_get_content_type(coap_pkt_t *pkt) +{ + return _get_content_format(pkt, COAP_OPT_CONTENT_FORMAT); +} + +unsigned coap_get_accept(coap_pkt_t *pkt) +{ + return _get_content_format(pkt, COAP_OPT_ACCEPT); +} + ssize_t coap_opt_get_next(const coap_pkt_t *pkt, coap_optpos_t *opt, uint8_t **value, bool init_opt) {