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