return result;
}
+BT_EXPORT_API int bluetooth_mesh_node_reset(bluetooth_mesh_node_info_t *node)
+{
+ int result;
+
+ BT_CHECK_PARAMETER(node, return);
+
+ BT_INIT_PARAMS();
+ BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+ g_array_append_vals(in_param1, node, sizeof(bluetooth_mesh_node_info_t));
+
+ BT_INFO("Mesh: Reset the Node");
+ result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NODE_RESET,
+ in_param1, in_param2, in_param3, in_param4, &out_param);
+ BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+ return result;
+}
+
BT_EXPORT_API int bluetooth_mesh_network_create(
const char *net_name, bluetooth_mesh_node_t *node,
uint16_t total_models, bluetooth_mesh_model_t **models,
requester_unique_creds, sender, &node, out_param1);
break;
}
+ case BT_MESH_NODE_RESET: {
+ bluetooth_mesh_node_info_t node;
+ memset(&node, 0x00, sizeof(bluetooth_mesh_node_info_t));
+
+ __bt_service_get_parameters(in_param1,
+ &node, sizeof(bluetooth_mesh_node_info_t));
+
+ BT_INFO("Mesh: Reset the Node");
+ result = _bt_mesh_network_reset_node(requester_unique_creds,
+ sender, &node);
+
+ break;
+ }
case BT_MESH_MODEL_GET_APPKEY_LIST: {
bluetooth_mesh_model_configure_t req;
case BT_MESH_NODE_TTL_EXECUTE:
case BT_MESH_NODE_GET_NETKEYS:
case BT_MESH_NODE_GET_APPKEYS:
+ case BT_MESH_NODE_RESET:
case BT_MESH_MODEL_CONFIGURE_APPKEY:
case BT_MESH_MODEL_GET_APPKEY_LIST:
case BT_MESH_MODEL_EXECUTE_MSG:
const char *sender,
bluetooth_mesh_node_discover_t *req);
+int _bt_mesh_network_reset_node(const char *app_cred, const char *sender,
+ bluetooth_mesh_node_info_t *node);
+
bool _bt_mesh_check_pending_request(uint32_t opcode,
uint16_t dest, uint8_t net_uuid[]);
int _bt_mesh_network_remove_net_configuration(bluetooth_mesh_network_t *net);
+int _bt_mesh_network_remove_node_configuration(bluetooth_mesh_node_info_t *node);
+
int _bt_mesh_network_create_cdb(int result,
const char *sender, const char *app_creds,
uint8_t uuid[16], uint8_t token[8],
return BLUETOOTH_ERROR_NONE;
}
+int _bt_mesh_network_reset_node(const char *app_cred, const char *sender,
+ bluetooth_mesh_node_info_t *node)
+{
+ int ret = OAL_STATUS_SUCCESS;
+ uint16_t netkey_idx;
+ oal_uuid_t net_uuid;
+ uint16_t data_len;
+ uint8_t buffer[MESH_CONFIG_BUFFER_MAX_LEN];
+
+ /* If Scanning is going on */
+ if (_bt_mesh_is_provisioning() ||
+ _bt_mesh_is_scanning()) {
+ BT_ERR("Device is buzy..");
+ return BLUETOOTH_ERROR_DEVICE_BUSY;
+ }
+
+ _bt_mesh_util_convert_string_to_hex(node->net_uuid,
+ strlen(node->net_uuid), net_uuid.uuid, 16);
+
+ /* Check pending request */
+ if (_bt_mesh_check_pending_request(MESH_OPCODE_NODE_RESET,
+ node->primary_unicast, net_uuid.uuid)) {
+ BT_ERR("Device is buzy..");
+ return BLUETOOTH_ERROR_DEVICE_BUSY;
+ }
+ BT_INFO("Mesh: Reset a remote Node [0x%2.2x] Elem Cnt [0x%2.2x]",
+ node->primary_unicast, node->num_elements);
+ /* Get Subnet index of the remote node for TX encryption */
+ netkey_idx = _bt_mesh_node_get_subnet_idx(net_uuid.uuid, node->primary_unicast);
+ if (netkey_idx == MESH_NET_IDX_INVALID)
+ return BLUETOOTH_ERROR_INTERNAL;
+
+ data_len = _bt_mesh_util_opcode_set(MESH_OPCODE_NODE_RESET, buffer);
+
+ /* Send Node Reset command 5 times to ensure reliability */
+ for (int i = 0; i < 5; i++)
+ ret = mesh_conf_send_message(&net_uuid, node->primary_unicast,
+ true, netkey_idx, buffer, data_len);
+
+ if (ret != OAL_STATUS_SUCCESS) {
+ BT_ERR("Mesh: Node Reset Failed!: %d", ret);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ BT_INFO("Mesh: Node reset Done, Send Delete req: Unicast[0x%2.2x]",
+ node->primary_unicast);
+
+ ret = mesh_delete_remote_node(&net_uuid, node->primary_unicast,
+ node->num_elements);
+ if (ret != OAL_STATUS_SUCCESS) {
+ BT_ERR("Mesh: Remote Node Deletion Failed!: %d", ret);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ return _bt_mesh_network_remove_node_configuration(node);
+}
+
int _bt_mesh_node_model_appkey_execute(const char *app_cred, const char *sender,
bluetooth_mesh_model_configure_t *req)
{
return BLUETOOTH_ERROR_NONE;
}
+int _bt_mesh_network_remove_node_configuration(
+ bluetooth_mesh_node_info_t *node)
+{
+ GSList *l;
+ _bt_mesh_cdb_t *cdb_cfg = NULL;
+ uint8_t net_uuid[16];
+ BT_INFO("Mesh: Remove Node Configuration: Unicast [0x%2.2x]",
+ node->primary_unicast);
+
+ _bt_mesh_util_convert_string_to_hex(node->net_uuid,
+ strlen(node->net_uuid), net_uuid, 16);
+
+ /* Find CDB */
+ l = g_slist_find_custom(cdb_list, net_uuid,
+ __mesh_compare_app_network_uuid);
+ if (!l) {
+ BT_ERR("Mesh: Could not find Network Entry: unexpected!!");
+ return BLUETOOTH_ERROR_INVALID_PARAM;
+ }
+
+ cdb_cfg = (_bt_mesh_cdb_t*)l->data;
+
+ if (_bt_mesh_conf_delete_node(cdb_cfg, node->primary_unicast)) {
+ BT_INFO("Mesh: Node Entry deleted from Config DB");
+ if (!_bt_mesh_node_del_node(cdb_cfg, node->primary_unicast)) {
+ BT_ERR("Mesh: Node Entry could not be unloaded from memory");
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+ } else {
+ BT_ERR("Mesh: Node Entry could not be deleted from Config DB");
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+ return BLUETOOTH_ERROR_NONE;
+}
+
int _bt_mesh_network_remove_net_configuration(
bluetooth_mesh_network_t *net)
{
return true;
}
+uint8_t _bt_mesh_node_del_node(_bt_mesh_cdb_t *cfg,
+ uint16_t unicast)
+{
+ struct _bt_mesh_node_t *rmt;
+ uint8_t num_ele, i;
+ struct mesh_network_t *network;
+
+ if (!cfg)
+ return 0;
+
+ BT_INFO("Mesh: Uload Node Entry [0x%2.2x]", unicast);
+ network = l_queue_find(networks, __mesh_net_uuid_match, cfg->uuid);
+ if (!network)
+ return 0;
+
+ rmt = l_queue_find(network->nodes,
+ __mesh_match_node_addr, L_UINT_TO_PTR(unicast));
+ if (!rmt)
+ return 0;
+
+ rmt = l_queue_remove_if(network->nodes, __mesh_match_node_addr,
+ L_UINT_TO_PTR(unicast));
+ if (!rmt)
+ return 0;
+
+ num_ele = rmt->num_ele;
+
+ for (i = 0; i < num_ele; ++i)
+ l_queue_destroy(rmt->els[i], NULL);
+
+ l_free(rmt->els);
+
+ l_queue_destroy(rmt->net_keys, NULL);
+ l_queue_destroy(rmt->app_keys, NULL);
+ l_free(rmt);
+
+ return num_ele;
+}
+
bool _bt_mesh_node_add_node(uint8_t net_uuid[],
const uint8_t node_uuid[16], uint16_t unicast,
uint8_t ele_cnt, uint16_t net_idx)
} bluetooth_mesh_authentication_request_t;
typedef struct {
+ char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
uint16_t primary_unicast;
+ uint16_t num_elements;
char dev_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
} bluetooth_mesh_node_info_t;
int bluetooth_mesh_network_destroy(bluetooth_mesh_network_t *network);
/**
+ * Reset a remote Node & remove it from network
+ */
+int bluetooth_mesh_node_reset(bluetooth_mesh_node_info_t *node);
+
+/**
* Load already created Network
*/
int bluetooth_mesh_network_load(const char *token,
BT_MESH_NODE_TTL_EXECUTE,
BT_MESH_NODE_GET_NETKEYS,
BT_MESH_NODE_GET_APPKEYS,
+ BT_MESH_NODE_RESET,
BT_MESH_MODEL_CONFIGURE_APPKEY,
BT_MESH_MODEL_GET_APPKEY_LIST,
BT_MESH_MODEL_EXECUTE_MSG,