mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
net/rdcli: rename to cord_ep
This commit is contained in:
parent
5668100dc3
commit
18cc7ee3ed
@ -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
|
||||
|
@ -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
|
||||
|
@ -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());
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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");
|
||||
|
@ -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 <hauke.petersen@fu-berlin.de>
|
||||
*/
|
||||
|
||||
#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 */
|
||||
/** @} */
|
88
sys/include/net/cord/ep_standalone.h
Normal file
88
sys/include/net/cord/ep_standalone.h
Normal file
@ -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 <hauke.petersen@fu-berlin.de>
|
||||
*/
|
||||
|
||||
#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 */
|
||||
/** @} */
|
@ -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 <hauke.petersen@fu-berlin.de>
|
||||
*/
|
||||
|
||||
#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 */
|
||||
/** @} */
|
@ -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
|
||||
|
@ -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 <hauke.petersen@fu-berlin.de>
|
||||
*
|
||||
@ -20,18 +20,18 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#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:");
|
||||
|
@ -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 <hauke.petersen@fu-berlin.de>
|
||||
*
|
||||
@ -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
|
Loading…
Reference in New Issue
Block a user