nRF5 SDK for Mesh v5.0.0
device_state_manager.h
1 /* Copyright (c) 2010 - 2020, 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 
68 #define DSM_APP_MAX_LIMIT (247)
69 
70 #define DSM_SUBNET_MAX_LIMIT (252)
71 
72 #define DSM_ADDR_MAX_LIMIT (185)
73 
83 typedef uint16_t mesh_key_index_t;
85 typedef uint16_t dsm_handle_t;
86 
90 typedef struct
91 {
92  uint16_t address_start;
93  uint16_t count;
95 
101 void dsm_init(void);
102 
113 uint32_t dsm_load_config_apply(void);
114 
118 void dsm_clear(void);
119 
139 uint32_t dsm_address_publish_add(uint16_t raw_address, dsm_handle_t * p_address_handle);
140 
149 uint32_t dsm_address_publish_add_handle(dsm_handle_t address_handle);
150 
162 uint32_t dsm_address_publish_virtual_add(const uint8_t * p_label_uuid, dsm_handle_t * p_address_handle);
163 
172 uint32_t dsm_address_publish_remove(dsm_handle_t address_handle);
173 
190 
197 
215 uint32_t dsm_address_subscription_add(uint16_t raw_address, dsm_handle_t * p_address_handle);
216 
228 uint32_t dsm_address_subscription_virtual_add(const uint8_t * p_label_uuid, dsm_handle_t * p_address_handle);
229 
238 uint32_t dsm_address_subscription_add_handle(dsm_handle_t address_handle);
239 
240 
251 _DEPRECATED bool dsm_address_subscription_get(dsm_handle_t address_handle);
252 
263 _DEPRECATED bool dsm_address_is_rx(const nrf_mesh_address_t * p_addr);
264 
275 uint32_t dsm_address_subscription_count_get(dsm_handle_t address_handle, uint16_t * p_count);
276 
290 uint32_t dsm_address_subscription_remove(dsm_handle_t address_handle);
291 
303 uint32_t dsm_address_get(dsm_handle_t address_handle, nrf_mesh_address_t * p_address);
304 
321 uint32_t dsm_address_get_all(dsm_handle_t * p_address_handle_list, uint32_t * p_count);
322 
333 uint32_t dsm_address_handle_get(const nrf_mesh_address_t * p_address, dsm_handle_t * p_address_handle);
334 
357 
366 
377 uint32_t dsm_subnet_handle_to_netkey_index(dsm_handle_t subnet_handle, mesh_key_index_t * p_netkey_index);
378 
393 uint32_t dsm_subnet_add(mesh_key_index_t net_key_id, const uint8_t * p_key, dsm_handle_t * p_subnet_handle);
394 
404 uint32_t dsm_subnet_kr_phase_get(dsm_handle_t subnet_handle, nrf_mesh_key_refresh_phase_t * p_phase);
405 
421 uint32_t dsm_subnet_update(dsm_handle_t subnet_handle, const uint8_t * p_key);
422 
436 uint32_t dsm_subnet_update_swap_keys(dsm_handle_t subnet_handle);
437 
452 uint32_t dsm_subnet_update_commit(dsm_handle_t subnet_handle);
453 
464 uint32_t dsm_subnet_delete(dsm_handle_t subnet_handle);
465 
478 uint32_t dsm_subnet_get_all(mesh_key_index_t * p_key_list, uint32_t * p_count);
479 
491 uint32_t dsm_subnet_key_get(dsm_handle_t subnet_handle, uint8_t * p_key);
492 
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 
692 uint32_t dsm_tx_secmat_get(dsm_handle_t subnet_handle, dsm_handle_t app_handle, nrf_mesh_secmat_t * p_secmat);
693 
694 #if (MESH_FEATURE_LPN_ENABLED || MESH_FEATURE_FRIEND_ENABLED)
695 
712 uint32_t dsm_tx_friendship_secmat_get(dsm_handle_t subnet_handle, dsm_handle_t app_handle, nrf_mesh_secmat_t * p_secmat);
713 #endif
714 
725 uint32_t dsm_beacon_info_get(dsm_handle_t subnet_handle,
726  const nrf_mesh_beacon_info_t ** pp_beacon_info);
727 
739 uint32_t dsm_proxy_identity_get(dsm_handle_t subnet_handle, const uint8_t ** pp_identity);
740 
752  const nrf_mesh_network_secmat_t ** pp_net);
753 
756 #endif /* DEVICE_STATE_MANAGER_H__ */
757 
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.
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.
_DEPRECATED 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...
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:261
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...
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:311
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:245
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:332
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 master network security material from the given netkey index.
nrf_mesh_key_refresh_phase_t
Key refresh phase.
Definition: nrf_mesh.h:225
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 application and master network 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:374
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.
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 Bluetooth Mesh Profile Specificati...
uint32_t dsm_load_config_apply(void)
Apply data loaded from the mesh configuration system into Device State Manager structures.
void dsm_init(void)
Initialize the device state manager.
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