Wirepas SDK
node_configuration.h File Reference

Go to the source code of this file.

Functions

__STATIC_INLINE app_res_e configureNode (app_addr_t my_addr, app_lib_settings_net_addr_t my_network_addr, app_lib_settings_net_channel_t my_network_ch, const uint8_t *my_authentication_key_p, const uint8_t *my_encryption_key_p)
 Helper function to initially setup a node if not already configured. This configuration can be modified later with remote API. More...
 
__STATIC_INLINE app_addr_t getUniqueAddress ()
 Helper function to generate a unique unicast address. More...
 
__STATIC_INLINE app_res_e OverrideNodeConfig (app_addr_t new_addr, app_lib_settings_role_t new_role, app_lib_settings_net_addr_t new_network_addr, app_lib_settings_net_channel_t new_network_ch)
 Helper function to apply new configuration on a node. Will override old configuration. More...
 
__STATIC_INLINE app_res_e configureNodeFromBuildParameters ()
 Wrapper on top of configureNode to get parameters from build system and hardcoded values from chip (for unique node address) The value must be defined in app confik.mk file at build time. More...
 

Variables

const uint8_t * authen_key_p
 
const uint8_t * cipher_key_p
 

Function Documentation

◆ configureNode()

__STATIC_INLINE app_res_e configureNode ( app_addr_t  my_addr,
app_lib_settings_net_addr_t  my_network_addr,
app_lib_settings_net_channel_t  my_network_ch,
const uint8_t *  my_authentication_key_p,
const uint8_t *  my_encryption_key_p 
)

Helper function to initially setup a node if not already configured. This configuration can be modified later with remote API.

Example on use. Address, network address and channel is set if they are not yet set:

#define NETWORK_ADDRESS 0x123456
#define NETWORK_CHANNEL 1
static const uint8_t authen_key[16] = {0x11,...,0xff}
static const uint8_t cipher_key[16] = {0x11,...,0xff}
void App_init(const app_global_functions_t * functions)
{
// Basic configuration of the node with a unique node address
NETWORK_ADDRESS,
NETWORK_CHANNEL,
authen_key,
cypher_key) != APP_RES_OK)
{
// Could not configure the node
// It should not happen except if one of the config value is invalid
return;
}
...
}
Parameters
my_addrNode Address to set if not present
my_network_addrNetwork address to set if not present
my_network_chNetwork channel to set if not present
my_authentication_key_pAuthentication key to set if not present. If NULL, it is not set.
my_encryption_key_pEncryption key to set if not present. If NULL, it is not set.
Returns
APP_RES_OK if the configuration is successful, an error code otherwise
Note
Only unset parameters are set
Keys are only set if node address was not set before calling this function to avoid setting a key in case the keys were removed intentionally from remote api

Definition at line 63 of file node_configuration.h.

69 {
70  // Check node address
71  app_addr_t node_addr;
72  app_res_e res;
73 
74  if (lib_settings->getNodeAddress(&node_addr) != APP_RES_OK)
75  {
76  // Not set
77  res = lib_settings->setNodeAddress(my_addr);
78  if (res != APP_RES_OK)
79  {
80  return res;
81  }
82 
83  // Node address was not set => first time we call this function
84  if (my_authentication_key_p != NULL
85  && lib_settings->getAuthenticationKey(NULL) != APP_RES_OK)
86  {
87  // Not set
88  res = lib_settings->setAuthenticationKey(my_authentication_key_p);
89  if (res != APP_RES_OK)
90  {
91  return res;
92  }
93  }
94 
95  // Node address was not set so first time we call this function
96  if (my_encryption_key_p != NULL
97  && lib_settings->getEncryptionKey(NULL) != APP_RES_OK)
98  {
99  // Not set
100  res = lib_settings->setEncryptionKey(my_encryption_key_p);
101  if (res != APP_RES_OK)
102  {
103  return res;
104  }
105  }
106  }
107 
108  // Check network address
109  app_lib_settings_net_addr_t network_addr;
110  if (lib_settings->getNetworkAddress(&network_addr) != APP_RES_OK)
111  {
112  // Not set
113  res = lib_settings->setNetworkAddress(my_network_addr);
114  if (res != APP_RES_OK)
115  {
116  return res;
117  }
118  }
119 
120  // Check network channel
122  if (lib_settings->getNetworkChannel(&network_ch) != APP_RES_OK)
123  {
124  // Not set
125  res = lib_settings->setNetworkChannel(my_network_ch);
126  if (res != APP_RES_OK)
127  {
128  return res;
129  }
130  }
131 
132  return APP_RES_OK;
133 }

◆ configureNodeFromBuildParameters()

__STATIC_INLINE app_res_e configureNodeFromBuildParameters ( )

Wrapper on top of configureNode to get parameters from build system and hardcoded values from chip (for unique node address) The value must be defined in app confik.mk file at build time.

Returns
APP_RES_OK if the configuration is successful, an error code otherwise
Note
Calling this function without setting a network address and channel in your config.mk will result in an error at execution time
Examples
appconfig/app.c, custom_app/app.c, minimal_app/app.c, scheduler/app.c, and shared_data/app.c.

Definition at line 224 of file node_configuration.h.

225 {
226 #if defined(NETWORK_ADDRESS) & defined(NETWORK_CHANNEL)
228  NETWORK_ADDRESS,
229  NETWORK_CHANNEL,
230  authen_key_p,
231  cipher_key_p);
232 #else
234 #endif
235 }

◆ getUniqueAddress()

__STATIC_INLINE app_addr_t getUniqueAddress ( )

Helper function to generate a unique unicast address.

Returns
A unique unicast address generated from chip unique id

Definition at line 139 of file node_configuration.h.

140 {
141  app_addr_t address = getUniqueId();
142 
143  // Check the address is in correct range
144  if ((address & 0xFF000000) == 0x80000000)
145  {
146  // Address would be in the multicast space
147  address &= 0x7fffffff;
148  }
149 
150  if (address == 0x0)
151  {
152  // Zero is not a valid address
153  address = 1;
154  }
155 
156  return address;
157 }

◆ OverrideNodeConfig()

__STATIC_INLINE app_res_e OverrideNodeConfig ( app_addr_t  new_addr,
app_lib_settings_role_t  new_role,
app_lib_settings_net_addr_t  new_network_addr,
app_lib_settings_net_channel_t  new_network_ch 
)

Helper function to apply new configuration on a node. Will override old configuration.

Parameters
new_addrNode Address to set
new_roleNode Role to set
new_network_addrNetwork address to set
new_network_chNetwork channel to set
Returns
APP_RES_OK if the configuration is successful, an error code otherwise

Definition at line 173 of file node_configuration.h.

179 {
180  app_res_e res;
181 
182  res = lib_settings->setNodeAddress(new_addr);
183  if (res != APP_RES_OK)
184  {
185  return res;
186  }
187  res = lib_settings->setNodeRole(new_role);
188  if (res != APP_RES_OK)
189  {
190  return res;
191  }
192  res = lib_settings->setNetworkAddress(new_network_addr);
193  if (res != APP_RES_OK)
194  {
195  return res;
196  }
197  res = lib_settings->setNetworkChannel(new_network_ch);
198  if (res != APP_RES_OK)
199  {
200  return res;
201  }
202 
203  return APP_RES_OK;
204 }

Variable Documentation

◆ authen_key_p

const uint8_t* authen_key_p

◆ cipher_key_p

const uint8_t* cipher_key_p
app_lib_settings_net_channel_t
uint8_t app_lib_settings_net_channel_t
Channel type definition.
Definition: wms_settings.h:58
configureNode
__STATIC_INLINE app_res_e configureNode(app_addr_t my_addr, app_lib_settings_net_addr_t my_network_addr, app_lib_settings_net_channel_t my_network_ch, const uint8_t *my_authentication_key_p, const uint8_t *my_encryption_key_p)
Helper function to initially setup a node if not already configured. This configuration can be modifi...
Definition: node_configuration.h:63
app_res_e
app_res_e
Definition: wms_app.h:201
APP_RES_NOT_IMPLEMENTED
@ APP_RES_NOT_IMPLEMENTED
Definition: wms_app.h:208
app_lib_settings_net_addr_t
uint32_t app_lib_settings_net_addr_t
Network address type definition.
Definition: wms_settings.h:53
APP_RES_OK
@ APP_RES_OK
Definition: wms_app.h:204
app_global_functions_t
List of global functions, passed to App_entrypoint()
Definition: wms_app.h:157
getUniqueAddress
__STATIC_INLINE app_addr_t getUniqueAddress()
Helper function to generate a unique unicast address.
Definition: node_configuration.h:139
app_addr_t
uint32_t app_addr_t
Definition: wms_app.h:228
authen_key_p
const uint8_t * authen_key_p
cipher_key_p
const uint8_t * cipher_key_p