Wirepas SDK
provisioning_proxy/app.c
/* Copyright 2019 Wirepas Ltd. All Rights Reserved.
*
* See file LICENSE.txt for full license details.
*
*/
/*
* \file app.c
* \brief This file is an application example to use the provisioning proxy
* library.
*/
#include "api.h"
#include "button.h"
#include "provisioning.h"
#include "shared_data.h"
#define DEBUG_LOG_MODULE_NAME "PROXY APP"
#define DEBUG_LOG_MAX_LEVEL LVL_INFO
#include "debug_log.h"
#define JOINING_TX_POWER 8
//#define LOW_LATENCY_NODE 1
#define ENABLE_LOCAL_PROVISIONING true
static const uint8_t authentication_key[] = {NET_AUTHEN_KEY};
static const uint8_t encryption_key[] = {NET_CIPHER_KEY};
static bool beacon_tx_enabled = false;
static void button_0_cb(uint8_t button_id, button_event_e event)
{
(void)button_id;
(void)event;
/* Turn joining beacon transmission on or off. */
if (beacon_tx_enabled)
{
beacon_tx_enabled = false;
}
else
{
beacon_tx_enabled = true;
}
}
bool start_cb(const uint8_t * p_uid,
uint8_t uid_len,
{
(void) p_uid;
(void) uid_len;
provisioning_uid_t * prov_uid = (provisioning_uid_t *)p_uid;
/* Log provisioning request details */
LOG(LVL_INFO, "Provisioning request - Method: %d", method);
{
if (prov_uid!= NULL && uid_len > 0)
{
LOG(LVL_INFO, "Extended UID provisioning:");
LOG(LVL_INFO, " Authenticator UID Type: %d", prov_uid->authenticator_uid_type);
LOG_BUFFER(LVL_INFO, prov_uid->authenticator_uid, PROV_AUTH_UID_SIZE_BYTES);
LOG(LVL_INFO, " Node UID Type: %d", prov_uid->node_uid_type);
LOG_BUFFER(LVL_INFO, prov_uid->node_uid, PROV_UUID_SIZE_BYTES);
LOG_BUFFER(LVL_INFO, p_uid, uid_len);
}
}
else if (p_uid != NULL && uid_len > 0)
{
LOG(LVL_INFO, "Standard provisioning - UID:");
if (prov_uid != NULL && uid_len > 0)
{
LOG_BUFFER(LVL_INFO, prov_uid->uid, uid_len);
}
}
/* The proxy will send the same network parameters to the new node than
* the ones it is using.
*/
p_param->net_addr = NETWORK_ADDRESS;
p_param->net_chan = NETWORK_CHANNEL;
memcpy(p_param->auth_key,
authentication_key,
memcpy(p_param->enc_key, encryption_key, APP_LIB_SETTINGS_AES_KEY_NUM_BYTES);
LOG(LVL_INFO, "Accepting node - sending network config");
return true;
}
void App_init(const app_global_functions_t * functions)
{
(void) functions;
/* Example of factory key used for secured method if local provisioning is
enabled.
In production applications, store the key in secure storage instead of
hardcoding here. See wms_secure_storage.h. Hardcoding results in the
data being stored as plaintext on the flash.
*/
static const uint8_t factory_key[] = {
0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9,
0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9,
0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9,
0xd1, 0xd2, 0xd3, 0xd4, 0xd5
};
static const uint32_t id = 0x12345678;
{
.tx_power = JOINING_TX_POWER,
.payload = (uint8_t *)&id,
.num_bytes = sizeof(id),
.is_local_sec_allowed = ENABLE_LOCAL_PROVISIONING,
.is_local_unsec_allowed = ENABLE_LOCAL_PROVISIONING,
.key = factory_key,
.key_len = 32,
.start_cb = start_cb
};
LOG(LVL_INFO, "Starting");
/* Basic configuration of the node with a unique node address. */
{
/* Could not configure the node. It should not happen except if one
* of the config value is invalid.
*/
return;
}
/* Proxy must be configured as Headnode. */
/* Configure new node. */
#ifdef LOW_LATENCY_NODE
lib_settings->setNodeRole(APP_LIB_SETTINGS_ROLE_HEADNODE_LL);
#else
lib_settings->setNodeRole(APP_LIB_SETTINGS_ROLE_HEADNODE_LE);
#endif
/* Start the stack. */
lib_state->startStack();
}
PROV_UUID_SIZE_BYTES
#define PROV_UUID_SIZE_BYTES
Definition: provisioning.h:19
provisioning_proxy_conf_t
This structure holds the joining proxy parameters.
Definition: provisioning.h:266
LVL_INFO
#define LVL_INFO
Definition: debug_log.h:83
APP_LIB_SETTINGS_ROLE_HEADNODE_LE
@ APP_LIB_SETTINGS_ROLE_HEADNODE_LE
Definition: wms_settings.h:80
LOG_BUFFER
#define LOG_BUFFER(level, buffer, size)
Print a buffer if its severity is lower or equal to DEBUG_LOG_MAX_LEVEL.
Definition: debug_log.h:206
Provisioning_Proxy_init
provisioning_ret_e Provisioning_Proxy_init(provisioning_proxy_conf_t *conf)
Initialize the provisioning proxy.
Provisioning_Proxy_start
provisioning_ret_e Provisioning_Proxy_start(void)
Start sending joining beacons. Provisioning packets will be forwarded to provisioning server or treat...
button.h
Board-independent button functions.
PROV_AUTH_UID_SIZE_BYTES
#define PROV_AUTH_UID_SIZE_BYTES
Authenticator UID size.
Definition: provisioning.h:34
provisioning_uid_t
Definition: provisioning.h:191
node_configuration.h
provisioning_proxy_net_param_t::enc_key
uint8_t enc_key[APP_LIB_SETTINGS_AES_KEY_NUM_BYTES]
Definition: provisioning.h:158
provisioning_proxy_net_param_t::auth_key
uint8_t auth_key[APP_LIB_SETTINGS_AES_KEY_NUM_BYTES]
Definition: provisioning.h:160
provisioning_proxy_net_param_t::net_chan
app_lib_settings_net_channel_t net_chan
Definition: provisioning.h:164
APP_RES_OK
@ APP_RES_OK
Definition: wms_app.h:204
provisioning_method_e
provisioning_method_e
Provisioning methods.
Definition: provisioning.h:68
Provisioning_Proxy_stop
provisioning_ret_e Provisioning_Proxy_stop(void)
Stops the provisioning proxy.
app_global_functions_t
List of global functions, passed to App_entrypoint()
Definition: wms_app.h:157
PROV_METHOD_IS_EXTENDED_UID
#define PROV_METHOD_IS_EXTENDED_UID(x)
Macro to check whether secure method uses extended UID.
Definition: provisioning.h:104
debug_log.h
Button_register_for_event
button_res_e Button_register_for_event(uint8_t button_id, button_event_e event, on_button_event_cb cb)
Register for a button event.
APP_LIB_SETTINGS_AES_KEY_NUM_BYTES
#define APP_LIB_SETTINGS_AES_KEY_NUM_BYTES
AES key size in bytes.
Definition: wms_settings.h:44
configureNodeFromBuildParameters
__STATIC_INLINE app_res_e configureNodeFromBuildParameters()
Wrapper on top of configureNode to get parameters from build system and hardcoded values from chip (f...
Definition: node_configuration.h:224
provisioning_uid_t::uid
uint8_t uid[79]
Definition: provisioning.h:193
provisioning_proxy_conf_t::tx_power
int8_t tx_power
Definition: provisioning.h:273
LOG_INIT
#define LOG_INIT()
Definition: debug_log.h:66
shared_data.h
LOG
#define LOG(level, fmt,...)
Print a log message if its severity is lower or equal to DEBUG_LOG_MAX_LEVEL.
Definition: debug_log.h:173
BUTTON_PRESSED
@ BUTTON_PRESSED
Definition: button.h:22
provisioning_proxy_net_param_t
This structure contains the network parameters sent by the provisioning proxy to the new node.
Definition: provisioning.h:155
APP_LIB_SETTINGS_ROLE_HEADNODE_LL
@ APP_LIB_SETTINGS_ROLE_HEADNODE_LL
Definition: wms_settings.h:82
provisioning.h
provisioning_proxy_net_param_t::net_addr
app_lib_settings_net_addr_t net_addr
Definition: provisioning.h:162
api.h
button_event_e
button_event_e
Different events for a button.
Definition: button.h:21