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 if (TIZEN_WLAN_BOARD_SPRD) {
48 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 if (TIZEN_WLAN_BOARD_SPRD) {
76 rv = netconfig_execute_file(path, args, envs);
81 DBG("Successfully removed wireless device driver");
85 static int __netconfig_p2p_firmware_start(void)
87 #if defined TIZEN_P2P_ENABLE
89 const char *path = WLAN_DRIVER_SCRIPT;
90 char *const args[] = { "/usr/bin/wlan.sh", "p2p", NULL };
91 char *const envs[] = { NULL };
93 rv = netconfig_execute_file(path, args, envs);
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 (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 (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) {
237 #if defined WLAN_CONCURRENT_MODE
238 netconfig_vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
239 if (flight_mode == 0 && type == NETCONFIG_WIFI_STA &&
240 netconfig_is_wifi_direct_on() == TRUE) {
241 netconfig_interface_down(WIFI_IFNAME);
246 if (type == NETCONFIG_WIFI_P2P && wifi_state_get_technology_state() > NETCONFIG_WIFI_TECH_OFF) {
247 netconfig_interface_down(WLAN_P2P_IFACE_NAME);
252 err = __netconfig_wifi_firmware_stop(type);
253 if (err < 0 && err != -EALREADY)
256 current_driver = NETCONFIG_WIFI_OFF;
264 if (current_driver > NETCONFIG_WIFI_OFF) {
265 if (current_driver == alias) {
267 #if defined WLAN_CONCURRENT_MODE
268 if (type == NETCONFIG_WIFI_STA)
269 netconfig_interface_up(WIFI_IFNAME);
270 #if defined TIZEN_P2P_ENABLE
271 else if (type == NETCONFIG_WIFI_P2P)
272 netconfig_interface_up(WLAN_P2P_IFACE_NAME);
281 err = __netconfig_wifi_firmware_start(type);
283 DBG("Failed to execute script file");
285 current_driver = alias;
290 gboolean handle_start(WifiFirmware *firmware, GDBusMethodInvocation *context, const gchar *device)
294 g_return_val_if_fail(firmware != NULL, FALSE);
296 DBG("Wi-Fi firmware start %s", device != NULL ? device : "null");
298 if (g_strcmp0("p2p", device) == 0)
299 err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, TRUE);
300 else if (g_strcmp0("softap", device) == 0)
301 err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, TRUE);
306 if (err == -EALREADY)
307 netconfig_error_already_exists(context);
308 else if (g_strcmp0("softap", device) == 0 && err == -EIO && netconfig_is_wifi_direct_on() == FALSE) {
309 if (netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, FALSE) == 0 && netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, TRUE) == 0) {
310 wifi_firmware_complete_start(firmware, context);
313 netconfig_error_wifi_driver_failed(context);
315 netconfig_error_wifi_driver_failed(context);
320 wifi_firmware_complete_start(firmware, context);
324 gboolean handle_stop(WifiFirmware *firmware, GDBusMethodInvocation *context, const gchar *device)
328 g_return_val_if_fail(firmware != NULL, FALSE);
330 DBG("Wi-Fi firmware stop %s", device != NULL ? device : "null");
332 if (g_strcmp0("p2p", device) == 0)
333 err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, FALSE);
334 else if (g_strcmp0("softap", device) == 0)
335 err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, FALSE);
340 if (err == -EALREADY)
341 netconfig_error_already_exists(context);
343 netconfig_error_wifi_driver_failed(context);
348 wifi_firmware_complete_stop(firmware, context);