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"
51 #define SPRD_CP2_FIRMWARE_PATH "/hal/bin/cp2-downloader"
52 #define SPRD_CP2_FIRMWARE_STATE_PATH "/tmp/.wifi-firmware-loaded"
53 #define WIFI_SYSTEMD_SERVICE_PATH "/usr/lib/systemd/system/wifi-ready.service"
54 static int is_wifi_firmware_downloaded = FALSE;
56 static Wifi *wifi_object = NULL;
57 static NetConnmanAgent *connman_agent_object = NULL;
58 static WifiFirmware *wififirmware_object = NULL;
59 static char *wifi_def_mac = NULL;
61 Wifi *get_wifi_object(void){
65 static gboolean handle_check_black_list(Wifi *wifi, GDBusMethodInvocation *context,
66 const gchar *name, const gchar *security_type, const gchar *eap)
68 ERR("Name (%s)", name);
69 INFO("disable to check");
70 wifi_complete_check_black_list(wifi, context, TRUE);
74 static void _set_wifi_mac_address(void)
76 gchar *mac_addr = NULL;
78 mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
79 if (mac_addr == NULL || strlen(mac_addr) < 17) {
81 netconfig_set_mac_address_to_vconf(wifi_def_mac);
83 netconfig_set_mac_address_from_file();
89 void wifi_set_default_mac(char *def_mac)
97 wifi_def_mac = def_mac;
100 int wifi_check_systemd_service(void)
102 if (access(WIFI_SYSTEMD_SERVICE_PATH, F_OK ) != -1 )
108 int wifi_check_interface(const char *ifname)
110 char path[WIFI_MAC_PATH_LENGTH];
112 snprintf(path, WIFI_MAC_PATH_LENGTH, WIFI_MAC_ADDR_PATH, ifname);
114 if (access(path, F_OK ) != -1 )
120 void __netconfig_wifi_connect_reply(GObject *source_object, GAsyncResult *res,
123 GDBusConnection *conn = NULL;
124 GError *error = NULL;
125 GVariant *params = NULL;
126 char *interface_name = user_data;
128 DBG("WiFi Connection Reply");
130 conn = G_DBUS_CONNECTION(source_object);
131 g_dbus_connection_call_finish(conn, res, &error);
133 ERR("WiFi Connection Error [%s]", error->message);
134 /* No need to emit WiFiConnectFail signal if Connection is
136 if (error->code == G_IO_ERROR_TIMED_OUT) {
138 DBG("WiFi Connection in Progress");
139 netconfig_gdbus_pending_call_unref();
140 g_free(interface_name);
145 params = g_variant_new("(s)", interface_name);
146 if (netconfig_dbus_emit_signal(NULL, NETCONFIG_WIFI_PATH,
147 NETCONFIG_WIFI_INTERFACE, "WiFiConnectFail",
149 ERR("Failed to emit WiFiConnectFail signal");
151 DBG("Successfully sent WiFiConnectFail signal");
153 DBG("WiFi Connection has been initiated successfully");
155 netconfig_gdbus_pending_call_unref();
156 g_free(interface_name);
160 static void _update_wifi_firmware_state(void)
163 mode_t mode = S_IRGRP | S_IWUSR | S_IXGRP;
165 fd = creat(SPRD_CP2_FIRMWARE_STATE_PATH, mode);
169 DBG("Failed to create wifi firmware state file");
171 is_wifi_firmware_downloaded = TRUE;
174 static int _get_wifi_firmware_state(void)
176 if (!is_wifi_firmware_downloaded
177 && access(SPRD_CP2_FIRMWARE_STATE_PATH, F_OK) != 0)
178 is_wifi_firmware_downloaded = FALSE;
180 is_wifi_firmware_downloaded = TRUE;
181 return is_wifi_firmware_downloaded;
184 int wifi_firmware_download(void)
187 const char *path = SPRD_CP2_FIRMWARE_PATH;
188 char *const args[] = { SPRD_CP2_FIRMWARE_PATH, NULL };
189 char *const envs[] = { NULL };
191 if (!_get_wifi_firmware_state()) {
192 rv = netconfig_execute_file(path, args, envs);
194 DBG("wifi firmware download fails");
197 _update_wifi_firmware_state();
198 DBG("wifi firmware download successes");
204 void wifi_object_create_and_init(void)
206 DBG("Create wifi object.");
207 GDBusInterfaceSkeleton *interface_wifi = NULL;
208 GDBusInterfaceSkeleton *interface_connman_agent = NULL;
209 GDBusInterfaceSkeleton *interface_wifi_firmware = NULL;
210 GDBusConnection *connection = NULL;
211 GDBusObjectManagerServer *server = netdbus_get_wifi_manager();
215 connection = netdbus_get_connection();
216 g_dbus_object_manager_server_set_connection(server, connection);
218 /*Interface netconfig.wifi*/
219 wifi_object = wifi_skeleton_new();
220 interface_wifi = G_DBUS_INTERFACE_SKELETON(wifi_object);
223 g_signal_connect(wifi_object, "handle-load-driver",
224 G_CALLBACK(handle_load_driver), NULL);
225 g_signal_connect(wifi_object, "handle-remove-driver",
226 G_CALLBACK(handle_remove_driver), NULL);
227 g_signal_connect(wifi_object, "handle-load-p2p-driver",
228 G_CALLBACK(handle_load_p2p_driver), NULL);
229 g_signal_connect(wifi_object, "handle-remove-p2p-driver",
230 G_CALLBACK(handle_remove_p2p_driver), NULL);
233 g_signal_connect(wifi_object, "handle-request-bssid-scan",
234 G_CALLBACK(handle_request_bssid_scan), NULL);
235 g_signal_connect(wifi_object, "handle-get-bssid-list",
236 G_CALLBACK(handle_get_bssid_list), NULL);
237 g_signal_connect(wifi_object, "handle-netlink-scan",
238 G_CALLBACK(handle_netlink_scan), NULL);
241 g_signal_connect(wifi_object, "handle-request-wps-connect",
242 G_CALLBACK(handle_request_wps_connect), NULL);
243 g_signal_connect(wifi_object, "handle-request-wps-cancel",
244 G_CALLBACK(handle_request_wps_cancel), NULL);
247 g_signal_connect(wifi_object, "handle-launch-direct",
248 G_CALLBACK(handle_launch_direct), NULL);
251 g_signal_connect(wifi_object, "handle-create-eap-config",
252 G_CALLBACK(handle_create_eap_config), NULL);
253 g_signal_connect(wifi_object, "handle-delete-eap-config",
254 G_CALLBACK(handle_delete_eap_config), NULL);
257 g_signal_connect(wifi_object, "handle-add-vsie",
258 G_CALLBACK(handle_add_vsie), NULL);
259 g_signal_connect(wifi_object, "handle-get-vsie",
260 G_CALLBACK(handle_get_vsie), NULL);
261 g_signal_connect(wifi_object, "handle-remove-vsie",
262 G_CALLBACK(handle_remove_vsie), NULL);
264 /* IP conflict methods */
265 g_signal_connect(wifi_object, "handle-ip-conflict-set-enable",
266 G_CALLBACK(handle_ip_conflict_set_enable), NULL);
267 g_signal_connect(wifi_object, "handle-is-ip-conflict-detect-enabled",
268 G_CALLBACK(handle_is_ip_conflict_detect_enabled), NULL);
269 g_signal_connect(wifi_object, "handle-set-ip-conflict-period",
270 G_CALLBACK(handle_set_ip_conflict_period), NULL);
271 g_signal_connect(wifi_object, "handle-get-ip-conflict-state",
272 G_CALLBACK(handle_get_ip_conflict_state), NULL);
273 g_signal_connect(wifi_object, "handle-get-ip-conflict-period",
274 G_CALLBACK(handle_get_ip_conflict_period), NULL);
276 /* WIFI configuration */
277 g_signal_connect(wifi_object, "handle-save-configuration",
278 G_CALLBACK(handle_save_configuration), NULL);
279 g_signal_connect(wifi_object, "handle-remove-configuration",
280 G_CALLBACK(handle_remove_configuration), NULL);
281 g_signal_connect(wifi_object, "handle-reset-wifi-config",
282 G_CALLBACK(handle_reset_wifi_config), NULL);
283 g_signal_connect(wifi_object, "handle-get-config-ids",
284 G_CALLBACK(handle_get_config_ids), NULL);
285 g_signal_connect(wifi_object, "handle-load-configuration",
286 G_CALLBACK(handle_load_configuration), NULL);
287 g_signal_connect(wifi_object, "handle-set-config-field",
288 G_CALLBACK(handle_set_config_field), NULL);
289 g_signal_connect(wifi_object, "handle-get-config-passphrase",
290 G_CALLBACK(handle_get_config_passphrase), NULL);
292 /* WIFI EAP configuration */
293 g_signal_connect(wifi_object, "handle-save-eap-configuration",
294 G_CALLBACK(handle_save_eap_configuration), NULL);
295 g_signal_connect(wifi_object, "handle-load-eap-configuration",
296 G_CALLBACK(handle_load_eap_configuration), NULL);
299 g_signal_connect(wifi_object, "handle-set-bgscan",
300 G_CALLBACK(handle_set_bgscan), NULL);
301 g_signal_connect(wifi_object, "handle-set-bgscan-interval",
302 G_CALLBACK(handle_set_bgscan_interval), NULL);
303 g_signal_connect(wifi_object, "handle-get-bgscan-interval",
304 G_CALLBACK(handle_get_bgscan_interval), NULL);
305 g_signal_connect(wifi_object, "handle-resume-bgscan",
306 G_CALLBACK(handle_resume_bgscan), NULL);
307 g_signal_connect(wifi_object, "handle-pause-bgscan",
308 G_CALLBACK(handle_pause_bgscan), NULL);
309 g_signal_connect(wifi_object, "handle-reset-bgscan-interval",
310 G_CALLBACK(handle_reset_bgscan_interval), NULL);
313 g_signal_connect(wifi_object, "handle-get-autoscan",
314 G_CALLBACK(handle_get_autoscan), NULL);
315 g_signal_connect(wifi_object, "handle-get-autoscanmode",
316 G_CALLBACK(handle_get_autoscanmode), NULL);
318 /* Extension API methods */
319 g_signal_connect(wifi_object, "handle-flush-bss",
320 G_CALLBACK(handle_flush_bss), NULL);
323 g_signal_connect(wifi_object, "handle-set-passpoint",
324 G_CALLBACK(handle_set_passpoint), NULL);
325 g_signal_connect(wifi_object, "handle-get-passpoint",
326 G_CALLBACK(handle_get_passpoint), NULL);
328 /* EAP authentication */
329 g_signal_connect(wifi_object, "handle-get-aka-auth",
330 G_CALLBACK(handle_get_aka_auth), NULL);
331 g_signal_connect(wifi_object, "handle-get-sim-auth",
332 G_CALLBACK(handle_get_sim_auth), NULL);
333 g_signal_connect(wifi_object, "handle-get-sim-imsi",
334 G_CALLBACK(handle_get_sim_imsi), NULL);
335 g_signal_connect(wifi_object, "handle-req-aka-auth",
336 G_CALLBACK(handle_req_aka_auth), NULL);
337 g_signal_connect(wifi_object, "handle-req-sim-auth",
338 G_CALLBACK(handle_req_sim_auth), NULL);
340 /* WIFI MDM blacklist */
341 g_signal_connect(wifi_object, "handle-check-black-list",
342 G_CALLBACK(handle_check_black_list), NULL);
345 g_signal_connect(wifi_object, "handle-tdls-disconnect",
346 G_CALLBACK(handle_tdls_disconnect), NULL);
347 g_signal_connect(wifi_object, "handle-tdls-connected-peer",
348 G_CALLBACK(handle_tdls_connected_peer), NULL);
349 g_signal_connect(wifi_object, "handle-tdls-discover",
350 G_CALLBACK(handle_tdls_discover), NULL);
351 g_signal_connect(wifi_object, "handle-tdls-connect",
352 G_CALLBACK(handle_tdls_connect), NULL);
353 g_signal_connect(wifi_object, "handle-tdls-channel-switch",
354 G_CALLBACK(handle_tdls_channel_switch), NULL);
355 g_signal_connect(wifi_object, "handle-tdls-cancel-channel-switch",
356 G_CALLBACK(handle_tdls_cancel_channel_switch), NULL);
358 /* Passphrase Encryption */
359 g_signal_connect(wifi_object, "handle-encrypt-passphrase",
360 G_CALLBACK(handle_encrypt_passphrase), NULL);
361 g_signal_connect(wifi_object, "handle-decrypt-passphrase",
362 G_CALLBACK(handle_decrypt_passphrase), NULL);
363 g_signal_connect(wifi_object, "handle-decrypt-conf-obj",
364 G_CALLBACK(handle_decrypt_conf_obj), NULL);
367 g_signal_connect(wifi_object, "handle-dpp-enter-peer-uri",
368 G_CALLBACK(handle_dpp_enter_peer_uri), NULL);
369 g_signal_connect(wifi_object, "handle-dpp-generate-uri",
370 G_CALLBACK(handle_dpp_generate_uri), NULL);
371 g_signal_connect(wifi_object, "handle-dpp-start-configurator-initiator",
372 G_CALLBACK(handle_dpp_start_configurator_initiator), NULL);
373 g_signal_connect(wifi_object, "handle-dpp-start-enrollee-initiator",
374 G_CALLBACK(handle_dpp_start_enrollee_initiator), NULL);
375 g_signal_connect(wifi_object, "handle-dpp-start-configurator-responder",
376 G_CALLBACK(handle_dpp_start_configurator_responder), NULL);
377 g_signal_connect(wifi_object, "handle-dpp-start-enrollee-responder",
378 G_CALLBACK(handle_dpp_start_enrollee_responder), NULL);
379 g_signal_connect(wifi_object, "handle-dpp-stop",
380 G_CALLBACK(handle_dpp_stop), NULL);
382 if (!g_dbus_interface_skeleton_export(interface_wifi, connection,
383 NETCONFIG_WIFI_PATH, NULL)) {
384 ERR("Export WIFI_PATH for wifi failed");
387 /* Interface connman.Agent */
388 connman_agent_object = net_connman_agent_skeleton_new();
390 interface_connman_agent = G_DBUS_INTERFACE_SKELETON(connman_agent_object);
391 g_signal_connect(connman_agent_object, "handle-report-error",
392 G_CALLBACK(handle_report_error), NULL);
393 g_signal_connect(connman_agent_object, "handle-request-browser",
394 G_CALLBACK(handle_request_browser), NULL);
395 g_signal_connect(connman_agent_object, "handle-request-input",
396 G_CALLBACK(handle_request_input), NULL);
397 g_signal_connect(connman_agent_object, "handle-set-field",
398 G_CALLBACK(handle_set_field), NULL);
400 if (!g_dbus_interface_skeleton_export(interface_connman_agent, connection,
401 NETCONFIG_WIFI_PATH, NULL)) {
402 ERR("Export WIFI_PATH for agent failed");
405 /*Interface netconfig.wifi.Firmware*/
406 wififirmware_object = wifi_firmware_skeleton_new();
408 interface_wifi_firmware = G_DBUS_INTERFACE_SKELETON(wififirmware_object);
409 g_signal_connect(wififirmware_object, "handle-start",
410 G_CALLBACK(handle_start), NULL);
411 g_signal_connect(wififirmware_object, "handle-stop",
412 G_CALLBACK(handle_stop), NULL);
414 if (!g_dbus_interface_skeleton_export(interface_wifi_firmware, connection,
415 NETCONFIG_WIFI_PATH, NULL)) {
416 ERR("Export WIFI_PATH for firmware failed");
419 _set_wifi_mac_address();
421 wifi_state_initialize();
422 wifi_power_initialize();
427 void wifi_object_deinit(void)
429 g_object_unref(wifi_object);
430 g_object_unref(connman_agent_object);
431 g_object_unref(wififirmware_object);
433 wifi_power_deinitialize();
434 wifi_state_deinitialize();
436 g_free(wifi_def_mac);