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 false
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 * uid,
uint8_t uid_len,
{
/* The proxy will send the same network parameters to the new node than
* the ones it is using.
*/
param->net_addr = NETWORK_ADDRESS;
param->net_chan = NETWORK_CHANNEL;
memcpy(param->auth_key,
authentication_key,
memcpy(param->enc_key, encryption_key, APP_LIB_SETTINGS_AES_KEY_NUM_BYTES);
return true;
}
void App_init(const app_global_functions_t * functions)
{
/* Factory key used for secured method if local provisioning is enabled. */
static const uint8_t factory_key[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0X09, 0X0A, 0X0B, 0X0C, 0X0D, 0X0E, 0X0F,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0X09, 0X0A, 0X0B, 0X0C, 0X0D, 0X0E, 0X0F
};
{
.tx_power = JOINING_TX_POWER,
.payload = NULL,
.num_bytes = 0,
.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();
}
provisioning_proxy_conf_t
This structure holds the joining proxy parameters.
Definition: provisioning.h:167
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:68
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.
node_configuration.h
provisioning_proxy_net_param_t::enc_key
uint8_t enc_key[APP_LIB_SETTINGS_AES_KEY_NUM_BYTES]
Definition: provisioning.h:97
provisioning_proxy_net_param_t::auth_key
uint8_t auth_key[APP_LIB_SETTINGS_AES_KEY_NUM_BYTES]
Definition: provisioning.h:99
provisioning_proxy_net_param_t::net_chan
app_lib_settings_net_channel_t net_chan
Definition: provisioning.h:103
APP_RES_OK
@ APP_RES_OK
Definition: wms_app.h:204
provisioning_method_e
provisioning_method_e
supported provisioning methods
Definition: provisioning.h:43
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
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:233
provisioning_proxy_conf_t::tx_power
int8_t tx_power
Definition: provisioning.h:174
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:172
Button_init
void Button_init(void)
Initialize Button module.
BUTTON_PRESSED
@ BUTTON_PRESSED
Definition: button.h:18
provisioning_proxy_net_param_t
This structure contains the network parameters sent by the provisioning proxy to the new node.
Definition: provisioning.h:94
APP_LIB_SETTINGS_ROLE_HEADNODE_LL
@ APP_LIB_SETTINGS_ROLE_HEADNODE_LL
Definition: wms_settings.h:70
provisioning.h
provisioning_proxy_net_param_t::net_addr
app_lib_settings_net_addr_t net_addr
Definition: provisioning.h:101
api.h
button_event_e
button_event_e
Different events for a button.
Definition: button.h:17