diff --git a/sys/include/net/nanocoap.h b/sys/include/net/nanocoap.h index be04a417d506..e144ee1f9080 100644 --- a/sys/include/net/nanocoap.h +++ b/sys/include/net/nanocoap.h @@ -974,7 +974,8 @@ size_t coap_opt_put_block_object(uint8_t *buf, uint16_t lastonum, static inline size_t coap_opt_put_block1_control(uint8_t *buf, uint16_t lastonum, coap_block1_t *block) { - return coap_opt_put_block_object(buf, lastonum, block, COAP_OPT_BLOCK1); + return coap_opt_put_uint(buf, lastonum, COAP_OPT_BLOCK1, + (block->blknum << 4) | block->szx | (block->more ? 0x8 : 0)); } /** @@ -991,8 +992,9 @@ static inline size_t coap_opt_put_block1_control(uint8_t *buf, uint16_t lastonum static inline size_t coap_opt_put_block2_control(uint8_t *buf, uint16_t lastonum, coap_block1_t *block) { - block->more = 0; - return coap_opt_put_block_object(buf, lastonum, block, COAP_OPT_BLOCK2); + /* block.more must be zero, so no need to 'or' it in */ + return coap_opt_put_uint(buf, lastonum, COAP_OPT_BLOCK2, + (block->blknum << 4) | block->szx); } /** @@ -1127,7 +1129,12 @@ size_t coap_put_option(uint8_t *buf, uint16_t lastonum, uint16_t onum, uint8_t * * * @returns amount of bytes written to @p buf */ -size_t coap_put_option_block1(uint8_t *buf, uint16_t lastonum, unsigned blknum, unsigned szx, int more); +static inline size_t coap_put_option_block1(uint8_t *buf, uint16_t lastonum, + unsigned blknum, unsigned szx, int more) +{ + return coap_opt_put_uint(buf, lastonum, COAP_OPT_BLOCK1, + (blknum << 4) | szx | (more ? 0x8 : 0)); +} /** * @brief Insert content type option into buffer @@ -1139,7 +1146,11 @@ size_t coap_put_option_block1(uint8_t *buf, uint16_t lastonum, unsigned blknum, * * @returns amount of bytes written to @p buf */ -size_t coap_put_option_ct(uint8_t *buf, uint16_t lastonum, uint16_t content_type); +static inline size_t coap_put_option_ct(uint8_t *buf, uint16_t lastonum, + uint16_t content_type) +{ + return coap_opt_put_uint(buf, lastonum, COAP_OPT_CONTENT_FORMAT, content_type); +} /**@}*/ diff --git a/sys/net/application_layer/nanocoap/nanocoap.c b/sys/net/application_layer/nanocoap/nanocoap.c index ab833b147295..c8136a0e1660 100644 --- a/sys/net/application_layer/nanocoap/nanocoap.c +++ b/sys/net/application_layer/nanocoap/nanocoap.c @@ -571,20 +571,6 @@ size_t coap_put_option(uint8_t *buf, uint16_t lastonum, uint16_t onum, uint8_t * return (size_t)n; } -size_t coap_put_option_ct(uint8_t *buf, uint16_t lastonum, uint16_t content_type) -{ - if (content_type == 0) { - return coap_put_option(buf, lastonum, COAP_OPT_CONTENT_FORMAT, NULL, 0); - } - else if (content_type <= 255) { - uint8_t tmp = content_type; - return coap_put_option(buf, lastonum, COAP_OPT_CONTENT_FORMAT, &tmp, sizeof(tmp)); - } - else { - return coap_put_option(buf, lastonum, COAP_OPT_CONTENT_FORMAT, (uint8_t *)&content_type, sizeof(content_type)); - } -} - static unsigned _size2szx(size_t size) { unsigned szx = 0; @@ -612,19 +598,6 @@ static unsigned _slicer_blknum(coap_block_slicer_t *slicer) return blknum; } -static size_t coap_put_option_block(uint8_t *buf, uint16_t lastonum, unsigned blknum, unsigned szx, int more, uint16_t option) -{ - uint32_t blkopt = (blknum << 4) | szx | (more ? 0x8 : 0); - size_t olen = _encode_uint(&blkopt); - - return coap_put_option(buf, lastonum, option, (uint8_t *)&blkopt, olen); -} - -size_t coap_put_option_block1(uint8_t *buf, uint16_t lastonum, unsigned blknum, unsigned szx, int more) -{ - return coap_put_option_block(buf, lastonum, blknum, szx, more, COAP_OPT_BLOCK1); -} - int coap_get_block1(coap_pkt_t *pkt, coap_block1_t *block1) { uint32_t blknum;