nRF5 SDK for Mesh v2.1.1
device_state_manager.h
1 /* Copyright (c) 2010 - 2018, Nordic Semiconductor ASA
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form, except as embedded into a Nordic
11  * Semiconductor ASA integrated circuit in a product or a software update for
12  * such product, must reproduce the above copyright notice, this list of
13  * conditions and the following disclaimer in the documentation and/or other
14  * materials provided with the distribution.
15  *
16  * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
17  * contributors may be used to endorse or promote products derived from this
18  * software without specific prior written permission.
19  *
20  * 4. This software, with or without modification, must only be used with a
21  * Nordic Semiconductor ASA integrated circuit.
22  *
23  * 5. Any software provided in binary form under this license must not be reverse
24  * engineered, decompiled, modified and/or disassembled.
25  *
26  * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
27  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28  * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
29  * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
30  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
32  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
35  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef DEVICE_STATE_MANAGER_H__
39 #define DEVICE_STATE_MANAGER_H__
40 
41 #include <stdbool.h>
42 #include <stdint.h>
43 #include "nrf_mesh.h"
44 
45 #include "nrf_mesh_config_app.h"
46 #include "toolchain.h"
47 
60 #define DSM_ADDR_MAX (DSM_VIRTUAL_ADDR_MAX + DSM_NONVIRTUAL_ADDR_MAX)
61 
62 #define DSM_HANDLE_INVALID (0xFFFF)
63 
65 #define DSM_KEY_INDEX_MAX (NRF_MESH_GLOBAL_KEY_INDEX_MAX)
66 
76 typedef uint16_t mesh_key_index_t;
78 typedef uint16_t dsm_handle_t;
79 
83 typedef struct
84 {
85  uint16_t address_start;
86  uint16_t count;
88 
94 void dsm_init(void);
95 
103 bool dsm_flash_config_load(void);
104 
110 bool dsm_has_unflashed_data(void);
111 
117 const void * dsm_flash_area_get(void);
118 
122 void dsm_clear(void);
123 
143 uint32_t dsm_address_publish_add(uint16_t raw_address, dsm_handle_t * p_address_handle);
144 
153 uint32_t dsm_address_publish_add_handle(dsm_handle_t address_handle);
154 
166 uint32_t dsm_address_publish_virtual_add(const uint8_t * p_label_uuid, dsm_handle_t * p_address_handle);
167 
176 uint32_t dsm_address_publish_remove(dsm_handle_t address_handle);
177 
194 
201 
219 uint32_t dsm_address_subscription_add(uint16_t raw_address, dsm_handle_t * p_address_handle);
220 
232 uint32_t dsm_address_subscription_virtual_add(const uint8_t * p_label_uuid, dsm_handle_t * p_address_handle);
233 
242 uint32_t dsm_address_subscription_add_handle(dsm_handle_t address_handle);
243 
244 
255 _DEPRECATED bool dsm_address_subscription_get(dsm_handle_t address_handle);
256 
264 bool dsm_address_is_rx(const nrf_mesh_address_t * p_addr);
265 
276 uint32_t dsm_address_subscription_count_get(dsm_handle_t address_handle, uint16_t * p_count);
277 
291 uint32_t dsm_address_subscription_remove(dsm_handle_t address_handle);
292 
304 uint32_t dsm_address_get(dsm_handle_t address_handle, nrf_mesh_address_t * p_address);
305 
322 uint32_t dsm_address_get_all(dsm_handle_t * p_address_handle_list, uint32_t * p_count);
323 
334 uint32_t dsm_address_handle_get(const nrf_mesh_address_t * p_address, dsm_handle_t * p_address_handle);
335 
358 
367 
378 uint32_t dsm_subnet_handle_to_netkey_index(dsm_handle_t subnet_handle, mesh_key_index_t * p_netkey_index);
379 
394 uint32_t dsm_subnet_add(mesh_key_index_t net_key_id, const uint8_t * p_key, dsm_handle_t * p_subnet_handle);
395 
405 uint32_t dsm_subnet_kr_phase_get(dsm_handle_t subnet_handle, nrf_mesh_key_refresh_phase_t * p_phase);
406 
422 uint32_t dsm_subnet_update(dsm_handle_t subnet_handle, const uint8_t * p_key);
423 
437 uint32_t dsm_subnet_update_swap_keys(dsm_handle_t subnet_handle);
438 
453 uint32_t dsm_subnet_update_commit(dsm_handle_t subnet_handle);
454 
465 uint32_t dsm_subnet_delete(dsm_handle_t subnet_handle);
466 
479 uint32_t dsm_subnet_get_all(mesh_key_index_t * p_key_list, uint32_t * p_count);
480 
492 uint32_t dsm_subnet_key_get(dsm_handle_t subnet_handle, uint8_t * p_key);
521 uint32_t dsm_devkey_add(uint16_t raw_unicast_addr, dsm_handle_t subnet_handle, const uint8_t * p_key, dsm_handle_t * p_devkey_handle);
522 
533 uint32_t dsm_devkey_delete(dsm_handle_t dev_handle);
534 
546 uint32_t dsm_devkey_handle_get(uint16_t unicast_address, dsm_handle_t * p_devkey_handle);
547 
564 
573 
586 uint32_t dsm_appkey_handle_to_appkey_index(dsm_handle_t appkey_handle, mesh_key_index_t * p_index);
587 
600 uint32_t dsm_appkey_handle_to_subnet_handle(dsm_handle_t appkey_handle, dsm_handle_t * p_netkey_handle);
601 
623 uint32_t dsm_appkey_add(mesh_key_index_t app_key_id, dsm_handle_t subnet_handle, const uint8_t * p_key, dsm_handle_t * p_app_handle);
624 
643 uint32_t dsm_appkey_update(dsm_handle_t app_handle, const uint8_t * p_key);
644 
653 uint32_t dsm_appkey_delete(dsm_handle_t app_handle);
654 
670 uint32_t dsm_appkey_get_all(dsm_handle_t subnet_handle, mesh_key_index_t * p_key_list, uint32_t * p_count);
671 
691 uint32_t dsm_tx_secmat_get(dsm_handle_t subnet_handle, dsm_handle_t app_handle, nrf_mesh_secmat_t * p_secmat);
692 
703 uint32_t dsm_beacon_info_get(dsm_handle_t subnet_handle,
704  const nrf_mesh_beacon_info_t ** pp_beacon_info);
705 
718 uint32_t dsm_proxy_identity_get(dsm_handle_t subnet_handle, const uint8_t ** pp_identity);
719 
731  const nrf_mesh_network_secmat_t ** pp_net);
732 
735 #endif /* DEVICE_STATE_MANAGER_H__ */
736 
void dsm_clear(void)
Clear all stored state in the Device State Manager, including flash state.
_DEPRECATED bool dsm_address_subscription_get(dsm_handle_t address_handle)
Returns whether the given address_handle is in the global subscription list.
uint32_t dsm_address_subscription_virtual_add(const uint8_t *p_label_uuid, dsm_handle_t *p_address_handle)
Adds the specified virtual address to the global subscription list.
uint32_t dsm_subnet_kr_phase_get(dsm_handle_t subnet_handle, nrf_mesh_key_refresh_phase_t *p_phase)
Retrieves the current key refresh phase for a subnetwork.
bool dsm_has_unflashed_data(void)
Check whether there&#39;s data waiting to be flashed.
uint32_t dsm_subnet_update(dsm_handle_t subnet_handle, const uint8_t *p_key)
Updates an existing subnetwork key.
uint32_t dsm_devkey_handle_get(uint16_t unicast_address, dsm_handle_t *p_devkey_handle)
Obtains the handle for a device key.
uint32_t dsm_address_publish_add(uint16_t raw_address, dsm_handle_t *p_address_handle)
Adds an address to the DSM to be used as a publish address.
Network security material structure.
Definition: nrf_mesh.h:246
uint32_t dsm_address_subscription_count_get(dsm_handle_t address_handle, uint16_t *p_count)
Returns the number of subscriptions registered for an address in the global subscription list...
uint32_t dsm_address_get(dsm_handle_t address_handle, nrf_mesh_address_t *p_address)
Retrieves the address for a given address handle and fills out the given nrf_mesh_address_t structure...
const void * dsm_flash_area_get(void)
Get a pointer to the flash area used by the device state manager.
uint32_t dsm_appkey_update(dsm_handle_t app_handle, const uint8_t *p_key)
Updates an existing application key.
uint32_t dsm_subnet_key_get(dsm_handle_t subnet_handle, uint8_t *p_key)
Gets the (root) network key for a given subnet handle.
uint32_t dsm_address_publish_remove(dsm_handle_t address_handle)
Removes an address that has been used as a publish address.
Structure representing the unicast addresses assigned to this device.
Information structure for the Bluetooth Mesh network beacons.
Definition: nrf_mesh.h:292
uint32_t dsm_address_handle_get(const nrf_mesh_address_t *p_address, dsm_handle_t *p_address_handle)
Retrieves the address handle for a given nrf_mesh_address_t structure.
uint32_t dsm_address_publish_virtual_add(const uint8_t *p_label_uuid, dsm_handle_t *p_address_handle)
Adds a virtual address to the DSM to be used as a publish address.
uint16_t dsm_handle_t
DSM handle type, used for the handles returned for the each set of data added.
uint32_t dsm_address_get_all(dsm_handle_t *p_address_handle_list, uint32_t *p_count)
Get a list of all address handles in the address pool.
uint32_t dsm_appkey_get_all(dsm_handle_t subnet_handle, mesh_key_index_t *p_key_list, uint32_t *p_count)
Retrieves all the application key indices of the stored application keys of a specific subnetwork...
dsm_handle_t dsm_net_key_index_to_subnet_handle(mesh_key_index_t net_key_index)
Retrieves the subnetwork handle for a given network key index.
uint32_t dsm_beacon_info_get(dsm_handle_t subnet_handle, const nrf_mesh_beacon_info_t **pp_beacon_info)
Retrieves the necessary info for sending a mesh network beacon packet.
Application security material structure.
Definition: nrf_mesh.h:230
uint32_t dsm_subnet_update_swap_keys(dsm_handle_t subnet_handle)
Starts using the new subnetwork key.
uint32_t dsm_devkey_delete(dsm_handle_t dev_handle)
Removes an existing device key from the device state storage.
uint32_t dsm_local_unicast_addresses_set(const dsm_local_unicast_address_t *p_address)
Set the unicast addresses of the device.
uint16_t mesh_key_index_t
Key index type, used for network key index and application key index.
uint32_t dsm_appkey_handle_to_appkey_index(dsm_handle_t appkey_handle, mesh_key_index_t *p_index)
Retrieves the application key index for a specified application key handle.
dsm_handle_t dsm_appkey_index_to_appkey_handle(mesh_key_index_t appkey_index)
Retrieves the application key handle for a given application key index.
dsm_handle_t dsm_subnet_handle_get(const nrf_mesh_network_secmat_t *p_secmat)
Retrieves the subnetwork handle for a given network security material structure.
Bluetooth Mesh security material structure.
Definition: nrf_mesh.h:313
uint32_t dsm_subnet_delete(dsm_handle_t subnet_handle)
Removes an existing subnetwork from the device state storage.
uint32_t dsm_subnet_handle_to_netkey_index(dsm_handle_t subnet_handle, mesh_key_index_t *p_netkey_index)
Retrieves the key index for a subnetwork.
uint32_t dsm_net_secmat_from_keyindex_get(mesh_key_index_t net_key_index, const nrf_mesh_network_secmat_t **pp_net)
Retrives the network security material from the given netkey index.
nrf_mesh_key_refresh_phase_t
Key refresh phase.
Definition: nrf_mesh.h:210
uint32_t dsm_appkey_add(mesh_key_index_t app_key_id, dsm_handle_t subnet_handle, const uint8_t *p_key, dsm_handle_t *p_app_handle)
Adds an application key and its associated application key index to the device state storage...
uint32_t dsm_address_subscription_add_handle(dsm_handle_t address_handle)
Adds a subscription to an existing address handle.
uint32_t dsm_tx_secmat_get(dsm_handle_t subnet_handle, dsm_handle_t app_handle, nrf_mesh_secmat_t *p_secmat)
Retrieves the necessary security material for sending a mesh packet.
uint32_t dsm_address_subscription_remove(dsm_handle_t address_handle)
Removes the given address_handle from the global subscription list.
uint32_t dsm_address_publish_add_handle(dsm_handle_t address_handle)
Adds a publication to an existing address handle.
Bluetooth Mesh address.
Definition: nrf_mesh.h:355
uint32_t dsm_subnet_add(mesh_key_index_t net_key_id, const uint8_t *p_key, dsm_handle_t *p_subnet_handle)
Adds a subnetwork and its associated network key index to the device state storage.
bool dsm_flash_config_load(void)
Load DSM state from flash, to recover state.
uint16_t address_start
First address in the range of unicast addresses.
uint32_t dsm_devkey_add(uint16_t raw_unicast_addr, dsm_handle_t subnet_handle, const uint8_t *p_key, dsm_handle_t *p_devkey_handle)
Adds a device key.
uint32_t dsm_appkey_handle_to_subnet_handle(dsm_handle_t appkey_handle, dsm_handle_t *p_netkey_handle)
Stores the network key handle to the p_netkey_handle pointer for a specified application key handle...
uint16_t count
Number of addresses in the range of unicast addresses.
void dsm_local_unicast_addresses_get(dsm_local_unicast_address_t *p_address)
Get the local unicast address range of the device.
uint32_t dsm_subnet_get_all(mesh_key_index_t *p_key_list, uint32_t *p_count)
Retrieves all the network key indices of the stored subnetworks.
uint32_t dsm_appkey_delete(dsm_handle_t app_handle)
Removes an existing application key from the device state storage.
uint32_t dsm_address_subscription_add(uint16_t raw_address, dsm_handle_t *p_address_handle)
Adds the specified address to the global subscription list.
uint32_t dsm_subnet_update_commit(dsm_handle_t subnet_handle)
Commits to using the new subnetwork key.
uint32_t dsm_proxy_identity_get(dsm_handle_t subnet_handle, const uint8_t **pp_identity)
Retrieves the identity key for advertising with node identity, see section 7.2.2.2.3 in Bluetooth Mesh Profile Specification v1.0.
void dsm_init(void)
Initialize the device state manager.
bool dsm_address_is_rx(const nrf_mesh_address_t *p_addr)
Returns whether the device will process packets received on the given destination address...
dsm_handle_t dsm_appkey_handle_get(const nrf_mesh_application_secmat_t *p_secmat)
Retrieves the application key handle for a given application security material.

Documentation feedback | Developer Zone | Subscribe | Updated