Skip to content

Commit 1420c8e

Browse files
committed
net/nanocoap: use coap_opt_add_uint() and remove unused
1 parent c02872f commit 1420c8e

File tree

2 files changed

+16
-32
lines changed

2 files changed

+16
-32
lines changed

sys/include/net/nanocoap.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,8 @@ size_t coap_opt_put_block_object(uint8_t *buf, uint16_t lastonum,
974974
static inline size_t coap_opt_put_block1_control(uint8_t *buf, uint16_t lastonum,
975975
coap_block1_t *block)
976976
{
977-
return coap_opt_put_block_object(buf, lastonum, block, COAP_OPT_BLOCK1);
977+
return coap_opt_put_uint(buf, lastonum, COAP_OPT_BLOCK1,
978+
(block->blknum << 4) | block->szx | (block->more ? 0x8 : 0));
978979
}
979980

980981
/**
@@ -991,8 +992,9 @@ static inline size_t coap_opt_put_block1_control(uint8_t *buf, uint16_t lastonum
991992
static inline size_t coap_opt_put_block2_control(uint8_t *buf, uint16_t lastonum,
992993
coap_block1_t *block)
993994
{
994-
block->more = 0;
995-
return coap_opt_put_block_object(buf, lastonum, block, COAP_OPT_BLOCK2);
995+
/* block.more must be zero, so no need to 'or' it in */
996+
return coap_opt_put_uint(buf, lastonum, COAP_OPT_BLOCK2,
997+
(block->blknum << 4) | block->szx);
996998
}
997999

9981000
/**
@@ -1127,7 +1129,12 @@ size_t coap_put_option(uint8_t *buf, uint16_t lastonum, uint16_t onum, uint8_t *
11271129
*
11281130
* @returns amount of bytes written to @p buf
11291131
*/
1130-
size_t coap_put_option_block1(uint8_t *buf, uint16_t lastonum, unsigned blknum, unsigned szx, int more);
1132+
static inline size_t coap_put_option_block1(uint8_t *buf, uint16_t lastonum,
1133+
unsigned blknum, unsigned szx, int more)
1134+
{
1135+
return coap_opt_put_uint(buf, lastonum, COAP_OPT_BLOCK1,
1136+
(blknum << 4) | szx | (more ? 0x8 : 0));
1137+
}
11311138

11321139
/**
11331140
* @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,
11391146
*
11401147
* @returns amount of bytes written to @p buf
11411148
*/
1142-
size_t coap_put_option_ct(uint8_t *buf, uint16_t lastonum, uint16_t content_type);
1149+
static inline size_t coap_put_option_ct(uint8_t *buf, uint16_t lastonum,
1150+
uint16_t content_type)
1151+
{
1152+
return coap_opt_put_uint(buf, lastonum, COAP_OPT_CONTENT_FORMAT, content_type);
1153+
}
11431154
/**@}*/
11441155

11451156

sys/net/application_layer/nanocoap/nanocoap.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -571,20 +571,6 @@ size_t coap_put_option(uint8_t *buf, uint16_t lastonum, uint16_t onum, uint8_t *
571571
return (size_t)n;
572572
}
573573

574-
size_t coap_put_option_ct(uint8_t *buf, uint16_t lastonum, uint16_t content_type)
575-
{
576-
if (content_type == 0) {
577-
return coap_put_option(buf, lastonum, COAP_OPT_CONTENT_FORMAT, NULL, 0);
578-
}
579-
else if (content_type <= 255) {
580-
uint8_t tmp = content_type;
581-
return coap_put_option(buf, lastonum, COAP_OPT_CONTENT_FORMAT, &tmp, sizeof(tmp));
582-
}
583-
else {
584-
return coap_put_option(buf, lastonum, COAP_OPT_CONTENT_FORMAT, (uint8_t *)&content_type, sizeof(content_type));
585-
}
586-
}
587-
588574
static unsigned _size2szx(size_t size)
589575
{
590576
unsigned szx = 0;
@@ -612,19 +598,6 @@ static unsigned _slicer_blknum(coap_block_slicer_t *slicer)
612598
return blknum;
613599
}
614600

615-
static size_t coap_put_option_block(uint8_t *buf, uint16_t lastonum, unsigned blknum, unsigned szx, int more, uint16_t option)
616-
{
617-
uint32_t blkopt = (blknum << 4) | szx | (more ? 0x8 : 0);
618-
size_t olen = _encode_uint(&blkopt);
619-
620-
return coap_put_option(buf, lastonum, option, (uint8_t *)&blkopt, olen);
621-
}
622-
623-
size_t coap_put_option_block1(uint8_t *buf, uint16_t lastonum, unsigned blknum, unsigned szx, int more)
624-
{
625-
return coap_put_option_block(buf, lastonum, blknum, szx, more, COAP_OPT_BLOCK1);
626-
}
627-
628601
int coap_get_block1(coap_pkt_t *pkt, coap_block1_t *block1)
629602
{
630603
uint32_t blknum;

0 commit comments

Comments
 (0)