2 * Network Configuration Module
4 * Copyright (c) 2000 - 2012 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.
22 #include <vconf-keys.h>
29 #include "netsupplicant.h"
30 #include "wifi-firmware.h"
31 #include "network-statistics.h"
32 #if defined WLAN_CHECK_POWERSAVE
33 #include "wifi-powersave.h"
36 #define WLAN_DRIVER_SCRIPT "/usr/bin/wlan.sh"
37 #define WLAN_IFACE_NAME "wlan0"
38 #define WLAN_P2P_IFACE_NAME "p2p0"
40 static int __netconfig_sta_firmware_start(void)
43 const char *path = WLAN_DRIVER_SCRIPT;
44 char *const args[] = { "/usr/bin/wlan.sh", "start", NULL };
45 char *const envs[] = { NULL };
47 rv = netconfig_execute_file(path, args, envs);
51 rv = netconfig_interface_up(WLAN_IFACE_NAME);
55 DBG("Successfully loaded wireless device driver");
59 static int __netconfig_sta_firmware_stop(void)
62 const char *path = WLAN_DRIVER_SCRIPT;
63 char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL };
64 char *const envs[] = { NULL };
66 /* Update statistics before driver remove */
67 netconfig_wifi_statistics_update_powered_off();
69 rv = netconfig_interface_down(WLAN_IFACE_NAME);
73 rv = netconfig_execute_file(path, args, envs);
77 DBG("Successfully removed wireless device driver");
81 static int __netconfig_p2p_firmware_start(void)
83 #if defined TIZEN_P2P_ENABLE
85 const char *path = WLAN_DRIVER_SCRIPT;
86 char *const args[] = { "/usr/bin/wlan.sh", "p2p", NULL };
87 char *const envs[] = { NULL };
89 rv = netconfig_execute_file(path, args, envs);
93 rv = netconfig_interface_up(WLAN_IFACE_NAME);
97 #if defined TIZEN_WLAN_USE_P2P_INTERFACE
98 rv = netconfig_interface_up(WLAN_P2P_IFACE_NAME);
103 DBG("Successfully loaded p2p device driver");
110 static int __netconfig_p2p_firmware_stop(void)
112 #if defined TIZEN_P2P_ENABLE
114 const char *path = WLAN_DRIVER_SCRIPT;
115 char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL };
116 char *const envs[] = { NULL };
118 rv = netconfig_interface_down(WLAN_IFACE_NAME);
122 rv = netconfig_execute_file(path, args, envs);
126 DBG("Successfully removed p2p device driver");
133 static int __netconfig_softap_firmware_start(void)
135 #if defined TIZEN_TETHERING_ENABLE
137 const char *path = WLAN_DRIVER_SCRIPT;
138 char *const args[] = { "/usr/bin/wlan.sh", "softap", NULL };
139 char *const envs[] = { NULL };
141 rv = netconfig_execute_file(path, args, envs);
145 if (netconfig_interface_up(WLAN_IFACE_NAME) == FALSE)
148 DBG("Successfully loaded softap device driver");
155 static int __netconfig_softap_firmware_stop(void)
157 #if defined TIZEN_TETHERING_ENABLE
159 const char *path = WLAN_DRIVER_SCRIPT;
160 char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL };
161 char *const envs[] = { NULL };
163 rv = netconfig_interface_down(WLAN_IFACE_NAME);
167 rv = netconfig_execute_file(path, args, envs);
171 DBG("Successfully removed softap device driver");
178 static int __netconfig_wifi_firmware_start(enum netconfig_wifi_firmware type)
180 if (netconfig_emulator_is_emulated() == TRUE)
184 case NETCONFIG_WIFI_STA:
185 return __netconfig_sta_firmware_start();
186 case NETCONFIG_WIFI_P2P:
187 return __netconfig_p2p_firmware_start();
188 case NETCONFIG_WIFI_SOFTAP:
189 return __netconfig_softap_firmware_start();
197 static int __netconfig_wifi_firmware_stop(enum netconfig_wifi_firmware type)
199 if (netconfig_emulator_is_emulated() == TRUE)
203 case NETCONFIG_WIFI_STA:
204 return __netconfig_sta_firmware_stop();
205 case NETCONFIG_WIFI_P2P:
206 return __netconfig_p2p_firmware_stop();
207 case NETCONFIG_WIFI_SOFTAP:
208 return __netconfig_softap_firmware_stop();
216 int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable)
219 static enum netconfig_wifi_firmware current_driver = NETCONFIG_WIFI_OFF;
220 enum netconfig_wifi_firmware alias = type;
222 #if defined WLAN_CONCURRENT_MODE
225 if (type == NETCONFIG_WIFI_P2P)
226 alias = NETCONFIG_WIFI_STA;
229 DBG("Wi-Fi current firmware %d (type: %d %s)", current_driver, type,
230 enable == TRUE ? "enable" : "disable");
232 if (enable == FALSE) {
233 if (current_driver == NETCONFIG_WIFI_OFF) {
235 } else if (current_driver == alias) {
236 #if defined WLAN_CHECK_POWERSAVE
237 if (type == NETCONFIG_WIFI_STA &&
238 netconfig_wifi_is_powersave_mode() == TRUE) {
239 netconfig_interface_down(WIFI_IFNAME);
245 #if defined WLAN_CONCURRENT_MODE
246 #if defined TIZEN_TELEPHONY_ENABLE
247 vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
249 if (flight_mode == 0 && type == NETCONFIG_WIFI_STA &&
250 netconfig_is_wifi_direct_on() == TRUE) {
251 netconfig_interface_down(WIFI_IFNAME);
256 if (type == NETCONFIG_WIFI_P2P &&
257 netconfig_wifi_state_get_technology_state() >
258 NETCONFIG_WIFI_TECH_OFF) {
259 netconfig_interface_down(WLAN_P2P_IFACE_NAME);
264 err = __netconfig_wifi_firmware_stop(type);
265 if (err < 0 && err != -EALREADY)
268 current_driver = NETCONFIG_WIFI_OFF;
276 if (current_driver > NETCONFIG_WIFI_OFF) {
277 if (current_driver == alias) {
278 #if defined WLAN_CHECK_POWERSAVE
279 if (type == NETCONFIG_WIFI_STA &&
280 netconfig_wifi_is_powersave_mode() == TRUE) {
281 netconfig_interface_up(WIFI_IFNAME);
287 #if defined WLAN_CONCURRENT_MODE
288 if (type == NETCONFIG_WIFI_STA)
289 netconfig_interface_up(WIFI_IFNAME);
290 #if defined TIZEN_P2P_ENABLE
291 else if (type == NETCONFIG_WIFI_P2P)
292 netconfig_interface_up(WLAN_P2P_IFACE_NAME);
301 err = __netconfig_wifi_firmware_start(type);
303 DBG("Failed to execute script file");
305 current_driver = alias;
310 gboolean handle_start(WifiFirmware *firmware, GDBusMethodInvocation *context, const gchar *device)
314 g_return_val_if_fail(firmware != NULL, FALSE);
316 DBG("Wi-Fi firmware start %s", device != NULL ? device : "null");
318 if (g_strcmp0("p2p", device) == 0)
319 err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, TRUE);
320 else if (g_strcmp0("softap", device) == 0)
321 err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, TRUE);
326 if (err == -EALREADY)
327 netconfig_error_already_exists(context);
329 netconfig_error_wifi_driver_failed(context);
331 wifi_firmware_complete_start(firmware, context);
335 wifi_firmware_complete_start(firmware, context);
339 gboolean handle_stop(WifiFirmware *firmware, GDBusMethodInvocation *context, const gchar *device)
343 g_return_val_if_fail(firmware != NULL, FALSE);
345 DBG("Wi-Fi firmware stop %s", device != NULL ? device : "null");
347 if (g_strcmp0("p2p", device) == 0)
348 err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, FALSE);
349 else if (g_strcmp0("softap", device) == 0)
350 err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, FALSE);
355 if (err == -EALREADY)
356 netconfig_error_already_exists(context);
358 netconfig_error_wifi_driver_failed(context);
360 wifi_firmware_complete_start(firmware, context);
364 wifi_firmware_complete_start(firmware, context);