Skip to content

Commit b9280e2

Browse files
committed
[nrf fromlist] net: coap: Add API to send reset message
Add helper API to construct CoAP Reset message. Upstream PR #: 80445 Signed-off-by: Seppo Takalo <[email protected]>
1 parent bd7931e commit b9280e2

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
@@ -528,6 +528,21 @@ int coap_packet_init(struct coap_packet *cpkt, uint8_t *data, uint16_t max_len,
528528
int coap_ack_init(struct coap_packet *cpkt, const struct coap_packet *req,
529529
uint8_t *data, uint16_t max_len, uint8_t code);
530530

531+
/**
532+
* @brief Create a new CoAP Reset message for given request.
533+
*
534+
* This function works like @ref coap_packet_init, filling CoAP header type,
535+
* and CoAP header message id fields.
536+
*
537+
* @param cpkt New packet to be initialized using the storage from @a data.
538+
* @param req CoAP request packet that is being acknowledged
539+
* @param data Data that will contain a CoAP packet information
540+
* @param max_len Maximum allowable length of data
541+
*
542+
* @return 0 in case of success or negative in case of error.
543+
*/
544+
int coap_rst_init(struct coap_packet *cpkt, const struct coap_packet *req,
545+
uint8_t *data, uint16_t max_len);
531546
/**
532547
* @brief Returns a randomly generated array of 8 bytes, that can be
533548
* 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
@@ -229,6 +229,19 @@ int coap_ack_init(struct coap_packet *cpkt, const struct coap_packet *req,
229229
token, code, id);
230230
}
231231

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

0 commit comments

Comments
 (0)