2 * Network Configuration Module
4 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
27 #include "netsupplicant.h"
28 #include "wifi-firmware.h"
29 #include "network-statistics.h"
32 #define WLAN_P2P_IFACE_NAME "p2p0"
34 static int __netconfig_sta_firmware_start(void)
38 rv = netconfig_interface_up(WIFI_IFNAME);
42 INFO("Successfully loaded wireless device driver");
46 static int __netconfig_sta_firmware_stop(void)
51 /* Update statistics before driver remove */
52 netconfig_wifi_statistics_update_powered_off();
54 rv = netconfig_interface_down(WIFI_IFNAME);
58 INFO("Successfully removed wireless device driver");
63 static int __netconfig_p2p_firmware_start(void)
66 #if defined TIZEN_P2P_ENABLE
68 rv = netconfig_interface_up(WLAN_P2P_IFACE_NAME);
72 INFO("Successfully up p2p device driver");
75 INFO("P2P Device is not supported");
81 static int __netconfig_p2p_firmware_stop(void)
84 #if defined TIZEN_P2P_ENABLE
86 rv = netconfig_interface_down(WLAN_P2P_IFACE_NAME);
90 INFO("Successfully down p2p device driver");
93 INFO("P2P Device is not supported");
98 static int __netconfig_wifi_firmware_start(
99 enum netconfig_wifi_firmware type)
103 if (netconfig_emulator_is_emulated() == TRUE)
107 case NETCONFIG_WIFI_STA:
108 return __netconfig_sta_firmware_start();
109 case NETCONFIG_WIFI_P2P:
110 return __netconfig_p2p_firmware_start();
118 static int __netconfig_wifi_firmware_stop(enum netconfig_wifi_firmware type)
120 if (netconfig_emulator_is_emulated() == TRUE)
124 case NETCONFIG_WIFI_STA:
125 return __netconfig_sta_firmware_stop();
126 case NETCONFIG_WIFI_P2P:
127 return __netconfig_p2p_firmware_stop();
135 int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable)
138 static enum netconfig_wifi_firmware current_driver = NETCONFIG_WIFI_OFF;
139 enum netconfig_wifi_firmware alias = type;
141 #if defined WLAN_CONCURRENT_MODE
144 if (type == NETCONFIG_WIFI_P2P)
145 alias = NETCONFIG_WIFI_STA;
148 INFO("Wi-Fi current firmware %d (type: %d %s)", current_driver, type,
149 enable == TRUE ? "enable" : "disable");
151 if (enable == FALSE) {
152 if (current_driver == NETCONFIG_WIFI_OFF) {
154 } else if (current_driver == alias) {
156 #if defined WLAN_CONCURRENT_MODE
157 vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
159 if (flight_mode == 0 && type == NETCONFIG_WIFI_STA &&
160 netconfig_is_wifi_direct_on() == TRUE) {
161 netconfig_interface_down(WIFI_IFNAME);
166 if (type == NETCONFIG_WIFI_P2P &&
167 netconfig_wifi_state_get_technology_state() >
168 NETCONFIG_WIFI_TECH_OFF) {
169 netconfig_interface_down(WLAN_P2P_IFACE_NAME);
174 err = __netconfig_wifi_firmware_stop(type);
175 if (err < 0 && err != -EALREADY)
178 current_driver = NETCONFIG_WIFI_OFF;
186 if (current_driver > NETCONFIG_WIFI_OFF) {
187 if (current_driver == alias) {
189 #if defined WLAN_CONCURRENT_MODE
190 if (type == NETCONFIG_WIFI_STA)
191 netconfig_interface_up(WIFI_IFNAME);
192 #if defined TIZEN_P2P_ENABLE
193 else if (type == NETCONFIG_WIFI_P2P)
194 netconfig_interface_up(WLAN_P2P_IFACE_NAME);
203 err = __netconfig_wifi_firmware_start(type);
205 INFO("Failed to start the Firmware");
207 current_driver = alias;
212 gboolean netconfig_iface_wifi_start(
213 NetconfigWifi *wifi, gchar *device, GError **error)
217 g_return_val_if_fail(wifi != NULL, FALSE);
219 INFO("Wi-Fi firmware start %s", device != NULL ? device : "null");
221 if (g_strcmp0("p2p", device) == 0)
222 err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, TRUE);
223 else if (g_strcmp0("softap", device) == 0)
224 err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, TRUE);
229 if (err == -EALREADY)
230 netconfig_error_already_exists(error);
232 netconfig_error_wifi_driver_failed(error);
240 gboolean netconfig_iface_wifi_stop(
241 NetconfigWifi *wifi, gchar *device, GError **error)
245 g_return_val_if_fail(wifi != NULL, FALSE);
247 INFO("Wi-Fi firmware stop %s", device != NULL ? device : "null");
249 if (g_strcmp0("p2p", device) == 0)
250 err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, FALSE);
251 else if (g_strcmp0("softap", device) == 0)
252 err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, FALSE);
257 if (err == -EALREADY)
258 netconfig_error_already_exists(error);
260 netconfig_error_wifi_driver_failed(error);