Apply device policy for wifi and wifi profile
[platform/core/connectivity/libnet-client.git] / src / network-signal-handler.c
1 /*
2  * Network Client Library
3  *
4  * Copyright 2012 Samsung Electronics Co., Ltd
5  *
6  * Licensed under the Flora License, Version 1.1 (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.tizenopensource.org/license
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 "network-internal.h"
21 #include "network-dbus-request.h"
22 #include "network-signal-handler.h"
23
24 extern __thread network_info_t NetworkInfo;
25 extern __thread network_request_table_t request_table[NETWORK_REQUEST_TYPE_MAX];
26
27 static __thread net_state_type_t service_state_table[NET_DEVICE_MAX] = {
28                                                         NET_STATE_TYPE_UNKNOWN, };
29 static __thread int net_service_error = NET_ERR_NONE;
30 static __thread guint gdbus_conn_subscribe_id_connman_state = 0;
31 static __thread guint gdbus_conn_subscribe_id_connman_error = 0;
32 static __thread guint gdbus_conn_subscribe_id_supplicant = 0;
33 static __thread guint gdbus_conn_subscribe_id_netconfig_wifi = 0;
34 static __thread guint gdbus_conn_subscribe_id_netconfig = 0;
35 static __thread int net_dpm_wifi_state = -1;
36 static __thread int net_dpm_wifi_profile_state = -1;
37
38 static int __net_handle_wifi_power_rsp(gboolean value)
39 {
40         __NETWORK_FUNC_ENTER__;
41
42         net_event_info_t event_data = { 0, };
43
44         if (value == TRUE) {
45                 NetworkInfo.wifi_state = WIFI_ON;
46                 event_data.Error = NET_ERR_NONE;
47         } else {
48                 NetworkInfo.wifi_state = WIFI_OFF;
49                 event_data.Error = NET_ERR_NONE;
50
51                 if (request_table[NETWORK_REQUEST_TYPE_SCAN].flag == TRUE)
52                         memset(&request_table[NETWORK_REQUEST_TYPE_SCAN],
53                                         0, sizeof(network_request_table_t));
54         }
55
56         if (request_table[NETWORK_REQUEST_TYPE_WIFI_POWER].flag == TRUE) {
57                 memset(&request_table[NETWORK_REQUEST_TYPE_WIFI_POWER],
58                                 0, sizeof(network_request_table_t));
59
60                 event_data.Event = NET_EVENT_WIFI_POWER_RSP;
61                 NETWORK_LOG(NETWORK_LOW, "NET_EVENT_WIFI_POWER_RSP wifi state: %d",
62                                 NetworkInfo.wifi_state);
63
64                 _net_dbus_pending_call_unref();
65         } else {
66                 event_data.Event = NET_EVENT_WIFI_POWER_IND;
67                 NETWORK_LOG(NETWORK_LOW, "NET_EVENT_WIFI_POWER_IND wifi state: %d",
68                                 NetworkInfo.wifi_state);
69         }
70
71         event_data.Datalength = sizeof(net_wifi_state_t);
72         event_data.Data = &(NetworkInfo.wifi_state);
73
74         _net_client_callback(&event_data);
75
76         __NETWORK_FUNC_EXIT__;
77         return NET_ERR_NONE;
78 }
79
80 static wlan_security_mode_type_t __net_get_wlan_sec_mode(int security)
81 {
82         switch (security) {
83         default:
84                 return WLAN_SEC_MODE_NONE;
85         case 2:
86                 return WLAN_SEC_MODE_WEP;
87         case 3:
88                 return WLAN_SEC_MODE_WPA_PSK;
89         case 4:
90                 return WLAN_SEC_MODE_IEEE8021X;
91         }
92 }
93
94 static int __net_handle_specific_scan_resp(GSList *bss_info_list)
95 {
96         __NETWORK_FUNC_ENTER__;
97
98         int count = 0;;
99         net_event_info_t event_data = { 0, };
100
101         if (request_table[NETWORK_REQUEST_TYPE_SPECIFIC_SCAN].flag == TRUE) {
102                 memset(&request_table[NETWORK_REQUEST_TYPE_SPECIFIC_SCAN],
103                                 0, sizeof(network_request_table_t));
104
105                 _net_dbus_pending_call_unref();
106
107                 count = (int)g_slist_length(bss_info_list);
108                 NETWORK_LOG(NETWORK_LOW,
109                                 "Received the signal: %s with total bss count = %d",
110                                 NETCONFIG_SIGNAL_SPECIFIC_SCAN_DONE,
111                                 count);
112
113                 event_data.Event = NET_EVENT_SPECIFIC_SCAN_IND;
114                 event_data.Datalength = count;
115                 event_data.Data = bss_info_list;
116
117                 _net_client_callback(&event_data);
118         } else
119                 g_slist_free_full(bss_info_list, g_free);
120
121         __NETWORK_FUNC_EXIT__;
122         return NET_ERR_NONE;
123 }
124
125 static int __net_handle_wifi_specific_scan_rsp(GVariant *param)
126 {
127         GVariantIter *iter = NULL;
128         GVariant *value = NULL;
129         gchar *key = NULL;
130         const gchar *ssid = NULL;
131         gint32 security = 0;
132         gboolean wps = FALSE;
133         GSList *bss_info_list = NULL;
134         gboolean ssid_found = FALSE;
135         gboolean sec_found = FALSE;
136         gboolean wps_found = FALSE;
137
138         g_variant_get(param, "(a{sv})", &iter);
139
140         while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
141                 if (g_strcmp0(key, "ssid") == 0 && ssid_found == FALSE) {
142                         ssid = g_variant_get_string(value, NULL);
143                         NETWORK_LOG(NETWORK_LOW, "SSID: %s", ssid);
144                         ssid_found = TRUE;
145                 }
146                 if (g_strcmp0(key, "security") == 0 && sec_found == FALSE) {
147                         security = g_variant_get_int32(value);
148                         NETWORK_LOG(NETWORK_LOW, "with security: %d", security);
149                         sec_found = TRUE;
150                 }
151                 if (g_strcmp0(key, "wps") == 0 && wps_found == FALSE) {
152                         wps = g_variant_get_boolean(value);
153                         NETWORK_LOG(NETWORK_LOW, "wps supported: %d", wps);
154                         wps_found = TRUE;
155                 }
156
157                 if (ssid_found == TRUE && sec_found == TRUE && wps_found == TRUE) {
158                         struct ssid_scan_bss_info_t *bss = NULL;
159                         bss = g_try_new0(struct ssid_scan_bss_info_t, 1);
160                         if (bss == NULL) {
161                                 NETWORK_LOG(NETWORK_ERROR, "Memory allocation error");
162
163                                 g_slist_free_full(bss_info_list, g_free);
164                                 g_variant_unref(value);
165                                 g_free(key);
166                                 return NET_ERR_UNKNOWN;
167                         }
168
169                         g_strlcpy(bss->ssid, ssid, NET_WLAN_ESSID_LEN);
170                         bss->security = __net_get_wlan_sec_mode(security);
171                         bss->wps = (char)wps;
172                         bss_info_list = g_slist_append(bss_info_list, bss);
173
174                         ssid_found = sec_found = wps_found = FALSE;
175                 }
176         }
177         g_variant_iter_free(iter);
178
179         __net_handle_specific_scan_resp(bss_info_list);
180
181         /* To enhance performance,
182          * BSS list should be release in a delayed manner in _net_client_callback */
183
184         return NET_ERR_NONE;
185 }
186
187 static int __net_handle_wps_scan_resp(GSList *bss_info_list)
188 {
189         __NETWORK_FUNC_ENTER__;
190
191         int count = 0;;
192         net_event_info_t event_data = { 0, };
193
194         if (request_table[NETWORK_REQUEST_TYPE_WPS_SCAN].flag == TRUE) {
195                 memset(&request_table[NETWORK_REQUEST_TYPE_WPS_SCAN],
196                                 0, sizeof(network_request_table_t));
197
198                 _net_dbus_pending_call_unref();
199
200                 count = (int)g_slist_length(bss_info_list);
201                 NETWORK_LOG(NETWORK_LOW,
202                                 "Received the signal: %s with total bss count = %d",
203                                 NETCONFIG_SIGNAL_WPS_SCAN_DONE,
204                                 count);
205
206                 event_data.Event = NET_EVENT_WPS_SCAN_IND;
207                 event_data.Datalength = count;
208                 event_data.Data = bss_info_list;
209
210                 _net_client_callback(&event_data);
211         } else
212                 g_slist_free_full(bss_info_list, g_free);
213
214         __NETWORK_FUNC_EXIT__;
215         return NET_ERR_NONE;
216 }
217
218 static int __net_handle_wifi_wps_scan_rsp(GVariant *param)
219 {
220         GVariantIter *iter = NULL;
221         GVariant *value = NULL;
222         gchar *key = NULL;
223         GSList *bss_info_list = NULL;
224         const gchar *ssid = NULL;
225         const gchar *bssid = NULL;
226         gsize ssid_len;
227         int rssi = -89;
228         int mode = 0;
229         gboolean ssid_found = FALSE;
230         gboolean bssid_found = FALSE;
231         gboolean rssi_found = FALSE;
232         gboolean mode_found = FALSE;
233
234         g_variant_get(param, "(a{sv})", &iter);
235
236         while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
237                 if (g_strcmp0(key, "ssid") == 0) {
238                         ssid = g_variant_get_fixed_array(value, &ssid_len, sizeof(guchar));
239                         ssid_found = TRUE;
240                 } else if (g_strcmp0(key, "bssid") == 0) {
241                         bssid = g_variant_get_string(value, NULL);
242                         bssid_found = TRUE;
243                 } else if (g_strcmp0(key, "rssi") == 0) {
244                         rssi = g_variant_get_int32(value);
245                         rssi_found = TRUE;
246                 } else if (g_strcmp0(key, "mode") == 0) {
247                         mode = g_variant_get_int32(value);
248                         mode_found = TRUE;
249                 }
250
251                 if (ssid_found == TRUE && bssid_found == TRUE &&
252                         rssi_found == TRUE && mode_found == TRUE) {
253                         struct wps_scan_bss_info_t *bss = NULL;
254                         bss = g_try_new0(struct wps_scan_bss_info_t, 1);
255                         if (bss == NULL) {
256                                 NETWORK_LOG(NETWORK_ERROR, "Memory allocation error");
257
258                                 g_slist_free_full(bss_info_list, g_free);
259                                 g_variant_unref(value);
260                                 g_free(key);
261                                 return NET_ERR_UNKNOWN;
262                         }
263
264                         memcpy(bss->ssid, ssid, ssid_len);
265                         g_strlcpy(bss->bssid, bssid, NET_WLAN_BSSID_LEN+1);
266                         bss->rssi = rssi;
267                         bss->mode = mode;
268                         bss_info_list = g_slist_append(bss_info_list, bss);
269
270                         ssid_found = bssid_found = FALSE;
271                         rssi_found = mode_found = FALSE;
272                 }
273         }
274         g_variant_iter_free(iter);
275
276         __net_handle_wps_scan_resp(bss_info_list);
277
278         return NET_ERR_NONE;
279 }
280
281 static void __net_handle_state_ind(const char *profile_name,
282                 net_state_type_t profile_state)
283 {
284         __NETWORK_FUNC_ENTER__;
285
286         net_event_info_t event_data = { 0, };
287
288         event_data.Error = NET_ERR_NONE;
289         event_data.Event = NET_EVENT_NET_STATE_IND;
290
291         g_strlcpy(event_data.ProfileName, profile_name, sizeof(event_data.ProfileName));
292
293         event_data.Datalength = sizeof(net_state_type_t);
294         event_data.Data = &profile_state;
295
296         NETWORK_LOG(NETWORK_LOW,
297                         "Sending NET_EVENT_NET_STATE_IND, state: %d, profile name: %s",
298                         profile_state, event_data.ProfileName);
299
300         _net_client_callback(&event_data);
301
302         __NETWORK_FUNC_EXIT__;
303 }
304
305 static void __net_handle_failure_ind(const char *profile_name,
306                 net_device_t device_type)
307 {
308         __NETWORK_FUNC_ENTER__;
309
310         net_event_info_t event_data = { 0, };
311
312         const char *svc_name1 =
313                         request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].ProfileName;
314         const char *svc_name2 =
315                         request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].ProfileName;
316         const char *svc_name3 =
317                         request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].ProfileName;
318
319         if (request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag == TRUE &&
320                         strstr(profile_name, svc_name1) != NULL) {
321                 memset(&request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION], 0,
322                                 sizeof(network_request_table_t));
323
324                 event_data.Event = NET_EVENT_OPEN_RSP;
325
326                 _net_dbus_pending_call_unref();
327         } else if (request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].flag == TRUE &&
328                         g_strcmp0(profile_name, svc_name2) == 0) {
329                 memset(&request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS], 0,
330                                 sizeof(network_request_table_t));
331
332                 event_data.Event = NET_EVENT_WIFI_WPS_RSP;
333
334                 memset(&request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION], 0,
335                                                 sizeof(network_request_table_t));
336
337                 _net_dbus_pending_call_unref();
338         } else if (request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].flag == TRUE &&
339                         g_strcmp0(profile_name, svc_name3) == 0) {
340                 memset(&request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION], 0,
341                                 sizeof(network_request_table_t));
342
343                 event_data.Event = NET_EVENT_CLOSE_RSP;
344
345                 _net_dbus_pending_call_unref();
346         } else {
347                 __net_handle_state_ind(profile_name, NET_STATE_TYPE_FAILURE);
348
349                 __NETWORK_FUNC_EXIT__;
350                 return;
351         }
352
353         g_strlcpy(event_data.ProfileName,
354                         profile_name, NET_PROFILE_NAME_LEN_MAX+1);
355
356         if (net_service_error != NET_ERR_NONE)
357                 event_data.Error = net_service_error;
358         else {
359                 event_data.Error = NET_ERR_CONNECTION_CONNECT_FAILED;
360                 NETWORK_LOG(NETWORK_ERROR, "Event error defined %d", event_data.Error);
361         }
362         event_data.Datalength = 0;
363         event_data.Data = NULL;
364
365         net_service_error = NET_ERR_NONE;
366
367         NETWORK_LOG(NETWORK_ERROR, "State failure %d", event_data.Error);
368         _net_client_callback(&event_data);
369
370         /* Reseting the state back in case of failure state */
371         service_state_table[device_type] = NET_STATE_TYPE_IDLE;
372
373         __NETWORK_FUNC_EXIT__;
374 }
375
376 static int string2state(const char *state)
377 {
378         if (g_strcmp0(state, "idle") == 0)
379                 return NET_STATE_TYPE_IDLE;
380         else if (g_strcmp0(state, "association") == 0)
381                 return NET_STATE_TYPE_ASSOCIATION;
382         else if (g_strcmp0(state, "configuration") == 0)
383                 return NET_STATE_TYPE_CONFIGURATION;
384         else if (g_strcmp0(state, "ready") == 0)
385                 return NET_STATE_TYPE_READY;
386         else if (g_strcmp0(state, "online") == 0)
387                 return NET_STATE_TYPE_ONLINE;
388         else if (g_strcmp0(state, "disconnect") == 0)
389                 return NET_STATE_TYPE_DISCONNECT;
390         else if (g_strcmp0(state, "failure") == 0)
391                 return NET_STATE_TYPE_FAILURE;
392
393         return NET_STATE_TYPE_UNKNOWN;
394 }
395
396 static int __net_handle_service_state_changed(const gchar *sig_path,
397                 const char *key, const char *state)
398 {
399         net_err_t Error = NET_ERR_NONE;
400         net_state_type_t old_state, new_state;
401
402         net_event_info_t event_data = { 0, };
403         net_device_t device_type = NET_DEVICE_UNKNOWN;
404
405         if (sig_path == NULL)
406                 return Error;
407
408         device_type = _net_get_tech_type_from_path(sig_path);
409         if (device_type == NET_DEVICE_UNKNOWN)
410                 return Error;
411
412         NETWORK_LOG(NETWORK_LOW, "[%s] %s", state, sig_path);
413
414         if (device_type == NET_DEVICE_WIFI && NetworkInfo.wifi_state == WIFI_OFF) {
415                 NETWORK_LOG(NETWORK_LOW, "Wi-Fi is off");
416                 return Error;
417         }
418
419         old_state = service_state_table[device_type];
420         new_state = string2state(state);
421
422         if (old_state == new_state)
423                 return Error;
424
425         service_state_table[device_type] = new_state;
426
427         switch (new_state) {
428         case NET_STATE_TYPE_IDLE:
429                 if (device_type == NET_DEVICE_WIFI &&
430                                 NetworkInfo.wifi_state == WIFI_CONNECTED) {
431                         NetworkInfo.wifi_state = WIFI_ON;
432                 }
433         case NET_STATE_TYPE_ASSOCIATION:
434         case NET_STATE_TYPE_CONFIGURATION:
435                 __net_handle_state_ind(sig_path, new_state);
436                 break;
437
438         case NET_STATE_TYPE_READY:
439         case NET_STATE_TYPE_ONLINE:
440         {
441                 if (old_state != NET_STATE_TYPE_READY &&
442                                 old_state != NET_STATE_TYPE_ONLINE) {
443                         const char *svc_name1 =
444                                         request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].ProfileName;
445                         const char *svc_name2 =
446                                         request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].ProfileName;
447
448                         if (request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag == TRUE &&
449                                         strstr(sig_path, svc_name1) != NULL) {
450                                 memset(&request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION], 0,
451                                                 sizeof(network_request_table_t));
452
453                                 event_data.Event = NET_EVENT_OPEN_RSP;
454
455                                 NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_OPEN_RSP");
456
457                                 _net_dbus_pending_call_unref();
458                         } else if (request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].flag == TRUE &&
459                                         g_strcmp0(sig_path, svc_name2) == 0) {
460                                 memset(&request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS], 0,
461                                                 sizeof(network_request_table_t));
462
463                                 event_data.Event = NET_EVENT_WIFI_WPS_RSP;
464
465                                 NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_WIFI_WPS_RSP");
466
467                                 _net_dbus_pending_call_unref();
468                         } else {
469                                 event_data.Event = NET_EVENT_OPEN_IND;
470
471                                 NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_OPEN_IND");
472                         }
473
474                         net_profile_info_t prof_info;
475                         if ((Error = net_get_profile_info(sig_path, &prof_info)) != NET_ERR_NONE) {
476                                 NETWORK_LOG(NETWORK_ERROR, "net_get_profile_info() failed [%s]",
477                                                 _net_print_error(Error));
478
479                                 event_data.Datalength = 0;
480                                 event_data.Data = NULL;
481                         } else {
482                                 event_data.Datalength = sizeof(net_profile_info_t);
483                                 event_data.Data = &prof_info;
484                         }
485
486                         event_data.Error = Error;
487                         g_strlcpy(event_data.ProfileName, sig_path, NET_PROFILE_NAME_LEN_MAX+1);
488
489                         _net_client_callback(&event_data);
490                 } else
491                         __net_handle_state_ind(sig_path, new_state);
492
493                 break;
494         }
495         case NET_STATE_TYPE_DISCONNECT:
496         {
497                 const char *svc_name1 =
498                                 request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].ProfileName;
499                 const char *svc_name2 =
500                                 request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].ProfileName;
501                 const char *svc_name3 =
502                                 request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].ProfileName;
503
504                 if (request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag != TRUE &&
505                         request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].flag != TRUE &&
506                         request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].flag != TRUE) {
507                         /** Send Close Ind */
508                         event_data.Error = Error;
509                         event_data.Event =  NET_EVENT_CLOSE_IND;
510                         g_strlcpy(event_data.ProfileName, sig_path, NET_PROFILE_NAME_LEN_MAX+1);
511
512                         event_data.Datalength = 0;
513                         event_data.Data = NULL;
514
515                         NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_CLOSE_IND");
516
517                         _net_client_callback(&event_data);
518                 }
519
520                 if (request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION].flag == TRUE &&
521                                 strstr(sig_path, svc_name2) != NULL) {
522                         memset(&request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION], 0,
523                                         sizeof(network_request_table_t));
524
525                         /** Send Open Resp */
526                         event_data.Error = NET_ERR_OPERATION_ABORTED;
527                         event_data.Event =  NET_EVENT_OPEN_RSP;
528                         g_strlcpy(event_data.ProfileName, sig_path, NET_PROFILE_NAME_LEN_MAX+1);
529
530                         event_data.Datalength = 0;
531                         event_data.Data = NULL;
532
533                         NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_OPEN_RSP");
534
535                         _net_dbus_pending_call_unref();
536
537                         _net_client_callback(&event_data);
538                 }
539
540                 if (request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS].flag == TRUE &&
541                                 g_strcmp0(sig_path, svc_name3) == 0) {
542                         memset(&request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS], 0,
543                                         sizeof(network_request_table_t));
544
545                         /** Send WPS Resp */
546                         event_data.Error = NET_ERR_OPERATION_ABORTED;
547                         event_data.Event =  NET_EVENT_WIFI_WPS_RSP;
548                         g_strlcpy(event_data.ProfileName, sig_path, NET_PROFILE_NAME_LEN_MAX+1);
549
550                         event_data.Datalength = 0;
551                         event_data.Data = NULL;
552
553                         NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_WIFI_WPS_RSP");
554                         _net_dbus_pending_call_unref();
555
556                         _net_client_callback(&event_data);
557                 }
558
559                 if (request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].flag == TRUE &&
560                                 g_strcmp0(sig_path, svc_name1) == 0) {
561                         memset(&request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION], 0,
562                                         sizeof(network_request_table_t));
563
564                         /** Send Close Resp */
565                         event_data.Error = Error;
566                         event_data.Event =  NET_EVENT_CLOSE_RSP;
567                         g_strlcpy(event_data.ProfileName, sig_path, NET_PROFILE_NAME_LEN_MAX+1);
568
569                         event_data.Datalength = 0;
570                         event_data.Data = NULL;
571
572                         NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_CLOSE_RSP");
573
574                         _net_dbus_pending_call_unref();
575
576                         _net_client_callback(&event_data);
577                 }
578                 break;
579         }
580         case NET_STATE_TYPE_FAILURE:
581                 __net_handle_failure_ind(sig_path, device_type);
582                 break;
583
584         default:
585                 Error = NET_ERR_UNKNOWN_METHOD;
586                 break;
587         }
588
589         return Error;
590 }
591
592 static int string2error(const char *error)
593 {
594         if (g_strcmp0(error, "out-of-range") == 0)
595                 return NET_ERR_CONNECTION_OUT_OF_RANGE;
596         else if (g_strcmp0(error, "pin-missing") == 0)
597                 return NET_ERR_CONNECTION_PIN_MISSING;
598         else if (g_strcmp0(error, "dhcp-failed") == 0)
599                 return NET_ERR_CONNECTION_DHCP_FAILED;
600         else if (g_strcmp0(error, "connect-failed") == 0)
601                 return NET_ERR_CONNECTION_CONNECT_FAILED;
602         else if (g_strcmp0(error, "login-failed") == 0)
603                 return NET_ERR_CONNECTION_LOGIN_FAILED;
604         else if (g_strcmp0(error, "auth-failed") == 0)
605                 return NET_ERR_CONNECTION_AUTH_FAILED;
606         else if (g_strcmp0(error, "invalid-key") == 0)
607                 return NET_ERR_CONNECTION_INVALID_KEY;
608
609         return NET_ERR_UNKNOWN;
610 }
611
612 static int __net_handle_service_set_error(const char *key, const char *error)
613 {
614         if (error == NULL || *error == '\0')
615                 return NET_ERR_NONE;
616
617         NETWORK_LOG(NETWORK_ERROR, "[%s] %s", key, error);
618
619         net_service_error = string2error(error);
620
621         return NET_ERR_NONE;
622 }
623
624 static int __net_handle_scan_done(GVariant *param)
625 {
626         net_event_info_t event_data = { 0, };
627
628         if (request_table[NETWORK_REQUEST_TYPE_SPECIFIC_SCAN].flag == TRUE)
629                 return NET_ERR_NONE;
630         else if (request_table[NETWORK_REQUEST_TYPE_SCAN].flag == TRUE) {
631                 memset(&request_table[NETWORK_REQUEST_TYPE_SCAN], 0,
632                                 sizeof(network_request_table_t));
633
634                 event_data.Event = NET_EVENT_WIFI_SCAN_RSP;
635
636                 _net_dbus_pending_call_unref();
637         } else {
638                 event_data.Event = NET_EVENT_WIFI_SCAN_IND;
639         }
640
641         event_data.Error = NET_ERR_NONE;
642         event_data.Datalength = 0;
643         event_data.Data = NULL;
644
645         _net_client_callback(&event_data);
646
647         return NET_ERR_NONE;
648 }
649
650 static int __net_handle_ethernet_cable_state_rsp(GVariant *param)
651 {
652         GVariantIter *iter = NULL;
653         GVariant *value = NULL;
654         const char *key = NULL;
655         const gchar *sig_value = NULL;
656
657         g_variant_get(param, "(a{sv})", &iter);
658
659         while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
660                 if (g_strcmp0(key, "key") == 0) {
661                         sig_value = g_variant_get_string(value, NULL);
662                         NETWORK_LOG(NETWORK_LOW, "Check Ethernet Monitor Result: %s",
663                                                 sig_value);
664                 }
665         }
666         g_variant_iter_free(iter);
667
668         net_event_info_t event_data;
669         if (g_strcmp0(sig_value, "ATTACHED") == 0) {
670                         event_data.Event = NET_EVENT_ETHERNET_CABLE_ATTACHED;
671                         event_data.Error = NET_ERR_NONE;
672         } else {
673                         event_data.Event = NET_EVENT_ETHERNET_CABLE_DETACHED;
674                         event_data.Error = NET_ERR_NONE;
675         }
676         event_data.Datalength = 0;
677         event_data.Data = NULL;
678
679         _net_client_callback(&event_data);
680         return NET_ERR_NONE;
681 }
682
683 static int __net_handle_network_dpm_wifi_event(GVariant *param)
684 {
685         __NETWORK_FUNC_ENTER__;
686
687         GVariantIter *iter = NULL;
688         GVariant *value = NULL;
689         const char *key = NULL;
690         const gchar *sig_value = NULL;
691
692         g_variant_get(param, "(a{sv})", &iter);
693
694         while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
695                 if (g_strcmp0(key, "key") == 0) {
696                         sig_value = g_variant_get_string(value, NULL);
697                         NETWORK_LOG(NETWORK_LOW, "Wifi device policy : %s",
698                                                 sig_value);
699                         if (g_strcmp0(sig_value, "allowed") == 0)
700                                 net_dpm_wifi_state = TRUE;
701                         else
702                                 net_dpm_wifi_state = FALSE;
703                 }
704         }
705         g_variant_iter_free(iter);
706
707         return NET_ERR_NONE;
708         __NETWORK_FUNC_EXIT__;
709 }
710
711 static int __net_handle_network_dpm_wifi_profile_event(GVariant *param)
712 {
713         __NETWORK_FUNC_ENTER__;
714
715         GVariantIter *iter = NULL;
716         GVariant *value = NULL;
717         const char *key = NULL;
718         const gchar *sig_value = NULL;
719
720         g_variant_get(param, "(a{sv})", &iter);
721
722         while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
723                 if (g_strcmp0(key, "key") == 0) {
724                         sig_value = g_variant_get_string(value, NULL);
725                         NETWORK_LOG(NETWORK_LOW, "Wifi profile device policy : %s",
726                                                 sig_value);
727                         if (g_strcmp0(sig_value, "allowed") == 0)
728                                 net_dpm_wifi_profile_state = TRUE;
729                         else
730                                 net_dpm_wifi_profile_state = FALSE;
731                 }
732         }
733         g_variant_iter_free(iter);
734
735         return NET_ERR_NONE;
736         __NETWORK_FUNC_EXIT__;
737 }
738
739 static void __net_connman_service_signal_filter(GDBusConnection *conn,
740                 const gchar *name, const gchar *path, const gchar *interface,
741                 const gchar *sig, GVariant *param, gpointer user_data)
742 {
743         __NETWORK_FUNC_ENTER__;
744
745         const char *key = NULL;
746         const char *value = NULL;
747         GVariant *var;
748
749         if (g_strcmp0(sig, SIGNAL_PROPERTY_CHANGED) == 0) {
750                 g_variant_get(param, "(sv)", &key, &var);
751
752                 if (g_strcmp0(key, "State") == 0) {
753                         g_variant_get(var, "s", &value);
754
755                         __net_handle_service_state_changed(path, key, value);
756                 } else if (g_strcmp0(key, "Error") == 0) {
757                         g_variant_get(var, "s", &value);
758
759                         __net_handle_service_set_error(key, value);
760                 }
761
762                 g_free((gchar *)value);
763                 g_free((gchar *)key);
764                 if (NULL != var)
765                         g_variant_unref(var);
766         }
767
768         __NETWORK_FUNC_EXIT__;
769 }
770 static int __net_handle_wifi_tdls_connected_event(GVariant *param)
771 {
772         __NETWORK_FUNC_ENTER__;
773
774         GVariantIter *iter = NULL;
775         GVariant *value = NULL;
776         const char *key = NULL;
777         const gchar *sig_value = NULL;
778
779         g_variant_get(param, "(a{sv})", &iter);
780
781         while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
782                 if (g_strcmp0(key, "peermac") == 0) {
783                         sig_value = g_variant_get_string(value, NULL);
784
785                         NETWORK_LOG(NETWORK_ERROR, "TDLS Connected Peer Mac Adress: %s",
786                                                 sig_value);
787                 }
788         }
789         g_variant_iter_free(iter);
790
791         net_event_info_t event_data;
792         memset(&event_data, 0, sizeof(event_data));
793
794         event_data.Error = NET_ERR_NONE;
795         event_data.Event = NET_EVENT_TDLS_CONNECTED_IND;
796         event_data.Data = g_strdup(sig_value);
797
798         if (event_data.Data)
799                 event_data.Datalength = strlen(event_data.Data);
800         else
801                 event_data.Datalength = 0;
802
803         NETWORK_LOG(NETWORK_ERROR, "Sending NET_EVENT_TDLS_CONNECTED_IND");
804         _net_client_callback(&event_data);
805         g_free(event_data.Data);
806
807         __NETWORK_FUNC_EXIT__;
808         return NET_ERR_NONE;
809 }
810
811 static int __net_handle_wifi_tdls_disconnected_event(GVariant *param)
812 {
813         __NETWORK_FUNC_ENTER__;
814
815         GVariantIter *iter = NULL;
816         GVariant *value = NULL;
817         const char *key = NULL;
818         const gchar *sig_value = NULL;
819
820         g_variant_get(param, "(a{sv})", &iter);
821
822         while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
823                 if (g_strcmp0(key, "peermac") == 0) {
824                         sig_value = g_variant_get_string(value, NULL);
825
826                         NETWORK_LOG(NETWORK_ERROR, "TDLS Connected Peer Mac Adress: %s",
827                                                 sig_value);
828                 }
829         }
830         g_variant_iter_free(iter);
831
832         net_event_info_t event_data;
833         memset(&event_data, 0, sizeof(event_data));
834
835         event_data.Error = NET_ERR_NONE;
836         event_data.Event = NET_EVENT_TDLS_DISCONNECTED_IND;
837         event_data.Data = g_strdup(sig_value);
838
839         if (event_data.Data)
840                 event_data.Datalength = strlen(event_data.Data);
841         else
842                 event_data.Datalength = 0;
843
844         NETWORK_LOG(NETWORK_ERROR, "Sending NET_EVENT_TDLS_DISCONNECTED_IND");
845         _net_client_callback(&event_data);
846         g_free(event_data.Data);
847
848         __NETWORK_FUNC_EXIT__;
849         return NET_ERR_NONE;
850 }
851
852 static int __net_handle_wifi_connect_fail_event(GVariant *param)
853 {
854         __NETWORK_FUNC_ENTER__;
855
856         net_event_info_t event_data = { 0, };
857         network_request_table_t *open_info =
858                         &request_table[NETWORK_REQUEST_TYPE_OPEN_CONNECTION];
859         network_request_table_t *wps_info =
860                         &request_table[NETWORK_REQUEST_TYPE_ENROLL_WPS];
861
862         event_data.Datalength = 0;
863         event_data.Data = NULL;
864
865         NETWORK_LOG(NETWORK_HIGH, "Failed to connect WiFi");
866
867         if (open_info->flag == TRUE) {
868                 memset(open_info, 0, sizeof(network_request_table_t));
869                 event_data.Error = NET_ERR_INVALID_OPERATION;
870                 event_data.Event = NET_EVENT_OPEN_RSP;
871                 NETWORK_LOG(NETWORK_HIGH, "Sending NET_EVENT_OPEN_RSP");
872         } else if (wps_info->flag == TRUE) {
873                 memset(wps_info, 0, sizeof(network_request_table_t));
874                 event_data.Error = NET_ERR_INVALID_OPERATION;
875                 event_data.Event = NET_EVENT_WIFI_WPS_RSP;
876                 NETWORK_LOG(NETWORK_HIGH, "Sending NET_EVENT_WIFI_WPS_RSP");
877         } else {
878                 NETWORK_LOG(NETWORK_LOW, "WiFi Connection flag not set");
879                 __NETWORK_FUNC_EXIT__;
880                 return NET_ERR_NONE;
881         }
882         _net_client_callback(&event_data);
883
884         __NETWORK_FUNC_EXIT__;
885         return NET_ERR_NONE;
886 }
887
888 static void __net_supplicant_signal_filter(GDBusConnection *conn,
889                 const gchar *name, const gchar *path, const gchar *interface,
890                 const gchar *sig, GVariant *param, gpointer user_data)
891 {
892         if (g_strcmp0(sig, SIGNAL_SCAN_DONE) == 0)
893                 __net_handle_scan_done(param);
894 }
895
896 static void __net_netconfig_signal_filter(GDBusConnection *conn,
897                 const gchar *name, const gchar *path, const gchar *interface,
898                 const gchar *sig, GVariant *param, gpointer user_data)
899 {
900         if (g_strcmp0(sig, NETCONFIG_SIGNAL_POWERON_COMPLETED) == 0)
901                 __net_handle_wifi_power_rsp(TRUE);
902         else if (g_strcmp0(sig, NETCONFIG_SIGNAL_POWEROFF_COMPLETED) == 0)
903                 __net_handle_wifi_power_rsp(FALSE);
904         else if (g_strcmp0(sig, NETCONFIG_SIGNAL_SPECIFIC_SCAN_DONE) == 0)
905                 __net_handle_wifi_specific_scan_rsp(param);
906         else if (g_strcmp0(sig, NETCONFIG_SIGNAL_WPS_SCAN_DONE) == 0)
907                 __net_handle_wifi_wps_scan_rsp(param);
908         else if (g_strcmp0(sig, NETCONFIG_SIGNAL_TDLS_CONNECTED) == 0)
909                 __net_handle_wifi_tdls_connected_event(param);
910         else if (g_strcmp0(sig, NETCONFIG_SIGNAL_TDLS_DISCONNECTED) == 0)
911                 __net_handle_wifi_tdls_disconnected_event(param);
912         else if (g_strcmp0(sig, NETCONFIG_SIGNAL_WIFI_CONNECT_FAIL) == 0)
913                 __net_handle_wifi_connect_fail_event(param);
914 }
915
916 static void __net_netconfig_network_signal_filter(GDBusConnection *conn,
917                 const gchar *name, const gchar *path, const gchar *interface,
918                 const gchar *sig, GVariant *param, gpointer user_data)
919 {
920         if (g_strcmp0(sig, NETCONFIG_SIGNAL_ETHERNET_CABLE_STATE) == 0)
921                 __net_handle_ethernet_cable_state_rsp(param);
922         else if (g_strcmp0(sig, NETCONFIG_SIGNAL_DPM_WIFI) == 0)
923                 __net_handle_network_dpm_wifi_event(param);
924         else if (g_strcmp0(sig, NETCONFIG_SIGNAL_DPM_WIFI_PROFILE) == 0)
925                 __net_handle_network_dpm_wifi_profile_event(param);
926 }
927
928 /*****************************************************************************
929  * Global Functions
930  *****************************************************************************/
931
932 int _net_get_dpm_wifi_state(void)
933 {
934         return net_dpm_wifi_state;
935 }
936
937 void _net_set_dpm_wifi_state(int state)
938 {
939         net_dpm_wifi_state = state;
940 }
941
942 gboolean _net_get_dpm_wifi_profile_state()
943 {
944         return net_dpm_wifi_profile_state;
945 }
946
947 void _net_set_dpm_wifi_profile_state(int state)
948 {
949         net_dpm_wifi_profile_state = state;
950 }
951
952 int _net_deregister_signal(void)
953 {
954         __NETWORK_FUNC_ENTER__;
955
956         GDBusConnection *connection;
957         net_err_t Error = NET_ERR_NONE;
958
959         connection = _net_dbus_get_gdbus_conn();
960         if (connection == NULL) {
961                 NETWORK_LOG(NETWORK_ERROR, "Already de-registered");
962                 __NETWORK_FUNC_EXIT__;
963                 return NET_ERR_APP_NOT_REGISTERED;
964         }
965
966         g_dbus_connection_signal_unsubscribe(connection,
967                                                 gdbus_conn_subscribe_id_connman_state);
968         g_dbus_connection_signal_unsubscribe(connection,
969                                                 gdbus_conn_subscribe_id_connman_error);
970         g_dbus_connection_signal_unsubscribe(connection,
971                                                 gdbus_conn_subscribe_id_supplicant);
972         g_dbus_connection_signal_unsubscribe(connection,
973                                                 gdbus_conn_subscribe_id_netconfig_wifi);
974         g_dbus_connection_signal_unsubscribe(connection,
975                                                 gdbus_conn_subscribe_id_netconfig);
976
977         Error = _net_dbus_close_gdbus_call();
978         if (Error != NET_ERR_NONE) {
979                 __NETWORK_FUNC_EXIT__;
980                 return Error;
981         }
982
983         __NETWORK_FUNC_EXIT__;
984         return Error;
985 }
986
987 int _net_subscribe_signal_wifi(void)
988 {
989         __NETWORK_FUNC_ENTER__;
990
991         GDBusConnection *connection;
992         net_err_t Error = NET_ERR_NONE;
993
994         connection = _net_dbus_get_gdbus_conn();
995         if (connection == NULL) {
996                 __NETWORK_FUNC_EXIT__;
997                 return NET_ERR_UNKNOWN;
998         }
999
1000         /* Create supplicant service connection */
1001         gdbus_conn_subscribe_id_supplicant = g_dbus_connection_signal_subscribe(
1002                         connection,
1003                         SUPPLICANT_SERVICE,
1004                         SUPPLICANT_IFACE_INTERFACE,
1005                         "ScanDone",
1006                         NULL,
1007                         NULL,
1008                         G_DBUS_SIGNAL_FLAGS_NONE,
1009                         __net_supplicant_signal_filter,
1010                         NULL,
1011                         NULL);
1012
1013         /* Create net-config service connection */
1014         gdbus_conn_subscribe_id_netconfig_wifi = g_dbus_connection_signal_subscribe(
1015                         connection,
1016                         NETCONFIG_SERVICE,
1017                         NETCONFIG_WIFI_INTERFACE,
1018                         NULL,
1019                         NETCONFIG_WIFI_PATH,
1020                         NULL,
1021                         G_DBUS_SIGNAL_FLAGS_NONE,
1022                         __net_netconfig_signal_filter,
1023                         NULL,
1024                         NULL);
1025
1026         if (gdbus_conn_subscribe_id_supplicant == 0 ||
1027                 gdbus_conn_subscribe_id_netconfig_wifi == 0) {
1028                 NETWORK_LOG(NETWORK_ERROR, "Failed register signals "
1029                                 "supplicant(%d), netconfig_wifi(%d)",
1030                                 gdbus_conn_subscribe_id_supplicant,
1031                                 gdbus_conn_subscribe_id_netconfig_wifi);
1032                 Error = NET_ERR_NOT_SUPPORTED;
1033         }
1034
1035         __NETWORK_FUNC_EXIT__;
1036         return Error;
1037 }
1038
1039 int _net_register_signal(void)
1040 {
1041         __NETWORK_FUNC_ENTER__;
1042
1043         GDBusConnection *connection;
1044         net_err_t Error = NET_ERR_NONE;
1045
1046         Error = _net_dbus_create_gdbus_call();
1047         if (Error != NET_ERR_NONE) {
1048                 __NETWORK_FUNC_EXIT__;
1049                 return Error;
1050         }
1051
1052         connection = _net_dbus_get_gdbus_conn();
1053         if (connection == NULL) {
1054                 __NETWORK_FUNC_EXIT__;
1055                 return NET_ERR_UNKNOWN;
1056         }
1057
1058         /* Create connman service state connection */
1059         gdbus_conn_subscribe_id_connman_state = g_dbus_connection_signal_subscribe(
1060                         connection,
1061                         CONNMAN_SERVICE,
1062                         CONNMAN_SERVICE_INTERFACE,
1063                         SIGNAL_PROPERTY_CHANGED,
1064                         NULL,
1065                         "State",
1066                         G_DBUS_SIGNAL_FLAGS_NONE,
1067                         __net_connman_service_signal_filter,
1068                         NULL,
1069                         NULL);
1070
1071         /* Create connman service error connection */
1072         gdbus_conn_subscribe_id_connman_error = g_dbus_connection_signal_subscribe(
1073                         connection,
1074                         CONNMAN_SERVICE,
1075                         CONNMAN_SERVICE_INTERFACE,
1076                         SIGNAL_PROPERTY_CHANGED,
1077                         NULL,
1078                         "Error",
1079                         G_DBUS_SIGNAL_FLAGS_NONE,
1080                         __net_connman_service_signal_filter,
1081                         NULL,
1082                         NULL);
1083
1084         /* Create net-config service connection for network */
1085         gdbus_conn_subscribe_id_netconfig = g_dbus_connection_signal_subscribe(
1086                         connection,
1087                         NETCONFIG_SERVICE,
1088                         NETCONFIG_NETWORK_INTERFACE,
1089                         NULL,
1090                         NETCONFIG_NETWORK_PATH,
1091                         NULL,
1092                         G_DBUS_SIGNAL_FLAGS_NONE,
1093                         __net_netconfig_network_signal_filter,
1094                         NULL,
1095                         NULL);
1096
1097         if (gdbus_conn_subscribe_id_connman_state == 0 ||
1098                 gdbus_conn_subscribe_id_connman_error == 0 ||
1099                 gdbus_conn_subscribe_id_netconfig == 0) {
1100                 NETWORK_LOG(NETWORK_ERROR, "Failed register signals "
1101                                 "connman_state(%d), connman_error(%d), netconfig(%d)",
1102                                 gdbus_conn_subscribe_id_connman_state,
1103                                 gdbus_conn_subscribe_id_connman_error,
1104                                 gdbus_conn_subscribe_id_netconfig);
1105                 Error = NET_ERR_NOT_SUPPORTED;
1106         }
1107
1108         __NETWORK_FUNC_EXIT__;
1109         return Error;
1110 }
1111
1112 static int __net_get_all_tech_states(GVariant *msg, net_state_type_t *state_table)
1113 {
1114         __NETWORK_FUNC_ENTER__;
1115
1116         net_err_t Error = NET_ERR_NONE;
1117         GVariantIter *iter_main = NULL;
1118         GVariantIter *var = NULL;
1119         GVariant *value = NULL;
1120         gchar *path = NULL;
1121         gchar *key = NULL;
1122         gboolean data;
1123
1124         g_variant_get(msg, "(a(oa{sv}))", &iter_main);
1125         while (g_variant_iter_loop(iter_main, "(oa{sv})", &path, &var)) {
1126
1127                 if (path == NULL)
1128                         continue;
1129
1130                 while (g_variant_iter_loop(var, "{sv}", &key, &value)) {
1131                         if (g_strcmp0(key, "Connected") == 0) {
1132                                 data = g_variant_get_boolean(value);
1133                                 if (!data)
1134                                         continue;
1135
1136                                 if (g_strcmp0(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) == 0) {
1137                                         *(state_table + NET_DEVICE_WIFI) = NET_STATE_TYPE_READY;
1138                                         NetworkInfo.wifi_state = WIFI_CONNECTED;
1139                                 } else if (g_strcmp0(path, CONNMAN_CELLULAR_TECHNOLOGY_PREFIX) == 0)
1140                                         *(state_table + NET_DEVICE_CELLULAR) = NET_STATE_TYPE_READY;
1141                                 else if (g_strcmp0(path, CONNMAN_ETHERNET_TECHNOLOGY_PREFIX) == 0)
1142                                         *(state_table + NET_DEVICE_ETHERNET) = NET_STATE_TYPE_READY;
1143                                 else if (g_strcmp0(path, CONNMAN_BLUETOOTH_TECHNOLOGY_PREFIX) == 0)
1144                                         *(state_table + NET_DEVICE_BLUETOOTH) = NET_STATE_TYPE_READY;
1145                                 else
1146                                         NETWORK_LOG(NETWORK_ERROR, "Invalid technology type");
1147                         } else if (g_strcmp0(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) == 0 &&
1148                                         g_strcmp0(key, "Powered") == 0) {
1149                                 data = g_variant_get_boolean(value);
1150                                 if (data == FALSE)
1151                                         NetworkInfo.wifi_state = WIFI_OFF;
1152                                 else if (data == TRUE && NetworkInfo.wifi_state < WIFI_ON)
1153                                         NetworkInfo.wifi_state = WIFI_ON;
1154                         }
1155                 }
1156         }
1157         g_variant_iter_free(iter_main);
1158
1159         __NETWORK_FUNC_EXIT__;
1160         return Error;
1161 }
1162
1163 static int __net_dbus_get_all_technology_states(net_state_type_t *state_table)
1164 {
1165         __NETWORK_FUNC_ENTER__;
1166
1167         net_err_t Error = NET_ERR_NONE;
1168         GVariant *message = NULL;
1169
1170         message = _net_invoke_dbus_method(CONNMAN_SERVICE,
1171                         CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
1172                         "GetTechnologies", NULL, &Error);
1173         if (message == NULL) {
1174                 NETWORK_LOG(NETWORK_ERROR, "Failed to get technology info");
1175                 goto done;
1176         }
1177
1178         Error = __net_get_all_tech_states(message, state_table);
1179
1180         g_variant_unref(message);
1181
1182 done:
1183         __NETWORK_FUNC_EXIT__;
1184         return Error;
1185 }
1186
1187 int _net_init_service_state_table(void)
1188 {
1189         __NETWORK_FUNC_ENTER__;
1190
1191         net_err_t Error = NET_ERR_NONE;
1192
1193         Error = __net_dbus_get_all_technology_states(&service_state_table[0]);
1194         if (Error != NET_ERR_NONE) {
1195                 __NETWORK_FUNC_EXIT__;
1196                 return Error;
1197         }
1198
1199         NETWORK_LOG(NETWORK_HIGH, "init service state table. "
1200                                 "wifi:%d, cellular:%d, ethernet:%d, bluetooth:%d",
1201                                 service_state_table[NET_DEVICE_WIFI],
1202                                 service_state_table[NET_DEVICE_CELLULAR],
1203                                 service_state_table[NET_DEVICE_ETHERNET],
1204                                 service_state_table[NET_DEVICE_BLUETOOTH]);
1205
1206         __NETWORK_FUNC_EXIT__;
1207         return NET_ERR_NONE;
1208 }