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"
36 #define WLAN_P2P_IFACE_NAME_TV "p2p0"
37 #define WLAN_P2P_IFACE_NAME_COMMON "wlan0"
38 #define WLAN_P2P_IFACE_NAME ((TIZEN_TV) ? (WLAN_P2P_IFACE_NAME_TV) : (WLAN_P2P_IFACE_NAME_COMMON))
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 #if defined TIZEN_WLAN_USE_P2P_INTERFACE
94 rv = netconfig_interface_up(WLAN_P2P_IFACE_NAME);
99 DBG("Successfully loaded p2p device driver");
106 static int __netconfig_p2p_firmware_stop(void)
108 #if defined TIZEN_P2P_ENABLE
110 const char *path = WLAN_DRIVER_SCRIPT;
111 char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL };
112 char *const envs[] = { NULL };
114 rv = netconfig_interface_down(WLAN_IFACE_NAME);
118 rv = netconfig_execute_file(path, args, envs);
122 DBG("Successfully removed p2p device driver");
129 static int __netconfig_softap_firmware_start(void)
131 #if defined TIZEN_TETHERING_ENABLE
133 const char *path = WLAN_DRIVER_SCRIPT;
134 char *const args[] = { "/usr/bin/wlan.sh", "softap", NULL };
135 char *const envs[] = { NULL };
137 rv = netconfig_execute_file(path, args, envs);
141 if (netconfig_interface_up(WLAN_IFACE_NAME) == FALSE)
144 DBG("Successfully loaded softap device driver");
151 static int __netconfig_softap_firmware_stop(void)
153 #if defined TIZEN_TETHERING_ENABLE
155 const char *path = WLAN_DRIVER_SCRIPT;
156 char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL };
157 char *const envs[] = { NULL };
159 rv = netconfig_interface_down(WLAN_IFACE_NAME);
163 rv = netconfig_execute_file(path, args, envs);
167 DBG("Successfully removed softap device driver");
174 static int __netconfig_wifi_firmware_start(enum netconfig_wifi_firmware type)
176 if (emulator_is_emulated() == TRUE)
180 case NETCONFIG_WIFI_STA:
181 return __netconfig_sta_firmware_start();
182 case NETCONFIG_WIFI_P2P:
183 return __netconfig_p2p_firmware_start();
184 case NETCONFIG_WIFI_SOFTAP:
185 return __netconfig_softap_firmware_start();
193 static int __netconfig_wifi_firmware_stop(enum netconfig_wifi_firmware type)
195 if (emulator_is_emulated() == TRUE)
199 case NETCONFIG_WIFI_STA:
200 return __netconfig_sta_firmware_stop();
201 case NETCONFIG_WIFI_P2P:
202 return __netconfig_p2p_firmware_stop();
203 case NETCONFIG_WIFI_SOFTAP:
204 return __netconfig_softap_firmware_stop();
212 int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable)
215 static enum netconfig_wifi_firmware current_driver = NETCONFIG_WIFI_OFF;
216 enum netconfig_wifi_firmware alias = type;
218 #if defined WLAN_CONCURRENT_MODE
221 if (type == NETCONFIG_WIFI_P2P)
222 alias = NETCONFIG_WIFI_STA;
225 DBG("Wi-Fi current firmware %d (type: %d %s)", current_driver, type,
226 enable == TRUE ? "enable" : "disable");
228 if (enable == FALSE) {
229 if (current_driver == NETCONFIG_WIFI_OFF) {
231 } else if (current_driver == alias) {
233 #if defined WLAN_CONCURRENT_MODE
234 netconfig_vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
235 if (flight_mode == 0 && type == NETCONFIG_WIFI_STA &&
236 netconfig_is_wifi_direct_on() == TRUE) {
237 netconfig_interface_down(WIFI_IFNAME);
242 if (type == NETCONFIG_WIFI_P2P && wifi_state_get_technology_state() > NETCONFIG_WIFI_TECH_OFF) {
243 netconfig_interface_down(WLAN_P2P_IFACE_NAME);
248 err = __netconfig_wifi_firmware_stop(type);
249 if (err < 0 && err != -EALREADY)
252 current_driver = NETCONFIG_WIFI_OFF;
260 if (current_driver > NETCONFIG_WIFI_OFF) {
261 if (current_driver == alias) {
263 #if defined WLAN_CONCURRENT_MODE
264 if (type == NETCONFIG_WIFI_STA)
265 netconfig_interface_up(WIFI_IFNAME);
266 #if defined TIZEN_P2P_ENABLE
267 else if (type == NETCONFIG_WIFI_P2P)
268 netconfig_interface_up(WLAN_P2P_IFACE_NAME);
277 err = __netconfig_wifi_firmware_start(type);
279 DBG("Failed to execute script file");
281 current_driver = alias;
286 gboolean handle_start(WifiFirmware *firmware, GDBusMethodInvocation *context, const gchar *device)
290 g_return_val_if_fail(firmware != NULL, FALSE);
292 DBG("Wi-Fi firmware start %s", device != NULL ? device : "null");
294 if (g_strcmp0("p2p", device) == 0)
295 err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, TRUE);
296 else if (g_strcmp0("softap", device) == 0)
297 err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, TRUE);
302 if (err == -EALREADY)
303 netconfig_error_already_exists(context);
304 else if (g_strcmp0("softap", device) == 0 && err == -EIO && netconfig_is_wifi_direct_on() == FALSE) {
305 if (netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, FALSE) == 0 && netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, TRUE) == 0) {
306 wifi_firmware_complete_start(firmware, context);
309 netconfig_error_wifi_driver_failed(context);
311 netconfig_error_wifi_driver_failed(context);
316 wifi_firmware_complete_start(firmware, context);
320 gboolean handle_stop(WifiFirmware *firmware, GDBusMethodInvocation *context, const gchar *device)
324 g_return_val_if_fail(firmware != NULL, FALSE);
326 DBG("Wi-Fi firmware stop %s", device != NULL ? device : "null");
328 if (g_strcmp0("p2p", device) == 0)
329 err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, FALSE);
330 else if (g_strcmp0("softap", device) == 0)
331 err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, FALSE);
336 if (err == -EALREADY)
337 netconfig_error_already_exists(context);
339 netconfig_error_wifi_driver_failed(context);
344 wifi_firmware_complete_stop(firmware, context);