Skip to content

Commit e13e909

Browse files
LukasWoodtlicarlescufi
authored andcommitted
net: coap: Add function for removing block transfer option
In some cases the options of a CoAP message are reused for block transfer. Then the block header needs to be updated. The current approach is to remove the old block option and add an updated one. Signed-off-by: Lukas Woodtli <[email protected]>
1 parent 6277a39 commit e13e909

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

include/zephyr/net/coap.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,18 @@ int coap_block_transfer_init(struct coap_block_context *ctx,
606606
*/
607607
int coap_append_descriptive_block_option(struct coap_packet *cpkt, struct coap_block_context *ctx);
608608

609+
/**
610+
* @brief Remove BLOCK1 or BLOCK2 option from the packet.
611+
*
612+
* If the CoAP packet is a request then BLOCK1 is removed
613+
* otherwise BLOCK2 is removed.
614+
*
615+
* @param cpkt Packet to be updated.
616+
*
617+
* @return 0 in case of success or negative in case of error.
618+
*/
619+
int coap_remove_descriptive_block_option(struct coap_packet *cpkt);
620+
609621
/**
610622
* @brief Append BLOCK1 option to the packet.
611623
*

subsys/net/lib/coap/coap.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,15 @@ int coap_append_descriptive_block_option(struct coap_packet *cpkt, struct coap_b
10961096
}
10971097
}
10981098

1099+
int coap_remove_descriptive_block_option(struct coap_packet *cpkt)
1100+
{
1101+
if (is_request(cpkt)) {
1102+
return coap_packet_remove_option(cpkt, COAP_OPTION_BLOCK1);
1103+
} else {
1104+
return coap_packet_remove_option(cpkt, COAP_OPTION_BLOCK2);
1105+
}
1106+
}
1107+
10991108
int coap_append_block1_option(struct coap_packet *cpkt,
11001109
struct coap_block_context *ctx)
11011110
{

0 commit comments

Comments
 (0)