/*
* Network Configuration Module
*
- * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
*/
-
#include <errno.h>
+#include <vconf.h>
+#include <vconf-keys.h>
+#include <stdio.h>
+#include <fcntl.h>
+
#include "log.h"
#include "util.h"
#include "netdbus.h"
#include "wifi-firmware.h"
#include "network-statistics.h"
+#define WLAN_DRIVER_SCRIPT "/usr/bin/wlan.sh"
+#define WLAN_IFACE_NAME "wlan0"
-#define WLAN_P2P_IFACE_NAME "p2p0"
+#define WLAN_P2P_IFACE_NAME_TV "p2p0"
+#define WLAN_P2P_IFACE_NAME_COMMON "wlan0"
+#define WLAN_P2P_IFACE_NAME ((TIZEN_TV) ? (WLAN_P2P_IFACE_NAME_TV) : (WLAN_P2P_IFACE_NAME_COMMON))
+#define QUAD_CPUS_COUNT 4
+#define TEMP_BUFFER_LEN 100
+#define WIFI_MAC_ADD_PATH "/sys/class/net/wlan0/address"
static int __netconfig_sta_firmware_start(void)
{
int rv = 0;
+ const char *path = WLAN_DRIVER_SCRIPT;
+ char *const args[] = { "/usr/bin/wlan.sh", "start", NULL };
+ char *const envs[] = { NULL };
- rv = netconfig_interface_up(WIFI_IFNAME);
- if (!rv)
+ rv = netconfig_execute_file(path, args, envs);
+ if (rv < 0)
return -EIO;
- INFO("Successfully loaded wireless device driver");
+ rv = netconfig_interface_up(WLAN_IFACE_NAME);
+ if (rv != TRUE)
+ return -EIO;
+
+ DBG("Successfully loaded wireless device driver");
return 0;
}
static int __netconfig_sta_firmware_stop(void)
{
-
int rv = 0;
+ const char *path = WLAN_DRIVER_SCRIPT;
+ char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL };
+ char *const envs[] = { NULL };
/* Update statistics before driver remove */
netconfig_wifi_statistics_update_powered_off();
- rv = netconfig_interface_down(WIFI_IFNAME);
- if (!rv)
+ rv = netconfig_interface_down(WLAN_IFACE_NAME);
+ if (rv != TRUE)
return -EIO;
- INFO("Successfully removed wireless device driver");
+ rv = netconfig_execute_file(path, args, envs);
+ if (rv < 0)
+ return -EIO;
+
+ DBG("Successfully removed wireless device driver");
return 0;
}
-
static int __netconfig_p2p_firmware_start(void)
{
+ if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT))
+ return -ENODEV;
-#if defined TIZEN_P2P_ENABLE
int rv = 0;
- rv = netconfig_interface_up(WLAN_P2P_IFACE_NAME);
- if (!rv)
+ const char *path = WLAN_DRIVER_SCRIPT;
+ char *const args[] = { "/usr/bin/wlan.sh", "p2p", NULL };
+ char *const envs[] = { NULL };
+
+ rv = netconfig_execute_file(path, args, envs);
+ if (rv < 0)
return -EIO;
- INFO("Successfully up p2p device driver");
- return 0;
-#else
- INFO("P2P Device is not supported");
- return -ENODEV;
+#if defined TIZEN_WLAN_USE_P2P_INTERFACE
+ rv = netconfig_interface_up(WLAN_P2P_IFACE_NAME);
+ if (rv != TRUE)
+ return -EIO;
#endif
+ DBG("Successfully loaded p2p device driver");
+ return 0;
}
static int __netconfig_p2p_firmware_stop(void)
{
+ if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT))
+ return -ENODEV;
-#if defined TIZEN_P2P_ENABLE
int rv = 0;
- rv = netconfig_interface_down(WLAN_P2P_IFACE_NAME);
- if (!rv)
+ const char *path = WLAN_DRIVER_SCRIPT;
+ char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL };
+ char *const envs[] = { NULL };
+
+ rv = netconfig_interface_down(WLAN_IFACE_NAME);
+ if (rv != TRUE)
return -EIO;
- INFO("Successfully down p2p device driver");
- return 0;
-#else
- INFO("P2P Device is not supported");
- return -ENODEV;
-#endif
+ rv = netconfig_execute_file(path, args, envs);
+ if (rv < 0)
+ return -EIO;
+ DBG("Successfully removed p2p device driver");
+ return 0;
}
-static int __netconfig_wifi_firmware_start(
- enum netconfig_wifi_firmware type)
+
+static int __netconfig_softap_firmware_start(void)
{
+ if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_TETHERING))
+ return -ENODEV;
- INFO(" %d",type);
- if (netconfig_emulator_is_emulated() == TRUE)
+ int rv = 0;
+ const char *path = WLAN_DRIVER_SCRIPT;
+ char *const args[] = { "/usr/bin/wlan.sh", "softap", NULL };
+ char *const envs[] = { NULL };
+
+ rv = netconfig_execute_file(path, args, envs);
+ if (rv < 0)
+ return -EIO;
+
+ if (netconfig_interface_up(WLAN_IFACE_NAME) == FALSE)
+ return -EIO;
+
+ DBG("Successfully loaded softap device driver");
+ return 0;
+}
+
+static int __netconfig_softap_firmware_stop(void)
+{
+ if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_TETHERING))
+ return -ENODEV;
+
+ int rv = 0;
+ const char *path = WLAN_DRIVER_SCRIPT;
+ char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL };
+ char *const envs[] = { NULL };
+
+ rv = netconfig_interface_down(WLAN_IFACE_NAME);
+ if (rv != TRUE)
+ return -EIO;
+
+ rv = netconfig_execute_file(path, args, envs);
+ if (rv < 0)
+ return -EIO;
+
+ DBG("Successfully removed softap device driver");
+ return 0;
+}
+
+static int __netconfig_wifi_firmware_start(enum netconfig_wifi_firmware type)
+{
+ if (emulator_is_emulated() == TRUE)
return -EIO;
switch (type) {
return __netconfig_sta_firmware_start();
case NETCONFIG_WIFI_P2P:
return __netconfig_p2p_firmware_start();
+ case NETCONFIG_WIFI_SOFTAP:
+ return __netconfig_softap_firmware_start();
default:
break;
}
static int __netconfig_wifi_firmware_stop(enum netconfig_wifi_firmware type)
{
- if (netconfig_emulator_is_emulated() == TRUE)
+ if (emulator_is_emulated() == TRUE)
return -EIO;
switch (type) {
return __netconfig_sta_firmware_stop();
case NETCONFIG_WIFI_P2P:
return __netconfig_p2p_firmware_stop();
+ case NETCONFIG_WIFI_SOFTAP:
+ return __netconfig_softap_firmware_stop();
default:
break;
}
return -ENXIO;
}
+static int __netconfig_set_rps_cpus(void)
+{
+ int fd, i;
+ ssize_t count;
+ char t_buf[TEMP_BUFFER_LEN];
+ char r_buf[TEMP_BUFFER_LEN];
+
+ if (access(WIFI_MAC_ADD_PATH, F_OK) != 0) {
+ DBG("WiFi driver is not loaded... ");
+ return -1;
+ } else {
+ DBG("WiFi driver loaded... ");
+ }
+
+ for (i = 0; i < QUAD_CPUS_COUNT; i++) {
+ snprintf(t_buf, TEMP_BUFFER_LEN, "/sys/class/net/wlan0/queues/rx-%d/rps_cpus", i);
+ DBG("Command : [%s]", t_buf);
+ fd = open(t_buf, O_RDWR | O_CLOEXEC);
+
+ if (fd < 0) {
+ DBG("failed to open rps file");
+ return -1;
+ } else {
+ count = read(fd, r_buf, 1);
+
+ if (count < 0) {
+ DBG("read failed");
+ close(fd);
+ return -1;
+ } else {
+ DBG("read size = %d", count);
+ }
+
+ if (r_buf[0] == 'e') {
+ close(fd);
+ continue;
+ } else {
+ DBG("e is already written");
+ }
+
+ if (lseek(fd, 0, SEEK_SET) < 0) {
+ DBG("lseek failed");
+ close(fd);
+ return -1;
+ }
+
+ count = write(fd, "e", 1);
+
+ if (count < 0) {
+ DBG("write failed");
+ close(fd);
+ return -1;
+ } else {
+ DBG("write size = %d", count);
+ }
+
+ close(fd);
+ }
+ }
+
+ return 0;
+}
+
int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable)
{
int err;
static enum netconfig_wifi_firmware current_driver = NETCONFIG_WIFI_OFF;
enum netconfig_wifi_firmware alias = type;
-#if defined WLAN_CONCURRENT_MODE
- int flight_mode = 0;
-
- if (type == NETCONFIG_WIFI_P2P)
- alias = NETCONFIG_WIFI_STA;
-#endif
-
- INFO("Wi-Fi current firmware %d (type: %d %s)", current_driver, type,
+ DBG("Wi-Fi current firmware %d (type: %d %s)", current_driver, type,
enable == TRUE ? "enable" : "disable");
if (enable == FALSE) {
return -EALREADY;
} else if (current_driver == alias) {
-#if defined WLAN_CONCURRENT_MODE
- vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
-
- if (flight_mode == 0 && type == NETCONFIG_WIFI_STA &&
- netconfig_is_wifi_direct_on() == TRUE) {
- netconfig_interface_down(WIFI_IFNAME);
-
- return -EALREADY;
- }
-
- if (type == NETCONFIG_WIFI_P2P &&
- netconfig_wifi_state_get_technology_state() >
- NETCONFIG_WIFI_TECH_OFF) {
- netconfig_interface_down(WLAN_P2P_IFACE_NAME);
-
- return -EALREADY;
- }
-#endif
err = __netconfig_wifi_firmware_stop(type);
if (err < 0 && err != -EALREADY)
return err;
}
if (current_driver > NETCONFIG_WIFI_OFF) {
- if (current_driver == alias) {
-
-#if defined WLAN_CONCURRENT_MODE
- if (type == NETCONFIG_WIFI_STA)
- netconfig_interface_up(WIFI_IFNAME);
-#if defined TIZEN_P2P_ENABLE
- else if (type == NETCONFIG_WIFI_P2P)
- netconfig_interface_up(WLAN_P2P_IFACE_NAME);
-#endif
-#endif
+ if (current_driver == alias)
return -EALREADY;
- }
return -EIO;
}
err = __netconfig_wifi_firmware_start(type);
if (err < 0)
- INFO("Failed to start the Firmware");
+ DBG("Failed to execute script file");
else
current_driver = alias;
+ if (__netconfig_set_rps_cpus() < 0)
+ DBG("Failed to set rps_cpus");
+
return err;
}
-gboolean netconfig_iface_wifi_start(
- NetconfigWifi *wifi, gchar *device, GError **error)
+gboolean handle_start(WifiFirmware *firmware, GDBusMethodInvocation *context, const gchar *device)
{
int err;
- g_return_val_if_fail(wifi != NULL, FALSE);
+ g_return_val_if_fail(firmware != NULL, TRUE);
- INFO("Wi-Fi firmware start %s", device != NULL ? device : "null");
+ DBG("Wi-Fi firmware start %s", device != NULL ? device : "null");
if (g_strcmp0("p2p", device) == 0)
err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, TRUE);
if (err < 0) {
if (err == -EALREADY)
- netconfig_error_already_exists(error);
- else
- netconfig_error_wifi_driver_failed(error);
-
- return FALSE;
+ netconfig_error_already_exists(context);
+ else if (g_strcmp0("softap", device) == 0 && err == -EIO && netconfig_is_wifi_direct_on() == FALSE) {
+ if (netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, FALSE) == 0 && netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, TRUE) == 0) {
+ wifi_firmware_complete_start(firmware, context);
+ return TRUE;
+ } else
+ netconfig_error_wifi_driver_failed(context);
+ } else
+ netconfig_error_wifi_driver_failed(context);
+
+ return TRUE;
}
+ wifi_firmware_complete_start(firmware, context);
return TRUE;
}
-gboolean netconfig_iface_wifi_stop(
- NetconfigWifi *wifi, gchar *device, GError **error)
+gboolean handle_stop(WifiFirmware *firmware, GDBusMethodInvocation *context, const gchar *device)
{
int err;
- g_return_val_if_fail(wifi != NULL, FALSE);
+ g_return_val_if_fail(firmware != NULL, TRUE);
- INFO("Wi-Fi firmware stop %s", device != NULL ? device : "null");
+ DBG("Wi-Fi firmware stop %s", device != NULL ? device : "null");
if (g_strcmp0("p2p", device) == 0)
err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, FALSE);
if (err < 0) {
if (err == -EALREADY)
- netconfig_error_already_exists(error);
+ netconfig_error_already_exists(context);
else
- netconfig_error_wifi_driver_failed(error);
+ netconfig_error_wifi_driver_failed(context);
- return FALSE;
+ return TRUE;
}
+ wifi_firmware_complete_stop(firmware, context);
return TRUE;
}