1 /* 2 * SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef _PROVISIONER_MAIN_H_ 8 #define _PROVISIONER_MAIN_H_ 9 10 #include "net.h" 11 #include "mesh_bearer_adapt.h" 12 13 #ifdef __cplusplus 14 extern "C" { 15 #endif 16 17 #define BLE_MESH_INVALID_NODE_INDEX 0xFFFF 18 #define BLE_MESH_NODE_NAME_SIZE 31 19 20 /* Each node information stored by provisioner */ 21 struct bt_mesh_node { 22 /* Device information */ 23 uint8_t addr[6]; /* Node device address */ 24 uint8_t addr_type; /* Node device address type */ 25 uint8_t dev_uuid[16]; /* Node Device UUID */ 26 uint16_t oob_info; /* Node OOB information */ 27 28 /* Provisioning information */ 29 uint16_t unicast_addr; /* Node unicast address */ 30 uint8_t element_num; /* Node element number */ 31 uint16_t net_idx; /* Node NetKey Index */ 32 uint8_t flags; /* Node key refresh flag and iv update flag */ 33 uint32_t iv_index; /* Node IV Index */ 34 uint8_t dev_key[16]; /* Node device key */ 35 36 /* Additional information */ 37 char name[BLE_MESH_NODE_NAME_SIZE + 1]; /* Node name */ 38 uint16_t comp_length; /* Length of Composition Data */ 39 uint8_t *comp_data; /* Value of Composition Data */ 40 } __packed; 41 42 int bt_mesh_provisioner_init(void); 43 44 int bt_mesh_provisioner_net_create(void); 45 46 void bt_mesh_provisioner_main_reset(bool erase); 47 48 int bt_mesh_provisioner_deinit(bool erase); 49 50 bool bt_mesh_provisioner_check_is_addr_dup(uint16_t addr, uint8_t elem_num, bool comp_with_own); 51 52 uint16_t bt_mesh_provisioner_get_node_count(void); 53 54 int bt_mesh_provisioner_restore_node_info(struct bt_mesh_node *node); 55 56 int bt_mesh_provisioner_provision(const bt_mesh_addr_t *addr, const uint8_t uuid[16], 57 uint16_t oob_info, uint16_t unicast_addr, 58 uint8_t element_num, uint16_t net_idx, 59 uint8_t flags, uint32_t iv_index, 60 const uint8_t dev_key[16], uint16_t *index); 61 62 int bt_mesh_provisioner_remove_node(const uint8_t uuid[16]); 63 64 int bt_mesh_provisioner_restore_node_name(uint16_t addr, const char *name); 65 66 int bt_mesh_provisioner_restore_node_comp_data(uint16_t addr, const uint8_t *data, uint16_t length); 67 68 struct bt_mesh_node *bt_mesh_provisioner_get_node_with_uuid(const uint8_t uuid[16]); 69 70 struct bt_mesh_node *bt_mesh_provisioner_get_node_with_addr(uint16_t unicast_addr); 71 72 int bt_mesh_provisioner_delete_node_with_uuid(const uint8_t uuid[16]); 73 74 int bt_mesh_provisioner_delete_node_with_node_addr(uint16_t unicast_addr); 75 76 int bt_mesh_provisioner_delete_node_with_dev_addr(const bt_mesh_addr_t *addr); 77 78 int bt_mesh_provisioner_set_node_name(uint16_t index, const char *name); 79 80 const char *bt_mesh_provisioner_get_node_name(uint16_t index); 81 82 uint16_t bt_mesh_provisioner_get_node_index(const char *name); 83 84 struct bt_mesh_node *bt_mesh_provisioner_get_node_with_name(const char *name); 85 86 const struct bt_mesh_node **bt_mesh_provisioner_get_node_table_entry(void); 87 88 int bt_mesh_provisioner_store_node_comp_data(uint16_t addr, const uint8_t *data, uint16_t length); 89 90 const uint8_t *bt_mesh_provisioner_net_key_get(uint16_t net_idx); 91 92 struct bt_mesh_subnet *bt_mesh_provisioner_subnet_get(uint16_t net_idx); 93 94 bool bt_mesh_provisioner_check_msg_dst(uint16_t dst); 95 96 const uint8_t *bt_mesh_provisioner_dev_key_get(uint16_t dst); 97 98 struct bt_mesh_app_key *bt_mesh_provisioner_app_key_find(uint16_t app_idx); 99 100 int bt_mesh_provisioner_local_app_key_add(const uint8_t app_key[16], 101 uint16_t net_idx, uint16_t *app_idx); 102 103 int bt_mesh_provisioner_local_app_key_update(const uint8_t app_key[16], 104 uint16_t net_idx, uint16_t app_idx); 105 106 const uint8_t *bt_mesh_provisioner_local_app_key_get(uint16_t net_idx, uint16_t app_idx); 107 108 int bt_mesh_provisioner_local_app_key_del(uint16_t net_idx, uint16_t app_idx, bool store); 109 110 int bt_mesh_provisioner_local_net_key_add(const uint8_t net_key[16], uint16_t *net_idx); 111 112 int bt_mesh_provisioner_local_net_key_update(const uint8_t net_key[16], uint16_t net_idx); 113 114 const uint8_t *bt_mesh_provisioner_local_net_key_get(uint16_t net_idx); 115 116 int bt_mesh_provisioner_local_net_key_del(uint16_t net_idx, bool store); 117 118 /* Provisioner bind local client model with proper appkey index */ 119 int bt_mesh_provisioner_bind_local_model_app_idx(uint16_t elem_addr, uint16_t mod_id, 120 uint16_t cid, uint16_t app_idx); 121 122 typedef void (* bt_mesh_heartbeat_recv_cb_t)(uint16_t hb_src, uint16_t hb_dst, 123 uint8_t init_ttl, uint8_t rx_ttl, 124 uint8_t hops, uint16_t feat, int8_t rssi); 125 126 int bt_mesh_provisioner_recv_heartbeat(bt_mesh_heartbeat_recv_cb_t cb); 127 128 int bt_mesh_provisioner_set_heartbeat_filter_type(uint8_t filter_type); 129 130 int bt_mesh_provisioner_set_heartbeat_filter_info(uint8_t op, uint16_t src, uint16_t dst); 131 132 void bt_mesh_provisioner_heartbeat(uint16_t hb_src, uint16_t hb_dst, 133 uint8_t init_ttl, uint8_t rx_ttl, 134 uint8_t hops, uint16_t feat, int8_t rssi); 135 136 /* Provisioner print own element information */ 137 int bt_mesh_print_local_composition_data(void); 138 139 int bt_mesh_provisioner_store_node_info(struct bt_mesh_node *node); 140 141 #ifdef __cplusplus 142 } 143 #endif 144 145 #endif /* _PROVISIONER_MAIN_H_ */ 146