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 (!netconfig_check_feature_supported(WIFI_DIRECT_FEATURE))
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");
105 static int __netconfig_p2p_firmware_stop(void)
107 if (!netconfig_check_feature_supported(WIFI_DIRECT_FEATURE))
111 const char *path = WLAN_DRIVER_SCRIPT;
112 char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL };
113 char *const envs[] = { NULL };
115 rv = netconfig_interface_down(WLAN_IFACE_NAME);
119 rv = netconfig_execute_file(path, args, envs);
123 DBG("Successfully removed p2p device driver");
127 static int __netconfig_softap_firmware_start(void)
129 if (!netconfig_check_feature_supported(TETHERING_FEATURE))
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");
148 static int __netconfig_softap_firmware_stop(void)
150 if (!netconfig_check_feature_supported(TETHERING_FEATURE))
154 const char *path = WLAN_DRIVER_SCRIPT;
155 char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL };
156 char *const envs[] = { NULL };
158 rv = netconfig_interface_down(WLAN_IFACE_NAME);
162 rv = netconfig_execute_file(path, args, envs);
166 DBG("Successfully removed softap device driver");
170 static int __netconfig_wifi_firmware_start(enum netconfig_wifi_firmware type)
172 if (emulator_is_emulated() == TRUE)
176 case NETCONFIG_WIFI_STA:
177 return __netconfig_sta_firmware_start();
178 case NETCONFIG_WIFI_P2P:
179 return __netconfig_p2p_firmware_start();
180 case NETCONFIG_WIFI_SOFTAP:
181 return __netconfig_softap_firmware_start();
189 static int __netconfig_wifi_firmware_stop(enum netconfig_wifi_firmware type)
191 if (emulator_is_emulated() == TRUE)
195 case NETCONFIG_WIFI_STA:
196 return __netconfig_sta_firmware_stop();
197 case NETCONFIG_WIFI_P2P:
198 return __netconfig_p2p_firmware_stop();
199 case NETCONFIG_WIFI_SOFTAP:
200 return __netconfig_softap_firmware_stop();
208 int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable)
211 static enum netconfig_wifi_firmware current_driver = NETCONFIG_WIFI_OFF;
212 enum netconfig_wifi_firmware alias = type;
214 #if defined WLAN_CONCURRENT_MODE
217 if (type == NETCONFIG_WIFI_P2P)
218 alias = NETCONFIG_WIFI_STA;
221 DBG("Wi-Fi current firmware %d (type: %d %s)", current_driver, type,
222 enable == TRUE ? "enable" : "disable");
224 if (enable == FALSE) {
225 if (current_driver == NETCONFIG_WIFI_OFF) {
227 } else if (current_driver == alias) {
229 #if defined WLAN_CONCURRENT_MODE
230 netconfig_vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
231 if (flight_mode == 0 && type == NETCONFIG_WIFI_STA &&
232 netconfig_is_wifi_direct_on() == TRUE) {
233 netconfig_interface_down(WIFI_IFNAME);
238 if (type == NETCONFIG_WIFI_P2P && wifi_state_get_technology_state() > NETCONFIG_WIFI_TECH_OFF) {
239 netconfig_interface_down(WLAN_P2P_IFACE_NAME);
244 err = __netconfig_wifi_firmware_stop(type);
245 if (err < 0 && err != -EALREADY)
248 current_driver = NETCONFIG_WIFI_OFF;
256 if (current_driver > NETCONFIG_WIFI_OFF) {
257 if (current_driver == alias) {
259 #if defined WLAN_CONCURRENT_MODE
260 if (type == NETCONFIG_WIFI_STA)
261 netconfig_interface_up(WIFI_IFNAME);
262 else if (netconfig_check_feature_supported(WIFI_DIRECT_FEATURE)
263 && type == NETCONFIG_WIFI_P2P)
264 netconfig_interface_up(WLAN_P2P_IFACE_NAME);
272 err = __netconfig_wifi_firmware_start(type);
274 DBG("Failed to execute script file");
276 current_driver = alias;
281 gboolean handle_start(WifiFirmware *firmware, GDBusMethodInvocation *context, const gchar *device)
285 g_return_val_if_fail(firmware != NULL, FALSE);
287 DBG("Wi-Fi firmware start %s", device != NULL ? device : "null");
289 if (g_strcmp0("p2p", device) == 0)
290 err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, TRUE);
291 else if (g_strcmp0("softap", device) == 0)
292 err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, TRUE);
297 if (err == -EALREADY)
298 netconfig_error_already_exists(context);
299 else if (g_strcmp0("softap", device) == 0 && err == -EIO && netconfig_is_wifi_direct_on() == FALSE) {
300 if (netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, FALSE) == 0 && netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, TRUE) == 0) {
301 wifi_firmware_complete_start(firmware, context);
304 netconfig_error_wifi_driver_failed(context);
306 netconfig_error_wifi_driver_failed(context);
311 wifi_firmware_complete_start(firmware, context);
315 gboolean handle_stop(WifiFirmware *firmware, GDBusMethodInvocation *context, const gchar *device)
319 g_return_val_if_fail(firmware != NULL, FALSE);
321 DBG("Wi-Fi firmware stop %s", device != NULL ? device : "null");
323 if (g_strcmp0("p2p", device) == 0)
324 err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, FALSE);
325 else if (g_strcmp0("softap", device) == 0)
326 err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, FALSE);
331 if (err == -EALREADY)
332 netconfig_error_already_exists(context);
334 netconfig_error_wifi_driver_failed(context);
339 wifi_firmware_complete_stop(firmware, context);