From: sungsik jang Date: Wed, 22 Aug 2012 06:22:49 +0000 (+0900) Subject: tizen 2.0beta X-Git-Tag: 2.0_alpha~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=198509504b279a27dd87784ef17411d75a940bfa;p=framework%2Fconnectivity%2Flibwifi-direct.git tizen 2.0beta --- diff --git a/debian/changelog b/debian/changelog index f324d33..e73c2eb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,231 @@ -libwifi-direct (0.0.1) unstable; urgency=low +libwifi-direct (0.2.8) unstable; urgency=low - * Wi-Fi Direct library initial upload - * Git : public/pkgs/w/libwifi-direct - * Tag : libwifi-direct_0.0.1 + * tagging "tizen_build" + * Git : framework/connectivity/libwifi-direct + * Tag : libwifi-direct_0.2.8 + + -- Sungsik Jang Mon, 13 Aug 2012 15:37:09 +0900 + +libwifi-direct (0.2.7) unstable; urgency=low + + * stripped package + * Git : slp/pkgs/l/libwifi-direct + * Tag : libwifi-direct_0.2.7 + + -- Sungsik Jang Mon, 16 Jul 2012 13:08:38 +0900 + +libwifi-direct (0.2.5) unstable; urgency=low + + * applied new APIs. + * Git : slp/pkgs/l/libwifi-direct + * Tag : libwifi-direct_0.2.5 + + -- Sungsik Jang Fri, 01 Jun 2012 15:20:07 +0900 + +libwifi-direct (0.2.4) unstable; urgency=low + + * package version update + * Git : slp/pkgs/l/libwifi-direct + * Tag : libwifi-direct_0.2.4 + + -- Dongwook Lee Thu, 24 May 2012 02:05:08 +0900 + +libwifi-direct (0.2.3) unstable; urgency=low + + * IP lease (DHCP) event is added. + * Git : slp/pkgs/l/libwifi-direct + * Tag : libwifi-direct_0.2.3 + + -- Dongwook Lee Mon, 21 May 2012 11:46:18 +0900 + +libwifi-direct (0.2.2) unstable; urgency=low + + * package update + * Git : slp/pkgs/l/libwifi-direct + * Tag : libwifi-direct_0.2.2 + + -- Dongwook Lee Sat, 19 May 2012 01:39:34 +0900 + +libwifi-direct (0.2.1) unstable; urgency=low + + * added new APIs for bada + * Git : slp/pkgs/l/libwifi-direct + * Tag : libwifi-direct_0.2.1 + + -- Sungsik Jang Wed, 09 May 2012 13:39:38 +0900 + +libwifi-direct (0.2.0) unstable; urgency=low + + * Wi-Fi Direct Library initial upload + * Git : slp/pkgs/l/libwifi-direct + * Tag : libwifi-direct_0.2.0 + + -- Sungsik Jang Mon, 23 Apr 2012 11:49:23 +0900 + +wifi-direct (0.1.8) unstable; urgency=low + + * fixed i386 build break + * Git : slp/pkgs/w/wifi-direct + * Tag : wifi-direct_0.1.8 + + -- Sungsik Jang Thu, 19 Apr 2012 23:03:05 +0900 + +wifi-direct (0.1.7) unstable; urgency=low + + * fixed i386 build break + * Git : slp/pkgs/w/wifi-direct + * Tag : wifi-direct_0.1.7 + + -- Sungsik Jang Thu, 19 Apr 2012 22:51:36 +0900 + +wifi-direct (0.1.6) unstable; urgency=low + + * modified the defect of displaying popup + * Git : slp/pkgs/w/wifi-direct + * Tag : wifi-direct_0.1.6 + + -- Sungsik Jang Thu, 19 Apr 2012 22:28:09 +0900 + +wifi-direct (0.1.5) unstable; urgency=low + + * modified spec file / modified the foreach API + * Git : slp/pkgs/w/wifi-direct + * Tag : wifi-direct_0.1.5 + + -- Sungsik Jang Thu, 29 Mar 2012 15:20:25 +0900 + +wifi-direct (0.1.4) unstable; urgency=low + + * Check socket fd is writable to avoid accessing a closed socket fd. + * Git : slp/pkgs/w/wifi-direct + * Tag : wifi-direct_0.1.4 + + -- Dongwook Lee Tue, 20 Mar 2012 13:14:25 +0900 + +wifi-direct (0.1.3) unstable; urgency=low + + * applied the changed dbus interface name of SONET + * Git : slp/pkgs/w/wifi-direct + * Tag : wifi-direct_0.1.3 + + -- Sungsik Jang Tue, 20 Mar 2012 09:57:15 +0900 + +wifi-direct (0.1.2) unstable; urgency=low + + * fixed build dependancy problerm + * Git : slp/pkgs/w/wifi-direct + * Tag : wifi-direct_0.1.2 + + -- Sungsik Jang Fri, 16 Mar 2012 13:41:24 +0900 + +wifi-direct (0.1.1) unstable; urgency=low + + * Applied C API style (Phase 2) + * Git : slp/pkgs/w/wifi-direct + * Tag : wifi-direct_0.1.1 + + -- Sungsik Jang Wed, 14 Mar 2012 13:57:03 +0900 + +wifi-direct (0.1.0) unstable; urgency=low + + * Applied C API style (Phase 2) + * Git : slp/pkgs/w/wifi-direct + * Tag : wifi-direct_0.1.0 + + -- Sungsik Jang Wed, 14 Mar 2012 13:03:46 +0900 + +wifi-direct (0.0.11) unstable; urgency=low + + * changed connection callback function / changed deactivation oem to excute wifi-direct drive off + * Git : slp/pkgs/w/wifi-direct + * Tag : wifi-direct_0.0.11 + + -- Sungsik Jang Tue, 28 Feb 2012 16:40:34 +0900 + +wifi-direct (0.0.10) unstable; urgency=low + + * added launching system popup application / fixed disconnection defect + * Git : slp/pkgs/w/wifi-direct + * Tag : wifi-direct_0.0.10 + + -- Sungsik Jang Tue, 21 Feb 2012 17:29:54 +0900 + +wifi-direct (0.0.9) unstable; urgency=low + + * fixed i386 build error + * Git : slp/pkgs/w/wifi-direct + * Tag : wifi-direct_0.0.9 + + -- Sungsik Jang Thu, 16 Feb 2012 21:47:42 +0900 + +wifi-direct (0.0.8) unstable; urgency=low + + * Applied C API style + * Git : slp/pkgs/w/wifi-direct + * Tag : wifi-direct_0.0.8 + + -- Sungsik Jang Thu, 16 Feb 2012 13:57:02 +0900 + +wifi-direct (0.0.7) unstable; urgency=low + + * Rollback to wifi-direct_0.0.6 + sonet dbus name change(com.samsung.sonet->net.sonet) + * Git : slp/pkgs/w/wifi-direct + * Tag : wifi-direct_0.0.7 + + -- Dongwook Lee > Fri, 10 Feb 2012 10:15:01 +0900 + +wifi-direct (0.0.6) unstable; urgency=low + + * Fixed S1-1045 (wl0.1 default interface issue) / updated doxygen + * Git : slp/pkgs/w/wifi-direct + * Tag : wifi-direct_0.0.6 + + -- Sungsik Jang Wed, 01 Feb 2012 19:12:44 +0900 + +wifi-direct (0.0.5) unstable; urgency=low + + * Fixed i386 build error issue + * Git : slp/pkgs/w/wifi-direct + * Tag : wifi-direct_0.0.5 + + -- Sungsik Jang Thu, 19 Jan 2012 14:28:15 +0900 + +wifi-direct (0.0.4) unstable; urgency=low + + * Fixed i386 build error issue + * Git : slp/pkgs/w/wifi-direct + * Tag : wifi-direct_0.0.4 + + -- Sungsik Jang Thu, 19 Jan 2012 14:15:44 +0900 + +wifi-direct (0.0.3) unstable; urgency=low + + * Fixed i386 build error issue + * Git : slp/pkgs/w/wifi-direct + * Tag : wifi-direct_0.0.3 + + -- Sungsik Jang Tue, 17 Jan 2012 00:01:17 +0900 + +wifi-direct (0.0.2) unstable; urgency=low + + * Fixed uploading issue + * Git : slp/pkgs/w/wifi-direct + * Tag : wifi-direct_0.0.2 + + -- Taeksu Shin Mon, 16 Jan 2012 23:39:22 +0900 + +wifi-direct (0.0.1) unstable; urgency=low + + * Applied new release + * Git : slp/pkgs/w/wifi-direct + * Tag : wifi-direct_0.0.1 + + -- Sungsik Jang Mon, 16 Jan 2012 21:42:30 +0900 + +wifi-direct (0.0.1) unstable; urgency=low + + * debian/changelog + + -- Misun Kim Tue, 22 Feb 2011 16:54:20 +0900 - -- Dongwook Lee Sat, 17 Mar 2012 18:41:24 +0900 diff --git a/include/wifi-direct-internal.h b/include/wifi-direct-internal.h index 924df3c..a5f0e75 100644 --- a/include/wifi-direct-internal.h +++ b/include/wifi-direct-internal.h @@ -55,14 +55,16 @@ typedef unsigned int ipv4_addr_t; #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" #define IP2STR(a) (a)[0], (a)[1], (a)[2], (a)[3] -#ifdef IPSTR -#undef IPSTR -#define IPSTR " %d.%d.%d.%d" -#endif /** IPSTR */ +#define IPSTR "%d.%d.%d.%d" #define WIFI_DIRECT_MAX_SSID_LEN 32 #define WIFI_DIRECT_WPS_PIN_LEN 8 +#define WIFI_DIRECT_MAC_ADDRESS_INFO_FILE "/opt/etc/.mac.info" +#define VCONFKEY_IFNAME "memory/private/wifi_direct_manager/p2p_ifname" +#define VCONFKEY_LOCAL_IP "memory/private/wifi_direct_manager/p2p_local_ip" +#define VCONFKEY_SUBNET_MASK "memory/private/wifi_direct_manager/p2p_subnet_mask" +#define VCONFKEY_GATEWAY "memory/private/wifi_direct_manager/p2p_gateway" typedef enum { @@ -94,13 +96,20 @@ typedef enum WIFI_DIRECT_CMD_GET_INCOMMING_PEER_INFO, WIFI_DIRECT_CMD_SET_WPA, WIFI_DIRECT_CMD_GET_SUPPORTED_WPS_MODE, + WIFI_DIRECT_CMD_SET_CURRENT_WPS_MODE, WIFI_DIRECT_CMD_GET_CONNECTED_PEERS_INFO, WIFI_DIRECT_CMD_CANCEL_GROUP, WIFI_DIRECT_CMD_DISCONNECT, + WIFI_DIRECT_CMD_SET_GO_INTENT, WIFI_DIRECT_CMD_GET_GO_INTENT, WIFI_DIRECT_CMD_GET_DEVICE_MAC, WIFI_DIRECT_CMD_IS_AUTONOMOUS_GROUP, - + WIFI_DIRECT_CMD_SET_MAX_CLIENT, + WIFI_DIRECT_CMD_GET_MAX_CLIENT, + WIFI_DIRECT_CMD_SET_AUTOCONNECTION_MODE, + WIFI_DIRECT_CMD_IS_DISCOVERABLE, + WIFI_DIRECT_CMD_GET_OWN_GROUP_CHANNEL, + WIFI_DIRECT_CMD_SET_OEM_LOGLEVEL, WIFI_DIRECT_CMD_MAX @@ -134,6 +143,7 @@ typedef enum WIFI_DIRECT_CLI_EVENT_GROUP_CREATE_RSP, /**< */ WIFI_DIRECT_CLI_EVENT_GROUP_DESTROY_RSP, /**< */ + WIFI_DIRECT_CLI_EVENT_IP_LEASED_IND, /**< */ } wfd_client_event_e; /** @@ -143,7 +153,7 @@ typedef struct { char ssid[WIFI_DIRECT_MAX_SSID_LEN + 1]; int channel; - wifi_direct_wps_cfg_e wps_config; + wifi_direct_wps_type_e wps_config; int max_clients; bool hide_SSID; int group_owner_intent; @@ -161,16 +171,17 @@ typedef struct { bool is_group_owner; char ssid[WIFI_DIRECT_MAX_SSID_LEN + 1]; - char mac_address[6]; + unsigned char mac_address[6]; int channel; bool is_connected; unsigned int services; bool is_persistent_go; - char intf_mac_address[6]; + unsigned char intf_mac_address[6]; unsigned int wps_device_pwd_id; unsigned int wps_cfg_methods; unsigned int category; unsigned int subcategory; + bool is_wfd_device ; } wfd_discovery_entry_s; @@ -180,11 +191,13 @@ typedef struct typedef struct { char ssid[WIFI_DIRECT_MAX_SSID_LEN + 1]; - char mac_address[6]; - char intf_mac_address[6]; + unsigned char ip_address[4]; + unsigned char mac_address[6]; + unsigned char intf_mac_address[6]; unsigned int services; bool is_p2p; unsigned short category; + int channel; } wfd_connected_peer_info_s; @@ -194,7 +207,7 @@ typedef struct int timeout; int peer_index; - char mac_addr[6]; + unsigned char mac_addr[6]; } wifi_direct_client_request_data_s; diff --git a/include/wifi-direct.h b/include/wifi-direct.h index 869472c..ceaae16 100644 --- a/include/wifi-direct.h +++ b/include/wifi-direct.h @@ -47,7 +47,7 @@ typedef enum 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_NOT_INITIALIZED = -0x00008000|0x0201, /**< Not initialized */ WIFI_DIRECT_ERROR_COMMUNICATION_FAILED = -0x00008000|0x0202, /**< I/O error */ WIFI_DIRECT_ERROR_WIFI_USED = -0x00008000|0x0203, /**< WiFi is being used */ WIFI_DIRECT_ERROR_MOBILE_AP_USED = -0x00008000|0x0204, /**< Mobile AP is being used */ @@ -197,14 +197,14 @@ typedef enum /** - * 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; +* @brief Enumeration for Wi-Fi WPS type +*/ +typedef enum { + WIFI_DIRECT_WPS_TYPE_NONE = 0x00, /**< No WPS type */ + WIFI_DIRECT_WPS_TYPE_PBC = 0x01, /**< Push Button Configuration */ + WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY = 0x02, /**< Display PIN code */ + WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD = 0x04, /**< Provide the keypad to input the PIN */ +} wifi_direct_wps_type_e; /** * @struct wifi_direct_config_data_s @@ -221,7 +221,7 @@ typedef struct int channel; /** WPS configuration parameters. */ - wifi_direct_wps_cfg_e wps_config; + wifi_direct_wps_type_e wps_config; /** Max number of STAs allowed associations */ int max_clients; @@ -255,8 +255,10 @@ typedef struct 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_primary_device_type_e primary_device_type; /** Primary category of device */ + wifi_direct_secondary_device_type_e secondary_device_type; /** Sub category of device */ + int supported_wps_types; /** The list of supported WPS type. \n + The OR operation on #wifi_direct_wps_type_e can be used like #WIFI_DIRECT_WPS_TYPE_PBC | #WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY */ } wifi_direct_discovered_peer_info_s; @@ -266,11 +268,13 @@ typedef struct */ typedef struct { - char* ssid; /** Null-terminated device friendly name. */ + char* ssid; /** Device friendly name. */ + char* ip_address; /**< The IP address */ char* mac_address; /** Device's P2P Device Address */ char* interface_address; /** Device's P2P Interface Address */ bool p2p_supported; /* whether peer is a P2P device */ wifi_direct_primary_device_type_e primary_device_type; /* primary category of device */ + int channel; /* Operating channel */ } wifi_direct_connected_peer_info_s; /** @@ -339,6 +343,23 @@ typedef void (*wifi_direct_connection_state_changed_cb) (int error_code, void *user_data); + +/** +* @brief Called when IP address of client is assigned when your device is group owner. +* @param[in] mac_address The MAC address of connection peer +* @param[in] ip_address The IP address of connection peer +* @param[in] interface_address The interface address of connection peer +* @param[in] user_data The user data passed from the callback registration function +* @see wifi_direct_set_client_ip_address_assigned_cb() +* @see wifi_direct_unset_client_ip_address_assigned_cb() +*/ +typedef void (*wifi_direct_client_ip_address_assigned_cb) (const char* mac_address, + const char* ip_address, + const char* interface_address, + void *user_data); + + + /*============================================================================= Wifi Direct Client APIs =============================================================================*/ @@ -735,6 +756,36 @@ int wifi_direct_set_connection_state_changed_cb(wifi_direct_connection_state_cha int wifi_direct_unset_connection_state_changed_cb(void); +/** +* @brief Registers the callback called when IP address of client is assigned when your device is group owner. +* @param[in] cb The callback function to invoke +* @param[in] user_data The user data to be passed to the callback function +* @return 0 on success, otherwise a negative error value. +* @retval #WIFI_DIRECT_ERROR_NONE Successful +* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized +* @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize(). +* @see wifi_direct_initialize() +* @see wifi_direct_unset_client_ip_address_assigned_cb() +* @see wifi_direct_client_ip_address_assigned_cb() +*/ +int wifi_direct_set_client_ip_address_assigned_cb(wifi_direct_client_ip_address_assigned_cb cb, void* user_data); + + +/** +* @brief Unregisters the callback called when IP address of client is assigned when your device is group owner. +* @return 0 on success, otherwise a negative error value. +* @retval #WIFI_DIRECT_ERROR_NONE Successful +* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized +* @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize(). +* @see wifi_direct_initialize() +* @see wifi_direct_set_connection_state_changed_cb() +*/ +int wifi_direct_unset_client_ip_address_assigned_cb(void); + + + + /*****************************************************************************************/ /* wifi_direct_activate API function prototype * int wifi_direct_activate(void); @@ -1670,6 +1721,25 @@ int wifi_direct_set_ssid(const char *ssid); int wifi_direct_get_ssid(char **ssid); +/** +* @brief Gets the name of network interface. For example, eth0 and pdp0. +* @remarks @a name must be released with free() by you. +* @param[out] name The name of network interface +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_DIRECT_ERROR_NONE Successful +* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed +* @retval #WIFI_DIRECT_ERROR_OUT_OF_MEMORY Out of memory +* @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed +* @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted +* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized +* @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy +* @pre Wi-Fi Direct service must be activated by wifi_direct_activate(). +* @see wifi_direct_activate() +*/ +int wifi_direct_get_network_interface_name(char** name); + + /*****************************************************************************************/ /* wifi_direct_get_ip_address API function prototype * int wifi_direct_get_ip_address(char** ip_address) @@ -1721,6 +1791,44 @@ int wifi_direct_get_ssid(char **ssid); ******************************************************************************/ int wifi_direct_get_ip_address(char **ip_address); +/** +* @brief Gets the Subnet Mask. +* @remarks @a subnet_mask must be released with free() by you. +* @param[out] subnet_mask The subnet mask +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_DIRECT_ERROR_NONE Successful +* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed +* @retval #WIFI_DIRECT_ERROR_OUT_OF_MEMORY Out of memory +* @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed +* @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted +* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized +* @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy +* @pre Wi-Fi Direct service must be activated by wifi_direct_activate(). +* @see wifi_direct_activate() +*/ +int wifi_direct_get_subnet_mask(char** subnet_mask); + + +/** +* @brief Gets the Gateway address. +* @remarks @a gateway_address must be released with free() by you. +* @param[out] gateway_address The gateway address +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_DIRECT_ERROR_NONE Successful +* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed +* @retval #WIFI_DIRECT_ERROR_OUT_OF_MEMORY Out of memory +* @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed +* @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted +* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized +* @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy +* @pre Wi-Fi Direct service must be activated by wifi_direct_activate(). +* @see wifi_direct_activate() +*/ +int wifi_direct_get_gateway_address(char** gateway_address); + + /*****************************************************************************************/ /* wifi_direct_get_mac_addr API function prototype @@ -1824,6 +1932,42 @@ int wifi_direct_get_mac_address(char **mac_address); int wifi_direct_get_state(wifi_direct_state_e * state); + +/** +* @brief Checks whether this device is discoverable or not. +* @param[out] discoverable Indicats whether this device is discoverable or not +* @return 0 on success, otherwise a negative error value. +* @retval #WIFI_DIRECT_ERROR_NONE Successful +* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed +* @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed +* @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted +* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized +* @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy +* @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize(). +* @see wifi_direct_initialize() +*/ +int wifi_direct_is_discoverable(bool* discoverable); + + +/** +* @brief Gets the primary device type of local device. +* @param[out] type The primary device type +* @return 0 on success, otherwise a negative error value. +* @retval #WIFI_DIRECT_ERROR_NONE Successful +* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed +* @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed +* @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted +* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized +* @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy +* @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize(). +* @see wifi_direct_initialize() +*/ +int wifi_direct_get_primary_device_type(wifi_direct_primary_device_type_e* type); + + + /*****************************************************************************************/ /* wifi_direct_accept_connection API function prototype * int wifi_direct_accept_connection(char* mac_address); @@ -1885,55 +2029,6 @@ int wifi_direct_get_state(wifi_direct_state_e * state); 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 - * - * 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 @@ -1998,7 +2093,7 @@ int wifi_direct_set_wpa_passphrase(char *passphrase); * \pre Device must support the pbc button mode. * - * \see wifi_direct_get_supported_wps_mode + * \see wifi_direct_foreach_supported_wps_types * * \par Sync (or) Async: * This is a Synchronous API. @@ -2212,7 +2307,7 @@ int wifi_direct_generate_wps_pin(void); * * @param wps_mode Memory to store supported wps mode. Application must allocate memory. * - * \see wifi_direct_wps_cfg_e + * \see wifi_direct_wps_type_e * * \par Sync (or) Async: * This is a Synchronous API. @@ -2256,6 +2351,98 @@ int wifi_direct_generate_wps_pin(void); int wifi_direct_get_supported_wps_mode(int *wps_mode); +/** +* @brief Called when you get the supported WPS(Wi-Fi Protected Setup) type repeatedly. +* @param[in] type The type of WPS +* @param[in] user_data The user data passed from the request function +* @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop +* @pre wifi_direct_foreach_supported_wps_types() will invoke this callback. +* @see wifi_direct_foreach_supported_wps_types() +*/ +typedef bool(*wifi_direct_supported_wps_type_cb)(wifi_direct_wps_type_e type, void* user_data); + +/** +* @brief Gets the supported WPS(Wi-Fi Protected Setup) types. +* @param[in] callback The callback function to invoke +* @param[in] user_data The user data to be passed to the callback function +* @retval #WIFI_DIRECT_ERROR_NONE Successful +* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter +* @see wifi_direct_supported_wps_type_cb() +*/ +int wifi_direct_foreach_supported_wps_types(wifi_direct_supported_wps_type_cb callback, void* user_data); + +/** + * @brief Sets the WPS(Wi-Fi Protected Setup) type. + * @param[in] type The type of WPS + * @retval #WIFI_DIRECT_ERROR_NONE Successful + * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter + * @see wifi_direct_foreach_supported_wps_types() + */ +int wifi_direct_set_wps_type(wifi_direct_wps_type_e type); +/** + * @brief Gets the WPS(Wi-Fi Protected Setup) type. + * @param[out] type The type of WPS + * @retval #WIFI_DIRECT_ERROR_NONE Successful + * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter + * @see wifi_direct_foreach_supported_wps_types() + */ +int wifi_direct_get_wps_type(wifi_direct_wps_type_e* type); + +/** +* @brief Sets the intent of a group owner. +* @remakrs The range of intent is 0 ~ 15. +* @param[in] intent The intent of a group owner +* @retval #WIFI_DIRECT_ERROR_NONE Successful +* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter +* @see wifi_direct_get_group_owner_intent() +*/ +int wifi_direct_set_group_owner_intent(int intent); + +/** +* @brief Gets the intent of a group owner. +* @param[out] intent The intent of a group owner +* @retval #WIFI_DIRECT_ERROR_NONE Successful +* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter +* @see wifi_direct_set_group_owner_intent() +*/ +int wifi_direct_get_group_owner_intent(int* intent); + +/** +* @brief Sets the max number of clients. +* @param[in] max The max number of clients +* @retval #WIFI_DIRECT_ERROR_NONE Successful +* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter +* @see wifi_direct_get_max_clients() +*/ +int wifi_direct_set_max_clients(int max); + +/** +* @brief Gets the max number of clients. +* @param[in] max The max number of clients +* @retval #WIFI_DIRECT_ERROR_NONE Successful +* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter +* @see wifi_direct_set_max_clients() +*/ +int wifi_direct_get_max_clients(int* max); + + +/** +* @brief Gets the channel of own group. +* @param[out] channel The channel of own group +* @return 0 on success, otherwise a negative error value. +* @retval #WIFI_DIRECT_ERROR_NONE Successful +* @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed +* @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed +* @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted +* @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized +* @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy +* @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize(). +* @see wifi_direct_initialize() +*/ +int wifi_direct_get_own_group_channel(int* channel); + + /*****************************************************************************************/ /* wifi_direct_get_config_data API function prototype * int wifi_direct_get_config_data(wifi_direct_config_data_s** config) @@ -2356,7 +2543,7 @@ int wifi_direct_get_config_data(wifi_direct_config_data_s ** config); * * // Change params * config->group_owner_intent = 8; -* config->wps_config = WIFI_DIRECT_WPS_PUSHBUTTON; +* config->wps_config = WIFI_DIRECT_WPS_TYPE_PBC; * config->want_persistent_group = false; * config->hide_SSID = false; * strncpy(config->ssid, "My WiFi Direct", WIFI_DIRECT_MAX_SSID_LEN); @@ -2376,6 +2563,16 @@ int wifi_direct_set_config_data(wifi_direct_config_data_s * config); /** + * @brief Sets the Autoconnection mode. + * @param[in] + * @retval #WIFI_DIRECT_ERROR_NONE Successful + * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter + * @see wifi_direct_foreach_supported_wps_types() + */ +int wifi_direct_set_autoconnection_mode(bool mode); + + +/** * @} */ diff --git a/packaging/libwifi-direct.spec b/packaging/libwifi-direct.spec index 41451f7..aca9dca 100755 --- a/packaging/libwifi-direct.spec +++ b/packaging/libwifi-direct.spec @@ -1,6 +1,6 @@ Name: libwifi-direct Summary: wifi direct library (Shared Library) -Version: 0.1.0 +Version: 0.2.8 Release: 1 Group: TO_BE_FILLED License: Apache-2.0 @@ -12,7 +12,7 @@ BuildRequires: pkgconfig(vconf) BuildRequires: cmake BuildRequires: gettext-devel -%define debug_package %{nil} +#%define debug_package %{nil} %description wifi direct library (Shared Library) @@ -36,13 +36,13 @@ export ARCH=i586 %endif %build - cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -make %{?jobs:-j%jobs} +#make %{?jobs:-j%jobs} %install rm -rf %{buildroot} %make_install +%__strip %{buildroot}%{_libdir}/libwifi-direct.so.0.0 %post @@ -59,4 +59,5 @@ rm -rf %{buildroot} %defattr(-,root,root,-) %{_libdir}/pkgconfig/wifi-direct.pc %{_includedir}/wifi-direct/wifi-direct.h +%{_includedir}/wifi-direct/wifi-direct-internal.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 98fd2e1..78d76ab 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -107,5 +107,6 @@ CONFIGURE_FILE(wifi-direct.pc.in wifi-direct.pc @ONLY) # Install INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib COMPONENT Runtime) INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/wifi-direct.h DESTINATION include/wifi-direct) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/wifi-direct-internal.h DESTINATION include/wifi-direct) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/wifi-direct.pc DESTINATION lib/pkgconfig) diff --git a/src/include/wifi-direct-client-proxy.h b/src/include/wifi-direct-client-proxy.h index 4c3eb02..8f8a549 100644 --- a/src/include/wifi-direct-client-proxy.h +++ b/src/include/wifi-direct-client-proxy.h @@ -77,9 +77,11 @@ typedef struct wifi_direct_device_state_changed_cb activation_cb; wifi_direct_discovery_state_chagned_cb discover_cb; wifi_direct_connection_state_changed_cb connection_cb; + wifi_direct_client_ip_address_assigned_cb ip_assigned_cb; void *user_data_for_cb_activation; void *user_data_for_cb_discover; void *user_data_for_cb_connection; + void *user_data_for_cb_ip_assigned; } wifi_direct_client_info_s; diff --git a/src/wifi-direct-client-proxy.c b/src/wifi-direct-client-proxy.c index a561058..b5d8de0 100644 --- a/src/wifi-direct-client-proxy.c +++ b/src/wifi-direct-client-proxy.c @@ -24,6 +24,7 @@ /***************************************************************************** * Standard headers *****************************************************************************/ +#define _GNU_SOURCE #include #include #include @@ -119,7 +120,7 @@ static int macaddr_atoe(char *p, unsigned char mac[]) { int i = 0; - printf("MAC [%s]\n", p); + WFD_CLIENT_LOG(WFD_LOG_LOW, "macaddr_atoe : input MAC = [%s]\n", p); for (;;) { @@ -189,6 +190,9 @@ static char *__wfd_print_event(wfd_client_event_e event) case WIFI_DIRECT_CLI_EVENT_GROUP_DESTROY_RSP: return "WIFI_DIRECT_CLI_EVENT_GROUP_DESTROY_RSP"; break; + case WIFI_DIRECT_CLI_EVENT_IP_LEASED_IND: + return "WIFI_DIRECT_CLI_EVENT_IP_LEASED_IND"; + break; default: return "WIFI_DIRECT_CLI_EVENT_unknown"; @@ -210,8 +214,12 @@ static char *__wfd_print_error(wifi_direct_error_e error) 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_NOT_INITIALIZED: + return "WIFI_DIRECT_ERROR_NOT_INITIALIZED"; + case WIFI_DIRECT_ERROR_TOO_MANY_CLIENT: + return "WIFI_DIRECT_ERROR_TOO_MANY_CLIENT"; + case WIFI_DIRECT_ERROR_RESOURCE_BUSY: + return "WIFI_DIRECT_ERROR_RESOURCE_BUSY"; case WIFI_DIRECT_ERROR_NONE: return "WIFI_DIRECT_ERROR_NONE"; default: @@ -367,6 +375,28 @@ static gboolean __wfd_client_process_event(GIOChannel * source, WFD_CLIENT_LOG(WFD_LOG_ERROR, "connection_cb is NULL!!\n"); break; + // ToDo: Handling IP lease event... + case WIFI_DIRECT_CLI_EVENT_IP_LEASED_IND: + if (client->ip_assigned_cb != NULL) + { + char* ifname = NULL; + ifname = vconf_get_str(VCONFKEY_IFNAME); + + if (ifname == NULL) + WFD_CLIENT_LOG(WFD_LOG_LOW, "vconf (%s) value is NULL!!!\n", VCONFKEY_IFNAME); + else + WFD_CLIENT_LOG(WFD_LOG_LOW, "VCONFKEY_IFNAME(%s) : %s\n", VCONFKEY_IFNAME, ifname); + + client->ip_assigned_cb(param1, + param2, + ifname, + client->user_data_for_cb_ip_assigned); + + } + else + WFD_CLIENT_LOG(WFD_LOG_ERROR, "ip_assigned_cb is NULL!!\n"); + break; + default: break; } @@ -508,25 +538,25 @@ static int __wfd_client_read_socket(int sockfd, char *dataptr, int datalen) return -1; } - WFD_CLIENT_LOG(WFD_LOG_LOW, "@@@@@@@ len = %d @@@@@@@@@@@\n", datalen); + WFD_CLIENT_LOG(WFD_LOG_ERROR, "@@@@@@@ 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); + WFD_CLIENT_LOG(WFD_LOG_ERROR, "POLL ret = %d, \n", pollret); if (pollret > 0) { if (pollfd.revents == POLLIN) { - WFD_CLIENT_LOG(WFD_LOG_LOW, "POLLIN \n"); + WFD_CLIENT_LOG(WFD_LOG_ERROR, "POLLIN \n"); while (datalen) { errno = 0; retval = read(sockfd, (char *) dataptr, datalen); - WFD_CLIENT_LOG(WFD_LOG_LOW, "sockfd %d retval %d\n", sockfd, + WFD_CLIENT_LOG(WFD_LOG_ERROR, "sockfd %d retval %d\n", sockfd, retval); if (retval <= 0) { @@ -545,7 +575,7 @@ static int __wfd_client_read_socket(int sockfd, char *dataptr, int datalen) } else if (pollfd.revents & POLLHUP) { - WFD_CLIENT_LOG(WFD_LOG_LOW, "POLLHUP\n"); + WFD_CLIENT_LOG(WFD_LOG_ERROR, "POLLHUP\n"); __WFD_CLIENT_FUNC_END__; return 0; } @@ -630,6 +660,7 @@ void __wfd_client_print_entry_list(wfd_discovery_entry_s * list, int num) 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_LOW, "wps cfg method : %x\n", list[i].wps_cfg_methods); } WFD_CLIENT_LOG(WFD_LOG_ERROR, "------------------------------------------\n"); @@ -651,6 +682,8 @@ void __wfd_client_print_connected_peer_info(wfd_connected_peer_info_s * list, in 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_LOW, "channel : %d\n", list[i].channel); + WFD_CLIENT_LOG(WFD_LOG_LOW, "IP ["IPSTR"]\n", IP2STR(list[i].ip_address)); } WFD_CLIENT_LOG(WFD_LOG_ERROR, "------------------------------------------\n"); @@ -665,8 +698,8 @@ void __wfd_client_print_config_data(wfd_config_data_s * config) 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) + WIFI_DIRECT_WPS_TYPE_PBC) ? + "Pushbutton" : (config-> wps_config == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY) ? "Display" : "Keypad"); WFD_CLIENT_LOG(WFD_LOG_LOW, "Max client = [%d]\n", config->max_clients); @@ -968,7 +1001,7 @@ int wifi_direct_set_device_state_changed_cb(wifi_direct_device_state_changed_cb { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is not initialized.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_NOT_PERMITTED; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } client_info->activation_cb = cb; @@ -988,7 +1021,7 @@ int wifi_direct_unset_device_state_changed_cb(void) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is not initialized.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_NOT_PERMITTED; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } client_info->activation_cb = NULL; @@ -1017,7 +1050,7 @@ wifi_direct_set_discovery_state_changed_cb { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is not initialized.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_NOT_PERMITTED; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } client_info->discover_cb = cb; @@ -1037,7 +1070,7 @@ int wifi_direct_unset_discovery_state_changed_cb(void) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is not initialized.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_NOT_PERMITTED; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } client_info->discover_cb = NULL; @@ -1066,7 +1099,7 @@ wifi_direct_set_connection_state_changed_cb { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is not initialized.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_NOT_PERMITTED; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } client_info->connection_cb = cb; @@ -1086,7 +1119,7 @@ int wifi_direct_unset_connection_state_changed_cb(void) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is not initialized.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_NOT_PERMITTED; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } client_info->connection_cb = NULL; @@ -1096,6 +1129,52 @@ int wifi_direct_unset_connection_state_changed_cb(void) } +int wifi_direct_set_client_ip_address_assigned_cb(wifi_direct_client_ip_address_assigned_cb cb, void* user_data) +{ + wifi_direct_client_info_s *client_info = __wfd_get_control(); + + __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_INITIALIZED; + } + + client_info->ip_assigned_cb = cb; + client_info->user_data_for_cb_ip_assigned = user_data; + + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_unset_client_ip_address_assigned_cb(void) +{ + wifi_direct_client_info_s *client_info = __wfd_get_control(); + + __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_INITIALIZED; + } + + client_info->ip_assigned_cb = NULL; + client_info->user_data_for_cb_ip_assigned = NULL; + + return WIFI_DIRECT_ERROR_NONE; +} + + int wifi_direct_activate(void) { wifi_direct_client_info_s *client_info = __wfd_get_control(); @@ -1107,7 +1186,7 @@ int wifi_direct_activate(void) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } wifi_direct_client_request_s req; @@ -1191,7 +1270,7 @@ int wifi_direct_deactivate(void) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } wifi_direct_client_request_s req; @@ -1274,7 +1353,14 @@ int wifi_direct_start_discovery(bool listen_only, int timeout) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (timeout < 0) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "Nagative value. Param [timeout]!\n"); + __WFD_CLIENT_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; } wifi_direct_client_request_s req; @@ -1363,7 +1449,7 @@ int wifi_direct_cancel_discovery(void) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } wifi_direct_client_request_s req; @@ -1449,7 +1535,7 @@ int wifi_direct_foreach_discovered_peers(wifi_direct_discovered_peer_cb callback { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } if (callback == NULL) @@ -1565,6 +1651,7 @@ int wifi_direct_foreach_discovered_peers(wifi_direct_discovered_peer_cb callback peer_list->is_persistent_group_owner = buff[i].is_persistent_go; peer_list->interface_address = (char *) calloc(1, 18); snprintf(peer_list->interface_address, 18, MACSTR, MAC2STR(buff[i].intf_mac_address)); + peer_list->supported_wps_types= buff[i].wps_cfg_methods; peer_list->primary_device_type = buff[i].category; peer_list->secondary_device_type = buff[i].subcategory; @@ -1603,7 +1690,7 @@ int wifi_direct_connect(const char *mac_address) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } if (mac_address == NULL) @@ -1706,7 +1793,7 @@ int wifi_direct_disconnect_all(void) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } wifi_direct_client_request_s req; @@ -1800,7 +1887,7 @@ int wifi_direct_disconnect(const char *mac_address) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } wifi_direct_client_request_s req; @@ -1898,7 +1985,7 @@ int wifi_direct_accept_connection(char *mac_address) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } if (mac_address == NULL) @@ -2000,7 +2087,7 @@ int wifi_direct_foreach_connected_peers(wifi_direct_connected_peer_cb callback, { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } if (callback == NULL) @@ -2111,13 +2198,16 @@ int wifi_direct_foreach_connected_peers(wifi_direct_connected_peer_cb callback, { 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->ip_address= (char *) calloc(1, 16); + snprintf(peer_list->ip_address, 16, IPSTR, IP2STR(buff[i].ip_address)); peer_list->mac_address = (char *) calloc(1, 18); snprintf(peer_list->mac_address, 18, MACSTR, MAC2STR(buff[i].mac_address)); peer_list->interface_address = (char *) calloc(1, 18); snprintf(peer_list->interface_address, 18, MACSTR, MAC2STR(buff[i].intf_mac_address)); peer_list->p2p_supported = buff[i].is_p2p; peer_list->primary_device_type = buff[i].category; - + peer_list->channel = buff[i].channel; + if (!callback(peer_list, user_data)) break; } @@ -2152,7 +2242,7 @@ int wifi_direct_create_group(void) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } wifi_direct_client_request_s req; @@ -2238,7 +2328,7 @@ int wifi_direct_destroy_group(void) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } wifi_direct_client_request_s req; @@ -2331,7 +2421,7 @@ int wifi_direct_is_group_owner(bool * owner) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } wifi_direct_client_request_s req; @@ -2427,7 +2517,7 @@ int wifi_direct_is_autonomous_group(bool * autonomous_group) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } wifi_direct_client_request_s req; @@ -2505,95 +2595,7 @@ int wifi_direct_is_autonomous_group(bool * autonomous_group) } -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) +int wifi_direct_set_group_owner_intent(int intent) { wifi_direct_client_info_s *client_info = __wfd_get_control(); @@ -2604,18 +2606,16 @@ int wifi_direct_set_wpa_passphrase(char *passphrase) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } - if (NULL == passphrase) + if (intent < 0 || intent > 15) { - WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [passphrase]!\n"); + WFD_CLIENT_LOG(WFD_LOG_ERROR, "Invalid Param : intent[%d]\n", intent); __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; @@ -2624,11 +2624,10 @@ int wifi_direct_set_wpa_passphrase(char *passphrase) memset(&req, 0, sizeof(wifi_direct_client_request_s)); memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); - req.cmd = WIFI_DIRECT_CMD_SET_WPA; + req.cmd = WIFI_DIRECT_CMD_SET_GO_INTENT; req.client_id = client_info->client_id; - status = - __wfd_client_send_request(client_info->sync_sockfd, &req, + status =__wfd_client_send_request(client_info->sync_sockfd, &req, sizeof(wifi_direct_client_request_s)); if (status != WIFI_DIRECT_ERROR_NONE) { @@ -2646,7 +2645,8 @@ int wifi_direct_set_wpa_passphrase(char *passphrase) WFD_CLIENT_LOG(WFD_LOG_LOW, "writing msg hdr is success!\n"); status = - __wfd_client_send_request(client_info->sync_sockfd, passphrase, 64); + __wfd_client_send_request(client_info->sync_sockfd, &intent, + sizeof(int)); if (status != WIFI_DIRECT_ERROR_NONE) { WFD_CLIENT_LOG(WFD_LOG_ERROR, @@ -2674,13 +2674,13 @@ int wifi_direct_set_wpa_passphrase(char *passphrase) } else { - if (rsp.cmd == WIFI_DIRECT_CMD_SET_WPA) + if (rsp.cmd == WIFI_DIRECT_CMD_SET_GO_INTENT) { 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_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; @@ -2700,7 +2700,7 @@ int wifi_direct_set_wpa_passphrase(char *passphrase) } -int wifi_direct_activate_pushbutton(void) +int wifi_direct_get_group_owner_intent(int* intent) { wifi_direct_client_info_s *client_info = __wfd_get_control(); @@ -2711,7 +2711,7 @@ int wifi_direct_activate_pushbutton(void) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } wifi_direct_client_request_s req; @@ -2722,7 +2722,7 @@ int wifi_direct_activate_pushbutton(void) 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.cmd = WIFI_DIRECT_CMD_GET_GO_INTENT; req.client_id = client_info->client_id; status = @@ -2755,7 +2755,7 @@ int wifi_direct_activate_pushbutton(void) } else { - if (rsp.cmd == WIFI_DIRECT_CMD_ACTIVATE_PUSHBUTTON) + if (rsp.cmd == WIFI_DIRECT_CMD_GET_GO_INTENT) { if (rsp.result != WIFI_DIRECT_ERROR_NONE) { @@ -2769,7 +2769,9 @@ int wifi_direct_activate_pushbutton(void) else { WFD_CLIENT_LOG(WFD_LOG_LOW, - "wifi_direct_activate_pushbutton() SUCCESS \n"); + "int wifi_direct_get_group_owner_intent() intent[%d] SUCCESS \n", + rsp.param1); + *intent = rsp.param1; } } else @@ -2785,10 +2787,8 @@ int wifi_direct_activate_pushbutton(void) return WIFI_DIRECT_ERROR_NONE; } - -int wifi_direct_set_wps_pin(char *pin) +int wifi_direct_set_max_clients(int max) { - wifi_direct_client_info_s *client_info = __wfd_get_control(); __WFD_CLIENT_FUNC_START__; @@ -2798,16 +2798,10 @@ int wifi_direct_set_wps_pin(char *pin) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } - 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); + WFD_CLIENT_LOG(WFD_LOG_LOW, "max client [%d]\n", max); wifi_direct_client_request_s req; wifi_direct_client_response_s rsp; @@ -2817,11 +2811,10 @@ int wifi_direct_set_wps_pin(char *pin) memset(&req, 0, sizeof(wifi_direct_client_request_s)); memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); - req.cmd = WIFI_DIRECT_CMD_SET_WPS_PIN; + req.cmd = WIFI_DIRECT_CMD_SET_MAX_CLIENT; req.client_id = client_info->client_id; - status = - __wfd_client_send_request(client_info->sync_sockfd, &req, + status =__wfd_client_send_request(client_info->sync_sockfd, &req, sizeof(wifi_direct_client_request_s)); if (status != WIFI_DIRECT_ERROR_NONE) { @@ -2839,8 +2832,8 @@ int wifi_direct_set_wps_pin(char *pin) 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); + __wfd_client_send_request(client_info->sync_sockfd, &max, + sizeof(int)); if (status != WIFI_DIRECT_ERROR_NONE) { WFD_CLIENT_LOG(WFD_LOG_ERROR, @@ -2861,12 +2854,14 @@ int wifi_direct_set_wps_pin(char *pin) 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_WPS_PIN) + if (rsp.cmd == WIFI_DIRECT_CMD_SET_MAX_CLIENT) { if (rsp.result != WIFI_DIRECT_ERROR_NONE) { @@ -2891,8 +2886,7 @@ int wifi_direct_set_wps_pin(char *pin) return WIFI_DIRECT_ERROR_NONE; } - -int wifi_direct_get_wps_pin(char **pin) +int wifi_direct_get_max_clients(int* max) { wifi_direct_client_info_s *client_info = __wfd_get_control(); @@ -2903,19 +2897,18 @@ int wifi_direct_get_wps_pin(char **pin) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } wifi_direct_client_request_s req; wifi_direct_client_response_s rsp; - char la_pin[WIFI_DIRECT_WPS_PIN_LEN + 1] = { 0, }; int status = WIFI_DIRECT_ERROR_NONE; memset(&req, 0, sizeof(wifi_direct_client_request_s)); memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); - req.cmd = WIFI_DIRECT_CMD_GET_WPS_PIN; + req.cmd = WIFI_DIRECT_CMD_GET_MAX_CLIENT; req.client_id = client_info->client_id; status = @@ -2948,7 +2941,7 @@ int wifi_direct_get_wps_pin(char **pin) } else { - if (rsp.cmd == WIFI_DIRECT_CMD_GET_WPS_PIN) + if (rsp.cmd == WIFI_DIRECT_CMD_GET_MAX_CLIENT) { if (rsp.result != WIFI_DIRECT_ERROR_NONE) { @@ -2962,13 +2955,9 @@ int wifi_direct_get_wps_pin(char **pin) 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; + "int wifi_direct_get_max_clients() max_client[%d] SUCCESS \n", + rsp.param1); + *max = rsp.param1; } } else @@ -2984,8 +2973,7 @@ int wifi_direct_get_wps_pin(char **pin) return WIFI_DIRECT_ERROR_NONE; } - -int wifi_direct_generate_wps_pin(void) +int wifi_direct_get_own_group_channel(int* channel) { wifi_direct_client_info_s *client_info = __wfd_get_control(); @@ -2996,43 +2984,43 @@ int wifi_direct_generate_wps_pin(void) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } wifi_direct_client_request_s req; wifi_direct_client_response_s rsp; - int status = WIFI_DIRECT_ERROR_NONE; + 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_GENERATE_WPS_PIN; + req.cmd = WIFI_DIRECT_CMD_GET_OWN_GROUP_CHANNEL; req.client_id = client_info->client_id; - status = + ret = __wfd_client_send_request(client_info->sync_sockfd, &req, sizeof(wifi_direct_client_request_s)); - if (status != WIFI_DIRECT_ERROR_NONE) + 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(status)); + __wfd_print_error(ret)); client_info->sync_sockfd = -1; __wfd_reset_control(); __WFD_CLIENT_FUNC_END__; return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; } - if ((status = + 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", - status, strerror(errno)); + "Error!!! reading socket, status = %d errno = %s\n", ret, + strerror(errno)); client_info->sync_sockfd = -1; __wfd_reset_control(); __WFD_CLIENT_FUNC_END__; @@ -3040,7 +3028,7 @@ int wifi_direct_generate_wps_pin(void) } else { - if (rsp.cmd == WIFI_DIRECT_CMD_GENERATE_WPS_PIN) + if (rsp.cmd == WIFI_DIRECT_CMD_GET_OWN_GROUP_CHANNEL) { if (rsp.result != WIFI_DIRECT_ERROR_NONE) { @@ -3053,8 +3041,9 @@ int wifi_direct_generate_wps_pin(void) } else { - WFD_CLIENT_LOG(WFD_LOG_LOW, - "wifi_direct_generate_wps_pin() SUCCESS \n"); + WFD_CLIENT_LOG(WFD_LOG_LOW, "channel = [%d]\n", + (int) rsp.param1); + *channel = rsp.param1; } } else @@ -3068,10 +3057,10 @@ int wifi_direct_generate_wps_pin(void) __WFD_CLIENT_FUNC_END__; return WIFI_DIRECT_ERROR_NONE; -} +} -int wifi_direct_get_supported_wps_mode(int *wps_mode) +int wifi_direct_set_wpa_passphrase(char *passphrase) { wifi_direct_client_info_s *client_info = __wfd_get_control(); @@ -3082,67 +3071,87 @@ int wifi_direct_get_supported_wps_mode(int *wps_mode) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + 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 ret = WIFI_DIRECT_ERROR_NONE; + 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_SUPPORTED_WPS_MODE; + req.cmd = WIFI_DIRECT_CMD_SET_WPA; req.client_id = client_info->client_id; - ret = + status = __wfd_client_send_request(client_info->sync_sockfd, &req, sizeof(wifi_direct_client_request_s)); - if (ret != WIFI_DIRECT_ERROR_NONE) + 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(ret)); + __wfd_print_error(status)); 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_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!!! reading socket, status = %d errno = %s\n", ret, + "Error!!! writing to socket, Errno = %s\n", strerror(errno)); - client_info->sync_sockfd = -1; + 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_SUPPORTED_WPS_MODE) + if (rsp.cmd == WIFI_DIRECT_CMD_SET_WPA) { 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_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_LOW, "Supported wps config = [%d]\n", - (int) rsp.param1); - *wps_mode = rsp.param1; - } } else { @@ -3155,11 +3164,10 @@ int wifi_direct_get_supported_wps_mode(int *wps_mode) __WFD_CLIENT_FUNC_END__; return WIFI_DIRECT_ERROR_NONE; - } -int wifi_direct_set_ssid(const char *ssid) +int wifi_direct_activate_pushbutton(void) { wifi_direct_client_info_s *client_info = __wfd_get_control(); @@ -3170,18 +3178,9 @@ int wifi_direct_set_ssid(const char *ssid) { 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; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } - WFD_CLIENT_LOG(WFD_LOG_ERROR, "ssid = [%s]\n", ssid); - wifi_direct_client_request_s req; wifi_direct_client_response_s rsp; @@ -3190,7 +3189,7 @@ int wifi_direct_set_ssid(const char *ssid) 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.cmd = WIFI_DIRECT_CMD_ACTIVATE_PUSHBUTTON; req.client_id = client_info->client_id; status = @@ -3209,24 +3208,6 @@ int wifi_direct_set_ssid(const char *ssid) 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) @@ -3241,17 +3222,22 @@ int wifi_direct_set_ssid(const char *ssid) } else { - if (rsp.cmd == WIFI_DIRECT_CMD_SET_SSID) + if (rsp.cmd == WIFI_DIRECT_CMD_ACTIVATE_PUSHBUTTON) { 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_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 { @@ -3267,38 +3253,38 @@ int wifi_direct_set_ssid(const char *ssid) } - -int wifi_direct_get_ssid(char **ssid) +int wifi_direct_set_wps_pin(char *pin) { + wifi_direct_client_info_s *client_info = __wfd_get_control(); __WFD_CLIENT_FUNC_START__; - if (NULL == ssid) + if ((client_info->is_registered == false) + || (client_info->client_id == WFD_INVALID_ID)) { - WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [ssid]!\n"); + WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } - if ((client_info->is_registered == false) - || (client_info->client_id == WFD_INVALID_ID)) + if (NULL == pin) { - WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); + WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [pin]!\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + 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; - 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.cmd = WIFI_DIRECT_CMD_SET_WPS_PIN; req.client_id = client_info->client_id; status = @@ -3317,6 +3303,24 @@ int wifi_direct_get_ssid(char **ssid) 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) @@ -3324,14 +3328,12 @@ int wifi_direct_get_ssid(char **ssid) 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.cmd == WIFI_DIRECT_CMD_SET_WPS_PIN) { if (rsp.result != WIFI_DIRECT_ERROR_NONE) { @@ -3342,19 +3344,6 @@ int wifi_direct_get_ssid(char **ssid) __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 { @@ -3370,37 +3359,30 @@ int wifi_direct_get_ssid(char **ssid) } -int wifi_direct_get_ip_address(char **ip_address) +int wifi_direct_get_wps_pin(char **pin) { 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; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } wifi_direct_client_request_s req; wifi_direct_client_response_s rsp; - char la_ip[64] = { 0, }; + 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_IP_ADDR; + req.cmd = WIFI_DIRECT_CMD_GET_WPS_PIN; req.client_id = client_info->client_id; status = @@ -3433,7 +3415,7 @@ int wifi_direct_get_ip_address(char **ip_address) } else { - if (rsp.cmd == WIFI_DIRECT_CMD_GET_IP_ADDR) + if (rsp.cmd == WIFI_DIRECT_CMD_GET_WPS_PIN) { if (rsp.result != WIFI_DIRECT_ERROR_NONE) { @@ -3447,13 +3429,13 @@ int wifi_direct_get_ip_address(char **ip_address) else { WFD_CLIENT_LOG(WFD_LOG_LOW, - "wifi_direct_get_ip_address() SUCCESS \n"); - strncpy(la_ip, rsp.param2, strlen(rsp.param2)); + "wifi_direct_get_wps_pin() SUCCESS \n"); + strncpy(la_pin, rsp.param2, WIFI_DIRECT_WPS_PIN_LEN); - char *temp_ip; - temp_ip = strdup(la_ip); + char *temp_pin; + temp_pin = strdup(la_pin); - *ip_address = temp_ip; + *pin = temp_pin; } } else @@ -3470,37 +3452,29 @@ int wifi_direct_get_ip_address(char **ip_address) } -int wifi_direct_get_mac_address(char **mac_address) +int wifi_direct_generate_wps_pin(void) { 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_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } 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.cmd = WIFI_DIRECT_CMD_GENERATE_WPS_PIN; req.client_id = client_info->client_id; status = @@ -3508,11 +3482,13 @@ int wifi_direct_get_mac_address(char **mac_address) 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", + WFD_CLIENT_LOG(WFD_LOG_ERROR, + "Error!!! writing to socket, Errno = %s\n", strerror(errno)); - WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n", + WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n", __wfd_print_error(status)); - close(client_info->sync_sockfd); + client_info->sync_sockfd = -1; + __wfd_reset_control(); __WFD_CLIENT_FUNC_END__; return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; } @@ -3521,15 +3497,17 @@ int wifi_direct_get_mac_address(char **mac_address) __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp, sizeof(wifi_direct_client_response_s))) <= 0) { - WFD_CLIENT_LOG(WFD_LOG_LOW, + 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_DEVICE_MAC) + if (rsp.cmd == WIFI_DIRECT_CMD_GENERATE_WPS_PIN) { if (rsp.result != WIFI_DIRECT_ERROR_NONE) { @@ -3543,17 +3521,7 @@ int wifi_direct_get_mac_address(char **mac_address) 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; - + "wifi_direct_generate_wps_pin() SUCCESS \n"); } } else @@ -3570,25 +3538,18 @@ int wifi_direct_get_mac_address(char **mac_address) } -int wifi_direct_get_state(wifi_direct_state_e * state) +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 (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; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } wifi_direct_client_request_s req; @@ -3599,7 +3560,7 @@ int wifi_direct_get_state(wifi_direct_state_e * state) 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.cmd = WIFI_DIRECT_CMD_GET_SUPPORTED_WPS_MODE; req.client_id = client_info->client_id; ret = @@ -3632,21 +3593,22 @@ int wifi_direct_get_state(wifi_direct_state_e * state) } else { - if (rsp.cmd == WIFI_DIRECT_CMD_GET_LINK_STATUS) + 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 %s\n", rsp.result, + 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, "Link Status = %d \n", + WFD_CLIENT_LOG(WFD_LOG_LOW, "Supported wps config = [%d]\n", (int) rsp.param1); - *state = (wifi_direct_state_e) rsp.param1; + *wps_mode = rsp.param1; } } else @@ -3660,10 +3622,11 @@ int wifi_direct_get_state(wifi_direct_state_e * state) __WFD_CLIENT_FUNC_END__; return WIFI_DIRECT_ERROR_NONE; + } -int wifi_direct_get_config_data(wifi_direct_config_data_s ** config) +int wifi_direct_foreach_supported_wps_types(wifi_direct_supported_wps_type_cb callback, void* user_data) { wifi_direct_client_info_s *client_info = __wfd_get_control(); @@ -3674,51 +3637,50 @@ int wifi_direct_get_config_data(wifi_direct_config_data_s ** config) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } - if (config == NULL) + if (callback == NULL) { - WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [config]!\n"); + 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; - wfd_config_data_s ls_config; - int status = WIFI_DIRECT_ERROR_NONE; + 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_CONFIG; + req.cmd = WIFI_DIRECT_CMD_GET_SUPPORTED_WPS_MODE; req.client_id = client_info->client_id; - status = + ret = __wfd_client_send_request(client_info->sync_sockfd, &req, sizeof(wifi_direct_client_request_s)); - if (status != WIFI_DIRECT_ERROR_NONE) + 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(status)); + __wfd_print_error(ret)); client_info->sync_sockfd = -1; __wfd_reset_control(); __WFD_CLIENT_FUNC_END__; return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; } - if ((status = + 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", - status, strerror(errno)); + "Error!!! reading socket, status = %d errno = %s\n", ret, + strerror(errno)); client_info->sync_sockfd = -1; __wfd_reset_control(); __WFD_CLIENT_FUNC_END__; @@ -3726,30 +3688,1304 @@ int wifi_direct_get_config_data(wifi_direct_config_data_s ** config) } else { - if (rsp.cmd == WIFI_DIRECT_CMD_GET_CONFIG) + if (rsp.cmd == WIFI_DIRECT_CMD_GET_SUPPORTED_WPS_MODE) { 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_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 { - int status = 0; - - WFD_CLIENT_LOG(WFD_LOG_LOW, "Link status = %d \n", + WFD_CLIENT_LOG(WFD_LOG_LOW, "Supported wps config = [%d]\n", (int) rsp.param1); + int wps_mode; + bool result; + + wps_mode = 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) - { + if (wps_mode & WIFI_DIRECT_WPS_TYPE_PBC) + result = callback(WIFI_DIRECT_WPS_TYPE_PBC, user_data); + + if ((result == true) && (wps_mode & WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY)) + result = callback(WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY, user_data); + + + if ((result == true) && (wps_mode & WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD)) + result = callback(WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD, user_data); + } + } + else + { + 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_type(wifi_direct_wps_type_e type) +{ + 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_NOT_INITIALIZED; + } + + if (type == WIFI_DIRECT_WPS_TYPE_PBC + || type == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY + || type == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) + { + WFD_CLIENT_LOG(WFD_LOG_LOW, "Param wps_mode [%d]\n", type); + } + else + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "Invalid Param [wps_mode]!\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_SET_CURRENT_WPS_MODE; + req.client_id = client_info->client_id; + + status =__wfd_client_send_request(client_info->sync_sockfd, &req, + sizeof(wifi_direct_client_request_s)); + if (status != WIFI_DIRECT_ERROR_NONE) + { + 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, &type, + sizeof(wifi_direct_wps_type_e)); + 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_CURRENT_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_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_type(wifi_direct_wps_type_e* type) +{ + 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_NOT_INITIALIZED; + } + + if (type == NULL) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [type]!\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); + + *type = ls_config.wps_config; + + WFD_CLIENT_LOG(WFD_LOG_LOW, "wifi_direct_get_wps_type() 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_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_NOT_INITIALIZED; + } + + 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_NOT_INITIALIZED; + } + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + char la_ssid[WIFI_DIRECT_MAX_SSID_LEN + 1] = { 0, }; + + int status = WIFI_DIRECT_ERROR_NONE; + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_SSID; + req.client_id = client_info->client_id; + + status = + __wfd_client_send_request(client_info->sync_sockfd, &req, + sizeof(wifi_direct_client_request_s)); + if (status != WIFI_DIRECT_ERROR_NONE) + { + 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 = NULL; + temp_ssid = strdup(la_ssid); + if (NULL == temp_ssid) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "Failed to allocate memory for SSID\n"); + return WIFI_DIRECT_ERROR_OUT_OF_MEMORY; + } + + *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_network_interface_name(char** name) +{ + wifi_direct_client_info_s *client_info = __wfd_get_control(); + + __WFD_CLIENT_FUNC_START__; + + if (NULL == name) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [name]!\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_NOT_INITIALIZED; + } + + wifi_direct_state_e status = 0; + int result; + result = wifi_direct_get_state(&status); + WFD_CLIENT_LOG(WFD_LOG_LOW, "wifi_direct_get_state() state=[%d], result=[%d]\n", status, result); + + if( status < WIFI_DIRECT_STATE_CONNECTED) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "Device is not connected!\n"); + __WFD_CLIENT_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_PERMITTED; + } + + char* get_str = NULL; + get_str = vconf_get_str(VCONFKEY_IFNAME); + + if (get_str == NULL) + { + WFD_CLIENT_LOG(WFD_LOG_LOW, "vconf (%s) value is NULL!!!\n", VCONFKEY_IFNAME); + __WFD_CLIENT_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_PERMITTED; + } + else + { + WFD_CLIENT_LOG(WFD_LOG_LOW, "VCONFKEY_IFNAME(%s) : %s\n", VCONFKEY_IFNAME, get_str); + + char *temp_ifname = NULL; + temp_ifname = strdup(get_str); + if (NULL == temp_ifname) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "Failed to allocate memory for ifname.\n"); + return WIFI_DIRECT_ERROR_OUT_OF_MEMORY; + } + + *name = temp_ifname; + } + + __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_NOT_INITIALIZED; + } + + wifi_direct_state_e state = 0; + int result; + result = wifi_direct_get_state(&state); + WFD_CLIENT_LOG(WFD_LOG_LOW, "wifi_direct_get_state() state=[%d], result=[%d]\n", state, result); + + if( state < WIFI_DIRECT_STATE_CONNECTED) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "Device is not connected!\n"); + __WFD_CLIENT_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_PERMITTED; + } + + char* get_str = NULL; + get_str = vconf_get_str(VCONFKEY_LOCAL_IP); + + if (get_str == NULL) + { + WFD_CLIENT_LOG(WFD_LOG_LOW, "vconf (%s) value is NULL!!!\n", VCONFKEY_LOCAL_IP); + __WFD_CLIENT_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_PERMITTED; + } + else + { + WFD_CLIENT_LOG(WFD_LOG_LOW, "VCONFKEY_LOCAL_IP(%s) : %s\n", VCONFKEY_LOCAL_IP, get_str); + + char *temp_ip = NULL; + temp_ip = strdup(get_str); + if (NULL == temp_ip) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "Failed to allocate memory for local ip address.\n"); + return WIFI_DIRECT_ERROR_OUT_OF_MEMORY; + } + + *ip_address = temp_ip; + } + + +#if 0 + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + char la_ip[64] = { 0, }; + + int status = WIFI_DIRECT_ERROR_NONE; + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_IP_ADDR; + req.client_id = client_info->client_id; + + status = + __wfd_client_send_request(client_info->sync_sockfd, &req, + sizeof(wifi_direct_client_request_s)); + if (status != WIFI_DIRECT_ERROR_NONE) + { + 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 = NULL; + temp_ip = strdup(la_ip); + if (NULL == temp_ip) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "Failed to allocate memory for IP address\n"); + return WIFI_DIRECT_ERROR_OUT_OF_MEMORY; + } + + *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; + } + } +#endif + + __WFD_CLIENT_FUNC_END__; + + return WIFI_DIRECT_ERROR_NONE; +} + + +int wifi_direct_get_subnet_mask(char** subnet_mask) +{ + wifi_direct_client_info_s *client_info = __wfd_get_control(); + + __WFD_CLIENT_FUNC_START__; + + if (NULL == subnet_mask) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [subnet_mask]!\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_NOT_INITIALIZED; + } + + wifi_direct_state_e status = 0; + int result; + result = wifi_direct_get_state(&status); + WFD_CLIENT_LOG(WFD_LOG_LOW, "wifi_direct_get_state() state=[%d], result=[%d]\n", status, result); + + if( status < WIFI_DIRECT_STATE_CONNECTED) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "Device is not connected!\n"); + __WFD_CLIENT_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_PERMITTED; + } + + + char* get_str = NULL; + get_str = vconf_get_str(VCONFKEY_SUBNET_MASK); + + if (get_str == NULL) + { + WFD_CLIENT_LOG(WFD_LOG_LOW, "vconf (%s) value is NULL!!!\n", VCONFKEY_SUBNET_MASK); + __WFD_CLIENT_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_PERMITTED; + } + else + { + WFD_CLIENT_LOG(WFD_LOG_LOW, "VCONFKEY_SUBNET_MASK(%s) : %s\n", VCONFKEY_SUBNET_MASK, get_str); + + char *temp_subnetmask = NULL; + temp_subnetmask = strdup(get_str); + if (NULL == temp_subnetmask) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "Failed to allocate memory for subnet mask.\n"); + return WIFI_DIRECT_ERROR_OUT_OF_MEMORY; + } + + *subnet_mask = temp_subnetmask; + } + + __WFD_CLIENT_FUNC_END__; + + return WIFI_DIRECT_ERROR_NONE; +} + + +int wifi_direct_get_gateway_address(char** gateway_address) +{ + wifi_direct_client_info_s *client_info = __wfd_get_control(); + + __WFD_CLIENT_FUNC_START__; + + if (NULL == gateway_address) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [gateway_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_NOT_INITIALIZED; + } + + wifi_direct_state_e status = 0; + int result; + result = wifi_direct_get_state(&status); + WFD_CLIENT_LOG(WFD_LOG_LOW, "wifi_direct_get_state() state=[%d], result=[%d]\n", status, result); + + if( status < WIFI_DIRECT_STATE_CONNECTED) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "Device is not connected!\n"); + __WFD_CLIENT_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_PERMITTED; + } + + char* get_str = NULL; + get_str = vconf_get_str(VCONFKEY_GATEWAY); + + if (get_str == NULL) + { + WFD_CLIENT_LOG(WFD_LOG_LOW, "vconf (%s) value is NULL!!!\n", VCONFKEY_GATEWAY); + __WFD_CLIENT_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_PERMITTED; + } + else + { + WFD_CLIENT_LOG(WFD_LOG_LOW, "VCONFKEY_GATEWAY(%s) : %s\n", VCONFKEY_GATEWAY, get_str); + + char *temp_gateway = NULL; + temp_gateway = strdup(get_str); + if (NULL == temp_gateway) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "Failed to allocate memory for gateway address.\n"); + return WIFI_DIRECT_ERROR_OUT_OF_MEMORY; + } + + *gateway_address = temp_gateway; + } + + __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_NOT_INITIALIZED; + } + +#if 0 + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + unsigned char la_mac_addr[6] = { 0, }; + + int status = WIFI_DIRECT_ERROR_NONE; + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_DEVICE_MAC; + req.client_id = client_info->client_id; + + status = + __wfd_client_send_request(client_info->sync_sockfd, &req, + sizeof(wifi_direct_client_request_s)); + if (status != WIFI_DIRECT_ERROR_NONE) + { + 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); + if (NULL == temp_mac) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "Failed to allocate memory for MAC address\n"); + return WIFI_DIRECT_ERROR_OUT_OF_MEMORY; + } + + 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; + } + } + +#else + int fd; + int n; + char mac_info[18]; + unsigned char la_mac_addr[6]; + + memset(mac_info, 0, sizeof(mac_info)); + + if( (fd = open(WIFI_DIRECT_MAC_ADDRESS_INFO_FILE, O_RDONLY)) == -1) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "[.mac.info] file open failed.\n"); + __WFD_CLIENT_FUNC_END__; + return WIFI_DIRECT_ERROR_OPERATION_FAILED; + } + + n = read(fd, mac_info, 18); + if(n < 0) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "[.mac.info] file read failed.\n"); + __WFD_CLIENT_FUNC_END__; + return WIFI_DIRECT_ERROR_OPERATION_FAILED; + } + + WFD_CLIENT_LOG(WFD_LOG_LOW, "mac_address = [%s]\n", mac_info); + + memset(la_mac_addr, 0, sizeof(la_mac_addr)); + macaddr_atoe(mac_info, la_mac_addr); + la_mac_addr[0] = la_mac_addr[0] | 0x02; + la_mac_addr[1] = la_mac_addr[1]; + la_mac_addr[2] = la_mac_addr[2]; + la_mac_addr[3] = la_mac_addr[3]; + la_mac_addr[4] = la_mac_addr[4]; + la_mac_addr[5] = la_mac_addr[5]; + + char *temp_mac = NULL; + temp_mac = (char *) calloc(1, 18); + if (NULL == temp_mac) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "Failed to allocate memory for MAC address\n"); + return WIFI_DIRECT_ERROR_OUT_OF_MEMORY; + } + + //strncpy(temp_mac, mac_info, strlen(mac_info)); + snprintf(temp_mac, 18, MACSTR, MAC2STR(la_mac_addr)); + + *mac_address = temp_mac; + +#endif + + __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_NOT_INITIALIZED; + } + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + + int ret = WIFI_DIRECT_ERROR_NONE; + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_LINK_STATUS; + req.client_id = client_info->client_id; + + ret = + __wfd_client_send_request(client_info->sync_sockfd, &req, + sizeof(wifi_direct_client_request_s)); + if (ret != WIFI_DIRECT_ERROR_NONE) + { + 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; + + /* for CAPI : there is no WIFI_DIRECT_STATE_GROUP_OWNER type in CAPI */ + if(*state == WIFI_DIRECT_STATE_GROUP_OWNER) + *state = WIFI_DIRECT_STATE_CONNECTED; + + } + } + else + { + 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_discoverable(bool* discoverable) +{ +{ + wifi_direct_client_info_s *client_info = __wfd_get_control(); + + __WFD_CLIENT_FUNC_START__; + + if (discoverable == NULL) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [discoverable]!\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_NOT_INITIALIZED; + } + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + + int status = WIFI_DIRECT_ERROR_NONE; + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_IS_DISCOVERABLE; + req.client_id = client_info->client_id; + + status = + __wfd_client_send_request(client_info->sync_sockfd, &req, + sizeof(wifi_direct_client_request_s)); + if (status != WIFI_DIRECT_ERROR_NONE) + { + 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_DISCOVERABLE) + { + 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_discoverable() %s SUCCESS \n", + rsp.param2); + *discoverable = (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_primary_device_type(wifi_direct_primary_device_type_e* type) +{ + wifi_direct_client_info_s *client_info = __wfd_get_control(); + + __WFD_CLIENT_FUNC_START__; + + if (NULL == type) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [type]!\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_NOT_INITIALIZED; + } + + + int result; + wifi_direct_config_data_s *config; + result = wifi_direct_get_config_data(&config); + if(result != WIFI_DIRECT_ERROR_NONE) + { + WFD_CLIENT_LOG(WFD_LOG_ERROR, "Failed to get wifi_direct_get_config_data() result=[%d]\n", result); + __WFD_CLIENT_FUNC_END__; + return WIFI_DIRECT_ERROR_OPERATION_FAILED; + } + + WFD_CLIENT_LOG(WFD_LOG_LOW, "Current primary_dev_type [%d]\n", config->primary_dev_type); + + *type = config->primary_dev_type; + + __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_NOT_INITIALIZED; + } + + 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; } @@ -3806,7 +5042,7 @@ int wifi_direct_set_config_data(wifi_direct_config_data_s * config) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } if (config == NULL) @@ -3916,6 +5152,105 @@ int wifi_direct_set_config_data(wifi_direct_config_data_s * config) } +int wifi_direct_set_autoconnection_mode(bool 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_NOT_INITIALIZED; + } + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + + int status = WIFI_DIRECT_ERROR_NONE; + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_SET_AUTOCONNECTION_MODE; + req.client_id = client_info->client_id; + + status =__wfd_client_send_request(client_info->sync_sockfd, &req, + sizeof(wifi_direct_client_request_s)); + if (status != WIFI_DIRECT_ERROR_NONE) + { + 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, &mode, + sizeof(bool)); + 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_AUTOCONNECTION_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_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(); @@ -3927,7 +5262,7 @@ int wifi_direct_set_p2poem_loglevel(int increase_log_level) { WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n"); __WFD_CLIENT_FUNC_END__; - return WIFI_DIRECT_ERROR_STRANGE_CLIENT; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; } wifi_direct_client_request_s req;