--- /dev/null
+/*
+ * libwifi-direct
+ *
+ * Copyright (c) 2000 - 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.
+ *
+ */
+
+#ifndef __WIFI_DIRECT_INTERFACE_H_
+#define __WIFI_DIRECT_INTERFACE_H_
+
+#include <errno.h>
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+/**
+ * @addtogroup CAPI_NET_WIFI_DIRECT_MODULE
+ * @{
+ */
+
+/**
+ * @brief Enumeration for Wi-Fi Direct error code
+ */
+typedef enum
+{
+ WIFI_DIRECT_ERROR_NONE = 0, /**< Successful */
+ WIFI_DIRECT_ERROR_OUT_OF_MEMORY = -ENOMEM, /**< Out of memory */
+ WIFI_DIRECT_ERROR_NOT_PERMITTED = -EPERM, /**< Operation not permitted */
+ WIFI_DIRECT_ERROR_INVALID_PARAMETER = -EINVAL, /**< Invalid function parameter */
+ WIFI_DIRECT_ERROR_RESOURCE_BUSY = -EBUSY, /**< Device or resource busy */
+ WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT = -ETIMEDOUT, /**< Connection timed out */
+ WIFI_DIRECT_ERROR_NOT_INITIALIZED = -0x00008000|0x0201, /**< Not initialized */
+ WIFI_DIRECT_ERROR_COMMUNICATION_FAILED = -0x00008000|0x0202, /**< I/O error */
+ WIFI_DIRECT_ERROR_WIFI_USED = -0x00008000|0x0203, /**< WiFi is being used */
+ WIFI_DIRECT_ERROR_MOBILE_AP_USED = -0x00008000|0x0204, /**< Mobile AP is being used */
+ WIFI_DIRECT_ERROR_CONNECTION_FAILED = -0x00008000|0x0205, /**< Connection failed */
+ WIFI_DIRECT_ERROR_AUTH_FAILED = -0x00008000|0x0206, /**< Authentication failed */
+ WIFI_DIRECT_ERROR_OPERATION_FAILED = -0x00008000|0x0207, /**< Operation failed */
+ WIFI_DIRECT_ERROR_TOO_MANY_CLIENT = -0x00008000|0x0208, /**< Too many client */
+} wifi_direct_error_e;
+
+/**
+ * @brief Enumeration for Wi-Fi Direct link status
+ */
+typedef enum
+{
+ WIFI_DIRECT_STATE_DEACTIVATED = 0,
+ /**< */
+ WIFI_DIRECT_STATE_DEACTIVATING, /**< */
+ WIFI_DIRECT_STATE_ACTIVATING, /**< */
+ WIFI_DIRECT_STATE_ACTIVATED, /**< */
+ WIFI_DIRECT_STATE_DISCOVERING, /**< */
+ WIFI_DIRECT_STATE_CONNECTING, /**< */
+ WIFI_DIRECT_STATE_DISCONNECTING, /**< */
+ WIFI_DIRECT_STATE_CONNECTED, /**< */
+ WIFI_DIRECT_STATE_GROUP_OWNER /**< */
+} wifi_direct_state_e;
+
+/**
+ * @brief Enumeration for Wi-Fi Direct device state
+ */
+typedef enum
+{
+ WIFI_DIRECT_DEVICE_STATE_ACTIVATED,
+ WIFI_DIRECT_DEVICE_STATE_DEACTIVATED,
+} wifi_direct_device_state_e;
+
+/**
+ * @brief Enumeration for Wi-Fi Direct discovery state
+ */
+typedef enum
+{
+ WIFI_DIRECT_ONLY_LISTEN_STARTED,
+ WIFI_DIRECT_DISCOVERY_STARTED,
+ WIFI_DIRECT_DISCOVERY_FOUND,
+ WIFI_DIRECT_DISCOVERY_FINISHED,
+} wifi_direct_discovery_state_e;
+
+/**
+ * @brief Enumeration for Wi-Fi Direct connection state
+ */
+typedef enum
+{
+ WIFI_DIRECT_CONNECTION_REQ, /**< */
+ WIFI_DIRECT_CONNECTION_WPS_REQ, /**< */
+ WIFI_DIRECT_CONNECTION_IN_PROGRESS, /**< */
+ WIFI_DIRECT_CONNECTION_RSP, /**< */
+ WIFI_DIRECT_DISASSOCIATION_IND, /**< */
+ WIFI_DIRECT_DISCONNECTION_RSP, /**< */
+ WIFI_DIRECT_DISCONNECTION_IND, /**< */
+ WIFI_DIRECT_GROUP_CREATED, /**< */
+ WIFI_DIRECT_GROUP_DESTROYED, /**< */
+ WIFI_DIRECT_INVITATION_REQ,
+} wifi_direct_connection_state_e;
+
+/**
+ * @brief Enumeration for Wi-Fi Direct secondary device type
+ */
+typedef enum
+{
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_PC = 1, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_SERVER = 2, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_MEDIA_CTR = 3, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_UMPC = 4, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_NOTEBOOK = 5, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_DESKTOP = 6, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_MID = 7, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_NETBOOK = 8, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_KEYBOARD = 1, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_MOUSE = 2, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_JOYSTICK = 3, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_TRACKBALL = 4, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_CONTROLLER = 5, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_REMOTE = 6, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_TOUCHSCREEN = 7,/**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_BIO_READER = 8, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_BAR_READER = 9, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PRINTER_PRINTER = 1, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PRINTER_SCANNER = 2, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PRINTER_FAX = 3, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PRINTER_COPIER = 4, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PRINTER_ALLINONE = 5, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_CAMERA_DIGITAL_STILL = 1, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_CAMERA_VIDEO = 2, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_CAMERA_WEBCAM = 3, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_CAMERA_SECONDARYURITY = 4, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_STORAGE_NAS = 1, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_NETWORK_INFRA_AP = 1, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_NETWORK_INFRA_ROUTER = 2, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_NETWORK_INFRA_SWITCH = 3, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_NETWORK_INFRA_GATEWAY = 4, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_DISPLAY_TV = 1, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_DISPLAY_PIC_FRAME = 2, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_DISPLAY_PROJECTOR = 3, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_DISPLAY_MONITOR = 4, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_MULTIMEDIA_DAR = 1, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_MULTIMEDIA_PVR = 2, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_MULTIMEDIA_MCX = 3, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_MULTIMEDIA_STB = 4, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_MULTIMEDIA_MSMAME = 5, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_MULTIMEDIA_PVP = 6, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_GAME_XBOX = 1, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_GAME_XBOX_360 = 2, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_GAME_PS = 3, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_GAME_CONSOLE = 4, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_GAME_PORTABLE = 5, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PHONE_WM = 1, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PHONE_SINGLE = 2, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PHONE_DUAL = 3, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PHONE_SM_SINGLE = 4,
+ /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PHONE_SM_DUAL = 5, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_AUDIO_TUNER = 1, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_AUDIO_SPEAKER = 2, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_AUDIO_PMP = 3, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_AUDIO_HEADSET = 4, /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_AUDIO_HEADPHONE = 5,
+ /**< */
+ WIFI_DIRECT_SECONDARY_DEVICE_TYPE_AUDIO_MIC = 6, /**< */
+} wifi_direct_secondary_device_type_e;
+
+/**
+ * @brief Enumeration for Wi-Fi Direct primary device type
+ */
+typedef enum
+{
+ WIFI_DIRECT_PRIMARY_DEVICE_TYPE_COMPUTER = 1, /**< */
+ WIFI_DIRECT_PRIMARY_DEVICE_TYPE_INPUT_DEVICE = 2, /**< */
+ WIFI_DIRECT_PRIMARY_DEVICE_TYPE_PRINTER = 3, /**< */
+ WIFI_DIRECT_PRIMARY_DEVICE_TYPE_CAMERA = 4, /**< */
+ WIFI_DIRECT_PRIMARY_DEVICE_TYPE_STORAGE = 5, /**< */
+ WIFI_DIRECT_PRIMARY_DEVICE_TYPE_NETWORK_INFRA = 6, /**< */
+ WIFI_DIRECT_PRIMARY_DEVICE_TYPE_DISPLAY = 7, /**< */
+ WIFI_DIRECT_PRIMARY_DEVICE_TYPE_MULTIMEDIA_DEVICE = 8, /**< */
+ WIFI_DIRECT_PRIMARY_DEVICE_TYPE_GAME_DEVICE = 9, /**< */
+ WIFI_DIRECT_PRIMARY_DEVICE_TYPE_TELEPHONE = 10, /**< */
+ WIFI_DIRECT_PRIMARY_DEVICE_TYPE_AUDIO = 11, /**< */
+ WIFI_DIRECT_PRIMARY_DEVICE_TYPE_OTHER = 255 /**< */
+} wifi_direct_primary_device_type_e;
+
+
+/**
+* @brief Enumeration for Wi-Fi WPS type
+*/
+typedef enum {
+ WIFI_DIRECT_WPS_TYPE_NONE = 0x00, /**< No WPS type */
+ WIFI_DIRECT_WPS_TYPE_PBC = 0x01, /**< Push Button Configuration */
+ WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY = 0x02, /**< Display PIN code */
+ WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD = 0x04, /**< Provide the keypad to input the PIN */
+} wifi_direct_wps_type_e;
+
+
+/**
+ * @struct wifi_direct_discovered_peer_info_s
+ * Wi-Fi Direct buffer structure to store result of peer discovery
+ */
+typedef struct
+{
+ char* device_name; /** Null-terminated device friendly name. */
+ char *mac_address; /** Device's P2P Device Address */
+ char* interface_address; /** Device's P2P Interface Address. Valid only if device is a P2P GO. */
+ int channel; /** Channel the device is listening on. */
+ bool is_connected; /** Is peer connected*/
+ bool is_group_owner; /** Is an active P2P Group Owner */
+ bool is_persistent_group_owner; /** Is a stored Persistent GO */
+ wifi_direct_primary_device_type_e primary_device_type; /** Primary category of device */
+ wifi_direct_secondary_device_type_e secondary_device_type; /** Sub category of device */
+ int supported_wps_types; /** The list of supported WPS type. \n
+ The OR operation on #wifi_direct_wps_type_e can be used like #WIFI_DIRECT_WPS_TYPE_PBC | #WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY */
+ char* ssid; /**< Service set identifier - DEPRECATED */
+} wifi_direct_discovered_peer_info_s;
+
+
+/**
+ * @struct wifi_direct_connected_peer_info_s
+ * Wi-Fi Direct buffer structure to store information of connected peer
+ */
+typedef struct
+{
+ char* device_name; /** Device friendly name. */
+ char* ip_address; /**< The IP address */
+ char* mac_address; /** Device's P2P Device Address */
+ char* interface_address; /** Device's P2P Interface Address */
+ bool p2p_supported; /* whether peer is a P2P device */
+ wifi_direct_primary_device_type_e primary_device_type; /* primary category of device */
+ int channel; /* Operating channel */
+ char* ssid; /**< Service set identifier - DEPRECATED */
+} wifi_direct_connected_peer_info_s;
+
+/**
+ * Notification callback function type. \n
+ *
+ * Discover notifications can occur at the peers or P2P groups are found.
+ *
+ * @param event Specifies the types of notifications.
+ * - WIFI_DIRECT_DISCOVERY_STARTED
+ * - WIFI_DIRECT_ONLY_LISTEN_STARTED
+ * - WIFI_DIRECT_DISCOVERY_FOUND
+ * - WIFI_DIRECT_DISCOVERY_FINISHED
+ * @param error_code In failure case.
+ * @param user_data User can transfer the user specific data in callback.
+ *
+ */
+typedef void (*wifi_direct_discovery_state_chagned_cb) (int error_code,
+ wifi_direct_discovery_state_e
+ discovery_state,
+ void *user_data);
+
+/**
+ * Notification callback function type. \n
+ *
+ * Activation notifications callback function type.
+ *
+ * @param event Specifies the types of notifications.
+ * - WIFI_DIRECT_DEVICE_STATE_ACTIVATED
+ * - WIFI_DIRECT_DEVICE_STATE_DEACTIVATED
+ * @param error_code In failure case.
+ * @param user_data User can transfer the user specific data in callback.
+ *
+ */
+typedef void (*wifi_direct_device_state_changed_cb) (int error_code,
+ wifi_direct_device_state_e
+ device_state,
+ void *user_data);
+
+/**
+ * connection notification callback function type. \n
+ *
+ * @param event Specifies the types of notifications.
+ * - WIFI_DIRECT_CONNECTION_REQ
+ * - WIFI_DIRECT_CONNECTION_WPS_REQ
+ * - WIFI_DIRECT_CONNECTION_IN_PROGRESS
+ * - WIFI_DIRECT_CONNECTION_RSP
+ * - WIFI_DIRECT_DISASSOCIATION_IND
+ * - WIFI_DIRECT_DISCONNECTION_RSP
+ * - WIFI_DIRECT_DISCONNECTION_IND
+ * - WIFI_DIRECT_GROUP_CREATED
+ * - WIFI_DIRECT_GROUP_DESTROYED
+ *
+ * @param error_code In failure case.
+ *
+ * @param param1 additional data for connection. ex) MAC
+ * @param param2 additional data for connection. ex) SSID
+ *
+ * @param user_data User can transfer the user specific data in callback.
+ *
+ */
+typedef void (*wifi_direct_connection_state_changed_cb) (int error_code,
+ wifi_direct_connection_state_e
+ connection_state,
+ const char
+ *mac_address,
+ void *user_data);
+
+
+
+/**
+* @brief Called when IP address of client is assigned when your device is group owner.
+* @param[in] mac_address The MAC address of connection peer
+* @param[in] ip_address The IP address of connection peer
+* @param[in] interface_address The interface address of connection peer
+* @param[in] user_data The user data passed from the callback registration function
+* @see wifi_direct_set_client_ip_address_assigned_cb()
+* @see wifi_direct_unset_client_ip_address_assigned_cb()
+*/
+typedef void (*wifi_direct_client_ip_address_assigned_cb) (const char* mac_address,
+ const char* ip_address,
+ const char* interface_address,
+ void *user_data);
+
+
+
+/*=============================================================================
+ Wifi Direct Client APIs
+=============================================================================*/
+
+/*****************************************************************************/
+/* wifi_direct_initialize API function prototype
+ * int wifi_direct_initialize (void);
+ */
+/**
+ * \brief This API shall register the client application with the Wi-Fi Direct server and initialize the various variables. \n
+ *
+ * \pre None.
+ *
+ * \post Application is registered.
+ *
+ * \see wifi_direct_device_state_changed_cb
+ * \see wifi_direct_discovery_state_chagned_cb
+ * \see wifi_direct_connection_state_changed_cb
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ * \return Return Type (int) \n
+ *
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_TOO_MANY_CLIENT for "Too many users" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \remarks None.
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo(void)
+ * {
+ *
+ * int result;
+ *
+ * result = wifi_direct_initialize();
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE).........// Successfully connected to the wifi direct server
+ *
+ * \endcode
+ ******************************************************************************/
+int wifi_direct_initialize(void);
+
+
+/*****************************************************************************************/
+/* wifi_direct_deinitialize API function prototype
+ * int wifi_direct_deinitialize(void);
+ */
+
+/**
+ * \brief This API shall deregister the client application with the Wi-Fi Direct server and releases all resources.
+ *
+ * \pre Application must be already registered to the Wi-Fi Direct server.
+ *
+ * \post Application is de-registered.
+ *
+ * \see wifi_direct_initialize
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ *
+ * \par Async Response Message:
+ * None
+ *
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo(void)
+ * {
+
+ * int result;
+ *
+ * result = wifi_direct_deinitialize();
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // Deregister is successful
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_deinitialize(void);
+
+
+/*****************************************************************************/
+/* wifi_direct_set_connection_state_changed_cb API function prototype
+ * int wifi_direct_set_connection_state_changed_cb(wifi_direct_device_state_changed_cb cb, void* user_data)
+ */
+/**
+ * \brief This API shall register the activation callback function and user data from client. \n
+ *
+ * \pre The Client should be initialized.
+ *
+ * \see wifi_direct_initialize
+ * \see wifi_direct_device_state_changed_cb
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ * \param[in] cb Application Callback function pointer to receive Wi-Fi Direct events
+ * \param[in] user_data user data
+ *
+ * \return Return Type (int) \n
+ *
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \remarks None.
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo(void)
+ * {
+ *
+ * int result;
+ *
+ * result = wifi_direct_set_connection_state_changed_cb(_cb_activation, void* user_data);
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE).........// Successfully registered the callback function
+ *
+ * \endcode
+ ******************************************************************************/
+int wifi_direct_set_device_state_changed_cb(wifi_direct_device_state_changed_cb cb, void *user_data);
+
+
+/*****************************************************************************/
+/* wifi_direct_unset_connection_state_changed_cb API function prototype
+ * int wifi_direct_unset_connection_state_changed_cb(void)
+ */
+/**
+ * \brief This API shall deregister the activation callback function and user data from client. \n
+ *
+ * \pre The Client should be initialized.
+ *
+ * \see wifi_direct_initialize
+ * \see wifi_direct_set_connection_state_changed_cb
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ * \return Return Type (int) \n
+ *
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \remarks None.
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo(void)
+ * {
+ *
+ * int result;
+ *
+ * result = wifi_direct_unset_connection_state_changed_cb();
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE).........// Successfully deregistered the callback function
+ *
+ * \endcode
+ ******************************************************************************/
+int wifi_direct_unset_device_state_changed_cb(void);
+
+
+
+/*****************************************************************************/
+/* wifi_direct_set_discovery_state_changed_cb API function prototype
+ * int wifi_direct_set_discover_state_changed_cb(wifi_direct_discovery_state_chagned_cb cb, void* user_data)
+ */
+/**
+ * \brief This API shall register the discover callback function and user data from client. \n
+ *
+ * \pre The Client should be initialized.
+ *
+ * \see wifi_direct_initialize
+ * \see wifi_direct_discovery_state_chagned_cb
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ * \param[in] cb Application Callback function pointer to receive Wi-Fi Direct events
+ * \param[in] user_data user data
+ *
+ * \return Return Type (int) \n
+ *
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \remarks None.
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo(void)
+ * {
+ *
+ * int result;
+ *
+ * result = wifi_direct_set_discovery_state_changed_cb(_cb_discover, void* user_data);
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE).........// Successfully registered the callback function
+ *
+ * \endcode
+ ******************************************************************************/
+int wifi_direct_set_discovery_state_changed_cb(wifi_direct_discovery_state_chagned_cb cb, void *user_data);
+
+
+/*****************************************************************************/
+/* wifi_direct_unset_discovery_state_changed_cb API function prototype
+ * int wifi_direct_unset_discovery_state_changed_cb(void)
+ */
+/**
+ * \brief This API shall deregister the discover callback function and user data from client. \n
+ *
+ * \pre The Client should be initialized.
+ *
+ * \see wifi_direct_initialize
+ * \see wifi_direct_set_discovery_state_changed_cb
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ * \return Return Type (int) \n
+ *
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \remarks None.
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo(void)
+ * {
+ *
+ * int result;
+ *
+ * result = wifi_direct_unset_discovery_state_changed_cb();
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE).........// Successfully deregistered the callback function
+ *
+ * \endcode
+ ******************************************************************************/
+int wifi_direct_unset_discovery_state_changed_cb(void);
+
+
+
+/*****************************************************************************/
+/* wifi_direct_set_connection_state_changed_cb API function prototype
+ * int wifi_direct_set_connection_state_changed_cb(wifi_direct_connection_state_changed_cb cb, void* user_data)
+ */
+/**
+ * \brief This API shall register the connection callback function and user data from client. \n
+ *
+ * \pre The Client should be initialized.
+ *
+ * \see wifi_direct_initialize
+ * \see wifi_direct_connection_state_changed_cb
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ * \param[in] cb Application Callback function pointer to receive Wi-Fi Direct events
+ * \param[in] user_data user data
+ *
+ * \return Return Type (int) \n
+ *
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \remarks None.
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo(void)
+ * {
+ *
+ * int result;
+ *
+ * result = wifi_direct_set_connection_state_changed_cb(_cb_connection, void* user_data);
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE).........// Successfully registered the callback function
+ *
+ * \endcode
+ ******************************************************************************/
+int wifi_direct_set_connection_state_changed_cb(wifi_direct_connection_state_changed_cb cb, void *user_data);
+
+
+/*****************************************************************************/
+/* wifi_direct_unset_connection_state_changed_cb API function prototype
+ * int wifi_direct_unset_connection_state_changed_cb(void)
+ */
+/**
+ * \brief This API shall deregister the connection callback function and user data from client. \n
+ *
+ * \pre The Client should be initialized.
+ *
+ * \see wifi_direct_initialize
+ * \see wifi_direct_set_connection_state_changed_cb
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ * \return Return Type (int) \n
+ *
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \remarks None.
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo(void)
+ * {
+ *
+ * int result;
+ *
+ * result = wifi_direct_unset_connection_state_changed_cb();
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE).........// Successfully deregistered the callback function
+ *
+ * \endcode
+ ******************************************************************************/
+int wifi_direct_unset_connection_state_changed_cb(void);
+
+
+/**
+* @brief Registers the callback called when IP address of client is assigned when your device is group owner.
+* @param[in] cb The callback function to invoke
+* @param[in] user_data The user data to be passed to the callback function
+* @return 0 on success, otherwise a negative error value.
+* @retval #WIFI_DIRECT_ERROR_NONE Successful
+* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized
+* @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize().
+* @see wifi_direct_initialize()
+* @see wifi_direct_unset_client_ip_address_assigned_cb()
+* @see wifi_direct_client_ip_address_assigned_cb()
+*/
+int wifi_direct_set_client_ip_address_assigned_cb(wifi_direct_client_ip_address_assigned_cb cb, void* user_data);
+
+
+/**
+* @brief Unregisters the callback called when IP address of client is assigned when your device is group owner.
+* @return 0 on success, otherwise a negative error value.
+* @retval #WIFI_DIRECT_ERROR_NONE Successful
+* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized
+* @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize().
+* @see wifi_direct_initialize()
+* @see wifi_direct_set_connection_state_changed_cb()
+*/
+int wifi_direct_unset_client_ip_address_assigned_cb(void);
+
+
+
+
+/*****************************************************************************************/
+/* wifi_direct_activate API function prototype
+ * int wifi_direct_activate(void);
+ */
+
+/**
+ * \brief This API shall open a wireless adapter device for P2P use.
+
+ * \pre Application must be already registered to the Wi-Fi Direct server.
+ *
+ * \post wireless adapter device will be ready to use.
+ *
+ * \see wifi_direct_initialize
+ *
+ * \par Sync (or) Async:
+ * This is a Asynchronous API.
+ *
+ * \warning
+ * None
+ *
+ *
+ * \par Async Response Message:
+ * - WIFI_DIRECT_DEVICE_STATE_ACTIVATED : Application will receive this event via wifi_direct_device_state_changed_cb, when activation process is completed. \n
+ *
+ *
+ * \return Return Type (int*) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ * - WIFI_DIRECT_ERROR_WIFI_USED for "WiFi is being used" \n
+ * - WIFI_DIRECT_ERROR_MOBILE_AP_USED for "Mobile AP is being used" \n
+ *
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo(void)
+ * {
+
+ * int result;
+ *
+ * result = wifi_direct_activate();
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // activation is successful
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_activate(void);
+
+
+/*****************************************************************************************/
+/* wifi_direct_deactivate API function prototype
+ * int wifi_direct_deactivate(void);
+ */
+
+/**
+ * \brief This API shall close a wireless adapter device for P2P use
+
+ * \pre Wireless adapter device must be already opened.
+ *
+ * \post wireless adapter device will be closed.
+ *
+ * \see wifi_direct_activate
+ *
+ * \par Sync (or) Async:
+ * This is a Asynchronous API.
+ *
+ * \warning
+ * None
+ *
+ *
+ * \par Async Response Message:
+ * - WIFI_DIRECT_DEVICE_STATE_DEACTIVATED : Application will receive this event via wifi_direct_device_state_changed_cb, when deactivation process is completed. \n
+
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo(void)
+ * {
+ * int result;
+ *
+ * result = wifi_direct_deactivate();
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // Deactivation is successful
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_deactivate(void);
+
+
+/*****************************************************************************************/
+/* wifi_direct_start_discovery API function prototype
+ * int wifi_direct_start_discovery(bool listen_only, int timeout);
+ */
+/**
+ * \brief This API shall Start a discovery to find all P2P capable devices. \n
+ * Applications will be notified event via wifi_direct_discovery_state_chagned_cb(). \n
+ *
+ * @param listen_only if true, skip the initial 802.11 scan and then enter
+ * Listen state instead of cycling between Search and Listen.
+ * @param timeout Specifies the duration of discovery period, in seconds.
+ * APs. If 0, a default value will be used, which depends on UX guideline.
+ *
+ * \pre Wireless adapter device must be already opened.
+ *
+ *
+ * \see wifi_direct_get_discovery_result
+ *
+ * \par Sync (or) Async:
+ * This is a Asynchronous API.
+ *
+ * \warning
+ * None
+ *
+ *
+ * \par Async Response Message:
+ * - WIFI_DIRECT_DISCOVERY_STARTED : Application will receive this event via wifi_direct_discovery_state_chagned_cb (), when discover process (80211 Scan) started. \n
+ * - WIFI_DIRECT_ONLY_LISTEN_STARTED : Application will receive this event via wifi_direct_discovery_state_chagned_cb (), when discover process (listen only mode) started. \n
+ * - WIFI_DIRECT_DISCOVERY_FOUND : Application will receive this event via wifi_direct_discovery_state_chagned_cb (), when peer or group is found. \n
+ * - WIFI_DIRECT_DISCOVERY_FINISHED : Once the whole discovery process is completed, applications will receive it via wifi_direct_discovery_state_chagned_cb (). \n
+ * Applications may then call wifi_direct_foreach_discovered_peers() to get the final result. \n
+ * With the intermediate or final list of P2P capable devices, applications can update their UI if needed. \n
+ * It is up to the applications to control how often to update their UI display. \n
+ *
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_INVALID_PARAMETER for "Invalid function parameter" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo(void)
+ * {
+
+ * int result;
+ *
+ * result = wifi_direct_start_discovery(TRUE, 0);
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // discovery request is successful
+ *
+ *\endcode
+ *
+ *\remarks If discover is over, peer can not find the device and the device can not find peer, too.
+ *
+ ******************************************************************************/
+int wifi_direct_start_discovery(bool listen_only, int timeout);
+
+
+/*****************************************************************************************/
+/* wifi_direct_cancel_discovery API function prototype
+ * int wifi_direct_cancel_discovery(void);
+ */
+/**
+ * \brief This API shall cancel the discovery process started from wifi_direct_start_discovery. \n
+ *
+ * \pre discovery process must be started.
+ *
+ * \post discovery process stopped.
+ *
+ * \see wifi_direct_client_start_discovery
+ *
+ * \par Sync (or) Async:
+ * This is a Asynchronous API.
+ *
+ * \warning
+ * None
+ *
+ *
+ * \par Async Response Message:
+ * - WIFI_DIRECT_DISCOVERY_FINISHED : Applications will receive a this event
+ * via callback when the discovery process is cancelled or completed.
+ *
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo(void)
+ * {
+
+ * int result;
+ *
+ * result = wifi_direct_cancel_discovery();
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // discovery cancel request is successful
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_cancel_discovery(void);
+
+
+/**
+ * discorverd peers notification callback function type. \n
+ *
+ * @param peer The discovered peer information.
+ * @param user_data The user data passed from the foreach function.
+ * @return @c true to continue with the next iteration of the loop,
+ * \n @c false to break out of the loop.
+ *
+ * @pre wifi_direct_foreach_discovered_peers() will invoke this function.
+ *
+ * @see wifi_direct_foreach_discovered_peers()
+ *
+ */
+typedef bool(*wifi_direct_discovered_peer_cb) (wifi_direct_discovered_peer_info_s * peer, void *user_data);
+
+
+/*****************************************************************************************/
+/* wifi_direct_foreach_discovered_peers API function prototype
+ * int wifi_direct_foreach_discovered_peers(wifi_direct_discovered_peer_cb, void* user_data)
+ */
+/**
+ * \brief This API shall get the information of all discovered peers. \n
+ *
+ * @param callback The callback function to invoke.
+ * @param user_data The user data passed from the foreach function.
+ *
+ * \see wifi_direct_discovered_peer_cb
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_INVALID_PARAMETER for "Invalid function parameter" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * bool _cb_discovered_peers_impl(wifi_direct_discovered_peer_info_s* peer, void* user_data)
+ * {
+ * 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
+ * }
+ *
+ *
+ * void foo()
+ * {
+ * int result;
+ *
+ * ad->peer_list = NULL;
+ * ad->peer_count = 0;
+ * ad ->selected_peer_index = 0;
+ * result = wifi_direct_foreach_discovered_peers(_cb_discovered_peers_impl, (void*)ad);
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // get discovery result is successful
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_foreach_discovered_peers(wifi_direct_discovered_peer_cb
+ callback, void *user_data);
+
+
+/*****************************************************************************************/
+/* wifi_direct_connect API function prototype
+ * int wifi_direct_connect(const char* mac_address);
+ */
+/**
+ * \brief This API shall connect to specified peer by automatically determining whether to perform group \n
+ * formation, join an existing group, invite, re-invoke a group. The decision is \n
+ * based on the current state of the peers (i.e. GO, STA, not connected) and the \n
+ * availability of persistent data. \n
+ *
+ * @param mac_addr Device address of target peer.
+ *
+ * \par Sync (or) Async:
+ * This is a Asynchronous API.
+ *
+ * \warning
+ * None
+ *
+ *
+ * \par Async Response Message:
+ * - WIFI_DIRECT_CONNECTION_IN_PROGRESS : Applications will receive this event
+ * via callback when the connection process is started.
+ * - WIFI_DIRECT_CONNECTION_RSP : Applications will receive this event
+ * via callback when the connection process is completed or failed.
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_INVALID_PARAMETER for "Invalid function parameter" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT for "Connection timed out" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ * - WIFI_DIRECT_ERROR_CONNECTION_FAILED for "Create Link fail" \n
+ * - WIFI_DIRECT_ERROR_AUTH_FAILED for "Create Link Auth fail" \n
+ *
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo(unsigned char* mac_addr)
+ * {
+
+ * int result;
+ *
+ * result = wifi_direct_connect(mac_addr);
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // connect request is successful
+ *
+ *\endcode
+ *
+ *\remarks This API will try to send provisioning request befre connecting.
+ *
+ ******************************************************************************/
+int wifi_direct_connect(const char *mac_address);
+
+
+/*****************************************************************************************/
+/* wifi_direct_disconnect_all API function prototype
+ * int wifi_direct_disconnect_all(void);
+ */
+/**
+ * \brief This API shall tear down all connected links to peers (stop soft AP, and close interface). \n
+ *
+ * \see wifi_direct_connect
+ *
+ * \par Sync (or) Async:
+ * This is a Asynchronous API.
+ *
+ * \warning
+ * None
+ *
+ *
+ * \par Async Response Message:
+ * - WIFI_DIRECT_DISCONNECTION_RSP : Applications will receive this event
+ * via callback when the disconnection process is completed.
+ *
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo(void)
+ * {
+
+ * int result;
+ *
+ * result = wifi_direct_disconnect_all();
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // disconnect request is successful
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_disconnect_all(void);
+
+
+
+/*****************************************************************************************/
+/* wifi_direct_disconnect API function prototype
+ * int wifi_direct_disconnect(const char* mac_address);
+ */
+/**
+ * \brief This API shall disconnect the specified peer by mac address.
+ *
+ * @param mac_addr Device address of target peer.
+ *
+ * \see
+ *
+ * \par Sync (or) Async:
+ * This is a Asynchronous API.
+ *
+ * \warning
+ * None
+ *
+ *
+ * \par Async Response Message:
+ * - WIFI_DIRECT_DISCONNECTION_RSP : Applications will receive a this event
+ * via callback when a peer is disconnected.
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_INVALID_PARAMETER for "Invalid function parameter" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo(unsigned char* mac_addr)
+ * {
+
+ * int result;
+ *
+ * result = wifi_direct_disconnect(mac_addr);
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // disconnect request is successful
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_disconnect(const char *mac_address);
+
+
+
+/**
+ * connected peers notification callback function type. \n
+ *
+ * @param peer The connected peer information.
+ * @param user_data The user data passed from the foreach function.
+ * @return @c true to continue with the next iteration of the loop,
+ * \n @c false to break out of the loop.
+ *
+ * @pre wifi_direct_foreach_connected_peers() will invoke this function.
+ *
+ * @see wifi_direct_foreach_connected_peers()
+ *
+ */
+typedef bool(*wifi_direct_connected_peer_cb) (wifi_direct_connected_peer_info_s
+ * peer, void *user_data);
+
+
+/*****************************************************************************************/
+/* wifi_direct_foreach_connected_peers API function prototype
+ * int wifi_direct_foreach_connected_peers(wifi_direct_connected_peer_cb, void* user_data)
+ */
+/**
+ * \brief This API shall get the information of all connected peers. \n
+ *
+ * @param callback The callback function to invoke.
+ * @param user_data The user data passed from the foreach function.
+ *
+ * \see wifi_direct_connected_peer_cb
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_INVALID_PARAMETER for "Invalid function parameter" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * bool _cb_connected_peers_impl(wifi_direct_connected_peer_info_s* peer, void* user_data)
+ *{
+ *
+ * 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
+ *}
+ *
+ * void foo()
+ * {
+ * int result;
+ *
+ * ad->connected_peer_list = NULL;
+ * ad->connected_peer_count = 0;
+ *
+ * result = wifi_direct_foreach_connected_peers(_cb_connected_peers_impl, (void*)ad);
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // get discovery result is successful
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_foreach_connected_peers(wifi_direct_connected_peer_cb
+ callback, void *user_data);
+
+
+
+/*****************************************************************************************/
+/* wifi_direct_create_group API function prototype
+ * int wifi_direct_create_group();
+ */
+/**
+ * \brief This API shall set up device as a Group Owner and wait for clients to connect. \n
+ * Create a soft AP, start the WPS registrar, start the DHCP server. \n
+ *
+ * \see wifi_direct_destroy_group
+ *
+ * \par Sync (or) Async:
+ * This is a Asynchronous API.
+ *
+ * \warning
+ * None
+ *
+ *
+ * \par Async Response Message:
+ * - WIFI_DIRECT_GROUP_CREATED : Applications will receive this event
+ * via callback when the group creating request is successful. \n
+ * Errorcode will be set to the WFD_ERROR_CREATE_LINK_FAIL value. \n
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ * - WIFI_DIRECT_ERROR_CONNECTION_FAILED for "Create Link fail" \n
+ * - WIFI_DIRECT_ERROR_AUTH_FAILED for "Create Link Auth fail" \n
+ *
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo()
+ * {
+
+ * int result;
+ *
+ * result = wifi_direct_create_group();
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // create group request is successful
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_create_group(void);
+
+
+
+/*****************************************************************************************/
+/* wifi_direct_destroy_group API function prototype
+ * int wifi_direct_destroy_group();
+ */
+/**
+ * \brief This API shall cancel P2P Group create or tear down a P2P Group that we own. \n
+ *
+ * \see wifi_direct_create_group
+ *
+ * \par Sync (or) Async:
+ * This is a Asynchronous API.
+ *
+ * \warning
+ * None
+ *
+ *
+ * \par Async Response Message:
+ * - WIFI_DIRECT_GROUP_DESTROYED : Applications will receive this event via callback when the group is cancelled. \n
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ * - WIFI_DIRECT_ERROR_CONNECTION_FAILED for "Create Link fail" \n
+ * - WIFI_DIRECT_ERROR_AUTH_FAILED for "Create Link Auth fail" \n
+ *
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo()
+ * {
+
+ * int result;
+ *
+ * result = wifi_direct_destroy_group();
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // cancel group request is successful
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_destroy_group(void);
+
+
+/*****************************************************************************************/
+/* wifi_direct_is_group_owner API function prototype
+ * int wifi_direct_is_group_owner(bool *owner);
+ */
+/**
+ * \brief This API shall check whether the currunt client is group owner or not.
+ * @param owner Memory to store the value of TURE or FALSE. Application must allocate memory.
+ *
+ * \see wifi_direct_create_group
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_INVALID_PARAMETER for "Invalid function parameter" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo(void)
+ * {
+
+ * int result;
+ * bool owner;
+ *
+ * result = wifi_direct_is_group_owner(&owner);
+ *
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // checking the value is successful
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_is_group_owner(bool * is_group_owner);
+
+
+
+/*****************************************************************************************/
+/* wifi_direct_is_autonomous_group API function prototype
+ * int wifi_direct_is_autonomous_group(bool *autonomous_group);
+ */
+/**
+ * \brief This API shall check whether the currunt group is autonomous group or not.
+ * @param autonomous_group Memory to store the value of TURE or FALSE. Application must allocate memory.
+ *
+ * \see wifi_direct_create_group
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_INVALID_PARAMETER for "Invalid function parameter" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo(void)
+ * {
+
+ * int result;
+ * bool autonomous_group;
+ *
+ * result = wifi_direct_is_autonomous_group(&autonomous_group);
+ *
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // checking the value is successful
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_is_autonomous_group(bool * is_autonomous_group);
+
+
+
+
+/*****************************************************************************************/
+/* wifi_direct_set_ssid API function prototype
+ * int wifi_direct_set_ssid(const char* ssid);
+ */
+/**
+ * \brief This API shall set or update ssid of local device. \n
+ * @param ssid new ssid to set. Application must set the new ssid before.
+ *
+ * \see wifi_direct_get_ssid
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_INVALID_PARAMETER for "Invalid function parameter" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo()
+ * {
+ * int result;
+ * char ssid[11] = {0,};
+ *
+ * memset(pin, 0x00, sizeof(pin));
+ * printf("Input 8 digit PIN number :\n");
+ * scanf("%s", pin);
+ *
+ *if( strlen(ssid) > 0 )
+ * result = wifi_direct_set_ssid(ssid);
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // setting ssid is successful
+ *
+ *\endcode
+ *
+ *\remarks When the wifi direct is re-activated, ssid will be reset to the device name. \n
+ *
+ *
+ ******************************************************************************/
+int wifi_direct_set_ssid(const char *ssid);
+
+
+/**
+ * @brief Sets the friendly name of local device.
+ * @details This device name is shown to other devices during device discovery.
+ * @remarks The name set by you is only valid during activated state.
+ * After Wi-Fi Direct is deactivated, this name will be as the phone name.
+ * @param[in] device_name The name to local device
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #WIFI_DIRECT_ERROR_NONE Successful
+ * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed
+ * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed
+ * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitteds
+ * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy
+ * @pre Wi-Fi Direct must be activated by wifi_direct_activate().
+ * @see wifi_direct_activate()
+ * @see wifi_direct_get_device_name()
+ */
+int wifi_direct_set_device_name(const char* device_name);
+
+/**
+ * @brief Gets the name of local device.
+ * @remarks @a device_name must be released with free() by you.
+ * @param[out] device_name The name to local device
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #WIFI_DIRECT_ERROR_NONE Successful
+ * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed
+ * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed
+ * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy
+ * @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize().
+ * @see wifi_direct_initialize()
+ * @see wifi_direct_set_device_name()
+ */
+int wifi_direct_get_device_name(char** device_name);
+
+/*****************************************************************************************/
+/* wifi_direct_get_ssid API function prototype
+ * int wifi_direct_get_ssid(char** ssid)
+ */
+/**
+ * \brief This API shall get ssid of local device. \n
+ * @param ssid Pointer to store ssid. Application must free this memory.
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_INVALID_PARAMETER for "Invalid function parameter" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo()
+ * {
+ * int result;
+ * char* ssid = NULL;
+ *
+ * result = wifi_direct_get_ssid(&ssid);
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // getting ssid is successful
+ *
+ * free(ssid); // Application should free the memory.
+ *
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_get_ssid(char **ssid);
+
+
+/**
+* @brief Gets the name of network interface. For example, eth0 and pdp0.
+* @remarks @a name must be released with free() by you.
+* @param[out] name The name of network interface
+* @return 0 on success, otherwise negative error value.
+* @retval #WIFI_DIRECT_ERROR_NONE Successful
+* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed
+* @retval #WIFI_DIRECT_ERROR_OUT_OF_MEMORY Out of memory
+* @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed
+* @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted
+* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized
+* @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy
+* @pre Wi-Fi Direct service must be activated by wifi_direct_activate().
+* @see wifi_direct_activate()
+*/
+int wifi_direct_get_network_interface_name(char** name);
+
+
+/*****************************************************************************************/
+/* wifi_direct_get_ip_address API function prototype
+ * int wifi_direct_get_ip_address(char** ip_address)
+ */
+/**
+ * \brief This API shall get IP address of local device interface. \n
+ * @param ip_addr Pointer to store ip address. Application must free this memory.
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_INVALID_PARAMETER for "Invalid function parameter" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo()
+ * {
+ * int result;
+ * char* ip = NULL;
+ *
+ * result = wifi_direct_get_ip_address(&ip);
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // getting IP is successful
+ *
+ * free(ip); // Application should free the memory.
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_get_ip_address(char **ip_address);
+
+/**
+* @brief Gets the Subnet Mask.
+* @remarks @a subnet_mask must be released with free() by you.
+* @param[out] subnet_mask The subnet mask
+* @return 0 on success, otherwise negative error value.
+* @retval #WIFI_DIRECT_ERROR_NONE Successful
+* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed
+* @retval #WIFI_DIRECT_ERROR_OUT_OF_MEMORY Out of memory
+* @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed
+* @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted
+* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized
+* @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy
+* @pre Wi-Fi Direct service must be activated by wifi_direct_activate().
+* @see wifi_direct_activate()
+*/
+int wifi_direct_get_subnet_mask(char** subnet_mask);
+
+
+/**
+* @brief Gets the Gateway address.
+* @remarks @a gateway_address must be released with free() by you.
+* @param[out] gateway_address The gateway address
+* @return 0 on success, otherwise negative error value.
+* @retval #WIFI_DIRECT_ERROR_NONE Successful
+* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed
+* @retval #WIFI_DIRECT_ERROR_OUT_OF_MEMORY Out of memory
+* @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed
+* @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted
+* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized
+* @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy
+* @pre Wi-Fi Direct service must be activated by wifi_direct_activate().
+* @see wifi_direct_activate()
+*/
+int wifi_direct_get_gateway_address(char** gateway_address);
+
+
+
+/*****************************************************************************************/
+/* wifi_direct_get_mac_addr API function prototype
+ * int wifi_direct_get_mac_address(char **mac_address)
+ */
+/**
+ * \brief This API shall get device MAC address of local device.\n
+ * @param mac_addr Pointer to store MAC address. Application must free this memory.
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_INVALID_PARAMETER for "Invalid function parameter" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo()
+ * {
+ * int result;
+ * char* mac_addr =NULL;
+ *
+ * result = wifi_direct_get_mac_addr(&mac_addr);
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // getting device MAC is successful
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_get_mac_address(char **mac_address);
+
+
+/*****************************************************************************************/
+/* wifi_direct_get_state API function prototype
+ * int wifi_direct_get_state(wifi_direct_state_e * status);
+ */
+/**
+ * \brief This API shall get current Wi-Fi direct link status. \n
+ * @param status Memory to store link status information. Application must allocate memory.
+ *
+ * \see wifi_direct_state_e
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_INVALID_PARAMETER for "Invalid function parameter" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo()
+ * {
+ * int result;
+ * wifi_direct_state_e status;
+ *
+ * result = wifi_direct_get_state(&status);
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // getting link status is successful
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_get_state(wifi_direct_state_e * state);
+
+
+
+/**
+* @brief Checks whether this device is discoverable or not by P2P discovery.
+* @details If you call wifi_direct_start_discovery(), then your device can be discoverable.
+* @param[out] discoverable The status of discoverable: (@c true = discoverable, @c false = non-discoverable)
+* @return 0 on success, otherwise a negative error value.
+* @retval #WIFI_DIRECT_ERROR_NONE Successful
+* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed
+* @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed
+* @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted
+* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized
+* @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy
+* @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize().
+* @see wifi_direct_initialize()
+* @see wifi_direct_start_discovery()
+* @see wifi_direct_cancel_discovery()
+*/
+int wifi_direct_is_discoverable(bool* discoverable);
+
+/**
+* @brief Checks whether the local device is listening only.
+* @details If you call wifi_direct_start_discovery() with @a listen_only as @c true,
+* then skip the initial 802.11 Scan and then enter Listen state instead of cycling between Scan andListen.
+* @param[out] listen_only The status of listen only: (@c true = listen only, @c false = cycling between Scan and Listen or not in discovery state)
+* @return 0 on success, otherwise a negative error value.
+* @retval #WIFI_DIRECT_ERROR_NONE Successful
+* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed
+* @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed
+* @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted
+* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized
+* @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy
+* @pre Wi-Fi Direct service must be activated by wifi_direct_activate().
+* @see wifi_direct_start_discovery()
+* @see wifi_direct_cancel_discovery()
+* @see wifi_direct_is_discoverable()
+*/
+int wifi_direct_is_listening_only(bool* listen_only);
+
+/**
+* @brief Gets the primary device type of local device.
+* @param[out] type The primary device type
+* @return 0 on success, otherwise a negative error value.
+* @retval #WIFI_DIRECT_ERROR_NONE Successful
+* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed
+* @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed
+* @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted
+* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized
+* @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy
+* @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize().
+* @see wifi_direct_initialize()
+*/
+int wifi_direct_get_primary_device_type(wifi_direct_primary_device_type_e* type);
+
+ /**
+* @brief Gets the secondary device type of local device.
+* @param[out] type The secondary device type
+* @return 0 on success, otherwise a negative error value.
+* @retval #WIFI_DIRECT_ERROR_NONE Successful
+* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed
+* @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed
+* @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted
+* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized
+* @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy
+* @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize().
+* @see wifi_direct_initialize()
+*/
+int wifi_direct_get_secondary_device_type(wifi_direct_secondary_device_type_e* type);
+
+
+/*****************************************************************************************/
+/* wifi_direct_accept_connection API function prototype
+ * int wifi_direct_accept_connection(char* mac_address);
+ */
+/**
+ * \brief This API shall accept connection request from specified peer. \n
+ * This API shall be used to respond the connection request event, WIFI_DIRECT_CONNECTION_REQ.
+ *
+ * @param mac_addr Device address of target peer.
+ *
+ * \see wifi_direct_connect
+ *
+ * \par Sync (or) Async:
+ * This is a Asynchronous API.
+ *
+ * \warning
+ * None
+ *
+ * \par Async Response Message:
+ * - WIFI_DIRECT_CONNECTION_IN_PROGRESS : Applications will receive this event
+ * via callback when the connection process is started.
+ * - WIFI_DIRECT_CONNECTION_RSP : Applications will receive this event
+ * via callback when the connection process is completed or failed.
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_INVALID_PARAMETER for "Invalid function parameter" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT for "Connection timed out" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ * - WIFI_DIRECT_ERROR_CONNECTION_FAILED for "Create Link fail" \n
+ * - WIFI_DIRECT_ERROR_AUTH_FAILED for "Create Link Auth fail" \n
+ *
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo(unsigned char* mac_addr)
+ * {
+ * int result;
+ *
+ * result = wifi_direct_accept_connection(mac_addr);
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // connect request is successful
+ *
+ *\endcode
+ *
+ *\remarks This API will not try to send provisioning request.
+ *
+ ******************************************************************************/
+int wifi_direct_accept_connection(char *mac_address);
+
+
+
+/*****************************************************************************************/
+/* wifi_direct_set_wpa_passphrase API function prototype
+ * int wifi_direct_set_wpa_passphrase(char* passphrase)
+ */
+/**
+ * \brief This API shall set or update wpa password. If a client create Group (Soft AP), this password will be used. \n
+ * @param passphrase new wpa password to set. Application must set the new password before.
+ *
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_INVALID_PARAMETER for "Invalid function parameter" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo()
+ * {
+ * int result;
+ * char new_wpa[64+1] = {0,};
+ *
+ * printf("Input new WPA:\n");
+ * scanf("%s",new_wpa);
+ *
+ *if( strlen(new_wpa) > 0 )
+ * result = wifi_direct_set_wpa_passphrase(new_wpa);
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // setting password is successful
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_set_wpa_passphrase(char *passphrase);
+
+
+/*****************************************************************************************/
+/* wifi_direct_activate_pushbutton API function prototype
+ * int wifi_direct_activate_pushbutton(void);
+ */
+/**
+ * \brief This API shall start wps PBC.
+
+ * \pre Device must support the pbc button mode.
+ *
+ * \see wifi_direct_foreach_supported_wps_types
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo(void)
+ * {
+
+ * int result;
+ *
+ * result = wifi_direct_activate_pushbutton();
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // activating push button is successful
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_activate_pushbutton(void);
+
+
+/*****************************************************************************************/
+/* wifi_direct_set_wps_pin API function prototype
+ * int wifi_direct_set_wps_pin(char* pin)
+ */
+/**
+ * \brief This API shall set or update the WPS PIN number user expects. \n
+ * @param pin new pin to set. Application must set the new pin number before.
+ *
+ * \see wifi_direct_generate_wps_pin.
+ * \see wifi_direct_get_wps_pin
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_INVALID_PARAMETER for "Invalid function parameter" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo()
+ * {
+ * int result;
+ * char pin[WIFI_DIRECT_WPS_PIN_LEN+1]= { 0, };
+ *
+ * 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);
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // setting wps pin number is successful
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_set_wps_pin(char *pin);
+
+
+/*****************************************************************************************/
+/* wifi_direct_get_wps_pin API function prototype
+ * int wifi_direct_get_wps_pin(char** pin)
+ */
+/**
+ * \brief This API shall get the WPS PIN number. \n
+ * @param pin Pointer to store pin number. Application must free this memory.
+ *
+ * \see wifi_direct_set_wps_pin
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_INVALID_PARAMETER for "Invalid function parameter" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo()
+ * {
+ * int result;
+ * char* pin = NULL;
+ *
+ * result = wifi_direct_get_wps_pin(&pin);
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // getting wps pin number is successful
+ *
+ * free(pin); // Application should free the memory.
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_get_wps_pin(char **pin);
+
+
+/*****************************************************************************************/
+/* wifi_direct_generate_wps_pin API function prototype
+ * wifi_direct_generate_wps_pin(void);
+ */
+/**
+ * \brief This API shall generate the random WPS PIN number.\n
+ * To get the generated PIN number, use wifi_direct_get_wps_pin() API.
+ *
+ * \see wifi_direct_set_wps_pin
+ * \see wifi_direct_get_wps_pin
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo()
+ * {
+ * int result;
+ *
+ * result = wifi_direct_generate_wps_pin();
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // generating wps pin number is successful
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_generate_wps_pin(void);
+
+
+/*****************************************************************************************/
+/* wifi_direct_get_supported_wps_mode API function prototype
+ * int wifi_direct_get_supported_wps_mode(int *wps_mode);
+ */
+/**
+ * \brief This API shall get the supported wps mode. \n
+ * The result is bit flag.
+ *
+ * @param wps_mode Memory to store supported wps mode. Application must allocate memory.
+ *
+ * \see wifi_direct_wps_type_e
+ *
+ * \par Sync (or) Async:
+ * This is a Synchronous API.
+ *
+ * \warning
+ * None
+ *
+ *
+ * \return Return Type (int) \n
+ * - WIFI_DIRECT_ERROR_NONE on success \n
+ * - WIFI_DIRECT_ERROR_OPERATION_FAILED for "Unkown error" \n
+ * - WIFI_DIRECT_ERROR_OUT_OF_MEMORY for "Out of memory" \n
+ * - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED for "I/O error" \n
+ * - WIFI_DIRECT_ERROR_NOT_PERMITTED for "Operation not permitted" \n
+ * - WIFI_DIRECT_ERROR_INVALID_PARAMETER for "Invalid function parameter" \n
+ * - WIFI_DIRECT_ERROR_RESOURCE_BUSY for "Device or resource busy" \n
+ * - WIFI_DIRECT_ERROR_STRANGE_CLIENT for "Invalid Client" \n
+ *
+ *
+ * \par Prospective Clients:
+ * External Apps.
+ *
+ * \code
+ *
+ * #include <wifi-direct.h>
+ *
+ * void foo()
+ * {
+ * int result;
+ * int supported_wps_mode = 0;
+ *
+ * result = wifi_direct_get_supported_wps_mode(&supported_wps_mode);
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // getting supported wps mode is successful
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_get_supported_wps_mode(int *wps_mode);
+
+
+/**
+* @brief Called when you get the supported WPS(Wi-Fi Protected Setup) type repeatedly.
+* @param[in] type The type of WPS
+* @param[in] user_data The user data passed from the request function
+* @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop
+* @pre wifi_direct_foreach_supported_wps_types() will invoke this callback.
+* @see wifi_direct_foreach_supported_wps_types()
+*/
+typedef bool(*wifi_direct_supported_wps_type_cb)(wifi_direct_wps_type_e type, void* user_data);
+
+/**
+* @brief Gets the supported WPS(Wi-Fi Protected Setup) types.
+* @param[in] callback The callback function to invoke
+* @param[in] user_data The user data to be passed to the callback function
+* @retval #WIFI_DIRECT_ERROR_NONE Successful
+* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+* @see wifi_direct_supported_wps_type_cb()
+*/
+int wifi_direct_foreach_supported_wps_types(wifi_direct_supported_wps_type_cb callback, void* user_data);
+
+/**
+ * @brief Sets the WPS(Wi-Fi Protected Setup) type.
+ * @param[in] type The type of WPS
+ * @retval #WIFI_DIRECT_ERROR_NONE Successful
+ * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see wifi_direct_foreach_supported_wps_types()
+ */
+int wifi_direct_set_wps_type(wifi_direct_wps_type_e type);
+/**
+ * @brief Gets the WPS(Wi-Fi Protected Setup) type.
+ * @param[out] type The type of WPS
+ * @retval #WIFI_DIRECT_ERROR_NONE Successful
+ * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see wifi_direct_foreach_supported_wps_types()
+ */
+int wifi_direct_get_wps_type(wifi_direct_wps_type_e* type);
+
+/**
+* @brief Sets the intent of a group owner.
+* @remakrs The range of intent is 0 ~ 15.
+* @param[in] intent The intent of a group owner
+* @retval #WIFI_DIRECT_ERROR_NONE Successful
+* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+* @see wifi_direct_get_group_owner_intent()
+*/
+int wifi_direct_set_group_owner_intent(int intent);
+
+/**
+* @brief Gets the intent of a group owner.
+* @param[out] intent The intent of a group owner
+* @retval #WIFI_DIRECT_ERROR_NONE Successful
+* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+* @see wifi_direct_set_group_owner_intent()
+*/
+int wifi_direct_get_group_owner_intent(int* intent);
+
+/**
+* @brief Sets the max number of clients.
+* @param[in] max The max number of clients
+* @retval #WIFI_DIRECT_ERROR_NONE Successful
+* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+* @see wifi_direct_get_max_clients()
+*/
+int wifi_direct_set_max_clients(int max);
+
+/**
+* @brief Gets the max number of clients.
+* @param[in] max The max number of clients
+* @retval #WIFI_DIRECT_ERROR_NONE Successful
+* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+* @see wifi_direct_set_max_clients()
+*/
+int wifi_direct_get_max_clients(int* max);
+
+
+/**
+* @brief Gets the channel of own group. - DEPRECATED
+* @param[out] channel The channel of own group
+* @return 0 on success, otherwise a negative error value.
+* @retval #WIFI_DIRECT_ERROR_NONE Successful
+* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed
+* @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed
+* @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted
+* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized
+* @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy
+* @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize().
+* @see wifi_direct_initialize()
+*/
+int wifi_direct_get_own_group_channel(int* channel);
+
+
+/**
+* @brief Gets the operating channel.
+* @param[out] channel The operating channel
+* @return 0 on success, otherwise a negative error value.
+* @retval #WIFI_DIRECT_ERROR_NONE Successful
+* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed
+* @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed
+* @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted
+* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized
+* @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy
+* @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize().
+* @see wifi_direct_initialize()
+*/
+int wifi_direct_get_operating_channel(int* channel);
+
+/**
+ * @brief Sets the Autoconnection mode.
+ * @param[in]
+ * @retval #WIFI_DIRECT_ERROR_NONE Successful
+ * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see wifi_direct_foreach_supported_wps_types()
+ */
+int wifi_direct_set_autoconnection_mode(bool mode);
+
+int wifi_direct_is_autoconnection_mode(bool* mode);
+
+/**
+* @brief Enables the persistent group.
+* @details If @a enabled is true, then P2P persisten group will be used when creating a group and establishing a connection.
+* @param[in] enabled The status of persistent group: (@c true = enabled, @c false = disabled)
+* @retval #WIFI_DIRECT_ERROR_NONE Successful
+* @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed
+* @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed
+* @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted
+* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized
+* @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy
+* @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize().
+* @see wifi_direct_initialize()
+* @see wifi_direct_is_persistent_group_enabled()
+*/
+int wifi_direct_set_persistent_group_enabled(bool enabled);
+
+/**
+* @brief Checks whether the persistent group is enabled or disabled.
+* @param[out] enabled The status of persistent group: (@c true = enabled, @c false = disabled)
+* @retval #WIFI_DIRECT_ERROR_NONE Successful
+* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed
+* @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed
+* @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted
+* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized
+* @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy
+* @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize().
+* @see wifi_direct_initialize()
+* @see wifi_direct_set_persistent_group_enabled()
+*/
+int wifi_direct_is_persistent_group_enabled(bool* enabled);
+
+
+/**
+* @brief Called when you get the persistent groups repeatedly.
+* @param[in] mac_address The MAC address of persistent group owner
+* @param[in] ssid The SSID(Service Set Identifier) of persistent group owner
+* @param[in] user_data The user data passed from the request function
+* @return @c true to continue with the next iteration of the loop, \n @c false to break out of theloop
+* @pre wifi_direct_foreach_persistent_groups() will invoke this callback.
+* @see wifi_direct_foreach_persistent_groups()
+*/
+typedef bool(*wifi_direct_persistent_group_cb)(const char* mac_address, const char* ssid, void* user_data);
+
+/**
+* @brief Gets the persistent groups.
+* @param[in] callback The callback function to invoke
+* @param[in] user_data The user data to be passed to the callback function
+* @retval #WIFI_DIRECT_ERROR_NONE Successful
+* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed
+* @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed
+* @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted
+* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized
+* @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy
+* @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize().
+* @post wifi_direct_persistent_group_cb() will be called.
+* @see wifi_direct_initialize()
+* @see wifi_direct_persistent_group_cb()
+*/
+int wifi_direct_foreach_persistent_groups(wifi_direct_persistent_group_cb callback, void* user_data);
+
+/**
+* @brief Remove a persistent group.
+* @param[in] mac_address The MAC address of persistent group owner
+* @param[in] ssid The SSID(Service Set Identifier) of persistent group owner
+* @retval #WIFI_DIRECT_ERROR_NONE Successful
+* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed
+* @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed
+* @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted
+* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized
+* @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy
+* @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize().
+* @see wifi_direct_initialize()
+* @see wifi_direct_foreach_persistent_groups()
+*/
+int wifi_direct_remove_persistent_group(const char* mac_address, const char* ssid);
+
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__WIFI_DIRECT_INTERFACE_H_
--- /dev/null
+/*
+ * libwifi-direct
+ *
+ * Copyright (c) 2000 - 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 <netdb.h>
+#include <sys/socket.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/un.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <signal.h>
+#include <glib.h>
+#include <linux/unistd.h>
+#include <sys/poll.h>
+
+#include <vconf.h>
+
+/*****************************************************************************
+ * Wi-Fi Direct Service headers
+ *****************************************************************************/
+#include "wifi-direct.h"
+#include "wifi-direct-client-proxy.h"
+#include "wifi-direct-internal.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,
+ .user_data_for_cb_activation = NULL,
+ .user_data_for_cb_discover = NULL,
+ .user_data_for_cb_connection = NULL
+};
+
+/*****************************************************************************
+ * Local Functions Definition
+ *****************************************************************************/
+static int __wfd_client_read_socket(int sockfd, char *dataptr, int datalen);
+
+#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 > 2)
+ close(g_client_info.sync_sockfd);
+ g_client_info.sync_sockfd = -1;
+
+ if (g_client_info.async_sockfd > 2)
+ 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.user_data_for_cb_activation = NULL;
+ g_client_info.user_data_for_cb_discover = NULL;
+ g_client_info.user_data_for_cb_connection = NULL;
+}
+
+
+static int macaddr_atoe(char *p, unsigned char mac[])
+{
+ int i = 0;
+
+ WDC_LOGD( "macaddr_atoe : input MAC = [%s]\n", p);
+
+ 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_ACTIVATION:
+ return "ACTIVATION";
+ break;
+ case WIFI_DIRECT_CLI_EVENT_DEACTIVATION:
+ return "DEACTIVATION";
+ break;
+ case WIFI_DIRECT_CLI_EVENT_INVALID:
+ return "WIFI_DIRECT_CLI_EVENT_INVALID";
+ 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_REQ:
+ return "WIFI_DIRECT_CLI_EVENT_CONNECTION_REQ";
+ break;
+
+ case WIFI_DIRECT_CLI_EVENT_CONNECTION_START:
+ return "WIFI_DIRECT_CLI_EVENT_CONNECTION_START";
+ 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_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;
+
+ default:
+ return "WIFI_DIRECT_CLI_EVENT_unknown";
+ break;
+ }
+}
+
+static char *__wfd_print_error(wifi_direct_error_e error)
+{
+ switch (error)
+ {
+ case WIFI_DIRECT_ERROR_OPERATION_FAILED:
+ return "WIFI_DIRECT_ERROR_OPERATION_FAILED";
+ case WIFI_DIRECT_ERROR_OUT_OF_MEMORY:
+ return "WIFI_DIRECT_ERROR_OUT_OF_MEMORY";
+ case WIFI_DIRECT_ERROR_COMMUNICATION_FAILED:
+ return "WIFI_DIRECT_ERROR_COMMUNICATION_FAILED";
+ case WIFI_DIRECT_ERROR_NOT_PERMITTED:
+ return "WIFI_DIRECT_ERROR_NOT_PERMITTED";
+ 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_TOO_MANY_CLIENT:
+ return "WIFI_DIRECT_ERROR_TOO_MANY_CLIENT";
+ case WIFI_DIRECT_ERROR_RESOURCE_BUSY:
+ return "WIFI_DIRECT_ERROR_RESOURCE_BUSY";
+ case WIFI_DIRECT_ERROR_NONE:
+ return "WIFI_DIRECT_ERROR_NONE";
+ 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:
+ return WIFI_DIRECT_DISCOVERY_STARTED;
+ break;
+ case WIFI_DIRECT_CLI_EVENT_DISCOVER_END:
+ return WIFI_DIRECT_DISCOVERY_FINISHED;
+ break;
+ case WIFI_DIRECT_CLI_EVENT_DISCOVER_FOUND_PEERS:
+ return WIFI_DIRECT_DISCOVERY_FOUND;
+ break;
+
+ case WIFI_DIRECT_CLI_EVENT_CONNECTION_START:
+ return WIFI_DIRECT_CONNECTION_IN_PROGRESS;
+ break;
+ case WIFI_DIRECT_CLI_EVENT_CONNECTION_REQ:
+ return WIFI_DIRECT_CONNECTION_REQ;
+ 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_CONNECTION_WPS_REQ:
+ return WIFI_DIRECT_CONNECTION_WPS_REQ;
+ 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;
+ case WIFI_DIRECT_CLI_EVENT_INVITATION_REQ:
+ return WIFI_DIRECT_INVITATION_REQ;
+ break;
+ default:
+ WDC_LOGE("Invalid event : [%d]", event);
+ break;
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+}
+
+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[64] = { 0, };
+
+ memset(&client_noti, 0, sizeof(wifi_direct_client_noti_s));
+
+ // 1.Read socket
+ if (__wfd_client_read_socket(sockfd, (char *) &client_noti,
+ sizeof(wifi_direct_client_noti_s)) <= 0)
+ {
+ WDC_LOGE("Error!!! Reading Async Event[%d]", sockfd);
+ //close(sockfd);
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return false;
+ }
+
+ WDC_LOGD( "Received Event is [%d,%s], error[%d]\n",
+ client_noti.event, __wfd_print_event(client_noti.event),
+ client_noti.error);
+
+ event = client_noti.event;
+ error = client_noti.error;
+ 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 != NULL)
+ client->activation_cb(error,
+ (wifi_direct_device_state_e)
+ __wfd_convert_client_event(event),
+ client->user_data_for_cb_activation);
+ else
+ WDC_LOGE("activation_cb is NULL!!");
+ break;
+
+ 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:
+ case WIFI_DIRECT_CLI_EVENT_DISCOVER_FOUND_PEERS:
+ if (client->discover_cb != NULL)
+ client->discover_cb(error,
+ (wifi_direct_discovery_state_e)
+ __wfd_convert_client_event(event),
+ client->user_data_for_cb_discover);
+ else
+ WDC_LOGE("discover_cb is NULL!!");
+ 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:
+ case WIFI_DIRECT_CLI_EVENT_INVITATION_REQ:
+ if (client->connection_cb != NULL)
+ client->connection_cb(error,
+ (wifi_direct_connection_state_e)
+ __wfd_convert_client_event(event), param1,
+ client->user_data_for_cb_connection);
+ else
+ WDC_LOGE("connection_cb is NULL!!");
+ break;
+
+ // ToDo: Handling IP lease event...
+ case WIFI_DIRECT_CLI_EVENT_IP_LEASED_IND:
+ if (client->ip_assigned_cb != NULL)
+ {
+ char* ifname = NULL;
+ ifname = vconf_get_str(VCONFKEY_IFNAME);
+
+ if (ifname == NULL)
+ WDC_LOGD("vconf (%s) value is NULL!!!", VCONFKEY_IFNAME);
+ else
+ WDC_LOGD("VCONFKEY_IFNAME(%s) : %s", VCONFKEY_IFNAME, ifname);
+
+ client->ip_assigned_cb(param1,
+ param2,
+ ifname,
+ client->user_data_for_cb_ip_assigned);
+
+ }
+ else
+ WDC_LOGE("ip_assigned_cb is NULL!!");
+ break;
+
+ default:
+ break;
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return TRUE;
+}
+
+static wifi_direct_error_e __wfd_client_send_request(int sockfd, void *req_data, int dataLength)
+{
+ int retval = 0;
+
+ __WDC_LOG_FUNC_START__;
+
+ if (sockfd > 0)
+ {
+ WDC_LOGD("Write [%d] bytes to socket [%d].", dataLength, sockfd);
+ errno = 0;
+ retval = write(sockfd, (char *) req_data, dataLength);
+
+ if (retval <= 0)
+ {
+ WDC_LOGE("Error!!! writing to the socket. Error = %s", strerror(errno));
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+ }
+
+ WDC_LOGE("Error!!! Invalid sockfd [%d]", sockfd);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+static wifi_direct_error_e __wfd_client_async_event_init(int clientid)
+{
+ int len = 0;
+ int sockfd = 0;
+ struct sockaddr_un servAddr;
+ char *path = "/tmp/wfd_client_socket";
+
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ errno = 0;
+ if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+ {
+ WDC_LOGE("Error!!! creating async socket. Error = [%s].", strerror(errno));
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ WDC_LOGD("Created async socket [%d]", sockfd);
+
+ memset(&servAddr, 0, sizeof(servAddr));
+ servAddr.sun_family = AF_UNIX;
+ strcpy(servAddr.sun_path, path);
+ len = sizeof(servAddr.sun_family) + strlen(path);
+
+ WDC_LOGD("Connecting to server socket to register async socket [%d]", sockfd);
+ errno = 0;
+ if ((connect(sockfd, (struct sockaddr *) &servAddr, len)) < 0)
+ {
+ WDC_LOGE("Error!!! connecting to server socket. Error = [%s].", strerror(errno));
+ close(sockfd);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ wifi_direct_client_request_s req;
+ int result = WIFI_DIRECT_ERROR_NONE;
+
+ memset(&req, 0, sizeof(wifi_direct_client_request_s));
+
+ req.cmd = WIFI_DIRECT_CMD_INIT_ASYNC_SOCKET;
+ req.client_id = clientid;
+
+ result =
+ __wfd_client_send_request(sockfd, &req, sizeof(wifi_direct_client_request_s));
+
+ if (result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
+ WDC_LOGE("Error!!! [%s]", __wfd_print_error(result));
+ close(sockfd);
+ __WDC_LOG_FUNC_END__;
+ return result;
+ }
+
+ client_info->async_sockfd = sockfd;
+
+ WDC_LOGE("Async socket is created= %d", sockfd);
+
+ }
+
+ return (sockfd);
+}
+
+
+static int __wfd_client_read_socket(int sockfd, char *dataptr, int datalen)
+{
+ int pollret = 0;
+ struct pollfd pollfd;
+ int timeout = 60000; /** for 60 sec */
+ int retval = 0;
+ int total_data_recd = 0;
+
+ __WDC_LOG_FUNC_START__;
+
+ if (sockfd <= 0)
+ {
+ WDC_LOGE("Error!!! Invalid socket FD [%d]", sockfd);
+ __WDC_LOG_FUNC_END__;
+ return -1;
+ }
+
+ if ((dataptr == NULL) || (datalen <= 0))
+ {
+ WDC_LOGE("Error!!! Invalid parameter");
+ __WDC_LOG_FUNC_END__;
+ return -1;
+ }
+
+ WDC_LOGE("@@@@@@@ len = %d @@@@@@@@@@@", datalen);
+
+ pollfd.fd = sockfd;
+ pollfd.events = POLLIN | POLLERR | POLLHUP;
+ pollret = poll(&pollfd, 1, timeout);
+
+ WDC_LOGE("POLL ret = %d", pollret);
+
+ if (pollret > 0)
+ {
+ if (pollfd.revents == POLLIN)
+ {
+ WDC_LOGE("POLLIN");
+
+ while (datalen)
+ {
+ errno = 0;
+ retval = read(sockfd, (char *) dataptr, datalen);
+ WDC_LOGE("sockfd %d retval %d", sockfd,
+ retval);
+ if (retval <= 0)
+ {
+ WDC_LOGE("Error!!! reading data, error [%s]", strerror(errno));
+ __WDC_LOG_FUNC_END__;
+ return retval;
+ }
+ total_data_recd += retval;
+ dataptr += retval;
+ datalen -= retval;
+ }
+ __WDC_LOG_FUNC_END__;
+ return total_data_recd;
+ }
+ else if (pollfd.revents & POLLHUP)
+ {
+ WDC_LOGE("POLLHUP");
+ __WDC_LOG_FUNC_END__;
+ return 0;
+ }
+ else if (pollfd.revents & POLLERR)
+ {
+ WDC_LOGE("POLLERR");
+ __WDC_LOG_FUNC_END__;
+ return 0;
+ }
+ }
+ else if (pollret == 0)
+ {
+ WDC_LOGE("POLLing timeout");
+ __WDC_LOG_FUNC_END__;
+ return 0;
+ }
+ else
+ {
+ WDC_LOGE("Polling unknown error");
+ __WDC_LOG_FUNC_END__;
+ return -1;
+ }
+ __WDC_LOG_FUNC_END__;
+ return 1;
+}
+
+
+static int __wfd_client_read_more_data(int sockfd, void *pData, int Datalen)
+{
+ int retval = 0;
+
+ __WDC_LOG_FUNC_START__;
+
+ if (sockfd < 0)
+ {
+ WDC_LOGE("Error!!! Inavlid argument passed");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (pData == NULL)
+ {
+ WDC_LOGE("Error!!! Inavlid argument passed");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (Datalen <= 0)
+ {
+ WDC_LOGE("Error!!! Inavlid argument passed");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ /** Initialising the structure variable */
+ memset(pData, 0, Datalen);
+ errno = 0;
+ retval = __wfd_client_read_socket(sockfd, (char *) pData, Datalen);
+ if (retval <= 0)
+ {
+ WDC_LOGE("Error!!! reading response from CM. errno = [%d]", errno);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+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 : "MACSTR, MAC2STR(list[i].mac_address));
+ WDC_LOGD("wps cfg method : %x", list[i].wps_cfg_methods);
+ }
+ 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 : " MACSTR "\n", MAC2STR(list[i].mac_address));
+ WDC_LOGD("Interface MAC : " MACSTR "\n", MAC2STR(list[i].intf_mac_address));
+ WDC_LOGD("services : %d\n", list[i].services);
+ WDC_LOGD("is_p2p : %d\n", list[i].is_p2p);
+ WDC_LOGD("category : %d\n", list[i].category);
+ WDC_LOGD("channel : %d\n", list[i].channel);
+ WDC_LOGD("IP ["IPSTR"]\n", IP2STR(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 ==\n", i);
+ WDC_LOGD("ssid : %s\n", list[i].ssid);
+ WDC_LOGD("GO MAC : " MACSTR "\n",
+ MAC2STR(list[i].go_mac_address));
+ }
+ WDC_LOGD("------------------------------------------\n");
+}
+
+
+
+void __wfd_client_print_config_data(wfd_config_data_s * config)
+{
+ if (config == NULL)
+ return;
+
+ WDC_LOGD("Operating channel = [%d]\n", config->channel);
+ WDC_LOGD("WPS 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");
+
+ WDC_LOGD("Max client = [%d]\n", config->max_clients);
+ WDC_LOGD("grp_owner_intent = [%d]\n", config->group_owner_intent);
+ WDC_LOGD("hide-SSID = [%d]\n", config->hide_SSID);
+ WDC_LOGD("want_persistent_group = [%d]\n", config->want_persistent_group);
+ WDC_LOGD("auto_connection = [%d]\n", config->auto_connection);
+ WDC_LOGD("primary_dev_type = [%d]\n", config->primary_dev_type);
+ WDC_LOGD("secondary_dev_type = [%d]\n",
+ config->secondary_dev_type);
+
+}
+
+
+int wifi_direct_initialize(void)
+{
+ struct sockaddr_un servAddr;
+ char *path = "/tmp/wfd_client_socket";
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+ int sockfd = 0;
+ int len = 0;
+ int ret = 0;
+
+ __WDC_LOG_FUNC_START__;
+
+ if (client_info->is_registered == TRUE)
+ {
+ WDC_LOGE("Warning!!! Already registered\nUpdate user data and callback!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+ }
+
+ errno = 0;
+ if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+ {
+ WDC_LOGE("Error!!! creating sync socket. Error = [%s].", strerror(errno));
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ WDC_LOGD("Created sync socket [%d]", sockfd);
+
+ memset(&servAddr, 0, sizeof(servAddr));
+ servAddr.sun_family = AF_UNIX;
+ strcpy(servAddr.sun_path, path);
+ len = sizeof(servAddr.sun_family) + strlen(path);
+
+ WDC_LOGD("Connecting to server socket to register sync socket [%d]", sockfd);
+
+ int retry_count = 2;
+ while (retry_count > 0)
+ {
+ errno = 0;
+ if ((ret = connect(sockfd, (struct sockaddr *) &servAddr, len)) < 0)
+ {
+ WDC_LOGD("Launching wfd-server..\n");
+ system("dbus-send --system --print-reply --dest=net.netconfig /net/netconfig/wifi net.netconfig.wifi.LaunchDirect");
+ retry_count--;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ if (ret < 0)
+ {
+ WDC_LOGE("Error!!! connecting to server socket. Error = [%d] %s.\n",
+ errno, strerror(errno));
+ if (sockfd > 0)
+ close(sockfd);
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s resp;
+
+ int status = WIFI_DIRECT_ERROR_NONE;
+
+ 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\n", req.client_id);
+
+ status = __wfd_client_send_request(sockfd, &req, sizeof(wifi_direct_client_request_s));
+
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ close(sockfd);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ /*Get client id */
+ if ((status = __wfd_client_read_socket(sockfd, (char *) &resp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (resp.cmd == WIFI_DIRECT_CMD_REGISTER)
+ {
+ if (resp.result == WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Client ID received = %d \n",
+ resp.client_id);
+ WDC_LOGD("Connected sync socket %d to the wifi direct server socket\n",
+ sockfd);
+ client_info->sync_sockfd = sockfd;
+ client_info->client_id = resp.client_id;
+ client_info->is_registered = TRUE;
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Client Register = %d\n",
+ resp.result);
+ close(sockfd);
+ __WDC_LOG_FUNC_END__;
+ return resp.result;
+ }
+
+ int async_sockfd = -1;
+ /* Send request for establishing async communication channel */
+ if ((async_sockfd =
+ __wfd_client_async_event_init(client_info->client_id)) ==
+ WIFI_DIRECT_ERROR_COMMUNICATION_FAILED)
+ {
+ WDC_LOGE("Error!!! creating Async Socket \n");
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ client_info->async_sockfd = async_sockfd;
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid Response received from wfd Server. cmd = %d \n",
+ resp.cmd);
+ close(sockfd);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ }
+ }
+
+ GIOChannel *gio = g_io_channel_unix_new(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);
+
+ WDC_LOGD("Scoket is successfully registered to g_main_loop.\n");
+
+ client_info->g_source_id = g_source_id;
+
+ // Initialize callbacks
+ client_info->activation_cb = NULL;
+ client_info->discover_cb = NULL;
+ client_info->connection_cb = NULL;
+ client_info->user_data_for_cb_activation = NULL;
+ client_info->user_data_for_cb_discover = NULL;
+ client_info->user_data_for_cb_connection = NULL;
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+
+int wifi_direct_deinitialize(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (client_info->is_registered == false)
+ {
+ WDC_LOGE("Client is already deregistered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ client_info->activation_cb = NULL;
+ client_info->discover_cb = NULL;
+ client_info->connection_cb = NULL;
+ client_info->user_data_for_cb_activation = NULL;
+ client_info->user_data_for_cb_discover = NULL;
+ client_info->user_data_for_cb_connection = NULL;
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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 = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ //
+ // Deinit protocol: Send the deregister cmd and wait for socket close...
+ //
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGD( "Deinit Successfull\n");
+
+ if (client_info->g_source_id > 0)
+ g_source_remove(client_info->g_source_id);
+ client_info->g_source_id = -1;
+
+ close(client_info->sync_sockfd);
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+ }
+ else
+ {
+ WDC_LOGD("Error.. Something wrong...!!!\n");
+ }
+
+ __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)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (NULL == cb)
+ {
+ WDC_LOGE("Callback is NULL.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (client_info->is_registered == false)
+ {
+ WDC_LOGE("Client is not initialized.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ client_info->activation_cb = cb;
+ client_info->user_data_for_cb_activation = user_data;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_unset_device_state_changed_cb(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (client_info->is_registered == false)
+ {
+ WDC_LOGE("Client is not initialized.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ client_info->activation_cb = NULL;
+ client_info->user_data_for_cb_activation = NULL;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int
+wifi_direct_set_discovery_state_changed_cb
+(wifi_direct_discovery_state_chagned_cb cb, void *user_data)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (NULL == cb)
+ {
+ WDC_LOGE("Callback is NULL.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (client_info->is_registered == false)
+ {
+ WDC_LOGE("Client is not initialized.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ client_info->discover_cb = cb;
+ client_info->user_data_for_cb_discover = user_data;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_unset_discovery_state_changed_cb(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (client_info->is_registered == false)
+ {
+ WDC_LOGE("Client is not initialized.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ client_info->discover_cb = NULL;
+ client_info->user_data_for_cb_discover = NULL;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int
+wifi_direct_set_connection_state_changed_cb
+(wifi_direct_connection_state_changed_cb cb, void *user_data)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (NULL == cb)
+ {
+ WDC_LOGE("Callback is NULL.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (client_info->is_registered == false)
+ {
+ WDC_LOGE("Client is not initialized.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ client_info->connection_cb = cb;
+ client_info->user_data_for_cb_connection = user_data;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_unset_connection_state_changed_cb(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (client_info->is_registered == false)
+ {
+ WDC_LOGE("Client is not initialized.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ client_info->connection_cb = NULL;
+ client_info->user_data_for_cb_connection = NULL;
+
+ 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)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (NULL == cb)
+ {
+ WDC_LOGE("Callback is NULL.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (client_info->is_registered == false)
+ {
+ WDC_LOGE("Client is not initialized.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ client_info->ip_assigned_cb = cb;
+ client_info->user_data_for_cb_ip_assigned = user_data;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_unset_client_ip_address_assigned_cb(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (client_info->is_registered == false)
+ {
+ WDC_LOGE("Client is not initialized.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ client_info->ip_assigned_cb = NULL;
+ client_info->user_data_for_cb_ip_assigned = NULL;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_activate(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_ACTIVATE;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_ACTIVATE)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGE("Activating device is successfull.\n");
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_deactivate(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_DEACTIVATE;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_DEACTIVATE)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGE("Device Deactivated! \n");
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_start_discovery(bool listen_only, int timeout)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (timeout < 0)
+ {
+ WDC_LOGE("Nagative value. Param [timeout]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_START_DISCOVERY;
+ req.client_id = client_info->client_id;
+ req.data.listen_only = listen_only;
+ req.data.timeout = timeout;
+
+ WDC_LOGE("listen only (%d) timeout (%d) \n",
+ listen_only, timeout);
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_START_DISCOVERY)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGE("wifi_direct_start_discovery() SUCCESS \n");
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_cancel_discovery(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_CANCEL_DISCOVERY;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_CANCEL_DISCOVERY)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGE("wifi_direct_cancel_discovery() SUCCESS \n");
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_foreach_discovered_peers(wifi_direct_discovered_peer_cb callback, void *user_data)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (callback == NULL)
+ {
+ WDC_LOGE("NULL Param [callback]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int i;
+
+ int status = 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_GET_DISCOVERY_RESULT;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_GET_DISCOVERY_RESULT)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ int num = rsp.param1;
+ int status = 0;
+ wfd_discovery_entry_s *buff = NULL;
+
+ WDC_LOGD("Num of found peers = %d \n",
+ (int) rsp.param1);
+
+ if (num > 0)
+ {
+ buff =
+ (wfd_discovery_entry_s *) malloc(num * sizeof (wfd_discovery_entry_s));
+ if (buff == NULL)
+ {
+ WDC_LOGE("malloc() failed!!!.\n");
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ status =
+ __wfd_client_read_more_data(client_info->sync_sockfd,
+ buff,
+ num *
+ sizeof
+ (wfd_discovery_entry_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ if (NULL != buff)
+ free(buff);
+ //peer_list = NULL;
+ WDC_LOGE("socket read error.\n");
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __wfd_client_print_entry_list(buff, num);
+
+ WDC_LOGD("wifi_direct_foreach_discovered_peers() SUCCESS\n");
+
+
+ wifi_direct_discovered_peer_info_s *peer_list;
+
+ for (i = 0; i < num; i++)
+ {
+ peer_list = (wifi_direct_discovered_peer_info_s *) calloc(1, sizeof(wifi_direct_discovered_peer_info_s));
+ peer_list->is_group_owner = buff[i].is_group_owner;
+ peer_list->device_name = strdup(buff[i].device_name);
+ peer_list->mac_address = (char *) calloc(1, 18);
+ snprintf(peer_list->mac_address, 18, MACSTR, MAC2STR(buff[i].mac_address));
+ peer_list->channel = buff[i].channel;
+ peer_list->is_connected = buff[i].is_connected;
+ peer_list->is_persistent_group_owner = buff[i].is_persistent_go;
+ peer_list->interface_address = (char *) calloc(1, 18);
+ snprintf(peer_list->interface_address, 18, MACSTR, MAC2STR(buff[i].intf_mac_address));
+ peer_list->supported_wps_types= buff[i].wps_cfg_methods;
+ peer_list->primary_device_type = buff[i].category;
+ peer_list->secondary_device_type = buff[i].subcategory;
+
+ if (!callback(peer_list, user_data))
+ break;
+ }
+
+ if (NULL != buff)
+ free(buff);
+
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_connect(const char *mac_address)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+ unsigned char la_mac_addr[6];
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (mac_address == NULL)
+ {
+ WDC_LOGE("mac_addr is NULL.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_CONNECT;
+ req.client_id = client_info->client_id;
+
+ macaddr_atoe(mac_address, la_mac_addr);
+
+ req.data.mac_addr[0] = la_mac_addr[0];
+ req.data.mac_addr[1] = la_mac_addr[1];
+ req.data.mac_addr[2] = la_mac_addr[2];
+ req.data.mac_addr[3] = la_mac_addr[3];
+ req.data.mac_addr[4] = la_mac_addr[4];
+ req.data.mac_addr[5] = la_mac_addr[5];
+
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_CONNECT)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGD("wifi_direct_connect() SUCCESS \n");
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_disconnect_all(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_DISCONNECT_ALL;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_DISCONNECT_ALL)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGE("wifi_direct_disconnect_all() SUCCESS \n");
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_disconnect(const char *mac_address)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+ unsigned char la_mac_addr[6];
+
+ __WDC_LOG_FUNC_START__;
+
+ if (mac_address == NULL)
+ {
+ WDC_LOGE("mac_address is NULL.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_DISCONNECT;
+ req.client_id = client_info->client_id;
+
+ macaddr_atoe(mac_address, la_mac_addr);
+
+ req.data.mac_addr[0] = la_mac_addr[0];
+ req.data.mac_addr[1] = la_mac_addr[1];
+ req.data.mac_addr[2] = la_mac_addr[2];
+ req.data.mac_addr[3] = la_mac_addr[3];
+ req.data.mac_addr[4] = la_mac_addr[4];
+ req.data.mac_addr[5] = la_mac_addr[5];
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_DISCONNECT)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGE("wifi_direct_disconnect() SUCCESS \n");
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+
+}
+
+
+
+int wifi_direct_accept_connection(char *mac_address)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+ unsigned char la_mac_addr[6];
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (mac_address == NULL)
+ {
+ WDC_LOGE("mac_addr is NULL.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_SEND_CONNECT_REQ;
+ req.client_id = client_info->client_id;
+
+ macaddr_atoe(mac_address, la_mac_addr);
+
+ req.data.mac_addr[0] = la_mac_addr[0];
+ req.data.mac_addr[1] = la_mac_addr[1];
+ req.data.mac_addr[2] = la_mac_addr[2];
+ req.data.mac_addr[3] = la_mac_addr[3];
+ req.data.mac_addr[4] = la_mac_addr[4];
+ req.data.mac_addr[5] = la_mac_addr[5];
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_SEND_CONNECT_REQ)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGE("wifi_direct_connect() SUCCESS \n");
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_foreach_connected_peers(wifi_direct_connected_peer_cb callback, void *user_data)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (callback == NULL)
+ {
+ WDC_LOGE("NULL Param [callback]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int i;
+
+ int status = 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_GET_CONNECTED_PEERS_INFO;
+ req.client_id = client_info->client_id;
+
+ status = __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status = __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_GET_CONNECTED_PEERS_INFO)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+
+ int num = rsp.param1;
+ int status = 0;
+ wfd_connected_peer_info_s *buff = NULL;
+
+ WDC_LOGD("Num of connected peers = %d \n",
+ (int) rsp.param1);
+
+ if (num > 0)
+ {
+ buff =
+ (wfd_connected_peer_info_s *) malloc(num *
+ sizeof
+ (wfd_connected_peer_info_s));
+ if (buff == NULL)
+ {
+ WDC_LOGE("malloc() failed!!!.\n");
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ status =
+ __wfd_client_read_more_data(client_info->sync_sockfd,
+ buff,
+ num *
+ sizeof
+ (wfd_connected_peer_info_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ if (NULL != buff)
+ free(buff);
+ WDC_LOGE("socket read error.\n");
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __wfd_client_print_connected_peer_info(buff, num);
+
+ WDC_LOGD("wifi_direct_foreach_connected_peers() SUCCESS\n");
+
+ wifi_direct_connected_peer_info_s *peer_list;
+
+ for (i = 0; i < num; i++)
+ {
+ peer_list = (wifi_direct_connected_peer_info_s *) calloc(1, sizeof(wifi_direct_connected_peer_info_s));
+ peer_list->device_name = strdup(buff[i].device_name);
+ peer_list->ip_address= (char *) calloc(1, 16);
+ snprintf(peer_list->ip_address, 16, IPSTR, IP2STR(buff[i].ip_address));
+ peer_list->mac_address = (char *) calloc(1, 18);
+ snprintf(peer_list->mac_address, 18, MACSTR, MAC2STR(buff[i].mac_address));
+ peer_list->interface_address = (char *) calloc(1, 18);
+ snprintf(peer_list->interface_address, 18, MACSTR, MAC2STR(buff[i].intf_mac_address));
+ peer_list->p2p_supported = buff[i].is_p2p;
+ peer_list->primary_device_type = buff[i].category;
+ peer_list->channel = buff[i].channel;
+
+ if (!callback(peer_list, user_data))
+ break;
+ }
+
+ if (NULL != buff)
+ free(buff);
+
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_create_group(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_CREATE_GROUP;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_CREATE_GROUP)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGE("wifi_direct_create_group() SUCCESS \n");
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n", rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_destroy_group(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_CANCEL_GROUP;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_CANCEL_GROUP)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGE("wifi_direct_destroy_group() SUCCESS \n");
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_is_group_owner(bool * owner)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (owner == NULL)
+ {
+ WDC_LOGE("NULL Param [owner]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_IS_GROUPOWNER;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_IS_GROUPOWNER)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d \n",
+ rsp.result);
+ WDC_LOGD("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGD("wifi_direct_is_group_owner() %s SUCCESS \n", rsp.param2);
+ *owner = (bool) rsp.param1;
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+
+}
+
+
+int wifi_direct_is_autonomous_group(bool * autonomous_group)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (autonomous_group == NULL)
+ {
+ WDC_LOGE("NULL Param [autonomous_group]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_IS_AUTONOMOUS_GROUP;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_IS_AUTONOMOUS_GROUP)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d \n", rsp.result);
+ WDC_LOGD("Error!!! [%s]\n", __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGD("wifi_direct_is_autonomous_group() %s SUCCESS \n", rsp.param2);
+ *autonomous_group = (bool) rsp.param1;
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+
+}
+
+
+int wifi_direct_set_group_owner_intent(int intent)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (intent < 0 || intent > 15)
+ {
+ WDC_LOGE("Invalid Param : intent[%d]\n", intent);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_SET_GO_INTENT;
+ req.client_id = client_info->client_id;
+
+ status =__wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ WDC_LOGD("writing msg hdr is success!\n");
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &intent,
+ sizeof(int));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_SET_GO_INTENT)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d \n",
+ rsp.result);
+ WDC_LOGD("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_get_group_owner_intent(int* intent)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_GET_GO_INTENT;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_GET_GO_INTENT)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d \n",
+ rsp.result);
+ WDC_LOGD("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGD("int wifi_direct_get_group_owner_intent() intent[%d] SUCCESS \n", rsp.param1);
+ *intent = rsp.param1;
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n", rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_set_max_clients(int max)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ WDC_LOGD("max client [%d]\n", max);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_SET_MAX_CLIENT;
+ req.client_id = client_info->client_id;
+
+ status =__wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ WDC_LOGD("writing msg hdr is success!\n");
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &max,
+ sizeof(int));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_SET_MAX_CLIENT)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d \n",
+ rsp.result);
+ WDC_LOGD("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_get_max_clients(int* max)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_GET_MAX_CLIENT;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_GET_MAX_CLIENT)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d \n",
+ rsp.result);
+ WDC_LOGD("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGD("int wifi_direct_get_max_clients() max_client[%d] SUCCESS \n", rsp.param1);
+ *max = rsp.param1;
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+/* Deprecated */
+int wifi_direct_get_own_group_channel(int* channel)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int ret = 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_GET_OWN_GROUP_CHANNEL;
+ req.client_id = client_info->client_id;
+
+ ret =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (ret != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(ret));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((ret =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", ret, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_GET_OWN_GROUP_CHANNEL)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d \n",
+ rsp.result);
+ WDC_LOGD("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGD("channel = [%d]\n",
+ (int) rsp.param1);
+ *channel = rsp.param1;
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n", rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+
+}
+
+
+int wifi_direct_get_operating_channel(int* channel)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int ret = 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_GET_OWN_GROUP_CHANNEL;
+ req.client_id = client_info->client_id;
+
+ ret =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (ret != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(ret));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((ret =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", ret, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_GET_OWN_GROUP_CHANNEL)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d \n", rsp.result);
+ WDC_LOGD("Error!!! [%s]\n", __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGD("channel = [%d]\n", (int) rsp.param1);
+ *channel = rsp.param1;
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n", rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+
+}
+
+
+int wifi_direct_set_wpa_passphrase(char *passphrase)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (NULL == passphrase)
+ {
+ WDC_LOGE("NULL Param [passphrase]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ WDC_LOGE("passphrase = [%s]\n", passphrase);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_SET_WPA;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ WDC_LOGD("writing msg hdr is success!\n");
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, passphrase, 64);
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_SET_WPA)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n", rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_activate_pushbutton(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_ACTIVATE_PUSHBUTTON;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_ACTIVATE_PUSHBUTTON)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d \n",
+ rsp.result);
+ WDC_LOGD("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGD("wifi_direct_activate_pushbutton() SUCCESS");
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_set_wps_pin(char *pin)
+{
+
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (NULL == pin)
+ {
+ WDC_LOGE("NULL Param [pin]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+ WDC_LOGE("pin = [%s]\n", pin);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_SET_WPS_PIN;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ WDC_LOGD("writing msg hdr is success!\n");
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, pin,
+ WIFI_DIRECT_WPS_PIN_LEN);
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE( "Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_SET_WPS_PIN)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d \n",
+ rsp.result);
+ WDC_LOGD("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_get_wps_pin(char **pin)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ char la_pin[WIFI_DIRECT_WPS_PIN_LEN + 1] = { 0, };
+
+ int status = 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_GET_WPS_PIN;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_GET_WPS_PIN)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d \n",
+ rsp.result);
+ WDC_LOGD("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGD("wifi_direct_get_wps_pin() SUCCESS");
+ strncpy(la_pin, rsp.param2, WIFI_DIRECT_WPS_PIN_LEN);
+
+ char *temp_pin;
+ temp_pin = strdup(la_pin);
+
+ *pin = temp_pin;
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_generate_wps_pin(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_GENERATE_WPS_PIN;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_GENERATE_WPS_PIN)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d",
+ rsp.result);
+ WDC_LOGD("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGD("wifi_direct_generate_wps_pin() SUCCESS");
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_get_supported_wps_mode(int *wps_mode)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int ret = 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_GET_SUPPORTED_WPS_MODE;
+ req.client_id = client_info->client_id;
+
+ ret =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (ret != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(ret));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((ret =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", ret, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_GET_SUPPORTED_WPS_MODE)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d \n",
+ rsp.result);
+ WDC_LOGD("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGD("Supported wps config = [%d]\n",
+ (int) rsp.param1);
+ *wps_mode = rsp.param1;
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+
+}
+
+
+int wifi_direct_foreach_supported_wps_types(wifi_direct_supported_wps_type_cb callback, void* user_data)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (callback == NULL)
+ {
+ WDC_LOGE("NULL Param [callback]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int ret = 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_GET_SUPPORTED_WPS_MODE;
+ req.client_id = client_info->client_id;
+
+ ret =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (ret != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(ret));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((ret =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE(
+ "Error!!! reading socket, status = %d errno = %s\n", ret,
+ strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_GET_SUPPORTED_WPS_MODE)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d \n",
+ rsp.result);
+ WDC_LOGD("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGD( "Supported wps config = [%d]\n",
+ (int) rsp.param1);
+ int wps_mode;
+ bool result;
+
+ wps_mode = rsp.param1;
+
+ if (wps_mode & WIFI_DIRECT_WPS_TYPE_PBC)
+ result = callback(WIFI_DIRECT_WPS_TYPE_PBC, user_data);
+
+ if ((result == true) && (wps_mode & WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY))
+ result = callback(WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY, user_data);
+
+
+ if ((result == true) && (wps_mode & WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD))
+ result = callback(WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD, user_data);
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+
+}
+
+
+int wifi_direct_set_wps_type(wifi_direct_wps_type_e type)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __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]\n", type);
+ }
+ else
+ {
+ WDC_LOGE("Invalid Param [wps_mode]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_SET_CURRENT_WPS_MODE;
+ req.client_id = client_info->client_id;
+
+ status =__wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ WDC_LOGD("writing msg hdr is success!\n");
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &type,
+ sizeof(wifi_direct_wps_type_e));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_SET_CURRENT_WPS_MODE)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d \n",
+ rsp.result);
+ WDC_LOGD("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_get_wps_type(wifi_direct_wps_type_e* type)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __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;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ wfd_config_data_s ls_config;
+
+ int status = 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_GET_CONFIG;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_GET_CONFIG)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ int status = 0;
+
+ WDC_LOGD("Link status = %d \n",
+ (int) rsp.param1);
+
+ status =
+ __wfd_client_read_more_data(client_info->sync_sockfd,
+ &ls_config,
+ sizeof(wfd_config_data_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("socket read error.");
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ __wfd_client_print_config_data(&ls_config);
+
+ *type = ls_config.wps_config;
+
+ WDC_LOGD("wifi_direct_get_wps_type() SUCCESS");
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n", rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+/* DPRECATED */
+int wifi_direct_set_ssid(const char *ssid)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (NULL == ssid)
+ {
+ WDC_LOGE("NULL Param [ssid]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ WDC_LOGE("ssid = [%s]\n", ssid);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_SET_SSID;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ WDC_LOGD("writing msg hdr is success!");
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, ssid,
+ WIFI_DIRECT_MAX_SSID_LEN);
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE(
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_SET_SSID)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_get_ssid(char **ssid)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (NULL == ssid)
+ {
+ WDC_LOGE("NULL Param [ssid]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ char la_ssid[WIFI_DIRECT_MAX_SSID_LEN + 1] = { 0, };
+
+ int status = 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_GET_SSID;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_GET_SSID)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d \n",
+ rsp.result);
+ WDC_LOGD("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGD(
+ "wifi_direct_get_ssid() %s SUCCESS \n",
+ rsp.param2);
+ strncpy(la_ssid, rsp.param2, WIFI_DIRECT_MAX_SSID_LEN);
+
+ char *temp_ssid = NULL;
+ temp_ssid = strdup(la_ssid);
+ if (NULL == temp_ssid)
+ {
+ WDC_LOGE("Failed to allocate memory for SSID\n");
+ return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
+ }
+
+ *ssid = temp_ssid;
+ }
+
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_get_device_name(char** device_name)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (NULL == device_name)
+ {
+ WDC_LOGE("NULL Param [device_name]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ 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 status = 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_GET_DEVICE_NAME;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
+ WDC_LOGE("Error!!! [%s]", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_GET_DEVICE_NAME)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d \n",
+ rsp.result);
+ WDC_LOGD("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGD("wifi_direct_get_device_name() %s SUCCESS \n", rsp.param2);
+ strncpy(la_device_name, rsp.param2, WIFI_DIRECT_MAX_DEVICE_NAME_LEN);
+
+ char *temp_device_name = NULL;
+ temp_device_name = strdup(la_device_name);
+ if (NULL == temp_device_name)
+ {
+ WDC_LOGE("Failed to allocate memory for device name\n");
+ return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
+ }
+
+ *device_name = temp_device_name;
+ }
+
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_set_device_name(const char *device_name)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ if (NULL == device_name)
+ {
+ WDC_LOGE("NULL Param [device_name]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ WDC_LOGE("device_name = [%s]\n", device_name);
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_SET_DEVICE_NAME;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ WDC_LOGD( "writing msg hdr is success!\n");
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, device_name,
+ WIFI_DIRECT_MAX_DEVICE_NAME_LEN);
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __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 \n", rsp.result);
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ 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)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (NULL == name)
+ {
+ WDC_LOGE("NULL Param [name]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_state_e status = 0;
+ int result;
+ 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;
+ }
+
+ char* get_str = NULL;
+ get_str = vconf_get_str(VCONFKEY_IFNAME);
+
+ if (get_str == NULL)
+ {
+ WDC_LOGD( "vconf (%s) value is NULL!!!\n", VCONFKEY_IFNAME);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_PERMITTED;
+ }
+ else
+ {
+ WDC_LOGD( "VCONFKEY_IFNAME(%s) : %s\n", VCONFKEY_IFNAME, get_str);
+
+ char *temp_ifname = NULL;
+ temp_ifname = strdup(get_str);
+ if (NULL == temp_ifname)
+ {
+ WDC_LOGE("Failed to allocate memory for ifname.\n");
+ return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
+ }
+
+ *name = temp_ifname;
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+
+int wifi_direct_get_ip_address(char **ip_address)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (NULL == ip_address)
+ {
+ WDC_LOGE("NULL Param [ip_address]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_state_e state = 0;
+ int result;
+ result = wifi_direct_get_state(&state);
+ WDC_LOGD( "wifi_direct_get_state() state=[%d], result=[%d]\n", state, result);
+
+ if( state < WIFI_DIRECT_STATE_CONNECTED)
+ {
+ WDC_LOGE("Device is not connected!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_PERMITTED;
+ }
+
+ char* get_str = NULL;
+ get_str = vconf_get_str(VCONFKEY_LOCAL_IP);
+
+ if (get_str == NULL)
+ {
+ WDC_LOGD("vconf (%s) value is NULL!!!\n", VCONFKEY_LOCAL_IP);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_PERMITTED;
+ }
+ else
+ {
+ WDC_LOGD("VCONFKEY_LOCAL_IP(%s) : %s\n", VCONFKEY_LOCAL_IP, get_str);
+
+ char *temp_ip = NULL;
+ temp_ip = strdup(get_str);
+ if (NULL == temp_ip)
+ {
+ WDC_LOGE("Failed to allocate memory for local ip address.\n");
+ return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
+ }
+
+ *ip_address = temp_ip;
+ }
+
+
+#if 0
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ char la_ip[64] = { 0, };
+
+ int status = 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_GET_IP_ADDR;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_GET_IP_ADDR)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d \n",
+ rsp.result);
+ WDC_LOGD("Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGD("wifi_direct_get_ip_address() SUCCESS \n");
+ strncpy(la_ip, rsp.param2, strlen(rsp.param2));
+
+ char *temp_ip = NULL;
+ temp_ip = strdup(la_ip);
+ if (NULL == temp_ip)
+ {
+ WDC_LOGE("Failed to allocate memory for IP address\n");
+ return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
+ }
+
+ *ip_address = temp_ip;
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+#endif
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_get_subnet_mask(char** subnet_mask)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (NULL == subnet_mask)
+ {
+ WDC_LOGE("NULL Param [subnet_mask]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_state_e status = 0;
+ int result;
+ 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;
+ }
+
+
+ char* get_str = NULL;
+ get_str = vconf_get_str(VCONFKEY_SUBNET_MASK);
+
+ if (get_str == NULL)
+ {
+ WDC_LOGD("vconf (%s) value is NULL!!!\n", VCONFKEY_SUBNET_MASK);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_PERMITTED;
+ }
+ else
+ {
+ WDC_LOGD("VCONFKEY_SUBNET_MASK(%s) : %s", VCONFKEY_SUBNET_MASK, get_str);
+
+ char *temp_subnetmask = NULL;
+ temp_subnetmask = strdup(get_str);
+ if (NULL == temp_subnetmask)
+ {
+ WDC_LOGE("Failed to allocate memory for subnet mask.\n");
+ return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
+ }
+
+ *subnet_mask = temp_subnetmask;
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_get_gateway_address(char** gateway_address)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (NULL == gateway_address)
+ {
+ WDC_LOGE("NULL Param [gateway_address]!\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGE("Client is NOT registered.\n");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+ wifi_direct_state_e status = 0;
+ int result;
+ 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;
+ }
+
+ char* get_str = NULL;
+ get_str = vconf_get_str(VCONFKEY_GATEWAY);
+
+ if (get_str == NULL)
+ {
+ WDC_LOGD("vconf (%s) value is NULL!!!\n", VCONFKEY_GATEWAY);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_PERMITTED;
+ }
+ else
+ {
+ WDC_LOGD("VCONFKEY_GATEWAY(%s) : %s", VCONFKEY_GATEWAY, get_str);
+
+ char *temp_gateway = NULL;
+ temp_gateway = strdup(get_str);
+ if (NULL == temp_gateway)
+ {
+ WDC_LOGE("Failed to allocate memory for gateway address.");
+ return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
+ }
+
+ *gateway_address = temp_gateway;
+ }
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_get_mac_address(char **mac_address)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (NULL == mac_address)
+ {
+ WDC_LOGE("NULL Param [mac_address]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WDC_LOGD("Client is NOT registered.");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+ }
+
+#if 0
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ unsigned char la_mac_addr[6] = { 0, };
+
+ int status = 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_GET_DEVICE_MAC;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! writing to socket, Errno = %s\n", strerror(errno));
+ WDC_LOGD("Error!!! [%s]\n", __wfd_print_error(status));
+ close(client_info->sync_sockfd);
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGD("Error!!! reading socket, status = %d errno = %s", status, strerror(errno));
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_GET_DEVICE_MAC)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d", rsp.result);
+ WDC_LOGD("Error!!! [%s]", __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGD("wifi_direct_get_mac_addr() SUCCESS");
+ strncpy((char *) la_mac_addr, (char *) rsp.param2,
+ strlen(rsp.param2));
+
+ char *temp_mac = NULL;
+ temp_mac = (char *) calloc(1, 18);
+ if (NULL == temp_mac)
+ {
+ WDC_LOGE("Failed to allocate memory for MAC address");
+ return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
+ }
+
+ sprintf(temp_mac, MACSTR, MAC2STR(la_mac_addr));
+
+ *mac_address = temp_mac;
+
+ }
+ }
+ else
+ {
+ WDC_LOGE("Error!!! Invalid resp cmd = %d",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+#else
+ int fd;
+ int n;
+ char mac_info[18];
+ unsigned char la_mac_addr[6];
+
+ memset(mac_info, 0, sizeof(mac_info));
+
+ if( (fd = open(WIFI_DIRECT_MAC_ADDRESS_INFO_FILE, O_RDONLY)) == -1)
+ {
+ WDC_LOGE("[.mac.info] file open failed.");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ n = read(fd, mac_info, 18);
+ if(n < 0)
+ {
+ WDC_LOGE("[.mac.info] file read failed.");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ WDC_LOGD("mac_address = [%s]", mac_info);
+
+ memset(la_mac_addr, 0, sizeof(la_mac_addr));
+ macaddr_atoe(mac_info, la_mac_addr);
+ la_mac_addr[0] = la_mac_addr[0] | 0x02;
+ la_mac_addr[1] = la_mac_addr[1];
+ la_mac_addr[2] = la_mac_addr[2];
+ la_mac_addr[3] = la_mac_addr[3];
+ la_mac_addr[4] = la_mac_addr[4];
+ la_mac_addr[5] = la_mac_addr[5];
+
+ char *temp_mac = NULL;
+ temp_mac = (char *) calloc(1, 18);
+ if (NULL == temp_mac)
+ {
+ WDC_LOGE("Failed to allocate memory for MAC address");
+ return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
+ }
+
+ //strncpy(temp_mac, mac_info, strlen(mac_info));
+ snprintf(temp_mac, 18, MACSTR, MAC2STR(la_mac_addr));
+
+ *mac_address = temp_mac;
+
+#endif
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_get_state(wifi_direct_state_e * state)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (NULL == state)
+ {
+ WDC_LOGE("NULL Param [state]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ 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;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int ret = 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_GET_LINK_STATUS;
+ req.client_id = client_info->client_id;
+
+ ret =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (ret != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
+ WDC_LOGE("Error!!! [%s]", __wfd_print_error(ret));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((ret =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s", ret,
+ strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_GET_LINK_STATUS)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d %s", rsp.result, __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ 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;
+
+ }
+ }
+ 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_is_discoverable(bool* discoverable)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (discoverable == NULL)
+ {
+ WDC_LOGE("NULL Param [discoverable]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ 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;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_IS_DISCOVERABLE;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
+ WDC_LOGE("Error!!! [%s]", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_IS_DISCOVERABLE)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d", rsp.result);
+ WDC_LOGD("Error!!! [%s]", __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGD("wifi_direct_is_discoverable() %s SUCCESS", rsp.param2);
+ *discoverable = (bool) rsp.param1;
+ }
+ }
+ 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_is_listening_only(bool* listen_only)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (listen_only == NULL)
+ {
+ WDC_LOGE("NULL Param [listen_only]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ 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;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_IS_LISTENING_ONLY;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
+ WDC_LOGE("Error!!! [%s]", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_IS_LISTENING_ONLY)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d", rsp.result);
+ WDC_LOGD("Error!!! [%s]", __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGD("wifi_direct_is_listening_only() %s SUCCESS", rsp.param2);
+ *listen_only = (bool) rsp.param1;
+ }
+ }
+ 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_primary_device_type(wifi_direct_primary_device_type_e* type)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (NULL == type)
+ {
+ WDC_LOGE("NULL Param [type]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ 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;
+ }
+
+ WDC_LOGD("Current primary_dev_type [%d]", WIFI_DIRECT_PRIMARY_DEVICE_TYPE_TELEPHONE);
+
+ *type = WIFI_DIRECT_PRIMARY_DEVICE_TYPE_TELEPHONE; // Telephone
+
+ __WDC_LOG_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_get_secondary_device_type(wifi_direct_secondary_device_type_e* type)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (NULL == type)
+ {
+ WDC_LOGE("NULL Param [type]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ 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;
+ }
+
+
+ WDC_LOGD("Current second_dev_type [%d]", WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PHONE_SM_DUAL);
+
+ *type = WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PHONE_SM_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)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ 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;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_SET_AUTOCONNECTION_MODE;
+ req.client_id = client_info->client_id;
+
+ status =__wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ WDC_LOGD("writing msg hdr is success!");
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &mode,
+ sizeof(bool));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
+ WDC_LOGE("Error!!! [%s]", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_SET_AUTOCONNECTION_MODE)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d", rsp.result);
+ WDC_LOGD("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_is_autoconnection_mode(bool* mode)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (mode == NULL)
+ {
+ WDC_LOGE("NULL Param [mode]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ 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;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_IS_AUTOCONNECTION_MODE;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
+ WDC_LOGE("Error!!! [%s]", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_IS_AUTOCONNECTION_MODE)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d", rsp.result);
+ WDC_LOGD("Error!!! [%s]", __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGD("wifi_direct_is_autoconnection_mode() %s SUCCESS", rsp.param2);
+ *mode = (bool) rsp.param1;
+ }
+ }
+ 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_set_persistent_group_enabled(bool enabled)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ 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;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = WIFI_DIRECT_ERROR_NONE;
+
+ 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 = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
+ WDC_LOGE("Error!!! [%s]",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_ACTIVATE_PERSISTENT_GROUP
+ || rsp.cmd == WIFI_DIRECT_CMD_DEACTIVATE_PERSISTENT_GROUP)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD( "Error!!! Result received = %d", rsp.result);
+ WDC_LOGD( "Error!!! [%s]", __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGD("wifi_direct_set_persistent_group_enabled() SUCCESS");
+ }
+ }
+ 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_is_persistent_group_enabled(bool* enabled)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ if (enabled == NULL)
+ {
+ WDC_LOGE("NULL Param [enabled]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ 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;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int status = 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_IS_PERSISTENT_GROUP;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
+ WDC_LOGE("Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_IS_PERSISTENT_GROUP)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d", rsp.result);
+ WDC_LOGD("Error!!! [%s]", __wfd_print_error(rsp.result));
+ __WDC_LOG_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WDC_LOGD("wifi_direct_is_persistent_group_enabled() %s SUCCESS", rsp.param2);
+ *enabled = (bool) rsp.param1;
+ }
+ }
+ 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_foreach_persistent_groups(wifi_direct_persistent_group_cb callback, void* user_data)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ 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 (callback == NULL)
+ {
+ WDC_LOGE("NULL Param [callback]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ int i;
+
+ int status = 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_GET_PERSISTENT_GROUP_INFO;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
+ WDC_LOGE("Error!!! [%s]", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_GET_PERSISTENT_GROUP_INFO)
+ {
+ 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
+ {
+
+ int num = rsp.param1;
+ int status = 0;
+ wfd_persistent_group_info_s *buff = NULL;
+
+ WDC_LOGD("Num of persistent groups = %d", (int) rsp.param1);
+
+ if (num > 0)
+ {
+ buff = (wfd_persistent_group_info_s *) malloc(num * sizeof(wfd_persistent_group_info_s));
+ if (buff == NULL)
+ {
+ WDC_LOGE("malloc() failed!!!.");
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ status =
+ __wfd_client_read_more_data(client_info->sync_sockfd,
+ buff,
+ num *
+ sizeof
+ (wfd_persistent_group_info_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ if (NULL != buff)
+ free(buff);
+ WDC_LOGE("socket read error.");
+ 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 = strdup(buff[i].ssid);
+ go_mac_address = (char *) calloc(1, 18);
+ snprintf(go_mac_address, 18, MACSTR, MAC2STR(buff[i].go_mac_address));
+
+ if (!callback(go_mac_address, ssid, user_data))
+ break;
+ }
+
+ if (NULL != buff)
+ free(buff);
+
+ }
+ }
+ 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_remove_persistent_group(const char* mac_address, const char* ssid)
+{
+ __WDC_LOG_FUNC_START__;
+
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ 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 ( NULL== mac_address )
+ {
+ WDC_LOGE("NULL Param [mac_address]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if ( NULL== ssid )
+ {
+ WDC_LOGE("NULL Param [ssid]!");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+ wfd_persistent_group_info_s persistent_group_info;
+ unsigned char la_mac_addr[6];
+
+ int status = 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_REMOVE_PERSISTENT_GROUP;
+ req.client_id = client_info->client_id;
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
+ WDC_LOGE("Error!!! [%s]", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ WDC_LOGD("writing msg hdr is success!");
+
+ strncpy(persistent_group_info.ssid, ssid, strlen(ssid));
+
+ memset(la_mac_addr, 0, sizeof(la_mac_addr));
+ macaddr_atoe(mac_address, la_mac_addr);
+ persistent_group_info.go_mac_address[0] = la_mac_addr[0];
+ persistent_group_info.go_mac_address[1] = la_mac_addr[1];
+ persistent_group_info.go_mac_address[2] = la_mac_addr[2];
+ persistent_group_info.go_mac_address[3] = la_mac_addr[3];
+ persistent_group_info.go_mac_address[4] = la_mac_addr[4];
+ persistent_group_info.go_mac_address[5] = la_mac_addr[5];
+
+ status =
+ __wfd_client_send_request(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, Errno = %s", strerror(errno));
+ WDC_LOGE("Error!!! [%s]", __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((status =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_REMOVE_PERSISTENT_GROUP)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d", rsp.result);
+ WDC_LOGD("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_set_p2poem_loglevel(int increase_log_level)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WDC_LOG_FUNC_START__;
+
+ 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;
+ }
+
+ wifi_direct_client_request_s req;
+ wifi_direct_client_response_s rsp;
+
+ int ret = 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_SET_OEM_LOGLEVEL;
+ req.client_id = client_info->client_id;
+ if (increase_log_level == 0)
+ req.data.listen_only = false;
+ else
+ req.data.listen_only = true;
+
+ ret =
+ __wfd_client_send_request(client_info->sync_sockfd, &req,
+ sizeof(wifi_direct_client_request_s));
+ if (ret != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
+ WDC_LOGE("Error!!! [%s]", __wfd_print_error(ret));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ if ((ret =
+ __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
+ sizeof(wifi_direct_client_response_s))) <= 0)
+ {
+ WDC_LOGE("Error!!! reading socket, status = %d errno = %s", ret, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_SET_OEM_LOGLEVEL)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WDC_LOGD("Error!!! Result received = %d", rsp.result);
+ WDC_LOGD("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;
+}