--- /dev/null
+/*
+ * libwifi-direct
+ *
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Sungsik Jang <sungsik.jang@samsung.com>, Dongwook Lee <dwmax.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+/*****************************************************************************
+ * Standard headers
+ *****************************************************************************/
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <netdb.h>
+#include <sys/socket.h>
+#include <string.h>
+#include <sys/un.h>
+#include <sys/wait.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <signal.h>
+#include <linux/unistd.h>
+#include <sys/poll.h>
+#include <pthread.h>
+#include <errno.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+/*****************************************************************************
+ * System headers
+ *****************************************************************************/
+#include <vconf.h>
+#include <system_info.h>
+
+/*****************************************************************************
+ * Wi-Fi Direct Service headers
+ *****************************************************************************/
+#include "wifi-direct.h"
+#include "wifi-direct-internal.h"
+#include "wifi-direct-client-proxy.h"
+#include "wifi-direct-ipc.h"
+
+/*****************************************************************************
+ * Macros and Typedefs
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Global Variables
+ *****************************************************************************/
+wifi_direct_client_info_s g_client_info = {
+ .is_registered = FALSE,
+ .client_id = -1,
+ .sync_sockfd = -1,
+ .async_sockfd = -1,
+ .activation_cb = NULL,
+ .discover_cb = NULL,
+ .connection_cb = NULL,
+ .ip_assigned_cb = NULL,
+ .peer_found_cb = NULL,
+ .user_data_for_cb_activation = NULL,
+ .user_data_for_cb_discover = NULL,
+ .user_data_for_cb_connection = NULL,
+ .user_data_for_cb_ip_assigned = NULL,
+ .user_data_for_cb_peer_found = NULL,
+ .user_data_for_cb_device_name = NULL,
+#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
+ .service_cb = NULL,
+ .user_data_for_cb_service = NULL,
+#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+
+ .mutex = PTHREAD_MUTEX_INITIALIZER
+};
+
+/*****************************************************************************
+ * Local Functions Definition
+ *****************************************************************************/
+
+#ifdef __NR_gettid
+pid_t gettid(void)
+{
+ return syscall(__NR_gettid);
+}
+#else
+#error "__NR_gettid is not defined, please include linux/unistd.h"
+#endif
+
+static wifi_direct_client_info_s *__wfd_get_control()
+{
+ return &g_client_info;
+}
+
+static void __wfd_reset_control()
+{
+
+ if (g_client_info.g_source_id > 0)
+ g_source_remove(g_client_info.g_source_id);
+ g_client_info.g_source_id = -1;
+
+ // Protect standard input / output / error
+ if (g_client_info.sync_sockfd > 0)
+ close(g_client_info.sync_sockfd);
+ g_client_info.sync_sockfd = -1;
+
+ if (g_client_info.async_sockfd > 0)
+ close(g_client_info.async_sockfd);
+ g_client_info.async_sockfd = -1;
+
+ g_client_info.is_registered = FALSE;
+
+ // Initialize callbacks
+ g_client_info.activation_cb = NULL;
+ g_client_info.discover_cb = NULL;
+ g_client_info.connection_cb = NULL;
+ g_client_info.ip_assigned_cb = NULL;
+ g_client_info.peer_found_cb = NULL;
+ g_client_info.user_data_for_cb_activation = NULL;
+ g_client_info.user_data_for_cb_discover = NULL;
+ g_client_info.user_data_for_cb_connection = NULL;
+ g_client_info.user_data_for_cb_ip_assigned = NULL;
+ g_client_info.user_data_for_cb_peer_found = NULL;
+ g_client_info.user_data_for_cb_device_name = NULL;
+
+#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
+ g_client_info.service_cb = NULL;
+ g_client_info.user_data_for_cb_service= NULL;
+#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+
+
+ pthread_mutex_destroy(&g_client_info.mutex);
+}
+
+static int macaddr_atoe(char *p, unsigned char mac[])
+{
+ int i = 0;
+
+ for (;;) {
+ mac[i++] = (char) strtoul(p, &p, 16);
+ if (!*p++ || i == 6)
+ break;
+ }
+
+ return (i == 6);
+}
+
+static char *__wfd_print_event(wfd_client_event_e event)
+{
+ switch (event)
+ {
+ case WIFI_DIRECT_CLI_EVENT_INVALID:
+ return "WIFI_DIRECT_CLI_EVENT_INVALID";
+ break;
+ case WIFI_DIRECT_CLI_EVENT_ACTIVATION:
+ return "ACTIVATION";
+ break;
+ case WIFI_DIRECT_CLI_EVENT_DEACTIVATION:
+ return "DEACTIVATION";
+ break;
+ case WIFI_DIRECT_CLI_EVENT_DISCOVER_START:
+ return "WIFI_DIRECT_CLI_EVENT_DISCOVER_START";
+ break;
+ case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_LISTEN_ONLY:
+ return "WIFI_DIRECT_CLI_EVENT_DISCOVER_START_LISTEN_ONLY";
+ break;
+ case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_SEARCH_LISTEN:
+ return "WIFI_DIRECT_CLI_EVENT_DISCOVER_START_SEARCH_LISTEN";
+ break;
+ case WIFI_DIRECT_CLI_EVENT_DISCOVER_END:
+ return "WIFI_DIRECT_CLI_EVENT_DISCOVER_END";
+ break;
+ case WIFI_DIRECT_CLI_EVENT_DISCOVER_FOUND_PEERS:
+ return "WIFI_DIRECT_CLI_EVENT_DISCOVER_FOUND_PEERS";
+ break;
+ case WIFI_DIRECT_CLI_EVENT_CONNECTION_START:
+ return "WIFI_DIRECT_CLI_EVENT_CONNECTION_START";
+ break;
+ case WIFI_DIRECT_CLI_EVENT_CONNECTION_REQ:
+ return "WIFI_DIRECT_CLI_EVENT_CONNECTION_REQ";
+ break;
+ case WIFI_DIRECT_CLI_EVENT_CONNECTION_RSP:
+ return "WIFI_DIRECT_CLI_EVENT_CONNECTION_RSP";
+ break;
+ case WIFI_DIRECT_CLI_EVENT_CONNECTION_WPS_REQ:
+ return "WIFI_DIRECT_CLI_EVENT_CONNECTION_WPS_REQ";
+ break;
+ case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_RSP:
+ return "WIFI_DIRECT_CLI_EVENT_DISCONNECTION_RSP";
+ break;
+ case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_IND:
+ return "WIFI_DIRECT_CLI_EVENT_DISCONNECTION_IND";
+ break;
+ case WIFI_DIRECT_CLI_EVENT_DISASSOCIATION_IND:
+ return "WIFI_DIRECT_CLI_EVENT_DISASSOCIATION_IND";
+ break;
+ case WIFI_DIRECT_CLI_EVENT_GROUP_CREATE_RSP:
+ return "WIFI_DIRECT_CLI_EVENT_GROUP_CREATE_RSP";
+ break;
+ case WIFI_DIRECT_CLI_EVENT_GROUP_DESTROY_RSP:
+ return "WIFI_DIRECT_CLI_EVENT_GROUP_DESTROY_RSP";
+ break;
+ case WIFI_DIRECT_CLI_EVENT_IP_LEASED_IND:
+ return "WIFI_DIRECT_CLI_EVENT_IP_LEASED_IND";
+ break;
+#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
+ case WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_FOUND:
+ return "WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_FOUND";
+ break;
+ case WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_STARTED:
+ return "WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_STARTED";
+ break;
+ case WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_FINISHED:
+ return "WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_FINSIHED";
+ break;
+#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+
+ default:
+ return "WIFI_DIRECT_CLI_EVENT_unknown";
+ break;
+ }
+}
+
+static char *__wfd_print_error(wifi_direct_error_e error)
+{
+ switch (error)
+ {
+ case WIFI_DIRECT_ERROR_NONE:
+ return "WIFI_DIRECT_ERROR_NONE";
+ case WIFI_DIRECT_ERROR_NOT_PERMITTED:
+ return "WIFI_DIRECT_ERROR_NOT_PERMITTED";
+ case WIFI_DIRECT_ERROR_OUT_OF_MEMORY:
+ return "WIFI_DIRECT_ERROR_OUT_OF_MEMORY";
+ case WIFI_DIRECT_ERROR_PERMISSION_DENIED:
+ return "WIFI_DIRECT_ERROR_PERMISSION_DENIED";
+ case WIFI_DIRECT_ERROR_RESOURCE_BUSY:
+ return "WIFI_DIRECT_ERROR_RESOURCE_BUSY";
+ case WIFI_DIRECT_ERROR_INVALID_PARAMETER:
+ return "WIFI_DIRECT_ERROR_INVALID_PARAMETER";
+ case WIFI_DIRECT_ERROR_NOT_INITIALIZED:
+ return "WIFI_DIRECT_ERROR_NOT_INITIALIZED";
+ case WIFI_DIRECT_ERROR_COMMUNICATION_FAILED:
+ return "WIFI_DIRECT_ERROR_COMMUNICATION_FAILED";
+ case WIFI_DIRECT_ERROR_WIFI_USED:
+ return "WIFI_DIRECT_ERROR_WIFI_USED";
+ case WIFI_DIRECT_ERROR_MOBILE_AP_USED:
+ return "WIFI_DIRECT_ERROR_MOBILE_AP_USED";
+ case WIFI_DIRECT_ERROR_CONNECTION_FAILED:
+ return "WIFI_DIRECT_ERROR_CONNECTION_FAILED";
+ case WIFI_DIRECT_ERROR_AUTH_FAILED:
+ return "WIFI_DIRECT_ERROR_AUTH_FAILED";
+ case WIFI_DIRECT_ERROR_OPERATION_FAILED:
+ return "WIFI_DIRECT_ERROR_OPERATION_FAILED";
+ case WIFI_DIRECT_ERROR_TOO_MANY_CLIENT:
+ return "WIFI_DIRECT_ERROR_TOO_MANY_CLIENT";
+ case WIFI_DIRECT_ERROR_ALREADY_INITIALIZED:
+ return "WIFI_DIRECT_ERROR_ALREADY_INITIALIZED";
+ default:
+ WDC_LOGE("Invalid error value: [%d]", error);
+ return "Invalid error";
+ }
+}
+
+static int __wfd_convert_client_event(wfd_client_event_e event)
+{
+ __WDC_LOG_FUNC_START__;
+
+ switch (event)
+ {
+ case WIFI_DIRECT_CLI_EVENT_ACTIVATION:
+ return WIFI_DIRECT_DEVICE_STATE_ACTIVATED;
+ break;
+ case WIFI_DIRECT_CLI_EVENT_DEACTIVATION:
+ return WIFI_DIRECT_DEVICE_STATE_DEACTIVATED;
+ break;
+
+ case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_LISTEN_ONLY:
+ return WIFI_DIRECT_ONLY_LISTEN_STARTED;
+ break;
+ case WIFI_DIRECT_CLI_EVENT_DISCOVER_START:
+ case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_SEARCH_LISTEN:
+ return WIFI_DIRECT_DISCOVERY_STARTED;
+ break;
+ case WIFI_DIRECT_CLI_EVENT_DISCOVER_FOUND_PEERS:
+ return WIFI_DIRECT_DISCOVERY_FOUND;
+ break;
+ case WIFI_DIRECT_CLI_EVENT_DISCOVER_END:
+ return WIFI_DIRECT_DISCOVERY_FINISHED;
+ break;
+ case WIFI_DIRECT_CLI_EVENT_CONNECTION_REQ:
+ return WIFI_DIRECT_CONNECTION_REQ;
+ break;
+ case WIFI_DIRECT_CLI_EVENT_CONNECTION_WPS_REQ:
+ return WIFI_DIRECT_CONNECTION_WPS_REQ;
+ break;
+ case WIFI_DIRECT_CLI_EVENT_CONNECTION_START:
+ return WIFI_DIRECT_CONNECTION_IN_PROGRESS;
+ break;
+ case WIFI_DIRECT_CLI_EVENT_CONNECTION_RSP:
+ return WIFI_DIRECT_CONNECTION_RSP;
+ break;
+ case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_RSP:
+ return WIFI_DIRECT_DISCONNECTION_RSP;
+ break;
+ case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_IND:
+ return WIFI_DIRECT_DISCONNECTION_IND;
+ break;
+ case WIFI_DIRECT_CLI_EVENT_DISASSOCIATION_IND:
+ return WIFI_DIRECT_DISASSOCIATION_IND;
+ break;
+ case WIFI_DIRECT_CLI_EVENT_GROUP_CREATE_RSP:
+ return WIFI_DIRECT_GROUP_CREATED;
+ break;
+ case WIFI_DIRECT_CLI_EVENT_GROUP_DESTROY_RSP:
+ return WIFI_DIRECT_GROUP_DESTROYED;
+ break;
+#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
+ case WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_FOUND:
+ return WIFI_DIRECT_SERVICE_DISCOVERY_FOUND;
+ break;
+ case WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_STARTED:
+ return WIFI_DIRECT_SERVICE_DISCOVERY_STARTED;
+ break;
+ case WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_FINISHED:
+ return WIFI_DIRECT_SERVICE_DISCOVERY_FINISHED;
+ break;
+#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+ default:
+ WDC_LOGE("Invalid event : [%d]", event);
+ break;
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return -1;
+}
+
+char *__wfd_client_print_cmd(wifi_direct_cmd_e cmd)
+{
+ switch (cmd)
+ {
+ case WIFI_DIRECT_CMD_REGISTER:
+ return "WIFI_DIRECT_CMD_REGISTER";
+ case WIFI_DIRECT_CMD_INIT_ASYNC_SOCKET:
+ return "WIFI_DIRECT_CMD_INIT_ASYNC_SOCKET";
+ case WIFI_DIRECT_CMD_DEREGISTER:
+ return "WIFI_DIRECT_CMD_DEREGISTER";
+ case WIFI_DIRECT_CMD_ACTIVATE:
+ return "WIFI_DIRECT_CMD_ACTIVATE";
+ case WIFI_DIRECT_CMD_DEACTIVATE:
+ return "WIFI_DIRECT_CMD_DEACTIVATE";
+ case WIFI_DIRECT_CMD_START_DISCOVERY:
+ return "WIFI_DIRECT_CMD_START_DISCOVERY";
+ case WIFI_DIRECT_CMD_START_DISCOVERY_SPECIFIC_CHANNEL:
+ return "WIFI_DIRECT_CMD_START_DISCOVERY_SPECIFIC_CHANNEL";
+ case WIFI_DIRECT_CMD_CANCEL_DISCOVERY:
+ return "WIFI_DIRECT_CMD_CANCEL_DISCOVERY";
+ case WIFI_DIRECT_CMD_GET_DISCOVERY_RESULT:
+ return "WIFI_DIRECT_CMD_GET_DISCOVERY_RESULT";
+ case WIFI_DIRECT_CMD_GET_LINK_STATUS:
+ return "WIFI_DIRECT_CMD_GET_LINK_STATUS";
+ case WIFI_DIRECT_CMD_CONNECT:
+ return "WIFI_DIRECT_CMD_CONNECT";
+ case WIFI_DIRECT_CMD_CANCEL_CONNECT:
+ return "WIFI_DIRECT_CMD_CANCEL_CONNECT";
+ case WIFI_DIRECT_CMD_CANCEL_CONNECTION:
+ return "WIFI_DIRECT_CMD_CANCEL_CONNECTION";
+ case WIFI_DIRECT_CMD_REJECT_CONNECTION:
+ return "WIFI_DIRECT_CMD_REJECT_CONNECTION";
+ case WIFI_DIRECT_CMD_DISCONNECT_ALL:
+ return "WIFI_DIRECT_CMD_DISCONNECT_ALL";
+ case WIFI_DIRECT_CMD_CREATE_GROUP:
+ return "WIFI_DIRECT_CMD_CREATE_GROUP";
+ case WIFI_DIRECT_CMD_IS_GROUPOWNER:
+ return "WIFI_DIRECT_CMD_IS_GROUPOWNER";
+ case WIFI_DIRECT_CMD_GET_SSID:
+ return "WIFI_DIRECT_CMD_GET_SSID";
+ case WIFI_DIRECT_CMD_SET_SSID:
+ return "WIFI_DIRECT_CMD_SET_SSID";
+ case WIFI_DIRECT_CMD_GET_IP_ADDR:
+ return "WIFI_DIRECT_CMD_GET_IP_ADDR";
+ case WIFI_DIRECT_CMD_GET_CONFIG:
+ return "WIFI_DIRECT_CMD_GET_CONFIG";
+ case WIFI_DIRECT_CMD_SET_CONFIG:
+ return "WIFI_DIRECT_CMD_SET_CONFIG";
+ case WIFI_DIRECT_CMD_SEND_CONNECT_REQ:
+ return "WIFI_DIRECT_CMD_SEND_CONNECT_REQ";
+ case WIFI_DIRECT_CMD_ACTIVATE_PUSHBUTTON:
+ return "WIFI_DIRECT_CMD_ACTIVATE_PUSHBUTTON";
+ case WIFI_DIRECT_CMD_SET_WPS_PIN:
+ return "WIFI_DIRECT_CMD_SET_WPS_PIN";
+ case WIFI_DIRECT_CMD_GET_WPS_PIN:
+ return "WIFI_DIRECT_CMD_GET_WPS_PIN";
+ case WIFI_DIRECT_CMD_GENERATE_WPS_PIN:
+ return "WIFI_DIRECT_CMD_GENERATE_WPS_PIN";
+ case WIFI_DIRECT_CMD_SET_WPA:
+ return "WIFI_DIRECT_CMD_SET_WPA";
+ case WIFI_DIRECT_CMD_GET_SUPPORTED_WPS_MODE:
+ return "WIFI_DIRECT_CMD_GET_SUPPORTED_WPS_MODE";
+ case WIFI_DIRECT_CMD_GET_LOCAL_WPS_MODE:
+ return "WIFI_DIRECT_CMD_GET_LOCAL_WPS_MODE";
+ case WIFI_DIRECT_CMD_SET_REQ_WPS_MODE:
+ return "WIFI_DIRECT_CMD_SET_REQ_WPS_MODE";
+ case WIFI_DIRECT_CMD_GET_REQ_WPS_MODE:
+ return "WIFI_DIRECT_CMD_GET_REQ_WPS_MODE";
+ case WIFI_DIRECT_CMD_GET_CONNECTED_PEERS_INFO:
+ return "WIFI_DIRECT_CMD_GET_CONNECTED_PEERS_INFO";
+ case WIFI_DIRECT_CMD_DESTROY_GROUP:
+ return "WIFI_DIRECT_CMD_DESTROY_GROUP";
+ case WIFI_DIRECT_CMD_DISCONNECT:
+ return "WIFI_DIRECT_CMD_DISCONNECT";
+ case WIFI_DIRECT_CMD_SET_GO_INTENT:
+ return "WIFI_DIRECT_CMD_SET_GO_INTENT";
+ case WIFI_DIRECT_CMD_GET_GO_INTENT:
+ return "WIFI_DIRECT_CMD_GET_GO_INTENT";
+ case WIFI_DIRECT_CMD_GET_MAC_ADDR:
+ return "WIFI_DIRECT_CMD_GET_MAC_ADDR";
+ case WIFI_DIRECT_CMD_IS_AUTONOMOUS_GROUP:
+ return "WIFI_DIRECT_CMD_IS_AUTONOMOUS_GROUP";
+ case WIFI_DIRECT_CMD_SET_MAX_CLIENT:
+ return "WIFI_DIRECT_CMD_SET_MAX_CLIENT";
+ case WIFI_DIRECT_CMD_GET_MAX_CLIENT:
+ return "WIFI_DIRECT_CMD_GET_MAX_CLIENT";
+ case WIFI_DIRECT_CMD_SET_AUTOCONNECTION_MODE:
+ return "WIFI_DIRECT_CMD_SET_AUTOCONNECTION_MODE";
+ case WIFI_DIRECT_CMD_IS_AUTOCONNECTION_MODE:
+ return "WIFI_DIRECT_CMD_IS_AUTOCONNECTION_MODE";
+ case WIFI_DIRECT_CMD_IS_DISCOVERABLE:
+ return "WIFI_DIRECT_CMD_IS_DISCOVERABLE";
+ case WIFI_DIRECT_CMD_IS_LISTENING_ONLY:
+ return "WIFI_DIRECT_CMD_IS_LISTENING_ONLY";
+ case WIFI_DIRECT_CMD_GET_OPERATING_CHANNEL:
+ return "WIFI_DIRECT_CMD_GET_OPERATING_CHANNEL";
+ case WIFI_DIRECT_CMD_ACTIVATE_PERSISTENT_GROUP:
+ return "WIFI_DIRECT_CMD_ACTIVATE_PERSISTENT_GROUP";
+ case WIFI_DIRECT_CMD_DEACTIVATE_PERSISTENT_GROUP:
+ return "WIFI_DIRECT_CMD_DEACTIVATE_PERSISTENT_GROUP";
+ case WIFI_DIRECT_CMD_IS_PERSISTENT_GROUP:
+ return "WIFI_DIRECT_CMD_IS_PERSISTENT_GROUP";
+ case WIFI_DIRECT_CMD_GET_PERSISTENT_GROUP_INFO:
+ return "WIFI_DIRECT_CMD_GET_PERSISTENT_GROUP_INFO";
+ case WIFI_DIRECT_CMD_REMOVE_PERSISTENT_GROUP:
+ return "WIFI_DIRECT_CMD_REMOVE_PERSISTENT_GROUP";
+ case WIFI_DIRECT_CMD_GET_DEVICE_NAME:
+ return "WIFI_DIRECT_CMD_GET_DEVICE_NAME";
+ case WIFI_DIRECT_CMD_SET_DEVICE_NAME:
+ return "WIFI_DIRECT_CMD_SET_DEVICE_NAME";
+ case WIFI_DIRECT_CMD_SET_OEM_LOGLEVEL:
+ return "WIFI_DIRECT_CMD_SET_OEM_LOGLEVEL";
+ case WIFI_DIRECT_CMD_GET_PEER_INFO:
+ return "WIFI_DIRECT_CMD_GET_PEER_INFO";
+
+ case WIFI_DIRECT_CMD_SET_PASSPHRASE:
+ return "WIFI_DIRECT_CMD_SET_PASSPHRASE";
+ case WIFI_DIRECT_CMD_GET_PASSPHRASE:
+ return "WIFI_DIRECT_CMD_GET_PASSPHRASE";
+ case WIFI_DIRECT_CMD_SET_AUTOCONNECTION_PEER:
+ return "WIFI_DIRECT_CMD_SET_AUTOCONNECTION_PEER";
+
+#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
+ case WIFI_DIRECT_CMD_REGISTER_LOCAL_SERVICE:
+ return "WIFI_DIRECT_CMD_REGISTER_LOCAL_SERVICE";
+ case WIFI_DIRECT_CMD_DEREGISTER_LOCAL_SERVICE:
+ return "WIFI_DIRECT_CMD_DEREGISTER_LOCAL_SERVICE";
+ case WIFI_DIRECT_CMD_START_SERVICE_DISCOVERY:
+ return "WIFI_DIRECT_CMD_START_SERVICE_DISCOVERY";
+ case WIFI_DIRECT_CMD_CANCEL_SERVICE_DISCOVERY:
+ return "WIFI_DIRECT_CMD_CANCEL_SERVICE_DISCOVERY";
+#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+
+#ifdef TIZEN_FEATURE_WIFI_DISPLAY
+ case WIFI_DIRECT_CMD_INIT_MIRACAST:
+ return "WIFI_DIRECT_CMD_INIT_MIRACAST";
+ case WIFI_DIRECT_CMD_INIT_DISPLAY:
+ return "WIFI_DIRECT_CMD_INIT_DISPLAY";
+ case WIFI_DIRECT_CMD_DEINIT_DISPLAY:
+ return "WIFI_DIRECT_CMD_DEINIT_DISPLAY";
+ case WIFI_DIRECT_CMD_SET_DISPLAY:
+ return "WIFI_DIRECT_CMD_SET_DISPLAY";
+ case WIFI_DIRECT_CMD_SET_DISPLAY_AVAILABILITY:
+ return "WIFI_DIRECT_CMD_SET_DISPLAY_AVAILABILITY";
+ case WIFI_DIRECT_CMD_GET_PEER_DISPLAY_TYPE:
+ return "WIFI_DIRECT_CMD_GET_PEER_DISPLAY_TYPE";
+ case WIFI_DIRECT_CMD_GET_PEER_DISPLAY_AVAILABILITY:
+ return "WIFI_DIRECT_CMD_GET_PEER_DISPLAY_AVAILABILITY";
+ case WIFI_DIRECT_CMD_GET_PEER_DISPLAY_HDCP:
+ return "WIFI_DIRECT_CMD_GET_PEER_DISPLAY_HDCP";
+ case WIFI_DIRECT_CMD_GET_PEER_DISPLAY_PORT:
+ return "WIFI_DIRECT_CMD_GET_PEER_DISPLAY_PORT";
+ case WIFI_DIRECT_CMD_GET_PEER_DISPLAY_THROUGHPUT:
+ return "WIFI_DIRECT_CMD_GET_PEER_DISPLAY_THROUGHPUT";
+#endif /* TIZEN_FEATURE_WIFI_DISPLAY */
+ default:
+ return "WIFI_DIRECT_CMD_INVALID";
+
+ }
+}
+
+static int __wfd_client_check_socket(int sock, int timeout)
+{
+ struct pollfd p_fd;
+ int res = 0;
+
+ if (sock < 0 || timeout < 0) {
+ WDC_LOGE("Invalid parameter");
+ return -1;
+ }
+
+ p_fd.fd = sock;
+ p_fd.events = POLLIN | POLLERR | POLLHUP | POLLNVAL;
+ res = poll((struct pollfd *) &p_fd, 1, timeout);
+
+ if (res < 0) {
+ WDC_LOGE("Polling error from socket[%d]. [%s]", sock, strerror(errno));
+ return -1;
+ } else if (res == 0) {
+ WDC_LOGD( "poll timeout. socket is busy");
+ return 1;
+ } else {
+ if (p_fd.revents & POLLERR) {
+ WDC_LOGE("Error! POLLERR from socket[%d]", sock);
+ return -1;
+ } else if (p_fd.revents & POLLHUP) {
+ WDC_LOGE("Error! POLLHUP from socket[%d]", sock);
+ return -1;
+ } else if (p_fd.revents & POLLNVAL) {
+ WDC_LOGE("Error! POLLNVAL from socket[%d]", sock);
+ return -1;
+ } else if (p_fd.revents & POLLIN) {
+ WDC_LOGD("POLLIN from socket [%d]", sock);
+ return 0;
+ }
+ }
+
+ WDC_LOGD("Unknown poll event [%d]", p_fd.revents);
+ return -1;
+}
+
+static int __wfd_client_write_socket(int sockfd, void *data, int data_len)
+{
+ __WDC_LOG_FUNC_START__;
+ int wbytes = 0;
+
+ if (sockfd < 0 || !data || data_len <= 0) {
+ WDC_LOGE("Invalid parameter");
+ __WDC_LOG_FUNC_END__;
+ return -1;
+ }
+
+ WDC_LOGD("Write [%d] bytes to socket [%d].", data_len, sockfd);
+ wbytes = write(sockfd, (char*) data, data_len);
+ if (wbytes <= 0) {
+ WDC_LOGE("Error!!! writing to the socket. Error = %s", strerror(errno));
+ __WDC_LOG_FUNC_END__;
+ return -1;
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return 0;
+}
+
+static int __wfd_client_read_socket(int sockfd, char *data, int data_len)
+{
+ __WDC_LOG_FUNC_START__;
+ int rbytes = 0;
+ int total_rbytes = 0;
+ int res = 0;
+
+ if (sockfd < 0) {
+ WDC_LOGE("Error!!! Invalid socket FD [%d]", sockfd);
+ __WDC_LOG_FUNC_END__;
+ return -1;
+ }
+
+ if (!data || data_len <= 0) {
+ WDC_LOGE("Error!!! Invalid parameter");
+ __WDC_LOG_FUNC_END__;
+ return -1;
+ }
+
+ res = __wfd_client_check_socket(sockfd, 10000);
+ if (res < 0) {
+ WDC_LOGE("Socket error");
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ } else if (res > 0) {
+ WDC_LOGE("Socket is busy");
+ return WIFI_DIRECT_ERROR_RESOURCE_BUSY;
+ }
+
+ while(data_len) {
+ rbytes = read(sockfd, data, data_len);
+ if (rbytes <= 0) {
+ WDC_LOGE("Failed to read socket[%d] [%s]", sockfd, strerror(errno));
+ return -1;
+ }
+ total_rbytes += rbytes;
+ data += rbytes;
+ data_len -= rbytes;
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return total_rbytes;
+}
+
+static int __wfd_client_send_request(int sockfd, wifi_direct_client_request_s *req,
+ wifi_direct_client_response_s *rsp)
+{
+ __WDC_LOG_FUNC_START__;
+ int res = 0;
+
+ if (!req || !rsp || sockfd < 0) {
+ WDC_LOGE("Invalid parameter");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ pthread_mutex_lock(&g_client_info.mutex);
+ res = __wfd_client_write_socket(sockfd, req, sizeof(wifi_direct_client_request_s));
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Failed to write into socket [%s]", __wfd_print_error(res));
+ __wfd_reset_control();
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ WDC_LOGD("Succeeded to send request [%d: %s]", req->cmd, __wfd_client_print_cmd(req->cmd));
+
+ res = __wfd_client_read_socket(sockfd, (char*) rsp, sizeof(wifi_direct_client_response_s));
+ pthread_mutex_unlock(&g_client_info.mutex);
+ if (res <= 0) {
+ WDC_LOGE("Failed to read socket [%d]", res);
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if (rsp->cmd != req->cmd) {
+ WDC_LOGE("Invalid resp [%d], Original request [%d]", rsp->cmd, req->cmd);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if (rsp->result != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Result received [%s]", __wfd_print_error(rsp->result));
+ __WDC_LOG_FUNC_END__;
+ return rsp->result;
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+static gboolean __wfd_client_process_event(GIOChannel *source,
+ GIOCondition condition,
+ gpointer data)
+{
+ wfd_client_event_e event = WIFI_DIRECT_CLI_EVENT_INVALID;
+ wifi_direct_client_info_s *client = __wfd_get_control();
+ int sockfd = client->async_sockfd;
+ wifi_direct_client_noti_s client_noti;
+ wifi_direct_error_e error = WIFI_DIRECT_ERROR_NONE;
+ char param1[64] = { 0, };
+ char param2[256] = { 0, };
+#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
+ int service_type;
+#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+ int res = 0;
+
+ memset(&client_noti, 0, sizeof(wifi_direct_client_noti_s));
+
+ // 1.Read socket
+ res = __wfd_client_read_socket(sockfd, (char*) &client_noti,
+ sizeof(wifi_direct_client_noti_s));
+ if (res <= 0) {
+ WDC_LOGE("Error!!! Reading Async Event[%d]", sockfd);
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return false;
+ }
+ WDC_LOGD( "Received Event is [%d,%s], error[%d]", client_noti.event,
+ __wfd_print_event(client_noti.event), client_noti.error);
+
+ event = client_noti.event;
+ error = client_noti.error;
+#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
+ service_type = client_noti.type;
+#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+ memcpy(param1, client_noti.param1, sizeof(client_noti.param1));
+ memcpy(param2, client_noti.param2, sizeof(client_noti.param2));
+
+
+ // 2. dispatch event
+ switch (event) {
+ case WIFI_DIRECT_CLI_EVENT_ACTIVATION:
+ case WIFI_DIRECT_CLI_EVENT_DEACTIVATION:
+ if (!client->activation_cb) {
+ WDC_LOGE("activation_cb is NULL!!");
+ break;
+ }
+ client->activation_cb(error,
+ (wifi_direct_device_state_e) __wfd_convert_client_event(event),
+ client->user_data_for_cb_activation);
+ break;
+ case WIFI_DIRECT_CLI_EVENT_DISCOVER_FOUND_PEERS:
+ if (client->peer_found_cb) {
+ client->peer_found_cb(error,
+ (wifi_direct_discovery_state_e) __wfd_convert_client_event(event),
+ param1, client->user_data_for_cb_discover);
+ }
+ case WIFI_DIRECT_CLI_EVENT_DISCOVER_START:
+ case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_LISTEN_ONLY:
+ case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_SEARCH_LISTEN:
+ case WIFI_DIRECT_CLI_EVENT_DISCOVER_END:
+ if (!client->discover_cb) {
+ WDC_LOGE("discover_cb is NULL!!");
+ break;
+ }
+ client->discover_cb(error,
+ (wifi_direct_discovery_state_e) __wfd_convert_client_event(event),
+ client->user_data_for_cb_discover);
+ break;
+ case WIFI_DIRECT_CLI_EVENT_CONNECTION_START:
+ case WIFI_DIRECT_CLI_EVENT_CONNECTION_REQ:
+ case WIFI_DIRECT_CLI_EVENT_CONNECTION_RSP:
+ case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_RSP:
+ case WIFI_DIRECT_CLI_EVENT_CONNECTION_WPS_REQ:
+ case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_IND:
+ case WIFI_DIRECT_CLI_EVENT_DISASSOCIATION_IND:
+ case WIFI_DIRECT_CLI_EVENT_GROUP_CREATE_RSP:
+ case WIFI_DIRECT_CLI_EVENT_GROUP_DESTROY_RSP:
+ if (!client->connection_cb) {
+ WDC_LOGE("connection_cb is NULL!!");
+ break;
+ }
+ client->connection_cb(error,
+ (wifi_direct_connection_state_e) __wfd_convert_client_event(event),
+ param1, client->user_data_for_cb_connection);
+ break;
+
+ // ToDo: Handling IP lease event...
+ case WIFI_DIRECT_CLI_EVENT_IP_LEASED_IND:
+ if (!client->ip_assigned_cb) {
+ WDC_LOGE("ip_assigned_cb is NULL!!");
+ break;
+ }
+ char *ifname = NULL;
+ ifname = vconf_get_str(VCONFKEY_IFNAME);
+ if (!ifname) {
+ WDC_LOGD("vconf (%s) value is NULL!!!", VCONFKEY_IFNAME);
+ break;
+ }
+ WDC_LOGD("VCONFKEY_IFNAME(%s) : %s", VCONFKEY_IFNAME, ifname);
+ client->ip_assigned_cb(param1, param2, ifname,
+ client->user_data_for_cb_ip_assigned);
+ free(ifname);
+ break;
+
+#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
+ case WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_STARTED:
+ case WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_FOUND:
+ case WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_FINISHED:
+ if (!client->service_cb) {
+ WDC_LOGE("service_cb is NULL!!\n");
+ break;
+ }
+ client->service_cb(error,
+ (wifi_direct_service_discovery_state_e) __wfd_convert_client_event(event),
+ (wifi_direct_service_type_e) service_type, param2, param1, client->user_data_for_cb_service);
+ break;
+#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+
+ default:
+ break;
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return TRUE;
+}
+
+void __wfd_client_print_entry_list(wfd_discovery_entry_s *list, int num)
+{
+ int i = 0;
+
+ WDC_LOGD("------------------------------------------");
+ for (i = 0; i < num; i++)
+ {
+ WDC_LOGD("== Peer index : %d ==", i);
+ WDC_LOGD("is Group Owner ? %s", list[i].is_group_owner ? "YES" : "NO");
+ WDC_LOGD("device_name : %s", list[i].device_name);
+ WDC_LOGD("MAC address : "MACSECSTR, MAC2SECSTR(list[i].mac_address));
+ WDC_LOGD("wps cfg method : %x", list[i].wps_cfg_methods);
+ WDC_LOGD("Device Type: %d - %d", list[i].category, list[i].subcategory);
+ WDC_LOGD("Listen channel: %d", list[i].channel);
+ }
+ WDC_LOGD("------------------------------------------");
+}
+
+void __wfd_client_print_connected_peer_info(wfd_connected_peer_info_s *list, int num)
+{
+ int i = 0;
+
+ WDC_LOGD("------------------------------------------\n");
+ for (i = 0; i < num; i++) {
+ WDC_LOGD("== Peer index : %d ==\n", i);
+ WDC_LOGD("device_name : %s\n", list[i].device_name);
+ WDC_LOGD("Device MAC : " MACSECSTR "\n", MAC2SECSTR(list[i].mac_address));
+ WDC_LOGD("Device Type: %d - %d", list[i].category, list[i].subcategory);
+ WDC_LOGD("channel : %d\n", list[i].channel);
+ WDC_LOGD("IP ["IPSECSTR"]\n", IP2SECSTR(list[i].ip_address));
+ }
+ WDC_LOGD("------------------------------------------\n");
+}
+
+void __wfd_client_print_persistent_group_info(wfd_persistent_group_info_s *list, int num)
+{
+ int i = 0;
+
+ WDC_LOGD("------------------------------------------\n");
+ for (i = 0; i < num; i++) {
+ WDC_LOGD("== Persistent Group index : %d ==", i);
+ WDC_LOGD("ssid : %s", list[i].ssid);
+ WDC_LOGD("GO MAC : " MACSECSTR, MAC2SECSTR(list[i].go_mac_address));
+ }
+ WDC_LOGD("------------------------------------------\n");
+}
+
+static int __wfd_client_async_event_init(int clientid)
+{
+ __WDC_LOG_FUNC_START__;
+ int sockfd = 0;
+ struct sockaddr_un saddr;
+ wifi_direct_client_request_s req;
+ int res = 0;
+
+ sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (sockfd < 0) {
+ WDC_LOGE("Failed to async socket[%s]", strerror(errno));
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ WDC_LOGD("Succeeded to create async socket[%d]", sockfd);
+
+ memset(&saddr, 0, sizeof(saddr));
+ saddr.sun_family = AF_UNIX;
+ g_snprintf(saddr.sun_path, sizeof(saddr.sun_path), WFD_SOCK_FILE_PATH);
+
+ WDC_LOGD("Connecting to server socket to register async socket [%d]", sockfd);
+ res = connect(sockfd, (struct sockaddr *) &saddr, sizeof(saddr));
+ if (res < 0) {
+ WDC_LOGE("Error!!! connecting to server socket. Error = [%s].", strerror(errno));
+ close(sockfd);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+
+ req.cmd = WIFI_DIRECT_CMD_INIT_ASYNC_SOCKET;
+ req.client_id = clientid;
+
+ res = __wfd_client_write_socket(sockfd, &req, sizeof(wifi_direct_client_request_s));
+ if (res < WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Failed to write to socket[%s]", strerror(errno));
+ WDC_LOGE("Error!!! [%s]", __wfd_print_error(res));
+ close(sockfd);
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ g_client_info.async_sockfd = sockfd;
+
+ WDC_LOGE("Async socket is created= %d", sockfd);
+
+ return sockfd;
+}
+
+static int __wfd_client_launch_server_dbus(void)
+{
+ GDBusConnection *netconfig_bus = NULL;
+ GError *g_error = NULL;
+
+#if !GLIB_CHECK_VERSION(2,36,0)
+ g_type_init();
+#endif
+ netconfig_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &g_error);
+ if (netconfig_bus == NULL) {
+ if(g_error != NULL) {
+ WDC_LOGE("Couldn't connect to system bus "
+ "error [%d: %s]", g_error->code, g_error->message);
+ g_error_free(g_error);
+ }
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ g_dbus_connection_call_sync(netconfig_bus,
+ NETCONFIG_SERVICE,
+ NETCONFIG_WIFI_PATH,
+ NETCONFIG_WIFI_INTERFACE,
+ NETCONFIG_WIFI_LAUNCHDIRECT,
+ NULL,
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ DBUS_REPLY_TIMEOUT,
+ NULL,
+ &g_error);
+
+ if(g_error !=NULL) {
+ WDC_LOGE("g_dbus_connection_call_sync() failed"
+ "error [%d: %s]", g_error->code, g_error->message);
+ g_error_free(g_error);
+ return WIFI_DIRECT_ERROR_PERMISSION_DENIED;
+ }
+
+ g_object_unref(netconfig_bus);
+
+ WDC_LOGD("Successfully launched wfd-manager");
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_initialize(void)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ struct sockaddr_un saddr;
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s resp;
+ int retry_count = 10;
+ int sockfd = 0;
+ bool wifi_direct_enable;
+ int res = 0;
+
+ if (g_client_info.is_registered == TRUE) {
+ WDC_LOGW("Warning!!! Already registered\nUpdate user data and callback!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_ALREADY_INITIALIZED;
+ }
+
+/*TEMP: Hawk-P Tizen TV Platform does not support security check*/
+#if !defined TIZEN_TV
+ res = system_info_get_platform_bool("tizen.org/feature/network.wifi.direct", &wifi_direct_enable);
+ if (res < 0) {
+ WDC_LOGE("Failed to get sys info");
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ if(!wifi_direct_enable) {
+ WDC_LOGE("Wi-Fi Direct not supported");
+ return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
+ }
+
+#endif
+ sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (sockfd < 0) {
+ WDC_LOGE("Error!!! creating sync socket[%s]", strerror(errno));
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ WDC_LOGD("Created sync socket [%d]", sockfd);
+
+ memset(&saddr, 0, sizeof(saddr));
+ saddr.sun_family = AF_UNIX;
+ g_snprintf(saddr.sun_path, sizeof(saddr.sun_path), WFD_SOCK_FILE_PATH);
+
+ WDC_LOGD("Connecting to server socket to register sync socket [%d]", sockfd);
+ while (retry_count > 0) {
+ res = connect(sockfd, (struct sockaddr*) &saddr, sizeof(saddr));
+ if (!res){
+ WDC_LOGD("Succeeded to connect to server socket[%s]", strerror(errno));
+ break;
+ }
+
+ WDC_LOGD("Launching wfd-server..\n");
+ res = __wfd_client_launch_server_dbus();
+ if (res != WIFI_DIRECT_ERROR_NONE)
+ WDC_LOGE("Failed to send dbus msg[%s]", strerror(errno));
+ retry_count--;
+
+ /* wait a little before retrying the next socket connection */
+ usleep(150000);
+ }
+
+ if (res < 0) {
+ WDC_LOGE("Failed to connect to wfd-manager socket[%s]", strerror(errno));
+ close(sockfd);
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&resp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_REGISTER;
+ req.client_id = gettid();
+ WDC_LOGD("Client ID = %d", req.client_id);
+
+ res = __wfd_client_send_request(sockfd, &req, &resp);
+ if (res < 0) {
+ WDC_LOGE("Failed to register client");
+ close(sockfd);
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ g_client_info.sync_sockfd = sockfd;
+ g_client_info.client_id = resp.client_id;
+ g_client_info.is_registered = TRUE;
+
+ int async_sockfd = -1;
+ async_sockfd = __wfd_client_async_event_init(g_client_info.client_id);
+ if (async_sockfd < 0) {
+ WDC_LOGE("Failed to create async socket \n");
+ close(sockfd);
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ g_client_info.async_sockfd = async_sockfd;
+
+ GIOChannel *gio = g_io_channel_unix_new(g_client_info.async_sockfd);
+ int g_source_id = g_io_add_watch(gio, G_IO_IN | G_IO_ERR | G_IO_HUP,
+ (GIOFunc) __wfd_client_process_event, NULL);
+ g_io_channel_unref(gio);
+
+ g_client_info.g_source_id = g_source_id;
+
+ // Initialize callbacks
+ g_client_info.activation_cb = NULL;
+ g_client_info.discover_cb = NULL;
+ g_client_info.connection_cb = NULL;
+ g_client_info.ip_assigned_cb = NULL;
+
+ g_client_info.peer_found_cb = NULL;
+ g_client_info.user_data_for_cb_activation = NULL;
+ g_client_info.user_data_for_cb_discover = NULL;
+ g_client_info.user_data_for_cb_connection = NULL;
+ g_client_info.user_data_for_cb_ip_assigned = NULL;
+ g_client_info.user_data_for_cb_peer_found = NULL;
+ g_client_info.user_data_for_cb_device_name = NULL;
+
+#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
+ g_client_info.service_cb = NULL;
+ g_client_info.user_data_for_cb_service= NULL;
+#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_deinitialize(void)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ if (g_client_info.is_registered == false) {
+ WDC_LOGE("Client is already deregistered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ g_client_info.activation_cb = NULL;
+ g_client_info.discover_cb = NULL;
+ g_client_info.connection_cb = NULL;
+ g_client_info.ip_assigned_cb = NULL;
+ g_client_info.peer_found_cb = NULL;
+ g_client_info.user_data_for_cb_activation = NULL;
+ g_client_info.user_data_for_cb_discover = NULL;
+ g_client_info.user_data_for_cb_connection = NULL;
+ g_client_info.user_data_for_cb_ip_assigned = NULL;
+ g_client_info.user_data_for_cb_peer_found = NULL;
+
+#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
+ g_client_info.service_cb = NULL;
+ g_client_info.user_data_for_cb_service = NULL;
+#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_DEREGISTER;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res < 0)
+ WDC_LOGD("Failed to deinitialize. But continue deinitialization");
+ else
+ WDC_LOGD("Deinit Successfull");
+
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_set_device_state_changed_cb(wifi_direct_device_state_changed_cb cb,
+ void *user_data)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ if (!cb) {
+ WDC_LOGE("Invalid parameter");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (g_client_info.is_registered == false) {
+ WDC_LOGE("Client is not initialized.");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ g_client_info.activation_cb = cb;
+ g_client_info.user_data_for_cb_activation = user_data;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_unset_device_state_changed_cb(void)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ if (g_client_info.is_registered == false) {
+ WDC_LOGE("Client is not initialized.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ g_client_info.activation_cb = NULL;
+ g_client_info.user_data_for_cb_activation = NULL;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int
+wifi_direct_set_discovery_state_changed_cb(wifi_direct_discovery_state_chagned_cb cb,
+ void *user_data)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ if (!cb) {
+ WDC_LOGE("Callback is NULL.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (g_client_info.is_registered == false) {
+ WDC_LOGE("Client is not initialized.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ g_client_info.discover_cb = cb;
+ g_client_info.user_data_for_cb_discover = user_data;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_unset_discovery_state_changed_cb(void)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ if (g_client_info.is_registered == false) {
+ WDC_LOGE("Client is not initialized.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ g_client_info.discover_cb = NULL;
+ g_client_info.user_data_for_cb_discover = NULL;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int
+wifi_direct_set_peer_found_cb(wifi_direct_peer_found_cb cb,
+ void *user_data)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ if (!cb) {
+ WDC_LOGE("Callback is NULL.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (g_client_info.is_registered == false) {
+ WDC_LOGE("Client is not initialized.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ g_client_info.peer_found_cb = cb;
+ g_client_info.user_data_for_cb_peer_found = user_data;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_unset_peer_found_cb(void)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ if (g_client_info.is_registered == false) {
+ WDC_LOGE("Client is not initialized.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ g_client_info.peer_found_cb = NULL;
+ g_client_info.user_data_for_cb_peer_found = NULL;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_set_service_state_changed_cb
+(wifi_direct_service_state_changed_cb cb, void *user_data)
+{
+#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
+
+ if (!cb) {
+ WDC_LOGE("Callback is NULL.");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (g_client_info.is_registered == false) {
+ WDC_LOGE("Client is not initialized.");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ g_client_info.service_cb = cb;
+ g_client_info.user_data_for_cb_service = user_data;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+#else /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+ return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
+#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+}
+
+
+int wifi_direct_unset_service_state_changed_cb(void)
+{
+#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
+
+ if (g_client_info.is_registered == false) {
+ WDC_LOGE("Client is not initialized.");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ g_client_info.service_cb = NULL;
+ g_client_info.user_data_for_cb_service = NULL;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+#else /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+ return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
+#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+}
+
+int wifi_direct_set_connection_state_changed_cb(wifi_direct_connection_state_changed_cb cb,
+ void *user_data)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ if (!cb) {
+ WDC_LOGE("Callback is NULL.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (g_client_info.is_registered == false) {
+ WDC_LOGE("Client is not initialized.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ g_client_info.connection_cb = cb;
+ g_client_info.user_data_for_cb_connection = user_data;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_unset_connection_state_changed_cb(void)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ if (g_client_info.is_registered == false) {
+ WDC_LOGE("Client is not initialized");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ g_client_info.connection_cb = NULL;
+ g_client_info.user_data_for_cb_connection = NULL;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_set_client_ip_address_assigned_cb(wifi_direct_client_ip_address_assigned_cb cb,
+ void* user_data)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ if (!cb) {
+ WDC_LOGE("Callback is NULL");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (g_client_info.is_registered == false) {
+ WDC_LOGE("Client is not initialized");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ g_client_info.ip_assigned_cb = cb;
+ g_client_info.user_data_for_cb_ip_assigned = user_data;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_unset_client_ip_address_assigned_cb(void)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ if (g_client_info.is_registered == false) {
+ WDC_LOGE("Client is not initialized");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ g_client_info.ip_assigned_cb = NULL;
+ g_client_info.user_data_for_cb_ip_assigned = NULL;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_activate(void)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_ACTIVATE;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_activate() SUCCESS");
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_deactivate(void)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_DEACTIVATE;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_deactivate() SUCCESS");
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_start_discovery(bool listen_only, int timeout)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (timeout < 0) {
+ WDC_LOGE("Nagative value. Param [timeout]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_START_DISCOVERY;
+ req.client_id = g_client_info.client_id;
+ req.data.int1 = listen_only;
+ req.data.int2 = timeout;
+ WDC_LOGE("listen only (%d) timeout (%d)", listen_only, timeout);
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_start_discovery() SUCCESS");
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_start_discovery_specific_channel(bool listen_only, int timeout, wifi_direct_discovery_channel_e channel)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (timeout < 0) {
+ WDC_LOGE("Nagative value. Param [timeout]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_START_DISCOVERY_SPECIFIC_CHANNEL;
+ req.client_id = g_client_info.client_id;
+ req.data.int1 = timeout;
+ req.data.int2 = channel;
+
+ WDC_LOGD("timeout (%d) channel (%d)", timeout, channel);
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_start_discovery_specific_channel() SUCCESS");
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_cancel_discovery(void)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_CANCEL_DISCOVERY;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_cancel_discovery() SUCCESS");
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
+static char **get_service_list(char *services, unsigned int *count)
+{
+ __WDC_LOG_FUNC_START__;
+ char **result = NULL;
+ char *pos1 = NULL;
+ char *pos2 = NULL;
+ unsigned int cnt = 0;
+ unsigned int i = 0;
+ unsigned int j = 0;
+
+ if (!count || !services || (services && strlen(services) <= 0)) {
+ WDC_LOGE("Invalid parameters.");
+ __WDC_LOG_FUNC_END__;
+ return NULL;
+ }
+
+ pos1 = services;
+ pos2 = g_strdup(services);
+
+ pos1 = strtok (pos1,",\n");
+ while (pos1) {
+ cnt++;
+ pos1 = strtok (NULL, ",\n");
+ }
+ WDC_LOGD("Total Service Count = %d", cnt);
+
+ if (cnt > 0) {
+ result = (char**) g_try_malloc0_n(cnt, sizeof(char *));
+ if (!result) {
+ WDC_LOGE("Failed to allocate memory for result");
+ g_free(pos2);
+ return NULL;
+ }
+ pos2 = strtok (pos2,",\n");
+ while (pos2 != NULL) {
+ char *s = strchr(pos2, ' ');
+ if (s) {
+ *s = '\0';
+ result[i++] = strdup(pos2);
+ pos2 = strtok (NULL, ",\n");
+ }
+ }
+ }
+
+ g_free(pos1);
+ g_free(pos2);
+
+ if (cnt == i) {
+ *count = cnt;
+ return result;
+ } else {
+ *count = 0;
+ if (result) {
+ for (j=0; j<i && result[j] != NULL; j++)
+ free(result[j]);
+ free(result);
+ }
+ return NULL;
+ }
+}
+#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+
+int wifi_direct_foreach_discovered_peers(wifi_direct_discovered_peer_cb cb,
+ void *user_data)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+ int i;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!cb) {
+ WDC_LOGE("NULL Param [callback]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_DISCOVERY_RESULT;
+ req.client_id = g_client_info.client_id;
+
+ pthread_mutex_lock(&g_client_info.mutex);
+ res = __wfd_client_write_socket(g_client_info.sync_sockfd, &req, sizeof(wifi_direct_client_request_s));
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Failed to write into socket [%s]", __wfd_print_error(res));
+ __wfd_reset_control();
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ WDC_LOGD("Succeeded to send request [%d: %s]", req.cmd, __wfd_client_print_cmd(req.cmd));
+
+ res = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) &rsp,
+ sizeof(wifi_direct_client_response_s));
+ if (res <= 0) {
+ WDC_LOGE("Failed to read socket [%d]", res);
+ __wfd_reset_control();
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if (rsp.cmd != req.cmd) {
+ WDC_LOGE("Invalid resp [%d]", rsp.cmd);
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Result received [%s]", __wfd_print_error(rsp.result));
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+
+ short num = rsp.param1;
+ short num_tmp = 0;
+ wfd_discovery_entry_s *buff = NULL;
+ wfd_discovery_entry_s *buff_tmp = NULL;
+
+ WDC_LOGD("Num of found peers = %d", num);
+
+ if (num > 1023) {
+ WDC_LOGE("Discovered peer number restricted by 255(real number:%d)", num);
+ num_tmp = num -1023;
+ num = 1023;
+ }
+
+ if (num > 0) {
+ buff = (wfd_discovery_entry_s*) g_try_malloc0_n(num, sizeof (wfd_discovery_entry_s));
+ if (!buff) {
+ WDC_LOGE("Failed to alloc memory");
+ pthread_mutex_unlock(&g_client_info.mutex);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ res = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) buff,
+ num * sizeof(wfd_discovery_entry_s));
+ if (num_tmp) {
+ WDC_LOGD("Rest data should be read out");
+ buff_tmp = (wfd_discovery_entry_s*) g_try_malloc0_n(num_tmp, sizeof (wfd_discovery_entry_s));
+ if (buff_tmp) {
+ __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) buff_tmp,
+ num_tmp * sizeof(wfd_discovery_entry_s));
+ g_free(buff_tmp);
+ }
+ }
+ pthread_mutex_unlock(&g_client_info.mutex);
+ if (res <= 0) {
+ free(buff);
+ WDC_LOGE("Failed to read socket");
+ __wfd_reset_control();
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ __wfd_client_print_entry_list(buff, num);
+ WDC_LOGD("wifi_direct_foreach_discovered_peers() SUCCESS");
+
+ wifi_direct_discovered_peer_info_s *peer_list;
+
+ for (i = 0; i < num; i++) {
+ peer_list = (wifi_direct_discovered_peer_info_s *) g_try_malloc0(sizeof(wifi_direct_discovered_peer_info_s));
+ peer_list->device_name = g_strndup(buff[i].device_name, WIFI_DIRECT_MAX_DEVICE_NAME_LEN+1);
+ peer_list->mac_address = (char*) g_try_malloc0(MACSTR_LEN);
+ g_snprintf(peer_list->mac_address, MACSTR_LEN, MACSTR, MAC2STR(buff[i].mac_address));
+ peer_list->interface_address = (char*) g_try_malloc0(MACSTR_LEN);
+ g_snprintf(peer_list->interface_address, MACSTR_LEN, MACSTR, MAC2STR(buff[i].intf_address));
+ peer_list->channel = buff[i].channel;
+ peer_list->is_connected = buff[i].is_connected;
+ peer_list->is_group_owner = buff[i].is_group_owner;
+ peer_list->is_persistent_group_owner = buff[i].is_persistent_go;
+ peer_list->primary_device_type = buff[i].category;
+ peer_list->secondary_device_type = buff[i].subcategory;
+ peer_list->supported_wps_types= buff[i].wps_cfg_methods;
+#ifdef TIZEN_FEATURE_WIFI_DISPLAY
+ peer_list->is_miracast_device = buff[i].is_wfd_device;
+#endif /* TIZEN_FEATURE_WIFI_DISPLAY */
+
+ if (!cb(peer_list, user_data))
+ break;
+ }
+
+ g_free(buff);
+ } else {
+ pthread_mutex_unlock(&g_client_info.mutex);
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_connect(char *mac_address)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ unsigned char la_mac_addr[6];
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!mac_address) {
+ WDC_LOGE("mac_addr is NULL");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_CONNECT;
+ req.client_id = g_client_info.client_id;
+ macaddr_atoe(mac_address, la_mac_addr);
+ memcpy(req.data.mac_addr, la_mac_addr, MACADDR_LEN);
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_connect() SUCCESS");
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_cancel_connection(char *mac_address)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false)
+ || (g_client_info.client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!mac_address) {
+ WDC_LOGE("mac_addr is NULL");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_CANCEL_CONNECTION;
+ req.client_id = g_client_info.client_id;
+ macaddr_atoe(mac_address, req.data.mac_addr);
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_cancel_connect() SUCCESS");
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_reject_connection(char *mac_address)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!mac_address) {
+ WDC_LOGE("mac_addr is NULL");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_REJECT_CONNECTION;
+ req.client_id = g_client_info.client_id;
+ macaddr_atoe(mac_address, req.data.mac_addr);
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGE("wifi_direct_reject_connection() SUCCESS");
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_disconnect_all(void)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_DISCONNECT_ALL;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGE("wifi_direct_disconnect_all() SUCCESS");
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_disconnect(char *mac_address)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ unsigned char la_mac_addr[6];
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!mac_address) {
+ WDC_LOGE("mac_address is NULL");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_DISCONNECT;
+ req.client_id = g_client_info.client_id;
+ macaddr_atoe(mac_address, la_mac_addr);
+ memcpy(req.data.mac_addr, la_mac_addr, 6);
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGE("wifi_direct_disconnect() SUCCESS");
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+
+}
+
+int wifi_direct_accept_connection(char *mac_address)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ unsigned char la_mac_addr[6];
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!mac_address) {
+ WDC_LOGE("mac_addr is NULL");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_SEND_CONNECT_REQ;
+ req.client_id = g_client_info.client_id;
+ macaddr_atoe(mac_address, la_mac_addr);
+ memcpy(req.data.mac_addr, la_mac_addr, 6);
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGE("wifi_direct_connect() SUCCESS \n");
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_foreach_connected_peers(wifi_direct_connected_peer_cb cb,
+ void *user_data)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+ int i;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!cb) {
+ WDC_LOGE("NULL Param [callback]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_CONNECTED_PEERS_INFO;
+ req.client_id = g_client_info.client_id;
+
+ pthread_mutex_lock(&g_client_info.mutex);
+ res = __wfd_client_write_socket(g_client_info.sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Failed to write into socket [%s]", __wfd_print_error(res));
+ __wfd_reset_control();
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ WDC_LOGD("Succeeded to send request [%d: %s]", req.cmd, __wfd_client_print_cmd(req.cmd));
+
+ res = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) &rsp,
+ sizeof(wifi_direct_client_response_s));
+ if (res <= 0) {
+ WDC_LOGE("Failed to read socket [%d]", res);
+ __wfd_reset_control();
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if (rsp.cmd != req.cmd) {
+ WDC_LOGE("Invalid resp [%d]", rsp.cmd);
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Result received [%s]", __wfd_print_error(rsp.result));
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+
+ short num = rsp.param1;
+ wfd_connected_peer_info_s *buff = NULL;
+
+ WDC_LOGD("Num of connected peers = %d", (int) rsp.param1);
+
+ if (num > 8 || num < 1) {
+ WDC_LOGE("Invalid number of connected peer(%d)", num);
+ buff = (wfd_connected_peer_info_s*) g_try_malloc0_n(num, sizeof(wfd_connected_peer_info_s));
+ if (!buff) {
+ WDC_LOGE("malloc() failed!!!");
+ pthread_mutex_unlock(&g_client_info.mutex);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ res= __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) buff,
+ num * sizeof(wfd_connected_peer_info_s));
+ pthread_mutex_unlock(&g_client_info.mutex);
+ } else if (num < 1) {
+ WDC_LOGE("Invalid number of connected peer(%d)", num);
+ pthread_mutex_unlock(&g_client_info.mutex);
+ } else {
+ buff = (wfd_connected_peer_info_s*) g_try_malloc0_n(num, sizeof(wfd_connected_peer_info_s));
+ if (!buff) {
+ WDC_LOGE("malloc() failed!!!");
+ pthread_mutex_unlock(&g_client_info.mutex);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ res= __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) buff,
+ num * sizeof(wfd_connected_peer_info_s));
+ pthread_mutex_unlock(&g_client_info.mutex);
+ if (res <= 0) {
+ free(buff);
+ WDC_LOGE("socket read error");
+ __wfd_reset_control();
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ __wfd_client_print_connected_peer_info(buff, num);
+ WDC_LOGD("wifi_direct_foreach_connected_peers() SUCCESS");
+
+ wifi_direct_connected_peer_info_s *peer_list = NULL;
+
+ for (i = 0; i < num; i++) {
+ peer_list = (wifi_direct_connected_peer_info_s *) g_try_malloc0(sizeof(wifi_direct_connected_peer_info_s));
+ peer_list->device_name = g_strdup(buff[i].device_name);
+ peer_list->ip_address= (char*) g_try_malloc0(IPSTR_LEN);
+ g_snprintf(peer_list->ip_address, IPSTR_LEN, IPSTR, IP2STR(buff[i].ip_address));
+ peer_list->mac_address = (char*) calloc(1, MACSTR_LEN);
+ g_snprintf(peer_list->mac_address, MACSTR_LEN, MACSTR, MAC2STR(buff[i].mac_address));
+ peer_list->interface_address = (char*) g_try_malloc0( MACSTR_LEN);
+ g_snprintf(peer_list->interface_address, MACSTR_LEN, MACSTR, MAC2STR(buff[i].intf_address));
+ peer_list->p2p_supported = buff[i].is_p2p;
+ peer_list->primary_device_type = buff[i].category;
+ peer_list->secondary_device_type = buff[i].subcategory;
+ peer_list->channel = buff[i].channel;
+#ifdef TIZEN_FEATURE_WIFI_DISPLAY
+ peer_list->is_miracast_device = buff[i].is_wfd_device;
+#endif /* TIZEN_FEATURE_WIFI_DISPLAY */
+
+ if (!cb(peer_list, user_data))
+ break;
+ }
+ g_free(buff);
+ buff = NULL;
+ }
+ g_free(buff);
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_create_group(void)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_CREATE_GROUP;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGE("wifi_direct_create_group() SUCCESS \n");
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_destroy_group(void)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_DESTROY_GROUP;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGE("wifi_direct_destroy_group() SUCCESS");
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_is_group_owner(bool *owner)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!owner) {
+ WDC_LOGE("NULL Param [owner]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_IS_GROUPOWNER;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_is_group_owner() SUCCESS");
+ *owner = (bool) rsp.param1;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_is_autonomous_group(bool *autonomous_group)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!autonomous_group) {
+ WDC_LOGE("NULL Param [autonomous_group]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_IS_AUTONOMOUS_GROUP;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_is_autonomous_group() SUCCESS");
+ *autonomous_group = (bool) rsp.param1;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_set_group_owner_intent(int intent)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (intent < 0 || intent > 15) {
+ WDC_LOGE("Invalid Param : intent[%d]", intent);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_SET_GO_INTENT;
+ req.client_id = g_client_info.client_id;
+ req.data.int1 = intent;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_set_group_owner_intent() SUCCESS");
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_get_group_owner_intent(int *intent)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!intent) {
+ WDC_LOGE("Invalid Parameter");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_GO_INTENT;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("int wifi_direct_get_group_owner_intent() intent[%d] SUCCESS", rsp.param1);
+ *intent = rsp.param1;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_set_max_clients(int max)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+ WDC_LOGD("max client [%d]\n", max);
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_SET_MAX_CLIENT;
+ req.client_id = g_client_info.client_id;
+ req.data.int1 = max;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("int wifi_direct_set_max_clients() SUCCESS");
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_get_max_clients(int *max)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!max) {
+ WDC_LOGE("Invalid Parameter");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_MAX_CLIENT;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("int wifi_direct_get_max_clients() max_client[%d] SUCCESS", rsp.param1);
+ *max = rsp.param1;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_get_operating_channel(int *channel)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!channel) {
+ WDC_LOGE("NULL Param [channel]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_OPERATING_CHANNEL;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("channel = [%d]", (int) rsp.param1);
+ *channel = rsp.param1;
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+
+}
+
+int wifi_direct_activate_pushbutton(void)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_ACTIVATE_PUSHBUTTON;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_activate_pushbutton() SUCCESS");
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_set_wps_pin(char *pin)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int status = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!pin) {
+ WDC_LOGE("NULL Param [pin]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+ WDC_LOGE("pin = [%s]\n", pin);
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_SET_WPS_PIN;
+ req.client_id = g_client_info.client_id;
+ req.cmd_data_len = WIFI_DIRECT_WPS_PIN_LEN+1;
+
+ pthread_mutex_lock(&g_client_info.mutex);
+ status = __wfd_client_write_socket(g_client_info.sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Error!!! writing to socket[%s]", __wfd_print_error(status));
+ __wfd_reset_control();
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ WDC_LOGD("writing msg hdr is success!\n");
+
+ status = __wfd_client_write_socket(g_client_info.sync_sockfd, pin,
+ WIFI_DIRECT_WPS_PIN_LEN);
+ if (status != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Error!!! writing to socket[%s]", __wfd_print_error(status));
+ __wfd_reset_control();
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ status = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) &rsp,
+ sizeof(wifi_direct_client_response_s));
+ pthread_mutex_unlock(&g_client_info.mutex);
+ if (status <= 0) {
+ WDC_LOGE("Error!!! reading socket, status = %d", status);
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if (rsp.cmd != req.cmd) {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d", rsp.cmd);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGD("Error!!! Result received = %d", rsp.result);
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_get_wps_pin(char **pin)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ char la_pin[WIFI_DIRECT_WPS_PIN_LEN + 1] = { 0, };
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_WPS_PIN;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_get_wps_pin() SUCCESS");
+ g_strlcpy(la_pin, rsp.param2, WIFI_DIRECT_WPS_PIN_LEN +1);
+ *pin = g_strdup(la_pin);
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_get_supported_wps_mode(int *wps_mode)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!wps_mode) {
+ WDC_LOGE("NULL Param [wps_mode]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_SUPPORTED_WPS_MODE;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("Supported wps config = [%d]", (int) rsp.param1);
+ *wps_mode = rsp.param1;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_foreach_supported_wps_types(wifi_direct_supported_wps_type_cb cb, void* user_data)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!cb) {
+ WDC_LOGE("NULL Param [callback]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_SUPPORTED_WPS_MODE;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("Supported wps config = [%d]", (int) rsp.param1);
+
+ int wps_mode;
+ bool result = TRUE;
+
+ wps_mode = rsp.param1;
+ if (wps_mode & WIFI_DIRECT_WPS_TYPE_PBC)
+ result = cb(WIFI_DIRECT_WPS_TYPE_PBC, user_data);
+ if ((result == true) && (wps_mode & WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY))
+ result = cb(WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY, user_data);
+ if ((result == true) && (wps_mode & WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD))
+ result = cb(WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD, user_data);
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_get_local_wps_type(wifi_direct_wps_type_e *type)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (type == NULL) {
+ WDC_LOGE("NULL Param [type]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_LOCAL_WPS_MODE;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_get_wps_type() SUCCESS");
+ *type = rsp.param1;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_set_req_wps_type(wifi_direct_wps_type_e type)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (type == WIFI_DIRECT_WPS_TYPE_PBC ||
+ type == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY ||
+ type == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) {
+ WDC_LOGD("Param wps_mode [%d]", type);
+ } else {
+ WDC_LOGE("Invalid Param [wps_mode]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_SET_REQ_WPS_MODE;
+ req.client_id = g_client_info.client_id;
+ req.data.int1 = type;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_set_req_wps_type() SUCCESS");
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_get_req_wps_type(wifi_direct_wps_type_e *type)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (type == NULL) {
+ WDC_LOGE("NULL Param [type]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_REQ_WPS_MODE;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_get_req_wps_type() SUCCESS");
+ *type = rsp.param1;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_get_ssid(char **ssid)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ char la_ssid[WIFI_DIRECT_MAX_SSID_LEN + 1] = { 0, };
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!ssid) {
+ WDC_LOGE("NULL Param [ssid]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_SSID;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_get_ssid() %s SUCCESS", rsp.param2);
+ g_strlcpy(la_ssid, rsp.param2, WIFI_DIRECT_MAX_SSID_LEN + 1);
+ *ssid = g_strdup(la_ssid);
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_get_device_name(char **device_name)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ char la_device_name[WIFI_DIRECT_MAX_DEVICE_NAME_LEN + 1] = { 0, };
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!device_name) {
+ WDC_LOGE("NULL Param [device_name]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_DEVICE_NAME;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_get_device_name() %s SUCCESS \n", rsp.param2);
+ g_strlcpy(la_device_name, rsp.param2, WIFI_DIRECT_MAX_DEVICE_NAME_LEN + 1);
+ *device_name = g_strdup(la_device_name);
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_set_device_name(const char *device_name)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int status = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!device_name) {
+ WDC_LOGE("NULL Param [device_name]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+ WDC_LOGE("device_name = [%s]", device_name);
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_SET_DEVICE_NAME;
+ req.client_id = g_client_info.client_id;
+
+ pthread_mutex_lock(&g_client_info.mutex);
+ status = __wfd_client_write_socket(g_client_info.sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Error!!! writing to socket[%s]", __wfd_print_error(status));
+ __wfd_reset_control();
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ WDC_LOGD( "writing msg hdr is success!\n");
+
+ status = __wfd_client_write_socket(g_client_info.sync_sockfd, (void*) device_name,
+ WIFI_DIRECT_MAX_DEVICE_NAME_LEN);
+ if (status != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Error!!! writing to socket[%s]", __wfd_print_error(status));
+ __wfd_reset_control();
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ status = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) &rsp,
+ sizeof(wifi_direct_client_response_s));
+ pthread_mutex_unlock(&g_client_info.mutex);
+ if (status <= 0) {
+ WDC_LOGE("Error!!! reading socket, status = %d", status);
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ } else {
+ if (rsp.cmd == WIFI_DIRECT_CMD_SET_DEVICE_NAME) {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Error!!! Result received = %d", rsp.result);
+ WDC_LOGE("Error!!! [%s]", __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ } else {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d", rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_get_network_interface_name(char **name)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_state_e status = 0;
+ char *get_str = NULL;
+ int result;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!name) {
+ WDC_LOGE("NULL Param [name]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ result = wifi_direct_get_state(&status);
+ WDC_LOGD("wifi_direct_get_state() state=[%d], result=[%d]\n", status, result);
+
+ if (status < WIFI_DIRECT_STATE_CONNECTED) {
+ WDC_LOGE("Device is not connected!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_PERMITTED;
+ }
+
+ get_str = vconf_get_str(VCONFKEY_IFNAME);
+ if (!get_str) {
+ WDC_LOGD( "vconf (%s) value is NULL!!!\n", VCONFKEY_IFNAME);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_PERMITTED;
+ }
+ WDC_LOGD( "VCONFKEY_IFNAME(%s) : %s\n", VCONFKEY_IFNAME, get_str);
+ *name = g_strdup(get_str);
+ g_free(get_str);
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_get_ip_address(char **ip_address)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = 0;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!ip_address) {
+ WDC_LOGE("NULL Param [ip_address]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_IP_ADDR;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ *ip_address = g_strdup(rsp.param2);
+ WDC_LOGD("IP address = [%s]", *ip_address);
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_get_subnet_mask(char **subnet_mask)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_state_e status = 0;
+ char *get_str = NULL;
+ int result;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!subnet_mask) {
+ WDC_LOGE("NULL Param [subnet_mask]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ result = wifi_direct_get_state(&status);
+ WDC_LOGD("wifi_direct_get_state() state=[%d], result=[%d]", status, result);
+ if( status < WIFI_DIRECT_STATE_CONNECTED) {
+ WDC_LOGE("Device is not connected!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_PERMITTED;
+ }
+
+ get_str = vconf_get_str(VCONFKEY_SUBNET_MASK);
+ if (!get_str) {
+ WDC_LOGD("vconf (%s) value is NULL!!!", VCONFKEY_SUBNET_MASK);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_PERMITTED;
+ }
+ WDC_LOGD("VCONFKEY_SUBNET_MASK(%s) : %s", VCONFKEY_SUBNET_MASK, get_str);
+ *subnet_mask = g_strdup(get_str);
+ g_free(get_str);
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_get_gateway_address(char **gateway_address)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_state_e status = 0;
+ char *get_str = NULL;
+ int result;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!gateway_address) {
+ WDC_LOGE("NULL Param [gateway_address]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ result = wifi_direct_get_state(&status);
+ WDC_LOGD("wifi_direct_get_state() state=[%d], result=[%d]", status, result);
+ if(status < WIFI_DIRECT_STATE_CONNECTED) {
+ WDC_LOGE("Device is not connected!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_PERMITTED;
+ }
+
+ get_str = vconf_get_str(VCONFKEY_GATEWAY);
+ if (!get_str) {
+ WDC_LOGD("vconf (%s) value is NULL!!!", VCONFKEY_GATEWAY);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_PERMITTED;
+ }
+ WDC_LOGD("VCONFKEY_GATEWAY(%s) : %s", VCONFKEY_GATEWAY, get_str);
+ *gateway_address = g_strdup(get_str);
+ g_free(get_str);
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_get_mac_address(char **mac_address)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!mac_address) {
+ WDC_LOGE("NULL Param [mac_address]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_MAC_ADDR;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ *mac_address = g_strdup(rsp.param2);
+ WDC_SECLOGD("MAC address = [%s]", *mac_address);
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_get_state(wifi_direct_state_e *state)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if (!state) {
+ WDC_LOGE("NULL Param [state]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_LINK_STATUS;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("Link Status = %d", (int) rsp.param1);
+ *state = (wifi_direct_state_e) rsp.param1;
+
+ /* for CAPI : there is no WIFI_DIRECT_STATE_GROUP_OWNER type in CAPI */
+ if(*state == WIFI_DIRECT_STATE_GROUP_OWNER)
+ *state = WIFI_DIRECT_STATE_CONNECTED;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_is_discoverable(bool* discoverable)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!discoverable) {
+ WDC_LOGE("NULL Param [discoverable]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_IS_DISCOVERABLE;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_is_discoverable() SUCCESS");
+ *discoverable = (bool) rsp.param1;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_is_listening_only(bool* listen_only)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!listen_only) {
+ WDC_LOGE("NULL Param [listen_only]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_IS_LISTENING_ONLY;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_is_listening_only() SUCCESS");
+ *listen_only = (bool) rsp.param1;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_get_primary_device_type(wifi_direct_primary_device_type_e* type)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ if (!type) {
+ WDC_LOGE("NULL Param [type]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ WDC_LOGD("Current primary_dev_type [%d]", WIFI_DIRECT_PRIMARY_DEVICE_TYPE_TELEPHONE);
+ *type = WIFI_DIRECT_PRIMARY_DEVICE_TYPE_TELEPHONE;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_get_secondary_device_type(wifi_direct_secondary_device_type_e* type)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (NULL == type) {
+ WDC_LOGE("NULL Param [type]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ WDC_LOGD("Current second_dev_type [%d]", WIFI_DIRECT_SECONDARY_DEVICE_TYPE_TELEPHONE_SMARTPHONE_DUAL);
+ *type = WIFI_DIRECT_SECONDARY_DEVICE_TYPE_TELEPHONE_SMARTPHONE_DUAL; // smart phone dual mode (wifi and cellular)
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_set_autoconnection_mode(bool mode)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_SET_AUTOCONNECTION_MODE;
+ req.client_id = g_client_info.client_id;
+ req.data.int1 = mode;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_is_autoconnection_mode(bool *mode)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!mode) {
+ WDC_LOGE("NULL Param [mode]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_IS_AUTOCONNECTION_MODE;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_is_autoconnection_mode() SUCCESS");
+ *mode = (bool) rsp.param1;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+
+}
+
+
+int wifi_direct_set_persistent_group_enabled(bool enabled)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ if (enabled == true)
+ req.cmd = WIFI_DIRECT_CMD_ACTIVATE_PERSISTENT_GROUP;
+ else
+ req.cmd = WIFI_DIRECT_CMD_DEACTIVATE_PERSISTENT_GROUP;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_set_persistent_group_enabled() SUCCESS");
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_is_persistent_group_enabled(bool *enabled)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!enabled) {
+ WDC_LOGE("NULL Param [enabled]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_IS_PERSISTENT_GROUP;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_is_persistent_group_enabled() SUCCESS");
+ *enabled = (bool) rsp.param1;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_foreach_persistent_groups(wifi_direct_persistent_group_cb cb,
+ void* user_data)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+ int i;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!cb) {
+ WDC_LOGE("NULL Param [callback]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_PERSISTENT_GROUP_INFO;
+ req.client_id = g_client_info.client_id;
+
+ pthread_mutex_lock(&g_client_info.mutex);
+ res = __wfd_client_write_socket(g_client_info.sync_sockfd, &req, sizeof(wifi_direct_client_request_s));
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Failed to write into socket [%s]", __wfd_print_error(res));
+ __wfd_reset_control();
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ WDC_LOGD("Succeeded to send request [%d: %s]", req.cmd, __wfd_client_print_cmd(req.cmd));
+
+ res = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) &rsp,
+ sizeof(wifi_direct_client_response_s));
+ if (res <= 0) {
+ WDC_LOGE("Failed to read socket [%d]", res);
+ __wfd_reset_control();
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if (rsp.cmd != req.cmd) {
+ WDC_LOGE("Invalid resp [%d]", rsp.cmd);
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Result received [%s]", __wfd_print_error(rsp.result));
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+
+ short num = rsp.param1;
+ short num_tmp = 0;
+ wfd_persistent_group_info_s *buff = NULL;
+ wfd_persistent_group_info_s *buff_tmp = NULL;
+
+ WDC_LOGD("Num of persistent groups = %d", (int) rsp.param1);
+
+ if (num > 1023) {
+ WDC_LOGE("Discovered peer number restricted by 255(real number:%d)", num);
+ num_tmp = num -1023;
+ num = 1023;
+ }
+
+ if (num > 0) {
+ buff = (wfd_persistent_group_info_s *) g_try_malloc0_n(num, sizeof(wfd_persistent_group_info_s));
+ if (!buff) {
+ WDC_LOGE("malloc() failed!!!.");
+ pthread_mutex_unlock(&g_client_info.mutex);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ res = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) buff,
+ num * sizeof(wfd_persistent_group_info_s));
+ if (num_tmp) {
+ WDC_LOGD("Rest data should be read out");
+ buff_tmp = (wfd_persistent_group_info_s*) calloc(num_tmp, sizeof (wfd_persistent_group_info_s));
+ if (buff_tmp) {
+ __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) buff_tmp,
+ num_tmp * sizeof(wfd_persistent_group_info_s));
+ g_free(buff_tmp);
+ }
+ }
+ pthread_mutex_unlock(&g_client_info.mutex);
+ if (res <= 0){
+ free(buff);
+ WDC_LOGE("socket read error.");
+ __wfd_reset_control();
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ __wfd_client_print_persistent_group_info(buff, num);
+ WDC_LOGD("wifi_direct_foreach_persistent_groups() SUCCESS");
+
+ char *ssid;
+ char *go_mac_address;
+
+ for (i = 0; i < num; i++) {
+ ssid = g_strndup(buff[i].ssid, WIFI_DIRECT_MAX_SSID_LEN+1);
+ if (!ssid) {
+ WDC_LOGD("Failed to copy ssid");
+ break;
+ }
+ go_mac_address = (char*) g_try_malloc0(MACSTR_LEN);
+ if (!go_mac_address) {
+ WDC_LOGD("Failed to allocate memory for GO MAC address");
+ g_free(ssid);
+ g_free(buff);
+ return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
+ }
+ g_snprintf(go_mac_address, MACSTR_LEN, MACSTR, MAC2STR(buff[i].go_mac_address));
+
+ res = cb(go_mac_address, ssid, user_data);
+ g_free(ssid);
+ ssid = NULL;
+ g_free(go_mac_address);
+ go_mac_address = NULL;
+ if (!res)
+ break;
+ }
+ g_free(buff);
+
+ } else {
+ pthread_mutex_unlock(&g_client_info.mutex);
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_remove_persistent_group(char *mac_address, const char *ssid)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ wfd_persistent_group_info_s persistent_group_info;
+ int status = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!mac_address || !ssid) {
+ WDC_LOGE("NULL Param");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_REMOVE_PERSISTENT_GROUP;
+ req.client_id = g_client_info.client_id;
+
+ pthread_mutex_lock(&g_client_info.mutex);
+ status = __wfd_client_write_socket(g_client_info.sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Error!!! writing to socket[%s]", __wfd_print_error(status));
+ __wfd_reset_control();
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ WDC_LOGD("writing msg hdr is success!");
+
+ g_strlcpy(persistent_group_info.ssid, ssid, WIFI_DIRECT_MAX_SSID_LEN + 1);
+ macaddr_atoe(mac_address, persistent_group_info.go_mac_address);
+
+ status = __wfd_client_write_socket(g_client_info.sync_sockfd, &persistent_group_info,
+ sizeof(wfd_persistent_group_info_s));
+ if (status != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Error!!! writing to socket[%s]", __wfd_print_error(status));
+ __wfd_reset_control();
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ status = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) &rsp,
+ sizeof(wifi_direct_client_response_s));
+ pthread_mutex_unlock(&g_client_info.mutex);
+ if (status <= 0) {
+ WDC_LOGE("Error!!! reading socket, status = %d", status);
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if (rsp.cmd !=req.cmd) {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d", rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGD("Error!!! Result received = %d", rsp.result);
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_set_p2poem_loglevel(int increase_log_level)
+{
+ __WDC_LOG_FUNC_START__;
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_SET_OEM_LOGLEVEL;
+ req.client_id = g_client_info.client_id;
+ if (increase_log_level == 0)
+ req.data.int1 = false;
+ else
+ req.data.int1 = true;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_start_service_discovery(char *mac_address,
+ wifi_direct_service_type_e type)
+{
+#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
+
+ unsigned char la_mac_addr[MACADDR_LEN] = {0, };
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered.");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (type >= WIFI_DIRECT_SERVICE_TYPE_ALL &&
+ type <= WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO) {
+ WDC_LOGD("Param service_type [%d]", type);
+ } else {
+ WDC_LOGE("Invalid Param [type]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_START_SERVICE_DISCOVERY;
+ req.client_id = g_client_info.client_id;
+ req.data.int1 = type;
+ if (mac_address)
+ macaddr_atoe(mac_address, la_mac_addr);
+ memcpy(req.data.mac_addr, la_mac_addr, MACADDR_LEN);
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+#else /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+ return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
+#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+}
+
+
+int wifi_direct_cancel_service_discovery(char *mac_address,
+ wifi_direct_service_type_e type)
+{
+#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
+
+ unsigned char la_mac_addr[MACADDR_LEN] = {0, };
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered.");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (type >= WIFI_DIRECT_SERVICE_TYPE_ALL &&
+ type <= WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO) {
+ WDC_LOGD("Param service_type [%d]", type);
+ } else {
+ WDC_LOGE("Invalid Param [type]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_CANCEL_SERVICE_DISCOVERY;
+ req.client_id = g_client_info.client_id;
+ req.data.int1 = type;
+ if (mac_address)
+ macaddr_atoe(mac_address, la_mac_addr);
+ memcpy(req.data.mac_addr, la_mac_addr, MACADDR_LEN);
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+#else /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+ return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
+#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+}
+
+int wifi_direct_register_service(wifi_direct_service_type_e type, char *info1, char *info2, unsigned int *service_id)
+{
+#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ char *buf = NULL;
+ int status = WIFI_DIRECT_ERROR_NONE;
+ int len = 0;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered.");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!info1) {
+ WDC_LOGE("data is NULL");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (type < WIFI_DIRECT_SERVICE_TYPE_ALL ||
+ type > WIFI_DIRECT_SERVICE_TYPE_VENDOR) {
+ WDC_LOGE("Invalid Param [type]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+ WDC_LOGD("Service type [%d]", type);
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ len = strlen(info1) + strlen(info2) + 2;
+ WDC_LOGD("info [%s|%s], len [%d]", info1, info2, len);
+ buf= g_try_malloc0(sizeof(wifi_direct_client_request_s) + len);
+ if (NULL == buf) {
+ WDC_LOGE("Failed to allocate memory for buf");
+ return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
+ }
+
+ req.cmd = WIFI_DIRECT_CMD_REGISTER_SERVICE;
+ req.client_id = g_client_info.client_id;
+ req.data.int1 = type;
+ req.cmd_data_len = len;
+
+ memcpy(buf, &req, sizeof(wifi_direct_client_request_s));
+ g_snprintf(buf + sizeof(wifi_direct_client_request_s), len, "%s|%s", info1, info2);
+
+ pthread_mutex_lock(&g_client_info.mutex);
+ status = __wfd_client_write_socket(g_client_info.sync_sockfd, buf,
+ sizeof(wifi_direct_client_request_s) + len);
+ g_free(buf);
+ if (status != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
+ __wfd_reset_control();
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ WDC_LOGD("Success writing data to the socket!");
+
+ status = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) &rsp,
+ sizeof(wifi_direct_client_response_s));
+ pthread_mutex_unlock(&g_client_info.mutex);
+ if (status <= 0) {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s", status, strerror(errno));
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if (rsp.cmd != req.cmd) {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d", rsp.cmd);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Error!!! Result received = %d", rsp.result);
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+
+ *service_id = rsp.param1;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+#else /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+ return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
+#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+}
+
+int wifi_direct_deregister_service(unsigned int service_id)
+{
+#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = 0;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered.");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_DEREGISTER_SERVICE;
+ req.client_id = g_client_info.client_id;
+ req.data.int1 = service_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+#else /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+ return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
+#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
+}
+
+int wifi_direct_init_miracast(bool enable)
+{
+#ifdef TIZEN_FEATURE_WIFI_DISPLAY
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered.");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_INIT_MIRACAST;
+ req.client_id = g_client_info.client_id;
+ req.data.int1 = enable;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+#else /* TIZEN_FEATURE_WIFI_DISPLAY */
+ return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
+#endif /* TIZEN_FEATURE_WIFI_DISPLAY */
+}
+
+int wifi_direct_get_peer_info(char* mac_address, wifi_direct_discovered_peer_info_s** peer_info)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered.");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!mac_address) {
+ WDC_LOGE("mac_addr is NULL");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_PEER_INFO;
+ req.client_id = g_client_info.client_id;
+ macaddr_atoe(mac_address, req.data.mac_addr);
+
+ pthread_mutex_lock(&g_client_info.mutex);
+ res = __wfd_client_write_socket(g_client_info.sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Failed to write into socket [%s]", __wfd_print_error(res));
+ __wfd_reset_control();
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ WDC_LOGD("Succeeded to send request [%d: %s]", req.cmd, __wfd_client_print_cmd(req.cmd));
+
+ res = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) &rsp,
+ sizeof(wifi_direct_client_response_s));
+ if (res <= 0) {
+ WDC_LOGE("Failed to read socket [%d]", res);
+ __wfd_reset_control();
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if (rsp.cmd != req.cmd) {
+ WDC_LOGE("Invalid resp [%d]", rsp.cmd);
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Result received [%s]", __wfd_print_error(rsp.result));
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+
+ wfd_discovery_entry_s *buff = NULL;
+
+ buff = (wfd_discovery_entry_s*) g_try_malloc0(sizeof (wfd_discovery_entry_s));
+ if (!buff) {
+ WDC_LOGE("Failed to alloc memory");
+ pthread_mutex_unlock(&g_client_info.mutex);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ res = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) buff,
+ sizeof(wfd_discovery_entry_s));
+ pthread_mutex_unlock(&g_client_info.mutex);
+ if (res <= 0) {
+ free(buff);
+ WDC_LOGE("Failed to read socket");
+ __wfd_reset_control();
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ __wfd_client_print_entry_list(buff, 1);
+ WDC_LOGD("wifi_direct_get_peer() SUCCESS");
+
+ wifi_direct_discovered_peer_info_s *peer = NULL;
+
+ peer = (wifi_direct_discovered_peer_info_s *) g_try_malloc0(sizeof(wifi_direct_discovered_peer_info_s));
+ if (!peer) {
+ WDC_LOGE("Failed to alloc memory");
+ pthread_mutex_unlock(&g_client_info.mutex);
+ g_free(buff);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ peer->device_name = g_strdup(buff->device_name);
+ peer->mac_address = (char*) g_try_malloc0(MACSTR_LEN);
+ g_snprintf(peer->mac_address, MACSTR_LEN, MACSTR, MAC2STR(buff->mac_address));
+ peer->interface_address = (char*) g_try_malloc0(MACSTR_LEN);
+ g_snprintf(peer->interface_address, MACSTR_LEN, MACSTR, MAC2STR(buff->intf_address));
+ peer->channel = buff->channel;
+ peer->is_connected = buff->is_connected;
+ peer->is_group_owner = buff->is_group_owner;
+ peer->is_persistent_group_owner = buff->is_persistent_go;
+ peer->primary_device_type = buff->category;
+ peer->secondary_device_type = buff->subcategory;
+ peer->supported_wps_types= buff->wps_cfg_methods;
+#ifdef TIZEN_FEATURE_WIFI_DISPLAY
+ peer->is_miracast_device = buff->is_wfd_device;
+#endif /* TIZEN_FEATURE_WIFI_DISPLAY */
+
+ g_free(buff);
+ *peer_info = peer;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_set_passphrase(const char *passphrase)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int status = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered.");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!passphrase) {
+ WDC_LOGE("NULL Param [passphrase]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+ WDC_LOGD("passphrase = [%s]", passphrase);
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_SET_PASSPHRASE;
+ req.client_id = g_client_info.client_id;
+ req.cmd_data_len = 64;
+
+ pthread_mutex_lock(&g_client_info.mutex);
+ status = __wfd_client_write_socket(g_client_info.sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Error!!! writing to socket[%s]", __wfd_print_error(status));
+ __wfd_reset_control();
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ WDC_LOGD( "writing msg hdr is success!\n");
+
+ status = __wfd_client_write_socket(g_client_info.sync_sockfd, (void*) passphrase,
+ req.cmd_data_len);
+ if (status != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Error!!! writing to socket[%s]", __wfd_print_error(status));
+ __wfd_reset_control();
+ pthread_mutex_unlock(&g_client_info.mutex);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ status = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) &rsp,
+ sizeof(wifi_direct_client_response_s));
+ pthread_mutex_unlock(&g_client_info.mutex);
+
+ if (status <= 0) {
+ WDC_LOGE("Error!!! reading socket, status = %d", status);
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ } else {
+ if (rsp.cmd == WIFI_DIRECT_CMD_SET_PASSPHRASE) {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Error!!! Result received = %d", rsp.result);
+ WDC_LOGE("Error!!! [%s]", __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ } else {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d", rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_get_passphrase(char** passphrase)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ char la_passphrase[WIFI_DIRECT_WPA_LEN+1] = {0,};
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered.");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if(!passphrase){
+ WDC_LOGE("NULL Param [passphrase]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_PASSPHRASE;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Error!!! Invalid resp = %d", res);
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+
+ WDC_LOGD("wifi_direct_get_wpa_passphrase() SUCCESS");
+ g_strlcpy(la_passphrase, rsp.param2, WIFI_DIRECT_WPA_LEN + 1);
+ *passphrase = g_strdup(la_passphrase);
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_set_autoconnection_peer(char *mac_address)
+{
+ __WDC_LOG_FUNC_START__;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ unsigned char la_mac_addr[6];
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!mac_address) {
+ WDC_LOGE("mac_addr is NULL");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_SET_AUTOCONNECTION_PEER;
+ req.client_id = g_client_info.client_id;
+ macaddr_atoe(mac_address, la_mac_addr);
+ memcpy(req.data.mac_addr, la_mac_addr, MACADDR_LEN);
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_set_autoconnection_peer() SUCCESS");
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_init_display(void)
+{
+ __WDC_LOG_FUNC_START__;
+#ifdef TIZEN_FEATURE_WIFI_DISPLAY
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered.");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_INIT_DISPLAY;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+#else /* TIZEN_FEATURE_WIFI_DISPLAY */
+ return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
+#endif /* TIZEN_FEATURE_WIFI_DISPLAY */
+}
+
+int wifi_direct_deinit_display(void)
+{
+ __WDC_LOG_FUNC_START__;
+#ifdef TIZEN_FEATURE_WIFI_DISPLAY
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
+
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((client_info->is_registered == false) ||
+ (client_info->client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_DEINIT_DISPLAY;
+ req.client_id = g_client_info.client_id;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Error!!! Invalid resp = %d", res);
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+#else /* TIZEN_FEATURE_WIFI_DISPLAY */
+ return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
+#endif /* TIZEN_FEATURE_WIFI_DISPLAY */
+}
+
+int wifi_direct_set_display(wifi_direct_display_type_e type, int port, int hdcp)
+{
+ __WDC_LOG_FUNC_START__;
+#ifdef TIZEN_FEATURE_WIFI_DISPLAY
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
+
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((client_info->is_registered == false) ||
+ (client_info->client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (type < WIFI_DIRECT_DISPLAY_TYPE_SOURCE || type > WIFI_DIRECT_DISPLAY_TYPE_DUAL || port < 0 || hdcp < 0) {
+ WDC_LOGE("Invalid paramaeters passed type[%d], port[%d], hdcp[%d]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_SET_DISPLAY;
+ req.client_id = g_client_info.client_id;
+ req.data.int1 = type;
+ req.data.int2 = port;
+ req.data.int3 = hdcp;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Error!!! Invalid resp = %d", res);
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+#else /* TIZEN_FEATURE_WIFI_DISPLAY */
+ return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
+#endif /* TIZEN_FEATURE_WIFI_DISPLAY */
+}
+
+int wifi_direct_set_display_availability(bool availability)
+{
+ __WDC_LOG_FUNC_START__;
+#ifdef TIZEN_FEATURE_WIFI_DISPLAY
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered.");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (availability < 0) {
+ WDC_LOGE("Invalid parameter");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_SET_DISPLAY_AVAILABILITY;
+ req.client_id = g_client_info.client_id;
+ req.data.int1 = availability;
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ WDC_LOGE("Error!!! Invalid resp = %d", res);
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+#else /* TIZEN_FEATURE_WIFI_DISPLAY */
+ return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
+#endif /* TIZEN_FEATURE_WIFI_DISPLAY */
+}
+
+int wifi_direct_get_peer_display_type(char *mac_address, wifi_direct_display_type_e *type)
+{
+ __WDC_LOG_FUNC_START__;
+#ifdef TIZEN_FEATURE_WIFI_DISPLAY
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
+
+ unsigned char la_mac_addr[6];
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!mac_address || !type) {
+ WDC_LOGE("NULL Param!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_PEER_DISPLAY_TYPE;
+ req.client_id = g_client_info.client_id;
+ macaddr_atoe(mac_address, la_mac_addr);
+ memcpy(req.data.mac_addr, la_mac_addr, 6);
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_get_peer_display_type() SUCCESS");
+ *type = rsp.param1;
+
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+#else /* TIZEN_FEATURE_WIFI_DISPLAY */
+ return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
+#endif /* TIZEN_FEATURE_WIFI_DISPLAY */
+}
+
+int wifi_direct_get_peer_display_availability(char *mac_address, bool *availability)
+{
+ __WDC_LOG_FUNC_START__;
+#ifdef TIZEN_FEATURE_WIFI_DISPLAY
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
+
+ unsigned char la_mac_addr[6];
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!mac_address || !availability) {
+ WDC_LOGE("NULL Param!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_PEER_DISPLAY_AVAILABILITY;
+ req.client_id = g_client_info.client_id;
+ macaddr_atoe(mac_address, la_mac_addr);
+ memcpy(req.data.mac_addr, la_mac_addr, 6);
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_get_peer_display_availability() SUCCESS");
+ *availability = rsp.param1;
+
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+#else /* TIZEN_FEATURE_WIFI_DISPLAY */
+ return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
+#endif /* TIZEN_FEATURE_WIFI_DISPLAY */
+}
+
+int wifi_direct_get_peer_display_hdcp(char *mac_address, int *hdcp)
+{
+ __WDC_LOG_FUNC_START__;
+#ifdef TIZEN_FEATURE_WIFI_DISPLAY
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
+
+ unsigned char la_mac_addr[6];
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!mac_address || !hdcp) {
+ WDC_LOGE("NULL Param!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_PEER_DISPLAY_HDCP;
+ req.client_id = g_client_info.client_id;
+ macaddr_atoe(mac_address, la_mac_addr);
+ memcpy(req.data.mac_addr, la_mac_addr, 6);
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_get_peer_display_hdcp() SUCCESS");
+ *hdcp = rsp.param1;
+
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+#else /* TIZEN_FEATURE_WIFI_DISPLAY */
+ return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
+#endif /* TIZEN_FEATURE_WIFI_DISPLAY */
+}
+
+int wifi_direct_get_peer_display_port(char *mac_address, int *port)
+{
+ __WDC_LOG_FUNC_START__;
+#ifdef TIZEN_FEATURE_WIFI_DISPLAY
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
+
+ unsigned char la_mac_addr[6];
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!mac_address || !port) {
+ WDC_LOGE("NULL Param!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_PEER_DISPLAY_PORT;
+ req.client_id = g_client_info.client_id;
+ macaddr_atoe(mac_address, la_mac_addr);
+ memcpy(req.data.mac_addr, la_mac_addr, 6);
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_get_peer_display_port() SUCCESS");
+ *port = rsp.param1;
+
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+#else /* TIZEN_FEATURE_WIFI_DISPLAY */
+ return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
+#endif /* TIZEN_FEATURE_WIFI_DISPLAY */
+}
+
+int wifi_direct_get_peer_display_throughput(char *mac_address, int *throughput)
+{
+ __WDC_LOG_FUNC_START__;
+#ifdef TIZEN_FEATURE_WIFI_DISPLAY
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
+
+ unsigned char la_mac_addr[6];
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int res = WIFI_DIRECT_ERROR_NONE;
+
+ if ((g_client_info.is_registered == false) ||
+ (g_client_info.client_id == WFD_INVALID_ID)) {
+ WDC_LOGE("Client is NOT registered");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (!mac_address || !throughput) {
+ WDC_LOGE("NULL Param!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+ memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
+
+ req.cmd = WIFI_DIRECT_CMD_GET_PEER_DISPLAY_THROUGHPUT;
+ req.client_id = g_client_info.client_id;
+ macaddr_atoe(mac_address, la_mac_addr);
+ memcpy(req.data.mac_addr, la_mac_addr, 6);
+
+ res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
+ if (res != WIFI_DIRECT_ERROR_NONE) {
+ __WDC_LOG_FUNC_END__;
+ return res;
+ }
+ WDC_LOGD("wifi_direct_get_peer_display_throughput() SUCCESS");
+ *throughput = rsp.param1;
+
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+#else /* TIZEN_FEATURE_WIFI_DISPLAY */
+ return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
+#endif /* TIZEN_FEATURE_WIFI_DISPLAY */
+}
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <assert.h>
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <wifi-direct.h>
+
+#define RESET_COLOR "\e[m"
+#define MAKE_RED "\e[31m"
+#define MAKE_GREEN "\e[32m"
+
+#define __FUNC_ENTER__ printf("%s() entering...\n", __func__)
+#define __FUNC_EXIT__ printf("%s() leaving...\n", __func__)
+
+#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
+#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
+
+#define MAX_PEER_NUM 10
+
+static const char *test_wfd_convert_error_to_string(wifi_direct_error_e err_type)
+{
+ switch (err_type) {
+ case WIFI_DIRECT_ERROR_NONE:
+ return "NONE";
+ case WIFI_DIRECT_ERROR_NOT_PERMITTED:
+ return "NOT_PERMITTED";
+ case WIFI_DIRECT_ERROR_OUT_OF_MEMORY:
+ return "OUT_OF_MEMORY";
+ case WIFI_DIRECT_ERROR_RESOURCE_BUSY:
+ return "RESOURCE_BUSY";
+ case WIFI_DIRECT_ERROR_INVALID_PARAMETER:
+ return "INVALID_PARAMETER";
+ case WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT:
+ return "CONNECTION_TIME_OUT";
+ case WIFI_DIRECT_ERROR_NOT_INITIALIZED:
+ return "NOT_INITIALIZED";
+ case WIFI_DIRECT_ERROR_COMMUNICATION_FAILED:
+ return "COMMUNICATION_FAILED";
+ case WIFI_DIRECT_ERROR_WIFI_USED:
+ return "WIFI_USED";
+ case WIFI_DIRECT_ERROR_MOBILE_AP_USED:
+ return "MOBILE_AP_USED";
+ case WIFI_DIRECT_ERROR_CONNECTION_FAILED:
+ return "CONNECTION_FAILED";
+ case WIFI_DIRECT_ERROR_AUTH_FAILED:
+ return "AUTH_FAILED";
+ case WIFI_DIRECT_ERROR_OPERATION_FAILED:
+ return "OPERATION_FAILED";
+ case WIFI_DIRECT_ERROR_TOO_MANY_CLIENT:
+ return "TOO_MANY_CLIENT";
+ case WIFI_DIRECT_ERROR_ALREADY_INITIALIZED:
+ return "ALREADY_INITIALIZED";
+ case WIFI_DIRECT_ERROR_CONNECTION_CANCELED:
+ return "CONNECTION_CANCELED";
+ default:
+ return "UNKNOWN";
+ }
+ return "UNKNOWN";
+}
+
+enum
+{
+ CMD_QUIT,
+ CMD_FULL_MENU,
+ CMD_INITIALIZE,
+ CMD_ACTIVATE_WIFI_DIRECT,
+ CMD_DEACTIVATE_WIFI_DIRECT,
+ CMD_START_DISCOVER,
+ CMD_START_DISCOVER_WITH_LISTEN_ONLY,
+ CMD_START_DISCOVER_SPECIFIC_CHANNEL,
+ CMD_CANCEL_DISCOVER,
+ CMD_GET_DISVOCERY_RESULT,
+ //CMD_SEND_PROVISION_DISCOVER_REQ,
+ CMD_SEND_CONNECTION_REQ,
+ CMD_GET_LINK_STATUS,
+ CMD_CONNECT_PEER,
+ CMD_DISCONNECT_ALL,
+ CMD_DISCONNECT,
+
+ CMD_ENABLE_PUSH_BUTTON,
+ CMD_CREATE_GROUP,
+ CMD_CANCEL_GROUP,
+ CMD_IS_GROUP_OWNER,
+ CMD_REJECT,
+ CMD_INVITE,
+ CMD_SET_DEVICE_NAME,
+ CMD_GET_DEVICE_NAME,
+ CMD_SET_SSID,
+ CMD_GET_SSID,
+ CMD_SET_WPA,
+ CMD_SET_CHANNEL,
+ CMD_SET_WPS_CONFIG,
+ CMD_SET_MAX_CLIENT,
+ CMD_GET_MAX_CLIENT,
+ CMD_SET_HIDE_SSID,
+ CMD_ACTIVATE_PERSISTENT_GROUP,
+ CMD_DEACTIVATE_PERSISTENT_GROUP,
+ CMD_IS_PERSISTENT_GROUP_ACTIVATED,
+ CMD_GET_PERSISTENT_GROUP_LIST,
+ CMD_REMOVE_PERSISTENT_GROUP,
+ //CMD_SET_GROUP_OWNER,
+ CMD_SET_AUTO_CONNECTION,
+ CMD_IS_AUTO_CONNECTION,
+ //CMD_SET_LISTEN_ONLY,
+ CMD_SET_WPS_PIN,
+ CMD_GET_WPS_PIN,
+ CMD_GET_SUPPORTED_WPS_MODE,
+ CMD_SET_CURRENT_WPS_MODE,
+ CMD_GET_CURRENT_WPS_MODE,
+ CMD_GET_CONNECTED_PEERS_INFO,
+ CMD_GET_GO_INTENT,
+ CMD_SET_GO_INTENT,
+ CMD_GET_DEVICE_MAC,
+ CMD_IS_AUTONOMOUS_GROUP,
+ CMD_SET_ACTIVATION_CB,
+ CMD_SET_DISCOVER_CB,
+ CMD_SET_SERVICE_CB,
+ CMD_SET_CONNECTION_CB,
+ CMD_SET_PEER_FOUND_CB,
+ CMD_SET_DEVICE_NAME_CB,
+ CMD_UNSET_ACTIVATION_CB,
+ CMD_UNSET_DISCOVER_CB,
+ CMD_UNSET_SERVICE_CB,
+ CMD_UNSET_CONNECTION_CB,
+ CMD_UNSET_PEER_FOUND_CB,
+ CMD_UNSET_DEVICE_NAME_CB,
+ CMD_GET_NETWORK_IF_NAME,
+ CMD_GET_SUBNET_MASK,
+ CMD_GET_GATEWAY_ADDR,
+ CMD_IS_DISCOVERABLE,
+ CMD_IS_LISTEN_ONLY,
+ CMD_GET_PRIMARY_DEVICE_TYPE,
+ CMD_GET_SECONDARY_DEVICE_TYPE,
+ CMD_GET_OPERATING_CHANNEL,
+ CMD_GET_IP_ADDR,
+ CMD_REGISTER_SERVICE,
+ CMD_DEREGISTER_SERVICE,
+ CMD_START_SERVICE_DISCOVERY,
+ CMD_CANCEL_SERVICE_DISCOVERY,
+
+ CMD_INCREASE_OEM_LOGLEVEL,
+ CMD_DECREASE_OEM_LOGLEVEL,
+ CMD_DEINITIALIZE,
+ CMD_INIT_MIRACAST,
+ CMD_GET_PEER_INFO,
+ CMD_SET_PASSPHRASE,
+ CMD_GET_PASSPHRASE,
+ CMD_SET_AUTOCONNECTION_PEER,
+
+ CMD_INIT_DISPLAY,
+ CMD_DEINIT_DISPLAY,
+ CMD_SET_DISPLAY,
+ CMD_SET_DISPLAY_AVAILABILITY,
+ CMD_GET_PEER_DISPLAY_TYPE,
+ CMD_GET_PEER_DISPLAY_AVAILABILITY,
+ CMD_GET_PEER_DISPLAY_HDCP,
+ CMD_GET_PEER_DISPLAY_PORT,
+ CMD_GET_PEER_DISPLAY_THROUGHPUT,
+
+ CMD_INVALID = 255,
+};
+
+typedef struct
+{
+ int cmd;
+ char* menu_str;
+} menu_str_t;
+
+menu_str_t g_menu_str[] =
+{
+ { CMD_QUIT, "CMD_QUIT" },
+ { CMD_FULL_MENU, "CMD_FULL_MENU" },
+ { CMD_INITIALIZE, "CMD_INITIALIZE" },
+ { CMD_ACTIVATE_WIFI_DIRECT, "CMD_ACTIVATE_WIFI_DIRECT" },
+ { CMD_DEACTIVATE_WIFI_DIRECT, "CMD_DEACTIVATE_WIFI_DIRECT" },
+ { CMD_START_DISCOVER, "CMD_START_DISCOVER" },
+ { CMD_START_DISCOVER_WITH_LISTEN_ONLY, "CMD_START_DISCOVER_WITH_LISTEN_ONLY" },
+ { CMD_START_DISCOVER_SPECIFIC_CHANNEL, "CMD_START_DISCOVER_SPECIFIC_CHANNEL" },
+ { CMD_CANCEL_DISCOVER, "CMD_CANCEL_DISCOVER" },
+ { CMD_GET_DISVOCERY_RESULT, "CMD_GET_DISVOCERY_RESULT" },
+ //{ CMD_SEND_PROVISION_DISCOVER_REQ, "CMD_SEND_PROVISION_DISCOVER_REQ" },
+ { CMD_SEND_CONNECTION_REQ, "CMD_SEND_CONNECTION_REQ" },
+
+ { CMD_GET_LINK_STATUS, "CMD_GET_LINK_STATUS" },
+ { CMD_CONNECT_PEER, "CMD_CONNECT_PEER" },
+ { CMD_DISCONNECT_ALL, "CMD_DISCONNECT_ALL" },
+ { CMD_DISCONNECT, "CMD_DISCONNECT" },
+
+ { CMD_ENABLE_PUSH_BUTTON, "CMD_ENABLE_PUSH_BUTTON" },
+
+ { CMD_CREATE_GROUP, "CMD_CREATE_GROUP" },
+ { CMD_CANCEL_GROUP, "CMD_CANCEL_GROUP" },
+ { CMD_IS_GROUP_OWNER, "CMD_IS_GROUP_OWNER" },
+ { CMD_REJECT, "CMD_REJECT" },
+ { CMD_INVITE, "CMD_INVITE" },
+ { CMD_SET_DEVICE_NAME, "CMD_SET_DEVICE_NAME" },
+ { CMD_GET_DEVICE_NAME, "CMD_GET_DEVICE_NAME" },
+ { CMD_SET_SSID, "CMD_SET_SSID" },
+ { CMD_GET_SSID, "CMD_GET_SSID" },
+ { CMD_SET_WPA, "CMD_SET_WPA" },
+ { CMD_SET_CHANNEL, "CMD_SET_CHANNEL" },
+ { CMD_SET_WPS_CONFIG, "CMD_SET_WPS_CONFIG" },
+ { CMD_SET_MAX_CLIENT, "CMD_SET_MAX_CLIENT" },
+ { CMD_GET_MAX_CLIENT, "CMD_GET_MAX_CLIENT" },
+ { CMD_SET_HIDE_SSID, "CMD_SET_HIDE_SSID" },
+ { CMD_ACTIVATE_PERSISTENT_GROUP, "CMD_ACTIVATE_PERSISTENT_GROUP" },
+ { CMD_DEACTIVATE_PERSISTENT_GROUP, "CMD_DEACTIVATE_PERSISTENT_GROUP" },
+ { CMD_IS_PERSISTENT_GROUP_ACTIVATED, "CMD_IS_PERSISTENT_GROUP_ACTIVATED" },
+ { CMD_GET_PERSISTENT_GROUP_LIST, "CMD_GET_PERSISTENT_GROUP_LIST" },
+ { CMD_REMOVE_PERSISTENT_GROUP, "CMD_REMOVE_PERSISTENT_GROUP" },
+ //{ CMD_SET_GROUP_OWNER, "CMD_SET_GROUP_OWNER" },
+ { CMD_SET_AUTO_CONNECTION, "CMD_SET_AUTO_CONNECTION" },
+ { CMD_IS_AUTO_CONNECTION, "CMD_IS_AUTO_CONNECTION" },
+ //{ CMD_SET_LISTEN_ONLY, "CMD_SET_LISTEN_ONLY" },
+ { CMD_SET_WPS_PIN, "CMD_SET_WPS_PIN" },
+ { CMD_GET_WPS_PIN, "CMD_GET_WPS_PIN" },
+ { CMD_GET_SUPPORTED_WPS_MODE, "CMD_GET_SUPPORTED_WPS_MODE" },
+ { CMD_SET_CURRENT_WPS_MODE, "CMD_SET_CURRENT_WPS_MODE" },
+ { CMD_GET_CURRENT_WPS_MODE, "CMD_GET_CURRENT_WPS_MODE" },
+ { CMD_GET_CONNECTED_PEERS_INFO, "CMD_GET_CONNECTED_PEERS_INFO" },
+ { CMD_GET_GO_INTENT, "CMD_GET_GO_INTENT" },
+ { CMD_SET_GO_INTENT, "CMD_SET_GO_INTENT" },
+ { CMD_GET_DEVICE_MAC, "CMD_GET_DEVICE_MAC" },
+ { CMD_IS_AUTONOMOUS_GROUP, "CMD_IS_AUTONOMOUS_GROUP" },
+ { CMD_SET_ACTIVATION_CB, "CMD_SET_ACTIVATION_CB" },
+ { CMD_SET_DISCOVER_CB, "CMD_SET_DISCOVER_CB" },
+ { CMD_SET_CONNECTION_CB, "CMD_SET_CONNECTION_CB" },
+ { CMD_SET_PEER_FOUND_CB, "CMD_SET_PEER_FOUND_CB" },
+ { CMD_SET_DEVICE_NAME_CB, "CMD_SET_DEVICE_NAME_CB"},
+ { CMD_UNSET_ACTIVATION_CB, "CMD_UNSET_ACTIVATION_CB" },
+ { CMD_UNSET_DISCOVER_CB, "CMD_UNSET_DISCOVER_CB" },
+ { CMD_UNSET_CONNECTION_CB, "CMD_UNSET_CONNECTION_CB" },
+ { CMD_UNSET_PEER_FOUND_CB, "CMD_UNSET_PEER_FOUND_CB" },
+ { CMD_GET_NETWORK_IF_NAME, "CMD_GET_NETWORK_IF_NAME" },
+ { CMD_GET_SUBNET_MASK, "CMD_GET_SUBNET_MASK" },
+ { CMD_GET_GATEWAY_ADDR, "CMD_GET_GATEWAY_ADDR" },
+ { CMD_IS_DISCOVERABLE, "CMD_IS_DISCOVERABLE" },
+ { CMD_IS_LISTEN_ONLY, "CMD_IS_LISTEN_ONLY" },
+ { CMD_GET_PRIMARY_DEVICE_TYPE, "CMD_GET_PRIMARY_DEVICE_TYPE" },
+ { CMD_GET_SECONDARY_DEVICE_TYPE, "CMD_GET_SECONDARY_DEVICE_TYPE" },
+ { CMD_GET_OPERATING_CHANNEL, "CMD_GET_OPERATING_CHANNEL" },
+ { CMD_GET_IP_ADDR, "CMD_GET_IP_ADDR" },
+ { CMD_REGISTER_SERVICE, "CMD_REGISTER_SERVICE" },
+ { CMD_DEREGISTER_SERVICE, "CMD_DEREGISTER_SERVICE" },
+ { CMD_START_SERVICE_DISCOVERY,"CMD_START_SERVICE_DISCOVERY" },
+ { CMD_CANCEL_SERVICE_DISCOVERY,"CMD_CANCEL_SERVICE_DISCOVERY" },
+
+ { CMD_INCREASE_OEM_LOGLEVEL, "CMD_INCREASE_OEM_LOGLEVEL" },
+ { CMD_DECREASE_OEM_LOGLEVEL, "CMD_DECREASE_OEM_LOGLEVEL" },
+
+ { CMD_DEINITIALIZE, "CMD_DEINITIALIZE" },
+ { CMD_INIT_MIRACAST, "CMD_INIT_MIRACAST" },
+ { CMD_GET_PEER_INFO, "CMD_GET_PEER_INFO" },
+ {CMD_SET_PASSPHRASE, "CMD_SET_PASSPHRASE" },
+ {CMD_GET_PASSPHRASE, "CMD_GET_PASSPHRASE" },
+ {CMD_SET_AUTOCONNECTION_PEER, "CMD_SET_AUTOCONNECTION_PEER" },
+
+ {CMD_INIT_DISPLAY, "CMD_INIT_DISPLAY" },
+ {CMD_DEINIT_DISPLAY, "CMD_DEINIT_DISPLAY" },
+ {CMD_SET_DISPLAY, "CMD_SET_DISPLAY" },
+ {CMD_SET_DISPLAY_AVAILABILITY, "CMD_SET_DISPLAY_AVAILABILITY" },
+ {CMD_GET_PEER_DISPLAY_TYPE, "CMD_GET_PEER_DISPLAY_TYPE" },
+ {CMD_GET_PEER_DISPLAY_AVAILABILITY, "CMD_GET_PEER_DISPLAY_AVAILABILITY" },
+ {CMD_GET_PEER_DISPLAY_HDCP, "CMD_GET_PEER_DISPLAY_HDCP" },
+ {CMD_GET_PEER_DISPLAY_PORT, "CMD_GET_PEER_DISPLAY_PORT" },
+ {CMD_GET_PEER_DISPLAY_THROUGHPUT, "CMD_GET_PEER_DISPLAY_THROUGHPUT" },
+
+ { -1, NULL }, };
+
+struct appdata
+{
+ GMainLoop* main_loop;
+
+ wifi_direct_discovered_peer_info_s peer_list[MAX_PEER_NUM];
+ int peer_count;
+ int selected_peer_index;
+
+ wifi_direct_connected_peer_info_s connected_peer_list[MAX_PEER_NUM];
+ int connected_peer_count;
+};
+
+struct appdata* g_test_appdata;
+
+struct appdata* get_appdata()
+{
+ return g_test_appdata;
+}
+
+void set_appdata(struct appdata* p)
+{
+ g_test_appdata = p;
+}
+
+static inline void prt_help(const char *cmd)
+{
+ printf("%s -t [dest ID]\n", cmd);
+ printf(" -u [my ID]\n");
+ printf(" -p [passwd]\n");
+ printf(" -a [alias]\n");
+}
+
+static int get_param(int argc, char **argv, struct appdata *ad)
+{
+ printf("Parsing argument...\n");
+ int opt;
+ while ((opt = getopt(argc, argv, "t:u:p:a:")) != -1)
+ {
+ printf("Parsing argument...:%c\n", opt);
+ switch (opt)
+ {
+ case 't':
+ default:
+ prt_help(argv[0]);
+ return -1;
+ }
+ }
+
+ printf("Argument: \n");
+
+ return 0;
+}
+
+void usage()
+{
+ printf("Call Test Program\n");
+ printf(" %d: quit\n", CMD_QUIT);
+ printf(" %d: Full menu\n", CMD_FULL_MENU);
+}
+
+char*
+cmd_transform(char*str)
+{
+ int i, j;
+ int len;
+ static char static_buffer[255];
+
+ if (str == NULL)
+ return "";
+
+ len = strlen(str);
+ if (len == 0)
+ return "";
+
+ // remove "CMD_"
+ // lower char
+ // replance "_" to space
+ for (i = 0, j = 4; i < len; i++, j++)
+ {
+ if (str[j] >= 'A' && str[j] <= 'Z')
+ static_buffer[i] = str[j] + 'a' - 'A';
+ else if (str[j] == '_')
+ static_buffer[i] = ' ';
+ else
+ {
+ static_buffer[i] = str[j];
+ }
+ }
+ static_buffer[j] = '\0';
+
+ return static_buffer;
+}
+
+void usage_full()
+{
+ int i;
+ printf("Call Test Program\n");
+
+ for (i = 0; g_menu_str[i].cmd != -1; i++)
+ {
+ if(i%4 == 0)
+ printf("\n");
+ printf(" %02d: %-32s ", g_menu_str[i].cmd,
+ cmd_transform(g_menu_str[i].menu_str));
+
+ }
+ printf("\n");
+}
+
+int is_digit(const char* str)
+{
+ int len;
+ int i;
+
+ if (str == NULL)
+ return -1;
+
+ if (strlen(str) == 0)
+ return -1;
+
+ len = strlen(str);
+ for (i = 0; i < len; i++)
+ {
+ if (str[i] < '0' || str[i] > '9')
+ return -2;
+ }
+
+ return 0;
+}
+
+char* print_link_state(wifi_direct_state_e state)
+{
+ if (state == WIFI_DIRECT_STATE_DEACTIVATED)
+ return "DEACTIVATED";
+ if (state == WIFI_DIRECT_STATE_ACTIVATING)
+ return "ACTIVATING";
+ if (state == WIFI_DIRECT_STATE_ACTIVATED)
+ return "ACTIVATED";
+ if (state == WIFI_DIRECT_STATE_DISCOVERING)
+ return "DISCOVERING";
+ if (state == WIFI_DIRECT_STATE_CONNECTING)
+ return "CONNECTING";
+ if (state == WIFI_DIRECT_STATE_DISCONNECTING)
+ return "DISCONNECTING";
+ if (state == WIFI_DIRECT_STATE_CONNECTED)
+ return "CONNECTED";
+ if (state == WIFI_DIRECT_STATE_GROUP_OWNER)
+ return "GROUP OWNER";
+
+ return "Unknown state";
+}
+
+int select_peer(struct appdata* ad)
+{
+ wifi_direct_discovered_peer_info_s* list;
+ int target = -1;
+ int i;
+
+ if (ad==NULL)
+ return 0;
+
+ list = ad->peer_list;
+
+ for(i=0; i<ad->peer_count; i++)
+ {
+ printf ("index [%d] MAC [%s] Owner=[%s] SSID[%s]\n",
+ i,
+ list[i].mac_address,
+ list[i].is_group_owner ? "YES" : "NO",
+ list[i].device_name);
+ }
+
+ printf("input peer index:\n");
+ scanf("%d", &target);
+
+ if (target < 0 || target > ad->peer_count)
+ {
+ printf("Wrong contact index [%d]\n", target);
+ return -1;
+ }
+ else
+ {
+ ad->selected_peer_index = target;
+ }
+
+ return 1;
+}
+
+
+void print_peers_connected(struct appdata* ad)
+{
+ wifi_direct_connected_peer_info_s* list;
+ int target = -1;
+ int i, j;
+
+ if (ad==NULL)
+ return;
+
+ list = ad->connected_peer_list;
+
+ for(i=0; i<ad->connected_peer_count; i++)
+ {
+ if (list[i].service_count == 0) {
+ printf ("index [%d] MAC [%s] SSID[%s] \n", i, list[i].mac_address, list[i].device_name);
+ } else {
+ char services[256] = {0,};
+ unsigned int len = 0;
+ printf ("Service Count = [%d][%p]\n" ,list[i].service_count,list[i].service_list);
+ for (j=0; j<list[i].service_count && list[i].service_list != NULL; j++) {
+ printf ("Service[%p]=%s\n", list[i].service_list[j], list[i].service_list[j]);
+ snprintf(services + len, 256-len, " %s", list[i].service_list[j]);
+ len = len + strlen(list[i].service_list[j]) + 1;
+ }
+ printf ("index [%d] MAC [%s] SSID[%s] Services=[%s]\n", i, list[i].mac_address, list[i].device_name, services);
+ }
+ }
+
+}
+
+void print_peers(struct appdata* ad)
+{
+ wifi_direct_discovered_peer_info_s* list;
+ int target = -1;
+ int i, j;
+
+ if (ad==NULL)
+ return;
+
+ list = ad->peer_list;
+
+ for(i=0; i<ad->peer_count; i++)
+ {
+ if (list[i].service_count == 0) {
+ printf ("index [%d] MAC [%s] Owner=[%s] connected=[%d] SSID[%s] ctg=[%d/%d] \n",
+ i,
+ list[i].mac_address,
+ list[i].is_group_owner ? "YES" : "NO",
+ list[i].is_connected,
+ list[i].device_name,
+ list[i].primary_device_type,
+ list[i].secondary_device_type
+ );
+ } else {
+ char services[256] = {0,};
+ unsigned int len = 0;
+ printf ("Service Count = [%d][%p]\n" ,list[i].service_count,list[i].service_list);
+ for (j=0; j<list[i].service_count && list[i].service_list != NULL; j++) {
+ printf ("Service[%p]=%s\n", list[i].service_list[j], list[i].service_list[j]);
+ snprintf(services + len, 256-len, " %s", list[i].service_list[j]);
+ len = len + strlen(list[i].service_list[j]) + 1;
+ }
+ printf ("index [%d] MAC [%s] Owner=[%s] connected=[%d] SSID[%s] ctg=[%d/%d] Services=[%s]\n",
+ i,
+ list[i].mac_address,
+ list[i].is_group_owner ? "YES" : "NO",
+ list[i].is_connected,
+ list[i].device_name,
+ list[i].primary_device_type,
+ list[i].secondary_device_type,
+ services
+ );
+ }
+ }
+
+}
+
+
+void event_printf(char*s)
+{
+ printf("========================================>%s\n", s);
+}
+
+void _cb_activation(int error_code, wifi_direct_device_state_e device_state, void *user_data)
+{
+ __FUNC_ENTER__;
+
+ struct appdata* ad = (struct appdata*) user_data;
+ int ret;
+
+ switch (device_state)
+ {
+
+ case WIFI_DIRECT_DEVICE_STATE_ACTIVATED:
+ event_printf("event -WIFI_DIRECT_DEVICE_STATE_ACTIVATED\n");
+ break;
+
+ case WIFI_DIRECT_DEVICE_STATE_DEACTIVATED:
+ event_printf("event - WIFI_DIRECT_DEVICE_STATE_DEACTIVATED\n");
+ break;
+
+ default:
+ break;
+ }
+}
+
+
+bool _cb_discovered_peers_impl(wifi_direct_discovered_peer_info_s* peer, void* user_data)
+{
+ __FUNC_ENTER__;
+
+ struct appdata* ad = (struct appdata*) user_data;
+
+ if(NULL != peer)
+ {
+ if ( ad->peer_count >= MAX_PEER_NUM )
+ return false; // break out of the loop
+
+ memcpy(&ad->peer_list[ad->peer_count], peer, sizeof(wifi_direct_discovered_peer_info_s));
+ ad->peer_count++;
+
+ }
+
+ return true; // continue with the next iteration of the loop
+}
+
+bool _cb_connected_peers_impl(wifi_direct_connected_peer_info_s* peer, void* user_data)
+{
+ __FUNC_ENTER__;
+
+ struct appdata* ad = (struct appdata*) user_data;
+
+ if(NULL != peer)
+ {
+ if ( ad->connected_peer_count >= MAX_PEER_NUM )
+ return false; // break out of the loop
+
+ memcpy(&ad->connected_peer_list[ad->connected_peer_count], peer, sizeof(wifi_direct_connected_peer_info_s));
+ ad->connected_peer_count++;
+
+ }
+
+ return true; // continue with the next iteration of the loop
+}
+
+bool _cb_persistent_groups_impl(const char* mac_address, const char* ssid, void* user_data)
+{
+ __FUNC_ENTER__;
+
+ struct appdata* ad = (struct appdata*) user_data;
+
+ if(NULL != mac_address)
+ printf("mac_address=[%s]\n", mac_address);
+
+ if(NULL != ssid)
+ printf("ssid=[%s]\n", ssid);
+
+ return true; // continue with the next iteration of the loop
+}
+
+void _cb_discover(int error_code, wifi_direct_discovery_state_e discovery_state, void *user_data)
+{
+ __FUNC_ENTER__;
+
+ struct appdata* ad = (struct appdata*) user_data;
+ int ret;
+
+ switch (discovery_state)
+ {
+
+ case WIFI_DIRECT_DISCOVERY_STARTED:
+ event_printf("event - WIFI_DIRECT_DISCOVERY_STARTED\n");
+ break;
+
+ case WIFI_DIRECT_ONLY_LISTEN_STARTED:
+ event_printf("event - WIFI_DIRECT_ONLY_LISTEN_STARTED\n");
+ break;
+
+ case WIFI_DIRECT_DISCOVERY_FINISHED:
+ event_printf("event - WIFI_DIRECT_DISCOVERY_FINISHED\n");
+ break;
+
+ case WIFI_DIRECT_DISCOVERY_FOUND:
+ {
+ event_printf("event - WIFI_DIRECT_DISCOVERY_FOUND\n");
+
+ memset(ad->peer_list, 0x00, sizeof(wifi_direct_discovered_peer_info_s)*MAX_PEER_NUM);
+ ad->peer_count = 0;
+ ad ->selected_peer_index = 0;
+
+ ret = wifi_direct_foreach_discovered_peers(_cb_discovered_peers_impl, (void*)ad);
+ printf("wifi_direct_foreach_discovered_peers() ret=[%d]\n", ret);
+ }
+ break;
+
+ default:
+ break;
+ }
+ // _activate_push_cb((void*)NULL, (Evas_Object*)NULL, (void*)NULL);
+
+}
+
+void _cb_peer_found(int error_code, wifi_direct_discovery_state_e discovery_state, const char * mac_address,void *user_data)
+{
+ __FUNC_ENTER__;
+
+ struct appdata* ad = (struct appdata*) user_data;
+ int ret;
+
+ switch (discovery_state)
+ {
+ case WIFI_DIRECT_DISCOVERY_FOUND:
+ {
+ event_printf("event - WIFI_DIRECT_DISCOVERY_FOUND\n");
+
+ if(mac_address[0] != '/0') {
+ printf("Peer Address is %s", mac_address);
+ wifi_direct_discovered_peer_info_s* peer_info = NULL;
+
+ wifi_direct_get_peer_info(mac_address, &peer_info);
+ if(peer_info !=NULL) {
+ printf ("MAC [%s] Owner=[%s] connected=[%d] SSID[%s] ctg=[%d/%d]",
+ peer_info->mac_address,
+ peer_info->is_group_owner ? "YES" : "NO",
+ peer_info->is_connected,
+ peer_info->device_name,
+ peer_info->primary_device_type,
+ peer_info->secondary_device_type
+ );
+ if(peer_info->mac_address)
+ free(peer_info->mac_address);
+ if(peer_info->interface_address)
+ free(peer_info->interface_address);
+ if(peer_info)
+ free(peer_info);
+ }
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+void _cb_service(int error_code,
+ wifi_direct_service_discovery_state_e discovery_state,
+ wifi_direct_service_type_e service_type,
+ void *response_data, const char * mac_address, void *user_data)
+{
+ __FUNC_ENTER__;
+
+ struct appdata* ad = (struct appdata*) user_data;
+ int ret;
+
+ switch (discovery_state)
+ {
+
+ case WIFI_DIRECT_SERVICE_DISCOVERY_STARTED:
+ event_printf("event - WIFI_DIRECT_SERVICE_DISCOVERY_STARTED\n");
+ break;
+
+ case WIFI_DIRECT_SERVICE_DISCOVERY_FINISHED:
+ event_printf("event - WIFI_DIRECT_SERVICE_DISCOVERY_FINISHED\n");
+ break;
+
+ case WIFI_DIRECT_SERVICE_DISCOVERY_FOUND:
+ {
+ event_printf("event - WIFI_DIRECT_SERVICE_DISCOVERY_FOUND\n");
+ if (mac_address != NULL)
+ printf("Peer Wi-Fi Direct mac address %s\n", mac_address);
+ if (response_data != NULL)
+ printf("Peer service response %s\n", response_data);
+ if (service_type == WIFI_DIRECT_SERVICE_TYPE_ALL)
+ printf("Service type = WIFI_DIRECT_SERVICE_TYPE_ALL\n");
+ else if (service_type == WIFI_DIRECT_SERVICE_TYPE_BONJOUR)
+ printf("Service type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR\n");
+ else if (service_type == WIFI_DIRECT_SERVICE_TYPE_UPNP)
+ printf("Service type = WIFI_DIRECT_SERVICE_TYPE_UPNP\n");
+ else if (service_type == WIFI_DIRECT_SERVICE_TYPE_BT_ADDR)
+ printf("Service type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR\n");
+ else if (service_type == WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO)
+ printf("service_type == WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO");
+ else
+ printf("Requested Service !!! NOT FOUND !!!\n");
+ }
+ break;
+
+ default:
+ break;
+ }
+ __FUNC_EXIT__;
+}
+
+void _cb_connection(int error_code, wifi_direct_connection_state_e connection_state, const char* mac_address, void *user_data)
+{
+ __FUNC_ENTER__;
+ char status[100] =
+ { 0, };
+ char *ip_addr = NULL;
+ bool owner;
+
+ switch (connection_state)
+ {
+
+ case WIFI_DIRECT_CONNECTION_IN_PROGRESS:
+ {
+ event_printf("event - WIFI_DIRECT_CONNECTION_IN_PROGRESS\n");
+
+ if ( error_code == WIFI_DIRECT_ERROR_NONE )
+ {
+ unsigned char _peer_mac[18]={0,};
+
+ if(NULL != mac_address)
+ strncpy(_peer_mac, mac_address, strlen(mac_address));
+
+
+ printf ("Connection start with [%s] \n", _peer_mac);
+
+ event_printf("Error None\n");
+
+ }
+ else
+ {
+ }
+
+ }
+ break;
+
+ case WIFI_DIRECT_CONNECTION_RSP:
+ {
+ event_printf("event - WIFI_DIRECT_CONNECTION_RSP\n");
+
+ if ( error_code == WIFI_DIRECT_ERROR_NONE )
+ {
+ char incomming_peer_mac[18]={0,};
+
+ if(NULL != mac_address)
+ strncpy(incomming_peer_mac, mac_address, strlen(mac_address));
+
+
+ printf ("Connection response with [%s] \n", incomming_peer_mac);
+
+ event_printf("Error None\n");
+
+ wifi_direct_is_group_owner(&owner);
+ if (owner)
+ {
+ wifi_direct_get_ip_address(&ip_addr);
+ if(NULL!=ip_addr)
+ {
+ sprintf(status, "<color=#FFFFFF>GO - IP : %s", ip_addr);
+ free(ip_addr);
+ }
+
+ }
+ else
+ {
+ wifi_direct_get_ip_address(&ip_addr);
+ if(NULL!=ip_addr)
+ {
+ sprintf(status, "<color=#FFFFFF>STA - IP : %s", ip_addr);
+ free(ip_addr);
+ }
+ }
+ }
+ else
+ {
+ if ( error_code == WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT )
+ event_printf("Error Code - WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT\n");
+ else if ( error_code == WIFI_DIRECT_ERROR_AUTH_FAILED )
+ event_printf("Error Code - WIFI_DIRECT_ERROR_AUTH_FAILED\n");
+ else if ( error_code == WIFI_DIRECT_ERROR_CONNECTION_FAILED )
+ event_printf("Error Code - WIFI_DIRECT_ERROR_CONNECTION_FAILED\n");
+ }
+
+ }
+ break;
+
+ case WIFI_DIRECT_CONNECTION_WPS_REQ:
+ {
+ event_printf("event - WIFI_DIRECT_CONNECTION_WPS_REQ\n");
+
+ wifi_direct_wps_type_e wps_mode;
+
+ int result;
+
+ result = wifi_direct_get_local_wps_type(&wps_mode);
+ printf("wifi_direct_get__local_wps_type() result=[%d]\n", result);
+
+ //BCMP2P_DISCOVER_ENTRY notification_data;
+ //memcpy(¬ification_data, pNotificationData, sizeof(notification_data));
+ if ( wps_mode == WIFI_DIRECT_WPS_TYPE_PBC)
+ {
+ printf("wps_config is WIFI_DIRECT_WPS_TYPE_PBC\n");
+
+ }
+ else if ( wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY)
+ {
+ printf("wps_config is WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY\n");
+
+ int num;
+ char pin[9]= { 0, };
+ int result;
+
+ struct appdata *ad = (struct appdata *) user_data;
+
+ if (NULL == ad)
+ printf("ERROR : ad is NULL!!!\n");
+
+ memset(pin, 0x00, sizeof(pin));
+ printf("Input 8 digit PIN number :\n");
+ scanf("%s", pin);
+
+ if( strlen(pin) > 0 )
+ result = wifi_direct_set_wps_pin(pin);
+ else
+ printf("Invalid PIN number\n");
+
+ if ( result == WIFI_DIRECT_ERROR_NONE )
+ {
+ int i = ad->selected_peer_index;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_accept_connection(list[i].mac_address);
+ printf("wifi_direct_accept_connection() result=[%d]\n", result);
+ }
+ else
+ printf("wifi_direct_set_wps_pin Error [%d]\n", result);
+
+ }
+ else if ( wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD )
+ {
+ printf("wps_config is WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n");
+ char *pin = NULL;
+
+ result = wifi_direct_get_wps_pin(&pin);
+ printf("wifi_direct_get_wps_pin() result=[%d]\n", result);
+ if ( NULL != pin )
+ {
+ printf("WPS_PIN [%s]\n", pin);
+ free(pin);
+ }
+ else
+ printf("WPS_PIN is NULL !! \n");
+ }
+ else
+ {
+ printf("wps_config is unkown!\n");
+ }
+
+ }
+ break;
+
+ case WIFI_DIRECT_CONNECTION_REQ:
+ {
+ event_printf("event - WIFI_DIRECT_CONNECTION_REQ\n");
+ char incomming_peer_mac[18];
+ wifi_direct_wps_type_e wps_mode;
+ bool auto_connection_mode;
+ int result;
+
+ memset(incomming_peer_mac, 0, sizeof(incomming_peer_mac));
+
+ if(NULL != mac_address)
+ strncpy(incomming_peer_mac, mac_address, strlen(mac_address));
+
+ printf ("Connection Request from [%s] \n", incomming_peer_mac);
+
+ result = wifi_direct_get_local_wps_type(&wps_mode);
+ printf("wifi_direct_get_local_wps_type() result=[%d]\n", result);
+
+ result = wifi_direct_is_autoconnection_mode(&auto_connection_mode);
+ printf("wifi_direct_is_autoconnection_mode() result=[%d]\n", result);
+
+ if(auto_connection_mode == TRUE)
+ {
+
+ result = wifi_direct_accept_connection(incomming_peer_mac);
+ printf("wifi_direct_accept_connection() result=[%d]\n", result);
+ }
+ else
+ {
+
+ if ( wps_mode == WIFI_DIRECT_WPS_TYPE_PBC)
+ {
+ char pushbutton;
+ printf("wps_config is WIFI_DIRECT_WPS_TYPE_PBC\n");
+ printf("************\n");
+ printf("Connect? (Y/N)\n");
+ printf("*************\n");
+
+ scanf("%c", &pushbutton);
+
+ if( (pushbutton == 'Y') || (pushbutton == 'y') )
+ {
+ result = wifi_direct_accept_connection(incomming_peer_mac);
+ printf("wifi_direct_accept_connection() result=[%d]\n", result);
+ }
+ }
+ else if ( wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD )
+ {
+ printf("wps_config is WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n");
+
+ char pin[9]= { 0, };
+
+ memset(pin, 0x00, sizeof(pin));
+ printf("*********************\n");
+ printf("Input 8 digit PIN number :\n");
+ printf("*********************\n");
+ scanf("%s", pin);
+
+ if( strlen(pin) > 0 )
+ result = wifi_direct_set_wps_pin(pin);
+ else
+ printf("Invalid PIN number\n");
+
+
+ if ( result == WIFI_DIRECT_ERROR_NONE )
+ {
+ result = wifi_direct_accept_connection(incomming_peer_mac);
+ printf("wifi_direct_accept_connection() result=[%d]\n", result);
+ }
+ else
+ printf("wifi_direct_set_wps_pin Error [%d]\n", result);
+
+ }
+ else
+ {
+ printf("wps_config is unkown!\n");
+ }
+ }
+
+
+
+ }
+ break;
+
+ case WIFI_DIRECT_DISCONNECTION_IND:
+ {
+ event_printf("event - WIFI_DIRECT_DISCONNECTION_IND\n");
+
+ if ( error_code == WIFI_DIRECT_ERROR_NONE )
+ {
+ char incomming_peer_mac[18]={0,};
+
+ if(NULL != mac_address)
+ strncpy(incomming_peer_mac, mac_address, strlen(mac_address));
+
+ printf ("Disconnection IND from [%s] \n", incomming_peer_mac);
+
+ event_printf("Error None\n");
+ }
+
+ }
+ break;
+
+ case WIFI_DIRECT_DISCONNECTION_RSP:
+ {
+ event_printf("event - WIFI_DIRECT_DISCONNECTION_RSP\n");
+
+ if ( error_code == WIFI_DIRECT_ERROR_NONE )
+ {
+ char incomming_peer_mac[18]={0,};
+
+ if(NULL != mac_address)
+ strncpy(incomming_peer_mac, mac_address, strlen(mac_address));
+
+ printf ("Disconnection RSP with [%s] \n", incomming_peer_mac);
+
+ event_printf("Error None\n");
+ }
+
+ }
+ break;
+
+ case WIFI_DIRECT_DISASSOCIATION_IND:
+ {
+
+ event_printf("event - WIFI_DIRECT_DISASSOCIATION_IND\n");
+
+ if ( error_code == WIFI_DIRECT_ERROR_NONE )
+ {
+ char incomming_peer_mac[18]={0,};
+
+ if(NULL != mac_address)
+ strncpy(incomming_peer_mac, mac_address, strlen(mac_address));
+
+ printf ("Disassociation IND from [%s] \n", incomming_peer_mac);
+
+ event_printf("Error None\n");
+ }
+ }
+ break;
+
+ case WIFI_DIRECT_GROUP_CREATED:
+ {
+ event_printf("event - WIFI_DIRECT_GROUP_CREATED\n");
+ }
+ break;
+
+ case WIFI_DIRECT_GROUP_DESTROYED:
+ {
+ event_printf("event - WIFI_DIRECT_GROUP_DESTROYED\n");
+ }
+ break;
+
+ default:
+ break;
+
+ }
+
+ __FUNC_EXIT__;
+}
+
+
+void _cb_ip_assigned(const char* mac_address, const char* ip_address, const char* interface_address, void *user_data)
+{
+ __FUNC_ENTER__;
+
+ if(NULL != mac_address)
+ printf ("mac_address [%s] \n", mac_address);
+ else
+ printf ("mac_address is NULL !!\n");
+
+ if(NULL != ip_address)
+ printf ("ip_address [%s] \n", ip_address);
+ else
+ printf ("ip_address is NULL !!\n");
+
+ if(NULL != interface_address)
+ printf ("interface_address [%s] \n", interface_address);
+ else
+ printf ("interface_address is NULL !!\n");
+
+ __FUNC_EXIT__;
+
+}
+
+bool _cb_foreach_supported_wps_impl(wifi_direct_wps_type_e type, void* user_data)
+{
+ __FUNC_ENTER__;
+
+ struct appdata* ad = (struct appdata*) user_data;
+
+ switch (type)
+ {
+ case WIFI_DIRECT_WPS_TYPE_PBC:
+ printf("type=[WIFI_DIRECT_WPS_TYPE_PBC]\n");
+ break;
+ case WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY:
+ printf("type=[WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY]\n");
+ break;
+ case WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD:
+ printf("type=[WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD]\n");
+ break;
+ default:
+ printf("ERROR : type=[%d]\n", type);
+ break;
+ }
+
+ return true; // continue with the next iteration of the loop
+}
+
+
+int _get_current_state(void)
+{
+ __FUNC_ENTER__;
+ wifi_direct_state_e status;
+ wifi_direct_get_state(&status);
+ __FUNC_EXIT__;
+
+ return status;
+}
+
+int init_wfd_client(struct appdata *ad)
+{
+ int ret;
+
+ ret = wifi_direct_initialize();
+ printf("wifi_direct_initialize() result=[%d]\n", ret);
+
+ ret = wifi_direct_set_device_state_changed_cb(_cb_activation, (void*)ad);
+ printf("wifi_direct_set_device_state_changed_cb() result=[%d]\n", ret);
+
+ ret = wifi_direct_set_discovery_state_changed_cb(_cb_discover, (void*)ad);
+ printf("wifi_direct_set_discovery_state_changed_cb() result=[%d]\n", ret);
+
+ ret = wifi_direct_set_connection_state_changed_cb(_cb_connection, (void*)ad);
+ printf("wifi_direct_set_connection_state_changed_cb() result=[%d]\n", ret);
+
+ ret = wifi_direct_set_client_ip_address_assigned_cb(_cb_ip_assigned, (void*)ad);
+ printf("wifi_direct_set_client_ip_address_assigned_cb() result=[%d]\n", ret);
+
+ ret = wifi_direct_set_service_state_changed_cb(_cb_service, (void*)ad);
+ printf("wifi_direct_set_service_state_changed_cb() result=[%d]\n", ret);
+
+ ret = wifi_direct_set_peer_found_cb(_cb_peer_found, (void*)ad);
+ printf("wifi_direct_set_peer_found_cb() result=[%d]\n", ret);
+
+ return ret;
+}
+
+void process_input(const char *input, gpointer user_data)
+{
+ struct appdata *ad = (struct appdata *) user_data;
+ int result = -1;
+
+ int cmd = -1;
+ cmd = strtol(input, NULL, 0);
+ if (is_digit(input) < 0 || strlen(input) == 0 || errno == ERANGE || errno
+ == EINVAL)
+ cmd = CMD_INVALID;
+
+ printf("cmd=[%d]\n", cmd);
+
+ switch (cmd)
+ {
+ case CMD_INITIALIZE:
+ {
+ result = init_wfd_client(ad);
+ printf("init_wfd_client() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_SET_ACTIVATION_CB:
+ {
+ result = wifi_direct_set_device_state_changed_cb(_cb_activation, (void*)ad);
+ printf("wifi_direct_set_device_state_changed_cb() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_UNSET_ACTIVATION_CB:
+ {
+ result = wifi_direct_unset_device_state_changed_cb();
+ printf("wifi_direct_unset_device_state_changed_cb() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_SET_DISCOVER_CB:
+ {
+ result = wifi_direct_set_discovery_state_changed_cb(_cb_discover, (void*)ad);
+ printf("wifi_direct_set_discovery_state_changed_cb() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_UNSET_DISCOVER_CB:
+ {
+ result = wifi_direct_unset_discovery_state_changed_cb();
+ printf("wifi_direct_unset_discovery_state_changed_cb() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_SET_CONNECTION_CB:
+ {
+ result = wifi_direct_set_connection_state_changed_cb(_cb_connection, (void*)ad);
+ printf("wifi_direct_set_connection_state_changed_cb() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_UNSET_CONNECTION_CB:
+ {
+ result = wifi_direct_unset_connection_state_changed_cb();
+ printf("wifi_direct_unset_connection_state_changed_cb() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_SET_SERVICE_CB:
+ {
+ result = wifi_direct_set_service_state_changed_cb(_cb_service, (void*)ad);
+ printf("wifi_direct_set_service_state_changed_cb() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_UNSET_SERVICE_CB:
+ {
+ result = wifi_direct_unset_service_state_changed_cb();
+ printf("wifi_direct_unset_service_changed_cb() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_SET_PEER_FOUND_CB:
+ {
+ result = wifi_direct_set_peer_found_cb(_cb_peer_found, (void*)ad);
+ printf("wifi_direct_set_peer_found_cb() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_UNSET_PEER_FOUND_CB:
+ {
+ result = wifi_direct_unset_peer_found_cb();
+ printf("wifi_direct_unset_peer_found_cb() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_DEINITIALIZE:
+ result = wifi_direct_deinitialize();
+ printf("wifi_direct_deinitialize() result=[%d]\n", result);
+ break;
+ case CMD_ACTIVATE_WIFI_DIRECT:
+ if (ad != NULL)
+ {
+ result = wifi_direct_activate();
+ printf("wifi_direct_activate() result=[%d]\n", result);
+
+ if ( result == WIFI_DIRECT_ERROR_WIFI_USED )
+ printf(" ERROR : WIFI_DIRECT_ERROR_WIFI_USED \n");
+ else if ( result == WIFI_DIRECT_ERROR_MOBILE_AP_USED )
+ printf(" ERROR : WIFI_DIRECT_ERROR_MOBILE_AP_USED \n");
+
+ }
+ break;
+
+ case CMD_DEACTIVATE_WIFI_DIRECT:
+ if (ad != NULL)
+ {
+ result = wifi_direct_deactivate();
+ printf("wifi_direct_deactivate() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_START_DISCOVER_WITH_LISTEN_ONLY:
+ if (ad != NULL)
+ {
+ result = wifi_direct_start_discovery(TRUE, 15);
+ printf("wifi_direct_start_discovery() listen_only=[true] result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_START_DISCOVER:
+ if (ad != NULL)
+ {
+ //result = wifi_direct_start_discovery(FALSE, 15);
+ result = wifi_direct_start_discovery(FALSE, 0);
+ printf("wifi_direct_start_discovery() listen_only=[false] result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_START_DISCOVER_SPECIFIC_CHANNEL:
+ if (ad != NULL)
+ {
+ int input;
+ printf("Select Discovery Channel :\n");
+ printf("1. WIFI_DIRECT_DISCOVERY_FULL_SCAN\n");
+ printf("2. WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL\n");
+ printf("3. WIFI_DIRECT_DISCOVERY_CHANNEL1\n");
+ printf("4. WIFI_DIRECT_DISCOVERY_CHANNEL6\n");
+ printf("5. WIFI_DIRECT_DISCOVERY_CHANNEL11\n");
+ scanf("%d", &input);
+
+ switch(input)
+ {
+ case 1 :
+ {
+ result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_FULL_SCAN);
+ printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_FULL_SCAN, result);
+ }
+ break;
+ case 2 :
+ {
+ result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL);
+ printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL, result);
+ }
+ break;
+ case 3 :
+ {
+ result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_CHANNEL1);
+ printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_CHANNEL1, result);
+ }
+ break;
+ case 4 :
+ {
+ result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_CHANNEL6);
+ printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_CHANNEL6, result);
+ }
+ break;
+ case 5 :
+ {
+ result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_CHANNEL11);
+ printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_CHANNEL11, result);
+ }
+ break;
+ default :
+ printf("ERROR : Invalid Channel !!!\n");
+ break;
+ }
+
+ }
+ break;
+
+ case CMD_CANCEL_DISCOVER:
+ if (ad != NULL)
+ {
+ result = wifi_direct_cancel_discovery();
+ printf("wifi_direct_cancel_discovery() result=[%d]\n", result);
+ }
+ break;
+ case CMD_GET_DISVOCERY_RESULT:
+ if (ad != NULL)
+ {
+ memset(ad->peer_list, 0x00, sizeof(wifi_direct_discovered_peer_info_s)*MAX_PEER_NUM);
+ ad->peer_count = 0;
+ ad ->selected_peer_index = 0;
+
+ result = wifi_direct_foreach_discovered_peers(_cb_discovered_peers_impl, (void*)ad);
+ printf("wifi_direct_foreach_discovered_peers() ret=[%d]\n", result);
+
+ print_peers(ad);
+ }
+ break;
+
+ case CMD_SEND_CONNECTION_REQ:
+ if (ad != NULL)
+ {
+ if (select_peer(ad))
+ {
+ int i = ad->selected_peer_index;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_accept_connection(list[i].mac_address);
+
+ printf ("Connecting... peer-index[%d] MAC [%s] Owner=[%s] SSID[%s]\n",
+ i,
+ list[i].mac_address,
+ list[i].is_group_owner ? "YES" : "NO",
+ list[i].device_name);
+
+ printf("wifi_direct_accept_connection() result=[%d]\n", result);
+ }
+ }
+ break;
+
+ case CMD_DISCONNECT_ALL:
+ if (ad != NULL)
+ {
+ result = wifi_direct_disconnect_all();
+ printf("wifi_direct_disconnect_all() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_DISCONNECT:
+ if (ad != NULL)
+ {
+ if (select_peer(ad))
+ {
+ int i = ad->selected_peer_index;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_disconnect(list[i].mac_address);
+
+ printf ("Disconnecting... peer-index[%d] MAC [%s] SSID[%s]\n",
+ i,
+ list[i].mac_address,
+ list[i].device_name);
+
+ printf("wifi_direct_disconnect() result=[%d]\n", result);
+ }
+ }
+ break;
+
+
+ case CMD_GET_LINK_STATUS:
+ if (ad != NULL)
+ {
+ wifi_direct_state_e status = 0;
+ result = wifi_direct_get_state(&status);
+ printf("wifi_direct_get_state() state=[%s(%d)], result=[%d]\n", print_link_state(status), status, result);
+ }
+ break;
+
+ case CMD_CONNECT_PEER:
+ if (ad != NULL)
+ {
+ if (select_peer(ad))
+ {
+ wifi_direct_wps_type_e wps_mode;
+
+ result = wifi_direct_get_local_wps_type(&wps_mode);
+ printf("wifi_direct_get_local_wps_type() result=[%d]\n", result);
+
+ if( wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD )
+ {
+ printf("wifi_direct_generate_wps_pin() result=[%d]\n", result);
+ }
+
+ int i = ad->selected_peer_index;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_connect(list[i].mac_address);
+
+ printf ("Connecting... peer-index[%d] MAC [%s] Owner=[%s] SSID[%s]\n",
+ i,
+ list[i].mac_address,
+ list[i].is_group_owner ? "YES" : "NO",
+ list[i].device_name);
+
+ printf("wifi_direct_connect() result=[%d]\n", result);
+
+ }
+ }
+ break;
+
+ case CMD_ENABLE_PUSH_BUTTON:
+ if (ad != NULL)
+ {
+ result = wifi_direct_activate_pushbutton();
+ printf("wifi_direct_activate_pushbutton() result=[%d]\n", result);
+ }
+ break;
+ case CMD_CREATE_GROUP:
+ if (ad != NULL)
+ {
+ result = wifi_direct_create_group();
+ printf("wifi_direct_create_group() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_CANCEL_GROUP:
+ if (ad != NULL)
+ {
+ result = wifi_direct_destroy_group();
+ printf("wifi_direct_destroy_group() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_IS_GROUP_OWNER:
+ if (ad != NULL)
+ {
+ bool is_group_owner;
+ result = wifi_direct_is_group_owner(&is_group_owner);
+ printf("wifi_direct_is_group_owner() is GO[%d] result=[%d]\n", is_group_owner, result);
+ }
+ break;
+ case CMD_REJECT:
+ if (ad != NULL)
+ {
+ //result = wifi_direct_client_reject();
+ printf("Under construction...\n");
+ }
+ break;
+
+ case CMD_INVITE:
+ if (ad != NULL)
+ {
+ //result = wifi_direct_client_invite();
+ printf("Under construction...\n");
+ }
+ break;
+
+ case CMD_SET_DEVICE_NAME:
+ {
+ if (ad != NULL)
+ {
+ char device_name[32 + 1];
+
+ memset(device_name, 0, sizeof(device_name));
+ printf("Input device name :\n");
+ scanf("%s",device_name);
+
+ if (strlen(device_name) <= 0)
+ printf("invalid device name !!\n");
+ else
+ printf("device_name: [%s]\n", device_name);
+
+
+ if ((strlen(device_name) > 0))
+ {
+ result = wifi_direct_set_device_name(device_name);
+ printf("wifi_direct_set_device_name() ret=[%d]\n", result);
+ }
+ }
+ }
+ break;
+
+ case CMD_GET_DEVICE_NAME:
+ {
+ if (ad != NULL)
+ {
+ char* device_name = NULL;
+
+ result = wifi_direct_get_device_name(&device_name);
+ printf("wifi_direct_get_device_name() result=[%d]\n", result);
+
+ if (NULL != device_name)
+ {
+ printf("ssid: [%s]\n", device_name);
+ free(device_name);
+ }
+
+ }
+ }
+ break;
+
+ case CMD_GET_SSID:
+ {
+ if (ad != NULL)
+ {
+ char* ssid = NULL;
+
+ result = wifi_direct_get_ssid(&ssid);
+ printf("wifi_direct_get_ssid() result=[%d]\n", result);
+
+ if (NULL != ssid)
+ {
+ printf("ssid: [%s]\n", ssid);
+ free(ssid);
+ }
+
+ }
+ }
+ break;
+
+ case CMD_SET_CHANNEL:
+ if (ad != NULL)
+ {
+
+#if 0
+ wifi_direct_config_data_s *config;
+ result = wifi_direct_get_config_data(&config);
+ if(result != WIFI_DIRECT_ERROR_NONE)
+ {
+ printf("Failed to get wifi_direct_get_config_data() result=[%d]\n", result);
+ }
+ else
+ {
+ printf("Current operating channel: [%d]\n", config->channel);
+ printf("Input operation channel:\n");
+ scanf("%d", &config->channel);
+
+ printf("New operation channel: [%d]\n", config->channel);
+
+ result = wifi_direct_set_config_data(config);
+ printf("wifi_direct_set_config_data() result=[%d]\n", result);
+ }
+#endif
+
+ }
+ break;
+ case CMD_SET_WPS_CONFIG:
+ if (ad != NULL)
+ {
+#if 0
+ wifi_direct_config_data_s *config;
+ result = wifi_direct_get_config_data(&config);
+ if(result != WIFI_DIRECT_ERROR_NONE)
+ {
+ printf("Failed to get wifi_direct_get_config_data() result=[%d]\n", result);
+ }
+ else
+ {
+ printf("Current WPS config method: [%d, %s]\n", config->wps_config,
+ (config->wps_config==WIFI_DIRECT_WPS_TYPE_PBC)?"Pushbutton":
+ (config->wps_config==WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY)?"Display":"Keypad");
+ printf("Input operation channel[%d:Pushbutton %d:display %d:keypad] \n",
+ WIFI_DIRECT_WPS_TYPE_PBC, WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY, WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD);
+
+ scanf("%d", &config->wps_config);
+
+ printf("New WPS config method: [%d, %s]\n", config->channel,
+ (config->wps_config==WIFI_DIRECT_WPS_TYPE_PBC)?"Pushbutton":
+ (config->wps_config==WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY)?"Display":"Keypad");
+
+ result = wifi_direct_set_config_data(config);
+ printf("wifi_direct_set_config_data() result=[%d]\n", result);
+ }
+#endif
+ }
+ break;
+ case CMD_SET_MAX_CLIENT:
+ if (ad != NULL)
+ {
+ int max_client;
+ result = wifi_direct_get_max_clients(&max_client);
+
+ printf("Current max client=[%d]\n", max_client);
+ printf("Input new max client:\n");
+ scanf("%d", &max_client);
+
+ result = wifi_direct_set_max_clients(max_client);
+ printf("wifi_direct_set_max_clients() result=[%d] max_client[%d]\n", result, max_client);
+ }
+ break;
+
+ case CMD_GET_MAX_CLIENT:
+ if (ad != NULL)
+ {
+ int max_client;
+
+ result = wifi_direct_get_max_clients(&max_client);
+ printf("wifi_direct_get_max_clients() result=[%d] max_client[%d]\n", result, max_client);
+ }
+ break;
+
+ case CMD_SET_HIDE_SSID:
+ if (ad != NULL)
+ {
+#if 0
+ wifi_direct_config_data_s *config;
+ result = wifi_direct_get_config_data(&config);
+ if(result != WIFI_DIRECT_ERROR_NONE)
+ {
+ printf("Failed to get wifi_direct_get_config_data() result=[%d]\n", result);
+ }
+ else
+ {
+ printf("Current hide SSID: [%d]\n", config->hide_SSID);
+ printf("Want to hide SSID (0: no hide, 1: hide):\n");
+ scanf("%d", config->hide_SSID);
+ printf("New hide SSID: [%d]\n", config->hide_SSID);
+ result = wifi_direct_set_config_data(config);
+ printf("wifi_direct_set_config_data() result=[%d]\n", result);
+ }
+#endif
+
+ }
+ break;
+
+ case CMD_ACTIVATE_PERSISTENT_GROUP:
+ if (ad != NULL)
+ {
+ result = wifi_direct_set_persistent_group_enabled(true);
+
+ if(result != WIFI_DIRECT_ERROR_NONE)
+ printf("Failed to wifi_direct_set_persistent_group_enabled() result=[%d]\n", result);
+ else
+ printf("wifi_direct_set_persistent_group_enabled() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_DEACTIVATE_PERSISTENT_GROUP:
+ if (ad != NULL)
+ {
+ result = wifi_direct_set_persistent_group_enabled(false);
+
+ if(result != WIFI_DIRECT_ERROR_NONE)
+ printf("Failed to wifi_direct_set_persistent_group_enabled() result=[%d]\n", result);
+ else
+ printf("wifi_direct_set_persistent_group_enabled() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_IS_PERSISTENT_GROUP_ACTIVATED:
+ if (ad != NULL)
+ {
+ bool enabled;
+
+ result = wifi_direct_is_persistent_group_enabled(&enabled);
+ printf("wifi_direct_is_persistent_group_enabled() result=[%d]\n", result);
+ if ( enabled == TRUE )
+ printf("Persistent Group mode!! \n");
+ else
+ printf("NOT Persistent group mode!! \n");
+ }
+ break;
+
+
+ case CMD_GET_PERSISTENT_GROUP_LIST:
+ if (ad != NULL)
+ {
+ result = wifi_direct_foreach_persistent_groups(_cb_persistent_groups_impl, (void*)ad);
+ printf("wifi_direct_foreach_persistent_groups() ret=[%d]\n", result);
+ }
+ break;
+
+ case CMD_REMOVE_PERSISTENT_GROUP:
+ if (ad != NULL)
+ {
+ char mac[18];
+ char ssid[32 + 1];
+
+ memset(mac, 0, sizeof(mac));
+ memset(ssid, 0, sizeof(ssid));
+
+ printf("Input GO MAC :\n");
+ scanf("%s",mac);
+
+ if (strlen(mac) <= 0)
+ printf("invalid GO MAC !!\n");
+ else
+ printf("GO MAC: [%s]\n", mac);
+
+
+ printf("Input ssid :\n");
+ scanf("%s",ssid);
+
+ if (strlen(ssid) <= 0)
+ printf("invalid ssid !!\n");
+ else
+ printf("ssid: [%s]\n", ssid);
+
+
+ if ((strlen(mac) > 0) && (strlen(ssid) > 0))
+ {
+ result = wifi_direct_remove_persistent_group(mac, ssid);
+ printf("wifi_direct_remove_persistent_group() ret=[%d]\n", result);
+ }
+
+ }
+ break;
+
+#if 0
+ case CMD_SET_GROUP_OWNER:
+ if (ad != NULL)
+ {
+ wifi_direct_config_data_s *config;
+ result = wifi_direct_get_config_data(&config);
+ if(result != WIFI_DIRECT_ERROR_NONE)
+ {
+ printf("Failed to get wifi_direct_get_config_data() result=[%d]\n", result);
+ }
+ else
+ {
+ printf("Current want-group-owner: [%d]\n", config->want_group_owner);
+ printf("Input want-group-owner:\n");
+ scanf("%d", config->want_group_owner);
+
+ printf("New want-group-owner: [%d]\n", config->want_group_owner);
+
+ result = wifi_direct_set_config_data(config);
+ printf("wifi_direct_set_config_data() result=[%d]\n", result);
+ }
+ }
+ break;
+#endif
+
+ case CMD_SET_AUTO_CONNECTION:
+ if (ad != NULL)
+ {
+ int autoconnection_mode;
+
+ printf("Input Auto connection: \n");
+ printf("[1] true [2] false\n");
+
+ scanf("%d", &autoconnection_mode);
+
+ if (autoconnection_mode == 1)
+ result = wifi_direct_set_autoconnection_mode(true);
+ else if (autoconnection_mode == 2)
+ result = wifi_direct_set_autoconnection_mode(false);
+ else
+ printf("Invalid input parameter!!!\n");
+
+ printf("wifi_direct_set_autoconnection_mode() result=[%d] \n", result);
+
+ }
+ break;
+
+ case CMD_IS_AUTO_CONNECTION:
+ if (ad != NULL)
+ {
+ bool auto_connection = false;
+
+ result = wifi_direct_is_autoconnection_mode(&auto_connection);
+ printf("wifi_direct_is_autoconnection_mode() result=[%d]\n", result);
+ if ( auto_connection == TRUE )
+ printf("Auto connection mode !! \n");
+ else
+ printf("NOT Auto connection mode !! \n");
+
+ }
+ break;
+
+
+#if 0
+ case CMD_SET_LISTEN_ONLY:
+ if (ad != NULL)
+ {
+ wifi_direct_config_data_s *config;
+ result = wifi_direct_get_config_data(&config);
+ if(result != WIFI_DIRECT_ERROR_NONE)
+ {
+ printf("Failed to get wifi_direct_get_config_data() result=[%d]\n", result);
+ }
+ else
+ {
+ printf("Current want-listen-only: [%d]\n", config->want_listen_only);
+ printf("Input want-listen-only:\n");
+ scanf("%d", config->want_listen_only);
+
+ printf("New want-listen-only: [%d]\n", config->want_listen_only);
+
+ result = wifi_direct_set_config_data(config);
+ printf("wifi_direct_set_config_data() result=[%d]\n", result);
+ }
+ }
+ break;
+#endif
+
+ case CMD_SET_WPS_PIN:
+ if (ad != NULL)
+ {
+
+ char pin[9] = {0,};
+
+ printf("Input PIN number :\n");
+ scanf("%s", pin);
+ printf("New PIN: [%s]\n", pin);
+
+ if ((strlen(pin) > 0) && (strlen(pin) < 9))
+ wifi_direct_set_wps_pin(pin);
+ else
+ printf("Invalid PIN number\n");
+ }
+ break;
+
+ case CMD_GET_WPS_PIN:
+ if (ad != NULL)
+ {
+ char *pin = NULL;
+
+ result = wifi_direct_get_wps_pin(&pin);
+ printf("wifi_direct_get_wps_pin() result=[%d]\n", result);
+ if ( NULL != pin )
+ {
+ printf("WPS_PIN [%s]\n", pin);
+ free(pin);
+ }
+ else
+ printf("WPS_PIN is NULL !! \n");
+ }
+ break;
+
+ case CMD_GET_SUPPORTED_WPS_MODE:
+ if (ad != NULL)
+ {
+ int supported_wps_mode = 0;
+
+ result = wifi_direct_foreach_supported_wps_types(_cb_foreach_supported_wps_impl, NULL);
+ printf("wifi_direct_foreach_supported_wps_types() result=[%d]\n", result);
+
+ result = wifi_direct_get_supported_wps_mode (&supported_wps_mode);
+ printf("wifi_direct_foreach_supported_wps_types() supported=[%d] result=[%d]\n", supported_wps_mode, result);
+ }
+ break;
+
+ case CMD_SET_CURRENT_WPS_MODE:
+ if (ad != NULL)
+ {
+
+ wifi_direct_wps_type_e wps_mode;
+ int input;
+
+ result = wifi_direct_get_req_wps_type(&wps_mode);
+ switch(wps_mode)
+ {
+ case WIFI_DIRECT_WPS_TYPE_PBC :
+ printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PBC]\n");
+ break;
+ case WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY :
+ printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY]\n");
+ break;
+ case WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD :
+ printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD]\n");
+ break;
+ default :
+ printf("ERROR : wps_mode=[%d]\n", wps_mode);
+ break;
+ }
+
+ printf("Input new wps mode:\n");
+ printf("1. WIFI_DIRECT_WPS_TYPE_PBC\n");
+ printf("2. WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY\n");
+ printf("3. WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n");
+ scanf("%d", &input);
+
+ switch(input)
+ {
+ case 1 :
+ wps_mode = WIFI_DIRECT_WPS_TYPE_PBC;
+ break;
+ case 2 :
+ wps_mode = WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY;
+ break;
+ case 3 :
+ wps_mode = WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD;
+ break;
+ default :
+ printf("ERROR : Invalid input wps_mode!!!\n");
+ break;
+ }
+
+ result = wifi_direct_set_req_wps_type(wps_mode);
+ printf("wifi_direct_set_wps_type() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_GET_CURRENT_WPS_MODE:
+ if (ad != NULL)
+ {
+ wifi_direct_wps_type_e wps_mode;
+ result = wifi_direct_get_req_wps_type(&wps_mode);
+ printf("wifi_direct_get_wps_type() wps_mode=[%d], result=[%d]\n", wps_mode, result);
+ switch(wps_mode)
+ {
+ case WIFI_DIRECT_WPS_TYPE_PBC :
+ printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PBC]\n");
+ break;
+ case WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY :
+ printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY]\n");
+ break;
+ case WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD :
+ printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD]\n");
+ break;
+ default :
+ printf("ERROR : wps_mode=[%d]\n", wps_mode);
+ break;
+ }
+
+ }
+ break;
+
+ case CMD_GET_CONNECTED_PEERS_INFO:
+ if (ad != NULL)
+ {
+ memset(ad->connected_peer_list, 0x00, sizeof(wifi_direct_connected_peer_info_s)*MAX_PEER_NUM);
+ ad->connected_peer_count = 0;
+
+ result = wifi_direct_foreach_connected_peers(_cb_connected_peers_impl, (void*)ad);
+ printf("wifi_direct_foreach_connected_peers() ret=[%d]\n", result);
+ print_peers_connected(ad);
+ }
+ break;
+
+ case CMD_GET_GO_INTENT:
+ if (ad != NULL)
+ {
+ int go_intent;
+
+ result = wifi_direct_get_group_owner_intent(&go_intent);
+ printf("wifi_direct_get_group_owner_intent() result=[%d] go_intent[%d]\n", result, go_intent);
+ }
+ break;
+
+ case CMD_SET_GO_INTENT:
+ if (ad != NULL)
+ {
+ int go_intent;
+ result = wifi_direct_get_group_owner_intent(&go_intent);
+
+ printf("Current GO intent=[%d]\n", go_intent);
+ printf("Input new GO intent [0~15]:\n");
+ scanf("%d", &go_intent);
+
+ result = wifi_direct_set_group_owner_intent(go_intent);
+ printf("wifi_direct_set_group_owner_intent() result=[%d] go_intent[%d]\n", result, go_intent);
+ }
+ break;
+
+ case CMD_GET_DEVICE_MAC:
+ if (ad != NULL)
+ {
+ char *device_mac = NULL;
+
+ result = wifi_direct_get_mac_address(&device_mac);
+ printf("wifi_direct_get_mac_addr() result=[%d]\n", result);
+ if ( NULL != device_mac )
+ printf ("MAC [%s] \n", device_mac);
+ else
+ printf("device_mac is NULL !! \n");
+ }
+ break;
+
+ case CMD_IS_AUTONOMOUS_GROUP:
+ if (ad != NULL)
+ {
+ bool autonomous_group;
+
+ result = wifi_direct_is_autonomous_group(&autonomous_group);
+ printf("wifi_direct_is_autonomous_group() result=[%d]\n", result);
+ if ( autonomous_group == TRUE )
+ printf("Autonomous Group !! \n");
+ else
+ printf("NOT Autonomous group !! \n");
+
+ }
+ break;
+
+ case CMD_GET_NETWORK_IF_NAME:
+ if (ad != NULL)
+ {
+ char* name = NULL;
+
+ result = wifi_direct_get_network_interface_name(&name);
+ printf("wifi_direct_get_network_interface_name() result=[%d]\n", result);
+
+ if (NULL != name)
+ {
+ printf("name: [%s]\n", name);
+ free(name);
+ }
+
+ }
+ break;
+
+ case CMD_GET_SUBNET_MASK:
+ if (ad != NULL)
+ {
+ char* subnet_mask = NULL;
+
+ result = wifi_direct_get_subnet_mask(&subnet_mask);
+ printf("wifi_direct_get_subnet_mask() result=[%d]\n", result);
+
+ if (NULL != subnet_mask)
+ {
+ printf("subnet_mask: [%s]\n", subnet_mask);
+ free(subnet_mask);
+ }
+
+ }
+ break;
+
+
+ case CMD_GET_GATEWAY_ADDR:
+ if (ad != NULL)
+ {
+ char* gateway_address = NULL;
+
+ result = wifi_direct_get_gateway_address(&gateway_address);
+ printf("wifi_direct_get_gateway_address() result=[%d]\n", result);
+
+ if (NULL != gateway_address)
+ {
+ printf("gateway_address: [%s]\n", gateway_address);
+ free(gateway_address);
+ }
+
+ }
+ break;
+
+ case CMD_IS_DISCOVERABLE:
+ if (ad != NULL)
+ {
+ bool discoverable = false;
+
+ result = wifi_direct_is_discoverable(&discoverable);
+ printf("wifi_direct_is_discoverable() result=[%d]\n", result);
+ if ( discoverable == TRUE )
+ printf("Discoverable state !! \n");
+ else
+ printf("NOT Discoverable state !! \n");
+
+ }
+ break;
+
+ case CMD_IS_LISTEN_ONLY:
+ if (ad != NULL)
+ {
+ bool listen_only = false;
+
+ result = wifi_direct_is_listening_only(&listen_only);
+ printf("wifi_direct_is_listening_only() result=[%d]\n", result);
+ if ( listen_only == TRUE )
+ printf("Listen only state !! \n");
+ else
+ printf("NOT Listen only state !! \n");
+
+ }
+ break;
+
+ case CMD_GET_PRIMARY_DEVICE_TYPE:
+ if (ad != NULL)
+ {
+ wifi_direct_primary_device_type_e type;
+
+ result = wifi_direct_get_primary_device_type(&type);
+
+ printf("wifi_direct_get_primary_device_type() result=[%d]\n", result);
+ printf("Primary Device TYPE [%d]\n", type);
+
+ }
+ break;
+
+ case CMD_GET_SECONDARY_DEVICE_TYPE:
+ if (ad != NULL)
+ {
+ wifi_direct_secondary_device_type_e type;
+
+ result = wifi_direct_get_secondary_device_type(&type);
+
+ printf("wifi_direct_get_secondary_device_type() result=[%d]\n", result);
+ printf("Secondary Device TYPE [%d]\n", type);
+ }
+ break;
+
+ case CMD_GET_OPERATING_CHANNEL:
+ if (ad != NULL)
+ {
+ int operating_channel;
+
+ result = wifi_direct_get_operating_channel(&operating_channel);
+
+ printf("wifi_direct_get_own_group_channel() result=[%d]\n", result);
+ printf("Operating Channel [%d]\n", operating_channel);
+
+ }
+ break;
+
+ case CMD_GET_IP_ADDR:
+ {
+ if (ad != NULL)
+ {
+ char* ip_addr = NULL;
+
+ result = wifi_direct_get_ip_address(&ip_addr);
+ printf("wifi_direct_get_ip_address() result=[%d]\n", result);
+ if(NULL != ip_addr)
+ {
+ printf("IP [%s]\n", ip_addr);
+ free(ip_addr);
+ }
+ else
+ {
+ printf("IP is NULL\n");
+ }
+ }
+ }
+ break;
+
+ case CMD_INCREASE_OEM_LOGLEVEL:
+ wifi_direct_set_p2poem_loglevel(1);
+ break;
+
+ case CMD_DECREASE_OEM_LOGLEVEL:
+ wifi_direct_set_p2poem_loglevel(0);
+ break;
+
+ case CMD_REGISTER_SERVICE:
+ if (ad != NULL)
+ {
+ wifi_direct_service_type_e service_type;
+ int input;
+ char info1[50] = {0,};
+ char info2[50] = {0,};
+ char str[50] = {0, };
+
+ printf("Input service type:\n");
+ printf("1. WIFI_DIRECT_SERVICE_TYPE_ALL\n");
+ printf("2. WIFI_DIRECT_SERVICE_TYPE_BONJOUR\n");
+ printf("3. WIFI_DIRECT_SERVICE_TYPE_UPNP\n");
+ printf("4. WIFI_DIRECT_SERVICE_TYPE_BT_ADDR\n");
+ printf("5. WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO\n");
+ scanf("%d", &input);
+ printf("input = %d\n",input);
+
+ switch(input)
+ {
+ case 1 :
+ service_type = WIFI_DIRECT_SERVICE_TYPE_ALL;
+ break;
+ case 2 :
+ service_type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR;
+ printf("Enter info 1\n");
+ scanf("%s", info1);
+ printf("Enter info 2\n");
+ scanf("%s", info2);
+ break;
+ case 3 :
+ service_type = WIFI_DIRECT_SERVICE_TYPE_UPNP;
+ printf("Enter info 1\n");
+ scanf("%s", info1);
+ printf("Enter info 2\n");
+ scanf("%s", info2);
+ break;
+ case 4 :
+ service_type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR;
+ break;
+ case 5 :
+ service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO;
+ printf("Enter contact info\n");
+ scanf("%s", str);
+ break;
+ default :
+ printf("ERROR : Invalid input service_type!!!\n");
+ break;
+ }
+
+ result = wifi_direct_register_service(service_type, info1, info2, &input);
+ printf("wifi_direct_register_service() service id=[%d] result=[%d]\n",
+ input, result);
+ }
+ break;
+
+ case CMD_DEREGISTER_SERVICE:
+ if (ad != NULL)
+ {
+ int input;
+
+ printf("Enter service id:\n");
+ scanf("%d", &input);
+
+
+ result = wifi_direct_deregister_service(input);
+ printf("wifi_direct_deregister_service() result=[%d]\n",
+ result);
+ }
+ break;
+ case CMD_START_SERVICE_DISCOVERY:
+ if (ad != NULL)
+ {
+ int input;
+ wifi_direct_service_type_e service_type;
+
+ printf("Input service type:\n");
+ printf("1. WIFI_DIRECT_SERVICE_TYPE_ALL\n");
+ printf("2. WIFI_DIRECT_SERVICE_TYPE_BONJOUR\n");
+ printf("3. WIFI_DIRECT_SERVICE_TYPE_UPNP\n");
+ printf("4. WIFI_DIRECT_SERVICE_TYPE_BT_ADDR\n");
+ printf("5. WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO\n");
+ scanf("%d", &input);
+ printf("input = %d\n",input);
+
+ switch(input)
+ {
+ case 1 :
+ service_type = WIFI_DIRECT_SERVICE_TYPE_ALL;
+ break;
+ case 2 :
+ service_type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR;
+ break;
+ case 3 :
+ service_type = WIFI_DIRECT_SERVICE_TYPE_UPNP;
+ break;
+ case 4 :
+ service_type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR;
+ break;
+ case 5 :
+ service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO;
+ break;
+ default :
+ printf("ERROR : Invalid input service_type!!!\n");
+ break;
+ }
+
+ if (select_peer(ad))
+ {
+
+ result = wifi_direct_start_service_discovery(
+ NULL, service_type);
+
+ printf ("Service Discovery... broadcast service type[%d]\n",
+ service_type);
+ } else {
+ int i = ad->selected_peer_index;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_start_service_discovery(
+ list[i].mac_address, service_type);
+
+ printf ("Service Discovery... peer-index[%d] MAC [%s] service type[%d]\n",
+ i,list[i].mac_address, service_type);
+ }
+
+ printf("wifi_direct_start_service_discovery() result=[%d]\n", result);
+
+ }
+ break;
+
+ case CMD_CANCEL_SERVICE_DISCOVERY:
+ if (ad != NULL)
+ {
+ int input;
+ wifi_direct_service_type_e service_type;
+
+ printf("Input service ID:\n");
+
+ scanf("%d", &input);
+ printf("input = %d\n",input);
+
+ switch(input)
+ {
+ case 1 :
+ service_type = WIFI_DIRECT_SERVICE_TYPE_ALL;
+ break;
+ case 2 :
+ service_type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR;
+ break;
+ case 3 :
+ service_type = WIFI_DIRECT_SERVICE_TYPE_UPNP;
+ break;
+ case 4 :
+ service_type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR;
+ break;
+ case 5 :
+ service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO;
+ break;
+ default :
+ printf("ERROR : Invalid input service_type!!!\n");
+ break;
+ }
+
+ if (select_peer(ad))
+ {
+
+
+ result = wifi_direct_cancel_service_discovery(
+ NULL, service_type);
+
+ printf ("Service Discovery... broadcast service type[%d]\n",
+ service_type);
+ } else {
+ int i = ad->selected_peer_index;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_cancel_service_discovery(
+ list[i].mac_address, service_type);
+
+ printf ("Service Discovery... peer-index[%d] MAC [%s] service type[%d]\n",
+ i,list[i].mac_address, service_type);
+ }
+ printf("wifi_direct_cancel_service_discovery() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_INIT_MIRACAST:
+ if (ad != NULL)
+ {
+ int miracast_enable;
+
+ printf("Input miracast enable: \n");
+ printf("[1] true [2] false\n");
+
+ scanf("%d", &miracast_enable);
+
+ if (miracast_enable == 1)
+ result = wifi_direct_init_miracast(true);
+ else if (miracast_enable == 2)
+ result = wifi_direct_init_miracast(false);
+ else
+ printf("Invalid input parameter!!!\n");
+
+ printf("wifi_direct_init_miracast() result=[%d] \n", result);
+
+ }
+ break;
+
+ case CMD_GET_PEER_INFO:
+ if (ad != NULL)
+ if (select_peer(ad))
+ {
+ int i = ad->selected_peer_index;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+ wifi_direct_discovered_peer_info_s* peer_info = NULL;
+
+ result = wifi_direct_get_peer_info(list[i].mac_address, &peer_info);
+ if(peer_info !=NULL) {
+ printf ("MAC [%s] Owner=[%s] connected=[%d] SSID[%s] ctg=[%d/%d]",
+ peer_info->mac_address,
+ peer_info->is_group_owner ? "YES" : "NO",
+ peer_info->is_connected,
+ peer_info->device_name,
+ peer_info->primary_device_type,
+ peer_info->secondary_device_type
+ );
+ if(peer_info->mac_address)
+ free(peer_info->mac_address);
+ if(peer_info->interface_address)
+ free(peer_info->interface_address);
+ if(peer_info)
+ free(peer_info);
+ }
+
+ printf("wifi_direct_get_peer() result=[%d]\n", result);
+ }
+ break;
+ case CMD_SET_PASSPHRASE:
+ {
+ if (ad != NULL)
+ {
+ char passphrase[64 + 1];
+
+ memset(passphrase, 0, sizeof(passphrase));
+ printf("Input passphrase :\n");
+ scanf("%s",passphrase);
+
+ if (strlen(passphrase) <= 0)
+ printf("invalid passphrase !!\n");
+ else
+ printf("passphrase: [%s]\n", passphrase);
+
+
+ if ((strlen(passphrase) > 0))
+ {
+ result = wifi_direct_set_passphrase(passphrase);
+ printf("wifi_direct_set_passphrase() ret=[%d]\n", result);
+ }
+ }
+ }
+ break;
+ case CMD_GET_PASSPHRASE:
+ {
+ if (ad != NULL)
+ {
+ char* passphrase = NULL;
+
+ result = wifi_direct_get_passphrase(&passphrase);
+ printf("wifi_direct_get_passphrase() result=[%d]\n", result);
+
+ if (NULL != passphrase)
+ {
+ printf("passphrase: [%s]\n", passphrase);
+ free(passphrase);
+ }
+
+ }
+ }
+ break;
+ case CMD_SET_AUTOCONNECTION_PEER:
+ if (ad != NULL)
+ {
+ char * mac_address = NULL;
+ printf("\nEnter Mac_address: ");
+ if(scanf(" %ms", &mac_address) < 1)
+ break;
+
+ if (strlen(mac_address) > 23)
+ {
+ printf("\nWrong Mac_address");
+ }
+ else {
+
+ int rv = wifi_direct_set_autoconnection_peer(mac_address);
+
+ if (rv == WIFI_DIRECT_ERROR_NONE)
+ {
+ free(mac_address);
+ printf(MAKE_GREEN"SUCCESS %s"RESET_COLOR"\n",__func__);
+ break;
+ }
+ printf(MAKE_RED"FAILED %s : %s"RESET_COLOR"\n",__func__,test_wfd_convert_error_to_string(rv));
+ }
+
+ free(mac_address);
+ }
+ break;
+ case CMD_INIT_DISPLAY:
+ {
+ if (ad != NULL)
+ {
+ result = wifi_direct_init_display();
+ printf("wifi_direct_init_display() result=[%d]\n", result);
+ }
+ }
+ break;
+ case CMD_DEINIT_DISPLAY:
+ {
+ if (ad != NULL)
+ {
+ result = wifi_direct_deinit_display();
+ printf("wifi_direct_deinit_display() result=[%d]\n", result);
+ }
+ }
+ break;
+ case CMD_SET_DISPLAY:
+ {
+ if (ad != NULL)
+ {
+ int rv = WIFI_DIRECT_ERROR_NONE;
+ int use_default = 0;
+
+ printf("Press [0] For Setting Default Values\n");
+ if(scanf(" %d",&use_default) < 1) {
+ break;
+ }
+
+ if(use_default == 0) {
+ rv = wifi_direct_set_display(WIFI_DIRECT_DISPLAY_TYPE_SOURCE, 7236, 1);
+ } else {
+ int display_type = 0;
+ int port_number = 0;
+ int hdcp = 0;
+
+ printf("DISPLAY_TYPE----->\n");
+ printf("(0) for WIFI_DISPLAY_TYPE_SOURCE,\n");
+ printf("(1) for WIFI_DISPLAY_TYPE_PRIMARY_SINK,\n");
+ printf("(2) for WIFI_DISPLAY_TYPE_SECONDARY_SINK,\n");
+ printf("(3) WIFI_DISPLAY_TYPE_DUAL_ROLE\n");
+ printf("Please Enter DISPLAY_TYPE -----> ");
+ if(scanf(" %d",&display_type) < 1) {
+ break;
+ }
+
+ printf("Please Enter PORT NUMBER -----> ");
+ if(scanf(" %d",&port_number) < 1) {
+ break;
+ }
+ printf("Please Enter HDCP -----> ");
+ if(scanf(" %d",&hdcp) < 1) {
+ break;
+ }
+
+ rv = wifi_direct_set_display(display_type, port_number, hdcp);
+ }
+
+ if(rv == WIFI_DIRECT_ERROR_NONE) {
+ printf(MAKE_GREEN"Success %s : %s"RESET_COLOR"\n",__func__,test_wfd_convert_error_to_string(rv));
+ break;
+ }
+
+ printf(MAKE_RED"FAILED %s : %s"RESET_COLOR"\n",__func__,test_wfd_convert_error_to_string(rv));
+ break;
+ }
+ }
+ break;
+ case CMD_SET_DISPLAY_AVAILABILITY:
+ {
+ if (ad != NULL)
+ {
+ int availability = 0;
+
+ printf("Enter Wi-Fi Display availability : ");
+ if(scanf(" %d", &availability) < 0) {
+ break;
+ }
+
+ int rv = wifi_direct_set_display_availability(availability);
+ if (WIFI_DIRECT_ERROR_NONE == rv)
+ {
+ printf(MAKE_GREEN"Set Wi-Fi Display availability Successfull"RESET_COLOR"\n");
+ break;
+ }
+ printf(MAKE_RED"Set Wi-Fi Display availability : %s ",test_wfd_convert_error_to_string(rv));
+ printf(RESET_COLOR"\n");
+ break;
+ }
+ }
+ break;
+ case CMD_GET_PEER_DISPLAY_TYPE:
+ if (ad != NULL)
+ {
+ if (select_peer(ad))
+ {
+ int i = ad->selected_peer_index;
+ int type;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_get_peer_display_type(list[i].mac_address, &type);
+
+ printf("wifi_direct_get_peer_display_type() result=[%d]\n", type);
+ }
+ }
+ break;
+ case CMD_GET_PEER_DISPLAY_AVAILABILITY:
+ if (ad != NULL)
+ {
+ if (select_peer(ad))
+ {
+ int i = ad->selected_peer_index;
+ int availability;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_get_peer_display_availability(list[i].mac_address, &availability);
+
+ printf("wifi_direct_get_peer_display_availability() result=[%d]\n", availability);
+ }
+ }
+ break;
+ case CMD_GET_PEER_DISPLAY_HDCP:
+ if (ad != NULL)
+ {
+ if (select_peer(ad))
+ {
+ int i = ad->selected_peer_index;
+ int hdcp;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_get_peer_display_hdcp(list[i].mac_address, &hdcp);
+
+ printf("wifi_direct_get_peer_display_hdcp() result=[%d]\n", hdcp);
+ }
+ }
+ break;
+ case CMD_GET_PEER_DISPLAY_PORT:
+ if (ad != NULL)
+ {
+ if (select_peer(ad))
+ {
+ int i = ad->selected_peer_index;
+ int port;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_get_peer_display_port(list[i].mac_address, &port);
+
+ printf("wifi_direct_get_peer_display_port() result=[%d]\n", port);
+ }
+ }
+ break;
+ case CMD_GET_PEER_DISPLAY_THROUGHPUT:
+ if (ad != NULL)
+ {
+ if (select_peer(ad))
+ {
+ int i = ad->selected_peer_index;
+ int tput;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_get_peer_display_throughput(list[i].mac_address, &tput);
+
+ printf("wifi_direct_get_peer_display_throughput() result=[%d]\n", tput);
+ }
+ }
+ break;
+
+ case CMD_FULL_MENU:
+ usage_full();
+ break;
+
+ case CMD_QUIT:
+ printf("Bye\n");
+ g_main_loop_quit(ad->main_loop);
+ break;
+
+ default:
+ usage_full();
+ break;
+ }
+}
+
+static gboolean test_terminal_read_std_input(GIOChannel * source,
+ GIOCondition condition, gpointer user_data)
+{
+ int fd = 0;
+
+ static char buf[1024];
+ int n;
+
+ errno = 0;
+ n = read(fd, buf, 1024);
+
+ buf[n - 1] = '\0'; // remove new line...
+ if (n == 0)
+ {
+ printf("Error: read() from stdin returns 0.\n");
+ }
+ else if (n < 0)
+ {
+ printf("input: read, err=%s\n", strerror(errno));
+ }
+ else
+ {
+ printf("\n\n");
+ //printf("Read [%d]bytes data: [%s]\n", n, buf);
+ //printf("Processing it ---------------------\n", n, buf);
+ }
+
+ process_input(buf, user_data);
+
+ return TRUE;
+}
+
+int main(int argc, char **argv)
+{
+ GMainLoop *main_loop;
+ int pid = -1;
+ int result;
+
+ struct appdata *ad = NULL;
+
+#if !GLIB_CHECK_VERSION(2,36,0)
+ g_type_init();
+#endif
+
+ main_loop = g_main_loop_new(NULL, FALSE);
+
+ ad = (struct appdata*)malloc(sizeof(struct appdata));
+
+ ad->main_loop = main_loop;
+#if 0
+ ad->peer_list = NULL;
+#endif
+ ad->peer_count = 0;
+
+ set_appdata(ad);
+
+ int r = get_param(argc, argv, ad);
+ if (r)
+ return -1;
+
+
+ int std_input_fd = 0;
+ GIOChannel *gio2 = g_io_channel_unix_new(std_input_fd);
+ g_io_add_watch(gio2, G_IO_IN, (GIOFunc) test_terminal_read_std_input, ad);
+ g_io_channel_unref(gio2);
+
+ usage_full();
+
+ g_main_loop_run(main_loop);
+
+ return 0;
+}
+