Skip to content

Commit 3b4e54e

Browse files
LukasWoodtlicarlescufi
authored andcommitted
net: coap: Add function to check for block option in message
The added function allows to check if a descriptive block option was already added to a message. Signed-off-by: Lukas Woodtli <[email protected]>
1 parent e13e909 commit 3b4e54e

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

include/zephyr/net/coap.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,19 @@ 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 Check if a descriptive block option is set in the packet.
611+
*
612+
* If the CoAP packet is a request then an available BLOCK1 option
613+
* would be checked otherwise a BLOCK2 option would be checked.
614+
*
615+
* @param cpkt Packet to be checked.
616+
*
617+
* @return true if the corresponding block option is set,
618+
* false otherwise.
619+
*/
620+
bool coap_has_descriptive_block_option(struct coap_packet *cpkt);
621+
609622
/**
610623
* @brief Remove BLOCK1 or BLOCK2 option from the packet.
611624
*

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+
bool coap_has_descriptive_block_option(struct coap_packet *cpkt)
1100+
{
1101+
if (is_request(cpkt)) {
1102+
return coap_get_option_int(cpkt, COAP_OPTION_BLOCK1) >= 0;
1103+
} else {
1104+
return coap_get_option_int(cpkt, COAP_OPTION_BLOCK2) >= 0;
1105+
}
1106+
}
1107+
10991108
int coap_remove_descriptive_block_option(struct coap_packet *cpkt)
11001109
{
11011110
if (is_request(cpkt)) {

0 commit comments

Comments
 (0)