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.
24 #include <vconf-keys.h>
35 #include "wifi-bssid-scan.h"
36 #include "wifi-netlink-scan.h"
37 #include "wifi-power.h"
38 #include "wifi-state.h"
39 #include "wifi-agent.h"
40 #include "wifi-firmware.h"
41 #include "wifi-passpoint.h"
42 #include "wifi-eap-config.h"
43 #include "wifi-background-scan.h"
44 #include "ip-conflict-detect.h"
45 #include "wifi-config.h"
46 #include "wifi-tdls.h"
47 #include "wifi-key-encryption.h"
48 #include "wifi-extension.h"
50 #define SPRD_CP2_FIRMWARE_PATH "/usr/bin/cp2-downloader"
51 #define SPRD_CP2_FIRMWARE_STATE_PATH "/tmp/.wifi-firmware-loaded"
52 static int is_wifi_firmware_downloaded = FALSE;
54 static Wifi *wifi_object = NULL;
55 static NetConnmanAgent *connman_agent_object = NULL;
56 static WifiFirmware *wififirmware_object = NULL;
58 Wifi *get_wifi_object(void){
62 static gboolean handle_check_black_list(Wifi *wifi, GDBusMethodInvocation *context,
63 const gchar *name, const gchar *security_type, const gchar *eap)
65 ERR("Name (%s)", name);
66 INFO("disable to check");
67 wifi_complete_check_black_list(wifi, context, TRUE);
71 static void _set_wifi_mac_address(void)
73 gchar *mac_addr = NULL;
75 mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
76 if (mac_addr != NULL) {
77 if (strlen(mac_addr) == 0)
78 netconfig_set_mac_address_from_file();
83 void __netconfig_wifi_connect_reply(GObject *source_object, GAsyncResult *res,
86 GDBusConnection *conn = NULL;
89 DBG("WiFi Connection Reply");
91 conn = G_DBUS_CONNECTION(source_object);
92 g_dbus_connection_call_finish(conn, res, &error);
94 ERR("WiFi Connection Error [%s]", error->message);
95 /* No need to emit WiFiConnectFail signal if Connection is
97 if (error->code == G_IO_ERROR_TIMED_OUT) {
99 DBG("WiFi Connection in Progress");
100 netconfig_gdbus_pending_call_unref();
104 if (netconfig_dbus_emit_signal(NULL, NETCONFIG_WIFI_PATH,
105 NETCONFIG_WIFI_INTERFACE, "WiFiConnectFail",
107 ERR("Failed to emit WiFiConnectFail signal");
109 DBG("Successfully sent WiFiConnectFail signal");
111 DBG("WiFi Connection has been initiated successfully");
113 netconfig_gdbus_pending_call_unref();
117 static void _update_wifi_firmware_state(void)
120 mode_t mode = S_IRGRP | S_IWUSR | S_IXGRP;
122 fd = creat(SPRD_CP2_FIRMWARE_STATE_PATH, mode);
126 DBG("Failed to create wifi firmware state file");
128 is_wifi_firmware_downloaded = TRUE;
131 static int _get_wifi_firmware_state(void)
133 if (!is_wifi_firmware_downloaded
134 && access(SPRD_CP2_FIRMWARE_STATE_PATH, F_OK) != 0)
135 is_wifi_firmware_downloaded = FALSE;
137 is_wifi_firmware_downloaded = TRUE;
138 return is_wifi_firmware_downloaded;
141 int wifi_firmware_download(void)
144 const char *path = SPRD_CP2_FIRMWARE_PATH;
145 char *const args[] = { SPRD_CP2_FIRMWARE_PATH, NULL };
146 char *const envs[] = { NULL };
148 if (!_get_wifi_firmware_state()) {
149 rv = netconfig_execute_file(path, args, envs);
151 DBG("wifi firmware download fails");
154 _update_wifi_firmware_state();
155 DBG("wifi firmware download successes");
161 void wifi_object_create_and_init(void)
163 DBG("Create wifi object.");
164 GDBusInterfaceSkeleton *interface_wifi = NULL;
165 GDBusInterfaceSkeleton *interface_connman_agent = NULL;
166 GDBusInterfaceSkeleton *interface_wifi_firmware = NULL;
167 GDBusConnection *connection = NULL;
168 GDBusObjectManagerServer *server = netdbus_get_wifi_manager();
172 connection = netdbus_get_connection();
173 g_dbus_object_manager_server_set_connection(server, connection);
175 /*Interface netconfig.wifi*/
176 wifi_object = wifi_skeleton_new();
177 interface_wifi = G_DBUS_INTERFACE_SKELETON(wifi_object);
180 g_signal_connect(wifi_object, "handle-load-driver",
181 G_CALLBACK(handle_load_driver), NULL);
182 g_signal_connect(wifi_object, "handle-remove-driver",
183 G_CALLBACK(handle_remove_driver), NULL);
184 g_signal_connect(wifi_object, "handle-load-p2p-driver",
185 G_CALLBACK(handle_load_p2p_driver), NULL);
186 g_signal_connect(wifi_object, "handle-remove-p2p-driver",
187 G_CALLBACK(handle_remove_p2p_driver), NULL);
190 g_signal_connect(wifi_object, "handle-get-wifi-state",
191 G_CALLBACK(handle_get_wifi_state), NULL);
194 g_signal_connect(wifi_object, "handle-request-bssid-scan",
195 G_CALLBACK(handle_request_bssid_scan), NULL);
196 g_signal_connect(wifi_object, "handle-get-bssid-list",
197 G_CALLBACK(handle_get_bssid_list), NULL);
198 g_signal_connect(wifi_object, "handle-netlink-scan",
199 G_CALLBACK(handle_netlink_scan), NULL);
202 g_signal_connect(wifi_object, "handle-request-wps-connect",
203 G_CALLBACK(handle_request_wps_connect), NULL);
204 g_signal_connect(wifi_object, "handle-request-wps-cancel",
205 G_CALLBACK(handle_request_wps_cancel), NULL);
208 g_signal_connect(wifi_object, "handle-launch-direct",
209 G_CALLBACK(handle_launch_direct), NULL);
212 g_signal_connect(wifi_object, "handle-create-eap-config",
213 G_CALLBACK(handle_create_eap_config), NULL);
214 g_signal_connect(wifi_object, "handle-delete-eap-config",
215 G_CALLBACK(handle_delete_eap_config), NULL);
218 g_signal_connect(wifi_object, "handle-add-vsie",
219 G_CALLBACK(handle_add_vsie), NULL);
220 g_signal_connect(wifi_object, "handle-get-vsie",
221 G_CALLBACK(handle_get_vsie), NULL);
222 g_signal_connect(wifi_object, "handle-remove-vsie",
223 G_CALLBACK(handle_remove_vsie), NULL);
225 /* IP conflict methods */
226 g_signal_connect(wifi_object, "handle-ip-conflict-set-enable",
227 G_CALLBACK(handle_ip_conflict_set_enable), NULL);
228 g_signal_connect(wifi_object, "handle-is-ip-conflict-detect-enabled",
229 G_CALLBACK(handle_is_ip_conflict_detect_enabled), NULL);
230 g_signal_connect(wifi_object, "handle-set-ip-conflict-period",
231 G_CALLBACK(handle_set_ip_conflict_period), NULL);
232 g_signal_connect(wifi_object, "handle-get-ip-conflict-state",
233 G_CALLBACK(handle_get_ip_conflict_state), NULL);
234 g_signal_connect(wifi_object, "handle-get-ip-conflict-period",
235 G_CALLBACK(handle_get_ip_conflict_period), NULL);
237 /* WIFI configuration */
238 g_signal_connect(wifi_object, "handle-save-configuration",
239 G_CALLBACK(handle_save_configuration), NULL);
240 g_signal_connect(wifi_object, "handle-remove-configuration",
241 G_CALLBACK(handle_remove_configuration), NULL);
242 g_signal_connect(wifi_object, "handle-get-config-ids",
243 G_CALLBACK(handle_get_config_ids), NULL);
244 g_signal_connect(wifi_object, "handle-load-configuration",
245 G_CALLBACK(handle_load_configuration), NULL);
246 g_signal_connect(wifi_object, "handle-set-config-field",
247 G_CALLBACK(handle_set_config_field), NULL);
248 g_signal_connect(wifi_object, "handle-get-config-passphrase",
249 G_CALLBACK(handle_get_config_passphrase), NULL);
251 /* WIFI EAP configuration */
252 g_signal_connect(wifi_object, "handle-save-eap-configuration",
253 G_CALLBACK(handle_save_eap_configuration), NULL);
254 g_signal_connect(wifi_object, "handle-load-eap-configuration",
255 G_CALLBACK(handle_load_eap_configuration), NULL);
258 g_signal_connect(wifi_object, "handle-set-bgscan",
259 G_CALLBACK(handle_set_bgscan), NULL);
260 g_signal_connect(wifi_object, "handle-resume-bgscan",
261 G_CALLBACK(handle_resume_bgscan), NULL);
262 g_signal_connect(wifi_object, "handle-pause-bgscan",
263 G_CALLBACK(handle_pause_bgscan), NULL);
264 g_signal_connect(wifi_object, "handle-reset-bgscan-interval",
265 G_CALLBACK(handle_reset_bgscan_interval), NULL);
268 g_signal_connect(wifi_object, "handle-get-autoscan",
269 G_CALLBACK(handle_get_autoscan), NULL);
270 g_signal_connect(wifi_object, "handle-get-autoscanmode",
271 G_CALLBACK(handle_get_autoscanmode), NULL);
273 /* Extension API methods */
274 g_signal_connect(wifi_object, "handle-flush-bss",
275 G_CALLBACK(handle_flush_bss), NULL);
278 g_signal_connect(wifi_object, "handle-set-passpoint",
279 G_CALLBACK(handle_set_passpoint), NULL);
280 g_signal_connect(wifi_object, "handle-get-passpoint",
281 G_CALLBACK(handle_get_passpoint), NULL);
283 /* EAP authentication */
284 g_signal_connect(wifi_object, "handle-get-aka-auth",
285 G_CALLBACK(handle_get_aka_auth), NULL);
286 g_signal_connect(wifi_object, "handle-get-sim-auth",
287 G_CALLBACK(handle_get_sim_auth), NULL);
288 g_signal_connect(wifi_object, "handle-get-sim-imsi",
289 G_CALLBACK(handle_get_sim_imsi), NULL);
290 g_signal_connect(wifi_object, "handle-req-aka-auth",
291 G_CALLBACK(handle_req_aka_auth), NULL);
292 g_signal_connect(wifi_object, "handle-req-sim-auth",
293 G_CALLBACK(handle_req_sim_auth), NULL);
295 /* WIFI MDM blacklist */
296 g_signal_connect(wifi_object, "handle-check-black-list",
297 G_CALLBACK(handle_check_black_list), NULL);
300 g_signal_connect(wifi_object, "handle-tdls-disconnect",
301 G_CALLBACK(handle_tdls_disconnect), NULL);
302 g_signal_connect(wifi_object, "handle-tdls-connected-peer",
303 G_CALLBACK(handle_tdls_connected_peer), NULL);
304 g_signal_connect(wifi_object, "handle-tdls-discover",
305 G_CALLBACK(handle_tdls_discover), NULL);
306 g_signal_connect(wifi_object, "handle-tdls-connect",
307 G_CALLBACK(handle_tdls_connect), NULL);
308 g_signal_connect(wifi_object, "handle-tdls-channel-switch",
309 G_CALLBACK(handle_tdls_channel_switch), NULL);
310 g_signal_connect(wifi_object, "handle-tdls-cancel-channel-switch",
311 G_CALLBACK(handle_tdls_cancel_channel_switch), NULL);
313 /* Passphrase Encryption */
314 g_signal_connect(wifi_object, "handle-encrypt-passphrase",
315 G_CALLBACK(handle_encrypt_passphrase), NULL);
316 g_signal_connect(wifi_object, "handle-decrypt-passphrase",
317 G_CALLBACK(handle_decrypt_passphrase), NULL);
319 if (!g_dbus_interface_skeleton_export(interface_wifi, connection,
320 NETCONFIG_WIFI_PATH, NULL)) {
321 ERR("Export WIFI_PATH for wifi failed");
324 /* Interface connman.Agent */
325 connman_agent_object = net_connman_agent_skeleton_new();
327 interface_connman_agent = G_DBUS_INTERFACE_SKELETON(connman_agent_object);
328 g_signal_connect(connman_agent_object, "handle-report-error",
329 G_CALLBACK(handle_report_error), NULL);
330 g_signal_connect(connman_agent_object, "handle-request-browser",
331 G_CALLBACK(handle_request_browser), NULL);
332 g_signal_connect(connman_agent_object, "handle-request-input",
333 G_CALLBACK(handle_request_input), NULL);
334 g_signal_connect(connman_agent_object, "handle-set-field",
335 G_CALLBACK(handle_set_field), NULL);
337 if (!g_dbus_interface_skeleton_export(interface_connman_agent, connection,
338 NETCONFIG_WIFI_PATH, NULL)) {
339 ERR("Export WIFI_PATH for agent failed");
342 /*Interface netconfig.wifi.Firmware*/
343 wififirmware_object = wifi_firmware_skeleton_new();
345 interface_wifi_firmware = G_DBUS_INTERFACE_SKELETON(wififirmware_object);
346 g_signal_connect(wififirmware_object, "handle-start",
347 G_CALLBACK(handle_start), NULL);
348 g_signal_connect(wififirmware_object, "handle-stop",
349 G_CALLBACK(handle_stop), NULL);
351 if (!g_dbus_interface_skeleton_export(interface_wifi_firmware, connection,
352 NETCONFIG_WIFI_PATH, NULL)) {
353 ERR("Export WIFI_PATH for firmware failed");
356 _set_wifi_mac_address();
358 wifi_power_initialize();
363 void wifi_object_deinit(void)
365 g_object_unref(wifi_object);
366 g_object_unref(connman_agent_object);
367 g_object_unref(wififirmware_object);
369 wifi_power_deinitialize();