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, basic_interrupt/app.c, ble_scanner/app.c, ble_tx/app.c, blink/app.c, custom_app/app.c, minimal_app/app.c, nfc/app.c, provisioning_joining_node/app.c, provisioning_proxy/app.c, ruuvi_evk/app.c, scheduler/app.c, and shared_data/app.c.

Definition at line 233 of file node_configuration.h.

234 {
235 #if defined(NETWORK_ADDRESS) & defined(NETWORK_CHANNEL)
237  NETWORK_ADDRESS,
238  NETWORK_CHANNEL,
239  authen_key_p,
240  cipher_key_p);
241 #else
243 #endif
244 }

◆ 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 == 0x0)
145  {
146  // Zero is not a valid address
147  address = 1;
148  }
149  else if ((address & 0xFF000000) == 0x80000000)
150  {
151  // Address would be in the multicast space
152  address &= 0x7ffffffd;
153  }
154 
155  // Workaround:
156  // there is a bug in Wirepas reference gateway fixed in version 1.3.
157  // It doesn't forward messages from nodes with an address with the
158  // MSB set to one.
159  // In order to avoid this situation, explicitly reset the highest bit when
160  // generating a unique address.
161  // If the target network only has gateways with version >= 1.3, or with
162  // different gateway implementation it is safe to remove this line
163  address &= 0x7fffffff;
164 
165  return address;
166 }

◆ 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 182 of file node_configuration.h.

188 {
189  app_res_e res;
190 
191  res = lib_settings->setNodeAddress(new_addr);
192  if (res != APP_RES_OK)
193  {
194  return res;
195  }
196  res = lib_settings->setNodeRole(new_role);
197  if (res != APP_RES_OK)
198  {
199  return res;
200  }
201  res = lib_settings->setNetworkAddress(new_network_addr);
202  if (res != APP_RES_OK)
203  {
204  return res;
205  }
206  res = lib_settings->setNetworkChannel(new_network_ch);
207  if (res != APP_RES_OK)
208  {
209  return res;
210  }
211 
212  return APP_RES_OK;
213 }

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
Network channel type definition.
Definition: wms_settings.h:60
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