1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

net/rdcli: added common rdcli module

This commit is contained in:
Hauke Petersen 2017-07-25 15:12:39 +02:00
parent d7bf2c112e
commit f12d85d032
7 changed files with 189 additions and 0 deletions

View File

@ -707,6 +707,12 @@ ifneq (,$(filter skald,$(USEMODULE)))
USEMODULE += xtimer
USEMODULE += random
endif
ifneq (,$(filter rdcli_common,$(USEMODULE)))
USEMODULE += luid
USEMODULE += fmt
endif
# always select gpio (until explicit dependencies are sorted out)
FEATURES_OPTIONAL += periph_gpio

View File

@ -127,6 +127,9 @@ endif
ifneq (,$(filter skald,$(USEMODULE)))
DIRS += net/skald
endif
ifneq (,$(filter rdcli_common,$(USEMODULE)))
DIRS += net/application_layer/rdcli_common
endif
DIRS += $(dir $(wildcard $(addsuffix /Makefile, $(USEMODULE))))

View File

@ -159,6 +159,11 @@ 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();
#endif
/* initialize network devices */
#ifdef MODULE_AUTO_INIT_GNRC_NETIF

View File

@ -0,0 +1,54 @@
/*
* Copyright (C) 2017 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_common Shared Functions for CoRE RD Clients
* @ingroup net_rdcli
* @{
*
* @file
* @brief Shared CoRE RD client functions
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*/
#ifndef NET_RDCLI_COMMON_H
#define NET_RDCLI_COMMON_H
#include "net/rdcli_config.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Export the local endpoint identifier
*
* @note Use rdcli_common_get_ep() for accessing the endpoint identifier
*/
extern char rdcli_ep[];
/**
* @brief Generate unique endpoint identifier (ep)
*/
void rdcli_common_init(void);
/**
* @brief Get the local endpoint identifier
*/
static inline const char *rdcli_common_get_ep(void)
{
return (const char *)rdcli_ep;
}
#ifdef __cplusplus
}
#endif
#endif /* NET_RDCLI_COMMON_H */
/** @} */

View File

@ -0,0 +1,60 @@
/*
* Copyright (C) 2017 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_config CoAP Resource Directory Client Configuration
* @ingroup net_rdcli
* @{
*
* @file
* @brief
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*/
#ifndef NET_RDCLI_CONFIG_H
#define NET_RDCLI_CONFIG_H
#include "net/ipv6/addr.h"
#ifdef __cplusplus
extern "C" {
#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
* hexadecimal formatting with the given length of characters
* (RDCLI_EP_SUFFIX_LEN).
*
* Alternatively, the endpoint ID value can be defined at compile time by
* assigning a string value to the RDCLI_ED macro.
*
* @{
*/
#ifndef RDCLI_EP
/**
* @brief Number of generated hexadecimal characters added to the ep
*/
#define RDCLI_EP_SUFFIX_LEN (16)
/**
* @brief Default static prefix used for the generated ep
*/
#define RDCLI_EP_PREFIX "RIOT-"
#endif
/** @} */
#ifdef __cplusplus
}
#endif
#endif /* NET_RDCLI_CONFIG_H */
/** @} */

View File

@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,60 @@
/*
* Copyright (C) 2017 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.
*/
/**
* @ingroup net_rdcli_common
* @{
*
* @file
* @brief Implementation of common functions for CoRE RD clients
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/
#include "fmt.h"
#include "luid.h"
#include "net/rdcli_common.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
#ifdef RDCLI_EP
#define EP_LEN (sizeof(RDCLI_EP))
#define BUFSIZE (EP_LEN + 1)
#else
#define PREFIX_LEN (sizeof(RDCLI_EP_PREFIX))
#define BUFSIZE (PREFIX_LEN + RDCLI_EP_SUFFIX_LEN + 1)
#endif
char rdcli_ep[BUFSIZE];
void rdcli_common_init(void)
{
size_t pos = 0;
#ifdef RDCLI_EP
memcpy(rdcli_ep, RDCLI_EP, EP_LEN);
pos += EP_LEN;
#else
uint8_t luid[RDCLI_EP_SUFFIX_LEN / 2];
if (PREFIX_LEN) {
memcpy(rdcli_ep, RDCLI_EP_PREFIX, PREFIX_LEN);
pos += PREFIX_LEN - 1;
}
luid_get(luid, sizeof(luid));
fmt_bytes_hex(&rdcli_ep[pos], luid, sizeof(luid));
#endif
rdcli_ep[pos] = '\0';
}