g_free(elem);
}
+static void __bt_mesh_free_appkeys(void *data)
+{
+ bt_mesh_appkey_s *appkey = (bt_mesh_appkey_s*)data;
+ appkey_list = g_slist_remove(appkey_list, appkey);
+ g_free(appkey);
+}
+
static gint __bt_mesh_compare_net_uuid(gpointer *a, gpointer *b)
{
bt_mesh_network_s *net = (bt_mesh_network_s *)a;
return BT_ERROR_NONE;
}
+static void __bt_mesh_destroy_network_handles(bt_mesh_network_s *net)
+{
+ GSList *l;
+
+ if (!net)
+ return;
+
+ BT_INFO("Mesh: Destroy handles of Network [%s] UUID [%s] Token [%s]",
+ net->name, net->uuid, net->token);
+
+ /* Remove all Nodes of Network */
+ BT_INFO("Mesh: Total nodes present in Network [%d]",
+ g_slist_length(net->nodes));
+ for (l = net->nodes; l != NULL; l = l->next) {
+ bt_mesh_node_s *node_s = (bt_mesh_node_s*)l->data;
+
+ net->nodes = g_slist_remove(net->nodes, node_s);
+ node_list = g_slist_remove(node_list, node_s);
+ BT_INFO("Mesh: Total elements present in Node [%d]",
+ g_slist_length(node_s->elements));
+
+ g_slist_free_full(node_s->elements, __bt_mesh_free_elements);
+ g_free(node_s);
+ }
+
+ /* Remove all Netkeys & Appkeys of Network */
+ BT_INFO("Mesh: Total netkeys present in Network [%d]",
+ g_slist_length(net->netkeys));
+ for (l = net->netkeys; l != NULL; l = l->next) {
+ bt_mesh_netkey_s *netkey_s = (bt_mesh_netkey_s*)l->data;
+
+ net->netkeys = g_slist_remove(net->netkeys, netkey_s);
+ netkey_list = g_slist_remove(netkey_list, netkey_s);
+ BT_INFO("Mesh: Total appkeys present in Netkey [%d]",
+ g_slist_length(netkey_s->appkeys));
+ g_slist_free_full(netkey_s->appkeys, __bt_mesh_free_appkeys);
+ g_free(netkey_s);
+ }
+
+ /* Remove all groups of Network */
+ BT_INFO("Mesh: Total groups present in Network [%d]",
+ g_slist_length(net->groups));
+ for (l = net->groups; l != NULL; l = l->next) {
+ bt_mesh_group_s *group_s = (bt_mesh_group_s*)l->data;
+
+ net->groups = g_slist_remove(net->groups, group_s);
+ group_list = g_slist_remove(group_list, group_s);
+ g_free(group_s);
+ }
+ BT_INFO("Mesh: Handle Removal Done!");
+}
+
static void __bt_mesh_generate_element(bt_mesh_node_s *node_s,
bt_mesh_element_s *elem_s)
{
return BT_ERROR_NONE;
}
+int bt_mesh_network_destroy(bt_mesh_network_h network)
+{
+ FUNC_ENTRY;
+
+ int error_code = BT_ERROR_NONE;
+ bt_mesh_network_s *network_s;
+ bluetooth_mesh_network_t net;
+
+ BT_CHECK_MESH_SUPPORT();
+ BT_CHECK_MESH_INIT_STATUS();
+ BT_CHECK_INPUT_PARAMETER(network);
+ BT_MESH_VALIDATE_HANDLE(network, networks);
+
+ network_s = (bt_mesh_network_s*) network;
+ memset(&net, 0x00, sizeof(bluetooth_mesh_network_t));
+
+ g_strlcpy(net.uuid, network_s->uuid, 33);
+ g_strlcpy(net.token.token, network_s->token, 17);
+ g_strlcpy(net.name.name, network_s->name, BT_MESH_NETWORK_NAME_STRING_MAX_LEN + 1);
+
+ BT_INFO("Mesh: Destroy Network: Name [%s]", network_s->name);
+
+ BT_INFO("Mesh: Send Network Destroy Request to FRWK");
+ error_code = _bt_get_error_code(bluetooth_mesh_network_destroy(&net));
+ if (error_code != BT_ERROR_NONE) {
+ BT_INFO("Mesh: Network Destroy Failed!!");
+ BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code);
+
+ FUNC_EXIT;
+ return error_code;
+ }
+
+ BT_INFO("Mesh: Network Destroyed successfully");
+
+ __bt_mesh_destroy_network_handles(network_s);
+ networks = g_slist_remove(networks, network_s);
+ g_free(network_s);
+
+ BT_INFO("Mesh: Current number of networks after removing [%d]",
+ g_slist_length(networks));
+ FUNC_EXIT;
+ return error_code;
+}
+
/* Async API's to bt-service & stack */
int bt_mesh_network_create(bt_mesh_node_h config_client,
const char *network_name,
network_s->netkeys = g_slist_remove(network_s->netkeys, netkey_s);
netkey_list = g_slist_remove(netkey_list, netkey_s);
- g_slist_free_full(netkey_s->appkeys, g_free);
+ g_slist_free_full(netkey_s->appkeys, __bt_mesh_free_appkeys);
+ g_free(netkey_s);
FUNC_EXIT;
return BT_ERROR_NONE;