Added GetBssidList dbus call for wifi-manager to get BSSID list
[platform/core/connectivity/net-config.git] / src / wifi.c
index ea1b2d7..b91ee3b 100755 (executable)
@@ -18,6 +18,7 @@
  */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <unistd.h>
 #include <vconf.h>
 #include <vconf-keys.h>
@@ -29,6 +30,7 @@
 #include "neterror.h"
 #include "wifi-eap.h"
 #include "wifi-wps.h"
+#include "wifi-bssid-scan.h"
 #include "wifi-power.h"
 #include "wifi-state.h"
 #include "wifi-agent.h"
@@ -40,6 +42,9 @@
 #include "wifi-config.h"
 #include "wifi-tdls.h"
 
+#define SPRD_CP2_FIRMWARE_PATH "/usr/bin/cp2-downloader"
+static int is_wifi_firmware_downloaded = FALSE;
+
 static Wifi *wifi_object = NULL;
 static NetConnmanAgent *connman_agent_object = NULL;
 static WifiFirmware *wififirmware_object = NULL;
@@ -53,7 +58,7 @@ static gboolean handle_check_black_list(Wifi *wifi, GDBusMethodInvocation *conte
 {
        ERR("Name (%s)", name);
        INFO("disable to check");
-       wifi_complete_check_black_list (wifi, context, TRUE);
+       wifi_complete_check_black_list(wifi, context, TRUE);
        return TRUE;
 }
 
@@ -65,7 +70,7 @@ static void _set_wifi_mac_address(void)
        if (mac_addr != NULL) {
                if (strlen(mac_addr) == 0)
                        netconfig_set_mac_address_from_file();
-               g_free(mac_addr);
+               free(mac_addr);
        }
 }
 
@@ -81,6 +86,14 @@ void __netconfig_wifi_connect_reply(GObject *source_object, GAsyncResult *res,
        g_dbus_connection_call_finish(conn, res, &error);
        if (error != NULL) {
                ERR("WiFi Connection Error [%s]", error->message);
+               /* No need to emit WiFiConnectFail signal if Connection is
+                * in progress */
+               if (error->code == G_IO_ERROR_TIMED_OUT) {
+                       g_error_free(error);
+                       DBG("WiFi Connection in Progress");
+                       netconfig_gdbus_pending_call_unref();
+                       return;
+               }
                g_error_free(error);
                if (netconfig_dbus_emit_signal(NULL, NETCONFIG_WIFI_PATH,
                                NETCONFIG_WIFI_INTERFACE, "WiFiConnectFail",
@@ -95,6 +108,26 @@ void __netconfig_wifi_connect_reply(GObject *source_object, GAsyncResult *res,
        return;
 }
 
+int wifi_firmware_download(void)
+{
+       int rv = 0;
+       const char *path = SPRD_CP2_FIRMWARE_PATH;
+       char *const args[] = { SPRD_CP2_FIRMWARE_PATH, NULL };
+       char *const envs[] = { NULL };
+
+       if (!is_wifi_firmware_downloaded) {
+               rv = netconfig_execute_file(path, args, envs);
+               if (rv < 0) {
+                       DBG("wifi firmware download fails");
+                       return -EIO;
+               }
+               is_wifi_firmware_downloaded = TRUE;
+               DBG("wifi firmware download successes");
+       }
+
+       return 0;
+}
+
 void wifi_object_create_and_init(void)
 {
        DBG("Create wifi object.");
@@ -113,7 +146,7 @@ void wifi_object_create_and_init(void)
        wifi_object = wifi_skeleton_new();
        interface_wifi = G_DBUS_INTERFACE_SKELETON(wifi_object);
 
-       // WIFI power
+       /* WIFI power */
        g_signal_connect(wifi_object, "handle-load-driver",
                        G_CALLBACK(handle_load_driver), NULL);
        g_signal_connect(wifi_object, "handle-remove-driver",
@@ -123,27 +156,43 @@ void wifi_object_create_and_init(void)
        g_signal_connect(wifi_object, "handle-remove-p2p-driver",
                        G_CALLBACK(handle_remove_p2p_driver), NULL);
 
-       // WIFI state
+       /* WIFI state */
        g_signal_connect(wifi_object, "handle-get-wifi-state",
                        G_CALLBACK(handle_get_wifi_state), NULL);
 
-       // WIFI scan
+       /* WIFI scan */
        g_signal_connect(wifi_object, "handle-request-specific-scan",
                        G_CALLBACK(handle_request_specific_scan), NULL);
-       g_signal_connect(wifi_object, "handle-request-wps-scan",
-                       G_CALLBACK(handle_request_wps_scan), NULL);
-
-       // WIFI direct
+       g_signal_connect(wifi_object, "handle-request-bssid-scan",
+                       G_CALLBACK(handle_request_bssid_scan), NULL);
+       g_signal_connect(wifi_object, "handle-get-bssid-list",
+                       G_CALLBACK(handle_get_bssid_list), NULL);
+
+       /* WPS Connect */
+       g_signal_connect(wifi_object, "handle-request-wps-connect",
+                       G_CALLBACK(handle_request_wps_connect), NULL);
+       g_signal_connect(wifi_object, "handle-request-wps-cancel",
+                       G_CALLBACK(handle_request_wps_cancel), NULL);
+
+       /* WIFI direct */
        g_signal_connect(wifi_object, "handle-launch-direct",
                        G_CALLBACK(handle_launch_direct), NULL);
 
-       // EAP config
+       /* EAP config */
        g_signal_connect(wifi_object, "handle-create-eap-config",
                        G_CALLBACK(handle_create_eap_config), NULL);
        g_signal_connect(wifi_object, "handle-delete-eap-config",
                        G_CALLBACK(handle_delete_eap_config), NULL);
 
-       // WIFI configuration
+       /* VSIE methods */
+       g_signal_connect(wifi_object, "handle-add-vsie",
+                       G_CALLBACK(handle_add_vsie), NULL);
+       g_signal_connect(wifi_object, "handle-get-vsie",
+                       G_CALLBACK(handle_get_vsie), NULL);
+       g_signal_connect(wifi_object, "handle-remove-vsie",
+                       G_CALLBACK(handle_remove_vsie), NULL);
+
+       /* WIFI configuration */
        g_signal_connect(wifi_object, "handle-save-configuration",
                        G_CALLBACK(handle_save_configuration), NULL);
        g_signal_connect(wifi_object, "handle-remove-configuration",
@@ -156,13 +205,13 @@ void wifi_object_create_and_init(void)
                        G_CALLBACK(handle_set_config_field), NULL);
        g_signal_connect(wifi_object, "handle-get-config-passphrase",
                        G_CALLBACK(handle_get_config_passphrase), NULL);
-       // WIFI EAP configuration
+       /* WIFI EAP configuration */
        g_signal_connect(wifi_object, "handle-save-eap-configuration",
                        G_CALLBACK(handle_save_eap_configuration), NULL);
        g_signal_connect(wifi_object, "handle-load-eap-configuration",
                        G_CALLBACK(handle_load_eap_configuration), NULL);
 
-       // BG scan mode
+       /* BG scan mode */
        g_signal_connect(wifi_object, "handle-set-bgscan",
                        G_CALLBACK(handle_set_bgscan), NULL);
        g_signal_connect(wifi_object, "handle-resume-bgscan",
@@ -170,13 +219,19 @@ void wifi_object_create_and_init(void)
        g_signal_connect(wifi_object, "handle-pause-bgscan",
                        G_CALLBACK(handle_pause_bgscan), NULL);
 
-       // Passpoint
+       /*Auto Scan Mode */
+       g_signal_connect(wifi_object, "handle-get-autoscan",
+                       G_CALLBACK(handle_get_autoscan), NULL);
+       g_signal_connect(wifi_object, "handle-get-autoscanmode",
+                       G_CALLBACK(handle_get_autoscanmode), NULL);
+
+       /* Passpoint */
        g_signal_connect(wifi_object, "handle-set-passpoint",
                                G_CALLBACK(handle_set_passpoint), NULL);
        g_signal_connect(wifi_object, "handle-get-passpoint",
                                        G_CALLBACK(handle_get_passpoint), NULL);
 
-       // EAP authentication
+       /* EAP authentication */
        g_signal_connect(wifi_object, "handle-get-aka-auth",
                                G_CALLBACK(handle_get_aka_auth), NULL);
        g_signal_connect(wifi_object, "handle-get-sim-auth",
@@ -188,22 +243,30 @@ void wifi_object_create_and_init(void)
        g_signal_connect(wifi_object, "handle-req-sim-auth",
                        G_CALLBACK(handle_req_sim_auth), NULL);
 
-       // WIFI MDM blacklist
+       /* WIFI MDM blacklist */
        g_signal_connect(wifi_object, "handle-check-black-list",
                        G_CALLBACK(handle_check_black_list), NULL);
 
-       //TDLS methods
+       /* TDLS methods */
        g_signal_connect(wifi_object, "handle-tdls-disconnect",
                        G_CALLBACK(handle_tdls_disconnect), NULL);
        g_signal_connect(wifi_object, "handle-tdls-connected-peer",
                        G_CALLBACK(handle_tdls_connected_peer), NULL);
+       g_signal_connect(wifi_object, "handle-tdls-discover",
+                       G_CALLBACK(handle_tdls_discover), NULL);
+       g_signal_connect(wifi_object, "handle-tdls-connect",
+                       G_CALLBACK(handle_tdls_connect), NULL);
+       g_signal_connect(wifi_object, "handle-tdls-channel-switch",
+                       G_CALLBACK(handle_tdls_channel_switch), NULL);
+       g_signal_connect(wifi_object, "handle-tdls-cancel-channel-switch",
+                       G_CALLBACK(handle_tdls_cancel_channel_switch), NULL);
 
        if (!g_dbus_interface_skeleton_export(interface_wifi, connection,
                        NETCONFIG_WIFI_PATH, NULL)) {
                ERR("Export WIFI_PATH for wifi failed");
        }
 
-       /*Interface connman.Agent*/
+       /* Interface connman.Agent */
        connman_agent_object = net_connman_agent_skeleton_new();
 
        interface_connman_agent = G_DBUS_INTERFACE_SKELETON(connman_agent_object);