Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/nanocoap: write struct-based block1 option #10702

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions sys/include/net/nanocoap.h
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,20 @@ ssize_t coap_opt_finish(coap_pkt_t *pkt, uint16_t flags);
*/
size_t coap_opt_put_block2(uint8_t *buf, uint16_t lastonum, coap_block_slicer_t *slicer, bool more);

/**
* @brief Add the given block1 option into pkt
*
* @post pkt.payload advanced to first byte after option
* @post pkt.payload_len reduced by option length
*
* @param[in,out] pkt pkt referencing target buffer
* @param[in] block1 struct with block values
*
* @return number of bytes written to buffer
* @return <0 reserved for error but not implemented yet
*/
size_t coap_opt_add_block1(coap_pkt_t *pkt, coap_block1_t *block1);

/**
* @brief Get content type from packet
*
Expand Down
8 changes: 8 additions & 0 deletions sys/net/application_layer/nanocoap/nanocoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,14 @@ size_t coap_opt_put_block2(uint8_t *buf, uint16_t lastonum, coap_block_slicer_t
return coap_put_option_block(buf, lastonum, blknum, szx, more, COAP_OPT_BLOCK2);
}

size_t coap_opt_add_block1(coap_pkt_t *pkt, coap_block1_t *block1)
{
uint32_t val = (block1->blknum << 4) | block1->szx | (block1->more ? 0x8 : 0);
_encode_uint(&val);

return coap_opt_add_uint(pkt, COAP_OPT_BLOCK1, val);
}

size_t coap_opt_put_string(uint8_t *buf, uint16_t lastonum, uint16_t optnum,
const char *string, char separator)
{
Expand Down