2 * Network Client Library
4 * Copyright 2012 Samsung Electronics Co., Ltd
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
10 * http://www.tizenopensource.org/license
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.
20 #include "network-internal.h"
21 #include "network-dbus-request.h"
22 #include "network-signal-handler.h"
24 extern __thread network_info_t NetworkInfo;
25 extern __thread network_request_table_t request_table[NETWORK_REQUEST_TYPE_MAX];
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;
38 static int __net_handle_wifi_power_rsp(gboolean value)
40 __NETWORK_FUNC_ENTER__;
42 net_event_info_t event_data = { 0, };
45 NetworkInfo.wifi_state = WIFI_ON;
46 event_data.Error = NET_ERR_NONE;
48 NetworkInfo.wifi_state = WIFI_OFF;
49 event_data.Error = NET_ERR_NONE;
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));
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));
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);
64 _net_dbus_pending_call_unref();
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);
71 event_data.Datalength = sizeof(net_wifi_state_t);
72 event_data.Data = &(NetworkInfo.wifi_state);
74 _net_client_callback(&event_data);
76 __NETWORK_FUNC_EXIT__;
80 static wlan_security_mode_type_t __net_get_wlan_sec_mode(int security)
84 return WLAN_SEC_MODE_NONE;
86 return WLAN_SEC_MODE_WEP;
88 return WLAN_SEC_MODE_WPA_PSK;
90 return WLAN_SEC_MODE_IEEE8021X;
94 static int __net_handle_specific_scan_resp(GSList *bss_info_list)
96 __NETWORK_FUNC_ENTER__;
99 net_event_info_t event_data = { 0, };
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));
105 _net_dbus_pending_call_unref();
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,
113 event_data.Event = NET_EVENT_SPECIFIC_SCAN_IND;
114 event_data.Datalength = count;
115 event_data.Data = bss_info_list;
117 _net_client_callback(&event_data);
119 g_slist_free_full(bss_info_list, g_free);
121 __NETWORK_FUNC_EXIT__;
125 static int __net_handle_wifi_specific_scan_rsp(GVariant *param)
127 GVariantIter *iter = NULL;
128 GVariant *value = NULL;
130 const gchar *ssid = NULL;
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;
138 g_variant_get(param, "(a{sv})", &iter);
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);
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);
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);
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);
161 NETWORK_LOG(NETWORK_ERROR, "Memory allocation error");
163 g_slist_free_full(bss_info_list, g_free);
164 g_variant_unref(value);
166 return NET_ERR_UNKNOWN;
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);
174 ssid_found = sec_found = wps_found = FALSE;
177 g_variant_iter_free(iter);
179 __net_handle_specific_scan_resp(bss_info_list);
181 /* To enhance performance,
182 * BSS list should be release in a delayed manner in _net_client_callback */
187 static int __net_handle_wps_scan_resp(GSList *bss_info_list)
189 __NETWORK_FUNC_ENTER__;
192 net_event_info_t event_data = { 0, };
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));
198 _net_dbus_pending_call_unref();
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,
206 event_data.Event = NET_EVENT_WPS_SCAN_IND;
207 event_data.Datalength = count;
208 event_data.Data = bss_info_list;
210 _net_client_callback(&event_data);
212 g_slist_free_full(bss_info_list, g_free);
214 __NETWORK_FUNC_EXIT__;
218 static int __net_handle_wifi_wps_scan_rsp(GVariant *param)
220 GVariantIter *iter = NULL;
221 GVariant *value = NULL;
223 GSList *bss_info_list = NULL;
224 const gchar *ssid = NULL;
225 const gchar *bssid = NULL;
229 gboolean ssid_found = FALSE;
230 gboolean bssid_found = FALSE;
231 gboolean rssi_found = FALSE;
232 gboolean mode_found = FALSE;
234 g_variant_get(param, "(a{sv})", &iter);
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));
240 } else if (g_strcmp0(key, "bssid") == 0) {
241 bssid = g_variant_get_string(value, NULL);
243 } else if (g_strcmp0(key, "rssi") == 0) {
244 rssi = g_variant_get_int32(value);
246 } else if (g_strcmp0(key, "mode") == 0) {
247 mode = g_variant_get_int32(value);
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);
256 NETWORK_LOG(NETWORK_ERROR, "Memory allocation error");
258 g_slist_free_full(bss_info_list, g_free);
259 g_variant_unref(value);
261 return NET_ERR_UNKNOWN;
264 memcpy(bss->ssid, ssid, ssid_len);
265 g_strlcpy(bss->bssid, bssid, NET_WLAN_BSSID_LEN+1);
268 bss_info_list = g_slist_append(bss_info_list, bss);
270 ssid_found = bssid_found = FALSE;
271 rssi_found = mode_found = FALSE;
274 g_variant_iter_free(iter);
276 __net_handle_wps_scan_resp(bss_info_list);
281 static void __net_handle_state_ind(const char *profile_name,
282 net_state_type_t profile_state)
284 __NETWORK_FUNC_ENTER__;
286 net_event_info_t event_data = { 0, };
288 event_data.Error = NET_ERR_NONE;
289 event_data.Event = NET_EVENT_NET_STATE_IND;
291 g_strlcpy(event_data.ProfileName, profile_name, sizeof(event_data.ProfileName));
293 event_data.Datalength = sizeof(net_state_type_t);
294 event_data.Data = &profile_state;
296 NETWORK_LOG(NETWORK_LOW,
297 "Sending NET_EVENT_NET_STATE_IND, state: %d, profile name: %s",
298 profile_state, event_data.ProfileName);
300 _net_client_callback(&event_data);
302 __NETWORK_FUNC_EXIT__;
305 static void __net_handle_failure_ind(const char *profile_name,
306 net_device_t device_type)
308 __NETWORK_FUNC_ENTER__;
310 net_event_info_t event_data = { 0, };
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;
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));
324 event_data.Event = NET_EVENT_OPEN_RSP;
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));
332 event_data.Event = NET_EVENT_WIFI_WPS_RSP;
334 memset(&request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION], 0,
335 sizeof(network_request_table_t));
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));
343 event_data.Event = NET_EVENT_CLOSE_RSP;
345 _net_dbus_pending_call_unref();
347 __net_handle_state_ind(profile_name, NET_STATE_TYPE_FAILURE);
349 __NETWORK_FUNC_EXIT__;
353 g_strlcpy(event_data.ProfileName,
354 profile_name, NET_PROFILE_NAME_LEN_MAX+1);
356 if (net_service_error != NET_ERR_NONE)
357 event_data.Error = net_service_error;
359 event_data.Error = NET_ERR_CONNECTION_CONNECT_FAILED;
360 NETWORK_LOG(NETWORK_ERROR, "Event error defined %d", event_data.Error);
362 event_data.Datalength = 0;
363 event_data.Data = NULL;
365 net_service_error = NET_ERR_NONE;
367 NETWORK_LOG(NETWORK_ERROR, "State failure %d", event_data.Error);
368 _net_client_callback(&event_data);
370 /* Reseting the state back in case of failure state */
371 service_state_table[device_type] = NET_STATE_TYPE_IDLE;
373 __NETWORK_FUNC_EXIT__;
376 static int string2state(const char *state)
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;
393 return NET_STATE_TYPE_UNKNOWN;
396 static int __net_handle_service_state_changed(const gchar *sig_path,
397 const char *key, const char *state)
399 net_err_t Error = NET_ERR_NONE;
400 net_state_type_t old_state, new_state;
402 net_event_info_t event_data = { 0, };
403 net_device_t device_type = NET_DEVICE_UNKNOWN;
405 if (sig_path == NULL)
408 device_type = _net_get_tech_type_from_path(sig_path);
409 if (device_type == NET_DEVICE_UNKNOWN)
412 NETWORK_LOG(NETWORK_LOW, "[%s] %s", state, sig_path);
414 if (device_type == NET_DEVICE_WIFI && NetworkInfo.wifi_state == WIFI_OFF) {
415 NETWORK_LOG(NETWORK_LOW, "Wi-Fi is off");
419 old_state = service_state_table[device_type];
420 new_state = string2state(state);
422 if (old_state == new_state)
425 service_state_table[device_type] = 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;
433 case NET_STATE_TYPE_ASSOCIATION:
434 case NET_STATE_TYPE_CONFIGURATION:
435 __net_handle_state_ind(sig_path, new_state);
438 case NET_STATE_TYPE_READY:
439 case NET_STATE_TYPE_ONLINE:
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;
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));
453 event_data.Event = NET_EVENT_OPEN_RSP;
455 NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_OPEN_RSP");
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));
463 event_data.Event = NET_EVENT_WIFI_WPS_RSP;
465 NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_WIFI_WPS_RSP");
467 _net_dbus_pending_call_unref();
469 event_data.Event = NET_EVENT_OPEN_IND;
471 NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_OPEN_IND");
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));
479 event_data.Datalength = 0;
480 event_data.Data = NULL;
482 event_data.Datalength = sizeof(net_profile_info_t);
483 event_data.Data = &prof_info;
486 event_data.Error = Error;
487 g_strlcpy(event_data.ProfileName, sig_path, NET_PROFILE_NAME_LEN_MAX+1);
489 _net_client_callback(&event_data);
491 __net_handle_state_ind(sig_path, new_state);
495 case NET_STATE_TYPE_DISCONNECT:
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;
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);
512 event_data.Datalength = 0;
513 event_data.Data = NULL;
515 NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_CLOSE_IND");
517 _net_client_callback(&event_data);
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));
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);
530 event_data.Datalength = 0;
531 event_data.Data = NULL;
533 NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_OPEN_RSP");
535 _net_dbus_pending_call_unref();
537 _net_client_callback(&event_data);
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));
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);
550 event_data.Datalength = 0;
551 event_data.Data = NULL;
553 NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_WIFI_WPS_RSP");
554 _net_dbus_pending_call_unref();
556 _net_client_callback(&event_data);
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));
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);
569 event_data.Datalength = 0;
570 event_data.Data = NULL;
572 NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_CLOSE_RSP");
574 _net_dbus_pending_call_unref();
576 _net_client_callback(&event_data);
580 case NET_STATE_TYPE_FAILURE:
581 __net_handle_failure_ind(sig_path, device_type);
585 Error = NET_ERR_UNKNOWN_METHOD;
592 static int string2error(const char *error)
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;
609 return NET_ERR_UNKNOWN;
612 static int __net_handle_service_set_error(const char *key, const char *error)
614 if (error == NULL || *error == '\0')
617 NETWORK_LOG(NETWORK_ERROR, "[%s] %s", key, error);
619 net_service_error = string2error(error);
624 static int __net_handle_scan_done(GVariant *param)
626 net_event_info_t event_data = { 0, };
628 if (request_table[NETWORK_REQUEST_TYPE_SPECIFIC_SCAN].flag == TRUE)
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));
634 event_data.Event = NET_EVENT_WIFI_SCAN_RSP;
636 _net_dbus_pending_call_unref();
638 event_data.Event = NET_EVENT_WIFI_SCAN_IND;
641 event_data.Error = NET_ERR_NONE;
642 event_data.Datalength = 0;
643 event_data.Data = NULL;
645 _net_client_callback(&event_data);
650 static int __net_handle_ethernet_cable_state_rsp(GVariant *param)
652 GVariantIter *iter = NULL;
653 GVariant *value = NULL;
654 const char *key = NULL;
655 const gchar *sig_value = NULL;
657 g_variant_get(param, "(a{sv})", &iter);
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",
666 g_variant_iter_free(iter);
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;
673 event_data.Event = NET_EVENT_ETHERNET_CABLE_DETACHED;
674 event_data.Error = NET_ERR_NONE;
676 event_data.Datalength = 0;
677 event_data.Data = NULL;
679 _net_client_callback(&event_data);
683 static int __net_handle_network_dpm_wifi_event(GVariant *param)
685 __NETWORK_FUNC_ENTER__;
687 GVariantIter *iter = NULL;
688 GVariant *value = NULL;
689 const char *key = NULL;
690 const gchar *sig_value = NULL;
692 g_variant_get(param, "(a{sv})", &iter);
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",
699 if (g_strcmp0(sig_value, "allowed") == 0)
700 net_dpm_wifi_state = TRUE;
702 net_dpm_wifi_state = FALSE;
705 g_variant_iter_free(iter);
708 __NETWORK_FUNC_EXIT__;
711 static int __net_handle_network_dpm_wifi_profile_event(GVariant *param)
713 __NETWORK_FUNC_ENTER__;
715 GVariantIter *iter = NULL;
716 GVariant *value = NULL;
717 const char *key = NULL;
718 const gchar *sig_value = NULL;
720 g_variant_get(param, "(a{sv})", &iter);
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",
727 if (g_strcmp0(sig_value, "allowed") == 0)
728 net_dpm_wifi_profile_state = TRUE;
730 net_dpm_wifi_profile_state = FALSE;
733 g_variant_iter_free(iter);
736 __NETWORK_FUNC_EXIT__;
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)
743 __NETWORK_FUNC_ENTER__;
745 const char *key = NULL;
746 const char *value = NULL;
749 if (g_strcmp0(sig, SIGNAL_PROPERTY_CHANGED) == 0) {
750 g_variant_get(param, "(sv)", &key, &var);
752 if (g_strcmp0(key, "State") == 0) {
753 g_variant_get(var, "s", &value);
755 __net_handle_service_state_changed(path, key, value);
756 } else if (g_strcmp0(key, "Error") == 0) {
757 g_variant_get(var, "s", &value);
759 __net_handle_service_set_error(key, value);
762 g_free((gchar *)value);
763 g_free((gchar *)key);
765 g_variant_unref(var);
768 __NETWORK_FUNC_EXIT__;
770 static int __net_handle_wifi_tdls_connected_event(GVariant *param)
772 __NETWORK_FUNC_ENTER__;
774 GVariantIter *iter = NULL;
775 GVariant *value = NULL;
776 const char *key = NULL;
777 const gchar *sig_value = NULL;
779 g_variant_get(param, "(a{sv})", &iter);
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);
785 NETWORK_LOG(NETWORK_ERROR, "TDLS Connected Peer Mac Adress: %s",
789 g_variant_iter_free(iter);
791 net_event_info_t event_data;
792 memset(&event_data, 0, sizeof(event_data));
794 event_data.Error = NET_ERR_NONE;
795 event_data.Event = NET_EVENT_TDLS_CONNECTED_IND;
796 event_data.Data = g_strdup(sig_value);
799 event_data.Datalength = strlen(event_data.Data);
801 event_data.Datalength = 0;
803 NETWORK_LOG(NETWORK_ERROR, "Sending NET_EVENT_TDLS_CONNECTED_IND");
804 _net_client_callback(&event_data);
805 g_free(event_data.Data);
807 __NETWORK_FUNC_EXIT__;
811 static int __net_handle_wifi_tdls_disconnected_event(GVariant *param)
813 __NETWORK_FUNC_ENTER__;
815 GVariantIter *iter = NULL;
816 GVariant *value = NULL;
817 const char *key = NULL;
818 const gchar *sig_value = NULL;
820 g_variant_get(param, "(a{sv})", &iter);
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);
826 NETWORK_LOG(NETWORK_ERROR, "TDLS Connected Peer Mac Adress: %s",
830 g_variant_iter_free(iter);
832 net_event_info_t event_data;
833 memset(&event_data, 0, sizeof(event_data));
835 event_data.Error = NET_ERR_NONE;
836 event_data.Event = NET_EVENT_TDLS_DISCONNECTED_IND;
837 event_data.Data = g_strdup(sig_value);
840 event_data.Datalength = strlen(event_data.Data);
842 event_data.Datalength = 0;
844 NETWORK_LOG(NETWORK_ERROR, "Sending NET_EVENT_TDLS_DISCONNECTED_IND");
845 _net_client_callback(&event_data);
846 g_free(event_data.Data);
848 __NETWORK_FUNC_EXIT__;
852 static int __net_handle_wifi_connect_fail_event(GVariant *param)
854 __NETWORK_FUNC_ENTER__;
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];
862 event_data.Datalength = 0;
863 event_data.Data = NULL;
865 NETWORK_LOG(NETWORK_HIGH, "Failed to connect WiFi");
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");
878 NETWORK_LOG(NETWORK_LOW, "WiFi Connection flag not set");
879 __NETWORK_FUNC_EXIT__;
882 _net_client_callback(&event_data);
884 __NETWORK_FUNC_EXIT__;
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)
892 if (g_strcmp0(sig, SIGNAL_SCAN_DONE) == 0)
893 __net_handle_scan_done(param);
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)
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);
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)
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);
928 /*****************************************************************************
930 *****************************************************************************/
932 int _net_get_dpm_wifi_state(void)
934 return net_dpm_wifi_state;
937 void _net_set_dpm_wifi_state(int state)
939 net_dpm_wifi_state = state;
942 gboolean _net_get_dpm_wifi_profile_state()
944 return net_dpm_wifi_profile_state;
947 void _net_set_dpm_wifi_profile_state(int state)
949 net_dpm_wifi_profile_state = state;
952 int _net_deregister_signal(void)
954 __NETWORK_FUNC_ENTER__;
956 GDBusConnection *connection;
957 net_err_t Error = NET_ERR_NONE;
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;
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);
977 Error = _net_dbus_close_gdbus_call();
978 if (Error != NET_ERR_NONE) {
979 __NETWORK_FUNC_EXIT__;
983 __NETWORK_FUNC_EXIT__;
987 int _net_subscribe_signal_wifi(void)
989 __NETWORK_FUNC_ENTER__;
991 GDBusConnection *connection;
992 net_err_t Error = NET_ERR_NONE;
994 connection = _net_dbus_get_gdbus_conn();
995 if (connection == NULL) {
996 __NETWORK_FUNC_EXIT__;
997 return NET_ERR_UNKNOWN;
1000 /* Create supplicant service connection */
1001 gdbus_conn_subscribe_id_supplicant = g_dbus_connection_signal_subscribe(
1004 SUPPLICANT_IFACE_INTERFACE,
1008 G_DBUS_SIGNAL_FLAGS_NONE,
1009 __net_supplicant_signal_filter,
1013 /* Create net-config service connection */
1014 gdbus_conn_subscribe_id_netconfig_wifi = g_dbus_connection_signal_subscribe(
1017 NETCONFIG_WIFI_INTERFACE,
1019 NETCONFIG_WIFI_PATH,
1021 G_DBUS_SIGNAL_FLAGS_NONE,
1022 __net_netconfig_signal_filter,
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;
1035 __NETWORK_FUNC_EXIT__;
1039 int _net_register_signal(void)
1041 __NETWORK_FUNC_ENTER__;
1043 GDBusConnection *connection;
1044 net_err_t Error = NET_ERR_NONE;
1046 Error = _net_dbus_create_gdbus_call();
1047 if (Error != NET_ERR_NONE) {
1048 __NETWORK_FUNC_EXIT__;
1052 connection = _net_dbus_get_gdbus_conn();
1053 if (connection == NULL) {
1054 __NETWORK_FUNC_EXIT__;
1055 return NET_ERR_UNKNOWN;
1058 /* Create connman service state connection */
1059 gdbus_conn_subscribe_id_connman_state = g_dbus_connection_signal_subscribe(
1062 CONNMAN_SERVICE_INTERFACE,
1063 SIGNAL_PROPERTY_CHANGED,
1066 G_DBUS_SIGNAL_FLAGS_NONE,
1067 __net_connman_service_signal_filter,
1071 /* Create connman service error connection */
1072 gdbus_conn_subscribe_id_connman_error = g_dbus_connection_signal_subscribe(
1075 CONNMAN_SERVICE_INTERFACE,
1076 SIGNAL_PROPERTY_CHANGED,
1079 G_DBUS_SIGNAL_FLAGS_NONE,
1080 __net_connman_service_signal_filter,
1084 /* Create net-config service connection for network */
1085 gdbus_conn_subscribe_id_netconfig = g_dbus_connection_signal_subscribe(
1088 NETCONFIG_NETWORK_INTERFACE,
1090 NETCONFIG_NETWORK_PATH,
1092 G_DBUS_SIGNAL_FLAGS_NONE,
1093 __net_netconfig_network_signal_filter,
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;
1108 __NETWORK_FUNC_EXIT__;
1112 static int __net_get_all_tech_states(GVariant *msg, net_state_type_t *state_table)
1114 __NETWORK_FUNC_ENTER__;
1116 net_err_t Error = NET_ERR_NONE;
1117 GVariantIter *iter_main = NULL;
1118 GVariantIter *var = NULL;
1119 GVariant *value = NULL;
1124 g_variant_get(msg, "(a(oa{sv}))", &iter_main);
1125 while (g_variant_iter_loop(iter_main, "(oa{sv})", &path, &var)) {
1130 while (g_variant_iter_loop(var, "{sv}", &key, &value)) {
1131 if (g_strcmp0(key, "Connected") == 0) {
1132 data = g_variant_get_boolean(value);
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;
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);
1151 NetworkInfo.wifi_state = WIFI_OFF;
1152 else if (data == TRUE && NetworkInfo.wifi_state < WIFI_ON)
1153 NetworkInfo.wifi_state = WIFI_ON;
1157 g_variant_iter_free(iter_main);
1159 __NETWORK_FUNC_EXIT__;
1163 static int __net_dbus_get_all_technology_states(net_state_type_t *state_table)
1165 __NETWORK_FUNC_ENTER__;
1167 net_err_t Error = NET_ERR_NONE;
1168 GVariant *message = NULL;
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");
1178 Error = __net_get_all_tech_states(message, state_table);
1180 g_variant_unref(message);
1183 __NETWORK_FUNC_EXIT__;
1187 int _net_init_service_state_table(void)
1189 __NETWORK_FUNC_ENTER__;
1191 net_err_t Error = NET_ERR_NONE;
1193 Error = __net_dbus_get_all_technology_states(&service_state_table[0]);
1194 if (Error != NET_ERR_NONE) {
1195 __NETWORK_FUNC_EXIT__;
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]);
1206 __NETWORK_FUNC_EXIT__;
1207 return NET_ERR_NONE;