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