Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6a753ab
[nrf fromtree] net: coap: add no-response option definition and values
hubertmis Sep 23, 2024
d86b3c5
[nrf fromtree] net: lib: coap_client: wait for all acknowledgements
fgervais Sep 25, 2024
7346555
[nrf fromtree] tests: coap_client: wait enough for requests to be una…
fgervais Sep 24, 2024
82eb864
[nrf fromtree] include: zephyr: net: coap_service: Use _CONCAT expansion
pdgendt Sep 30, 2024
fb89dfd
[nrf fromtree] tests: coap_client: optimize/reduce sleep time
fgervais Sep 28, 2024
db039b2
[nrf fromtree] net: lib: coap: make ACK random factor runtime configu…
koalatux Sep 26, 2024
0bd5cc6
[nrf fromtree] net: coap_client: signal socket error to user
tautologyclub Oct 23, 2024
6d0dc73
[nrf fromtree] net: lib: coap_client: Protect initialization with mutex
SeppoTakalo Oct 23, 2024
8659fca
[nrf fromtree] net: lib: coap_client: Release internal request when f…
SeppoTakalo Oct 23, 2024
8787683
[nrf fromtree] net: lib: coap_client: check poll() condition before r…
SeppoTakalo Oct 24, 2024
e63f9e6
[nrf fromtree] net: lib: coap_client: Forward recv() errors to handli…
SeppoTakalo Oct 25, 2024
b5b4eff
[nrf fromtree] net: lib: coap_client: Don't decrease retry counter on…
SeppoTakalo Oct 25, 2024
88ea07c
[nrf fromtree] net: lib: coap_client: Use reset_internal_request() in…
SeppoTakalo Oct 25, 2024
d50bb85
[nrf fromtree] net: lib: coap_client: Fix reset handling
SeppoTakalo Oct 24, 2024
c893f6a
[nrf fromtree] net: coap: Add API to send reset message
SeppoTakalo Oct 25, 2024
d4afbcf
[nrf fromtree] net: lib: coap_client: Remove duplicate token comparison
SeppoTakalo Oct 25, 2024
8b75121
[nrf fromtree] net: lib: coap_client: Send RST for unknown queries
SeppoTakalo Oct 25, 2024
4a6854b
[nrf fromtree] tests: coap_client: Add tests for poll() errors
SeppoTakalo Oct 25, 2024
de72749
[nrf fromtree] net: lib: coap_client: Remove unnecessary atomic variable
SeppoTakalo Oct 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion include/zephyr/net/coap.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
COAP_OPTION_PROXY_SCHEME = 39, /**< Proxy-Scheme */
COAP_OPTION_SIZE1 = 60, /**< Size1 */
COAP_OPTION_ECHO = 252, /**< Echo (RFC 9175) */
COAP_OPTION_NO_RESPONSE = 258, /**< No-Response (RFC 7967) */
COAP_OPTION_REQUEST_TAG = 292 /**< Request-Tag (RFC 9175) */
};

Expand Down Expand Up @@ -222,6 +223,22 @@
COAP_CONTENT_FORMAT_APP_CBOR = 60 /**< application/cbor */
};

/**
* @brief Set of No-Response option values for CoAP.
*
* To be used when encoding or decoding a No-Response option defined
* in RFC 7967.
*/
enum coap_no_response {
COAP_NO_RESPONSE_SUPPRESS_2_XX = 0x02,
COAP_NO_RESPONSE_SUPPRESS_4_XX = 0x08,
COAP_NO_RESPONSE_SUPPRESS_5_XX = 0x10,

COAP_NO_RESPONSE_SUPPRESS_ALL = COAP_NO_RESPONSE_SUPPRESS_2_XX |
COAP_NO_RESPONSE_SUPPRESS_4_XX |
COAP_NO_RESPONSE_SUPPRESS_5_XX,
};

/** @cond INTERNAL_HIDDEN */

/* block option helper */
Expand Down Expand Up @@ -338,8 +355,15 @@
* @brief CoAP transmission parameters.
*/
struct coap_transmission_parameters {
/** Initial ACK timeout. Value is used as a base value to retry pending CoAP packets. */
/** Initial ACK timeout. Value is used as a base value to retry pending CoAP packets. */
uint32_t ack_timeout;
#if defined(CONFIG_COAP_RANDOMIZE_ACK_TIMEOUT) || defined(__DOXYGEN__)
/**
* Set CoAP ack random factor. A value of 150 means a factor of 1.5. A value of 0 defaults
* to @kconfig{CONFIG_COAP_ACK_RANDOM_PERCENT}. The value must be >= 100.
*/
uint16_t ack_random_percent;
#endif /* defined(CONFIG_COAP_RANDOMIZE_ACK_TIMEOUT) */
/** Set CoAP retry backoff factor. A value of 200 means a factor of 2.0. */
uint16_t coap_backoff_percent;
/** Maximum number of retransmissions. */
Expand Down Expand Up @@ -528,7 +552,22 @@
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);
/**

Check notice on line 570 in include/zephyr/net/coap.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/net/coap.h:570 -int coap_rst_init(struct coap_packet *cpkt, const struct coap_packet *req, - uint8_t *data, uint16_t max_len); +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.
*
Expand Down
3 changes: 1 addition & 2 deletions include/zephyr/net/coap_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct coap_client_option {
struct coap_client_internal_request {
uint8_t request_token[COAP_TOKEN_MAX_LEN];
uint32_t offset;
uint32_t last_id;
uint16_t last_id;
uint8_t request_tkl;
bool request_ongoing;
atomic_t in_callback;
Expand All @@ -108,7 +108,6 @@ struct coap_client {
int fd;
struct sockaddr address;
socklen_t socklen;
bool response_ready;
struct k_mutex lock;
uint8_t send_buf[MAX_COAP_MSG_LEN];
uint8_t recv_buf[MAX_COAP_MSG_LEN];
Expand Down
18 changes: 9 additions & 9 deletions include/zephyr/net/coap_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
};

#define __z_coap_service_define(_name, _host, _port, _flags, _res_begin, _res_end) \
static struct coap_service_data coap_service_data_##_name = { \
static struct coap_service_data _CONCAT(coap_service_data_, _name) = { \
.sock_fd = -1, \
}; \
const STRUCT_SECTION_ITERABLE(coap_service, _name) = { \
Expand All @@ -69,8 +69,8 @@
.flags = _flags, \
.res_begin = (_res_begin), \
.res_end = (_res_end), \
.data = &coap_service_data_##_name, \
.data = &_CONCAT(coap_service_data_, _name), \
}

Check notice on line 73 in include/zephyr/net/coap_service.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/net/coap_service.h:73 -#define __z_coap_service_define(_name, _host, _port, _flags, _res_begin, _res_end) \ - static struct coap_service_data _CONCAT(coap_service_data_, _name) = { \ - .sock_fd = -1, \ - }; \ - const STRUCT_SECTION_ITERABLE(coap_service, _name) = { \ - .name = STRINGIFY(_name), \ - .host = _host, \ - .port = (uint16_t *)(_port), \ - .flags = _flags, \ - .res_begin = (_res_begin), \ - .res_end = (_res_end), \ - .data = &_CONCAT(coap_service_data_, _name), \ +#define __z_coap_service_define(_name, _host, _port, _flags, _res_begin, _res_end) \ + static struct coap_service_data _CONCAT(coap_service_data_, _name) = { \ + .sock_fd = -1, \ + }; \ + const STRUCT_SECTION_ITERABLE(coap_service, _name) = { \ + .name = STRINGIFY(_name), .host = _host, .port = (uint16_t *)(_port), \ + .flags = _flags, .res_begin = (_res_begin), \ + .res_end = (_res_end), \ + .data = &_CONCAT(coap_service_data_, _name), \

/** @endcond */

Expand Down Expand Up @@ -111,8 +111,8 @@
* @param _service Name of the associated service.
*/
#define COAP_RESOURCE_DEFINE(_name, _service, ...) \
STRUCT_SECTION_ITERABLE_ALTERNATE(coap_resource_##_service, coap_resource, _name) \
= __VA_ARGS__
STRUCT_SECTION_ITERABLE_ALTERNATE(_CONCAT(coap_resource_, _service), coap_resource, \
_name) = __VA_ARGS__

Check notice on line 115 in include/zephyr/net/coap_service.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/net/coap_service.h:115 -#define COAP_RESOURCE_DEFINE(_name, _service, ...) \ - STRUCT_SECTION_ITERABLE_ALTERNATE(_CONCAT(coap_resource_, _service), coap_resource, \ +#define COAP_RESOURCE_DEFINE(_name, _service, ...) \ + STRUCT_SECTION_ITERABLE_ALTERNATE(_CONCAT(coap_resource_, _service), coap_resource, \

/**
* @brief Define a CoAP service with static resources.
Expand All @@ -132,11 +132,11 @@
* @param _flags Configuration flags @see @ref COAP_SERVICE_FLAGS.
*/
#define COAP_SERVICE_DEFINE(_name, _host, _port, _flags) \
extern struct coap_resource _CONCAT(_coap_resource_##_name, _list_start)[]; \
extern struct coap_resource _CONCAT(_coap_resource_##_name, _list_end)[]; \
extern struct coap_resource _CONCAT(_CONCAT(_coap_resource_, _name), _list_start)[]; \
extern struct coap_resource _CONCAT(_CONCAT(_coap_resource_, _name), _list_end)[]; \
__z_coap_service_define(_name, _host, _port, _flags, \
&_CONCAT(_coap_resource_##_name, _list_start)[0], \
&_CONCAT(_coap_resource_##_name, _list_end)[0])
&_CONCAT(_CONCAT(_coap_resource_, _name), _list_start)[0], \
&_CONCAT(_CONCAT(_coap_resource_, _name), _list_end)[0])

Check notice on line 139 in include/zephyr/net/coap_service.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/net/coap_service.h:139 -#define COAP_SERVICE_DEFINE(_name, _host, _port, _flags) \ - extern struct coap_resource _CONCAT(_CONCAT(_coap_resource_, _name), _list_start)[]; \ - extern struct coap_resource _CONCAT(_CONCAT(_coap_resource_, _name), _list_end)[]; \ - __z_coap_service_define(_name, _host, _port, _flags, \ - &_CONCAT(_CONCAT(_coap_resource_, _name), _list_start)[0], \ +#define COAP_SERVICE_DEFINE(_name, _host, _port, _flags) \ + extern struct coap_resource _CONCAT(_CONCAT(_coap_resource_, _name), _list_start)[]; \ + extern struct coap_resource _CONCAT(_CONCAT(_coap_resource_, _name), _list_end)[]; \ + __z_coap_service_define(_name, _host, _port, _flags, \ + &_CONCAT(_CONCAT(_coap_resource_, _name), _list_start)[0], \

/**
* @brief Count the number of CoAP services.
Expand Down Expand Up @@ -177,7 +177,7 @@
* @param _it Name of iterator (of type @ref coap_resource)
*/
#define COAP_RESOURCE_FOREACH(_service, _it) \
STRUCT_SECTION_FOREACH_ALTERNATE(coap_resource_##_service, coap_resource, _it)
STRUCT_SECTION_FOREACH_ALTERNATE(_CONCAT(coap_resource_, _service), coap_resource, _it)

Check notice on line 180 in include/zephyr/net/coap_service.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/net/coap_service.h:180 -#define COAP_RESOURCE_FOREACH(_service, _it) \ +#define COAP_RESOURCE_FOREACH(_service, _it) \

/**
* @brief Iterate over all static resources associated with @p _service .
Expand Down
21 changes: 19 additions & 2 deletions subsys/net/lib/coap/coap.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@
static struct coap_transmission_parameters coap_transmission_params = {
.max_retransmission = CONFIG_COAP_MAX_RETRANSMIT,
.ack_timeout = CONFIG_COAP_INIT_ACK_TIMEOUT_MS,
#if defined(CONFIG_COAP_RANDOMIZE_ACK_TIMEOUT)
.ack_random_percent = CONFIG_COAP_ACK_RANDOM_PERCENT,
#endif /* defined(CONFIG_COAP_RANDOMIZE_ACK_TIMEOUT) */
.coap_backoff_percent = CONFIG_COAP_BACKOFF_PERCENT
};

Check notice on line 67 in subsys/net/lib/coap/coap.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/net/lib/coap/coap.c:67 - .coap_backoff_percent = CONFIG_COAP_BACKOFF_PERCENT -}; + .coap_backoff_percent = CONFIG_COAP_BACKOFF_PERCENT};
static int insert_option(struct coap_packet *cpkt, uint16_t code, const uint8_t *value,
uint16_t len);

Expand Down Expand Up @@ -229,6 +232,19 @@
token, code, id);
}

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

Check notice on line 237 in subsys/net/lib/coap/coap.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/net/lib/coap/coap.c:237 -int coap_rst_init(struct coap_packet *cpkt, const struct coap_packet *req, - uint8_t *data, uint16_t max_len) +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);
}

Check notice on line 246 in subsys/net/lib/coap/coap.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/net/lib/coap/coap.c:246 - return coap_packet_init(cpkt, data, max_len, ver, COAP_TYPE_RESET, 0, - NULL, 0, id); + 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;
Expand Down Expand Up @@ -1706,8 +1722,9 @@
static uint32_t init_ack_timeout(const struct coap_transmission_parameters *params)
{
#if defined(CONFIG_COAP_RANDOMIZE_ACK_TIMEOUT)
const uint32_t max_ack = params->ack_timeout *
CONFIG_COAP_ACK_RANDOM_PERCENT / 100;
const uint16_t random_percent = params->ack_random_percent ? params->ack_random_percent
: CONFIG_COAP_ACK_RANDOM_PERCENT;
const uint32_t max_ack = params->ack_timeout * random_percent / 100U;
const uint32_t min_ack = params->ack_timeout;

/* Randomly generated initial ACK timeout
Expand Down
Loading
Loading