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 & 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 }
158 
174  app_lib_settings_role_t new_role,
176  new_network_addr,
178  new_network_ch)
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 }
205 
206 /*
207  * Network keys define in mcu/common/start.c and
208  * used only if default_network_cipher_key and default_network_authen_key
209  * are defined in one of the config.mk (set to NULL otherwise)
210  */
211 extern const uint8_t * authen_key_p;
212 extern const uint8_t * cipher_key_p;
213 
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 }
236 
237 #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:224
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:173
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