From: Milind Murhekar Date: Thu, 29 Mar 2018 09:59:31 +0000 (+0530) Subject: Add new APIs for Wi-Fi Direct X-Git-Tag: submit/tizen/20180426.072841~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9e9d8779b04acba4b34ca780eb65e5d34d0afd7e;p=platform%2Fcore%2Fapi%2Fwifi-direct.git Add new APIs for Wi-Fi Direct Decription: This patch adds the new API's for below functionalities for Wi-Fi Direct Applications. a) create Group with SSID b) set/get go intent based on device type c) set/unset notification for peer device info connection state d) set/get WPS config method e) remove persistent device based on BSSID f) remove all persistent device Change-Id: Ib0b2fe539737de038f5430cd64ebda33e238ef1b Signed-off-by: Milind Murhekar --- diff --git a/include/wifi-direct.h b/include/wifi-direct.h index 56a5dfc..012f0c8 100755 --- a/include/wifi-direct.h +++ b/include/wifi-direct.h @@ -32,6 +32,17 @@ extern "C" { * @{ */ +/** + * @brief Wi-Fi Direct Device Name maximum length. + * @since_tizen 5.0 + */ +#define WIFI_DIRECT_MAX_DEVICE_NAME_LEN 32 + +/** + * @brief Wi-Fi Direct MAC Address length. + * @since_tizen 5.0 + */ +#define WIFI_DIRECT_MAC_ADDRESS_LEN 18 /** * @brief Enumeration for Wi-Fi Direct error code. @@ -121,6 +132,16 @@ typedef enum { WIFI_DIRECT_GROUP_DESTROYED, /**< Group is destroyed */ } wifi_direct_connection_state_e; +/** + * @brief Enumeration for WPS Config Method type. + * @since_tizen 5.0 + */ +typedef enum { + WIFI_DIRECT_CONFIG_METHOD_DEFAULT = 0x00, /**< Use default config method */ + WIFI_DIRECT_CONFIG_METHOD_PBC = 0x01, /**< Push Button Configuration */ + WIFI_DIRECT_CONFIG_METHOD_PIN_DISPLAY = 0x02, /**< Display PIN code */ + WIFI_DIRECT_CONFIG_METHOD_PIN_KEYPAD = 0x04, /**< Provide the keypad to input the PIN */ +} wifi_direct_config_method_type_e; /** * @brief Enumeration for Wi-Fi Direct secondary device type. @@ -378,6 +399,14 @@ typedef enum { WIFI_DIRECT_VSIE_FRAME_ASSOC_REQ, } wifi_direct_vsie_frames_e; +/** + * @brief Wi-Fi Direct connection state structure to store result of new connection state callback. + * @since_tizen 5.0 + */ +typedef struct { + char device_name[WIFI_DIRECT_MAX_DEVICE_NAME_LEN+1]; /**< Null-terminated device friendly name. */ + char mac_address[WIFI_DIRECT_MAC_ADDRESS_LEN+1]; /**< Null-terminated Device's P2P Device Address */ +} wifi_direct_connection_state_cb_data_s; /** * @brief Wi-Fi Direct buffer structure to store result of peer discovery. @@ -638,6 +667,29 @@ typedef void (*wifi_direct_connection_state_changed_cb) (int error_code, const char *mac_address, void *user_data); +/** + * @brief Called when the state of connection is changed. + * @since_tizen 5.0 + * @details The following error codes can be delivered:\n + * #WIFI_DIRECT_ERROR_NONE\n + * #WIFI_DIRECT_ERROR_OPERATION_FAILED\n + * #WIFI_DIRECT_ERROR_NOT_PERMITTED + * @param[in] error_code The error code + * @param[in] connection_state The connection state + * @param[in] data_s The structure for peer data + * @param[in] user_data The user data passed from the callback registration function + * @pre wifi_direct_create_group(), wifi_direct_destroy_group(), wifi_direct_connect(), wifi_direct_disconnect() or wifi_direct_disconnect_all() will invoke this callback + * if you register this callback using wifi_direct_set_peer_info_connection_state_changed_cb(). + * @see wifi_direct_connect() + * @see wifi_direct_disconnect() + * @see wifi_direct_disconnect_all() + * @see wifi_direct_set_peer_info_connection_state_changed_cb() + * @see wifi_direct_unset_peer_info_connection_state_changed_cb() + */ +typedef void (*wifi_direct_peer_info_connection_state_changed_cb)(wifi_direct_error_e error_code, + wifi_direct_connection_state_e connection_state, + wifi_direct_connection_state_cb_data_s data_s, + void *user_data); /** * @brief Called when IP address of client is assigned when your device is the group owner. @@ -1331,6 +1383,36 @@ int wifi_direct_set_connection_state_changed_cb(wifi_direct_connection_state_cha */ int wifi_direct_unset_connection_state_changed_cb(void); +/** + * @brief Sets the callback called when the state of connection is changed. + * @since_tizen 5.0 + * @param[in] cb The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return @c 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_peer_info_connection_state_changed_cb() + * @see wifi_direct_peer_info_connection_state_changed_cb() + */ +int wifi_direct_set_peer_info_connection_state_changed_cb(wifi_direct_peer_info_connection_state_changed_cb cb, void *user_data); + +/** + * @brief Unsets the callback called when the state of connection is changed. + * @since_tizen 5.0 + * @return @c 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_peer_info_connection_state_changed_cb() + */ +int wifi_direct_unset_peer_info_connection_state_changed_cb(void); + /** * @brief Registers the callback called when the IP address of the client is assigned @@ -3000,6 +3082,31 @@ int wifi_direct_foreach_connected_peers(wifi_direct_connected_peer_cb callback, */ int wifi_direct_create_group(void); +/** + * @brief Creates a Wi-Fi Direct Group, asynchronously with given SSID name. + * @since_tizen 5.0 + * @details This function sets up device as the Group Owner and waits for clients to connect. + * In addition, a soft AP will be created, the WPS registrar and the DHCP server will be started. + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] ssid Referred to as a network name, it is a name that identifies a wireless network + * @return 0 on success, otherwise a negative error value + * @retval #WIFI_DIRECT_ERROR_NONE Successful + * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed + * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed + * @retval #WIFI_DIRECT_ERROR_PERMISSION_DENIED Permission denied + * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid paramters + * @retval #WIFI_DIRECT_ERROR_NOT_SUPPORTED Not supported + * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized + * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #WIFI_DIRECT_ERROR_AUTH_FAILED Authentication failed + * @pre Wi-Fi Direct service must be activated by wifi_direct_activate(). + * @post wifi_direct_connection_state_changed_cb() will be invoked with #WIFI_DIRECT_GROUP_CREATED. + * @see wifi_direct_activate() + * @see wifi_direct_destroy_group() + * @see wifi_direct_connection_state_changed_cb() + */ +int wifi_direct_create_group_with_ssid(const char *ssid); /** * @brief Destorys the Wi-Fi Direct Group, asynchronously. @@ -5405,6 +5512,28 @@ int wifi_direct_get_req_wps_type(wifi_direct_wps_type_e *type); */ int wifi_direct_set_group_owner_intent(int intent); +/** + * @brief Sets the intent of the group owner for each connection type. + * @since_tizen 5.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @remarks The range of intent is 0 - 15. The higher the @a intent is, the higher the probability to be the group owner is. + * @param[in] type The type of connection for a peer device + * @param[in] intent The intent of the group owner + * @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_PERMISSION_DENIED Permission denied + * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted + * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized + * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy + * @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize(). + * @see wifi_direct_initialize() + * @see wifi_direct_get_go_intent_per_type() + */ +int wifi_direct_set_go_intent_per_type(int type, int intent); /** * @brief Gets the intent of the group owner. @@ -5469,6 +5598,27 @@ int wifi_direct_set_group_owner_intent(int intent); */ int wifi_direct_get_group_owner_intent(int *intent); +/** + * @brief Gets the intent of the group owner for each connection type. + * @since_tizen 5.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] type The type of connection for a peer device + * @param[out] intent The intent of the group owner + * @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_PERMISSION_DENIED Permission denied + * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted + * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized + * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy + * @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize(). + * @see wifi_direct_initialize() + * @see wifi_direct_set_go_intent_per_type() + */ +int wifi_direct_get_go_intent_per_type(int type, int *intent); /** * @brief Sets the max number of clients. @@ -8173,6 +8323,91 @@ int wifi_direct_get_connecting_peer_info(wifi_direct_discovered_peer_info_s **pe */ int wifi_direct_get_peer_vsie(char *mac_address, char **vsie); +/** + * @brief Sets the advertizing WPS (Wi-Fi Protected Setup) type. + * @since_tizen 5.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] type The type of WPS. composition of #wifi_direct_config_method_type_e + * for example #WIFI_DIRECT_CONFIG_METHOD_PBC|#WIFI_DIRECT_CONFIG_METHOD_PIN_DISPLAY + * Use #WIFI_DIRECT_CONFIG_METHOD_DEFAULT to reset to default value + * @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_PERMISSION_DENIED Permission denied + * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted + * @retval #WIFI_DIRECT_ERROR_NOT_SUPPORTED Not supported + * @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_activate(). + * @see wifi_direct_initialize() + */ +int wifi_direct_set_wps_config_method(int type); + +/** + * @brief Gets the advertizing WPS (Wi-Fi Protected Setup) type. + * @since_tizen 5.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[out] type The type of WPS. composition of #wifi_direct_config_method_type_e + * @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_PERMISSION_DENIED Permission denied + * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted + * @retval #WIFI_DIRECT_ERROR_NOT_SUPPORTED Not supported + * @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(). + * @pre Wi-Fi Direct service must be activated by wifi_direct_activate(). + * @see wifi_direct_initialize() + */ +int wifi_direct_get_wps_config_method(int *type); + +/** + * @brief Removes a persistent device. + * @since_tizen 5.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] mac_address The MAC address of the persistent group owner + * @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_PERMISSION_DENIED Permission denied + * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted + * @retval #WIFI_DIRECT_ERROR_NOT_SUPPORTED Not supported + * @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_remove_persistent_device(char *mac_address); + +/** + * @brief Removes all persistent devices. + * @since_tizen 5.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @return 0 on success, otherwise a negative error value + * @retval #WIFI_DIRECT_ERROR_NONE Successful + * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed + * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed + * @retval #WIFI_DIRECT_ERROR_PERMISSION_DENIED Permission denied + * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted + * @retval #WIFI_DIRECT_ERROR_NOT_SUPPORTED Not supported + * @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_remove_all_persistent_devices(void); + /** * @} */ diff --git a/src/include/wifi-direct-client-proxy.h b/src/include/wifi-direct-client-proxy.h index 2f1efe7..433a4df 100644 --- a/src/include/wifi-direct-client-proxy.h +++ b/src/include/wifi-direct-client-proxy.h @@ -78,6 +78,9 @@ typedef struct { wifi_direct_service_state_changed_cb service_cb; void *user_data_for_cb_service; + wifi_direct_peer_info_connection_state_changed_cb peer_data_connection_cb; + void *user_data_for_cb_peer_data_connection; + } wifi_direct_client_info_s; extern char *wfd_debug_print(char *file, int line, char *format, ...); @@ -115,6 +118,14 @@ void wifi_direct_process_manage_disconnection(GDBusConnection *connection, GVariant *parameters, gpointer user_data); +void wifi_direct_process_manage_disconnection_ind(GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data); + void wifi_direct_process_manage_peer_ip_assigned(GDBusConnection *connection, const gchar *sender, const gchar *object_path, diff --git a/src/include/wifi-direct-ipc.h b/src/include/wifi-direct-ipc.h index fdcbce1..bdb9574 100644 --- a/src/include/wifi-direct-ipc.h +++ b/src/include/wifi-direct-ipc.h @@ -26,6 +26,7 @@ #define false 0 #define WFD_INVALID_ID -1 +#define WIFI_DIRECT_MAX_TYPE 8 #ifndef O_NONBLOCK #define O_NONBLOCK O_NDELAY diff --git a/src/wifi-direct-client-proxy.c b/src/wifi-direct-client-proxy.c index 448b887..d666252 100644 --- a/src/wifi-direct-client-proxy.c +++ b/src/wifi-direct-client-proxy.c @@ -321,6 +321,49 @@ void wifi_direct_process_manage_disconnection(GDBusConnection *connection, __WDC_LOG_FUNC_END__; } +void wifi_direct_process_manage_disconnection_ind(GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data) +{ + __WDC_LOG_FUNC_START__; + int error_code; + wifi_direct_connection_state_e connection_state; + const gchar *peer_mac_address = NULL; + const gchar *peer_dev_name = NULL; + wifi_direct_connection_state_cb_data_s data_s; + + wifi_direct_client_info_s *client = __wfd_get_control(); + + if (!parameters) { + __WDC_LOG_FUNC_END__; + return; + } + + if (!client->peer_data_connection_cb) { + WDC_LOGI("peer_data_connection_cb is NULL!!"); + __WDC_LOG_FUNC_END__; + return; + } + + g_variant_get(parameters, "(ii&s&s)", + &error_code, &connection_state, &peer_mac_address, &peer_dev_name); + + memset(&data_s, 0x00, sizeof(wifi_direct_connection_state_cb_data_s)); + g_strlcpy(data_s.mac_address, peer_mac_address, WIFI_DIRECT_MAC_ADDRESS_LEN+1); + g_strlcpy(data_s.device_name, peer_dev_name, WIFI_DIRECT_MAX_DEVICE_NAME_LEN+1); + + client->peer_data_connection_cb(error_code, + connection_state, + data_s, + client->user_data_for_cb_peer_data_connection); + + __WDC_LOG_FUNC_END__; +} + void wifi_direct_process_manage_peer_ip_assigned(GDBusConnection *connection, const gchar *sender, const gchar *object_path, @@ -1166,6 +1209,49 @@ int wifi_direct_unset_connection_state_changed_cb(void) return WIFI_DIRECT_ERROR_NONE; } +int wifi_direct_set_peer_info_connection_state_changed_cb(wifi_direct_peer_info_connection_state_changed_cb cb, void *user_data) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE); + + if (!cb) { + WDC_LOGE("Callback is NULL"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is not initialized"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + g_client_info.peer_data_connection_cb = cb; + g_client_info.user_data_for_cb_peer_data_connection = user_data; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_unset_peer_info_connection_state_changed_cb(void) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE); + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is not initialized"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + g_client_info.peer_data_connection_cb = NULL; + g_client_info.user_data_for_cb_peer_data_connection = NULL; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} int wifi_direct_set_client_ip_address_assigned_cb(wifi_direct_client_ip_address_assigned_cb cb, void* user_data) @@ -2003,6 +2089,48 @@ int wifi_direct_create_group(void) return ret; } +int wifi_direct_create_group_with_ssid(const char *ssid) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + GVariantBuilder *builder = NULL; + GVariant *params = NULL; + GError *error = NULL; + GVariant *reply = NULL; + int ret = WIFI_DIRECT_ERROR_NONE; + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!ssid) { + WDC_LOGE("NULL Param"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + g_variant_builder_add(builder, "{sv}", "ssid", g_variant_new_string(ssid)); + params = g_variant_new("(a{sv})", builder); + g_variant_builder_unref(builder); + + reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE, + "CreateGroup", params, &error); + + ret = __net_wifidirect_gerror_to_enum(error); + if (ret == WIFI_DIRECT_ERROR_NONE) { + g_variant_get(reply, "(i)", &ret); + g_variant_unref(reply); + } + + WDC_LOGD("%s() return : [%d]", __func__, ret); + __WDC_LOG_FUNC_END__; + return ret; +} int wifi_direct_destroy_group(void) { @@ -2200,6 +2328,103 @@ int wifi_direct_get_group_owner_intent(int *intent) return ret; } +int wifi_direct_set_go_intent_per_type(int type, int intent) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE); + + GError *error = NULL; + GVariant *reply = NULL; + GVariant *params = NULL; + int ret = WIFI_DIRECT_ERROR_NONE; + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (type < 0 || type >= WIFI_DIRECT_MAX_TYPE) { + WDC_LOGE("Invalid Param : type[%d]", type); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + if (intent < 0 || intent > 15) { + WDC_LOGE("Invalid Param : intent[%d]", intent); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + params = g_variant_new("(ii)", type, intent); + reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE, + "SetGoIntentPerType", + params, + &error); + + ret = __net_wifidirect_gerror_to_enum(error); + if (ret == WIFI_DIRECT_ERROR_NONE) { + g_variant_get(reply, "(i)", &ret); + g_variant_unref(reply); + } + + WDC_LOGD("return : [%d]", ret); + __WDC_LOG_FUNC_END__; + return ret; +} + +int wifi_direct_get_go_intent_per_type(int type, int *intent) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE); + + GError *error = NULL; + GVariant *reply = NULL; + GVariant *params = NULL; + int val = 0; + int ret = WIFI_DIRECT_ERROR_NONE; + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (type < 0 || type >= WIFI_DIRECT_MAX_TYPE) { + WDC_LOGE("Invalid Param : type[%d]", type); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + if (!intent) { + WDC_LOGE("Invalid Parameter"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + params = g_variant_new("(i)", type); + reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE, + "GetGoIntentPerType", + params, + &error); + + ret = __net_wifidirect_gerror_to_enum(error); + if (ret != WIFI_DIRECT_ERROR_NONE) { + return ret; + } + + g_variant_get(reply, "(ii)", &ret, &val); + *intent = val; + g_variant_unref(reply); + + WDC_LOGD("Intent = [%d]", *intent); + WDC_LOGD("return : [%d]", ret); + __WDC_LOG_FUNC_END__; + return ret; +} + int wifi_direct_set_max_clients(int max) { __WDC_LOG_FUNC_START__; @@ -4705,3 +4930,162 @@ int wifi_direct_get_peer_vsie(char *mac_address, char **vsie) return ret; } //LCOV_EXCL_STOP + +int wifi_direct_set_wps_config_method(int type) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + GError *error = NULL; + GVariant *reply = NULL; + GVariant *params = NULL; + int ret = WIFI_DIRECT_ERROR_NONE; + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if ((type < WIFI_DIRECT_CONFIG_METHOD_DEFAULT) || + (type > WIFI_DIRECT_CONFIG_METHOD_PIN_KEYPAD)) { + WDC_LOGE("Invalid wps config method"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + WDC_LOGD("Param wps_mode [%d]", type); + + params = g_variant_new("(i)", type); + reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE, + "SetWpsConfigMethod", + params, + &error); + + ret = __net_wifidirect_gerror_to_enum(error); + if (ret == WIFI_DIRECT_ERROR_NONE) { + g_variant_get(reply, "(i)", &ret); + g_variant_unref(reply); + } + + WDC_LOGD("return : [%d]", ret); + __WDC_LOG_FUNC_END__; + return ret; +} + +int wifi_direct_get_wps_config_method(int *type) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + GError *error = NULL; + GVariant *reply = NULL; + int mode = 0; + int ret = 0; + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!type) { + WDC_LOGE("NULL Param type"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE, + "GetWpsConfigMethod", + NULL, + &error); + + ret = __net_wifidirect_gerror_to_enum(error); + if (ret != WIFI_DIRECT_ERROR_NONE) { + return ret; + } + + g_variant_get(reply, "(ii)", &ret, &mode); + *type = mode; + g_variant_unref(reply); + + WDC_LOGD("return : [%d]", ret); + __WDC_LOG_FUNC_END__; + return ret; +} + +int wifi_direct_remove_persistent_device(char *mac_address) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + GError *error = NULL; + GVariant *reply = NULL; + GVariant *params = NULL; + int ret = WIFI_DIRECT_ERROR_NONE; + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!mac_address) { + WDC_LOGE("NULL Param"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + params = g_variant_new("(s)", mac_address); + reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE, + "RemovePersistentDevice", + params, + &error); + + ret = __net_wifidirect_gerror_to_enum(error); + if (ret == WIFI_DIRECT_ERROR_NONE) { + g_variant_get(reply, "(i)", &ret); + g_variant_unref(reply); + } + + WDC_LOGD("return : [%d]", ret); + + __WDC_LOG_FUNC_END__; + return ret; +} + +int wifi_direct_remove_all_persistent_devices(void) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + GError *error = NULL; + GVariant *reply = NULL; + int ret = WIFI_DIRECT_ERROR_NONE; + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE, + "RemoveAllPersistentDevice", + NULL, + &error); + + ret = __net_wifidirect_gerror_to_enum(error); + if (ret == WIFI_DIRECT_ERROR_NONE) { + g_variant_get(reply, "(i)", &ret); + g_variant_unref(reply); + } + + WDC_LOGD("return : [%d]", ret); + + __WDC_LOG_FUNC_END__; + return ret; +} diff --git a/src/wifi-direct-dbus.c b/src/wifi-direct-dbus.c index abb9698..64fc304 100644 --- a/src/wifi-direct-dbus.c +++ b/src/wifi-direct-dbus.c @@ -72,6 +72,12 @@ static struct { "Disconnection", wifi_direct_process_manage_disconnection }, + { + 0, + WFD_MANAGER_MANAGE_INTERFACE, + "DisconnectionInd", + wifi_direct_process_manage_disconnection_ind + }, { 0, WFD_MANAGER_MANAGE_INTERFACE, diff --git a/test/wifi_direct_test.c b/test/wifi_direct_test.c index 538db5c..a1ef539 100644 --- a/test/wifi_direct_test.c +++ b/test/wifi_direct_test.c @@ -89,6 +89,7 @@ enum { CMD_ENABLE_PUSH_BUTTON, CMD_CREATE_GROUP, + CMD_CREATE_GROUP_WITH_SSID, CMD_CANCEL_GROUP, CMD_IS_GROUP_OWNER, CMD_REJECT, @@ -180,6 +181,12 @@ enum { CMD_REMOVE_VSIE, CMD_GET_PEER_VSIE, + CMD_SET_GO_INTENT_PER_TYPE, + CMD_GET_GO_INTENT_PER_TYPE, + CMD_SET_WPS_CONFIG_METHOD, + CMD_GET_WPS_CONFIG_METHOD, + CMD_REMOVE_PERSISTENT_DEVICE, + CMD_REMOVE_ALL_PERSISTENT_DEVICE, CMD_INVALID = 255, }; @@ -213,6 +220,7 @@ menu_str_t g_menu_str[] = { { CMD_ENABLE_PUSH_BUTTON, "CMD_ENABLE_PUSH_BUTTON" }, { CMD_CREATE_GROUP, "CMD_CREATE_GROUP" }, + { CMD_CREATE_GROUP_WITH_SSID, "CMD_CREATE_GROUP_WITH_SSID" }, { CMD_CANCEL_GROUP, "CMD_CANCEL_GROUP" }, { CMD_IS_GROUP_OWNER, "CMD_IS_GROUP_OWNER" }, { CMD_REJECT, "CMD_REJECT" }, @@ -302,6 +310,12 @@ menu_str_t g_menu_str[] = { { CMD_REMOVE_VSIE, "CMD_REMOVE_VSIE" }, { CMD_GET_PEER_VSIE, "CMD_GET_PEER_VSIE" }, + { CMD_SET_GO_INTENT_PER_TYPE, "CMD_SET_GO_INTENT_PER_TYPE"}, + { CMD_GET_GO_INTENT_PER_TYPE, "CMD_GET_GO_INTENT_PER_TYPE"}, + { CMD_SET_WPS_CONFIG_METHOD, "CMD_SET_WPS_CONFIG_METHOD" }, + { CMD_GET_WPS_CONFIG_METHOD, "CMD_GET_WPS_CONFIG_METHOD" }, + { CMD_REMOVE_PERSISTENT_DEVICE, "CMD_REMOVE_PERSISTENT_DEVICE" }, + { CMD_REMOVE_ALL_PERSISTENT_DEVICE, "CMD_REMOVE_ALL_PERSISTENT_DEVICE" }, { -1, NULL }, }; @@ -1126,6 +1140,15 @@ void _cb_state_changed(wifi_direct_state_e state, return; } +void _cb_peer_info_connection(wifi_direct_error_e error_code, + wifi_direct_connection_state_e connection_state, + wifi_direct_connection_state_cb_data_s data_s, + void *user_data) +{ + printf("New Connection state changed to: [%d]\n", connection_state); + printf("Mac Address : [%s], Device Name : [%s]\n", data_s.mac_address, data_s.device_name); +} + int init_wfd_client(struct appdata *ad) { int ret; @@ -1154,6 +1177,9 @@ int init_wfd_client(struct appdata *ad) ret = wifi_direct_set_state_changed_cb(_cb_state_changed, (void*)ad); printf("wifi_direct_set_state_changed_cb() result=[%d]\n", ret); + ret = wifi_direct_set_peer_info_connection_state_changed_cb(_cb_peer_info_connection, (void *)ad); + printf("wifi_direct_set_peer_info_connection_state_changed_cb() result=[%d]\n", ret); + return ret; } @@ -1209,6 +1235,9 @@ void process_input(const char *input, gpointer user_data) { result = wifi_direct_set_connection_state_changed_cb(_cb_connection, (void*)ad); printf("wifi_direct_set_connection_state_changed_cb() result=[%d]\n", result); + + result = wifi_direct_set_peer_info_connection_state_changed_cb(_cb_peer_info_connection, (void *)ad); + printf("wifi_direct_set_peer_info_connection_state_changed_cb() result=[%d]\n", result); } break; @@ -1216,6 +1245,9 @@ void process_input(const char *input, gpointer user_data) { result = wifi_direct_unset_connection_state_changed_cb(); printf("wifi_direct_unset_connection_state_changed_cb() result=[%d]\n", result); + + result = wifi_direct_unset_peer_info_connection_state_changed_cb(); + printf("wifi_direct_unset_peer_info_connection_state_changed_cb() result=[%d]\n", result); } break; @@ -1492,6 +1524,7 @@ void process_input(const char *input, gpointer user_data) printf("wifi_direct_activate_pushbutton() result=[%d]\n", result); } break; + case CMD_CREATE_GROUP: if (ad != NULL) { result = wifi_direct_create_group(); @@ -1499,6 +1532,24 @@ void process_input(const char *input, gpointer user_data) } break; + case CMD_CREATE_GROUP_WITH_SSID: + if (ad != NULL) { + char *ssid = NULL; + + printf("Input group ssid name:\n"); + if (scanf(" %33ms", &ssid) < 1) + break; + + if (strlen(ssid) <= 0) + printf("invalid ssid name !!\n"); + else + printf("ssid: [%s]\n", ssid); + + result = wifi_direct_create_group_with_ssid(ssid); + printf("wifi_direct_create_group_with_ssid() result=[%d]\n", result); + } + break; + case CMD_CANCEL_GROUP: if (ad != NULL) { result = wifi_direct_destroy_group(); @@ -2615,6 +2666,86 @@ void process_input(const char *input, gpointer user_data) } } break; + case CMD_SET_GO_INTENT_PER_TYPE: + if (ad != NULL) { + int intent = 0; + int type = 0; + + printf("Enter group_owner_intent(valid range 0 ~ 15): "); + if (scanf(" %d", &intent) < 1) + break; + + printf("Enter connection type(valid range 0 ~ 7): "); + if (scanf(" %d", &type) < 1) + break; + + result = wifi_direct_set_go_intent_per_type(type, intent); + printf("wifi_direct_set_go_intent_per_type() ret[%d]\n", result); + } + break; + case CMD_GET_GO_INTENT_PER_TYPE: + if (ad != NULL) { + int intent = 0; + int type = 0; + + printf("Enter connection type(valid range 0 ~ 7): "); + if (scanf(" %d", &type) < 1) + break; + + result = wifi_direct_get_go_intent_per_type(type, &intent); + printf("wifi_direct_get_go_intent_per_type() ret[%d] type[%d] intent[%d]\n", result, + type, intent); + } + break; + case CMD_SET_WPS_CONFIG_METHOD: + if (ad != NULL) { + int wps_method = 0; + + printf("Enter wps method to set (default(0),pbc(1),pin_display(2),pin_keypad(4) : "); + if (scanf(" %d", &wps_method) < 1) + break; + + result = wifi_direct_set_wps_config_method(wps_method); + printf("wifi_direct_set_wps_config_method() ret[%d]\n", result); + break; + } + break; + case CMD_GET_WPS_CONFIG_METHOD: + if (ad != NULL) { + int wps_method = 0; + + result = wifi_direct_get_wps_config_method(&wps_method); + printf("wifi_direct_get_wps_config_method() result=[%d] wps_method[%d]\n", result, wps_method); + break; + } + break; + case CMD_REMOVE_PERSISTENT_DEVICE: + if (ad != NULL) { + char *mac = NULL; + + printf("Input device MAC :\n"); + if (scanf(" %18ms", &mac) < 1) + break; + + if (strlen(mac) <= 0) + printf("invalid device MAC !!\n"); + else + printf("device MAC: [%s]\n", mac); + + if (strlen(mac) > 0) { + result = wifi_direct_remove_persistent_device(mac); + printf("wifi_direct_remove_persistent_device() ret=[%d]\n", result); + } + + free(mac); + } + break; + case CMD_REMOVE_ALL_PERSISTENT_DEVICE: + if (ad != NULL) { + result = wifi_direct_remove_all_persistent_devices(); + printf("wifi_direct_remove_persistent_device() ret=[%d]\n", result); + } + break; case CMD_FULL_MENU: usage_full(); break;