--- /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_STRANGE_CLIENT = -0x00008000|0x0201, /**< Invalid Client */
+ 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_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;
+
+
+/**
+ * Wi-Fi Direct WPS config methods
+ */
+typedef enum
+{
+ WIFI_DIRECT_WPS_PUSHBUTTON = 0x0001, /**< Push Button mode*/
+ WIFI_DIRECT_WPS_DISPLAY = 0x0002, /**< Display mode */
+ WIFI_DIRECT_WPS_KEYPAD = 0x0004, /**< Keypad mode */
+} wifi_direct_wps_cfg_e;
+
+/**
+* @struct wifi_direct_config_data_s
+* Wi-Fi Direct configuration data structure
+*/
+typedef struct
+{
+ /** ssid */
+ char *ssid;
+
+ /** Specifies the operating channel. If zero, auto channel selection
+ * will be used to find a quiet channel.
+ */
+ int channel;
+
+ /** WPS configuration parameters. */
+ wifi_direct_wps_cfg_e wps_config;
+
+ /** Max number of STAs allowed associations */
+ int max_clients;
+
+ /** TRUE to hide SSID in beacons and probe responses, FALSE otherwise. */
+ bool hide_SSID;
+
+ /** P2P Group owner intent value. */
+ int group_owner_intent;
+
+ bool want_persistent_group;
+
+ /** Auto connection mode */
+ bool auto_connection;
+
+ wifi_direct_primary_device_type_e primary_dev_type;
+ wifi_direct_secondary_device_type_e secondary_dev_type;
+} wifi_direct_config_data_s;
+
+
+/**
+ * @struct wifi_direct_discovered_peer_info_s
+ * Wi-Fi Direct buffer structure to store result of peer discovery
+ */
+typedef struct
+{
+ char* ssid; /** 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 */
+} 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* ssid; /** Null-terminated device friendly name. */
+ 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 */
+} 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);
+
+
+/*=============================================================================
+ 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);
+
+
+/*****************************************************************************************/
+/* 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);
+
+
+/*****************************************************************************************/
+/* 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);
+
+
+/*****************************************************************************************/
+/* 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);
+
+
+/*****************************************************************************************/
+/* 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);
+
+
+/*****************************************************************************************/
+/* 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_get_go_intent API function prototype
+ * int wifi_direct_get_go_intent(int * intent);
+ */
+/**
+ * \brief This API shall get GO intent value. \n
+ * @param * intent variable to store intent value. Application must allocate 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;
+ * int go_intent;
+ *
+ * result = wifi_direct_get_go_intent(&go_intent);
+ *
+ * if(result == WIFI_DIRECT_ERROR_NONE)......... // getting GO intent is successful
+ *
+ *\endcode
+ *
+ *\remarks None.
+ *
+ ******************************************************************************/
+int wifi_direct_get_go_intent(int *intent);
+
+
+
+/*****************************************************************************************/
+/* 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_get_supported_wps_mode
+ *
+ * \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_cfg_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);
+
+
+/*****************************************************************************************/
+/* wifi_direct_get_config_data API function prototype
+* int wifi_direct_get_config_data(wifi_direct_config_data_s** config)
+*/
+/**
+* \brief This API shall get Wi-Fi direct configuration data. \n
+* @param config Pointer to store configuration information. Application must free this memory.
+*
+* \see wifi_direct_set_config_data
+*
+* \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_config_data_s* config;
+*
+* result = wifi_direct_get_config_data(&config);
+*
+* if(result == WIFI_DIRECT_ERROR_NONE)......... // getting config data is successful
+*
+*\endcode
+*
+*\remarks None.
+*
+******************************************************************************/
+int wifi_direct_get_config_data(wifi_direct_config_data_s ** config);
+
+
+/*****************************************************************************************/
+/* wifi_direct_set_config_data API function prototype
+* int wifi_direct_set_config_data(wifi_direct_config_data_s* config);
+*/
+/**
+* \brief This API shall set or update Wi-Fi direct configuration data. \n
+* @param config Wi-Fi configuration data to be set
+*
+* \see wifi_direct_get_config_data
+*
+* \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_config_data_s* config;
+*
+* result = wifi_direct_get_config_data(&config);
+*
+* if(result != WIFI_DIRECT_ERROR_NONE)......... // Getting configuration data is not successful
+* {
+* return;
+* }
+*
+* // Change params
+* config->group_owner_intent = 8;
+* config->wps_config = WIFI_DIRECT_WPS_PUSHBUTTON;
+* config->want_persistent_group = false;
+* config->hide_SSID = false;
+* strncpy(config->ssid, "My WiFi Direct", WIFI_DIRECT_MAX_SSID_LEN);
+*
+* result = wifi_direct_set_config_data(config);
+* if(result == WIFI_DIRECT_ERROR_NONE)......... // Setting configuration data is successful
+* {
+*
+*
+*
+*\endcode
+*
+*\remarks None.
+*
+******************************************************************************/
+int wifi_direct_set_config_data(wifi_direct_config_data_s * config);
+
+
+/**
+ * @}
+ */
+
+#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
+ *****************************************************************************/
+#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>
+
+/*****************************************************************************
+ * 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;
+
+ printf("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;
+
+ 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_STRANGE_CLIENT:
+ return "WIFI_DIRECT_ERROR_STRANGE_CLIENT";
+ case WIFI_DIRECT_ERROR_NONE:
+ return "WIFI_DIRECT_ERROR_NONE";
+ default:
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Invalid error value: [%d]\n", error);
+ return "Invalid error";
+ }
+}
+
+static int __wfd_convert_client_event(wfd_client_event_e event)
+{
+ __WFD_CLIENT_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;
+
+ default:
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Invalid event : [%d]\n", event);
+ break;
+ }
+
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Reading Async Event[%d]\n",
+ sockfd);
+ //close(sockfd);
+ __wfd_reset_control();
+ __WFD_CLIENT_FUNC_END__;
+ return false;
+ }
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "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
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "activation_cb is NULL!!\n");
+ 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
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "discover_cb is NULL!!\n");
+ break;
+
+ case WIFI_DIRECT_CLI_EVENT_CONNECTION_START:
+ case WIFI_DIRECT_CLI_EVENT_CONNECTION_REQ:
+ case WIFI_DIRECT_CLI_EVENT_CONNECTION_RSP:
+ case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_RSP:
+ case WIFI_DIRECT_CLI_EVENT_CONNECTION_WPS_REQ:
+ case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_IND:
+ case WIFI_DIRECT_CLI_EVENT_DISASSOCIATION_IND:
+ case WIFI_DIRECT_CLI_EVENT_GROUP_CREATE_RSP:
+ case WIFI_DIRECT_CLI_EVENT_GROUP_DESTROY_RSP:
+ if (client->connection_cb != NULL)
+ client->connection_cb(error,
+ (wifi_direct_connection_state_e)
+ __wfd_convert_client_event(event), param1,
+ client->user_data_for_cb_connection);
+ else
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "connection_cb is NULL!!\n");
+ break;
+
+ default:
+ break;
+ }
+
+ __WFD_CLIENT_FUNC_END__;
+
+ return TRUE;
+}
+
+static wifi_direct_error_e __wfd_client_send_request(int sockfd, void *req_data, int dataLength)
+{
+ int retval = 0;
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if (sockfd > 0)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Write [%d] bytes to socket [%d].\n",
+ dataLength, sockfd);
+ errno = 0;
+ retval = write(sockfd, (char *) req_data, dataLength);
+
+ if (retval <= 0)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to the socket. Error = %s \n",
+ strerror(errno));
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+ }
+
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+ }
+
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid sockfd [%d]\n", sockfd);
+ __WFD_CLIENT_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();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ errno = 0;
+ if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! creating async socket. Error = [%s].\n",
+ strerror(errno));
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Created async socket [%d]\n", sockfd);
+
+ memset(&servAddr, 0, sizeof(servAddr));
+ servAddr.sun_family = AF_UNIX;
+ strcpy(servAddr.sun_path, path);
+ len = sizeof(servAddr.sun_family) + strlen(path);
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW,
+ "Connecting to server socket to register async socket [%d]\n",
+ sockfd);
+ errno = 0;
+ if ((connect(sockfd, (struct sockaddr *) &servAddr, len)) < 0)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! connecting to server socket. Error = [%s].\n",
+ strerror(errno));
+ close(sockfd);
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(result));
+ close(sockfd);
+ __WFD_CLIENT_FUNC_END__;
+ return result;
+ }
+
+ client_info->async_sockfd = sockfd;
+
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Async socket is created= %d\n", 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;
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if (sockfd <= 0)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid socket FD [%d]\n",
+ sockfd);
+ __WFD_CLIENT_FUNC_END__;
+ return -1;
+ }
+
+ if ((dataptr == NULL) || (datalen <= 0))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid parameter\n");
+ __WFD_CLIENT_FUNC_END__;
+ return -1;
+ }
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "@@@@@@@ len = %d @@@@@@@@@@@\n", datalen);
+
+ pollfd.fd = sockfd;
+ pollfd.events = POLLIN | POLLERR | POLLHUP;
+ pollret = poll(&pollfd, 1, timeout);
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "POLL ret = %d, \n", pollret);
+
+ if (pollret > 0)
+ {
+ if (pollfd.revents == POLLIN)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "POLLIN \n");
+
+ while (datalen)
+ {
+ errno = 0;
+ retval = read(sockfd, (char *) dataptr, datalen);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "sockfd %d retval %d\n", sockfd,
+ retval);
+ if (retval <= 0)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading data, error [%s]\n",
+ strerror(errno));
+ __WFD_CLIENT_FUNC_END__;
+ return retval;
+ }
+ total_data_recd += retval;
+ dataptr += retval;
+ datalen -= retval;
+ }
+ __WFD_CLIENT_FUNC_END__;
+ return total_data_recd;
+ }
+ else if (pollfd.revents & POLLHUP)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "POLLHUP\n");
+ __WFD_CLIENT_FUNC_END__;
+ return 0;
+ }
+ else if (pollfd.revents & POLLERR)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "POLLERR\n");
+ __WFD_CLIENT_FUNC_END__;
+ return 0;
+ }
+ }
+ else if (pollret == 0)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "POLLing timeout \n");
+ __WFD_CLIENT_FUNC_END__;
+ return 0;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Polling unknown error \n");
+ __WFD_CLIENT_FUNC_END__;
+ return -1;
+ }
+ __WFD_CLIENT_FUNC_END__;
+ return 1;
+}
+
+
+static int __wfd_client_read_more_data(int sockfd, void *pData, int Datalen)
+{
+ int retval = 0;
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if (sockfd < 0)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Inavlid argument passed\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (pData == NULL)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Inavlid argument passed\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (Datalen <= 0)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Inavlid argument passed\n");
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading response from CM. errno = [%d] \n",
+ errno);
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+void __wfd_client_print_entry_list(wfd_discovery_entry_s * list, int num)
+{
+ int i = 0;
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "------------------------------------------\n");
+ for (i = 0; i < num; i++)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "== Peer index : %d ==\n", i);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "is Group Owner ? %s\n",
+ list[i].is_group_owner ? "YES" : "NO");
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "SSID : %s\n", list[i].ssid);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "MAC address : " MACSTR "\n",
+ MAC2STR(list[i].mac_address));
+ }
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "------------------------------------------\n");
+}
+
+void __wfd_client_print_connected_peer_info(wfd_connected_peer_info_s * list, int num)
+{
+ int i = 0;
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "------------------------------------------\n");
+ for (i = 0; i < num; i++)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "== Peer index : %d ==\n", i);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "ssid : %s\n", list[i].ssid);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Device MAC : " MACSTR "\n",
+ MAC2STR(list[i].mac_address));
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Interface MAC : " MACSTR "\n",
+ MAC2STR(list[i].intf_mac_address));
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "services : %d\n", list[i].services);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "is_p2p : %d\n", list[i].is_p2p);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "category : %d\n", list[i].category);
+ }
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "------------------------------------------\n");
+}
+
+
+void __wfd_client_print_config_data(wfd_config_data_s * config)
+{
+ if (config == NULL)
+ return;
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Operating channel = [%d]\n", config->channel);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "WPS method = [%d, %s]\n", config->wps_config,
+ (config->wps_config ==
+ WIFI_DIRECT_WPS_PUSHBUTTON) ?
+ "Pushbutton" : (config-> wps_config == WIFI_DIRECT_WPS_DISPLAY)
+ ? "Display" : "Keypad");
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Max client = [%d]\n", config->max_clients);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "grp_owner_intent = [%d]\n",
+ config->group_owner_intent);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "hide-SSID = [%d]\n", config->hide_SSID);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "want_persistent_group = [%d]\n",
+ config->want_persistent_group);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "auto_connection = [%d]\n",
+ config->auto_connection);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "primary_dev_type = [%d]\n",
+ config->primary_dev_type);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "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;
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if (client_info->is_registered == TRUE)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Warning!!! Already registered\nUpdate user data and callback!\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+ }
+
+ errno = 0;
+ if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! creating sync socket. Error = [%s].\n",
+ strerror(errno));
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Created sync socket [%d]\n", sockfd);
+
+ memset(&servAddr, 0, sizeof(servAddr));
+ servAddr.sun_family = AF_UNIX;
+ strcpy(servAddr.sun_path, path);
+ len = sizeof(servAddr.sun_family) + strlen(path);
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW,
+ "Connecting to server socket to register sync socket [%d]\n",
+ sockfd);
+
+
+
+ int retry_count = 2;
+ while (retry_count > 0)
+ {
+ errno = 0;
+ if ((ret = connect(sockfd, (struct sockaddr *) &servAddr, len)) < 0)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! connecting to server socket. Error = [%d] %s.\n",
+ errno, strerror(errno));
+ if (sockfd > 0)
+ close(sockfd);
+
+ __WFD_CLIENT_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();
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ close(sockfd);
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (resp.cmd == WIFI_DIRECT_CMD_REGISTER)
+ {
+ if (resp.result == WIFI_DIRECT_ERROR_NONE)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Client ID received = %d \n",
+ resp.client_id);
+ WFD_CLIENT_LOG(WFD_LOG_LOW,
+ "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
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! Client Register = %d\n",
+ resp.result);
+ close(sockfd);
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! creating Async Socket \n");
+ __wfd_reset_control();
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ client_info->async_sockfd = async_sockfd;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! Invalid Response received from wfd Server. cmd = %d \n",
+ resp.cmd);
+ close(sockfd);
+ __WFD_CLIENT_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);
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW,
+ "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;
+
+ __WFD_CLIENT_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+
+int wifi_direct_deinitialize(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if (client_info->is_registered == false)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is already deregistered.\n");
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "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();
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error.. Something wrong...!!!\n");
+ }
+
+ __wfd_reset_control();
+
+ __WFD_CLIENT_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();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if (NULL == cb)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Callback is NULL.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (client_info->is_registered == false)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is not initialized.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_PERMITTED;
+ }
+
+ 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();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if (client_info->is_registered == false)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is not initialized.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_PERMITTED;
+ }
+
+ 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();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if (NULL == cb)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Callback is NULL.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (client_info->is_registered == false)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is not initialized.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_PERMITTED;
+ }
+
+ 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();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if (client_info->is_registered == false)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is not initialized.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_PERMITTED;
+ }
+
+ 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();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if (NULL == cb)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Callback is NULL.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (client_info->is_registered == false)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is not initialized.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_PERMITTED;
+ }
+
+ 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();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if (client_info->is_registered == false)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is not initialized.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NOT_PERMITTED;
+ }
+
+ client_info->connection_cb = NULL;
+ client_info->user_data_for_cb_connection = NULL;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_activate(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ 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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_ACTIVATE)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! Result received = %d \n", rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Activating device is successfull.\n");
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_deactivate(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ 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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_DEACTIVATE)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! Result received = %d \n", rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Device Deactivated! \n");
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_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();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ 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;
+
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! Result received = %d \n", rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "wifi_direct_start_discovery() SUCCESS \n");
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_cancel_discovery(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ 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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_CANCEL_DISCOVERY)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! Result received = %d \n", rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "wifi_direct_cancel_discovery() SUCCESS \n");
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_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();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ if (callback == NULL)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [callback]!\n");
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Result received = %d \n", rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n", __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ int num = rsp.param1;
+ int status = 0;
+ wfd_discovery_entry_s *buff = NULL;
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "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;
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "socket read error.\n");
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __wfd_client_print_entry_list(buff, num);
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW,
+ "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->ssid = strdup(buff[i].ssid);
+ 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->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
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_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];
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ if (mac_address == NULL)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "mac_addr is NULL.\n");
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_CONNECT)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! Result received = %d \n", rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "wifi_direct_connect() SUCCESS \n");
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_disconnect_all(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ 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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_DISCONNECT_ALL)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! Result received = %d \n", rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "wifi_direct_disconnect_all() SUCCESS \n");
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_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];
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if (mac_address == NULL)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "mac_address is NULL.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ 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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_DISCONNECT)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! Result received = %d \n", rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "wifi_direct_disconnect() SUCCESS \n");
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_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];
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ if (mac_address == NULL)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "mac_addr is NULL.\n");
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! Result received = %d \n", rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "wifi_direct_connect() SUCCESS \n");
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_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();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ if (callback == NULL)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [callback]!\n");
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! Result received = %d \n", rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+
+ int num = rsp.param1;
+ int status = 0;
+ wfd_connected_peer_info_s *buff = NULL;
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "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);
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "socket read error.\n");
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __wfd_client_print_connected_peer_info(buff, num);
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW,
+ "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->ssid = strdup(buff[i].ssid);
+ 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;
+
+ if (!callback(peer_list, user_data))
+ break;
+ }
+
+ if (NULL != buff)
+ free(buff);
+
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_create_group(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ 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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_CREATE_GROUP)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! Result received = %d \n", rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "wifi_direct_create_group() SUCCESS \n");
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_destroy_group(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ 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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_CANCEL_GROUP)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! Result received = %d \n", rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "wifi_direct_destroy_group() SUCCESS \n");
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_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();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if (owner == NULL)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [owner]!\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ 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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_IS_GROUPOWNER)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
+ rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW,
+ "wifi_direct_is_group_owner() %s SUCCESS \n",
+ rsp.param2);
+ *owner = (bool) rsp.param1;
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_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();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if (autonomous_group == NULL)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [autonomous_group]!\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ 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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
+ rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW,
+ "wifi_direct_is_autonomous_group() %s SUCCESS \n",
+ rsp.param2);
+ *autonomous_group = (bool) rsp.param1;
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+
+}
+
+
+int wifi_direct_get_go_intent(int *intent)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ 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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
+ rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW,
+ "wifi_direct_get_go_intent() intent[%d] SUCCESS \n",
+ rsp.param1);
+ *intent = rsp.param1;
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_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();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ if (NULL == passphrase)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [passphrase]!\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "writing msg hdr is success!\n");
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, passphrase, 64);
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_SET_WPA)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! Result received = %d \n", rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_activate_pushbutton(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ 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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_ACTIVATE_PUSHBUTTON)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
+ rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW,
+ "wifi_direct_activate_pushbutton() SUCCESS \n");
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_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();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ if (NULL == pin)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [pin]!\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
+ rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_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();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ 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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
+ rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW,
+ "wifi_direct_get_wps_pin() SUCCESS \n");
+ strncpy(la_pin, rsp.param2, WIFI_DIRECT_WPS_PIN_LEN);
+
+ char *temp_pin;
+ temp_pin = strdup(la_pin);
+
+ *pin = temp_pin;
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_generate_wps_pin(void)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ 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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
+ rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW,
+ "wifi_direct_generate_wps_pin() SUCCESS \n");
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_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();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ 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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(ret));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n", ret,
+ strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
+ rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Supported wps config = [%d]\n",
+ (int) rsp.param1);
+ *wps_mode = rsp.param1;
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+
+}
+
+
+int wifi_direct_set_ssid(const char *ssid)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ if (NULL == ssid)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [ssid]!\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "writing msg hdr is success!\n");
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, ssid,
+ WIFI_DIRECT_MAX_SSID_LEN);
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_SET_SSID)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! Result received = %d \n", rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+
+int wifi_direct_get_ssid(char **ssid)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if (NULL == ssid)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [ssid]!\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ 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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_GET_SSID)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
+ rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW,
+ "wifi_direct_get_ssid() %s SUCCESS \n",
+ rsp.param2);
+ strncpy(la_ssid, rsp.param2, WIFI_DIRECT_MAX_SSID_LEN);
+
+ char *temp_ssid;
+ temp_ssid = strdup(la_ssid);
+
+ *ssid = temp_ssid;
+ }
+
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_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();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if (NULL == ip_address)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [ip_address]!\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ 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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
+ rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW,
+ "wifi_direct_get_ip_address() SUCCESS \n");
+ strncpy(la_ip, rsp.param2, strlen(rsp.param2));
+
+ char *temp_ip;
+ temp_ip = strdup(la_ip);
+
+ *ip_address = temp_ip;
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_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();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if (NULL == mac_address)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [mac_address]!\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ 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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ close(client_info->sync_sockfd);
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
+ rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW,
+ "wifi_direct_get_mac_addr() SUCCESS \n");
+ strncpy((char *) la_mac_addr, (char *) rsp.param2,
+ strlen(rsp.param2));
+
+ char *temp_mac = NULL;
+ temp_mac = (char *) calloc(1, 18);
+
+ sprintf(temp_mac, MACSTR, MAC2STR(la_mac_addr));
+
+ *mac_address = temp_mac;
+
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_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();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if (NULL == state)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [state]!\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ 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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(ret));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n", ret,
+ strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW,
+ "Error!!! Result received = %d %s\n", rsp.result,
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Link Status = %d \n",
+ (int) rsp.param1);
+ *state = (wifi_direct_state_e) rsp.param1;
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+int wifi_direct_get_config_data(wifi_direct_config_data_s ** config)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ if (config == NULL)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [config]!\n");
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_GET_CONFIG)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! Result received = %d \n", rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ else
+ {
+ int status = 0;
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "socket read error.\n");
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ __wfd_client_print_config_data(&ls_config);
+
+ wifi_direct_config_data_s *temp_config;
+ temp_config =
+ (wifi_direct_config_data_s *) calloc(1,
+ sizeof
+ (wifi_direct_config_data_s));
+
+ temp_config->ssid = strdup(ls_config.ssid);
+ temp_config->channel = ls_config.channel;
+ temp_config->wps_config = ls_config.wps_config;
+ temp_config->max_clients = ls_config.max_clients;
+ temp_config->hide_SSID = ls_config.hide_SSID;
+ temp_config->group_owner_intent = ls_config.group_owner_intent;
+ temp_config->want_persistent_group =
+ ls_config.want_persistent_group;
+ temp_config->auto_connection = ls_config.auto_connection;
+ temp_config->primary_dev_type = ls_config.primary_dev_type;
+ temp_config->secondary_dev_type = ls_config.secondary_dev_type;
+
+ *config = temp_config;
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW,
+ "wifi_direct_get_config_data() SUCCESS\n");
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+
+
+int wifi_direct_set_config_data(wifi_direct_config_data_s * config)
+{
+ wifi_direct_client_info_s *client_info = __wfd_get_control();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ if (config == NULL)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [config]!\n");
+ __WFD_CLIENT_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_SET_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "writing msg hdr is success!\n");
+
+
+ strncpy(ls_config.ssid, config->ssid, strlen(config->ssid));
+ ls_config.channel = config->channel;
+ ls_config.wps_config = config->wps_config;
+ ls_config.max_clients = config->max_clients;
+ ls_config.hide_SSID = config->hide_SSID;
+ ls_config.group_owner_intent = config->group_owner_intent;
+ ls_config.want_persistent_group = config->want_persistent_group;
+ ls_config.auto_connection = config->auto_connection;
+ ls_config.primary_dev_type = config->primary_dev_type;
+ ls_config.secondary_dev_type = config->secondary_dev_type;
+
+ __wfd_client_print_config_data(&ls_config);
+
+ status =
+ __wfd_client_send_request(client_info->sync_sockfd, &ls_config,
+ sizeof(wfd_config_data_s));
+ if (status != WIFI_DIRECT_ERROR_NONE)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(status));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n",
+ status, strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
+ }
+ else
+ {
+ if (rsp.cmd == WIFI_DIRECT_CMD_SET_CONFIG)
+ {
+ if (rsp.result != WIFI_DIRECT_ERROR_NONE)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
+ rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_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();
+
+ __WFD_CLIENT_FUNC_START__;
+
+ if ((client_info->is_registered == false)
+ || (client_info->client_id == WFD_INVALID_ID))
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
+ __WFD_CLIENT_FUNC_END__;
+ return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
+ }
+
+ 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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! writing to socket, Errno = %s\n",
+ strerror(errno));
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
+ __wfd_print_error(ret));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR,
+ "Error!!! reading socket, status = %d errno = %s\n", ret,
+ strerror(errno));
+ client_info->sync_sockfd = -1;
+ __wfd_reset_control();
+ __WFD_CLIENT_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)
+ {
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
+ rsp.result);
+ WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
+ __wfd_print_error(rsp.result));
+ __WFD_CLIENT_FUNC_END__;
+ return rsp.result;
+ }
+ }
+ else
+ {
+ WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
+ rsp.cmd);
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+ }
+
+ __WFD_CLIENT_FUNC_END__;
+
+ return WIFI_DIRECT_ERROR_NONE;
+}