Fix the svace issue (DEREF_OF_NULL)
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / bluez_hal / src / bt-hal-mesh-dbus-handler.c
index 5f995b4..0b9f872 100644 (file)
@@ -99,6 +99,11 @@ struct mesh_provision_auth_action {
        bt_hal_mesh_auth_variant_e auth_type;
 };
 
+struct mesh_remote_node_info {
+       uint16_t unicast;
+       uint8_t num_elements;
+};
+
 static struct mesh_provision_auth_action auth_table[] = {
        { "blink", BT_HAL_MESH_AUTH_REQ_BLINK_COUNT_INPUT},
        { "beep", BT_HAL_MESH_AUTH_REQ_BEEP_COUNT_INPUT},
@@ -1414,6 +1419,10 @@ static struct l_dbus_message *__mesh_agent_prompt_numeric_request(
 
        l = g_slist_find_custom(mesh_apps, net_uuid,
                        __mesh_compare_network_uuid);
+       if (!l) {
+               g_free(net_uuid);
+               return NULL;
+       }
        app = l->data;
 
        memset(&ev, 0, sizeof(ev));
@@ -1459,7 +1468,7 @@ static struct l_dbus_message *__mesh_agent_prompt_static_request(
        uint8_t *net_uuid;
        const char *dbus_path;
        GSList *l;
-       meshcfg_app *app;
+       meshcfg_app *app = NULL;
 
        dbus_path =  l_dbus_message_get_path(msg);
        net_uuid = __mesh_get_net_uuid_from_path(dbus_path, true,
@@ -1469,7 +1478,13 @@ static struct l_dbus_message *__mesh_agent_prompt_static_request(
 
        l = g_slist_find_custom(mesh_apps, net_uuid,
                        __mesh_compare_network_uuid);
-       app = l->data;
+
+       if (l) {
+               app = l->data;
+       } else {
+               ERR("Mesh: app not found");
+       }
+
 
        memset(&ev, 0, sizeof(ev));
        memcpy(ev.net_uuid, net_uuid, 16);
@@ -1480,7 +1495,10 @@ static struct l_dbus_message *__mesh_agent_prompt_static_request(
 
                struct hal_ev_mesh_provision_finished ev;
                memset(&ev, 0, sizeof(ev));
-               memcpy(ev.net_uuid, app->uuid, 16);
+
+               if (app)
+                       memcpy(ev.net_uuid, app->uuid, 16);
+
                ev.status = BT_STATUS_FAIL;
                ev.reason = BT_HAL_MESH_PROV_ERR_INTERNAL;
                if (mesh_event_cb)
@@ -1777,6 +1795,8 @@ void __bt_mesh_enable_scanning_timer(uint8_t *net_uuid, uint16_t secs)
        meshcfg_app *app;
        l = g_slist_find_custom(mesh_apps, net_uuid,
                        __mesh_compare_network_uuid);
+       if (!l)
+               return;
        app = l->data;
 
        if (app->scan_timer_id > 0) {
@@ -2295,6 +2315,62 @@ bt_status_t _bt_hal_mesh_network_scan(bt_uuid_t *net_uuid,
        return BT_STATUS_SUCCESS;
 }
 
+static void __bt_hal_mesh_delete_node_setup(struct l_dbus_message *msg,
+               void *user_data)
+{
+       struct mesh_remote_node_info *node_info = \
+               (struct mesh_remote_node_info*) user_data;
+
+       l_dbus_message_set_arguments(msg, "qy",
+               node_info->unicast, node_info->num_elements);
+       INFO("Mesh: Delete Remote Node Setup params passed");
+}
+
+static void __bt_hal_mesh_delete_node_reply(
+               struct l_dbus_proxy *proxy,
+                       struct l_dbus_message *msg, void *user_data)
+{
+       INFO("Mesh: Delete Remote Node Reply from DBUS");
+}
+
+bt_status_t _bt_hal_mesh_node_delete(bt_uuid_t *network,
+               uint16_t unicast, uint16_t num_elements)
+{
+       GSList *l;
+       meshcfg_app *app;
+       struct mesh_remote_node_info *node_info;
+       INFO("Mesh: Delete Remote Node");
+       l = g_slist_find_custom(mesh_apps, network->uu, __mesh_compare_network_uuid);
+       if (l) {
+               app = l->data;
+               if (!__bt_mesh_proxy_check(app)) {
+                       ERR("Mesh: Proxy check failed!!");
+                       return BT_STATUS_FAIL;
+               }
+               INFO("Mesh: Delete Remote Node Unicast [0x%2.2x] Num els [%u]",
+                       unicast, num_elements);
+
+               /* Delete Remote Node Request */
+               node_info = g_malloc0(sizeof(struct mesh_remote_node_info));
+               node_info->unicast = unicast;
+               node_info->num_elements = num_elements;
+
+               if (!l_dbus_proxy_method_call(app->mgmt_proxy, "DeleteRemoteNode",
+                                       __bt_hal_mesh_delete_node_setup,
+                                       __bt_hal_mesh_delete_node_reply, node_info,
+                                       l_free)) {
+                       ERR("Mesh: Delete Remote Node Request failed!!");
+                       g_free(node_info);
+                       return BT_STATUS_FAIL;
+               }
+       } else {
+               ERR("Mesh: App not found!!");
+               return BT_STATUS_PARM_INVALID;
+       }
+       INFO("Mesh: Delete Remote Node Call issued successfully!!");
+       return BT_STATUS_SUCCESS;
+}
+
 bt_status_t _bt_hal_mesh_network_destroy(bt_uuid_t *net_uuid)
 {
        GSList *l;