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(NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT))
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(NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT))
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(NETCONFIG_SUPPORTED_FEATURE_TETHERING))
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(NETCONFIG_SUPPORTED_FEATURE_TETHERING))
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 DBG("Wi-Fi current firmware %d (type: %d %s)", current_driver, type,
215 enable == TRUE ? "enable" : "disable");
217 if (enable == FALSE) {
218 if (current_driver == NETCONFIG_WIFI_OFF) {
220 } else if (current_driver == alias) {
222 err = __netconfig_wifi_firmware_stop(type);
223 if (err < 0 && err != -EALREADY)
226 current_driver = NETCONFIG_WIFI_OFF;
234 if (current_driver > NETCONFIG_WIFI_OFF) {
235 if (current_driver == alias)
241 err = __netconfig_wifi_firmware_start(type);
243 DBG("Failed to execute script file");
245 current_driver = alias;
250 gboolean handle_start(WifiFirmware *firmware, GDBusMethodInvocation *context, const gchar *device)
254 g_return_val_if_fail(firmware != NULL, FALSE);
256 DBG("Wi-Fi firmware start %s", device != NULL ? device : "null");
258 if (g_strcmp0("p2p", device) == 0)
259 err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, TRUE);
260 else if (g_strcmp0("softap", device) == 0)
261 err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, TRUE);
266 if (err == -EALREADY)
267 netconfig_error_already_exists(context);
268 else if (g_strcmp0("softap", device) == 0 && err == -EIO && netconfig_is_wifi_direct_on() == FALSE) {
269 if (netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, FALSE) == 0 && netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, TRUE) == 0) {
270 wifi_firmware_complete_start(firmware, context);
273 netconfig_error_wifi_driver_failed(context);
275 netconfig_error_wifi_driver_failed(context);
280 wifi_firmware_complete_start(firmware, context);
284 gboolean handle_stop(WifiFirmware *firmware, GDBusMethodInvocation *context, const gchar *device)
288 g_return_val_if_fail(firmware != NULL, FALSE);
290 DBG("Wi-Fi firmware stop %s", device != NULL ? device : "null");
292 if (g_strcmp0("p2p", device) == 0)
293 err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, FALSE);
294 else if (g_strcmp0("softap", device) == 0)
295 err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, FALSE);
300 if (err == -EALREADY)
301 netconfig_error_already_exists(context);
303 netconfig_error_wifi_driver_failed(context);
308 wifi_firmware_complete_stop(firmware, context);