ea1b2d74541315ba7454b4f9d51250c20f4ea117
[platform/core/connectivity/net-config.git] / src / wifi.c
1 /*
2  * Network Configuration Module
3  *
4  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20 #include <stdio.h>
21 #include <unistd.h>
22 #include <vconf.h>
23 #include <vconf-keys.h>
24
25 #include "log.h"
26 #include "wifi.h"
27 #include "util.h"
28 #include "netdbus.h"
29 #include "neterror.h"
30 #include "wifi-eap.h"
31 #include "wifi-wps.h"
32 #include "wifi-power.h"
33 #include "wifi-state.h"
34 #include "wifi-agent.h"
35 #include "wifi-firmware.h"
36 #include "wifi-ssid-scan.h"
37 #include "wifi-passpoint.h"
38 #include "wifi-eap-config.h"
39 #include "wifi-background-scan.h"
40 #include "wifi-config.h"
41 #include "wifi-tdls.h"
42
43 static Wifi *wifi_object = NULL;
44 static NetConnmanAgent *connman_agent_object = NULL;
45 static WifiFirmware *wififirmware_object = NULL;
46
47 Wifi *get_wifi_object(void){
48         return wifi_object;
49 }
50
51 static gboolean handle_check_black_list(Wifi *wifi, GDBusMethodInvocation *context,
52                 const gchar *name, const gchar *security_type, const gchar *eap)
53 {
54         ERR("Name (%s)", name);
55         INFO("disable to check");
56         wifi_complete_check_black_list (wifi, context, TRUE);
57         return TRUE;
58 }
59
60 static void _set_wifi_mac_address(void)
61 {
62         gchar *mac_addr = NULL;
63
64         mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
65         if (mac_addr != NULL) {
66                 if (strlen(mac_addr) == 0)
67                         netconfig_set_mac_address_from_file();
68                 g_free(mac_addr);
69         }
70 }
71
72 void __netconfig_wifi_connect_reply(GObject *source_object, GAsyncResult *res,
73                 gpointer user_data)
74 {
75         GDBusConnection *conn = NULL;
76         GError *error = NULL;
77
78         DBG("WiFi Connection Reply");
79
80         conn = G_DBUS_CONNECTION(source_object);
81         g_dbus_connection_call_finish(conn, res, &error);
82         if (error != NULL) {
83                 ERR("WiFi Connection Error [%s]", error->message);
84                 g_error_free(error);
85                 if (netconfig_dbus_emit_signal(NULL, NETCONFIG_WIFI_PATH,
86                                 NETCONFIG_WIFI_INTERFACE, "WiFiConnectFail",
87                                 NULL) == FALSE)
88                         ERR("Failed to emit WiFiConnectFail signal");
89                 else
90                         DBG("Successfully sent WiFiConnectFail signal");
91         } else
92                 DBG("WiFi Connection has been initiated successfully");
93
94         netconfig_gdbus_pending_call_unref();
95         return;
96 }
97
98 void wifi_object_create_and_init(void)
99 {
100         DBG("Create wifi object.");
101         GDBusInterfaceSkeleton *interface_wifi = NULL;
102         GDBusInterfaceSkeleton *interface_connman_agent = NULL;
103         GDBusInterfaceSkeleton *interface_wifi_firmware = NULL;
104         GDBusConnection *connection = NULL;
105         GDBusObjectManagerServer *server = netdbus_get_wifi_manager();
106         if (server == NULL)
107                 return;
108
109         connection = netdbus_get_connection();
110         g_dbus_object_manager_server_set_connection(server, connection);
111
112         /*Interface netconfig.wifi*/
113         wifi_object = wifi_skeleton_new();
114         interface_wifi = G_DBUS_INTERFACE_SKELETON(wifi_object);
115
116         // WIFI power
117         g_signal_connect(wifi_object, "handle-load-driver",
118                         G_CALLBACK(handle_load_driver), NULL);
119         g_signal_connect(wifi_object, "handle-remove-driver",
120                         G_CALLBACK(handle_remove_driver), NULL);
121         g_signal_connect(wifi_object, "handle-load-p2p-driver",
122                                 G_CALLBACK(handle_load_p2p_driver), NULL);
123         g_signal_connect(wifi_object, "handle-remove-p2p-driver",
124                         G_CALLBACK(handle_remove_p2p_driver), NULL);
125
126         // WIFI state
127         g_signal_connect(wifi_object, "handle-get-wifi-state",
128                         G_CALLBACK(handle_get_wifi_state), NULL);
129
130         // WIFI scan
131         g_signal_connect(wifi_object, "handle-request-specific-scan",
132                         G_CALLBACK(handle_request_specific_scan), NULL);
133         g_signal_connect(wifi_object, "handle-request-wps-scan",
134                         G_CALLBACK(handle_request_wps_scan), NULL);
135
136         // WIFI direct
137         g_signal_connect(wifi_object, "handle-launch-direct",
138                         G_CALLBACK(handle_launch_direct), NULL);
139
140         // EAP config
141         g_signal_connect(wifi_object, "handle-create-eap-config",
142                         G_CALLBACK(handle_create_eap_config), NULL);
143         g_signal_connect(wifi_object, "handle-delete-eap-config",
144                         G_CALLBACK(handle_delete_eap_config), NULL);
145
146         // WIFI configuration
147         g_signal_connect(wifi_object, "handle-save-configuration",
148                         G_CALLBACK(handle_save_configuration), NULL);
149         g_signal_connect(wifi_object, "handle-remove-configuration",
150                         G_CALLBACK(handle_remove_configuration), NULL);
151         g_signal_connect(wifi_object, "handle-get-config-ids",
152                         G_CALLBACK(handle_get_config_ids), NULL);
153         g_signal_connect(wifi_object, "handle-load-configuration",
154                         G_CALLBACK(handle_load_configuration), NULL);
155         g_signal_connect(wifi_object, "handle-set-config-field",
156                         G_CALLBACK(handle_set_config_field), NULL);
157         g_signal_connect(wifi_object, "handle-get-config-passphrase",
158                         G_CALLBACK(handle_get_config_passphrase), NULL);
159         // WIFI EAP configuration
160         g_signal_connect(wifi_object, "handle-save-eap-configuration",
161                         G_CALLBACK(handle_save_eap_configuration), NULL);
162         g_signal_connect(wifi_object, "handle-load-eap-configuration",
163                         G_CALLBACK(handle_load_eap_configuration), NULL);
164
165         // BG scan mode
166         g_signal_connect(wifi_object, "handle-set-bgscan",
167                         G_CALLBACK(handle_set_bgscan), NULL);
168         g_signal_connect(wifi_object, "handle-resume-bgscan",
169                         G_CALLBACK(handle_resume_bgscan), NULL);
170         g_signal_connect(wifi_object, "handle-pause-bgscan",
171                         G_CALLBACK(handle_pause_bgscan), NULL);
172
173         // Passpoint
174         g_signal_connect(wifi_object, "handle-set-passpoint",
175                                 G_CALLBACK(handle_set_passpoint), NULL);
176         g_signal_connect(wifi_object, "handle-get-passpoint",
177                                         G_CALLBACK(handle_get_passpoint), NULL);
178
179         // EAP authentication
180         g_signal_connect(wifi_object, "handle-get-aka-auth",
181                                 G_CALLBACK(handle_get_aka_auth), NULL);
182         g_signal_connect(wifi_object, "handle-get-sim-auth",
183                                 G_CALLBACK(handle_get_sim_auth), NULL);
184         g_signal_connect(wifi_object, "handle-get-sim-imsi",
185                                 G_CALLBACK(handle_get_sim_imsi), NULL);
186         g_signal_connect(wifi_object, "handle-req-aka-auth",
187                         G_CALLBACK(handle_req_aka_auth), NULL);
188         g_signal_connect(wifi_object, "handle-req-sim-auth",
189                         G_CALLBACK(handle_req_sim_auth), NULL);
190
191         // WIFI MDM blacklist
192         g_signal_connect(wifi_object, "handle-check-black-list",
193                         G_CALLBACK(handle_check_black_list), NULL);
194
195         //TDLS methods
196         g_signal_connect(wifi_object, "handle-tdls-disconnect",
197                         G_CALLBACK(handle_tdls_disconnect), NULL);
198         g_signal_connect(wifi_object, "handle-tdls-connected-peer",
199                         G_CALLBACK(handle_tdls_connected_peer), NULL);
200
201         if (!g_dbus_interface_skeleton_export(interface_wifi, connection,
202                         NETCONFIG_WIFI_PATH, NULL)) {
203                 ERR("Export WIFI_PATH for wifi failed");
204         }
205
206         /*Interface connman.Agent*/
207         connman_agent_object = net_connman_agent_skeleton_new();
208
209         interface_connman_agent = G_DBUS_INTERFACE_SKELETON(connman_agent_object);
210         g_signal_connect(connman_agent_object, "handle-report-error",
211                         G_CALLBACK(handle_report_error), NULL);
212         g_signal_connect(connman_agent_object, "handle-request-browser",
213                         G_CALLBACK(handle_request_browser), NULL);
214         g_signal_connect(connman_agent_object, "handle-request-input",
215                         G_CALLBACK(handle_request_input), NULL);
216         g_signal_connect(connman_agent_object, "handle-set-field",
217                         G_CALLBACK(handle_set_field), NULL);
218
219         if (!g_dbus_interface_skeleton_export(interface_connman_agent, connection,
220                         NETCONFIG_WIFI_PATH, NULL)) {
221                 ERR("Export WIFI_PATH for agent failed");
222         }
223
224         /*Interface netconfig.wifi.Firmware*/
225         wififirmware_object = wifi_firmware_skeleton_new();
226
227         interface_wifi_firmware = G_DBUS_INTERFACE_SKELETON(wififirmware_object);
228         g_signal_connect(wififirmware_object, "handle-start",
229                         G_CALLBACK(handle_start), NULL);
230         g_signal_connect(wififirmware_object, "handle-stop",
231                                 G_CALLBACK(handle_stop), NULL);
232
233         if (!g_dbus_interface_skeleton_export(interface_wifi_firmware, connection,
234                         NETCONFIG_WIFI_PATH, NULL)) {
235                 ERR("Export WIFI_PATH for firmware failed");
236         }
237
238         _set_wifi_mac_address();
239
240         wifi_power_initialize();
241
242         return;
243 }
244
245 void wifi_object_deinit(void)
246 {
247         g_object_unref(wifi_object);
248         g_object_unref(connman_agent_object);
249         g_object_unref(wififirmware_object);
250
251         wifi_power_deinitialize();
252 }