Add to get wifi state 94/30994/6
authorChengyi Zhao <chengyi1.zhao@archermind.com>
Mon, 1 Dec 2014 04:59:23 +0000 (12:59 +0800)
committerChengyi Zhao <chengyi1.zhao@archermind.com>
Tue, 2 Dec 2014 02:20:45 +0000 (10:20 +0800)
This wifi state is expressed as a state of the station mode,
especially,after 'tethering' has been enabled, this wifi
state will be set to 'CONNECTION_WIFI_STATE_DEACTIVATED'.

Change-Id: Ia876fcdbfa04d2177c57a2f21911c669a96b3fe1
Signed-off-by: Chengyi Zhao <chengyi1.zhao@archermind.com>
src/include/net_pm_wlan.h
src/libnetwork.c

index cad52d28ef0f7750bd63b3fdc251868aac5ecaa7..799930775e678f2654cd0102cc8c6c49f861d7dd 100644 (file)
@@ -115,27 +115,6 @@ extern "C"
                                        ENUMS
 =============================================================================*/
 
-/**
-* @enum net_wifi_state_t
-* This enum indicates wifi state
-*/
-typedef enum {
-       /** Unknown state */
-       WIFI_UNKNOWN = 0x00,
-       /** Wi-Fi is Off */
-       WIFI_OFF,
-       /** Wi-Fi is On(idle/failure) */
-       WIFI_ON,
-       /** Trying to connect(association/configuration) */
-       WIFI_CONNECTING,
-       /** Wi-Fi is connected to an AP(ready/online) */
-       WIFI_CONNECTED,
-       /** Trying to disconnect(connected,
-        * but disconnecting process is on going)
-        */
-       WIFI_DISCONNECTING,
-} net_wifi_state_t;
-
 /**
 *@enum net_wifi_background_scan_mode_t
 * This enum indicates background scanning mode.
index 19a99d62719e758db1a8865747fbbaaf91d2ee8f..f176a9655cb542e465f6933926f7274f821830fe 100755 (executable)
@@ -20,6 +20,7 @@
 #include <vconf/vconf.h>
 #include <winet-wifi.h>
 #include <connman-lib.h>
+#include <connman-technology.h>
 #include "net_connection_private.h"
 
 static GSList *prof_handle_list = NULL;
@@ -318,33 +319,30 @@ bool _connection_libnet_check_profile_cb_validity(connection_profile_h profile)
        return false;
 }
 
-
 bool _connection_libnet_get_wifi_state(connection_wifi_state_e *state)
 {
-       net_wifi_state_t wlan_state = WIFI_OFF;
-       /*
-       net_profile_name_t profile_name;
-       TODO:
-       if (net_get_wifi_state(&wlan_state, &profile_name) != NET_ERR_NONE) {
-               CONNECTION_LOG(CONNECTION_ERROR, "Error!! net_get_wifi_state() failed.\n");
-               return false;
-       }
-        */
-       switch (wlan_state) {
-       case WIFI_OFF:
-               *state = CONNECTION_WIFI_STATE_DEACTIVATED;
-               break;
-       case WIFI_ON:
-       case WIFI_CONNECTING:
-               *state = CONNECTION_WIFI_STATE_DISCONNECTED;
-               break;
-       case WIFI_CONNECTED:
-       case WIFI_DISCONNECTING:
-               *state = CONNECTION_WIFI_STATE_CONNECTED;
-               break;
-       default :
-               CONNECTION_LOG(CONNECTION_ERROR, "Error!! Unknown state\n");
+       struct connman_technology *technology;
+       bool powered;
+       bool tethering;
+       bool connected;
+
+       technology = connman_get_technology(TECH_TYPE_WIFI);
+       if (technology == NULL)
                return false;
+
+       *state = CONNECTION_WIFI_STATE_DEACTIVATED;
+       powered = connman_get_technology_powered(technology);
+       tethering = connman_get_technology_tethering(technology);
+
+       if (powered) {
+               if (!tethering) {
+                       connected = connman_get_technology_connected(
+                                                               technology);
+                       if (connected)
+                               *state = CONNECTION_WIFI_STATE_CONNECTED;
+                       else
+                               *state = CONNECTION_WIFI_STATE_DISCONNECTED;
+               }
        }
 
        return true;