Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions examples/networking/coap/gcoap/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,16 @@ static void _resp_handler(const gcoap_request_memo_t *memo, coap_pkt_t* pdu,
uri_parser_result_t urip;
uri_parser_process(&urip, _last_req_uri, strlen(_last_req_uri));
if (*_proxy_uri) {
gcoap_req_init(pdu, (uint8_t *)pdu->hdr, CONFIG_GCOAP_PDU_BUF_SIZE,
gcoap_req_init(pdu, pdu->buf, CONFIG_GCOAP_PDU_BUF_SIZE,
COAP_METHOD_GET, NULL);
}
else {
gcoap_req_init(pdu, (uint8_t *)pdu->hdr, CONFIG_GCOAP_PDU_BUF_SIZE,
gcoap_req_init(pdu, pdu->buf, CONFIG_GCOAP_PDU_BUF_SIZE,
COAP_METHOD_GET, urip.path);
}

if (msg_type == COAP_TYPE_ACK) {
coap_hdr_set_type(pdu->hdr, COAP_TYPE_CON);
coap_pkt_set_type(pdu, COAP_TYPE_CON);
}
block.blknum++;
coap_opt_add_block2_control(pdu, &block);
Expand All @@ -151,7 +151,7 @@ static void _resp_handler(const gcoap_request_memo_t *memo, coap_pkt_t* pdu,

int len = coap_opt_finish(pdu, COAP_OPT_FINISH_NONE);
gcoap_socket_type_t tl = _get_tl(*_proxy_uri ? _proxy_uri : _last_req_uri);
_send((uint8_t *)pdu->hdr, len, remote, memo->context, tl);
_send(pdu->buf, len, remote, memo->context, tl);
}
else {
puts("--- blockwise complete ---");
Expand Down Expand Up @@ -338,7 +338,7 @@ static int _cli_cmd(int argc, char **argv)
}
}

coap_hdr_set_type(pdu.hdr, msg_type);
coap_pkt_set_type(&pdu, msg_type);

size_t paylen = 0;
if (apos < argc) {
Expand Down
2 changes: 1 addition & 1 deletion examples/networking/coap/gcoap/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
static ssize_t _encode_link(const coap_resource_t *resource, char *buf,
size_t maxlen, coap_link_encoder_ctx_t *context);
static ssize_t _stats_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, coap_request_ctx_t *ctx);
static ssize_t _riot_board_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, coap_request_ctx_t *ctx);

Check warning on line 65 in examples/networking/coap/gcoap/server.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
#if IS_USED(MODULE_PERIPH_RTC)
static ssize_t _rtc_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, coap_request_ctx_t *ctx);
#endif
Expand Down Expand Up @@ -119,7 +119,7 @@
}
size_t len;
char str_time[20] = "";
uint8_t buf[sizeof(coap_hdr_t) + COAP_TOKEN_LENGTH_MAX + 1 + sizeof(str_time)];
uint8_t buf[sizeof(coap_udp_hdr_t) + COAP_TOKEN_LENGTH_MAX + 1 + sizeof(str_time)];
coap_pkt_t pdu;
const coap_resource_t *rtc_resource = NULL;
const gcoap_listener_t *listener = NULL;
Expand All @@ -132,7 +132,7 @@
switch (gcoap_obs_init(&pdu, buf, sizeof(buf), rtc_resource)) {
case GCOAP_OBS_INIT_OK:
len = coap_opt_finish(&pdu, COAP_OPT_FINISH_PAYLOAD);
memcpy(pdu.payload, str_time, strftime(str_time, sizeof(str_time), "%Y-%m-%d %H:%M:%S", &tm_now));

Check warning on line 135 in examples/networking/coap/gcoap/server.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
pdu.payload_len = strlen(str_time);
len += pdu.payload_len;
if (!gcoap_obs_send(buf, len, rtc_resource)) {
Expand All @@ -157,7 +157,7 @@
gcoap_resp_init(pdu, buf, len, COAP_CODE_CONTENT);
size_t resp_len = coap_opt_finish(pdu, COAP_OPT_FINISH_PAYLOAD);
char str_time[20] = "";
memcpy(pdu->payload, str_time, strftime(str_time, sizeof(str_time), "%Y-%m-%d %H:%M:%S", &tm_now));

Check warning on line 160 in examples/networking/coap/gcoap/server.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
pdu->payload_len = strlen(str_time);
resp_len += pdu->payload_len;
return resp_len;
Expand Down Expand Up @@ -206,7 +206,7 @@
return 0;
}

static ssize_t _riot_board_handler(coap_pkt_t *pdu, uint8_t *buf, size_t len, coap_request_ctx_t *ctx)

Check warning on line 209 in examples/networking/coap/gcoap/server.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
{
(void)ctx;
gcoap_resp_init(pdu, buf, len, COAP_CODE_CONTENT);
Expand Down Expand Up @@ -268,7 +268,7 @@
gcoap_register_listener(&_listener);
#if IS_USED(MODULE_PERIPH_RTC)
static event_periodic_callback_t _ev_pcb_rtc;
event_periodic_callback_init(&_ev_pcb_rtc, ZTIMER_MSEC, EVENT_PRIO_MEDIUM, _rtc_notify_observers, NULL);

Check warning on line 271 in examples/networking/coap/gcoap/server.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
event_periodic_callback_start(&_ev_pcb_rtc, 10 * MS_PER_SEC);
#endif
}
10 changes: 5 additions & 5 deletions examples/networking/coap/gcoap_dtls/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,16 @@ static void _resp_handler(const gcoap_request_memo_t *memo, coap_pkt_t* pdu,
uri_parser_result_t urip;
uri_parser_process(&urip, _last_req_uri, strlen(_last_req_uri));
if (*_proxy_uri) {
gcoap_req_init(pdu, (uint8_t *)pdu->hdr, CONFIG_GCOAP_PDU_BUF_SIZE,
gcoap_req_init(pdu, pdu->buf, CONFIG_GCOAP_PDU_BUF_SIZE,
COAP_METHOD_GET, NULL);
}
else {
gcoap_req_init(pdu, (uint8_t *)pdu->hdr, CONFIG_GCOAP_PDU_BUF_SIZE,
gcoap_req_init(pdu, pdu->buf, CONFIG_GCOAP_PDU_BUF_SIZE,
COAP_METHOD_GET, urip.path);
}

if (msg_type == COAP_TYPE_ACK) {
coap_hdr_set_type(pdu->hdr, COAP_TYPE_CON);
coap_pkt_set_type(pdu, COAP_TYPE_CON);
}
block.blknum++;
coap_opt_add_block2_control(pdu, &block);
Expand All @@ -151,7 +151,7 @@ static void _resp_handler(const gcoap_request_memo_t *memo, coap_pkt_t* pdu,

int len = coap_opt_finish(pdu, COAP_OPT_FINISH_NONE);
gcoap_socket_type_t tl = _get_tl(*_proxy_uri ? _proxy_uri : _last_req_uri);
_send((uint8_t *)pdu->hdr, len, remote, memo->context, tl);
_send(pdu->buf, len, remote, memo->context, tl);
}
else {
puts("--- blockwise complete ---");
Expand Down Expand Up @@ -344,7 +344,7 @@ static int _cli_cmd(int argc, char **argv)
}
}

coap_hdr_set_type(pdu.hdr, msg_type);
coap_pkt_set_type(&pdu, msg_type);

size_t paylen = 0;
if (apos < argc) {
Expand Down
6 changes: 3 additions & 3 deletions examples/networking/coap/nanocoap_server/coap_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#include "event/thread.h"
#include "event/timeout.h"
#include "fmt.h"
#include "hashes/sha256.h"
#include "net/nanocoap.h"
#include "net/nanocoap_sock.h"
#include "hashes/sha256.h"

/* internal value that can be read/written via CoAP */
static uint8_t internal_value = 0;
Expand All @@ -38,14 +38,14 @@
(uint8_t *)sub_uri, sub_uri_len);
}

static ssize_t _riot_board_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len, coap_request_ctx_t *context)

Check warning on line 41 in examples/networking/coap/nanocoap_server/coap_handler.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
{
(void)context;
return coap_reply_simple(pkt, COAP_CODE_205, buf, len,
COAP_FORMAT_TEXT, (uint8_t*)RIOT_BOARD, strlen(RIOT_BOARD));
}

static ssize_t _riot_block2_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len, coap_request_ctx_t *context)

Check warning on line 48 in examples/networking/coap/nanocoap_server/coap_handler.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
{
(void)context;
coap_block_slicer_t slicer;
Expand All @@ -60,7 +60,7 @@

/* Add actual content */
bufpos += coap_blockwise_put_bytes(&slicer, bufpos, block2_intro, sizeof(block2_intro)-1);
bufpos += coap_blockwise_put_bytes(&slicer, bufpos, (uint8_t*)RIOT_VERSION, strlen(RIOT_VERSION));

Check warning on line 63 in examples/networking/coap/nanocoap_server/coap_handler.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
bufpos += coap_blockwise_put_char(&slicer, bufpos, ')');
bufpos += coap_blockwise_put_bytes(&slicer, bufpos, block2_board, sizeof(block2_board)-1);
bufpos += coap_blockwise_put_bytes(&slicer, bufpos, (uint8_t*)RIOT_BOARD, strlen(RIOT_BOARD));
Expand Down Expand Up @@ -155,7 +155,7 @@
return reply_len;
}

uint8_t *pkt_pos = (uint8_t*)pkt->hdr + reply_len;
uint8_t *pkt_pos = pkt->buf + reply_len;
if (blockwise) {
pkt_pos += coap_opt_put_block1_control(pkt_pos, 0, &block1);
}
Expand All @@ -164,7 +164,7 @@
pkt_pos += fmt_bytes_hex((char *)pkt_pos, digest, sizeof(digest));
}

return pkt_pos - (uint8_t*)pkt->hdr;
return pkt_pos - pkt->buf;
}

NANOCOAP_RESOURCE(echo) {
Expand All @@ -174,7 +174,7 @@
.path = "/riot/board", .methods = COAP_GET, .handler = _riot_board_handler
};
NANOCOAP_RESOURCE(value) {
.path = "/riot/value", .methods = COAP_GET | COAP_PUT | COAP_POST, .handler = _riot_value_handler

Check warning on line 177 in examples/networking/coap/nanocoap_server/coap_handler.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
};
NANOCOAP_RESOURCE(ver) {
.path = "/riot/ver", .methods = COAP_GET, .handler = _riot_block2_handler
Expand All @@ -196,7 +196,7 @@
response, sizeof(response));
}

static ssize_t _separate_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len, coap_request_ctx_t *context)

Check warning on line 199 in examples/networking/coap/nanocoap_server/coap_handler.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
{
static event_timeout_t event_timeout;
static event_callback_t event_timed = EVENT_CALLBACK_INIT(_send_response, &_separate_ctx);
Expand Down
Binary file added examples/wasm/hello.wasm
Binary file not shown.
38 changes: 27 additions & 11 deletions sys/include/net/gcoap.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,14 +400,15 @@

#include "event/callback.h"
#include "event/timeout.h"
#include "net/ipv6/addr.h"
#include "net/sock/udp.h"
#include "net/nanocoap.h"

#if IS_USED(MODULE_GCOAP_DTLS)
#include "net/sock/dtls.h"
# include "net/sock/dtls.h"
#endif
#if IS_USED(MODULE_NANOCOAP_CACHE)
# include "net/nanocoap/cache.h"
#endif
#include "net/nanocoap.h"
#include "net/nanocoap/cache.h"
#include "timex.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -479,7 +480,7 @@ extern "C" {
/**
* @brief Maximum length in bytes for a header, including the token
*/
#define GCOAP_HEADER_MAXLEN (sizeof(coap_hdr_t) + GCOAP_TOKENLEN_MAX)
#define GCOAP_HEADER_MAXLEN (sizeof(coap_udp_hdr_t) + GCOAP_TOKENLEN_MAX)

/**
* @ingroup net_gcoap_conf
Expand Down Expand Up @@ -1188,22 +1189,37 @@ sock_dtls_t *gcoap_get_sock_dtls(void);
#endif

/**
* @brief Get the header of a request from a @ref gcoap_request_memo_t
* @brief Get the buffer from a @ref gcoap_request_memo_t
*
* @param[in] memo A request memo. Must not be NULL.
*
* @return The request header for the given request memo.
* @return The buffer storing the message
*/
static inline coap_hdr_t *gcoap_request_memo_get_hdr(const gcoap_request_memo_t *memo)
static inline uint8_t *gcoap_request_memo_get_buf(gcoap_request_memo_t *memo)
{
if (memo->send_limit == GCOAP_SEND_LIMIT_NON) {
return (coap_hdr_t *)&memo->msg.hdr_buf[0];
return &memo->msg.hdr_buf[0];
}
else {
return (coap_hdr_t *)memo->msg.data.pdu_buf;
return memo->msg.data.pdu_buf;
}
}

/**
* @brief Get the header of a request from a @ref gcoap_request_memo_t
*
* @param[in] memo A request memo. Must not be NULL.
*
* @return The request header for the given request memo.
*
* @deprecated Use @ref gcoap_request_memo_get_buf instead
*/
static inline coap_udp_hdr_t *gcoap_request_memo_get_hdr(const gcoap_request_memo_t *memo)
{
gcoap_request_memo_t *evil_cast_is_evil = (gcoap_request_memo_t *)memo;
return (coap_udp_hdr_t *)gcoap_request_memo_get_buf(evil_cast_is_evil);
}

#ifdef __cplusplus
}
#endif
Expand Down
Loading
Loading