Wirepas SDK
node_configuration.h
Go to the documentation of this file.
1 /* Copyright 2017 Wirepas Ltd. All Rights Reserved.
2  *
3  * See file LICENSE.txt for full license details.
4  *
5  */
6 
7 #ifndef NODECONFIGURATION_H_
8 #define NODECONFIGURATION_H_
9 
10 #include "api.h"
11 #include "uniqueId.h"
12 
64  app_addr_t my_addr,
65  app_lib_settings_net_addr_t my_network_addr,
66  app_lib_settings_net_channel_t my_network_ch,
67  const uint8_t * my_authentication_key_p,
68  const uint8_t * my_encryption_key_p)
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 }
134 
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 &= 0x7fffffff;
153  }
154 
155  return address;
156 }
157 
173  app_lib_settings_role_t new_role,
175  new_network_addr,
177  new_network_ch)
178 {
179  app_res_e res;
180 
181  res = lib_settings->setNodeAddress(new_addr);
182  if (res != APP_RES_OK)
183  {
184  return res;
185  }
186  res = lib_settings->setNodeRole(new_role);
187  if (res != APP_RES_OK)
188  {
189  return res;
190  }
191  res = lib_settings->setNetworkAddress(new_network_addr);
192  if (res != APP_RES_OK)
193  {
194  return res;
195  }
196  res = lib_settings->setNetworkChannel(new_network_ch);
197  if (res != APP_RES_OK)
198  {
199  return res;
200  }
201 
202  return APP_RES_OK;
203 }
204 
205 /*
206  * Network keys define in mcu/common/start.c and
207  * used only if default_network_cipher_key and default_network_authen_key
208  * are defined in one of the config.mk (set to NULL otherwise)
209  */
210 extern const uint8_t * authen_key_p;
211 extern const uint8_t * cipher_key_p;
212 
224 {
225 #if defined(NETWORK_ADDRESS) & defined(NETWORK_CHANNEL)
227  NETWORK_ADDRESS,
228  NETWORK_CHANNEL,
229  authen_key_p,
230  cipher_key_p);
231 #else
233 #endif
234 }
235 
236 #endif /* NODECONFIGURATION_H_ */
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
__STATIC_INLINE
#define __STATIC_INLINE
Definition: wms_app.h:20
APP_RES_OK
@ APP_RES_OK
Definition: wms_app.h:204
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:223
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.
Definition: node_configuration.h:172
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
app_lib_settings_role_t
uint8_t app_lib_settings_role_t
Node role type.
Definition: wms_settings.h:92
cipher_key_p
const uint8_t * cipher_key_p
api.h