net/gcoap: Move config macros to 'CONFIG_' namespace
Macros that changed: GCOAP_MSG_QUEUE_SIZE -> CONFIG_GCOAP_MSG_QUEUE_SIZE GCOAP_NO_AUTO_INIT -> CONFIG_GCOAP_NO_AUTO_INIT GCOAP_NO_RETRANS_BACKOFF -> CONFIG_GCOAP_NO_RETRANS_BACKOFF GCOAP_NON_TIMEOUT -> CONFIG_GCOAP_NON_TIMEOUT GCOAP_OBS_CLIENTS_MAX -> CONFIG_GCOAP_OBS_CLIENTS_MAX GCOAP_OBS_OPTIONS_BUF -> CONFIG_GCOAP_OBS_OPTIONS_BUF GCOAP_OBS_REGISTRATIONS_MAX -> CONFIG_GCOAP_OBS_REGISTRATIONS_MAX GCOAP_OBS_VALUE_WIDTH -> CONFIG_GCOAP_OBS_VALUE_WIDTH GCOAP_PDU_BUF_SIZE -> CONFIG_GCOAP_PDU_BUF_SIZE GCOAP_PORT -> CONFIG_GCOAP_PORT GCOAP_RECV_TIMEOUT -> CONFIG_GCOAP_RECV_TIMEOUT GCOAP_REQ_OPTIONS_BUF -> CONFIG_GCOAP_REQ_OPTIONS_BUF GCOAP_REQ_WAITING_MAX -> CONFIG_GCOAP_REQ_WAITING_MAX GCOAP_RESEND_BUFS_MAX -> CONFIG_GCOAP_RESEND_BUFS_MAX GCOAP_RESP_OPTIONS_BUF -> CONFIG_GCOAP_RESP_OPTIONS_BUF GCOAP_TOKENLEN -> CONFIG_GCOAP_TOKENLEN
This commit is contained in:
parent
f0cde06391
commit
bab6f4737c
@ -11,15 +11,15 @@ RIOTBASE ?= $(CURDIR)/../..
|
||||
|
||||
## Uncomment to redefine port, for example use 61616 for RFC 6282 UDP compression.
|
||||
#GCOAP_PORT = 5683
|
||||
#CFLAGS += -DGCOAP_PORT=$(GCOAP_PORT)
|
||||
#CFLAGS += -DCONFIG_GCOAP_PORT=$(GCOAP_PORT)
|
||||
|
||||
## Uncomment to redefine request token length, max 8.
|
||||
#GCOAP_TOKENLEN = 2
|
||||
#CFLAGS += -DGCOAP_TOKENLEN=$(GCOAP_TOKENLEN)
|
||||
#CFLAGS += -DCONFIG_GCOAP_TOKENLEN=$(GCOAP_TOKENLEN)
|
||||
|
||||
# Increase from default for confirmable block2 follow-on requests
|
||||
GCOAP_RESEND_BUFS_MAX ?= 2
|
||||
CFLAGS += -DGCOAP_RESEND_BUFS_MAX=$(GCOAP_RESEND_BUFS_MAX)
|
||||
CONFIG_GCOAP_RESEND_BUFS_MAX ?= 2
|
||||
CFLAGS += -DCONFIG_GCOAP_RESEND_BUFS_MAX=$(CONFIG_GCOAP_RESEND_BUFS_MAX)
|
||||
|
||||
# Include packages that pull up and auto-init the link layer.
|
||||
# NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present
|
||||
|
||||
@ -12,11 +12,11 @@ RIOTBASE ?= $(CURDIR)/../..
|
||||
|
||||
# Redefine port, for example use 61616 for RFC 6282 UDP compression.
|
||||
#GCOAP_PORT = 5683
|
||||
#CFLAGS += -DGCOAP_PORT=$(GCOAP_PORT)
|
||||
#CFLAGS += -DCONFIG_GCOAP_PORT=$(GCOAP_PORT)
|
||||
|
||||
# Redefine request token length, max 8.
|
||||
#GCOAP_TOKENLEN = 2
|
||||
#CFLAGS += -DGCOAP_TOKENLEN=$(GCOAP_TOKENLEN)
|
||||
#CFLAGS += -DCONFIG_GCOAP_TOKENLEN=$(GCOAP_TOKENLEN)
|
||||
|
||||
# Border router requirements
|
||||
ifeq (,$(SLIP_UART))
|
||||
|
||||
@ -137,7 +137,7 @@ static void _resp_handler(const gcoap_request_memo_t *memo, coap_pkt_t* pdu,
|
||||
return;
|
||||
}
|
||||
|
||||
gcoap_req_init(pdu, (uint8_t *)pdu->hdr, GCOAP_PDU_BUF_SIZE,
|
||||
gcoap_req_init(pdu, (uint8_t *)pdu->hdr, CONFIG_GCOAP_PDU_BUF_SIZE,
|
||||
COAP_METHOD_GET, _last_req_path);
|
||||
if (msg_type == COAP_TYPE_ACK) {
|
||||
coap_hdr_set_type(pdu->hdr, COAP_TYPE_CON);
|
||||
@ -270,7 +270,7 @@ int gcoap_cli_cmd(int argc, char **argv)
|
||||
{
|
||||
/* Ordered like the RFC method code numbers, but off by 1. GET is code 0. */
|
||||
char *method_codes[] = {"get", "post", "put"};
|
||||
uint8_t buf[GCOAP_PDU_BUF_SIZE];
|
||||
uint8_t buf[CONFIG_GCOAP_PDU_BUF_SIZE];
|
||||
coap_pkt_t pdu;
|
||||
size_t len;
|
||||
|
||||
@ -282,7 +282,7 @@ int gcoap_cli_cmd(int argc, char **argv)
|
||||
if (strcmp(argv[1], "info") == 0) {
|
||||
uint8_t open_reqs = gcoap_op_state();
|
||||
|
||||
printf("CoAP server is listening on port %u\n", GCOAP_PORT);
|
||||
printf("CoAP server is listening on port %u\n", CONFIG_GCOAP_PORT);
|
||||
printf(" CLI requests sent: %u\n", req_count);
|
||||
printf("CoAP open requests: %u\n", open_reqs);
|
||||
return 0;
|
||||
@ -314,7 +314,7 @@ int gcoap_cli_cmd(int argc, char **argv)
|
||||
*/
|
||||
if (((argc == apos + 3) && (code_pos == 0)) ||
|
||||
((argc == apos + 4) && (code_pos != 0))) {
|
||||
gcoap_req_init(&pdu, &buf[0], GCOAP_PDU_BUF_SIZE, code_pos+1, argv[apos+2]);
|
||||
gcoap_req_init(&pdu, &buf[0], CONFIG_GCOAP_PDU_BUF_SIZE, code_pos+1, argv[apos+2]);
|
||||
coap_hdr_set_type(pdu.hdr, msg_type);
|
||||
|
||||
memset(_last_req_path, 0, _LAST_REQ_PATH_MAX);
|
||||
@ -346,7 +346,7 @@ int gcoap_cli_cmd(int argc, char **argv)
|
||||
}
|
||||
else {
|
||||
/* send Observe notification for /cli/stats */
|
||||
switch (gcoap_obs_init(&pdu, &buf[0], GCOAP_PDU_BUF_SIZE,
|
||||
switch (gcoap_obs_init(&pdu, &buf[0], CONFIG_GCOAP_PDU_BUF_SIZE,
|
||||
&_resources[0])) {
|
||||
case GCOAP_OBS_INIT_OK:
|
||||
DEBUG("gcoap_cli: creating /cli/stats notification\n");
|
||||
|
||||
@ -159,7 +159,7 @@ void auto_init(void)
|
||||
openthread_bootstrap();
|
||||
#endif
|
||||
#ifdef MODULE_GCOAP
|
||||
if (!IS_ACTIVE(GCOAP_NO_AUTO_INIT)) {
|
||||
if (!IS_ACTIVE(CONFIG_GCOAP_NO_AUTO_INIT)) {
|
||||
DEBUG("Auto init gcoap module.\n");
|
||||
gcoap_init();
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@
|
||||
*
|
||||
* ## Server Operation ##
|
||||
*
|
||||
* gcoap listens for requests on GCOAP_PORT, 5683 by default. You can redefine
|
||||
* gcoap listens for requests on CONFIG_GCOAP_PORT, 5683 by default. You can redefine
|
||||
* this by uncommenting the appropriate lines in gcoap's make file.
|
||||
*
|
||||
* gcoap allows an application to specify a collection of request resource paths
|
||||
@ -193,7 +193,7 @@
|
||||
*
|
||||
* By default, the value for the Observe option in a notification is three
|
||||
* bytes long. For resources that change slowly, this length can be reduced via
|
||||
* GCOAP_OBS_VALUE_WIDTH.
|
||||
* CONFIG_GCOAP_OBS_VALUE_WIDTH.
|
||||
*
|
||||
* A client always may re-register for a resource with the same token or with
|
||||
* a new token to indicate continued interest in receiving notifications about
|
||||
@ -365,22 +365,22 @@ extern "C" {
|
||||
/**
|
||||
* @brief Size for module message queue
|
||||
*/
|
||||
#ifndef GCOAP_MSG_QUEUE_SIZE
|
||||
#define GCOAP_MSG_QUEUE_SIZE (4)
|
||||
#ifndef CONFIG_GCOAP_MSG_QUEUE_SIZE
|
||||
#define CONFIG_GCOAP_MSG_QUEUE_SIZE (4)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Server port; use RFC 7252 default if not defined
|
||||
*/
|
||||
#ifndef GCOAP_PORT
|
||||
#define GCOAP_PORT (5683)
|
||||
#ifndef CONFIG_GCOAP_PORT
|
||||
#define CONFIG_GCOAP_PORT (5683)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Size of the buffer used to build a CoAP request or response
|
||||
*/
|
||||
#ifndef GCOAP_PDU_BUF_SIZE
|
||||
#define GCOAP_PDU_BUF_SIZE (128)
|
||||
#ifndef CONFIG_GCOAP_PDU_BUF_SIZE
|
||||
#define CONFIG_GCOAP_PDU_BUF_SIZE (128)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -392,8 +392,8 @@ extern "C" {
|
||||
* @deprecated Will not be available after the 2020.07 release. Used only by
|
||||
* gcoap_finish(), which also is deprecated.
|
||||
*/
|
||||
#ifndef GCOAP_REQ_OPTIONS_BUF
|
||||
#define GCOAP_REQ_OPTIONS_BUF (4)
|
||||
#ifndef CONFIG_GCOAP_REQ_OPTIONS_BUF
|
||||
#define CONFIG_GCOAP_REQ_OPTIONS_BUF (4)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -405,8 +405,8 @@ extern "C" {
|
||||
* @deprecated Will not be available after the 2020.07 release. Used only by
|
||||
* gcoap_finish(), which also is deprecated.
|
||||
*/
|
||||
#ifndef GCOAP_RESP_OPTIONS_BUF
|
||||
#define GCOAP_RESP_OPTIONS_BUF (4)
|
||||
#ifndef CONFIG_GCOAP_RESP_OPTIONS_BUF
|
||||
#define CONFIG_GCOAP_RESP_OPTIONS_BUF (4)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -418,15 +418,15 @@ extern "C" {
|
||||
* @deprecated Will not be available after the 2020.07 release. Used only by
|
||||
* gcoap_finish(), which also is deprecated.
|
||||
*/
|
||||
#ifndef GCOAP_OBS_OPTIONS_BUF
|
||||
#define GCOAP_OBS_OPTIONS_BUF (4)
|
||||
#ifndef CONFIG_GCOAP_OBS_OPTIONS_BUF
|
||||
#define CONFIG_GCOAP_OBS_OPTIONS_BUF (4)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Maximum number of requests awaiting a response
|
||||
*/
|
||||
#ifndef GCOAP_REQ_WAITING_MAX
|
||||
#define GCOAP_REQ_WAITING_MAX (2)
|
||||
#ifndef CONFIG_GCOAP_REQ_WAITING_MAX
|
||||
#define CONFIG_GCOAP_REQ_WAITING_MAX (2)
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
@ -446,8 +446,8 @@ extern "C" {
|
||||
*
|
||||
* Value must be in the range 0 to @ref GCOAP_TOKENLEN_MAX.
|
||||
*/
|
||||
#ifndef GCOAP_TOKENLEN
|
||||
#define GCOAP_TOKENLEN (2)
|
||||
#ifndef CONFIG_GCOAP_TOKENLEN
|
||||
#define CONFIG_GCOAP_TOKENLEN (2)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -461,8 +461,8 @@ extern "C" {
|
||||
*
|
||||
* If disabled, gcoap_init() must be called by some other means.
|
||||
*/
|
||||
#ifndef GCOAP_NO_AUTO_INIT
|
||||
#define GCOAP_NO_AUTO_INIT 0
|
||||
#ifndef CONFIG_GCOAP_NO_AUTO_INIT
|
||||
#define CONFIG_GCOAP_NO_AUTO_INIT 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -485,8 +485,8 @@ extern "C" {
|
||||
* @ingroup net_gcoap_conf
|
||||
* @brief Time in usec that the event loop waits for an incoming CoAP message
|
||||
*/
|
||||
#ifndef GCOAP_RECV_TIMEOUT
|
||||
#define GCOAP_RECV_TIMEOUT (1 * US_PER_SEC)
|
||||
#ifndef CONFIG_GCOAP_RECV_TIMEOUT
|
||||
#define CONFIG_GCOAP_RECV_TIMEOUT (1 * US_PER_SEC)
|
||||
#endif
|
||||
|
||||
#ifdef DOXYGEN
|
||||
@ -495,12 +495,12 @@ extern "C" {
|
||||
* @brief Turns off retransmission backoff when defined (undefined per default)
|
||||
*
|
||||
* In normal operations the timeout between retransmissions doubles. When
|
||||
* GCOAP_NO_RETRANS_BACKOFF is defined this doubling does not happen.
|
||||
* CONFIG_GCOAP_NO_RETRANS_BACKOFF is defined this doubling does not happen.
|
||||
*
|
||||
* @see COAP_ACK_TIMEOUT
|
||||
* @see COAP_ACK_VARIANCE
|
||||
*/
|
||||
#define GCOAP_NO_RETRANS_BACKOFF
|
||||
#define CONFIG_GCOAP_NO_RETRANS_BACKOFF
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -509,8 +509,8 @@ extern "C" {
|
||||
*
|
||||
* Set to 0 to disable timeout.
|
||||
*/
|
||||
#ifndef GCOAP_NON_TIMEOUT
|
||||
#define GCOAP_NON_TIMEOUT (5000000U)
|
||||
#ifndef CONFIG_GCOAP_NON_TIMEOUT
|
||||
#define CONFIG_GCOAP_NON_TIMEOUT (5000000U)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -530,16 +530,16 @@ extern "C" {
|
||||
* @ingroup net_gcoap_conf
|
||||
* @brief Maximum number of Observe clients
|
||||
*/
|
||||
#ifndef GCOAP_OBS_CLIENTS_MAX
|
||||
#define GCOAP_OBS_CLIENTS_MAX (2)
|
||||
#ifndef CONFIG_GCOAP_OBS_CLIENTS_MAX
|
||||
#define CONFIG_GCOAP_OBS_CLIENTS_MAX (2)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup net_gcoap_conf
|
||||
* @brief Maximum number of registrations for Observable resources
|
||||
*/
|
||||
#ifndef GCOAP_OBS_REGISTRATIONS_MAX
|
||||
#define GCOAP_OBS_REGISTRATIONS_MAX (2)
|
||||
#ifndef CONFIG_GCOAP_OBS_REGISTRATIONS_MAX
|
||||
#define CONFIG_GCOAP_OBS_REGISTRATIONS_MAX (2)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -571,18 +571,18 @@ extern "C" {
|
||||
* sec). For resources that change only slowly, the reduced message length is
|
||||
* useful when packet size is limited.
|
||||
*/
|
||||
#ifndef GCOAP_OBS_VALUE_WIDTH
|
||||
#define GCOAP_OBS_VALUE_WIDTH (3)
|
||||
#ifndef CONFIG_GCOAP_OBS_VALUE_WIDTH
|
||||
#define CONFIG_GCOAP_OBS_VALUE_WIDTH (3)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief See GCOAP_OBS_VALUE_WIDTH
|
||||
* @brief See CONFIG_GCOAP_OBS_VALUE_WIDTH
|
||||
*/
|
||||
#if (GCOAP_OBS_VALUE_WIDTH == 3)
|
||||
#if (CONFIG_GCOAP_OBS_VALUE_WIDTH == 3)
|
||||
#define GCOAP_OBS_TICK_EXPONENT (5)
|
||||
#elif (GCOAP_OBS_VALUE_WIDTH == 2)
|
||||
#elif (CONFIG_GCOAP_OBS_VALUE_WIDTH == 2)
|
||||
#define GCOAP_OBS_TICK_EXPONENT (16)
|
||||
#elif (GCOAP_OBS_VALUE_WIDTH == 1)
|
||||
#elif (CONFIG_GCOAP_OBS_VALUE_WIDTH == 1)
|
||||
#define GCOAP_OBS_TICK_EXPONENT (24)
|
||||
#endif
|
||||
|
||||
@ -607,8 +607,8 @@ extern "C" {
|
||||
* @ingroup net_gcoap_conf
|
||||
* @brief Count of PDU buffers available for resending confirmable messages
|
||||
*/
|
||||
#ifndef GCOAP_RESEND_BUFS_MAX
|
||||
#define GCOAP_RESEND_BUFS_MAX (1)
|
||||
#ifndef CONFIG_GCOAP_RESEND_BUFS_MAX
|
||||
#define CONFIG_GCOAP_RESEND_BUFS_MAX (1)
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
@ -73,17 +73,17 @@ static gcoap_listener_t _default_listener = {
|
||||
typedef struct {
|
||||
mutex_t lock; /* Shares state attributes safely */
|
||||
gcoap_listener_t *listeners; /* List of registered listeners */
|
||||
gcoap_request_memo_t open_reqs[GCOAP_REQ_WAITING_MAX];
|
||||
gcoap_request_memo_t open_reqs[CONFIG_GCOAP_REQ_WAITING_MAX];
|
||||
/* Storage for open requests; if first
|
||||
byte of an entry is zero, the entry
|
||||
is available */
|
||||
atomic_uint next_message_id; /* Next message ID to use */
|
||||
sock_udp_ep_t observers[GCOAP_OBS_CLIENTS_MAX];
|
||||
sock_udp_ep_t observers[CONFIG_GCOAP_OBS_CLIENTS_MAX];
|
||||
/* Observe clients; allows reuse for
|
||||
observe memos */
|
||||
gcoap_observe_memo_t observe_memos[GCOAP_OBS_REGISTRATIONS_MAX];
|
||||
gcoap_observe_memo_t observe_memos[CONFIG_GCOAP_OBS_REGISTRATIONS_MAX];
|
||||
/* Observed resource registrations */
|
||||
uint8_t resend_bufs[GCOAP_RESEND_BUFS_MAX][GCOAP_PDU_BUF_SIZE];
|
||||
uint8_t resend_bufs[CONFIG_GCOAP_RESEND_BUFS_MAX][CONFIG_GCOAP_PDU_BUF_SIZE];
|
||||
/* Buffers for PDU for request resends;
|
||||
if first byte of an entry is zero,
|
||||
the entry is available */
|
||||
@ -95,8 +95,8 @@ static gcoap_state_t _coap_state = {
|
||||
|
||||
static kernel_pid_t _pid = KERNEL_PID_UNDEF;
|
||||
static char _msg_stack[GCOAP_STACK_SIZE];
|
||||
static msg_t _msg_queue[GCOAP_MSG_QUEUE_SIZE];
|
||||
static uint8_t _listen_buf[GCOAP_PDU_BUF_SIZE];
|
||||
static msg_t _msg_queue[CONFIG_GCOAP_MSG_QUEUE_SIZE];
|
||||
static uint8_t _listen_buf[CONFIG_GCOAP_PDU_BUF_SIZE];
|
||||
static sock_udp_t _sock;
|
||||
|
||||
|
||||
@ -106,13 +106,13 @@ static void *_event_loop(void *arg)
|
||||
msg_t msg_rcvd;
|
||||
(void)arg;
|
||||
|
||||
msg_init_queue(_msg_queue, GCOAP_MSG_QUEUE_SIZE);
|
||||
msg_init_queue(_msg_queue, CONFIG_GCOAP_MSG_QUEUE_SIZE);
|
||||
|
||||
sock_udp_ep_t local;
|
||||
memset(&local, 0, sizeof(sock_udp_ep_t));
|
||||
local.family = AF_INET6;
|
||||
local.netif = SOCK_ADDR_ANY_NETIF;
|
||||
local.port = GCOAP_PORT;
|
||||
local.port = CONFIG_GCOAP_PORT;
|
||||
|
||||
int res = sock_udp_create(&_sock, &local, NULL, 0);
|
||||
if (res < 0) {
|
||||
@ -136,7 +136,7 @@ static void *_event_loop(void *arg)
|
||||
/* reduce retries remaining, double timeout and resend */
|
||||
else {
|
||||
memo->send_limit--;
|
||||
#ifdef GCOAP_NO_RETRANS_BACKOFF
|
||||
#ifdef CONFIG_GCOAP_NO_RETRANS_BACKOFF
|
||||
unsigned i = 0;
|
||||
#else
|
||||
unsigned i = COAP_MAX_RETRANSMIT - memo->send_limit;
|
||||
@ -186,7 +186,7 @@ static void _listen(sock_udp_t *sock)
|
||||
* waiting so the request's timeout can be handled in a timely manner in
|
||||
* _event_loop(). */
|
||||
ssize_t res = sock_udp_recv(sock, _listen_buf, sizeof(_listen_buf),
|
||||
open_reqs > 0 ? GCOAP_RECV_TIMEOUT : SOCK_NO_TIMEOUT,
|
||||
open_reqs > 0 ? CONFIG_GCOAP_RECV_TIMEOUT : SOCK_NO_TIMEOUT,
|
||||
&remote);
|
||||
if (res <= 0) {
|
||||
#if ENABLE_DEBUG
|
||||
@ -452,7 +452,7 @@ static void _find_req_memo(gcoap_request_memo_t **memo_ptr, coap_pkt_t *src_pdu,
|
||||
coap_pkt_t *memo_pdu = &memo_pdu_data;
|
||||
unsigned cmplen = coap_get_token_len(src_pdu);
|
||||
|
||||
for (int i = 0; i < GCOAP_REQ_WAITING_MAX; i++) {
|
||||
for (int i = 0; i < CONFIG_GCOAP_REQ_WAITING_MAX; i++) {
|
||||
if (_coap_state.open_reqs[i].state == GCOAP_MEMO_UNUSED)
|
||||
continue;
|
||||
|
||||
@ -534,7 +534,7 @@ static int _find_observer(sock_udp_ep_t **observer, sock_udp_ep_t *remote)
|
||||
{
|
||||
int empty_slot = -1;
|
||||
*observer = NULL;
|
||||
for (unsigned i = 0; i < GCOAP_OBS_CLIENTS_MAX; i++) {
|
||||
for (unsigned i = 0; i < CONFIG_GCOAP_OBS_CLIENTS_MAX; i++) {
|
||||
|
||||
if (_coap_state.observers[i].family == AF_UNSPEC) {
|
||||
empty_slot = i;
|
||||
@ -566,7 +566,7 @@ static int _find_obs_memo(gcoap_observe_memo_t **memo, sock_udp_ep_t *remote,
|
||||
sock_udp_ep_t *remote_observer = NULL;
|
||||
_find_observer(&remote_observer, remote);
|
||||
|
||||
for (unsigned i = 0; i < GCOAP_OBS_REGISTRATIONS_MAX; i++) {
|
||||
for (unsigned i = 0; i < CONFIG_GCOAP_OBS_REGISTRATIONS_MAX; i++) {
|
||||
if (_coap_state.observe_memos[i].observer == NULL) {
|
||||
empty_slot = i;
|
||||
continue;
|
||||
@ -602,7 +602,7 @@ static void _find_obs_memo_resource(gcoap_observe_memo_t **memo,
|
||||
const coap_resource_t *resource)
|
||||
{
|
||||
*memo = NULL;
|
||||
for (int i = 0; i < GCOAP_OBS_REGISTRATIONS_MAX; i++) {
|
||||
for (int i = 0; i < CONFIG_GCOAP_OBS_REGISTRATIONS_MAX; i++) {
|
||||
if (_coap_state.observe_memos[i].observer != NULL
|
||||
&& _coap_state.observe_memos[i].resource == resource) {
|
||||
*memo = &_coap_state.observe_memos[i];
|
||||
@ -658,24 +658,24 @@ int gcoap_req_init(coap_pkt_t *pdu, uint8_t *buf, size_t len,
|
||||
pdu->hdr = (coap_hdr_t *)buf;
|
||||
|
||||
/* generate token */
|
||||
#if GCOAP_TOKENLEN
|
||||
uint8_t token[GCOAP_TOKENLEN];
|
||||
for (size_t i = 0; i < GCOAP_TOKENLEN; i += 4) {
|
||||
#if CONFIG_GCOAP_TOKENLEN
|
||||
uint8_t token[CONFIG_GCOAP_TOKENLEN];
|
||||
for (size_t i = 0; i < CONFIG_GCOAP_TOKENLEN; i += 4) {
|
||||
uint32_t rand = random_uint32();
|
||||
memcpy(&token[i],
|
||||
&rand,
|
||||
(GCOAP_TOKENLEN - i >= 4) ? 4 : GCOAP_TOKENLEN - i);
|
||||
(CONFIG_GCOAP_TOKENLEN - i >= 4) ? 4 : CONFIG_GCOAP_TOKENLEN - i);
|
||||
}
|
||||
uint16_t msgid = (uint16_t)atomic_fetch_add(&_coap_state.next_message_id, 1);
|
||||
ssize_t res = coap_build_hdr(pdu->hdr, COAP_TYPE_NON, &token[0], GCOAP_TOKENLEN,
|
||||
code, msgid);
|
||||
ssize_t res = coap_build_hdr(pdu->hdr, COAP_TYPE_NON, &token[0],
|
||||
CONFIG_GCOAP_TOKENLEN, code, msgid);
|
||||
#else
|
||||
uint16_t msgid = (uint16_t)atomic_fetch_add(&_coap_state.next_message_id, 1);
|
||||
ssize_t res = coap_build_hdr(pdu->hdr, COAP_TYPE_NON, NULL, GCOAP_TOKENLEN,
|
||||
code, msgid);
|
||||
ssize_t res = coap_build_hdr(pdu->hdr, COAP_TYPE_NON, NULL,
|
||||
CONFIG_GCOAP_TOKENLEN, code, msgid);
|
||||
#endif
|
||||
|
||||
coap_pkt_init(pdu, buf, len - GCOAP_REQ_OPTIONS_BUF, res);
|
||||
coap_pkt_init(pdu, buf, len - CONFIG_GCOAP_REQ_OPTIONS_BUF, res);
|
||||
if (path != NULL) {
|
||||
res = coap_opt_add_string(pdu, COAP_OPT_URI_PATH, path, '/');
|
||||
}
|
||||
@ -736,7 +736,7 @@ size_t gcoap_req_send(const uint8_t *buf, size_t len,
|
||||
if ((resp_handler != NULL) || (msg_type == COAP_TYPE_CON)) {
|
||||
mutex_lock(&_coap_state.lock);
|
||||
/* Find empty slot in list of open requests. */
|
||||
for (int i = 0; i < GCOAP_REQ_WAITING_MAX; i++) {
|
||||
for (int i = 0; i < CONFIG_GCOAP_REQ_WAITING_MAX; i++) {
|
||||
if (_coap_state.open_reqs[i].state == GCOAP_MEMO_UNUSED) {
|
||||
memo = &_coap_state.open_reqs[i];
|
||||
memo->state = GCOAP_MEMO_WAIT;
|
||||
@ -757,10 +757,11 @@ size_t gcoap_req_send(const uint8_t *buf, size_t len,
|
||||
case COAP_TYPE_CON:
|
||||
/* copy buf to resend_bufs record */
|
||||
memo->msg.data.pdu_buf = NULL;
|
||||
for (int i = 0; i < GCOAP_RESEND_BUFS_MAX; i++) {
|
||||
for (int i = 0; i < CONFIG_GCOAP_RESEND_BUFS_MAX; i++) {
|
||||
if (!_coap_state.resend_bufs[i][0]) {
|
||||
memo->msg.data.pdu_buf = &_coap_state.resend_bufs[i][0];
|
||||
memcpy(memo->msg.data.pdu_buf, buf, GCOAP_PDU_BUF_SIZE);
|
||||
memcpy(memo->msg.data.pdu_buf, buf,
|
||||
CONFIG_GCOAP_PDU_BUF_SIZE);
|
||||
memo->msg.data.pdu_len = len;
|
||||
break;
|
||||
}
|
||||
@ -782,7 +783,7 @@ size_t gcoap_req_send(const uint8_t *buf, size_t len,
|
||||
case COAP_TYPE_NON:
|
||||
memo->send_limit = GCOAP_SEND_LIMIT_NON;
|
||||
memcpy(&memo->msg.hdr_buf[0], buf, GCOAP_HEADER_MAXLEN);
|
||||
timeout = GCOAP_NON_TIMEOUT;
|
||||
timeout = CONFIG_GCOAP_NON_TIMEOUT;
|
||||
break;
|
||||
default:
|
||||
memo->state = GCOAP_MEMO_UNUSED;
|
||||
@ -845,7 +846,7 @@ int gcoap_resp_init(coap_pkt_t *pdu, uint8_t *buf, size_t len, unsigned code)
|
||||
|
||||
pdu->options_len = 0;
|
||||
pdu->payload = buf + header_len;
|
||||
pdu->payload_len = len - header_len - GCOAP_RESP_OPTIONS_BUF;
|
||||
pdu->payload_len = len - header_len - CONFIG_GCOAP_RESP_OPTIONS_BUF;
|
||||
|
||||
if (coap_get_observe(pdu) == COAP_OBS_REGISTER) {
|
||||
/* generate initial notification value */
|
||||
@ -874,7 +875,7 @@ int gcoap_obs_init(coap_pkt_t *pdu, uint8_t *buf, size_t len,
|
||||
memo->token_len, COAP_CODE_CONTENT, msgid);
|
||||
|
||||
if (hdrlen > 0) {
|
||||
coap_pkt_init(pdu, buf, len - GCOAP_OBS_OPTIONS_BUF, hdrlen);
|
||||
coap_pkt_init(pdu, buf, len - CONFIG_GCOAP_OBS_OPTIONS_BUF, hdrlen);
|
||||
|
||||
uint32_t now = xtimer_now_usec();
|
||||
pdu->observe_value = (now >> GCOAP_OBS_TICK_EXPONENT) & 0xFFFFFF;
|
||||
@ -907,7 +908,7 @@ size_t gcoap_obs_send(const uint8_t *buf, size_t len,
|
||||
uint8_t gcoap_op_state(void)
|
||||
{
|
||||
uint8_t count = 0;
|
||||
for (int i = 0; i < GCOAP_REQ_WAITING_MAX; i++) {
|
||||
for (int i = 0; i < CONFIG_GCOAP_REQ_WAITING_MAX; i++) {
|
||||
if (_coap_state.open_reqs[i].state != GCOAP_MEMO_UNUSED) {
|
||||
count++;
|
||||
}
|
||||
|
||||
@ -54,36 +54,38 @@ static const char *resource_list_str = "</act/switch>,</sensor/temp>,</test/info
|
||||
/*
|
||||
* Client GET request success case. Test request generation.
|
||||
* Request /time resource from libcoap example
|
||||
* Includes token of length GCOAP_TOKENLEN.
|
||||
* Includes token of length CONFIG_GCOAP_TOKENLEN.
|
||||
*/
|
||||
static void test_gcoap__client_get_req(void)
|
||||
{
|
||||
uint8_t buf[GCOAP_PDU_BUF_SIZE];
|
||||
uint8_t buf[CONFIG_GCOAP_PDU_BUF_SIZE];
|
||||
coap_pkt_t pdu;
|
||||
size_t len;
|
||||
char path[] = "/time";
|
||||
|
||||
/* Create expected pdu_data, with token length from GCOAP_TOKENLEN. */
|
||||
/* Create expected pdu_data, with token length from CONFIG_GCOAP_TOKENLEN. */
|
||||
size_t hdr_fixed_len = 4;
|
||||
uint8_t hdr_fixed[] = { 0x52, 0x01, 0xe6, 0x02 };
|
||||
size_t options_len = 5;
|
||||
uint8_t options[] = { 0xb4, 0x74, 0x69, 0x6d, 0x65 };
|
||||
|
||||
uint8_t pdu_data[hdr_fixed_len + GCOAP_TOKENLEN + options_len];
|
||||
uint8_t pdu_data[hdr_fixed_len + CONFIG_GCOAP_TOKENLEN + options_len];
|
||||
|
||||
memcpy(&pdu_data[0], &hdr_fixed[0], hdr_fixed_len);
|
||||
#if GCOAP_TOKENLEN
|
||||
#if CONFIG_GCOAP_TOKENLEN
|
||||
/* actual value is random */
|
||||
memset(&pdu_data[hdr_fixed_len], 0x9b, GCOAP_TOKENLEN);
|
||||
memset(&pdu_data[hdr_fixed_len], 0x9b, CONFIG_GCOAP_TOKENLEN);
|
||||
#endif
|
||||
memcpy(&pdu_data[hdr_fixed_len + GCOAP_TOKENLEN], &options[0], options_len);
|
||||
memcpy(&pdu_data[hdr_fixed_len + CONFIG_GCOAP_TOKENLEN], &options[0],
|
||||
options_len);
|
||||
|
||||
len = gcoap_request(&pdu, &buf[0], GCOAP_PDU_BUF_SIZE, COAP_METHOD_GET,
|
||||
&path[0]);
|
||||
len = gcoap_request(&pdu, &buf[0], CONFIG_GCOAP_PDU_BUF_SIZE,
|
||||
COAP_METHOD_GET, &path[0]);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code(&pdu));
|
||||
TEST_ASSERT_EQUAL_INT(GCOAP_TOKENLEN, coap_get_token_len(&pdu));
|
||||
TEST_ASSERT_EQUAL_INT(hdr_fixed_len + GCOAP_TOKENLEN, coap_get_total_hdr_len(&pdu));
|
||||
TEST_ASSERT_EQUAL_INT(CONFIG_GCOAP_TOKENLEN, coap_get_token_len(&pdu));
|
||||
TEST_ASSERT_EQUAL_INT(hdr_fixed_len + CONFIG_GCOAP_TOKENLEN,
|
||||
coap_get_total_hdr_len(&pdu));
|
||||
TEST_ASSERT_EQUAL_INT(COAP_TYPE_NON, coap_get_type(&pdu));
|
||||
|
||||
char uri[NANOCOAP_URI_MAX] = {0};
|
||||
@ -100,7 +102,7 @@ static void test_gcoap__client_get_req(void)
|
||||
*/
|
||||
static void test_gcoap__client_get_resp(void)
|
||||
{
|
||||
uint8_t buf[GCOAP_PDU_BUF_SIZE];
|
||||
uint8_t buf[CONFIG_GCOAP_PDU_BUF_SIZE];
|
||||
coap_pkt_t pdu;
|
||||
int res;
|
||||
size_t hdr_fixed_len = 4;
|
||||
@ -135,13 +137,13 @@ static void test_gcoap__client_get_resp(void)
|
||||
*/
|
||||
static void test_gcoap__client_put_req(void)
|
||||
{
|
||||
uint8_t buf[GCOAP_PDU_BUF_SIZE]; /* header 4, token 2, path 11 */
|
||||
uint8_t buf[CONFIG_GCOAP_PDU_BUF_SIZE]; /* header 4, token 2, path 11 */
|
||||
coap_pkt_t pdu;
|
||||
size_t len;
|
||||
char path[] = "/riot/value";
|
||||
char payload[] = "1";
|
||||
|
||||
gcoap_req_init(&pdu, buf, GCOAP_PDU_BUF_SIZE, COAP_METHOD_PUT, path);
|
||||
gcoap_req_init(&pdu, buf, CONFIG_GCOAP_PDU_BUF_SIZE, COAP_METHOD_PUT, path);
|
||||
coap_opt_add_format(&pdu, COAP_FORMAT_TEXT);
|
||||
len = coap_opt_finish(&pdu, COAP_OPT_FINISH_PAYLOAD);
|
||||
memcpy(pdu.payload, payload, 1);
|
||||
@ -159,7 +161,7 @@ static void test_gcoap__client_put_req(void)
|
||||
static void test_gcoap__client_put_req_overfill(void)
|
||||
{
|
||||
/* header 4, token 2, path 11, format 1, marker 1 = 19 */
|
||||
uint8_t buf[18+GCOAP_REQ_OPTIONS_BUF];
|
||||
uint8_t buf[18+CONFIG_GCOAP_REQ_OPTIONS_BUF];
|
||||
coap_pkt_t pdu;
|
||||
ssize_t len;
|
||||
char path[] = "/riot/value";
|
||||
@ -180,7 +182,7 @@ static void test_gcoap__client_put_req_overfill(void)
|
||||
*/
|
||||
static void test_gcoap__client_get_query(void)
|
||||
{
|
||||
uint8_t buf[GCOAP_PDU_BUF_SIZE];
|
||||
uint8_t buf[CONFIG_GCOAP_PDU_BUF_SIZE];
|
||||
coap_pkt_t pdu;
|
||||
char path[] = "/time";
|
||||
char key1[] = "ab";
|
||||
@ -189,7 +191,7 @@ static void test_gcoap__client_get_query(void)
|
||||
char expected[] = "ab=cde&f";
|
||||
int optlen;
|
||||
|
||||
gcoap_req_init(&pdu, buf, GCOAP_PDU_BUF_SIZE, COAP_METHOD_GET, path);
|
||||
gcoap_req_init(&pdu, buf, CONFIG_GCOAP_PDU_BUF_SIZE, COAP_METHOD_GET, path);
|
||||
|
||||
optlen = gcoap_add_qstring(&pdu, key1, val1);
|
||||
TEST_ASSERT_EQUAL_INT(7, optlen);
|
||||
@ -212,18 +214,19 @@ static void test_gcoap__client_get_query(void)
|
||||
*/
|
||||
static void test_gcoap__client_get_path_defer(void)
|
||||
{
|
||||
uint8_t buf[GCOAP_PDU_BUF_SIZE];
|
||||
uint8_t buf[CONFIG_GCOAP_PDU_BUF_SIZE];
|
||||
coap_pkt_t pdu;
|
||||
size_t len, optlen;
|
||||
char path[] = "/time";
|
||||
|
||||
gcoap_req_init(&pdu, buf, GCOAP_PDU_BUF_SIZE, COAP_METHOD_GET, NULL);
|
||||
gcoap_req_init(&pdu, buf, CONFIG_GCOAP_PDU_BUF_SIZE, COAP_METHOD_GET, NULL);
|
||||
coap_opt_add_uint(&pdu, COAP_OPT_OBSERVE, 0);
|
||||
coap_opt_add_string(&pdu, COAP_OPT_URI_PATH, path, '/');
|
||||
optlen = 6;
|
||||
|
||||
len = coap_opt_finish(&pdu, COAP_OPT_FINISH_NONE);
|
||||
TEST_ASSERT_EQUAL_INT(len, sizeof(coap_hdr_t) + GCOAP_TOKENLEN + optlen);
|
||||
TEST_ASSERT_EQUAL_INT(len,
|
||||
sizeof(coap_hdr_t) + CONFIG_GCOAP_TOKENLEN +optlen);
|
||||
|
||||
coap_parse(&pdu, buf, len);
|
||||
|
||||
@ -255,7 +258,7 @@ static int _read_cli_stats_req(coap_pkt_t *pdu, uint8_t *buf)
|
||||
/* Server GET request success case. Validate request example. */
|
||||
static void test_gcoap__server_get_req(void)
|
||||
{
|
||||
uint8_t buf[GCOAP_PDU_BUF_SIZE];
|
||||
uint8_t buf[CONFIG_GCOAP_PDU_BUF_SIZE];
|
||||
coap_pkt_t pdu;
|
||||
|
||||
int res = _read_cli_stats_req(&pdu, &buf[0]);
|
||||
@ -278,7 +281,7 @@ static void test_gcoap__server_get_req(void)
|
||||
*/
|
||||
static void test_gcoap__server_get_resp(void)
|
||||
{
|
||||
uint8_t buf[GCOAP_PDU_BUF_SIZE];
|
||||
uint8_t buf[CONFIG_GCOAP_PDU_BUF_SIZE];
|
||||
coap_pkt_t pdu;
|
||||
|
||||
/* read request */
|
||||
@ -327,7 +330,7 @@ static int _read_cli_stats_req_con(coap_pkt_t *pdu, uint8_t *buf)
|
||||
/* Server CON GET request success case. Validate request is confirmable. */
|
||||
static void test_gcoap__server_con_req(void)
|
||||
{
|
||||
uint8_t buf[GCOAP_PDU_BUF_SIZE];
|
||||
uint8_t buf[CONFIG_GCOAP_PDU_BUF_SIZE];
|
||||
coap_pkt_t pdu;
|
||||
|
||||
int res = _read_cli_stats_req_con(&pdu, &buf[0]);
|
||||
@ -343,7 +346,7 @@ static void test_gcoap__server_con_req(void)
|
||||
*/
|
||||
static void test_gcoap__server_con_resp(void)
|
||||
{
|
||||
uint8_t buf[GCOAP_PDU_BUF_SIZE];
|
||||
uint8_t buf[CONFIG_GCOAP_PDU_BUF_SIZE];
|
||||
coap_pkt_t pdu;
|
||||
|
||||
/* read request */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user