From f0b0e252543a868a63b774f66dc7a26b0385d5a8 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Mon, 15 Oct 2018 09:49:00 +0200 Subject: [PATCH 1/8] net/rdcli: new module structure and high-level doc --- sys/Makefile | 6 +- .../{rdcli_common => cord/common}/Makefile | 2 + .../common}/rdcli_common.c | 0 sys/net/application_layer/cord/doc.txt | 65 +++++++++++++++++++ .../{rdcli => cord/ep}/Makefile | 2 + .../{rdcli => cord/ep}/rdcli.c | 0 .../{rdcli => cord/ep}/rdcli_standalone.c | 0 .../{rdcli_simple => cord/epsim}/Makefile | 2 + .../epsim}/rdcli_simple.c | 0 .../epsim}/rdcli_simple_standalone.c | 0 10 files changed, 74 insertions(+), 3 deletions(-) rename sys/net/application_layer/{rdcli_common => cord/common}/Makefile (59%) rename sys/net/application_layer/{rdcli_common => cord/common}/rdcli_common.c (100%) create mode 100644 sys/net/application_layer/cord/doc.txt rename sys/net/application_layer/{rdcli => cord/ep}/Makefile (89%) rename sys/net/application_layer/{rdcli => cord/ep}/rdcli.c (100%) rename sys/net/application_layer/{rdcli => cord/ep}/rdcli_standalone.c (100%) rename sys/net/application_layer/{rdcli_simple => cord/epsim}/Makefile (87%) rename sys/net/application_layer/{rdcli_simple => cord/epsim}/rdcli_simple.c (100%) rename sys/net/application_layer/{rdcli_simple => cord/epsim}/rdcli_simple_standalone.c (100%) diff --git a/sys/Makefile b/sys/Makefile index 9d63db742c..871f33f26c 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -128,13 +128,13 @@ ifneq (,$(filter skald,$(USEMODULE))) DIRS += net/skald endif ifneq (,$(filter rdcli_common,$(USEMODULE))) - DIRS += net/application_layer/rdcli_common + DIRS += net/application_layer/cord/common endif ifneq (,$(filter rdcli_simple,$(USEMODULE))) - DIRS += net/application_layer/rdcli_simple + DIRS += net/application_layer/cord/epsim endif ifneq (,$(filter rdcli,$(USEMODULE))) - DIRS += net/application_layer/rdcli + DIRS += net/application_layer/cord/ep endif diff --git a/sys/net/application_layer/rdcli_common/Makefile b/sys/net/application_layer/cord/common/Makefile similarity index 59% rename from sys/net/application_layer/rdcli_common/Makefile rename to sys/net/application_layer/cord/common/Makefile index 48422e909a..6ac70df22b 100644 --- a/sys/net/application_layer/rdcli_common/Makefile +++ b/sys/net/application_layer/cord/common/Makefile @@ -1 +1,3 @@ +MODULE = rdcli_common + include $(RIOTBASE)/Makefile.base diff --git a/sys/net/application_layer/rdcli_common/rdcli_common.c b/sys/net/application_layer/cord/common/rdcli_common.c similarity index 100% rename from sys/net/application_layer/rdcli_common/rdcli_common.c rename to sys/net/application_layer/cord/common/rdcli_common.c diff --git a/sys/net/application_layer/cord/doc.txt b/sys/net/application_layer/cord/doc.txt new file mode 100644 index 0000000000..c136144d3a --- /dev/null +++ b/sys/net/application_layer/cord/doc.txt @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2018 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup net_cord CoRE RD Endpoint and Lookup Client + * @ingroup net + * @brief Library for interacting as endpoint and lookup client with CoRE + * Resource Directories + * + * # About + * The `cord` ([Co]RE [R]esource [D]irectory) module provides endpoint and + * lookup client functionality for interacting with CoRE Resource Directories + * (RDs) as defined in `draft-ietf-core-resource-directory-15`. + * + * @see https://tools.ietf.org/html/draft-ietf-core-resource-directory-15 + * + * `draft-ietf-core-resource-directory-15` defines two types different roles for + * nodes when interacting with a RD: + * - `endpoint`: registers and manages entries at the RD + * - `client`: performs different kind of lookups + * + * ``` + * Registration Lookup, Group + * Interface Interfaces + * +----+ | | + * | EP |---- | | + * +----+ ---- | | + * --|- +------+ | + * +----+ | ----| | | +--------+ + * | EP | ---------|-----| RD |----|-----| Client | + * +----+ | ----| | | +--------+ + * --|- +------+ | + * +----+ ---- | | + * | EP |---- | | + * +----+ + * ``` + * Figure copied form `draft-ietf-core-resource-directory-15`. + * + * @note In the context of this module, we refer to these roles as `endpoint + * (ep)` and `lookup client (lc)`. This should hopefully prevent some + * confusion in conjunction with the `client` and `server` roles as + * defined by CoAP. + * + * # Structure + * + * This module is structured in a number of submodules with goal to reflect the + * different roles described in `draft-ietf-core-resource-directory-15`: + * + * - `cord_ep`: standard endpoint implementation following the rules as + * defined i.a. in sections 5.2, 5.3, A.1, and A.2 + * - `cord_epsim`: endpoint implementation following the simple registration + * procedure as defined in section 5.3.1 + * - `cord_lc`: lookup client implementation for querying information from + * an RD using the lookup and group interfaces (**NOT + * YET IMPLEMENTED**) + * - `cord_config`: header file collection (default) configuration values used + * throughout this module + * - `cord_common`: shared functionality used by the above submodules + * + */ diff --git a/sys/net/application_layer/rdcli/Makefile b/sys/net/application_layer/cord/ep/Makefile similarity index 89% rename from sys/net/application_layer/rdcli/Makefile rename to sys/net/application_layer/cord/ep/Makefile index 3b2e7e88b2..885829de20 100644 --- a/sys/net/application_layer/rdcli/Makefile +++ b/sys/net/application_layer/cord/ep/Makefile @@ -1,3 +1,5 @@ +MODULE = rdcli + SRC = rdcli.c ifneq (,$(filter rdcli_standalone,$(USEMODULE))) diff --git a/sys/net/application_layer/rdcli/rdcli.c b/sys/net/application_layer/cord/ep/rdcli.c similarity index 100% rename from sys/net/application_layer/rdcli/rdcli.c rename to sys/net/application_layer/cord/ep/rdcli.c diff --git a/sys/net/application_layer/rdcli/rdcli_standalone.c b/sys/net/application_layer/cord/ep/rdcli_standalone.c similarity index 100% rename from sys/net/application_layer/rdcli/rdcli_standalone.c rename to sys/net/application_layer/cord/ep/rdcli_standalone.c diff --git a/sys/net/application_layer/rdcli_simple/Makefile b/sys/net/application_layer/cord/epsim/Makefile similarity index 87% rename from sys/net/application_layer/rdcli_simple/Makefile rename to sys/net/application_layer/cord/epsim/Makefile index 997bf2fc80..db17736b3c 100644 --- a/sys/net/application_layer/rdcli_simple/Makefile +++ b/sys/net/application_layer/cord/epsim/Makefile @@ -1,3 +1,5 @@ +MODULE = rdcli_simple + SRC = rdcli_simple.c ifneq (,$(filter rdcli_simple_standalone,$(USEMODULE))) diff --git a/sys/net/application_layer/rdcli_simple/rdcli_simple.c b/sys/net/application_layer/cord/epsim/rdcli_simple.c similarity index 100% rename from sys/net/application_layer/rdcli_simple/rdcli_simple.c rename to sys/net/application_layer/cord/epsim/rdcli_simple.c diff --git a/sys/net/application_layer/rdcli_simple/rdcli_simple_standalone.c b/sys/net/application_layer/cord/epsim/rdcli_simple_standalone.c similarity index 100% rename from sys/net/application_layer/rdcli_simple/rdcli_simple_standalone.c rename to sys/net/application_layer/cord/epsim/rdcli_simple_standalone.c From 787524400c2fbe83d375abe068606ba4fa3f8993 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Mon, 15 Oct 2018 10:05:33 +0200 Subject: [PATCH 2/8] net/rdcli_common: rename to cord_common --- Makefile.dep | 6 ++-- examples/rdcli/main.c | 4 +-- examples/rdcli_simple/main.c | 6 ++-- sys/Makefile | 2 +- sys/auto_init/auto_init.c | 8 ++--- .../net/{rdcli_common.h => cord/common.h} | 34 +++++++++---------- .../application_layer/cord/common/Makefile | 2 +- .../common/{rdcli_common.c => cord_common.c} | 20 +++++------ sys/net/application_layer/cord/ep/rdcli.c | 6 ++-- .../cord/epsim/rdcli_simple.c | 4 +-- sys/shell/commands/sc_rdcli.c | 1 - 11 files changed, 46 insertions(+), 47 deletions(-) rename sys/include/net/{rdcli_common.h => cord/common.h} (53%) rename sys/net/application_layer/cord/common/{rdcli_common.c => cord_common.c} (75%) diff --git a/Makefile.dep b/Makefile.dep index b38bd61472..943e6f4fb5 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -755,7 +755,7 @@ ifneq (,$(filter rdcli_simple_standalone,$(USEMODULE))) endif ifneq (,$(filter rdcli_simple,$(USEMODULE))) - USEMODULE += rdcli_common + USEMODULE += cord_common USEMODULE += fmt endif @@ -765,7 +765,7 @@ ifneq (,$(filter rdcli_standalone,$(USEMODULE))) endif ifneq (,$(filter rdcli,$(USEMODULE))) - USEMODULE += rdcli_common + USEMODULE += cord_common USEMODULE += core_thread_flags USEMODULE += gcoap USEMODULE += fmt @@ -774,7 +774,7 @@ ifneq (,$(filter rdcli,$(USEMODULE))) endif endif -ifneq (,$(filter rdcli_common,$(USEMODULE))) +ifneq (,$(filter cord_common,$(USEMODULE))) USEMODULE += fmt USEMODULE += gcoap USEMODULE += luid diff --git a/examples/rdcli/main.c b/examples/rdcli/main.c index f60f794a96..4d00e6d885 100644 --- a/examples/rdcli/main.c +++ b/examples/rdcli/main.c @@ -24,7 +24,7 @@ #include "shell.h" #include "net/ipv6/addr.h" #include "net/gcoap.h" -#include "net/rdcli_common.h" +#include "net/cord/common.h" #include "net/rdcli_standalone.h" #define MAIN_QUEUE_SIZE (8) @@ -98,7 +98,7 @@ int main(void) rdcli_standalone_reg_cb(_on_rdcli_event); puts("Client information:"); - printf(" ep: %s\n", rdcli_common_get_ep()); + printf(" ep: %s\n", cord_common_get_ep()); printf(" lt: %is\n", (int)RDCLI_LT); char line_buf[SHELL_DEFAULT_BUFSIZE]; diff --git a/examples/rdcli_simple/main.c b/examples/rdcli_simple/main.c index 5931e64376..24726dcd21 100644 --- a/examples/rdcli_simple/main.c +++ b/examples/rdcli_simple/main.c @@ -23,7 +23,7 @@ #include "shell.h" #include "net/gcoap.h" -#include "net/rdcli_common.h" +#include "net/cord/common.h" #define BUFSIZE (64U) @@ -68,7 +68,7 @@ int main(void) /* fill riot info */ sprintf(riot_info, "{\"ep\":\"%s\",\"lt\":%u}", - rdcli_common_get_ep(), RDCLI_LT); + cord_common_get_ep(), RDCLI_LT); /* register resource handlers with gcoap */ gcoap_register_listener(&listener); @@ -77,7 +77,7 @@ int main(void) puts("RD client information:"); printf(" RD addr: %s\n", RDCLI_SERVER_ADDR); printf(" RD port: %u\n", (unsigned)RDCLI_SERVER_PORT); - printf(" ep: %s\n", rdcli_common_get_ep()); + printf(" ep: %s\n", cord_common_get_ep()); printf(" lt: %is\n", (int)RDCLI_LT); /* run the shell */ diff --git a/sys/Makefile b/sys/Makefile index 871f33f26c..5cefa1c6e1 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -127,7 +127,7 @@ endif ifneq (,$(filter skald,$(USEMODULE))) DIRS += net/skald endif -ifneq (,$(filter rdcli_common,$(USEMODULE))) +ifneq (,$(filter cord_common,$(USEMODULE))) DIRS += net/application_layer/cord/common endif ifneq (,$(filter rdcli_simple,$(USEMODULE))) diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index fd8398807b..ed815aa8ba 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -158,10 +158,10 @@ void auto_init(void) DEBUG("Auto init Skald\n"); skald_init(); #endif -#ifdef MODULE_RDCLI_COMMON - DEBUG("Auto init rdcli_common module\n"); - extern void rdcli_common_init(void); - rdcli_common_init(); +#ifdef MODULE_CORD_COMMON + DEBUG("Auto init cord_common module\n"); + extern void cord_common_init(void); + cord_common_init(); #endif #ifdef MODULE_RDCLI_STANDALONE DEBUG("Auto init rdcli_standalone\n"); diff --git a/sys/include/net/rdcli_common.h b/sys/include/net/cord/common.h similarity index 53% rename from sys/include/net/rdcli_common.h rename to sys/include/net/cord/common.h index e3654f70fd..ee5864f5f4 100644 --- a/sys/include/net/rdcli_common.h +++ b/sys/include/net/cord/common.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Freie Universität Berlin + * Copyright (C) 2017,2018 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -7,19 +7,19 @@ */ /** - * @defgroup net_rdcli_common CoRE RD Client Common - * @ingroup net - * @brief Shared functionality for CoRE Resource Directory clients + * @defgroup net_cord_common CoRE RD Common + * @ingroup net_cord + * @brief Shared functionality for CoRE Resource Directory endpoints * @{ * * @file - * @brief Shared CoRE RD client functions + * @brief Shared CoRE RD endpoint functions * * @author Hauke Petersen */ -#ifndef NET_RDCLI_COMMON_H -#define NET_RDCLI_COMMON_H +#ifndef NET_CORD_COMMON_H +#define NET_CORD_COMMON_H #include "net/rdcli_config.h" @@ -30,39 +30,39 @@ extern "C" { /** * @brief Export the local endpoint identifier * - * @note Use rdcli_common_get_ep() for accessing the endpoint identifier + * @note Use cord_common_get_ep() for accessing the endpoint identifier */ -extern char rdcli_ep[]; +extern char cord_common_ep[]; /** * @brief Generate unique endpoint identifier (ep) */ -void rdcli_common_init(void); +void cord_common_init(void); /** * @brief Get the local endpoint identifier */ -static inline const char *rdcli_common_get_ep(void) +static inline const char *cord_common_get_ep(void) { - return (const char *)rdcli_ep; + return (const char *)cord_common_ep; } /** * @brief Add selected query string options to a gcoap request * * This function adds: - * - `ep` -> as extracted by rdcli_commont_get_ep() - * - [optional] `lt` -> if defined by RDCLI_LT - * - [optional] 'd' -> if defined by RDCLI_D + * - `ep` -> as extracted by cord_common_get_ep() + * - [optional] `lt` -> if defined by CORD_LT + * - [optional] 'd' -> if defined by CORD_D * * @return 0 on success * @return <0 on error */ -int rdcli_common_add_qstring(coap_pkt_t *pkt); +int cord_common_add_qstring(coap_pkt_t *pkt); #ifdef __cplusplus } #endif -#endif /* NET_RDCLI_COMMON_H */ +#endif /* NET_CORD_COMMON_H */ /** @} */ diff --git a/sys/net/application_layer/cord/common/Makefile b/sys/net/application_layer/cord/common/Makefile index 6ac70df22b..2f0ff3a63c 100644 --- a/sys/net/application_layer/cord/common/Makefile +++ b/sys/net/application_layer/cord/common/Makefile @@ -1,3 +1,3 @@ -MODULE = rdcli_common +MODULE = cord_common include $(RIOTBASE)/Makefile.base diff --git a/sys/net/application_layer/cord/common/rdcli_common.c b/sys/net/application_layer/cord/common/cord_common.c similarity index 75% rename from sys/net/application_layer/cord/common/rdcli_common.c rename to sys/net/application_layer/cord/common/cord_common.c index 1e8f210f46..85fc893e03 100644 --- a/sys/net/application_layer/cord/common/rdcli_common.c +++ b/sys/net/application_layer/cord/common/cord_common.c @@ -7,7 +7,7 @@ */ /** - * @ingroup net_rdcli_common + * @ingroup net_cord_common * @{ * * @file @@ -22,7 +22,7 @@ #include "luid.h" #include "net/gcoap.h" -#include "net/rdcli_common.h" +#include "net/cord/common.h" #define ENABLE_DEBUG (0) #include "debug.h" @@ -35,29 +35,29 @@ #define BUFSIZE (PREFIX_LEN + RDCLI_EP_SUFFIX_LEN) #endif -char rdcli_ep[BUFSIZE]; +char cord_common_ep[BUFSIZE]; -void rdcli_common_init(void) +void cord_common_init(void) { #ifdef RDCLI_EP - memcpy(rdcli_ep, RDCLI_EP, BUFSIZE); + memcpy(cord_common_ep, RDCLI_EP, BUFSIZE); #else uint8_t luid[RDCLI_EP_SUFFIX_LEN / 2]; if (PREFIX_LEN > 1) { - memcpy(rdcli_ep, RDCLI_EP_PREFIX, (PREFIX_LEN - 1)); + memcpy(cord_common_ep, RDCLI_EP_PREFIX, (PREFIX_LEN - 1)); } luid_get(luid, sizeof(luid)); - fmt_bytes_hex(&rdcli_ep[PREFIX_LEN - 1], luid, sizeof(luid)); - rdcli_ep[BUFSIZE - 1] = '\0'; + fmt_bytes_hex(&cord_common_ep[PREFIX_LEN - 1], luid, sizeof(luid)); + cord_common_ep[BUFSIZE - 1] = '\0'; #endif } -int rdcli_common_add_qstring(coap_pkt_t *pkt) +int cord_common_add_qstring(coap_pkt_t *pkt) { /* extend the url with some query string options */ - int res = gcoap_add_qstring(pkt, "ep", rdcli_ep); + int res = gcoap_add_qstring(pkt, "ep", cord_common_ep); if (res < 0) { return res; } diff --git a/sys/net/application_layer/cord/ep/rdcli.c b/sys/net/application_layer/cord/ep/rdcli.c index 0742ebcc1c..dbbbd1e3e4 100644 --- a/sys/net/application_layer/cord/ep/rdcli.c +++ b/sys/net/application_layer/cord/ep/rdcli.c @@ -27,7 +27,7 @@ #include "net/gcoap.h" #include "net/ipv6/addr.h" #include "net/rdcli.h" -#include "net/rdcli_common.h" +#include "net/cord/common.h" #include "net/rdcli_config.h" #ifdef MODULE_RDCLI_STANDALONE @@ -273,7 +273,7 @@ int rdcli_register(const sock_udp_ep_t *remote, const char *regif) } /* set some packet options and write query string */ coap_hdr_set_type(pkt.hdr, COAP_TYPE_CON); - rdcli_common_add_qstring(&pkt); + cord_common_add_qstring(&pkt); /* add the resource description as payload */ res = gcoap_get_resource_list(pkt.payload, pkt.payload_len, @@ -355,7 +355,7 @@ void rdcli_dump_status(void) ipv6_addr_to_str(addr, (ipv6_addr_t *)&_rd_remote.addr, sizeof(addr)); printf("RD address: coap://[%s]:%i\n", addr, (int)_rd_remote.port); - printf(" ep name: %s\n", rdcli_common_get_ep()); + printf(" ep name: %s\n", cord_common_get_ep()); printf(" lifetime: %is\n", (int)RDCLI_LT); printf(" reg if: %s\n", _rd_regif); printf(" location: %s\n", _rd_loc); diff --git a/sys/net/application_layer/cord/epsim/rdcli_simple.c b/sys/net/application_layer/cord/epsim/rdcli_simple.c index 20edc90ceb..3da1cffeb9 100644 --- a/sys/net/application_layer/cord/epsim/rdcli_simple.c +++ b/sys/net/application_layer/cord/epsim/rdcli_simple.c @@ -23,7 +23,7 @@ #include "fmt.h" #include "net/gcoap.h" #include "net/rdcli_config.h" -#include "net/rdcli_common.h" +#include "net/cord/common.h" #include "net/rdcli_simple.h" #include "net/ipv6/addr.h" @@ -56,7 +56,7 @@ int rdcli_simple_register(void) /* make packet confirmable */ coap_hdr_set_type(pkt.hdr, COAP_TYPE_CON); /* add Uri-Query options */ - if (rdcli_common_add_qstring(&pkt) < 0) { + if (cord_common_add_qstring(&pkt) < 0) { return RDCLI_SIMPLE_ERROR; } /* finish, we don't have any payload */ diff --git a/sys/shell/commands/sc_rdcli.c b/sys/shell/commands/sc_rdcli.c index c67b79016d..5a44aaf17d 100644 --- a/sys/shell/commands/sc_rdcli.c +++ b/sys/shell/commands/sc_rdcli.c @@ -25,7 +25,6 @@ #include "net/nanocoap.h" #include "net/sock/util.h" #include "net/rdcli_config.h" -#include "net/rdcli_common.h" static int make_sock_ep(sock_udp_ep_t *ep, const char *addr) { From 152623577ef6668641507c9118cb1ea426baa6f2 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Mon, 15 Oct 2018 10:19:08 +0200 Subject: [PATCH 3/8] net/rdcli_config: rename to cord_config --- sys/include/net/cord/common.h | 2 +- .../net/{rdcli_config.h => cord/config.h} | 49 +++++++++---------- .../cord/common/cord_common.c | 24 ++++----- sys/net/application_layer/cord/ep/rdcli.c | 4 +- .../cord/ep/rdcli_standalone.c | 4 +- .../cord/epsim/rdcli_simple.c | 4 +- .../cord/epsim/rdcli_simple_standalone.c | 6 +-- sys/shell/commands/sc_rdcli.c | 4 +- 8 files changed, 48 insertions(+), 49 deletions(-) rename sys/include/net/{rdcli_config.h => cord/config.h} (58%) diff --git a/sys/include/net/cord/common.h b/sys/include/net/cord/common.h index ee5864f5f4..050a19959d 100644 --- a/sys/include/net/cord/common.h +++ b/sys/include/net/cord/common.h @@ -21,7 +21,7 @@ #ifndef NET_CORD_COMMON_H #define NET_CORD_COMMON_H -#include "net/rdcli_config.h" +#include "net/cord/config.h" #ifdef __cplusplus extern "C" { diff --git a/sys/include/net/rdcli_config.h b/sys/include/net/cord/config.h similarity index 58% rename from sys/include/net/rdcli_config.h rename to sys/include/net/cord/config.h index 078261859b..51361361c6 100644 --- a/sys/include/net/rdcli_config.h +++ b/sys/include/net/cord/config.h @@ -7,21 +7,20 @@ */ /** - * @defgroup net_rdcli_config CoRE RD Client Configuration - * @ingroup net - * @brief Shared CoRE Resource Directory Client Configuration + * @defgroup net_cord_config CoRE RD Endpoint and Lookup Client Configuration + * @ingroup net_cord + * @brief Configuration options for CoRE RD endpoints and lookup clients * @{ * * @file - * @brief CoRE RD Client static configuration default values + * @brief (Default) configuration values for CoRE RD endpoints and lookup + * clients * * @author Hauke Petersen */ -#ifndef NET_RDCLI_CONFIG_H -#define NET_RDCLI_CONFIG_H - -#include "net/ipv6/addr.h" +#ifndef NET_CORD_CONFIG_H +#define NET_CORD_CONFIG_H #ifdef __cplusplus extern "C" { @@ -30,49 +29,49 @@ extern "C" { /** * @brief Default lifetime in seconds (the default is 1 day) */ -#ifndef RDCLI_LT -#define RDCLI_LT (86400UL) +#ifndef CORD_LT +#define CORD_LT (86400UL) #endif /** * @brief Delay until the RD client starts to try registering (in seconds) */ -#ifndef RDCLI_STARTUP_DELAY -#define RDCLI_STARTUP_DELAY (3U) +#ifndef CORD_STARTUP_DELAY +#define CORD_STARTUP_DELAY (3U) #endif /** * @brief Default client update interval (default is 3/4 the lifetime) */ -#ifndef RDCLI_UPDATE_INTERVAL -#define RDCLI_UPDATE_INTERVAL ((RDCLI_LT / 4) * 3) +#ifndef CORD_UPDATE_INTERVAL +#define CORD_UPDATE_INTERVAL ((CORD_LT / 4) * 3) #endif /** * @name Endpoint ID definition * * Per default, the endpoint ID (ep) is generated by concatenation of a user - * defined prefix (RDCLI_EP_PREFIX) and a locally unique ID (luid) encoded in + * defined prefix (CORD_EP_PREFIX) and a locally unique ID (luid) encoded in * hexadecimal formatting with the given length of characters - * (RDCLI_EP_SUFFIX_LEN). + * (CORD_EP_SUFFIX_LEN). * * Alternatively, the endpoint ID value can be defined at compile time by - * assigning a string value to the RDCLI_ED macro. + * assigning a string value to the CORD_ED macro. * * @{ */ -#ifndef RDCLI_EP +#ifndef CORD_EP /** * @brief Number of generated hexadecimal characters added to the ep * * @note Must be an even number */ -#define RDCLI_EP_SUFFIX_LEN (16) +#define CORD_EP_SUFFIX_LEN (16) /** * @brief Default static prefix used for the generated ep */ -#define RDCLI_EP_PREFIX "RIOT-" +#define CORD_EP_PREFIX "RIOT-" #endif /** @} */ @@ -80,20 +79,20 @@ extern "C" { * @brief Use ALL_NODES multicast address as default address when looking for * a RD server */ -#ifndef RDCLI_SERVER_ADDR -#define RDCLI_SERVER_ADDR "ff02::1" +#ifndef CORD_SERVER_ADDR +#define CORD_SERVER_ADDR "ff02::1" #endif /** * @brief Default Port to use when looking for RDs */ -#ifndef RDCLI_SERVER_PORT -#define RDCLI_SERVER_PORT COAP_PORT +#ifndef CORD_SERVER_PORT +#define CORD_SERVER_PORT COAP_PORT #endif #ifdef __cplusplus } #endif -#endif /* NET_RDCLI_CONFIG_H */ +#endif /* NET_CORD_CONFIG_H */ /** @} */ diff --git a/sys/net/application_layer/cord/common/cord_common.c b/sys/net/application_layer/cord/common/cord_common.c index 85fc893e03..2de2e4ef2c 100644 --- a/sys/net/application_layer/cord/common/cord_common.c +++ b/sys/net/application_layer/cord/common/cord_common.c @@ -28,24 +28,24 @@ #include "debug.h" -#ifdef RDCLI_EP -#define BUFSIZE (sizeof(RDCLI_EP)) /* contains \0 termination char */ +#ifdef CORD_EP +#define BUFSIZE (sizeof(CORD_EP)) /* contains \0 termination char */ #else -#define PREFIX_LEN (sizeof(RDCLI_EP_PREFIX)) /* contains \0 char */ -#define BUFSIZE (PREFIX_LEN + RDCLI_EP_SUFFIX_LEN) +#define PREFIX_LEN (sizeof(CORD_EP_PREFIX)) /* contains \0 char */ +#define BUFSIZE (PREFIX_LEN + CORD_EP_SUFFIX_LEN) #endif char cord_common_ep[BUFSIZE]; void cord_common_init(void) { -#ifdef RDCLI_EP - memcpy(cord_common_ep, RDCLI_EP, BUFSIZE); +#ifdef CORD_EP + memcpy(cord_common_ep, CORD_EP, BUFSIZE); #else - uint8_t luid[RDCLI_EP_SUFFIX_LEN / 2]; + uint8_t luid[CORD_EP_SUFFIX_LEN / 2]; if (PREFIX_LEN > 1) { - memcpy(cord_common_ep, RDCLI_EP_PREFIX, (PREFIX_LEN - 1)); + memcpy(cord_common_ep, CORD_EP_PREFIX, (PREFIX_LEN - 1)); } luid_get(luid, sizeof(luid)); @@ -63,9 +63,9 @@ int cord_common_add_qstring(coap_pkt_t *pkt) } /* [optional] set the lifetime parameter */ -#if RDCLI_LT +#if CORD_LT char lt[11]; - lt[fmt_u32_dec(lt, RDCLI_LT)] = '\0'; + lt[fmt_u32_dec(lt, CORD_LT)] = '\0'; res = gcoap_add_qstring(pkt, "lt", lt); if (res < 0) { return res; @@ -73,8 +73,8 @@ int cord_common_add_qstring(coap_pkt_t *pkt) #endif /* [optional] set the domain parameter */ -#ifdef RDCLI_D - res = gcoap_add_qstring(pkt, "d", RDCLI_D); +#ifdef CORD_D + res = gcoap_add_qstring(pkt, "d", CORD_D); if (res < 0) { return res; } diff --git a/sys/net/application_layer/cord/ep/rdcli.c b/sys/net/application_layer/cord/ep/rdcli.c index dbbbd1e3e4..517b423de6 100644 --- a/sys/net/application_layer/cord/ep/rdcli.c +++ b/sys/net/application_layer/cord/ep/rdcli.c @@ -28,7 +28,7 @@ #include "net/ipv6/addr.h" #include "net/rdcli.h" #include "net/cord/common.h" -#include "net/rdcli_config.h" +#include "net/cord/config.h" #ifdef MODULE_RDCLI_STANDALONE #include "net/rdcli_standalone.h" @@ -356,7 +356,7 @@ void rdcli_dump_status(void) printf("RD address: coap://[%s]:%i\n", addr, (int)_rd_remote.port); printf(" ep name: %s\n", cord_common_get_ep()); - printf(" lifetime: %is\n", (int)RDCLI_LT); + printf(" lifetime: %is\n", (int)CORD_LT); printf(" reg if: %s\n", _rd_regif); printf(" location: %s\n", _rd_loc); } diff --git a/sys/net/application_layer/cord/ep/rdcli_standalone.c b/sys/net/application_layer/cord/ep/rdcli_standalone.c index 73026d90c9..19002e2718 100644 --- a/sys/net/application_layer/cord/ep/rdcli_standalone.c +++ b/sys/net/application_layer/cord/ep/rdcli_standalone.c @@ -25,7 +25,7 @@ #include "thread.h" #include "xtimer.h" #include "net/rdcli.h" -#include "net/rdcli_config.h" +#include "net/cord/config.h" #include "net/rdcli_standalone.h" #define ENABLE_DEBUG (0) @@ -38,7 +38,7 @@ #define UPDATE_TIMEOUT (0xe537) -#define TIMEOUT_US ((uint64_t)(RDCLI_UPDATE_INTERVAL * US_PER_SEC)) +#define TIMEOUT_US ((uint64_t)(CORD_UPDATE_INTERVAL * US_PER_SEC)) static char _stack[STACKSIZE]; diff --git a/sys/net/application_layer/cord/epsim/rdcli_simple.c b/sys/net/application_layer/cord/epsim/rdcli_simple.c index 3da1cffeb9..f85642cca2 100644 --- a/sys/net/application_layer/cord/epsim/rdcli_simple.c +++ b/sys/net/application_layer/cord/epsim/rdcli_simple.c @@ -22,7 +22,7 @@ #include "fmt.h" #include "net/gcoap.h" -#include "net/rdcli_config.h" +#include "net/cord/config.h" #include "net/cord/common.h" #include "net/rdcli_simple.h" #include "net/ipv6/addr.h" @@ -39,7 +39,7 @@ int rdcli_simple_register(void) sock_udp_ep_t remote = { .family = AF_INET6, .netif = SOCK_ADDR_ANY_NETIF, - .port = RDCLI_SERVER_PORT, + .port = CORD_SERVER_PORT, }; /* parse RD server address */ diff --git a/sys/net/application_layer/cord/epsim/rdcli_simple_standalone.c b/sys/net/application_layer/cord/epsim/rdcli_simple_standalone.c index 0bf1ff66b5..4245b13b01 100644 --- a/sys/net/application_layer/cord/epsim/rdcli_simple_standalone.c +++ b/sys/net/application_layer/cord/epsim/rdcli_simple_standalone.c @@ -21,7 +21,7 @@ #include "log.h" #include "thread.h" #include "xtimer.h" -#include "net/rdcli_config.h" +#include "net/cord/config.h" #include "net/rdcli_simple.h" #define STACKSIZE (THREAD_STACKSIZE_DEFAULT) @@ -35,7 +35,7 @@ static void *reg_runner(void *arg) (void)arg; /* wait some seconds to give the address configuration some time to settle */ - xtimer_sleep(RDCLI_STARTUP_DELAY); + xtimer_sleep(CORD_STARTUP_DELAY); while (1) { if (rdcli_simple_register() != RDCLI_SIMPLE_OK) { @@ -44,7 +44,7 @@ static void *reg_runner(void *arg) LOG_ERROR("[rdcli_simple] error: unable to send registration\n"); break; } - xtimer_sleep(RDCLI_UPDATE_INTERVAL); + xtimer_sleep(CORD_UPDATE_INTERVAL); } return NULL; diff --git a/sys/shell/commands/sc_rdcli.c b/sys/shell/commands/sc_rdcli.c index 5a44aaf17d..b480ba076c 100644 --- a/sys/shell/commands/sc_rdcli.c +++ b/sys/shell/commands/sc_rdcli.c @@ -24,7 +24,7 @@ #include "net/rdcli.h" #include "net/nanocoap.h" #include "net/sock/util.h" -#include "net/rdcli_config.h" +#include "net/cord/config.h" static int make_sock_ep(sock_udp_ep_t *ep, const char *addr) { @@ -35,7 +35,7 @@ static int make_sock_ep(sock_udp_ep_t *ep, const char *addr) ep->family = AF_INET6; ep->netif = SOCK_ADDR_ANY_NETIF; if (ep->port == 0) { - ep->port = RDCLI_SERVER_PORT; + ep->port = CORD_SERVER_PORT; } return 0; } From 226b9fa383213bf99d9986d1d28053682289af05 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Mon, 15 Oct 2018 10:44:32 +0200 Subject: [PATCH 4/8] net/rdcli_simple: rename to cord_epsim --- Makefile.dep | 9 ++- examples/rdcli_simple/Makefile | 2 +- makefiles/pseudomodules.inc.mk | 2 +- sys/Makefile | 2 +- sys/auto_init/auto_init.c | 8 +-- sys/include/net/cord/epsim.h | 68 +++++++++++++++++++ sys/include/net/rdcli_simple.h | 61 ----------------- sys/net/application_layer/cord/epsim/Makefile | 8 +-- .../epsim/{rdcli_simple.c => cord_epsim.c} | 23 +++---- ...e_standalone.c => cord_epsim_standalone.c} | 16 +++-- 10 files changed, 103 insertions(+), 96 deletions(-) create mode 100644 sys/include/net/cord/epsim.h delete mode 100644 sys/include/net/rdcli_simple.h rename sys/net/application_layer/cord/epsim/{rdcli_simple.c => cord_epsim.c} (74%) rename sys/net/application_layer/cord/epsim/{rdcli_simple_standalone.c => cord_epsim_standalone.c} (77%) diff --git a/Makefile.dep b/Makefile.dep index 943e6f4fb5..8aac8bf941 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -749,14 +749,14 @@ ifneq (,$(filter skald,$(USEMODULE))) USEMODULE += random endif -ifneq (,$(filter rdcli_simple_standalone,$(USEMODULE))) - USEMODULE += rdcli_simple +ifneq (,$(filter cord_epsim_standalone,$(USEMODULE))) + USEMODULE += cord_epsim USEMODULE += xtimer endif -ifneq (,$(filter rdcli_simple,$(USEMODULE))) +ifneq (,$(filter cord_epsim,$(USEMODULE))) USEMODULE += cord_common - USEMODULE += fmt + USEMODULE += gcoap endif ifneq (,$(filter rdcli_standalone,$(USEMODULE))) @@ -776,7 +776,6 @@ endif ifneq (,$(filter cord_common,$(USEMODULE))) USEMODULE += fmt - USEMODULE += gcoap USEMODULE += luid endif diff --git a/examples/rdcli_simple/Makefile b/examples/rdcli_simple/Makefile index d2d95afa10..cf10e75118 100644 --- a/examples/rdcli_simple/Makefile +++ b/examples/rdcli_simple/Makefile @@ -20,7 +20,7 @@ USEMODULE += auto_init_gnrc_netif USEMODULE += gnrc_ipv6_default # Run the simple CoRE resource directory -USEMODULE += rdcli_simple_standalone +USEMODULE += cord_epsim_standalone # Include the shell for testing purposes USEMODULE += shell diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 8c13111f20..edae194676 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -5,6 +5,7 @@ PSEUDOMODULES += can_pm PSEUDOMODULES += can_raw PSEUDOMODULES += ccn-lite-utils PSEUDOMODULES += conn_can_isotp_multi +PSEUDOMODULES += cord_epsim_standalone PSEUDOMODULES += core_% PSEUDOMODULES += ecc_% PSEUDOMODULES += emb6_router @@ -53,7 +54,6 @@ PSEUDOMODULES += printf_float PSEUDOMODULES += prng PSEUDOMODULES += prng_% PSEUDOMODULES += rdcli_standalone -PSEUDOMODULES += rdcli_simple_standalone PSEUDOMODULES += saul_adc PSEUDOMODULES += saul_default PSEUDOMODULES += saul_gpio diff --git a/sys/Makefile b/sys/Makefile index 5cefa1c6e1..5d9342643d 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -130,7 +130,7 @@ endif ifneq (,$(filter cord_common,$(USEMODULE))) DIRS += net/application_layer/cord/common endif -ifneq (,$(filter rdcli_simple,$(USEMODULE))) +ifneq (,$(filter cord_epsim,$(USEMODULE))) DIRS += net/application_layer/cord/epsim endif ifneq (,$(filter rdcli,$(USEMODULE))) diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index ed815aa8ba..7e00e1ac44 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -168,10 +168,10 @@ void auto_init(void) extern void rdcli_standalone_run(void); rdcli_standalone_run(); #endif -#ifdef MODULE_RDCLI_SIMPLE_STANDALONE - DEBUG("Auto init rdcli_simple module\n"); - extern void rdcli_simple_run(void); - rdcli_simple_run(); +#ifdef MODULE_CORD_EPSIM_STANDALONE + DEBUG("Auto init cord_epsim module\n"); + extern void cord_epsim_run(void); + cord_epsim_run(); #endif #ifdef MODULE_ASYMCUTE DEBUG("Auto init Asymcute\n"); diff --git a/sys/include/net/cord/epsim.h b/sys/include/net/cord/epsim.h new file mode 100644 index 0000000000..ef4050a16a --- /dev/null +++ b/sys/include/net/cord/epsim.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2017-2018 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup net_cord_epsim CoRE RD Simple Registration Endpoint + * @ingroup net_cord + * @brief CoRE Resource Directory endpoint using the simple registration + * procedure + * @{ + * + * @file + * @brief Interface for the CoRE RD simple registration endpoint + * + * @author Hauke Petersen + */ + +#ifndef NET_CORD_EPSIM_H +#define NET_CORD_EPSIM_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Error codes used by the cord_epsim implementation + */ +enum { + CORD_EPSIM_OK = 0, /**< all good */ + CORD_EPSIM_NOADDR = -1, /**< on address conversion errors */ + CORD_EPSIM_ERROR = -2, /**< on other errors */ +}; + +/** + * @brief Initiate the node registration by sending an empty CoAP POST message + * to the RD server's /.well-known/core resource + * + * @return CORD_EPSIM_OK on success + * @return CORD_EPSIM_NOADDR if conversion of RD address fails + * @return CORD_EPSIM_ERROR if something goes wrong preparing or sending the + * initial request + */ +int cord_epsim_register(void); + +#if defined(MODULE_CORD_EPSIM_STANDALONE) || defined(DOXYGEN) +/** + * @brief Spawn a new thread that registers the node and updates the + * registration with all responding RDs using the simple registration + * process + * + * @note Only available with the `cord_epsim_standalone` module compiled in + * + * @warning This function must only be called once (typically during system + * initialization) + */ +void cord_epsim_run(void); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* NET_CORD_EPSIM_H */ +/** @} */ diff --git a/sys/include/net/rdcli_simple.h b/sys/include/net/rdcli_simple.h deleted file mode 100644 index 8614f8f004..0000000000 --- a/sys/include/net/rdcli_simple.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2017-2018 Freie Universität Berlin - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup net_rdcli_simple CoRE RD Simple Client - * @ingroup net - * @brief CoAP-based CoRE Resource Directory client supporting the simple - * registration only - * @{ - * - * @file - * @brief Interface for a simple CoRE RD registration - * - * @author Hauke Petersen - */ - -#ifndef NET_RDCLI_SIMPLE_H -#define NET_RDCLI_SIMPLE_H - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Error codes used by the rdcli_simple implementation - */ -enum { - RDCLI_SIMPLE_OK = 0, /**< all good */ - RDCLI_SIMPLE_NOADDR = -1, /**< on address conversion errors */ - RDCLI_SIMPLE_ERROR = -2, /**< on other errors */ -}; - -/** - * @brief Initiate the node registration by sending an empty CoAP POST message - * to the RD server's /.well-known/core resource - * - * @return RDCLI_SIMPLE_OK on success - * @return RDCLI_SIMPLE_NOADDR if conversion of RD address fails - * @return RDCLI_SIMPLE_ERROR if something goes wrong preparing or sending the - * initial request - */ -int rdcli_simple_register(void); - -/** - * @brief Spawn a new thread that registers the node and updates the - * registration with all responding RDs using the simple registration - * process - */ -void rdcli_simple_run(void); - -#ifdef __cplusplus -} -#endif - -#endif /* NET_RDCLI_SIMPLE_H */ -/** @} */ diff --git a/sys/net/application_layer/cord/epsim/Makefile b/sys/net/application_layer/cord/epsim/Makefile index db17736b3c..75aa88acb9 100644 --- a/sys/net/application_layer/cord/epsim/Makefile +++ b/sys/net/application_layer/cord/epsim/Makefile @@ -1,9 +1,9 @@ -MODULE = rdcli_simple +MODULE = cord_epsim -SRC = rdcli_simple.c +SRC = cord_epsim.c -ifneq (,$(filter rdcli_simple_standalone,$(USEMODULE))) - SRC += rdcli_simple_standalone.c +ifneq (,$(filter cord_epsim_standalone,$(USEMODULE))) + SRC += cord_epsim_standalone.c endif include $(RIOTBASE)/Makefile.base diff --git a/sys/net/application_layer/cord/epsim/rdcli_simple.c b/sys/net/application_layer/cord/epsim/cord_epsim.c similarity index 74% rename from sys/net/application_layer/cord/epsim/rdcli_simple.c rename to sys/net/application_layer/cord/epsim/cord_epsim.c index f85642cca2..b9b6a8d810 100644 --- a/sys/net/application_layer/cord/epsim/rdcli_simple.c +++ b/sys/net/application_layer/cord/epsim/cord_epsim.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Freie Universität Berlin + * Copyright (C) 2017-2018 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -7,11 +7,11 @@ */ /** - * @ingroup net_rdcli_simple + * @ingroup net_cord_epsim * @{ * * @file - * @brief Simplified CoAP resource directory client implementation + * @brief CoRE RD simple registration endpoint implementation * * @author Hauke Petersen * @@ -20,11 +20,10 @@ #include -#include "fmt.h" #include "net/gcoap.h" +#include "net/cord/epsim.h" #include "net/cord/config.h" #include "net/cord/common.h" -#include "net/rdcli_simple.h" #include "net/ipv6/addr.h" #define BUFSIZE (128U) @@ -34,7 +33,7 @@ static coap_pkt_t pkt; static uint8_t buf[BUFSIZE]; -int rdcli_simple_register(void) +int cord_epsim_register(void) { sock_udp_ep_t remote = { .family = AF_INET6, @@ -44,26 +43,26 @@ int rdcli_simple_register(void) /* parse RD server address */ if (ipv6_addr_from_str((ipv6_addr_t *)&remote.addr.ipv6, - RDCLI_SERVER_ADDR) == NULL) { - return RDCLI_SIMPLE_NOADDR; + CORD_SERVER_ADDR) == NULL) { + return CORD_EPSIM_NOADDR; } /* build the initial CON packet */ if (gcoap_req_init(&pkt, buf, sizeof(buf), COAP_METHOD_POST, "/.well-known/core") < 0) { - return RDCLI_SIMPLE_ERROR; + return CORD_EPSIM_ERROR; } /* make packet confirmable */ coap_hdr_set_type(pkt.hdr, COAP_TYPE_CON); /* add Uri-Query options */ if (cord_common_add_qstring(&pkt) < 0) { - return RDCLI_SIMPLE_ERROR; + return CORD_EPSIM_ERROR; } /* finish, we don't have any payload */ ssize_t len = gcoap_finish(&pkt, 0, COAP_FORMAT_NONE); if (gcoap_req_send2(buf, len, &remote, NULL) == 0) { - return RDCLI_SIMPLE_ERROR; + return CORD_EPSIM_ERROR; } - return RDCLI_SIMPLE_OK; + return CORD_EPSIM_OK; } diff --git a/sys/net/application_layer/cord/epsim/rdcli_simple_standalone.c b/sys/net/application_layer/cord/epsim/cord_epsim_standalone.c similarity index 77% rename from sys/net/application_layer/cord/epsim/rdcli_simple_standalone.c rename to sys/net/application_layer/cord/epsim/cord_epsim_standalone.c index 4245b13b01..98f0eaa662 100644 --- a/sys/net/application_layer/cord/epsim/rdcli_simple_standalone.c +++ b/sys/net/application_layer/cord/epsim/cord_epsim_standalone.c @@ -7,11 +7,11 @@ */ /** - * @ingroup net_rdcli_simple + * @ingroup net_cord_epsim * @{ * * @file - * @brief Standalone extension for the simple RD registration client + * @brief Standalone extension for the simple RD registration endpoint * * @author Hauke Petersen * @@ -21,12 +21,12 @@ #include "log.h" #include "thread.h" #include "xtimer.h" +#include "net/cord/epsim.h" #include "net/cord/config.h" -#include "net/rdcli_simple.h" #define STACKSIZE (THREAD_STACKSIZE_DEFAULT) #define PRIO (THREAD_PRIORITY_MAIN - 1) -#define TNAME "rdcli_simple" +#define TNAME "cord_epsim" static char _stack[STACKSIZE]; @@ -38,10 +38,10 @@ static void *reg_runner(void *arg) xtimer_sleep(CORD_STARTUP_DELAY); while (1) { - if (rdcli_simple_register() != RDCLI_SIMPLE_OK) { + if (cord_epsim_register() != CORD_EPSIM_OK) { /* if this fails once, it will always fail, so we might as well * quit now */ - LOG_ERROR("[rdcli_simple] error: unable to send registration\n"); + LOG_ERROR("[cord_epsim] error: unable to send registration\n"); break; } xtimer_sleep(CORD_UPDATE_INTERVAL); @@ -50,7 +50,9 @@ static void *reg_runner(void *arg) return NULL; } -void rdcli_simple_run(void) +#ifdef MODULE_CORD_EPSIM_STANDALONE +void cord_epsim_run(void) { thread_create(_stack, sizeof(_stack), PRIO, 0, reg_runner, NULL, TNAME); } +#endif From 5668100dc3b29973c19c0ee31d0e0c82b2e34606 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Mon, 15 Oct 2018 10:53:41 +0200 Subject: [PATCH 5/8] examples/rdcli_simple: rename to cord_epsim --- examples/{rdcli_simple => cord_epsim}/Makefile | 8 ++++---- examples/{rdcli_simple => cord_epsim}/README.md | 14 +++++++------- examples/{rdcli_simple => cord_epsim}/main.c | 8 ++++---- 3 files changed, 15 insertions(+), 15 deletions(-) rename examples/{rdcli_simple => cord_epsim}/Makefile (91%) rename examples/{rdcli_simple => cord_epsim}/README.md (54%) rename examples/{rdcli_simple => cord_epsim}/main.c (91%) diff --git a/examples/rdcli_simple/Makefile b/examples/cord_epsim/Makefile similarity index 91% rename from examples/rdcli_simple/Makefile rename to examples/cord_epsim/Makefile index cf10e75118..f40884bdeb 100644 --- a/examples/rdcli_simple/Makefile +++ b/examples/cord_epsim/Makefile @@ -1,5 +1,5 @@ # name of your application -APPLICATION = rdcli_simple +APPLICATION = cord_epsim # If no BOARD is found in the environment, use this default: BOARD ?= native @@ -40,8 +40,8 @@ RD_LT ?= 60 RD_ADDR ?= \"ff02::1\" RD_PORT ?= 5683 -CFLAGS += -DRDCLI_LT=$(RD_LT) -CFLAGS += -DRDCLI_SERVER_ADDR=$(RD_ADDR) -CFLAGS += -DRDCLI_SERVER_PORT=$(RD_PORT) +CFLAGS += -DCORD_LT=$(RD_LT) +CFLAGS += -DCORD_SERVER_ADDR=$(RD_ADDR) +CFLAGS += -DCORD_SERVER_PORT=$(RD_PORT) include $(RIOTBASE)/Makefile.include diff --git a/examples/rdcli_simple/README.md b/examples/cord_epsim/README.md similarity index 54% rename from examples/rdcli_simple/README.md rename to examples/cord_epsim/README.md index 3fb6139133..811e7591d2 100644 --- a/examples/rdcli_simple/README.md +++ b/examples/cord_epsim/README.md @@ -1,15 +1,15 @@ -CoRE Resource Directory: Simple Registration Example -==================================================== +CoRE Resource Directory: Simple Endpoint Example +================================================ This example shows how a node can register with a CoRE resource directory using -the simple registration process as described in -draft-ietf-core-resource-directory-11, section 5.3.2. +the simple registration procedure as described in +draft-ietf-core-resource-directory-15, section 5.3.1. The registration process needs an endpoint name as well as a lifetime for the -registry entry. You can edit these values by overriding `RDCLI_EP` and -`RDCLI_LT`: +registry entry. These are statically defined during compile time and you can +edit these values by overriding `CORD_EP` and `CORD_LT`: ``` -CFLAGS="-DRDCLI_LT=\"7200\" -DRDCLI_EP=\"MyNode\"" make all +CFLAGS="-DCORD_LT=\"7200\" -DCORD_EP=\"MyNode\"" make all ``` Per default, the node is looking for the CoRE RD at the all nodes link-local diff --git a/examples/rdcli_simple/main.c b/examples/cord_epsim/main.c similarity index 91% rename from examples/rdcli_simple/main.c rename to examples/cord_epsim/main.c index 24726dcd21..99a4dd446f 100644 --- a/examples/rdcli_simple/main.c +++ b/examples/cord_epsim/main.c @@ -68,17 +68,17 @@ int main(void) /* fill riot info */ sprintf(riot_info, "{\"ep\":\"%s\",\"lt\":%u}", - cord_common_get_ep(), RDCLI_LT); + cord_common_get_ep(), CORD_LT); /* register resource handlers with gcoap */ gcoap_register_listener(&listener); /* print RD client information */ puts("RD client information:"); - printf(" RD addr: %s\n", RDCLI_SERVER_ADDR); - printf(" RD port: %u\n", (unsigned)RDCLI_SERVER_PORT); + printf(" RD addr: %s\n", CORD_SERVER_ADDR); + printf(" RD port: %u\n", (unsigned)CORD_SERVER_PORT); printf(" ep: %s\n", cord_common_get_ep()); - printf(" lt: %is\n", (int)RDCLI_LT); + printf(" lt: %is\n", (int)CORD_LT); /* run the shell */ char line_buf[SHELL_DEFAULT_BUFSIZE]; From 18cc7ee3edfb8e379b95546bcf589b0dcc982867 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Mon, 15 Oct 2018 11:19:06 +0200 Subject: [PATCH 6/8] net/rdcli: rename to cord_ep --- Makefile.dep | 7 +- examples/rdcli/Makefile | 2 +- examples/rdcli/main.c | 14 +-- makefiles/pseudomodules.inc.mk | 2 +- sys/Makefile | 2 +- sys/auto_init/auto_init.c | 8 +- sys/include/net/{rdcli.h => cord/ep.h} | 70 +++++++-------- sys/include/net/cord/ep_standalone.h | 88 ++++++++++++++++++ sys/include/net/rdcli_standalone.h | 90 ------------------- sys/net/application_layer/cord/ep/Makefile | 8 +- .../cord/ep/{rdcli.c => cord_ep.c} | 72 +++++++-------- ...dcli_standalone.c => cord_ep_standalone.c} | 32 ++++--- 12 files changed, 193 insertions(+), 202 deletions(-) rename sys/include/net/{rdcli.h => cord/ep.h} (54%) create mode 100644 sys/include/net/cord/ep_standalone.h delete mode 100644 sys/include/net/rdcli_standalone.h rename sys/net/application_layer/cord/ep/{rdcli.c => cord_ep.c} (86%) rename sys/net/application_layer/cord/ep/{rdcli_standalone.c => cord_ep_standalone.c} (73%) diff --git a/Makefile.dep b/Makefile.dep index 8aac8bf941..006ad059dd 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -759,16 +759,15 @@ ifneq (,$(filter cord_epsim,$(USEMODULE))) USEMODULE += gcoap endif -ifneq (,$(filter rdcli_standalone,$(USEMODULE))) - USEMODULE += rdcli +ifneq (,$(filter cord_ep_standalone,$(USEMODULE))) + USEMODULE += cord_ep USEMODULE += xtimer endif -ifneq (,$(filter rdcli,$(USEMODULE))) +ifneq (,$(filter cord_ep,$(USEMODULE))) USEMODULE += cord_common USEMODULE += core_thread_flags USEMODULE += gcoap - USEMODULE += fmt ifneq (,$(filter shell_commands,$(USEMODULE))) USEMODULE += sock_util endif diff --git a/examples/rdcli/Makefile b/examples/rdcli/Makefile index cf1007f7ec..c5b70456d3 100644 --- a/examples/rdcli/Makefile +++ b/examples/rdcli/Makefile @@ -19,7 +19,7 @@ USEMODULE += auto_init_gnrc_netif USEMODULE += gnrc_ipv6_default USEMODULE += gnrc_icmpv6_echo -USEMODULE += rdcli_standalone +USEMODULE += cord_ep_standalone USEMODULE += shell USEMODULE += shell_commands diff --git a/examples/rdcli/main.c b/examples/rdcli/main.c index 4d00e6d885..d34572da57 100644 --- a/examples/rdcli/main.c +++ b/examples/rdcli/main.c @@ -25,22 +25,22 @@ #include "net/ipv6/addr.h" #include "net/gcoap.h" #include "net/cord/common.h" -#include "net/rdcli_standalone.h" +#include "net/cord/ep_standalone.h" #define MAIN_QUEUE_SIZE (8) static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; /* we will use a custom event handler for dumping rdcli_standalone events */ -static void _on_rdcli_event(rdcli_standalone_event_t event) +static void _on_rdcli_event(cord_ep_standalone_event_t event) { switch (event) { - case RDCLI_REGISTERED: + case CORD_EP_REGISTERED: puts("rdcli event: now registered with a RD"); break; - case RDCLI_DEREGISTERED: + case CORD_EP_DEREGISTERED: puts("rdcli event: dropped client registration"); break; - case RDCLI_UPDATED: + case CORD_EP_UPDATED: puts("rdcli event: successfully updated client registration"); break; } @@ -94,8 +94,8 @@ int main(void) /* setup CoAP resources */ gcoap_register_listener(&_listener); - /* register event callback with rdcli_standalone */ - rdcli_standalone_reg_cb(_on_rdcli_event); + /* register event callback with cord_ep_standalone */ + cord_ep_standalone_reg_cb(_on_rdcli_event); puts("Client information:"); printf(" ep: %s\n", cord_common_get_ep()); diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index edae194676..f27ea28fb4 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -5,6 +5,7 @@ PSEUDOMODULES += can_pm PSEUDOMODULES += can_raw PSEUDOMODULES += ccn-lite-utils PSEUDOMODULES += conn_can_isotp_multi +PSEUDOMODULES += cord_ep_standalone PSEUDOMODULES += cord_epsim_standalone PSEUDOMODULES += core_% PSEUDOMODULES += ecc_% @@ -53,7 +54,6 @@ PSEUDOMODULES += pktqueue PSEUDOMODULES += printf_float PSEUDOMODULES += prng PSEUDOMODULES += prng_% -PSEUDOMODULES += rdcli_standalone PSEUDOMODULES += saul_adc PSEUDOMODULES += saul_default PSEUDOMODULES += saul_gpio diff --git a/sys/Makefile b/sys/Makefile index 5d9342643d..6068eb76e3 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -133,7 +133,7 @@ endif ifneq (,$(filter cord_epsim,$(USEMODULE))) DIRS += net/application_layer/cord/epsim endif -ifneq (,$(filter rdcli,$(USEMODULE))) +ifneq (,$(filter cord_ep,$(USEMODULE))) DIRS += net/application_layer/cord/ep endif diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index 7e00e1ac44..d81277d478 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -163,10 +163,10 @@ void auto_init(void) extern void cord_common_init(void); cord_common_init(); #endif -#ifdef MODULE_RDCLI_STANDALONE - DEBUG("Auto init rdcli_standalone\n"); - extern void rdcli_standalone_run(void); - rdcli_standalone_run(); +#ifdef MODULE_CORD_EP_STANDALONE + DEBUG("Auto init cord_ep_standalone\n"); + extern void cord_ep_standalone_run(void); + cord_ep_standalone_run(); #endif #ifdef MODULE_CORD_EPSIM_STANDALONE DEBUG("Auto init cord_epsim module\n"); diff --git a/sys/include/net/rdcli.h b/sys/include/net/cord/ep.h similarity index 54% rename from sys/include/net/rdcli.h rename to sys/include/net/cord/ep.h index f9b2a049f5..0a1409f5a7 100644 --- a/sys/include/net/rdcli.h +++ b/sys/include/net/cord/ep.h @@ -7,8 +7,8 @@ */ /** - * @defgroup net_rdcli CoRE RD Endpoint Library - * @ingroup net + * @defgroup net_cord_ep CoRE RD Endpoint + * @ingroup net_cord * @brief Library for using RIOT as CoRE Resource Directory endpoint * * This module implements a CoRE Resource Directory endpoint library, that @@ -17,14 +17,10 @@ * draft-ietf-core-resource-directory-15. * @see https://tools.ietf.org/html/draft-ietf-core-resource-directory-15 * - * @note As the name of this library (`rdcli`) can be misleading in - * context of the RD draft (endpoint vs client), this library - * will most likely undergo a name change in the near future... - * * # Design Decisions * - all operations provided by this module are fully synchronous, meaning that * the functions will block until an operation is successful or will time out - * - the implementation limits the client to be registered with a single RD at + * - the implementation limits the endpoint to be registered with a single RD at * any point in time * * @{ @@ -35,8 +31,8 @@ * @author Hauke Petersen */ -#ifndef NET_RDCLI_H -#define NET_RDCLI_H +#ifndef NET_CORD_EP_H +#define NET_CORD_EP_H #include "net/sock/udp.h" @@ -48,11 +44,11 @@ extern "C" { * @brief Return values and error codes used by this module */ enum { - RDCLI_OK = 0, /**< everything went as expected */ - RDCLI_TIMEOUT = -1, /**< no response from the network */ - RDCLI_ERR = -2, /**< internal error or invalid reply */ - RDCLI_NORD = -3, /**< not connected to an RD */ - RDCLI_OVERFLOW = -4, /**< internal buffers can not handle input */ + CORD_EP_OK = 0, /**< everything went as expected */ + CORD_EP_TIMEOUT = -1, /**< no response from the network */ + CORD_EP_ERR = -2, /**< internal error or invalid reply */ + CORD_EP_NORD = -3, /**< not connected to an RD */ + CORD_EP_OVERFLOW = -4, /**< internal buffers can not handle input */ }; /** @@ -62,19 +58,19 @@ enum { * @param[out] regif the registration interface is written to this buffer * @param[in] maxlen size of @p regif * - * @return RDCLI_OK on success - * @return RDCLI_TIMEOUT if the discovery request times out - * @return RDCLI_NORD if addressed endpoint is not a RD - * @return RDCLI_ERR on any other internal error + * @return CORD_EP_OK on success + * @return CORD_EP_TIMEOUT if the discovery request times out + * @return CORD_EP_NORD if addressed endpoint is not a RD + * @return CORD_EP_ERR on any other internal error */ -int rdcli_discover_regif(const sock_udp_ep_t *remote, - char *regif, size_t maxlen); +int cord_ep_discover_regif(const sock_udp_ep_t *remote, + char *regif, size_t maxlen); /** * @brief Initiate the node registration by sending an empty push * * - if registration fails (e.g. timeout), we are not associated with any RD - * anymore (even if we have been before we called rdcli_register) + * anymore (even if we have been before we called cord_ep_register) * * @note In case a multicast address is given, the @p regif parameter MUST be * NULL. The first RD responding to the request will be chosen and all @@ -84,40 +80,40 @@ int rdcli_discover_regif(const sock_udp_ep_t *remote, * @param[in] regif registration interface resource of the RD, it will be * discovered automatically when set to NULL * - * @return RDCLI_OK on success - * @return RDCLI_TIMEOUT on registration timeout - * @return RDCLI_NORD if addressed endpoint is not a RD - * @return RDCLI_OVERFLOW if @p regif does not fit into internal buffer - * @return RDCLI_ERR on any other internal error + * @return CORD_EP_OK on success + * @return CORD_EP_TIMEOUT on registration timeout + * @return CORD_EP_NORD if addressed endpoint is not a RD + * @return CORD_EP_OVERFLOW if @p regif does not fit into internal buffer + * @return CORD_EP_ERR on any other internal error */ -int rdcli_register(const sock_udp_ep_t *remote, const char *regif); +int cord_ep_register(const sock_udp_ep_t *remote, const char *regif); /** * @brief Update our current entry at the RD * - * @return RDCLI_OK on success - * @return RDCLI_TIMEOUT if the update request times out - * @return RDCLI_ERR on any other internal error + * @return CORD_EP_OK on success + * @return CORD_EP_TIMEOUT if the update request times out + * @return CORD_EP_ERR on any other internal error */ -int rdcli_update(void); +int cord_ep_update(void); /** * @brief Unregister from a given RD server * - * @return RDCLI_OK on success - * @return RDCLI_TIMEOUT if the remove request times out - * @return RDCLI_ERR on any other internal error + * @return CORD_EP_OK on success + * @return CORD_EP_TIMEOUT if the remove request times out + * @return CORD_EP_ERR on any other internal error */ -int rdcli_remove(void); +int cord_ep_remove(void); /** * @brief Dump the current RD connection status to STDIO (for debugging) */ -void rdcli_dump_status(void); +void cord_ep_dump_status(void); #ifdef __cplusplus } #endif -#endif /* NET_RDCLI_H */ +#endif /* NET_CORD_EP_H */ /** @} */ diff --git a/sys/include/net/cord/ep_standalone.h b/sys/include/net/cord/ep_standalone.h new file mode 100644 index 0000000000..9d900b71ed --- /dev/null +++ b/sys/include/net/cord/ep_standalone.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2017-2018 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup net_cord_ep_standalone CoRE RD Endpoint Standalone Extension + * @ingroup net_cord_ep + * @brief Run a CoRE Resource Directory endpoint standalone + * + * This sub-module enables a CoRE RD endpoint to manage is registration state + * with a RD autonomously by periodically running the update procedure. This + * is implemented by running a dedicated thread. + * + * @{ + * + * @file + * @brief CoRE Resource Directory endpoint standalone extension + * + * @author Hauke Petersen + */ + +#ifndef NET_CORD_EP_STANDALONE_H +#define NET_CORD_EP_STANDALONE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Possible types of events triggered by the cord_ep_standalone module + */ +typedef enum { + CORD_EP_REGISTERED, + CORD_EP_DEREGISTERED, + CORD_EP_UPDATED, +} cord_ep_standalone_event_t; + +/** + * @brief Callback function signature for RD endpoint state synchronization + * + * The registered callback function is executed in the context of the dedicated + * standalone RD endpoint's thread. + * + * @param[in] t type of event + */ +typedef void(*cord_ep_standalone_cb_t)(cord_ep_standalone_event_t event); + +/** + * @brief Spawn a new thread that takes care of sending periodic updates to an + * active RD entry + * + * @warning This function must only be called once (typically during system + * initialization) + */ +void cord_ep_standalone_run(void); + +/** + * @brief Register a callback to be notified about RD endpoint state changes + * + * Only a single callback can be active at any point in time, so setting a new + * callback will override the existing one. + * + * @pre @p cb != NULL + * + * @param[in] cb callback to execute on RD endpoint state changes + */ +void cord_ep_standalone_reg_cb(cord_ep_standalone_cb_t cb); + +/** + * @brief Signal the cord_ep thread about connection status change + * + * @note This function should not be called by a user, but it is called from + * withing the cord_ep implementation + * + * @param[in] connected set to true if we are connected to a RD + */ +void cord_ep_standalone_signal(bool connected); + +#ifdef __cplusplus +} +#endif + +#endif /* NET_CORD_EP_STANDALONE_H */ +/** @} */ diff --git a/sys/include/net/rdcli_standalone.h b/sys/include/net/rdcli_standalone.h deleted file mode 100644 index a76041b882..0000000000 --- a/sys/include/net/rdcli_standalone.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2017-2018 Freie Universität Berlin - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup net_rdcli_standalone CoRE RD Standalone Extension - * @ingroup net_rdcli - * @brief Run CoRE Resource Directory client in standalone configuration - * - * This sub-module enables the CoRE RD client to manage is registration state - * with a server autonomously by periodically running the update procedure. This - * is implemented by running a dedicated thread. - * - * @{ - * - * @file - * @brief CoRE Resource Directory client standalone extension - * - * @author Hauke Petersen - */ - -#ifndef NET_RDCLI_STANDALONE_H -#define NET_RDCLI_STANDALONE_H - -#include "net/sock/udp.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Possible types of events triggered by the standalone rdcli module - */ -typedef enum { - RDCLI_REGISTERED, - RDCLI_DEREGISTERED, - RDCLI_UPDATED, -} rdcli_standalone_event_t; - -/** - * @brief Callback function signature for RD client state synchronization - * - * The registered callback function is executed in the context of the dedicated - * standalone RD client's thread. - * - * @param[in] t type of event - */ -typedef void(*rdcli_standalone_cb_t)(rdcli_standalone_event_t event); - -/** - * @brief Spawn a new thread that takes care of sending periodic updates to an - * active RD entry - * - * @note This function must only be called once (typically during system - * initialization) - */ -void rdcli_standalone_run(void); - -/** - * @brief Register a callback to be notified about RD client state changes - * - * Only a single callback can be active at any point in time, so setting a new - * callback will override the existing one. - * - * @pre @p cb != NULL - * - * @param[in] cb callback to execute on RD client state changes - */ -void rdcli_standalone_reg_cb(rdcli_standalone_cb_t cb); - -/** - * @brief Signal the rdcli thread about connection status change - * - * @note This function should not be called by a user, but it is called from - * withing the rdcli implementation - * - * @param[in] connected set to true if we are connected to a RD - */ -void rdcli_standalone_signal(bool connected); - -#ifdef __cplusplus -} -#endif - -#endif /* NET_RDCLI_STANDALONE_H */ -/** @} */ diff --git a/sys/net/application_layer/cord/ep/Makefile b/sys/net/application_layer/cord/ep/Makefile index 885829de20..d64da730e7 100644 --- a/sys/net/application_layer/cord/ep/Makefile +++ b/sys/net/application_layer/cord/ep/Makefile @@ -1,9 +1,9 @@ -MODULE = rdcli +MODULE = cord_ep -SRC = rdcli.c +SRC = cord_ep.c -ifneq (,$(filter rdcli_standalone,$(USEMODULE))) - SRC += rdcli_standalone.c +ifneq (,$(filter cord_ep_standalone,$(USEMODULE))) + SRC += cord_ep_standalone.c endif include $(RIOTBASE)/Makefile.base diff --git a/sys/net/application_layer/cord/ep/rdcli.c b/sys/net/application_layer/cord/ep/cord_ep.c similarity index 86% rename from sys/net/application_layer/cord/ep/rdcli.c rename to sys/net/application_layer/cord/ep/cord_ep.c index 517b423de6..a2ea5f28f2 100644 --- a/sys/net/application_layer/cord/ep/rdcli.c +++ b/sys/net/application_layer/cord/ep/cord_ep.c @@ -7,11 +7,11 @@ */ /** - * @ingroup net_rdcli + * @ingroup net_cord_ep * @{ * * @file - * @brief CoRE Resource Directory client implementation + * @brief CoRE Resource Directory endpoint implementation * * @author Hauke Petersen * @@ -20,18 +20,18 @@ #include -#include "fmt.h" #include "mutex.h" +#include "assert.h" #include "thread_flags.h" #include "net/gcoap.h" #include "net/ipv6/addr.h" -#include "net/rdcli.h" +#include "net/cord/ep.h" #include "net/cord/common.h" #include "net/cord/config.h" -#ifdef MODULE_RDCLI_STANDALONE -#include "net/rdcli_standalone.h" +#ifdef MODULE_CORD_EP_STANDALONE +#include "net/cord/ep_standalone.h" #endif #define ENABLE_DEBUG (0) @@ -68,16 +68,16 @@ static int _sync(void) thread_flags_t flags = thread_flags_wait_any(FLAG_MASK); if (flags & FLAG_ERR) { - return RDCLI_ERR; + return CORD_EP_ERR; } else if (flags & FLAG_TIMEOUT) { - return RDCLI_TIMEOUT; + return CORD_EP_TIMEOUT; } else if (flags & FLAG_OVERFLOW) { - return RDCLI_OVERFLOW; + return CORD_EP_OVERFLOW; } else { - return RDCLI_OK; + return CORD_EP_OK; } } @@ -137,13 +137,13 @@ static int _update_remove(unsigned code, gcoap_resp_handler_t handle) coap_pkt_t pkt; if (_rd_loc[0] == 0) { - return RDCLI_NORD; + return CORD_EP_NORD; } /* build CoAP request packet */ int res = gcoap_req_init(&pkt, buf, sizeof(buf), code, _rd_loc); if (res < 0) { - return RDCLI_ERR; + return CORD_EP_ERR; } coap_hdr_set_type(pkt.hdr, COAP_TYPE_CON); ssize_t pkt_len = gcoap_finish(&pkt, 0, COAP_FORMAT_NONE); @@ -158,7 +158,7 @@ static int _update_remove(unsigned code, gcoap_resp_handler_t handle) static void _on_discover(unsigned req_state, coap_pkt_t *pdu, sock_udp_ep_t *remote) { - thread_flags_t flag = RDCLI_NORD; + thread_flags_t flag = CORD_EP_NORD; (void)remote; if (req_state == GCOAP_MEMO_RESP) { @@ -216,19 +216,19 @@ static int _discover_internal(const sock_udp_ep_t *remote, int res = gcoap_req_init(&pkt, buf, sizeof(buf), COAP_METHOD_GET, "/.well-known/core"); if (res < 0) { - return RDCLI_ERR; + return CORD_EP_ERR; } coap_hdr_set_type(pkt.hdr, COAP_TYPE_CON); gcoap_add_qstring(&pkt, "rt", "core.rd"); size_t pkt_len = gcoap_finish(&pkt, 0, COAP_FORMAT_NONE); res = gcoap_req_send2(buf, pkt_len, remote, _on_discover); if (res < 0) { - return RDCLI_ERR; + return CORD_EP_ERR; } return _sync(); } -int rdcli_discover_regif(const sock_udp_ep_t *remote, char *regif, size_t maxlen) +int cord_ep_discover_regif(const sock_udp_ep_t *remote, char *regif, size_t maxlen) { assert(remote && regif); @@ -238,7 +238,7 @@ int rdcli_discover_regif(const sock_udp_ep_t *remote, char *regif, size_t maxlen return res; } -int rdcli_register(const sock_udp_ep_t *remote, const char *regif) +int cord_ep_register(const sock_udp_ep_t *remote, const char *regif) { assert(remote); @@ -253,13 +253,13 @@ int rdcli_register(const sock_udp_ep_t *remote, const char *regif) * discovery for it first (see section 5.2) */ if (regif == NULL) { retval = _discover_internal(remote, _rd_regif, sizeof(_rd_regif)); - if (retval != RDCLI_OK) { + if (retval != CORD_EP_OK) { goto end; } } else { if (strlen(_rd_regif) >= sizeof(_rd_regif)) { - retval = RDCLI_OVERFLOW; + retval = CORD_EP_OVERFLOW; goto end; } strncpy(_rd_regif, regif, sizeof(_rd_regif)); @@ -268,7 +268,7 @@ int rdcli_register(const sock_udp_ep_t *remote, const char *regif) /* build and send CoAP POST request to the RD's registration interface */ res = gcoap_req_init(&pkt, buf, sizeof(buf), COAP_METHOD_POST, _rd_regif); if (res < 0) { - retval = RDCLI_ERR; + retval = CORD_EP_ERR; goto end; } /* set some packet options and write query string */ @@ -279,7 +279,7 @@ int rdcli_register(const sock_udp_ep_t *remote, const char *regif) res = gcoap_get_resource_list(pkt.payload, pkt.payload_len, COAP_FORMAT_LINK); if (res < 0) { - retval = RDCLI_ERR; + retval = CORD_EP_ERR; goto end; } @@ -289,19 +289,19 @@ int rdcli_register(const sock_udp_ep_t *remote, const char *regif) /* send out the request */ res = gcoap_req_send2(buf, pkt_len, remote, _on_register); if (res < 0) { - retval = RDCLI_ERR; + retval = CORD_EP_ERR; goto end; } retval = _sync(); end: - /* if we encountered any error, we mark the client as not connected */ - if (retval != RDCLI_OK) { + /* if we encountered any error, we mark the endpoint as not connected */ + if (retval != CORD_EP_OK) { _rd_loc[0] = '\0'; } -#ifdef MODULE_RDCLI_STANDALONE +#ifdef MODULE_CORD_EP_STANDALONE else { - rdcli_standalone_signal(true); + cord_ep_standalone_signal(true); } #endif @@ -309,14 +309,14 @@ end: return retval; } -int rdcli_update(void) +int cord_ep_update(void) { _lock(); int res = _update_remove(COAP_METHOD_POST, _on_update); - if (res != RDCLI_OK) { + if (res != CORD_EP_OK) { /* in case we are not able to reach the RD, we drop the association */ -#ifdef MODULE_RDCLI_STANDALONE - rdcli_standalone_signal(false); +#ifdef MODULE_CORD_EP_STANDALONE + cord_ep_standalone_signal(false); #endif _rd_loc[0] = '\0'; } @@ -324,25 +324,25 @@ int rdcli_update(void) return res; } -int rdcli_remove(void) +int cord_ep_remove(void) { _lock(); if (_rd_loc[0] == '\0') { mutex_unlock(&_mutex); - return RDCLI_NORD; + return CORD_EP_NORD; } -#ifdef MODULE_RDCLI_STANDALONE - rdcli_standalone_signal(false); +#ifdef MODULE_CORD_EP_STANDALONE + cord_ep_standalone_signal(false); #endif _update_remove(COAP_METHOD_DELETE, _on_remove); /* we actually do not care about the result, we drop the RD local RD entry * in any case */ _rd_loc[0] = '\0'; mutex_unlock(&_mutex); - return RDCLI_OK; + return CORD_EP_OK; } -void rdcli_dump_status(void) +void cord_ep_dump_status(void) { puts("CoAP RD connection status:"); diff --git a/sys/net/application_layer/cord/ep/rdcli_standalone.c b/sys/net/application_layer/cord/ep/cord_ep_standalone.c similarity index 73% rename from sys/net/application_layer/cord/ep/rdcli_standalone.c rename to sys/net/application_layer/cord/ep/cord_ep_standalone.c index 19002e2718..de2a58e405 100644 --- a/sys/net/application_layer/cord/ep/rdcli_standalone.c +++ b/sys/net/application_layer/cord/ep/cord_ep_standalone.c @@ -7,11 +7,11 @@ */ /** - * @ingroup net_rdcli_simple + * @ingroup net_cord_ep_standalone * @{ * * @file - * @brief Standalone extension for the simple RD registration client + * @brief Standalone extension for the CoRE RD endpoint implementation * * @author Hauke Petersen * @@ -24,9 +24,9 @@ #include "assert.h" #include "thread.h" #include "xtimer.h" -#include "net/rdcli.h" +#include "net/cord/ep.h" #include "net/cord/config.h" -#include "net/rdcli_standalone.h" +#include "net/cord/ep_standalone.h" #define ENABLE_DEBUG (0) #include "debug.h" @@ -34,7 +34,7 @@ /* stack configuration */ #define STACKSIZE (THREAD_STACKSIZE_DEFAULT) #define PRIO (THREAD_PRIORITY_MAIN - 1) -#define TNAME "rdcli" +#define TNAME "cord_ep" #define UPDATE_TIMEOUT (0xe537) @@ -46,14 +46,14 @@ static xtimer_t _timer; static kernel_pid_t _runner_pid; static msg_t _msg; -static rdcli_standalone_cb_t _cb = NULL; +static cord_ep_standalone_cb_t _cb = NULL; static void _set_timer(void) { xtimer_set_msg64(&_timer, TIMEOUT_US, &_msg, _runner_pid); } -static void _notify(rdcli_standalone_event_t event) +static void _notify(cord_ep_standalone_event_t event) { if (_cb) { _cb(event); @@ -70,16 +70,14 @@ static void *_reg_runner(void *arg) _msg.type = UPDATE_TIMEOUT; while (1) { - DEBUG("rd stand: waiting for message\n"); msg_receive(&in); if (in.type == UPDATE_TIMEOUT) { - if (rdcli_update() == RDCLI_OK) { - DEBUG("rd stand: update ok\n"); + if (cord_ep_update() == CORD_EP_OK) { _set_timer(); - _notify(RDCLI_UPDATED); + _notify(CORD_EP_UPDATED); } else { - _notify(RDCLI_DEREGISTERED); + _notify(CORD_EP_DEREGISTERED); } } } @@ -87,25 +85,25 @@ static void *_reg_runner(void *arg) return NULL; /* should never be reached */ } -void rdcli_standalone_run(void) +void cord_ep_standalone_run(void) { thread_create(_stack, sizeof(_stack), PRIO, 0, _reg_runner, NULL, TNAME); } -void rdcli_standalone_signal(bool connected) +void cord_ep_standalone_signal(bool connected) { /* clear timer in any case */ xtimer_remove(&_timer); /* reset the update timer in case a connection was established or updated */ if (connected) { _set_timer(); - _notify(RDCLI_REGISTERED); + _notify(CORD_EP_REGISTERED); } else { - _notify(RDCLI_DEREGISTERED); + _notify(CORD_EP_DEREGISTERED); } } -void rdcli_standalone_reg_cb(rdcli_standalone_cb_t cb) +void cord_ep_standalone_reg_cb(cord_ep_standalone_cb_t cb) { /* Note: we do not allow re-setting the callback (via passing cb := NULL), * as this would mean additional complexity for synchronizing the From cfe4370a95a5bbf229c1da0c15cf849fc1464a49 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Mon, 15 Oct 2018 11:37:04 +0200 Subject: [PATCH 7/8] sys/shell/rdcli: rename to sc_cord_ep.c --- sys/shell/commands/Makefile | 4 +-- .../commands/{sc_rdcli.c => sc_cord_ep.c} | 32 +++++++++---------- sys/shell/commands/shell_commands.c | 8 ++--- 3 files changed, 22 insertions(+), 22 deletions(-) rename sys/shell/commands/{sc_rdcli.c => sc_cord_ep.c} (81%) diff --git a/sys/shell/commands/Makefile b/sys/shell/commands/Makefile index bcffa1c43e..9f5c4604f1 100644 --- a/sys/shell/commands/Makefile +++ b/sys/shell/commands/Makefile @@ -66,8 +66,8 @@ endif ifneq (,$(filter conn_can,$(USEMODULE))) SRC += sc_can.c endif -ifneq (,$(filter rdcli,$(USEMODULE))) - SRC += sc_rdcli.c +ifneq (,$(filter cord_ep,$(USEMODULE))) + SRC += sc_cord_ep.c endif ifneq (,$(filter periph_rtc,$(FEATURES_PROVIDED))) diff --git a/sys/shell/commands/sc_rdcli.c b/sys/shell/commands/sc_cord_ep.c similarity index 81% rename from sys/shell/commands/sc_rdcli.c rename to sys/shell/commands/sc_cord_ep.c index b480ba076c..a3023ffdc7 100644 --- a/sys/shell/commands/sc_rdcli.c +++ b/sys/shell/commands/sc_cord_ep.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Freie Universität Berlin + * Copyright (C) 2017-2018 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -11,7 +11,7 @@ * @{ * * @file - * @brief Shell commands for the rdcli module + * @brief Shell commands for the cord_ep module * * @author Hauke Petersen * @@ -21,7 +21,7 @@ #include #include -#include "net/rdcli.h" +#include "net/cord/ep.h" #include "net/nanocoap.h" #include "net/sock/util.h" #include "net/cord/config.h" @@ -40,7 +40,7 @@ static int make_sock_ep(sock_udp_ep_t *ep, const char *addr) return 0; } -int _rdcli_handler(int argc, char **argv) +int _cord_ep_handler(int argc, char **argv) { int res; @@ -60,12 +60,12 @@ int _rdcli_handler(int argc, char **argv) regif = argv[3]; } puts("Registering with RD now, this may take a short while..."); - if (rdcli_register(&remote, regif) != RDCLI_OK) { + if (cord_ep_register(&remote, regif) != CORD_EP_OK) { puts("error: registration failed"); } else { puts("registration successful\n"); - rdcli_dump_status(); + cord_ep_dump_status(); } } else if ((argc > 1) && (strcmp(argv[1], "discover") == 0)) { @@ -79,7 +79,7 @@ int _rdcli_handler(int argc, char **argv) printf("error: unable to parse address\n"); return 1; } - if (rdcli_discover_regif(&remote, regif, sizeof(regif)) == RDCLI_OK) { + if (cord_ep_discover_regif(&remote, regif, sizeof(regif)) == CORD_EP_OK) { printf("the registration interface is '%s'\n", regif); } else { @@ -87,14 +87,14 @@ int _rdcli_handler(int argc, char **argv) } } else if ((argc > 1) && (strcmp(argv[1], "update") == 0)) { - res = rdcli_update(); - if (res == RDCLI_OK) { + res = cord_ep_update(); + if (res == CORD_EP_OK) { puts("RD update successful"); } - else if (res == RDCLI_NORD) { + else if (res == CORD_EP_NORD) { puts("error: not associated with any RD"); } - else if (res == RDCLI_TIMEOUT) { + else if (res == CORD_EP_TIMEOUT) { puts("error: unable to reach RD - dropped association"); } else { @@ -102,14 +102,14 @@ int _rdcli_handler(int argc, char **argv) } } else if ((argc > 1) && (strcmp(argv[1], "remove") == 0)) { - res = rdcli_remove(); - if (res == RDCLI_OK) { + res = cord_ep_remove(); + if (res == CORD_EP_OK) { puts("node successfully removed from RD"); } - else if (res == RDCLI_NORD) { + else if (res == CORD_EP_NORD) { puts("error: not associated with any RD"); } - else if (res == RDCLI_TIMEOUT) { + else if (res == CORD_EP_TIMEOUT) { puts("error: unable to reach RD - remove association only locally"); } else { @@ -117,7 +117,7 @@ int _rdcli_handler(int argc, char **argv) } } else if ((argc > 1) && (strcmp(argv[1], "info") == 0)) { - rdcli_dump_status(); + cord_ep_dump_status(); } else { printf("usage: %s \n", diff --git a/sys/shell/commands/shell_commands.c b/sys/shell/commands/shell_commands.c index 673ef75eb4..c7f0f2249c 100644 --- a/sys/shell/commands/shell_commands.c +++ b/sys/shell/commands/shell_commands.c @@ -142,8 +142,8 @@ extern int _ls_handler(int argc, char **argv); extern int _can_handler(int argc, char **argv); #endif -#ifdef MODULE_RDCLI -extern int _rdcli_handler(int argc, char **argv); +#ifdef MODULE_CORD_EP +extern int _cord_ep_handler(int argc, char **argv); #endif const shell_command_t _shell_command_list[] = { @@ -237,8 +237,8 @@ const shell_command_t _shell_command_list[] = { #ifdef MODULE_CONN_CAN {"can", "CAN commands", _can_handler}, #endif -#ifdef MODULE_RDCLI - {"rdcli", "CoAP RD client commands", _rdcli_handler }, +#ifdef MODULE_CORD_EP + {"cord_ep", "Resource directory endpoint commands", _cord_ep_handler }, #endif {NULL, NULL, NULL} }; From 34fa61d7db78f75accc83e995b503afdca8d405c Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Mon, 15 Oct 2018 11:46:38 +0200 Subject: [PATCH 8/8] examples/rdcli: rename to cord_ep --- examples/{rdcli => cord_ep}/Makefile | 4 ++-- examples/cord_ep/README.md | 25 +++++++++++++++++++++++++ examples/{rdcli => cord_ep}/main.c | 16 ++++++++-------- examples/rdcli/README.md | 20 -------------------- 4 files changed, 35 insertions(+), 30 deletions(-) rename examples/{rdcli => cord_ep}/Makefile (96%) create mode 100644 examples/cord_ep/README.md rename examples/{rdcli => cord_ep}/main.c (83%) delete mode 100644 examples/rdcli/README.md diff --git a/examples/rdcli/Makefile b/examples/cord_ep/Makefile similarity index 96% rename from examples/rdcli/Makefile rename to examples/cord_ep/Makefile index c5b70456d3..79a1ad5dce 100644 --- a/examples/rdcli/Makefile +++ b/examples/cord_ep/Makefile @@ -1,5 +1,5 @@ # name of your application -APPLICATION = rdcli +APPLICATION = cord_ep # If no BOARD is found in the environment, use this default: BOARD ?= native @@ -32,7 +32,7 @@ USEMODULE += fmt CFLAGS += -DDEVELHELP # For debugging and demonstration purposes, we limit the lifetime to 60s -CFLAGS += -DRDCLI_LT=60 +CFLAGS += -DCORD_LT=60 # Change this to 0 show compiler invocation lines by default: QUIET ?= 1 diff --git a/examples/cord_ep/README.md b/examples/cord_ep/README.md new file mode 100644 index 0000000000..4b11baf715 --- /dev/null +++ b/examples/cord_ep/README.md @@ -0,0 +1,25 @@ +CoRE Resource Directory: Endpoint Example +========================================= + +This example application demonstrates the usage of RIOT's Resource Directory +(RD) endpoint module, called `cord_ep`. This module supports the registration, +update, and removal procedures as defined in +[draft-ietf-core-resource-directory-15](https://tools.ietf.org/html/draft-ietf-core-resource-directory-15). + +Usage +===== +The examples includes a shell command that you can use to interact with a given +RD, called `cord_ep`. Simply use that shell command without parameters for +more information on its usage. + +Some connection parameters are configured statically during compile time, +namely the lifetime (`CORD_LT`) and the node's endpoint name (`CORD_EP`). You +can change these values at compile time by overriding their defines using +command line arguments: +``` +CFLAGS="-DCORD_EP=\\\"your_ep_name_here\\\"" make all +``` +or by setting their values in the application's Makefile: +``` +CFLAGS += "-DCORD_EP=\"MyNewEpName\"" +``` diff --git a/examples/rdcli/main.c b/examples/cord_ep/main.c similarity index 83% rename from examples/rdcli/main.c rename to examples/cord_ep/main.c index d34572da57..b02f51de62 100644 --- a/examples/rdcli/main.c +++ b/examples/cord_ep/main.c @@ -11,7 +11,7 @@ * @{ * * @file - * @brief CoRE Resource Directory client (rdcli) example application + * @brief CoRE Resource Directory endpoint (cord_ep) example * * @author Hauke Petersen * @@ -30,18 +30,18 @@ #define MAIN_QUEUE_SIZE (8) static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; -/* we will use a custom event handler for dumping rdcli_standalone events */ -static void _on_rdcli_event(cord_ep_standalone_event_t event) +/* we will use a custom event handler for dumping cord_ep events */ +static void _on_ep_event(cord_ep_standalone_event_t event) { switch (event) { case CORD_EP_REGISTERED: - puts("rdcli event: now registered with a RD"); + puts("RD endpoint event: now registered with a RD"); break; case CORD_EP_DEREGISTERED: - puts("rdcli event: dropped client registration"); + puts("RD endpoint event: dropped client registration"); break; case CORD_EP_UPDATED: - puts("rdcli event: successfully updated client registration"); + puts("RD endpoint event: successfully updated client registration"); break; } } @@ -95,11 +95,11 @@ int main(void) gcoap_register_listener(&_listener); /* register event callback with cord_ep_standalone */ - cord_ep_standalone_reg_cb(_on_rdcli_event); + cord_ep_standalone_reg_cb(_on_ep_event); puts("Client information:"); printf(" ep: %s\n", cord_common_get_ep()); - printf(" lt: %is\n", (int)RDCLI_LT); + printf(" lt: %is\n", (int)CORD_LT); char line_buf[SHELL_DEFAULT_BUFSIZE]; shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); diff --git a/examples/rdcli/README.md b/examples/rdcli/README.md deleted file mode 100644 index 315e6087e6..0000000000 --- a/examples/rdcli/README.md +++ /dev/null @@ -1,20 +0,0 @@ -CoRE Resource Directory Client Example -====================================== -This example application demonstrates the usage of RIOT's Resource Directory -(RD) client module, called `rdcli`. This module supports the registration, -update, and removal processes as defined in the -[Resource Directory Draft](https://tools.ietf.org/html/draft-ietf-core-resource-directory-14). - -Usage -===== -The examples includes a shell command that you can use to interact with a given -RD server, called `rdcli`. Simply use that shell command without parameters for -more information on its usage. - -Some connection parameters are configured statically during compile time, -namely the lifetime (`RDCLI_LT`) and the node's endpoint name (`RDCLI_EP`). You -can change these values during command line by overriding these values in the -application's Makefile, e.g. add -``` -CFLAGS += "-DRDCLI_EP=\"MyNewEpName\"" -```