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_WPA2_PSK;
92 return WLAN_SEC_MODE_IEEE8021X;
96 static int __net_handle_specific_scan_resp(GSList *bss_info_list)
98 __NETWORK_FUNC_ENTER__;
101 net_event_info_t event_data = { 0, };
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));
107 _net_dbus_pending_call_unref();
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,
115 event_data.Event = NET_EVENT_SPECIFIC_SCAN_IND;
116 event_data.Datalength = count;
117 event_data.Data = bss_info_list;
119 _net_client_callback(&event_data);
121 g_slist_free_full(bss_info_list, g_free);
123 __NETWORK_FUNC_EXIT__;
127 static int __net_handle_wifi_specific_scan_rsp(GVariant *param)
129 GVariantIter *iter = NULL;
130 GVariant *value = NULL;
132 const gchar *ssid = NULL;
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;
140 g_variant_get(param, "(a{sv})", &iter);
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);
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);
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);
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);
163 NETWORK_LOG(NETWORK_ERROR, "Memory allocation error");
165 g_slist_free_full(bss_info_list, g_free);
166 g_variant_unref(value);
168 return NET_ERR_UNKNOWN;
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);
176 ssid_found = sec_found = wps_found = FALSE;
179 g_variant_iter_free(iter);
181 __net_handle_specific_scan_resp(bss_info_list);
183 /* To enhance performance,
184 * BSS list should be release in a delayed manner in _net_client_callback */
189 static int __net_handle_wps_scan_resp(GSList *bss_info_list)
191 __NETWORK_FUNC_ENTER__;
194 net_event_info_t event_data = { 0, };
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));
200 _net_dbus_pending_call_unref();
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,
208 event_data.Event = NET_EVENT_WPS_SCAN_IND;
209 event_data.Datalength = count;
210 event_data.Data = bss_info_list;
212 _net_client_callback(&event_data);
214 g_slist_free_full(bss_info_list, g_free);
216 __NETWORK_FUNC_EXIT__;
220 static int __net_handle_wifi_wps_scan_rsp(GVariant *param)
222 GVariantIter *iter = NULL;
223 GVariant *value = NULL;
225 GSList *bss_info_list = NULL;
226 const gchar *ssid = NULL;
227 const gchar *bssid = NULL;
231 gboolean ssid_found = FALSE;
232 gboolean bssid_found = FALSE;
233 gboolean rssi_found = FALSE;
234 gboolean mode_found = FALSE;
236 g_variant_get(param, "(a{sv})", &iter);
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));
242 } else if (g_strcmp0(key, "bssid") == 0) {
243 bssid = g_variant_get_string(value, NULL);
245 } else if (g_strcmp0(key, "rssi") == 0) {
246 rssi = g_variant_get_int32(value);
248 } else if (g_strcmp0(key, "mode") == 0) {
249 mode = g_variant_get_int32(value);
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);
258 NETWORK_LOG(NETWORK_ERROR, "Memory allocation error");
260 g_slist_free_full(bss_info_list, g_free);
261 g_variant_unref(value);
263 return NET_ERR_UNKNOWN;
266 memcpy(bss->ssid, ssid, ssid_len);
267 g_strlcpy(bss->bssid, bssid, NET_WLAN_BSSID_LEN+1);
270 bss_info_list = g_slist_append(bss_info_list, bss);
272 ssid_found = bssid_found = FALSE;
273 rssi_found = mode_found = FALSE;
276 g_variant_iter_free(iter);
278 __net_handle_wps_scan_resp(bss_info_list);
283 static void __net_handle_state_ind(const char *profile_name,
284 net_state_type_t profile_state)
286 __NETWORK_FUNC_ENTER__;
288 net_event_info_t event_data = { 0, };
290 event_data.Error = NET_ERR_NONE;
291 event_data.Event = NET_EVENT_NET_STATE_IND;
293 g_strlcpy(event_data.ProfileName, profile_name, sizeof(event_data.ProfileName));
295 event_data.Datalength = sizeof(net_state_type_t);
296 event_data.Data = &profile_state;
298 NETWORK_LOG(NETWORK_LOW,
299 "Sending NET_EVENT_NET_STATE_IND, state: %d, profile name: %s",
300 profile_state, event_data.ProfileName);
302 _net_client_callback(&event_data);
304 __NETWORK_FUNC_EXIT__;
307 static void __net_handle_failure_ind(const char *profile_name,
308 net_device_t device_type)
310 __NETWORK_FUNC_ENTER__;
312 net_event_info_t event_data = { 0, };
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;
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));
326 event_data.Event = NET_EVENT_OPEN_RSP;
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));
334 event_data.Event = NET_EVENT_WIFI_WPS_RSP;
336 memset(&request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION], 0,
337 sizeof(network_request_table_t));
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));
345 event_data.Event = NET_EVENT_CLOSE_RSP;
347 _net_dbus_pending_call_unref();
349 __net_handle_state_ind(profile_name, NET_STATE_TYPE_FAILURE);
351 __NETWORK_FUNC_EXIT__;
355 g_strlcpy(event_data.ProfileName,
356 profile_name, NET_PROFILE_NAME_LEN_MAX+1);
358 if (net_service_error != NET_ERR_NONE)
359 event_data.Error = net_service_error;
361 event_data.Error = NET_ERR_CONNECTION_CONNECT_FAILED;
362 NETWORK_LOG(NETWORK_ERROR, "Event error defined %d", event_data.Error);
364 event_data.Datalength = 0;
365 event_data.Data = NULL;
367 net_service_error = NET_ERR_NONE;
369 NETWORK_LOG(NETWORK_ERROR, "State failure %d", event_data.Error);
370 _net_client_callback(&event_data);
372 /* Reseting the state back in case of failure state */
373 service_state_table[device_type] = NET_STATE_TYPE_IDLE;
375 __NETWORK_FUNC_EXIT__;
378 static int string2state(const char *state)
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;
395 return NET_STATE_TYPE_UNKNOWN;
398 static int __net_handle_service_state_changed(const gchar *sig_path,
399 const char *key, const char *state)
401 net_err_t Error = NET_ERR_NONE;
402 net_state_type_t old_state, new_state;
404 net_event_info_t event_data = { 0, };
405 net_device_t device_type = NET_DEVICE_UNKNOWN;
407 if (sig_path == NULL)
410 device_type = _net_get_tech_type_from_path(sig_path);
411 if (device_type == NET_DEVICE_UNKNOWN)
414 NETWORK_LOG(NETWORK_LOW, "[%s] %s", state, sig_path);
416 if (device_type == NET_DEVICE_WIFI && NetworkInfo.wifi_state == WIFI_OFF) {
417 NETWORK_LOG(NETWORK_LOW, "Wi-Fi is off");
421 old_state = service_state_table[device_type];
422 new_state = string2state(state);
424 if (old_state == new_state)
427 service_state_table[device_type] = 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;
435 if (old_state == NET_STATE_TYPE_DISCONNECT)
437 case NET_STATE_TYPE_ASSOCIATION:
438 case NET_STATE_TYPE_CONFIGURATION:
439 __net_handle_state_ind(sig_path, new_state);
442 case NET_STATE_TYPE_READY:
443 case NET_STATE_TYPE_ONLINE:
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;
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));
457 event_data.Event = NET_EVENT_OPEN_RSP;
459 NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_OPEN_RSP");
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));
467 event_data.Event = NET_EVENT_WIFI_WPS_RSP;
469 NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_WIFI_WPS_RSP");
471 _net_dbus_pending_call_unref();
473 event_data.Event = NET_EVENT_OPEN_IND;
475 NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_OPEN_IND");
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));
483 event_data.Datalength = 0;
484 event_data.Data = NULL;
486 event_data.Datalength = sizeof(net_profile_info_t);
487 event_data.Data = &prof_info;
490 event_data.Error = Error;
491 g_strlcpy(event_data.ProfileName, sig_path, NET_PROFILE_NAME_LEN_MAX+1);
493 _net_client_callback(&event_data);
498 case NET_STATE_TYPE_DISCONNECT:
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;
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));
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);
517 event_data.Datalength = 0;
518 event_data.Data = NULL;
520 NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_OPEN_RSP");
522 _net_dbus_pending_call_unref();
524 _net_client_callback(&event_data);
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));
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);
538 event_data.Datalength = 0;
539 event_data.Data = NULL;
541 NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_WIFI_WPS_RSP");
542 _net_dbus_pending_call_unref();
544 _net_client_callback(&event_data);
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));
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);
558 event_data.Datalength = 0;
559 event_data.Data = NULL;
561 NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_CLOSE_RSP");
563 _net_dbus_pending_call_unref();
565 _net_client_callback(&event_data);
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);
574 event_data.Datalength = 0;
575 event_data.Data = NULL;
577 NETWORK_LOG(NETWORK_LOW, "Sending NET_EVENT_CLOSE_IND");
579 _net_client_callback(&event_data);
583 case NET_STATE_TYPE_FAILURE:
584 __net_handle_failure_ind(sig_path, device_type);
588 Error = NET_ERR_UNKNOWN_METHOD;
595 static int string2error(const char *error)
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;
612 return NET_ERR_UNKNOWN;
615 static int __net_handle_service_set_error(const char *key, const char *error)
617 if (error == NULL || *error == '\0')
620 NETWORK_LOG(NETWORK_ERROR, "[%s] %s", key, error);
622 net_service_error = string2error(error);
627 static int __net_handle_scan_done(GVariant *param)
629 net_event_info_t event_data = { 0, };
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));
635 event_data.Event = NET_EVENT_WIFI_SCAN_RSP;
637 _net_dbus_pending_call_unref();
639 event_data.Event = NET_EVENT_WIFI_SCAN_IND;
642 event_data.Error = NET_ERR_NONE;
643 event_data.Datalength = 0;
644 event_data.Data = NULL;
646 _net_client_callback(&event_data);
651 static int __net_handle_ethernet_cable_state_rsp(GVariant *param)
653 GVariantIter *iter = NULL;
654 GVariant *value = NULL;
655 const char *key = NULL;
656 const gchar *sig_value = NULL;
658 g_variant_get(param, "(a{sv})", &iter);
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",
667 g_variant_iter_free(iter);
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;
674 event_data.Event = NET_EVENT_ETHERNET_CABLE_DETACHED;
675 event_data.Error = NET_ERR_NONE;
677 event_data.Datalength = 0;
678 event_data.Data = NULL;
680 _net_client_callback(&event_data);
684 static int __net_handle_network_dpm_wifi_event(GVariant *param)
686 __NETWORK_FUNC_ENTER__;
688 GVariantIter *iter = NULL;
689 GVariant *value = NULL;
690 const char *key = NULL;
691 const gchar *sig_value = NULL;
693 g_variant_get(param, "(a{sv})", &iter);
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",
700 if (g_strcmp0(sig_value, "allowed") == 0)
701 net_dpm_wifi_state = TRUE;
703 net_dpm_wifi_state = FALSE;
706 g_variant_iter_free(iter);
708 __NETWORK_FUNC_EXIT__;
712 static int __net_handle_network_dpm_wifi_profile_event(GVariant *param)
714 __NETWORK_FUNC_ENTER__;
716 GVariantIter *iter = NULL;
717 GVariant *value = NULL;
718 const char *key = NULL;
719 const gchar *sig_value = NULL;
721 g_variant_get(param, "(a{sv})", &iter);
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",
728 if (g_strcmp0(sig_value, "allowed") == 0)
729 net_dpm_wifi_profile_state = TRUE;
731 net_dpm_wifi_profile_state = FALSE;
734 g_variant_iter_free(iter);
736 __NETWORK_FUNC_EXIT__;
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)
744 __NETWORK_FUNC_ENTER__;
746 const char *key = NULL;
747 const char *value = NULL;
750 if (g_strcmp0(sig, SIGNAL_PROPERTY_CHANGED) == 0) {
751 g_variant_get(param, "(sv)", &key, &var);
753 if (g_strcmp0(key, "State") == 0) {
754 g_variant_get(var, "s", &value);
756 __net_handle_service_state_changed(path, key, value);
757 } else if (g_strcmp0(key, "Error") == 0) {
758 g_variant_get(var, "s", &value);
760 __net_handle_service_set_error(key, value);
763 g_free((gchar *)value);
764 g_free((gchar *)key);
766 g_variant_unref(var);
769 __NETWORK_FUNC_EXIT__;
771 static int __net_handle_wifi_tdls_connected_event(GVariant *param)
773 __NETWORK_FUNC_ENTER__;
775 GVariantIter *iter = NULL;
776 GVariant *value = NULL;
777 const char *key = NULL;
778 const gchar *sig_value = NULL;
780 g_variant_get(param, "(a{sv})", &iter);
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);
786 NETWORK_LOG(NETWORK_ERROR, "TDLS Connected Peer Mac Address: %s",
790 g_variant_iter_free(iter);
792 net_event_info_t event_data;
793 memset(&event_data, 0, sizeof(event_data));
795 event_data.Error = NET_ERR_NONE;
796 event_data.Event = NET_EVENT_TDLS_CONNECTED_IND;
797 event_data.Data = g_strdup(sig_value);
800 event_data.Datalength = strlen(event_data.Data) + 1;
802 event_data.Datalength = 0;
804 NETWORK_LOG(NETWORK_ERROR, "Sending NET_EVENT_TDLS_CONNECTED_IND");
805 _net_client_callback(&event_data);
806 g_free(event_data.Data);
808 __NETWORK_FUNC_EXIT__;
812 static int __net_handle_wifi_tdls_disconnected_event(GVariant *param)
814 __NETWORK_FUNC_ENTER__;
816 GVariantIter *iter = NULL;
817 GVariant *value = NULL;
818 const char *key = NULL;
819 const gchar *sig_value = NULL;
821 g_variant_get(param, "(a{sv})", &iter);
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);
827 NETWORK_LOG(NETWORK_ERROR, "TDLS Connected Peer Mac Address: %s",
831 g_variant_iter_free(iter);
833 net_event_info_t event_data;
834 memset(&event_data, 0, sizeof(event_data));
836 event_data.Error = NET_ERR_NONE;
837 event_data.Event = NET_EVENT_TDLS_DISCONNECTED_IND;
838 event_data.Data = g_strdup(sig_value);
841 event_data.Datalength = strlen(event_data.Data) + 1;
843 event_data.Datalength = 0;
845 NETWORK_LOG(NETWORK_ERROR, "Sending NET_EVENT_TDLS_DISCONNECTED_IND");
846 _net_client_callback(&event_data);
847 g_free(event_data.Data);
849 __NETWORK_FUNC_EXIT__;
853 static int __net_handle_wifi_connect_fail_event(GVariant *param)
855 __NETWORK_FUNC_ENTER__;
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];
863 event_data.Datalength = 0;
864 event_data.Data = NULL;
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);
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");
881 NETWORK_LOG(NETWORK_LOW, "WiFi Connection flag not set");
882 __NETWORK_FUNC_EXIT__;
885 _net_client_callback(&event_data);
887 __NETWORK_FUNC_EXIT__;
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)
895 if (g_strcmp0(sig, SIGNAL_SCAN_DONE) == 0)
896 __net_handle_scan_done(param);
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)
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);
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)
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);
931 /*****************************************************************************
933 *****************************************************************************/
935 int _net_get_dpm_wifi_state(void)
937 return net_dpm_wifi_state;
940 void _net_set_dpm_wifi_state(int state)
942 net_dpm_wifi_state = state;
945 gboolean _net_get_dpm_wifi_profile_state()
947 return net_dpm_wifi_profile_state;
950 void _net_set_dpm_wifi_profile_state(int state)
952 net_dpm_wifi_profile_state = state;
955 int _net_deregister_signal(void)
957 __NETWORK_FUNC_ENTER__;
959 GDBusConnection *connection;
960 net_err_t Error = NET_ERR_NONE;
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;
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);
980 Error = _net_dbus_close_gdbus_call();
981 if (Error != NET_ERR_NONE) {
982 __NETWORK_FUNC_EXIT__;
986 __NETWORK_FUNC_EXIT__;
990 int _net_subscribe_signal_wifi(void)
992 __NETWORK_FUNC_ENTER__;
994 GDBusConnection *connection;
995 net_err_t Error = NET_ERR_NONE;
997 connection = _net_dbus_get_gdbus_conn();
998 if (connection == NULL) {
999 __NETWORK_FUNC_EXIT__;
1000 return NET_ERR_UNKNOWN;
1003 /* Create supplicant service connection */
1004 gdbus_conn_subscribe_id_supplicant = g_dbus_connection_signal_subscribe(
1007 CONNMAN_MANAGER_INTERFACE,
1009 CONNMAN_MANAGER_PATH,
1011 G_DBUS_SIGNAL_FLAGS_NONE,
1012 __net_connman_manager_signal_filter,
1016 /* Create net-config service connection */
1017 gdbus_conn_subscribe_id_netconfig_wifi = g_dbus_connection_signal_subscribe(
1020 NETCONFIG_WIFI_INTERFACE,
1022 NETCONFIG_WIFI_PATH,
1024 G_DBUS_SIGNAL_FLAGS_NONE,
1025 __net_netconfig_signal_filter,
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;
1038 __NETWORK_FUNC_EXIT__;
1042 int _net_register_signal(void)
1044 __NETWORK_FUNC_ENTER__;
1046 GDBusConnection *connection;
1047 net_err_t Error = NET_ERR_NONE;
1049 Error = _net_dbus_create_gdbus_call();
1050 if (Error != NET_ERR_NONE) {
1051 __NETWORK_FUNC_EXIT__;
1055 connection = _net_dbus_get_gdbus_conn();
1056 if (connection == NULL) {
1057 __NETWORK_FUNC_EXIT__;
1058 return NET_ERR_UNKNOWN;
1061 /* Create connman service state connection */
1062 gdbus_conn_subscribe_id_connman_state = g_dbus_connection_signal_subscribe(
1065 CONNMAN_SERVICE_INTERFACE,
1066 SIGNAL_PROPERTY_CHANGED,
1069 G_DBUS_SIGNAL_FLAGS_NONE,
1070 __net_connman_service_signal_filter,
1074 /* Create connman service error connection */
1075 gdbus_conn_subscribe_id_connman_error = g_dbus_connection_signal_subscribe(
1078 CONNMAN_SERVICE_INTERFACE,
1079 SIGNAL_PROPERTY_CHANGED,
1082 G_DBUS_SIGNAL_FLAGS_NONE,
1083 __net_connman_service_signal_filter,
1087 /* Create net-config service connection for network */
1088 gdbus_conn_subscribe_id_netconfig = g_dbus_connection_signal_subscribe(
1091 NETCONFIG_NETWORK_INTERFACE,
1093 NETCONFIG_NETWORK_PATH,
1095 G_DBUS_SIGNAL_FLAGS_NONE,
1096 __net_netconfig_network_signal_filter,
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;
1111 __NETWORK_FUNC_EXIT__;
1115 static int __net_get_all_tech_states(GVariant *msg, net_state_type_t *state_table)
1117 __NETWORK_FUNC_ENTER__;
1119 net_err_t Error = NET_ERR_NONE;
1120 GVariantIter *iter_main = NULL;
1121 GVariantIter *var = NULL;
1122 GVariant *value = NULL;
1127 g_variant_get(msg, "(a(oa{sv}))", &iter_main);
1128 while (g_variant_iter_loop(iter_main, "(oa{sv})", &path, &var)) {
1133 while (g_variant_iter_loop(var, "{sv}", &key, &value)) {
1134 if (g_strcmp0(key, "Connected") == 0) {
1135 data = g_variant_get_boolean(value);
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;
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);
1154 NetworkInfo.wifi_state = WIFI_OFF;
1155 else if (data == TRUE && NetworkInfo.wifi_state < WIFI_ON)
1156 NetworkInfo.wifi_state = WIFI_ON;
1160 g_variant_iter_free(iter_main);
1162 __NETWORK_FUNC_EXIT__;
1166 static int __net_dbus_get_all_technology_states(net_state_type_t *state_table)
1168 __NETWORK_FUNC_ENTER__;
1170 net_err_t Error = NET_ERR_NONE;
1171 GVariant *message = NULL;
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");
1181 Error = __net_get_all_tech_states(message, state_table);
1183 g_variant_unref(message);
1186 __NETWORK_FUNC_EXIT__;
1190 int _net_init_service_state_table(void)
1192 __NETWORK_FUNC_ENTER__;
1194 net_err_t Error = NET_ERR_NONE;
1196 Error = __net_dbus_get_all_technology_states(&service_state_table[0]);
1197 if (Error != NET_ERR_NONE) {
1198 __NETWORK_FUNC_EXIT__;
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]);
1209 __NETWORK_FUNC_EXIT__;
1210 return NET_ERR_NONE;