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"
40 #define WLAN_P2P_IFACE_NAME "p2p0"
41 #else /* defined(TIZEN_TV) */
42 #define WLAN_P2P_IFACE_NAME "wlan0"
43 #endif /* defined(TIZEN_TV) */
45 static int __netconfig_sta_firmware_start(void)
48 const char *path = WLAN_DRIVER_SCRIPT;
49 char *const args[] = { "/usr/bin/wlan.sh", "start", NULL };
50 char *const envs[] = { NULL };
52 rv = netconfig_execute_file(path, args, envs);
56 rv = netconfig_interface_up(WLAN_IFACE_NAME);
60 DBG("Successfully loaded wireless device driver");
64 static int __netconfig_sta_firmware_stop(void)
67 const char *path = WLAN_DRIVER_SCRIPT;
68 char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL };
69 char *const envs[] = { NULL };
71 /* Update statistics before driver remove */
72 netconfig_wifi_statistics_update_powered_off();
74 rv = netconfig_interface_down(WLAN_IFACE_NAME);
78 rv = netconfig_execute_file(path, args, envs);
82 DBG("Successfully removed wireless device driver");
86 static int __netconfig_p2p_firmware_start(void)
88 #if defined TIZEN_P2P_ENABLE
90 const char *path = WLAN_DRIVER_SCRIPT;
91 char *const args[] = { "/usr/bin/wlan.sh", "p2p", NULL };
92 char *const envs[] = { NULL };
94 rv = netconfig_execute_file(path, args, envs);
98 #if defined TIZEN_WLAN_USE_P2P_INTERFACE
99 rv = netconfig_interface_up(WLAN_P2P_IFACE_NAME);
104 DBG("Successfully loaded p2p device driver");
111 static int __netconfig_p2p_firmware_stop(void)
113 #if defined TIZEN_P2P_ENABLE
115 const char *path = WLAN_DRIVER_SCRIPT;
116 char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL };
117 char *const envs[] = { NULL };
119 rv = netconfig_interface_down(WLAN_IFACE_NAME);
123 rv = netconfig_execute_file(path, args, envs);
127 DBG("Successfully removed p2p device driver");
134 static int __netconfig_softap_firmware_start(void)
136 #if defined TIZEN_TETHERING_ENABLE
138 const char *path = WLAN_DRIVER_SCRIPT;
139 char *const args[] = { "/usr/bin/wlan.sh", "softap", NULL };
140 char *const envs[] = { NULL };
142 rv = netconfig_execute_file(path, args, envs);
146 if (netconfig_interface_up(WLAN_IFACE_NAME) == FALSE)
149 DBG("Successfully loaded softap device driver");
156 static int __netconfig_softap_firmware_stop(void)
158 #if defined TIZEN_TETHERING_ENABLE
160 const char *path = WLAN_DRIVER_SCRIPT;
161 char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL };
162 char *const envs[] = { NULL };
164 rv = netconfig_interface_down(WLAN_IFACE_NAME);
168 rv = netconfig_execute_file(path, args, envs);
172 DBG("Successfully removed softap device driver");
179 static int __netconfig_wifi_firmware_start(enum netconfig_wifi_firmware type)
181 if (emulator_is_emulated() == TRUE)
185 case NETCONFIG_WIFI_STA:
186 return __netconfig_sta_firmware_start();
187 case NETCONFIG_WIFI_P2P:
188 return __netconfig_p2p_firmware_start();
189 case NETCONFIG_WIFI_SOFTAP:
190 return __netconfig_softap_firmware_start();
198 static int __netconfig_wifi_firmware_stop(enum netconfig_wifi_firmware type)
200 if (emulator_is_emulated() == TRUE)
204 case NETCONFIG_WIFI_STA:
205 return __netconfig_sta_firmware_stop();
206 case NETCONFIG_WIFI_P2P:
207 return __netconfig_p2p_firmware_stop();
208 case NETCONFIG_WIFI_SOFTAP:
209 return __netconfig_softap_firmware_stop();
217 int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable)
220 static enum netconfig_wifi_firmware current_driver = NETCONFIG_WIFI_OFF;
221 enum netconfig_wifi_firmware alias = type;
223 #if defined WLAN_CONCURRENT_MODE
226 if (type == NETCONFIG_WIFI_P2P)
227 alias = NETCONFIG_WIFI_STA;
230 DBG("Wi-Fi current firmware %d (type: %d %s)", current_driver, type,
231 enable == TRUE ? "enable" : "disable");
233 if (enable == FALSE) {
234 if (current_driver == NETCONFIG_WIFI_OFF) {
236 } else if (current_driver == alias) {
237 #if defined WLAN_CHECK_POWERSAVE
238 if (type == NETCONFIG_WIFI_STA && netconfig_wifi_is_powersave_mode() == TRUE) {
239 netconfig_interface_down(WIFI_IFNAME);
244 #if defined WLAN_CONCURRENT_MODE
245 #if defined TIZEN_TELEPHONY_ENABLE
246 vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
248 if (flight_mode == 0 && type == NETCONFIG_WIFI_STA &&
249 netconfig_is_wifi_direct_on() == TRUE) {
250 netconfig_interface_down(WIFI_IFNAME);
255 if (type == NETCONFIG_WIFI_P2P && wifi_state_get_technology_state() > NETCONFIG_WIFI_TECH_OFF) {
256 netconfig_interface_down(WLAN_P2P_IFACE_NAME);
261 err = __netconfig_wifi_firmware_stop(type);
262 if (err < 0 && err != -EALREADY)
265 current_driver = NETCONFIG_WIFI_OFF;
273 if (current_driver > NETCONFIG_WIFI_OFF) {
274 if (current_driver == alias) {
275 #if defined WLAN_CHECK_POWERSAVE
276 if (type == NETCONFIG_WIFI_STA && netconfig_wifi_is_powersave_mode() == TRUE) {
277 netconfig_interface_up(WIFI_IFNAME);
283 #if defined WLAN_CONCURRENT_MODE
284 if (type == NETCONFIG_WIFI_STA)
285 netconfig_interface_up(WIFI_IFNAME);
286 #if defined TIZEN_P2P_ENABLE
287 else if (type == NETCONFIG_WIFI_P2P)
288 netconfig_interface_up(WLAN_P2P_IFACE_NAME);
297 err = __netconfig_wifi_firmware_start(type);
299 DBG("Failed to execute script file");
301 current_driver = alias;
306 gboolean handle_start(WifiFirmware *firmware, GDBusMethodInvocation *context, const gchar *device)
310 g_return_val_if_fail(firmware != NULL, FALSE);
312 DBG("Wi-Fi firmware start %s", device != NULL ? device : "null");
314 if (g_strcmp0("p2p", device) == 0)
315 err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, TRUE);
316 else if (g_strcmp0("softap", device) == 0)
317 err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, TRUE);
322 if (err == -EALREADY)
323 netconfig_error_already_exists(context);
324 else if (g_strcmp0("softap", device) == 0 && err == -EIO && netconfig_is_wifi_direct_on() == FALSE) {
325 if (netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, FALSE) == 0 && netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, TRUE) == 0) {
326 wifi_firmware_complete_start(firmware, context);
329 netconfig_error_wifi_driver_failed(context);
332 netconfig_error_wifi_driver_failed(context);
337 wifi_firmware_complete_start(firmware, context);
341 gboolean handle_stop(WifiFirmware *firmware, GDBusMethodInvocation *context, const gchar *device)
345 g_return_val_if_fail(firmware != NULL, FALSE);
347 DBG("Wi-Fi firmware stop %s", device != NULL ? device : "null");
349 if (g_strcmp0("p2p", device) == 0)
350 err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, FALSE);
351 else if (g_strcmp0("softap", device) == 0)
352 err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, FALSE);
357 if (err == -EALREADY)
358 netconfig_error_already_exists(context);
360 netconfig_error_wifi_driver_failed(context);
365 wifi_firmware_complete_stop(firmware, context);