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