4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://floralicense.org/license
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
24 #include <Elementary.h>
27 //#include <vconf-keys.h>
28 #include <tethering.h>
29 #include <network-cm-intf.h>
30 #include <network-wifi-intf.h>
33 #include "wfd_ug_view.h"
34 #include "wfd_client.h"
37 * This function let the ug make a change callback for wifi state
39 * @param[in] key the pointer to the key
40 * @param[in] data the pointer to the main data structure
42 static void _wifi_state_cb(keynode_t *key, void *data)
44 __WDUG_LOG_FUNC_ENTER__;
45 struct ug_data *ugd = (struct ug_data *)data;
49 res = vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
51 WDUG_LOGE("Failed to get wifi state from vconf. [%d]\n", res);
55 if (wifi_state == VCONFKEY_WIFI_OFF) {
56 WDUG_LOGI("WiFi is turned off\n");
57 wfd_client_swtch_force(ugd, TRUE);
59 WDUG_LOGI("WiFi is turned on\n");
62 res = net_deregister_client();
63 if (res != NET_ERR_NONE) {
64 WDUG_LOGE("Failed to deregister network client. [%d]\n", res);
67 __WDUG_LOG_FUNC_EXIT__;
71 * This function let the ug make a event callback for network registering
73 * @param[in] event_info the pointer to the information of network event
74 * @param[in] user_data the pointer to the user data
76 static void _network_event_cb(net_event_info_t *event_info, void *user_data)
78 __WDUG_LOG_FUNC_ENTER__;
79 WDUG_LOGI("Event from network. [%d]\n", event_info->Event);
80 __WDUG_LOG_FUNC_EXIT__;
84 * This function let the ug turn wifi off
85 * @return If success, return 0, else return -1
86 * @param[in] data the pointer to the main data structure
88 int wfd_wifi_off(void *data)
90 __WDUG_LOG_FUNC_ENTER__;
91 struct ug_data *ugd = (struct ug_data *)data;
94 res = vconf_notify_key_changed(VCONFKEY_WIFI_STATE, _wifi_state_cb, ugd);
96 WDUG_LOGE("Failed to register vconf callback\n");
100 WDUG_LOGI("Vconf key callback is registered\n");
102 res = net_register_client((net_event_cb_t) _network_event_cb, NULL);
103 if (res != NET_ERR_NONE) {
104 WDUG_LOGE("Failed to register network client. [%d]\n", res);
108 WDUG_LOGI("Network client is registered\n");
110 res = net_wifi_power_off();
111 if (res != NET_ERR_NONE) {
112 WDUG_LOGE("Failed to turn off wifi. [%d]\n", res);
116 WDUG_LOGI("WiFi power off\n");
118 __WDUG_LOG_FUNC_EXIT__;
123 * This function let the ug make a change callback for enabling hotspot state
125 * @param[in] key the pointer to the key
126 * @param[in] data the pointer to the main data structure
128 static void _enable_hotspot_state_cb(keynode_t *key, void *data)
130 __WDUG_LOG_FUNC_ENTER__;
131 struct ug_data *ugd = (struct ug_data *)data;
134 tethering_error_e ret = TETHERING_ERROR_NONE;
135 tethering_h th = NULL;
137 res = vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &hotspot_mode);
139 WDUG_LOGE("Failed to get mobile hotspot state from vconf. [%d]\n", res);
143 if (hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI) {
144 WDUG_LOGI(" Mobile hotspot is activated\n");
147 th = ugd->hotspot_handle;
151 ret = tethering_unset_enabled_cb(th, TETHERING_TYPE_WIFI);
152 if (ret != TETHERING_ERROR_NONE) {
153 WDUG_LOGE("tethering_unset_enabled_cb is failed(%d)\n", ret);
156 /* Destroy tethering handle */
157 ret = tethering_destroy(th);
158 if (ret != TETHERING_ERROR_NONE) {
159 WDUG_LOGE("tethering_destroy is failed(%d)\n", ret);
162 ugd->hotspot_handle = NULL;
165 __WDUG_LOG_FUNC_EXIT__;
169 * This function let the ug make a change callback for disabling hotspot state
171 * @param[in] key the pointer to the key
172 * @param[in] data the pointer to the main data structure
174 static void _disable_hotspot_state_cb(keynode_t *key, void *data)
176 __WDUG_LOG_FUNC_ENTER__;
177 struct ug_data *ugd = (struct ug_data *)data;
180 tethering_error_e ret = TETHERING_ERROR_NONE;
181 tethering_h th = NULL;
183 res = vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &hotspot_mode);
185 WDUG_LOGE("Failed to get mobile hotspot state from vconf. [%d]\n", res);
189 if (!(hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI)) {
190 WDUG_LOGI(" Mobile hotspot is deactivated\n");
191 wfd_client_swtch_force(ugd, TRUE);
194 th = ugd->hotspot_handle;
198 ret = tethering_unset_disabled_cb(th, TETHERING_TYPE_WIFI);
199 if (ret != TETHERING_ERROR_NONE) {
200 WDUG_LOGE("tethering_unset_disabled_cb is failed(%d)\n", ret);
203 /* Destroy tethering handle */
204 ret = tethering_destroy(th);
205 if (ret != TETHERING_ERROR_NONE) {
206 WDUG_LOGE("tethering_destroy is failed(%d)\n", ret);
209 ugd->hotspot_handle = NULL;
212 __WDUG_LOG_FUNC_EXIT__;
216 * This function let the ug make a callback for setting tethering mode enabled
218 * @param[in] error the returned error code
219 * @param[in] type the type of tethering
220 * @param[in] is_requested whether tethering mode is enabled
221 * @param[in] data the pointer to the user data
223 static void __enabled_cb(tethering_error_e error, tethering_type_e type, bool is_requested, void *data)
225 __WDUG_LOG_FUNC_ENTER__;
227 if (error != TETHERING_ERROR_NONE) {
228 if (is_requested != TRUE) {
232 WDUG_LOGE("error !!! TETHERING is not enabled.\n");
236 WDUG_LOGI("TETHERING is enabled.\n");
238 __WDUG_LOG_FUNC_EXIT__;
243 * This function let the ug make a callback for setting tethering mode disabled
245 * @param[in] error the returned error code
246 * @param[in] type the type of tethering
247 * @param[in] code whether tethering mode is enabled
248 * @param[in] data the pointer to the user data
250 static void __disabled_cb(tethering_error_e error, tethering_type_e type, tethering_disabled_cause_e code, void *data)
252 __WDUG_LOG_FUNC_ENTER__;
254 if (error != TETHERING_ERROR_NONE) {
255 if (code != TETHERING_DISABLED_BY_REQUEST) {
259 WDUG_LOGE("error !!! TETHERING is not disabled.\n");
263 WDUG_LOGI("TETHERING is disabled.\n");
265 __WDUG_LOG_FUNC_EXIT__;
270 * This function let the ug turn AP on
271 * @return If success, return 0, else return -1
272 * @param[in] data the pointer to the main data structure
274 int wfd_mobile_ap_on(void *data)
276 __WDUG_LOG_FUNC_ENTER__;
277 struct ug_data *ugd = (struct ug_data *)data;
279 tethering_error_e ret = TETHERING_ERROR_NONE;
280 tethering_h th = NULL;
282 res = vconf_notify_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE, _enable_hotspot_state_cb, ugd);
284 WDUG_LOGE("Failed to register vconf callback\n");
288 /* Create tethering handle */
289 ret = tethering_create(&th);
290 if (ret != TETHERING_ERROR_NONE) {
291 WDUG_LOGE("Failed to tethering_create() [%d]\n", ret);
294 WDUG_LOGI("Succeeded to tethering_create()\n");
298 ret = tethering_set_enabled_cb(th, TETHERING_TYPE_WIFI, __enabled_cb, NULL);
299 if (ret != TETHERING_ERROR_NONE) {
300 WDUG_LOGE("tethering_set_enabled_cb is failed\n", ret);
304 /* Enable tethering */
305 ret = tethering_enable(th, TETHERING_TYPE_WIFI);
306 if (ret != TETHERING_ERROR_NONE) {
307 WDUG_LOGE("Failed to turn on mobile hotspot. [%d]\n", ret);
310 WDUG_LOGI("Succeeded to turn on mobile hotspot\n");
313 ugd->hotspot_handle = th;
314 ugd->is_hotspot_off = FALSE;
316 __WDUG_LOG_FUNC_EXIT__;
321 * This function let the ug turn AP off
322 * @return If success, return 0, else return -1
323 * @param[in] data the pointer to the main data structure
325 int wfd_mobile_ap_off(void *data)
327 __WDUG_LOG_FUNC_ENTER__;
328 struct ug_data *ugd = (struct ug_data *)data;
330 tethering_error_e ret = TETHERING_ERROR_NONE;
331 tethering_h th = NULL;
333 res = vconf_notify_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE, _disable_hotspot_state_cb, ugd);
335 WDUG_LOGE("Failed to register vconf callback\n");
339 /* Create tethering handle */
340 ret = tethering_create(&th);
341 if (ret != TETHERING_ERROR_NONE) {
342 WDUG_LOGE("Failed to tethering_create() [%d]\n", ret);
345 WDUG_LOGI("Succeeded to tethering_create()\n");
349 ret = tethering_set_disabled_cb(th, TETHERING_TYPE_WIFI, __disabled_cb, NULL);
350 if (ret != TETHERING_ERROR_NONE) {
351 WDUG_LOGE("tethering_set_disabled_cb is failed\n", ret);
355 /* Disable tethering */
356 ret = tethering_disable(th, TETHERING_TYPE_WIFI);
357 if (ret != TETHERING_ERROR_NONE) {
358 WDUG_LOGE("Failed to turn off mobile hotspot. [%d]\n", ret);
361 WDUG_LOGI("Succeeded to turn off mobile hotspot\n");
364 ugd->hotspot_handle = th;
365 ugd->is_hotspot_off = TRUE;
367 __WDUG_LOG_FUNC_EXIT__;
372 * This function let the ug find the peer by mac address
373 * @return the found peer
374 * @param[in] data the pointer to the main data structure
375 * @param[in] mac_addr the pointer to mac address
377 static device_type_s *wfd_client_find_peer_by_mac(void *data, const char *mac_addr)
379 __WDUG_LOG_FUNC_ENTER__;
380 struct ug_data *ugd = (struct ug_data *)data;
384 WDUG_LOGE("Incorrect parameter(NULL)\n");
388 if (ugd->multi_connect_mode != WFD_MULTI_CONNECT_MODE_NONE) {
389 for (i = 0; i < ugd->raw_multi_selected_peer_cnt; i++) {
390 WDUG_LOGI("[Multi Connect] check %dth peer\n", i);
391 if (!strncmp(mac_addr, (const char *)ugd->raw_multi_selected_peers[i].mac_addr, MAC_LENGTH)) {
392 WDUG_LOGI("selected found peer. [%d]\n", i);
393 __WDUG_LOG_FUNC_EXIT__;
394 return &ugd->raw_multi_selected_peers[i];
398 for (i = 0; i < ugd->raw_discovered_peer_cnt; i++) {
399 WDUG_LOGI("check %dth peer\n", i);
400 if (!strncmp(mac_addr, (const char *)ugd->raw_discovered_peers[i].mac_addr, MAC_LENGTH)) {
401 WDUG_LOGI("found peer. [%d]\n", i);
402 __WDUG_LOG_FUNC_EXIT__;
403 return &ugd->raw_discovered_peers[i];
408 __WDUG_LOG_FUNC_EXIT__;
413 * This function let the ug make a callback for registering activation event
415 * @param[in] error_code the returned error code
416 * @param[in] device_state the state of device
417 * @param[in] user_data the pointer to the main data structure
419 void _activation_cb(int error_code, wifi_direct_device_state_e device_state, void *user_data)
421 __WDUG_LOG_FUNC_ENTER__;
423 struct ug_data *ugd = (struct ug_data *)user_data;
425 wfd_refresh_wifi_direct_state(ugd);
427 switch (device_state) {
428 case WIFI_DIRECT_DEVICE_STATE_ACTIVATED:
429 WDUG_LOGI("WIFI_DIRECT_DEVICE_STATE_ACTIVATED\n");
430 if (error_code != WIFI_DIRECT_ERROR_NONE) {
431 WDUG_LOGE("Error in Activation/Deactivation [%d]\n", error_code);
432 wfd_ug_warn_popup(ugd, _("IDS_WFD_POP_ACTIVATE_FAIL"), POPUP_TYPE_ACTIVATE_FAIL);
434 ugd->head_text_mode = HEAD_TEXT_TYPE_DIRECT;
436 wfd_ug_view_refresh_glitem(ugd->head);
440 ugd->head_text_mode = HEAD_TEXT_TYPE_ACTIVATED;
442 wfd_ug_view_refresh_glitem(ugd->head);
444 wfg_ug_act_popup_remove(ugd);
446 res = vconf_ignore_key_changed(VCONFKEY_WIFI_STATE, _wifi_state_cb);
448 WDUG_LOGE("Failed to ignore vconf key callback for wifi state\n");
451 res = vconf_ignore_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE, _disable_hotspot_state_cb);
453 WDUG_LOGE("Failed to ignore vconf key callback for hotspot state\n");
456 res = wifi_direct_start_discovery(FALSE, MAX_SCAN_TIME_OUT);
457 if (res != WIFI_DIRECT_ERROR_NONE) {
458 WDUG_LOGE("Failed to start discovery. [%d]\n", res);
459 ugd->is_re_discover = TRUE;
460 wifi_direct_cancel_discovery();
462 WDUG_LOGI("Discovery is started\n");
463 ugd->is_re_discover = FALSE;
467 case WIFI_DIRECT_DEVICE_STATE_DEACTIVATED:
468 WDUG_LOGI("WIFI_DIRECT_DEVICE_STATE_DEACTIVATED\n");
469 if (error_code != WIFI_DIRECT_ERROR_NONE) {
470 WDUG_LOGE("Error in Activation/Deactivation [%d]\n", error_code);
471 wfd_ug_warn_popup(ugd, _("IDS_WFD_POP_DEACTIVATE_FAIL"), POPUP_TYPE_DEACTIVATE_FAIL);
472 ugd->head_text_mode = HEAD_TEXT_TYPE_DIRECT;
474 wfd_ug_view_refresh_glitem(ugd->head);
478 ugd->head_text_mode = HEAD_TEXT_TYPE_DIRECT;
482 * when deactivated, clear all the
483 * discovered peers and connected peers
485 if (ugd->raw_discovered_peer_cnt > 0) {
486 memset(ugd->raw_discovered_peers, 0x00, ugd->raw_discovered_peer_cnt*sizeof(device_type_s));
489 if (ugd->raw_connected_peer_cnt > 0) {
490 memset(ugd->raw_connected_peers, 0x00, ugd->raw_connected_peer_cnt*sizeof(device_type_s));
493 ugd->raw_discovered_peer_cnt = 0;
494 ugd->raw_connected_peer_cnt = 0;
496 wfd_ug_view_update_peers(ugd);
498 /* remove the callback for hotspot */
499 res = vconf_ignore_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE, _enable_hotspot_state_cb);
501 WDUG_LOGE("Failed to ignore vconf key callback for hotspot state\n");
504 /* when deactivated, stop the timer */
505 if (ugd->monitor_timer) {
506 ecore_timer_del(ugd->monitor_timer);
507 ugd->monitor_timer = NULL;
514 wfd_ug_view_refresh_glitem(ugd->head);
517 wfd_ug_view_refresh_button(ugd->scan_btn, _("IDS_WFD_BUTTON_SCAN"), TRUE);
520 if (ugd->multi_connect_btn) {
521 wfd_ug_view_refresh_button(ugd->multi_scan_btn, _("IDS_WFD_BUTTON_SCAN"), TRUE);
525 elm_object_disabled_set(ugd->back_btn, FALSE);
528 __WDUG_LOG_FUNC_EXIT__;
533 * This function let the ug make a callback for discovering peer
535 * @param[in] peer the pointer to the discovered peer
536 * @param[in] user_data the pointer to the main data structure
538 bool _wfd_discoverd_peer_cb(wifi_direct_discovered_peer_info_s *peer, void *user_data)
540 __WDUG_LOG_FUNC_ENTER__;
541 if (NULL == peer || NULL == user_data) {
542 WDUG_LOGE("Incorrect parameter(NULL)\n");
543 __WDUG_LOG_FUNC_EXIT__;
547 struct ug_data *ugd = (struct ug_data *)user_data;
548 int peer_cnt = ugd->raw_discovered_peer_cnt;
550 WDUG_LOGI("%dth discovered peer. [%s] [%s]\n", peer_cnt, peer->device_name, peer->mac_address);
552 strncpy(ugd->raw_discovered_peers[peer_cnt].ssid, peer->device_name, sizeof(ugd->raw_discovered_peers[peer_cnt].ssid));
553 ugd->raw_discovered_peers[peer_cnt].category = peer->primary_device_type;
554 strncpy(ugd->raw_discovered_peers[peer_cnt].mac_addr, peer->mac_address, MAC_LENGTH);
555 strncpy(ugd->raw_discovered_peers[peer_cnt].if_addr, peer->interface_address, MAC_LENGTH);
556 ugd->raw_discovered_peers[peer_cnt].is_group_owner = peer->is_group_owner;
557 ugd->raw_discovered_peers[peer_cnt].is_persistent_group_owner = peer->is_persistent_group_owner;
558 ugd->raw_discovered_peers[peer_cnt].is_connected = peer->is_connected;
560 if (TRUE == peer->is_connected) {
561 ugd->raw_discovered_peers[peer_cnt].conn_status = PEER_CONN_STATUS_CONNECTED;
563 ugd->raw_discovered_peers[peer_cnt].conn_status = PEER_CONN_STATUS_DISCONNECTED;
566 WDUG_LOGI("\tSSID: [%s]\n", ugd->raw_discovered_peers[peer_cnt].ssid);
567 WDUG_LOGI("\tPeer category [%d] -> [%d]\n", peer->primary_device_type, ugd->raw_discovered_peers[peer_cnt].category);
568 WDUG_LOGI("\tStatus: [%d]\n", ugd->raw_discovered_peers[peer_cnt].conn_status);
570 ugd->raw_discovered_peer_cnt++;
572 free(peer->device_name);
573 free(peer->mac_address);
574 free(peer->interface_address);
577 __WDUG_LOG_FUNC_EXIT__;
582 * This function let the ug make a callback for connected peer
584 * @param[in] peer the pointer to the connected peer
585 * @param[in] user_data the pointer to the main data structure
587 bool _wfd_connected_peer_cb(wifi_direct_connected_peer_info_s *peer, void *user_data)
589 __WDUG_LOG_FUNC_ENTER__;
590 if (NULL == peer || NULL == user_data) {
591 WDUG_LOGE("Incorrect parameter(NULL)\n");
592 __WDUG_LOG_FUNC_EXIT__;
596 struct ug_data *ugd = (struct ug_data *)user_data;
597 int peer_cnt = ugd->raw_connected_peer_cnt;
599 WDUG_LOGI("%dth connected peer. [%s] [%s]\n", peer_cnt, peer->device_name, peer->mac_address);
601 strncpy(ugd->raw_connected_peers[peer_cnt].ssid, peer->device_name, sizeof(ugd->raw_connected_peers[peer_cnt].ssid));
602 ugd->raw_connected_peers[peer_cnt].category = peer->primary_device_type;
603 strncpy(ugd->raw_connected_peers[peer_cnt].mac_addr, peer->mac_address, MAC_LENGTH);
604 strncpy(ugd->raw_connected_peers[peer_cnt].if_addr, peer->interface_address, MAC_LENGTH);
605 ugd->raw_connected_peers[peer_cnt].conn_status = PEER_CONN_STATUS_CONNECTED;
607 WDUG_LOGI("\tStatus: [%d]\n", ugd->raw_connected_peers[peer_cnt].conn_status);
608 WDUG_LOGI("\tCategory: [%d]\n", ugd->raw_connected_peers[peer_cnt].category);
609 WDUG_LOGI("\tSSID: [%s]\n", ugd->raw_connected_peers[peer_cnt].ssid);
610 WDUG_LOGI("\tMAC addr: [" MACSTR "]\n", ugd->raw_connected_peers[peer_cnt].mac_addr);
611 WDUG_LOGI("\tIface addr: [" MACSTR "]\n", ugd->raw_connected_peers[peer_cnt].if_addr);
613 ugd->raw_connected_peer_cnt++;
615 free(peer->device_name);
616 free(peer->mac_address);
617 free(peer->interface_address);
620 __WDUG_LOG_FUNC_EXIT__;
625 * This function let the ug get the found peers
626 * @return If success, return 0, else return -1
627 * @param[in] ugd the pointer to the main data structure
629 int wfd_ug_get_discovered_peers(struct ug_data *ugd)
631 __WDUG_LOG_FUNC_ENTER__;
638 ugd->raw_discovered_peer_cnt = 0;
639 res = wifi_direct_foreach_discovered_peers(_wfd_discoverd_peer_cb, (void *)ugd);
640 if (res != WIFI_DIRECT_ERROR_NONE) {
641 ugd->raw_discovered_peer_cnt = 0;
642 WDUG_LOGE("Get discovery result failed: %d\n", res);
645 __WDUG_LOG_FUNC_EXIT__;
650 * This function let the ug get the connected peers
651 * @return If success, return 0, else return -1
652 * @param[in] ugd the pointer to the main data structure
654 int wfd_ug_get_connected_peers(struct ug_data *ugd)
656 __WDUG_LOG_FUNC_ENTER__;
663 ugd->raw_connected_peer_cnt = 0;
664 res = wifi_direct_foreach_connected_peers(_wfd_connected_peer_cb, (void *)ugd);
665 if (res != WIFI_DIRECT_ERROR_NONE) {
666 ugd->raw_connected_peer_cnt = 0;
667 WDUG_LOGE("Get connected peer failed: %d\n", res);
670 __WDUG_LOG_FUNC_EXIT__;
675 * This function let the ug make a callback for deactivating wfd automatically
676 * @return if stop the timer, return ECORE_CALLBACK_CANCEL, else return ECORE_CALLBACK_RENEW
677 * @param[in] user_data the pointer to the main data structure
679 static Eina_Bool _wfd_automatic_deactivated_for_no_connection_cb(void *user_data)
683 struct ug_data *ugd = (struct ug_data *)user_data;
686 WDUG_LOGE("NULL parameters.\n");
687 return ECORE_CALLBACK_CANCEL;
690 /* check the action, if action is exist, keep the cb */
691 res = wifi_direct_get_state(&ugd->wfd_status);
692 if (res != WIFI_DIRECT_ERROR_NONE) {
693 WDUG_LOGE("Failed to get link status. [%d]\n", res);
694 return ECORE_CALLBACK_CANCEL;
697 if (ugd->last_wfd_status != ugd->wfd_status) {
698 WDUG_LOGE("Action is exist, last status: %d\n",
699 ugd->last_wfd_status);
700 ugd->last_wfd_status = ugd->wfd_status;
701 ugd->last_wfd_time = time(NULL);
702 return ECORE_CALLBACK_RENEW;
705 /* check the timeout, if not timeout, keep the cb */
706 interval = time(NULL) - ugd->last_wfd_time;
707 if (interval < MAX_NO_ACTION_TIME_OUT) {
708 return ECORE_CALLBACK_RENEW;
711 /* turn off the Wi-Fi Direct */
712 wifi_direct_get_state(&ugd->wfd_status);
713 if (ugd->wfd_status < WIFI_DIRECT_STATE_ACTIVATING) {
714 WDUG_LOGE("Wi-Fi Direct is already deactivated\n");
716 wfd_ug_warn_popup(ugd, IDS_WFD_POP_AUTOMATIC_TURN_OFF, POP_TYPE_AUTOMATIC_TURN_OFF);
719 return ECORE_CALLBACK_CANCEL;
723 * This function let the ug make a callback for registering discover event
725 * @param[in] error_code the returned error code
726 * @param[in] discovery_state the state of discover
727 * @param[in] user_data the pointer to the main data structure
729 void _discover_cb(int error_code, wifi_direct_discovery_state_e discovery_state, void *user_data)
731 __WDUG_LOG_FUNC_ENTER__;
732 struct ug_data *ugd = (struct ug_data *)user_data;
735 WDUG_LOGE("Incorrect parameter(NULL)\n");
739 WDUG_LOGI("Discovery event [%d], error_code [%d]\n", discovery_state, error_code);
741 if (discovery_state == WIFI_DIRECT_ONLY_LISTEN_STARTED) {
742 __WDUG_LOG_FUNC_EXIT__;
744 } else if (discovery_state == WIFI_DIRECT_DISCOVERY_STARTED) {
745 ugd->head_text_mode = HEAD_TEXT_TYPE_SCANING;
747 /* clear all the previous discovered peers */
748 if (ugd->raw_discovered_peer_cnt > 0) {
749 memset(ugd->raw_discovered_peers, 0x00, ugd->raw_discovered_peer_cnt*sizeof(device_type_s));
752 ugd->raw_discovered_peer_cnt = 0;
753 } else if (discovery_state == WIFI_DIRECT_DISCOVERY_FOUND) {
754 ugd->head_text_mode = HEAD_TEXT_TYPE_DIRECT;
755 wfd_ug_get_discovered_peers(ugd);
757 ugd->head_text_mode = HEAD_TEXT_TYPE_DIRECT;
759 if (TRUE == ugd->is_re_discover) {
760 ugd->is_re_discover = FALSE;
761 wifi_direct_start_discovery(FALSE, MAX_SCAN_TIME_OUT);
763 /* start LISTEN ONLY mode */
764 wifi_direct_start_discovery(TRUE, 0);
768 wfd_ug_view_refresh_glitem(ugd->head);
769 wfd_ug_view_update_peers(ugd);
770 wfd_update_multiconnect_device(ugd);
772 if (WIFI_DIRECT_DISCOVERY_STARTED == discovery_state) {
774 wfd_ug_view_refresh_button(ugd->scan_btn, _("IDS_WFD_BUTTON_STOPSCAN"), TRUE);
777 if (ugd->multi_connect_btn) {
778 wfd_ug_view_refresh_button(ugd->multi_scan_btn, _("IDS_WFD_BUTTON_STOPSCAN"), TRUE);
782 wfd_ug_view_refresh_button(ugd->scan_btn, _("IDS_WFD_BUTTON_SCAN"), TRUE);
785 if (ugd->multi_connect_btn) {
786 wfd_ug_view_refresh_button(ugd->multi_scan_btn, _("IDS_WFD_BUTTON_SCAN"), TRUE);
790 __WDUG_LOG_FUNC_EXIT__;
795 * This function let the ug make a callback for registering connection event
797 * @param[in] error_code the returned error code
798 * @param[in] connection_state the state of connection
799 * @param[in] mac_address the mac address of peer
800 * @param[in] user_data the pointer to the main data structure
802 void _connection_cb(int error_code, wifi_direct_connection_state_e connection_state, const char *mac_address, void *user_data)
804 __WDUG_LOG_FUNC_ENTER__;
805 struct ug_data *ugd = (struct ug_data *)user_data;
806 device_type_s *peer = NULL;
810 WDUG_LOGI("Connection event [%d], error_code [%d], multi_connect_mode [%d]\n",
811 connection_state, error_code, ugd->multi_connect_mode);
813 if (mac_address == NULL) {
814 WDUG_LOGE("Incorrect parameter(peer mac is NULL)\n");
818 /* when not in connection, mac_address is empty */
819 if (connection_state <= WIFI_DIRECT_DISASSOCIATION_IND) {
820 peer = wfd_client_find_peer_by_mac(ugd, mac_address);
822 if (NULL == peer || '\0' == peer->ssid[0]) {
823 WDUG_LOGE("invalid peer from connection !!\n");
828 if (ugd->multi_connect_mode == WFD_MULTI_CONNECT_MODE_IN_PROGRESS) {
829 switch (connection_state) {
830 case WIFI_DIRECT_CONNECTION_RSP:
831 WDUG_LOGI("MULTI: WIFI_DIRECT_CONNECTION_RSP\n");
833 if (error_code == WIFI_DIRECT_ERROR_NONE) {
834 peer->conn_status = PEER_CONN_STATUS_CONNECTED;
835 wfd_ug_get_connected_peers(ugd);
837 peer->conn_status = PEER_CONN_STATUS_FAILED_TO_CONNECT;
840 wfd_ug_view_update_peers(ugd);
842 /* connect the next peer */
843 ugd->g_source_multi_connect_next = g_timeout_add(1000, wfd_multi_connect_next_cb, ugd);
845 case WIFI_DIRECT_CONNECTION_IN_PROGRESS:
846 WDUG_LOGI("MULTI: WIFI_DIRECT_CONNECTION_IN_PROGRESS\n");
847 peer->conn_status = PEER_CONN_STATUS_CONNECTING;
848 wfd_ug_view_update_peers(ugd);
850 case WIFI_DIRECT_GROUP_CREATED:
851 WDUG_LOGI("MULTI: WIFI_DIRECT_GROUP_CREATED\n");
852 wfd_multi_connect_next_cb(ugd);
858 switch (connection_state) {
859 case WIFI_DIRECT_CONNECTION_RSP:
860 WDUG_LOGI("WIFI_DIRECT_CONNECTION_RSP\n");
862 if (error_code == WIFI_DIRECT_ERROR_NONE) {
863 peer->conn_status = PEER_CONN_STATUS_CONNECTED;
864 wfd_ug_get_connected_peers(ugd);
866 peer->conn_status = PEER_CONN_STATUS_FAILED_TO_CONNECT;
869 wfd_ug_view_update_peers(ugd);
871 case WIFI_DIRECT_DISASSOCIATION_IND:
872 WDUG_LOGI("WIFI_DIRECT_DISASSOCIATION_IND\n");
873 /* change the multi connection mode, it can be connected now */
874 if (ugd->multi_connect_mode == WFD_MULTI_CONNECT_MODE_COMPLETED) {
875 ugd->multi_connect_mode = WFD_MULTI_CONNECT_MODE_IN_PROGRESS;
878 /* if other peer disconnected, get connected peers and update */
879 peer->conn_status = PEER_CONN_STATUS_WAIT_FOR_CONNECT;
880 wfd_ug_get_connected_peers(ugd);
881 wfd_ug_view_update_peers(ugd);
883 case WIFI_DIRECT_DISCONNECTION_RSP:
884 case WIFI_DIRECT_DISCONNECTION_IND:
885 WDUG_LOGI("WIFI_DIRECT_DISCONNECTION_X\n");
887 /* when disconnection, clear all the connected peers */
888 if (ugd->raw_connected_peer_cnt > 0) {
889 memset(ugd->raw_connected_peers, 0x00, ugd->raw_connected_peer_cnt*sizeof(device_type_s));
892 ugd->raw_connected_peer_cnt = 0;
894 /* start discovery again */
895 res = wifi_direct_start_discovery(FALSE, MAX_SCAN_TIME_OUT);
896 if (res != WIFI_DIRECT_ERROR_NONE) {
897 WDUG_LOGE("Failed to start discovery. [%d]\n", res);
898 ugd->is_re_discover = TRUE;
899 wifi_direct_cancel_discovery();
901 WDUG_LOGI("Discovery is started\n");
902 ugd->is_re_discover = FALSE;
906 case WIFI_DIRECT_CONNECTION_IN_PROGRESS:
907 WDUG_LOGI("WIFI_DIRECT_CONNECTION_IN_PROGRESS\n");
908 peer->conn_status = PEER_CONN_STATUS_CONNECTING;
909 wfd_ug_view_update_peers(ugd);
911 case WIFI_DIRECT_CONNECTION_REQ:
912 case WIFI_DIRECT_CONNECTION_WPS_REQ:
913 WDUG_LOGI("WIFI_DIRECT_CLI_EVENT_CONNECTION_REQ\n");
921 wfd_ug_view_refresh_glitem(peer->gl_item);
924 _change_multi_button_title(ugd);
927 /* refresh the scan button */
928 wfd_refresh_wifi_direct_state(ugd);
929 if (WIFI_DIRECT_STATE_CONNECTING == ugd->wfd_status ||
930 WIFI_DIRECT_STATE_DISCONNECTING == ugd->wfd_status) {
931 res = wifi_direct_is_group_owner(&owner);
932 if (res == WIFI_DIRECT_ERROR_NONE) {
935 wfd_ug_view_refresh_button(ugd->scan_btn, _("IDS_WFD_BUTTON_SCAN"), FALSE);
938 if (ugd->multi_connect_btn) {
939 wfd_ug_view_refresh_button(ugd->multi_scan_btn, _("IDS_WFD_BUTTON_SCAN"), FALSE);
943 WDUG_LOGE("Failed to get whether client is group owner. [%d]\n", res);
947 wfd_ug_view_refresh_button(ugd->scan_btn, _("IDS_WFD_BUTTON_SCAN"), TRUE);
950 if (ugd->multi_connect_btn) {
951 wfd_ug_view_refresh_button(ugd->multi_scan_btn, _("IDS_WFD_BUTTON_SCAN"), TRUE);
955 /* if no connection, start the monitor timer */
956 wifi_direct_get_state(&ugd->wfd_status);
957 WDUG_LOGI("status: %d", ugd->wfd_status);
959 if (ugd->wfd_status >= WIFI_DIRECT_STATE_CONNECTED) {
960 if (ugd->monitor_timer) {
961 ecore_timer_del(ugd->monitor_timer);
962 ugd->monitor_timer = NULL;
965 if (NULL == ugd->monitor_timer) {
966 WDUG_LOGI("start the monitor timer\n");
967 ugd->last_wfd_time = time(NULL);
968 ugd->monitor_timer = ecore_timer_add(5.0,
969 (Ecore_Task_Cb)_wfd_automatic_deactivated_for_no_connection_cb, ugd);
973 __WDUG_LOG_FUNC_EXIT__;
978 * This function let the ug get wi-fi direct status from vconf
979 * @return If success, return 0, else return -1
980 * @param[in] data the pointer to the main data structure
982 int wfd_get_vconf_status(void *data)
984 __WDUG_LOG_FUNC_ENTER__;
985 struct ug_data *ugd = (struct ug_data *)data;
987 int wifi_direct_state = 0;
989 /* get wifi direct status from vconf */
990 if (vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wifi_direct_state) < 0) {
991 WDUG_LOGE("Error reading vconf (%s)\n", VCONFKEY_WIFI_DIRECT_STATE);
995 ugd->wfd_status = wifi_direct_state;
997 /* get device name from vconf */
998 dev_name = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
999 if (dev_name == NULL) {
1000 ugd->dev_name = strdup(DEFAULT_DEV_NAME);
1001 WDUG_LOGE("The AP name is NULL(setting default value)\n");
1003 ugd->dev_name = strdup(dev_name);
1007 __WDUG_LOG_FUNC_EXIT__;
1012 * This function let the ug refresh current status of wi-fi direct
1013 * @return If success, return 0, else return -1
1014 * @param[in] data the pointer to the main data structure
1016 int wfd_refresh_wifi_direct_state(void *data)
1018 __WDUG_LOG_FUNC_ENTER__;
1019 struct ug_data *ugd = (struct ug_data *)data;
1021 wifi_direct_state_e wfd_status;
1023 res = wifi_direct_get_state(&wfd_status);
1024 if (res != WIFI_DIRECT_ERROR_NONE) {
1025 WDUG_LOGE("Failed to get link status. [%d]\n", res);
1029 WDUG_LOGI("WFD status [%d]", wfd_status);
1030 ugd->wfd_status = wfd_status;
1032 __WDUG_LOG_FUNC_EXIT__;
1037 * This function let the ug do initialization
1038 * @return If success, return 0, else return -1
1039 * @param[in] data the pointer to the main data structure
1041 int init_wfd_client(void *data)
1043 __WDUG_LOG_FUNC_ENTER__;
1044 struct ug_data *ugd = (struct ug_data *)data;
1047 res = wifi_direct_initialize();
1048 if (res != WIFI_DIRECT_ERROR_NONE) {
1049 WDUG_LOGE("Failed to initialize wifi direct. [%d]\n", res);
1053 res = wifi_direct_initialize();
1054 if (res != WIFI_DIRECT_ERROR_NONE) {
1055 WDUG_LOGE("Failed to initialize Wi-Fi Direct. error code = [%d]\n", res);
1059 res = wifi_direct_set_device_state_changed_cb(_activation_cb, (void *)ugd);
1060 if (res != WIFI_DIRECT_ERROR_NONE) {
1061 WDUG_LOGE("Failed to register _cb_activation. error code = [%d]\n", res);
1065 res = wifi_direct_set_discovery_state_changed_cb(_discover_cb, (void *)ugd);
1066 if (res != WIFI_DIRECT_ERROR_NONE) {
1067 WDUG_LOGE("Failed to register _cb_discover. error code = [%d]\n", res);
1071 res = wifi_direct_set_connection_state_changed_cb(_connection_cb, (void *)ugd);
1072 if (res != WIFI_DIRECT_ERROR_NONE) {
1073 WDUG_LOGE("Failed to register _cb_connection. error code = [%d]\n", res);
1077 /* update WFD status */
1078 wfd_refresh_wifi_direct_state(ugd);
1079 if (ugd->wfd_status > WIFI_DIRECT_STATE_ACTIVATING) {
1085 WDUG_LOGI("WFD link status. [%d]\n", ugd->wfd_status);
1087 /* start the monitor timer */
1088 ugd->last_wfd_time = time(NULL);
1089 ugd->last_wfd_status = WIFI_DIRECT_STATE_DEACTIVATED;
1090 ugd->monitor_timer = ecore_timer_add(5.0, (Ecore_Task_Cb)_wfd_automatic_deactivated_for_no_connection_cb, ugd);
1092 ugd->is_re_discover = FALSE;
1094 __WDUG_LOG_FUNC_EXIT__;
1099 * This function let the ug do de-initialization
1100 * @return If success, return 0, else return -1
1101 * @param[in] data the pointer to the main data structure
1103 int deinit_wfd_client(void *data)
1105 __WDUG_LOG_FUNC_ENTER__;
1106 struct ug_data *ugd = (struct ug_data *)data;
1108 tethering_error_e ret = TETHERING_ERROR_NONE;
1109 tethering_h th = NULL;
1111 wfd_refresh_wifi_direct_state(ugd);
1113 if (ugd->wfd_status == WIFI_DIRECT_STATE_DISCOVERING) {
1114 WDUG_LOGI("Stop discovery before deregister client\n");
1115 wifi_direct_cancel_discovery();
1118 res = wifi_direct_deinitialize();
1119 if (res != WIFI_DIRECT_ERROR_NONE) {
1120 WDUG_LOGE("Failed to deregister client. [%d]\n", res);
1123 /* release monitor timer */
1124 if (ugd->monitor_timer) {
1125 ecore_timer_del(ugd->monitor_timer);
1126 ugd->monitor_timer = NULL;
1129 /* release vconf, hotspot.. */
1130 res = vconf_ignore_key_changed(VCONFKEY_WIFI_STATE, _wifi_state_cb);
1132 WDUG_LOGE("Failed to ignore vconf key callback for wifi state\n");
1135 res = net_deregister_client();
1136 if (res != NET_ERR_NONE) {
1137 WDUG_LOGE("Failed to deregister network client. [%d]\n", res);
1140 res = vconf_ignore_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE, _enable_hotspot_state_cb);
1142 WDUG_LOGE("Failed to ignore vconf key callback for hotspot state\n");
1145 res = vconf_ignore_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE, _disable_hotspot_state_cb);
1147 WDUG_LOGE("Failed to ignore vconf key callback for hotspot state\n");
1150 th = ugd->hotspot_handle;
1153 /* Deregister cbs */
1154 ret = tethering_unset_enabled_cb(th, TETHERING_TYPE_WIFI);
1155 if (ret != TETHERING_ERROR_NONE) {
1156 WDUG_LOGE("tethering_unset_enabled_cb is failed(%d)\n", ret);
1159 ret = tethering_unset_disabled_cb(th, TETHERING_TYPE_WIFI);
1160 if (ret != TETHERING_ERROR_NONE) {
1161 WDUG_LOGE("tethering_unset_disabled_cb is failed(%d)\n", ret);
1164 /* Destroy tethering handle */
1165 ret = tethering_destroy(th);
1166 if (ret != TETHERING_ERROR_NONE) {
1167 WDUG_LOGE("tethering_destroy is failed(%d)\n", ret);
1170 ugd->hotspot_handle = NULL;
1173 __WDUG_LOG_FUNC_EXIT__;
1178 * This function let the ug turn wi-fi direct on
1179 * @return If success, return 0, else return -1
1180 * @param[in] data the pointer to the main data structure
1182 int wfd_client_switch_on(void *data)
1184 __WDUG_LOG_FUNC_ENTER__;
1185 struct ug_data *ugd = (struct ug_data *)data;
1188 wfd_refresh_wifi_direct_state(ugd);
1189 WDUG_LOGI("WFD status [%d]\n", ugd->wfd_status);
1191 if (ugd->wfd_status < WIFI_DIRECT_STATE_ACTIVATING) {
1193 res = vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
1195 WDUG_LOGE("Failed to get wifi state from vconf. [%d]\n", res);
1200 res = vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &hotspot_mode);
1202 WDUG_LOGE("Failed to get mobile hotspot state from vconf. [%d]\n", res);
1206 if (wifi_state > VCONFKEY_WIFI_OFF) {
1207 WDUG_LOGI("WiFi is connected, so have to turn off WiFi");
1208 wfd_ug_act_popup(ugd, _("IDS_WFD_POP_WIFI_OFF"), POPUP_TYPE_WIFI_OFF);
1209 } else if (hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI) {
1210 WDUG_LOGI("WiFi is connected, so have to turn off WiFi");
1211 wfd_ug_act_popup(ugd, _("IDS_WFD_POP_HOTSPOT_OFF"), POPUP_TYPE_HOTSPOT_OFF);
1213 res = wifi_direct_activate();
1214 if (res != WIFI_DIRECT_ERROR_NONE) {
1215 WDUG_LOGE("Failed to activate Wi-Fi Direct. error code = [%d]\n", res);
1216 wfd_ug_warn_popup(ugd, _("IDS_WFD_POP_ACTIVATE_FAIL"), POPUP_TYPE_TERMINATE);
1218 ugd->head_text_mode = HEAD_TEXT_TYPE_DIRECT;
1219 wfd_ug_view_refresh_glitem(ugd->head);
1223 /* refresh the header */
1224 ugd->head_text_mode = HEAD_TEXT_TYPE_ACTIVATING;
1225 wfd_ug_view_refresh_glitem(ugd->head);
1227 /* while activating, disable the buttons */
1228 if (ugd->scan_btn) {
1229 wfd_ug_view_refresh_button(ugd->scan_btn, _("IDS_WFD_BUTTON_SCAN"), FALSE);
1232 if (ugd->multi_scan_btn) {
1233 wfd_ug_view_refresh_button(ugd->multi_scan_btn, _("IDS_WFD_BUTTON_SCAN"), FALSE);
1236 if (ugd->back_btn) {
1237 elm_object_disabled_set(ugd->back_btn, TRUE);
1241 WDUG_LOGI("Wi-Fi Direct is already activated\n");
1244 __WDUG_LOG_FUNC_EXIT__;
1249 * This function let the ug turn wi-fi direct off
1250 * @return If success, return 0, else return -1
1251 * @param[in] data the pointer to the main data structure
1253 int wfd_client_switch_off(void *data)
1255 __WDUG_LOG_FUNC_ENTER__;
1256 struct ug_data *ugd = (struct ug_data *)data;
1259 wfd_refresh_wifi_direct_state(ugd);
1260 WDUG_LOGI("WFD status [%d]\n", ugd->wfd_status);
1262 if (ugd->wfd_status < WIFI_DIRECT_STATE_ACTIVATING) {
1263 WDUG_LOGI("Wi-Fi Direct is already deactivated\n");
1265 /*if connected, disconnect all devices*/
1266 if (WIFI_DIRECT_STATE_CONNECTED == ugd->wfd_status) {
1267 res = wifi_direct_disconnect_all();
1268 if (res != WIFI_DIRECT_ERROR_NONE) {
1269 WDUG_LOGE("Failed to send disconnection request to all. [%d]\n", res);
1274 res = wifi_direct_deactivate();
1275 if (res != WIFI_DIRECT_ERROR_NONE) {
1276 WDUG_LOGE("Failed to deactivate Wi-Fi Direct. error code = [%d]\n", res);
1277 wfd_ug_warn_popup(ugd, _("IDS_WFD_POP_DEACTIVATE_FAIL"), POPUP_TYPE_TERMINATE);
1279 ugd->head_text_mode = HEAD_TEXT_TYPE_DIRECT;
1280 wfd_ug_view_refresh_glitem(ugd->head);
1284 /* refresh the header */
1285 ugd->head_text_mode = HEAD_TEXT_TYPE_DEACTIVATING;
1286 wfd_ug_view_refresh_glitem(ugd->head);
1288 /* while deactivating, disable the buttons */
1289 if (ugd->scan_btn) {
1290 wfd_ug_view_refresh_button(ugd->scan_btn, _("IDS_WFD_BUTTON_SCAN"), FALSE);
1293 if (ugd->multi_scan_btn) {
1294 wfd_ug_view_refresh_button(ugd->multi_scan_btn, _("IDS_WFD_BUTTON_SCAN"), FALSE);
1297 if (ugd->back_btn) {
1298 elm_object_disabled_set(ugd->back_btn, TRUE);
1302 __WDUG_LOG_FUNC_EXIT__;
1307 * This function let the ug turn wi-fi direct on/off forcely
1308 * @return If success, return 0, else return -1
1309 * @param[in] data the pointer to the main data structure
1310 * @param[in] onoff whether to turn on/off wi-fi direct
1312 int wfd_client_swtch_force(void *data, int onoff)
1314 __WDUG_LOG_FUNC_ENTER__;
1315 struct ug_data *ugd = (struct ug_data *)data;
1319 res = wifi_direct_activate();
1320 if (res != WIFI_DIRECT_ERROR_NONE) {
1321 WDUG_LOGE("Failed to activate Wi-Fi Direct. error code = [%d]\n", res);
1322 wfd_ug_warn_popup(ugd, _("IDS_WFD_POP_ACTIVATE_FAIL"), POPUP_TYPE_TERMINATE);
1324 ugd->head_text_mode = HEAD_TEXT_TYPE_DIRECT;
1325 wfd_ug_view_refresh_glitem(ugd->head);
1329 res = wifi_direct_deactivate();
1330 if (res != WIFI_DIRECT_ERROR_NONE) {
1331 WDUG_LOGE("Failed to deactivate Wi-Fi Direct. error code = [%d]\n", res);
1332 wfd_ug_warn_popup(ugd, _("IDS_WFD_POP_DEACTIVATE_FAIL"), POPUP_TYPE_TERMINATE);
1334 ugd->head_text_mode = HEAD_TEXT_TYPE_DIRECT;
1335 wfd_ug_view_refresh_glitem(ugd->head);
1340 __WDUG_LOG_FUNC_EXIT__;
1345 * This function let the ug create a group
1346 * @return If success, return 0, else return -1
1348 int wfd_client_group_add()
1350 __WDUG_LOG_FUNC_ENTER__;
1353 res = wifi_direct_create_group();
1354 if (res != WIFI_DIRECT_ERROR_NONE) {
1355 WDUG_LOGE("Failed to add group");
1356 __WDUG_LOG_FUNC_EXIT__;
1360 __WDUG_LOG_FUNC_EXIT__;
1365 * This function let the ug connect to the device by mac address
1366 * @return If success, return 0, else return -1
1367 * @param[in] mac_addr the pointer to the mac address of device
1369 int wfd_client_connect(const char *mac_addr)
1371 __WDUG_LOG_FUNC_ENTER__;
1374 WDUG_LOGE("connect to peer=[%s]\n", mac_addr);
1375 res = wifi_direct_connect(mac_addr);
1376 if (res != WIFI_DIRECT_ERROR_NONE) {
1377 WDUG_LOGE("Failed to send connection request. [%d]\n", res);
1381 __WDUG_LOG_FUNC_EXIT__;
1386 * This function let the ug disconnect to the device by mac address
1387 * @return If success, return 0, else return -1
1388 * @param[in] mac_addr the pointer to the mac address of device
1390 int wfd_client_disconnect(const char *mac_addr)
1392 __WDUG_LOG_FUNC_ENTER__;
1395 if (mac_addr == NULL) {
1396 res = wifi_direct_disconnect_all();
1397 if (res != WIFI_DIRECT_ERROR_NONE) {
1398 WDUG_LOGE("Failed to send disconnection request to all. [%d]\n", res);
1402 res = wifi_direct_disconnect(mac_addr);
1403 if (res != WIFI_DIRECT_ERROR_NONE) {
1404 WDUG_LOGE("Failed to send disconnection request. [%d]\n", res);
1409 __WDUG_LOG_FUNC_EXIT__;
1414 * This function let the ug set the intent of a group owner
1415 * @return If success, return 0, else return -1
1416 * @param[in] go_intent the intent parameter
1418 int wfd_client_set_p2p_group_owner_intent(int go_intent)
1420 __WDUG_LOG_FUNC_ENTER__;
1423 res = wifi_direct_set_group_owner_intent(go_intent);
1424 if (res != WIFI_DIRECT_ERROR_NONE) {
1425 WDUG_LOGE("Failed to wifi_direct_set_go_intent(%d). [%d]\n", go_intent, res);
1429 __WDUG_LOG_FUNC_EXIT__;