Commit e96e95b6 authored by Seppo Takalo's avatar Seppo Takalo Committed by Mahesh Mahadevan
Browse files

net: coap: Add API to send reset message



Add helper API to construct CoAP Reset message.

Signed-off-by: default avatarSeppo Takalo <seppo.takalo@nordicsemi.no>
parent 1890dbd6
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -552,6 +552,21 @@ int coap_packet_init(struct coap_packet *cpkt, uint8_t *data, uint16_t max_len,
int coap_ack_init(struct coap_packet *cpkt, const struct coap_packet *req,
		  uint8_t *data, uint16_t max_len, uint8_t code);

/**
 * @brief Create a new CoAP Reset message for given request.
 *
 * This function works like @ref coap_packet_init, filling CoAP header type,
 * and CoAP header message id fields.
 *
 * @param cpkt New packet to be initialized using the storage from @a data.
 * @param req CoAP request packet that is being acknowledged
 * @param data Data that will contain a CoAP packet information
 * @param max_len Maximum allowable length of data
 *
 * @return 0 in case of success or negative in case of error.
 */
int coap_rst_init(struct coap_packet *cpkt, const struct coap_packet *req,
		  uint8_t *data, uint16_t max_len);
/**
 * @brief Returns a randomly generated array of 8 bytes, that can be
 * used as a message's token.
+13 −0
Original line number Diff line number Diff line
@@ -232,6 +232,19 @@ int coap_ack_init(struct coap_packet *cpkt, const struct coap_packet *req,
				token, code, id);
}

int coap_rst_init(struct coap_packet *cpkt, const struct coap_packet *req,
		  uint8_t *data, uint16_t max_len)
{
	uint16_t id;
	uint8_t ver;

	ver = coap_header_get_version(req);
	id = coap_header_get_id(req);

	return coap_packet_init(cpkt, data, max_len, ver, COAP_TYPE_RESET, 0,
				NULL, 0, id);
}

static void option_header_set_delta(uint8_t *opt, uint8_t delta)
{
	*opt = (delta & 0xF) << 4;