2 * Network Configuration Module
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
21 * This file implements wifi direct manager functions.
23 * @file wifi-direct-manager.c
24 * @author Gibyoung Kim (lastkgb.kim@samsung.com)
31 #include <sys/utsname.h>
36 #include <glib-object.h>
38 #include <wifi-direct.h>
40 #include "wifi-direct-ipc.h"
41 #include "wifi-direct-manager.h"
42 #include "wifi-direct-oem.h"
43 #include "wifi-direct-session.h"
44 #include "wifi-direct-group.h"
45 #include "wifi-direct-peer.h"
46 #include "wifi-direct-state.h"
47 #include "wifi-direct-event.h"
48 #include "wifi-direct-util.h"
49 #include "wifi-direct-log.h"
50 #include "wifi-direct-error.h"
51 #include "wifi-direct-iface.h"
52 #include "wifi-direct-dbus.h"
54 wfd_manager_s *g_manager;
56 wfd_manager_s *wfd_get_manager()
61 static int _wfd_local_init_device(wfd_manager_s *manager)
63 __WDS_LOG_FUNC_ENTER__;
64 wfd_device_s *local = NULL;
68 WDS_LOGE("Invalid parameter");
73 local = (wfd_device_s*) g_try_malloc0(sizeof(wfd_device_s));
75 WDS_LOGE("Failed to allocate memory for local device [%s]", strerror(errno));
79 res = wfd_util_get_phone_name(local->dev_name);
81 WDS_LOGE("Failed to get phone name of local device. Use default device name");
82 g_strlcpy(local->dev_name, DEFAULT_DEVICE_NAME, DEV_NAME_LEN + 1);
84 WDS_LOGD("Local Device name [%s]", local->dev_name);
85 wfd_util_set_dev_name_notification();
87 res = wfd_util_get_local_dev_mac(local->dev_addr);
89 WDS_LOGE("Failed to get local device MAC address");
92 memcpy(local->intf_addr, local->dev_addr, MACADDR_LEN);
93 local->intf_addr[4] ^= 0x80;
94 WDS_LOGD("Local Interface MAC address [" MACSECSTR "]",
95 MAC2SECSTR(local->intf_addr));
97 local->config_methods = WFD_WPS_MODE_PBC | WFD_WPS_MODE_DISPLAY | WFD_WPS_MODE_KEYPAD;
98 local->wps_mode = WFD_WPS_MODE_PBC;
99 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
100 local->services = NULL;
101 local->service_count = 0;
102 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
103 // TODO: initialize other local device datas
104 manager->local = local;
106 __WDS_LOG_FUNC_EXIT__;
110 static int _wfd_local_deinit_device(wfd_manager_s *manager)
112 __WDS_LOG_FUNC_ENTER__;
115 WDS_LOGE("Invalid parameter");
119 wfd_util_unset_dev_name_notification();
121 // TODO: free member of local device
122 g_free(manager->local);
124 __WDS_LOG_FUNC_EXIT__;
128 int wfd_local_reset_data(wfd_manager_s *manager)
130 __WDS_LOG_FUNC_ENTER__;
131 wfd_device_s *local = NULL;
134 WDS_LOGE("Invalid parameter");
138 local = manager->local;
139 /* init local device data */
140 local->dev_role = WFD_DEV_ROLE_NONE;
141 local->wps_mode = WFD_WPS_MODE_PBC;
142 memset(local->go_dev_addr, 0x0, MACADDR_LEN);
143 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
144 memset(&(local->display), 0x0, sizeof(wfd_display_s));
145 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
146 memset(local->ip_addr, 0x0, IPADDR_LEN);
148 __WDS_LOG_FUNC_EXIT__;
152 int wfd_local_get_dev_name(char *dev_name)
154 __WDS_LOG_FUNC_ENTER__;
155 wfd_device_s *local = g_manager->local;
158 WDS_LOGE("Invalid parameter");
159 __WDS_LOG_FUNC_EXIT__;
163 g_strlcpy(dev_name, local->dev_name, DEV_NAME_LEN + 1);
164 WDS_LOGD("Local device name [%s]", dev_name);
166 __WDS_LOG_FUNC_EXIT__;
170 int wfd_local_set_dev_name(char *dev_name)
172 __WDS_LOG_FUNC_ENTER__;
173 wfd_device_s *local = g_manager->local;
176 WDS_LOGE("Invalid parameter");
177 __WDS_LOG_FUNC_EXIT__;
181 g_strlcpy(local->dev_name, dev_name, DEV_NAME_LEN + 1);
183 if (g_manager->state >= WIFI_DIRECT_STATE_ACTIVATED) {
184 wfd_oem_set_dev_name(g_manager->oem_ops, dev_name);
185 WDS_LOGD("Device name changed.");
187 WDS_LOGE("Device name can't changed: state is %d",g_manager->state);
190 __WDS_LOG_FUNC_EXIT__;
194 int wfd_local_get_dev_mac(char *dev_mac)
196 __WDS_LOG_FUNC_ENTER__;
197 wfd_device_s *local = g_manager->local;
200 WDS_LOGE("Invalid parameter");
201 __WDS_LOG_FUNC_EXIT__;
205 g_snprintf(dev_mac, MACSTR_LEN, MACSTR, MAC2STR(local->dev_addr));
206 WDS_SECLOGD("Local device MAC address [%s]", dev_mac);
208 __WDS_LOG_FUNC_EXIT__;
213 int wfd_local_get_intf_mac(unsigned char *intf_mac)
215 __WDS_LOG_FUNC_ENTER__;
216 wfd_device_s *local = g_manager->local;
219 WDS_LOGE("Invalid parameter");
220 __WDS_LOG_FUNC_EXIT__;
224 g_snprintf(intf_mac, MACSTR_LEN, MACSTR, MAC2STR(local->intf_addr));
225 WDS_SECLOGD("Local interface MAC address [%s]", intf_mac);
227 __WDS_LOG_FUNC_EXIT__;
232 int wfd_local_get_ip_addr(char *ip_str)
234 __WDS_LOG_FUNC_ENTER__;
235 wfd_device_s *local = g_manager->local;
238 WDS_LOGE("Invalid parameter");
239 __WDS_LOG_FUNC_EXIT__;
243 snprintf(ip_str, IPSTR_LEN, IPSTR, IP2STR(local->ip_addr));
244 WDS_SECLOGD("Local IP address [" IPSECSTR "]", IP2SECSTR(local->ip_addr));
246 __WDS_LOG_FUNC_EXIT__;
250 int wfd_local_get_supported_wps_mode(int *config_methods)
252 __WDS_LOG_FUNC_ENTER__;
253 wfd_device_s *local = g_manager->local;
255 if (!config_methods) {
256 WDS_LOGE("Invalid parameter");
257 __WDS_LOG_FUNC_EXIT__;
261 *config_methods = local->config_methods;
262 WDS_LOGD("Local config method [0x%x]", *config_methods);
264 __WDS_LOG_FUNC_EXIT__;
268 int wfd_local_get_wps_mode(int *wps_mode)
270 __WDS_LOG_FUNC_ENTER__;
271 wfd_device_s *local = g_manager->local;
274 WDS_LOGE("Invalid parameter");
275 __WDS_LOG_FUNC_EXIT__;
279 *wps_mode = local->wps_mode;
280 WDS_LOGD("Local wps mode [0x%x]", *wps_mode);
282 __WDS_LOG_FUNC_EXIT__;
287 int wfd_local_set_wps_mode(int wps_mode)
289 __WDS_LOG_FUNC_ENTER__;
290 wfd_device_s *local = g_manager->local;
293 WDS_LOGE("Invalid parameter");
294 __WDS_LOG_FUNC_EXIT__;
298 local->wps_mode = wps_mode;
299 WDS_LOGD("Local wps mode [0x%x]", wps_mode);
301 __WDS_LOG_FUNC_EXIT__;
306 int wfd_manager_get_go_intent(int *go_intent)
308 __WDS_LOG_FUNC_ENTER__;
310 WDS_LOGE("Invalid parameter");
311 __WDS_LOG_FUNC_EXIT__;
315 *go_intent = g_manager->go_intent;
316 WDS_LOGD("Local GO intent [%d]", *go_intent);
318 __WDS_LOG_FUNC_EXIT__;
322 int wfd_manager_set_go_intent(int go_intent)
324 __WDS_LOG_FUNC_ENTER__;
326 if (go_intent < 0 || go_intent > 15) {
327 WDS_LOGE("Invalid parameter");
328 __WDS_LOG_FUNC_EXIT__;
332 g_manager->go_intent = go_intent;
333 if (g_manager->state >= WIFI_DIRECT_STATE_ACTIVATED)
334 wfd_oem_set_go_intent(g_manager->oem_ops, go_intent);
336 __WDS_LOG_FUNC_EXIT__;
340 int wfd_manager_get_max_station(int *max_station)
342 __WDS_LOG_FUNC_ENTER__;
345 WDS_LOGE("Invalid parameter");
346 __WDS_LOG_FUNC_EXIT__;
350 *max_station = g_manager->max_station;
351 WDS_LOGD("Local max station[%d]", *max_station);
353 __WDS_LOG_FUNC_EXIT__;
357 int wfd_manager_set_max_station(int max_station)
359 __WDS_LOG_FUNC_ENTER__;
361 if (max_station < 1) {
362 WDS_LOGE("Invalid parameter");
363 __WDS_LOG_FUNC_EXIT__;
367 g_manager->max_station = max_station;
369 __WDS_LOG_FUNC_EXIT__;
373 int wfd_manager_get_autoconnection(int *autoconnection)
375 __WDS_LOG_FUNC_ENTER__;
376 if (!autoconnection) {
377 WDS_LOGE("Invalid parameter");
378 __WDS_LOG_FUNC_EXIT__;
382 *autoconnection = g_manager->autoconnection;
383 WDS_LOGD("Local autoconnection [%s]", *autoconnection ? "TRUE":"FALSE");
385 __WDS_LOG_FUNC_EXIT__;
389 int wfd_manager_set_autoconnection(int autoconnection)
391 __WDS_LOG_FUNC_ENTER__;
392 if (autoconnection < 0) {
393 WDS_LOGE("Invalid parameter");
394 __WDS_LOG_FUNC_EXIT__;
398 g_manager->autoconnection = autoconnection;
400 __WDS_LOG_FUNC_EXIT__;
404 int wfd_manager_get_req_wps_mode(int *req_wps_mode)
406 __WDS_LOG_FUNC_ENTER__;
409 WDS_LOGE("Invalid parameter");
410 __WDS_LOG_FUNC_EXIT__;
414 *req_wps_mode = g_manager->req_wps_mode;
415 WDS_LOGD("Requested wps mode [0x%x]", *req_wps_mode);
417 __WDS_LOG_FUNC_EXIT__;
421 int wfd_manager_set_req_wps_mode(int req_wps_mode)
423 __WDS_LOG_FUNC_ENTER__;
424 wfd_device_s *local = g_manager->local;
426 if (req_wps_mode != WIFI_DIRECT_WPS_TYPE_PBC &&
427 req_wps_mode != WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY &&
428 req_wps_mode != WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) {
429 WDS_LOGE("Invalid parameter");
430 __WDS_LOG_FUNC_EXIT__;
434 g_manager->req_wps_mode = req_wps_mode;
435 WDS_LOGD("Requested wps mode [0x%x]", req_wps_mode);
436 if (req_wps_mode == WFD_WPS_MODE_DISPLAY)
437 local->wps_mode = WFD_WPS_MODE_KEYPAD;
438 else if (req_wps_mode == WFD_WPS_MODE_KEYPAD)
439 local->wps_mode = WFD_WPS_MODE_DISPLAY;
441 local->wps_mode = req_wps_mode;
443 __WDS_LOG_FUNC_EXIT__;
447 int wfd_manager_local_config_set(wfd_manager_s *manager)
449 __WDS_LOG_FUNC_ENTER__;
450 wfd_device_s *local = NULL;
454 WDS_LOGE("Invalid parameter");
455 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
458 local = manager->local;
460 local->wps_mode = WFD_WPS_MODE_PBC;
461 WDS_LOGD("Device name set as %s", local->dev_name);
462 res = wfd_oem_set_dev_name(manager->oem_ops, local->dev_name);
464 WDS_LOGE("Failed to set device name");
465 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
468 res = wfd_oem_set_dev_type(manager->oem_ops, local->pri_dev_type, local->sec_dev_type);
470 WDS_LOGE("Failed to set device type");
471 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
474 res = wfd_oem_set_go_intent(manager->oem_ops, manager->go_intent);
476 WDS_LOGE("Failed to set go intent");
477 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
480 return WIFI_DIRECT_ERROR_NONE;
483 int wfd_manager_activate(wfd_manager_s *manager)
485 __WDS_LOG_FUNC_ENTER__;
490 WDS_LOGE("Invalid parameter");
491 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
494 if (manager->state > WIFI_DIRECT_STATE_ACTIVATING) {
495 WDS_LOGE("Already activated");
499 if (manager->state == WIFI_DIRECT_STATE_ACTIVATING) {
500 WDS_LOGE("In progress");
501 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
504 res = wfd_util_wifi_direct_activatable();
506 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
508 wfd_state_get(manager, &prev_state);
509 wfd_state_set(manager, WIFI_DIRECT_STATE_ACTIVATING);
510 #if defined(TIZEN_WLAN_CONCURRENT_ENABLE)
511 res = wfd_util_check_wifi_state();
513 WDS_LOGE("Failed to get wifi state");
514 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
515 } else if (res == 0) {
516 #endif /* TIZEN_WLAN_CONCURRENT_ENABLE */
517 res = wfd_oem_activate(manager->oem_ops, 0);
519 WDS_LOGE("Failed to activate");
520 wfd_state_set(manager, prev_state);
521 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
523 #if defined(TIZEN_WLAN_CONCURRENT_ENABLE)
525 res = wfd_oem_activate(manager->oem_ops, res);
527 WDS_LOGE("Failed to activate");
528 wfd_state_set(manager, prev_state);
529 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
532 #endif /* TIZEN_WLAN_CONCURRENT_ENABLE */
533 WDS_LOGE("Succeeded to activate");
535 wfd_state_set(manager, WIFI_DIRECT_STATE_ACTIVATED);
536 wfd_util_set_wifi_direct_state(WIFI_DIRECT_STATE_ACTIVATED);
538 wfd_manager_local_config_set(manager);
539 wfd_util_set_country();
540 #ifdef TIZEN_FEATURE_DEFAULT_CONNECTION_AGENT
541 wfd_util_start_wifi_direct_popup();
542 #endif /* TIZEN_FEATURE_DEFAULT_CONNECTION_AGENT */
544 res = wfd_util_get_local_dev_mac(manager->local->dev_addr);
546 WDS_LOGE("Failed to get local device MAC address");
549 memcpy(manager->local->intf_addr, manager->local->dev_addr, MACADDR_LEN);
550 manager->local->intf_addr[4] ^= 0x80;
551 WDS_LOGD("Local Interface MAC address [" MACSECSTR "]",
552 MAC2SECSTR(manager->local->intf_addr));
554 __WDS_LOG_FUNC_EXIT__;
555 return WIFI_DIRECT_ERROR_NONE;
558 int wfd_manager_deactivate(wfd_manager_s *manager)
560 __WDS_LOG_FUNC_ENTER__;
565 WDS_LOGE("Invalid parameter");
566 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
569 wfd_state_get(manager, &prev_state);
570 wfd_state_set(manager, WIFI_DIRECT_STATE_DEACTIVATING);
572 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
573 res = wfd_oem_miracast_init(manager->oem_ops, false);
575 WDS_LOGE("Failed to initialize miracast");
576 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
578 res = wfd_oem_destroy_group(manager->oem_ops, GROUP_IFNAME);
580 WDS_LOGE("Failed to destroy group before deactivation");
582 #if defined(TIZEN_WLAN_CONCURRENT_ENABLE) && defined(TIZEN_MOBILE)
583 res = wfd_util_check_wifi_state();
585 WDS_LOGE("Failed to get wifi state");
586 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
587 } else if (res == 0) {
588 #endif /* TIZEN_WLAN_CONCURRENT_ENABLE && TIZEN_MOBILE */
589 res = wfd_oem_deactivate(manager->oem_ops, 0);
591 WDS_LOGE("Failed to deactivate");
592 wfd_state_set(manager, prev_state);
593 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
595 #if defined(TIZEN_WLAN_CONCURRENT_ENABLE) && defined(TIZEN_MOBILE)
597 // FIXME: We should do something to stop p2p feature of Driver
598 res = wfd_oem_deactivate(manager->oem_ops, res);
600 WDS_LOGE("Failed to deactivate");
601 wfd_state_set(manager, prev_state);
602 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
604 WDS_LOGE("Do not need to deactivate Wi-Fi");
606 #endif /* TIZEN_WLAN_CONCURRENT_ENABLE && TIZEN_MOBILE */
607 WDS_LOGE("Succeeded to deactivate");
609 wfd_state_set(manager, WIFI_DIRECT_STATE_DEACTIVATED);
610 wfd_util_set_wifi_direct_state(WIFI_DIRECT_STATE_DEACTIVATED);
612 manager->req_wps_mode = WFD_WPS_MODE_PBC;
614 wfd_destroy_group(manager, GROUP_IFNAME);
615 wfd_destroy_session(manager);
616 wfd_peer_clear_all(manager);
617 wfd_local_reset_data(manager);
619 #ifdef TIZEN_FEATURE_DEFAULT_CONNECTION_AGENT
620 wfd_util_stop_wifi_direct_popup();
621 #endif /* TIZEN_FEATURE_DEFAULT_CONNECTION_AGENT */
622 __WDS_LOG_FUNC_EXIT__;
623 return WIFI_DIRECT_ERROR_NONE;
626 int wfd_manager_connect(wfd_manager_s *manager, unsigned char *peer_addr)
628 __WDS_LOG_FUNC_ENTER__;
629 wfd_session_s *session = NULL;
632 if (!manager || !peer_addr) {
633 WDS_LOGE("Invalid parameter");
634 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
637 if (manager->state != WIFI_DIRECT_STATE_ACTIVATED &&
638 manager->state != WIFI_DIRECT_STATE_DISCOVERING &&
639 manager->state != WIFI_DIRECT_STATE_GROUP_OWNER) {
640 __WDS_LOG_FUNC_EXIT__;
641 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
644 wfd_group_s *group = (wfd_group_s*) manager->group;
645 if (group && group->member_count >= manager->max_station) {
646 __WDS_LOG_FUNC_EXIT__;
647 return WIFI_DIRECT_ERROR_TOO_MANY_CLIENT;
650 session = (wfd_session_s*) manager->session;
651 if (session && session->type != SESSION_TYPE_INVITE) {
652 WDS_LOGE("Session already exist and it's not an invitation session");
653 __WDS_LOG_FUNC_EXIT__;
654 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
658 session = wfd_create_session(manager, peer_addr,
659 manager->req_wps_mode, SESSION_DIRECTION_OUTGOING);
661 WDS_LOGE("Failed to create new session");
662 __WDS_LOG_FUNC_EXIT__;
663 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
667 if (manager->local->dev_role == WFD_DEV_ROLE_GO &&
668 session->type != SESSION_TYPE_INVITE) {
669 session->type = SESSION_TYPE_INVITE;
670 res = wfd_session_invite(session);
672 res = wfd_session_start(session);
675 WDS_LOGE("Failed to start session");
676 wfd_destroy_session(manager);
677 __WDS_LOG_FUNC_EXIT__;
678 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
680 wfd_state_set(manager, WIFI_DIRECT_STATE_CONNECTING);
682 __WDS_LOG_FUNC_EXIT__;
683 return WIFI_DIRECT_ERROR_NONE;
686 int wfd_manager_accept_connection(wfd_manager_s *manager, unsigned char *peer_addr)
688 __WDS_LOG_FUNC_ENTER__;
689 wfd_session_s *session = NULL;
690 wfd_device_s *peer = NULL;
693 if (!manager || !peer_addr) {
694 WDS_LOGE("Invalid parameter");
695 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
698 session = (wfd_session_s*) manager->session;
700 WDS_LOGE("Session not found");
701 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
704 peer = wfd_peer_find_by_dev_addr(manager, peer_addr);
706 WDS_LOGE("Peer is NULL");
707 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
710 // TODO: check peer_addr with session's peer_addr
712 if (manager->local->dev_role == WFD_DEV_ROLE_GO) {
713 WDS_LOGD("My device is GO and peer want to join my group, so WPS will be started");
714 res = wfd_session_wps(session);
715 } else if (peer->dev_role == WFD_DEV_ROLE_GO) {
716 WDS_LOGD("Peer device is GO, so Prov_Disc or Join will be started");
717 if (session->type == SESSION_TYPE_INVITE) {
718 if (session->state == SESSION_STATE_CREATED) {
719 WDS_LOGD("Invitation session. PD will be started");
720 res = wfd_session_start(session);
722 WDS_LOGD("Invitation session. Join will be started");
723 res = wfd_session_join(session);
726 if (manager->autoconnection && (manager->auto_pin[0] != 0))
727 g_strlcpy(session->wps_pin, manager->auto_pin, PINSTR_LEN + 1);
729 WDS_LOGD("Peer device is GO, so WPS will be started");
730 res = wfd_session_connect(session);
733 /* We should wait GO_NEGO_REQ from peer(MO) in autoconnection mode. */
734 /* Otherwise, GO Nego is sometimes failed. */
735 if (manager->autoconnection == FALSE) {
736 WDS_LOGD("My device is Device, so Negotiation will be started");
737 res = wfd_session_connect(session);
741 WDS_LOGE("Failed to start session");
742 if (manager->local->dev_role == WFD_DEV_ROLE_GO) {
743 wfd_state_set(manager, WIFI_DIRECT_STATE_GROUP_OWNER);
744 wfd_util_set_wifi_direct_state(WIFI_DIRECT_STATE_GROUP_OWNER);
746 wfd_state_set(manager, WIFI_DIRECT_STATE_ACTIVATED);
747 wfd_util_set_wifi_direct_state(WIFI_DIRECT_STATE_ACTIVATED);
749 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
751 wfd_state_set(manager, WIFI_DIRECT_STATE_CONNECTING);
753 __WDS_LOG_FUNC_EXIT__;
754 return WIFI_DIRECT_ERROR_NONE;
758 int wfd_manager_cancel_connection(wfd_manager_s *manager, unsigned char *peer_addr)
760 __WDS_LOG_FUNC_ENTER__;
761 wfd_group_s *group = NULL;
764 if (!manager || !peer_addr) {
765 WDS_LOGE("Invalid parameter");
766 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
769 if (!manager->session && manager->state != WIFI_DIRECT_STATE_CONNECTING) {
770 WDS_LOGE("It's not CONNECTING state");
771 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
774 res = wfd_session_cancel(manager->session, peer_addr);
776 WDS_LOGE("Failed to cancel session");
777 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
780 if (manager->local->dev_role != WFD_DEV_ROLE_GO)
781 wfd_oem_destroy_group(manager->oem_ops, GROUP_IFNAME);
783 group = (wfd_group_s*) manager->group;
785 wfd_group_remove_member(group, peer_addr);
786 if ((wfd_group_is_autonomous(manager->group) != TRUE) && !group->member_count) {
787 wfd_oem_destroy_group(manager->oem_ops, group->ifname);
788 wfd_destroy_group(manager, group->ifname);
790 wfd_oem_disconnect(manager->oem_ops, peer_addr);
794 if (manager->local->dev_role == WFD_DEV_ROLE_GO) {
795 wfd_state_set(manager, WIFI_DIRECT_STATE_GROUP_OWNER);
796 if (group && group->member_count > 0)
797 wfd_util_set_wifi_direct_state(WIFI_DIRECT_STATE_GROUP_OWNER);
799 wfd_state_set(manager, WIFI_DIRECT_STATE_ACTIVATED);
800 wfd_util_set_wifi_direct_state(WIFI_DIRECT_STATE_ACTIVATED);
803 __WDS_LOG_FUNC_EXIT__;
804 return WIFI_DIRECT_ERROR_NONE;
808 int wfd_manager_reject_connection(wfd_manager_s *manager, unsigned char *peer_addr)
810 __WDS_LOG_FUNC_ENTER__;
811 wfd_session_s *session = NULL;
814 if (!manager || !peer_addr) {
815 WDS_LOGE("Invalid parameter");
816 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
819 session = (wfd_session_s*) manager->session;
821 WDS_LOGE("Session not found");
822 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
825 if (manager->state != WIFI_DIRECT_STATE_CONNECTING) {
826 WDS_LOGE("It's not permitted with this state [%d]", manager->state);
827 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
830 if (session->direction != SESSION_DIRECTION_INCOMING) {
831 WDS_LOGE("Only incomming session can be rejected");
832 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
835 res = wfd_session_reject(session, peer_addr);
837 WDS_LOGE("Failed to reject connection");
838 // TODO: check whether set state and break
840 wfd_destroy_session(manager);
842 if (manager->local->dev_role == WFD_DEV_ROLE_GO) {
843 wfd_state_set(manager, WIFI_DIRECT_STATE_GROUP_OWNER);
844 wfd_util_set_wifi_direct_state(WIFI_DIRECT_STATE_GROUP_OWNER);
846 wfd_state_set(manager, WIFI_DIRECT_STATE_ACTIVATED);
847 wfd_util_set_wifi_direct_state(WIFI_DIRECT_STATE_ACTIVATED);
850 __WDS_LOG_FUNC_EXIT__;
851 return WIFI_DIRECT_ERROR_NONE;
855 int wfd_manager_disconnect(wfd_manager_s *manager, unsigned char *peer_addr)
857 __WDS_LOG_FUNC_ENTER__;
858 wfd_group_s *group = NULL;
859 wfd_device_s *peer = NULL;
863 WDS_LOGE("Invalid parameter");
864 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
868 WDS_LOGE("Invalid parameter");
869 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
872 group = (wfd_group_s*) manager->group;
874 WDS_LOGE("Group not found");
875 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
878 peer = wfd_group_find_member_by_addr(group, peer_addr);
880 WDS_LOGE("Connected peer not found");
881 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
884 wfd_state_set(manager, WIFI_DIRECT_STATE_DISCONNECTING);
886 if (manager->local->dev_role == WFD_DEV_ROLE_GO) {
887 #ifdef CTRL_IFACE_DBUS
888 /* dbus using device address to identify the peer */
889 res = wfd_oem_disconnect(manager->oem_ops, peer->dev_addr);
890 #else /* CTRL_IFACE_DBUS */
891 res = wfd_oem_disconnect(manager->oem_ops, peer->intf_addr);
892 #endif /* CTRL_IFACE_DBUS */
894 res = wfd_oem_destroy_group(manager->oem_ops, group->ifname);
897 WDS_LOGE("Failed to disconnect peer");
898 res = WIFI_DIRECT_ERROR_OPERATION_FAILED;
901 WDS_LOGE("Succeeded to disconnect peer");
903 wfd_group_remove_member(group, peer_addr);
904 if (!group->member_count) {
905 wfd_oem_destroy_group(manager->oem_ops, group->ifname);
906 wfd_destroy_group(manager, group->ifname);
909 if (manager->local->dev_role == WFD_DEV_ROLE_GO) {
910 wfd_state_set(manager, WIFI_DIRECT_STATE_GROUP_OWNER);
911 wfd_util_set_wifi_direct_state(WIFI_DIRECT_STATE_GROUP_OWNER);
913 wfd_state_set(manager, WIFI_DIRECT_STATE_ACTIVATED);
914 wfd_util_set_wifi_direct_state(WIFI_DIRECT_STATE_ACTIVATED);
917 __WDS_LOG_FUNC_EXIT__;
918 return WIFI_DIRECT_ERROR_NONE;
921 if (manager->local->dev_role == WFD_DEV_ROLE_GO) {
922 wfd_state_set(manager, WIFI_DIRECT_STATE_GROUP_OWNER);
923 wfd_util_set_wifi_direct_state(WIFI_DIRECT_STATE_GROUP_OWNER);
925 wfd_state_set(manager, WIFI_DIRECT_STATE_CONNECTED);
926 wfd_util_set_wifi_direct_state(WIFI_DIRECT_STATE_CONNECTED);
929 __WDS_LOG_FUNC_EXIT__;
933 int wfd_manager_disconnect_all(wfd_manager_s *manager)
935 __WDS_LOG_FUNC_ENTER__;
936 wfd_group_s *group = NULL;
940 WDS_LOGE("Invalid parameter");
941 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
944 group = (wfd_group_s*) manager->group;
946 WDS_LOGE("Group not found");
947 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
950 wfd_state_set(manager, WIFI_DIRECT_STATE_DISCONNECTING);
952 res = wfd_oem_destroy_group(manager->oem_ops, group->ifname);
954 WDS_LOGE("Failed to destroy group");
955 res = WIFI_DIRECT_ERROR_OPERATION_FAILED;
958 WDS_LOGE("Succeeded to disconnect all peer");
960 wfd_destroy_group(manager, group->ifname);
962 wfd_state_set(manager, WIFI_DIRECT_STATE_ACTIVATED);
963 wfd_util_set_wifi_direct_state(WIFI_DIRECT_STATE_ACTIVATED);
965 __WDS_LOG_FUNC_EXIT__;
966 return WIFI_DIRECT_ERROR_NONE;
969 if (manager->local->dev_role == WFD_DEV_ROLE_GO) {
970 wfd_state_set(manager, WIFI_DIRECT_STATE_GROUP_OWNER);
971 wfd_util_set_wifi_direct_state(WIFI_DIRECT_STATE_GROUP_OWNER);
973 wfd_state_set(manager, WIFI_DIRECT_STATE_CONNECTED);
974 wfd_util_set_wifi_direct_state(WIFI_DIRECT_STATE_CONNECTED);
977 __WDS_LOG_FUNC_EXIT__;
981 int wfd_manager_get_peer_info(wfd_manager_s *manager, unsigned char *addr, wfd_discovery_entry_s **peer)
983 __WDS_LOG_FUNC_ENTER__;
984 wfd_device_s *peer_dev = NULL;
985 wfd_discovery_entry_s *peer_info;
986 wfd_oem_device_s *oem_dev = NULL;
989 if (!manager || !addr) {
990 WDS_LOGE("Invalid parameter");
994 unsigned long time = 0;
995 #if !(__GNUC__ <= 4 && __GNUC_MINOR__ < 8)
996 wfd_util_get_current_time(&time);
999 gettimeofday(&tval, NULL);
1002 WDS_LOGI("Current time [%ld]", time);
1004 res = wfd_oem_get_peer_info(manager->oem_ops, addr, &oem_dev);
1005 if (res < 0 || !oem_dev) {
1006 WDS_LOGE("Failed to get peer information");
1010 peer_dev = wfd_peer_find_by_addr(manager, addr);
1012 peer_dev = (wfd_device_s*) g_try_malloc0(sizeof(wfd_device_s));
1014 WDS_LOGE("Failed to allocate memory for peer device. [%s]", strerror(errno));
1018 memcpy(peer_dev->dev_addr, addr, MACADDR_LEN);
1019 manager->peers = g_list_prepend(manager->peers, peer_dev);
1020 manager->peer_count++;
1021 peer_dev->time = time;
1022 WDS_LOGD("peer_count[%d]", manager->peer_count);
1024 if (oem_dev->age > 30 && peer_dev->state == WFD_PEER_STATE_DISCOVERED) {
1025 WDS_LOGE("Too old age to update peer");
1031 g_strlcpy(peer_dev->dev_name, oem_dev->dev_name, DEV_NAME_LEN + 1);
1032 memcpy(peer_dev->intf_addr, oem_dev->intf_addr, MACADDR_LEN);
1033 memcpy(peer_dev->go_dev_addr, oem_dev->go_dev_addr, MACADDR_LEN);
1034 peer_dev->dev_role = oem_dev->dev_role;
1035 peer_dev->config_methods = oem_dev->config_methods;
1036 peer_dev->pri_dev_type = oem_dev->pri_dev_type;
1037 peer_dev->sec_dev_type = oem_dev->sec_dev_type;
1038 peer_dev->dev_flags = oem_dev->dev_flags;
1039 peer_dev->group_flags = oem_dev->group_flags;
1040 peer_dev->wps_mode = oem_dev->wps_mode;
1042 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
1043 memcpy(&(peer_dev->display), &(oem_dev->display), sizeof(wfd_display_s));
1044 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
1046 peer_dev->time = time;
1047 peer_dev->channel = oem_dev->channel;
1051 peer_info = (wfd_discovery_entry_s*) g_try_malloc0(sizeof(wfd_discovery_entry_s));
1053 WDS_LOGE("Failed to allocate memory for peer data. [%s]", strerror(errno));
1057 g_strlcpy(peer_info->device_name, peer_dev->dev_name, DEV_NAME_LEN + 1);
1058 memcpy(peer_info->mac_address, peer_dev->dev_addr, MACADDR_LEN);
1059 memcpy(peer_info->intf_address, peer_dev->intf_addr, MACADDR_LEN);
1060 peer_info->channel = peer_dev->channel;
1061 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
1062 peer_info->services = 0;
1063 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
1064 peer_info->is_group_owner = peer_dev->dev_role == WFD_DEV_ROLE_GO;
1065 peer_info->is_persistent_go = peer_dev->group_flags & WFD_OEM_GROUP_FLAG_PERSISTENT_GROUP;
1066 peer_info->is_connected = peer_dev->dev_role == WFD_DEV_ROLE_GC;
1067 peer_info->wps_device_pwd_id = 0;
1068 peer_info->wps_cfg_methods = peer_dev->config_methods;
1069 peer_info->category = peer_dev->pri_dev_type;
1070 peer_info->subcategory = peer_dev->sec_dev_type;
1072 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
1073 if (peer_dev->display.availability && peer_dev->display.port)
1074 peer_info->is_wfd_device = 1;
1075 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
1079 __WDS_LOG_FUNC_EXIT__;
1084 int wfd_manager_get_peers(wfd_manager_s *manager, wfd_discovery_entry_s **peers_data)
1086 __WDS_LOG_FUNC_ENTER__;
1088 wfd_device_s *peer = NULL;
1089 wfd_discovery_entry_s *peers = NULL;
1094 if (!manager || !peers_data) {
1095 WDS_LOGE("Invalid parameter");
1099 unsigned long time = 0;
1100 #if !(__GNUC__ <= 4 && __GNUC_MINOR__ < 8)
1101 wfd_util_get_current_time(&time);
1103 struct timeval tval;
1104 gettimeofday(&tval, NULL);
1107 WDS_LOGI("Current time [%ld]", time);
1109 peer_count = manager->peer_count;
1110 WDS_LOGI("peer count [%ld]", peer_count);
1113 else if (peer_count == 0)
1117 peers = (wfd_discovery_entry_s*) g_try_malloc0_n(peer_count, sizeof(wfd_discovery_entry_s));
1119 WDS_LOGE("Failed to allocate memory for peer data. [%s]", strerror(errno));
1123 temp = g_list_first(manager->peers);
1124 while (temp && count < peer_count) {
1128 if (peer->time + 8 < time) {
1129 WDS_LOGD("Device data is too old to report to application [%s]", peer->dev_name);
1130 res = wfd_update_peer(manager, peer);
1132 WDS_LOGE("This device is disappeared [%s]", peer->dev_name);
1133 temp = g_list_next(temp);
1134 manager->peers = g_list_remove(manager->peers, peer);
1135 manager->peer_count--;
1142 g_strlcpy(peers[count].device_name, peer->dev_name, DEV_NAME_LEN + 1);
1143 memcpy(peers[count].mac_address, peer->dev_addr, MACADDR_LEN);
1144 memcpy(peers[count].intf_address, peer->intf_addr, MACADDR_LEN);
1145 peers[count].channel = peer->channel;
1146 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
1147 peers[count].services = 0;
1148 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
1149 peers[count].is_group_owner = peer->dev_role == WFD_DEV_ROLE_GO;
1150 peers[count].is_persistent_go = peer->group_flags & WFD_OEM_GROUP_FLAG_PERSISTENT_GROUP;
1151 peers[count].is_connected = peer->dev_role == WFD_DEV_ROLE_GC;
1152 peers[count].wps_device_pwd_id = 0;
1153 peers[count].wps_cfg_methods = peer->config_methods;
1154 peers[count].category = peer->pri_dev_type;
1155 peers[count].subcategory = peer->sec_dev_type;
1157 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
1158 if (peer->display.availability && peer->display.port)
1159 peers[count].is_wfd_device = 1;
1160 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
1162 WDS_LOGD("%dth peer [%s]", count, peer->dev_name);
1164 temp = g_list_next(temp);
1167 WDS_LOGD("%d peers converted", count);
1168 WDS_LOGD("Final peer count is %d", manager->peer_count);
1170 *peers_data = peers;
1172 __WDS_LOG_FUNC_EXIT__;
1176 int wfd_manager_get_connected_peers(wfd_manager_s *manager, wfd_connected_peer_info_s **peers_data)
1178 __WDS_LOG_FUNC_ENTER__;
1179 wfd_connected_peer_info_s *peers = NULL;
1180 wfd_group_s *group = NULL;
1181 wfd_device_s *peer = NULL;
1186 if (!manager || !peers_data) {
1187 WDS_LOGE("Invalid parameter");
1191 group = manager->group;
1193 WDS_LOGE("Group not exist");
1197 peer_count = group->member_count;
1198 if (peer_count == 0) {
1199 WDS_LOGD("Member not exist");
1204 peers = (wfd_connected_peer_info_s*) g_try_malloc0_n(peer_count, sizeof(wfd_connected_peer_info_s));
1206 WDS_LOGE("Failed to allocate memory for connected peer data. [%s]", strerror(errno));
1210 temp = g_list_first(group->members);
1211 while (temp && count < group->member_count) {
1214 g_strlcpy(peers[count].device_name, peer->dev_name, DEV_NAME_LEN + 1);
1215 memcpy(peers[count].mac_address, peer->dev_addr, MACADDR_LEN);
1216 memcpy(peers[count].intf_address, peer->intf_addr, MACADDR_LEN);
1217 memcpy(peers[count].ip_address, peer->ip_addr, IPADDR_LEN);
1218 peers[count].category = peer->pri_dev_type;
1219 peers[count].subcategory = peer->sec_dev_type;
1220 peers[count].channel = peer->channel;
1221 peers[count].is_p2p = 1;
1222 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
1223 peers[count].services = 0;
1224 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
1226 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
1227 if (peer->display.availability && peer->display.port)
1228 peers[count].is_wfd_device = 1;
1230 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
1232 WDS_LOGD("%dth member converted[%s]", count, peers[count].device_name);
1235 temp = g_list_next(temp);
1238 WDS_LOGD("%d members converted", count);
1240 *peers_data = peers;
1242 __WDS_LOG_FUNC_EXIT__;
1247 wfd_device_s *wfd_manager_find_connected_peer(wfd_manager_s *manager, unsigned char *peer_addr)
1249 __WDS_LOG_FUNC_ENTER__;
1250 wfd_device_s *peer = NULL;
1252 if (!manager || !peer_addr) {
1253 WDS_LOGE("Invalid parameter");
1257 peer = wfd_group_find_member_by_addr(manager->group, peer_addr);
1259 __WDS_LOG_FUNC_EXIT__;
1264 int wfd_manager_get_goup_ifname(char **ifname)
1266 __WDS_LOG_FUNC_ENTER__;
1267 wfd_group_s *group = g_manager->group;
1270 WDS_LOGE("Invalid parameter");
1271 __WDS_LOG_FUNC_EXIT__;
1276 WDS_LOGE("Group not exist");
1280 *ifname = group->ifname;
1282 __WDS_LOG_FUNC_EXIT__;
1286 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
1287 int wfd_manager_set_display_device(int type, int port, int hdcp)
1289 __WDS_LOG_FUNC_ENTER__;
1290 wfd_device_s * device = g_manager->local;
1291 wfd_oem_display_s display;
1295 WDS_LOGE("Invalid parameter");
1296 __WDS_LOG_FUNC_EXIT__;
1300 memset(&display, 0x0, sizeof(wfd_oem_display_s));
1302 display.type = type;
1303 display.port = port;
1304 display.hdcp_support = hdcp;
1306 display.availability = device->display.availability;
1307 display.max_tput = device->display.max_tput;
1309 res = wfd_oem_set_display(g_manager->oem_ops, (wfd_oem_display_s*)&display);
1311 WDS_LOGE("Failed to set wifi display");
1315 device->display.type = type;
1316 device->display.port = port;
1317 device->display.hdcp_support = hdcp;
1319 __WDS_LOG_FUNC_EXIT__;
1323 int wfd_manager_set_session_availability(int availability)
1325 __WDS_LOG_FUNC_ENTER__;
1326 wfd_device_s * device = g_manager->local;
1327 wfd_oem_display_s display;
1331 WDS_LOGE("Invalid parameter");
1332 __WDS_LOG_FUNC_EXIT__;
1336 memset(&display, 0x0, sizeof(wfd_oem_display_s));
1338 display.availability = availability;
1340 display.type = device->display.type;
1341 display.hdcp_support = device->display.hdcp_support;
1342 display.port = device->display.port;
1343 display.max_tput = device->display.max_tput;
1345 res = wfd_oem_set_display(g_manager->oem_ops, (wfd_oem_display_s*)&display);
1347 WDS_LOGE("Failed to set wifi display session availability");
1351 device->display.availability = availability;
1353 __WDS_LOG_FUNC_EXIT__;
1357 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
1359 int wfd_manager_start_discovery(wfd_manager_s *manager, int mode, int timeout,
1360 const char* type, int channel)
1362 __WDS_LOG_FUNC_ENTER__;
1363 int res = WIFI_DIRECT_ERROR_OPERATION_FAILED;
1364 wfd_oem_scan_param_s param;
1365 memset(¶m, 0x0, sizeof(wfd_oem_scan_param_s));
1367 WDS_LOGI("Mode: [%d], Timeout: [%d], type: [%s]", mode, timeout, type, channel);
1369 if (manager->local->dev_role == WFD_DEV_ROLE_GO)
1370 param.scan_type = WFD_OEM_SCAN_TYPE_SOCIAL;
1372 if (channel == WFD_DISCOVERY_FULL_SCAN) {
1373 param.scan_type = WFD_OEM_SCAN_TYPE_FULL;
1374 } else if (channel == WFD_DISCOVERY_SOCIAL_CHANNEL) {
1375 param.scan_type = WFD_OEM_SCAN_TYPE_SOCIAL;
1376 } else if (channel == WFD_DISCOVERY_CHANNEL1) {
1377 param.scan_type = WFD_OEM_SCAN_TYPE_CHANNEL1;
1379 } else if (channel == WFD_DISCOVERY_CHANNEL6) {
1380 param.scan_type = WFD_OEM_SCAN_TYPE_CHANNEL6;
1382 } else if (channel == WFD_DISCOVERY_CHANNEL11) {
1383 param.scan_type = WFD_OEM_SCAN_TYPE_CHANNEL11;
1386 param.scan_type = WFD_OEM_SCAN_TYPE_SPECIFIC;
1387 param.freq = wfd_util_channel_to_freq(channel);
1391 param.scan_mode = WFD_OEM_SCAN_MODE_PASSIVE;
1393 param.scan_mode = WFD_OEM_SCAN_MODE_ACTIVE;
1395 param.scan_time = timeout;
1397 res = wfd_oem_start_scan(manager->oem_ops, ¶m);
1399 WDS_LOGE("Failed to start scan");
1400 __WDS_LOG_FUNC_EXIT__;
1401 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1405 manager->scan_mode = WFD_SCAN_MODE_PASSIVE;
1407 manager->scan_mode = WFD_SCAN_MODE_ACTIVE;
1409 if (manager->local->dev_role != WFD_DEV_ROLE_GO) {
1410 wfd_state_set(manager, WIFI_DIRECT_STATE_DISCOVERING);
1411 wfd_util_set_wifi_direct_state(WIFI_DIRECT_STATE_DISCOVERING);
1414 WDS_LOGD("Succeeded to start scan");
1415 __WDS_LOG_FUNC_EXIT__;
1416 return WIFI_DIRECT_ERROR_NONE;
1419 int wfd_manager_cancel_discovery(wfd_manager_s *manager)
1421 __WDS_LOG_FUNC_ENTER__;
1424 res = wfd_oem_stop_scan(manager->oem_ops);
1426 WDS_LOGE("Failed to stop scan");
1427 __WDS_LOG_FUNC_EXIT__;
1428 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1431 if (manager->local->dev_role == WFD_DEV_ROLE_GO) {
1432 wfd_state_set(manager, WIFI_DIRECT_STATE_GROUP_OWNER);
1433 wfd_util_set_wifi_direct_state(WIFI_DIRECT_STATE_GROUP_OWNER);
1435 wfd_state_set(manager, WIFI_DIRECT_STATE_ACTIVATED);
1436 wfd_util_set_wifi_direct_state(WIFI_DIRECT_STATE_ACTIVATED);
1439 WDS_LOGD("Succeeded to stop scan");
1440 __WDS_LOG_FUNC_EXIT__;
1441 return WIFI_DIRECT_ERROR_NONE;
1444 wfd_device_s *wfd_manager_get_peer_by_addr(wfd_manager_s *manager, unsigned char *peer_addr)
1446 __WDS_LOG_FUNC_ENTER__;
1447 wfd_device_s *peer = NULL;
1448 if(manager->group) {
1449 peer = wfd_group_find_member_by_addr(manager->group, peer_addr);
1456 peer = wfd_peer_find_by_addr(manager, peer_addr);
1458 __WDS_LOG_FUNC_EXIT__;
1462 static wfd_manager_s *wfd_manager_init()
1464 __WDS_LOG_FUNC_ENTER__;
1465 wfd_manager_s *manager = NULL;
1468 manager = (wfd_manager_s*) g_try_malloc0(sizeof(wfd_manager_s));
1470 WDS_LOGE("Failed to allocate memory for wfd_manager structure");
1474 manager->go_intent = 7;
1475 manager->req_wps_mode = WFD_WPS_MODE_PBC;
1476 manager->max_station = 8;
1477 manager->session_timer = 120;
1478 res = _wfd_local_init_device(manager);
1480 WDS_LOGE("Failed to initialize local device");
1482 return NULL; // really stop manager?
1484 WDS_LOGD("Succeeded to initialize local device");
1486 __WDS_LOG_FUNC_EXIT__;
1490 int wfd_manager_deinit(wfd_manager_s *manager)
1492 __WDS_LOG_FUNC_ENTER__;
1495 WDS_LOGE("Invalid parameter");
1496 __WDS_LOG_FUNC_EXIT__;
1500 _wfd_local_deinit_device(manager);
1504 __WDS_LOG_FUNC_EXIT__;
1508 static void *wfd_plugin_init(wfd_manager_s *manager)
1510 __WDS_LOG_FUNC_ENTER__;
1512 struct utsname kernel_info;
1516 WDS_LOGE("Invalid parameter");
1517 __WDS_LOG_FUNC_EXIT__;
1521 res = uname(&kernel_info);
1523 WDS_LOGE("Failed to detect target type");
1524 __WDS_LOG_FUNC_EXIT__;
1527 WDS_LOGD("Node name [%s], HW ID [%s]", kernel_info.nodename, kernel_info.machine);
1531 #if defined(TIZEN_ARCH_64)
1532 handle = dlopen(SUPPL_PLUGIN_64BIT_PATH, RTLD_NOW);
1534 handle = dlopen(SUPPL_PLUGIN_PATH, RTLD_NOW);
1537 WDS_LOGE("Failed to open shared object. [%s]", dlerror());
1538 __WDS_LOG_FUNC_EXIT__;
1543 int (*plugin_load)(wfd_oem_ops_s **ops) = NULL;
1544 plugin_load = (int (*)(wfd_oem_ops_s **ops)) dlsym(handle, "wfd_plugin_load");
1546 WDS_LOGE( "Failed to load symbol. Error = [%s]", strerror(errno));
1548 __WDS_LOG_FUNC_EXIT__;
1552 wfd_oem_ops_s *temp_ops;
1553 (*plugin_load)(&temp_ops);
1554 manager->oem_ops = temp_ops;
1556 res = wfd_oem_init(temp_ops, (wfd_oem_event_cb) wfd_process_event, manager);
1558 WDS_LOGE("Failed to initialize OEM");
1560 __WDS_LOG_FUNC_EXIT__;
1563 WDS_LOGD("Succeeded to initialize OEM");
1565 __WDS_LOG_FUNC_EXIT__;
1569 static int wfd_plugin_deinit(wfd_manager_s *manager)
1571 __WDS_LOG_FUNC_ENTER__;
1573 if (!manager || !manager->plugin_handle) {
1574 WDS_LOGE("Invalid parameter");
1575 __WDS_LOG_FUNC_EXIT__;
1579 dlclose(manager->plugin_handle);
1580 manager->plugin_handle = NULL;
1582 __WDS_LOG_FUNC_EXIT__;
1586 int main(int argc, char *argv[])
1588 __WDS_LOG_FUNC_ENTER__;
1589 GMainLoop *main_loop = NULL;
1591 #if !GLIB_CHECK_VERSION(2,32,0)
1592 if (!g_thread_supported())
1593 g_thread_init(NULL);
1596 #if !GLIB_CHECK_VERSION(2,36,0)
1600 // TODO: Parsing argument
1601 /* Wi-Fi direct connection for S-Beam can be optimized using argument */
1604 * wfd-manager initialization
1606 g_manager = wfd_manager_init();
1608 WDS_LOGE("Failed to initialize wifi-direct manager");
1609 __WDS_LOG_FUNC_EXIT__;
1612 WDS_LOGD("Succeeded to initialize manager");
1615 * wfd_manager_plugin initialization
1617 g_manager->plugin_handle = wfd_plugin_init(g_manager);
1618 if (!g_manager->plugin_handle) {
1619 WDS_LOGE("Failed to initialize plugin");
1620 wfd_manager_deinit(g_manager);
1621 __WDS_LOG_FUNC_EXIT__;
1624 WDS_LOGD("Succeeded to load plugin");
1626 if (!wfd_manager_dbus_init()) {
1627 WDS_LOGE("Failed to DBus");
1628 wfd_plugin_deinit(g_manager);
1629 wfd_manager_deinit(g_manager);
1630 __WDS_LOG_FUNC_EXIT__;
1634 main_loop = g_main_loop_new(NULL, FALSE);
1635 if (main_loop == NULL) {
1636 WDS_LOGE("Failed to create GMainLoop structure");
1637 __WDS_LOG_FUNC_EXIT__;
1640 g_manager->main_loop = main_loop;
1641 g_main_loop_run(main_loop);
1643 wfd_manager_dbus_unregister();
1644 wfd_manager_dbus_deinit();
1646 wfd_plugin_deinit(g_manager);
1647 wfd_manager_deinit(g_manager);
1649 __WDS_LOG_FUNC_EXIT__;