wmesh-manager: Add support to get softAP station info
[platform/core/connectivity/wifi-mesh-manager.git] / src / wmesh-service-interface.c
index ab84d8a..3f640b3 100644 (file)
@@ -214,7 +214,7 @@ static gboolean _wmeshd_dbus_handle_enable(Manager *object,
        wmeshd_check_null_ret_error("info", info, FALSE);
 
        /* Register event handler first */
-       ret = wmesh_request_register_event_handler();
+       ret = wmesh_request_register_event_handler(service);
        if (WMESHD_ERROR_IN_PROGRESS == ret) {
                WMESH_LOGE("Currently set netlink event handler !! [%d]", ret);
                ret = WMESHD_ERROR_NONE;
@@ -651,6 +651,43 @@ static gboolean _wmeshd_dbus_handle_set_softap(NetWmesh *object,
        return TRUE;
 }
 
+static gboolean _wmeshd_dbus_handle_get_softap(NetWmesh *object,
+               GDBusMethodInvocation *invocation, gpointer user_data)
+{
+       int ret = WMESHD_ERROR_NONE;
+       wmesh_service *service = (wmesh_service *)user_data;
+       char *interface, *ssid, *mode, *passphrase;
+       int channel, visibility, max_sta, security;
+       (void) service; // unused
+
+       /* Get softAP information */
+       ret = wmesh_request_get_softap_config(&interface, &ssid, &mode, &channel,
+                                               &visibility, &max_sta, &security, &passphrase);
+       if (WMESHD_ERROR_NONE != ret) {
+               WMESH_LOGE("Failed to wmesh_request_get_softap_config [%d]", ret);
+               net_wmesh_complete_get_softap(object, invocation, "", "", 0, 0, 0, 0,
+                                                               "", ret);
+               return FALSE;
+       }
+
+       WMESH_LOGD("SSID      : %s", ssid);
+       WMESH_LOGD("mode      : %s", mode);
+       WMESH_LOGD("channel   : %d", channel);
+       WMESH_LOGD("visibility: %d", visibility);
+       WMESH_LOGD("max_sta   : %d", max_sta);
+       WMESH_LOGD("security  : %d", security);
+       WMESH_LOGD("Passphrase  : %s", passphrase ? passphrase : "NULL");
+
+       if (security == 1)
+               net_wmesh_complete_get_softap(object, invocation, ssid, mode, channel,
+                                                               visibility, max_sta, security, passphrase, ret);
+       else
+               net_wmesh_complete_get_softap(object, invocation, ssid, mode, channel,
+                                                               visibility, max_sta, security, "", ret);
+
+       return TRUE;
+}
+
 static gboolean _wmeshd_dbus_handle_enable_softap(NetWmesh *object,
                GDBusMethodInvocation *invocation, gpointer user_data)
 {
@@ -685,6 +722,21 @@ static gboolean _wmeshd_dbus_handle_disable_softap(NetWmesh *object,
        return TRUE;
 }
 
+static gboolean _wmeshd_dbus_handle_is_softap_enabled(NetWmesh *object,
+               GDBusMethodInvocation *invocation, gpointer user_data)
+{
+       bool status;
+       (void) user_data;
+
+       /* Check SoftAP status */
+       status = wmesh_request_check_softap_status();
+       WMESH_LOGD("SoftAP is %s", status ? "enabled" : "disabled");
+
+       net_wmesh_complete_is_softap_enabled(object, invocation, status);
+
+       return TRUE;
+}
+
 static gboolean _wmeshd_dbus_handle_create_mesh_network(NetWmesh *object,
                GDBusMethodInvocation *invocation,
                gchar *mesh_id, gint channel, gint security,
@@ -779,7 +831,7 @@ static gboolean _wmeshd_dbus_handle_set_interfaces(NetWmesh *object,
 }
 
 static gboolean _wmeshd_dbus_handle_get_station_info(NetWmesh *object,
-               GDBusMethodInvocation *invocation,
+               GDBusMethodInvocation *invocation, gint station_type,
                gpointer user_data)
 {
        int ret = WMESHD_ERROR_NONE;
@@ -791,12 +843,31 @@ static gboolean _wmeshd_dbus_handle_get_station_info(NetWmesh *object,
        wmesh_service *service = (wmesh_service *)user_data;
        wmesh_interface_s *info = service->interface_info;
 
-       /* Clear mesh station list */
-       g_list_free_full(service->station_list, _on_station_list_destroy);
-       service->station_list = NULL;
+       if (station_type == WMESHD_STATION_TYPE_MESH_POINT) {
+               /* Clear mesh station list */
+               g_list_free_full(service->station_list, _on_station_list_destroy);
+               service->station_list = NULL;
+
+               ret = wmesh_request_get_station_info(
+                                                               info->mesh_interface, &service->station_list);
+       } else if (station_type == WMESHD_STATION_TYPE_SOFTAP) {
+               /* Clear softAP station list */
+               g_list_free_full(service->softap_station_list,
+                                                _on_station_list_destroy);
+               service->softap_station_list = NULL;
+
+               ret = wmesh_request_get_station_info(
+                                                               info->softap_interface,
+                                                               &service->softap_station_list);
+       } else {
+               WMESH_LOGE("Invalid station type");
+
+               g_dbus_method_invocation_return_error(invocation,
+                               G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Invalid station type");
+
+               return FALSE;
+       }
 
-       ret = wmesh_request_get_station_info(
-                               info->mesh_interface, &service->station_list);
        if (WMESHD_ERROR_NONE != ret) {
                WMESH_LOGE("Failed to wmesh_request_get_station_info");
 
@@ -839,7 +910,11 @@ static gboolean _wmeshd_dbus_handle_get_station_info(NetWmesh *object,
                /* Get station information and make variant data */
                g_variant_builder_init(&builder, G_VARIANT_TYPE("aa{sv}"));
 
-               iter = service->station_list;
+               if (station_type == WMESHD_STATION_TYPE_MESH_POINT)
+                       iter = service->station_list;
+               else
+                       iter = service->softap_station_list;
+
                while (iter != NULL) {
                        wmesh_station_info_s *item = (wmesh_station_info_s*)iter->data;
 
@@ -874,18 +949,20 @@ static gboolean _wmeshd_dbus_handle_get_station_info(NetWmesh *object,
                                                g_variant_new_uint32(item->tx_bitrate)); /* 10 times */
                        g_variant_builder_add(&builder, "{sv}", "rx_bitrate",
                                                g_variant_new_uint32(item->rx_bitrate)); /* 10 times */
-                       g_variant_builder_add(&builder, "{sv}", "mesh_llid",
-                                               g_variant_new_uint16(item->llid));
-                       g_variant_builder_add(&builder, "{sv}", "mesh_plid",
-                                               g_variant_new_uint16(item->plid));
-                       g_variant_builder_add(&builder, "{sv}", "mesh_plink",
-                                               g_variant_new_byte(item->mesh_plink)); /* 0 : DISCON, 1 : ESTAB */
-                       g_variant_builder_add(&builder, "{sv}", "local_ps_mode",
-                                               g_variant_new_uint32(item->local_ps_mode)); /* 0 : INACTIVE, 1 : ACTIVE */
-                       g_variant_builder_add(&builder, "{sv}", "peer_ps_mode",
-                                               g_variant_new_uint32(item->peer_ps_mode)); /* 0 : INACTIVE, 1 : ACTIVE */
-                       g_variant_builder_add(&builder, "{sv}", "non_peer_ps_mode",
-                                               g_variant_new_uint32(item->non_peer_ps_mode)); /* 0 : INACTIVE, 1 : ACTIVE */
+                       if (station_type == WMESHD_STATION_TYPE_MESH_POINT) {
+                               g_variant_builder_add(&builder, "{sv}", "mesh_llid",
+                                                               g_variant_new_uint16(item->llid));
+                               g_variant_builder_add(&builder, "{sv}", "mesh_plid",
+                                                               g_variant_new_uint16(item->plid));
+                               g_variant_builder_add(&builder, "{sv}", "mesh_plink",
+                                                               g_variant_new_byte(item->mesh_plink)); /* 0 : DISCON, 1 : ESTAB */
+                               g_variant_builder_add(&builder, "{sv}", "local_ps_mode",
+                                                               g_variant_new_uint32(item->local_ps_mode)); /* 0 : INACTIVE, 1 : ACTIVE */
+                               g_variant_builder_add(&builder, "{sv}", "peer_ps_mode",
+                                                               g_variant_new_uint32(item->peer_ps_mode)); /* 0 : INACTIVE, 1 : ACTIVE */
+                               g_variant_builder_add(&builder, "{sv}", "non_peer_ps_mode",
+                                                               g_variant_new_uint32(item->non_peer_ps_mode)); /* 0 : INACTIVE, 1 : ACTIVE */
+                       }
                        g_variant_builder_add(&builder, "{sv}", "authorized",
                                                g_variant_new_boolean(item->authorized));
                        g_variant_builder_add(&builder, "{sv}", "associated",
@@ -1124,10 +1201,14 @@ static void _wmeshd_dbus_on_bus_acquired(GDBusConnection *conn, const gchar *nam
                        G_CALLBACK(_wmeshd_dbus_handle_unset_gate), service);
        g_signal_connect(meshd_dbus_object, "handle-set-softap",
                        G_CALLBACK(_wmeshd_dbus_handle_set_softap), service);
+       g_signal_connect(meshd_dbus_object, "handle-get-softap",
+                       G_CALLBACK(_wmeshd_dbus_handle_get_softap), service);
        g_signal_connect(meshd_dbus_object, "handle-enable-softap",
                        G_CALLBACK(_wmeshd_dbus_handle_enable_softap), service);
        g_signal_connect(meshd_dbus_object, "handle-disable-softap",
                        G_CALLBACK(_wmeshd_dbus_handle_disable_softap), service);
+       g_signal_connect(meshd_dbus_object, "handle-is-softap-enabled",
+                       G_CALLBACK(_wmeshd_dbus_handle_is_softap_enabled), NULL);
        g_signal_connect(meshd_dbus_object, "handle-create-mesh-network",
                        G_CALLBACK(_wmeshd_dbus_handle_create_mesh_network), service);
        g_signal_connect(meshd_dbus_object, "handle-connect-mesh-network",
@@ -1268,6 +1349,12 @@ static void _wmeshd_dbus_deinit(wmesh_service *service)
                g_list_free_full(service->station_list, _on_station_list_destroy);
        service->station_list = NULL;
 
+       /* Clear mesh station list */
+       if (service->softap_station_list)
+               g_list_free_full(service->softap_station_list,
+                                                _on_station_list_destroy);
+       service->softap_station_list = NULL;
+
        g_free(service->interface_info);
        service->interface_info = NULL;
 }