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>
33 #include "wifi-bssid-scan.h"
34 #include "wifi-netlink-scan.h"
35 #include "wifi-power.h"
36 #include "wifi-state.h"
37 #include "wifi-agent.h"
38 #include "wifi-firmware.h"
39 #include "wifi-passpoint.h"
40 #include "wifi-eap-config.h"
41 #include "wifi-background-scan.h"
42 #include "ip-conflict-detect.h"
43 #include "wifi-config.h"
44 #include "wifi-tdls.h"
45 #include "wifi-key-encryption.h"
46 #include "wifi-extension.h"
48 #define SPRD_CP2_FIRMWARE_PATH "/usr/bin/cp2-downloader"
49 static int is_wifi_firmware_downloaded = FALSE;
51 static Wifi *wifi_object = NULL;
52 static NetConnmanAgent *connman_agent_object = NULL;
53 static WifiFirmware *wififirmware_object = NULL;
55 Wifi *get_wifi_object(void){
59 static gboolean handle_check_black_list(Wifi *wifi, GDBusMethodInvocation *context,
60 const gchar *name, const gchar *security_type, const gchar *eap)
62 ERR("Name (%s)", name);
63 INFO("disable to check");
64 wifi_complete_check_black_list(wifi, context, TRUE);
68 static void _set_wifi_mac_address(void)
70 gchar *mac_addr = NULL;
72 mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
73 if (mac_addr != NULL) {
74 if (strlen(mac_addr) == 0)
75 netconfig_set_mac_address_from_file();
80 void __netconfig_wifi_connect_reply(GObject *source_object, GAsyncResult *res,
83 GDBusConnection *conn = NULL;
86 DBG("WiFi Connection Reply");
88 conn = G_DBUS_CONNECTION(source_object);
89 g_dbus_connection_call_finish(conn, res, &error);
91 ERR("WiFi Connection Error [%s]", error->message);
92 /* No need to emit WiFiConnectFail signal if Connection is
94 if (error->code == G_IO_ERROR_TIMED_OUT) {
96 DBG("WiFi Connection in Progress");
97 netconfig_gdbus_pending_call_unref();
101 if (netconfig_dbus_emit_signal(NULL, NETCONFIG_WIFI_PATH,
102 NETCONFIG_WIFI_INTERFACE, "WiFiConnectFail",
104 ERR("Failed to emit WiFiConnectFail signal");
106 DBG("Successfully sent WiFiConnectFail signal");
108 DBG("WiFi Connection has been initiated successfully");
110 netconfig_gdbus_pending_call_unref();
114 int wifi_firmware_download(void)
117 const char *path = SPRD_CP2_FIRMWARE_PATH;
118 char *const args[] = { SPRD_CP2_FIRMWARE_PATH, NULL };
119 char *const envs[] = { NULL };
121 if (!is_wifi_firmware_downloaded) {
122 rv = netconfig_execute_file(path, args, envs);
124 DBG("wifi firmware download fails");
127 is_wifi_firmware_downloaded = TRUE;
128 DBG("wifi firmware download successes");
134 void wifi_object_create_and_init(void)
136 DBG("Create wifi object.");
137 GDBusInterfaceSkeleton *interface_wifi = NULL;
138 GDBusInterfaceSkeleton *interface_connman_agent = NULL;
139 GDBusInterfaceSkeleton *interface_wifi_firmware = NULL;
140 GDBusConnection *connection = NULL;
141 GDBusObjectManagerServer *server = netdbus_get_wifi_manager();
145 connection = netdbus_get_connection();
146 g_dbus_object_manager_server_set_connection(server, connection);
148 /*Interface netconfig.wifi*/
149 wifi_object = wifi_skeleton_new();
150 interface_wifi = G_DBUS_INTERFACE_SKELETON(wifi_object);
153 g_signal_connect(wifi_object, "handle-load-driver",
154 G_CALLBACK(handle_load_driver), NULL);
155 g_signal_connect(wifi_object, "handle-remove-driver",
156 G_CALLBACK(handle_remove_driver), NULL);
157 g_signal_connect(wifi_object, "handle-load-p2p-driver",
158 G_CALLBACK(handle_load_p2p_driver), NULL);
159 g_signal_connect(wifi_object, "handle-remove-p2p-driver",
160 G_CALLBACK(handle_remove_p2p_driver), NULL);
163 g_signal_connect(wifi_object, "handle-get-wifi-state",
164 G_CALLBACK(handle_get_wifi_state), NULL);
167 g_signal_connect(wifi_object, "handle-request-bssid-scan",
168 G_CALLBACK(handle_request_bssid_scan), NULL);
169 g_signal_connect(wifi_object, "handle-get-bssid-list",
170 G_CALLBACK(handle_get_bssid_list), NULL);
171 g_signal_connect(wifi_object, "handle-netlink-scan",
172 G_CALLBACK(handle_netlink_scan), NULL);
175 g_signal_connect(wifi_object, "handle-request-wps-connect",
176 G_CALLBACK(handle_request_wps_connect), NULL);
177 g_signal_connect(wifi_object, "handle-request-wps-cancel",
178 G_CALLBACK(handle_request_wps_cancel), NULL);
181 g_signal_connect(wifi_object, "handle-launch-direct",
182 G_CALLBACK(handle_launch_direct), NULL);
185 g_signal_connect(wifi_object, "handle-create-eap-config",
186 G_CALLBACK(handle_create_eap_config), NULL);
187 g_signal_connect(wifi_object, "handle-delete-eap-config",
188 G_CALLBACK(handle_delete_eap_config), NULL);
191 g_signal_connect(wifi_object, "handle-add-vsie",
192 G_CALLBACK(handle_add_vsie), NULL);
193 g_signal_connect(wifi_object, "handle-get-vsie",
194 G_CALLBACK(handle_get_vsie), NULL);
195 g_signal_connect(wifi_object, "handle-remove-vsie",
196 G_CALLBACK(handle_remove_vsie), NULL);
198 /* IP conflict methods */
199 g_signal_connect(wifi_object, "handle-ip-conflict-set-enable",
200 G_CALLBACK(handle_ip_conflict_set_enable), NULL);
201 g_signal_connect(wifi_object, "handle-is-ip-conflict-detect-enabled",
202 G_CALLBACK(handle_is_ip_conflict_detect_enabled), NULL);
203 g_signal_connect(wifi_object, "handle-set-ip-conflict-period",
204 G_CALLBACK(handle_set_ip_conflict_period), NULL);
205 g_signal_connect(wifi_object, "handle-get-ip-conflict-state",
206 G_CALLBACK(handle_get_ip_conflict_state), NULL);
207 g_signal_connect(wifi_object, "handle-get-ip-conflict-period",
208 G_CALLBACK(handle_get_ip_conflict_period), NULL);
210 /* WIFI configuration */
211 g_signal_connect(wifi_object, "handle-save-configuration",
212 G_CALLBACK(handle_save_configuration), NULL);
213 g_signal_connect(wifi_object, "handle-remove-configuration",
214 G_CALLBACK(handle_remove_configuration), NULL);
215 g_signal_connect(wifi_object, "handle-get-config-ids",
216 G_CALLBACK(handle_get_config_ids), NULL);
217 g_signal_connect(wifi_object, "handle-load-configuration",
218 G_CALLBACK(handle_load_configuration), NULL);
219 g_signal_connect(wifi_object, "handle-set-config-field",
220 G_CALLBACK(handle_set_config_field), NULL);
221 g_signal_connect(wifi_object, "handle-get-config-passphrase",
222 G_CALLBACK(handle_get_config_passphrase), NULL);
224 /* WIFI EAP configuration */
225 g_signal_connect(wifi_object, "handle-save-eap-configuration",
226 G_CALLBACK(handle_save_eap_configuration), NULL);
227 g_signal_connect(wifi_object, "handle-load-eap-configuration",
228 G_CALLBACK(handle_load_eap_configuration), NULL);
231 g_signal_connect(wifi_object, "handle-set-bgscan",
232 G_CALLBACK(handle_set_bgscan), NULL);
233 g_signal_connect(wifi_object, "handle-resume-bgscan",
234 G_CALLBACK(handle_resume_bgscan), NULL);
235 g_signal_connect(wifi_object, "handle-pause-bgscan",
236 G_CALLBACK(handle_pause_bgscan), NULL);
237 g_signal_connect(wifi_object, "handle-reset-bgscan-interval",
238 G_CALLBACK(handle_reset_bgscan_interval), NULL);
241 g_signal_connect(wifi_object, "handle-get-autoscan",
242 G_CALLBACK(handle_get_autoscan), NULL);
243 g_signal_connect(wifi_object, "handle-get-autoscanmode",
244 G_CALLBACK(handle_get_autoscanmode), NULL);
246 /* Extension API methods */
247 g_signal_connect(wifi_object, "handle-flush-bss",
248 G_CALLBACK(handle_flush_bss), NULL);
251 g_signal_connect(wifi_object, "handle-set-passpoint",
252 G_CALLBACK(handle_set_passpoint), NULL);
253 g_signal_connect(wifi_object, "handle-get-passpoint",
254 G_CALLBACK(handle_get_passpoint), NULL);
256 /* EAP authentication */
257 g_signal_connect(wifi_object, "handle-get-aka-auth",
258 G_CALLBACK(handle_get_aka_auth), NULL);
259 g_signal_connect(wifi_object, "handle-get-sim-auth",
260 G_CALLBACK(handle_get_sim_auth), NULL);
261 g_signal_connect(wifi_object, "handle-get-sim-imsi",
262 G_CALLBACK(handle_get_sim_imsi), NULL);
263 g_signal_connect(wifi_object, "handle-req-aka-auth",
264 G_CALLBACK(handle_req_aka_auth), NULL);
265 g_signal_connect(wifi_object, "handle-req-sim-auth",
266 G_CALLBACK(handle_req_sim_auth), NULL);
268 /* WIFI MDM blacklist */
269 g_signal_connect(wifi_object, "handle-check-black-list",
270 G_CALLBACK(handle_check_black_list), NULL);
273 g_signal_connect(wifi_object, "handle-tdls-disconnect",
274 G_CALLBACK(handle_tdls_disconnect), NULL);
275 g_signal_connect(wifi_object, "handle-tdls-connected-peer",
276 G_CALLBACK(handle_tdls_connected_peer), NULL);
277 g_signal_connect(wifi_object, "handle-tdls-discover",
278 G_CALLBACK(handle_tdls_discover), NULL);
279 g_signal_connect(wifi_object, "handle-tdls-connect",
280 G_CALLBACK(handle_tdls_connect), NULL);
281 g_signal_connect(wifi_object, "handle-tdls-channel-switch",
282 G_CALLBACK(handle_tdls_channel_switch), NULL);
283 g_signal_connect(wifi_object, "handle-tdls-cancel-channel-switch",
284 G_CALLBACK(handle_tdls_cancel_channel_switch), NULL);
286 /* Passphrase Encryption */
287 g_signal_connect(wifi_object, "handle-encrypt-passphrase",
288 G_CALLBACK(handle_encrypt_passphrase), NULL);
289 g_signal_connect(wifi_object, "handle-decrypt-passphrase",
290 G_CALLBACK(handle_decrypt_passphrase), NULL);
292 if (!g_dbus_interface_skeleton_export(interface_wifi, connection,
293 NETCONFIG_WIFI_PATH, NULL)) {
294 ERR("Export WIFI_PATH for wifi failed");
297 /* Interface connman.Agent */
298 connman_agent_object = net_connman_agent_skeleton_new();
300 interface_connman_agent = G_DBUS_INTERFACE_SKELETON(connman_agent_object);
301 g_signal_connect(connman_agent_object, "handle-report-error",
302 G_CALLBACK(handle_report_error), NULL);
303 g_signal_connect(connman_agent_object, "handle-request-browser",
304 G_CALLBACK(handle_request_browser), NULL);
305 g_signal_connect(connman_agent_object, "handle-request-input",
306 G_CALLBACK(handle_request_input), NULL);
307 g_signal_connect(connman_agent_object, "handle-set-field",
308 G_CALLBACK(handle_set_field), NULL);
310 if (!g_dbus_interface_skeleton_export(interface_connman_agent, connection,
311 NETCONFIG_WIFI_PATH, NULL)) {
312 ERR("Export WIFI_PATH for agent failed");
315 /*Interface netconfig.wifi.Firmware*/
316 wififirmware_object = wifi_firmware_skeleton_new();
318 interface_wifi_firmware = G_DBUS_INTERFACE_SKELETON(wififirmware_object);
319 g_signal_connect(wififirmware_object, "handle-start",
320 G_CALLBACK(handle_start), NULL);
321 g_signal_connect(wififirmware_object, "handle-stop",
322 G_CALLBACK(handle_stop), NULL);
324 if (!g_dbus_interface_skeleton_export(interface_wifi_firmware, connection,
325 NETCONFIG_WIFI_PATH, NULL)) {
326 ERR("Export WIFI_PATH for firmware failed");
329 _set_wifi_mac_address();
331 wifi_power_initialize();
336 void wifi_object_deinit(void)
338 g_object_unref(wifi_object);
339 g_object_unref(connman_agent_object);
340 g_object_unref(wififirmware_object);
342 wifi_power_deinitialize();