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"
33 #define WLAN_DRIVER_SCRIPT "/usr/bin/wlan.sh"
34 #define WLAN_IFACE_NAME "wlan0"
37 #define WLAN_P2P_IFACE_NAME "p2p0"
38 #else /* defined(TIZEN_TV) */
39 #define WLAN_P2P_IFACE_NAME "wlan0"
40 #endif /* defined(TIZEN_TV) */
42 static int __netconfig_sta_firmware_start(void)
45 const char *path = WLAN_DRIVER_SCRIPT;
46 char *const args[] = { "/usr/bin/wlan.sh", "start", NULL };
47 char *const envs[] = { NULL };
49 rv = netconfig_execute_file(path, args, envs);
53 rv = netconfig_interface_up(WLAN_IFACE_NAME);
57 DBG("Successfully loaded wireless device driver");
61 static int __netconfig_sta_firmware_stop(void)
64 const char *path = WLAN_DRIVER_SCRIPT;
65 char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL };
66 char *const envs[] = { NULL };
68 /* Update statistics before driver remove */
69 netconfig_wifi_statistics_update_powered_off();
71 rv = netconfig_interface_down(WLAN_IFACE_NAME);
75 rv = netconfig_execute_file(path, args, envs);
79 DBG("Successfully removed wireless device driver");
83 static int __netconfig_p2p_firmware_start(void)
85 #if defined TIZEN_P2P_ENABLE
87 const char *path = WLAN_DRIVER_SCRIPT;
88 char *const args[] = { "/usr/bin/wlan.sh", "p2p", NULL };
89 char *const envs[] = { NULL };
91 rv = netconfig_execute_file(path, args, envs);
95 #if defined TIZEN_WLAN_USE_P2P_INTERFACE
96 rv = netconfig_interface_up(WLAN_P2P_IFACE_NAME);
101 DBG("Successfully loaded p2p device driver");
108 static int __netconfig_p2p_firmware_stop(void)
110 #if defined TIZEN_P2P_ENABLE
112 const char *path = WLAN_DRIVER_SCRIPT;
113 char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL };
114 char *const envs[] = { NULL };
116 rv = netconfig_interface_down(WLAN_IFACE_NAME);
120 rv = netconfig_execute_file(path, args, envs);
124 DBG("Successfully removed p2p device driver");
131 static int __netconfig_softap_firmware_start(void)
133 #if defined TIZEN_TETHERING_ENABLE
135 const char *path = WLAN_DRIVER_SCRIPT;
136 char *const args[] = { "/usr/bin/wlan.sh", "softap", NULL };
137 char *const envs[] = { NULL };
139 rv = netconfig_execute_file(path, args, envs);
143 if (netconfig_interface_up(WLAN_IFACE_NAME) == FALSE)
146 DBG("Successfully loaded softap device driver");
153 static int __netconfig_softap_firmware_stop(void)
155 #if defined TIZEN_TETHERING_ENABLE
157 const char *path = WLAN_DRIVER_SCRIPT;
158 char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL };
159 char *const envs[] = { NULL };
161 rv = netconfig_interface_down(WLAN_IFACE_NAME);
165 rv = netconfig_execute_file(path, args, envs);
169 DBG("Successfully removed softap device driver");
176 static int __netconfig_wifi_firmware_start(enum netconfig_wifi_firmware type)
178 if (emulator_is_emulated() == TRUE)
182 case NETCONFIG_WIFI_STA:
183 return __netconfig_sta_firmware_start();
184 case NETCONFIG_WIFI_P2P:
185 return __netconfig_p2p_firmware_start();
186 case NETCONFIG_WIFI_SOFTAP:
187 return __netconfig_softap_firmware_start();
195 static int __netconfig_wifi_firmware_stop(enum netconfig_wifi_firmware type)
197 if (emulator_is_emulated() == TRUE)
201 case NETCONFIG_WIFI_STA:
202 return __netconfig_sta_firmware_stop();
203 case NETCONFIG_WIFI_P2P:
204 return __netconfig_p2p_firmware_stop();
205 case NETCONFIG_WIFI_SOFTAP:
206 return __netconfig_softap_firmware_stop();
214 int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable)
217 static enum netconfig_wifi_firmware current_driver = NETCONFIG_WIFI_OFF;
218 enum netconfig_wifi_firmware alias = type;
220 #if defined WLAN_CONCURRENT_MODE
223 if (type == NETCONFIG_WIFI_P2P)
224 alias = NETCONFIG_WIFI_STA;
227 DBG("Wi-Fi current firmware %d (type: %d %s)", current_driver, type,
228 enable == TRUE ? "enable" : "disable");
230 if (enable == FALSE) {
231 if (current_driver == NETCONFIG_WIFI_OFF) {
233 } else if (current_driver == alias) {
235 #if defined WLAN_CONCURRENT_MODE
236 netconfig_vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
237 if (flight_mode == 0 && type == NETCONFIG_WIFI_STA &&
238 netconfig_is_wifi_direct_on() == TRUE) {
239 netconfig_interface_down(WIFI_IFNAME);
244 if (type == NETCONFIG_WIFI_P2P && wifi_state_get_technology_state() > NETCONFIG_WIFI_TECH_OFF) {
245 netconfig_interface_down(WLAN_P2P_IFACE_NAME);
250 err = __netconfig_wifi_firmware_stop(type);
251 if (err < 0 && err != -EALREADY)
254 current_driver = NETCONFIG_WIFI_OFF;
262 if (current_driver > NETCONFIG_WIFI_OFF) {
263 if (current_driver == alias) {
265 #if defined WLAN_CONCURRENT_MODE
266 if (type == NETCONFIG_WIFI_STA)
267 netconfig_interface_up(WIFI_IFNAME);
268 #if defined TIZEN_P2P_ENABLE
269 else if (type == NETCONFIG_WIFI_P2P)
270 netconfig_interface_up(WLAN_P2P_IFACE_NAME);
279 err = __netconfig_wifi_firmware_start(type);
281 DBG("Failed to execute script file");
283 current_driver = alias;
288 gboolean handle_start(WifiFirmware *firmware, GDBusMethodInvocation *context, const gchar *device)
292 g_return_val_if_fail(firmware != NULL, FALSE);
294 DBG("Wi-Fi firmware start %s", device != NULL ? device : "null");
296 if (g_strcmp0("p2p", device) == 0)
297 err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, TRUE);
298 else if (g_strcmp0("softap", device) == 0)
299 err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, TRUE);
304 if (err == -EALREADY)
305 netconfig_error_already_exists(context);
306 else if (g_strcmp0("softap", device) == 0 && err == -EIO && netconfig_is_wifi_direct_on() == FALSE) {
307 if (netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, FALSE) == 0 && netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, TRUE) == 0) {
308 wifi_firmware_complete_start(firmware, context);
311 netconfig_error_wifi_driver_failed(context);
313 netconfig_error_wifi_driver_failed(context);
318 wifi_firmware_complete_start(firmware, context);
322 gboolean handle_stop(WifiFirmware *firmware, GDBusMethodInvocation *context, const gchar *device)
326 g_return_val_if_fail(firmware != NULL, FALSE);
328 DBG("Wi-Fi firmware stop %s", device != NULL ? device : "null");
330 if (g_strcmp0("p2p", device) == 0)
331 err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, FALSE);
332 else if (g_strcmp0("softap", device) == 0)
333 err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, FALSE);
338 if (err == -EALREADY)
339 netconfig_error_already_exists(context);
341 netconfig_error_wifi_driver_failed(context);
346 wifi_firmware_complete_stop(firmware, context);