Skip to content

Commit e96e95b

Browse files
SeppoTakalommahadevan108
authored andcommitted
net: coap: Add API to send reset message
Add helper API to construct CoAP Reset message. Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
1 parent 1890dbd commit e96e95b

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

include/zephyr/net/coap.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,21 @@ int coap_packet_init(struct coap_packet *cpkt, uint8_t *data, uint16_t max_len,
552552
int coap_ack_init(struct coap_packet *cpkt, const struct coap_packet *req,
553553
uint8_t *data, uint16_t max_len, uint8_t code);
554554

555+
/**
556+
* @brief Create a new CoAP Reset message for given request.
557+
*
558+
* This function works like @ref coap_packet_init, filling CoAP header type,
559+
* and CoAP header message id fields.
560+
*
561+
* @param cpkt New packet to be initialized using the storage from @a data.
562+
* @param req CoAP request packet that is being acknowledged
563+
* @param data Data that will contain a CoAP packet information
564+
* @param max_len Maximum allowable length of data
565+
*
566+
* @return 0 in case of success or negative in case of error.
567+
*/
568+
int coap_rst_init(struct coap_packet *cpkt, const struct coap_packet *req,
569+
uint8_t *data, uint16_t max_len);
555570
/**
556571
* @brief Returns a randomly generated array of 8 bytes, that can be
557572
* used as a message's token.

subsys/net/lib/coap/coap.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,19 @@ int coap_ack_init(struct coap_packet *cpkt, const struct coap_packet *req,
232232
token, code, id);
233233
}
234234

235+
int coap_rst_init(struct coap_packet *cpkt, const struct coap_packet *req,
236+
uint8_t *data, uint16_t max_len)
237+
{
238+
uint16_t id;
239+
uint8_t ver;
240+
241+
ver = coap_header_get_version(req);
242+
id = coap_header_get_id(req);
243+
244+
return coap_packet_init(cpkt, data, max_len, ver, COAP_TYPE_RESET, 0,
245+
NULL, 0, id);
246+
}
247+
235248
static void option_header_set_delta(uint8_t *opt, uint8_t delta)
236249
{
237250
*opt = (delta & 0xF) << 4;

0 commit comments

Comments
 (0)