ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
-
INCLUDE(FindPkgConfig)
PKG_CHECK_MODULES(pkgs REQUIRED
dbus-1
ENDFOREACH(flag)
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall")
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS "-I${CMAKE_SOURCE_DIR}/include ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
SET(CMAKE_C_FLAGS_RELEASE "-O2")
+net-config (0.1.77) unstable; urgency=low
+
+ * Revise net-config to fit Android supplicant
+ * Revise net-config log
+ * Git: slp/pkgs/n/net-config
+ * Tag: net-config_0.1.77
+
+ -- Danny Jeongseok Seo <s.seo@samsung.com> Tue, 24 Apr 2012 23:08:11 +0900
+
net-config (0.1.76) unstable; urgency=low
* Add a vconf key for local MAC address of Wi-Fi device
*
*/
-#ifndef __NETCONFIG_EMULATOR_H_
-#define __NETCONFIG_EMULATOR_H_
+#ifndef __NETCONFIG_EMULATOR_H__
+#define __NETCONFIG_EMULATOR_H__
#ifdef __cplusplus
extern "C" {
}
#endif
-#endif /* __NETCONFIG_EMULATOR_H_ */
+#endif /* __NETCONFIG_EMULATOR_H__ */
#endif
#include <dlog.h>
+#include <stdio.h>
+#include <string.h>
-#define _SLOG(level, format, arg...) \
+#define __LOG(level, format, arg...) \
do { \
- SLOG(level, "net-config", "(%s:%d)"format"\n", __FILE__, __LINE__, ##arg); \
+ char *ch = strrchr(__FILE__, '/'); \
+ ch = ch ? ch + 1 : __FILE__; \
+ SLOG(level, PACKAGE, "%s:%s() "format"\n", ch, __FUNCTION__, ## arg); \
} while(0)
-#define _PRT(level, format, arg...) \
+#define __PRT(level, format, arg...) \
do { \
- fprintf(stderr, "["PACKAGE"](%s:%d)"format"\n", __FILE__, __LINE__, ##arg); \
+ char *ch = strrchr(__FILE__, '/'); \
+ ch = ch ? ch + 1 : __FILE__; \
+ fprintf(stderr, PACKAGE": %s:%s() "format"\n", ch, __FUNCTION__, ## arg); \
} while(0)
-#define _NO_LOG(level, format, arg...) do {} while (0)
-#define _LOG _SLOG
-
-#define DBG(format, arg...) _LOG(LOG_DEBUG, format, ##arg)
-#define WARN(format, arg...) _LOG(LOG_WARN, format, ##arg)
-#define INFO(format, arg...) _LOG(LOG_INFO, format, ##arg)
-#define ERR(format, arg...) _LOG(LOG_ERROR, format, ##arg)
+#define DBG(format, arg...) __LOG(LOG_DEBUG, format, ## arg)
+#define INFO(format, arg...) __LOG(LOG_INFO, format, ## arg)
+#define WARN(format, arg...) __LOG(LOG_WARN, format, ## arg)
+#define ERR(format, arg...) __LOG(LOG_ERROR, format, ## arg)
#ifdef __cplusplus
}
GType netconfig_network_state_get_type(void);
-
gpointer netconfig_network_state_create_and_init(DBusGConnection *conn);
G_END_DECLS
*
*/
-#ifndef __NETCONFIG_UTIL_H_
-#define __NETCONFIG_UTIL_H_
+#ifndef __NETCONFIG_UTIL_H__
+#define __NETCONFIG_UTIL_H__
#ifdef __cplusplus
extern "C" {
gboolean netconfig_is_wifi_direct_on(void);
gboolean netconfig_is_wifi_tethering_on(void);
-void netconfig_wifi_check_local_bssid(void);
gboolean netconfig_execute_file(const char *file_path,
char *const args[], char *const env[]);
}
#endif
-#endif /* __NETCONFIG_UTIL_H_ */
+#endif /* __NETCONFIG_UTIL_H__ */
*
*/
-#ifndef __NETCONFIG_WIFIBACKGROUNDSCAN_H_
-#define __NETCONFIG_WIFIBACKGROUNDSCAN_H_
+#ifndef __NETCONFIG_WIFIBACKGROUND_SCAN_H__
+#define __NETCONFIG_WIFIBACKGROUND_SCAN_H__
#ifdef __cplusplus
extern "C" {
}
#endif
-#endif /* __NETCONFIG_WIFIBACKGROUNDSCAN_H_ */
+#endif /* __NETCONFIG_WIFIBACKGROUND_SCAN_H__ */
*
*/
-#ifndef __NETCONFIG_WIFIINDICATOR_H_
-#define __NETCONFIG_WIFIINDICATOR_H_
+#ifndef __NETCONFIG_WIFI_INDICATOR_H__
+#define __NETCONFIG_WIFI_INDICATOR_H__
#ifdef __cplusplus
extern "C" {
}
#endif
-#endif /* __NETCONFIG_WIFIINDICATOR_H_ */
+#endif /* __NETCONFIG_WIFI_INDICATOR_H__ */
*
*/
-#ifndef __NETCONFIG_WIFISTATE_H_
-#define __NETCONFIG_WIFISTATE_H_
+#ifndef __NETCONFIG_WIFI_STATE_H__
+#define __NETCONFIG_WIFI_STATE_H__
#ifdef __cplusplus
extern "C" {
enum netconfig_wifi_service_state
netconfig_wifi_state_get_service_state(void);
+gchar *netconfig_wifi_get_technology_state(void);
+
+void netconfig_wifi_update_power_state(gboolean powered);
+
#ifdef __cplusplus
}
#endif
-#endif /* __NETCONFIG_WIFISTATE_H_ */
+#endif /* __NETCONFIG_WIFI_STATE_H__ */
WIFI_POWER_ON = 0x01,
};
-enum netconfig_wifi_power_triggering_state {
- WIFI_NON_OF_TRIGGERING = 0x01,
-
- WIFI_ACTIVATING = 0x02,
- WIFI_DEACTIVATING = 0x03,
-};
-
GType netconfig_wifi_get_type(void);
-
gpointer netconfig_wifi_create_and_init(DBusGConnection *conn);
-gboolean netconfig_wifi_remove_driver(void);
-
-gboolean netconfig_wifi_enable_technology(void);
-gboolean netconfig_wifi_disable_technology(void);
-void netconfig_wifi_set_power_triggering_state(
- enum netconfig_wifi_power_triggering_state state);
-enum netconfig_wifi_power_triggering_state
- netconfig_wifi_get_power_triggering_state(void);
-
-gboolean netconfig_iface_wifi_load_driver(NetconfigWifi *wifi, GError **error);
-gboolean netconfig_iface_wifi_remove_driver(NetconfigWifi *wifi, GError **error);
-
G_END_DECLS
#ifdef __cplusplus
<?xml version="1.0" encoding="UTF-8"?>
-<node name="/">
+<node name="/net/netconfig/network">
<interface name="net.netconfig.network">
<method name="UpdateDefaultConnectionInfo">
<arg type="s" name="connection_type" direction="in" />
<arg type="s" name="proxy_addr" direction="in" />
</method>
</interface>
-</node>
\ No newline at end of file
+</node>
<?xml version="1.0" encoding="UTF-8"?>
-<node name="/">
+<node name="/net/netconfig/wifi">
<interface name="net.netconfig.wifi">
<method name="LoadDriver">
</method>
<arg name="error" type="s"/>
</signal>
</interface>
-</node>
\ No newline at end of file
+</node>
Name: net-config
Summary: TIZEN Network Configuration Module
-Version: 0.1.76
+Version: 0.1.77
Release: 1
Group: System/Network
License: Apache License Version 2.0
*
*/
-#include "log.h"
-#include "neterror.h"
-#include "network-state.h"
-
#include <vconf.h>
#include <vconf-keys.h>
#include <syspopup_caller.h>
+#include "log.h"
+#include "neterror.h"
+#include "network-state.h"
+
#define NETCONFIG_NETWORK_STATE_PATH "/net/netconfig/network"
#define PROP_DEFAULT FALSE
bundle *b = NULL;
int wifi_ug_state = 0;
- vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE,&wifi_ug_state);
+ vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state);
if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)
return;
#include "log.h"
#include "dbus.h"
#include "util.h"
-#include "wifi.h"
#include "wifi-state.h"
#include "wifi-indicator.h"
#include "wifi-background-scan.h"
static void __netconfig_wifi_technology_state_signal_handler(
const char *sigvalue, const char *property)
{
- int wifi_state = 0;
static char previous_technology_state[DBUS_STATE_MAX_BUFLEN] = {0};
if (sigvalue == NULL || property == NULL)
g_strlcpy(previous_technology_state, property, sizeof(previous_technology_state));
- vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
-
INFO("Technology state value is %s, property %s", sigvalue, property);
- if (g_str_equal(property, "offline") == TRUE) {
- if (netconfig_wifi_get_power_triggering_state() == WIFI_DEACTIVATING)
- netconfig_wifi_set_power_triggering_state(WIFI_NON_OF_TRIGGERING);
-
- if (wifi_state != VCONFKEY_WIFI_OFF) {
- vconf_set_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_OFF);
-
- vconf_set_int(VCONF_WIFI_LAST_POWER_ON_STATE, WIFI_POWER_OFF);
-
- vconf_set_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_OFF);
- }
- netconfig_wifi_bgscan_stop();
- } else if (g_str_equal(property, "available") == TRUE) {
- switch (netconfig_wifi_get_power_triggering_state()) {
- case WIFI_ACTIVATING:
- /* Wi-Fi power on triggered */
- netconfig_wifi_enable_technology();
-
- netconfig_wifi_device_picker_service_start();
-
- netconfig_wifi_check_local_bssid();
-
- break;
-
- case WIFI_DEACTIVATING:
- /* Wi-Fi power off triggered */
- netconfig_wifi_remove_driver();
-
- break;
- default:
- DBG("Wi-Fi tethering or direct enabled");
- }
- } else if (g_str_equal(property, "enabled") == TRUE) {
- if (netconfig_wifi_get_power_triggering_state() == WIFI_ACTIVATING) {
- netconfig_wifi_set_power_triggering_state(WIFI_NON_OF_TRIGGERING);
-
- if (wifi_state == VCONFKEY_WIFI_OFF) {
- vconf_set_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_NOT_CONNECTED);
-
- vconf_set_int(VCONF_WIFI_LAST_POWER_ON_STATE, WIFI_POWER_ON);
+ if (g_str_equal(property, "offline") == TRUE) {
+ gchar *wifi_tech_state = NULL;
- vconf_set_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_UNCONNECTED);
- }
+ wifi_tech_state = netconfig_wifi_get_technology_state();
+ INFO("Wi-Fi technology state: %s", wifi_tech_state);
- netconfig_wifi_bgscan_start();
- }
- }
+ if (wifi_tech_state == NULL)
+ netconfig_wifi_update_power_state(FALSE);
+ else
+ g_free(wifi_tech_state);
+ } else if (g_str_equal(property, "enabled") == TRUE)
+ netconfig_wifi_update_power_state(TRUE);
}
static void netconfig_wifi_set_essid(const char *active_profile)
int err;
int state = -1;
char *essid_name = NULL;
- DBusConnection *conn = NULL;
+ DBusConnection *connection = NULL;
DBusMessage *message = NULL;
int MessageType = 0;
return;
}
- conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (conn == NULL) {
- ERR("Error!!! Can't get on system bus");
+ connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+ if (connection == NULL) {
+ ERR("Failed to get system bus");
return;
}
- message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, conn, active_profile,
+ message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, connection, active_profile,
CONNMAN_SERVICE_INTERFACE, "GetProperties");
if (message == NULL) {
- ERR("Error!!! Failed to get service properties");
- dbus_connection_unref(conn);
+ ERR("Failed to get service properties");
+ dbus_connection_unref(connection);
return;
}
dbus_message_unref(message);
- dbus_connection_unref(conn);
+ dbus_connection_unref(connection);
}
static void netconfig_wifi_unset_essid(void)
return FALSE;
}
-void netconfig_wifi_check_local_bssid(void)
-{
-}
-
gboolean netconfig_execute_file(const char *file_path,
char *const args[], char *const env[])
{
if (!(pid = fork())) {
register unsigned int index = 0;
- DBG("pid(%d), ppid (%d)", getpid(), getppid());
- DBG("Inside child, exec (%s) command", file_path);
+ INFO("pid(%d), ppid (%d)", getpid(), getppid());
+ INFO("Inside child, exec (%s) command", file_path);
index = 0;
while (args[index] != NULL) {
NULL
};
- int snr_level = 0;
-
- vconf_get_int(VCONFKEY_WIFI_STRENGTH, &snr_level);
if (netconfig_wifi_state_get_service_state() == NETCONFIG_WIFI_CONNECTED)
if (__netconfig_wifi_bgscan_get_mode() == WIFI_BGSCAN_MODE_EXPONENTIAL)
- if (snr_level > 2)
return FALSE;
if (netconfig_wifi_state_get_service_state() == NETCONFIG_WIFI_CONNECTING)
if (data == NULL)
return;
- DBG("[%s]", __FUNCTION__);
netconfig_stop_timer(&(data->timer_id));
data->mode = __netconfig_wifi_bgscan_get_mode();
switch (data->mode) {
- case WIFI_BGSCAN_MODE_EXPONENTIAL:
- if (data->time == 0)
- data->time = SCAN_EXPONENTIAL_MIN;
- else if ((data->time >= SCAN_EXPONENTIAL_MAX) || (data->time > SCAN_EXPONENTIAL_MAX / 2))
- data->time = SCAN_EXPONENTIAL_MAX;
- else
- data->time = data->time * 2;
- break;
- case WIFI_BGSCAN_MODE_PERIODIC:
- data->time = SCAN_PERIODIC_DELAY;
- break;
- default:
- data->time = SCAN_INITIAL_DELAY;
- break;
- }
- switch (data->mode) {
- case WIFI_BGSCAN_MODE_PERIODIC:
- DBG("[%s]BG scan mode is periodic", __FUNCTION__);
- break;
- case WIFI_BGSCAN_MODE_EXPONENTIAL:
- DBG("[%s]BG scan mode is exponential", __FUNCTION__);
- break;
- default:
- DBG("[%s]strange value [%d]", __FUNCTION__, data->mode);
- break;
+ case WIFI_BGSCAN_MODE_EXPONENTIAL:
+ if (data->time == 0)
+ data->time = SCAN_EXPONENTIAL_MIN;
+ else if ((data->time >= SCAN_EXPONENTIAL_MAX) || (data->time > SCAN_EXPONENTIAL_MAX / 2))
+ data->time = SCAN_EXPONENTIAL_MAX;
+ else
+ data->time = data->time * 2;
+
+ DBG("Wi-Fi background scan with exponentially increasing period");
+ break;
+
+ case WIFI_BGSCAN_MODE_PERIODIC:
+ data->time = SCAN_PERIODIC_DELAY;
+
+ DBG("Wi-Fi background scan periodically");
+ break;
+
+ default:
+ data->time = SCAN_INITIAL_DELAY;
+ DBG("Wi-Fi background scan with initial delay");
}
DBG("Register background scan timer with %d seconds", data->time);
+
netconfig_start_timer_seconds(data->time, __netconfig_wifi_bgscan_request_scan, data, &(data->timer_id));
}
if (data == NULL)
return;
- DBG("[%s]", __FUNCTION__);
+ DBG("Stop Wi-Fi background scan timer");
+
netconfig_stop_timer(&(data->timer_id));
}
if (timer == NULL)
return FALSE;
- DBG("[%s] Try to send a scan request to ConnMan", __FUNCTION__);
+ DBG("Request Wi-Fi scan to ConnMan");
__netconfig_wifi_bgscan_stop_timer(timer);
#include "util.h"
#include "wifi-indicator.h"
-#define NETCONFIG_WIFI_INDICATOR_UPDATE_INTERVAL 1
+#define NETCONFIG_WIFI_INDICATOR_UPDATE_INTERVAL 3
#define VCONFKEY_WIFI_SNR_MIN -85
#define VCONFKEY_WIFI_SNR_MAX -55
return -1;
}
-static void __netconfig_wifi_service_disconnect(void)
-{
- int MessageType = 0;
- DBusConnection *conn = NULL;
- DBusMessage *message = NULL;
- char *path_ptr = NULL;
- char path[DBUS_PATH_MAX_BUFLEN] = { 0 };
-
- path_ptr = &path[0];
-
- if (__netconfig_wifi_get_interface((const char **)(&path_ptr)) < 0) {
- ERR("ERR fail to get interface");
- return;
- }
-
- INFO("interface name is [%s]", path_ptr);
-
- conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (conn == NULL) {
- ERR("Error!!! Can't get on system bus");
- return;
- }
-
- message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE, conn, (char *)path,
- SUPPLICANT_INTERFACE ".Interface", "Disconnect");
-
- if (message == NULL) {
- ERR("Error!!! Failed to get service properties");
- dbus_connection_unref(conn);
- return;
- }
-
- MessageType = dbus_message_get_type(message);
-
- if (MessageType == DBUS_MESSAGE_TYPE_ERROR) {
- const char *ptr = dbus_message_get_error_name(message);
- ERR("Error!!! Error message received [%s]", ptr);
- }
-
- dbus_message_unref(message);
-
- dbus_connection_unref(conn);
-}
-
#ifdef NL80211
static int __netconfig_wifi_get_signal(const char *path, int *sig)
{
last_snr = snr_level;
}
- if (rssi_dbm < NETCONFIG_WIFI_WEAK_SIGNAL) {
- INFO("rssi (%d) is under (%d)", rssi_dbm,
- VCONFKEY_WIFI_SNR_MIN);
-
- __netconfig_wifi_service_disconnect();
- }
-
return 0;
}
*/
#include <stdio.h>
+#include <unistd.h>
#include <vconf.h>
#include <vconf-keys.h>
#include <wifi-direct.h>
#include "neterror.h"
#include "netconfig.h"
#include "emulator.h"
+#include "wifi-state.h"
#include "wifi-background-scan.h"
+gboolean netconfig_iface_wifi_load_driver(NetconfigWifi *wifi, GError **error);
+gboolean netconfig_iface_wifi_remove_driver(NetconfigWifi *wifi, GError **error);
+
#include "netconfig-iface-wifi-glue.h"
#define NETCONFIG_WIFI_PATH "/net/netconfig/wifi"
}
-static enum netconfig_wifi_power_triggering_state
-__netconfig_wifi_triggering_state(gboolean is_set_method,
- enum netconfig_wifi_power_triggering_state state)
-{
- static enum netconfig_wifi_power_triggering_state wifi_state =
- WIFI_NON_OF_TRIGGERING;
-
- if (is_set_method != TRUE)
- return wifi_state;
-
- if (wifi_state != state)
- wifi_state = state;
-
- DBG("Wi-Fi power triggering state set %d", wifi_state);
-
- return wifi_state;
-}
-
-void netconfig_wifi_set_power_triggering_state(
- enum netconfig_wifi_power_triggering_state state)
-{
- __netconfig_wifi_triggering_state(TRUE, state);
-}
-
-enum netconfig_wifi_power_triggering_state
- netconfig_wifi_get_power_triggering_state(void)
-{
- return __netconfig_wifi_triggering_state(FALSE, -1);
-}
-
-gboolean netconfig_wifi_enable_technology(void)
+static gboolean __netconfig_wifi_enable_technology(void)
{
DBusMessage *reply = NULL;
char path[DBUS_PATH_MAX_BUFLEN] = "/";
return TRUE;
}
-gboolean netconfig_wifi_disable_technology(void)
+static gboolean __netconfig_wifi_disable_technology(void)
{
DBusMessage *reply = NULL;
char path[DBUS_PATH_MAX_BUFLEN] = "/";
return TRUE;
}
-gboolean netconfig_wifi_remove_driver(void)
+static gboolean __netconfig_wifi_try_to_load_driver(void);
+static gboolean __netconfig_wifi_try_to_remove_driver(void);
+
+static void __netconfig_wifi_direct_state_cb(int error_code,
+ wifi_direct_device_state_e device_state, void *user_data)
{
- return __netconfig_wifi_remove_driver();
+ wifi_direct_unset_device_state_changed_cb();
+ wifi_direct_deinitialize();
+
+ if (device_state == WIFI_DIRECT_DEVICE_STATE_DEACTIVATED) {
+ __netconfig_wifi_try_to_load_driver();
+
+ return;
+ }
+
+ /* TODO: error report */
}
+static gboolean __netconfig_wifi_direct_power_off(void)
+{
+ DBG("Wi-Fi direct is turning off");
+
+ if (wifi_direct_initialize() < 0)
+ return FALSE;
+
+ if (wifi_direct_set_device_state_changed_cb(
+ __netconfig_wifi_direct_state_cb, NULL) < 0)
+ return FALSE;
+
+ if (wifi_direct_deactivate() < 0)
+ return FALSE;
+
+ return TRUE;
+}
static gboolean __netconfig_wifi_try_to_load_driver(void)
{
- gboolean ret = FALSE;
-
- netconfig_wifi_set_power_triggering_state(WIFI_ACTIVATING);
+ int count = 0;
+ gchar *wifi_tech_state = NULL;
- ret = __netconfig_wifi_load_driver();
+ if (netconfig_is_wifi_tethering_on() == TRUE) {
+ /* TODO: Wi-Fi tethering turns off here */
+ /* return TRUE; */
+ return FALSE;
+ }
- if (ret == FALSE) {
- DBG("Fail to load Wi-Fi driver");
+ if (netconfig_is_wifi_direct_on() == TRUE) {
+ if (__netconfig_wifi_direct_power_off() == TRUE)
+ return TRUE;
+ else
+ return FALSE;
+ }
+ if (__netconfig_wifi_load_driver() != TRUE) {
__netconfig_wifi_remove_driver();
- netconfig_wifi_set_power_triggering_state(WIFI_NON_OF_TRIGGERING);
+ return FALSE;
}
- return ret;
-}
+ /* TODO: Do I need some time to activate new link for ConnMan? I don't think so */
+ /* sleep(1); */
-static gboolean __netconfig_wifi_try_to_remove_driver(void)
-{
- gboolean ret = FALSE;
+ for (count = 0; count < 3; count++) {
+ __netconfig_wifi_enable_technology();
- netconfig_wifi_set_power_triggering_state(WIFI_DEACTIVATING);
+ wifi_tech_state = netconfig_wifi_get_technology_state();
+ INFO("Wi-Fi technology state: %s", wifi_tech_state);
- netconfig_wifi_device_picker_service_stop();
+ if (g_str_equal(wifi_tech_state, "EnabledTechnologies") == TRUE) {
+ netconfig_wifi_update_power_state(TRUE);
- ret = netconfig_wifi_disable_technology();
+ netconfig_wifi_device_picker_service_start();
- if (ret == FALSE) {
- DBG("Fail to disable Wi-Fi technology");
+ return TRUE;
+ }
+
+ g_free(wifi_tech_state);
- netconfig_wifi_set_power_triggering_state(WIFI_NON_OF_TRIGGERING);
+ wifi_tech_state = NULL;
}
- return ret;
+ __netconfig_wifi_try_to_remove_driver();
+
+ return FALSE;
}
-static void __netconfig_wifi_direct_state_cb(int error_code,
- wifi_direct_device_state_e device_state, void *user_data)
+static gboolean __netconfig_wifi_try_to_remove_driver(void)
{
- wifi_direct_unset_device_state_changed_cb();
- wifi_direct_deinitialize();
+ int count = 0;
+ gchar *wifi_tech_state = NULL;
- if (device_state == WIFI_DIRECT_DEVICE_STATE_DEACTIVATED) {
- __netconfig_wifi_try_to_load_driver();
+ netconfig_wifi_device_picker_service_stop();
- return;
- }
+ for (count = 0; count < 3; count++) {
+ __netconfig_wifi_disable_technology();
- /* TODO: error report */
-}
+ wifi_tech_state = netconfig_wifi_get_technology_state();
+ INFO("Wi-Fi technology state: %s", wifi_tech_state);
-static gboolean __netconfig_wifi_direct_power_off(void)
-{
- DBG("Wi-Fi direct is turning off");
+ if (g_str_equal(wifi_tech_state, "EnabledTechnologies") != TRUE) {
+ netconfig_wifi_update_power_state(FALSE);
- if (wifi_direct_initialize() < 0)
- return FALSE;
+ return __netconfig_wifi_remove_driver();
+ }
- if (wifi_direct_set_device_state_changed_cb(
- __netconfig_wifi_direct_state_cb, NULL) < 0)
- return FALSE;
+ g_free(wifi_tech_state);
- if (wifi_direct_deactivate() < 0)
- return FALSE;
+ wifi_tech_state = NULL;
+ }
- return TRUE;
+ return __netconfig_wifi_remove_driver();
}
static void __netconfig_wifi_airplane_mode(keynode_t* node,
return;
DBG("Turning Wi-Fi off");
+
__netconfig_wifi_try_to_remove_driver();
powered_off_by_flightmode = TRUE;
if (powered_off_by_flightmode != TRUE)
return;
- DBG("Turning Wi-Fi on");
-
- if (netconfig_is_wifi_tethering_on() == TRUE) {
- /* TODO: Wi-Fi tethering turns off here */
-
- return;
- }
-
- if (netconfig_is_wifi_direct_on() == TRUE) {
- __netconfig_wifi_direct_power_off();
-
- return;
- }
-
__netconfig_wifi_try_to_load_driver();
powered_off_by_flightmode = FALSE;
vconf_get_int(VCONF_WIFI_LAST_POWER_ON_STATE, &wifi_last_state);
if (wifi_last_state == WIFI_POWER_ON) {
- if (netconfig_is_wifi_tethering_on() != TRUE &&
- netconfig_is_wifi_direct_on() != TRUE) {
- DBG("Turn Wi-Fi on automatically");
+ DBG("Turn Wi-Fi on automatically");
- __netconfig_wifi_try_to_load_driver();
- }
+ __netconfig_wifi_try_to_load_driver();
}
}
gboolean netconfig_iface_wifi_load_driver(NetconfigWifi *wifi, GError **error)
{
- DBG("Check pre-condition to load Wi-Fi driver");
+ DBG("Wi-Fi turned on");
g_return_val_if_fail(wifi != NULL, FALSE);
- if (netconfig_is_wifi_tethering_on() == TRUE) {
- /* TODO: Wi-Fi tethering turns off here */
-
- /* return TRUE; */
- return FALSE;
- }
-
- if (netconfig_is_wifi_direct_on() == TRUE) {
- if (__netconfig_wifi_direct_power_off() == TRUE)
- return TRUE;
- else {
- netconfig_error_wifi_direct_failed(error);
- return FALSE;
- }
- }
-
- DBG("Loading Wi-Fi driver");
-
if (__netconfig_wifi_try_to_load_driver() != TRUE) {
netconfig_error_wifi_driver_failed(error);
+
return FALSE;
}
gboolean netconfig_iface_wifi_remove_driver(NetconfigWifi *wifi, GError **error)
{
- DBG("Removing Wi-Fi driver");
+ DBG("Wi-Fi turned off");
g_return_val_if_fail(wifi != NULL, FALSE);
- if (__netconfig_wifi_try_to_remove_driver() != TRUE)
- {
+ if (__netconfig_wifi_try_to_remove_driver() != TRUE) {
netconfig_error_wifi_driver_failed(error);
+
return FALSE;
}
return TRUE;
}
-
*
*/
+#include <vconf.h>
+#include <vconf-keys.h>
+
#include "log.h"
#include "dbus.h"
+#include "util.h"
#include "wifi-state.h"
+#include "wifi-background-scan.h"
static enum netconfig_wifi_service_state
wifi_service_state = NETCONFIG_WIFI_UNKNOWN;
return __netconfig_wifi_state_get_connman_service_state();
}
+
+gchar *netconfig_wifi_get_technology_state(void)
+{
+ DBusConnection *connection = NULL;
+ DBusMessage *message = NULL;
+ DBusMessageIter args, dict;
+ gboolean wifi_tech_available = FALSE;
+ gboolean wifi_tech_enabled = FALSE;
+
+ connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+ if (connection == NULL) {
+ ERR("Failed to get system bus");
+ return NULL;
+ }
+
+ message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, connection,
+ CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, "GetProperties");
+ if (message == NULL) {
+ ERR("Failed to get Wi-Fi technology state");
+ dbus_connection_unref(connection);
+ return NULL;
+ }
+
+ dbus_message_iter_init(message, &args);
+ dbus_message_iter_recurse(&args, &dict);
+
+ while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+ DBusMessageIter key_iter, sub_iter1, sub_iter2;
+ const char *key = NULL;
+ const char *tech_name = NULL;
+
+ dbus_message_iter_recurse(&dict, &key_iter);
+ dbus_message_iter_get_basic(&key_iter, &key);
+
+ if (strcmp(key, "AvailableTechnologies") == 0 ||
+ strcmp(key, "EnabledTechnologies") == 0) {
+ dbus_message_iter_next(&key_iter);
+ dbus_message_iter_recurse(&key_iter, &sub_iter1);
+
+ if (dbus_message_iter_get_arg_type(&sub_iter1) == DBUS_TYPE_ARRAY)
+ dbus_message_iter_recurse(&sub_iter1, &sub_iter2);
+ else
+ goto next_dict;
+
+ while (dbus_message_iter_get_arg_type(&sub_iter2) == DBUS_TYPE_STRING) {
+ dbus_message_iter_get_basic(&sub_iter2, &tech_name);
+
+ if (tech_name != NULL && strcmp(tech_name, "wifi") == 0) {
+ if (strcmp(key, "AvailableTechnologies") == 0)
+ wifi_tech_available = TRUE;
+ else if (strcmp(key, "EnabledTechnologies") == 0)
+ wifi_tech_enabled = TRUE;
+ }
+
+ dbus_message_iter_next(&sub_iter2);
+ }
+ }
+
+next_dict:
+ dbus_message_iter_next(&dict);
+ }
+
+ dbus_message_unref(message);
+ dbus_connection_unref(connection);
+
+ if (wifi_tech_enabled)
+ return g_strdup("EnabledTechnologies");
+ else if (wifi_tech_available)
+ return g_strdup("AvailableTechnologies");
+ else
+ return NULL;
+}
+
+void netconfig_wifi_update_power_state(gboolean powered)
+{
+ int wifi_state = 0;
+
+ vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
+
+ if (powered == TRUE) {
+ if (wifi_state == VCONFKEY_WIFI_OFF &&
+ netconfig_is_wifi_direct_on() != TRUE &&
+ netconfig_is_wifi_tethering_on() != TRUE) {
+ DBG("Wi-Fi successfully turned on");
+
+ vconf_set_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_NOT_CONNECTED);
+
+ vconf_set_int(VCONF_WIFI_LAST_POWER_ON_STATE, WIFI_POWER_ON);
+
+ vconf_set_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_UNCONNECTED);
+
+ netconfig_wifi_bgscan_start();
+ }
+ } else {
+ netconfig_wifi_bgscan_stop();
+
+ if (wifi_state != VCONFKEY_WIFI_OFF) {
+ DBG("Wi-Fi successfully turned off");
+
+ vconf_set_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_OFF);
+
+ vconf_set_int(VCONF_WIFI_LAST_POWER_ON_STATE, WIFI_POWER_OFF);
+
+ vconf_set_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_OFF);
+ }
+ }
+}