Sync with Tizen 2.4(v1.1.38)
[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
42 static Wifi *wifi_object = NULL;
43 static NetConnmanAgent *connman_agent_object = NULL;
44 static WifiFirmware *wififirmware_object = NULL;
45
46 Wifi *get_wifi_object(void){
47         return wifi_object;
48 }
49
50 static gboolean handle_check_black_list(Wifi *wifi, GDBusMethodInvocation *context,
51                 const gchar *name, const gchar *security_type, const gchar *eap)
52 {
53         ERR("Name (%s)", name);
54         INFO("disable to check");
55         wifi_complete_check_black_list (wifi, context, TRUE);
56         return TRUE;
57 }
58
59 static void _set_wifi_mac_address(void)
60 {
61         gchar *mac_addr = NULL;
62
63         mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
64         if (mac_addr != NULL) {
65                 if (strlen(mac_addr) == 0)
66                         netconfig_set_mac_address_from_file();
67                 g_free(mac_addr);
68         }
69 }
70
71 void wifi_object_create_and_init(void)
72 {
73         DBG("Create wifi object.");
74         GDBusInterfaceSkeleton *interface_wifi = NULL;
75         GDBusInterfaceSkeleton *interface_connman_agent = NULL;
76         GDBusInterfaceSkeleton *interface_wifi_firmware = NULL;
77         GDBusConnection *connection = NULL;
78         GDBusObjectManagerServer *server = netdbus_get_wifi_manager();
79         if (server == NULL)
80                 return;
81
82         connection = netdbus_get_connection();
83         g_dbus_object_manager_server_set_connection(server, connection);
84
85         /*Interface netconfig.wifi*/
86         wifi_object = wifi_skeleton_new();
87         interface_wifi = G_DBUS_INTERFACE_SKELETON(wifi_object);
88
89         // WIFI power
90         g_signal_connect(wifi_object, "handle-load-driver",
91                         G_CALLBACK(handle_load_driver), NULL);
92         g_signal_connect(wifi_object, "handle-remove-driver",
93                         G_CALLBACK(handle_remove_driver), NULL);
94         g_signal_connect(wifi_object, "handle-load-p2p-driver",
95                                 G_CALLBACK(handle_load_p2p_driver), NULL);
96         g_signal_connect(wifi_object, "handle-remove-p2p-driver",
97                         G_CALLBACK(handle_remove_p2p_driver), NULL);
98
99         // WIFI state
100         g_signal_connect(wifi_object, "handle-get-wifi-state",
101                         G_CALLBACK(handle_get_wifi_state), NULL);
102
103         // WIFI scan
104         g_signal_connect(wifi_object, "handle-request-specific-scan",
105                         G_CALLBACK(handle_request_specific_scan), NULL);
106         g_signal_connect(wifi_object, "handle-request-wps-scan",
107                         G_CALLBACK(handle_request_wps_scan), NULL);
108
109         // WIFI direct
110         g_signal_connect(wifi_object, "handle-launch-direct",
111                         G_CALLBACK(handle_launch_direct), NULL);
112
113         // EAP config
114         g_signal_connect(wifi_object, "handle-create-eap-config",
115                         G_CALLBACK(handle_create_eap_config), NULL);
116         g_signal_connect(wifi_object, "handle-delete-eap-config",
117                         G_CALLBACK(handle_delete_eap_config), NULL);
118
119         // WIFI configuration
120         g_signal_connect(wifi_object, "handle-save-configuration",
121                         G_CALLBACK(handle_save_configuration), NULL);
122         g_signal_connect(wifi_object, "handle-remove-configuration",
123                         G_CALLBACK(handle_remove_configuration), NULL);
124         g_signal_connect(wifi_object, "handle-get-config-ids",
125                         G_CALLBACK(handle_get_config_ids), NULL);
126         g_signal_connect(wifi_object, "handle-load-configuration",
127                         G_CALLBACK(handle_load_configuration), NULL);
128         g_signal_connect(wifi_object, "handle-set-config-field",
129                         G_CALLBACK(handle_set_config_field), NULL);
130         g_signal_connect(wifi_object, "handle-get-config-passphrase",
131                         G_CALLBACK(handle_get_config_passphrase), NULL);
132         // WIFI EAP configuration
133         g_signal_connect(wifi_object, "handle-save-eap-configuration",
134                         G_CALLBACK(handle_save_eap_configuration), NULL);
135         g_signal_connect(wifi_object, "handle-load-eap-configuration",
136                         G_CALLBACK(handle_load_eap_configuration), NULL);
137
138         // BG scan mode
139         g_signal_connect(wifi_object, "handle-set-bgscan",
140                         G_CALLBACK(handle_set_bgscan), NULL);
141         g_signal_connect(wifi_object, "handle-resume-bgscan",
142                         G_CALLBACK(handle_resume_bgscan), NULL);
143         g_signal_connect(wifi_object, "handle-pause-bgscan",
144                         G_CALLBACK(handle_pause_bgscan), NULL);
145
146         // Passpoint
147         g_signal_connect(wifi_object, "handle-set-passpoint",
148                                 G_CALLBACK(handle_set_passpoint), NULL);
149         g_signal_connect(wifi_object, "handle-get-passpoint",
150                                         G_CALLBACK(handle_get_passpoint), NULL);
151
152         // EAP authentication
153         g_signal_connect(wifi_object, "handle-get-aka-auth",
154                                 G_CALLBACK(handle_get_aka_auth), NULL);
155         g_signal_connect(wifi_object, "handle-get-sim-auth",
156                                 G_CALLBACK(handle_get_sim_auth), NULL);
157         g_signal_connect(wifi_object, "handle-get-sim-imsi",
158                                 G_CALLBACK(handle_get_sim_imsi), NULL);
159         g_signal_connect(wifi_object, "handle-req-aka-auth",
160                         G_CALLBACK(handle_req_aka_auth), NULL);
161         g_signal_connect(wifi_object, "handle-req-sim-auth",
162                         G_CALLBACK(handle_req_sim_auth), NULL);
163
164         // WIFI MDM blacklist
165         g_signal_connect(wifi_object, "handle-check-black-list",
166                         G_CALLBACK(handle_check_black_list), NULL);
167
168         if (!g_dbus_interface_skeleton_export(interface_wifi, connection,
169                         NETCONFIG_WIFI_PATH, NULL)) {
170                 ERR("Export WIFI_PATH for wifi failed");
171         }
172
173         /*Interface connman.Agent*/
174         connman_agent_object = net_connman_agent_skeleton_new();
175
176         interface_connman_agent = G_DBUS_INTERFACE_SKELETON(connman_agent_object);
177         g_signal_connect(connman_agent_object, "handle-report-error",
178                         G_CALLBACK(handle_report_error), NULL);
179         g_signal_connect(connman_agent_object, "handle-request-browser",
180                         G_CALLBACK(handle_request_browser), NULL);
181         g_signal_connect(connman_agent_object, "handle-request-input",
182                         G_CALLBACK(handle_request_input), NULL);
183         g_signal_connect(connman_agent_object, "handle-set-field",
184                         G_CALLBACK(handle_set_field), NULL);
185
186         if (!g_dbus_interface_skeleton_export(interface_connman_agent, connection,
187                         NETCONFIG_WIFI_PATH, NULL)) {
188                 ERR("Export WIFI_PATH for agent failed");
189         }
190
191         /*Interface netconfig.wifi.Firmware*/
192         wififirmware_object = wifi_firmware_skeleton_new();
193
194         interface_wifi_firmware = G_DBUS_INTERFACE_SKELETON(wififirmware_object);
195         g_signal_connect(wififirmware_object, "handle-start",
196                         G_CALLBACK(handle_start), NULL);
197         g_signal_connect(wififirmware_object, "handle-stop",
198                                 G_CALLBACK(handle_stop), NULL);
199
200         if (!g_dbus_interface_skeleton_export(interface_wifi_firmware, connection,
201                         NETCONFIG_WIFI_PATH, NULL)) {
202                 ERR("Export WIFI_PATH for firmware failed");
203         }
204
205         _set_wifi_mac_address();
206
207         wifi_power_initialize();
208
209         return;
210 }
211
212 void wifi_object_deinit(void)
213 {
214         g_object_unref(wifi_object);
215         g_object_unref(connman_agent_object);
216         g_object_unref(wififirmware_object);
217
218         wifi_power_deinitialize();
219 }