diff --git a/examples/nanocoap_server/coap_handler.c b/examples/nanocoap_server/coap_handler.c index f777dab9c0e7..e4a1a40d1501 100644 --- a/examples/nanocoap_server/coap_handler.c +++ b/examples/nanocoap_server/coap_handler.c @@ -10,14 +10,17 @@ #include #include -#include "event/callback.h" -#include "event/timeout.h" -#include "event/thread.h" #include "fmt.h" #include "net/nanocoap.h" #include "net/nanocoap_sock.h" #include "hashes/sha256.h" -#include "kernel_defines.h" + +#if MODULE_EVENT_THREAD +# include "event.h" +# include "event/thread.h" +# include "event/timeout.h" +# include "event/callback.h" +#endif /* internal value that can be read/written via CoAP */ static uint8_t internal_value = 0; @@ -158,7 +161,7 @@ ssize_t _sha256_handler(coap_pkt_t* pkt, uint8_t *buf, size_t len, coap_request_ 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); } @@ -167,7 +170,7 @@ ssize_t _sha256_handler(coap_pkt_t* pkt, uint8_t *buf, size_t len, coap_request_ 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) { diff --git a/tests/net/nanocoap_cli/nanocli_client.c b/tests/net/nanocoap_cli/nanocli_client.c index 3266c69055d0..a64d1369b867 100644 --- a/tests/net/nanocoap_cli/nanocli_client.c +++ b/tests/net/nanocoap_cli/nanocli_client.c @@ -25,7 +25,6 @@ #include "net/coap.h" #include "net/gnrc/netif.h" -#include "net/ipv6.h" #include "net/nanocoap.h" #include "net/nanocoap_sock.h" #include "net/sock/udp.h" @@ -85,8 +84,7 @@ int nanotest_client_cmd(int argc, char **argv) { /* Ordered like the RFC method code numbers, but off by 1. GET is code 0. */ const char *method_codes[] = {"get", "post", "put"}; - unsigned buflen = 128; - uint8_t buf[buflen]; + uint8_t buf[128]; coap_pkt_t pkt; size_t len; uint8_t token[2] = {0xDA, 0xEC}; @@ -106,13 +104,13 @@ int nanotest_client_cmd(int argc, char **argv) goto end; } - pkt.hdr = (coap_hdr_t *)buf; + pkt.buf = buf; /* parse options */ if (argc == 5 || argc == 6) { - ssize_t hdrlen = coap_build_hdr(pkt.hdr, COAP_TYPE_CON, &token[0], 2, + ssize_t hdrlen = coap_build_udp_hdr(buf, sizeof(buf), COAP_TYPE_CON, &token[0], 2, code_pos+1, 1); - coap_pkt_init(&pkt, &buf[0], buflen, hdrlen); + coap_pkt_init(&pkt, &buf[0], sizeof(buf), hdrlen); coap_opt_add_string(&pkt, COAP_OPT_URI_PATH, argv[4], '/'); if (argc == 6) { coap_opt_add_uint(&pkt, COAP_OPT_CONTENT_FORMAT, COAP_FORMAT_TEXT); @@ -129,7 +127,7 @@ int nanotest_client_cmd(int argc, char **argv) printf("nanocli: sending msg ID %u, %" PRIuSIZE " bytes\n", coap_get_id(&pkt), len); - ssize_t res = _send(&pkt, buflen, argv[2], argv[3]); + ssize_t res = _send(&pkt, sizeof(buf), argv[2], argv[3]); if (res < 0) { printf("nanocli: msg send failed: %" PRIdSIZE "\n", res); } diff --git a/tests/pkg/edhoc_c/initiator.c b/tests/pkg/edhoc_c/initiator.c index c0597ef3751f..9e8301a7eb8e 100644 --- a/tests/pkg/edhoc_c/initiator.c +++ b/tests/pkg/edhoc_c/initiator.c @@ -20,9 +20,7 @@ #include #include "net/gnrc/netif.h" -#include "net/ipv6.h" #include "net/nanocoap_sock.h" -#include "shell.h" #include "edhoc/edhoc.h" #include "edhoc_keys.h" @@ -33,9 +31,6 @@ #include "tinycrypt/sha256.h" #endif -#define ENABLE_DEBUG 0 -#include "debug.h" - #define COAP_BUF_SIZE (256U) #if IS_ACTIVE(CONFIG_INITIATOR) @@ -114,11 +109,9 @@ static ssize_t _build_coap_pkt(coap_pkt_t *pkt, uint8_t *buf, ssize_t buflen, uint8_t token[2] = { 0xDA, 0xEC }; ssize_t len = 0; - /* set pkt buffer */ - pkt->hdr = (coap_hdr_t *)buf; /* build header, confirmed message always post */ - ssize_t hdrlen = coap_build_hdr(pkt->hdr, COAP_TYPE_CON, token, - sizeof(token), COAP_METHOD_POST, 1); + ssize_t hdrlen = coap_build_udp_hdr(buf, buflen, COAP_TYPE_CON, token, + sizeof(token), COAP_METHOD_POST, 1); coap_pkt_init(pkt, buf, buflen, hdrlen); coap_opt_add_string(pkt, COAP_OPT_URI_PATH, "/.well-known/edhoc", '/'); diff --git a/tests/riotboot_flashwrite/coap_handler.c b/tests/riotboot_flashwrite/coap_handler.c index 12a09de83916..e721ffa87c6c 100644 --- a/tests/riotboot_flashwrite/coap_handler.c +++ b/tests/riotboot_flashwrite/coap_handler.c @@ -8,7 +8,6 @@ #include #include -#include #include "net/nanocoap.h" #include "riotboot/flashwrite.h" @@ -72,10 +71,10 @@ ssize_t _flashwrite_handler(coap_pkt_t* pkt, uint8_t *buf, size_t len, coap_requ return reply_len; } - uint8_t *pkt_pos = (uint8_t*)pkt->hdr + reply_len; + uint8_t *pkt_pos = pkt->buf + reply_len; pkt_pos += coap_put_block1_ok(pkt_pos, &block1, 0); - return pkt_pos - (uint8_t*)pkt->hdr; + return pkt_pos - pkt->buf; } NANOCOAP_RESOURCE(flashwrite) {