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

pkg/wakaama/contrib: cleanup device object implementation

This commit is contained in:
Leandro Lanzieri 2021-03-23 11:50:57 +01:00
parent 70c4c6b8c1
commit 3d012bfd2c
No known key found for this signature in database
GPG Key ID: F4E9A721761C7593
7 changed files with 422 additions and 334 deletions

View File

@ -21,6 +21,7 @@
#include "kernel_defines.h"
#include "lwm2m_client.h"
#include "objects/device.h"
#include "lwm2m_client_config.h"
#include "lwm2m_client_objects.h"
@ -29,7 +30,6 @@
* 'contrib/objects') */
lwm2m_object_t *get_server_object(int server_id, const char *binding,
int lifetime, bool storing);
lwm2m_object_t *lwm2m_get_object_device(void);
lwm2m_object_t *lwm2m_client_get_server_object(lwm2m_client_data_t *client_data,
int server_id)
@ -42,10 +42,3 @@ lwm2m_object_t *lwm2m_client_get_server_object(lwm2m_client_data_t *client_data,
false);
return ret;
}
lwm2m_object_t *lwm2m_client_get_device_object(
lwm2m_client_data_t *client_data)
{
(void)client_data;
return lwm2m_get_object_device();
}

View File

@ -5,5 +5,6 @@
# directory for more details.
#
rsource "Kconfig.light_control"
rsource "Kconfig.device"
rsource "Kconfig.security"
rsource "Kconfig.light_control"

View File

@ -0,0 +1,68 @@
# Copyright (c) 2021 HAW Hamburg
#
# 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.
#
menu "Device"
choice
bool "Device binding and queue mode"
default LWM2M_DEVICE_BINDING_U
config LWM2M_DEVICE_BINDING_U
bool "UDP"
config LWM2M_DEVICE_BINDING_UQ
bool "UDP with Queue mode"
config LWM2M_DEVICE_BINDING_S
bool "SMS"
config LWM2M_DEVICE_BINDING_SQ
bool "SMS with Queue mode"
config LWM2M_DEVICE_BINDING_US
bool "UDP and SMS"
config LWM2M_DEVICE_BINDING_UQS
bool "UDP with Queue mode and SMS"
endchoice
config LWM2M_DEVICE_NAME
string "Device name"
default "testRIOTDevice"
help
This is the device name used to register at the LwM2M server.
config LWM2M_DEVICE_MANUFACTURER
string "Device manufacturer"
default "A RIOT maker"
config LWM2M_DEVICE_MODEL
string "Device model"
default "$(BOARD)"
config LWM2M_DEVICE_TYPE
string "Device type"
default "RIOT device"
config LWM2M_DEVICE_SERIAL
string "Device serial number"
default "undefined"
config LWM2M_DEVICE_FW_VERSION
string "Device firmware version"
default ""
config LWM2M_DEVICE_HW_VERSION
string "Device hardware version"
default "$(BOARD)"
config LWM2M_DEVICE_SW_VERSION
string "Device software version"
default ""
endmenu # Device

View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2018 Beduino Master Projekt - University of Bremen
* 2021 HAW Hamburg
*
* 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
@ -13,6 +14,7 @@
* @brief Device object implementation for LwM2M client using Wakaama
*
* @author Christian Manal <manal@uni-bremen.de>
* @author Leandro Lanzieri <leandro.lanzieri@haw-hamburg.de>
* @}
*/
@ -25,43 +27,90 @@
#include "objects/device.h"
#include "lwm2m_client_config.h"
#define ENABLE_DEBUG 0
#include "debug.h"
/* Set to true if reboot requested. */
static bool reboot;
/* Lookup table for static resources of device object */
static const char *_static_resources[] = {
[LWM2M_RES_MANUFACTURER] = CONFIG_LWM2M_DEVICE_MANUFACTURER,
[LWM2M_RES_MODEL_NO] = CONFIG_LWM2M_DEVICE_MODEL,
[LWM2M_RES_SERIAL] = CONFIG_LWM2M_DEVICE_SERIAL,
[LWM2M_RES_FW_VER] = CONFIG_LWM2M_DEVICE_FW_VERSION,
[LWM2M_RES_BINDINGS] = CONFIG_LWM2M_DEVICE_BINDINGS,
[LWM2M_RES_TYPE] = CONFIG_LWM2M_DEVICE_TYPE,
[LWM2M_RES_HW_VERSION] = CONFIG_LWM2M_DEVICE_HW_VERSION,
[LWM2M_RES_SW_VERSION] = CONFIG_LWM2M_DEVICE_SW_VERSION,
[LWM2M_DEVICE_RESOURCES] = NULL
/**
* @brief 'Execute' callback for the Device object.
*
* @param[in] instance_id Instance ID. Should be 0 as a single instance exists.
* @param[in] resource_id ID of the resource to execute.
* @param[in] buffer Information needed for the execution.
* @param[in] length Length of @p buffer.
* @param[in] object Device object pointer
*
* @return COAP_204_CHANGED on success
* @return COAP_404_NOT_FOUND when wrong instance specified
* @return COAP_400_BAD_REQUEST when wrong information has been sent
* @return COAP_405_METHOD_NOT_ALLOWED when trying to execute a resource that is not supported
*/
static uint8_t _execute_cb(uint16_t instance_id, uint16_t resource_id, uint8_t *buffer, int length,
lwm2m_object_t *object);
/**
* @brief 'Read' callback for the Device object.
*
* @param[in] instance_id Instance ID. Should be 0 as a single instance exists.
* @param[in, out] num_data Number of resources requested. 0 means all.
* @param[in, out] data_array Initialized data array to output the values,
* when @p num_data != 0. Uninitialized otherwise.
* @param[in] object Device object pointer
*
* @return COAP_205_CONTENT on success
* @return COAP_404_NOT_FOUND when resource can't be found
* @return COAP_500_INTERNAL_SERVER_ERROR otherwise
*/
static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data_array,
lwm2m_object_t *object);
/**
* @brief 'Discover' callback for the Device object.
*
* @param[in] instance_id Instance ID. Should be 0 as a single instance exists.
* @param[in, out] num_data Number of resources requested. 0 means all.
* @param[in, out] data_array Initialized data array to determine if the resource exists,
* when @p num_data != 0. Uninitialized otherwise.
* @param[in] object Device object pointer
*
* @return COAP_205_CONTENT on success
* @return COAP_404_NOT_FOUND when a resource is not supported
* @return COAP_500_INTERNAL_SERVER_ERROR otherwise
*/
static uint8_t _discover_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data_array,
lwm2m_object_t *object);
typedef struct {
lwm2m_list_t list; /**< Linked list handle */
} lwm2m_obj_device_inst_t;
static const lwm2m_obj_device_inst_t _instance;
/**
* @brief Implementation of the object interface for the Device Object.
*/
static lwm2m_object_t _device_object = {
.next = NULL,
.objID = LWM2M_DEVICE_OBJECT_ID,
.instanceList = (lwm2m_list_t *)&_instance,
.readFunc = _read_cb,
.executeFunc = _execute_cb,
.discoverFunc = _discover_cb,
.writeFunc = NULL,
.deleteFunc = NULL,
.createFunc = NULL,
.userData = NULL
};
/*Descriptor of a LwM2M device object instance */
typedef struct {
uint8_t *power_sources; /**< types of power sources (0-7) */
uint16_t *power_voltage; /**< voltage of power sources in mV */
uint16_t *power_current; /**< current of power sources in mA */
uint8_t battery_status; /**< battery status (0-6) */
uint32_t mem_total; /**< amount of memory on the device in kB */
uint16_t(*ext_dev_info)[2]; /**< external devices information */
uint8_t ext_dev_info_len; /**< amount of external devices information */
uint8_t error_code[7]; /**< error codes */
uint8_t error_code_used; /**< amount of error codes used */
} dev_data_t;
static uint8_t prv_device_discover(uint16_t instance_id, int *num_dataP,
lwm2m_data_t **data_arrayP,
lwm2m_object_t *objectP)
static uint8_t _discover_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data_array,
lwm2m_object_t *object)
{
uint8_t result;
int i;
(void)objectP;
(void)object;
if (instance_id != 0) {
return COAP_404_NOT_FOUND;
@ -69,7 +118,7 @@ static uint8_t prv_device_discover(uint16_t instance_id, int *num_dataP,
result = COAP_205_CONTENT;
if (*num_dataP == 0) {
if (*num_data == 0) {
/* This list must contain all available resources */
uint16_t res[] = {
LWM2M_RES_MANUFACTURER, LWM2M_RES_MODEL_NO, LWM2M_RES_SERIAL,
@ -80,19 +129,22 @@ static uint8_t prv_device_discover(uint16_t instance_id, int *num_dataP,
};
int len = ARRAY_SIZE(res);
*data_arrayP = lwm2m_data_new(len);
if (*data_arrayP == NULL) {
*data_array = lwm2m_data_new(len);
*num_data = len;
if (*data_array == NULL) {
DEBUG("[lwm2m:device:discover] could not allocate data array\n");
return COAP_500_INTERNAL_SERVER_ERROR;
}
*num_dataP = len;
for (i = 0; i < len; i++) {
(*data_arrayP)[i].id = res[i];
(*data_array)[i].id = res[i];
}
}
else {
/* Check if each given resource is present */
for (i = 0; i < *num_dataP && result == COAP_205_CONTENT; i++) {
switch ((*data_arrayP)[i].id) {
for (i = 0; i < *num_data && result == COAP_205_CONTENT; i++) {
switch ((*data_array)[i].id) {
case LWM2M_RES_MANUFACTURER:
case LWM2M_RES_MODEL_NO:
case LWM2M_RES_SERIAL:
@ -114,23 +166,22 @@ static uint8_t prv_device_discover(uint16_t instance_id, int *num_dataP,
return result;
}
static uint8_t prv_device_read(uint16_t instance_id, int *num_dataP,
lwm2m_data_t **data_arrayP,
lwm2m_object_t *objectP)
static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data_array,
lwm2m_object_t *object)
{
(void)object;
int i;
uint8_t result = COAP_404_NOT_FOUND;
dev_data_t *data = (dev_data_t *)objectP->userData;
(void)data;
DEBUG("[lwm2m:device:read]\n");
/* Single instance object */
if (instance_id != 0) {
goto out;
return COAP_404_NOT_FOUND;
}
/* Full object requested */
if (*num_dataP == 0) {
if (*num_data == 0) {
DEBUG("[lwm2m:device:read] all resources are requested\n");
/* This list must contain all readable resources */
uint16_t resList[] = {
LWM2M_RES_MANUFACTURER, LWM2M_RES_MODEL_NO, LWM2M_RES_SERIAL,
@ -138,109 +189,103 @@ static uint8_t prv_device_read(uint16_t instance_id, int *num_dataP,
LWM2M_RES_BINDINGS, LWM2M_RES_TYPE, LWM2M_RES_ERROR_CODE,
};
int cnt = ARRAY_SIZE(resList);
*data_arrayP = lwm2m_data_new(cnt);
if (*data_arrayP == NULL) {
result = COAP_500_INTERNAL_SERVER_ERROR;
goto out;
*data_array = lwm2m_data_new(cnt);
*num_data = cnt;
if (*data_array == NULL) {
DEBUG("[lwm2m:device:read] could not allocate data array\n");
return COAP_500_INTERNAL_SERVER_ERROR;
}
*num_dataP = cnt;
for (i = 0; i < cnt; i++) {
(*data_arrayP)[i].id = resList[i];
(*data_array)[i].id = resList[i];
}
}
for (i = 0; i < *num_dataP; i++) {
switch ((*data_arrayP)[i].id) {
/* Exec resources */
case LWM2M_RES_REBOOT:
case LWM2M_RES_FRESET:
case LWM2M_RES_ERROR_CODE_RESET:
result = COAP_405_METHOD_NOT_ALLOWED;
goto out;
break;
case LWM2M_RES_ERROR_CODE:
/* TODO: Here some error reporting should be implemented. */
lwm2m_data_encode_int(LWM2M_DEVICE_ERR_NO_ERR, *data_arrayP + i);
result = COAP_205_CONTENT;
break;
/* The rest are either static or not defined resources */
default:
if (_static_resources[(*data_arrayP)[i].id]) {
lwm2m_data_encode_string(
_static_resources[(*data_arrayP)[i].id],
*data_arrayP + i);
result = COAP_205_CONTENT;
}
else {
result = COAP_404_NOT_FOUND;
goto out;
}
for (i = 0; i < *num_data; i++) {
lwm2m_data_t *data = &(*data_array)[i];
DEBUG("[lwm2m:device:read] reading resource %d\n", data->id);
switch (data->id) {
/* Exec resources, can't be read */
case LWM2M_RES_REBOOT:
case LWM2M_RES_FRESET:
case LWM2M_RES_ERROR_CODE_RESET:
return COAP_405_METHOD_NOT_ALLOWED;
break;
case LWM2M_RES_ERROR_CODE:
/* TODO: Here some error reporting should be implemented. For now returning no error */
lwm2m_data_encode_int(LWM2M_DEVICE_ERR_NO_ERR, data);
break;
case LWM2M_RES_MANUFACTURER:
lwm2m_data_encode_string(CONFIG_LWM2M_DEVICE_MANUFACTURER, data);
break;
case LWM2M_RES_MODEL_NO:
lwm2m_data_encode_string(CONFIG_LWM2M_DEVICE_MODEL, data);
break;
case LWM2M_RES_SERIAL:
lwm2m_data_encode_string(CONFIG_LWM2M_DEVICE_SERIAL, data);
break;
case LWM2M_RES_FW_VER:
lwm2m_data_encode_string(CONFIG_LWM2M_DEVICE_FW_VERSION, data);
break;
case LWM2M_RES_BINDINGS:
lwm2m_data_encode_string(CONFIG_LWM2M_DEVICE_BINDINGS, data);
break;
case LWM2M_RES_TYPE:
lwm2m_data_encode_string(CONFIG_LWM2M_DEVICE_TYPE, data);
break;
case LWM2M_RES_HW_VERSION:
lwm2m_data_encode_string(CONFIG_LWM2M_DEVICE_HW_VERSION, data);
break;
case LWM2M_RES_SW_VERSION:
lwm2m_data_encode_string(CONFIG_LWM2M_DEVICE_SW_VERSION, data);
break;
case LWM2M_DEVICE_RESOURCES:
lwm2m_data_encode_string(NULL, data);
break;
/* The rest are not defined resources */
default:
return COAP_404_NOT_FOUND;
}
}
out:
return result;
return COAP_205_CONTENT;
}
static uint8_t prv_device_write(uint16_t instance_id, int num_data,
lwm2m_data_t *data_array,
lwm2m_object_t *objectP)
static uint8_t _execute_cb(uint16_t instance_id, uint16_t resource_id, uint8_t *buffer, int length,
lwm2m_object_t *object)
{
dev_data_t *data = (dev_data_t *)objectP->userData;
(void)data;
(void)instance_id;
(void)num_data;
(void)data_array;
if (data_array[0].id < LWM2M_DEVICE_RESOURCES) {
/* for now not writing resources */
return COAP_405_METHOD_NOT_ALLOWED;
}
else {
return COAP_404_NOT_FOUND;
}
}
static uint8_t prv_device_execute(uint16_t instance_id, uint16_t resource_id,
uint8_t *buffer, int length,
lwm2m_object_t *objectP)
{
uint8_t result;
dev_data_t *data = (dev_data_t *)objectP->userData;
(void)data;
(void)buffer;
(void)length;
(void)objectP;
(void)object;
/* single instance object */
if (instance_id != 0) {
result = COAP_404_NOT_FOUND;
goto err_out;
return COAP_404_NOT_FOUND;
}
if (length != 0) {
result = COAP_400_BAD_REQUEST;
goto err_out;
return COAP_400_BAD_REQUEST;
}
switch (resource_id) {
case LWM2M_RES_REBOOT:
reboot = true;
result = COAP_204_CHANGED;
break;
case LWM2M_RES_ERROR_CODE_RESET:
/* TODO */
case LWM2M_RES_FRESET:
/* TODO Callback? */
default:
result = COAP_405_METHOD_NOT_ALLOWED;
/* for now only rebooting is available */
if (resource_id == LWM2M_RES_REBOOT) {
reboot = true;
return COAP_204_CHANGED;
}
err_out:
return result;
return COAP_405_METHOD_NOT_ALLOWED;
}
/*
@ -251,63 +296,10 @@ bool lwm2m_device_reboot_requested(void)
return reboot;
}
lwm2m_object_t *lwm2m_get_object_device(void)
lwm2m_object_t *lwm2m_object_device_init(lwm2m_client_data_t *client_data)
{
lwm2m_object_t *obj;
assert(client_data);
obj = (lwm2m_object_t *)lwm2m_malloc(sizeof(lwm2m_object_t));
if (obj == NULL) {
goto err_out;
}
memset(obj, 0, sizeof(lwm2m_object_t));
obj->instanceList = (lwm2m_list_t *)lwm2m_malloc(sizeof(lwm2m_list_t));
if (obj->instanceList == NULL) {
goto free_obj;
}
memset(obj->instanceList, 0, sizeof(lwm2m_list_t));
obj->objID = LWM2M_DEVICE_OBJECT_ID;
obj->readFunc = prv_device_read;
obj->writeFunc = prv_device_write;
obj->executeFunc = prv_device_execute;
obj->discoverFunc = prv_device_discover;
/* Don't allocate memory for stuff that isn't used at the moment */
/* obj->userData = lwm2m_malloc(sizeof(dev_data_t)); */
/* if (obj->userData == NULL) { */
/* goto free_ilist; */
/* } */
/* */
/* memset(obj->userData, 0, sizeof(dev_data_t)); */
/* INT USER DATA HERE */
return obj;
/* free_ilist: */
/* lwm2m_free(obj->instanceList); */
free_obj:
lwm2m_free(obj);
err_out:
return NULL;
}
void lwm2m_free_object_device(lwm2m_object_t *obj)
{
if (obj == NULL) {
return;
}
if (obj->userData) {
lwm2m_free(obj->userData);
}
if (obj->instanceList) {
lwm2m_free(obj->instanceList);
}
lwm2m_free(obj);
_device_object.userData = client_data;
return &_device_object;
}

View File

@ -59,10 +59,10 @@ extern "C" {
#endif
/**
* @brief Device name used to register at the LwM2M server
* @brief Default port for the local LwM2M CoAPs server
*/
#ifndef CONFIG_LWM2M_DEVICE_NAME
#define CONFIG_LWM2M_DEVICE_NAME "testRIOTDevice"
#ifndef CONFIG_LWM2M_LOCAL_DTLS_PORT
#define CONFIG_LWM2M_LOCAL_DTLS_PORT "5684"
#endif
/**
@ -92,131 +92,6 @@ extern "C" {
#define CONFIG_LWM2M_BOOTSTRAP
#endif
/**
* @brief Device object manufacturer string
*/
#ifndef CONFIG_LWM2M_DEVICE_MANUFACTURER
#define CONFIG_LWM2M_DEVICE_MANUFACTURER "A RIOT maker"
#endif
/**
* @brief Device object model.
*
* @note Defaults to the board name
*/
#ifndef CONFIG_LWM2M_DEVICE_MODEL
#define CONFIG_LWM2M_DEVICE_MODEL RIOT_BOARD
#endif
/**
* @brief Device object serial number
*/
#ifndef CONFIG_LWM2M_DEVICE_SERIAL
#define CONFIG_LWM2M_DEVICE_SERIAL "undefined"
#endif
/**
* @brief Device object firmware version
*
* @note Defaults to the running RIOT version
*/
#ifndef CONFIG_LWM2M_DEVICE_FW_VERSION
#define CONFIG_LWM2M_DEVICE_FW_VERSION RIOT_VERSION
#endif
/**
* @{
* @name Device bindings and queue modes
*
* This options are meant to be set either via Kconfig or CFLAGS:
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.mk}
* CFLAGS += -DCONFIG_LWM2M_DEVICE_BINDING_UQ
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* @note Only one option should be selected. If more than one is defined the
* priority follows this order. By default
* @ref CONFIG_LWM2M_DEVICE_BINDING_U is assumed.
*/
#ifdef DOXYGEN
/**
* @brief UDP binding
*/
#define CONFIG_LWM2M_DEVICE_BINDING_U
/**
* @brief UDP binding with Queue mode
*/
#define CONFIG_LWM2M_DEVICE_BINDING_UQ
/**
* @brief SMS binding
*/
#define CONFIG_LWM2M_DEVICE_BINDING_S
/**
* @brief SMS binding with Queue mode
*/
#define CONFIG_LWM2M_DEVICE_BINDING_SQ
/**
* @brief UDP and SMS bindings
*/
#define CONFIG_LWM2M_DEVICE_BINDING_US
/**
* @brief UDP and SMS bindings with Queue mode
*/
#define CONFIG_LWM2M_DEVICE_BINDING_UQS
#endif
/** @} */
/**
* @brief Device object device type
*/
#ifndef CONFIG_LWM2M_DEVICE_TYPE
#define CONFIG_LWM2M_DEVICE_TYPE "RIOT device"
#endif
/**
* @brief Device object hardware version
*
* @note Defaults to the board name
*/
#ifndef CONFIG_LWM2M_DEVICE_HW_VERSION
#define CONFIG_LWM2M_DEVICE_HW_VERSION RIOT_BOARD
#endif
/**
* @brief Device object software version
*
* @note Defaults to the running RIOT version
*/
#ifndef CONFIG_LWM2M_DEVICE_SW_VERSION
#define CONFIG_LWM2M_DEVICE_SW_VERSION RIOT_VERSION
#endif
/**
* @brief Device binding and queue mode
*
* @note Select using CONFIG_LWM2M_DEVICE_BINDING_*
*/
#if defined(CONFIG_LWM2M_DEVICE_BINDING_U)
#define CONFIG_LWM2M_DEVICE_BINDINGS "U"
#elif defined(CONFIG_LWM2M_DEVICE_BINDING_UQ)
#define CONFIG_LWM2M_DEVICE_BINDINGS "UQ"
#elif defined(CONFIG_LWM2M_DEVICE_BINDING_S)
#define CONFIG_LWM2M_DEVICE_BINDINGS "S"
#elif defined(CONFIG_LWM2M_DEVICE_BINDING_SQ)
#define CONFIG_LWM2M_DEVICE_BINDINGS "SQ"
#elif defined(CONFIG_LWM2M_DEVICE_BINDING_US)
#define CONFIG_LWM2M_DEVICE_BINDINGS "US"
#elif defined(CONFIG_LWM2M_DEVICE_BINDING_UQS)
#define CONFIG_LWM2M_DEVICE_BINDINGS "UQS"
#else
#define CONFIG_LWM2M_DEVICE_BINDINGS "U"
#endif
/**
* @brief Number to use as base for assigning tags to @ref net_credman credentials.
*/

View File

@ -51,18 +51,7 @@ extern "C" {
* @return NULL otherwise
*/
lwm2m_object_t *lwm2m_client_get_server_object(
lwm2m_client_data_t *client_data);
/**
* @brief Creates a LwM2M device object with the default configuration from
* net/lwm2m.h
* @param[in, out] client_data Pointer to a LwM2M client data descriptor
*
* @return Pointer to the created object
* @return NULL otherwise
*/
lwm2m_object_t *lwm2m_client_get_device_object(
lwm2m_client_data_t *client_data);
lwm2m_client_data_t *client_data, int server_id);
/**
* @brief Creates a LwM2M access control object with the default configuration

View File

@ -10,6 +10,33 @@
* @ingroup lwm2m_objects
* @defgroup lwm2m_objects_device Device LwM2M object
* @brief Device object implementation for LwM2M client using Wakaama
*
* | Name | ID | Mandatory | Type | Range | Units | Implemented |
* |-----------------------------|:--:|:---------:|:-------:|:-----:|:-----:|:-----------:|
* | Manufacturer | 0 | No | String | - | - | Yes |
* | Model Number | 1 | No | String | - | - | Yes |
* | Serial Number | 2 | No | String | - | - | Yes |
* | Firmware Version | 3 | No | String | - | - | Yes |
* | Reboot | 4 | Yes | - | - | - | Yes |
* | Factory Reset | 5 | No | - | - | - | No |
* | Available Power Sources | 6 | No | Integer | 0-7 | - | No |
* | Power Source Voltage | 7 | No | Integer | - | mV | No |
* | Power Source Current | 8 | No | Integer | - | mA | No |
* | Battery Level | 9 | No | Integer | 0-100 | % | No |
* | Memory Free | 10 | No | Integer | - | KB | No |
* | Error Code | 11 | Yes | Integer | 0-8 | - | No |
* | Reset Error Code | 12 | No | - | - | - | No |
* | Current Time | 13 | No | Time | - | - | No |
* | UTC Offset | 14 | No | String | - | - | No |
* | Timezone | 15 | No | String | - | - | No |
* | Supported Binding and Modes | 16 | Yes | String | - | - | Yes |
* | Device Type | 17 | No | String | - | - | Yes |
* | Hardware Version | 18 | No | String | - | - | Yes |
* | Software Version | 19 | No | String | - | - | Yes |
* | Battery Status | 20 | No | Integer | 0-6 | - | No |
* | Memory Total | 21 | No | Integer | - | - | No |
* | ExtDevInfo | 22 | No | Objlnk | - | - | No |
*
* @{
*
* @file
@ -29,6 +56,7 @@ extern "C" {
#include <string.h>
#include "liblwm2m.h"
#include "lwm2m_client.h"
#include "lwm2m_client_config.h"
/**
@ -81,11 +109,153 @@ enum lwm2m_device_error_codes {
};
/**
* @brief Frees the memory of @p obj device object
* @defgroup lwm2m_objects_device_config LwM2M Device Object configuration
* @ingroup lwm2m_client_config
*
* @param[in] obj pointer to the device object
* @brief Configuration options for the LwM2M Device Object.
* @{
*/
void lwm2m_free_object_device(lwm2m_object_t *obj);
/**
* @brief Device name used to register at the LwM2M server
*/
#ifndef CONFIG_LWM2M_DEVICE_NAME
#define CONFIG_LWM2M_DEVICE_NAME "testRIOTDevice"
#endif
/**
* @brief Device object manufacturer string
*/
#ifndef CONFIG_LWM2M_DEVICE_MANUFACTURER
#define CONFIG_LWM2M_DEVICE_MANUFACTURER "A RIOT maker"
#endif
/**
* @brief Device object model.
*
* @note Defaults to the board name
*/
#ifndef CONFIG_LWM2M_DEVICE_MODEL
#define CONFIG_LWM2M_DEVICE_MODEL RIOT_BOARD
#endif
/**
* @brief Device object serial number
*/
#ifndef CONFIG_LWM2M_DEVICE_SERIAL
#define CONFIG_LWM2M_DEVICE_SERIAL "undefined"
#endif
/**
* @brief Device object firmware version
*
* @note Defaults to the running RIOT version
*/
#ifndef CONFIG_LWM2M_DEVICE_FW_VERSION
#define CONFIG_LWM2M_DEVICE_FW_VERSION RIOT_VERSION
#endif
/**
* @{
* @name Device bindings and queue modes
*
* This options are meant to be set either via Kconfig or CFLAGS:
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.mk}
* CFLAGS += -DCONFIG_LWM2M_DEVICE_BINDING_UQ
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* @note Only one option should be selected. If more than one is defined the
* priority follows this order. By default
* @ref CONFIG_LWM2M_DEVICE_BINDING_U is assumed.
*/
#ifdef DOXYGEN
/**
* @brief UDP binding
*/
#define CONFIG_LWM2M_DEVICE_BINDING_U
/**
* @brief UDP binding with Queue mode
*/
#define CONFIG_LWM2M_DEVICE_BINDING_UQ
/**
* @brief SMS binding
*/
#define CONFIG_LWM2M_DEVICE_BINDING_S
/**
* @brief SMS binding with Queue mode
*/
#define CONFIG_LWM2M_DEVICE_BINDING_SQ
/**
* @brief UDP and SMS bindings
*/
#define CONFIG_LWM2M_DEVICE_BINDING_US
/**
* @brief UDP and SMS bindings with Queue mode
*/
#define CONFIG_LWM2M_DEVICE_BINDING_UQS
#endif
/** @} */
/**
* @brief Device object device type
*/
#ifndef CONFIG_LWM2M_DEVICE_TYPE
#define CONFIG_LWM2M_DEVICE_TYPE "RIOT device"
#endif
/**
* @brief Device object hardware version
*
* @note Defaults to the board name
*/
#ifndef CONFIG_LWM2M_DEVICE_HW_VERSION
#define CONFIG_LWM2M_DEVICE_HW_VERSION RIOT_BOARD
#endif
/**
* @brief Device object software version
*
* @note Defaults to the running RIOT version
*/
#ifndef CONFIG_LWM2M_DEVICE_SW_VERSION
#define CONFIG_LWM2M_DEVICE_SW_VERSION RIOT_VERSION
#endif
/** @} */
/**
* @brief Device binding and queue mode
*
* @note Select using CONFIG_LWM2M_DEVICE_BINDING_*
*/
#if defined(CONFIG_LWM2M_DEVICE_BINDING_U)
#define CONFIG_LWM2M_DEVICE_BINDINGS "U"
#elif defined(CONFIG_LWM2M_DEVICE_BINDING_UQ)
#define CONFIG_LWM2M_DEVICE_BINDINGS "UQ"
#elif defined(CONFIG_LWM2M_DEVICE_BINDING_S)
#define CONFIG_LWM2M_DEVICE_BINDINGS "S"
#elif defined(CONFIG_LWM2M_DEVICE_BINDING_SQ)
#define CONFIG_LWM2M_DEVICE_BINDINGS "SQ"
#elif defined(CONFIG_LWM2M_DEVICE_BINDING_US)
#define CONFIG_LWM2M_DEVICE_BINDINGS "US"
#elif defined(CONFIG_LWM2M_DEVICE_BINDING_UQS)
#define CONFIG_LWM2M_DEVICE_BINDINGS "UQS"
#else
#define CONFIG_LWM2M_DEVICE_BINDINGS "U"
#endif
/**
* @brief Initialize the Device object.
*
* @param[in] client_data LwM2M client data.
*
* @return Pointer to the Device object on success
*/
lwm2m_object_t *lwm2m_object_device_init(lwm2m_client_data_t *client_data);
/**
* @brief Determines if a reboot request has been issued to the device by a