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)
119 mode_t mode = S_IRGRP | S_IWUSR | S_IXGRP;
121 if (creat(SPRD_CP2_FIRMWARE_STATE_PATH, mode) < 0)
122 DBG("Failed to create wifi firmware state file");
124 is_wifi_firmware_downloaded = TRUE;
127 static int _get_wifi_firmware_state(void)
129 if (!is_wifi_firmware_downloaded
130 && access(SPRD_CP2_FIRMWARE_STATE_PATH, F_OK) != 0)
131 is_wifi_firmware_downloaded = FALSE;
133 is_wifi_firmware_downloaded = TRUE;
134 return is_wifi_firmware_downloaded;
137 int wifi_firmware_download(void)
140 const char *path = SPRD_CP2_FIRMWARE_PATH;
141 char *const args[] = { SPRD_CP2_FIRMWARE_PATH, NULL };
142 char *const envs[] = { NULL };
144 if (!_get_wifi_firmware_state()) {
145 rv = netconfig_execute_file(path, args, envs);
147 DBG("wifi firmware download fails");
150 _update_wifi_firmware_state();
151 DBG("wifi firmware download successes");
157 void wifi_object_create_and_init(void)
159 DBG("Create wifi object.");
160 GDBusInterfaceSkeleton *interface_wifi = NULL;
161 GDBusInterfaceSkeleton *interface_connman_agent = NULL;
162 GDBusInterfaceSkeleton *interface_wifi_firmware = NULL;
163 GDBusConnection *connection = NULL;
164 GDBusObjectManagerServer *server = netdbus_get_wifi_manager();
168 connection = netdbus_get_connection();
169 g_dbus_object_manager_server_set_connection(server, connection);
171 /*Interface netconfig.wifi*/
172 wifi_object = wifi_skeleton_new();
173 interface_wifi = G_DBUS_INTERFACE_SKELETON(wifi_object);
176 g_signal_connect(wifi_object, "handle-load-driver",
177 G_CALLBACK(handle_load_driver), NULL);
178 g_signal_connect(wifi_object, "handle-remove-driver",
179 G_CALLBACK(handle_remove_driver), NULL);
180 g_signal_connect(wifi_object, "handle-load-p2p-driver",
181 G_CALLBACK(handle_load_p2p_driver), NULL);
182 g_signal_connect(wifi_object, "handle-remove-p2p-driver",
183 G_CALLBACK(handle_remove_p2p_driver), NULL);
186 g_signal_connect(wifi_object, "handle-get-wifi-state",
187 G_CALLBACK(handle_get_wifi_state), NULL);
190 g_signal_connect(wifi_object, "handle-request-bssid-scan",
191 G_CALLBACK(handle_request_bssid_scan), NULL);
192 g_signal_connect(wifi_object, "handle-get-bssid-list",
193 G_CALLBACK(handle_get_bssid_list), NULL);
194 g_signal_connect(wifi_object, "handle-netlink-scan",
195 G_CALLBACK(handle_netlink_scan), NULL);
198 g_signal_connect(wifi_object, "handle-request-wps-connect",
199 G_CALLBACK(handle_request_wps_connect), NULL);
200 g_signal_connect(wifi_object, "handle-request-wps-cancel",
201 G_CALLBACK(handle_request_wps_cancel), NULL);
204 g_signal_connect(wifi_object, "handle-launch-direct",
205 G_CALLBACK(handle_launch_direct), NULL);
208 g_signal_connect(wifi_object, "handle-create-eap-config",
209 G_CALLBACK(handle_create_eap_config), NULL);
210 g_signal_connect(wifi_object, "handle-delete-eap-config",
211 G_CALLBACK(handle_delete_eap_config), NULL);
214 g_signal_connect(wifi_object, "handle-add-vsie",
215 G_CALLBACK(handle_add_vsie), NULL);
216 g_signal_connect(wifi_object, "handle-get-vsie",
217 G_CALLBACK(handle_get_vsie), NULL);
218 g_signal_connect(wifi_object, "handle-remove-vsie",
219 G_CALLBACK(handle_remove_vsie), NULL);
221 /* IP conflict methods */
222 g_signal_connect(wifi_object, "handle-ip-conflict-set-enable",
223 G_CALLBACK(handle_ip_conflict_set_enable), NULL);
224 g_signal_connect(wifi_object, "handle-is-ip-conflict-detect-enabled",
225 G_CALLBACK(handle_is_ip_conflict_detect_enabled), NULL);
226 g_signal_connect(wifi_object, "handle-set-ip-conflict-period",
227 G_CALLBACK(handle_set_ip_conflict_period), NULL);
228 g_signal_connect(wifi_object, "handle-get-ip-conflict-state",
229 G_CALLBACK(handle_get_ip_conflict_state), NULL);
230 g_signal_connect(wifi_object, "handle-get-ip-conflict-period",
231 G_CALLBACK(handle_get_ip_conflict_period), NULL);
233 /* WIFI configuration */
234 g_signal_connect(wifi_object, "handle-save-configuration",
235 G_CALLBACK(handle_save_configuration), NULL);
236 g_signal_connect(wifi_object, "handle-remove-configuration",
237 G_CALLBACK(handle_remove_configuration), NULL);
238 g_signal_connect(wifi_object, "handle-get-config-ids",
239 G_CALLBACK(handle_get_config_ids), NULL);
240 g_signal_connect(wifi_object, "handle-load-configuration",
241 G_CALLBACK(handle_load_configuration), NULL);
242 g_signal_connect(wifi_object, "handle-set-config-field",
243 G_CALLBACK(handle_set_config_field), NULL);
244 g_signal_connect(wifi_object, "handle-get-config-passphrase",
245 G_CALLBACK(handle_get_config_passphrase), NULL);
247 /* WIFI EAP configuration */
248 g_signal_connect(wifi_object, "handle-save-eap-configuration",
249 G_CALLBACK(handle_save_eap_configuration), NULL);
250 g_signal_connect(wifi_object, "handle-load-eap-configuration",
251 G_CALLBACK(handle_load_eap_configuration), NULL);
254 g_signal_connect(wifi_object, "handle-set-bgscan",
255 G_CALLBACK(handle_set_bgscan), NULL);
256 g_signal_connect(wifi_object, "handle-resume-bgscan",
257 G_CALLBACK(handle_resume_bgscan), NULL);
258 g_signal_connect(wifi_object, "handle-pause-bgscan",
259 G_CALLBACK(handle_pause_bgscan), NULL);
260 g_signal_connect(wifi_object, "handle-reset-bgscan-interval",
261 G_CALLBACK(handle_reset_bgscan_interval), NULL);
264 g_signal_connect(wifi_object, "handle-get-autoscan",
265 G_CALLBACK(handle_get_autoscan), NULL);
266 g_signal_connect(wifi_object, "handle-get-autoscanmode",
267 G_CALLBACK(handle_get_autoscanmode), NULL);
269 /* Extension API methods */
270 g_signal_connect(wifi_object, "handle-flush-bss",
271 G_CALLBACK(handle_flush_bss), NULL);
274 g_signal_connect(wifi_object, "handle-set-passpoint",
275 G_CALLBACK(handle_set_passpoint), NULL);
276 g_signal_connect(wifi_object, "handle-get-passpoint",
277 G_CALLBACK(handle_get_passpoint), NULL);
279 /* EAP authentication */
280 g_signal_connect(wifi_object, "handle-get-aka-auth",
281 G_CALLBACK(handle_get_aka_auth), NULL);
282 g_signal_connect(wifi_object, "handle-get-sim-auth",
283 G_CALLBACK(handle_get_sim_auth), NULL);
284 g_signal_connect(wifi_object, "handle-get-sim-imsi",
285 G_CALLBACK(handle_get_sim_imsi), NULL);
286 g_signal_connect(wifi_object, "handle-req-aka-auth",
287 G_CALLBACK(handle_req_aka_auth), NULL);
288 g_signal_connect(wifi_object, "handle-req-sim-auth",
289 G_CALLBACK(handle_req_sim_auth), NULL);
291 /* WIFI MDM blacklist */
292 g_signal_connect(wifi_object, "handle-check-black-list",
293 G_CALLBACK(handle_check_black_list), NULL);
296 g_signal_connect(wifi_object, "handle-tdls-disconnect",
297 G_CALLBACK(handle_tdls_disconnect), NULL);
298 g_signal_connect(wifi_object, "handle-tdls-connected-peer",
299 G_CALLBACK(handle_tdls_connected_peer), NULL);
300 g_signal_connect(wifi_object, "handle-tdls-discover",
301 G_CALLBACK(handle_tdls_discover), NULL);
302 g_signal_connect(wifi_object, "handle-tdls-connect",
303 G_CALLBACK(handle_tdls_connect), NULL);
304 g_signal_connect(wifi_object, "handle-tdls-channel-switch",
305 G_CALLBACK(handle_tdls_channel_switch), NULL);
306 g_signal_connect(wifi_object, "handle-tdls-cancel-channel-switch",
307 G_CALLBACK(handle_tdls_cancel_channel_switch), NULL);
309 /* Passphrase Encryption */
310 g_signal_connect(wifi_object, "handle-encrypt-passphrase",
311 G_CALLBACK(handle_encrypt_passphrase), NULL);
312 g_signal_connect(wifi_object, "handle-decrypt-passphrase",
313 G_CALLBACK(handle_decrypt_passphrase), NULL);
315 if (!g_dbus_interface_skeleton_export(interface_wifi, connection,
316 NETCONFIG_WIFI_PATH, NULL)) {
317 ERR("Export WIFI_PATH for wifi failed");
320 /* Interface connman.Agent */
321 connman_agent_object = net_connman_agent_skeleton_new();
323 interface_connman_agent = G_DBUS_INTERFACE_SKELETON(connman_agent_object);
324 g_signal_connect(connman_agent_object, "handle-report-error",
325 G_CALLBACK(handle_report_error), NULL);
326 g_signal_connect(connman_agent_object, "handle-request-browser",
327 G_CALLBACK(handle_request_browser), NULL);
328 g_signal_connect(connman_agent_object, "handle-request-input",
329 G_CALLBACK(handle_request_input), NULL);
330 g_signal_connect(connman_agent_object, "handle-set-field",
331 G_CALLBACK(handle_set_field), NULL);
333 if (!g_dbus_interface_skeleton_export(interface_connman_agent, connection,
334 NETCONFIG_WIFI_PATH, NULL)) {
335 ERR("Export WIFI_PATH for agent failed");
338 /*Interface netconfig.wifi.Firmware*/
339 wififirmware_object = wifi_firmware_skeleton_new();
341 interface_wifi_firmware = G_DBUS_INTERFACE_SKELETON(wififirmware_object);
342 g_signal_connect(wififirmware_object, "handle-start",
343 G_CALLBACK(handle_start), NULL);
344 g_signal_connect(wififirmware_object, "handle-stop",
345 G_CALLBACK(handle_stop), NULL);
347 if (!g_dbus_interface_skeleton_export(interface_wifi_firmware, connection,
348 NETCONFIG_WIFI_PATH, NULL)) {
349 ERR("Export WIFI_PATH for firmware failed");
352 _set_wifi_mac_address();
354 wifi_power_initialize();
359 void wifi_object_deinit(void)
361 g_object_unref(wifi_object);
362 g_object_unref(connman_agent_object);
363 g_object_unref(wififirmware_object);
365 wifi_power_deinitialize();