4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Sungsik Jang <sungsik.jang@samsung.com>, Dongwook Lee <dwmax.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
23 /*****************************************************************************
25 *****************************************************************************/
32 #include <sys/socket.h>
37 #include <sys/ioctl.h>
39 #include <linux/unistd.h>
47 /*****************************************************************************
49 *****************************************************************************/
51 #include <system_info.h>
53 /*****************************************************************************
54 * Wi-Fi Direct Service headers
55 *****************************************************************************/
56 #include "wifi-direct.h"
57 #include "wifi-direct-internal.h"
58 #include "wifi-direct-client-proxy.h"
59 #include "wifi-direct-ipc.h"
60 #include "wifi-direct-log.h"
61 #include "wifi-direct-dbus.h"
63 /*****************************************************************************
65 *****************************************************************************/
67 /*****************************************************************************
69 *****************************************************************************/
71 static __thread wifi_direct_client_info_s g_client_info = {0, };
73 /*****************************************************************************
74 * Local Functions Definition
75 *****************************************************************************/
77 static wifi_direct_client_info_s *__wfd_get_control()
79 return &g_client_info;
82 static int __net_wifidirect_gerror_to_enum(GError* error)
84 int ret = WIFI_DIRECT_ERROR_NONE;
86 WDC_LOGI("GError is NULL!!");
90 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed. error [%d: %s]",
91 error->code, error->message);
93 if (NULL == strstr(error->message, "net.wifidirect.Error")) {
95 if (NULL != strstr(error->message, ".AccessDenied")) {
96 WDC_LOGE("Client doesn't have wifidirect privilege");
97 ret = WIFI_DIRECT_ERROR_PERMISSION_DENIED;
99 WDC_LOGE("DBus failure");
100 ret = WIFI_DIRECT_ERROR_OPERATION_FAILED;
104 if (NULL != strstr(error->message, "InvalidParameter"))
105 ret = WIFI_DIRECT_ERROR_INVALID_PARAMETER;
106 else if (NULL != strstr(error->message, "NotPermitted"))
107 ret = WIFI_DIRECT_ERROR_NOT_PERMITTED;
108 else if (NULL != strstr(error->message, "OperationFailed"))
109 ret = WIFI_DIRECT_ERROR_OPERATION_FAILED;
111 else if (NULL != strstr(error->message, "TooManyClient"))
112 ret = WIFI_DIRECT_ERROR_TOO_MANY_CLIENT;
114 ret = WIFI_DIRECT_ERROR_OPERATION_FAILED;
121 static int __wfd_check_display_feature()
123 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
125 return WIFI_DIRECT_ERROR_NONE;
128 static int __wfd_check_service_discovery_feature()
130 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
132 return WIFI_DIRECT_ERROR_NONE;
136 void __wfd_vconf_state_changed_cb(keynode_t *key, void *data)
138 __WDC_LOG_FUNC_START__;
142 if (!g_client_info.state_cb) {
143 WDC_LOGI("g_state_cb is NULL!!");
144 __WDC_LOG_FUNC_END__;
145 return; //LCOV_EXCL_LINE
148 res = vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &state);
150 WDC_LOGE("Failed to get vconf value [%s]\n",
151 VCONFKEY_WIFI_DIRECT_STATE);
152 __WDC_LOG_FUNC_END__;
156 if (state == VCONFKEY_WIFI_DIRECT_ACTIVATED) {
157 state = WIFI_DIRECT_STATE_ACTIVATED;
158 } else if (state == VCONFKEY_WIFI_DIRECT_DEACTIVATED) {
159 state = WIFI_DIRECT_STATE_DEACTIVATED;
160 } else if (state == VCONFKEY_WIFI_DIRECT_CONNECTED) {
161 state = WIFI_DIRECT_STATE_CONNECTED;
162 } else if (state == VCONFKEY_WIFI_DIRECT_GROUP_OWNER) {
163 state = WIFI_DIRECT_STATE_CONNECTED;
164 } else if (state == VCONFKEY_WIFI_DIRECT_DISCOVERING) {
165 state = WIFI_DIRECT_STATE_DISCOVERING;
166 } else if (state == VCONFKEY_WIFI_DIRECT_DEACTIVATING) {
167 state = WIFI_DIRECT_STATE_DEACTIVATING;
168 } else if (state == VCONFKEY_WIFI_DIRECT_ACTIVATING) {
169 state = WIFI_DIRECT_STATE_ACTIVATING;
170 } else if (state == VCONFKEY_WIFI_DIRECT_CONNECTING) {
171 state = WIFI_DIRECT_STATE_CONNECTING;
172 } else if (state == VCONFKEY_WIFI_DIRECT_DISCONNECTING) {
173 state = WIFI_DIRECT_STATE_DISCONNECTING;
175 WDC_LOGE("This state cannot be set as wifi_direct vconf state[%d]", state);
176 __WDC_LOG_FUNC_END__;
180 g_client_info.state_cb(state, g_client_info.user_data_for_cb_state);
182 __WDC_LOG_FUNC_END__;
188 void wifi_direct_process_manage_activation(GDBusConnection *connection,
190 const gchar *object_path,
191 const gchar *interface,
193 GVariant *parameters,
196 __WDC_LOG_FUNC_START__;
198 wifi_direct_client_info_s *client = __wfd_get_control();
200 if (!client->activation_cb) {
201 WDC_LOGI("activation_cb is NULL!!");
202 return; //LCOV_EXCL_LINE
206 __WDC_LOG_FUNC_END__;
210 g_variant_get(parameters, "(i)", &error_code);
212 client->activation_cb(error_code,
213 WIFI_DIRECT_DEVICE_STATE_ACTIVATED,
214 client->user_data_for_cb_activation);
216 __WDC_LOG_FUNC_END__;
219 void wifi_direct_process_manage_deactivation(GDBusConnection *connection,
221 const gchar *object_path,
222 const gchar *interface,
224 GVariant *parameters,
227 __WDC_LOG_FUNC_START__;
229 wifi_direct_client_info_s *client = __wfd_get_control();
232 __WDC_LOG_FUNC_END__;
233 return; //LCOV_EXCL_LINE
236 if (!client->activation_cb) {
237 WDC_LOGI("activation_cb is NULL!!");
238 __WDC_LOG_FUNC_END__;
242 g_variant_get(parameters, "(i)", &error_code);
244 client->activation_cb(error_code,
245 WIFI_DIRECT_DEVICE_STATE_DEACTIVATED,
246 client->user_data_for_cb_activation);
248 __WDC_LOG_FUNC_END__;
252 void wifi_direct_process_manage_connection(GDBusConnection *connection,
254 const gchar *object_path,
255 const gchar *interface,
257 GVariant *parameters,
260 __WDC_LOG_FUNC_START__;
262 wifi_direct_connection_state_e connection_state;
263 const gchar *peer_mac_address = NULL;
264 wifi_direct_client_info_s *client = __wfd_get_control();
267 __WDC_LOG_FUNC_END__;
271 if (!client->connection_cb) {
272 WDC_LOGI("connection_cb is NULL!!");
273 __WDC_LOG_FUNC_END__;
277 g_variant_get(parameters, "(ii&s)",
278 &error_code, &connection_state, &peer_mac_address);
280 client->connection_cb(error_code,
283 client->user_data_for_cb_connection);
285 __WDC_LOG_FUNC_END__;
288 void wifi_direct_process_manage_disconnection(GDBusConnection *connection,
290 const gchar *object_path,
291 const gchar *interface,
293 GVariant *parameters,
296 __WDC_LOG_FUNC_START__;
298 wifi_direct_connection_state_e connection_state;
299 const gchar *peer_mac_address = NULL;
300 wifi_direct_client_info_s *client = __wfd_get_control();
303 __WDC_LOG_FUNC_END__;
307 if (!client->connection_cb) {
308 WDC_LOGI("connection_cb is NULL!!");
309 __WDC_LOG_FUNC_END__;
313 g_variant_get(parameters, "(ii&s)",
314 &error_code, &connection_state, &peer_mac_address);
316 client->connection_cb(error_code,
319 client->user_data_for_cb_connection);
321 __WDC_LOG_FUNC_END__;
324 void wifi_direct_process_manage_peer_ip_assigned(GDBusConnection *connection,
326 const gchar *object_path,
327 const gchar *interface,
329 GVariant *parameters,
332 __WDC_LOG_FUNC_START__;
333 char *get_str = NULL;
334 GError* error = NULL;
335 GVariant *reply = NULL;
336 const gchar *peer_mac_address = NULL;
337 const gchar *assigned_ip_address = NULL;
339 wifi_direct_client_info_s *client = __wfd_get_control();
342 __WDC_LOG_FUNC_END__;
346 g_variant_get(parameters, "(&s&s)",
347 &peer_mac_address, &assigned_ip_address);
349 if (!client->ip_assigned_cb) {
350 WDC_LOGI("ip_assigned_cb is NULL!!");
351 __WDC_LOG_FUNC_END__;
355 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
360 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
361 "error [%d: %s]", error->code, error->message);
363 __WDC_LOG_FUNC_END__;
367 g_variant_get(reply, "(i&s)", ret, &get_str);
368 g_variant_unref(reply);
370 WDC_LOGD("Interface Name = [%s]", get_str);
371 WDC_LOGD("%s() return : [%d]", __func__, ret);
373 client->ip_assigned_cb(peer_mac_address, assigned_ip_address, get_str,
374 client->user_data_for_cb_ip_assigned);
376 __WDC_LOG_FUNC_END__;
379 void wifi_direct_process_manage_listen_started(GDBusConnection *connection,
381 const gchar *object_path,
382 const gchar *interface,
384 GVariant *parameters,
387 __WDC_LOG_FUNC_START__;
388 wifi_direct_client_info_s *client = __wfd_get_control();
390 if (!client->discover_cb) {
391 WDC_LOGI("discover_cb is NULL!!");
392 __WDC_LOG_FUNC_END__;
396 client->discover_cb(WIFI_DIRECT_ERROR_NONE,
397 WIFI_DIRECT_ONLY_LISTEN_STARTED,
398 client->user_data_for_cb_discover);
400 __WDC_LOG_FUNC_END__;
403 void wifi_direct_process_manage_discovery_started(GDBusConnection *connection,
405 const gchar *object_path,
406 const gchar *interface,
408 GVariant *parameters,
411 __WDC_LOG_FUNC_START__;
412 wifi_direct_client_info_s *client = __wfd_get_control();
414 if (!client->discover_cb) {
415 WDC_LOGI("discover_cb is NULL!!");
416 __WDC_LOG_FUNC_END__;
420 client->discover_cb(WIFI_DIRECT_ERROR_NONE,
421 WIFI_DIRECT_DISCOVERY_STARTED,
422 client->user_data_for_cb_discover);
424 __WDC_LOG_FUNC_END__;
427 void wifi_direct_process_manage_discovery_finished(GDBusConnection *connection,
429 const gchar *object_path,
430 const gchar *interface,
432 GVariant *parameters,
435 __WDC_LOG_FUNC_START__;
436 wifi_direct_client_info_s *client = __wfd_get_control();
438 if (!client->discover_cb) {
439 WDC_LOGI("discover_cb is NULL!!");
440 __WDC_LOG_FUNC_END__;
444 client->discover_cb(WIFI_DIRECT_ERROR_NONE,
445 WIFI_DIRECT_DISCOVERY_FINISHED,
446 client->user_data_for_cb_discover);
448 __WDC_LOG_FUNC_END__;
451 void wifi_direct_process_manage_peer_found(GDBusConnection *connection,
453 const gchar *object_path,
454 const gchar *interface,
456 GVariant *parameters,
459 __WDC_LOG_FUNC_START__;
460 const gchar *peer_mac_address = NULL;
461 wifi_direct_client_info_s *client = __wfd_get_control();
464 __WDC_LOG_FUNC_END__;
468 g_variant_get(parameters, "(&s)", &peer_mac_address);
470 if (client->peer_found_cb) {
471 client->peer_found_cb(WIFI_DIRECT_ERROR_NONE,
472 WIFI_DIRECT_DISCOVERY_FOUND,
474 client->user_data_for_cb_discover);
476 WDC_LOGI("peer_found_cb is NULL!!");
479 if (!client->discover_cb) {
480 WDC_LOGI("discover_cb is NULL!!");
481 __WDC_LOG_FUNC_END__;
485 client->discover_cb(WIFI_DIRECT_ERROR_NONE,
486 WIFI_DIRECT_DISCOVERY_FOUND,
487 client->user_data_for_cb_discover);
489 __WDC_LOG_FUNC_END__;
492 void wifi_direct_process_manage_peer_lost(GDBusConnection *connection,
494 const gchar *object_path,
495 const gchar *interface,
497 GVariant *parameters,
500 __WDC_LOG_FUNC_START__;
501 const gchar *peer_mac_address = NULL;
502 wifi_direct_client_info_s *client = __wfd_get_control();
505 __WDC_LOG_FUNC_END__;
509 g_variant_get(parameters, "(&s)", &peer_mac_address);
511 if (client->peer_found_cb) {
512 client->peer_found_cb(WIFI_DIRECT_ERROR_NONE,
513 WIFI_DIRECT_DISCOVERY_LOST,
515 client->user_data_for_cb_discover);
517 WDC_LOGI("peer_found_cb is NULL!!");
520 if (!client->discover_cb) {
521 WDC_LOGI("discover_cb is NULL!!");
522 __WDC_LOG_FUNC_END__;
526 client->discover_cb(WIFI_DIRECT_ERROR_NONE,
527 WIFI_DIRECT_DISCOVERY_LOST,
528 client->user_data_for_cb_discover);
530 __WDC_LOG_FUNC_END__;
534 void wifi_direct_process_group_created(GDBusConnection *connection,
536 const gchar *object_path,
537 const gchar *interface,
539 GVariant *parameters,
542 __WDC_LOG_FUNC_START__;
543 wifi_direct_client_info_s *client = __wfd_get_control();
545 if (!client->connection_cb) {
546 WDC_LOGI("connection_cb is NULL!!");
547 __WDC_LOG_FUNC_END__;
551 client->connection_cb(WIFI_DIRECT_ERROR_NONE,
552 WIFI_DIRECT_GROUP_CREATED,
554 client->user_data_for_cb_connection);
556 __WDC_LOG_FUNC_END__;
559 void wifi_direct_process_group_destroyed(GDBusConnection *connection,
561 const gchar *object_path,
562 const gchar *interface,
564 GVariant *parameters,
567 __WDC_LOG_FUNC_START__;
568 wifi_direct_client_info_s *client = __wfd_get_control();
570 if (!client->connection_cb) {
571 WDC_LOGI("connection_cb is NULL!!");
572 __WDC_LOG_FUNC_END__;
576 client->connection_cb(WIFI_DIRECT_ERROR_NONE,
577 WIFI_DIRECT_GROUP_DESTROYED,
579 client->user_data_for_cb_connection);
581 __WDC_LOG_FUNC_END__;
585 void wifi_direct_process_service_discovery_started(GDBusConnection *connection,
587 const gchar *object_path,
588 const gchar *interface,
590 GVariant *parameters,
593 __WDC_LOG_FUNC_START__;
594 wifi_direct_client_info_s *client = __wfd_get_control();
596 if (!client->is_service_discovery_supported) {
597 WDC_LOGI("service discovery is not supported\n");
598 __WDC_LOG_FUNC_END__;
602 if (!client->service_cb) {
603 WDC_LOGI("service_cb is NULL!!\n");
604 __WDC_LOG_FUNC_END__;
608 client->service_cb(WIFI_DIRECT_ERROR_NONE,
609 WIFI_DIRECT_SERVICE_DISCOVERY_STARTED,
610 WIFI_DIRECT_SERVICE_TYPE_ALL,
613 client->user_data_for_cb_service);
615 __WDC_LOG_FUNC_END__;
618 void wifi_direct_process_service_discovery_found(GDBusConnection *connection,
620 const gchar *object_path,
621 const gchar *interface,
623 GVariant *parameters,
626 __WDC_LOG_FUNC_START__;
627 wifi_direct_service_type_e service_type;
628 const gchar* response_data = NULL;
629 const gchar* peer_mac_address = NULL;
630 wifi_direct_client_info_s *client = __wfd_get_control();
632 if (!client->is_service_discovery_supported) {
633 WDC_LOGI("service discovery is not supported\n");
634 __WDC_LOG_FUNC_END__;
639 __WDC_LOG_FUNC_END__;
643 g_variant_get(parameters, "(i&s&s)",
644 &service_type, &response_data, &peer_mac_address);
646 if (!client->service_cb) {
647 WDC_LOGI("service_cb is NULL!!\n");
648 __WDC_LOG_FUNC_END__;
652 client->service_cb(WIFI_DIRECT_ERROR_NONE,
653 WIFI_DIRECT_SERVICE_DISCOVERY_FOUND,
655 (void *) response_data,
657 client->user_data_for_cb_service);
659 __WDC_LOG_FUNC_END__;
662 void wifi_direct_process_service_discovery_finished(GDBusConnection *connection,
664 const gchar *object_path,
665 const gchar *interface,
667 GVariant *parameters,
670 __WDC_LOG_FUNC_START__;
671 wifi_direct_client_info_s *client = __wfd_get_control();
673 if (!client->is_service_discovery_supported) {
674 WDC_LOGI("service discovery is not supported\n");
675 __WDC_LOG_FUNC_END__;
679 if (!client->service_cb) {
680 WDC_LOGI("service_cb is NULL!!\n");
681 __WDC_LOG_FUNC_END__;
685 client->service_cb(WIFI_DIRECT_ERROR_NONE,
686 WIFI_DIRECT_SERVICE_DISCOVERY_FINISHED,
687 WIFI_DIRECT_SERVICE_TYPE_ALL,
690 client->user_data_for_cb_service);
692 __WDC_LOG_FUNC_END__;
696 void __wfd_client_print_entry_list(wfd_discovery_entry_s *list, int num)
700 WDC_LOGD("------------------------------------------");
701 for (i = 0; i < num; i++) {
702 WDC_LOGD("== Peer index : %d ==", i);
703 WDC_LOGD("is Group Owner ? %s", list[i].is_group_owner ? "YES" : "NO");
704 WDC_LOGD("device_name : %s", list[i].device_name);
705 WDC_LOGD("MAC address : "MACSECSTR, MAC2SECSTR(list[i].mac_address));
706 WDC_LOGD("wps cfg method : %x", list[i].wps_cfg_methods);
707 WDC_LOGD("Device Type: %d - %d", list[i].category, list[i].subcategory);
708 WDC_LOGD("Listen channel: %d", list[i].channel);
710 WDC_LOGD("------------------------------------------");
713 void __wfd_client_print_connected_peer_info(wfd_connected_peer_info_s *list, int num)
717 WDC_LOGD("------------------------------------------\n");
718 for (i = 0; i < num; i++) {
719 WDC_LOGD("== Peer index : %d ==\n", i);
720 WDC_LOGD("device_name : %s\n", list[i].device_name);
721 WDC_LOGD("Device MAC : " MACSECSTR "\n", MAC2SECSTR(list[i].mac_address));
722 WDC_LOGD("Device Type: %d - %d", list[i].category, list[i].subcategory);
723 WDC_LOGD("channel : %d\n", list[i].channel);
724 WDC_LOGD("IP ["IPSECSTR"]\n", IP2SECSTR(list[i].ip_address));
726 WDC_LOGD("------------------------------------------\n");
729 void __wfd_client_print_persistent_group_info(wfd_persistent_group_info_s *list, int num)
733 WDC_LOGD("------------------------------------------\n");
734 for (i = 0; i < num; i++) {
735 WDC_LOGD("== Persistent Group index : %d ==", i);
736 WDC_LOGD("ssid : %s", list[i].ssid);
737 WDC_LOGD("GO MAC : " MACSECSTR, MAC2SECSTR(list[i].go_mac_address));
739 WDC_LOGD("------------------------------------------\n");
743 static void __wfd_client_extract_discovered_peer_info(GVariantIter *iter,
744 wifi_direct_discovered_peer_info_s *info) {
745 __WDC_LOG_FUNC_START__;
746 GVariant *var = NULL;
749 while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
750 if (!g_strcmp0(key, "DeviceName")) {
751 const char *device_name = NULL;
753 g_variant_get(var, "&s", &device_name);
754 info->device_name = g_strndup(device_name, WIFI_DIRECT_MAX_DEVICE_NAME_LEN+1);
756 } else if (!g_strcmp0(key, "DeviceAddress")) {
757 unsigned char mac_address[MACADDR_LEN] = {0, };
759 wifi_direct_dbus_unpack_ay(mac_address, var, MACADDR_LEN);
760 info->mac_address = (char*) g_try_malloc0(MACSTR_LEN);
761 if (info->mac_address)
762 g_snprintf(info->mac_address, MACSTR_LEN, MACSTR, MAC2STR(mac_address));
764 } else if (!g_strcmp0(key, "InterfaceAddress")) {
765 unsigned char intf_address[MACADDR_LEN] = {0, };
767 wifi_direct_dbus_unpack_ay(intf_address, var, MACADDR_LEN);
768 info->interface_address = (char*) g_try_malloc0(MACSTR_LEN);
769 if (info->interface_address)
770 g_snprintf(info->interface_address, MACSTR_LEN, MACSTR, MAC2STR(intf_address));
772 } else if (!g_strcmp0(key, "Channel")) {
773 info->channel = g_variant_get_uint16(var);
775 } else if (!g_strcmp0(key, "IsGroupOwner")) {
776 info->is_group_owner = g_variant_get_boolean(var);
778 } else if (!g_strcmp0(key, "IsPersistentGO")) {
779 info->is_persistent_group_owner = g_variant_get_boolean(var);
781 } else if (!g_strcmp0(key, "IsConnected")) {
782 info->is_connected = g_variant_get_boolean(var);
784 } else if (!g_strcmp0(key, "Category")) {
785 info->primary_device_type = g_variant_get_uint16(var);
787 } else if (!g_strcmp0(key, "SubCategory")) {
788 info->secondary_device_type = g_variant_get_uint16(var);
790 } else if (!g_strcmp0(key, "IsWfdDevice")) {
791 if (g_client_info.is_display_supported)
792 info->is_miracast_device = g_variant_get_boolean(var);
798 __WDC_LOG_FUNC_END__;
802 int wifi_direct_initialize(void)
804 __WDC_LOG_FUNC_START__;
806 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
808 GError* error = NULL;
809 GVariant *reply = NULL;
810 bool wifi_direct_enable;
814 if (g_client_info.is_registered == TRUE) {
815 WDC_LOGW("Warning!!! Already registered\nUpdate user data and callback!");
816 __WDC_LOG_FUNC_END__;
817 return WIFI_DIRECT_ERROR_ALREADY_INITIALIZED;
820 res = system_info_get_platform_bool("tizen.org/feature/network.wifi.direct", &wifi_direct_enable);
822 WDC_LOGE("Failed to get sys info");
823 __WDC_LOG_FUNC_END__;
824 return res; //LCOV_EXCL_LINE
827 if (!wifi_direct_enable) {
828 WDC_LOGE("Wi-Fi Direct not supported");
829 return WIFI_DIRECT_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
832 if (wifi_direct_dbus_init() == FALSE) {
833 WDC_LOGW("Failed to initialize dbus");
834 __WDC_LOG_FUNC_END__;
835 return WIFI_DIRECT_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
838 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
839 "AddClient", NULL, &error);
840 res = __net_wifidirect_gerror_to_enum(error);
841 if (res != WIFI_DIRECT_ERROR_NONE) {
842 WDC_LOGE("Failed to Add Active Client");
846 g_variant_get(reply, "(i)", &res);
847 WDC_LOGD("Active Client id Added, ret[%d]", res);
849 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
850 "IsGroupOwner", NULL, &error);
852 res = __net_wifidirect_gerror_to_enum(error);
853 if (res != WIFI_DIRECT_ERROR_NONE)
856 g_variant_get(reply, "(b)", &val);
857 WDC_LOGD("is group owner [%s]", val ? "YES" : "NO");
859 g_client_info.is_registered = TRUE;
861 if (__wfd_check_display_feature() == WIFI_DIRECT_ERROR_NONE)
862 g_client_info.is_display_supported = TRUE;
864 g_client_info.is_display_supported = FALSE;
866 if (__wfd_check_service_discovery_feature() == WIFI_DIRECT_ERROR_NONE)
867 g_client_info.is_service_discovery_supported = TRUE;
869 g_client_info.is_service_discovery_supported = FALSE;
871 /* Initialize callbacks */
872 g_client_info.activation_cb = NULL;
873 g_client_info.user_data_for_cb_activation = NULL;
875 g_client_info.discover_cb = NULL;
876 g_client_info.user_data_for_cb_discover = NULL;
878 g_client_info.connection_cb = NULL;
879 g_client_info.user_data_for_cb_connection = NULL;
881 g_client_info.ip_assigned_cb = NULL;
882 g_client_info.user_data_for_cb_ip_assigned = NULL;
884 g_client_info.peer_found_cb = NULL;
885 g_client_info.user_data_for_cb_peer_found = NULL;
887 g_client_info.service_cb = NULL;
888 g_client_info.user_data_for_cb_service = NULL;
890 __WDC_LOG_FUNC_END__;
891 return WIFI_DIRECT_ERROR_NONE;
894 int wifi_direct_deinitialize(void)
896 __WDC_LOG_FUNC_START__;
898 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
900 if (g_client_info.is_registered == false) {
901 WDC_LOGE("Client is already deregistered");
902 __WDC_LOG_FUNC_END__;
903 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
906 wifi_direct_dbus_deinit();
908 g_client_info.activation_cb = NULL;
909 g_client_info.user_data_for_cb_activation = NULL;
911 g_client_info.discover_cb = NULL;
912 g_client_info.user_data_for_cb_discover = NULL;
914 g_client_info.connection_cb = NULL;
915 g_client_info.user_data_for_cb_connection = NULL;
917 g_client_info.ip_assigned_cb = NULL;
918 g_client_info.user_data_for_cb_ip_assigned = NULL;
920 g_client_info.peer_found_cb = NULL;
921 g_client_info.user_data_for_cb_peer_found = NULL;
923 g_client_info.service_cb = NULL;
924 g_client_info.user_data_for_cb_service = NULL;
926 g_client_info.is_registered = FALSE;
928 __WDC_LOG_FUNC_END__;
929 return WIFI_DIRECT_ERROR_NONE;
933 int wifi_direct_set_device_state_changed_cb(wifi_direct_device_state_changed_cb cb,
936 __WDC_LOG_FUNC_START__;
938 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
941 WDC_LOGE("Invalid parameter");
942 __WDC_LOG_FUNC_END__;
943 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
946 if (g_client_info.is_registered == false) {
947 WDC_LOGE("Client is not initialized.");
948 __WDC_LOG_FUNC_END__;
949 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
952 g_client_info.activation_cb = cb;
953 g_client_info.user_data_for_cb_activation = user_data;
955 __WDC_LOG_FUNC_END__;
956 return WIFI_DIRECT_ERROR_NONE;
960 int wifi_direct_unset_device_state_changed_cb(void)
962 __WDC_LOG_FUNC_START__;
964 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
966 if (g_client_info.is_registered == false) {
967 WDC_LOGE("Client is not initialized.\n");
968 __WDC_LOG_FUNC_END__;
969 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
972 g_client_info.activation_cb = NULL;
973 g_client_info.user_data_for_cb_activation = NULL;
975 __WDC_LOG_FUNC_END__;
976 return WIFI_DIRECT_ERROR_NONE;
981 wifi_direct_set_discovery_state_changed_cb(wifi_direct_discovery_state_chagned_cb cb,
984 __WDC_LOG_FUNC_START__;
986 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
989 WDC_LOGE("Callback is NULL.\n");
990 __WDC_LOG_FUNC_END__;
991 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
994 if (g_client_info.is_registered == false) {
995 WDC_LOGE("Client is not initialized.\n");
996 __WDC_LOG_FUNC_END__;
997 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1000 g_client_info.discover_cb = cb;
1001 g_client_info.user_data_for_cb_discover = user_data;
1003 __WDC_LOG_FUNC_END__;
1004 return WIFI_DIRECT_ERROR_NONE;
1008 int wifi_direct_unset_discovery_state_changed_cb(void)
1010 __WDC_LOG_FUNC_START__;
1012 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1014 if (g_client_info.is_registered == false) {
1015 WDC_LOGE("Client is not initialized.\n");
1016 __WDC_LOG_FUNC_END__;
1017 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1020 g_client_info.discover_cb = NULL;
1021 g_client_info.user_data_for_cb_discover = NULL;
1023 __WDC_LOG_FUNC_END__;
1024 return WIFI_DIRECT_ERROR_NONE;
1027 int wifi_direct_set_peer_found_cb(wifi_direct_peer_found_cb cb,
1030 __WDC_LOG_FUNC_START__;
1032 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1035 WDC_LOGE("Callback is NULL.\n");
1036 __WDC_LOG_FUNC_END__;
1037 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1040 if (g_client_info.is_registered == false) {
1041 WDC_LOGE("Client is not initialized.\n");
1042 __WDC_LOG_FUNC_END__;
1043 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1046 g_client_info.peer_found_cb = cb;
1047 g_client_info.user_data_for_cb_peer_found = user_data;
1049 __WDC_LOG_FUNC_END__;
1050 return WIFI_DIRECT_ERROR_NONE;
1054 int wifi_direct_unset_peer_found_cb(void)
1056 __WDC_LOG_FUNC_START__;
1058 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1060 if (g_client_info.is_registered == false) {
1061 WDC_LOGE("Client is not initialized.\n");
1062 __WDC_LOG_FUNC_END__;
1063 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1066 g_client_info.peer_found_cb = NULL;
1067 g_client_info.user_data_for_cb_peer_found = NULL;
1069 __WDC_LOG_FUNC_END__;
1070 return WIFI_DIRECT_ERROR_NONE;
1073 int wifi_direct_set_service_state_changed_cb(wifi_direct_service_state_changed_cb cb,
1076 __WDC_LOG_FUNC_START__;
1078 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
1082 WDC_LOGE("Callback is NULL.");
1083 __WDC_LOG_FUNC_END__;
1084 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1087 if (g_client_info.is_registered == false) {
1088 WDC_LOGE("Client is not initialized.");
1089 __WDC_LOG_FUNC_END__;
1090 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1093 g_client_info.service_cb = cb;
1094 g_client_info.user_data_for_cb_service = user_data;
1096 __WDC_LOG_FUNC_END__;
1098 return WIFI_DIRECT_ERROR_NONE;
1102 int wifi_direct_unset_service_state_changed_cb(void)
1104 __WDC_LOG_FUNC_START__;
1106 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
1109 if (g_client_info.is_registered == false) {
1110 WDC_LOGE("Client is not initialized.");
1111 __WDC_LOG_FUNC_END__;
1112 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1115 g_client_info.service_cb = NULL;
1116 g_client_info.user_data_for_cb_service = NULL;
1118 __WDC_LOG_FUNC_END__;
1120 return WIFI_DIRECT_ERROR_NONE;
1123 int wifi_direct_set_connection_state_changed_cb(wifi_direct_connection_state_changed_cb cb,
1126 __WDC_LOG_FUNC_START__;
1128 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1131 WDC_LOGE("Callback is NULL.\n");
1132 __WDC_LOG_FUNC_END__;
1133 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1136 if (g_client_info.is_registered == false) {
1137 WDC_LOGE("Client is not initialized.\n");
1138 __WDC_LOG_FUNC_END__;
1139 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1142 g_client_info.connection_cb = cb;
1143 g_client_info.user_data_for_cb_connection = user_data;
1145 __WDC_LOG_FUNC_END__;
1146 return WIFI_DIRECT_ERROR_NONE;
1150 int wifi_direct_unset_connection_state_changed_cb(void)
1152 __WDC_LOG_FUNC_START__;
1154 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1156 if (g_client_info.is_registered == false) {
1157 WDC_LOGE("Client is not initialized");
1158 __WDC_LOG_FUNC_END__;
1159 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1162 g_client_info.connection_cb = NULL;
1163 g_client_info.user_data_for_cb_connection = NULL;
1165 __WDC_LOG_FUNC_END__;
1166 return WIFI_DIRECT_ERROR_NONE;
1170 int wifi_direct_set_client_ip_address_assigned_cb(wifi_direct_client_ip_address_assigned_cb cb,
1173 __WDC_LOG_FUNC_START__;
1175 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1178 WDC_LOGE("Callback is NULL");
1179 __WDC_LOG_FUNC_END__;
1180 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1183 if (g_client_info.is_registered == false) {
1184 WDC_LOGE("Client is not initialized");
1185 __WDC_LOG_FUNC_END__;
1186 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1189 g_client_info.ip_assigned_cb = cb;
1190 g_client_info.user_data_for_cb_ip_assigned = user_data;
1192 __WDC_LOG_FUNC_END__;
1193 return WIFI_DIRECT_ERROR_NONE;
1196 int wifi_direct_unset_client_ip_address_assigned_cb(void)
1198 __WDC_LOG_FUNC_START__;
1200 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1202 if (g_client_info.is_registered == false) {
1203 WDC_LOGE("Client is not initialized");
1204 __WDC_LOG_FUNC_END__;
1205 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1208 g_client_info.ip_assigned_cb = NULL;
1209 g_client_info.user_data_for_cb_ip_assigned = NULL;
1211 __WDC_LOG_FUNC_END__;
1212 return WIFI_DIRECT_ERROR_NONE;
1215 int wifi_direct_set_state_changed_cb(wifi_direct_state_changed_cb cb, void *user_data)
1217 __WDC_LOG_FUNC_START__;
1218 int ret = WIFI_DIRECT_ERROR_NONE;
1220 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1223 WDC_LOGE("Callback is NULL");
1224 __WDC_LOG_FUNC_END__;
1225 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1228 ret = vconf_notify_key_changed(VCONFKEY_WIFI_DIRECT_STATE,
1229 __wfd_vconf_state_changed_cb, NULL);
1231 WDC_LOGE("Failed to set vconf notification callback");
1232 __WDC_LOG_FUNC_END__;
1233 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1236 g_client_info.state_cb = cb;
1237 g_client_info.user_data_for_cb_state = user_data;
1239 __WDC_LOG_FUNC_END__;
1240 return WIFI_DIRECT_ERROR_NONE;
1243 int wifi_direct_unset_state_changed_cb(void)
1245 __WDC_LOG_FUNC_START__;
1248 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1250 ret = vconf_ignore_key_changed(VCONFKEY_WIFI_DIRECT_STATE,
1251 __wfd_vconf_state_changed_cb);
1253 WDC_LOGE("Failed to ignore vconf notification callback");
1254 __WDC_LOG_FUNC_END__;
1255 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1258 g_client_info.state_cb = NULL;
1259 g_client_info.user_data_for_cb_state = NULL;
1261 __WDC_LOG_FUNC_END__;
1262 return WIFI_DIRECT_ERROR_NONE;
1265 int wifi_direct_activate(void)
1267 __WDC_LOG_FUNC_START__;
1268 GError *error = NULL;
1269 GVariant *reply = NULL;
1270 int ret = WIFI_DIRECT_ERROR_NONE;
1272 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1274 if (g_client_info.is_registered == false) {
1275 WDC_LOGE("Client is NOT registered");
1276 __WDC_LOG_FUNC_END__;
1277 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1280 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1281 "Activate", NULL, &error);
1283 ret = __net_wifidirect_gerror_to_enum(error);
1284 if (ret == WIFI_DIRECT_ERROR_NONE) {
1285 g_variant_get(reply, "(i)", &ret);
1286 g_variant_unref(reply);
1289 WDC_LOGD("%s() return : [%d]", __func__, ret);
1290 __WDC_LOG_FUNC_END__;
1294 int wifi_direct_deactivate(void)
1296 __WDC_LOG_FUNC_START__;
1297 GError *error = NULL;
1298 GVariant *reply = NULL;
1299 int ret = WIFI_DIRECT_ERROR_NONE;
1301 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1303 if (g_client_info.is_registered == false) {
1304 WDC_LOGE("Client is NOT registered");
1305 __WDC_LOG_FUNC_END__;
1306 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1309 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1310 "Deactivate", NULL, &error);
1312 ret = __net_wifidirect_gerror_to_enum(error);
1313 if (ret == WIFI_DIRECT_ERROR_NONE) {
1314 g_variant_get(reply, "(i)", &ret);
1315 g_variant_unref(reply);
1318 WDC_LOGD("%s() return : [%d]", __func__, ret);
1319 __WDC_LOG_FUNC_END__;
1323 int wifi_direct_start_discovery(bool listen_only, int timeout)
1325 __WDC_LOG_FUNC_START__;
1326 GVariantBuilder *builder = NULL;
1327 GVariant *params = NULL;
1328 GError *error = NULL;
1329 GVariant *reply = NULL;
1330 int ret = WIFI_DIRECT_ERROR_NONE;
1332 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1334 if (g_client_info.is_registered == false) {
1335 WDC_LOGE("Client is NOT registered");
1336 __WDC_LOG_FUNC_END__;
1337 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1341 WDC_LOGE("Negative value. Param [timeout]!");
1342 __WDC_LOG_FUNC_END__;
1343 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1346 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
1347 g_variant_builder_add(builder, "{sv}", "Mode", g_variant_new("b", listen_only));
1348 g_variant_builder_add(builder, "{sv}", "Timeout", g_variant_new("i", timeout));
1349 params = g_variant_new("(a{sv})", builder);
1350 g_variant_builder_unref(builder);
1351 WDC_LOGI("listen only (%d) timeout (%d)", listen_only, timeout);
1353 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1354 "StartDiscovery", params, &error);
1356 ret = __net_wifidirect_gerror_to_enum(error);
1357 if (ret == WIFI_DIRECT_ERROR_NONE) {
1358 g_variant_get(reply, "(i)", &ret);
1359 g_variant_unref(reply);
1362 WDC_LOGD("%s() return : [%d]", __func__, ret);
1363 __WDC_LOG_FUNC_END__;
1367 int wifi_direct_start_discovery_specific_channel(bool listen_only,
1369 wifi_direct_discovery_channel_e channel)
1371 __WDC_LOG_FUNC_START__;
1372 GVariantBuilder *builder = NULL;
1373 GVariant *params = NULL;
1374 GError *error = NULL;
1375 GVariant *reply = NULL;
1376 int ret = WIFI_DIRECT_ERROR_NONE;
1378 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1380 if (g_client_info.is_registered == false) {
1381 WDC_LOGE("Client is NOT registered");
1382 __WDC_LOG_FUNC_END__;
1383 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1387 WDC_LOGE("Negative value. Param [timeout]!");
1388 __WDC_LOG_FUNC_END__;
1389 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1392 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
1393 g_variant_builder_add(builder, "{sv}", "Mode", g_variant_new("b", listen_only));
1394 g_variant_builder_add(builder, "{sv}", "Timeout", g_variant_new("i", timeout));
1395 g_variant_builder_add(builder, "{sv}", "Channel", g_variant_new("i", channel));
1396 params = g_variant_new("(a{sv})", builder);
1397 g_variant_builder_unref(builder);
1398 WDC_LOGI("listen only (%d) timeout (%d)", listen_only, timeout);
1400 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1401 "StartDiscovery", params, &error);
1403 ret = __net_wifidirect_gerror_to_enum(error);
1404 if (ret == WIFI_DIRECT_ERROR_NONE) {
1405 g_variant_get(reply, "(i)", &ret);
1406 g_variant_unref(reply);
1409 WDC_LOGD("%s() return : [%d]", __func__, ret);
1410 __WDC_LOG_FUNC_END__;
1414 int wifi_direct_start_discovery_specific_freq(bool listen_only,
1415 int timeout, int frequency)
1417 __WDC_LOG_FUNC_START__;
1418 GVariantBuilder *builder = NULL;
1419 GVariant *params = NULL;
1420 GError *error = NULL;
1421 GVariant *reply = NULL;
1422 int ret = WIFI_DIRECT_ERROR_NONE;
1424 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1426 if (g_client_info.is_registered == false) {
1427 WDC_LOGE("Client is NOT registered");
1428 __WDC_LOG_FUNC_END__;
1429 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1432 if (timeout < 0 || frequency <= 0) {
1433 WDC_LOGE("Invalid parameter");
1434 __WDC_LOG_FUNC_END__;
1435 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1438 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
1439 g_variant_builder_add(builder, "{sv}", "Mode",
1440 g_variant_new("b", listen_only));
1441 g_variant_builder_add(builder, "{sv}", "Timeout",
1442 g_variant_new("i", timeout));
1443 g_variant_builder_add(builder, "{sv}", "Frequency",
1444 g_variant_new("i", frequency));
1445 params = g_variant_new("(a{sv})", builder);
1446 g_variant_builder_unref(builder);
1448 WDC_LOGI("listen only (%d) timeout (%d) frequency (%d)", listen_only,
1449 timeout, frequency);
1451 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1452 "StartDiscovery", params,
1455 ret = __net_wifidirect_gerror_to_enum(error);
1456 if (ret == WIFI_DIRECT_ERROR_NONE) {
1457 g_variant_get(reply, "(i)", &ret);
1458 g_variant_unref(reply);
1461 WDC_LOGD("%s() return : [%d]", __func__, ret);
1462 __WDC_LOG_FUNC_END__;
1466 int wifi_direct_cancel_discovery(void)
1468 __WDC_LOG_FUNC_START__;
1469 GError *error = NULL;
1470 GVariant *reply = NULL;
1471 int ret = WIFI_DIRECT_ERROR_NONE;
1473 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1475 if (g_client_info.is_registered == false) {
1476 WDC_LOGE("Client is NOT registered");
1477 __WDC_LOG_FUNC_END__;
1478 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1481 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1482 "StopDiscovery", NULL, &error);
1484 ret = __net_wifidirect_gerror_to_enum(error);
1485 if (ret == WIFI_DIRECT_ERROR_NONE) {
1486 g_variant_get(reply, "(i)", &ret);
1487 g_variant_unref(reply);
1490 WDC_LOGD("%s() return : [%d]", __func__, ret);
1491 __WDC_LOG_FUNC_END__;
1496 static char **get_service_list(char *services, unsigned int *count)
1498 __WDC_LOG_FUNC_START__;
1499 char **result = NULL;
1502 unsigned int cnt = 0;
1505 char *saveptr = NULL;
1507 if (!count || !services || (services && strlen(services) <= 0)) {
1508 WDC_LOGE("Invalid parameters.");
1509 __WDC_LOG_FUNC_END__;
1514 pos2 = g_strdup(services);
1516 pos1 = strtok_r(pos1, ",\n", &saveptr);
1519 pos1 = strtok_r(NULL, ",\n", &saveptr);
1521 WDC_LOGD("Total Service Count = %d", cnt);
1524 result = (char**) g_try_malloc0_n(cnt, sizeof(char *));
1526 WDC_LOGE("Failed to allocate memory for result");
1530 pos2 = strtok_r(pos2, ",\n", &saveptr);
1531 while (pos2 != NULL) {
1532 char *s = strchr(pos2, ' ');
1535 result[i++] = strdup(pos2);
1536 pos2 = strtok_r(NULL, ",\n", &saveptr);
1550 for (j = 0; j < i && result[j] != NULL; j++)
1557 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
1559 int wifi_direct_foreach_discovered_peers(wifi_direct_discovered_peer_cb cb,
1562 __WDC_LOG_FUNC_START__;
1564 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1566 GVariant *params = NULL;
1567 GError *error = NULL;
1568 GVariant *reply = NULL;
1569 GVariantIter *iter_peers = NULL;
1570 GVariantIter *iter_peer = NULL;
1571 int ret = WIFI_DIRECT_ERROR_NONE;
1573 if (g_client_info.is_registered == false) {
1574 WDC_LOGE("Client is NOT registered");
1575 __WDC_LOG_FUNC_END__;
1576 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1580 WDC_LOGE("NULL Param [callback]!");
1581 __WDC_LOG_FUNC_END__;
1582 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1585 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1586 "GetDiscoveredPeers", params, &error);
1588 ret = __net_wifidirect_gerror_to_enum(error);
1589 if (ret != WIFI_DIRECT_ERROR_NONE)
1592 g_variant_get(reply, "(iaa{sv})", &ret, &iter_peers);
1593 if (ret != WIFI_DIRECT_ERROR_NONE) {
1594 __WDC_LOG_FUNC_END__;
1595 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1598 WDC_LOGD("wifi_direct_foreach_discovered_peers() SUCCESS");
1600 while (g_variant_iter_loop(iter_peers, "a{sv}", &iter_peer)) {
1601 wifi_direct_discovered_peer_info_s *peer_info = NULL;
1603 peer_info = (wifi_direct_discovered_peer_info_s *)
1604 g_try_malloc0(sizeof(wifi_direct_discovered_peer_info_s));
1606 WDC_LOGE("Failed to allocate memory");
1610 __wfd_client_extract_discovered_peer_info(iter_peer, peer_info);
1611 /* __wfd_client_print_entry_list(peer_info, 1); */
1613 if (!cb(peer_info, user_data)) {
1614 g_variant_iter_free(iter_peer);
1619 g_variant_iter_free(iter_peers);
1620 g_variant_unref(reply);
1621 __WDC_LOG_FUNC_END__;
1622 return WIFI_DIRECT_ERROR_NONE;
1625 int wifi_direct_connect(char *mac_address)
1627 __WDC_LOG_FUNC_START__;
1629 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1631 GVariant *params = NULL;
1632 GError *error = NULL;
1633 GVariant *reply = NULL;
1634 int ret = WIFI_DIRECT_ERROR_NONE;
1636 if (g_client_info.is_registered == false) {
1637 WDC_LOGE("Client is NOT registered");
1638 __WDC_LOG_FUNC_END__;
1639 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1643 WDC_LOGE("mac_addr is NULL");
1644 __WDC_LOG_FUNC_END__;
1645 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1648 params = g_variant_new("(s)", mac_address);
1649 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1650 "Connect", params, &error);
1652 ret = __net_wifidirect_gerror_to_enum(error);
1653 if (ret == WIFI_DIRECT_ERROR_NONE) {
1654 g_variant_get(reply, "(i)", &ret);
1655 g_variant_unref(reply);
1658 WDC_LOGD("%s() return : [%d]", __func__, ret);
1659 __WDC_LOG_FUNC_END__;
1664 int wifi_direct_cancel_connection(char *mac_address)
1666 __WDC_LOG_FUNC_START__;
1668 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1670 GVariant *params = NULL;
1671 GError *error = NULL;
1672 GVariant *reply = NULL;
1673 int ret = WIFI_DIRECT_ERROR_NONE;
1675 if (g_client_info.is_registered == false) {
1676 WDC_LOGE("Client is NOT registered");
1677 __WDC_LOG_FUNC_END__;
1678 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1682 WDC_LOGE("mac_addr is NULL");
1683 __WDC_LOG_FUNC_END__;
1684 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1687 params = g_variant_new("(s)", mac_address);
1688 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1689 "CancelConnection", params, &error);
1691 ret = __net_wifidirect_gerror_to_enum(error);
1692 if (ret == WIFI_DIRECT_ERROR_NONE) {
1693 g_variant_get(reply, "(i)", &ret);
1694 g_variant_unref(reply);
1697 WDC_LOGD("%s() return : [%d]", __func__, ret);
1698 __WDC_LOG_FUNC_END__;
1703 int wifi_direct_reject_connection(char *mac_address)
1705 __WDC_LOG_FUNC_START__;
1707 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1709 GVariant *params = NULL;
1710 GError *error = NULL;
1711 GVariant *reply = NULL;
1712 int ret = WIFI_DIRECT_ERROR_NONE;
1714 if (g_client_info.is_registered == false) {
1715 WDC_LOGE("Client is NOT registered");
1716 __WDC_LOG_FUNC_END__;
1717 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1721 WDC_LOGE("mac_addr is NULL");
1722 __WDC_LOG_FUNC_END__;
1723 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1726 params = g_variant_new("(s)", mac_address);
1727 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1728 "RejectConnection", params, &error);
1730 ret = __net_wifidirect_gerror_to_enum(error);
1731 if (ret == WIFI_DIRECT_ERROR_NONE) {
1732 g_variant_get(reply, "(i)", &ret);
1733 g_variant_unref(reply);
1736 WDC_LOGD("%s() return : [%d]", __func__, ret);
1737 __WDC_LOG_FUNC_END__;
1742 int wifi_direct_disconnect_all(void)
1744 __WDC_LOG_FUNC_START__;
1746 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1748 GError *error = NULL;
1749 GVariant *reply = NULL;
1750 int ret = WIFI_DIRECT_ERROR_NONE;
1752 if (g_client_info.is_registered == false) {
1753 WDC_LOGE("Client is NOT registered");
1754 __WDC_LOG_FUNC_END__;
1755 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1758 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1759 "DisconnectAll", NULL, &error);
1761 ret = __net_wifidirect_gerror_to_enum(error);
1762 if (ret == WIFI_DIRECT_ERROR_NONE) {
1763 g_variant_get(reply, "(i)", &ret);
1764 g_variant_unref(reply);
1767 WDC_LOGD("%s() return : [%d]", __func__, ret);
1768 __WDC_LOG_FUNC_END__;
1773 int wifi_direct_disconnect(char *mac_address)
1775 __WDC_LOG_FUNC_START__;
1777 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1779 GVariant *params = NULL;
1780 GError *error = NULL;
1781 GVariant *reply = NULL;
1782 int ret = WIFI_DIRECT_ERROR_NONE;
1784 if (g_client_info.is_registered == false) {
1785 WDC_LOGE("Client is NOT registered");
1786 __WDC_LOG_FUNC_END__;
1787 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1791 WDC_LOGE("mac_addr is NULL");
1792 __WDC_LOG_FUNC_END__;
1793 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1796 params = g_variant_new("(s)", mac_address);
1797 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1798 "Disconnect", params, &error);
1800 ret = __net_wifidirect_gerror_to_enum(error);
1801 if (ret == WIFI_DIRECT_ERROR_NONE) {
1802 g_variant_get(reply, "(i)", &ret);
1803 g_variant_unref(reply);
1806 WDC_LOGD("%s() return : [%d]", __func__, ret);
1807 __WDC_LOG_FUNC_END__;
1811 int wifi_direct_accept_connection(char *mac_address)
1813 __WDC_LOG_FUNC_START__;
1815 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1817 GVariant *params = NULL;
1818 GError *error = NULL;
1819 GVariant *reply = NULL;
1820 int ret = WIFI_DIRECT_ERROR_NONE;
1822 if (g_client_info.is_registered == false) {
1823 WDC_LOGE("Client is NOT registered");
1824 __WDC_LOG_FUNC_END__;
1825 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1829 WDC_LOGE("mac_addr is NULL");
1830 __WDC_LOG_FUNC_END__;
1831 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1834 params = g_variant_new("(s)", mac_address);
1835 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1836 "AcceptConnection", params, &error);
1838 ret = __net_wifidirect_gerror_to_enum(error);
1839 if (ret == WIFI_DIRECT_ERROR_NONE) {
1840 g_variant_get(reply, "(i)", &ret);
1841 g_variant_unref(reply);
1844 WDC_LOGD("%s() return : [%d]", __func__, ret);
1845 __WDC_LOG_FUNC_END__;
1850 int wifi_direct_foreach_connected_peers(wifi_direct_connected_peer_cb cb,
1853 __WDC_LOG_FUNC_START__;
1855 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1857 GVariant *params = NULL;
1858 GError *error = NULL;
1859 GVariant *reply = NULL;
1860 GVariantIter *iter_peers = NULL;
1861 GVariantIter *iter_peer = NULL;
1862 GVariant *var = NULL;
1864 int ret = WIFI_DIRECT_ERROR_NONE;
1866 if (g_client_info.is_registered == false) {
1867 WDC_LOGE("Client is NOT registered");
1868 __WDC_LOG_FUNC_END__;
1869 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1873 WDC_LOGE("NULL Param [callback]!");
1874 __WDC_LOG_FUNC_END__;
1875 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1879 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1880 "GetConnectedPeers", params, &error);
1882 ret = __net_wifidirect_gerror_to_enum(error);
1883 if (ret != WIFI_DIRECT_ERROR_NONE)
1886 g_variant_get(reply, "(iaa{sv})", &ret, &iter_peers);
1887 if (ret != WIFI_DIRECT_ERROR_NONE) {
1888 __WDC_LOG_FUNC_END__;
1889 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1892 WDC_LOGD("wifi_direct_foreach_connected_peers() SUCCESS");
1894 while (g_variant_iter_loop(iter_peers, "a{sv}", &iter_peer)) {
1895 wifi_direct_connected_peer_info_s *peer_list = NULL;
1897 peer_list = (wifi_direct_connected_peer_info_s *) g_try_malloc0(sizeof(wifi_direct_connected_peer_info_s));
1899 WDC_LOGE("Failed to allocate memory");
1903 while (g_variant_iter_loop(iter_peer, "{sv}", &key, &var)) {
1904 if (!g_strcmp0(key, "DeviceName")) {
1905 const char *device_name = NULL;
1907 g_variant_get(var, "&s", &device_name);
1908 peer_list->device_name = g_strndup(device_name, WIFI_DIRECT_MAX_DEVICE_NAME_LEN+1);
1910 } else if (!g_strcmp0(key, "DeviceAddress")) {
1911 unsigned char mac_address[MACADDR_LEN] = {0, };
1913 wifi_direct_dbus_unpack_ay(mac_address, var, MACADDR_LEN);
1914 peer_list->mac_address = (char*) g_try_malloc0(MACSTR_LEN);
1915 if (peer_list->mac_address)
1916 g_snprintf(peer_list->mac_address, MACSTR_LEN, MACSTR, MAC2STR(mac_address));
1918 } else if (!g_strcmp0(key, "InterfaceAddress")) {
1919 unsigned char intf_address[MACADDR_LEN] = {0, };
1921 wifi_direct_dbus_unpack_ay(intf_address, var, MACADDR_LEN);
1922 peer_list->interface_address = (char*) g_try_malloc0(MACSTR_LEN);
1923 if (peer_list->interface_address)
1924 g_snprintf(peer_list->interface_address, MACSTR_LEN, MACSTR, MAC2STR(intf_address));
1926 } else if (!g_strcmp0(key, "IPAddress")) {
1927 unsigned char ip_address[IPADDR_LEN] = {0, };
1929 wifi_direct_dbus_unpack_ay(ip_address, var, IPADDR_LEN);
1930 peer_list->ip_address = (char*) g_try_malloc0(IPSTR_LEN);
1931 if (peer_list->ip_address)
1932 g_snprintf(peer_list->ip_address, IPSTR_LEN, IPSTR, IP2STR(ip_address));
1934 } else if (!g_strcmp0(key, "Channel")) {
1935 peer_list->channel = g_variant_get_uint16(var);
1937 } else if (!g_strcmp0(key, "Category")) {
1938 peer_list->primary_device_type = g_variant_get_uint16(var);
1940 } else if (!g_strcmp0(key, "SubCategory")) {
1941 peer_list->secondary_device_type = g_variant_get_uint16(var);
1943 } else if (!g_strcmp0(key, "IsWfdDevice")) {
1945 if (g_client_info.is_display_supported)
1946 peer_list->is_miracast_device = g_variant_get_boolean(var);
1947 } else if (!g_strcmp0(key, "IsP2P")) {
1948 peer_list->p2p_supported = g_variant_get_boolean(var);
1955 /* __wfd_client_print_connected_peer_info(peer_list, 1); */
1956 if (!cb(peer_list, user_data)) {
1957 g_variant_iter_free(iter_peer);
1962 g_variant_iter_free(iter_peers);
1963 g_variant_unref(reply);
1965 __WDC_LOG_FUNC_END__;
1966 return WIFI_DIRECT_ERROR_NONE;
1970 int wifi_direct_create_group(void)
1972 __WDC_LOG_FUNC_START__;
1974 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1976 GVariantBuilder *builder = NULL;
1977 GVariant *params = NULL;
1978 GError *error = NULL;
1979 GVariant *reply = NULL;
1980 int ret = WIFI_DIRECT_ERROR_NONE;
1982 if (g_client_info.is_registered == false) {
1983 WDC_LOGE("Client is NOT registered");
1984 __WDC_LOG_FUNC_END__;
1985 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1988 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
1989 params = g_variant_new("(a{sv})", builder);
1990 g_variant_builder_unref(builder);
1992 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
1993 "CreateGroup", params, &error);
1995 ret = __net_wifidirect_gerror_to_enum(error);
1996 if (ret == WIFI_DIRECT_ERROR_NONE) {
1997 g_variant_get(reply, "(i)", &ret);
1998 g_variant_unref(reply);
2001 WDC_LOGD("%s() return : [%d]", __func__, ret);
2002 __WDC_LOG_FUNC_END__;
2007 int wifi_direct_destroy_group(void)
2009 __WDC_LOG_FUNC_START__;
2011 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2013 GError *error = NULL;
2014 GVariant *reply = NULL;
2015 int ret = WIFI_DIRECT_ERROR_NONE;
2017 if (g_client_info.is_registered == false) {
2018 WDC_LOGE("Client is NOT registered");
2019 __WDC_LOG_FUNC_END__;
2020 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2023 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
2024 "DestroyGroup", NULL, &error);
2026 ret = __net_wifidirect_gerror_to_enum(error);
2027 if (ret == WIFI_DIRECT_ERROR_NONE) {
2028 g_variant_get(reply, "(i)", &ret);
2029 g_variant_unref(reply);
2032 WDC_LOGD("%s() return : [%d]", __func__, ret);
2033 __WDC_LOG_FUNC_END__;
2038 int wifi_direct_is_group_owner(bool *owner)
2040 __WDC_LOG_FUNC_START__;
2042 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2044 GError* error = NULL;
2045 GVariant *reply = NULL;
2046 int ret = WIFI_DIRECT_ERROR_NONE;
2049 if (g_client_info.is_registered == false) {
2050 WDC_LOGE("Client is NOT registered");
2051 __WDC_LOG_FUNC_END__;
2052 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2056 WDC_LOGE("NULL Param [owner]!");
2057 __WDC_LOG_FUNC_END__;
2058 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2061 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
2066 ret = __net_wifidirect_gerror_to_enum(error);
2067 if (ret != WIFI_DIRECT_ERROR_NONE)
2070 WDC_LOGD("%s() SUCCESS", __func__);
2071 g_variant_get(reply, "(b)", &val);
2073 g_variant_unref(reply);
2075 __WDC_LOG_FUNC_END__;
2076 return WIFI_DIRECT_ERROR_NONE;
2079 int wifi_direct_is_autonomous_group(bool *autonomous_group)
2081 __WDC_LOG_FUNC_START__;
2083 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2085 GError* error = NULL;
2086 GVariant *reply = NULL;
2087 int ret = WIFI_DIRECT_ERROR_NONE;
2090 if (g_client_info.is_registered == false) {
2091 WDC_LOGE("Client is NOT registered");
2092 __WDC_LOG_FUNC_END__;
2093 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2096 if (!autonomous_group) {
2097 WDC_LOGE("NULL Param [autonomous_group]!\n");
2098 __WDC_LOG_FUNC_END__;
2099 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2102 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
2107 ret = __net_wifidirect_gerror_to_enum(error);
2108 if (ret != WIFI_DIRECT_ERROR_NONE)
2111 WDC_LOGD("%s() SUCCESS", __func__);
2112 g_variant_get(reply, "(b)", &val);
2113 *autonomous_group = val;
2114 g_variant_unref(reply);
2116 __WDC_LOG_FUNC_END__;
2117 return WIFI_DIRECT_ERROR_NONE;
2121 int wifi_direct_set_group_owner_intent(int intent)
2123 __WDC_LOG_FUNC_START__;
2125 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2127 GError* error = NULL;
2128 GVariant *reply = NULL;
2129 GVariant *params = NULL;
2130 int ret = WIFI_DIRECT_ERROR_NONE;
2132 if (g_client_info.is_registered == false) {
2133 WDC_LOGE("Client is NOT registered");
2134 __WDC_LOG_FUNC_END__;
2135 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2138 if (intent < 0 || intent > 15) {
2139 WDC_LOGE("Invalid Param : intent[%d]", intent);
2140 __WDC_LOG_FUNC_END__;
2141 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2144 params = g_variant_new("(i)", intent);
2145 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2150 ret = __net_wifidirect_gerror_to_enum(error);
2151 if (ret == WIFI_DIRECT_ERROR_NONE) {
2152 g_variant_get(reply, "(i)", &ret);
2153 g_variant_unref(reply);
2156 WDC_LOGD("%s() return : [%d]", __func__, ret);
2157 __WDC_LOG_FUNC_END__;
2161 int wifi_direct_get_group_owner_intent(int *intent)
2163 __WDC_LOG_FUNC_START__;
2165 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2167 GError* error = NULL;
2168 GVariant *reply = NULL;
2170 int ret = WIFI_DIRECT_ERROR_NONE;
2172 if (g_client_info.is_registered == false) {
2173 WDC_LOGE("Client is NOT registered");
2174 __WDC_LOG_FUNC_END__;
2175 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2179 WDC_LOGE("Invalid Parameter");
2180 __WDC_LOG_FUNC_END__;
2181 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2184 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2189 ret = __net_wifidirect_gerror_to_enum(error);
2190 if (ret != WIFI_DIRECT_ERROR_NONE)
2193 g_variant_get(reply, "(ii)", &ret, &val);
2195 g_variant_unref(reply);
2197 WDC_LOGD("Intent = [%d]", *intent);
2198 WDC_LOGD("%s() return : [%d]", __func__, ret);
2199 __WDC_LOG_FUNC_END__;
2203 int wifi_direct_set_max_clients(int max)
2205 __WDC_LOG_FUNC_START__;
2207 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2209 GError* error = NULL;
2210 GVariant *reply = NULL;
2211 GVariant *params = NULL;
2212 int ret = WIFI_DIRECT_ERROR_NONE;
2214 if (g_client_info.is_registered == false) {
2215 WDC_LOGE("Client is NOT registered");
2216 __WDC_LOG_FUNC_END__;
2217 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2219 WDC_LOGD("max client [%d]\n", max);
2221 params = g_variant_new("(i)", max);
2222 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2227 ret = __net_wifidirect_gerror_to_enum(error);
2228 if (ret == WIFI_DIRECT_ERROR_NONE) {
2229 g_variant_get(reply, "(i)", &ret);
2230 g_variant_unref(reply);
2233 WDC_LOGD("%s() return : [%d]", __func__, ret);
2234 __WDC_LOG_FUNC_END__;
2238 int wifi_direct_get_max_clients(int *max)
2240 __WDC_LOG_FUNC_START__;
2242 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2244 GError* error = NULL;
2245 GVariant *reply = NULL;
2247 int ret = WIFI_DIRECT_ERROR_NONE;
2249 if (g_client_info.is_registered == false) {
2250 WDC_LOGE("Client is NOT registered");
2251 __WDC_LOG_FUNC_END__;
2252 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2256 WDC_LOGE("Invalid Parameter");
2257 __WDC_LOG_FUNC_END__;
2258 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2261 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2266 ret = __net_wifidirect_gerror_to_enum(error);
2267 if (ret != WIFI_DIRECT_ERROR_NONE)
2270 g_variant_get(reply, "(ii)", &ret, &val);
2272 g_variant_unref(reply);
2274 WDC_LOGD("max_client = [%d]", *max);
2275 WDC_LOGD("%s() return : [%d]", __func__, ret);
2276 __WDC_LOG_FUNC_END__;
2277 return WIFI_DIRECT_ERROR_NONE;
2280 int wifi_direct_get_operating_channel(int *channel)
2282 __WDC_LOG_FUNC_START__;
2284 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2286 GError* error = NULL;
2287 GVariant *reply = NULL;
2289 int ret = WIFI_DIRECT_ERROR_NONE;
2291 if (g_client_info.is_registered == false) {
2292 WDC_LOGE("Client is NOT registered");
2293 __WDC_LOG_FUNC_END__;
2294 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2298 WDC_LOGE("NULL Param [channel]!\n");
2299 __WDC_LOG_FUNC_END__;
2300 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2303 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2304 "GetOperatingChannel",
2308 ret = __net_wifidirect_gerror_to_enum(error);
2309 if (ret != WIFI_DIRECT_ERROR_NONE)
2312 g_variant_get(reply, "(ii)", &ret, &val);
2314 g_variant_unref(reply);
2316 WDC_LOGD("channel = [%d]", *channel);
2317 WDC_LOGD("%s() return : [%d]", __func__, ret);
2318 __WDC_LOG_FUNC_END__;
2319 return WIFI_DIRECT_ERROR_NONE;
2322 int wifi_direct_activate_pushbutton(void)
2324 __WDC_LOG_FUNC_START__;
2326 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2328 GError* error = NULL;
2329 GVariant *reply = NULL;
2330 int ret = WIFI_DIRECT_ERROR_NONE;
2332 if (g_client_info.is_registered == false) {
2333 WDC_LOGE("Client is NOT registered");
2334 __WDC_LOG_FUNC_END__;
2335 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2338 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
2339 "ActivatePushButton",
2343 ret = __net_wifidirect_gerror_to_enum(error);
2344 if (ret == WIFI_DIRECT_ERROR_NONE) {
2345 g_variant_get(reply, "(i)", &ret);
2346 g_variant_unref(reply);
2349 WDC_LOGD("%s() return : [%d]", __func__, ret);
2350 __WDC_LOG_FUNC_END__;
2354 int wifi_direct_set_wps_pin(char *pin)
2356 __WDC_LOG_FUNC_START__;
2358 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2360 GError* error = NULL;
2361 GVariant *reply = NULL;
2362 GVariant *params = NULL;
2363 int ret = WIFI_DIRECT_ERROR_NONE;
2365 if (g_client_info.is_registered == false) {
2366 WDC_LOGE("Client is NOT registered");
2367 __WDC_LOG_FUNC_END__;
2368 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2372 WDC_LOGE("NULL Param [pin]!");
2373 __WDC_LOG_FUNC_END__;
2374 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2376 WDC_LOGE("pin = [%s]\n", pin);
2378 params = g_variant_new("(s)", pin);
2379 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2384 ret = __net_wifidirect_gerror_to_enum(error);
2385 if (ret == WIFI_DIRECT_ERROR_NONE) {
2386 g_variant_get(reply, "(i)", &ret);
2387 g_variant_unref(reply);
2390 WDC_LOGD("%s() return : [%d]", __func__, ret);
2391 __WDC_LOG_FUNC_END__;
2396 int wifi_direct_get_wps_pin(char **pin)
2398 __WDC_LOG_FUNC_START__;
2400 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2402 GError* error = NULL;
2403 GVariant *reply = NULL;
2404 const char *str = NULL;
2405 int ret = WIFI_DIRECT_ERROR_NONE;
2407 if (g_client_info.is_registered == false) {
2408 WDC_LOGE("Client is NOT registered");
2409 __WDC_LOG_FUNC_END__;
2410 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2414 WDC_LOGE("NULL Param [pin]!");
2415 __WDC_LOG_FUNC_END__;
2416 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2419 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2424 ret = __net_wifidirect_gerror_to_enum(error);
2425 if (ret != WIFI_DIRECT_ERROR_NONE)
2428 g_variant_get(reply, "(i&s)", &ret, &str);
2431 g_variant_unref(reply);
2433 WDC_LOGD("%s() return : [%d]", __func__, ret);
2434 __WDC_LOG_FUNC_END__;
2438 int wifi_direct_get_supported_wps_mode(int *wps_mode)
2440 __WDC_LOG_FUNC_START__;
2442 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2444 GError* error = NULL;
2445 GVariant *reply = NULL;
2447 int ret = WIFI_DIRECT_ERROR_NONE;
2449 if (g_client_info.is_registered == false) {
2450 WDC_LOGE("Client is NOT registered");
2451 __WDC_LOG_FUNC_END__;
2452 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2456 WDC_LOGE("NULL Param [wps_mode]!");
2457 __WDC_LOG_FUNC_END__;
2458 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2461 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2462 "GetSupportedWpsMode",
2466 ret = __net_wifidirect_gerror_to_enum(error);
2467 if (ret != WIFI_DIRECT_ERROR_NONE)
2470 g_variant_get(reply, "(ii)", &ret, &mode);
2472 g_variant_unref(reply);
2474 WDC_LOGD("%s() return : [%d]", __func__, ret);
2475 __WDC_LOG_FUNC_END__;
2479 int wifi_direct_foreach_supported_wps_types(wifi_direct_supported_wps_type_cb cb, void* user_data)
2481 __WDC_LOG_FUNC_START__;
2483 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2485 GError* error = NULL;
2486 GVariant *reply = NULL;
2488 int ret = WIFI_DIRECT_ERROR_NONE;
2489 gboolean result = FALSE;
2491 if (g_client_info.is_registered == false) {
2492 WDC_LOGE("Client is NOT registered");
2493 __WDC_LOG_FUNC_END__;
2494 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2498 WDC_LOGE("NULL Param [callback]!");
2499 __WDC_LOG_FUNC_END__;
2500 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2503 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2504 "GetSupportedWpsMode",
2508 ret = __net_wifidirect_gerror_to_enum(error);
2509 if (ret != WIFI_DIRECT_ERROR_NONE)
2512 g_variant_get(reply, "(ii)", &ret, &wps_mode);
2513 g_variant_unref(reply);
2515 if (wps_mode & WIFI_DIRECT_WPS_TYPE_PBC)
2516 result = cb(WIFI_DIRECT_WPS_TYPE_PBC, user_data);
2517 if ((result == TRUE) && (wps_mode & WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY))
2518 result = cb(WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY, user_data);
2519 if ((result == TRUE) && (wps_mode & WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD))
2520 cb(WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD, user_data);
2522 WDC_LOGD("%s() return : [%d]", __func__, ret);
2523 __WDC_LOG_FUNC_END__;
2527 int wifi_direct_get_local_wps_type(wifi_direct_wps_type_e *type)
2529 __WDC_LOG_FUNC_START__;
2531 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2533 GError* error = NULL;
2534 GVariant *reply = NULL;
2536 int ret = WIFI_DIRECT_ERROR_NONE;
2538 if (g_client_info.is_registered == false) {
2539 WDC_LOGE("Client is NOT registered");
2540 __WDC_LOG_FUNC_END__;
2541 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2545 WDC_LOGE("NULL Param [type]!\n");
2546 __WDC_LOG_FUNC_END__;
2547 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2550 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2555 ret = __net_wifidirect_gerror_to_enum(error);
2556 if (ret != WIFI_DIRECT_ERROR_NONE)
2559 g_variant_get(reply, "(ii)", &ret, &mode);
2561 g_variant_unref(reply);
2563 WDC_LOGD("%s() return : [%d]", __func__, ret);
2564 __WDC_LOG_FUNC_END__;
2568 int wifi_direct_set_req_wps_type(wifi_direct_wps_type_e type)
2570 __WDC_LOG_FUNC_START__;
2572 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2574 GError* error = NULL;
2575 GVariant *reply = NULL;
2576 GVariant *params = NULL;
2577 int ret = WIFI_DIRECT_ERROR_NONE;
2579 if (g_client_info.is_registered == false) {
2580 WDC_LOGE("Client is NOT registered");
2581 __WDC_LOG_FUNC_END__;
2582 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2585 if (type == WIFI_DIRECT_WPS_TYPE_PBC ||
2586 type == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY ||
2587 type == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) {
2588 WDC_LOGD("Param wps_mode [%d]", type);
2590 WDC_LOGE("Invalid Param [wps_mode]!");
2591 __WDC_LOG_FUNC_END__;
2592 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2595 params = g_variant_new("(i)", type);
2596 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2601 ret = __net_wifidirect_gerror_to_enum(error);
2602 if (ret == WIFI_DIRECT_ERROR_NONE) {
2603 g_variant_get(reply, "(i)", &ret);
2604 g_variant_unref(reply);
2607 WDC_LOGD("%s() return : [%d]", __func__, ret);
2608 __WDC_LOG_FUNC_END__;
2612 int wifi_direct_get_req_wps_type(wifi_direct_wps_type_e *type)
2614 __WDC_LOG_FUNC_START__;
2616 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2618 GError* error = NULL;
2619 GVariant *reply = NULL;
2623 if (g_client_info.is_registered == false) {
2624 WDC_LOGE("Client is NOT registered");
2625 __WDC_LOG_FUNC_END__;
2626 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2630 WDC_LOGE("NULL Param [type]!\n");
2631 __WDC_LOG_FUNC_END__;
2632 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2635 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2640 ret = __net_wifidirect_gerror_to_enum(error);
2641 if (ret != WIFI_DIRECT_ERROR_NONE)
2644 g_variant_get(reply, "(ii)", &ret, &mode);
2646 g_variant_unref(reply);
2648 WDC_LOGD("%s() return : [%d]", __func__, ret);
2649 __WDC_LOG_FUNC_END__;
2653 int wifi_direct_get_ssid(char **ssid)
2655 __WDC_LOG_FUNC_START__;
2657 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2659 GError* error = NULL;
2660 GVariant *reply = NULL;
2661 const char *str = NULL;
2662 int ret = WIFI_DIRECT_ERROR_NONE;
2664 if (g_client_info.is_registered == false) {
2665 WDC_LOGE("Client is NOT registered");
2666 __WDC_LOG_FUNC_END__;
2667 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2671 WDC_LOGE("Invalid Parameter");
2672 __WDC_LOG_FUNC_END__;
2673 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2676 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2681 ret = __net_wifidirect_gerror_to_enum(error);
2682 if (ret != WIFI_DIRECT_ERROR_NONE)
2685 g_variant_get(reply, "(i&s)", &ret, &str);
2687 *ssid = strdup(str);
2688 g_variant_unref(reply);
2690 WDC_LOGD("%s() return : [%d]", __func__, ret);
2691 __WDC_LOG_FUNC_END__;
2695 int wifi_direct_get_device_name(char **device_name)
2697 __WDC_LOG_FUNC_START__;
2699 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2701 GError* error = NULL;
2702 GVariant *reply = NULL;
2703 const char *str = NULL;
2704 int ret = WIFI_DIRECT_ERROR_NONE;
2706 if (g_client_info.is_registered == false) {
2707 WDC_LOGE("Client is NOT registered");
2708 __WDC_LOG_FUNC_END__;
2709 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2713 WDC_LOGE("Invalid Parameter");
2714 __WDC_LOG_FUNC_END__;
2715 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2718 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2723 ret = __net_wifidirect_gerror_to_enum(error);
2724 if (ret != WIFI_DIRECT_ERROR_NONE)
2727 g_variant_get(reply, "(i&s)", &ret, &str);
2729 *device_name = strdup(str);
2730 g_variant_unref(reply);
2732 WDC_LOGD("%s() return : [%d]", __func__, ret);
2733 __WDC_LOG_FUNC_END__;
2737 int wifi_direct_set_device_name(const char *device_name)
2739 __WDC_LOG_FUNC_START__;
2741 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2743 GError* error = NULL;
2744 GVariant *reply = NULL;
2745 GVariant *params = NULL;
2746 int ret = WIFI_DIRECT_ERROR_NONE;
2748 if (g_client_info.is_registered == false) {
2749 WDC_LOGE("Client is NOT registered");
2750 __WDC_LOG_FUNC_END__;
2751 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2755 WDC_LOGE("NULL Param [device_name]!");
2756 __WDC_LOG_FUNC_END__;
2757 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2759 WDC_LOGE("device_name = [%s]", device_name);
2761 params = g_variant_new("(s)", device_name);
2762 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2767 ret = __net_wifidirect_gerror_to_enum(error);
2768 if (ret == WIFI_DIRECT_ERROR_NONE) {
2769 g_variant_get(reply, "(i)", &ret);
2770 g_variant_unref(reply);
2773 WDC_LOGD("%s() return : [%d]", __func__, ret);
2774 __WDC_LOG_FUNC_END__;
2779 int wifi_direct_get_network_interface_name(char **name)
2781 __WDC_LOG_FUNC_START__;
2783 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2785 wifi_direct_state_e status = 0;
2786 char *get_str = NULL;
2787 GError* error = NULL;
2788 GVariant *reply = NULL;
2789 int ret = WIFI_DIRECT_ERROR_NONE;
2791 if (g_client_info.is_registered == false) {
2792 WDC_LOGE("Client is NOT registered");
2793 __WDC_LOG_FUNC_END__;
2794 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2798 WDC_LOGE("NULL Param [name]!\n");
2799 __WDC_LOG_FUNC_END__;
2800 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2803 ret = wifi_direct_get_state(&status);
2804 WDC_LOGD("wifi_direct_get_state() state=[%d], ret=[%d]\n", status, ret);
2806 if (status < WIFI_DIRECT_STATE_CONNECTED) {
2807 WDC_LOGE("Device is not connected!\n");
2808 __WDC_LOG_FUNC_END__;
2809 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
2812 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2817 ret = __net_wifidirect_gerror_to_enum(error);
2818 if (ret != WIFI_DIRECT_ERROR_NONE)
2821 g_variant_get(reply, "(i&s)", ret, &get_str);
2822 if (get_str != NULL)
2823 *name = strdup(get_str);
2824 g_variant_unref(reply);
2826 WDC_LOGD("Interface Name = [%s]", *name);
2827 WDC_LOGD("%s() return : [%d]", __func__, ret);
2829 __WDC_LOG_FUNC_END__;
2830 return WIFI_DIRECT_ERROR_NONE;
2833 int wifi_direct_get_ip_address(char **ip_address)
2835 __WDC_LOG_FUNC_START__;
2837 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2839 GError* error = NULL;
2840 GVariant *reply = NULL;
2841 const char *str = NULL;
2842 int ret = WIFI_DIRECT_ERROR_NONE;
2844 if (g_client_info.is_registered == false) {
2845 WDC_LOGE("Client is NOT registered");
2846 __WDC_LOG_FUNC_END__;
2847 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2851 WDC_LOGE("NULL Param [ip_address]!\n");
2852 __WDC_LOG_FUNC_END__;
2853 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2856 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2861 ret = __net_wifidirect_gerror_to_enum(error);
2862 if (ret != WIFI_DIRECT_ERROR_NONE)
2865 g_variant_get(reply, "(i&s)", ret, &str);
2867 *ip_address = strdup(str);
2868 g_variant_unref(reply);
2870 WDC_LOGD("IP address = [%s]", *ip_address);
2871 WDC_LOGD("%s() return : [%d]", __func__, ret);
2872 __WDC_LOG_FUNC_END__;
2876 int wifi_direct_get_subnet_mask(char **subnet_mask)
2878 __WDC_LOG_FUNC_START__;
2880 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2882 wifi_direct_state_e status = 0;
2883 GError* error = NULL;
2884 GVariant *reply = NULL;
2885 char *get_str = NULL;
2886 int ret = WIFI_DIRECT_ERROR_NONE;
2888 if (g_client_info.is_registered == false) {
2889 WDC_LOGE("Client is NOT registered");
2890 __WDC_LOG_FUNC_END__;
2891 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2895 WDC_LOGE("NULL Param [subnet_mask]!");
2896 __WDC_LOG_FUNC_END__;
2897 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2900 ret = wifi_direct_get_state(&status);
2901 WDC_LOGD("wifi_direct_get_state() state=[%d], ret=[%d]", status, ret);
2902 if (status < WIFI_DIRECT_STATE_CONNECTED) {
2903 WDC_LOGE("Device is not connected!");
2904 __WDC_LOG_FUNC_END__;
2905 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
2908 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2913 ret = __net_wifidirect_gerror_to_enum(error);
2914 if (ret != WIFI_DIRECT_ERROR_NONE)
2917 g_variant_get(reply, "(i&s)", ret, &get_str);
2918 if (get_str != NULL)
2919 *subnet_mask = strdup(get_str);
2920 g_variant_unref(reply);
2922 WDC_LOGD("Subnet Mask = [%s]", *subnet_mask);
2923 WDC_LOGD("%s() return : [%d]", __func__, ret);
2925 __WDC_LOG_FUNC_END__;
2926 return WIFI_DIRECT_ERROR_NONE;
2929 int wifi_direct_get_gateway_address(char **gateway_address)
2931 __WDC_LOG_FUNC_START__;
2933 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2935 wifi_direct_state_e status = 0;
2936 GError* error = NULL;
2937 GVariant *reply = NULL;
2938 char *get_str = NULL;
2939 int ret = WIFI_DIRECT_ERROR_NONE;
2941 if (g_client_info.is_registered == false) {
2942 WDC_LOGE("Client is NOT registered");
2943 __WDC_LOG_FUNC_END__;
2944 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2947 if (!gateway_address) {
2948 WDC_LOGE("NULL Param [gateway_address]!");
2949 __WDC_LOG_FUNC_END__;
2950 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2953 ret = wifi_direct_get_state(&status);
2954 WDC_LOGD("wifi_direct_get_state() state=[%d], ret=[%d]", status, ret);
2955 if (status < WIFI_DIRECT_STATE_CONNECTED) {
2956 WDC_LOGE("Device is not connected!");
2957 __WDC_LOG_FUNC_END__;
2958 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
2961 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2966 ret = __net_wifidirect_gerror_to_enum(error);
2967 if (ret != WIFI_DIRECT_ERROR_NONE)
2970 g_variant_get(reply, "(i&s)", ret, &get_str);
2971 if (get_str != NULL)
2972 *gateway_address = strdup(get_str);
2973 g_variant_unref(reply);
2975 WDC_LOGD("Gateway Address = [%s]", *gateway_address);
2976 WDC_LOGD("%s() return : [%d]", __func__, ret);
2978 __WDC_LOG_FUNC_END__;
2979 return WIFI_DIRECT_ERROR_NONE;
2983 int wifi_direct_get_mac_address(char **mac_address)
2985 __WDC_LOG_FUNC_START__;
2987 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2989 GError* error = NULL;
2990 GVariant *reply = NULL;
2991 const char *str = NULL;
2992 int ret = WIFI_DIRECT_ERROR_NONE;
2994 if (g_client_info.is_registered == false) {
2995 WDC_LOGE("Client is NOT registered");
2996 __WDC_LOG_FUNC_END__;
2997 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3001 WDC_LOGE("NULL Param [mac_address]!");
3002 __WDC_LOG_FUNC_END__;
3003 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3006 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
3011 ret = __net_wifidirect_gerror_to_enum(error);
3012 if (ret != WIFI_DIRECT_ERROR_NONE)
3015 g_variant_get(reply, "(i&s)", &ret, &str);
3017 *mac_address = strdup(str);
3018 g_variant_unref(reply);
3020 WDC_SECLOGD("MAC address = [%s]", *mac_address);
3021 WDC_LOGD("%s() return : [%d]", __func__, ret);
3022 __WDC_LOG_FUNC_END__;
3026 int wifi_direct_get_state(wifi_direct_state_e *state)
3028 __WDC_LOG_FUNC_START__;
3030 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3033 int ret = WIFI_DIRECT_ERROR_NONE;
3036 WDC_LOGE("Invalid Parameter");
3037 __WDC_LOG_FUNC_END__;
3038 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3041 ret = vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &val);
3043 WDC_LOGE("Failed to get vconf value [%s]\n", VCONFKEY_WIFI_DIRECT_STATE);
3044 __WDC_LOG_FUNC_END__;
3045 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3048 if (val == VCONFKEY_WIFI_DIRECT_ACTIVATED) {
3049 *state = WIFI_DIRECT_STATE_ACTIVATED;
3050 } else if (val == VCONFKEY_WIFI_DIRECT_DEACTIVATED) {
3051 *state = WIFI_DIRECT_STATE_DEACTIVATED;
3052 } else if (val == VCONFKEY_WIFI_DIRECT_CONNECTED) {
3053 *state = WIFI_DIRECT_STATE_CONNECTED;
3054 } else if (val == VCONFKEY_WIFI_DIRECT_GROUP_OWNER) {
3055 *state = WIFI_DIRECT_STATE_CONNECTED;
3056 } else if (val == VCONFKEY_WIFI_DIRECT_DISCOVERING) {
3057 *state = WIFI_DIRECT_STATE_DISCOVERING;
3058 } else if (val == VCONFKEY_WIFI_DIRECT_DEACTIVATING) {
3059 *state = WIFI_DIRECT_STATE_DEACTIVATING;
3060 } else if (val == VCONFKEY_WIFI_DIRECT_ACTIVATING) {
3061 *state = WIFI_DIRECT_STATE_ACTIVATING;
3062 } else if (val == VCONFKEY_WIFI_DIRECT_CONNECTING) {
3063 *state = WIFI_DIRECT_STATE_CONNECTING;
3064 } else if (val == VCONFKEY_WIFI_DIRECT_DISCONNECTING) {
3065 *state = WIFI_DIRECT_STATE_DISCONNECTING;
3067 WDC_LOGE("This state cannot be set as wifi_direct vconf state[%d]", val);
3068 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3071 WDC_LOGD("State = [%d]", *state);
3072 WDC_LOGD("%s() return : [%d]", __func__, ret);
3073 __WDC_LOG_FUNC_END__;
3077 int wifi_direct_is_discoverable(bool* discoverable)
3079 __WDC_LOG_FUNC_START__;
3081 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3083 GError* error = NULL;
3084 GVariant *reply = NULL;
3085 int ret = WIFI_DIRECT_ERROR_NONE;
3087 if (g_client_info.is_registered == false) {
3088 WDC_LOGE("Client is NOT registered");
3089 __WDC_LOG_FUNC_END__;
3090 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3093 if (!discoverable) {
3094 WDC_LOGE("Invalid Parameter");
3095 __WDC_LOG_FUNC_END__;
3096 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3099 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
3100 "IsDiscoverable", NULL, &error);
3102 ret = __net_wifidirect_gerror_to_enum(error);
3103 if (ret != WIFI_DIRECT_ERROR_NONE)
3106 g_variant_get(reply, "(b)", discoverable);
3107 WDC_LOGD("Discoverable = [%s]", *discoverable ? "Yes" : "No");
3109 WDC_LOGD("%s() SUCCESS", __func__);
3110 g_variant_unref(reply);
3112 __WDC_LOG_FUNC_END__;
3113 return WIFI_DIRECT_ERROR_NONE;
3116 int wifi_direct_is_listening_only(bool* listen_only)
3118 __WDC_LOG_FUNC_START__;
3120 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3122 GError* error = NULL;
3123 GVariant *reply = NULL;
3124 int ret = WIFI_DIRECT_ERROR_NONE;
3126 if (g_client_info.is_registered == false) {
3127 WDC_LOGE("Client is NOT registered");
3128 __WDC_LOG_FUNC_END__;
3129 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3133 WDC_LOGE("Invalid Parameter");
3134 __WDC_LOG_FUNC_END__;
3135 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3138 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
3139 "IsListeningOnly", NULL, &error);
3141 ret = __net_wifidirect_gerror_to_enum(error);
3142 if (ret != WIFI_DIRECT_ERROR_NONE)
3145 g_variant_get(reply, "(b)", listen_only);
3147 WDC_LOGD("Is listen only = [%s]", *listen_only ? "Yes" : "No");
3148 WDC_LOGD("%s() SUCCESS", __func__);
3149 g_variant_unref(reply);
3151 __WDC_LOG_FUNC_END__;
3152 return WIFI_DIRECT_ERROR_NONE;
3156 int wifi_direct_get_primary_device_type(wifi_direct_primary_device_type_e* type)
3158 __WDC_LOG_FUNC_START__;
3160 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3162 GError* error = NULL;
3163 GVariant *reply = NULL;
3164 int ret = WIFI_DIRECT_ERROR_NONE;
3165 int primary_device_type = 0;
3167 if (g_client_info.is_registered == false) {
3168 WDC_LOGE("Client is NOT registered");
3169 __WDC_LOG_FUNC_END__;
3170 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3174 WDC_LOGE("NULL Param [type]!");
3175 __WDC_LOG_FUNC_END__;
3176 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3179 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
3180 "GetPrimaryDevType",
3183 ret = __net_wifidirect_gerror_to_enum(error);
3184 if (ret != WIFI_DIRECT_ERROR_NONE)
3187 WDC_LOGD("%s() SUCCESS", __func__);
3188 g_variant_get(reply, "(ii)", &ret, &primary_device_type);
3189 g_variant_unref(reply);
3190 *type = primary_device_type;
3192 __WDC_LOG_FUNC_END__;
3196 int wifi_direct_get_secondary_device_type(wifi_direct_secondary_device_type_e* type)
3198 __WDC_LOG_FUNC_START__;
3200 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3202 GError* error = NULL;
3203 GVariant *reply = NULL;
3204 int ret = WIFI_DIRECT_ERROR_NONE;
3205 int secondary_device_type = 0;
3207 if (g_client_info.is_registered == false) {
3208 WDC_LOGE("Client is NOT registered");
3209 __WDC_LOG_FUNC_END__;
3210 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3214 WDC_LOGE("NULL Param [type]!");
3215 __WDC_LOG_FUNC_END__;
3216 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3219 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
3220 "GetSecondaryDevType",
3223 ret = __net_wifidirect_gerror_to_enum(error);
3224 if (ret != WIFI_DIRECT_ERROR_NONE)
3227 WDC_LOGD("%s() SUCCESS", __func__);
3228 g_variant_get(reply, "(ii)", &ret, &secondary_device_type);
3229 g_variant_unref(reply);
3230 *type = secondary_device_type;
3232 __WDC_LOG_FUNC_END__;
3236 int wifi_direct_set_autoconnection_mode(bool mode)
3238 __WDC_LOG_FUNC_START__;
3240 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3242 GError* error = NULL;
3243 GVariant *reply = NULL;
3244 GVariant *params = NULL;
3245 int ret = WIFI_DIRECT_ERROR_NONE;
3247 if (g_client_info.is_registered == false) {
3248 WDC_LOGE("Client is NOT registered");
3249 __WDC_LOG_FUNC_END__;
3250 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3253 params = g_variant_new("(b)", mode);
3254 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
3255 "SetAutoConnectionMode",
3259 ret = __net_wifidirect_gerror_to_enum(error);
3260 if (ret == WIFI_DIRECT_ERROR_NONE) {
3261 g_variant_get(reply, "(i)", &ret);
3262 g_variant_unref(reply);
3265 WDC_LOGD("%s() return : [%d]", __func__, ret);
3266 __WDC_LOG_FUNC_END__;
3270 int wifi_direct_is_autoconnection_mode(bool *mode)
3272 __WDC_LOG_FUNC_START__;
3274 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3276 GError* error = NULL;
3277 GVariant *reply = NULL;
3279 int ret = WIFI_DIRECT_ERROR_NONE;
3281 if (g_client_info.is_registered == false) {
3282 WDC_LOGE("Client is NOT registered");
3283 __WDC_LOG_FUNC_END__;
3284 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3288 WDC_LOGE("NULL Param [mode]!");
3289 __WDC_LOG_FUNC_END__;
3290 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3293 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
3294 "IsAutoConnectionMode",
3298 ret = __net_wifidirect_gerror_to_enum(error);
3299 if (ret != WIFI_DIRECT_ERROR_NONE)
3302 g_variant_get(reply, "(ib)", &ret, &val);
3304 g_variant_unref(reply);
3306 WDC_LOGD("%s() return : [%d]", __func__, ret);
3307 __WDC_LOG_FUNC_END__;
3312 int wifi_direct_set_persistent_group_enabled(bool enabled)
3314 __WDC_LOG_FUNC_START__;
3316 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3318 GError* error = NULL;
3319 GVariant *reply = NULL;
3320 GVariant *params = NULL;
3321 int ret = WIFI_DIRECT_ERROR_NONE;
3323 if (g_client_info.is_registered == false) {
3324 WDC_LOGE("Client is NOT registered");
3325 __WDC_LOG_FUNC_END__;
3326 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3329 params = g_variant_new("(b)", enabled);
3330 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
3331 "SetPersistentGroupEnabled",
3335 ret = __net_wifidirect_gerror_to_enum(error);
3336 if (ret == WIFI_DIRECT_ERROR_NONE) {
3337 g_variant_get(reply, "(i)", &ret);
3338 g_variant_unref(reply);
3341 WDC_LOGD("%s() return : [%d]", __func__, ret);
3343 __WDC_LOG_FUNC_END__;
3344 return WIFI_DIRECT_ERROR_NONE;
3348 int wifi_direct_is_persistent_group_enabled(bool *enabled)
3350 __WDC_LOG_FUNC_START__;
3352 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3354 GError* error = NULL;
3355 GVariant *reply = NULL;
3356 int ret = WIFI_DIRECT_ERROR_NONE;
3359 if (g_client_info.is_registered == false) {
3360 WDC_LOGE("Client is NOT registered");
3361 __WDC_LOG_FUNC_END__;
3362 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3366 WDC_LOGE("NULL Param [enabled]!");
3367 __WDC_LOG_FUNC_END__;
3368 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3371 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
3372 "IsPersistentGroupEnabled",
3376 ret = __net_wifidirect_gerror_to_enum(error);
3377 if (ret != WIFI_DIRECT_ERROR_NONE)
3380 WDC_LOGD("%s() SUCCESS", __func__);
3381 g_variant_get(reply, "(b)", &val);
3383 g_variant_unref(reply);
3385 __WDC_LOG_FUNC_END__;
3386 return WIFI_DIRECT_ERROR_NONE;
3389 int wifi_direct_foreach_persistent_groups(wifi_direct_persistent_group_cb cb,
3392 __WDC_LOG_FUNC_START__;
3394 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3396 GVariant *params = NULL;
3397 GError *error = NULL;
3398 GVariant *reply = NULL;
3399 GVariantIter *iter_groups = NULL;
3400 GVariantIter *iter_group = NULL;
3401 GVariant *var = NULL;
3403 int ret = WIFI_DIRECT_ERROR_NONE;
3405 if (g_client_info.is_registered == false) {
3406 WDC_LOGE("Client is NOT registered");
3407 __WDC_LOG_FUNC_END__;
3408 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3412 WDC_LOGE("NULL Param [callback]!");
3413 __WDC_LOG_FUNC_END__;
3414 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3417 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
3418 "GetPersistentGroups", params, &error);
3420 ret = __net_wifidirect_gerror_to_enum(error);
3421 if (ret != WIFI_DIRECT_ERROR_NONE)
3424 g_variant_get(reply, "(iaa{sv})", &ret, &iter_groups);
3425 if (ret != WIFI_DIRECT_ERROR_NONE) {
3426 __WDC_LOG_FUNC_END__;
3427 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3430 WDC_LOGD("wifi_direct_foreach_persistent_groups() SUCCESS");
3432 while (g_variant_iter_loop(iter_groups, "a{sv}", &iter_group)) {
3433 const char *ssid = NULL;
3434 char *go_mac_address = NULL;
3436 while (g_variant_iter_loop(iter_group, "{sv}", &key, &var)) {
3437 if (!g_strcmp0(key, "SSID")) {
3438 g_variant_get(var, "&s", &ssid);
3440 } else if (!g_strcmp0(key, "GOMacAddress")) {
3441 unsigned char mac_address[MACADDR_LEN] = {0, };
3443 wifi_direct_dbus_unpack_ay(mac_address, var, MACADDR_LEN);
3444 go_mac_address = (char*) g_try_malloc0(MACSTR_LEN);
3446 g_snprintf(go_mac_address, MACSTR_LEN, MACSTR, MAC2STR(mac_address));
3453 ret = cb(go_mac_address, ssid, user_data);
3454 g_free(go_mac_address);
3455 go_mac_address = NULL;
3457 g_variant_iter_free(iter_group);
3462 g_variant_iter_free(iter_groups);
3463 __WDC_LOG_FUNC_END__;
3464 return WIFI_DIRECT_ERROR_NONE;
3468 int wifi_direct_remove_persistent_group(char *mac_address, const char *ssid)
3470 __WDC_LOG_FUNC_START__;
3472 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3474 GError* error = NULL;
3475 GVariant *reply = NULL;
3476 GVariant *params = NULL;
3477 int ret = WIFI_DIRECT_ERROR_NONE;
3479 if (g_client_info.is_registered == false) {
3480 WDC_LOGE("Client is NOT registered");
3481 __WDC_LOG_FUNC_END__;
3482 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3485 if (!mac_address || !ssid) {
3486 WDC_LOGE("NULL Param");
3487 __WDC_LOG_FUNC_END__;
3488 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3491 params = g_variant_new("(ss)", mac_address, ssid);
3492 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
3493 "RemovePersistentGroup",
3497 ret = __net_wifidirect_gerror_to_enum(error);
3498 if (ret == WIFI_DIRECT_ERROR_NONE) {
3499 g_variant_get(reply, "(i)", &ret);
3500 g_variant_unref(reply);
3503 WDC_LOGD("%s() return : [%d]", __func__, ret);
3505 __WDC_LOG_FUNC_END__;
3506 return WIFI_DIRECT_ERROR_NONE;
3510 int wifi_direct_start_service_discovery(char *mac_address,
3511 wifi_direct_service_type_e type)
3513 __WDC_LOG_FUNC_START__;
3515 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
3519 GError* error = NULL;
3520 GVariant *reply = NULL;
3521 GVariant *params = NULL;
3522 int ret = WIFI_DIRECT_ERROR_NONE;
3524 if (g_client_info.is_registered == false) {
3525 WDC_LOGE("Client is NOT registered.");
3526 __WDC_LOG_FUNC_END__;
3527 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3529 WDC_LOGD("Param service_type [%d]", type);
3532 params = g_variant_new("(is)", type, mac_address);
3534 params = g_variant_new("(is)", type, "00:00:00:00:00:00");
3536 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_SERVICE_INTERFACE,
3541 ret = __net_wifidirect_gerror_to_enum(error);
3542 if (ret == WIFI_DIRECT_ERROR_NONE) {
3543 g_variant_get(reply, "(i)", &ret);
3544 g_variant_unref(reply);
3547 WDC_LOGD("%s() return : [%d]", __func__, ret);
3548 __WDC_LOG_FUNC_END__;
3554 int wifi_direct_cancel_service_discovery(char *mac_address,
3555 wifi_direct_service_type_e type)
3557 __WDC_LOG_FUNC_START__;
3559 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
3561 GError* error = NULL;
3562 GVariant *reply = NULL;
3563 GVariant *params = NULL;
3564 int ret = WIFI_DIRECT_ERROR_NONE;
3566 if (g_client_info.is_registered == false) {
3567 WDC_LOGE("Client is NOT registered.");
3568 __WDC_LOG_FUNC_END__;
3569 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3571 WDC_LOGD("Param service_type [%d]", type);
3574 params = g_variant_new("(is)", type, mac_address);
3576 params = g_variant_new("(is)", type, "00:00:00:00:00:00");
3578 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_SERVICE_INTERFACE,
3583 ret = __net_wifidirect_gerror_to_enum(error);
3584 if (ret == WIFI_DIRECT_ERROR_NONE) {
3585 g_variant_get(reply, "(i)", &ret);
3586 g_variant_unref(reply);
3589 WDC_LOGD("%s() return : [%d]", __func__, ret);
3590 __WDC_LOG_FUNC_END__;
3595 int wifi_direct_register_service(wifi_direct_service_type_e type, char *info1, char *info2, unsigned int *service_id)
3597 __WDC_LOG_FUNC_START__;
3599 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
3601 GError* error = NULL;
3602 GVariant *reply = NULL;
3603 GVariant *params = NULL;
3605 int ret = WIFI_DIRECT_ERROR_NONE;
3608 if (g_client_info.is_registered == false) {
3609 WDC_LOGE("Client is NOT registered.");
3610 __WDC_LOG_FUNC_END__;
3611 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3614 if (!info1 || !info2) {
3615 WDC_LOGE("info1 or info2 is NULL");
3616 __WDC_LOG_FUNC_END__;
3617 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3621 WDC_LOGE("Invalid Param [service_id]!");
3622 __WDC_LOG_FUNC_END__;
3623 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3626 WDC_LOGD("Service type [%d]", type);
3628 len = strlen(info1) + strlen(info2) + 2;
3629 WDC_LOGD("info [%s|%s], len [%d]", info1, info2, len);
3631 buf = g_try_malloc0(len);
3633 WDC_LOGE("Failed to allocate memory for buf");
3634 return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
3637 g_snprintf(buf, len, "%s|%s", info1, info2);
3639 params = g_variant_new("(is)", type, buf);
3640 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_SERVICE_INTERFACE,
3645 ret = __net_wifidirect_gerror_to_enum(error);
3646 if (ret != WIFI_DIRECT_ERROR_NONE) {
3651 g_variant_get(reply, "(ii)", &ret, service_id);
3652 g_variant_unref(reply);
3655 WDC_LOGD("%s() return : [%d]", __func__, ret);
3656 __WDC_LOG_FUNC_END__;
3661 int wifi_direct_deregister_service(unsigned int service_id)
3663 __WDC_LOG_FUNC_START__;
3665 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
3667 GError* error = NULL;
3668 GVariant *reply = NULL;
3669 GVariant *params = NULL;
3670 int ret = WIFI_DIRECT_ERROR_NONE;
3672 if (g_client_info.is_registered == false) {
3673 WDC_LOGE("Client is NOT registered.");
3674 __WDC_LOG_FUNC_END__;
3675 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3678 params = g_variant_new("(i)", service_id);
3679 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_SERVICE_INTERFACE,
3684 ret = __net_wifidirect_gerror_to_enum(error);
3685 if (ret == WIFI_DIRECT_ERROR_NONE) {
3686 g_variant_get(reply, "(i)", &ret);
3687 g_variant_unref(reply);
3690 WDC_LOGD("%s() return : [%d]", __func__, ret);
3691 __WDC_LOG_FUNC_END__;
3696 int wifi_direct_init_miracast(bool enable)
3698 __WDC_LOG_FUNC_START__;
3699 int ret = WIFI_DIRECT_ERROR_NONE;
3702 ret = wifi_direct_init_display();
3704 ret = wifi_direct_deinit_display();
3706 __WDC_LOG_FUNC_END__;
3710 int wifi_direct_get_peer_info(char* mac_address, wifi_direct_discovered_peer_info_s** peer_info)
3712 __WDC_LOG_FUNC_START__;
3714 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3716 GVariant *params = NULL;
3717 GError *error = NULL;
3718 GVariant *reply = NULL;
3719 GVariantIter *iter_peer = NULL;
3720 GVariant *var = NULL;
3722 int ret = WIFI_DIRECT_ERROR_NONE;
3724 if (g_client_info.is_registered == false) {
3725 WDC_LOGE("Client is NOT registered");
3726 __WDC_LOG_FUNC_END__;
3727 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3731 WDC_LOGE("mac_addr is NULL");
3732 __WDC_LOG_FUNC_END__;
3733 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3737 WDC_LOGE("peer_info is NULL");
3738 __WDC_LOG_FUNC_END__;
3739 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3742 params = g_variant_new("(s)", mac_address);
3743 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
3744 "GetPeerInfo", params, &error);
3746 ret = __net_wifidirect_gerror_to_enum(error);
3747 if (ret != WIFI_DIRECT_ERROR_NONE)
3750 g_variant_get(reply, "(ia{sv})", &ret, &iter_peer);
3751 if (ret != WIFI_DIRECT_ERROR_NONE) {
3752 __WDC_LOG_FUNC_END__;
3753 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3756 WDC_LOGD("wifi_direct_get_peer() SUCCESS");
3758 wifi_direct_discovered_peer_info_s *peer = NULL;
3760 peer = (wifi_direct_discovered_peer_info_s *) g_try_malloc0(sizeof(wifi_direct_discovered_peer_info_s));
3762 WDC_LOGE("Failed to allocate memory");
3763 __WDC_LOG_FUNC_END__;
3764 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3767 while (g_variant_iter_loop(iter_peer, "{sv}", &key, &var)) {
3768 if (!g_strcmp0(key, "DeviceName")) {
3769 const char *device_name = NULL;
3771 g_variant_get(var, "&s", &device_name);
3772 peer->device_name = g_strndup(device_name, WIFI_DIRECT_MAX_DEVICE_NAME_LEN+1);
3774 } else if (!g_strcmp0(key, "DeviceAddress")) {
3775 unsigned char l_mac_address[MACADDR_LEN] = {0, };
3777 wifi_direct_dbus_unpack_ay(l_mac_address, var, MACADDR_LEN);
3778 peer->mac_address = (char*) g_try_malloc0(MACSTR_LEN);
3779 if (peer->mac_address)
3780 g_snprintf(peer->mac_address, MACSTR_LEN, MACSTR, MAC2STR(l_mac_address));
3782 } else if (!g_strcmp0(key, "InterfaceAddress")) {
3783 unsigned char intf_address[MACADDR_LEN] = {0, };
3785 wifi_direct_dbus_unpack_ay(intf_address, var, MACADDR_LEN);
3786 peer->interface_address = (char*) g_try_malloc0(MACSTR_LEN);
3787 if (peer->interface_address)
3788 g_snprintf(peer->interface_address, MACSTR_LEN, MACSTR, MAC2STR(intf_address));
3790 } else if (!g_strcmp0(key, "Channel")) {
3791 peer->channel = g_variant_get_uint16(var);
3793 } else if (!g_strcmp0(key, "IsGroupOwner")) {
3794 peer->is_group_owner = g_variant_get_boolean(var);
3796 } else if (!g_strcmp0(key, "IsPersistentGO")) {
3797 peer->is_persistent_group_owner = g_variant_get_boolean(var);
3799 } else if (!g_strcmp0(key, "IsConnected")) {
3800 peer->is_connected = g_variant_get_boolean(var);
3802 } else if (!g_strcmp0(key, "Category")) {
3803 peer->primary_device_type = g_variant_get_uint16(var);
3805 } else if (!g_strcmp0(key, "SubCategory")) {
3806 peer->secondary_device_type = g_variant_get_uint16(var);
3808 } else if (!g_strcmp0(key, "IsWfdDevice")) {
3809 if (g_client_info.is_display_supported)
3810 peer->is_miracast_device = g_variant_get_boolean(var);
3818 g_variant_unref(reply);
3820 __WDC_LOG_FUNC_END__;
3821 return WIFI_DIRECT_ERROR_NONE;
3824 int wifi_direct_set_passphrase(const char *passphrase)
3826 __WDC_LOG_FUNC_START__;
3828 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3830 GError* error = NULL;
3831 GVariant *reply = NULL;
3832 GVariant *params = NULL;
3833 int ret = WIFI_DIRECT_ERROR_NONE;
3835 if (g_client_info.is_registered == false) {
3836 WDC_LOGE("Client is NOT registered.");
3837 __WDC_LOG_FUNC_END__;
3838 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3842 WDC_LOGE("NULL Param [passphrase]!");
3843 __WDC_LOG_FUNC_END__;
3844 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3846 WDC_LOGD("passphrase = [%s]", passphrase);
3848 params = g_variant_new("(s)", passphrase);
3849 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
3854 ret = __net_wifidirect_gerror_to_enum(error);
3855 if (ret == WIFI_DIRECT_ERROR_NONE) {
3856 g_variant_get(reply, "(i)", &ret);
3857 g_variant_unref(reply);
3860 WDC_LOGD("%s() SUCCESS", __func__);
3862 __WDC_LOG_FUNC_END__;
3863 return WIFI_DIRECT_ERROR_NONE;
3866 int wifi_direct_get_passphrase(char** passphrase)
3868 __WDC_LOG_FUNC_START__;
3870 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3872 GError* error = NULL;
3873 GVariant *reply = NULL;
3874 const char *val = NULL;
3875 int ret = WIFI_DIRECT_ERROR_NONE;
3877 if (g_client_info.is_registered == false) {
3878 WDC_LOGE("Client is NOT registered.");
3879 __WDC_LOG_FUNC_END__;
3880 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3884 WDC_LOGE("NULL Param [passphrase]!");
3885 __WDC_LOG_FUNC_END__;
3886 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3889 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
3894 ret = __net_wifidirect_gerror_to_enum(error);
3895 if (ret != WIFI_DIRECT_ERROR_NONE)
3898 WDC_LOGD("%s() SUCCESS", __func__);
3899 g_variant_get(reply, "(i&s)", &ret, &val);
3901 *passphrase = strdup(val);
3902 g_variant_unref(reply);
3904 WDC_LOGD("%s() return : [%d]", __func__, ret);
3905 __WDC_LOG_FUNC_END__;
3909 int wifi_direct_set_autoconnection_peer(char *mac_address)
3911 __WDC_LOG_FUNC_START__;
3913 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3915 GError* error = NULL;
3916 GVariant *reply = NULL;
3917 GVariant *params = NULL;
3918 int ret = WIFI_DIRECT_ERROR_NONE;
3920 if (g_client_info.is_registered == false) {
3921 WDC_LOGE("Client is NOT registered.");
3922 __WDC_LOG_FUNC_END__;
3923 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3927 WDC_LOGE("NULL Param!");
3928 __WDC_LOG_FUNC_END__;
3929 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3932 params = g_variant_new("(s)", mac_address);
3933 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
3934 "SetAutoConnectionPeer",
3938 ret = __net_wifidirect_gerror_to_enum(error);
3939 if (ret == WIFI_DIRECT_ERROR_NONE) {
3940 g_variant_get(reply, "(i)", &ret);
3941 g_variant_unref(reply);
3944 WDC_LOGD("%s() return : [%d]", __func__, ret);
3945 __WDC_LOG_FUNC_END__;
3949 int wifi_direct_init_display(void)
3951 __WDC_LOG_FUNC_START__;
3953 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
3955 GError* error = NULL;
3956 GVariant *reply = NULL;
3957 int ret = WIFI_DIRECT_ERROR_NONE;
3959 if (g_client_info.is_registered == false) {
3960 WDC_LOGE("Client is NOT registered.");
3961 __WDC_LOG_FUNC_END__;
3962 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3965 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
3970 ret = __net_wifidirect_gerror_to_enum(error);
3971 if (ret == WIFI_DIRECT_ERROR_NONE) {
3972 g_variant_get(reply, "(i)", &ret);
3973 g_variant_unref(reply);
3976 WDC_LOGD("%s() return : [%d]", __func__, ret);
3977 __WDC_LOG_FUNC_END__;
3982 int wifi_direct_deinit_display(void)
3984 __WDC_LOG_FUNC_START__;
3986 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
3988 GError* error = NULL;
3989 GVariant *reply = NULL;
3990 int ret = WIFI_DIRECT_ERROR_NONE;
3992 if (g_client_info.is_registered == false) {
3993 WDC_LOGE("Client is NOT registered");
3994 __WDC_LOG_FUNC_END__;
3995 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3998 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
4003 ret = __net_wifidirect_gerror_to_enum(error);
4004 if (ret == WIFI_DIRECT_ERROR_NONE) {
4005 g_variant_get(reply, "(i)", &ret);
4006 g_variant_unref(reply);
4009 WDC_LOGD("%s() return : [%d]", __func__, ret);
4010 __WDC_LOG_FUNC_END__;
4015 int wifi_direct_set_display(wifi_direct_display_type_e type, int port, int hdcp)
4017 __WDC_LOG_FUNC_START__;
4019 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
4021 GError* error = NULL;
4022 GVariant *reply = NULL;
4023 GVariant *params = NULL;
4024 int ret = WIFI_DIRECT_ERROR_NONE;
4026 if (g_client_info.is_registered == false) {
4027 WDC_LOGE("Client is NOT registered");
4028 __WDC_LOG_FUNC_END__;
4029 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4032 if (port < 0 || hdcp < 0) {
4033 WDC_LOGE("Invalid paramaeters passed type[%d], port[%d], hdcp[%d]!", type, port, hdcp);
4034 __WDC_LOG_FUNC_END__;
4035 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4038 params = g_variant_new("(iii)", type, port, hdcp);
4039 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
4044 ret = __net_wifidirect_gerror_to_enum(error);
4045 if (ret == WIFI_DIRECT_ERROR_NONE) {
4046 g_variant_get(reply, "(i)", &ret);
4047 g_variant_unref(reply);
4050 WDC_LOGD("%s() return : [%d]", __func__, ret);
4051 __WDC_LOG_FUNC_END__;
4056 int wifi_direct_set_display_availability(bool availability)
4058 __WDC_LOG_FUNC_START__;
4060 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
4062 GError* error = NULL;
4063 GVariant *reply = NULL;
4064 GVariant *params = NULL;
4065 int ret = WIFI_DIRECT_ERROR_NONE;
4067 if (g_client_info.is_registered == false) {
4068 WDC_LOGE("Client is NOT registered.");
4069 __WDC_LOG_FUNC_END__;
4070 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4074 params = g_variant_new("(i)", availability);
4075 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
4080 ret = __net_wifidirect_gerror_to_enum(error);
4081 if (ret == WIFI_DIRECT_ERROR_NONE) {
4082 g_variant_get(reply, "(i)", &ret);
4083 g_variant_unref(reply);
4086 WDC_LOGD("%s() return : [%d]", __func__, ret);
4087 __WDC_LOG_FUNC_END__;
4093 int wifi_direct_get_peer_display_type(char *mac_address, wifi_direct_display_type_e *type)
4095 __WDC_LOG_FUNC_START__;
4097 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
4099 GError* error = NULL;
4100 GVariant *reply = NULL;
4101 GVariant *params = NULL;
4103 int ret = WIFI_DIRECT_ERROR_NONE;
4105 if (g_client_info.is_registered == false) {
4106 WDC_LOGE("Client is NOT registered");
4107 __WDC_LOG_FUNC_END__;
4108 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4111 if (!mac_address || !type) {
4112 WDC_LOGE("NULL Param!");
4113 __WDC_LOG_FUNC_END__;
4114 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4117 params = g_variant_new("(s)", mac_address);
4118 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
4123 ret = __net_wifidirect_gerror_to_enum(error);
4124 if (ret != WIFI_DIRECT_ERROR_NONE)
4127 g_variant_get(reply, "(ii)", &ret, &val);
4129 g_variant_unref(reply);
4131 WDC_LOGD("%s() return : [%d]", __func__, ret);
4132 __WDC_LOG_FUNC_END__;
4137 int wifi_direct_get_peer_display_availability(char *mac_address, bool *availability)
4139 __WDC_LOG_FUNC_START__;
4141 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
4143 GError* error = NULL;
4144 GVariant *reply = NULL;
4145 GVariant *params = NULL;
4147 int ret = WIFI_DIRECT_ERROR_NONE;
4149 if (g_client_info.is_registered == false) {
4150 WDC_LOGE("Client is NOT registered");
4151 __WDC_LOG_FUNC_END__;
4152 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4155 if (!mac_address || !availability) {
4156 WDC_LOGE("NULL Param!");
4157 __WDC_LOG_FUNC_END__;
4158 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4161 params = g_variant_new("(s)", mac_address);
4162 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
4163 "GetPeerAvailability",
4167 ret = __net_wifidirect_gerror_to_enum(error);
4168 if (ret != WIFI_DIRECT_ERROR_NONE)
4171 g_variant_get(reply, "(ii)", &ret, &val);
4172 *availability = val;
4173 g_variant_unref(reply);
4175 WDC_LOGD("%s() return : [%d]", __func__, ret);
4176 __WDC_LOG_FUNC_END__;
4181 int wifi_direct_get_peer_display_hdcp(char *mac_address, int *hdcp)
4183 __WDC_LOG_FUNC_START__;
4185 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
4187 GError* error = NULL;
4188 GVariant *reply = NULL;
4189 GVariant *params = NULL;
4191 int ret = WIFI_DIRECT_ERROR_NONE;
4193 if (g_client_info.is_registered == false) {
4194 WDC_LOGE("Client is NOT registered");
4195 __WDC_LOG_FUNC_END__;
4196 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4199 if (!mac_address || !hdcp) {
4200 WDC_LOGE("NULL Param!");
4201 __WDC_LOG_FUNC_END__;
4202 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4205 params = g_variant_new("(s)", mac_address);
4206 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
4211 ret = __net_wifidirect_gerror_to_enum(error);
4212 if (ret != WIFI_DIRECT_ERROR_NONE)
4215 g_variant_get(reply, "(ii)", &ret, &val);
4217 g_variant_unref(reply);
4219 WDC_LOGD("%s() return : [%d]", __func__, ret);
4220 __WDC_LOG_FUNC_END__;
4225 int wifi_direct_get_peer_display_port(char *mac_address, int *port)
4227 __WDC_LOG_FUNC_START__;
4229 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
4231 GError* error = NULL;
4232 GVariant *reply = NULL;
4233 GVariant *params = NULL;
4235 int ret = WIFI_DIRECT_ERROR_NONE;
4237 if (g_client_info.is_registered == false) {
4238 WDC_LOGE("Client is NOT registered");
4239 __WDC_LOG_FUNC_END__;
4240 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4243 if (!mac_address || !port) {
4244 WDC_LOGE("NULL Param!");
4245 __WDC_LOG_FUNC_END__;
4246 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4249 params = g_variant_new("(s)", mac_address);
4250 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
4255 ret = __net_wifidirect_gerror_to_enum(error);
4256 if (ret != WIFI_DIRECT_ERROR_NONE)
4259 g_variant_get(reply, "(ii)", &ret, &val);
4261 g_variant_unref(reply);
4263 WDC_LOGD("%s() return : [%d]", __func__, ret);
4264 __WDC_LOG_FUNC_END__;
4269 int wifi_direct_get_peer_display_throughput(char *mac_address, int *throughput)
4271 __WDC_LOG_FUNC_START__;
4273 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
4275 GError* error = NULL;
4276 GVariant *reply = NULL;
4277 GVariant *params = NULL;
4279 int ret = WIFI_DIRECT_ERROR_NONE;
4281 if (g_client_info.is_registered == false) {
4282 WDC_LOGE("Client is NOT registered");
4283 __WDC_LOG_FUNC_END__;
4284 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4287 if (!mac_address || !throughput) {
4288 WDC_LOGE("NULL Param!");
4289 __WDC_LOG_FUNC_END__;
4290 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4293 params = g_variant_new("(s)", mac_address);
4294 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
4295 "GetPeerThroughput",
4299 ret = __net_wifidirect_gerror_to_enum(error);
4300 if (ret != WIFI_DIRECT_ERROR_NONE)
4303 g_variant_get(reply, "(ii)", &ret, &val);
4305 g_variant_unref(reply);
4307 WDC_LOGD("%s() return : [%d]", __func__, ret);
4308 __WDC_LOG_FUNC_END__;
4313 int wifi_direct_set_session_timer(int seconds)
4315 __WDC_LOG_FUNC_START__;
4317 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
4319 GError* error = NULL;
4320 GVariant *reply = NULL;
4321 GVariant *params = NULL;
4322 int ret = WIFI_DIRECT_ERROR_NONE;
4324 if (g_client_info.is_registered == false) {
4325 WDC_LOGE("Client is NOT registered.");
4326 __WDC_LOG_FUNC_END__;
4327 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4330 WDC_LOGE("Negative Timer Value");
4331 __WDC_LOG_FUNC_END__;
4332 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4335 WDC_LOGD("seconds = [%d]", seconds);
4337 params = g_variant_new("(i)", seconds);
4338 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
4343 ret = __net_wifidirect_gerror_to_enum(error);
4344 if (ret == WIFI_DIRECT_ERROR_NONE) {
4345 g_variant_get(reply, "(i)", &ret);
4346 g_variant_unref(reply);
4349 WDC_LOGD("%s() SUCCESS", __func__);
4351 __WDC_LOG_FUNC_END__;
4352 return WIFI_DIRECT_ERROR_NONE;
4356 int wifi_direct_get_session_timer(int *seconds)
4358 __WDC_LOG_FUNC_START__;
4360 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
4362 GError* error = NULL;
4363 GVariant *reply = NULL;
4365 int ret = WIFI_DIRECT_ERROR_NONE;
4367 if (g_client_info.is_registered == false) {
4368 WDC_LOGE("Client is NOT registered");
4369 __WDC_LOG_FUNC_END__;
4370 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4374 WDC_LOGE("Invalid Parameter");
4375 __WDC_LOG_FUNC_END__;
4376 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4379 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
4384 ret = __net_wifidirect_gerror_to_enum(error);
4385 if (ret != WIFI_DIRECT_ERROR_NONE)
4388 g_variant_get(reply, "(ii)", &ret, &val);
4390 g_variant_unref(reply);
4392 WDC_LOGD("Session Timer = [%d] Seconds", *seconds);
4393 WDC_LOGD("%s() return : [%d]", __func__, ret);
4395 __WDC_LOG_FUNC_END__;
4399 int wifi_direct_set_auto_group_removal(bool enable)
4401 __WDC_LOG_FUNC_START__;
4403 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
4405 GError* error = NULL;
4406 GVariant *reply = NULL;
4407 GVariant *params = NULL;
4408 int ret = WIFI_DIRECT_ERROR_NONE;
4410 if (g_client_info.is_registered == false) {
4411 WDC_LOGE("Client is NOT registered");
4412 __WDC_LOG_FUNC_END__;
4413 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4416 params = g_variant_new("(b)", enable);
4417 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
4418 "SetAutoGroupRemoval",
4422 ret = __net_wifidirect_gerror_to_enum(error);
4423 if (ret == WIFI_DIRECT_ERROR_NONE) {
4424 g_variant_get(reply, "(i)", &ret);
4425 g_variant_unref(reply);
4428 WDC_LOGD("%s() return : [%d]", __func__, ret);
4429 __WDC_LOG_FUNC_END__;
4433 int wifi_direct_get_peer_rssi(char *mac_address, int *rssi)
4435 __WDC_LOG_FUNC_START__;
4437 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
4439 GError* error = NULL;
4440 GVariant *reply = NULL;
4441 GVariant *params = NULL;
4443 int ret = WIFI_DIRECT_ERROR_NONE;
4445 if (g_client_info.is_registered == false) {
4446 WDC_LOGE("Client is NOT registered");
4447 __WDC_LOG_FUNC_END__;
4448 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4451 if (!mac_address || !rssi) {
4452 WDC_LOGE("NULL Param!");
4453 __WDC_LOG_FUNC_END__;
4454 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4457 params = g_variant_new("(s)", mac_address);
4459 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
4464 ret = __net_wifidirect_gerror_to_enum(error);
4466 if (ret != WIFI_DIRECT_ERROR_NONE)
4469 g_variant_get(reply, "(ii)", &ret, &val);
4471 g_variant_unref(reply);
4473 WDC_LOGD("%s() return : [%d]", __func__, ret);
4474 __WDC_LOG_FUNC_END__;
4478 int wifi_direct_add_vsie(wifi_direct_vsie_frames_e frame_id,
4479 const char *vsie_str)
4481 __WDC_LOG_FUNC_START__;
4483 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
4485 GError* error = NULL;
4486 GVariant *reply = NULL;
4487 GVariant *params = NULL;
4488 int ret = WIFI_DIRECT_ERROR_NONE;
4490 if (g_client_info.is_registered == false) {
4491 WDC_LOGE("Client is NOT registered.");
4492 __WDC_LOG_FUNC_END__;
4493 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4497 WDC_LOGE("NULL Param [vsie_str]!");
4498 __WDC_LOG_FUNC_END__;
4499 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4502 params = g_variant_new("(is)", frame_id, vsie_str);
4503 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
4504 "AddVsie", params, &error);
4506 ret = __net_wifidirect_gerror_to_enum(error);
4507 if (ret != WIFI_DIRECT_ERROR_NONE)
4510 g_variant_get(reply, "(i)", &ret);
4511 g_variant_unref(reply);
4513 WDC_LOGD("%s() return : [%d]", __func__, ret);
4514 __WDC_LOG_FUNC_END__;
4518 int wifi_direct_get_vsie(wifi_direct_vsie_frames_e frame_id, char **vsie_str)
4520 __WDC_LOG_FUNC_START__;
4522 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
4524 GError* error = NULL;
4525 GVariant *reply = NULL;
4526 GVariant *params = NULL;
4527 const char *val = NULL;
4528 int ret = WIFI_DIRECT_ERROR_NONE;
4530 if (g_client_info.is_registered == false) {
4531 WDC_LOGE("Client is NOT registered.");
4532 __WDC_LOG_FUNC_END__;
4533 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4537 WDC_LOGE("NULL Param [vsie_str]!");
4538 __WDC_LOG_FUNC_END__;
4539 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4542 params = g_variant_new("(i)", frame_id);
4543 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
4544 "GetVsie", params, &error);
4546 ret = __net_wifidirect_gerror_to_enum(error);
4547 if (ret != WIFI_DIRECT_ERROR_NONE)
4550 g_variant_get(reply, "(i&s)", &ret, &val);
4552 *vsie_str = strdup(val);
4553 g_variant_unref(reply);
4555 WDC_LOGD("%s() return : [%d] vsie [%s]", __func__, ret, *vsie_str);
4556 __WDC_LOG_FUNC_END__;
4560 int wifi_direct_remove_vsie(wifi_direct_vsie_frames_e frame_id,
4561 const char *vsie_str)
4563 __WDC_LOG_FUNC_START__;
4565 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
4567 GError* error = NULL;
4568 GVariant *reply = NULL;
4569 GVariant *params = NULL;
4570 int ret = WIFI_DIRECT_ERROR_NONE;
4572 if (g_client_info.is_registered == false) {
4573 WDC_LOGE("Client is NOT registered.");
4574 __WDC_LOG_FUNC_END__;
4575 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4579 WDC_LOGE("NULL Param [vsie_str]!");
4580 __WDC_LOG_FUNC_END__;
4581 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4584 params = g_variant_new("(is)", frame_id, vsie_str);
4585 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
4586 "RemoveVsie", params, &error);
4588 ret = __net_wifidirect_gerror_to_enum(error);
4589 if (ret != WIFI_DIRECT_ERROR_NONE)
4592 g_variant_get(reply, "(i)", &ret);
4593 g_variant_unref(reply);
4595 WDC_LOGD("%s() return : [%d]", __func__, ret);
4596 __WDC_LOG_FUNC_END__;
4600 int wifi_direct_get_connecting_peer_info(
4601 wifi_direct_discovered_peer_info_s **peer_info)
4603 __WDC_LOG_FUNC_START__;
4605 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
4607 GError *error = NULL;
4608 GVariant *reply = NULL;
4609 GVariantIter *iter_peer = NULL;
4610 wifi_direct_discovered_peer_info_s *peer = NULL;
4611 int ret = WIFI_DIRECT_ERROR_NONE;
4613 if (g_client_info.is_registered == false) {
4614 WDC_LOGE("Client is NOT registered");
4615 __WDC_LOG_FUNC_END__;
4616 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4620 WDC_LOGE("peer_info is NULL");
4621 __WDC_LOG_FUNC_END__;
4622 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4625 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
4626 "GetConnectingPeer", NULL,
4629 ret = __net_wifidirect_gerror_to_enum(error);
4630 if (ret != WIFI_DIRECT_ERROR_NONE) {
4631 __WDC_LOG_FUNC_END__;
4635 g_variant_get(reply, "(ia{sv})", &ret, &iter_peer);
4636 if (ret != WIFI_DIRECT_ERROR_NONE) {
4637 __WDC_LOG_FUNC_END__;
4638 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
4641 WDC_LOGD("wifi_direct_get_peer() SUCCESS");
4643 peer = (wifi_direct_discovered_peer_info_s *)
4644 g_try_malloc0(sizeof(wifi_direct_discovered_peer_info_s));
4646 WDC_LOGE("Failed to allocate memory");
4647 __WDC_LOG_FUNC_END__;
4648 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
4651 __wfd_client_extract_discovered_peer_info(iter_peer, peer);
4652 /* __wfd_client_print_entry_list(peer, 1); */
4656 g_variant_unref(reply);
4658 WDC_LOGD("%s() return : [%d]", __func__, ret);
4659 __WDC_LOG_FUNC_END__;
4663 int wifi_direct_get_peer_vsie(char *mac_address, char **vsie)
4665 __WDC_LOG_FUNC_START__;
4667 CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
4669 GError* error = NULL;
4670 GVariant *reply = NULL;
4671 GVariant *params = NULL;
4672 const gchar *val = 0;
4673 int ret = WIFI_DIRECT_ERROR_NONE;
4675 if (g_client_info.is_registered == false) {
4676 WDC_LOGE("Client is NOT registered");
4677 __WDC_LOG_FUNC_END__;
4678 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4681 if (!mac_address || !vsie) {
4682 WDC_LOGE("NULL Param!");
4683 __WDC_LOG_FUNC_END__;
4684 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4687 params = g_variant_new("(s)", mac_address);
4689 reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
4694 ret = __net_wifidirect_gerror_to_enum(error);
4696 if (ret != WIFI_DIRECT_ERROR_NONE)
4699 g_variant_get(reply, "(i&s)", &ret, &val);
4700 *vsie = strdup(val);
4701 g_variant_unref(reply);
4703 WDC_LOGD("%s() return : [%d]", __func__, ret);
4704 __WDC_LOG_FUNC_END__;