src/utils/util.c
src/utils/emulator.c
src/utils/mdm-private.c
+ src/wifi-firmware.c
)
IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
+IF(TIZEN_P2P_ENABLE)
+ ADD_DEFINITIONS(-DTIZEN_P2P_ENABLE)
+ENDIF(TIZEN_P2P_ENABLE)
+
INCLUDE(FindPkgConfig)
PKG_CHECK_MODULES(pkgs REQUIRED
glib-2.0
/*
* 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 "glib.h"
-G_BEGIN_DECLS
+#define NETCONFIG_ERROR_QUARK (netconfig_error_quark())
+#define NETCONFIG_CONNMAN_AGENT_ERROR_QUARK (netconfig_connman_agent_error_quark())
-typedef enum {
- NETCONFIG_NO_ERROR = 0x00,
- NETCONFIG_ERROR_INTERNAL = 0x01,
- NETCONFIG_ERROR_NO_SERVICE = 0x02,
- NETCONFIG_ERROR_TRASPORT = 0x03,
- NETCONFIG_ERROR_NO_PROFILE = 0x04,
- NETCONFIG_ERROR_WRONG_PROFILE = 0x05,
- NETCONFIG_ERROR_WIFI_LOAD_INPROGRESS = 0x06,
- NETCONFIG_ERROR_WIFI_DRIVER_FAILURE = 0x07,
- NETCONFIG_ERROR_SECURITY_RESTRICTED = 0x08,
- NETCONFIG_ERROR_FAILED_GET_IMSI = 0x09,
- NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH = 0x0A,
- NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM = 0x0B,
- NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_WRONG_DATA = 0x0C,
- NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_DELAY = 0x0D,
- NETCONFIG_ERROR_MAX = 0x0E,
- NETCONFIG_ERROR_INVALID_PARAMETER = 0x0F,
- NETCONFIG_ERROR_PERMISSION_DENIED = 0x10,
-} NETCONFIG_ERROR;
-
-GQuark netconfig_error_quark(void);
-
-#define NETCONFIG_ERROR_QUARK (netconfig_error_quark())
-
-G_END_DECLS
-
-#ifdef __cplusplus
-}
-#endif
-
-void netconfig_error_wifi_load_inprogress(GError **error);
+void netconfig_error_inprogress(GError **error);
+void netconfig_error_already_exists(GError **error);
+void netconfig_error_invalid_parameter(GError **error);
+void netconfig_error_permission_denied(GError **error);
void netconfig_error_wifi_driver_failed(GError **error);
void netconfig_error_security_restricted(GError **error);
void netconfig_error_wifi_direct_failed(GError **error);
void netconfig_add_wifi_found_notification(void);
void netconfig_del_wifi_found_notification(void);
+gboolean netconfig_interface_up(const char *ifname);
+gboolean netconfig_interface_down(const char *ifname);
+
#ifdef __cplusplus
}
--- /dev/null
+/*
+ * Network Configuration Module
+ *
+ * Copyright (c) 2012-2013 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+#ifndef __NETCONFIG_WIFI_FIRMWARE_H__
+#define __NETCONFIG_WIFI_FIRMWARE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib.h>
+
+enum netconfig_wifi_firmware {
+ NETCONFIG_WIFI_OFF = 0x00,
+ NETCONFIG_WIFI_STA = 0x01,
+ NETCONFIG_WIFI_P2P = 0x02,
+ NETCONFIG_WIFI_SOFTAP = 0x03,
+};
+
+int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable);
+
+gboolean netconfig_iface_wifi_start(
+ NetconfigWifi *wifi, gchar *device, GError **error);
+gboolean netconfig_iface_wifi_stop(
+ NetconfigWifi *wifi, gchar *device, GError **error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __NETCONFIG_WIFI_FIRMWARE_H__ */
<arg type="a{sv}" name="OutFields" direction="out"/>
</method>
</interface>
+ <interface name="net.netconfig.wifi.Firmware">
+ <method name="Start">
+ <arg type="s" name="Device" direction="in"/>
+ </method>
+ <method name="Stop">
+ <arg type="s" name="Device" direction="in"/>
+ </method>
+ </interface>
</node>
Name: net-config
Summary: TIZEN Network Configuration Module
-Version: 0.1.90_33
+Version: 0.1.90_34
Release: 1
Group: System/Network
License: Apache-2.0
%build
-%cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
+%cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \
+ -DTIZEN_P2P_ENABLE=1 \
make %{?_smp_mflags}
/*
* 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 <glib.h>
+#include "netdbus.h"
#include "neterror.h"
#include "netconfig.h"
+typedef enum {
+ NETCONFIG_NO_ERROR = 0x00,
+ NETCONFIG_ERROR_INTERNAL = 0x01,
+ NETCONFIG_ERROR_NO_SERVICE = 0x02,
+ NETCONFIG_ERROR_TRASPORT = 0x03,
+ NETCONFIG_ERROR_NO_PROFILE = 0x04,
+ NETCONFIG_ERROR_WRONG_PROFILE = 0x05,
+ NETCONFIG_ERROR_INPROGRESS = 0x06,
+ NETCONFIG_ERROR_ALREADYEXISTS = 0x07,
+ NETCONFIG_ERROR_INVALID_PARAMETER = 0x08,
+ NETCONFIG_ERROR_PERMISSION_DENIED = 0x09,
+ NETCONFIG_ERROR_WIFI_DRIVER_FAILURE = 0x0A,
+ NETCONFIG_ERROR_FAILED_GET_IMSI = 0x0B,
+ NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH = 0x0C,
+ NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM = 0x0D,
+ NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_WRONG_DATA = 0x0E,
+ NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_DELAY = 0x0F,
+ NETCONFIG_ERROR_SECURITY_RESTRICTED = 0x10,
+ NETCONFIG_ERROR_WIFI_LOAD_INPROGRESS = 0x11,
+ NETCONFIG_ERROR_MAX = 0x12,
+
+} NETCONFIG_ERROR;
+
#define NETCONFIG_ERROR_INTERFACE NETCONFIG_SERVICE ".Error"
+#define CONNMAN_AGENT_ERROR_INTERFACE "net.connman.Agent.Error"
GQuark netconfig_error_quark(void)
{
return quark;
}
+GQuark netconfig_connman_agent_error_quark(void)
+{
+ static GQuark quark = 0;
+
+ if (!quark)
+ quark = g_quark_from_static_string("netconfig_connman_agent_error");
+
+ return quark;
+}
void netconfig_error_wifi_load_inprogress(GError **error)
{
g_set_error(error, netconfig_error_quark(), NETCONFIG_ERROR_WIFI_LOAD_INPROGRESS,
NETCONFIG_ERROR_INTERFACE ".WifiLoadInprogress");
}
-void netconfig_error_wifi_driver_failed(GError **error)
+
+
+void netconfig_error_inprogress(GError **error)
{
- g_set_error(error, netconfig_error_quark(), NETCONFIG_ERROR_WIFI_DRIVER_FAILURE,
- NETCONFIG_ERROR_INTERFACE ".WifiDriverFailed");
+ g_set_error(error, netconfig_error_quark(),
+ NETCONFIG_ERROR_INPROGRESS,
+ NETCONFIG_ERROR_INTERFACE ".InProgress");
+}
+
+void netconfig_error_already_exists(GError **error)
+{
+ g_set_error(error, netconfig_error_quark(),
+ NETCONFIG_ERROR_ALREADYEXISTS,
+ NETCONFIG_ERROR_INTERFACE ".AlreadyExists");
}
+void netconfig_error_invalid_parameter(GError **error)
+{
+ g_set_error(error, netconfig_error_quark(),
+ NETCONFIG_ERROR_INVALID_PARAMETER,
+ NETCONFIG_ERROR_INTERFACE ".InvalidParameter");
+}
+
+void netconfig_error_permission_denied(GError **error)
+{
+ g_set_error(error, netconfig_error_quark(),
+ NETCONFIG_ERROR_PERMISSION_DENIED,
+ NETCONFIG_ERROR_INTERFACE ".PermissionDenied");
+}
+
+
void netconfig_error_security_restricted(GError **error)
{
g_set_error(error, netconfig_error_quark(), NETCONFIG_ERROR_SECURITY_RESTRICTED,
NETCONFIG_ERROR_INTERFACE ".SecurityRestricted");
}
+void netconfig_error_wifi_driver_failed(GError **error)
+{
+ g_set_error(error, netconfig_error_quark(),
+ NETCONFIG_ERROR_WIFI_DRIVER_FAILURE,
+ NETCONFIG_ERROR_INTERFACE ".WifiDriverFailed");
+}
+
void netconfig_error_wifi_direct_failed(GError **error)
{
- g_set_error(error, netconfig_error_quark(), NETCONFIG_ERROR_WIFI_DRIVER_FAILURE,
+ g_set_error(error, netconfig_error_quark(),
+ NETCONFIG_ERROR_WIFI_DRIVER_FAILURE,
NETCONFIG_ERROR_INTERFACE ".WifiDirectFailed");
}
void netconfig_error_fail_get_imsi(GError **error)
{
- g_set_error(error, netconfig_error_quark(), NETCONFIG_ERROR_FAILED_GET_IMSI,
+ g_set_error(error, netconfig_error_quark(),
+ NETCONFIG_ERROR_FAILED_GET_IMSI,
NETCONFIG_ERROR_INTERFACE".FailGetSimImsi");
}
void netconfig_error_fail_req_sim_auth(GError **error)
{
- g_set_error(error, netconfig_error_quark(), NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH,
+ g_set_error(error, netconfig_error_quark(),
+ NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH,
NETCONFIG_ERROR_INTERFACE".FailReqSimAuth");
}
void netconfig_error_fail_req_sim_auth_wrong_param(GError **error)
{
- g_set_error(error, netconfig_error_quark(), NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM,
+ g_set_error(error, netconfig_error_quark(),
+ NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM,
NETCONFIG_ERROR_INTERFACE".FailReqSimAuthWrongParam");
}
void netconfig_error_fail_get_sim_auth_wrong_data(GError **error)
{
- g_set_error(error, netconfig_error_quark(), NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_WRONG_DATA,
+ g_set_error(error, netconfig_error_quark(),
+ NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_WRONG_DATA,
NETCONFIG_ERROR_INTERFACE".FailGetSimAuthWrongData");
}
void netconfig_error_fail_get_sim_auth_delay(GError **error)
{
- g_set_error(error, netconfig_error_quark(), NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_DELAY,
+ g_set_error(error, netconfig_error_quark(),
+ NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_DELAY,
NETCONFIG_ERROR_INTERFACE".FailGetSimAuthDelay");
}
-void netconfig_error_invalid_parameter(GError **error)
-{
- g_set_error(error, netconfig_error_quark(), NETCONFIG_ERROR_INVALID_PARAMETER,
- NETCONFIG_ERROR_INTERFACE ".InvalidParameter");
-}
-void netconfig_error_permission_denied(GError **error)
+void netconfig_error_init(void)
{
- g_set_error(error, netconfig_error_quark(), NETCONFIG_ERROR_PERMISSION_DENIED,
- NETCONFIG_ERROR_INTERFACE ".PermissionDenied");
+ /* TODO: register GError domain to make error_name */
+ /*
+ dbus_g_error_domain_register(NETCONFIG_ERROR_QUARK,
+ NETCONFIG_ERROR_INTERFACE,
+ code_num_netconfig);
+
+ dbus_g_error_domain_register(NETCONFIG_CONNMAN_AGENT_ERROR_QUARK,
+ CONNMAN_AGENT_ERROR_INTERFACE,
+ code_num_connman);
+ */
}
close(ctl_sk);
}
}
+
+gboolean netconfig_interface_up(const char *ifname)
+{
+ int fd;
+ struct ifreq ifr;
+
+ fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+ if (fd < 0)
+ return FALSE;
+
+ memset(&ifr, 0, sizeof(ifr));
+ g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+
+ if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
+ close(fd);
+ return FALSE;
+ }
+
+ ifr.ifr_flags |= (IFF_UP | IFF_DYNAMIC);
+ if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
+ close(fd);
+ return FALSE;
+ }
+
+ close(fd);
+
+ INFO("Successfully activated wireless interface");
+ return TRUE;
+}
+
+gboolean netconfig_interface_down(const char *ifname)
+{
+ int fd;
+ struct ifreq ifr;
+
+ fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+ if (fd < 0)
+ return FALSE;
+
+ memset(&ifr, 0, sizeof(ifr));
+ g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+
+ if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
+ close(fd);
+ return FALSE;
+ }
+
+ ifr.ifr_flags = (ifr.ifr_flags & ~IFF_UP) | IFF_DYNAMIC;
+ if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
+ close(fd);
+ return FALSE;
+ }
+
+ close(fd);
+
+ DBG("Successfully de-activated wireless interface");
+ return TRUE;
+}
+
--- /dev/null
+/*
+ * Network Configuration Module
+ *
+ * Copyright (c) 2012-2013 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+#include <errno.h>
+#include "log.h"
+#include "util.h"
+#include "netdbus.h"
+#include "emulator.h"
+#include "neterror.h"
+#include "netsupplicant.h"
+#include "wifi-firmware.h"
+#include "network-statistics.h"
+
+
+#define WLAN_P2P_IFACE_NAME "p2p0"
+
+static int __netconfig_sta_firmware_start(void)
+{
+ int rv = 0;
+
+ rv = netconfig_interface_up(WIFI_IFNAME);
+ if (!rv)
+ return -EIO;
+
+ INFO("Successfully loaded wireless device driver");
+ return 0;
+}
+
+static int __netconfig_sta_firmware_stop(void)
+{
+
+ int rv = 0;
+
+ /* Update statistics before driver remove */
+ netconfig_wifi_statistics_update_powered_off();
+
+ rv = netconfig_interface_down(WIFI_IFNAME);
+ if (!rv)
+ return -EIO;
+
+ INFO("Successfully removed wireless device driver");
+ return 0;
+}
+
+
+static int __netconfig_p2p_firmware_start(void)
+{
+
+#if defined TIZEN_P2P_ENABLE
+ int rv = 0;
+ rv = netconfig_interface_up(WLAN_P2P_IFACE_NAME);
+ if (!rv)
+ return -EIO;
+
+ INFO("Successfully up p2p device driver");
+ return 0;
+#else
+ INFO("P2P Device is not supported");
+ return -ENODEV;
+#endif
+
+}
+
+static int __netconfig_p2p_firmware_stop(void)
+{
+
+#if defined TIZEN_P2P_ENABLE
+ int rv = 0;
+ rv = netconfig_interface_down(WLAN_P2P_IFACE_NAME);
+ if (!rv)
+ return -EIO;
+
+ INFO("Successfully down p2p device driver");
+ return 0;
+#else
+ INFO("P2P Device is not supported");
+ return -ENODEV;
+#endif
+
+}
+static int __netconfig_wifi_firmware_start(
+ enum netconfig_wifi_firmware type)
+{
+
+ INFO(" %d",type);
+ if (netconfig_emulator_is_emulated() == TRUE)
+ return -EIO;
+
+ switch (type) {
+ case NETCONFIG_WIFI_STA:
+ return __netconfig_sta_firmware_start();
+ case NETCONFIG_WIFI_P2P:
+ return __netconfig_p2p_firmware_start();
+ default:
+ break;
+ }
+
+ return -ENXIO;
+}
+
+static int __netconfig_wifi_firmware_stop(enum netconfig_wifi_firmware type)
+{
+ if (netconfig_emulator_is_emulated() == TRUE)
+ return -EIO;
+
+ switch (type) {
+ case NETCONFIG_WIFI_STA:
+ return __netconfig_sta_firmware_stop();
+ case NETCONFIG_WIFI_P2P:
+ return __netconfig_p2p_firmware_stop();
+ default:
+ break;
+ }
+
+ return -ENXIO;
+}
+
+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,
+ enable == TRUE ? "enable" : "disable");
+
+ if (enable == FALSE) {
+ if (current_driver == NETCONFIG_WIFI_OFF) {
+ 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;
+
+ current_driver = NETCONFIG_WIFI_OFF;
+
+ return err;
+ }
+
+ return -EIO;
+ }
+
+ 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
+ return -EALREADY;
+ }
+
+ return -EIO;
+ }
+
+ err = __netconfig_wifi_firmware_start(type);
+ if (err < 0)
+ INFO("Failed to start the Firmware");
+ else
+ current_driver = alias;
+
+ return err;
+}
+
+gboolean netconfig_iface_wifi_start(
+ NetconfigWifi *wifi, gchar *device, GError **error)
+{
+ int err;
+
+ g_return_val_if_fail(wifi != NULL, FALSE);
+
+ INFO("Wi-Fi firmware start %s", device != NULL ? device : "null");
+
+ if (g_strcmp0("p2p", device) == 0)
+ err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, TRUE);
+ else if (g_strcmp0("softap", device) == 0)
+ err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, TRUE);
+ else
+ err = -EINVAL;
+
+ if (err < 0) {
+ if (err == -EALREADY)
+ netconfig_error_already_exists(error);
+ else
+ netconfig_error_wifi_driver_failed(error);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+gboolean netconfig_iface_wifi_stop(
+ NetconfigWifi *wifi, gchar *device, GError **error)
+{
+ int err;
+
+ g_return_val_if_fail(wifi != NULL, FALSE);
+
+ INFO("Wi-Fi firmware stop %s", device != NULL ? device : "null");
+
+ if (g_strcmp0("p2p", device) == 0)
+ err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, FALSE);
+ else if (g_strcmp0("softap", device) == 0)
+ err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, FALSE);
+ else
+ err = -EINVAL;
+
+ if (err < 0) {
+ if (err == -EALREADY)
+ netconfig_error_already_exists(error);
+ else
+ netconfig_error_wifi_driver_failed(error);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
*
*/
+
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include "mdm-private.h"
#include "wifi-agent.h"
#include "wifi-eap-config.h"
+#include "wifi-firmware.h"
#define WLAN_DRIVER_SCRIPT "/usr/bin/wlan.sh"
#include "wifi-eap-config.h"
#include "wifi-background-scan.h"
#include "wifi-agent.h"
+#include "wifi-firmware.h"
#include "netconfig-iface-wifi-glue.h"