############################# Check minimum CMake version #####################
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.3)
-PROJECT(wifi-direct C)
+PROJECT(wifi-direct)
SET(PACKAGE_DESCRIPTION "Library and header files for Wi-Fi Direct Native API")
############################# cmake packages ##################################
SET(COMMON_DEPS "dlog glib-2.0 gio-2.0 vconf capi-system-info")
SET(PC_DEPS "capi-base-common")
+SET(TEST_DEPS "glib-2.0")
+SET(GTEST_DEPS "gmock")
SET(TARGET_WIFI_DIRECT "wifi-direct")
SET(TARGET_WIFI_DIRECT_TEST "wifi_direct_test")
+SET(TARGET_WIFI_DIRECT_GTEST "gtest-wifi-direct")
+
+ADD_DEFINITIONS("-DUSE_DLOG")
ADD_SUBDIRECTORY(include)
ADD_SUBDIRECTORY(pkgconfig)
ADD_SUBDIRECTORY(src)
-ADD_SUBDIRECTORY(test)
+ADD_SUBDIRECTORY(tests)
Name: capi-network-wifi-direct
Summary: Network WiFi-Direct Library
-Version: 1.2.104
+Version: 1.3.0
Release: 1
Group: Network & Connectivity/API
License: Apache-2.0
BuildRequires: lcov
BuildRequires: tar
%endif
-%if 0%{?gtest:1}
BuildRequires: pkgconfig(gmock)
-%endif
BuildRequires: cmake
BuildRequires: gettext-devel
Provides: %{name}-profile_wearable = %{version}-%{release}
tar xf %{name}-gcov.tar -C %{buildroot}%{_datadir}/gcov/obj
%endif
+%check
+tests/gtest-wifi-direct
+%if 0%{?gcov:1}
+lcov -c --ignore-errors graph --no-external -b . -d . -o %{name}.info
+genhtml %{name}.info -o out --legend --show-details
+%endif
+
ln -sf libwifi-direct.so.%{version} %{buildroot}/%{_libdir}/libwifi-direct.so.0
%post -p /sbin/ldconfig
%files tool
%{_bindir}/wifi_direct_test
+%{_bindir}/gtest-wifi-direct
%if 0%{?gcov:1}
%files gcov
wifi_direct_dbus_signal_map[i].function,
NULL,
NULL);
- WDC_LOGD("Subscribed dbus signals [%d]", wifi_direct_dbus_signal_map[i].sub_id);
}
}
ref_count++;
+++ /dev/null
-########################## search for packages ################################
-
-PKG_CHECK_MODULES(TARGET_WIFI_DIRECT_TEST_REQ_PKGS REQUIRED glib-2.0)
-
-############################# compiler flags ##################################
-
-SET(EXTRA_FLAGS "-Wall -Werror")
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${CFLAGS} -fPIE")
-SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
-
-######################## directory configuration ############################
-
-INCLUDE_DIRECTORIES(${TARGET_WIFI_DIRECT_TEST_REQ_PKGS_INCLUDE_DIRS})
-LINK_DIRECTORIES(${TARGET_WIFI_DIRECT_TEST_REQ_PKGS_LIBRARY_DIRS})
-
-INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include)
-
-# Build
-ADD_EXECUTABLE(${TARGET_WIFI_DIRECT_TEST}
- ${CMAKE_CURRENT_SOURCE_DIR}/wifi_direct_test.c
-)
-
-TARGET_LINK_LIBRARIES(${TARGET_WIFI_DIRECT_TEST}
- ${TARGET_WIFI_DIRECT_TEST_REQ_PKGS_LIBRARIES} ${PROJECT_NAME})
-
-#Install
-INSTALL(TARGETS ${TARGET_WIFI_DIRECT_TEST} DESTINATION ${BIN_DIR})
-
+++ /dev/null
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <time.h>
-#include <assert.h>
-
-#include <glib.h>
-#include <glib-object.h>
-
-#include <wifi-direct.h>
-
-/* For wifi-direct package internal use only */
-#include <wifi-direct-internal.h>
-
-#define RESET_COLOR "\e[m"
-#define MAKE_RED "\e[31m"
-#define MAKE_GREEN "\e[32m"
-
-#define __FUNC_ENTER__ printf("%s() entering...\n", __func__)
-#define __FUNC_EXIT__ printf("%s() leaving...\n", __func__)
-
-#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
-#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
-#define MACSTR_LEN 18
-#define MAX_PEER_NUM 10
-
-static const char *test_wfd_convert_error_to_string(wifi_direct_error_e err_type)
-{
- switch (err_type) {
- case WIFI_DIRECT_ERROR_NONE:
- return "NONE";
- case WIFI_DIRECT_ERROR_NOT_PERMITTED:
- return "NOT_PERMITTED";
- case WIFI_DIRECT_ERROR_OUT_OF_MEMORY:
- return "OUT_OF_MEMORY";
- case WIFI_DIRECT_ERROR_RESOURCE_BUSY:
- return "RESOURCE_BUSY";
- case WIFI_DIRECT_ERROR_INVALID_PARAMETER:
- return "INVALID_PARAMETER";
- case WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT:
- return "CONNECTION_TIME_OUT";
- case WIFI_DIRECT_ERROR_NOT_INITIALIZED:
- return "NOT_INITIALIZED";
- case WIFI_DIRECT_ERROR_COMMUNICATION_FAILED:
- return "COMMUNICATION_FAILED";
- case WIFI_DIRECT_ERROR_WIFI_USED:
- return "WIFI_USED";
- case WIFI_DIRECT_ERROR_MOBILE_AP_USED:
- return "MOBILE_AP_USED";
- case WIFI_DIRECT_ERROR_CONNECTION_FAILED:
- return "CONNECTION_FAILED";
- case WIFI_DIRECT_ERROR_AUTH_FAILED:
- return "AUTH_FAILED";
- case WIFI_DIRECT_ERROR_OPERATION_FAILED:
- return "OPERATION_FAILED";
- case WIFI_DIRECT_ERROR_TOO_MANY_CLIENT:
- return "TOO_MANY_CLIENT";
- case WIFI_DIRECT_ERROR_ALREADY_INITIALIZED:
- return "ALREADY_INITIALIZED";
- case WIFI_DIRECT_ERROR_CONNECTION_CANCELED:
- return "CONNECTION_CANCELED";
- default:
- break;
- }
- return "UNKNOWN";
-}
-
-enum {
- CMD_QUIT,
- CMD_FULL_MENU,
- CMD_INITIALIZE,
- CMD_ACTIVATE_WIFI_DIRECT,
- CMD_DEACTIVATE_WIFI_DIRECT,
- CMD_START_DISCOVER,
- CMD_START_DISCOVER_WITH_LISTEN_ONLY,
- CMD_START_DISCOVER_SPECIFIC_CHANNEL,
- CMD_START_DISCOVER_SPECIFIC_FREQUENCY,
- CMD_CANCEL_DISCOVER,
- CMD_GET_DISVOCERY_RESULT,
- /* CMD_SEND_PROVISION_DISCOVER_REQ, */
- CMD_SEND_CONNECTION_REQ,
- CMD_GET_LINK_STATUS,
- CMD_CONNECT_PEER,
- CMD_CANCEL_CONNECTION,
- CMD_DISCONNECT_ALL,
- CMD_DISCONNECT,
-
- CMD_ENABLE_PUSH_BUTTON,
- CMD_CREATE_GROUP,
- CMD_CREATE_GROUP_WITH_SSID,
- CMD_CANCEL_GROUP,
- CMD_IS_GROUP_OWNER,
- CMD_REJECT,
- CMD_INVITE,
- CMD_SET_DEVICE_NAME,
- CMD_GET_DEVICE_NAME,
- CMD_SET_SSID,
- CMD_GET_SSID,
- CMD_SET_WPA,
- CMD_SET_CHANNEL,
- CMD_SET_WPS_CONFIG,
- CMD_SET_MAX_CLIENT,
- CMD_GET_MAX_CLIENT,
- CMD_SET_HIDE_SSID,
- CMD_ACTIVATE_PERSISTENT_GROUP,
- CMD_DEACTIVATE_PERSISTENT_GROUP,
- CMD_IS_PERSISTENT_GROUP_ACTIVATED,
- CMD_GET_PERSISTENT_GROUP_LIST,
- CMD_REMOVE_PERSISTENT_GROUP,
- /* CMD_SET_GROUP_OWNER, */
- CMD_SET_AUTO_CONNECTION,
- CMD_IS_AUTO_CONNECTION,
- /* CMD_SET_LISTEN_ONLY, */
- CMD_SET_WPS_PIN,
- CMD_GET_WPS_PIN,
- CMD_GET_SUPPORTED_WPS_MODE,
- CMD_SET_CURRENT_WPS_MODE,
- CMD_GET_CURRENT_WPS_MODE,
- CMD_GET_CONNECTED_PEERS_INFO,
- CMD_GET_GO_INTENT,
- CMD_SET_GO_INTENT,
- CMD_GET_DEVICE_MAC,
- CMD_IS_AUTONOMOUS_GROUP,
- CMD_SET_ACTIVATION_CB,
- CMD_SET_DISCOVER_CB,
- CMD_SET_SERVICE_CB,
- CMD_SET_CONNECTION_CB,
- CMD_SET_IP_ADDR_ASSIGNED_CB,
- CMD_SET_PEER_FOUND_CB,
- CMD_SET_DEVICE_NAME_CB,
- CMD_SET_STATE_CB,
- CMD_UNSET_ACTIVATION_CB,
- CMD_UNSET_DISCOVER_CB,
- CMD_UNSET_SERVICE_CB,
- CMD_UNSET_CONNECTION_CB,
- CMD_UNSET_IP_ADDR_ASSIGNED_CB,
- CMD_UNSET_PEER_FOUND_CB,
- CMD_UNSET_DEVICE_NAME_CB,
- CMD_UNSET_STATE_CB,
- CMD_GET_NETWORK_IF_NAME,
- CMD_GET_SUBNET_MASK,
- CMD_GET_GATEWAY_ADDR,
- CMD_IS_DISCOVERABLE,
- CMD_IS_LISTEN_ONLY,
- CMD_GET_PRIMARY_DEVICE_TYPE,
- CMD_GET_SECONDARY_DEVICE_TYPE,
- CMD_GET_OPERATING_CHANNEL,
- CMD_GET_IP_ADDR,
- CMD_REGISTER_SERVICE,
- CMD_DEREGISTER_SERVICE,
- CMD_START_SERVICE_DISCOVERY,
- CMD_CANCEL_SERVICE_DISCOVERY,
-
- CMD_INCREASE_OEM_LOGLEVEL,
- CMD_DECREASE_OEM_LOGLEVEL,
- CMD_DEINITIALIZE,
- CMD_INIT_MIRACAST,
- CMD_GET_PEER_INFO,
- CMD_SET_PASSPHRASE,
- CMD_GET_PASSPHRASE,
- CMD_SET_AUTOCONNECTION_PEER,
-
- CMD_INIT_DISPLAY,
- CMD_DEINIT_DISPLAY,
- CMD_SET_DISPLAY,
- CMD_SET_DISPLAY_AVAILABILITY,
- CMD_GET_DISPLAY,
- CMD_GET_DISPLAY_AVAILABILITY,
- CMD_GET_PEER_DISPLAY_TYPE,
- CMD_GET_PEER_DISPLAY_AVAILABILITY,
- CMD_GET_PEER_DISPLAY_HDCP,
- CMD_GET_PEER_DISPLAY_PORT,
- CMD_GET_PEER_DISPLAY_THROUGHPUT,
- CMD_GET_SESSION_TIMER,
- CMD_SET_SESSION_TIMER,
- CMD_SET_AUTO_GROUP_REMOVAL,
- CMD_GET_PEER_RSSI,
-
- CMD_ADD_VSIE,
- CMD_GET_VSIE,
- 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,
-};
-
-typedef struct {
- int cmd;
- char* menu_str;
-} menu_str_t;
-
-menu_str_t g_menu_str[] = {
- { CMD_QUIT, "CMD_QUIT" },
- { CMD_FULL_MENU, "CMD_FULL_MENU" },
- { CMD_INITIALIZE, "CMD_INITIALIZE" },
- { CMD_ACTIVATE_WIFI_DIRECT, "CMD_ACTIVATE_WIFI_DIRECT" },
- { CMD_DEACTIVATE_WIFI_DIRECT, "CMD_DEACTIVATE_WIFI_DIRECT" },
- { CMD_START_DISCOVER, "CMD_START_DISCOVER" },
- { CMD_START_DISCOVER_WITH_LISTEN_ONLY, "CMD_START_DISCOVER_WITH_LISTEN_ONLY" },
- { CMD_START_DISCOVER_SPECIFIC_CHANNEL, "CMD_START_DISCOVER_SPECIFIC_CHANNEL" },
- { CMD_START_DISCOVER_SPECIFIC_FREQUENCY, "CMD_START_DISCOVER_SPECIFIC_FREQUENCY" },
- { CMD_CANCEL_DISCOVER, "CMD_CANCEL_DISCOVER" },
- { CMD_GET_DISVOCERY_RESULT, "CMD_GET_DISVOCERY_RESULT" },
- /* { CMD_SEND_PROVISION_DISCOVER_REQ, "CMD_SEND_PROVISION_DISCOVER_REQ" }, */
- { CMD_SEND_CONNECTION_REQ, "CMD_SEND_CONNECTION_REQ" },
-
- { CMD_GET_LINK_STATUS, "CMD_GET_LINK_STATUS" },
- { CMD_CONNECT_PEER, "CMD_CONNECT_PEER" },
- { CMD_CANCEL_CONNECTION, "CMD_CANCEL_CONNECTION" },
- { CMD_DISCONNECT_ALL, "CMD_DISCONNECT_ALL" },
- { CMD_DISCONNECT, "CMD_DISCONNECT" },
-
- { CMD_ENABLE_PUSH_BUTTON, "CMD_ENABLE_PUSH_BUTTON" },
-
- { CMD_CREATE_GROUP, "CMD_CREATE_GROUP" },
- { CMD_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" },
- { CMD_INVITE, "CMD_INVITE" },
- { CMD_SET_DEVICE_NAME, "CMD_SET_DEVICE_NAME" },
- { CMD_GET_DEVICE_NAME, "CMD_GET_DEVICE_NAME" },
- { CMD_SET_SSID, "CMD_SET_SSID" },
- { CMD_GET_SSID, "CMD_GET_SSID" },
- { CMD_SET_WPA, "CMD_SET_WPA" },
- { CMD_SET_CHANNEL, "CMD_SET_CHANNEL" },
- { CMD_SET_WPS_CONFIG, "CMD_SET_WPS_CONFIG" },
- { CMD_SET_MAX_CLIENT, "CMD_SET_MAX_CLIENT" },
- { CMD_GET_MAX_CLIENT, "CMD_GET_MAX_CLIENT" },
- { CMD_SET_HIDE_SSID, "CMD_SET_HIDE_SSID" },
- { CMD_ACTIVATE_PERSISTENT_GROUP, "CMD_ACTIVATE_PERSISTENT_GROUP" },
- { CMD_DEACTIVATE_PERSISTENT_GROUP, "CMD_DEACTIVATE_PERSISTENT_GROUP" },
- { CMD_IS_PERSISTENT_GROUP_ACTIVATED, "CMD_IS_PERSISTENT_GROUP_ACTIVATED" },
- { CMD_GET_PERSISTENT_GROUP_LIST, "CMD_GET_PERSISTENT_GROUP_LIST" },
- { CMD_REMOVE_PERSISTENT_GROUP, "CMD_REMOVE_PERSISTENT_GROUP" },
- /* { CMD_SET_GROUP_OWNER, "CMD_SET_GROUP_OWNER" }, */
- { CMD_SET_AUTO_CONNECTION, "CMD_SET_AUTO_CONNECTION" },
- { CMD_IS_AUTO_CONNECTION, "CMD_IS_AUTO_CONNECTION" },
- /* { CMD_SET_LISTEN_ONLY, "CMD_SET_LISTEN_ONLY" }, */
- { CMD_SET_WPS_PIN, "CMD_SET_WPS_PIN" },
- { CMD_GET_WPS_PIN, "CMD_GET_WPS_PIN" },
- { CMD_GET_SUPPORTED_WPS_MODE, "CMD_GET_SUPPORTED_WPS_MODE" },
- { CMD_SET_CURRENT_WPS_MODE, "CMD_SET_CURRENT_WPS_MODE" },
- { CMD_GET_CURRENT_WPS_MODE, "CMD_GET_CURRENT_WPS_MODE" },
- { CMD_GET_CONNECTED_PEERS_INFO, "CMD_GET_CONNECTED_PEERS_INFO" },
- { CMD_GET_GO_INTENT, "CMD_GET_GO_INTENT" },
- { CMD_SET_GO_INTENT, "CMD_SET_GO_INTENT" },
- { CMD_GET_DEVICE_MAC, "CMD_GET_DEVICE_MAC" },
- { CMD_IS_AUTONOMOUS_GROUP, "CMD_IS_AUTONOMOUS_GROUP" },
- { CMD_SET_ACTIVATION_CB, "CMD_SET_ACTIVATION_CB" },
- { CMD_SET_DISCOVER_CB, "CMD_SET_DISCOVER_CB" },
- { CMD_SET_CONNECTION_CB, "CMD_SET_CONNECTION_CB" },
- { CMD_SET_IP_ADDR_ASSIGNED_CB, "CMD_SET_IP_ADDR_ASSIGNED_CB" },
- { CMD_SET_PEER_FOUND_CB, "CMD_SET_PEER_FOUND_CB" },
- { CMD_SET_DEVICE_NAME_CB, "CMD_SET_DEVICE_NAME_CB"},
- { CMD_SET_STATE_CB, "CMD_SET_STATE_CB"},
- { CMD_UNSET_ACTIVATION_CB, "CMD_UNSET_ACTIVATION_CB" },
- { CMD_UNSET_DISCOVER_CB, "CMD_UNSET_DISCOVER_CB" },
- { CMD_UNSET_CONNECTION_CB, "CMD_UNSET_CONNECTION_CB" },
- { CMD_UNSET_IP_ADDR_ASSIGNED_CB, "CMD_UNSET_IP_ADDR_ASSIGNED_CB" },
- { CMD_UNSET_PEER_FOUND_CB, "CMD_UNSET_PEER_FOUND_CB" },
- { CMD_UNSET_STATE_CB, "CMD_UNSET_STATE_CB" },
- { CMD_GET_NETWORK_IF_NAME, "CMD_GET_NETWORK_IF_NAME" },
- { CMD_GET_SUBNET_MASK, "CMD_GET_SUBNET_MASK" },
- { CMD_GET_GATEWAY_ADDR, "CMD_GET_GATEWAY_ADDR" },
- { CMD_IS_DISCOVERABLE, "CMD_IS_DISCOVERABLE" },
- { CMD_IS_LISTEN_ONLY, "CMD_IS_LISTEN_ONLY" },
- { CMD_GET_PRIMARY_DEVICE_TYPE, "CMD_GET_PRIMARY_DEVICE_TYPE" },
- { CMD_GET_SECONDARY_DEVICE_TYPE, "CMD_GET_SECONDARY_DEVICE_TYPE" },
- { CMD_GET_OPERATING_CHANNEL, "CMD_GET_OPERATING_CHANNEL" },
- { CMD_GET_IP_ADDR, "CMD_GET_IP_ADDR" },
- { CMD_REGISTER_SERVICE, "CMD_REGISTER_SERVICE" },
- { CMD_DEREGISTER_SERVICE, "CMD_DEREGISTER_SERVICE" },
- { CMD_START_SERVICE_DISCOVERY, "CMD_START_SERVICE_DISCOVERY" },
- { CMD_CANCEL_SERVICE_DISCOVERY, "CMD_CANCEL_SERVICE_DISCOVERY" },
-
- { CMD_INCREASE_OEM_LOGLEVEL, "CMD_INCREASE_OEM_LOGLEVEL" },
- { CMD_DECREASE_OEM_LOGLEVEL, "CMD_DECREASE_OEM_LOGLEVEL" },
-
- { CMD_DEINITIALIZE, "CMD_DEINITIALIZE" },
- { CMD_INIT_MIRACAST, "CMD_INIT_MIRACAST" },
- { CMD_GET_PEER_INFO, "CMD_GET_PEER_INFO" },
- { CMD_SET_PASSPHRASE, "CMD_SET_PASSPHRASE" },
- { CMD_GET_PASSPHRASE, "CMD_GET_PASSPHRASE" },
- { CMD_SET_AUTOCONNECTION_PEER, "CMD_SET_AUTOCONNECTION_PEER" },
-
- { CMD_INIT_DISPLAY, "CMD_INIT_DISPLAY" },
- { CMD_DEINIT_DISPLAY, "CMD_DEINIT_DISPLAY" },
- { CMD_SET_DISPLAY, "CMD_SET_DISPLAY" },
- { CMD_SET_DISPLAY_AVAILABILITY, "CMD_SET_DISPLAY_AVAILABILITY" },
- { CMD_GET_DISPLAY, "CMD_GET_DISPLAY" },
- { CMD_GET_DISPLAY_AVAILABILITY, "CMD_GET_DISPLAY_AVAILABILITY" },
- { CMD_GET_PEER_DISPLAY_TYPE, "CMD_GET_PEER_DISPLAY_TYPE" },
- { CMD_GET_PEER_DISPLAY_AVAILABILITY, "CMD_GET_PEER_DISPLAY_AVAILABILITY" },
- { CMD_GET_PEER_DISPLAY_HDCP, "CMD_GET_PEER_DISPLAY_HDCP" },
- { CMD_GET_PEER_DISPLAY_PORT, "CMD_GET_PEER_DISPLAY_PORT" },
- { CMD_GET_PEER_DISPLAY_THROUGHPUT, "CMD_GET_PEER_DISPLAY_THROUGHPUT" },
- { CMD_GET_SESSION_TIMER, "CMD_GET_SESSION_TIMER" },
- { CMD_SET_SESSION_TIMER, "CMD_SET_SESSION_TIMER" },
- { CMD_SET_AUTO_GROUP_REMOVAL, "CMD_SET_AUTO_GROUP_REMOVAL" },
- { CMD_GET_PEER_RSSI, "CMD_GET_PEER_RSSI" },
-
- { CMD_ADD_VSIE, "CMD_ADD_VSIE" },
- { CMD_GET_VSIE, "CMD_GET_VSIE" },
- { 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 }, };
-
-struct appdata {
- GMainLoop* main_loop;
-
- wifi_direct_discovered_peer_info_s peer_list[MAX_PEER_NUM];
- int peer_count;
- int selected_peer_index;
-
- wifi_direct_connected_peer_info_s connected_peer_list[MAX_PEER_NUM];
- int connected_peer_count;
-};
-
-struct appdata* g_test_appdata;
-
-void set_appdata(struct appdata* p)
-{
- g_test_appdata = p;
-}
-
-static inline void prt_help(const char *cmd)
-{
- printf("%s -t [dest ID]\n", cmd);
- printf(" -u [my ID]\n");
- printf(" -p [passwd]\n");
- printf(" -a [alias]\n");
-}
-
-static int get_param(int argc, char **argv, struct appdata *ad)
-{
- printf("Parsing argument...\n");
- int opt;
- while ((opt = getopt(argc, argv, "t:u:p:a:")) != -1) {
- printf("Parsing argument...:%c\n", opt);
- switch (opt) {
- case 't':
- default:
- prt_help(argv[0]);
- return -1;
- }
- }
-
- printf("Argument: \n");
-
- return 0;
-}
-
-char* cmd_transform(char*str)
-{
- int i, j;
- int len;
- static char static_buffer[255];
-
- if (str == NULL)
- return "";
-
- len = strlen(str);
- if (len == 0)
- return "";
-
- /* remove "CMD_" */
- /* lower char */
- /* replance "_" to space */
- for (i = 0, j = 4; i < len; i++, j++) {
- if (str[j] >= 'A' && str[j] <= 'Z')
- static_buffer[i] = str[j] + 'a' - 'A';
- else if (str[j] == '_')
- static_buffer[i] = ' ';
- else
- static_buffer[i] = str[j];
- }
- static_buffer[j] = '\0';
-
- return static_buffer;
-}
-
-void usage_full()
-{
- int i;
- printf("Call Test Program\n");
-
- for (i = 0; g_menu_str[i].cmd != -1; i++) {
- if (i % 4 == 0)
- printf("\n");
- printf(" %02d: %-32s ", g_menu_str[i].cmd,
- cmd_transform(g_menu_str[i].menu_str));
-
- }
- printf("\n");
-}
-
-int is_digit(const char* str)
-{
- int len;
- int i;
-
- if (str == NULL)
- return -1;
-
- if (strlen(str) == 0)
- return -1;
-
- len = strlen(str);
- for (i = 0; i < len; i++) {
- if (str[i] < '0' || str[i] > '9')
- return -2;
- }
-
- return 0;
-}
-
-char* print_link_state(wifi_direct_state_e state)
-{
- if (state == WIFI_DIRECT_STATE_DEACTIVATED)
- return "DEACTIVATED";
- if (state == WIFI_DIRECT_STATE_ACTIVATING)
- return "ACTIVATING";
- if (state == WIFI_DIRECT_STATE_ACTIVATED)
- return "ACTIVATED";
- if (state == WIFI_DIRECT_STATE_DISCOVERING)
- return "DISCOVERING";
- if (state == WIFI_DIRECT_STATE_CONNECTING)
- return "CONNECTING";
- if (state == WIFI_DIRECT_STATE_DISCONNECTING)
- return "DISCONNECTING";
- if (state == WIFI_DIRECT_STATE_CONNECTED)
- return "CONNECTED";
- if (state == WIFI_DIRECT_STATE_GROUP_OWNER)
- return "GROUP OWNER";
-
- return "Unknown state";
-}
-
-int select_peer(struct appdata* ad)
-{
- wifi_direct_discovered_peer_info_s* list;
- int target = -1;
- int i;
-
- if (ad == NULL)
- return 0;
-
- list = ad->peer_list;
-
- for (i = 0; i < ad->peer_count; i++) {
- printf("index [%d] MAC [%s] Owner=[%s] SSID[%s]\n",
- i,
- list[i].mac_address,
- list[i].is_group_owner ? "YES" : "NO",
- list[i].device_name);
- }
-
- printf("input peer index:\n");
- if (scanf(" %3d", &target) < 1)
- return 0;
-
- if (target < 0 || target > ad->peer_count) {
- printf("Wrong contact index [%d]\n", target);
- return 0;
- } else
- ad->selected_peer_index = target;
-
- return 1;
-}
-
-int select_connected_peer(struct appdata* ad)
-{
- wifi_direct_connected_peer_info_s* list;
- int target = -1;
- int i, j;
-
- if (ad == NULL)
- return 0;
-
- list = ad->connected_peer_list;
-
- for (i = 0; i < ad->connected_peer_count; i++) {
- if (list[i].service_count == 0) {
- printf("index [%d] MAC [%s] SSID[%s] P2P_Supported [%d]\n", i, list[i].mac_address, list[i].device_name, list[i].p2p_supported);
- } else {
- char services[256] = {0,};
- unsigned int len = 0;
- printf("Service Count = [%d][%p]\n", list[i].service_count, list[i].service_list);
- for (j = 0; j < list[i].service_count && list[i].service_list != NULL; j++) {
- printf("Service[%p]=%s\n", list[i].service_list[j], list[i].service_list[j]);
- snprintf(services + len, 256-len, " %s", list[i].service_list[j]);
- len = len + strlen(list[i].service_list[j]) + 1;
- }
- printf("index [%d] MAC [%s] SSID[%s] Services=[%s]\n", i, list[i].mac_address, list[i].device_name, services);
- }
- }
-
- printf("input peer index:\n");
- if (scanf(" %3d", &target) < 1)
- return -1;
-
- if (target < 0 || target > ad->connected_peer_count) {
- printf("Wrong contact index [%d]\n", target);
- return -1;
- } else
- ad->selected_peer_index = target;
-
- return 1;
-}
-
-void print_peers_connected(struct appdata* ad)
-{
- wifi_direct_connected_peer_info_s* list;
- int i, j;
-
- if (ad == NULL)
- return;
-
- list = ad->connected_peer_list;
-
- for (i = 0; i < ad->connected_peer_count; i++) {
- if (list[i].service_count == 0) {
- printf("index [%d] MAC [%s] SSID[%s] \n", i, list[i].mac_address, list[i].device_name);
- } else {
- char services[256] = {0,};
- unsigned int len = 0;
- printf("Service Count = [%d][%p]\n", list[i].service_count, list[i].service_list);
- for (j = 0; j < list[i].service_count && list[i].service_list != NULL; j++) {
- printf("Service[%p]=%s\n", list[i].service_list[j], list[i].service_list[j]);
- snprintf(services + len, 256-len, " %s", list[i].service_list[j]);
- len = len + strlen(list[i].service_list[j]) + 1;
- }
- printf("index [%d] MAC [%s] SSID[%s] Services=[%s]\n", i, list[i].mac_address, list[i].device_name, services);
- }
- }
-
-}
-
-void print_peers(struct appdata* ad)
-{
- wifi_direct_discovered_peer_info_s* list;
- int i, j;
-
- if (ad == NULL)
- return;
-
- list = ad->peer_list;
-
- for (i = 0; i < ad->peer_count; i++) {
- if (list[i].service_count == 0) {
- printf("index [%d] MAC [%s] Owner=[%s] connected=[%d] SSID[%s] ctg=[%d/%d] \n",
- i,
- list[i].mac_address,
- list[i].is_group_owner ? "YES" : "NO",
- list[i].is_connected,
- list[i].device_name,
- list[i].primary_device_type,
- list[i].secondary_device_type
- );
- } else {
- char services[256] = {0,};
- unsigned int len = 0;
- printf("Service Count = [%d][%p]\n", list[i].service_count, list[i].service_list);
- for (j = 0; j < list[i].service_count && list[i].service_list != NULL; j++) {
- printf("Service[%p]=%s\n", list[i].service_list[j], list[i].service_list[j]);
- snprintf(services + len, 256-len, " %s", list[i].service_list[j]);
- len = len + strlen(list[i].service_list[j]) + 1;
- }
- printf("index [%d] MAC [%s] Owner=[%s] connected=[%d] SSID[%s] ctg=[%d/%d] Services=[%s]\n",
- i,
- list[i].mac_address,
- list[i].is_group_owner ? "YES" : "NO",
- list[i].is_connected,
- list[i].device_name,
- list[i].primary_device_type,
- list[i].secondary_device_type,
- services
- );
- }
- }
-
-}
-
-
-void event_printf(char*s)
-{
- printf("========================================>%s\n", s);
-}
-
-void _cb_activation(int error_code, wifi_direct_device_state_e device_state, void *user_data)
-{
- __FUNC_ENTER__;
-
- switch (device_state) {
- case WIFI_DIRECT_DEVICE_STATE_ACTIVATED:
- event_printf("event -WIFI_DIRECT_DEVICE_STATE_ACTIVATED\n");
- break;
-
- case WIFI_DIRECT_DEVICE_STATE_DEACTIVATED:
- event_printf("event - WIFI_DIRECT_DEVICE_STATE_DEACTIVATED\n");
- break;
-
- default:
- break;
- }
-}
-
-
-bool _cb_discovered_peers_impl(wifi_direct_discovered_peer_info_s* peer, void* user_data)
-{
- __FUNC_ENTER__;
-
- struct appdata* ad = (struct appdata*) user_data;
-
- if (NULL != peer) {
- if (ad->peer_count >= MAX_PEER_NUM)
- return false; /* break out of the loop */
-
- memcpy(&ad->peer_list[ad->peer_count], peer, sizeof(wifi_direct_discovered_peer_info_s));
- ad->peer_count++;
- }
-
- return true; /* continue with the next iteration of the loop */
-}
-
-bool _cb_connected_peers_impl(wifi_direct_connected_peer_info_s* peer, void* user_data)
-{
- __FUNC_ENTER__;
-
- struct appdata* ad = (struct appdata*) user_data;
-
- if (NULL != peer) {
- if (ad->connected_peer_count >= MAX_PEER_NUM)
- return false; /* break out of the loop */
-
- memcpy(&ad->connected_peer_list[ad->connected_peer_count], peer, sizeof(wifi_direct_connected_peer_info_s));
- ad->connected_peer_count++;
- }
-
- return true; /* continue with the next iteration of the loop */
-}
-
-bool _cb_persistent_groups_impl(const char* mac_address, const char* ssid, void* user_data)
-{
- __FUNC_ENTER__;
-
- if (NULL != mac_address)
- printf("mac_address=[%s]\n", mac_address);
-
- if (NULL != ssid)
- printf("ssid=[%s]\n", ssid);
-
- return true; /* continue with the next iteration of the loop */
-}
-
-void _cb_discover(int error_code, wifi_direct_discovery_state_e discovery_state, void *user_data)
-{
- __FUNC_ENTER__;
-
- struct appdata* ad = (struct appdata*) user_data;
-
- switch (discovery_state) {
- case WIFI_DIRECT_DISCOVERY_STARTED:
- event_printf("event - WIFI_DIRECT_DISCOVERY_STARTED\n");
- break;
-
- case WIFI_DIRECT_ONLY_LISTEN_STARTED:
- event_printf("event - WIFI_DIRECT_ONLY_LISTEN_STARTED\n");
- break;
-
- case WIFI_DIRECT_DISCOVERY_FINISHED:
- event_printf("event - WIFI_DIRECT_DISCOVERY_FINISHED\n");
- break;
-
- case WIFI_DIRECT_DISCOVERY_FOUND:
- {
- int ret;
- event_printf("event - WIFI_DIRECT_DISCOVERY_FOUND\n");
-
- memset(ad->peer_list, 0x00, sizeof(wifi_direct_discovered_peer_info_s)*MAX_PEER_NUM);
- ad->peer_count = 0;
- ad->selected_peer_index = 0;
-
- ret = wifi_direct_foreach_discovered_peers(_cb_discovered_peers_impl, (void*)ad);
- printf("wifi_direct_foreach_discovered_peers() ret=[%d]\n", ret);
- }
- break;
-
- case WIFI_DIRECT_DISCOVERY_LOST:
- event_printf("event - WIFI_DIRECT_DISCOVERY_LOST\n");
- break;
-
- default:
- break;
- }
- /* _activate_push_cb((void*)NULL, (Evas_Object*)NULL, (void*)NULL); */
-
-}
-
-void _cb_peer_found(int error_code, wifi_direct_discovery_state_e discovery_state, const char * mac_address, void *user_data)
-{
- __FUNC_ENTER__;
-
- switch (discovery_state) {
- case WIFI_DIRECT_DISCOVERY_FOUND:
- {
- event_printf("event - WIFI_DIRECT_DISCOVERY_FOUND\n");
-
- if (mac_address[0] != '\0') {
- printf("Peer Address is %s", mac_address);
- wifi_direct_discovered_peer_info_s* peer_info = NULL;
-
- wifi_direct_get_peer_info((char *)mac_address, &peer_info);
- if (peer_info != NULL) {
- printf("MAC [%s] Owner=[%s] connected=[%d] SSID[%s] ctg=[%d/%d]",
- peer_info->mac_address,
- peer_info->is_group_owner ? "YES" : "NO",
- peer_info->is_connected,
- peer_info->device_name,
- peer_info->primary_device_type,
- peer_info->secondary_device_type
- );
- g_free(peer_info->mac_address);
- g_free(peer_info->interface_address);
- g_free(peer_info);
- }
- }
- }
- break;
-
- default:
- break;
- }
-}
-
-void _cb_service(int error_code,
- wifi_direct_service_discovery_state_e discovery_state,
- wifi_direct_service_type_e service_type,
- void *response_data, const char * mac_address, void *user_data)
-{
- __FUNC_ENTER__;
-
- switch (discovery_state) {
- case WIFI_DIRECT_SERVICE_DISCOVERY_STARTED:
- event_printf("event - WIFI_DIRECT_SERVICE_DISCOVERY_STARTED\n");
- break;
-
- case WIFI_DIRECT_SERVICE_DISCOVERY_FINISHED:
- event_printf("event - WIFI_DIRECT_SERVICE_DISCOVERY_FINISHED\n");
- break;
-
- case WIFI_DIRECT_SERVICE_DISCOVERY_FOUND:
- {
- event_printf("event - WIFI_DIRECT_SERVICE_DISCOVERY_FOUND\n");
- if (mac_address != NULL)
- printf("Peer Wi-Fi Direct mac address %s\n", mac_address);
- if (response_data != NULL)
- printf("Peer service response %s\n", (char *)response_data);
- if (service_type == WIFI_DIRECT_SERVICE_TYPE_ALL)
- printf("Service type = WIFI_DIRECT_SERVICE_TYPE_ALL\n");
- else if (service_type == WIFI_DIRECT_SERVICE_TYPE_BONJOUR)
- printf("Service type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR\n");
- else if (service_type == WIFI_DIRECT_SERVICE_TYPE_UPNP)
- printf("Service type = WIFI_DIRECT_SERVICE_TYPE_UPNP\n");
- else if (service_type == WIFI_DIRECT_SERVICE_TYPE_BT_ADDR)
- printf("Service type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR\n");
- else if (service_type == WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO)
- printf("service_type == WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO");
- else
- printf("Requested Service !!! NOT FOUND !!!\n");
- }
- break;
-
- default:
- break;
- }
- __FUNC_EXIT__;
-}
-
-void _cb_connection(int error_code, wifi_direct_connection_state_e connection_state, const char* mac_address, void *user_data)
-{
- __FUNC_ENTER__;
- char *ip_addr = NULL;
- bool owner;
-
- switch (connection_state) {
-
- case WIFI_DIRECT_CONNECTION_IN_PROGRESS:
- {
- event_printf("event - WIFI_DIRECT_CONNECTION_IN_PROGRESS\n");
-
- if (error_code == WIFI_DIRECT_ERROR_NONE) {
- char _peer_mac[MACSTR_LEN+1] = {0,};
-
- if (NULL != mac_address)
- g_strlcpy(_peer_mac, mac_address, sizeof(_peer_mac));
-
- printf("Connection start with [%s] \n", _peer_mac);
- event_printf("Error None\n");
-
- {
- wifi_direct_discovered_peer_info_s *peer = NULL;
- if (wifi_direct_get_connecting_peer_info(&peer)
- == WIFI_DIRECT_ERROR_NONE) {
- if (peer == NULL)
- printf("No connecting peer\n");
- else
- printf("Connecting peer info -> device name [%s], mac address [%s]\n",
- peer->device_name,
- peer->mac_address);
- } else {
- printf("failed to get connecting peer info\n");
- }
- g_free(peer);
- }
- }
- }
- break;
-
- case WIFI_DIRECT_CONNECTION_RSP:
- {
- event_printf("event - WIFI_DIRECT_CONNECTION_RSP\n");
-
- if (error_code == WIFI_DIRECT_ERROR_NONE) {
- char incomming_peer_mac[MACSTR_LEN+1] = {0,};
- char status[100] = {0,};
-
- if (NULL != mac_address)
- g_strlcpy(incomming_peer_mac, mac_address, sizeof(incomming_peer_mac));
-
- printf("Connection response with [%s] \n", incomming_peer_mac);
- event_printf("Error None\n");
-
- wifi_direct_is_group_owner(&owner);
- if (owner) {
- wifi_direct_get_ip_address(&ip_addr);
- if (NULL != ip_addr) {
- snprintf(status, sizeof(status), "<color=#FFFFFF>GO - IP : %s", ip_addr);
- free(ip_addr);
- }
-
- } else {
- wifi_direct_get_ip_address(&ip_addr);
- if (NULL != ip_addr) {
- snprintf(status, sizeof(status), "<color=#FFFFFF>STA - IP : %s", ip_addr);
- free(ip_addr);
- }
- }
- } else {
- if (error_code == WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT)
- event_printf("Error Code - WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT\n");
- else if (error_code == WIFI_DIRECT_ERROR_AUTH_FAILED)
- event_printf("Error Code - WIFI_DIRECT_ERROR_AUTH_FAILED\n");
- else if (error_code == WIFI_DIRECT_ERROR_CONNECTION_FAILED)
- event_printf("Error Code - WIFI_DIRECT_ERROR_CONNECTION_FAILED\n");
- }
-
- }
- break;
-
- case WIFI_DIRECT_CONNECTION_WPS_REQ:
- {
- event_printf("event - WIFI_DIRECT_CONNECTION_WPS_REQ\n");
-
- wifi_direct_wps_type_e wps_mode;
-
- int result = wifi_direct_get_local_wps_type(&wps_mode);
- printf("wifi_direct_get_local_wps_type() result=[%d]\n", result);
-
- /* BCMP2P_DISCOVER_ENTRY notification_data; */
- /* memcpy(¬ification_data, pNotificationData, sizeof(notification_data)); */
- if (wps_mode == WIFI_DIRECT_WPS_TYPE_PBC) {
- printf("wps_config is WIFI_DIRECT_WPS_TYPE_PBC\n");
-
- } else if (wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY) {
- printf("wps_config is WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY\n");
- char *pin = NULL;
-
- result = wifi_direct_get_wps_pin(&pin);
- printf("wifi_direct_get_wps_pin() result=[%d]\n", result);
- if (NULL != pin) {
- printf("WPS_PIN [%s]\n", pin);
- free(pin);
- } else
- printf("WPS_PIN is NULL !! \n");
-
- } else if (wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) {
- printf("wps_config is WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n");
- char pin[9] = { 0, };
- int l_result = WIFI_DIRECT_ERROR_NONE;
- struct appdata *ad = (struct appdata *) user_data;
-
- memset(pin, 0x00, sizeof(pin));
- printf("Input 8 digit PIN number :\n");
- if (scanf(" %8s", pin) < 1)
- break;
-
- l_result = wifi_direct_set_wps_pin(pin);
- if (l_result == WIFI_DIRECT_ERROR_NONE) {
- int i;
-
- if (NULL == ad) {
- printf("ERROR : ad is NULL!!!\n");
- break;
- }
-
- i = ad->selected_peer_index;
- wifi_direct_discovered_peer_info_s* list = ad->peer_list;
-
- l_result = wifi_direct_accept_connection(list[i].mac_address);
- printf("wifi_direct_accept_connection() result=[%d]\n", l_result);
- } else
- printf("wifi_direct_set_wps_pin Error [%d]\n", l_result);
- } else
- printf("wps_config is unknown!\n");
- }
- break;
-
- case WIFI_DIRECT_CONNECTION_REQ:
- {
- event_printf("event - WIFI_DIRECT_CONNECTION_REQ\n");
- char incomming_peer_mac[MACSTR_LEN+1];
- wifi_direct_wps_type_e wps_mode;
- bool auto_connection_mode;
- bool allow_connection = FALSE;
- int result;
-
- memset(incomming_peer_mac, 0, sizeof(incomming_peer_mac));
-
- if (NULL != mac_address)
- g_strlcpy(incomming_peer_mac, mac_address, sizeof(incomming_peer_mac));
-
- printf("Connection Request from [%s] \n", incomming_peer_mac);
-
- result = wifi_direct_get_local_wps_type(&wps_mode);
- printf("wifi_direct_get_local_wps_type() result=[%d]\n", result);
-
- result = wifi_direct_is_autoconnection_mode(&auto_connection_mode);
- printf("wifi_direct_is_autoconnection_mode() result=[%d]\n", result);
-
- if (auto_connection_mode == TRUE) {
- result = wifi_direct_accept_connection(incomming_peer_mac);
- printf("wifi_direct_accept_connection() result=[%d]\n", result);
- break;
- }
-
- char pushbutton;
- printf("************\n");
- printf("Connect? (Y/N)\n");
- printf("*************\n");
- if (scanf(" %c", &pushbutton) < 1)
- break;
-
- allow_connection = (pushbutton == 'Y') || (pushbutton == 'y');
- if (!allow_connection) {
- result = wifi_direct_reject_connection(incomming_peer_mac);
- printf("wifi_direct_reject_connection() result=[%d]\n", result);
- break;
- }
-
- if (wps_mode == WIFI_DIRECT_WPS_TYPE_PBC) {
- printf("wps_config is WIFI_DIRECT_WPS_TYPE_PBC\n");
- } else if (wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY) {
- char *pin = NULL;
- printf("wps_config is WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY\n");
- result = wifi_direct_get_wps_pin(&pin);
- printf("wifi_direct_get_wps_pin() result=[%d]\n", result);
- if (NULL != pin) {
- printf("WPS_PIN [%s]\n\n", pin);
- free(pin);
- } else
- printf("WPS_PIN is NULL !! \n");
- } else if (wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) {
- printf("wps_config is WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n");
-
- char pin[9] = { 0, };
-
- memset(pin, 0x00, sizeof(pin));
- printf("*********************\n");
- printf("Input 8 digit PIN number :\n");
- printf("*********************\n");
- if (scanf(" %8s", pin) < 1)
- break;
-
- if (strlen(pin) > 0) {
- result = wifi_direct_set_wps_pin(pin);
- printf("wifi_direct_set_wps_pin() result=[%d]\n", result);
- } else
- printf("Invalid PIN number\n");
-
- } else {
- printf("wps_config is unknown!\n");
- break;
- }
- result = wifi_direct_accept_connection(incomming_peer_mac);
- printf("wifi_direct_accept_connection() result=[%d]\n", result);
- }
- break;
-
- case WIFI_DIRECT_DISCONNECTION_IND:
- {
- event_printf("event - WIFI_DIRECT_DISCONNECTION_IND\n");
-
- if (error_code == WIFI_DIRECT_ERROR_NONE) {
- char incomming_peer_mac[MACSTR_LEN+1] = {0,};
-
- if (NULL != mac_address)
- g_strlcpy(incomming_peer_mac, mac_address, sizeof(incomming_peer_mac));
-
- printf("Disconnection IND from [%s] \n", incomming_peer_mac);
-
- event_printf("Error None\n");
- }
-
- }
- break;
-
- case WIFI_DIRECT_DISCONNECTION_RSP:
- {
- event_printf("event - WIFI_DIRECT_DISCONNECTION_RSP\n");
-
- if (error_code == WIFI_DIRECT_ERROR_NONE) {
- char incomming_peer_mac[MACSTR_LEN+1] = {0,};
-
- if (NULL != mac_address)
- g_strlcpy(incomming_peer_mac, mac_address, sizeof(incomming_peer_mac));
-
- printf("Disconnection RSP with [%s] \n", incomming_peer_mac);
-
- event_printf("Error None\n");
- }
-
- }
- break;
-
- case WIFI_DIRECT_DISASSOCIATION_IND:
- {
- event_printf("event - WIFI_DIRECT_DISASSOCIATION_IND\n");
-
- if (error_code == WIFI_DIRECT_ERROR_NONE) {
- char incomming_peer_mac[MACSTR_LEN+1] = {0,};
-
- if (NULL != mac_address)
- g_strlcpy(incomming_peer_mac, mac_address, sizeof(incomming_peer_mac));
-
- printf("Disassociation IND from [%s] \n", incomming_peer_mac);
-
- event_printf("Error None\n");
- }
- }
- break;
-
- case WIFI_DIRECT_GROUP_CREATED:
- {
- event_printf("event - WIFI_DIRECT_GROUP_CREATED\n");
- }
- break;
-
- case WIFI_DIRECT_GROUP_DESTROYED:
- {
- event_printf("event - WIFI_DIRECT_GROUP_DESTROYED\n");
- }
- break;
-
- default:
- break;
-
- }
-
- __FUNC_EXIT__;
-}
-
-
-void _cb_ip_assigned(const char* mac_address, const char* ip_address, const char* interface_address, void *user_data)
-{
- __FUNC_ENTER__;
-
- if (NULL != mac_address)
- printf("mac_address [%s] \n", mac_address);
- else
- printf("mac_address is NULL !!\n");
-
- if (NULL != ip_address)
- printf("ip_address [%s] \n", ip_address);
- else
- printf("ip_address is NULL !!\n");
-
- if (NULL != interface_address)
- printf("interface_address [%s] \n", interface_address);
- else
- printf("interface_address is NULL !!\n");
-
- __FUNC_EXIT__;
-
-}
-
-bool _cb_foreach_supported_wps_impl(wifi_direct_wps_type_e type, void* user_data)
-{
- __FUNC_ENTER__;
-
- switch (type) {
- case WIFI_DIRECT_WPS_TYPE_PBC:
- printf("type=[WIFI_DIRECT_WPS_TYPE_PBC]\n");
- break;
- case WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY:
- printf("type=[WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY]\n");
- break;
- case WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD:
- printf("type=[WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD]\n");
- break;
- default:
- printf("ERROR : type=[%d]\n", type);
- break;
- }
-
- return true; /* continue with the next iteration of the loop */
-}
-
-void _cb_state_changed(wifi_direct_state_e state,
- void *user_data)
-{
- printf("State Changed [%s]\n", print_link_state(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;
-
- ret = wifi_direct_initialize();
- printf("wifi_direct_initialize() result=[%d]\n", ret);
-
- ret = wifi_direct_set_device_state_changed_cb(_cb_activation, (void*)ad);
- printf("wifi_direct_set_device_state_changed_cb() result=[%d]\n", ret);
-
- ret = wifi_direct_set_discovery_state_changed_cb(_cb_discover, (void*)ad);
- printf("wifi_direct_set_discovery_state_changed_cb() result=[%d]\n", ret);
-
- ret = wifi_direct_set_connection_state_changed_cb(_cb_connection, (void*)ad);
- printf("wifi_direct_set_connection_state_changed_cb() result=[%d]\n", ret);
-
- ret = wifi_direct_set_client_ip_address_assigned_cb(_cb_ip_assigned, (void*)ad);
- printf("wifi_direct_set_client_ip_address_assigned_cb() result=[%d]\n", ret);
-
- ret = wifi_direct_set_service_state_changed_cb(_cb_service, (void*)ad);
- printf("wifi_direct_set_service_state_changed_cb() result=[%d]\n", ret);
-
- ret = wifi_direct_set_peer_found_cb(_cb_peer_found, (void*)ad);
- printf("wifi_direct_set_peer_found_cb() result=[%d]\n", ret);
-
- 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;
-}
-
-void process_input(const char *input, gpointer user_data)
-{
- struct appdata *ad = (struct appdata *) user_data;
- int result = -1;
- int cmd = strtol(input, NULL, 0);
-
- if (is_digit(input) < 0 || strlen(input) == 0 || errno == ERANGE || errno
- == EINVAL)
- cmd = CMD_INVALID;
-
- printf("cmd=[%d]\n", cmd);
-
- switch (cmd) {
- case CMD_INITIALIZE:
- {
- result = init_wfd_client(ad);
- printf("init_wfd_client() result=[%d]\n", result);
- }
- break;
-
- case CMD_SET_ACTIVATION_CB:
- {
- result = wifi_direct_set_device_state_changed_cb(_cb_activation, (void*)ad);
- printf("wifi_direct_set_device_state_changed_cb() result=[%d]\n", result);
- }
- break;
-
- case CMD_UNSET_ACTIVATION_CB:
- {
- result = wifi_direct_unset_device_state_changed_cb();
- printf("wifi_direct_unset_device_state_changed_cb() result=[%d]\n", result);
- }
- break;
-
- case CMD_SET_DISCOVER_CB:
- {
- result = wifi_direct_set_discovery_state_changed_cb(_cb_discover, (void*)ad);
- printf("wifi_direct_set_discovery_state_changed_cb() result=[%d]\n", result);
- }
- break;
-
- case CMD_UNSET_DISCOVER_CB:
- {
- result = wifi_direct_unset_discovery_state_changed_cb();
- printf("wifi_direct_unset_discovery_state_changed_cb() result=[%d]\n", result);
- }
- break;
-
- case CMD_SET_CONNECTION_CB:
- {
- result = wifi_direct_set_connection_state_changed_cb(_cb_connection, (void*)ad);
- printf("wifi_direct_set_connection_state_changed_cb() result=[%d]\n", result);
-
- 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;
-
- case CMD_UNSET_CONNECTION_CB:
- {
- result = wifi_direct_unset_connection_state_changed_cb();
- printf("wifi_direct_unset_connection_state_changed_cb() result=[%d]\n", result);
-
- 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;
-
- case CMD_SET_IP_ADDR_ASSIGNED_CB:
- {
- result = wifi_direct_set_client_ip_address_assigned_cb(_cb_ip_assigned, (void*)ad);
- printf("wifi_direct_set_client_ip_address_assigned_cb() result=[%d]\n", result);
- }
- break;
-
- case CMD_UNSET_IP_ADDR_ASSIGNED_CB:
- {
- result = wifi_direct_unset_client_ip_address_assigned_cb();
- printf("wifi_direct_unset_client_ip_address_assigned_cb() result=[%d]\n", result);
- }
- break;
-
- case CMD_SET_SERVICE_CB:
- {
- result = wifi_direct_set_service_state_changed_cb(_cb_service, (void*)ad);
- printf("wifi_direct_set_service_state_changed_cb() result=[%d]\n", result);
- }
- break;
-
- case CMD_UNSET_SERVICE_CB:
- {
- result = wifi_direct_unset_service_state_changed_cb();
- printf("wifi_direct_unset_service_changed_cb() result=[%d]\n", result);
- }
- break;
-
- case CMD_SET_PEER_FOUND_CB:
- {
- result = wifi_direct_set_peer_found_cb(_cb_peer_found, (void*)ad);
- printf("wifi_direct_set_peer_found_cb() result=[%d]\n", result);
- }
- break;
-
- case CMD_UNSET_PEER_FOUND_CB:
- {
- result = wifi_direct_unset_peer_found_cb();
- printf("wifi_direct_unset_peer_found_cb() result=[%d]\n", result);
- }
- break;
- case CMD_SET_STATE_CB:
- {
- result = wifi_direct_set_state_changed_cb(_cb_state_changed, (void*)ad);
- printf("wifi_direct_set_state_changed_cb() result=[%d]\n", result);
- }
- break;
- case CMD_UNSET_STATE_CB:
- {
- result = wifi_direct_unset_state_changed_cb();
- printf("wifi_direct_unset_state_changed_cb() result=[%d]\n", result);
- }
- break;
- case CMD_DEINITIALIZE:
- result = wifi_direct_deinitialize();
- printf("wifi_direct_deinitialize() result=[%d]\n", result);
- break;
- case CMD_ACTIVATE_WIFI_DIRECT:
- if (ad != NULL) {
- result = wifi_direct_activate();
- printf("wifi_direct_activate() result=[%d]\n", result);
-
- if (result == WIFI_DIRECT_ERROR_WIFI_USED)
- printf(" ERROR : WIFI_DIRECT_ERROR_WIFI_USED \n");
- else if (result == WIFI_DIRECT_ERROR_MOBILE_AP_USED)
- printf(" ERROR : WIFI_DIRECT_ERROR_MOBILE_AP_USED \n");
-
- }
- break;
-
- case CMD_DEACTIVATE_WIFI_DIRECT:
- if (ad != NULL) {
- result = wifi_direct_deactivate();
- printf("wifi_direct_deactivate() result=[%d]\n", result);
- }
- break;
-
- case CMD_START_DISCOVER_WITH_LISTEN_ONLY:
- if (ad != NULL) {
- result = wifi_direct_start_discovery(TRUE, 15);
- printf("wifi_direct_start_discovery() listen_only=[true] result=[%d]\n", result);
- }
- break;
-
- case CMD_START_DISCOVER:
- if (ad != NULL) {
- /* result = wifi_direct_start_discovery(FALSE, 15); */
- result = wifi_direct_start_discovery(FALSE, 0);
- printf("wifi_direct_start_discovery() listen_only=[false] result=[%d]\n", result);
- }
- break;
-
- case CMD_START_DISCOVER_SPECIFIC_CHANNEL:
- if (ad != NULL) {
- int input_discovery_channel;
- printf("Select Discovery Channel :\n");
- printf("1. WIFI_DIRECT_DISCOVERY_FULL_SCAN\n");
- printf("2. WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL\n");
- printf("3. WIFI_DIRECT_DISCOVERY_CHANNEL1\n");
- printf("4. WIFI_DIRECT_DISCOVERY_CHANNEL6\n");
- printf("5. WIFI_DIRECT_DISCOVERY_CHANNEL11\n");
- if (scanf(" %1d", &input_discovery_channel) < 1)
- break;
-
- switch (input_discovery_channel) {
- case 1:
- {
- result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_FULL_SCAN);
- printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_FULL_SCAN, result);
- }
- break;
- case 2:
- {
- result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL);
- printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL, result);
- }
- break;
- case 3:
- {
- result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_CHANNEL1);
- printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_CHANNEL1, result);
- }
- break;
- case 4:
- {
- result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_CHANNEL6);
- printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_CHANNEL6, result);
- }
- break;
- case 5:
- {
- result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_CHANNEL11);
- printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_CHANNEL11, result);
- }
- break;
- default:
- printf("ERROR : Invalid Channel !!!\n");
- break;
- }
-
- }
- break;
-
- case CMD_START_DISCOVER_SPECIFIC_FREQUENCY:
- if (ad != NULL) {
- int frequency;
- printf("Enter discover frequency :\n");
- if (scanf(" %5d", &frequency) < 1)
- break;
-
- result = wifi_direct_start_discovery_specific_freq(FALSE, 2, frequency);
- printf("wifi_direct_start_discovery_specific_freq() frequency=[%d] result=[%d]\n", frequency, result);
- }
- break;
-
- case CMD_CANCEL_DISCOVER:
- if (ad != NULL) {
- result = wifi_direct_cancel_discovery();
- printf("wifi_direct_cancel_discovery() result=[%d]\n", result);
- }
- break;
- case CMD_GET_DISVOCERY_RESULT:
- if (ad != NULL) {
- memset(ad->peer_list, 0x00, sizeof(wifi_direct_discovered_peer_info_s)*MAX_PEER_NUM);
- ad->peer_count = 0;
- ad->selected_peer_index = 0;
-
- result = wifi_direct_foreach_discovered_peers(_cb_discovered_peers_impl, (void*)ad);
- printf("wifi_direct_foreach_discovered_peers() ret=[%d]\n", result);
-
- print_peers(ad);
- }
- break;
-
- case CMD_SEND_CONNECTION_REQ:
- if (ad != NULL) {
- if (select_peer(ad)) {
- int i = ad->selected_peer_index;
- wifi_direct_discovered_peer_info_s* list = ad->peer_list;
-
- result = wifi_direct_accept_connection(list[i].mac_address);
-
- printf("Connecting... peer-index[%d] MAC [%s] Owner=[%s] SSID[%s]\n",
- i,
- list[i].mac_address,
- list[i].is_group_owner ? "YES" : "NO",
- list[i].device_name);
-
- printf("wifi_direct_accept_connection() result=[%d]\n", result);
- }
- }
- break;
-
- case CMD_DISCONNECT_ALL:
- if (ad != NULL) {
- result = wifi_direct_disconnect_all();
- printf("wifi_direct_disconnect_all() result=[%d]\n", result);
- }
- break;
-
- case CMD_DISCONNECT:
- if (ad != NULL) {
- if (select_connected_peer(ad)) {
- int i = ad->selected_peer_index;
- wifi_direct_connected_peer_info_s* list = ad->connected_peer_list;
-
- result = wifi_direct_disconnect(list[i].mac_address);
-
- printf("Disconnecting... peer-index[%d] MAC [%s] SSID[%s]\n",
- i,
- list[i].mac_address,
- list[i].device_name);
-
- printf("wifi_direct_disconnect() result=[%d]\n", result);
- }
- }
- break;
-
-
- case CMD_GET_LINK_STATUS:
- if (ad != NULL) {
- wifi_direct_state_e status = 0;
- result = wifi_direct_get_state(&status);
- printf("wifi_direct_get_state() state=[%s(%d)], result=[%d]\n", print_link_state(status), status, result);
- }
- break;
-
- case CMD_CONNECT_PEER:
- if (ad != NULL) {
- if (select_peer(ad)) {
- wifi_direct_wps_type_e wps_mode;
-
- result = wifi_direct_get_local_wps_type(&wps_mode);
- printf("wifi_direct_get_local_wps_type() result=[%d]\n", result);
-
- if (wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD)
- printf("wifi_direct_generate_wps_pin() result=[%d]\n", result);
-
- int i = ad->selected_peer_index;
- wifi_direct_discovered_peer_info_s* list = ad->peer_list;
-
- result = wifi_direct_connect(list[i].mac_address);
-
- printf("Connecting... peer-index[%d] MAC [%s] Owner=[%s] SSID[%s]\n",
- i,
- list[i].mac_address,
- list[i].is_group_owner ? "YES" : "NO",
- list[i].device_name);
-
- printf("wifi_direct_connect() result=[%d]\n", result);
-
- }
- }
- break;
-
- case CMD_CANCEL_CONNECTION:
- if (ad != NULL) {
- if (select_peer(ad)) {
- int i = ad->selected_peer_index;
- wifi_direct_discovered_peer_info_s* list = ad->peer_list;
-
- result = wifi_direct_cancel_connection(list[i].mac_address);
- printf("wifi_direct_cancel_connection() result=[%d]\n", result);
- }
- }
- break;
-
- case CMD_ENABLE_PUSH_BUTTON:
- if (ad != NULL) {
- result = wifi_direct_activate_pushbutton();
- printf("wifi_direct_activate_pushbutton() result=[%d]\n", result);
- }
- break;
-
- case CMD_CREATE_GROUP:
- if (ad != NULL) {
- result = wifi_direct_create_group();
- printf("wifi_direct_create_group() result=[%d]\n", result);
- }
- break;
-
- case CMD_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();
- printf("wifi_direct_destroy_group() result=[%d]\n", result);
- }
- break;
-
- case CMD_IS_GROUP_OWNER:
- if (ad != NULL) {
- bool is_group_owner;
- result = wifi_direct_is_group_owner(&is_group_owner);
- printf("wifi_direct_is_group_owner() is GO[%d] result=[%d]\n", is_group_owner, result);
- }
- break;
- case CMD_REJECT:
- if (ad != NULL) {
- /* result = wifi_direct_client_reject(); */
- printf("Under construction...\n");
- }
- break;
-
- case CMD_INVITE:
- if (ad != NULL) {
- /* result = wifi_direct_client_invite(); */
- printf("Under construction...\n");
- }
- break;
-
- case CMD_SET_DEVICE_NAME:
- {
- if (ad != NULL) {
- char *device_name = NULL;
-
- printf("Input device name :\n");
- if (scanf(" %33ms", &device_name) < 1)
- break;
-
- if (strlen(device_name) <= 0)
- printf("invalid device name !!\n");
- else
- printf("device_name: [%s]\n", device_name);
-
- if ((strlen(device_name) > 0)) {
- result = wifi_direct_set_device_name(device_name);
- printf("wifi_direct_set_device_name() ret=[%d]\n", result);
- }
-
- free(device_name);
- }
- }
- break;
-
- case CMD_GET_DEVICE_NAME:
- {
- if (ad != NULL) {
- char* device_name = NULL;
-
- result = wifi_direct_get_device_name(&device_name);
- printf("wifi_direct_get_device_name() result=[%d]\n", result);
-
- if (NULL != device_name) {
- printf("ssid: [%s]\n", device_name);
- free(device_name);
- }
-
- }
- }
- break;
-
- case CMD_GET_SSID:
- {
- if (ad != NULL) {
- char* ssid = NULL;
-
- result = wifi_direct_get_ssid(&ssid);
- printf("wifi_direct_get_ssid() result=[%d]\n", result);
-
- if (NULL != ssid) {
- printf("ssid: [%s]\n", ssid);
- free(ssid);
- }
-
- }
- }
- break;
-
- case CMD_SET_CHANNEL:
- case CMD_SET_WPS_CONFIG:
- break;
-
- case CMD_SET_MAX_CLIENT:
- if (ad != NULL) {
- int max_client;
-
- wifi_direct_get_max_clients(&max_client);
- printf("Current max client=[%d]\n", max_client);
- printf("Input new max client:\n");
-
- if (scanf(" %4d", &max_client))
- break;
-
- result = wifi_direct_set_max_clients(max_client);
-
- printf("wifi_direct_set_max_clients() result=[%d] max_client[%d]\n", result, max_client);
- }
- break;
-
- case CMD_GET_MAX_CLIENT:
- if (ad != NULL) {
- int max_client;
-
- result = wifi_direct_get_max_clients(&max_client);
- printf("wifi_direct_get_max_clients() result=[%d] max_client[%d]\n", result, max_client);
- }
- break;
-
- case CMD_SET_HIDE_SSID:
- break;
-
- case CMD_ACTIVATE_PERSISTENT_GROUP:
- if (ad != NULL) {
- result = wifi_direct_set_persistent_group_enabled(true);
-
- if (result != WIFI_DIRECT_ERROR_NONE)
- printf("Failed to wifi_direct_set_persistent_group_enabled() result=[%d]\n", result);
- else
- printf("wifi_direct_set_persistent_group_enabled() result=[%d]\n", result);
- }
- break;
-
- case CMD_DEACTIVATE_PERSISTENT_GROUP:
- if (ad != NULL) {
- result = wifi_direct_set_persistent_group_enabled(false);
-
- if (result != WIFI_DIRECT_ERROR_NONE)
- printf("Failed to wifi_direct_set_persistent_group_enabled() result=[%d]\n", result);
- else
- printf("wifi_direct_set_persistent_group_enabled() result=[%d]\n", result);
- }
- break;
-
- case CMD_IS_PERSISTENT_GROUP_ACTIVATED:
- if (ad != NULL) {
- bool enabled;
-
- result = wifi_direct_is_persistent_group_enabled(&enabled);
- printf("wifi_direct_is_persistent_group_enabled() result=[%d]\n", result);
- if (enabled == TRUE)
- printf("Persistent Group mode!! \n");
- else
- printf("NOT Persistent group mode!! \n");
- }
- break;
-
-
- case CMD_GET_PERSISTENT_GROUP_LIST:
- if (ad != NULL) {
- result = wifi_direct_foreach_persistent_groups(_cb_persistent_groups_impl, (void*)ad);
- printf("wifi_direct_foreach_persistent_groups() ret=[%d]\n", result);
- }
- break;
-
- case CMD_REMOVE_PERSISTENT_GROUP:
- if (ad != NULL) {
- char *mac = NULL;
- char *ssid = NULL;
-
- printf("Input GO MAC :\n");
- if (scanf(" %18ms", &mac) < 1)
- break;
-
- if (strlen(mac) <= 0)
- printf("invalid GO MAC !!\n");
- else
- printf("GO MAC: [%s]\n", mac);
-
- printf("Input ssid :\n");
- if (scanf(" %33ms", &ssid) < 1) {
- free(mac);
- break;
- }
-
- if (strlen(ssid) <= 0)
- printf("invalid ssid !!\n");
- else
- printf("ssid: [%s]\n", ssid);
-
- if ((strlen(mac) > 0) && (strlen(ssid) > 0)) {
- result = wifi_direct_remove_persistent_group(mac, ssid);
- printf("wifi_direct_remove_persistent_group() ret=[%d]\n", result);
- }
-
- free(mac);
- free(ssid);
- }
- break;
-
- case CMD_SET_AUTO_CONNECTION:
- if (ad != NULL) {
- int autoconnection_mode;
-
- printf("Input Auto connection: \n");
- printf("[1] true [2] false\n");
-
- if (scanf(" %1d", &autoconnection_mode) < 1)
- break;
-
- if (autoconnection_mode == 1)
- result = wifi_direct_set_autoconnection_mode(true);
- else if (autoconnection_mode == 2)
- result = wifi_direct_set_autoconnection_mode(false);
- else
- printf("Invalid input parameter!!!\n");
-
- printf("wifi_direct_set_autoconnection_mode() result=[%d] \n", result);
-
- }
- break;
-
- case CMD_IS_AUTO_CONNECTION:
- if (ad != NULL) {
- bool auto_connection = false;
-
- result = wifi_direct_is_autoconnection_mode(&auto_connection);
- printf("wifi_direct_is_autoconnection_mode() result=[%d]\n", result);
- if (auto_connection == TRUE)
- printf("Auto connection mode !! \n");
- else
- printf("NOT Auto connection mode !! \n");
-
- }
- break;
-
- case CMD_SET_WPS_PIN:
- if (ad != NULL) {
- char *pin = NULL;
-
- printf("Input PIN number :\n");
- if (scanf(" %9ms", &pin) < 1)
- break;
-
- printf("New PIN: [%s]\n", pin);
-
- if ((strlen(pin) > 0) && (strlen(pin) < 9))
- wifi_direct_set_wps_pin(pin);
- else
- printf("Invalid PIN number\n");
-
- free(pin);
- }
- break;
-
- case CMD_GET_WPS_PIN:
- if (ad != NULL) {
- char *pin = NULL;
-
- result = wifi_direct_get_wps_pin(&pin);
- printf("wifi_direct_get_wps_pin() result=[%d]\n", result);
- if (NULL != pin) {
- printf("WPS_PIN [%s]\n", pin);
- free(pin);
- } else
- printf("WPS_PIN is NULL !! \n");
- }
- break;
-
- case CMD_GET_SUPPORTED_WPS_MODE:
- if (ad != NULL) {
- int supported_wps_mode = 0;
-
- result = wifi_direct_foreach_supported_wps_types(_cb_foreach_supported_wps_impl, NULL);
- printf("wifi_direct_foreach_supported_wps_types() result=[%d]\n", result);
-
- result = wifi_direct_get_supported_wps_mode(&supported_wps_mode);
- printf("wifi_direct_foreach_supported_wps_types() supported=[%d] result=[%d]\n", supported_wps_mode, result);
- }
- break;
-
- case CMD_SET_CURRENT_WPS_MODE:
- if (ad != NULL) {
- wifi_direct_wps_type_e wps_mode;
- int input_wps_mode;
-
- result = wifi_direct_get_req_wps_type(&wps_mode);
- switch (wps_mode) {
- case WIFI_DIRECT_WPS_TYPE_PBC:
- printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PBC]\n");
- break;
- case WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY:
- printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY]\n");
- break;
- case WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD:
- printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD]\n");
- break;
- default:
- printf("ERROR : wps_mode=[%d]\n", wps_mode);
- break;
- }
-
- printf("Input new wps mode:\n");
- printf("1. WIFI_DIRECT_WPS_TYPE_PBC\n");
- printf("2. WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY\n");
- printf("3. WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n");
- if (scanf(" %1d", &input_wps_mode) < 1)
- break;
-
- switch (input_wps_mode) {
- case 1:
- wps_mode = WIFI_DIRECT_WPS_TYPE_PBC;
- break;
- case 2:
- wps_mode = WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY;
- break;
- case 3:
- wps_mode = WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD;
- break;
- default:
- printf("ERROR : Invalid input wps_mode!!!\n");
- break;
- }
-
- result = wifi_direct_set_req_wps_type(wps_mode);
- printf("wifi_direct_set_wps_type() result=[%d]\n", result);
- }
- break;
-
- case CMD_GET_CURRENT_WPS_MODE:
- if (ad != NULL) {
- wifi_direct_wps_type_e wps_mode;
- result = wifi_direct_get_req_wps_type(&wps_mode);
- printf("wifi_direct_get_wps_type() wps_mode=[%d], result=[%d]\n", wps_mode, result);
- switch (wps_mode) {
- case WIFI_DIRECT_WPS_TYPE_PBC:
- printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PBC]\n");
- break;
- case WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY:
- printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY]\n");
- break;
- case WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD:
- printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD]\n");
- break;
- default:
- printf("ERROR : wps_mode=[%d]\n", wps_mode);
- break;
- }
-
- }
- break;
-
- case CMD_GET_CONNECTED_PEERS_INFO:
- if (ad != NULL) {
- memset(ad->connected_peer_list, 0x00, sizeof(wifi_direct_connected_peer_info_s)*MAX_PEER_NUM);
- ad->connected_peer_count = 0;
-
- result = wifi_direct_foreach_connected_peers(_cb_connected_peers_impl, (void*)ad);
- printf("wifi_direct_foreach_connected_peers() ret=[%d]\n", result);
- print_peers_connected(ad);
- }
- break;
-
- case CMD_GET_GO_INTENT:
- if (ad != NULL) {
- int go_intent;
-
- result = wifi_direct_get_group_owner_intent(&go_intent);
- printf("wifi_direct_get_group_owner_intent() result=[%d] go_intent[%d]\n", result, go_intent);
- }
- break;
-
- case CMD_SET_GO_INTENT:
- if (ad != NULL) {
- int go_intent;
-
- wifi_direct_get_group_owner_intent(&go_intent);
- printf("Current GO intent=[%d]\n", go_intent);
- printf("Input new GO intent [0~15]:\n");
-
- if (scanf(" %2d", &go_intent) < 1)
- break;
-
- result = wifi_direct_set_group_owner_intent(go_intent);
-
- printf("wifi_direct_set_group_owner_intent() result=[%d] go_intent[%d]\n", result, go_intent);
- }
- break;
-
- case CMD_GET_DEVICE_MAC:
- if (ad != NULL) {
- char *device_mac = NULL;
-
- result = wifi_direct_get_mac_address(&device_mac);
- printf("wifi_direct_get_mac_addr() result=[%d]\n", result);
- if (NULL != device_mac) {
- printf("MAC [%s] \n", device_mac);
- free(device_mac);
- } else
- printf("device_mac is NULL !! \n");
- }
- break;
-
- case CMD_IS_AUTONOMOUS_GROUP:
- if (ad != NULL) {
- bool autonomous_group;
-
- result = wifi_direct_is_autonomous_group(&autonomous_group);
- printf("wifi_direct_is_autonomous_group() result=[%d]\n", result);
- if (autonomous_group == TRUE)
- printf("Autonomous Group !! \n");
- else
- printf("NOT Autonomous group !! \n");
-
- }
- break;
-
- case CMD_GET_NETWORK_IF_NAME:
- if (ad != NULL) {
- char* name = NULL;
-
- result = wifi_direct_get_network_interface_name(&name);
- printf("wifi_direct_get_network_interface_name() result=[%d]\n", result);
-
- if (NULL != name) {
- printf("name: [%s]\n", name);
- free(name);
- }
-
- }
- break;
-
- case CMD_GET_SUBNET_MASK:
- if (ad != NULL) {
- char* subnet_mask = NULL;
-
- result = wifi_direct_get_subnet_mask(&subnet_mask);
- printf("wifi_direct_get_subnet_mask() result=[%d]\n", result);
-
- if (NULL != subnet_mask) {
- printf("subnet_mask: [%s]\n", subnet_mask);
- free(subnet_mask);
- }
-
- }
- break;
-
-
- case CMD_GET_GATEWAY_ADDR:
- if (ad != NULL) {
- char* gateway_address = NULL;
-
- result = wifi_direct_get_gateway_address(&gateway_address);
- printf("wifi_direct_get_gateway_address() result=[%d]\n", result);
-
- if (NULL != gateway_address) {
- printf("gateway_address: [%s]\n", gateway_address);
- free(gateway_address);
- }
-
- }
- break;
-
- case CMD_IS_DISCOVERABLE:
- if (ad != NULL) {
- bool discoverable = false;
-
- result = wifi_direct_is_discoverable(&discoverable);
- printf("wifi_direct_is_discoverable() result=[%d]\n", result);
- if (discoverable == TRUE)
- printf("Discoverable state !! \n");
- else
- printf("NOT Discoverable state !! \n");
-
- }
- break;
-
- case CMD_IS_LISTEN_ONLY:
- if (ad != NULL) {
- bool listen_only = false;
-
- result = wifi_direct_is_listening_only(&listen_only);
- printf("wifi_direct_is_listening_only() result=[%d]\n", result);
- if (listen_only == TRUE)
- printf("Listen only state !! \n");
- else
- printf("NOT Listen only state !! \n");
-
- }
- break;
-
- case CMD_GET_PRIMARY_DEVICE_TYPE:
- if (ad != NULL) {
- wifi_direct_primary_device_type_e type;
-
- result = wifi_direct_get_primary_device_type(&type);
-
- printf("wifi_direct_get_primary_device_type() result=[%d]\n", result);
- printf("Primary Device TYPE [%d]\n", type);
-
- }
- break;
-
- case CMD_GET_SECONDARY_DEVICE_TYPE:
- if (ad != NULL) {
- wifi_direct_secondary_device_type_e type;
-
- result = wifi_direct_get_secondary_device_type(&type);
-
- printf("wifi_direct_get_secondary_device_type() result=[%d]\n", result);
- printf("Secondary Device TYPE [%d]\n", type);
- }
- break;
-
- case CMD_GET_OPERATING_CHANNEL:
- if (ad != NULL) {
- int operating_channel;
-
- result = wifi_direct_get_operating_channel(&operating_channel);
-
- printf("wifi_direct_get_own_group_channel() result=[%d]\n", result);
- printf("Operating Channel [%d]\n", operating_channel);
-
- }
- break;
-
- case CMD_GET_IP_ADDR:
- {
- if (ad != NULL) {
- char* ip_addr = NULL;
-
- result = wifi_direct_get_ip_address(&ip_addr);
- printf("wifi_direct_get_ip_address() result=[%d]\n", result);
- if (NULL != ip_addr) {
- printf("IP [%s]\n", ip_addr);
- free(ip_addr);
- } else {
- printf("IP is NULL\n");
- }
- }
- }
- break;
- case CMD_REGISTER_SERVICE:
- if (ad != NULL) {
- wifi_direct_service_type_e service_type = WIFI_DIRECT_SERVICE_TYPE_ALL;
- unsigned int input_service_type;
- unsigned int registered_service_id;
- char *info1 = NULL;
- char *info2 = NULL;
- char *str = NULL;
-
- printf("Input service type:\n");
- printf("1. WIFI_DIRECT_SERVICE_TYPE_ALL\n");
- printf("2. WIFI_DIRECT_SERVICE_TYPE_BONJOUR\n");
- printf("3. WIFI_DIRECT_SERVICE_TYPE_UPNP\n");
- printf("4. WIFI_DIRECT_SERVICE_TYPE_BT_ADDR\n");
- printf("5. WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO\n");
- if (scanf(" %1u", &input_service_type) < 1)
- break;
- printf("input = %u\n", input_service_type);
-
- switch (input_service_type) {
- case 1:
- service_type = WIFI_DIRECT_SERVICE_TYPE_ALL;
- break;
- case 2:
- service_type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR;
- printf("Enter info 1\n");
- if (scanf(" %50ms", &info1) < 1)
- break;
-
- printf("Enter info 2\n");
- if (scanf(" %50ms", &info2) < 1) {
- free(info1);
- info1 = NULL;
- }
-
- break;
- case 3:
- service_type = WIFI_DIRECT_SERVICE_TYPE_UPNP;
- printf("Enter info 1\n");
- if (scanf(" %50ms", &info1) < 1)
- break;
-
- printf("Enter info 2\n");
- if (scanf(" %50ms", &info2) < 1) {
- free(info1);
- info1 = NULL;
- }
-
- break;
- case 4:
- service_type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR;
- break;
- case 5:
- service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO;
- printf("Enter contact info\n");
- if (scanf(" %50ms", &str) < 1)
- break;
- info1 = str;
- break;
- default:
- printf("ERROR : Invalid input service_type!!!\n");
- break;
- }
-
- result = wifi_direct_register_service(service_type, info1, info2,
- ®istered_service_id);
- printf("wifi_direct_register_service() service id=[%u] result=[%d]\n",
- registered_service_id, result);
- if (info1)
- free(info1);
- free(info2);
- }
- break;
-
- case CMD_DEREGISTER_SERVICE:
- if (ad != NULL) {
- int input_service_id;
-
- printf("Enter service id:\n");
- if (scanf(" %5d", &input_service_id) < 1)
- break;
-
-
- result = wifi_direct_deregister_service(input_service_id);
- printf("wifi_direct_deregister_service() result=[%d]\n", result);
- }
- break;
- case CMD_START_SERVICE_DISCOVERY:
- if (ad != NULL) {
- int input_service_discovery;
- wifi_direct_service_type_e service_type = WIFI_DIRECT_SERVICE_TYPE_ALL;
-
- printf("Input service type:\n");
- printf("1. WIFI_DIRECT_SERVICE_TYPE_ALL\n");
- printf("2. WIFI_DIRECT_SERVICE_TYPE_BONJOUR\n");
- printf("3. WIFI_DIRECT_SERVICE_TYPE_UPNP\n");
- printf("4. WIFI_DIRECT_SERVICE_TYPE_BT_ADDR\n");
- printf("5. WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO\n");
- if (scanf(" %1d", &input_service_discovery) < 1)
- break;
- printf("input = %d\n", input_service_discovery);
-
- switch (input_service_discovery) {
- case 1:
- service_type = WIFI_DIRECT_SERVICE_TYPE_ALL;
- break;
- case 2:
- service_type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR;
- break;
- case 3:
- service_type = WIFI_DIRECT_SERVICE_TYPE_UPNP;
- break;
- case 4:
- service_type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR;
- break;
- case 5:
- service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO;
- break;
- default:
- printf("ERROR : Invalid input service_type!!!\n");
- break;
- }
-
- if (select_peer(ad)) {
-
- result = wifi_direct_start_service_discovery(
- NULL, service_type);
-
- printf("Service Discovery... broadcast service type[%d]\n",
- service_type);
- } else {
- int i = ad->selected_peer_index;
- wifi_direct_discovered_peer_info_s* list = ad->peer_list;
-
- result = wifi_direct_start_service_discovery(
- list[i].mac_address, service_type);
-
- printf("Service Discovery... peer-index[%d] MAC [%s] service type[%d]\n",
- i, list[i].mac_address, service_type);
- }
-
- printf("wifi_direct_start_service_discovery() result=[%d]\n", result);
-
- }
- break;
-
- case CMD_CANCEL_SERVICE_DISCOVERY:
- if (ad != NULL) {
- int input_service_discovery;
- wifi_direct_service_type_e service_type = WIFI_DIRECT_SERVICE_TYPE_ALL;
-
- printf("Input service ID:\n");
-
- if (scanf(" %1d", &input_service_discovery) < 1)
- break;
- printf("input = %d\n", input_service_discovery);
-
- switch (input_service_discovery) {
- case 1:
- service_type = WIFI_DIRECT_SERVICE_TYPE_ALL;
- break;
- case 2:
- service_type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR;
- break;
- case 3:
- service_type = WIFI_DIRECT_SERVICE_TYPE_UPNP;
- break;
- case 4:
- service_type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR;
- break;
- case 5:
- service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO;
- break;
- default:
- printf("ERROR : Invalid input service_type!!!\n");
- break;
- }
-
- if (select_peer(ad)) {
- result = wifi_direct_cancel_service_discovery(
- NULL, service_type);
-
- printf("Service Discovery... broadcast service type[%d]\n",
- service_type);
- } else {
- int i = ad->selected_peer_index;
- wifi_direct_discovered_peer_info_s* list = ad->peer_list;
-
- result = wifi_direct_cancel_service_discovery(
- list[i].mac_address, service_type);
-
- printf("Service Discovery... peer-index[%d] MAC [%s] service type[%d]\n",
- i, list[i].mac_address, service_type);
- }
- printf("wifi_direct_cancel_service_discovery() result=[%d]\n", result);
- }
- break;
-
- case CMD_INIT_MIRACAST:
- if (ad != NULL) {
- int miracast_enable;
-
- printf("Input miracast enable: \n");
- printf("[1] true [2] false\n");
-
- if (scanf(" %1d", &miracast_enable) < 1)
- break;
-
- if (miracast_enable == 1)
- result = wifi_direct_init_miracast(true);
- else if (miracast_enable == 2)
- result = wifi_direct_init_miracast(false);
- else
- printf("Invalid input parameter!!!\n");
-
- printf("wifi_direct_init_miracast() result=[%d] \n", result);
-
- }
- break;
-
- case CMD_GET_PEER_INFO:
- if (ad != NULL)
- if (select_peer(ad)) {
- int i = ad->selected_peer_index;
- wifi_direct_discovered_peer_info_s* list = ad->peer_list;
- wifi_direct_discovered_peer_info_s* peer_info = NULL;
-
- result = wifi_direct_get_peer_info(list[i].mac_address, &peer_info);
- if (peer_info != NULL) {
- printf("MAC [%s] Owner=[%s] connected=[%d] SSID[%s] ctg=[%d/%d]",
- peer_info->mac_address,
- peer_info->is_group_owner ? "YES" : "NO",
- peer_info->is_connected,
- peer_info->device_name,
- peer_info->primary_device_type,
- peer_info->secondary_device_type
- );
- g_free(peer_info->mac_address);
- g_free(peer_info->interface_address);
- g_free(peer_info);
- }
-
- printf("wifi_direct_get_peer() result=[%d]\n", result);
- }
- break;
- case CMD_SET_PASSPHRASE:
- {
- if (ad != NULL) {
- char passphrase[64] = {0, };
-
- printf("Input passphrase :\n");
- if (scanf(" %64[^\n]s", passphrase) < 1)
- break;
-
- if (strlen(passphrase) > 0) {
- printf("passphrase: [%s]\n", passphrase);
- result = wifi_direct_set_passphrase(passphrase);
- printf("wifi_direct_set_passphrase() ret=[%d]\n", result);
- } else
- printf("invalid passphrase !!\n");
- }
- }
- break;
- case CMD_GET_PASSPHRASE:
- {
- if (ad != NULL) {
- char* passphrase = NULL;
-
- result = wifi_direct_get_passphrase(&passphrase);
- printf("wifi_direct_get_passphrase() result=[%d]\n", result);
-
- if (NULL != passphrase) {
- printf("passphrase: [%s]\n", passphrase);
- free(passphrase);
- }
-
- }
- }
- break;
- case CMD_SET_AUTOCONNECTION_PEER:
- if (ad != NULL) {
- char * mac_address = NULL;
- printf("\nEnter Mac_address: ");
- if (scanf(" %18ms", &mac_address) < 1)
- break;
-
- if (strlen(mac_address) > 23) {
- printf("\nWrong Mac_address");
-
- } else {
- int rv = wifi_direct_set_autoconnection_peer(mac_address);
-
- if (rv == WIFI_DIRECT_ERROR_NONE) {
- free(mac_address);
- printf(MAKE_GREEN"SUCCESS %s"RESET_COLOR"\n", __func__);
- break;
- }
- printf(MAKE_RED"FAILED %s : %s"RESET_COLOR"\n", __func__, test_wfd_convert_error_to_string(rv));
- }
-
- free(mac_address);
- }
- break;
- case CMD_INIT_DISPLAY:
- {
- if (ad != NULL) {
- result = wifi_direct_init_display();
- printf("wifi_direct_init_display() result=[%d]\n", result);
- }
- }
- break;
- case CMD_DEINIT_DISPLAY:
- {
- if (ad != NULL) {
- result = wifi_direct_deinit_display();
- printf("wifi_direct_deinit_display() result=[%d]\n", result);
- }
- }
- break;
- case CMD_SET_DISPLAY:
- {
- if (ad != NULL) {
- int rv = WIFI_DIRECT_ERROR_NONE;
- int use_default = 0;
-
- printf("Press [0] For Setting Default Values\n");
- if (scanf(" %1d", &use_default) < 1)
- break;
-
- if (use_default == 0) {
- rv = wifi_direct_set_display(WIFI_DIRECT_DISPLAY_TYPE_SOURCE, 7236, 1);
- } else {
- int display_type = 0;
- int port_number = 0;
- int hdcp = 0;
-
- printf("DISPLAY_TYPE----->\n");
- printf("(0) for WIFI_DISPLAY_TYPE_SOURCE,\n");
- printf("(1) for WIFI_DISPLAY_TYPE_PRIMARY_SINK,\n");
- printf("(2) for WIFI_DISPLAY_TYPE_SECONDARY_SINK,\n");
- printf("(3) WIFI_DISPLAY_TYPE_DUAL_ROLE\n");
- printf("Please Enter DISPLAY_TYPE -----> ");
- if (scanf(" %1d", &display_type) < 1)
- break;
-
- printf("Please Enter PORT NUMBER -----> ");
- if (scanf(" %4d", &port_number) < 1)
- break;
-
- printf("Please Enter HDCP -----> ");
- if (scanf(" %1d", &hdcp) < 1)
- break;
-
- rv = wifi_direct_set_display(display_type, port_number, hdcp);
- }
-
- if (rv == WIFI_DIRECT_ERROR_NONE) {
- printf(MAKE_GREEN"Success %s : %s"RESET_COLOR"\n", __func__, test_wfd_convert_error_to_string(rv));
- break;
- }
-
- printf(MAKE_RED"FAILED %s : %s"RESET_COLOR"\n", __func__, test_wfd_convert_error_to_string(rv));
- break;
- }
- }
- break;
- case CMD_SET_DISPLAY_AVAILABILITY:
- {
- if (ad != NULL) {
- int availability = 0;
-
- printf("Enter Wi-Fi Display availability : ");
- if (scanf(" %1d", &availability) < 0)
- break;
-
- int rv = wifi_direct_set_display_availability(availability);
- if (WIFI_DIRECT_ERROR_NONE == rv) {
- printf(MAKE_GREEN"Set Wi-Fi Display availability Successful"RESET_COLOR"\n");
- break;
- }
- printf(MAKE_RED"Set Wi-Fi Display availability : %s ", test_wfd_convert_error_to_string(rv));
- printf(RESET_COLOR"\n");
- break;
- }
- }
- break;
- case CMD_GET_DISPLAY:
- {
- if (ad != NULL) {
- wifi_direct_display_type_e type;
- int port;
- int hdcp;
-
- result = wifi_direct_get_display(&type, &port, &hdcp);
-
- printf("wifi_direct_get_display() result=[%d] type=[%d] port=[%d] hdcp=[%d]\n", result, type, port, hdcp);
- break;
- }
- }
- break;
- case CMD_GET_DISPLAY_AVAILABILITY:
- {
- if (ad != NULL) {
- bool availability;
-
- result = wifi_direct_get_display_availability(&availability);
-
- printf("wifi_direct_get_display_availability() result=[%d] availability=[%d]\n", result, availability);
- break;
- }
- }
- break;
- case CMD_GET_PEER_DISPLAY_TYPE:
- if (ad != NULL) {
- if (select_peer(ad)) {
- int i = ad->selected_peer_index;
- wifi_direct_display_type_e type = WIFI_DIRECT_DISPLAY_TYPE_DUAL;
- wifi_direct_discovered_peer_info_s* list = ad->peer_list;
-
- result = wifi_direct_get_peer_display_type(list[i].mac_address, &type);
-
- printf("wifi_direct_get_peer_display_type() result=[%d] type=[%d]\n", result, type);
- }
- }
- break;
- case CMD_GET_PEER_DISPLAY_AVAILABILITY:
- if (ad != NULL) {
- if (select_peer(ad)) {
- int i = ad->selected_peer_index;
- bool availability = false;
- wifi_direct_discovered_peer_info_s* list = ad->peer_list;
-
- result = wifi_direct_get_peer_display_availability(list[i].mac_address, &availability);
-
- printf("wifi_direct_get_peer_display_availability() result=[%d] availability=[%d]\n", result, availability);
- }
- }
- break;
- case CMD_GET_PEER_DISPLAY_HDCP:
- if (ad != NULL) {
- if (select_peer(ad)) {
- int i = ad->selected_peer_index;
- int hdcp;
- wifi_direct_discovered_peer_info_s* list = ad->peer_list;
-
- result = wifi_direct_get_peer_display_hdcp(list[i].mac_address, &hdcp);
-
- printf("wifi_direct_get_peer_display_hdcp() result=[%d] hdcp=[%d]\n", result, hdcp);
- }
- }
- break;
- case CMD_GET_PEER_DISPLAY_PORT:
- if (ad != NULL) {
- if (select_peer(ad)) {
- int i = ad->selected_peer_index;
- int port;
- wifi_direct_discovered_peer_info_s* list = ad->peer_list;
-
- result = wifi_direct_get_peer_display_port(list[i].mac_address, &port);
-
- printf("wifi_direct_get_peer_display_port() result=[%d] port=[%d]\n", result, port);
- }
- }
- break;
- case CMD_GET_PEER_DISPLAY_THROUGHPUT:
- if (ad != NULL) {
- if (select_peer(ad)) {
- int i = ad->selected_peer_index;
- int tput;
- wifi_direct_discovered_peer_info_s* list = ad->peer_list;
-
- result = wifi_direct_get_peer_display_throughput(list[i].mac_address, &tput);
-
- printf("wifi_direct_get_peer_display_throughput() result=[%d] throughput=[%d]\n", result, tput);
- }
- }
- break;
- case CMD_GET_SESSION_TIMER:
- if (ad != NULL) {
- int session_timer;
- result = wifi_direct_get_session_timer(&session_timer);
- printf("wifi_direct_get_session_timer() result=[%d] session_timer[%d]\n",
- result, session_timer);
- }
- break;
- case CMD_SET_SESSION_TIMER:
- if (ad != NULL) {
- int session_timer;
- printf("Input Session Timer \n");
- if (scanf(" %2d", &session_timer) < 1)
- break;
-
- result = wifi_direct_set_session_timer(session_timer);
- printf("wifi_direct_set_session_timer() result=[%d] session_timer[%d]\n",
- result, session_timer);
- }
- break;
- case CMD_SET_AUTO_GROUP_REMOVAL:
- if (ad != NULL) {
- int enable;
- printf("Enter (1 to enable or 0 to Disable): ");
- if (scanf(" %1d", &enable) < 1)
- break;
-
- result = wifi_direct_set_auto_group_removal(enable);
- printf("wifi_direct_set_auto_group_removal() result=[%d]\n", result);
- if (enable == true)
- printf("Enable auto Group Removal!! \n");
- else
- printf("Disable auto Group Removal mode!! \n");
- }
- break;
- case CMD_GET_PEER_RSSI:
- if (ad != NULL) {
- if (select_peer(ad)) {
- int i = ad->selected_peer_index;
- int rssi = 0;
- wifi_direct_discovered_peer_info_s* list = ad->peer_list;
-
- result = wifi_direct_get_peer_rssi(list[i].mac_address, &rssi);
-
- printf("wifi_direct_get_peer_rssi() result=[%d] rssi=[%d]\n", result, rssi);
- }
- }
- break;
- case CMD_ADD_VSIE:
- {
- char *vsie = NULL;
- unsigned int frame_id;
-
- printf("Input frame_id:\n");
- if (scanf(" %2u", &frame_id) < 1)
- break;
-
- printf("Input vsie:\n");
- if (scanf(" %100ms", &vsie) < 1)
- break;
-
- if (strlen(vsie) <= 0)
- printf("invalid vsie !!\n");
- else
- printf("vsie: [%s]\n", vsie);
-
- if ((strlen(vsie) > 0)) {
- result = wifi_direct_add_vsie(frame_id, vsie);
- printf("wifi_direct_add_vsie() ret=[%d]\n", result);
- }
-
- free(vsie);
- }
- break;
- case CMD_GET_VSIE:
- {
- char *vsie = NULL;
- unsigned int frame_id;
-
- printf("Input frame_id:\n");
- if (scanf(" %2u", &frame_id) < 1)
- break;
-
- wifi_direct_get_vsie(frame_id, &vsie);
- printf("Received vsie [%s]\n", vsie ? vsie : "NULL");
- free(vsie);
- }
- break;
- case CMD_REMOVE_VSIE:
- {
- char *vsie = NULL;
- unsigned int frame_id;
-
- printf("Input frame_id:\n");
- if (scanf(" %2u", &frame_id) < 1)
- break;
-
- printf("Input vsie:\n");
- if (scanf(" %100ms", &vsie) < 1)
- break;
-
- if (strlen(vsie) <= 0)
- printf("invalid vsie !!\n");
- else
- printf("vsie: [%s]\n", vsie);
-
- if ((strlen(vsie) > 0)) {
- result = wifi_direct_remove_vsie(frame_id, vsie);
- printf("wifi_direct_add_vsie() ret=[%d]\n", result);
- }
-
- free(vsie);
- }
- break;
- case CMD_GET_PEER_VSIE:
- if (ad != NULL) {
- if (select_peer(ad)) {
- int i = ad->selected_peer_index;
- char *vsie = NULL;
- wifi_direct_discovered_peer_info_s* list = ad->peer_list;
-
- result = wifi_direct_get_peer_vsie(list[i].mac_address,
- &vsie);
-
- printf("wifi_direct_get_peer_vsie() result=[%d] vsie=[%s]\n", result, vsie);
-
- if (vsie)
- free(vsie);
- }
- }
- 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;
-
- case CMD_QUIT:
- printf("Bye\n");
- g_main_loop_quit(ad->main_loop);
- break;
-
- default:
- usage_full();
- break;
- }
-}
-
-static gboolean test_terminal_read_std_input(GIOChannel * source,
- GIOCondition condition, gpointer user_data)
-{
- int fd = 0;
-
- static char buf[1024];
- int n;
-
- errno = 0;
- n = read(fd, buf, 1024);
- if (n == 0) {
- printf("Error: read() from stdin returns 0.\n");
- } else if (n < 0) {
- char error_buf[100] = {0, };
- strerror_r(errno, error_buf, sizeof(error_buf));
- printf("input: read, err=%s\n", error_buf);
- } else {
- buf[n - 1] = '\0'; /* remove new line... */
- printf("\n\n");
- /* printf("Read [%d]bytes data: [%s]\n", n, buf); */
- /* printf("Processing it ---------------------\n", n, buf); */
- process_input(buf, user_data);
- }
-
- return TRUE;
-}
-
-int main(int argc, char **argv)
-{
- GMainLoop *main_loop;
- struct appdata *ad = NULL;
-
-#if !GLIB_CHECK_VERSION(2, 36, 0)
- g_type_init();
-#endif
-
- main_loop = g_main_loop_new(NULL, FALSE);
-
- ad = (struct appdata*)g_try_malloc0(sizeof(struct appdata));
- if (!ad)
- return -1;
-
- ad->main_loop = main_loop;
-
- ad->peer_count = 0;
-
- set_appdata(ad);
-
- int r = get_param(argc, argv, ad);
- if (r)
- return -1;
-
- int std_input_fd = 0;
- GIOChannel *gio2 = g_io_channel_unix_new(std_input_fd);
- g_io_add_watch(gio2, G_IO_IN, (GIOFunc) test_terminal_read_std_input, ad);
- g_io_channel_unref(gio2);
-
- usage_full();
-
- g_main_loop_run(main_loop);
-
- g_free(ad);
- return 0;
-}
--- /dev/null
+########################## search for packages ################################
+
+PKG_CHECK_MODULES(TARGET_WIFI_DIRECT_TEST_REQ_PKGS REQUIRED glib-2.0)
+
+############################# compiler flags ##################################
+
+SET(EXTRA_FLAGS "-Wall -Werror")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${CFLAGS} -fPIE")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+######################## directory configuration ############################
+
+INCLUDE_DIRECTORIES(${TARGET_WIFI_DIRECT_TEST_REQ_PKGS_INCLUDE_DIRS})
+LINK_DIRECTORIES(${TARGET_WIFI_DIRECT_TEST_REQ_PKGS_LIBRARY_DIRS})
+
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include)
+
+# Build
+ADD_EXECUTABLE(${TARGET_WIFI_DIRECT_TEST}
+ ${CMAKE_CURRENT_SOURCE_DIR}/wifi_direct_test.c
+)
+
+TARGET_LINK_LIBRARIES(${TARGET_WIFI_DIRECT_TEST}
+ ${TARGET_WIFI_DIRECT_TEST_REQ_PKGS_LIBRARIES} ${PROJECT_NAME})
+
+#Install
+INSTALL(TARGETS ${TARGET_WIFI_DIRECT_TEST} DESTINATION ${BIN_DIR})
+
+########################## search for packages ################################
+
+PKG_CHECK_MODULES(TARGET_WIFI_DIRECT_GTEST_REQ_PKGS REQUIRED ${GTEST_DEPS} ${COMMON_DEPS})
+
+############################# compiler flags ##################################
+
+SET(EXTRA_FLAGS "-Wall -Werror")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${CFLAGS} -fPIE")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_FLAGS} -std=c++11")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+######################## directory configuration ############################
+
+INCLUDE_DIRECTORIES(${TARGET_WIFI_DIRECT_GTEST_REQ_PKGS_INCLUDE_DIRS})
+LINK_DIRECTORIES(${TARGET_WIFI_DIRECT_GTEST_REQ_PKGS_LIBRARY_DIRS})
+
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
+FILE(GLOB GTEST_SRCS *.cpp mocks/*.cpp mocks/*.c mocks/WifiDirectManager/*.cpp ${CMAKE_SOURCE_DIR}/src/*.c)
+
+# Build
+ADD_EXECUTABLE(${TARGET_WIFI_DIRECT_GTEST} ${GTEST_SRCS})
+
+MESSAGE("${WIFI_DIRECT_DEPS_LIBRARIES}")
+TARGET_LINK_LIBRARIES(${TARGET_WIFI_DIRECT_GTEST}
+ ${TARGET_WIFI_DIRECT_GTEST_REQ_PKGS_LIBRARIES}
+ ${WIFI_DIRECT_DEPS_LIBRARIES})
+
+SET_TARGET_PROPERTIES(${TARGET_WIFI_DIRECT_GTEST} PROPERTIES
+ COMPILE_FLAGS "-fPIE"
+ #Never add any space for LINKFLAGS
+ LINK_FLAGS "-Wl,\
+--wrap=system_info_get_platform_bool")
+
+INSTALL(TARGETS ${TARGET_WIFI_DIRECT_GTEST} DESTINATION ${BIN_DIR})
--- /dev/null
+/*
+ * gtest-wifi-direct.cpp
+ *
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Sungsik Jang <sungsik.jang@samsung.com>, Dongwook Lee <dwmax.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/*****************************************************************************
+ * Standard headers
+ *****************************************************************************/
+
+/*****************************************************************************
+ * System headers
+ *****************************************************************************/
+#include <glib.h>
+#include <gtest/gtest.h>
+/*****************************************************************************
+ * Local headers
+ *****************************************************************************/
+#include "wifi-direct.h"
+#include "wifi-direct-internal.h"
+
+#include "mock_sysinfo.h"
+#include "mock_gdbus.h"
+#include "wifi_direct_manager_mock.h"
+/*****************************************************************************
+ * Macros and Typedefs
+ *****************************************************************************/
+/*****************************************************************************
+ * Global Variables
+ *****************************************************************************/
+/*****************************************************************************
+ * Local Functions Definition
+ *****************************************************************************/
+
+class WifiDirectInitTest : public ::testing::Test {
+protected:
+ void SetUp() override
+ {
+ //Setting up normal condition
+ mock_gdbus_gdbus_sync_enable(true);
+ mock_gdbus_gdbus_call_sync_enable(true);
+ wifi_direct_manager_mock_init();
+ }
+
+ void TearDown() override
+ {
+ wifi_direct_manager_mock_deinit();
+ }
+};
+
+TEST_F(WifiDirectInitTest, wifi_direct_initialize_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_initialize_Negative1)
+{
+ int ret;
+
+ mock_sysinfo_set_up_wifi_direct(false);
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_SUPPORTED, ret);
+
+ mock_sysinfo_set_up_wifi_direct(true);
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_initialize_Negative2)
+{
+ int ret;
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_ALREADY_INITIALIZED, ret);
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_initialize_Negative3)
+{
+ int ret;
+
+ mock_gdbus_gdbus_sync_enable(false);
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_OPERATION_FAILED, ret);
+
+ mock_gdbus_gdbus_sync_enable(true);
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_initialize_Negative4)
+{
+ int ret;
+
+ mock_gdbus_gdbus_call_sync_enable(false);
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_OPERATION_FAILED, ret);
+
+ mock_gdbus_gdbus_call_sync_enable(true);
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_deinitialize_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_INITIALIZED, ret);
+}
+
+static void __device_state_changed_cb(int error_code,
+ wifi_direct_device_state_e device_state,
+ void *user_data)
+{
+ return;
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_set_device_state_changed_cb_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_device_state_changed_cb(__device_state_changed_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_unset_device_state_changed_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_set_device_state_changed_cb_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_device_state_changed_cb(NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+static void __discovery_state_chagned_cb (int error_code,
+ wifi_direct_discovery_state_e discovery_state,
+ void *user_data)
+{
+ return;
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_set_discovery_state_changed_cb_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_discovery_state_changed_cb(__discovery_state_chagned_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_unset_discovery_state_changed_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_set_discovery_state_changed_cb_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_discovery_state_changed_cb(NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+static void __peer_found_cb(int error_code,
+ wifi_direct_discovery_state_e discovery_state,
+ const char *mac_address,
+ void *user_data)
+{
+ return;
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_set_peer_found_cb_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_peer_found_cb(__peer_found_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_unset_peer_found_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_set_peer_found_cb_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_peer_found_cb(NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+static void __service_state_changed_cb (int error_code,
+ wifi_direct_service_discovery_state_e service_state,
+ wifi_direct_service_type_e service_type,
+ void *response_data,
+ const char *mac_address,
+ void *user_data)
+{
+ return;
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_set_service_state_changed_cb_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_service_state_changed_cb(__service_state_changed_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_unset_service_state_changed_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_set_service_state_changed_cb_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_service_state_changed_cb(NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+static void __connection_state_changed_cb(int error_code,
+ wifi_direct_connection_state_e connection_state,
+ const char *mac_address,
+ void *user_data)
+{
+ return;
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_set_connection_state_changed_cb_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_connection_state_changed_cb(__connection_state_changed_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_unset_connection_state_changed_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_set_connection_state_changed_cb_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_connection_state_changed_cb(NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+static void __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)
+{
+ return;
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_set_peer_info_connection_state_changed_cb_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_peer_info_connection_state_changed_cb(__peer_info_connection_state_changed_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_unset_peer_info_connection_state_changed_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_set_peer_info_connection_state_changed_cb_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_peer_info_connection_state_changed_cb(NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+static void __client_ip_address_assigned_cb (const char *mac_address,
+ const char *ip_address,
+ const char *interface_address,
+ void *user_data)
+{
+ return;
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_set_client_ip_address_assigned_cb_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_client_ip_address_assigned_cb(__client_ip_address_assigned_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_unset_client_ip_address_assigned_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_set_client_ip_address_assigned_cb_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_client_ip_address_assigned_cb(NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+static void __state_changed_cb(wifi_direct_state_e state,
+ void *user_data)
+{
+ return;
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_set_state_changed_cb_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_state_changed_cb(__state_changed_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_unset_state_changed_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_set_state_changed_cb_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_state_changed_cb(NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+static void __check_activated_cb(int error_code,
+ wifi_direct_device_state_e device_state,
+ void *user_data)
+{
+ gboolean *activated = (gboolean *)user_data;
+ if (device_state == WIFI_DIRECT_DEVICE_STATE_ACTIVATED)
+ *activated = TRUE;
+ else
+ *activated = FALSE;
+
+ return;
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_activate_Positive)
+{
+ gboolean activated = FALSE;
+ int ret;
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_device_state_changed_cb(__check_activated_cb, (gpointer)&activated);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+
+ ASSERT_EQ(TRUE, activated);
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ASSERT_EQ(FALSE, activated);
+
+ ret = wifi_direct_unset_device_state_changed_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_activate_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ mock_gdbus_gdbus_call_sync_enable(false);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_OPERATION_FAILED, ret);
+
+ mock_gdbus_gdbus_call_sync_enable(true);
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectInitTest, wifi_direct_deactivate_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ mock_gdbus_gdbus_call_sync_enable(false);
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_OPERATION_FAILED, ret);
+
+ mock_gdbus_gdbus_call_sync_enable(true);
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+class WifiDirectDiscoveryTest : public ::testing::Test {
+protected:
+ void SetUp() override
+ {
+ //Setting up normal condition
+ mock_gdbus_gdbus_sync_enable(true);
+ mock_gdbus_gdbus_call_sync_enable(true);
+ wifi_direct_manager_mock_init();
+
+ int ret;
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+ }
+
+ void TearDown() override
+ {
+ int ret;
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_deinit();
+ }
+};
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_start_discovery_listen_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_set_discovery_state_changed_cb(__discovery_state_chagned_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_peer_found_cb(__peer_found_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_start_discovery(true, 0);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_listen_started_signal();
+ wifi_direct_manager_mock_generate_discovery_finished_signal();
+
+ ret = wifi_direct_unset_discovery_state_changed_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_unset_peer_found_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_start_discovery_listen_Negative)
+{
+ int ret;
+ ret = wifi_direct_start_discovery(false, -1);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_start_discovery_find_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_set_discovery_state_changed_cb(__discovery_state_chagned_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_peer_found_cb(__peer_found_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_start_discovery(false, 0);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_discovery_started_signal();
+ wifi_direct_manager_mock_generate_peer_found_signal();
+ wifi_direct_manager_mock_generate_peer_lost_signal();
+ wifi_direct_manager_mock_generate_discovery_finished_signal();
+
+ ret = wifi_direct_unset_discovery_state_changed_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_unset_peer_found_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_start_discovery_find_Negative)
+{
+ int ret;
+ ret = wifi_direct_start_discovery(false, -1);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_start_discovery_specific_channel_Positive)
+{
+ int ret;
+ ret = wifi_direct_start_discovery_specific_channel(false, 0, WIFI_DIRECT_DISCOVERY_FULL_SCAN);
+
+ wifi_direct_manager_mock_generate_discovery_started_signal();
+ wifi_direct_manager_mock_generate_peer_found_signal();
+ wifi_direct_manager_mock_generate_peer_lost_signal();
+ wifi_direct_manager_mock_generate_discovery_finished_signal();
+
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_start_discovery_specific_channel_Negative)
+{
+ int ret;
+ ret = wifi_direct_start_discovery_specific_channel(false, -1, WIFI_DIRECT_DISCOVERY_FULL_SCAN);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_start_discovery_specific_freq_Positive)
+{
+ int ret;
+ ret = wifi_direct_start_discovery_specific_freq(true, 0, 2412);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_listen_started_signal();
+ wifi_direct_manager_mock_generate_discovery_finished_signal();
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_start_discovery_specific_freq_Negative)
+{
+ int ret;
+ ret = wifi_direct_start_discovery_specific_freq(false, -1, 2412);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_cancel_discovery_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_start_discovery(false, 0);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_cancel_discovery();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_cancel_discovery_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_cancel_discovery();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+bool wifi_direct_foreach_discovered_peers_Positive_cb(wifi_direct_discovered_peer_info_s* peer, void* user_data)
+{
+ free(peer->device_name);
+ free(peer->mac_address);
+ free(peer->interface_address);
+ free(peer);
+ return true;
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_foreach_discovered_peers_Positive)
+{
+ int ret;
+ ret = wifi_direct_foreach_discovered_peers(wifi_direct_foreach_discovered_peers_Positive_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_foreach_discovered_peers_Negative)
+{
+ int ret;
+ ret = wifi_direct_foreach_discovered_peers(NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_start_service_discovery_Positive)
+{
+ int ret;
+ ret = wifi_direct_start_service_discovery(NULL, WIFI_DIRECT_SERVICE_TYPE_ALL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_start_service_discovery_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_start_service_discovery(NULL, WIFI_DIRECT_SERVICE_TYPE_ALL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_cancel_service_discovery_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_start_service_discovery(NULL, WIFI_DIRECT_SERVICE_TYPE_ALL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_cancel_service_discovery(NULL, WIFI_DIRECT_SERVICE_TYPE_ALL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_cancel_service_discovery_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_cancel_service_discovery(NULL, WIFI_DIRECT_SERVICE_TYPE_ALL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_register_service_Positive)
+{
+ unsigned int service_id;
+ char service_info[] = "service_string";
+ int ret;
+
+ ret = wifi_direct_register_service(WIFI_DIRECT_SERVICE_TYPE_ALL, service_info, service_info, &service_id);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_register_service_Negative1)
+{
+ unsigned int service_id;
+ int ret;
+
+ ret = wifi_direct_register_service(WIFI_DIRECT_SERVICE_TYPE_ALL, NULL, NULL, &service_id);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_register_service_Negative2)
+{
+ unsigned int service_id;
+ char service_info[] = "service_string";
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_register_service(WIFI_DIRECT_SERVICE_TYPE_ALL, service_info, service_info, &service_id);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_deregister_service_Positive)
+{
+ unsigned int service_id = 7;
+ int ret;
+
+ ret = wifi_direct_deregister_service(service_id);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_deregister_service_Negative)
+{
+ unsigned int service_id = 7;
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_deregister_service(service_id);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_get_peer_info_Positive)
+{
+ char test_mac[] = "aa:bb:cc:dd:ee:ff";
+ int ret;
+
+ wifi_direct_discovered_peer_info_s *peer_info = NULL;
+ ret = wifi_direct_get_peer_info(test_mac, &peer_info);
+ free(peer_info->device_name);
+ free(peer_info->mac_address);
+ free(peer_info->interface_address);
+ free(peer_info);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_get_peer_info_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_get_peer_info(NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+class WifiDirectGroupTest : public ::testing::Test {
+protected:
+ void SetUp() override
+ {
+ //Setting up normal condition
+ mock_gdbus_gdbus_sync_enable(true);
+ mock_gdbus_gdbus_call_sync_enable(true);
+ wifi_direct_manager_mock_init();
+
+ int ret;
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+ }
+
+ void TearDown() override
+ {
+ int ret;
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_deinit();
+ }
+};
+
+TEST_F(WifiDirectGroupTest, wifi_direct_create_group_Positive)
+{
+ int ret;
+ ret = wifi_direct_create_group();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_created_signal();
+
+ ret = wifi_direct_destroy_group();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_destroyed_signal();
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_create_group_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_create_group();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_create_group_with_ssid_Positive)
+{
+ int ret;
+ ret = wifi_direct_create_group_with_ssid("TEST");
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_create_group_with_ssid_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_create_group_with_ssid(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_create_group_with_ssid_Negative2)
+{
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_create_group_with_ssid("TEST");
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_destroy_group_Positive)
+{
+ int ret;
+ ret = wifi_direct_set_connection_state_changed_cb(__connection_state_changed_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_create_group();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_created_signal();
+
+ ret = wifi_direct_destroy_group();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_destroyed_signal();
+
+ ret = wifi_direct_unset_connection_state_changed_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_destroy_group_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_destroy_group();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_is_group_owner_Positive)
+{
+ bool owner;
+ int ret;
+
+ ret = wifi_direct_is_group_owner(&owner);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_is_group_owner_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_is_group_owner(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_is_autonomous_group_Positive)
+{
+ bool is_autonomous;
+ int ret;
+
+ ret = wifi_direct_is_autonomous_group(&is_autonomous);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_is_autonomous_group_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_is_autonomous_group(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+class WifiDirectSettingTest : public ::testing::Test {
+protected:
+ void SetUp() override
+ {
+ //Setting up normal condition
+ mock_gdbus_gdbus_sync_enable(true);
+ mock_gdbus_gdbus_call_sync_enable(true);
+ wifi_direct_manager_mock_init();
+
+ int ret;
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+ }
+
+ void TearDown() override
+ {
+ int ret;
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_deinit();
+ }
+};
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_group_owner_intent_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_set_group_owner_intent(7);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_group_owner_intent_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_set_group_owner_intent(-1);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_group_owner_intent_Positive)
+{
+ int go_intent;
+ int ret;
+
+ ret = wifi_direct_get_group_owner_intent(&go_intent);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_group_owner_intent_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_get_group_owner_intent(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_go_intent_per_type_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_set_go_intent_per_type(4, 7);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_go_intent_per_type_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_set_go_intent_per_type(-1, 7);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+
+ ret = wifi_direct_set_go_intent_per_type(4, -1);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_go_intent_per_type_Positive)
+{
+ int go_intent;
+ int ret;
+
+ ret = wifi_direct_get_go_intent_per_type(4, &go_intent);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_go_intent_per_type_Negative)
+{
+ int go_intent;
+ int ret;
+
+ ret = wifi_direct_get_go_intent_per_type(-1, &go_intent);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+
+ ret = wifi_direct_get_go_intent_per_type(4, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_max_clients_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_set_max_clients(10);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_max_clients_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_set_max_clients(-1);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_OPERATION_FAILED, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_max_clients_Positive)
+{
+ int client_num;
+ int ret;
+
+ ret = wifi_direct_get_max_clients(&client_num);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_max_clients_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_get_max_clients(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_operating_channel_Positive)
+{
+ int channel;
+ int ret;
+
+ ret = wifi_direct_create_group();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_get_operating_channel(&channel);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_destroy_group();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_operating_channel_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_get_operating_channel(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_operating_channel_Negative2)
+{
+ int channel;
+ int ret;
+
+ ret = wifi_direct_get_operating_channel(&channel);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_activate_pushbutton_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_create_group();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_activate_pushbutton();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_destroy_group();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_activate_pushbutton_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_activate_pushbutton();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_supported_wps_mode_Positive)
+{
+ int supported_wps_mode;
+ int ret;
+
+ ret = wifi_direct_get_supported_wps_mode(&supported_wps_mode);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_supported_wps_mode_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_get_supported_wps_mode(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+bool wifi_direct_foreach_supported_wps_types_Positive_cb(wifi_direct_wps_type_e type, void *user_data)
+{
+ return true;
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_foreach_supported_wps_types_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_foreach_supported_wps_types(wifi_direct_foreach_supported_wps_types_Positive_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_foreach_supported_wps_types_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_foreach_supported_wps_types(NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_local_wps_type_Positive)
+{
+ wifi_direct_wps_type_e type;
+ int ret;
+
+ ret = wifi_direct_get_local_wps_type(&type);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_local_wps_type_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_get_local_wps_type(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_req_wps_type_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_set_req_wps_type(WIFI_DIRECT_WPS_TYPE_PBC);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_req_wps_type_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_set_req_wps_type((wifi_direct_wps_type_e)0);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_req_wps_type_Positive)
+{
+ wifi_direct_wps_type_e type;
+ int ret;
+
+ ret = wifi_direct_get_req_wps_type(&type);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_req_wps_type_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_get_req_wps_type(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_ssid_Positive)
+{
+ char *ssid;
+ int ret;
+
+ ret = wifi_direct_get_ssid(&ssid);
+ free(ssid);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_ssid_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_get_ssid(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_device_name_Positive)
+{
+ char *device_name;
+ int ret;
+
+ ret = wifi_direct_get_device_name(&device_name);
+ free(device_name);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_device_name_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_get_device_name(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_device_name_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_set_device_name("TEST_DEVICE");
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_device_name_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_set_device_name(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_state_Positive)
+{
+ wifi_direct_state_e state;
+ int ret;
+
+ ret = wifi_direct_get_state(&state);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_state_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_get_state(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_mac_address_Positive)
+{
+ char *mac_address = NULL;
+ int ret;
+
+ ret = wifi_direct_get_mac_address(&mac_address);
+ free(mac_address);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_mac_address_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_get_mac_address(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_get_network_interface_name_Positive)
+{
+ char *iface_name;
+ int ret;
+
+ ret = wifi_direct_create_group();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_get_network_interface_name(&iface_name);
+ free(iface_name);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_destroy_group();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_get_network_interface_name_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_get_network_interface_name(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_get_network_interface_name_Negative2)
+{
+ char *iface_name;
+ int ret;
+
+ ret = wifi_direct_get_network_interface_name(&iface_name);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_get_ip_address_Positive)
+{
+ char *ip_address;
+ int ret;
+
+ ret = wifi_direct_create_group();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_get_ip_address(&ip_address);
+ free(ip_address);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_destroy_group();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_get_ip_address_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_get_ip_address(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_get_ip_address_Negative2)
+{
+ char *ip_address;
+ int ret;
+
+ ret = wifi_direct_get_ip_address(&ip_address);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_get_subnet_mask_Positive)
+{
+ char *subnet_mask;
+ int ret;
+
+ ret = wifi_direct_create_group();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_get_subnet_mask(&subnet_mask);
+ free(subnet_mask);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_destroy_group();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_get_subnet_mask_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_get_subnet_mask(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_get_subnet_mask_Negative2)
+{
+ char *subnet_mask;
+ int ret;
+
+ ret = wifi_direct_get_subnet_mask(&subnet_mask);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_get_gateway_address_Positive)
+{
+ char *gateway_address;
+ int ret;
+
+ ret = wifi_direct_create_group();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_get_gateway_address(&gateway_address);
+ free(gateway_address);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_destroy_group();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_get_gateway_address_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_get_gateway_address(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectGroupTest, wifi_direct_get_gateway_address_Negative2)
+{
+ char *gateway_address;
+ int ret;
+
+ ret = wifi_direct_get_gateway_address(&gateway_address);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_is_discoverable_Positive)
+{
+ bool is_discoverable;
+ int ret;
+
+ ret = wifi_direct_is_discoverable(&is_discoverable);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_is_discoverable_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_is_discoverable(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_is_listening_only_Positive)
+{
+ bool is_listening_only;
+ int ret;
+
+ ret = wifi_direct_is_listening_only(&is_listening_only);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_is_listening_only_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_is_listening_only(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_primary_device_type_Positive)
+{
+ wifi_direct_primary_device_type_e type;
+ int ret;
+
+ ret = wifi_direct_get_primary_device_type(&type);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_primary_device_type_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_get_primary_device_type(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_secondary_device_type_Positive)
+{
+ wifi_direct_secondary_device_type_e type;
+ int ret;
+
+ ret = wifi_direct_get_secondary_device_type(&type);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_secondary_device_type_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_get_secondary_device_type(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_autoconnection_mode_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_set_autoconnection_mode(false);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_autoconnection_mode_Negative)
+{
+ int ret;
+
+ mock_gdbus_gdbus_call_sync_enable(false);
+
+ ret = wifi_direct_set_autoconnection_mode(false);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_OPERATION_FAILED, ret);
+
+ mock_gdbus_gdbus_call_sync_enable(true);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_is_autoconnection_mode_Positive)
+{
+ bool auto_connection;
+ int ret;
+
+ ret = wifi_direct_is_autoconnection_mode(&auto_connection);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_is_autoconnection_mode_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_is_autoconnection_mode(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_persistent_group_enabled_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_set_persistent_group_enabled(true);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_persistent_group_enabled_Negative)
+{
+ int ret;
+
+ mock_gdbus_gdbus_call_sync_enable(false);
+
+ ret = wifi_direct_set_persistent_group_enabled(true);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_OPERATION_FAILED, ret);
+
+ mock_gdbus_gdbus_call_sync_enable(true);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_is_persistent_group_enabled_Positive)
+{
+ bool is_enable;
+ int ret;
+
+ ret = wifi_direct_is_persistent_group_enabled(&is_enable);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_is_persistent_group_enabled_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_is_persistent_group_enabled(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+bool wifi_direct_wifi_direct_foreach_persistent_groups_Positive_cb(const char *mac_address, const char *ssid, void *user_data)
+{
+ return true;
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_wifi_direct_foreach_persistent_groups_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_foreach_persistent_groups(wifi_direct_wifi_direct_foreach_persistent_groups_Positive_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_foreach_persistent_groups_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_foreach_persistent_groups(NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_foreach_persistent_groups_Negative2)
+{
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_foreach_persistent_groups(wifi_direct_wifi_direct_foreach_persistent_groups_Positive_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_remove_persistent_group_Positive)
+{
+ char mac_address[] = "dummy";
+ char ssid[] = "dummy";
+ int ret;
+
+ ret = wifi_direct_remove_persistent_group(mac_address, ssid);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_remove_persistent_group_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_remove_persistent_group(NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_remove_persistent_group_Negative2)
+{
+ char mac_address[] = "dummy";
+ char ssid[] = "dummy";
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_remove_persistent_group(mac_address, ssid);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_passphrase_Positive)
+{
+ char passphrase[] = "ABCDEFGH";
+ int ret;
+
+ ret = wifi_direct_set_passphrase(passphrase);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_passphrase_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_set_passphrase(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_passphrase_Negative2)
+{
+ char passphrase[] = "ABCDEFGH";
+ int ret;
+
+ ret = wifi_direct_create_group();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_passphrase(passphrase);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_passphrase_Positive)
+{
+ char *passphrase;
+ int ret;
+
+ ret = wifi_direct_create_group();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_get_passphrase(&passphrase);
+ free(passphrase);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_passphrase_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_get_passphrase(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_passphrase_Negative2)
+{
+ char *passphrase;
+ int ret;
+
+ ret = wifi_direct_get_passphrase(&passphrase);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_autoconnection_peer_Positive)
+{
+ char test_mac[] = {"aa:bb:cc:dd:ee:ff"};
+ int ret;
+
+ ret = wifi_direct_set_autoconnection_peer(test_mac);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_autoconnection_peer_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_set_autoconnection_peer(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_init_display_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_init_display();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_init_display_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_init_display();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_deinit_display_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_deinit_display();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_deinit_display_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_deinit_display();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+TEST_F(WifiDirectSettingTest, wifi_direct_set_display_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_set_display(WIFI_DIRECT_DISPLAY_TYPE_DUAL, 554, 1);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_display_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_set_display(WIFI_DIRECT_DISPLAY_TYPE_DUAL, -1, -1);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_display_Negative2)
+{
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_set_display(WIFI_DIRECT_DISPLAY_TYPE_DUAL, 554, 1);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_display_availability_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_set_display_availability(TRUE);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_display_availability_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_set_display_availability(TRUE);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_display_Positive)
+{
+ wifi_direct_display_type_e type;
+ int port;
+ int hdcp;
+ int ret;
+
+ ret = wifi_direct_get_display(&type, &port, &hdcp);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_display_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_get_display(NULL, NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_display_Negative2)
+{
+ wifi_direct_display_type_e type;
+ int port;
+ int hdcp;
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_get_display(&type, &port, &hdcp);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_display_availability_Positive)
+{
+ bool availability;
+ int ret;
+
+ ret = wifi_direct_get_display_availability(&availability);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_display_availability_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_get_display_availability(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_display_availability_Negative2)
+{
+ bool availability;
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_get_display_availability(&availability);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_peer_display_type_Positive)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ wifi_direct_display_type_e type;
+ int ret;
+
+ ret = wifi_direct_get_peer_display_type(mac_address, &type);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_peer_display_type_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_get_peer_display_type(NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_peer_display_type_Negative2)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ wifi_direct_display_type_e type;
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_get_peer_display_type(mac_address, &type);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_peer_display_availability_Positive)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ bool availability;
+ int ret;
+
+ ret = wifi_direct_get_peer_display_availability(mac_address, &availability);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_peer_display_availability_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_get_peer_display_availability(NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_peer_display_availability_Negative2)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ bool availability;
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_get_peer_display_availability(mac_address, &availability);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_peer_display_hdcp_Positive)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int hdcp;
+ int ret;
+
+ ret = wifi_direct_get_peer_display_hdcp(mac_address, &hdcp);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_peer_display_hdcp_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_get_peer_display_hdcp(NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_peer_display_hdcp_Negative2)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int hdcp;
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_get_peer_display_hdcp(mac_address, &hdcp);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_peer_display_port_Positive)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int port;
+ int ret;
+
+ ret = wifi_direct_get_peer_display_port(mac_address, &port);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_peer_display_port_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_get_peer_display_port(NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_peer_display_port_Negative2)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int port;
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_get_peer_display_port(mac_address, &port);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_peer_display_throughput_Positive)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int throughput;
+ int ret;
+
+ ret = wifi_direct_get_peer_display_throughput(mac_address, &throughput);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_peer_display_throughput_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_get_peer_display_throughput(NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_peer_display_throughput_Negative2)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int throughput;
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_get_peer_display_throughput(mac_address, &throughput);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_session_timer_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_set_session_timer(120);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_session_timer_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_set_session_timer(-1);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_session_timer_Positive)
+{
+ int second;
+ int ret;
+
+ ret = wifi_direct_get_session_timer(&second);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_session_timer_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_get_session_timer(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_auto_group_removal_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_set_auto_group_removal(true);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_auto_group_removal_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_set_auto_group_removal(true);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+TEST_F(WifiDirectSettingTest,wifi_direct_get_peer_rssi_Positive)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int rssi;
+ int ret;
+
+ ret = wifi_direct_get_peer_rssi(mac_address, &rssi);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_peer_rssi_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_get_peer_rssi(NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_peer_rssi_Negative2)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int rssi;
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_get_peer_rssi(mac_address, &rssi);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_add_vsie_Positive)
+{
+ char test_vsie[] = "TestVsieStr";
+ int ret;
+
+ ret = wifi_direct_add_vsie(WIFI_DIRECT_VSIE_FRAME_P2P_PROBE_REQ, test_vsie);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_add_vsie_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_add_vsie(WIFI_DIRECT_VSIE_FRAME_P2P_PROBE_REQ, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_add_vsie_Negative2)
+{
+ char test_vsie[] = "TestVsieStr";
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_add_vsie(WIFI_DIRECT_VSIE_FRAME_P2P_PROBE_REQ, test_vsie);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_vsie_Positive)
+{
+ char *test_vsie;
+ int ret;
+
+ ret = wifi_direct_get_vsie(WIFI_DIRECT_VSIE_FRAME_P2P_PROBE_REQ, &test_vsie);
+ free(test_vsie);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_vsie_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_get_vsie(WIFI_DIRECT_VSIE_FRAME_P2P_PROBE_REQ, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_vsie_Negative2)
+{
+ char *test_vsie;
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_get_vsie(WIFI_DIRECT_VSIE_FRAME_P2P_PROBE_REQ, &test_vsie);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_remove_vsie_Positive)
+{
+ char test_vsie[] = "TestVsieStr";
+ int ret;
+
+ ret = wifi_direct_remove_vsie(WIFI_DIRECT_VSIE_FRAME_P2P_PROBE_REQ, test_vsie);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_remove_vsie_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_remove_vsie(WIFI_DIRECT_VSIE_FRAME_P2P_PROBE_REQ, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_remove_vsie_Negative2)
+{
+ char test_vsie[] = "TestVsieStr";
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_remove_vsie(WIFI_DIRECT_VSIE_FRAME_P2P_PROBE_REQ, test_vsie);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_peer_vsie_Positive)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ char *vsie;
+ int ret;
+
+ ret = wifi_direct_get_peer_vsie(mac_address, &vsie);
+ free(vsie);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_peer_vsie_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_get_peer_vsie(NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_peer_vsie_Negative2)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ char *vsie;
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_get_peer_vsie(mac_address, &vsie);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_wps_config_method_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_set_wps_config_method(WIFI_DIRECT_CONFIG_METHOD_DEFAULT);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_wps_config_method_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_set_wps_config_method(-1);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_set_wps_config_method_Negative2)
+{
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_set_wps_config_method(WIFI_DIRECT_CONFIG_METHOD_DEFAULT);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_wps_config_method_Positive)
+{
+ int type;
+ int ret;
+
+ ret = wifi_direct_get_wps_config_method(&type);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_wps_config_method_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_get_wps_config_method(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_get_wps_config_method_Negative2)
+{
+ int type;
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_get_wps_config_method(&type);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_remove_persistent_device_Positive)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int ret;
+
+ ret = wifi_direct_remove_persistent_device(mac_address);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_remove_persistent_device_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_remove_persistent_device(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_remove_persistent_device_Negative2)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_remove_persistent_device(mac_address);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_remove_all_persistent_devices_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_remove_all_persistent_devices();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_remove_all_persistent_devices_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_remove_all_persistent_devices();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_init_miracast_Positive)
+{
+ int ret;
+
+ ret = wifi_direct_init_miracast(true);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectSettingTest, wifi_direct_init_miracast_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_init_miracast(true);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+class WifiDirectConnectTest : public ::testing::Test {
+protected:
+ void SetUp() override
+ {
+ //Setting up normal condition
+ mock_gdbus_gdbus_sync_enable(true);
+ mock_gdbus_gdbus_call_sync_enable(true);
+ wifi_direct_manager_mock_init();
+
+ int ret;
+ ret = wifi_direct_initialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+ }
+
+ void TearDown() override
+ {
+ int ret;
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_deinitialize();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_deinit();
+ }
+};
+
+TEST_F(WifiDirectConnectTest, wifi_direct_connect_positive)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int ret;
+
+ ret = wifi_direct_set_connection_state_changed_cb(__connection_state_changed_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_client_ip_address_assigned_cb(__client_ip_address_assigned_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_connect(mac_address);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_connection_in_progress_signal();
+ wifi_direct_manager_mock_generate_connection_rsp_with_no_error_go_signal();
+ wifi_direct_manager_mock_generate_peer_ip_assigned_signal();
+ wifi_direct_manager_mock_generate_disconnection_signal();
+
+ ret = wifi_direct_unset_connection_state_changed_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_unset_client_ip_address_assigned_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_connect_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_connect(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_connect_Negative2)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_connect(mac_address);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_accept_connection_positive)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int ret;
+
+ ret = wifi_direct_set_connection_state_changed_cb(__connection_state_changed_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_client_ip_address_assigned_cb(__client_ip_address_assigned_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_connection_request_pbc_signal();
+
+ ret = wifi_direct_accept_connection(mac_address);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_connection_in_progress_signal();
+ wifi_direct_manager_mock_generate_connection_rsp_with_no_error_go_signal();
+ wifi_direct_manager_mock_generate_peer_ip_assigned_signal();
+ wifi_direct_manager_mock_generate_disconnection_signal();
+
+ ret = wifi_direct_unset_connection_state_changed_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_unset_client_ip_address_assigned_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_accept_connection_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_accept_connection(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_accept_connection_Negative2)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_accept_connection(mac_address);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_cancel_connection_positive)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int ret;
+
+
+ ret = wifi_direct_set_connection_state_changed_cb(__connection_state_changed_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_connect(mac_address);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_connection_in_progress_signal();
+
+ ret = wifi_direct_cancel_connection(mac_address);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_connection_canceled_signal();
+
+ ret = wifi_direct_unset_connection_state_changed_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_unset_client_ip_address_assigned_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_cancel_connection_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_cancel_connection(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_cancel_connection_Negative2)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_cancel_connection(mac_address);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_reject_connection_positive)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int ret;
+
+
+ ret = wifi_direct_set_connection_state_changed_cb(__connection_state_changed_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_connection_request_pbc_signal();
+
+ ret = wifi_direct_reject_connection(mac_address);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_connection_canceled_signal();
+
+ ret = wifi_direct_unset_connection_state_changed_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_unset_client_ip_address_assigned_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_reject_connection_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_reject_connection(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_reject_connection_Negative2)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_reject_connection(mac_address);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_disconnect_all_positive)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int ret;
+
+ ret = wifi_direct_set_connection_state_changed_cb(__connection_state_changed_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_client_ip_address_assigned_cb(__client_ip_address_assigned_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_connect(mac_address);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_connection_in_progress_signal();
+ wifi_direct_manager_mock_generate_connection_rsp_with_no_error_go_signal();
+ wifi_direct_manager_mock_generate_peer_ip_assigned_signal();
+
+ ret = wifi_direct_disconnect_all();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_disconnection_signal();
+
+ ret = wifi_direct_unset_connection_state_changed_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_unset_client_ip_address_assigned_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_disconnect_all_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_disconnect_all();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_disconnect_positive)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int ret;
+
+ ret = wifi_direct_set_connection_state_changed_cb(__connection_state_changed_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_client_ip_address_assigned_cb(__client_ip_address_assigned_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_connect(mac_address);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_connection_in_progress_signal();
+ wifi_direct_manager_mock_generate_connection_rsp_with_no_error_go_signal();
+ wifi_direct_manager_mock_generate_peer_ip_assigned_signal();
+
+ ret = wifi_direct_disconnect(mac_address);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_disconnection_signal();
+
+ ret = wifi_direct_unset_connection_state_changed_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_unset_client_ip_address_assigned_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_disconnect_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_disconnect(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_disconnect_Negative2)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_disconnect(mac_address);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+bool wifi_direct_foreach_connected_peers_positive_cb(wifi_direct_connected_peer_info_s *peer, void *user_data)
+{
+ free(peer->device_name);
+ free(peer->mac_address);
+ free(peer->interface_address);
+ free(peer->ip_address);
+ free(peer);
+ return true;
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_foreach_connected_peers_positive)
+{
+ char mac_address[] = "aa:bb:cc:dd:ee:ff";
+ int ret;
+
+ ret = wifi_direct_set_connection_state_changed_cb(__connection_state_changed_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_set_client_ip_address_assigned_cb(__client_ip_address_assigned_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_connect(mac_address);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_connection_in_progress_signal();
+ wifi_direct_manager_mock_generate_connection_rsp_with_no_error_go_signal();
+ wifi_direct_manager_mock_generate_peer_ip_assigned_signal();
+
+ ret = wifi_direct_foreach_connected_peers(wifi_direct_foreach_connected_peers_positive_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_disconnection_signal();
+
+ ret = wifi_direct_unset_connection_state_changed_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ ret = wifi_direct_unset_client_ip_address_assigned_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_foreach_connected_peers_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_foreach_connected_peers(NULL, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_foreach_connected_peers_Negative2)
+{
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_foreach_connected_peers(wifi_direct_foreach_connected_peers_positive_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_get_connecting_peer_info_Positive)
+{
+ wifi_direct_discovered_peer_info_s *peer_info = NULL;
+ int ret;
+
+ ret = wifi_direct_set_connection_state_changed_cb(__connection_state_changed_cb, NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_connection_request_pbc_signal();
+
+ ret = wifi_direct_get_connecting_peer_info(&peer_info);
+ free(peer_info->device_name);
+ free(peer_info->mac_address);
+ free(peer_info->interface_address);
+ free(peer_info);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+
+ ret = wifi_direct_unset_connection_state_changed_cb();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_get_connecting_peer_info_Negative1)
+{
+ int ret;
+
+ ret = wifi_direct_get_connecting_peer_info(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_get_connecting_peer_info_Negative2)
+{
+ wifi_direct_discovered_peer_info_s *peer_info = NULL;
+ int ret;
+
+ ret = wifi_direct_deactivate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_deactivation_signal();
+
+ ret = wifi_direct_get_connecting_peer_info(&peer_info);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NOT_PERMITTED, ret);
+
+ ret = wifi_direct_activate();
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+
+ wifi_direct_manager_mock_generate_activation_signal();
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_set_wps_pin_Positive)
+{
+ char pin[] = {"12345678"};
+ int ret;
+
+ ret = wifi_direct_set_wps_pin(pin);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectDiscoveryTest, wifi_direct_set_wps_pin_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_set_wps_pin(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_get_wps_pin_Positive)
+{
+ char *pin = NULL;
+ int ret;
+
+ ret = wifi_direct_get_wps_pin(&pin);
+ free(pin);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, ret);
+}
+
+TEST_F(WifiDirectConnectTest, wifi_direct_get_wps_pin_Negative)
+{
+ int ret;
+
+ ret = wifi_direct_get_wps_pin(NULL);
+ ASSERT_EQ(WIFI_DIRECT_ERROR_INVALID_PARAMETER, ret);
+}
+
+int main(int argc, char **argv)
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __WIFI_DIRECT_DISPLAY_H__
+#define __WIFI_DIRECT_DISPLAY_H__
+
+namespace WifiDirectManagerNamespace {
+
+class WifiDirectDisplay {
+public:
+ WifiDirectDisplay() :
+ type_(3),
+ port_(554),
+ availability_(1),
+ hdcp_(1),
+ throughput_(54)
+ {};
+ int getType() {return type_;};
+ void setType(int type) {type_ = type;};
+ int getPort() {return port_;};
+ void setPort(int port) {port_ = port;};
+ int getAvailability() {return availability_;};
+ void setAvailability(int availability) {availability_ = availability;};
+ int getHdcp() {return hdcp_;};
+ void setHdcp(int hdcp) {hdcp_ = hdcp;};
+ int getThroughput() {return throughput_;};
+ void setThroughput(int throughput) {throughput_ = throughput;};
+private:
+ int type_;
+ int port_;
+ int availability_;
+ int hdcp_;
+ int throughput_;
+};
+
+}
+
+#endif /* __WIFI_DIRECT_DISPLAY_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __WIFI_DIRECT_ERROR_H__
+#define __WIFI_DIRECT_ERROR_H__
+
+#include <glib.h>
+#include <gio/gio.h>
+
+namespace WifiDirectManagerNamespace {
+
+class WifiDirectError {
+public:
+ WifiDirectError();
+ ~WifiDirectError();
+ GError *InvaildParameter(void);
+ GError *NotPermitted(void);
+ GError *OperationFailed(void);
+};
+
+}
+
+#endif /* __WIFI_DIRECT_STATE_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __WIFI_DIRECT_GROUP_H__
+#define __WIFI_DIRECT_GROUP_H__
+
+namespace WifiDirectManagerNamespace {
+
+#define WFD_GROUP_FLAG_NONE 0
+#define WFD_GROUP_FLAG_PERSISTENT 1
+#define WFD_GROUP_FLAG_AUTONOMOUS 2
+
+#define WFD_DEV_ROLE_NONE 0
+#define WFD_DEV_ROLE_GC 1
+#define WFD_DEV_ROLE_GO 2
+
+class WifiDirectGroup {
+public:
+ WifiDirectGroup() :
+ flag_(WFD_GROUP_FLAG_NONE),
+ role_(0),
+ member_cnt_(0),
+ op_channel_(2412),
+ iface_name_("wlan0"),
+ ip_addr_("192.168.0.1"),
+ subnet_mask_("255.255.255.0"),
+ gateway_addr_("192.168.0.1"),
+ passphrase_("ABCDEFG")
+ {};
+ void setRole(int role) { role_ = role;};
+ int getRole() {return role_;};
+ void setFlag(int flag) {flag_ = flag_ | flag;};
+ int getFlag() {return flag_;};
+ int getOperatingChannel() {return op_channel_;};
+ std::string getIfaceName() {return this->iface_name_;}
+ std::string getIpAddr() {return this->ip_addr_;}
+ std::string getSubnetMask() {return this->subnet_mask_;}
+ std::string getGatewayAddr() {return this->gateway_addr_;}
+ std::string getPassphrase() {return this->passphrase_;}
+private:
+ int flag_;
+ int role_;
+ int member_cnt_;
+ int op_channel_;
+ std::string iface_name_;
+ std::string ip_addr_;
+ std::string subnet_mask_;
+ std::string gateway_addr_;
+ std::string passphrase_;
+};
+
+}
+
+#endif /* __WIFI_DIRECT_PEER_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __WIFI_DIRECT_MANAGER_H__
+#define __WIFI_DIRECT_MANAGER_H__
+
+#include <map>
+#include <string>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "WifiDirectDisplay.h"
+#include "WifiDirectService.h"
+#include "WifiDirectSetting.h"
+#include "WifiDirectPeer.h"
+#include "WifiDirectGroup.h"
+#include "WifiDirectError.h"
+#include "WifiDirectState.h"
+#include "WifiDirectMethod.h"
+
+#define WFD_WPS_MODE_PBC 0x1
+#define WFD_WPS_MODE_DISPLAY 0x2
+#define WFD_WPS_MODE_KEYPAD 0x4
+
+#define WFD_SCAN_MODE_NONE 0x0
+#define WFD_SCAN_MODE_ACTIVE 0x1
+#define WFD_SCAN_MODE_PASSIVE 0x2
+
+/**
+ * Wi-Fi Direct connection state
+ */
+typedef enum {
+ WFD_EVENT_CONNECTION_REQ, /**< Connection is requested */
+ WFD_EVENT_CONNECTION_WPS_REQ, /**< WPS is requested */
+ WFD_EVENT_CONNECTION_IN_PROGRESS, /**< Connection in progress */
+ WFD_EVENT_CONNECTION_RSP, /**< Connected */
+ WFD_EVENT_DISASSOCIATION_IND, /**< Disconnected by remote Group Client */
+ WFD_EVENT_DISCONNECTION_RSP, /**< Disconnected by local device */
+ WFD_EVENT_DISCONNECTION_IND, /**< Disconnected by remote Group Owner */
+ WFD_EVENT_GROUP_CREATED, /**< Group is created */
+ WFD_EVENT_GROUP_DESTROYED, /**< Group is destroyed */
+} wfd_connection_event_e;
+
+namespace WifiDirectManagerNamespace {
+
+class WifiDirectManager {
+public:
+ WifiDirectManager();
+ ~WifiDirectManager();
+ GVariant *callMethod(const gchar *method_name,
+ GVariant *parameters,
+ GError **error);
+ void setState(const WifiDirectState state);
+ WifiDirectState getState() {return state_;};
+ int getScanMode() {return scan_mode_;};
+
+ GError *startDiscovery(int mode, int timeout,
+ const char* type, int channel, int frequency);
+ GError *stopDiscovery();
+ GError *createGroup(const char *ssid);
+ GError *destroyGroup();
+ GError *isGroupOwner(gboolean *is_group_owner);
+ GError *isAutoGroup(gboolean *is_auto_group);
+
+ GError *getMacAddress(std::string &mac_addr);
+ GError *setGoIntent(int go_intent);
+ GError *getGoIntent(int *go_intent);
+ GError *setMaxClient(int max_client);
+ GError *getMaxClient(int *max_client);
+ GError *getOperatingChannel(int *channel);
+ GError *ActivatePushbutton();
+ GError *GetSupportedWpsMode(int *supported_wps_mode);
+ GError *GetLocalWpsMode(int *wps_mode);
+ GError *setRequestWpsMode(int wps_mode);
+ GError *GetRequestWpsMode(int *wps_mode);
+ GError *setDeviceName(std::string device_name);
+ GError *getDeviceName(std::string &device_name);
+ GError *getInterfaceName(std::string &iface_name);
+ GError *getIpAddr(std::string &ip_addr);
+ GError *getSubnetMask(std::string &subnet_mask);
+ GError *getGatewayAddr(std::string &gateway_addr);
+
+ GError *enablePersistentGroup(gboolean enable);
+ GError *isPersistentGruopEnabled(gboolean *enable);
+
+ GError *getPersistentGroup(GVariant **group);
+ GError *removePersistentGroup(void);
+
+ GError *registerService(int service_type, std::string &info, int *service_id);
+ GError *deregisterService(int service_id);
+ GError *setPassphrase(std::string &passphrase);
+ GError *getPassphrase(std::string &passphrase);
+ GError *initDisplay(void);
+ GError *deinitDisplay(void);
+ GError *setConfig(int type, int port, int hdcp);
+ GError *getConfig(int *type, int *port, int *hdcp);
+ GError *setAvailiability(int availability);
+ GError *getAvailiability(int &availability);
+ GError *getPeerType(std::string &mac_addr, int *type);
+ GError *getPeerAvailability(std::string &mac_addr, int *availability);
+ GError *getPeerHdcp(std::string &mac_addr, int *hdcp);
+ GError *getPeerPort(std::string &mac_addr, int *port);
+ GError *getPeerThroughput(std::string &mac_addr, int *throuput);
+ GError *getPeerRssi(std::string &mac_addr, int *rssi);
+ GError *setSessionTimer(int second);
+ GError *getSessionTimer(int *second);
+ GError *setAutoGruopRemove(bool remove);
+ GError *addVsie(int frame_id, std::string &vsie);
+ GError *getVsie(int frame_id, std::string &vsie);
+ GError *removeVsie(int frame_id, std::string &vsie);
+ GError *getPeerVsie(std::string &mac_addr, std::string &vsie);
+ GError *setWpsConfigMethod(int wps_method);
+ GError *getWpsConfigMethod(int &wps_method);
+ GError *removePersistentDevice(std::string &mac_addr);
+ GError *removeAllPersistentDevice(void);
+ GError *connect(std::string &mac_addr);
+ GError *acceptConnection(std::string &mac_addr);
+ GError *cancelConnection(std::string &mac_addr);
+ GError *rejectConnection(std::string &mac_addr);
+ GError *disconnectAll(void);
+ GError *disconnect(std::string &mac_addr);
+ GError *getConnectedPeers(GVariant **ret);
+ GError *GetConnectingPeer(GVariant **ret);
+
+ GVariant *getPeerInfoGvariant(void);
+ GVariant *getDiscoveredPeersGvariant(void);
+
+ GVariant *activated(void);
+ GVariant *deactivated(void);
+
+ GVariant *peerFound(void);
+ GVariant *peerLost(void);
+
+ GVariant *connectionInProgress(void);
+ GVariant *connectionRspWithNoErrorGO(void);
+ GVariant *peerIpAssigned(void);
+ GVariant *disconnection(void);
+ GVariant *connectionRequestPbc(void);
+ GVariant *connectionCanceled(void);
+
+private:
+ WifiDirectError error_handler_;
+ WifiDirectSetting setting_;
+ WifiDirectState state_;
+ WifiDirectPeer peer_;
+ WifiDirectGroup *group_;
+ WifiDirectDisplay display_info_;
+ int config_methods_;
+ int wps_mode_;
+ int req_wps_mode_;
+ int scan_mode_;
+ int session_timer_;
+ bool auto_group_remove_;
+ gboolean persistent_gruop_enabled_;
+ std::string mac_address_;
+ std::string passphrase_;
+ std::map<std::string , WifiDirectMethod *> method_map_;
+ std::map<int, WifiDirectService *> service_map_;
+ gboolean isNotDiscoverable();
+};
+
+}
+
+#endif /* __WIFI_DIRECT_MANAGER_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __WIFI_DIRECT_METHOD_H__
+#define __WIFI_DIRECT_METHOD_H__
+
+#include <string>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+namespace WifiDirectManagerNamespace {
+
+class WifiDirectMethod {
+public:
+ virtual ~WifiDirectMethod() {};
+ virtual GVariant *handleMethod(GVariant *parameters, GError **error) = 0;
+};
+
+}
+
+#endif /* __WIFI_DIRECT_METHOD_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __WIFI_DIRECT_PEER_H__
+#define __WIFI_DIRECT_PEER_H__
+
+#include <stdbool.h>
+#include <string>
+#include <glib.h>
+
+#include "WifiDirectDisplay.h"
+
+
+#define WFD_OEM_WPS_MODE_PBC 0x1
+#define WFD_OEM_WPS_MODE_DISPLAY 0x2
+#define WFD_OEM_WPS_MODE_KEYPAD 0x4
+#define WFD_OEM_WPS_MODE_P2PS 0x8
+
+#define WFD_OEM_DEV_ROLE_NONE 0
+#define WFD_OEM_DEV_ROLE_GC 1
+#define WFD_OEM_DEV_ROLE_GO 2
+
+#define WFD_OEM_GROUP_FLAG_GROUP_OWNER 0x1
+#define WFD_OEM_GROUP_FLAG_PERSISTENT_GROUP 0x2
+
+#define MACADDR_LEN 6
+#define IPADDR_LEN 4
+
+namespace WifiDirectManagerNamespace {
+
+class WifiDirectPeer {
+public:
+ WifiDirectPeer() :
+ device_addr_{0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
+ iface_addr_{0xaa, 0xbb, 0xcc, 0xdd, 0xef, 0xff},
+ go_addr_{0x11, 0x22, 0x33, 0x44, 0x55, 0x66},
+ config_methods_(WFD_OEM_WPS_MODE_PBC),
+ dev_flag_(0x25),
+ group_flag_(0x0),
+ dev_role_(WFD_OEM_DEV_ROLE_NONE),
+ pri_dev_type_(10),
+ sec_dev_type_(1),
+ ip_addr_{192, 168, 49, 100},
+ ip_addr_mask_{255, 255, 255, 0},
+ ip_addr_go_{192, 168, 49, 1},
+ channel_(81),
+ group_freq_(2412),
+ is_wfd_device_(true),
+ rssi_(-42),
+ vsie_("TestVsie")
+ {};
+
+ GVariant *getPeerGvariant();
+ GVariantBuilder *getPeerGvariantBuilder();
+ WifiDirectDisplay getDisplay_info() {return display_info_;};
+ int getRssi() {return rssi_;};
+ std::string getVsie() {return vsie_;};
+ std::string getAddress() {return address_;};
+
+private:
+ const std::string device_name_ = "Test";
+ const std::string address_ = "aa:bb:cc:dd:ee:ff";
+ const unsigned char device_addr_[MACADDR_LEN];
+ const unsigned char iface_addr_[MACADDR_LEN];
+ const unsigned char go_addr_[MACADDR_LEN];
+ const int config_methods_;
+ const int dev_flag_;
+ const int group_flag_;
+ const int dev_role_;
+ const unsigned char pri_dev_type_;
+ const unsigned char sec_dev_type_;
+ const unsigned char ip_addr_[IPADDR_LEN];
+ const unsigned char ip_addr_mask_[IPADDR_LEN];
+ const unsigned char ip_addr_go_[IPADDR_LEN];
+ const int channel_;
+ const int group_freq_;
+ const bool is_wfd_device_;
+ const int rssi_;
+ WifiDirectDisplay display_info_;
+ std::string vsie_;
+
+ GVariant* packGVariantAy(const unsigned char *src, int size);
+};
+
+}
+
+#endif /* __WIFI_DIRECT_PEER_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __WIFI_DIRECT_SERVICE_H__
+#define __WIFI_DIRECT_SERVICE_H__
+
+namespace WifiDirectManagerNamespace {
+
+class WifiDirectService {
+public:
+ WifiDirectService(std::string &info) :
+ id_(7),
+ info_(info)
+ {};
+ int getId() {return id_;};
+private:
+ int id_;
+ std::string info_;
+};
+
+}
+
+#endif /* __WIFI_DIRECT_SERVICE_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __WIFI_DIRECT_SETTING_H__
+#define __WIFI_DIRECT_SETTING_H__
+
+namespace WifiDirectManagerNamespace {
+
+class WifiDirectSetting {
+public:
+ WifiDirectSetting() :
+ go_intent_(7),
+ max_client_(10),
+ device_name_("TIZEN")
+ {};
+ void setGoIntent(int go_intent) { go_intent_ = go_intent;};
+ int getGoIntent() {return go_intent_;};
+ void setMaxClient(int max_client) { max_client_ = max_client;};
+ int getMaxClient() {return max_client_;};
+ void setDeviceName(std::string device_name) { device_name_ = device_name;};
+ std::string getDeviceName() {return device_name_;};
+private:
+ int go_intent_;
+ int max_client_;
+ std::string device_name_;
+};
+
+}
+
+#endif /* __WIFI_DIRECT_SETTING_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __WIFI_DIRECT_SIGNAL_GENERATOR_H__
+#define __WIFI_DIRECT_SIGNAL_GENERATOR_H__
+
+#include <string>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+namespace WifiDirectManagerNamespace {
+
+class WifiDirectSignal {
+public:
+ WifiDirectSignal(guint id,
+ const gchar *member,
+ GDBusSignalCallback callback,
+ gpointer user_data) : id_(0), member_(std::string(member)), callback_(callback), user_data_(user_data) {}
+
+ std::string getName();
+ void generate(GVariant *parameters);
+private:
+ unsigned int id_;
+ std::string member_;
+ GDBusSignalCallback callback_;
+ gpointer user_data_;
+};
+
+}
+
+#endif /* __WIFI_DIRECT_SIGNAL_GENERATOR_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __WIFI_DIRECT_STATE_H__
+#define __WIFI_DIRECT_STATE_H__
+
+namespace WifiDirectManagerNamespace {
+
+enum class WifiDirectState {
+ kWifiDirectStateDeactivated, /**< Deactivated */
+ kWifiDirectStateDeactivating, /**< Deactivating */
+ kWifiDirectStateActivating, /**< Activating */
+ kWifiDirectStateActivated, /**< Activated */
+ kWifiDirectStateDiscovering, /**< Discovering */
+ kWifiDirectStateConnecting, /**< Connecting */
+ kWifiDirectStateDisconnecting, /**< Disconnecting */
+ kWifiDirectStateConnected, /**< Connected */
+ kWifiDirectStateGroupowner /**< Group owner */
+};
+
+}
+
+#endif /* __WIFI_DIRECT_STATE_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __MOCK_GDBUS_H__
+#define __MOCK_GDBUS_H__
+
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void mock_gdbus_gdbus_sync_enable(bool value);
+void mock_gdbus_gdbus_call_sync_enable(bool value);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MOCK_GDBUS_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __MOCK_SYSINFO_H__
+#define __MOCK_SYSINFO_H__
+
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void mock_sysinfo_set_up_wifi_direct(bool value);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MOCK_SYSINFO_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __WIFI_DIRECT_MANAGER_MOCK_H__
+#define __WIFI_DIRECT_MANAGER_MOCK_H__
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void wifi_direct_manager_mock_init();
+void wifi_direct_manager_mock_deinit();
+
+GVariant *wifi_direct_manager_mock_gdbus_call_sync(const gchar *method_name,
+ GVariant *parameters,
+ GError **error);
+
+void wifi_direct_manager_mock_gdbus_signal_subscribe(
+ guint id,
+ const gchar *member,
+ GDBusSignalCallback callback,
+ gpointer user_data);
+
+void wifi_direct_manager_mock_gdbus_signal_unsubscribe(guint id);
+
+void wifi_direct_manager_mock_generate_activation_signal();
+void wifi_direct_manager_mock_generate_deactivation_signal();
+void wifi_direct_manager_mock_generate_listen_started_signal();
+void wifi_direct_manager_mock_generate_discovery_started_signal();
+void wifi_direct_manager_mock_generate_discovery_finished_signal();
+void wifi_direct_manager_mock_generate_peer_found_signal();
+void wifi_direct_manager_mock_generate_peer_lost_signal();
+void wifi_direct_manager_mock_generate_created_signal();
+void wifi_direct_manager_mock_generate_destroyed_signal();
+void wifi_direct_manager_mock_generate_connection_in_progress_signal();
+void wifi_direct_manager_mock_generate_connection_rsp_with_no_error_go_signal();
+void wifi_direct_manager_mock_generate_peer_ip_assigned_signal();
+void wifi_direct_manager_mock_generate_disconnection_signal();
+void wifi_direct_manager_mock_generate_connection_request_pbc_signal();
+void wifi_direct_manager_mock_generate_connection_canceled_signal();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __WIFI_DIRECT_MANAGER_MOCK_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "wifi-direct.h"
+#include "WifiDirectError.h"
+
+using namespace WifiDirectManagerNamespace;
+
+#define WFD_MANAGER_QUARK (g_quark_from_string("wifi-direct-error-quark"))
+
+WifiDirectError::WifiDirectError()
+{
+ g_dbus_error_register_error(WFD_MANAGER_QUARK,
+ WIFI_DIRECT_ERROR_INVALID_PARAMETER,
+ "net.wifidirect.Error.InvalidParameter");
+
+
+ g_dbus_error_register_error(WFD_MANAGER_QUARK,
+ WIFI_DIRECT_ERROR_NOT_PERMITTED,
+ "net.wifidirect.Error.NotPermitted");
+
+
+ g_dbus_error_register_error(WFD_MANAGER_QUARK,
+ WIFI_DIRECT_ERROR_OPERATION_FAILED,
+ "net.wifidirect.Error.OperationFailed");
+
+
+ g_dbus_error_register_error(WFD_MANAGER_QUARK,
+ WIFI_DIRECT_ERROR_TOO_MANY_CLIENT,
+ "net.wifidirect.Error.TooManyClient");
+}
+
+WifiDirectError::~WifiDirectError()
+{
+ g_dbus_error_unregister_error(WFD_MANAGER_QUARK,
+ WIFI_DIRECT_ERROR_INVALID_PARAMETER,
+ "net.wifidirect.Error.InvalidParameter");
+
+
+ g_dbus_error_unregister_error(WFD_MANAGER_QUARK,
+ WIFI_DIRECT_ERROR_NOT_PERMITTED,
+ "net.wifidirect.Error.NotPermitted");
+
+
+ g_dbus_error_unregister_error(WFD_MANAGER_QUARK,
+ WIFI_DIRECT_ERROR_OPERATION_FAILED,
+ "net.wifidirect.Error.OperationFailed");
+
+
+ g_dbus_error_unregister_error(WFD_MANAGER_QUARK,
+ WIFI_DIRECT_ERROR_TOO_MANY_CLIENT,
+ "net.wifidirect.Error.TooManyClient");
+}
+
+GError *WifiDirectError::InvaildParameter(void)
+{
+ return g_dbus_error_new_for_dbus_error(
+ "net.wifidirect.Error.InvalidParameter",
+ "net.wifidirect.Error.InvalidParameter");
+}
+
+GError *WifiDirectError::NotPermitted(void)
+{
+ return g_dbus_error_new_for_dbus_error(
+ "net.wifidirect.Error.NotPermitted",
+ "net.wifidirect.Error.NotPermitted");
+}
+
+GError *WifiDirectError::OperationFailed(void)
+{
+ return g_dbus_error_new_for_dbus_error(
+ "net.wifidirect.Error.OperationFailed",
+ "net.wifidirect.Error.OperationFailed");
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+
+#include "wifi-direct.h"
+
+#include "WifiDirectManager.h"
+
+using namespace WifiDirectManagerNamespace;
+
+class AddClientHandler : WifiDirectMethod {
+public:
+ AddClientHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~AddClientHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ *error = NULL;
+ return g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "AddClient";
+ WifiDirectManager *mgr_;
+};
+
+class ActivateHandler : WifiDirectMethod {
+public:
+ ActivateHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~ActivateHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ *error = NULL;
+
+ return g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "Activate";
+ WifiDirectManager *mgr_;
+};
+
+class DeactivateHandler : WifiDirectMethod {
+public:
+ DeactivateHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~DeactivateHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ *error = NULL;
+
+ return g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "Deactivate";
+ WifiDirectManager *mgr_;
+};
+
+class StartDiscoveryHandler : WifiDirectMethod {
+public:
+ StartDiscoveryHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~StartDiscoveryHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ gboolean mode = FALSE;
+ gint32 timeout = 0;
+ gint32 channel = 0;
+ gint32 frequency = 0;
+ const gchar *type = NULL;
+ GVariantIter *iter = NULL;
+ gchar *key = NULL;
+ GVariant *var = NULL;
+ GVariant *ret = NULL;
+
+ if (g_strcmp0("(is)", g_variant_get_type_string(parameters)) != 0) {
+ g_variant_get(parameters, "(a{sv})", &iter);
+
+ while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
+ if (!g_strcmp0(key, "Mode"))
+ g_variant_get(var, "b", &mode);
+ else if (!g_strcmp0(key, "Timeout"))
+ g_variant_get(var, "i", &timeout);
+ else if (!g_strcmp0(key, "Type"))
+ g_variant_get(var, "&s", &type);
+ else if (!g_strcmp0(key, "Channel"))
+ g_variant_get(var, "i", &channel);
+ else if (!g_strcmp0(key, "Frequency"))
+ g_variant_get(var, "i", &frequency);
+ else
+ ;/* Do Nothing */
+ }
+
+ }
+ *error = mgr_->startDiscovery(mode, timeout, type, channel, frequency);
+ g_variant_iter_free(iter);
+
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "StartDiscovery";
+ WifiDirectManager *mgr_;
+};
+
+class StopDiscoveryHandler : WifiDirectMethod {
+public:
+ StopDiscoveryHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~StopDiscoveryHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ *error = mgr_->stopDiscovery();
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "StopDiscovery";
+ WifiDirectManager *mgr_;
+};
+
+class GetDiscoveredPeersHandler : WifiDirectMethod {
+public:
+ GetDiscoveredPeersHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetDiscoveredPeersHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ return mgr_->getDiscoveredPeersGvariant();
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetDiscoveredPeers";
+ WifiDirectManager *mgr_;
+};
+
+class CreateGroupHandler : WifiDirectMethod {
+public:
+ CreateGroupHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~CreateGroupHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariantIter *iter = NULL;
+ gchar *key = NULL;
+ GVariant *var = NULL;
+ GVariant *ret = NULL;
+ const char *ssid = NULL;
+
+ g_variant_get(parameters, "(a{sv})", &iter);
+
+ while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
+ if (!g_strcmp0(key, "ssid")) {
+ g_variant_get(var, "&s", &ssid);
+ }
+ }
+
+ *error = mgr_->createGroup(ssid);
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ g_variant_iter_free(iter);
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "CreateGroup";
+ WifiDirectManager *mgr_;
+};
+
+class DestroyGroupHandler : WifiDirectMethod {
+public:
+ DestroyGroupHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~DestroyGroupHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ *error = mgr_->destroyGroup();
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "DestroyGroup";
+ WifiDirectManager *mgr_;
+};
+
+class IsGroupOwnerHandler : WifiDirectMethod {
+public:
+ IsGroupOwnerHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~IsGroupOwnerHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ gboolean is_group_owner;
+ GVariant *ret = NULL;
+
+ *error = mgr_->isGroupOwner(&is_group_owner);
+ if (*error == NULL)
+ ret = g_variant_new("(b)", is_group_owner);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "IsGroupOwner";
+ WifiDirectManager *mgr_;
+};
+
+class GetMacAddressHandler : WifiDirectMethod {
+public:
+ GetMacAddressHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetMacAddressHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ std::string mac_addr;
+ GVariant *ret = NULL;
+
+ *error = mgr_->getMacAddress(mac_addr);
+ if (*error == NULL)
+ ret = g_variant_new("(is)", WIFI_DIRECT_ERROR_NONE, mac_addr.c_str());
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetMacAddress";
+ WifiDirectManager *mgr_;
+};
+
+class IsAutoGroupHandler : WifiDirectMethod {
+public:
+ IsAutoGroupHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~IsAutoGroupHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ gboolean is_auto_group;
+ GVariant *ret = NULL;
+
+ *error = mgr_->isGroupOwner(&is_auto_group);
+ if (*error == NULL)
+ ret = g_variant_new("(b)", is_auto_group);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "IsAutoGroup";
+ WifiDirectManager *mgr_;
+};
+
+class SetGoIntentHandler : WifiDirectMethod {
+public:
+ SetGoIntentHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~SetGoIntentHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ int go_intent = 0;
+
+ g_variant_get(parameters, "(i)", &go_intent);
+
+ *error = mgr_->setGoIntent(go_intent);
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "SetGoIntent";
+ WifiDirectManager *mgr_;
+};
+
+class GetGoIntentHandler : WifiDirectMethod {
+public:
+ GetGoIntentHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetGoIntentHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ int go_intent = 0;
+
+ *error = mgr_->getGoIntent(&go_intent);
+ if (*error == NULL)
+ ret = g_variant_new("(ii)", WIFI_DIRECT_ERROR_NONE, go_intent);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetGoIntent";
+ WifiDirectManager *mgr_;
+};
+
+class SetGoIntentPerTypeHandler : WifiDirectMethod {
+public:
+ SetGoIntentPerTypeHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~SetGoIntentPerTypeHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ return g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "SetGoIntentPerType";
+ WifiDirectManager *mgr_;
+};
+
+class GetGoIntentPerTypeHandler : WifiDirectMethod {
+public:
+ GetGoIntentPerTypeHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetGoIntentPerTypeHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ return g_variant_new("(ii)", WIFI_DIRECT_ERROR_NONE, 7);
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetGoIntentPerType";
+ WifiDirectManager *mgr_;
+};
+
+class SetMaxClientHandler : WifiDirectMethod {
+public:
+ SetMaxClientHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~SetMaxClientHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ int max_client;
+
+ g_variant_get(parameters, "(i)", &max_client);
+ *error = mgr_->setMaxClient(max_client);
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "SetMaxClient";
+ WifiDirectManager *mgr_;
+};
+
+class GetMaxClientHandler : WifiDirectMethod {
+public:
+ GetMaxClientHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetMaxClientHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ int max_client;
+
+ *error = mgr_->getMaxClient(&max_client);
+ if (*error == NULL)
+ ret = g_variant_new("(ii)", WIFI_DIRECT_ERROR_NONE, max_client);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetMaxClient";
+ WifiDirectManager *mgr_;
+};
+
+class GetOperatingChannelHandler : WifiDirectMethod {
+public:
+ GetOperatingChannelHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetOperatingChannelHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ int channel = 0;
+
+ *error = mgr_->getOperatingChannel(&channel);
+ if (*error == NULL)
+ ret = g_variant_new("(ii)", WIFI_DIRECT_ERROR_NONE, channel);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetOperatingChannel";
+ WifiDirectManager *mgr_;
+};
+
+class ActivatePushButtonHandler : WifiDirectMethod {
+public:
+ ActivatePushButtonHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~ActivatePushButtonHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ *error = mgr_->ActivatePushbutton();
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "ActivatePushButton";
+ WifiDirectManager *mgr_;
+};
+
+class GetSupportedWpsModeHandler : WifiDirectMethod {
+public:
+ GetSupportedWpsModeHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetSupportedWpsModeHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ int supported_wps_mode;
+ mgr_->GetSupportedWpsMode(&supported_wps_mode);
+
+ return g_variant_new("(ii)", WIFI_DIRECT_ERROR_NONE, supported_wps_mode);
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetSupportedWpsMode";
+ WifiDirectManager *mgr_;
+};
+
+class GetLocalWpsModeHandler : WifiDirectMethod {
+public:
+ GetLocalWpsModeHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetLocalWpsModeHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ int wps_mode;
+ mgr_->GetLocalWpsMode(&wps_mode);
+
+ return g_variant_new("(ii)", WIFI_DIRECT_ERROR_NONE, wps_mode);
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetLocalWpsMode";
+ WifiDirectManager *mgr_;
+};
+
+class SetReqWpsModeHandler : WifiDirectMethod {
+public:
+ SetReqWpsModeHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~SetReqWpsModeHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ int wps_mode;
+
+ g_variant_get(parameters, "(i)", &wps_mode);
+
+ mgr_->setRequestWpsMode(wps_mode);
+
+ return g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "SetReqWpsMode";
+ WifiDirectManager *mgr_;
+};
+
+class GetReqWpsModeHandler : WifiDirectMethod {
+public:
+ GetReqWpsModeHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetReqWpsModeHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ int wps_mode;
+
+ mgr_->GetRequestWpsMode(&wps_mode);
+
+ return g_variant_new("(ii)", WIFI_DIRECT_ERROR_NONE, wps_mode);
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetReqWpsMode";
+ WifiDirectManager *mgr_;
+};
+
+class GetDeviceNameHandler : WifiDirectMethod {
+public:
+ GetDeviceNameHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetDeviceNameHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ std::string device_name;
+
+ mgr_->getDeviceName(device_name);
+
+ return g_variant_new("(is)", WIFI_DIRECT_ERROR_NONE, device_name.c_str());
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetDeviceName";
+ WifiDirectManager *mgr_;
+};
+
+class SetDeviceNameHandler : WifiDirectMethod {
+public:
+ SetDeviceNameHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~SetDeviceNameHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ const char *device_name = NULL;
+
+ g_variant_get(parameters, "(&s)", &device_name);
+
+ mgr_->setDeviceName(std::string(device_name));
+
+ return g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "SetDeviceName";
+ WifiDirectManager *mgr_;
+};
+
+class GetInterfaceNameHandler : WifiDirectMethod {
+public:
+ GetInterfaceNameHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetInterfaceNameHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ std::string iface_name;
+
+ *error = mgr_->getInterfaceName(iface_name);
+ if (*error == NULL)
+ ret = g_variant_new("(is)", WIFI_DIRECT_ERROR_NONE, iface_name.c_str());
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetInterfaceName";
+ WifiDirectManager *mgr_;
+};
+
+class GetIPAddressHandler : WifiDirectMethod {
+public:
+ GetIPAddressHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetIPAddressHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ std::string ip_address;
+
+ *error = mgr_->getIpAddr(ip_address);
+ if (*error == NULL)
+ ret = g_variant_new("(is)", WIFI_DIRECT_ERROR_NONE, ip_address.c_str());
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetIPAddress";
+ WifiDirectManager *mgr_;
+};
+
+class GetSubnetMaskHandler : WifiDirectMethod {
+public:
+ GetSubnetMaskHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetSubnetMaskHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ std::string subnet_mask;
+
+ *error = mgr_->getSubnetMask(subnet_mask);
+ if (*error == NULL)
+ ret = g_variant_new("(is)", WIFI_DIRECT_ERROR_NONE, subnet_mask.c_str());
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetSubnetMask";
+ WifiDirectManager *mgr_;
+};
+
+class GetGatewayHandler : WifiDirectMethod {
+public:
+ GetGatewayHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetGatewayHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ std::string gateway_address;
+
+ *error = mgr_->getGatewayAddr(gateway_address);
+ if (*error == NULL)
+ ret = g_variant_new("(is)", WIFI_DIRECT_ERROR_NONE, gateway_address.c_str());
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetGateway";
+ WifiDirectManager *mgr_;
+};
+
+class IsDiscoverableHandler : WifiDirectMethod {
+public:
+ IsDiscoverableHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~IsDiscoverableHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ gboolean is_auto_group;
+
+ mgr_->isAutoGroup(&is_auto_group);
+ *error = NULL;
+
+ return g_variant_new("(b)", (mgr_->getState() == WifiDirectState::kWifiDirectStateDiscovering ||
+ is_auto_group));
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "IsDiscoverable";
+ WifiDirectManager *mgr_;
+};
+
+class IsListeningOnlyHandler : WifiDirectMethod {
+public:
+ IsListeningOnlyHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~IsListeningOnlyHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ *error = NULL;
+
+ return g_variant_new("(b)", (mgr_->getScanMode() == WFD_SCAN_MODE_PASSIVE));
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "IsListeningOnly";
+ WifiDirectManager *mgr_;
+};
+
+class GetPrimaryDevTypeHandler : WifiDirectMethod {
+public:
+ GetPrimaryDevTypeHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetPrimaryDevTypeHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ *error = NULL;
+
+ return g_variant_new("(ii)", WIFI_DIRECT_ERROR_NONE, 10);
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetPrimaryDevType";
+ WifiDirectManager *mgr_;
+};
+
+class GetSecondaryDevTypeHandler : WifiDirectMethod {
+public:
+ GetSecondaryDevTypeHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetSecondaryDevTypeHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ *error = NULL;
+
+ return g_variant_new("(ii)", WIFI_DIRECT_ERROR_NONE, 5);
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetSecondaryDevType";
+ WifiDirectManager *mgr_;
+};
+
+class SetAutoConnectionModeHandler : WifiDirectMethod {
+public:
+ SetAutoConnectionModeHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~SetAutoConnectionModeHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ *error = NULL;
+
+ return g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "SetAutoConnectionMode";
+ WifiDirectManager *mgr_;
+};
+
+class IsAutoConnectionModeHandler : WifiDirectMethod {
+public:
+ IsAutoConnectionModeHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~IsAutoConnectionModeHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ *error = NULL;
+
+ return g_variant_new("(ib)", WIFI_DIRECT_ERROR_NONE, TRUE);
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "IsAutoConnectionMode";
+ WifiDirectManager *mgr_;
+};
+
+class SetPersistentGroupEnabledHandler : WifiDirectMethod {
+public:
+ SetPersistentGroupEnabledHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~SetPersistentGroupEnabledHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ gboolean enable;
+
+ g_variant_get(parameters, "(b)", &enable);
+
+ *error = mgr_->enablePersistentGroup(enable);
+
+ return g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "SetPersistentGroupEnabled";
+ WifiDirectManager *mgr_;
+};
+
+class IsPersistentGroupEnabledHandler : WifiDirectMethod {
+public:
+ IsPersistentGroupEnabledHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~IsPersistentGroupEnabledHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ gboolean enable;
+
+ *error = mgr_->isPersistentGruopEnabled(&enable);
+
+ return g_variant_new("(ib)", WIFI_DIRECT_ERROR_NONE, enable);
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "IsPersistentGroupEnabled";
+ WifiDirectManager *mgr_;
+};
+
+class GetPersistentGroupsHandler : WifiDirectMethod {
+public:
+ GetPersistentGroupsHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetPersistentGroupsHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ *error = mgr_->getPersistentGroup(&ret);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetPersistentGroups";
+ WifiDirectManager *mgr_;
+};
+
+class RemovePersistentGroupHandler : WifiDirectMethod {
+public:
+ RemovePersistentGroupHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~RemovePersistentGroupHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ *error = mgr_->removePersistentGroup();
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "RemovePersistentGroup";
+ WifiDirectManager *mgr_;
+};
+
+class RegisterHandler : WifiDirectMethod {
+public:
+ RegisterHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~RegisterHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ int service_type;
+ const char *info_str = NULL;
+ int service_id;
+
+
+ g_variant_get(parameters, "(i&s)", &service_type, &info_str);
+ std::string info = std::string(info_str);
+ *error = mgr_->registerService(service_type, info, &service_id);
+ if (*error == NULL)
+ ret = g_variant_new("(ii)", WIFI_DIRECT_ERROR_NONE, service_id);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "Register";
+ WifiDirectManager *mgr_;
+};
+
+class DeregisterHandler : WifiDirectMethod {
+public:
+ DeregisterHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~DeregisterHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ int service_id;
+
+ g_variant_get(parameters, "(i)", &service_id);
+ *error = mgr_->deregisterService(service_id);
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "Deregister";
+ WifiDirectManager *mgr_;
+};
+
+class GetPeerInfoHandler : WifiDirectMethod {
+public:
+ GetPeerInfoHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetPeerInfoHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ *error = NULL;
+ return mgr_->getPeerInfoGvariant();
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetPeerInfo";
+ WifiDirectManager *mgr_;
+};
+
+class SetPassphraseHandler : WifiDirectMethod {
+public:
+ SetPassphraseHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~SetPassphraseHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ const char *passphrase_str = NULL;
+
+ g_variant_get(parameters, "(&s)", &passphrase_str);
+
+ std::string passphrase = std::string(passphrase_str);
+ *error = mgr_->setPassphrase(passphrase);
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "SetPassphrase";
+ WifiDirectManager *mgr_;
+};
+
+class GetPassphraseHandler : WifiDirectMethod {
+public:
+ GetPassphraseHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetPassphraseHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ std::string passphrase;
+ *error = mgr_->getPassphrase(passphrase);
+ if (*error == NULL)
+ ret = g_variant_new("(is)", WIFI_DIRECT_ERROR_NONE, passphrase.c_str());
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetPassphrase";
+ WifiDirectManager *mgr_;
+};
+
+class SetAutoConnectionPeerHandler : WifiDirectMethod {
+public:
+ SetAutoConnectionPeerHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~SetAutoConnectionPeerHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ return g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "SetAutoConnectionPeer";
+ WifiDirectManager *mgr_;
+};
+
+class InitHandler : WifiDirectMethod {
+public:
+ InitHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~InitHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ *error = mgr_->initDisplay();
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "Init";
+ WifiDirectManager *mgr_;
+};
+
+class DeinitHandler : WifiDirectMethod {
+public:
+ DeinitHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~DeinitHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ *error = mgr_->deinitDisplay();
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "Deinit";
+ WifiDirectManager *mgr_;
+};
+
+class SetConfigHandler : WifiDirectMethod {
+public:
+ SetConfigHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~SetConfigHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ int type, port, hdcp;
+ g_variant_get(parameters, "(iii)", &type, &port, &hdcp);
+
+ *error = mgr_->setConfig(type, port, hdcp);
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "SetConfig";
+ WifiDirectManager *mgr_;
+};
+
+class SetAvailiabilityHandler : WifiDirectMethod {
+public:
+ SetAvailiabilityHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~SetAvailiabilityHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ int availability;
+ g_variant_get(parameters, "(i)", &availability);
+
+ *error = mgr_->setAvailiability(availability);
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "SetAvailiability";
+ WifiDirectManager *mgr_;
+};
+
+class GetConfigHandler : WifiDirectMethod {
+public:
+ GetConfigHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetConfigHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ int type = 0;
+ int port = 0;
+ int hdcp = 0;
+
+ *error = mgr_->getConfig(&type, &port, &hdcp);
+ if (*error == NULL)
+ ret = g_variant_new("(iiii)", WIFI_DIRECT_ERROR_NONE, type, port, hdcp);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetConfig";
+ WifiDirectManager *mgr_;
+};
+
+class GetAvailiabilityHandler : WifiDirectMethod {
+public:
+ GetAvailiabilityHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetAvailiabilityHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ int availability = 0;
+ *error = mgr_->getAvailiability(availability);
+ if (*error == NULL)
+ ret = g_variant_new("(ii)", WIFI_DIRECT_ERROR_NONE, availability);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetAvailiability";
+ WifiDirectManager *mgr_;
+};
+
+class GetPeerTypeHandler : WifiDirectMethod {
+public:
+ GetPeerTypeHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetPeerTypeHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ const char *mac_addr_str;
+ int type = 0;
+ g_variant_get(parameters, "(&s)", &mac_addr_str);
+ std::string mac_addr = std::string(mac_addr_str);
+
+ *error = mgr_->getPeerType(mac_addr, &type);
+ if (*error == NULL)
+ ret = g_variant_new("(ii)", WIFI_DIRECT_ERROR_NONE, type);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetPeerType";
+ WifiDirectManager *mgr_;
+};
+
+class GetPeerAvailabilityHandler : WifiDirectMethod {
+public:
+ GetPeerAvailabilityHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetPeerAvailabilityHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ const char *mac_addr_str;
+ int availability = 0;
+ g_variant_get(parameters, "(&s)", &mac_addr_str);
+ std::string mac_addr = std::string(mac_addr_str);
+
+ *error = mgr_->getPeerAvailability(mac_addr, &availability);
+ if (*error == NULL)
+ ret = g_variant_new("(ii)", WIFI_DIRECT_ERROR_NONE, availability);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetPeerAvailability";
+ WifiDirectManager *mgr_;
+};
+
+class GetPeerHdcpHandler : WifiDirectMethod {
+public:
+ GetPeerHdcpHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetPeerHdcpHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ const char *mac_addr_str;
+ int hdcp = 0;
+ g_variant_get(parameters, "(&s)", &mac_addr_str);
+ std::string mac_addr = std::string(mac_addr_str);
+
+ *error = mgr_->getPeerHdcp(mac_addr, &hdcp);
+ if (*error == NULL)
+ ret = g_variant_new("(ii)", WIFI_DIRECT_ERROR_NONE, hdcp);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetPeerHdcp";
+ WifiDirectManager *mgr_;
+};
+
+class GetPeerPortHandler : WifiDirectMethod {
+public:
+ GetPeerPortHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetPeerPortHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ const char *mac_addr_str;
+ int port = 0;
+ g_variant_get(parameters, "(&s)", &mac_addr_str);
+ std::string mac_addr = std::string(mac_addr_str);
+
+ *error = mgr_->getPeerPort(mac_addr, &port);
+ if (*error == NULL)
+ ret = g_variant_new("(ii)", WIFI_DIRECT_ERROR_NONE, port);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetPeerPort";
+ WifiDirectManager *mgr_;
+};
+
+class GetPeerThroughputHandler : WifiDirectMethod {
+public:
+ GetPeerThroughputHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetPeerThroughputHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ const char *mac_addr_str;
+ int throughput = 0;
+ g_variant_get(parameters, "(&s)", &mac_addr_str);
+ std::string mac_addr = std::string(mac_addr_str);
+
+ *error = mgr_->getPeerThroughput(mac_addr, &throughput);
+ if (*error == NULL)
+ ret = g_variant_new("(ii)", WIFI_DIRECT_ERROR_NONE, throughput);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetPeerThroughput";
+ WifiDirectManager *mgr_;
+};
+
+class SetSessionTimerHandler : WifiDirectMethod {
+public:
+ SetSessionTimerHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~SetSessionTimerHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ int second = 0;
+ g_variant_get(parameters, "(i)", &second);
+
+ *error = mgr_->setSessionTimer(second);
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "SetSessionTimer";
+ WifiDirectManager *mgr_;
+};
+
+class GetSessionTimerHandler : WifiDirectMethod {
+public:
+ GetSessionTimerHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetSessionTimerHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ int second = 0;
+ *error = mgr_->getSessionTimer(&second);
+ if (*error == NULL)
+ ret = g_variant_new("(ii)", WIFI_DIRECT_ERROR_NONE, second);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetSessionTimer";
+ WifiDirectManager *mgr_;
+};
+
+class SetAutoGroupRemovalHandler : WifiDirectMethod {
+public:
+ SetAutoGroupRemovalHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~SetAutoGroupRemovalHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ gboolean remove = FALSE;
+
+ g_variant_get(parameters, "(b)", &remove);
+
+ *error = mgr_->setAutoGruopRemove(remove);
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "SetAutoGroupRemoval";
+ WifiDirectManager *mgr_;
+};
+
+class GetPeerRssiHandler : WifiDirectMethod {
+public:
+ GetPeerRssiHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetPeerRssiHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ const char *mac_addr_str;
+ int rssi = 0;
+ g_variant_get(parameters, "(&s)", &mac_addr_str);
+ std::string mac_addr = std::string(mac_addr_str);
+
+ *error = mgr_->getPeerRssi(mac_addr, &rssi);
+ if (*error == NULL)
+ ret = g_variant_new("(ii)", WIFI_DIRECT_ERROR_NONE, rssi);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetPeerRssi";
+ WifiDirectManager *mgr_;
+};
+
+class AddVsieHandler : WifiDirectMethod {
+public:
+ AddVsieHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~AddVsieHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ const char *vsie_str = NULL;
+ int frame_id = 0;
+ g_variant_get(parameters, "(i&s)", &frame_id, &vsie_str);
+ std::string vsie = std::string(vsie_str);
+
+ *error = mgr_->addVsie(frame_id, vsie);
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "AddVsie";
+ WifiDirectManager *mgr_;
+};
+
+class GetVsieHandler : WifiDirectMethod {
+public:
+ GetVsieHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetVsieHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ int frame_id = 0;
+ g_variant_get(parameters, "(i)", &frame_id);
+
+ std::string vsie = std::string("");
+ *error = mgr_->getVsie(frame_id, vsie);
+ if (*error == NULL)
+ ret = g_variant_new("(is)", WIFI_DIRECT_ERROR_NONE, vsie.c_str());
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetVsie";
+ WifiDirectManager *mgr_;
+};
+
+class RemoveVsieHandler : WifiDirectMethod {
+public:
+ RemoveVsieHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~RemoveVsieHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ const char *vsie_str = NULL;
+ int frame_id = 0;
+ g_variant_get(parameters, "(i&s)", &frame_id, &vsie_str);
+ std::string vsie = std::string(vsie_str);
+
+ *error = mgr_->removeVsie(frame_id, vsie);
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "RemoveVsie";
+ WifiDirectManager *mgr_;
+};
+
+class GetPeerVsieHandler : WifiDirectMethod {
+public:
+ GetPeerVsieHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetPeerVsieHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ const char *mac_address_str = NULL;
+ g_variant_get(parameters, "(&s)", &mac_address_str);
+ std::string mac_addr = std::string(mac_address_str);
+ std::string vsie = std::string("");
+
+ *error = mgr_->getPeerVsie(mac_addr, vsie);
+ if (*error == NULL)
+ ret = g_variant_new("(is)", WIFI_DIRECT_ERROR_NONE, vsie.c_str());
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetPeerVsie";
+ WifiDirectManager *mgr_;
+};
+
+class SetWpsConfigMethodHandler : WifiDirectMethod {
+public:
+ SetWpsConfigMethodHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~SetWpsConfigMethodHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ int wps_mode;
+ g_variant_get(parameters, "(i)", &wps_mode);
+ *error = mgr_->setWpsConfigMethod(wps_mode);
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "SetWpsConfigMethod";
+ WifiDirectManager *mgr_;
+};
+
+class GetWpsConfigMethodHandler : WifiDirectMethod {
+public:
+ GetWpsConfigMethodHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetWpsConfigMethodHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ int wps_mode;
+ *error = mgr_->getWpsConfigMethod(wps_mode);
+ if (*error == NULL)
+ ret = g_variant_new("(ii)", WIFI_DIRECT_ERROR_NONE, wps_mode);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetWpsConfigMethod";
+ WifiDirectManager *mgr_;
+};
+
+class RemovePersistentDeviceHandler : WifiDirectMethod {
+public:
+ RemovePersistentDeviceHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~RemovePersistentDeviceHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ const char *mac_address_str = NULL;
+ g_variant_get(parameters, "(&s)", &mac_address_str);
+ std::string mac_addr = std::string(mac_address_str);
+
+ *error = mgr_->removePersistentDevice(mac_addr);
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "RemovePersistentDevice";
+ WifiDirectManager *mgr_;
+};
+
+class RemoveAllPersistentDeviceHandler : WifiDirectMethod {
+public:
+ RemoveAllPersistentDeviceHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~RemoveAllPersistentDeviceHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ *error = mgr_->removeAllPersistentDevice();
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "RemoveAllPersistentDevice";
+ WifiDirectManager *mgr_;
+};
+
+class ConnectHandler : WifiDirectMethod {
+public:
+ ConnectHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~ConnectHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ const char *mac_address_str = NULL;
+ g_variant_get(parameters, "(&s)", &mac_address_str);
+ std::string mac_addr = std::string(mac_address_str);
+
+ *error = mgr_->connect(mac_addr);
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "Connect";
+ WifiDirectManager *mgr_;
+};
+
+class AcceptConnectionHandler : WifiDirectMethod {
+public:
+ AcceptConnectionHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~AcceptConnectionHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ const char *mac_address_str = NULL;
+ g_variant_get(parameters, "(&s)", &mac_address_str);
+ std::string mac_addr = std::string(mac_address_str);
+
+ *error = mgr_->acceptConnection(mac_addr);
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "AcceptConnection";
+ WifiDirectManager *mgr_;
+};
+
+class CancelConnectionHandler : WifiDirectMethod {
+public:
+ CancelConnectionHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~CancelConnectionHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ const char *mac_address_str = NULL;
+ g_variant_get(parameters, "(&s)", &mac_address_str);
+ std::string mac_addr = std::string(mac_address_str);
+
+ *error = mgr_->cancelConnection(mac_addr);
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "CancelConnection";
+ WifiDirectManager *mgr_;
+};
+
+class RejectConnectionHandler : WifiDirectMethod {
+public:
+ RejectConnectionHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~RejectConnectionHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ const char *mac_address_str = NULL;
+ g_variant_get(parameters, "(&s)", &mac_address_str);
+ std::string mac_addr = std::string(mac_address_str);
+
+ *error = mgr_->rejectConnection(mac_addr);
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "RejectConnection";
+ WifiDirectManager *mgr_;
+};
+
+class DisconnectAllHandler : WifiDirectMethod {
+public:
+ DisconnectAllHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~DisconnectAllHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ *error = mgr_->disconnectAll();
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "DisconnectAll";
+ WifiDirectManager *mgr_;
+};
+
+class DisconnectHandler : WifiDirectMethod {
+public:
+ DisconnectHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~DisconnectHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+ const char *mac_address_str = NULL;
+ g_variant_get(parameters, "(&s)", &mac_address_str);
+ std::string mac_addr = std::string(mac_address_str);
+
+ *error = mgr_->disconnect(mac_addr);
+ if (*error == NULL)
+ ret = g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "Disconnect";
+ WifiDirectManager *mgr_;
+};
+
+class GetConnectedPeersHandler : WifiDirectMethod {
+public:
+ GetConnectedPeersHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetConnectedPeersHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ *error = mgr_->getConnectedPeers(&ret);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetConnectedPeers";
+ WifiDirectManager *mgr_;
+};
+
+class GetConnectingPeerHandler : WifiDirectMethod {
+public:
+ GetConnectingPeerHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetConnectingPeerHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ GVariant *ret = NULL;
+
+ *error = mgr_->GetConnectingPeer(&ret);
+
+ return ret;
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetConnectingPeer";
+ WifiDirectManager *mgr_;
+};
+
+class SetWpsPinHandler : WifiDirectMethod {
+public:
+ SetWpsPinHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~SetWpsPinHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ const char *pin_str = NULL;
+ g_variant_get(parameters, "(&s)", &pin_str);
+
+ return g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "SetWpsPin";
+ WifiDirectManager *mgr_;
+};
+
+
+class GetWpsPinHandler : WifiDirectMethod {
+public:
+ GetWpsPinHandler(WifiDirectManager *mgr) : mgr_(mgr){};
+ ~GetWpsPinHandler()
+ {
+ };
+ GVariant *handleMethod(GVariant *parameters, GError **error) override
+ {
+ char pin_str[] = {"12345678"};
+
+ return g_variant_new("(is)", WIFI_DIRECT_ERROR_NONE, pin_str);
+ }
+ std::string getMethodName()
+ {
+ return method_name_;
+ }
+private:
+ const std::string method_name_ =
+ "GetWpsPin";
+ WifiDirectManager *mgr_;
+};
+WifiDirectManager::WifiDirectManager()
+{
+ this->group_ = nullptr;
+ this->state_ = WifiDirectState::kWifiDirectStateDeactivated;
+ this->config_methods_ = WFD_WPS_MODE_PBC | WFD_WPS_MODE_DISPLAY | WFD_WPS_MODE_KEYPAD;
+ this->wps_mode_ = WFD_WPS_MODE_PBC;
+ this->req_wps_mode_ = WFD_WPS_MODE_PBC;
+ this->scan_mode_ = WFD_SCAN_MODE_NONE;
+ this->persistent_gruop_enabled_ = FALSE;
+ this->session_timer_ = 120;
+ this->auto_group_remove_ = false;
+ this->mac_address_ = std::string("00:11:22:33:44:55");
+
+ AddClientHandler *add_client_handler = new AddClientHandler(this);
+ this->method_map_[add_client_handler->getMethodName()] = (WifiDirectMethod *)add_client_handler;
+
+ ActivateHandler *activate_handler = new ActivateHandler(this);
+ this->method_map_[activate_handler->getMethodName()] = (WifiDirectMethod *)activate_handler;
+
+ DeactivateHandler *deactivate_handler = new DeactivateHandler(this);
+ this->method_map_[deactivate_handler->getMethodName()] = (WifiDirectMethod *)deactivate_handler;
+
+ StartDiscoveryHandler *start_discovery_handler = new StartDiscoveryHandler(this);
+ this->method_map_[start_discovery_handler->getMethodName()] = (WifiDirectMethod *)start_discovery_handler;
+
+ StopDiscoveryHandler *stop_discovery_handler = new StopDiscoveryHandler(this);
+ this->method_map_[stop_discovery_handler->getMethodName()] = (WifiDirectMethod *)stop_discovery_handler;
+
+ GetDiscoveredPeersHandler *get_discovered_peers_handler = new GetDiscoveredPeersHandler(this);
+ this->method_map_[get_discovered_peers_handler->getMethodName()] = (WifiDirectMethod *)get_discovered_peers_handler;
+
+ CreateGroupHandler *create_group_handler = new CreateGroupHandler(this);
+ this->method_map_[create_group_handler->getMethodName()] = (WifiDirectMethod *)create_group_handler;
+
+ DestroyGroupHandler *destroy_group_handler = new DestroyGroupHandler(this);
+ this->method_map_[destroy_group_handler->getMethodName()] = (WifiDirectMethod *)destroy_group_handler;
+
+ IsGroupOwnerHandler *is_group_owner_handler = new IsGroupOwnerHandler(this);
+ this->method_map_[is_group_owner_handler->getMethodName()] = (WifiDirectMethod *)is_group_owner_handler;
+
+ GetMacAddressHandler *get_mac_address_handler = new GetMacAddressHandler(this);
+ this->method_map_[get_mac_address_handler->getMethodName()] = (WifiDirectMethod *)get_mac_address_handler;
+
+ IsAutoGroupHandler *is_auto_group_handler = new IsAutoGroupHandler(this);
+ this->method_map_[is_auto_group_handler->getMethodName()] = (WifiDirectMethod *)is_auto_group_handler;
+
+ SetGoIntentHandler *set_go_intent_handler = new SetGoIntentHandler(this);
+ this->method_map_[set_go_intent_handler->getMethodName()] = (WifiDirectMethod *)set_go_intent_handler;
+
+ GetGoIntentHandler *get_go_intent_handler = new GetGoIntentHandler(this);
+ this->method_map_[get_go_intent_handler->getMethodName()] = (WifiDirectMethod *)get_go_intent_handler;
+
+ SetGoIntentPerTypeHandler *set_go_intent_per_type_handler = new SetGoIntentPerTypeHandler(this);
+ this->method_map_[set_go_intent_per_type_handler->getMethodName()] = (WifiDirectMethod *)set_go_intent_per_type_handler;
+
+ GetGoIntentPerTypeHandler *get_go_intent_per_type_handler = new GetGoIntentPerTypeHandler(this);
+ this->method_map_[get_go_intent_per_type_handler->getMethodName()] = (WifiDirectMethod *)get_go_intent_per_type_handler;
+
+ SetMaxClientHandler *set_max_client_handler = new SetMaxClientHandler(this);
+ this->method_map_[set_max_client_handler->getMethodName()] = (WifiDirectMethod *)set_max_client_handler;
+
+ GetMaxClientHandler *get_max_client_handler = new GetMaxClientHandler(this);
+ this->method_map_[get_max_client_handler->getMethodName()] = (WifiDirectMethod *)get_max_client_handler;
+
+ GetOperatingChannelHandler *get_operating_channel_handler = new GetOperatingChannelHandler(this);
+ this->method_map_[get_operating_channel_handler->getMethodName()] = (WifiDirectMethod *)get_operating_channel_handler;
+
+ ActivatePushButtonHandler *activate_pushbutton_handler = new ActivatePushButtonHandler(this);
+ this->method_map_[activate_pushbutton_handler->getMethodName()] = (WifiDirectMethod *)activate_pushbutton_handler;
+
+ GetSupportedWpsModeHandler *get_supported_wps_mode_handler = new GetSupportedWpsModeHandler(this);
+ this->method_map_[get_supported_wps_mode_handler->getMethodName()] = (WifiDirectMethod *)get_supported_wps_mode_handler;
+
+ GetLocalWpsModeHandler *get_local_wps_mode_handler = new GetLocalWpsModeHandler(this);
+ this->method_map_[get_local_wps_mode_handler->getMethodName()] = (WifiDirectMethod *)get_local_wps_mode_handler;
+
+ SetReqWpsModeHandler *set_teq_wps_mode_handler = new SetReqWpsModeHandler(this);
+ this->method_map_[set_teq_wps_mode_handler->getMethodName()] = (WifiDirectMethod *)set_teq_wps_mode_handler;
+
+ GetReqWpsModeHandler *get_req_wps_mode_handler = new GetReqWpsModeHandler(this);
+ this->method_map_[get_req_wps_mode_handler->getMethodName()] = (WifiDirectMethod *)get_req_wps_mode_handler;
+
+ GetDeviceNameHandler *get_device_name_handler = new GetDeviceNameHandler(this);
+ this->method_map_[get_device_name_handler->getMethodName()] = (WifiDirectMethod *)get_device_name_handler;
+
+ SetDeviceNameHandler *set_device_name_handler = new SetDeviceNameHandler(this);
+ this->method_map_[set_device_name_handler->getMethodName()] = (WifiDirectMethod *)set_device_name_handler;
+
+ GetInterfaceNameHandler *get_interface_name_handler = new GetInterfaceNameHandler(this);
+ this->method_map_[get_interface_name_handler->getMethodName()] = (WifiDirectMethod *)get_interface_name_handler;
+
+ GetIPAddressHandler *get_ip_address_handler = new GetIPAddressHandler(this);
+ this->method_map_[get_ip_address_handler->getMethodName()] = (WifiDirectMethod *)get_ip_address_handler;
+
+ GetSubnetMaskHandler *get_subnet_mask_handler = new GetSubnetMaskHandler(this);
+ this->method_map_[get_subnet_mask_handler->getMethodName()] = (WifiDirectMethod *)get_subnet_mask_handler;
+
+ GetGatewayHandler *get_gateway_handler = new GetGatewayHandler(this);
+ this->method_map_[get_gateway_handler->getMethodName()] = (WifiDirectMethod *)get_gateway_handler;
+
+ IsDiscoverableHandler *is_discoverable_handler = new IsDiscoverableHandler(this);
+ this->method_map_[is_discoverable_handler->getMethodName()] = (WifiDirectMethod *)is_discoverable_handler;
+
+ IsListeningOnlyHandler *is_listening_only_handler = new IsListeningOnlyHandler(this);
+ this->method_map_[is_listening_only_handler->getMethodName()] = (WifiDirectMethod *)is_listening_only_handler;
+
+ GetPrimaryDevTypeHandler *get_primary_dev_type_handler = new GetPrimaryDevTypeHandler(this);
+ this->method_map_[get_primary_dev_type_handler->getMethodName()] = (WifiDirectMethod *)get_primary_dev_type_handler;
+
+ GetSecondaryDevTypeHandler *get_secondary_dev_type_handler = new GetSecondaryDevTypeHandler(this);
+ this->method_map_[get_secondary_dev_type_handler->getMethodName()] = (WifiDirectMethod *)get_secondary_dev_type_handler;
+
+ SetAutoConnectionModeHandler *set_auto_connection_mode_handler = new SetAutoConnectionModeHandler(this);
+ this->method_map_[set_auto_connection_mode_handler->getMethodName()] = (WifiDirectMethod *)set_auto_connection_mode_handler;
+
+ IsAutoConnectionModeHandler *is_auto_connection_mode_handler = new IsAutoConnectionModeHandler(this);
+ this->method_map_[is_auto_connection_mode_handler->getMethodName()] = (WifiDirectMethod *)is_auto_connection_mode_handler;
+
+ SetPersistentGroupEnabledHandler *set_persistent_group_enable_handler = new SetPersistentGroupEnabledHandler(this);
+ this->method_map_[set_persistent_group_enable_handler->getMethodName()] = (WifiDirectMethod *)set_persistent_group_enable_handler;
+
+ IsPersistentGroupEnabledHandler *is_persistent_group_enable_handler = new IsPersistentGroupEnabledHandler(this);
+ this->method_map_[is_persistent_group_enable_handler->getMethodName()] = (WifiDirectMethod *)is_persistent_group_enable_handler;
+
+ GetPersistentGroupsHandler *get_persistent_group_handler = new GetPersistentGroupsHandler(this);
+ this->method_map_[get_persistent_group_handler->getMethodName()] = (WifiDirectMethod *)get_persistent_group_handler;
+
+ RemovePersistentGroupHandler *remove_persistent_group_handler = new RemovePersistentGroupHandler(this);
+ this->method_map_[remove_persistent_group_handler->getMethodName()] = (WifiDirectMethod *)remove_persistent_group_handler;
+
+ RegisterHandler *register_handler = new RegisterHandler(this);
+ this->method_map_[register_handler->getMethodName()] = (WifiDirectMethod *)register_handler;
+
+ DeregisterHandler *deregister_handler = new DeregisterHandler(this);
+ this->method_map_[deregister_handler->getMethodName()] = (WifiDirectMethod *)deregister_handler;
+
+ GetPeerInfoHandler *get_peer_info_handler = new GetPeerInfoHandler(this);
+ this->method_map_[get_peer_info_handler->getMethodName()] = (WifiDirectMethod *)get_peer_info_handler;
+
+ SetPassphraseHandler *set_passphrase_handler = new SetPassphraseHandler(this);
+ this->method_map_[set_passphrase_handler->getMethodName()] = (WifiDirectMethod *)set_passphrase_handler;
+
+ GetPassphraseHandler *get_passphrase_handler = new GetPassphraseHandler(this);
+ this->method_map_[get_passphrase_handler->getMethodName()] = (WifiDirectMethod *)get_passphrase_handler;
+
+ SetAutoConnectionPeerHandler *set_auto_connection_peer_handler = new SetAutoConnectionPeerHandler(this);
+ this->method_map_[set_auto_connection_peer_handler->getMethodName()] = (WifiDirectMethod *)set_auto_connection_peer_handler;
+
+ InitHandler *init_handler = new InitHandler(this);
+ this->method_map_[init_handler->getMethodName()] = (WifiDirectMethod *)init_handler;
+
+ DeinitHandler *deinit_handler = new DeinitHandler(this);
+ this->method_map_[deinit_handler->getMethodName()] = (WifiDirectMethod *)deinit_handler;
+
+ SetConfigHandler *set_config_handler = new SetConfigHandler(this);
+ this->method_map_[set_config_handler->getMethodName()] = (WifiDirectMethod *)set_config_handler;
+
+ SetAvailiabilityHandler *set_availability_handler = new SetAvailiabilityHandler(this);
+ this->method_map_[set_availability_handler->getMethodName()] = (WifiDirectMethod *)set_availability_handler;
+
+ GetConfigHandler *get_config_handler = new GetConfigHandler(this);
+ this->method_map_[get_config_handler->getMethodName()] = (WifiDirectMethod *)get_config_handler;
+
+ GetAvailiabilityHandler *get_availability_handler = new GetAvailiabilityHandler(this);
+ this->method_map_[get_availability_handler->getMethodName()] = (WifiDirectMethod *)get_availability_handler;
+
+ GetPeerTypeHandler *get_peer_type_handler = new GetPeerTypeHandler(this);
+ this->method_map_[get_peer_type_handler->getMethodName()] = (WifiDirectMethod *)get_peer_type_handler;
+
+ GetPeerAvailabilityHandler *get_peer_availability_handler = new GetPeerAvailabilityHandler(this);
+ this->method_map_[get_peer_availability_handler->getMethodName()] = (WifiDirectMethod *)get_peer_availability_handler;
+
+ GetPeerHdcpHandler *get_peer_hdcp_handler = new GetPeerHdcpHandler(this);
+ this->method_map_[get_peer_hdcp_handler->getMethodName()] = (WifiDirectMethod *)get_peer_hdcp_handler;
+
+ GetPeerPortHandler *get_peer_port_handler = new GetPeerPortHandler(this);
+ this->method_map_[get_peer_port_handler->getMethodName()] = (WifiDirectMethod *)get_peer_port_handler;
+
+ GetPeerThroughputHandler *get_peer_throughput_handler = new GetPeerThroughputHandler(this);
+ this->method_map_[get_peer_throughput_handler->getMethodName()] = (WifiDirectMethod *)get_peer_throughput_handler;
+
+ GetPeerRssiHandler *get_peer_rssi_handler = new GetPeerRssiHandler(this);
+ this->method_map_[get_peer_rssi_handler->getMethodName()] = (WifiDirectMethod *)get_peer_rssi_handler;
+
+ SetSessionTimerHandler *set_session_timer_handler = new SetSessionTimerHandler(this);
+ this->method_map_[set_session_timer_handler->getMethodName()] = (WifiDirectMethod *)set_session_timer_handler;
+
+ GetSessionTimerHandler *get_session_timer_handler = new GetSessionTimerHandler(this);
+ this->method_map_[get_session_timer_handler->getMethodName()] = (WifiDirectMethod *)get_session_timer_handler;
+
+ SetAutoGroupRemovalHandler *set_auto_group_removal_handler = new SetAutoGroupRemovalHandler(this);
+ this->method_map_[set_auto_group_removal_handler->getMethodName()] = (WifiDirectMethod *)set_auto_group_removal_handler;
+
+ AddVsieHandler *add_vsie_handler = new AddVsieHandler(this);
+ this->method_map_[add_vsie_handler->getMethodName()] = (WifiDirectMethod *)add_vsie_handler;
+
+ GetVsieHandler *get_vsie_handler = new GetVsieHandler(this);
+ this->method_map_[get_vsie_handler->getMethodName()] = (WifiDirectMethod *)get_vsie_handler;
+
+ RemoveVsieHandler *remove_vsie_handler = new RemoveVsieHandler(this);
+ this->method_map_[remove_vsie_handler->getMethodName()] = (WifiDirectMethod *)remove_vsie_handler;
+
+ GetPeerVsieHandler *get_peer_vsie_handler = new GetPeerVsieHandler(this);
+ this->method_map_[get_peer_vsie_handler->getMethodName()] = (WifiDirectMethod *)get_peer_vsie_handler;
+
+ SetWpsConfigMethodHandler *set_wps_config_method_handler = new SetWpsConfigMethodHandler(this);
+ this->method_map_[set_wps_config_method_handler->getMethodName()] = (WifiDirectMethod *)set_wps_config_method_handler;
+
+ GetWpsConfigMethodHandler *get_wps_config_method_handler = new GetWpsConfigMethodHandler(this);
+ this->method_map_[get_wps_config_method_handler->getMethodName()] = (WifiDirectMethod *)get_wps_config_method_handler;
+
+ RemovePersistentDeviceHandler *remove_persistent_device_handler = new RemovePersistentDeviceHandler(this);
+ this->method_map_[remove_persistent_device_handler->getMethodName()] = (WifiDirectMethod *)remove_persistent_device_handler;
+
+ RemoveAllPersistentDeviceHandler *remove_all_persistent_device_handler = new RemoveAllPersistentDeviceHandler(this);
+ this->method_map_[remove_all_persistent_device_handler->getMethodName()] = (WifiDirectMethod *)remove_all_persistent_device_handler;
+
+ ConnectHandler *connect_handler = new ConnectHandler(this);
+ this->method_map_[connect_handler->getMethodName()] = (WifiDirectMethod *)connect_handler;
+
+ AcceptConnectionHandler *accept_connection_handler = new AcceptConnectionHandler(this);
+ this->method_map_[accept_connection_handler->getMethodName()] = (WifiDirectMethod *)accept_connection_handler;
+
+ CancelConnectionHandler *cancel_connection_handler = new CancelConnectionHandler(this);
+ this->method_map_[cancel_connection_handler->getMethodName()] = (WifiDirectMethod *)cancel_connection_handler;
+
+ RejectConnectionHandler *reject_connection_handler = new RejectConnectionHandler(this);
+ this->method_map_[reject_connection_handler->getMethodName()] = (WifiDirectMethod *)reject_connection_handler;
+
+ DisconnectAllHandler *disconnect_all_handler = new DisconnectAllHandler(this);
+ this->method_map_[disconnect_all_handler->getMethodName()] = (WifiDirectMethod *)disconnect_all_handler;
+
+ DisconnectHandler *disconnect_handler = new DisconnectHandler(this);
+ this->method_map_[disconnect_handler->getMethodName()] = (WifiDirectMethod *)disconnect_handler;
+
+ GetConnectedPeersHandler *get_connected_peers_handler = new GetConnectedPeersHandler(this);
+ this->method_map_[get_connected_peers_handler->getMethodName()] = (WifiDirectMethod *)get_connected_peers_handler;
+
+ GetConnectingPeerHandler *get_connecting_peer_handler = new GetConnectingPeerHandler(this);
+ this->method_map_[get_connecting_peer_handler->getMethodName()] = (WifiDirectMethod *)get_connecting_peer_handler;
+
+ SetWpsPinHandler *set_wps_pin_handler = new SetWpsPinHandler(this);
+ this->method_map_[set_wps_pin_handler->getMethodName()] = (WifiDirectMethod *)set_wps_pin_handler;
+
+ GetWpsPinHandler *get_wps_pin_handler = new GetWpsPinHandler(this);
+ this->method_map_[get_wps_pin_handler->getMethodName()] = (WifiDirectMethod *)get_wps_pin_handler;
+
+}
+
+WifiDirectManager::~WifiDirectManager()
+{
+ for(auto& elem : this->method_map_){
+ delete elem.second;
+ }
+ this->method_map_.clear();
+
+ for(auto& elem : this->service_map_){
+ delete elem.second;
+ }
+ this->method_map_.clear();
+
+ if (this->group_)
+ delete this->group_;
+}
+
+GVariant *WifiDirectManager::callMethod(const gchar *method_name,
+ GVariant *parameters,
+ GError **error)
+{
+ WifiDirectMethod *method_handler = this->method_map_[std::string(method_name)];
+ if (!method_handler)
+ return NULL;
+
+ return method_handler->handleMethod(parameters, error);
+}
+
+void WifiDirectManager::setState(const WifiDirectState state)
+{
+ this->state_ = state;
+
+ return;
+}
+
+GError *WifiDirectManager::startDiscovery(int mode, int timeout,
+ const char* type, int channel, int frequency)
+{
+ if (this->isNotDiscoverable())
+ return this->error_handler_.NotPermitted();
+
+
+ this->scan_mode_ = mode;
+ return NULL;
+}
+
+GError *WifiDirectManager::stopDiscovery()
+{
+ printf("state %d\n", static_cast<int>(this->state_));
+ if (this->state_ != WifiDirectState::kWifiDirectStateActivated &&
+ this->state_ != WifiDirectState::kWifiDirectStateDiscovering)
+ return this->error_handler_.NotPermitted();
+
+ this->scan_mode_ = WFD_SCAN_MODE_NONE;
+ return NULL;
+}
+
+GError *WifiDirectManager::createGroup(const char *ssid)
+{
+ if (this->group_ != nullptr || this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ this->group_ = new WifiDirectGroup();
+ this->group_->setFlag(WFD_GROUP_FLAG_AUTONOMOUS);
+ this->group_->setRole(WFD_DEV_ROLE_GO);
+
+ return NULL;
+}
+
+GError *WifiDirectManager::destroyGroup()
+{
+ if (this->group_ == nullptr)
+ return this->error_handler_.NotPermitted();
+
+ delete this->group_;
+ this->group_ = nullptr;
+
+ return NULL;
+}
+
+GError *WifiDirectManager::isGroupOwner(gboolean *is_group_owner)
+{
+ if (this->group_ == nullptr)
+ *is_group_owner = FALSE;
+ else
+ *is_group_owner = this->group_->getRole() == WFD_DEV_ROLE_GO;
+
+ return NULL;
+}
+
+GError *WifiDirectManager::isAutoGroup(gboolean *is_auto_group)
+{
+ if (this->group_ == nullptr)
+ *is_auto_group = FALSE;
+ else
+ *is_auto_group = (this->group_->getFlag() & WFD_GROUP_FLAG_AUTONOMOUS) != 0;
+
+ return NULL;
+}
+
+GError *WifiDirectManager::getMacAddress(std::string &mac_addr)
+{
+ mac_addr = this->mac_address_;
+
+ return NULL;
+}
+
+GError *WifiDirectManager::setGoIntent(int go_intent)
+{
+ this->setting_.setGoIntent(go_intent);
+ return NULL;
+}
+
+GError *WifiDirectManager::getGoIntent(int *go_intent)
+{
+ *go_intent = this->setting_.getGoIntent();
+ return NULL;
+}
+
+GError *WifiDirectManager::setMaxClient(int max_client)
+{
+ if (max_client < 1)
+ return this->error_handler_.OperationFailed();
+ this->setting_.setMaxClient(max_client);
+ return NULL;
+}
+
+GError *WifiDirectManager::getMaxClient(int *max_client)
+{
+ *max_client = this->setting_.getMaxClient();
+ return NULL;
+}
+
+GError *WifiDirectManager::getOperatingChannel(int *channel)
+{
+ if (this->group_ == nullptr)
+ return this->error_handler_.NotPermitted();
+
+ *channel = this->group_->getOperatingChannel();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::ActivatePushbutton()
+{
+ if (this->group_ == nullptr || this->group_->getRole() != WFD_DEV_ROLE_GO)
+ return this->error_handler_.NotPermitted();
+
+ /* Dummy */
+
+ return NULL;
+}
+
+GError *WifiDirectManager::GetSupportedWpsMode(int *supported_wps_mode)
+{
+ *supported_wps_mode = this->config_methods_;
+
+ return NULL;
+}
+
+GError *WifiDirectManager::GetLocalWpsMode(int *wps_mode)
+{
+ *wps_mode = this->wps_mode_;
+
+ return NULL;
+}
+
+GError *WifiDirectManager::setRequestWpsMode(int wps_mode)
+{
+ this->req_wps_mode_ = wps_mode;
+
+ return NULL;
+}
+
+GError *WifiDirectManager::GetRequestWpsMode(int *wps_mode)
+{
+ *wps_mode = this->req_wps_mode_;
+
+ return NULL;
+}
+
+GError *WifiDirectManager::setDeviceName(std::string device_name)
+{
+ this->setting_.setDeviceName(device_name);
+
+ return NULL;
+}
+
+GError *WifiDirectManager::getDeviceName(std::string &device_name)
+{
+ device_name = this->setting_.getDeviceName();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::getInterfaceName(std::string &iface_name)
+{
+ if (this->group_ == nullptr)
+ return this->error_handler_.NotPermitted();
+
+ iface_name = this->group_->getIfaceName();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::getIpAddr(std::string &ip_addr)
+{
+ if (this->group_ == nullptr)
+ return this->error_handler_.NotPermitted();
+
+ ip_addr = this->group_->getIpAddr();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::getSubnetMask(std::string &subnet_mask)
+{
+ if (this->group_ == nullptr)
+ return this->error_handler_.NotPermitted();
+
+ subnet_mask = this->group_->getSubnetMask();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::getGatewayAddr(std::string &gateway_addr)
+{
+ if (this->group_ == nullptr)
+ return this->error_handler_.NotPermitted();
+
+ gateway_addr = this->group_->getGatewayAddr();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::enablePersistentGroup(gboolean enable)
+{
+ this->persistent_gruop_enabled_ = enable;
+
+ return NULL;
+}
+
+GError *WifiDirectManager::isPersistentGruopEnabled(gboolean *enable)
+{
+ *enable = this->persistent_gruop_enabled_;
+
+ return NULL;
+}
+
+GVariant* __packGVariantAy(const unsigned char *src, int size)
+{
+ GVariantBuilder *builder = NULL;
+ GVariant *iter = NULL;
+ int i = 0;
+
+ if (!src) {
+ return NULL;
+ }
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
+
+ for (i = 0; i < size; i++)
+ g_variant_builder_add(builder, "y", src[i]);
+
+ iter = g_variant_new("ay", builder);
+
+ g_variant_builder_unref(builder);
+ return iter;
+}
+
+GError *WifiDirectManager::getPersistentGroup(GVariant **group)
+{
+ GVariant *ret;
+ GVariantBuilder *builder_groups;
+ unsigned char default_addr[] = {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
+
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ builder_groups = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}"));
+ GVariantBuilder builder_group;
+ g_variant_builder_init(&builder_group, G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(&builder_group, "{sv}",
+ "NetworkID",
+ g_variant_new_uint32(1));
+ g_variant_builder_add(&builder_group, "{sv}",
+ "SSID",
+ g_variant_new_string("TIZEN"));
+ g_variant_builder_add(&builder_group, "{sv}",
+ "GOMacAddress",
+ __packGVariantAy(default_addr, MACADDR_LEN));
+ g_variant_builder_add_value(builder_groups, g_variant_builder_end(&builder_group));
+ ret = g_variant_new("(iaa{sv})", WIFI_DIRECT_ERROR_NONE, builder_groups);
+ g_variant_builder_unref(builder_groups);
+ *group = ret;
+
+ return NULL;
+}
+
+GError *WifiDirectManager::removePersistentGroup(void)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::registerService(int service_type, std::string &info, int *service_id)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ WifiDirectService *wfd_service = new WifiDirectService(info);
+ this->service_map_[wfd_service->getId()] = (WifiDirectService *)wfd_service;
+
+ *service_id = wfd_service->getId();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::deregisterService(int service_id)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ WifiDirectService *wfd_service = this->service_map_[service_id];
+ if (wfd_service != nullptr) {
+ this->service_map_.erase(service_id);
+ delete wfd_service;
+ }
+
+ return NULL;
+}
+
+GError *WifiDirectManager::setPassphrase(std::string &passphrase)
+{
+ if (this->group_ != nullptr)
+ return this->error_handler_.NotPermitted();
+
+ this->passphrase_ = passphrase;
+
+ return NULL;
+}
+
+GError *WifiDirectManager::getPassphrase(std::string &passphrase)
+{
+ if (this->group_ == nullptr)
+ return this->error_handler_.NotPermitted();
+
+ passphrase = this->group_->getPassphrase();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::initDisplay(void)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::deinitDisplay(void)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::setConfig(int type, int port, int hdcp)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ this->display_info_.setType(type);
+ this->display_info_.setPort(port);
+ this->display_info_.setHdcp(hdcp);
+
+ return NULL;
+}
+
+GError *WifiDirectManager::getConfig(int *type, int *port, int *hdcp)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ *type = this->display_info_.getType();
+ *port = this->display_info_.getPort();
+ *hdcp = this->display_info_.getHdcp();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::setAvailiability(int availability)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ this->display_info_.setAvailability(availability);
+
+ return NULL;
+}
+
+GError *WifiDirectManager::getAvailiability(int &availability)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ availability = this->display_info_.getAvailability();
+ return NULL;
+}
+
+GError *WifiDirectManager::getPeerType(std::string &mac_addr, int *type)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ *type = this->peer_.getDisplay_info().getType();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::getPeerAvailability(std::string &mac_addr, int *availability)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ *availability = this->peer_.getDisplay_info().getAvailability();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::getPeerHdcp(std::string &mac_addr, int *hdcp)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ *hdcp = this->peer_.getDisplay_info().getHdcp();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::getPeerPort(std::string &mac_addr, int *port)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ *port = this->peer_.getDisplay_info().getPort();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::getPeerThroughput(std::string &mac_addr, int *throuput)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ *throuput = this->peer_.getDisplay_info().getThroughput();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::getPeerRssi(std::string &mac_addr, int *rssi)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ *rssi = this->peer_.getRssi();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::addVsie(int frame_id, std::string &vsie)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::getVsie(int frame_id, std::string &vsie)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ vsie = std::string("TestVsie");
+ return NULL;
+}
+
+GError *WifiDirectManager::removeVsie(int frame_id, std::string &vsie)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::getPeerVsie(std::string &mac_addr, std::string &vsie)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ vsie = this->peer_.getVsie();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::setWpsConfigMethod(int wps_method)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::getWpsConfigMethod(int &wps_method)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ wps_method = 0;
+
+ return NULL;
+}
+
+GError *WifiDirectManager::removePersistentDevice(std::string &mac_addr)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::removeAllPersistentDevice(void)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ return NULL;
+}
+
+static bool __is_discovery_available(WifiDirectManager *mgr)
+{
+ return mgr->getState() != WifiDirectState::kWifiDirectStateActivated &&
+ mgr->getState() != WifiDirectState::kWifiDirectStateDiscovering &&
+ mgr->getState() != WifiDirectState::kWifiDirectStateGroupowner;
+}
+
+GError *WifiDirectManager::connect(std::string &mac_addr)
+{
+ if (__is_discovery_available(this))
+ return this->error_handler_.NotPermitted();
+
+ /* Skipping connection session related operations
+ * such as comparing peer MAC address,
+ * setting WPS related operations,
+ * Checking Group creating process,
+ * and ETC.
+ */
+
+ return NULL;
+}
+
+GError *WifiDirectManager::acceptConnection(std::string &mac_addr)
+{
+ if (this->state_ != WifiDirectState::kWifiDirectStateConnecting)
+ return this->error_handler_.NotPermitted();
+
+ /* Skipping connection session related operations
+ * such as comparing peer MAC address,
+ * setting WPS related operations,
+ * Checking Group creating process,
+ * and ETC.
+ */
+
+ return NULL;
+}
+
+GError *WifiDirectManager::cancelConnection(std::string &mac_addr)
+{
+ if (this->state_ != WifiDirectState::kWifiDirectStateConnecting)
+ return this->error_handler_.NotPermitted();
+
+ /* Skipping connection session related operations
+ * such as comparing peer MAC address,
+ * setting WPS related operations,
+ * Checking Group creating process,
+ * and ETC.
+ */
+
+ return NULL;
+}
+
+GError *WifiDirectManager::rejectConnection(std::string &mac_addr)
+{
+ if (this->state_ != WifiDirectState::kWifiDirectStateConnecting)
+ return this->error_handler_.NotPermitted();
+
+ /* Skipping connection session related operations
+ * such as comparing peer MAC address,
+ * setting WPS related operations,
+ * Checking Group creating process,
+ * and ETC.
+ */
+
+ return NULL;
+}
+
+GError *WifiDirectManager::disconnectAll()
+{
+ if (this->group_ == nullptr || this->state_ < WifiDirectState::kWifiDirectStateConnected)
+ return this->error_handler_.NotPermitted();
+
+ /* Skipping connection session related operations
+ * such as comparing peer MAC address,
+ * setting WPS related operations,
+ * Checking Group creating process,
+ * and ETC.
+ */
+
+ return NULL;
+}
+
+GError *WifiDirectManager::disconnect(std::string &mac_addr)
+{
+ if (this->group_ == nullptr || this->state_ < WifiDirectState::kWifiDirectStateConnected)
+ return this->error_handler_.NotPermitted();
+
+ /* Skipping connection session related operations
+ * such as comparing peer MAC address,
+ * setting WPS related operations,
+ * Checking Group creating process,
+ * and ETC.
+ */
+
+ return NULL;
+}
+
+GError *WifiDirectManager::getConnectedPeers(GVariant **ret)
+{
+ if (this->group_ == nullptr || this->state_ < WifiDirectState::kWifiDirectStateConnected)
+ return this->error_handler_.NotPermitted();
+
+ /* Skipping connection session related operations
+ * such as comparing peer MAC address,
+ * setting WPS related operations,
+ * Checking Group creating process,
+ * and ETC.
+ */
+
+ *ret = this->getDiscoveredPeersGvariant();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::GetConnectingPeer(GVariant **ret)
+{
+ if (this->state_ != WifiDirectState::kWifiDirectStateConnecting)
+ return this->error_handler_.NotPermitted();
+
+ /* Skipping connection session related operations
+ * such as comparing peer MAC address,
+ * setting WPS related operations,
+ * Checking Group creating process,
+ * and ETC.
+ */
+
+ *ret = this->getPeerInfoGvariant();
+
+ return NULL;
+}
+
+GError *WifiDirectManager::setSessionTimer(int second)
+{
+ this->session_timer_ = second;
+
+ return NULL;
+}
+GError *WifiDirectManager::getSessionTimer(int *second)
+{
+ *second = this->session_timer_;
+ return NULL;
+}
+
+GError *WifiDirectManager::setAutoGruopRemove(bool remove)
+{
+ if (this->state_ < WifiDirectState::kWifiDirectStateActivated)
+ return this->error_handler_.NotPermitted();
+
+ this->auto_group_remove_ = remove;
+
+ return NULL;
+}
+
+GVariant *WifiDirectManager::getPeerInfoGvariant(void)
+{
+ GVariant *ret;
+ GVariantBuilder *builder_peer;
+
+ builder_peer = this->peer_.getPeerGvariantBuilder();
+ ret = g_variant_new("(ia{sv})", WIFI_DIRECT_ERROR_NONE, builder_peer);
+ g_variant_builder_unref(builder_peer);
+
+ return ret;
+}
+
+GVariant *WifiDirectManager::getDiscoveredPeersGvariant(void)
+{
+ GVariantBuilder *builder_peers = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}"));
+ GVariant *ret;
+
+ g_variant_builder_add_value(builder_peers, this->peer_.getPeerGvariant());
+ ret = g_variant_new("(iaa{sv})", WIFI_DIRECT_ERROR_NONE, builder_peers);
+ g_variant_builder_unref(builder_peers);
+
+ return ret;
+}
+
+GVariant *WifiDirectManager::activated(void)
+{
+ this->setState(WifiDirectState::kWifiDirectStateActivated);
+
+ return g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+}
+
+GVariant *WifiDirectManager::deactivated(void)
+{
+ this->setState(WifiDirectState::kWifiDirectStateDeactivated);
+
+ return g_variant_new("(i)", WIFI_DIRECT_ERROR_NONE);
+}
+
+GVariant *WifiDirectManager::peerFound(void)
+{
+ std::string address = this->peer_.getAddress();
+ return g_variant_new("(s)", address.c_str());
+}
+
+GVariant *WifiDirectManager::peerLost(void)
+{
+ std::string address = this->peer_.getAddress();
+ return g_variant_new("(s)", address.c_str());
+}
+
+GVariant *WifiDirectManager::connectionInProgress(void)
+{
+ this->setState(WifiDirectState::kWifiDirectStateConnecting);
+
+ std::string address = this->peer_.getAddress();
+ return g_variant_new("(iis)", WIFI_DIRECT_ERROR_NONE,
+ WFD_EVENT_CONNECTION_IN_PROGRESS,
+ address.c_str());
+}
+
+GVariant *WifiDirectManager::connectionRspWithNoErrorGO(void)
+{
+ this->group_ = new WifiDirectGroup();
+ this->group_->setRole(WFD_DEV_ROLE_GO);
+
+ std::string address = this->peer_.getAddress();
+ return g_variant_new("(iis)", WIFI_DIRECT_ERROR_NONE,
+ WFD_EVENT_CONNECTION_RSP,
+ address.c_str());
+}
+
+GVariant *WifiDirectManager::peerIpAssigned(void)
+{
+ this->setState(WifiDirectState::kWifiDirectStateConnected);
+
+ std::string address = this->peer_.getAddress();
+ char ip_str[] = "192.168.0.51";
+ return g_variant_new("(ss)", address.c_str(), ip_str);
+}
+
+GVariant *WifiDirectManager::disconnection(void)
+{
+ this->destroyGroup();
+
+ std::string address = this->peer_.getAddress();
+ return g_variant_new("(iis)", WIFI_DIRECT_ERROR_NONE,
+ WFD_EVENT_DISCONNECTION_RSP,
+ address.c_str());
+}
+
+GVariant *WifiDirectManager::connectionRequestPbc(void)
+{
+ this->setState(WifiDirectState::kWifiDirectStateConnecting);
+
+ std::string address = this->peer_.getAddress();
+ return g_variant_new("(iis)", WIFI_DIRECT_ERROR_NONE,
+ WFD_EVENT_CONNECTION_REQ,
+ address.c_str());
+}
+
+GVariant *WifiDirectManager::connectionCanceled(void)
+{
+ this->setState(WifiDirectState::kWifiDirectStateActivated);
+
+ std::string address = this->peer_.getAddress();
+ return g_variant_new("(iis)", WIFI_DIRECT_ERROR_CONNECTION_CANCELED,
+ WFD_EVENT_CONNECTION_RSP,
+ address.c_str());
+}
+
+gboolean WifiDirectManager::isNotDiscoverable()
+{
+ return this->state_ != WifiDirectState::kWifiDirectStateActivated &&
+ this->state_ != WifiDirectState::kWifiDirectStateDiscovering &&
+ this->state_ != WifiDirectState::kWifiDirectStateGroupowner;
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "WifiDirectPeer.h"
+
+using namespace WifiDirectManagerNamespace;
+
+GVariant* WifiDirectPeer::packGVariantAy(const unsigned char *src, int size)
+{
+ GVariantBuilder *builder = NULL;
+ GVariant *iter = NULL;
+ int i = 0;
+
+ if (!src) {
+ return NULL;
+ }
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
+
+ for (i = 0; i < size; i++)
+ g_variant_builder_add(builder, "y", src[i]);
+
+ iter = g_variant_new("ay", builder);
+
+ g_variant_builder_unref(builder);
+ return iter;
+}
+
+GVariant *WifiDirectPeer::getPeerGvariant()
+{
+ GVariantBuilder builder_peer;
+
+ g_variant_builder_init(&builder_peer, G_VARIANT_TYPE("a{sv}"));
+
+ g_variant_builder_add(&builder_peer, "{sv}",
+ "DeviceName",
+ g_variant_new_string(this->device_name_.c_str()));
+ g_variant_builder_add(&builder_peer, "{sv}",
+ "DeviceAddress",
+ this->packGVariantAy(this->device_addr_, MACADDR_LEN));
+ g_variant_builder_add(&builder_peer, "{sv}",
+ "InterfaceAddress",
+ this->packGVariantAy(this->iface_addr_, MACADDR_LEN));
+ g_variant_builder_add(&builder_peer, "{sv}",
+ "IPAddress",
+ this->packGVariantAy(this->ip_addr_, IPADDR_LEN));
+ g_variant_builder_add(&builder_peer, "{sv}",
+ "Channel",
+ g_variant_new_uint16(this->channel_));
+
+ g_variant_builder_add(&builder_peer, "{sv}",
+ "IsGroupOwner",
+ g_variant_new_boolean(this->dev_role_ == WFD_OEM_DEV_ROLE_GO));
+ g_variant_builder_add(&builder_peer, "{sv}",
+ "IsPersistentGO",
+ g_variant_new_boolean(this->group_flag_ & WFD_OEM_GROUP_FLAG_PERSISTENT_GROUP));
+ g_variant_builder_add(&builder_peer, "{sv}",
+ "IsConnected",
+ g_variant_new_boolean(this->dev_role_ == WFD_OEM_DEV_ROLE_GC));
+ g_variant_builder_add(&builder_peer, "{sv}",
+ "WpsDevicePwdID",
+ g_variant_new_uint16(0));
+ g_variant_builder_add(&builder_peer, "{sv}",
+ "WpsCfgMethods",
+ g_variant_new_uint16(this->config_methods_));
+ g_variant_builder_add(&builder_peer, "{sv}",
+ "Category",
+ g_variant_new_uint16(this->pri_dev_type_));
+ g_variant_builder_add(&builder_peer, "{sv}",
+ "SubCategory",
+ g_variant_new_uint16(this->sec_dev_type_));
+ g_variant_builder_add(&builder_peer, "{sv}",
+ "IsWfdDevice",
+ g_variant_new_boolean(this->is_wfd_device_));
+
+ return g_variant_builder_end(&builder_peer);
+}
+
+GVariantBuilder *WifiDirectPeer::getPeerGvariantBuilder()
+{
+ GVariantBuilder *builder_peer = NULL;
+
+ builder_peer = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(builder_peer, "{sv}",
+ "DeviceName",
+ g_variant_new_string(this->device_name_.c_str()));
+ g_variant_builder_add(builder_peer, "{sv}",
+ "DeviceAddress",
+ this->packGVariantAy(this->device_addr_, MACADDR_LEN));
+ g_variant_builder_add(builder_peer, "{sv}",
+ "InterfaceAddress",
+ this->packGVariantAy(this->iface_addr_, MACADDR_LEN));
+ g_variant_builder_add(builder_peer, "{sv}",
+ "IPAddress",
+ this->packGVariantAy(this->ip_addr_, IPADDR_LEN));
+ g_variant_builder_add(builder_peer, "{sv}",
+ "Channel",
+ g_variant_new_uint16(this->channel_));
+
+ g_variant_builder_add(builder_peer, "{sv}",
+ "IsGroupOwner",
+ g_variant_new_boolean(this->dev_role_ == WFD_OEM_DEV_ROLE_GO));
+ g_variant_builder_add(builder_peer, "{sv}",
+ "IsPersistentGO",
+ g_variant_new_boolean(this->group_flag_ & WFD_OEM_GROUP_FLAG_PERSISTENT_GROUP));
+ g_variant_builder_add(builder_peer, "{sv}",
+ "IsConnected",
+ g_variant_new_boolean(this->dev_role_ == WFD_OEM_DEV_ROLE_GC));
+ g_variant_builder_add(builder_peer, "{sv}",
+ "WpsDevicePwdID",
+ g_variant_new_uint16(0));
+ g_variant_builder_add(builder_peer, "{sv}",
+ "WpsCfgMethods",
+ g_variant_new_uint16(this->config_methods_));
+ g_variant_builder_add(builder_peer, "{sv}",
+ "Category",
+ g_variant_new_uint16(this->pri_dev_type_));
+ g_variant_builder_add(builder_peer, "{sv}",
+ "SubCategory",
+ g_variant_new_uint16(this->sec_dev_type_));
+ g_variant_builder_add(builder_peer, "{sv}",
+ "IsWfdDevice",
+ g_variant_new_boolean(this->is_wfd_device_));
+
+ return builder_peer;
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "WifiDirectSignal.h"
+
+using namespace WifiDirectManagerNamespace;
+
+
+std::string WifiDirectSignal::getName()
+{
+ return this->member_;
+}
+
+void WifiDirectSignal::generate(GVariant *parameters)
+{
+ this->callback_(nullptr, nullptr, nullptr, nullptr, this->member_.c_str(), parameters, this->user_data_);
+ return;
+}
--- /dev/null
+//
+// Copyright (c) 2020 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#include <stdio.h>
+#include <stdarg.h>
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+typedef enum {
+ LOG_ID_INVALID = -1,
+ LOG_ID_MAIN,
+ LOG_ID_RADIO,
+ LOG_ID_SYSTEM,
+ LOG_ID_APPS,
+ LOG_ID_KMSG,
+ LOG_ID_SYSLOG,
+ LOG_ID_MAX
+} log_id_t;
+
+API int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ vprintf(fmt, ap);
+ va_end(ap);
+ printf("\n");
+
+ return 0;
+}
--- /dev/null
+//
+// Copyright (c) 2020 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "wifi-direct.h"
+
+#include "mock_gdbus.h"
+#include "wifi_direct_manager_mock.h"
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+static bool mock_gdbus_sync_result = true;
+static bool mock_gdbus_call_sync_result = true;
+
+static GHashTable *map_id_to_signal_data = NULL;
+
+static volatile guint _global_subscriber_id = 1;
+
+typedef struct
+{
+ GDBusSignalCallback callback;
+ gpointer user_data;
+ guint id;
+} SignalSubscriber;
+
+typedef struct
+{
+ gchar *sender;
+ gchar *interface_name;
+ gchar *member;
+ gchar *object_path;
+ gchar *arg0;
+ GDBusSignalFlags flags;
+ SignalSubscriber *subscriber;
+} SignalData;
+
+static void __signal_data_destroy(gpointer data)
+{
+ SignalData *signal_data = (SignalData *)data;
+ g_free(signal_data->sender);
+ g_free(signal_data->interface_name);
+ g_free(signal_data->member);
+ g_free(signal_data->object_path);
+ g_free(signal_data->arg0);
+ g_free(signal_data->subscriber);
+ g_free(signal_data);
+}
+
+static GDBusConnection *get_uninitialized_connection(GBusType bus_type,
+ GCancellable *cancellable,
+ GError **error)
+{
+ return g_object_new(G_TYPE_DBUS_CONNECTION,
+ "address", "temporal_address",
+ "flags", G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
+ G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
+ "exit-on-close", TRUE,
+ NULL);
+}
+
+void mock_gdbus_gdbus_sync_enable(bool value)
+{
+ mock_gdbus_sync_result = value;
+}
+
+API GDBusConnection *g_bus_get_sync(GBusType bus_type, GCancellable *cancellable, GError **error)
+{
+ if (!mock_gdbus_sync_result) {
+ g_set_error(error,
+ G_IO_ERROR,
+ G_IO_ERROR_FAILED,
+ "MOCK g_bus_get_sync Error");
+ return NULL;
+ }
+
+ map_id_to_signal_data = g_hash_table_new_full(g_direct_hash,
+ g_direct_equal, NULL, __signal_data_destroy);
+
+ return get_uninitialized_connection(bus_type, cancellable, error);
+}
+
+API guint
+g_dbus_connection_signal_subscribe (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *interface_name,
+ const gchar *member,
+ const gchar *object_path,
+ const gchar *arg0,
+ GDBusSignalFlags flags,
+ GDBusSignalCallback callback,
+ gpointer user_data,
+ GDestroyNotify user_data_free_func)
+{
+ SignalData *signal_data;
+ SignalSubscriber *subscriber;
+
+ subscriber = g_new0(SignalSubscriber, 1);
+ subscriber->callback = callback;
+ subscriber->user_data = user_data;
+ subscriber->id = g_atomic_int_add (&_global_subscriber_id, 1); /* TODO: overflow etc. */
+
+ signal_data = g_new0(SignalData, 1);
+ signal_data->sender = g_strdup (sender);
+ signal_data->interface_name = g_strdup (interface_name);
+ signal_data->member = g_strdup (member);
+ signal_data->object_path = g_strdup (object_path);
+ signal_data->arg0 = g_strdup (arg0);
+ signal_data->flags = flags;
+ signal_data->subscriber = subscriber;
+
+ g_hash_table_insert(map_id_to_signal_data,
+ GUINT_TO_POINTER (subscriber->id),
+ signal_data);
+
+ wifi_direct_manager_mock_gdbus_signal_subscribe(subscriber->id,
+ member,
+ callback,
+ user_data);
+
+ return subscriber->id;
+}
+
+API void
+g_dbus_connection_signal_unsubscribe (GDBusConnection *connection,
+ guint subscription_id)
+{
+ wifi_direct_manager_mock_gdbus_signal_unsubscribe(subscription_id);
+
+ g_hash_table_remove(map_id_to_signal_data,
+ GUINT_TO_POINTER (subscription_id));
+
+ if (g_hash_table_size(map_id_to_signal_data) == 0)
+ g_hash_table_destroy(map_id_to_signal_data);
+
+}
+
+void mock_gdbus_gdbus_call_sync_enable(bool value)
+{
+ mock_gdbus_call_sync_result = value;
+}
+
+API GVariant *g_dbus_connection_call_sync(GDBusConnection *connection,
+ const gchar *bus_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ const GVariantType *reply_type,
+ GDBusCallFlags flags,
+ gint timeout_msec,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GVariant *ret;
+ if (!mock_gdbus_call_sync_result) {
+ if (parameters)
+ g_variant_unref(parameters);
+ g_set_error(error,
+ G_IO_ERROR,
+ G_IO_ERROR_FAILED,
+ "MOCK g_dbus_connection_call_sync Error");
+ return NULL;
+ }
+
+ ret = wifi_direct_manager_mock_gdbus_call_sync(method_name, parameters, error);
+ if (ret == NULL && *error == NULL) {
+ g_set_error(error,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_UNKNOWN_METHOD,
+ "org.freedesktop.DBus does not understand message %s", method_name);
+ return NULL;
+ }
+
+ return ret;
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <stdbool.h>
+#include <system_info.h>
+
+#include "mock_sysinfo.h"
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+static bool mock_sysinfo_result = true;
+
+void mock_sysinfo_set_up_wifi_direct(bool value)
+{
+ mock_sysinfo_result = value;
+}
+
+API int __wrap_system_info_get_platform_bool(const char *key, bool *value)
+{
+ *value = mock_sysinfo_result;
+ return SYSTEM_INFO_ERROR_NONE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <vconf.h>
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+API int vconf_notify_key_changed(const char *key, vconf_callback_fn cb,
+ void *user_data)
+{
+ return 0;
+}
+
+API int vconf_ignore_key_changed(const char *key, vconf_callback_fn cb)
+{
+ return 0;
+}
+
+API int vconf_get_int(const char *key, int *intval)
+{
+ *intval = 0;
+ return 0;
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "wifi-direct.h"
+
+#include "WifiDirectSignal.h"
+#include "WifiDirectManager.h"
+
+#include "wifi_direct_manager_mock.h"
+
+using namespace WifiDirectManagerNamespace;
+
+WifiDirectManager *p_wfd_mgr_mock;
+std::map<std::string, WifiDirectSignal *> signal_map_with_name;
+std::map<unsigned int, WifiDirectSignal *> signal_map_with_id;
+
+void wifi_direct_manager_mock_init()
+{
+ p_wfd_mgr_mock = new WifiDirectManager();
+}
+
+void wifi_direct_manager_mock_deinit()
+{
+ delete p_wfd_mgr_mock;
+}
+
+GVariant *wifi_direct_manager_mock_gdbus_call_sync(const gchar *method_name,
+ GVariant *parameters,
+ GError **error)
+{
+ GVariant *ret;
+
+ ret = p_wfd_mgr_mock->callMethod(method_name, parameters, error);
+ if (parameters)
+ g_variant_unref(parameters);
+
+ return ret;
+}
+
+void wifi_direct_manager_mock_gdbus_signal_subscribe(
+ guint id,
+ const gchar *member,
+ GDBusSignalCallback callback,
+ gpointer user_data)
+{
+ WifiDirectSignal *signal = new WifiDirectSignal(id, member, callback, user_data);
+
+ signal_map_with_name[signal->getName()] = signal;
+ signal_map_with_id[id] = signal;
+ return;
+}
+
+void wifi_direct_manager_mock_gdbus_signal_unsubscribe(guint id)
+{
+ WifiDirectSignal *signal = signal_map_with_id[id];
+ signal_map_with_id.erase(id);
+ signal_map_with_name.erase(signal->getName());
+ delete signal;
+
+ return;
+}
+
+void wifi_direct_manager_mock_generate_activation_signal()
+{
+ std::string signal_name = std::string("Activation");
+ WifiDirectSignal *signal = signal_map_with_name[signal_name];
+ GVariant *signal_parameter = p_wfd_mgr_mock->activated();
+
+ signal->generate(signal_parameter);
+
+ g_variant_unref(signal_parameter);
+
+ return;
+}
+
+void wifi_direct_manager_mock_generate_deactivation_signal()
+{
+ std::string signal_name = std::string("Deactivation");
+ WifiDirectSignal *signal = signal_map_with_name[signal_name];
+ GVariant *signal_parameter = p_wfd_mgr_mock->deactivated();
+
+ signal->generate(signal_parameter);
+
+ g_variant_unref(signal_parameter);
+}
+
+void wifi_direct_manager_mock_generate_listen_started_signal()
+{
+ std::string signal_name = std::string("ListenStarted");
+ WifiDirectSignal *signal = signal_map_with_name[signal_name];
+ signal->generate(NULL);
+}
+
+void wifi_direct_manager_mock_generate_discovery_started_signal()
+{
+ std::string signal_name = std::string("DiscoveryStarted");
+ WifiDirectSignal *signal = signal_map_with_name[signal_name];
+ signal->generate(NULL);
+}
+
+void wifi_direct_manager_mock_generate_discovery_finished_signal()
+{
+ std::string signal_name = std::string("DiscoveryFinished");
+ WifiDirectSignal *signal = signal_map_with_name[signal_name];
+ signal->generate(NULL);
+}
+
+void wifi_direct_manager_mock_generate_peer_found_signal()
+{
+ std::string signal_name = std::string("PeerFound");
+ WifiDirectSignal *signal = signal_map_with_name[signal_name];
+ GVariant *signal_parameter = p_wfd_mgr_mock->peerFound();
+
+ signal->generate(signal_parameter);
+
+ g_variant_unref(signal_parameter);
+
+ return;
+}
+
+void wifi_direct_manager_mock_generate_peer_lost_signal()
+{
+ std::string signal_name = std::string("PeerLost");
+ WifiDirectSignal *signal = signal_map_with_name[signal_name];
+ GVariant *signal_parameter = p_wfd_mgr_mock->peerLost();
+
+ signal->generate(signal_parameter);
+
+ g_variant_unref(signal_parameter);
+}
+
+void wifi_direct_manager_mock_generate_created_signal()
+{
+ std::string signal_name = std::string("Created");
+ WifiDirectSignal *signal = signal_map_with_name[signal_name];
+ signal->generate(NULL);
+}
+
+void wifi_direct_manager_mock_generate_destroyed_signal()
+{
+ std::string signal_name = std::string("Destroyed");
+ WifiDirectSignal *signal = signal_map_with_name[signal_name];
+ signal->generate(NULL);
+}
+
+void wifi_direct_manager_mock_generate_connection_in_progress_signal()
+{
+ std::string signal_name = std::string("Connection");
+ WifiDirectSignal *signal = signal_map_with_name[signal_name];
+ GVariant *signal_parameter = p_wfd_mgr_mock->connectionInProgress();
+
+ signal->generate(signal_parameter);
+
+ g_variant_unref(signal_parameter);
+}
+
+void wifi_direct_manager_mock_generate_connection_rsp_with_no_error_go_signal()
+{
+ std::string signal_name = std::string("Connection");
+ WifiDirectSignal *signal = signal_map_with_name[signal_name];
+ GVariant *signal_parameter = p_wfd_mgr_mock->connectionRspWithNoErrorGO();
+
+ signal->generate(signal_parameter);
+
+ g_variant_unref(signal_parameter);
+}
+
+void wifi_direct_manager_mock_generate_peer_ip_assigned_signal()
+{
+ std::string signal_name = std::string("PeerIPAssigned");
+ WifiDirectSignal *signal = signal_map_with_name[signal_name];
+ GVariant *signal_parameter = p_wfd_mgr_mock->peerIpAssigned();
+
+ signal->generate(signal_parameter);
+
+ g_variant_unref(signal_parameter);
+}
+
+void wifi_direct_manager_mock_generate_disconnection_signal()
+{
+ std::string signal_name = std::string("Disconnection");
+ WifiDirectSignal *signal = signal_map_with_name[signal_name];
+ GVariant *signal_parameter = p_wfd_mgr_mock->disconnection();
+
+ signal->generate(signal_parameter);
+
+ g_variant_unref(signal_parameter);
+}
+
+void wifi_direct_manager_mock_generate_connection_request_pbc_signal()
+{
+ std::string signal_name = std::string("Connection");
+ WifiDirectSignal *signal = signal_map_with_name[signal_name];
+ GVariant *signal_parameter = p_wfd_mgr_mock->connectionRequestPbc();
+
+ signal->generate(signal_parameter);
+
+ g_variant_unref(signal_parameter);
+}
+
+void wifi_direct_manager_mock_generate_connection_canceled_signal()
+{
+ std::string signal_name = std::string("Connection");
+ WifiDirectSignal *signal = signal_map_with_name[signal_name];
+ GVariant *signal_parameter = p_wfd_mgr_mock->connectionCanceled();
+
+ signal->generate(signal_parameter);
+
+ g_variant_unref(signal_parameter);
+}
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <assert.h>
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <wifi-direct.h>
+
+/* For wifi-direct package internal use only */
+#include <wifi-direct-internal.h>
+
+#define RESET_COLOR "\e[m"
+#define MAKE_RED "\e[31m"
+#define MAKE_GREEN "\e[32m"
+
+#define __FUNC_ENTER__ printf("%s() entering...\n", __func__)
+#define __FUNC_EXIT__ printf("%s() leaving...\n", __func__)
+
+#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
+#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
+#define MACSTR_LEN 18
+#define MAX_PEER_NUM 10
+
+static const char *test_wfd_convert_error_to_string(wifi_direct_error_e err_type)
+{
+ switch (err_type) {
+ case WIFI_DIRECT_ERROR_NONE:
+ return "NONE";
+ case WIFI_DIRECT_ERROR_NOT_PERMITTED:
+ return "NOT_PERMITTED";
+ case WIFI_DIRECT_ERROR_OUT_OF_MEMORY:
+ return "OUT_OF_MEMORY";
+ case WIFI_DIRECT_ERROR_RESOURCE_BUSY:
+ return "RESOURCE_BUSY";
+ case WIFI_DIRECT_ERROR_INVALID_PARAMETER:
+ return "INVALID_PARAMETER";
+ case WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT:
+ return "CONNECTION_TIME_OUT";
+ case WIFI_DIRECT_ERROR_NOT_INITIALIZED:
+ return "NOT_INITIALIZED";
+ case WIFI_DIRECT_ERROR_COMMUNICATION_FAILED:
+ return "COMMUNICATION_FAILED";
+ case WIFI_DIRECT_ERROR_WIFI_USED:
+ return "WIFI_USED";
+ case WIFI_DIRECT_ERROR_MOBILE_AP_USED:
+ return "MOBILE_AP_USED";
+ case WIFI_DIRECT_ERROR_CONNECTION_FAILED:
+ return "CONNECTION_FAILED";
+ case WIFI_DIRECT_ERROR_AUTH_FAILED:
+ return "AUTH_FAILED";
+ case WIFI_DIRECT_ERROR_OPERATION_FAILED:
+ return "OPERATION_FAILED";
+ case WIFI_DIRECT_ERROR_TOO_MANY_CLIENT:
+ return "TOO_MANY_CLIENT";
+ case WIFI_DIRECT_ERROR_ALREADY_INITIALIZED:
+ return "ALREADY_INITIALIZED";
+ case WIFI_DIRECT_ERROR_CONNECTION_CANCELED:
+ return "CONNECTION_CANCELED";
+ default:
+ break;
+ }
+ return "UNKNOWN";
+}
+
+enum {
+ CMD_QUIT,
+ CMD_FULL_MENU,
+ CMD_INITIALIZE,
+ CMD_ACTIVATE_WIFI_DIRECT,
+ CMD_DEACTIVATE_WIFI_DIRECT,
+ CMD_START_DISCOVER,
+ CMD_START_DISCOVER_WITH_LISTEN_ONLY,
+ CMD_START_DISCOVER_SPECIFIC_CHANNEL,
+ CMD_START_DISCOVER_SPECIFIC_FREQUENCY,
+ CMD_CANCEL_DISCOVER,
+ CMD_GET_DISVOCERY_RESULT,
+ /* CMD_SEND_PROVISION_DISCOVER_REQ, */
+ CMD_SEND_CONNECTION_REQ,
+ CMD_GET_LINK_STATUS,
+ CMD_CONNECT_PEER,
+ CMD_CANCEL_CONNECTION,
+ CMD_DISCONNECT_ALL,
+ CMD_DISCONNECT,
+
+ CMD_ENABLE_PUSH_BUTTON,
+ CMD_CREATE_GROUP,
+ CMD_CREATE_GROUP_WITH_SSID,
+ CMD_CANCEL_GROUP,
+ CMD_IS_GROUP_OWNER,
+ CMD_REJECT,
+ CMD_INVITE,
+ CMD_SET_DEVICE_NAME,
+ CMD_GET_DEVICE_NAME,
+ CMD_SET_SSID,
+ CMD_GET_SSID,
+ CMD_SET_WPA,
+ CMD_SET_CHANNEL,
+ CMD_SET_WPS_CONFIG,
+ CMD_SET_MAX_CLIENT,
+ CMD_GET_MAX_CLIENT,
+ CMD_SET_HIDE_SSID,
+ CMD_ACTIVATE_PERSISTENT_GROUP,
+ CMD_DEACTIVATE_PERSISTENT_GROUP,
+ CMD_IS_PERSISTENT_GROUP_ACTIVATED,
+ CMD_GET_PERSISTENT_GROUP_LIST,
+ CMD_REMOVE_PERSISTENT_GROUP,
+ /* CMD_SET_GROUP_OWNER, */
+ CMD_SET_AUTO_CONNECTION,
+ CMD_IS_AUTO_CONNECTION,
+ /* CMD_SET_LISTEN_ONLY, */
+ CMD_SET_WPS_PIN,
+ CMD_GET_WPS_PIN,
+ CMD_GET_SUPPORTED_WPS_MODE,
+ CMD_SET_CURRENT_WPS_MODE,
+ CMD_GET_CURRENT_WPS_MODE,
+ CMD_GET_CONNECTED_PEERS_INFO,
+ CMD_GET_GO_INTENT,
+ CMD_SET_GO_INTENT,
+ CMD_GET_DEVICE_MAC,
+ CMD_IS_AUTONOMOUS_GROUP,
+ CMD_SET_ACTIVATION_CB,
+ CMD_SET_DISCOVER_CB,
+ CMD_SET_SERVICE_CB,
+ CMD_SET_CONNECTION_CB,
+ CMD_SET_IP_ADDR_ASSIGNED_CB,
+ CMD_SET_PEER_FOUND_CB,
+ CMD_SET_DEVICE_NAME_CB,
+ CMD_SET_STATE_CB,
+ CMD_UNSET_ACTIVATION_CB,
+ CMD_UNSET_DISCOVER_CB,
+ CMD_UNSET_SERVICE_CB,
+ CMD_UNSET_CONNECTION_CB,
+ CMD_UNSET_IP_ADDR_ASSIGNED_CB,
+ CMD_UNSET_PEER_FOUND_CB,
+ CMD_UNSET_DEVICE_NAME_CB,
+ CMD_UNSET_STATE_CB,
+ CMD_GET_NETWORK_IF_NAME,
+ CMD_GET_SUBNET_MASK,
+ CMD_GET_GATEWAY_ADDR,
+ CMD_IS_DISCOVERABLE,
+ CMD_IS_LISTEN_ONLY,
+ CMD_GET_PRIMARY_DEVICE_TYPE,
+ CMD_GET_SECONDARY_DEVICE_TYPE,
+ CMD_GET_OPERATING_CHANNEL,
+ CMD_GET_IP_ADDR,
+ CMD_REGISTER_SERVICE,
+ CMD_DEREGISTER_SERVICE,
+ CMD_START_SERVICE_DISCOVERY,
+ CMD_CANCEL_SERVICE_DISCOVERY,
+
+ CMD_INCREASE_OEM_LOGLEVEL,
+ CMD_DECREASE_OEM_LOGLEVEL,
+ CMD_DEINITIALIZE,
+ CMD_INIT_MIRACAST,
+ CMD_GET_PEER_INFO,
+ CMD_SET_PASSPHRASE,
+ CMD_GET_PASSPHRASE,
+ CMD_SET_AUTOCONNECTION_PEER,
+
+ CMD_INIT_DISPLAY,
+ CMD_DEINIT_DISPLAY,
+ CMD_SET_DISPLAY,
+ CMD_SET_DISPLAY_AVAILABILITY,
+ CMD_GET_DISPLAY,
+ CMD_GET_DISPLAY_AVAILABILITY,
+ CMD_GET_PEER_DISPLAY_TYPE,
+ CMD_GET_PEER_DISPLAY_AVAILABILITY,
+ CMD_GET_PEER_DISPLAY_HDCP,
+ CMD_GET_PEER_DISPLAY_PORT,
+ CMD_GET_PEER_DISPLAY_THROUGHPUT,
+ CMD_GET_SESSION_TIMER,
+ CMD_SET_SESSION_TIMER,
+ CMD_SET_AUTO_GROUP_REMOVAL,
+ CMD_GET_PEER_RSSI,
+
+ CMD_ADD_VSIE,
+ CMD_GET_VSIE,
+ 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,
+};
+
+typedef struct {
+ int cmd;
+ char* menu_str;
+} menu_str_t;
+
+menu_str_t g_menu_str[] = {
+ { CMD_QUIT, "CMD_QUIT" },
+ { CMD_FULL_MENU, "CMD_FULL_MENU" },
+ { CMD_INITIALIZE, "CMD_INITIALIZE" },
+ { CMD_ACTIVATE_WIFI_DIRECT, "CMD_ACTIVATE_WIFI_DIRECT" },
+ { CMD_DEACTIVATE_WIFI_DIRECT, "CMD_DEACTIVATE_WIFI_DIRECT" },
+ { CMD_START_DISCOVER, "CMD_START_DISCOVER" },
+ { CMD_START_DISCOVER_WITH_LISTEN_ONLY, "CMD_START_DISCOVER_WITH_LISTEN_ONLY" },
+ { CMD_START_DISCOVER_SPECIFIC_CHANNEL, "CMD_START_DISCOVER_SPECIFIC_CHANNEL" },
+ { CMD_START_DISCOVER_SPECIFIC_FREQUENCY, "CMD_START_DISCOVER_SPECIFIC_FREQUENCY" },
+ { CMD_CANCEL_DISCOVER, "CMD_CANCEL_DISCOVER" },
+ { CMD_GET_DISVOCERY_RESULT, "CMD_GET_DISVOCERY_RESULT" },
+ /* { CMD_SEND_PROVISION_DISCOVER_REQ, "CMD_SEND_PROVISION_DISCOVER_REQ" }, */
+ { CMD_SEND_CONNECTION_REQ, "CMD_SEND_CONNECTION_REQ" },
+
+ { CMD_GET_LINK_STATUS, "CMD_GET_LINK_STATUS" },
+ { CMD_CONNECT_PEER, "CMD_CONNECT_PEER" },
+ { CMD_CANCEL_CONNECTION, "CMD_CANCEL_CONNECTION" },
+ { CMD_DISCONNECT_ALL, "CMD_DISCONNECT_ALL" },
+ { CMD_DISCONNECT, "CMD_DISCONNECT" },
+
+ { CMD_ENABLE_PUSH_BUTTON, "CMD_ENABLE_PUSH_BUTTON" },
+
+ { CMD_CREATE_GROUP, "CMD_CREATE_GROUP" },
+ { CMD_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" },
+ { CMD_INVITE, "CMD_INVITE" },
+ { CMD_SET_DEVICE_NAME, "CMD_SET_DEVICE_NAME" },
+ { CMD_GET_DEVICE_NAME, "CMD_GET_DEVICE_NAME" },
+ { CMD_SET_SSID, "CMD_SET_SSID" },
+ { CMD_GET_SSID, "CMD_GET_SSID" },
+ { CMD_SET_WPA, "CMD_SET_WPA" },
+ { CMD_SET_CHANNEL, "CMD_SET_CHANNEL" },
+ { CMD_SET_WPS_CONFIG, "CMD_SET_WPS_CONFIG" },
+ { CMD_SET_MAX_CLIENT, "CMD_SET_MAX_CLIENT" },
+ { CMD_GET_MAX_CLIENT, "CMD_GET_MAX_CLIENT" },
+ { CMD_SET_HIDE_SSID, "CMD_SET_HIDE_SSID" },
+ { CMD_ACTIVATE_PERSISTENT_GROUP, "CMD_ACTIVATE_PERSISTENT_GROUP" },
+ { CMD_DEACTIVATE_PERSISTENT_GROUP, "CMD_DEACTIVATE_PERSISTENT_GROUP" },
+ { CMD_IS_PERSISTENT_GROUP_ACTIVATED, "CMD_IS_PERSISTENT_GROUP_ACTIVATED" },
+ { CMD_GET_PERSISTENT_GROUP_LIST, "CMD_GET_PERSISTENT_GROUP_LIST" },
+ { CMD_REMOVE_PERSISTENT_GROUP, "CMD_REMOVE_PERSISTENT_GROUP" },
+ /* { CMD_SET_GROUP_OWNER, "CMD_SET_GROUP_OWNER" }, */
+ { CMD_SET_AUTO_CONNECTION, "CMD_SET_AUTO_CONNECTION" },
+ { CMD_IS_AUTO_CONNECTION, "CMD_IS_AUTO_CONNECTION" },
+ /* { CMD_SET_LISTEN_ONLY, "CMD_SET_LISTEN_ONLY" }, */
+ { CMD_SET_WPS_PIN, "CMD_SET_WPS_PIN" },
+ { CMD_GET_WPS_PIN, "CMD_GET_WPS_PIN" },
+ { CMD_GET_SUPPORTED_WPS_MODE, "CMD_GET_SUPPORTED_WPS_MODE" },
+ { CMD_SET_CURRENT_WPS_MODE, "CMD_SET_CURRENT_WPS_MODE" },
+ { CMD_GET_CURRENT_WPS_MODE, "CMD_GET_CURRENT_WPS_MODE" },
+ { CMD_GET_CONNECTED_PEERS_INFO, "CMD_GET_CONNECTED_PEERS_INFO" },
+ { CMD_GET_GO_INTENT, "CMD_GET_GO_INTENT" },
+ { CMD_SET_GO_INTENT, "CMD_SET_GO_INTENT" },
+ { CMD_GET_DEVICE_MAC, "CMD_GET_DEVICE_MAC" },
+ { CMD_IS_AUTONOMOUS_GROUP, "CMD_IS_AUTONOMOUS_GROUP" },
+ { CMD_SET_ACTIVATION_CB, "CMD_SET_ACTIVATION_CB" },
+ { CMD_SET_DISCOVER_CB, "CMD_SET_DISCOVER_CB" },
+ { CMD_SET_CONNECTION_CB, "CMD_SET_CONNECTION_CB" },
+ { CMD_SET_IP_ADDR_ASSIGNED_CB, "CMD_SET_IP_ADDR_ASSIGNED_CB" },
+ { CMD_SET_PEER_FOUND_CB, "CMD_SET_PEER_FOUND_CB" },
+ { CMD_SET_DEVICE_NAME_CB, "CMD_SET_DEVICE_NAME_CB"},
+ { CMD_SET_STATE_CB, "CMD_SET_STATE_CB"},
+ { CMD_UNSET_ACTIVATION_CB, "CMD_UNSET_ACTIVATION_CB" },
+ { CMD_UNSET_DISCOVER_CB, "CMD_UNSET_DISCOVER_CB" },
+ { CMD_UNSET_CONNECTION_CB, "CMD_UNSET_CONNECTION_CB" },
+ { CMD_UNSET_IP_ADDR_ASSIGNED_CB, "CMD_UNSET_IP_ADDR_ASSIGNED_CB" },
+ { CMD_UNSET_PEER_FOUND_CB, "CMD_UNSET_PEER_FOUND_CB" },
+ { CMD_UNSET_STATE_CB, "CMD_UNSET_STATE_CB" },
+ { CMD_GET_NETWORK_IF_NAME, "CMD_GET_NETWORK_IF_NAME" },
+ { CMD_GET_SUBNET_MASK, "CMD_GET_SUBNET_MASK" },
+ { CMD_GET_GATEWAY_ADDR, "CMD_GET_GATEWAY_ADDR" },
+ { CMD_IS_DISCOVERABLE, "CMD_IS_DISCOVERABLE" },
+ { CMD_IS_LISTEN_ONLY, "CMD_IS_LISTEN_ONLY" },
+ { CMD_GET_PRIMARY_DEVICE_TYPE, "CMD_GET_PRIMARY_DEVICE_TYPE" },
+ { CMD_GET_SECONDARY_DEVICE_TYPE, "CMD_GET_SECONDARY_DEVICE_TYPE" },
+ { CMD_GET_OPERATING_CHANNEL, "CMD_GET_OPERATING_CHANNEL" },
+ { CMD_GET_IP_ADDR, "CMD_GET_IP_ADDR" },
+ { CMD_REGISTER_SERVICE, "CMD_REGISTER_SERVICE" },
+ { CMD_DEREGISTER_SERVICE, "CMD_DEREGISTER_SERVICE" },
+ { CMD_START_SERVICE_DISCOVERY, "CMD_START_SERVICE_DISCOVERY" },
+ { CMD_CANCEL_SERVICE_DISCOVERY, "CMD_CANCEL_SERVICE_DISCOVERY" },
+
+ { CMD_INCREASE_OEM_LOGLEVEL, "CMD_INCREASE_OEM_LOGLEVEL" },
+ { CMD_DECREASE_OEM_LOGLEVEL, "CMD_DECREASE_OEM_LOGLEVEL" },
+
+ { CMD_DEINITIALIZE, "CMD_DEINITIALIZE" },
+ { CMD_INIT_MIRACAST, "CMD_INIT_MIRACAST" },
+ { CMD_GET_PEER_INFO, "CMD_GET_PEER_INFO" },
+ { CMD_SET_PASSPHRASE, "CMD_SET_PASSPHRASE" },
+ { CMD_GET_PASSPHRASE, "CMD_GET_PASSPHRASE" },
+ { CMD_SET_AUTOCONNECTION_PEER, "CMD_SET_AUTOCONNECTION_PEER" },
+
+ { CMD_INIT_DISPLAY, "CMD_INIT_DISPLAY" },
+ { CMD_DEINIT_DISPLAY, "CMD_DEINIT_DISPLAY" },
+ { CMD_SET_DISPLAY, "CMD_SET_DISPLAY" },
+ { CMD_SET_DISPLAY_AVAILABILITY, "CMD_SET_DISPLAY_AVAILABILITY" },
+ { CMD_GET_DISPLAY, "CMD_GET_DISPLAY" },
+ { CMD_GET_DISPLAY_AVAILABILITY, "CMD_GET_DISPLAY_AVAILABILITY" },
+ { CMD_GET_PEER_DISPLAY_TYPE, "CMD_GET_PEER_DISPLAY_TYPE" },
+ { CMD_GET_PEER_DISPLAY_AVAILABILITY, "CMD_GET_PEER_DISPLAY_AVAILABILITY" },
+ { CMD_GET_PEER_DISPLAY_HDCP, "CMD_GET_PEER_DISPLAY_HDCP" },
+ { CMD_GET_PEER_DISPLAY_PORT, "CMD_GET_PEER_DISPLAY_PORT" },
+ { CMD_GET_PEER_DISPLAY_THROUGHPUT, "CMD_GET_PEER_DISPLAY_THROUGHPUT" },
+ { CMD_GET_SESSION_TIMER, "CMD_GET_SESSION_TIMER" },
+ { CMD_SET_SESSION_TIMER, "CMD_SET_SESSION_TIMER" },
+ { CMD_SET_AUTO_GROUP_REMOVAL, "CMD_SET_AUTO_GROUP_REMOVAL" },
+ { CMD_GET_PEER_RSSI, "CMD_GET_PEER_RSSI" },
+
+ { CMD_ADD_VSIE, "CMD_ADD_VSIE" },
+ { CMD_GET_VSIE, "CMD_GET_VSIE" },
+ { 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 }, };
+
+struct appdata {
+ GMainLoop* main_loop;
+
+ wifi_direct_discovered_peer_info_s peer_list[MAX_PEER_NUM];
+ int peer_count;
+ int selected_peer_index;
+
+ wifi_direct_connected_peer_info_s connected_peer_list[MAX_PEER_NUM];
+ int connected_peer_count;
+};
+
+struct appdata* g_test_appdata;
+
+void set_appdata(struct appdata* p)
+{
+ g_test_appdata = p;
+}
+
+static inline void prt_help(const char *cmd)
+{
+ printf("%s -t [dest ID]\n", cmd);
+ printf(" -u [my ID]\n");
+ printf(" -p [passwd]\n");
+ printf(" -a [alias]\n");
+}
+
+static int get_param(int argc, char **argv, struct appdata *ad)
+{
+ printf("Parsing argument...\n");
+ int opt;
+ while ((opt = getopt(argc, argv, "t:u:p:a:")) != -1) {
+ printf("Parsing argument...:%c\n", opt);
+ switch (opt) {
+ case 't':
+ default:
+ prt_help(argv[0]);
+ return -1;
+ }
+ }
+
+ printf("Argument: \n");
+
+ return 0;
+}
+
+char* cmd_transform(char*str)
+{
+ int i, j;
+ int len;
+ static char static_buffer[255];
+
+ if (str == NULL)
+ return "";
+
+ len = strlen(str);
+ if (len == 0)
+ return "";
+
+ /* remove "CMD_" */
+ /* lower char */
+ /* replance "_" to space */
+ for (i = 0, j = 4; i < len; i++, j++) {
+ if (str[j] >= 'A' && str[j] <= 'Z')
+ static_buffer[i] = str[j] + 'a' - 'A';
+ else if (str[j] == '_')
+ static_buffer[i] = ' ';
+ else
+ static_buffer[i] = str[j];
+ }
+ static_buffer[j] = '\0';
+
+ return static_buffer;
+}
+
+void usage_full()
+{
+ int i;
+ printf("Call Test Program\n");
+
+ for (i = 0; g_menu_str[i].cmd != -1; i++) {
+ if (i % 4 == 0)
+ printf("\n");
+ printf(" %02d: %-32s ", g_menu_str[i].cmd,
+ cmd_transform(g_menu_str[i].menu_str));
+
+ }
+ printf("\n");
+}
+
+int is_digit(const char* str)
+{
+ int len;
+ int i;
+
+ if (str == NULL)
+ return -1;
+
+ if (strlen(str) == 0)
+ return -1;
+
+ len = strlen(str);
+ for (i = 0; i < len; i++) {
+ if (str[i] < '0' || str[i] > '9')
+ return -2;
+ }
+
+ return 0;
+}
+
+char* print_link_state(wifi_direct_state_e state)
+{
+ if (state == WIFI_DIRECT_STATE_DEACTIVATED)
+ return "DEACTIVATED";
+ if (state == WIFI_DIRECT_STATE_ACTIVATING)
+ return "ACTIVATING";
+ if (state == WIFI_DIRECT_STATE_ACTIVATED)
+ return "ACTIVATED";
+ if (state == WIFI_DIRECT_STATE_DISCOVERING)
+ return "DISCOVERING";
+ if (state == WIFI_DIRECT_STATE_CONNECTING)
+ return "CONNECTING";
+ if (state == WIFI_DIRECT_STATE_DISCONNECTING)
+ return "DISCONNECTING";
+ if (state == WIFI_DIRECT_STATE_CONNECTED)
+ return "CONNECTED";
+ if (state == WIFI_DIRECT_STATE_GROUP_OWNER)
+ return "GROUP OWNER";
+
+ return "Unknown state";
+}
+
+int select_peer(struct appdata* ad)
+{
+ wifi_direct_discovered_peer_info_s* list;
+ int target = -1;
+ int i;
+
+ if (ad == NULL)
+ return 0;
+
+ list = ad->peer_list;
+
+ for (i = 0; i < ad->peer_count; i++) {
+ printf("index [%d] MAC [%s] Owner=[%s] SSID[%s]\n",
+ i,
+ list[i].mac_address,
+ list[i].is_group_owner ? "YES" : "NO",
+ list[i].device_name);
+ }
+
+ printf("input peer index:\n");
+ if (scanf(" %3d", &target) < 1)
+ return 0;
+
+ if (target < 0 || target > ad->peer_count) {
+ printf("Wrong contact index [%d]\n", target);
+ return 0;
+ } else
+ ad->selected_peer_index = target;
+
+ return 1;
+}
+
+int select_connected_peer(struct appdata* ad)
+{
+ wifi_direct_connected_peer_info_s* list;
+ int target = -1;
+ int i, j;
+
+ if (ad == NULL)
+ return 0;
+
+ list = ad->connected_peer_list;
+
+ for (i = 0; i < ad->connected_peer_count; i++) {
+ if (list[i].service_count == 0) {
+ printf("index [%d] MAC [%s] SSID[%s] P2P_Supported [%d]\n", i, list[i].mac_address, list[i].device_name, list[i].p2p_supported);
+ } else {
+ char services[256] = {0,};
+ unsigned int len = 0;
+ printf("Service Count = [%d][%p]\n", list[i].service_count, list[i].service_list);
+ for (j = 0; j < list[i].service_count && list[i].service_list != NULL; j++) {
+ printf("Service[%p]=%s\n", list[i].service_list[j], list[i].service_list[j]);
+ snprintf(services + len, 256-len, " %s", list[i].service_list[j]);
+ len = len + strlen(list[i].service_list[j]) + 1;
+ }
+ printf("index [%d] MAC [%s] SSID[%s] Services=[%s]\n", i, list[i].mac_address, list[i].device_name, services);
+ }
+ }
+
+ printf("input peer index:\n");
+ if (scanf(" %3d", &target) < 1)
+ return -1;
+
+ if (target < 0 || target > ad->connected_peer_count) {
+ printf("Wrong contact index [%d]\n", target);
+ return -1;
+ } else
+ ad->selected_peer_index = target;
+
+ return 1;
+}
+
+void print_peers_connected(struct appdata* ad)
+{
+ wifi_direct_connected_peer_info_s* list;
+ int i, j;
+
+ if (ad == NULL)
+ return;
+
+ list = ad->connected_peer_list;
+
+ for (i = 0; i < ad->connected_peer_count; i++) {
+ if (list[i].service_count == 0) {
+ printf("index [%d] MAC [%s] SSID[%s] \n", i, list[i].mac_address, list[i].device_name);
+ } else {
+ char services[256] = {0,};
+ unsigned int len = 0;
+ printf("Service Count = [%d][%p]\n", list[i].service_count, list[i].service_list);
+ for (j = 0; j < list[i].service_count && list[i].service_list != NULL; j++) {
+ printf("Service[%p]=%s\n", list[i].service_list[j], list[i].service_list[j]);
+ snprintf(services + len, 256-len, " %s", list[i].service_list[j]);
+ len = len + strlen(list[i].service_list[j]) + 1;
+ }
+ printf("index [%d] MAC [%s] SSID[%s] Services=[%s]\n", i, list[i].mac_address, list[i].device_name, services);
+ }
+ }
+
+}
+
+void print_peers(struct appdata* ad)
+{
+ wifi_direct_discovered_peer_info_s* list;
+ int i, j;
+
+ if (ad == NULL)
+ return;
+
+ list = ad->peer_list;
+
+ for (i = 0; i < ad->peer_count; i++) {
+ if (list[i].service_count == 0) {
+ printf("index [%d] MAC [%s] Owner=[%s] connected=[%d] SSID[%s] ctg=[%d/%d] \n",
+ i,
+ list[i].mac_address,
+ list[i].is_group_owner ? "YES" : "NO",
+ list[i].is_connected,
+ list[i].device_name,
+ list[i].primary_device_type,
+ list[i].secondary_device_type
+ );
+ } else {
+ char services[256] = {0,};
+ unsigned int len = 0;
+ printf("Service Count = [%d][%p]\n", list[i].service_count, list[i].service_list);
+ for (j = 0; j < list[i].service_count && list[i].service_list != NULL; j++) {
+ printf("Service[%p]=%s\n", list[i].service_list[j], list[i].service_list[j]);
+ snprintf(services + len, 256-len, " %s", list[i].service_list[j]);
+ len = len + strlen(list[i].service_list[j]) + 1;
+ }
+ printf("index [%d] MAC [%s] Owner=[%s] connected=[%d] SSID[%s] ctg=[%d/%d] Services=[%s]\n",
+ i,
+ list[i].mac_address,
+ list[i].is_group_owner ? "YES" : "NO",
+ list[i].is_connected,
+ list[i].device_name,
+ list[i].primary_device_type,
+ list[i].secondary_device_type,
+ services
+ );
+ }
+ }
+
+}
+
+
+void event_printf(char*s)
+{
+ printf("========================================>%s\n", s);
+}
+
+void _cb_activation(int error_code, wifi_direct_device_state_e device_state, void *user_data)
+{
+ __FUNC_ENTER__;
+
+ switch (device_state) {
+ case WIFI_DIRECT_DEVICE_STATE_ACTIVATED:
+ event_printf("event -WIFI_DIRECT_DEVICE_STATE_ACTIVATED\n");
+ break;
+
+ case WIFI_DIRECT_DEVICE_STATE_DEACTIVATED:
+ event_printf("event - WIFI_DIRECT_DEVICE_STATE_DEACTIVATED\n");
+ break;
+
+ default:
+ break;
+ }
+}
+
+
+bool _cb_discovered_peers_impl(wifi_direct_discovered_peer_info_s* peer, void* user_data)
+{
+ __FUNC_ENTER__;
+
+ struct appdata* ad = (struct appdata*) user_data;
+
+ if (NULL != peer) {
+ if (ad->peer_count >= MAX_PEER_NUM)
+ return false; /* break out of the loop */
+
+ memcpy(&ad->peer_list[ad->peer_count], peer, sizeof(wifi_direct_discovered_peer_info_s));
+ ad->peer_count++;
+ }
+
+ return true; /* continue with the next iteration of the loop */
+}
+
+bool _cb_connected_peers_impl(wifi_direct_connected_peer_info_s* peer, void* user_data)
+{
+ __FUNC_ENTER__;
+
+ struct appdata* ad = (struct appdata*) user_data;
+
+ if (NULL != peer) {
+ if (ad->connected_peer_count >= MAX_PEER_NUM)
+ return false; /* break out of the loop */
+
+ memcpy(&ad->connected_peer_list[ad->connected_peer_count], peer, sizeof(wifi_direct_connected_peer_info_s));
+ ad->connected_peer_count++;
+ }
+
+ return true; /* continue with the next iteration of the loop */
+}
+
+bool _cb_persistent_groups_impl(const char* mac_address, const char* ssid, void* user_data)
+{
+ __FUNC_ENTER__;
+
+ if (NULL != mac_address)
+ printf("mac_address=[%s]\n", mac_address);
+
+ if (NULL != ssid)
+ printf("ssid=[%s]\n", ssid);
+
+ return true; /* continue with the next iteration of the loop */
+}
+
+void _cb_discover(int error_code, wifi_direct_discovery_state_e discovery_state, void *user_data)
+{
+ __FUNC_ENTER__;
+
+ struct appdata* ad = (struct appdata*) user_data;
+
+ switch (discovery_state) {
+ case WIFI_DIRECT_DISCOVERY_STARTED:
+ event_printf("event - WIFI_DIRECT_DISCOVERY_STARTED\n");
+ break;
+
+ case WIFI_DIRECT_ONLY_LISTEN_STARTED:
+ event_printf("event - WIFI_DIRECT_ONLY_LISTEN_STARTED\n");
+ break;
+
+ case WIFI_DIRECT_DISCOVERY_FINISHED:
+ event_printf("event - WIFI_DIRECT_DISCOVERY_FINISHED\n");
+ break;
+
+ case WIFI_DIRECT_DISCOVERY_FOUND:
+ {
+ int ret;
+ event_printf("event - WIFI_DIRECT_DISCOVERY_FOUND\n");
+
+ memset(ad->peer_list, 0x00, sizeof(wifi_direct_discovered_peer_info_s)*MAX_PEER_NUM);
+ ad->peer_count = 0;
+ ad->selected_peer_index = 0;
+
+ ret = wifi_direct_foreach_discovered_peers(_cb_discovered_peers_impl, (void*)ad);
+ printf("wifi_direct_foreach_discovered_peers() ret=[%d]\n", ret);
+ }
+ break;
+
+ case WIFI_DIRECT_DISCOVERY_LOST:
+ event_printf("event - WIFI_DIRECT_DISCOVERY_LOST\n");
+ break;
+
+ default:
+ break;
+ }
+ /* _activate_push_cb((void*)NULL, (Evas_Object*)NULL, (void*)NULL); */
+
+}
+
+void _cb_peer_found(int error_code, wifi_direct_discovery_state_e discovery_state, const char * mac_address, void *user_data)
+{
+ __FUNC_ENTER__;
+
+ switch (discovery_state) {
+ case WIFI_DIRECT_DISCOVERY_FOUND:
+ {
+ event_printf("event - WIFI_DIRECT_DISCOVERY_FOUND\n");
+
+ if (mac_address[0] != '\0') {
+ printf("Peer Address is %s", mac_address);
+ wifi_direct_discovered_peer_info_s* peer_info = NULL;
+
+ wifi_direct_get_peer_info((char *)mac_address, &peer_info);
+ if (peer_info != NULL) {
+ printf("MAC [%s] Owner=[%s] connected=[%d] SSID[%s] ctg=[%d/%d]",
+ peer_info->mac_address,
+ peer_info->is_group_owner ? "YES" : "NO",
+ peer_info->is_connected,
+ peer_info->device_name,
+ peer_info->primary_device_type,
+ peer_info->secondary_device_type
+ );
+ g_free(peer_info->mac_address);
+ g_free(peer_info->interface_address);
+ g_free(peer_info);
+ }
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+void _cb_service(int error_code,
+ wifi_direct_service_discovery_state_e discovery_state,
+ wifi_direct_service_type_e service_type,
+ void *response_data, const char * mac_address, void *user_data)
+{
+ __FUNC_ENTER__;
+
+ switch (discovery_state) {
+ case WIFI_DIRECT_SERVICE_DISCOVERY_STARTED:
+ event_printf("event - WIFI_DIRECT_SERVICE_DISCOVERY_STARTED\n");
+ break;
+
+ case WIFI_DIRECT_SERVICE_DISCOVERY_FINISHED:
+ event_printf("event - WIFI_DIRECT_SERVICE_DISCOVERY_FINISHED\n");
+ break;
+
+ case WIFI_DIRECT_SERVICE_DISCOVERY_FOUND:
+ {
+ event_printf("event - WIFI_DIRECT_SERVICE_DISCOVERY_FOUND\n");
+ if (mac_address != NULL)
+ printf("Peer Wi-Fi Direct mac address %s\n", mac_address);
+ if (response_data != NULL)
+ printf("Peer service response %s\n", (char *)response_data);
+ if (service_type == WIFI_DIRECT_SERVICE_TYPE_ALL)
+ printf("Service type = WIFI_DIRECT_SERVICE_TYPE_ALL\n");
+ else if (service_type == WIFI_DIRECT_SERVICE_TYPE_BONJOUR)
+ printf("Service type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR\n");
+ else if (service_type == WIFI_DIRECT_SERVICE_TYPE_UPNP)
+ printf("Service type = WIFI_DIRECT_SERVICE_TYPE_UPNP\n");
+ else if (service_type == WIFI_DIRECT_SERVICE_TYPE_BT_ADDR)
+ printf("Service type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR\n");
+ else if (service_type == WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO)
+ printf("service_type == WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO");
+ else
+ printf("Requested Service !!! NOT FOUND !!!\n");
+ }
+ break;
+
+ default:
+ break;
+ }
+ __FUNC_EXIT__;
+}
+
+void _cb_connection(int error_code, wifi_direct_connection_state_e connection_state, const char* mac_address, void *user_data)
+{
+ __FUNC_ENTER__;
+ char *ip_addr = NULL;
+ bool owner;
+
+ switch (connection_state) {
+
+ case WIFI_DIRECT_CONNECTION_IN_PROGRESS:
+ {
+ event_printf("event - WIFI_DIRECT_CONNECTION_IN_PROGRESS\n");
+
+ if (error_code == WIFI_DIRECT_ERROR_NONE) {
+ char _peer_mac[MACSTR_LEN+1] = {0,};
+
+ if (NULL != mac_address)
+ g_strlcpy(_peer_mac, mac_address, sizeof(_peer_mac));
+
+ printf("Connection start with [%s] \n", _peer_mac);
+ event_printf("Error None\n");
+
+ {
+ wifi_direct_discovered_peer_info_s *peer = NULL;
+ if (wifi_direct_get_connecting_peer_info(&peer)
+ == WIFI_DIRECT_ERROR_NONE) {
+ if (peer == NULL)
+ printf("No connecting peer\n");
+ else
+ printf("Connecting peer info -> device name [%s], mac address [%s]\n",
+ peer->device_name,
+ peer->mac_address);
+ } else {
+ printf("failed to get connecting peer info\n");
+ }
+ g_free(peer);
+ }
+ }
+ }
+ break;
+
+ case WIFI_DIRECT_CONNECTION_RSP:
+ {
+ event_printf("event - WIFI_DIRECT_CONNECTION_RSP\n");
+
+ if (error_code == WIFI_DIRECT_ERROR_NONE) {
+ char incomming_peer_mac[MACSTR_LEN+1] = {0,};
+ char status[100] = {0,};
+
+ if (NULL != mac_address)
+ g_strlcpy(incomming_peer_mac, mac_address, sizeof(incomming_peer_mac));
+
+ printf("Connection response with [%s] \n", incomming_peer_mac);
+ event_printf("Error None\n");
+
+ wifi_direct_is_group_owner(&owner);
+ if (owner) {
+ wifi_direct_get_ip_address(&ip_addr);
+ if (NULL != ip_addr) {
+ snprintf(status, sizeof(status), "<color=#FFFFFF>GO - IP : %s", ip_addr);
+ free(ip_addr);
+ }
+
+ } else {
+ wifi_direct_get_ip_address(&ip_addr);
+ if (NULL != ip_addr) {
+ snprintf(status, sizeof(status), "<color=#FFFFFF>STA - IP : %s", ip_addr);
+ free(ip_addr);
+ }
+ }
+ } else {
+ if (error_code == WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT)
+ event_printf("Error Code - WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT\n");
+ else if (error_code == WIFI_DIRECT_ERROR_AUTH_FAILED)
+ event_printf("Error Code - WIFI_DIRECT_ERROR_AUTH_FAILED\n");
+ else if (error_code == WIFI_DIRECT_ERROR_CONNECTION_FAILED)
+ event_printf("Error Code - WIFI_DIRECT_ERROR_CONNECTION_FAILED\n");
+ }
+
+ }
+ break;
+
+ case WIFI_DIRECT_CONNECTION_WPS_REQ:
+ {
+ event_printf("event - WIFI_DIRECT_CONNECTION_WPS_REQ\n");
+
+ wifi_direct_wps_type_e wps_mode;
+
+ int result = wifi_direct_get_local_wps_type(&wps_mode);
+ printf("wifi_direct_get_local_wps_type() result=[%d]\n", result);
+
+ /* BCMP2P_DISCOVER_ENTRY notification_data; */
+ /* memcpy(¬ification_data, pNotificationData, sizeof(notification_data)); */
+ if (wps_mode == WIFI_DIRECT_WPS_TYPE_PBC) {
+ printf("wps_config is WIFI_DIRECT_WPS_TYPE_PBC\n");
+
+ } else if (wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY) {
+ printf("wps_config is WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY\n");
+ char *pin = NULL;
+
+ result = wifi_direct_get_wps_pin(&pin);
+ printf("wifi_direct_get_wps_pin() result=[%d]\n", result);
+ if (NULL != pin) {
+ printf("WPS_PIN [%s]\n", pin);
+ free(pin);
+ } else
+ printf("WPS_PIN is NULL !! \n");
+
+ } else if (wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) {
+ printf("wps_config is WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n");
+ char pin[9] = { 0, };
+ int l_result = WIFI_DIRECT_ERROR_NONE;
+ struct appdata *ad = (struct appdata *) user_data;
+
+ memset(pin, 0x00, sizeof(pin));
+ printf("Input 8 digit PIN number :\n");
+ if (scanf(" %8s", pin) < 1)
+ break;
+
+ l_result = wifi_direct_set_wps_pin(pin);
+ if (l_result == WIFI_DIRECT_ERROR_NONE) {
+ int i;
+
+ if (NULL == ad) {
+ printf("ERROR : ad is NULL!!!\n");
+ break;
+ }
+
+ i = ad->selected_peer_index;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ l_result = wifi_direct_accept_connection(list[i].mac_address);
+ printf("wifi_direct_accept_connection() result=[%d]\n", l_result);
+ } else
+ printf("wifi_direct_set_wps_pin Error [%d]\n", l_result);
+ } else
+ printf("wps_config is unknown!\n");
+ }
+ break;
+
+ case WIFI_DIRECT_CONNECTION_REQ:
+ {
+ event_printf("event - WIFI_DIRECT_CONNECTION_REQ\n");
+ char incomming_peer_mac[MACSTR_LEN+1];
+ wifi_direct_wps_type_e wps_mode;
+ bool auto_connection_mode;
+ bool allow_connection = FALSE;
+ int result;
+
+ memset(incomming_peer_mac, 0, sizeof(incomming_peer_mac));
+
+ if (NULL != mac_address)
+ g_strlcpy(incomming_peer_mac, mac_address, sizeof(incomming_peer_mac));
+
+ printf("Connection Request from [%s] \n", incomming_peer_mac);
+
+ result = wifi_direct_get_local_wps_type(&wps_mode);
+ printf("wifi_direct_get_local_wps_type() result=[%d]\n", result);
+
+ result = wifi_direct_is_autoconnection_mode(&auto_connection_mode);
+ printf("wifi_direct_is_autoconnection_mode() result=[%d]\n", result);
+
+ if (auto_connection_mode == TRUE) {
+ result = wifi_direct_accept_connection(incomming_peer_mac);
+ printf("wifi_direct_accept_connection() result=[%d]\n", result);
+ break;
+ }
+
+ char pushbutton;
+ printf("************\n");
+ printf("Connect? (Y/N)\n");
+ printf("*************\n");
+ if (scanf(" %c", &pushbutton) < 1)
+ break;
+
+ allow_connection = (pushbutton == 'Y') || (pushbutton == 'y');
+ if (!allow_connection) {
+ result = wifi_direct_reject_connection(incomming_peer_mac);
+ printf("wifi_direct_reject_connection() result=[%d]\n", result);
+ break;
+ }
+
+ if (wps_mode == WIFI_DIRECT_WPS_TYPE_PBC) {
+ printf("wps_config is WIFI_DIRECT_WPS_TYPE_PBC\n");
+ } else if (wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY) {
+ char *pin = NULL;
+ printf("wps_config is WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY\n");
+ result = wifi_direct_get_wps_pin(&pin);
+ printf("wifi_direct_get_wps_pin() result=[%d]\n", result);
+ if (NULL != pin) {
+ printf("WPS_PIN [%s]\n\n", pin);
+ free(pin);
+ } else
+ printf("WPS_PIN is NULL !! \n");
+ } else if (wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) {
+ printf("wps_config is WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n");
+
+ char pin[9] = { 0, };
+
+ memset(pin, 0x00, sizeof(pin));
+ printf("*********************\n");
+ printf("Input 8 digit PIN number :\n");
+ printf("*********************\n");
+ if (scanf(" %8s", pin) < 1)
+ break;
+
+ if (strlen(pin) > 0) {
+ result = wifi_direct_set_wps_pin(pin);
+ printf("wifi_direct_set_wps_pin() result=[%d]\n", result);
+ } else
+ printf("Invalid PIN number\n");
+
+ } else {
+ printf("wps_config is unknown!\n");
+ break;
+ }
+ result = wifi_direct_accept_connection(incomming_peer_mac);
+ printf("wifi_direct_accept_connection() result=[%d]\n", result);
+ }
+ break;
+
+ case WIFI_DIRECT_DISCONNECTION_IND:
+ {
+ event_printf("event - WIFI_DIRECT_DISCONNECTION_IND\n");
+
+ if (error_code == WIFI_DIRECT_ERROR_NONE) {
+ char incomming_peer_mac[MACSTR_LEN+1] = {0,};
+
+ if (NULL != mac_address)
+ g_strlcpy(incomming_peer_mac, mac_address, sizeof(incomming_peer_mac));
+
+ printf("Disconnection IND from [%s] \n", incomming_peer_mac);
+
+ event_printf("Error None\n");
+ }
+
+ }
+ break;
+
+ case WIFI_DIRECT_DISCONNECTION_RSP:
+ {
+ event_printf("event - WIFI_DIRECT_DISCONNECTION_RSP\n");
+
+ if (error_code == WIFI_DIRECT_ERROR_NONE) {
+ char incomming_peer_mac[MACSTR_LEN+1] = {0,};
+
+ if (NULL != mac_address)
+ g_strlcpy(incomming_peer_mac, mac_address, sizeof(incomming_peer_mac));
+
+ printf("Disconnection RSP with [%s] \n", incomming_peer_mac);
+
+ event_printf("Error None\n");
+ }
+
+ }
+ break;
+
+ case WIFI_DIRECT_DISASSOCIATION_IND:
+ {
+ event_printf("event - WIFI_DIRECT_DISASSOCIATION_IND\n");
+
+ if (error_code == WIFI_DIRECT_ERROR_NONE) {
+ char incomming_peer_mac[MACSTR_LEN+1] = {0,};
+
+ if (NULL != mac_address)
+ g_strlcpy(incomming_peer_mac, mac_address, sizeof(incomming_peer_mac));
+
+ printf("Disassociation IND from [%s] \n", incomming_peer_mac);
+
+ event_printf("Error None\n");
+ }
+ }
+ break;
+
+ case WIFI_DIRECT_GROUP_CREATED:
+ {
+ event_printf("event - WIFI_DIRECT_GROUP_CREATED\n");
+ }
+ break;
+
+ case WIFI_DIRECT_GROUP_DESTROYED:
+ {
+ event_printf("event - WIFI_DIRECT_GROUP_DESTROYED\n");
+ }
+ break;
+
+ default:
+ break;
+
+ }
+
+ __FUNC_EXIT__;
+}
+
+
+void _cb_ip_assigned(const char* mac_address, const char* ip_address, const char* interface_address, void *user_data)
+{
+ __FUNC_ENTER__;
+
+ if (NULL != mac_address)
+ printf("mac_address [%s] \n", mac_address);
+ else
+ printf("mac_address is NULL !!\n");
+
+ if (NULL != ip_address)
+ printf("ip_address [%s] \n", ip_address);
+ else
+ printf("ip_address is NULL !!\n");
+
+ if (NULL != interface_address)
+ printf("interface_address [%s] \n", interface_address);
+ else
+ printf("interface_address is NULL !!\n");
+
+ __FUNC_EXIT__;
+
+}
+
+bool _cb_foreach_supported_wps_impl(wifi_direct_wps_type_e type, void* user_data)
+{
+ __FUNC_ENTER__;
+
+ switch (type) {
+ case WIFI_DIRECT_WPS_TYPE_PBC:
+ printf("type=[WIFI_DIRECT_WPS_TYPE_PBC]\n");
+ break;
+ case WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY:
+ printf("type=[WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY]\n");
+ break;
+ case WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD:
+ printf("type=[WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD]\n");
+ break;
+ default:
+ printf("ERROR : type=[%d]\n", type);
+ break;
+ }
+
+ return true; /* continue with the next iteration of the loop */
+}
+
+void _cb_state_changed(wifi_direct_state_e state,
+ void *user_data)
+{
+ printf("State Changed [%s]\n", print_link_state(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;
+
+ ret = wifi_direct_initialize();
+ printf("wifi_direct_initialize() result=[%d]\n", ret);
+
+ ret = wifi_direct_set_device_state_changed_cb(_cb_activation, (void*)ad);
+ printf("wifi_direct_set_device_state_changed_cb() result=[%d]\n", ret);
+
+ ret = wifi_direct_set_discovery_state_changed_cb(_cb_discover, (void*)ad);
+ printf("wifi_direct_set_discovery_state_changed_cb() result=[%d]\n", ret);
+
+ ret = wifi_direct_set_connection_state_changed_cb(_cb_connection, (void*)ad);
+ printf("wifi_direct_set_connection_state_changed_cb() result=[%d]\n", ret);
+
+ ret = wifi_direct_set_client_ip_address_assigned_cb(_cb_ip_assigned, (void*)ad);
+ printf("wifi_direct_set_client_ip_address_assigned_cb() result=[%d]\n", ret);
+
+ ret = wifi_direct_set_service_state_changed_cb(_cb_service, (void*)ad);
+ printf("wifi_direct_set_service_state_changed_cb() result=[%d]\n", ret);
+
+ ret = wifi_direct_set_peer_found_cb(_cb_peer_found, (void*)ad);
+ printf("wifi_direct_set_peer_found_cb() result=[%d]\n", ret);
+
+ 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;
+}
+
+void process_input(const char *input, gpointer user_data)
+{
+ struct appdata *ad = (struct appdata *) user_data;
+ int result = -1;
+ int cmd = strtol(input, NULL, 0);
+
+ if (is_digit(input) < 0 || strlen(input) == 0 || errno == ERANGE || errno
+ == EINVAL)
+ cmd = CMD_INVALID;
+
+ printf("cmd=[%d]\n", cmd);
+
+ switch (cmd) {
+ case CMD_INITIALIZE:
+ {
+ result = init_wfd_client(ad);
+ printf("init_wfd_client() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_SET_ACTIVATION_CB:
+ {
+ result = wifi_direct_set_device_state_changed_cb(_cb_activation, (void*)ad);
+ printf("wifi_direct_set_device_state_changed_cb() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_UNSET_ACTIVATION_CB:
+ {
+ result = wifi_direct_unset_device_state_changed_cb();
+ printf("wifi_direct_unset_device_state_changed_cb() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_SET_DISCOVER_CB:
+ {
+ result = wifi_direct_set_discovery_state_changed_cb(_cb_discover, (void*)ad);
+ printf("wifi_direct_set_discovery_state_changed_cb() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_UNSET_DISCOVER_CB:
+ {
+ result = wifi_direct_unset_discovery_state_changed_cb();
+ printf("wifi_direct_unset_discovery_state_changed_cb() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_SET_CONNECTION_CB:
+ {
+ result = wifi_direct_set_connection_state_changed_cb(_cb_connection, (void*)ad);
+ printf("wifi_direct_set_connection_state_changed_cb() result=[%d]\n", result);
+
+ 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;
+
+ case CMD_UNSET_CONNECTION_CB:
+ {
+ result = wifi_direct_unset_connection_state_changed_cb();
+ printf("wifi_direct_unset_connection_state_changed_cb() result=[%d]\n", result);
+
+ 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;
+
+ case CMD_SET_IP_ADDR_ASSIGNED_CB:
+ {
+ result = wifi_direct_set_client_ip_address_assigned_cb(_cb_ip_assigned, (void*)ad);
+ printf("wifi_direct_set_client_ip_address_assigned_cb() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_UNSET_IP_ADDR_ASSIGNED_CB:
+ {
+ result = wifi_direct_unset_client_ip_address_assigned_cb();
+ printf("wifi_direct_unset_client_ip_address_assigned_cb() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_SET_SERVICE_CB:
+ {
+ result = wifi_direct_set_service_state_changed_cb(_cb_service, (void*)ad);
+ printf("wifi_direct_set_service_state_changed_cb() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_UNSET_SERVICE_CB:
+ {
+ result = wifi_direct_unset_service_state_changed_cb();
+ printf("wifi_direct_unset_service_changed_cb() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_SET_PEER_FOUND_CB:
+ {
+ result = wifi_direct_set_peer_found_cb(_cb_peer_found, (void*)ad);
+ printf("wifi_direct_set_peer_found_cb() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_UNSET_PEER_FOUND_CB:
+ {
+ result = wifi_direct_unset_peer_found_cb();
+ printf("wifi_direct_unset_peer_found_cb() result=[%d]\n", result);
+ }
+ break;
+ case CMD_SET_STATE_CB:
+ {
+ result = wifi_direct_set_state_changed_cb(_cb_state_changed, (void*)ad);
+ printf("wifi_direct_set_state_changed_cb() result=[%d]\n", result);
+ }
+ break;
+ case CMD_UNSET_STATE_CB:
+ {
+ result = wifi_direct_unset_state_changed_cb();
+ printf("wifi_direct_unset_state_changed_cb() result=[%d]\n", result);
+ }
+ break;
+ case CMD_DEINITIALIZE:
+ result = wifi_direct_deinitialize();
+ printf("wifi_direct_deinitialize() result=[%d]\n", result);
+ break;
+ case CMD_ACTIVATE_WIFI_DIRECT:
+ if (ad != NULL) {
+ result = wifi_direct_activate();
+ printf("wifi_direct_activate() result=[%d]\n", result);
+
+ if (result == WIFI_DIRECT_ERROR_WIFI_USED)
+ printf(" ERROR : WIFI_DIRECT_ERROR_WIFI_USED \n");
+ else if (result == WIFI_DIRECT_ERROR_MOBILE_AP_USED)
+ printf(" ERROR : WIFI_DIRECT_ERROR_MOBILE_AP_USED \n");
+
+ }
+ break;
+
+ case CMD_DEACTIVATE_WIFI_DIRECT:
+ if (ad != NULL) {
+ result = wifi_direct_deactivate();
+ printf("wifi_direct_deactivate() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_START_DISCOVER_WITH_LISTEN_ONLY:
+ if (ad != NULL) {
+ result = wifi_direct_start_discovery(TRUE, 15);
+ printf("wifi_direct_start_discovery() listen_only=[true] result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_START_DISCOVER:
+ if (ad != NULL) {
+ /* result = wifi_direct_start_discovery(FALSE, 15); */
+ result = wifi_direct_start_discovery(FALSE, 0);
+ printf("wifi_direct_start_discovery() listen_only=[false] result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_START_DISCOVER_SPECIFIC_CHANNEL:
+ if (ad != NULL) {
+ int input_discovery_channel;
+ printf("Select Discovery Channel :\n");
+ printf("1. WIFI_DIRECT_DISCOVERY_FULL_SCAN\n");
+ printf("2. WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL\n");
+ printf("3. WIFI_DIRECT_DISCOVERY_CHANNEL1\n");
+ printf("4. WIFI_DIRECT_DISCOVERY_CHANNEL6\n");
+ printf("5. WIFI_DIRECT_DISCOVERY_CHANNEL11\n");
+ if (scanf(" %1d", &input_discovery_channel) < 1)
+ break;
+
+ switch (input_discovery_channel) {
+ case 1:
+ {
+ result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_FULL_SCAN);
+ printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_FULL_SCAN, result);
+ }
+ break;
+ case 2:
+ {
+ result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL);
+ printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL, result);
+ }
+ break;
+ case 3:
+ {
+ result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_CHANNEL1);
+ printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_CHANNEL1, result);
+ }
+ break;
+ case 4:
+ {
+ result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_CHANNEL6);
+ printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_CHANNEL6, result);
+ }
+ break;
+ case 5:
+ {
+ result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_CHANNEL11);
+ printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_CHANNEL11, result);
+ }
+ break;
+ default:
+ printf("ERROR : Invalid Channel !!!\n");
+ break;
+ }
+
+ }
+ break;
+
+ case CMD_START_DISCOVER_SPECIFIC_FREQUENCY:
+ if (ad != NULL) {
+ int frequency;
+ printf("Enter discover frequency :\n");
+ if (scanf(" %5d", &frequency) < 1)
+ break;
+
+ result = wifi_direct_start_discovery_specific_freq(FALSE, 2, frequency);
+ printf("wifi_direct_start_discovery_specific_freq() frequency=[%d] result=[%d]\n", frequency, result);
+ }
+ break;
+
+ case CMD_CANCEL_DISCOVER:
+ if (ad != NULL) {
+ result = wifi_direct_cancel_discovery();
+ printf("wifi_direct_cancel_discovery() result=[%d]\n", result);
+ }
+ break;
+ case CMD_GET_DISVOCERY_RESULT:
+ if (ad != NULL) {
+ memset(ad->peer_list, 0x00, sizeof(wifi_direct_discovered_peer_info_s)*MAX_PEER_NUM);
+ ad->peer_count = 0;
+ ad->selected_peer_index = 0;
+
+ result = wifi_direct_foreach_discovered_peers(_cb_discovered_peers_impl, (void*)ad);
+ printf("wifi_direct_foreach_discovered_peers() ret=[%d]\n", result);
+
+ print_peers(ad);
+ }
+ break;
+
+ case CMD_SEND_CONNECTION_REQ:
+ if (ad != NULL) {
+ if (select_peer(ad)) {
+ int i = ad->selected_peer_index;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_accept_connection(list[i].mac_address);
+
+ printf("Connecting... peer-index[%d] MAC [%s] Owner=[%s] SSID[%s]\n",
+ i,
+ list[i].mac_address,
+ list[i].is_group_owner ? "YES" : "NO",
+ list[i].device_name);
+
+ printf("wifi_direct_accept_connection() result=[%d]\n", result);
+ }
+ }
+ break;
+
+ case CMD_DISCONNECT_ALL:
+ if (ad != NULL) {
+ result = wifi_direct_disconnect_all();
+ printf("wifi_direct_disconnect_all() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_DISCONNECT:
+ if (ad != NULL) {
+ if (select_connected_peer(ad)) {
+ int i = ad->selected_peer_index;
+ wifi_direct_connected_peer_info_s* list = ad->connected_peer_list;
+
+ result = wifi_direct_disconnect(list[i].mac_address);
+
+ printf("Disconnecting... peer-index[%d] MAC [%s] SSID[%s]\n",
+ i,
+ list[i].mac_address,
+ list[i].device_name);
+
+ printf("wifi_direct_disconnect() result=[%d]\n", result);
+ }
+ }
+ break;
+
+
+ case CMD_GET_LINK_STATUS:
+ if (ad != NULL) {
+ wifi_direct_state_e status = 0;
+ result = wifi_direct_get_state(&status);
+ printf("wifi_direct_get_state() state=[%s(%d)], result=[%d]\n", print_link_state(status), status, result);
+ }
+ break;
+
+ case CMD_CONNECT_PEER:
+ if (ad != NULL) {
+ if (select_peer(ad)) {
+ wifi_direct_wps_type_e wps_mode;
+
+ result = wifi_direct_get_local_wps_type(&wps_mode);
+ printf("wifi_direct_get_local_wps_type() result=[%d]\n", result);
+
+ if (wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD)
+ printf("wifi_direct_generate_wps_pin() result=[%d]\n", result);
+
+ int i = ad->selected_peer_index;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_connect(list[i].mac_address);
+
+ printf("Connecting... peer-index[%d] MAC [%s] Owner=[%s] SSID[%s]\n",
+ i,
+ list[i].mac_address,
+ list[i].is_group_owner ? "YES" : "NO",
+ list[i].device_name);
+
+ printf("wifi_direct_connect() result=[%d]\n", result);
+
+ }
+ }
+ break;
+
+ case CMD_CANCEL_CONNECTION:
+ if (ad != NULL) {
+ if (select_peer(ad)) {
+ int i = ad->selected_peer_index;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_cancel_connection(list[i].mac_address);
+ printf("wifi_direct_cancel_connection() result=[%d]\n", result);
+ }
+ }
+ break;
+
+ case CMD_ENABLE_PUSH_BUTTON:
+ if (ad != NULL) {
+ result = wifi_direct_activate_pushbutton();
+ printf("wifi_direct_activate_pushbutton() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_CREATE_GROUP:
+ if (ad != NULL) {
+ result = wifi_direct_create_group();
+ printf("wifi_direct_create_group() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_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();
+ printf("wifi_direct_destroy_group() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_IS_GROUP_OWNER:
+ if (ad != NULL) {
+ bool is_group_owner;
+ result = wifi_direct_is_group_owner(&is_group_owner);
+ printf("wifi_direct_is_group_owner() is GO[%d] result=[%d]\n", is_group_owner, result);
+ }
+ break;
+ case CMD_REJECT:
+ if (ad != NULL) {
+ /* result = wifi_direct_client_reject(); */
+ printf("Under construction...\n");
+ }
+ break;
+
+ case CMD_INVITE:
+ if (ad != NULL) {
+ /* result = wifi_direct_client_invite(); */
+ printf("Under construction...\n");
+ }
+ break;
+
+ case CMD_SET_DEVICE_NAME:
+ {
+ if (ad != NULL) {
+ char *device_name = NULL;
+
+ printf("Input device name :\n");
+ if (scanf(" %33ms", &device_name) < 1)
+ break;
+
+ if (strlen(device_name) <= 0)
+ printf("invalid device name !!\n");
+ else
+ printf("device_name: [%s]\n", device_name);
+
+ if ((strlen(device_name) > 0)) {
+ result = wifi_direct_set_device_name(device_name);
+ printf("wifi_direct_set_device_name() ret=[%d]\n", result);
+ }
+
+ free(device_name);
+ }
+ }
+ break;
+
+ case CMD_GET_DEVICE_NAME:
+ {
+ if (ad != NULL) {
+ char* device_name = NULL;
+
+ result = wifi_direct_get_device_name(&device_name);
+ printf("wifi_direct_get_device_name() result=[%d]\n", result);
+
+ if (NULL != device_name) {
+ printf("ssid: [%s]\n", device_name);
+ free(device_name);
+ }
+
+ }
+ }
+ break;
+
+ case CMD_GET_SSID:
+ {
+ if (ad != NULL) {
+ char* ssid = NULL;
+
+ result = wifi_direct_get_ssid(&ssid);
+ printf("wifi_direct_get_ssid() result=[%d]\n", result);
+
+ if (NULL != ssid) {
+ printf("ssid: [%s]\n", ssid);
+ free(ssid);
+ }
+
+ }
+ }
+ break;
+
+ case CMD_SET_CHANNEL:
+ case CMD_SET_WPS_CONFIG:
+ break;
+
+ case CMD_SET_MAX_CLIENT:
+ if (ad != NULL) {
+ int max_client;
+
+ wifi_direct_get_max_clients(&max_client);
+ printf("Current max client=[%d]\n", max_client);
+ printf("Input new max client:\n");
+
+ if (scanf(" %4d", &max_client))
+ break;
+
+ result = wifi_direct_set_max_clients(max_client);
+
+ printf("wifi_direct_set_max_clients() result=[%d] max_client[%d]\n", result, max_client);
+ }
+ break;
+
+ case CMD_GET_MAX_CLIENT:
+ if (ad != NULL) {
+ int max_client;
+
+ result = wifi_direct_get_max_clients(&max_client);
+ printf("wifi_direct_get_max_clients() result=[%d] max_client[%d]\n", result, max_client);
+ }
+ break;
+
+ case CMD_SET_HIDE_SSID:
+ break;
+
+ case CMD_ACTIVATE_PERSISTENT_GROUP:
+ if (ad != NULL) {
+ result = wifi_direct_set_persistent_group_enabled(true);
+
+ if (result != WIFI_DIRECT_ERROR_NONE)
+ printf("Failed to wifi_direct_set_persistent_group_enabled() result=[%d]\n", result);
+ else
+ printf("wifi_direct_set_persistent_group_enabled() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_DEACTIVATE_PERSISTENT_GROUP:
+ if (ad != NULL) {
+ result = wifi_direct_set_persistent_group_enabled(false);
+
+ if (result != WIFI_DIRECT_ERROR_NONE)
+ printf("Failed to wifi_direct_set_persistent_group_enabled() result=[%d]\n", result);
+ else
+ printf("wifi_direct_set_persistent_group_enabled() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_IS_PERSISTENT_GROUP_ACTIVATED:
+ if (ad != NULL) {
+ bool enabled;
+
+ result = wifi_direct_is_persistent_group_enabled(&enabled);
+ printf("wifi_direct_is_persistent_group_enabled() result=[%d]\n", result);
+ if (enabled == TRUE)
+ printf("Persistent Group mode!! \n");
+ else
+ printf("NOT Persistent group mode!! \n");
+ }
+ break;
+
+
+ case CMD_GET_PERSISTENT_GROUP_LIST:
+ if (ad != NULL) {
+ result = wifi_direct_foreach_persistent_groups(_cb_persistent_groups_impl, (void*)ad);
+ printf("wifi_direct_foreach_persistent_groups() ret=[%d]\n", result);
+ }
+ break;
+
+ case CMD_REMOVE_PERSISTENT_GROUP:
+ if (ad != NULL) {
+ char *mac = NULL;
+ char *ssid = NULL;
+
+ printf("Input GO MAC :\n");
+ if (scanf(" %18ms", &mac) < 1)
+ break;
+
+ if (strlen(mac) <= 0)
+ printf("invalid GO MAC !!\n");
+ else
+ printf("GO MAC: [%s]\n", mac);
+
+ printf("Input ssid :\n");
+ if (scanf(" %33ms", &ssid) < 1) {
+ free(mac);
+ break;
+ }
+
+ if (strlen(ssid) <= 0)
+ printf("invalid ssid !!\n");
+ else
+ printf("ssid: [%s]\n", ssid);
+
+ if ((strlen(mac) > 0) && (strlen(ssid) > 0)) {
+ result = wifi_direct_remove_persistent_group(mac, ssid);
+ printf("wifi_direct_remove_persistent_group() ret=[%d]\n", result);
+ }
+
+ free(mac);
+ free(ssid);
+ }
+ break;
+
+ case CMD_SET_AUTO_CONNECTION:
+ if (ad != NULL) {
+ int autoconnection_mode;
+
+ printf("Input Auto connection: \n");
+ printf("[1] true [2] false\n");
+
+ if (scanf(" %1d", &autoconnection_mode) < 1)
+ break;
+
+ if (autoconnection_mode == 1)
+ result = wifi_direct_set_autoconnection_mode(true);
+ else if (autoconnection_mode == 2)
+ result = wifi_direct_set_autoconnection_mode(false);
+ else
+ printf("Invalid input parameter!!!\n");
+
+ printf("wifi_direct_set_autoconnection_mode() result=[%d] \n", result);
+
+ }
+ break;
+
+ case CMD_IS_AUTO_CONNECTION:
+ if (ad != NULL) {
+ bool auto_connection = false;
+
+ result = wifi_direct_is_autoconnection_mode(&auto_connection);
+ printf("wifi_direct_is_autoconnection_mode() result=[%d]\n", result);
+ if (auto_connection == TRUE)
+ printf("Auto connection mode !! \n");
+ else
+ printf("NOT Auto connection mode !! \n");
+
+ }
+ break;
+
+ case CMD_SET_WPS_PIN:
+ if (ad != NULL) {
+ char *pin = NULL;
+
+ printf("Input PIN number :\n");
+ if (scanf(" %9ms", &pin) < 1)
+ break;
+
+ printf("New PIN: [%s]\n", pin);
+
+ if ((strlen(pin) > 0) && (strlen(pin) < 9))
+ wifi_direct_set_wps_pin(pin);
+ else
+ printf("Invalid PIN number\n");
+
+ free(pin);
+ }
+ break;
+
+ case CMD_GET_WPS_PIN:
+ if (ad != NULL) {
+ char *pin = NULL;
+
+ result = wifi_direct_get_wps_pin(&pin);
+ printf("wifi_direct_get_wps_pin() result=[%d]\n", result);
+ if (NULL != pin) {
+ printf("WPS_PIN [%s]\n", pin);
+ free(pin);
+ } else
+ printf("WPS_PIN is NULL !! \n");
+ }
+ break;
+
+ case CMD_GET_SUPPORTED_WPS_MODE:
+ if (ad != NULL) {
+ int supported_wps_mode = 0;
+
+ result = wifi_direct_foreach_supported_wps_types(_cb_foreach_supported_wps_impl, NULL);
+ printf("wifi_direct_foreach_supported_wps_types() result=[%d]\n", result);
+
+ result = wifi_direct_get_supported_wps_mode(&supported_wps_mode);
+ printf("wifi_direct_foreach_supported_wps_types() supported=[%d] result=[%d]\n", supported_wps_mode, result);
+ }
+ break;
+
+ case CMD_SET_CURRENT_WPS_MODE:
+ if (ad != NULL) {
+ wifi_direct_wps_type_e wps_mode;
+ int input_wps_mode;
+
+ result = wifi_direct_get_req_wps_type(&wps_mode);
+ switch (wps_mode) {
+ case WIFI_DIRECT_WPS_TYPE_PBC:
+ printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PBC]\n");
+ break;
+ case WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY:
+ printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY]\n");
+ break;
+ case WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD:
+ printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD]\n");
+ break;
+ default:
+ printf("ERROR : wps_mode=[%d]\n", wps_mode);
+ break;
+ }
+
+ printf("Input new wps mode:\n");
+ printf("1. WIFI_DIRECT_WPS_TYPE_PBC\n");
+ printf("2. WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY\n");
+ printf("3. WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n");
+ if (scanf(" %1d", &input_wps_mode) < 1)
+ break;
+
+ switch (input_wps_mode) {
+ case 1:
+ wps_mode = WIFI_DIRECT_WPS_TYPE_PBC;
+ break;
+ case 2:
+ wps_mode = WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY;
+ break;
+ case 3:
+ wps_mode = WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD;
+ break;
+ default:
+ printf("ERROR : Invalid input wps_mode!!!\n");
+ break;
+ }
+
+ result = wifi_direct_set_req_wps_type(wps_mode);
+ printf("wifi_direct_set_wps_type() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_GET_CURRENT_WPS_MODE:
+ if (ad != NULL) {
+ wifi_direct_wps_type_e wps_mode;
+ result = wifi_direct_get_req_wps_type(&wps_mode);
+ printf("wifi_direct_get_wps_type() wps_mode=[%d], result=[%d]\n", wps_mode, result);
+ switch (wps_mode) {
+ case WIFI_DIRECT_WPS_TYPE_PBC:
+ printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PBC]\n");
+ break;
+ case WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY:
+ printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY]\n");
+ break;
+ case WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD:
+ printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD]\n");
+ break;
+ default:
+ printf("ERROR : wps_mode=[%d]\n", wps_mode);
+ break;
+ }
+
+ }
+ break;
+
+ case CMD_GET_CONNECTED_PEERS_INFO:
+ if (ad != NULL) {
+ memset(ad->connected_peer_list, 0x00, sizeof(wifi_direct_connected_peer_info_s)*MAX_PEER_NUM);
+ ad->connected_peer_count = 0;
+
+ result = wifi_direct_foreach_connected_peers(_cb_connected_peers_impl, (void*)ad);
+ printf("wifi_direct_foreach_connected_peers() ret=[%d]\n", result);
+ print_peers_connected(ad);
+ }
+ break;
+
+ case CMD_GET_GO_INTENT:
+ if (ad != NULL) {
+ int go_intent;
+
+ result = wifi_direct_get_group_owner_intent(&go_intent);
+ printf("wifi_direct_get_group_owner_intent() result=[%d] go_intent[%d]\n", result, go_intent);
+ }
+ break;
+
+ case CMD_SET_GO_INTENT:
+ if (ad != NULL) {
+ int go_intent;
+
+ wifi_direct_get_group_owner_intent(&go_intent);
+ printf("Current GO intent=[%d]\n", go_intent);
+ printf("Input new GO intent [0~15]:\n");
+
+ if (scanf(" %2d", &go_intent) < 1)
+ break;
+
+ result = wifi_direct_set_group_owner_intent(go_intent);
+
+ printf("wifi_direct_set_group_owner_intent() result=[%d] go_intent[%d]\n", result, go_intent);
+ }
+ break;
+
+ case CMD_GET_DEVICE_MAC:
+ if (ad != NULL) {
+ char *device_mac = NULL;
+
+ result = wifi_direct_get_mac_address(&device_mac);
+ printf("wifi_direct_get_mac_addr() result=[%d]\n", result);
+ if (NULL != device_mac) {
+ printf("MAC [%s] \n", device_mac);
+ free(device_mac);
+ } else
+ printf("device_mac is NULL !! \n");
+ }
+ break;
+
+ case CMD_IS_AUTONOMOUS_GROUP:
+ if (ad != NULL) {
+ bool autonomous_group;
+
+ result = wifi_direct_is_autonomous_group(&autonomous_group);
+ printf("wifi_direct_is_autonomous_group() result=[%d]\n", result);
+ if (autonomous_group == TRUE)
+ printf("Autonomous Group !! \n");
+ else
+ printf("NOT Autonomous group !! \n");
+
+ }
+ break;
+
+ case CMD_GET_NETWORK_IF_NAME:
+ if (ad != NULL) {
+ char* name = NULL;
+
+ result = wifi_direct_get_network_interface_name(&name);
+ printf("wifi_direct_get_network_interface_name() result=[%d]\n", result);
+
+ if (NULL != name) {
+ printf("name: [%s]\n", name);
+ free(name);
+ }
+
+ }
+ break;
+
+ case CMD_GET_SUBNET_MASK:
+ if (ad != NULL) {
+ char* subnet_mask = NULL;
+
+ result = wifi_direct_get_subnet_mask(&subnet_mask);
+ printf("wifi_direct_get_subnet_mask() result=[%d]\n", result);
+
+ if (NULL != subnet_mask) {
+ printf("subnet_mask: [%s]\n", subnet_mask);
+ free(subnet_mask);
+ }
+
+ }
+ break;
+
+
+ case CMD_GET_GATEWAY_ADDR:
+ if (ad != NULL) {
+ char* gateway_address = NULL;
+
+ result = wifi_direct_get_gateway_address(&gateway_address);
+ printf("wifi_direct_get_gateway_address() result=[%d]\n", result);
+
+ if (NULL != gateway_address) {
+ printf("gateway_address: [%s]\n", gateway_address);
+ free(gateway_address);
+ }
+
+ }
+ break;
+
+ case CMD_IS_DISCOVERABLE:
+ if (ad != NULL) {
+ bool discoverable = false;
+
+ result = wifi_direct_is_discoverable(&discoverable);
+ printf("wifi_direct_is_discoverable() result=[%d]\n", result);
+ if (discoverable == TRUE)
+ printf("Discoverable state !! \n");
+ else
+ printf("NOT Discoverable state !! \n");
+
+ }
+ break;
+
+ case CMD_IS_LISTEN_ONLY:
+ if (ad != NULL) {
+ bool listen_only = false;
+
+ result = wifi_direct_is_listening_only(&listen_only);
+ printf("wifi_direct_is_listening_only() result=[%d]\n", result);
+ if (listen_only == TRUE)
+ printf("Listen only state !! \n");
+ else
+ printf("NOT Listen only state !! \n");
+
+ }
+ break;
+
+ case CMD_GET_PRIMARY_DEVICE_TYPE:
+ if (ad != NULL) {
+ wifi_direct_primary_device_type_e type;
+
+ result = wifi_direct_get_primary_device_type(&type);
+
+ printf("wifi_direct_get_primary_device_type() result=[%d]\n", result);
+ printf("Primary Device TYPE [%d]\n", type);
+
+ }
+ break;
+
+ case CMD_GET_SECONDARY_DEVICE_TYPE:
+ if (ad != NULL) {
+ wifi_direct_secondary_device_type_e type;
+
+ result = wifi_direct_get_secondary_device_type(&type);
+
+ printf("wifi_direct_get_secondary_device_type() result=[%d]\n", result);
+ printf("Secondary Device TYPE [%d]\n", type);
+ }
+ break;
+
+ case CMD_GET_OPERATING_CHANNEL:
+ if (ad != NULL) {
+ int operating_channel;
+
+ result = wifi_direct_get_operating_channel(&operating_channel);
+
+ printf("wifi_direct_get_own_group_channel() result=[%d]\n", result);
+ printf("Operating Channel [%d]\n", operating_channel);
+
+ }
+ break;
+
+ case CMD_GET_IP_ADDR:
+ {
+ if (ad != NULL) {
+ char* ip_addr = NULL;
+
+ result = wifi_direct_get_ip_address(&ip_addr);
+ printf("wifi_direct_get_ip_address() result=[%d]\n", result);
+ if (NULL != ip_addr) {
+ printf("IP [%s]\n", ip_addr);
+ free(ip_addr);
+ } else {
+ printf("IP is NULL\n");
+ }
+ }
+ }
+ break;
+ case CMD_REGISTER_SERVICE:
+ if (ad != NULL) {
+ wifi_direct_service_type_e service_type = WIFI_DIRECT_SERVICE_TYPE_ALL;
+ unsigned int input_service_type;
+ unsigned int registered_service_id;
+ char *info1 = NULL;
+ char *info2 = NULL;
+ char *str = NULL;
+
+ printf("Input service type:\n");
+ printf("1. WIFI_DIRECT_SERVICE_TYPE_ALL\n");
+ printf("2. WIFI_DIRECT_SERVICE_TYPE_BONJOUR\n");
+ printf("3. WIFI_DIRECT_SERVICE_TYPE_UPNP\n");
+ printf("4. WIFI_DIRECT_SERVICE_TYPE_BT_ADDR\n");
+ printf("5. WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO\n");
+ if (scanf(" %1u", &input_service_type) < 1)
+ break;
+ printf("input = %u\n", input_service_type);
+
+ switch (input_service_type) {
+ case 1:
+ service_type = WIFI_DIRECT_SERVICE_TYPE_ALL;
+ break;
+ case 2:
+ service_type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR;
+ printf("Enter info 1\n");
+ if (scanf(" %50ms", &info1) < 1)
+ break;
+
+ printf("Enter info 2\n");
+ if (scanf(" %50ms", &info2) < 1) {
+ free(info1);
+ info1 = NULL;
+ }
+
+ break;
+ case 3:
+ service_type = WIFI_DIRECT_SERVICE_TYPE_UPNP;
+ printf("Enter info 1\n");
+ if (scanf(" %50ms", &info1) < 1)
+ break;
+
+ printf("Enter info 2\n");
+ if (scanf(" %50ms", &info2) < 1) {
+ free(info1);
+ info1 = NULL;
+ }
+
+ break;
+ case 4:
+ service_type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR;
+ break;
+ case 5:
+ service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO;
+ printf("Enter contact info\n");
+ if (scanf(" %50ms", &str) < 1)
+ break;
+ info1 = str;
+ break;
+ default:
+ printf("ERROR : Invalid input service_type!!!\n");
+ break;
+ }
+
+ result = wifi_direct_register_service(service_type, info1, info2,
+ ®istered_service_id);
+ printf("wifi_direct_register_service() service id=[%u] result=[%d]\n",
+ registered_service_id, result);
+ if (info1)
+ free(info1);
+ free(info2);
+ }
+ break;
+
+ case CMD_DEREGISTER_SERVICE:
+ if (ad != NULL) {
+ int input_service_id;
+
+ printf("Enter service id:\n");
+ if (scanf(" %5d", &input_service_id) < 1)
+ break;
+
+
+ result = wifi_direct_deregister_service(input_service_id);
+ printf("wifi_direct_deregister_service() result=[%d]\n", result);
+ }
+ break;
+ case CMD_START_SERVICE_DISCOVERY:
+ if (ad != NULL) {
+ int input_service_discovery;
+ wifi_direct_service_type_e service_type = WIFI_DIRECT_SERVICE_TYPE_ALL;
+
+ printf("Input service type:\n");
+ printf("1. WIFI_DIRECT_SERVICE_TYPE_ALL\n");
+ printf("2. WIFI_DIRECT_SERVICE_TYPE_BONJOUR\n");
+ printf("3. WIFI_DIRECT_SERVICE_TYPE_UPNP\n");
+ printf("4. WIFI_DIRECT_SERVICE_TYPE_BT_ADDR\n");
+ printf("5. WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO\n");
+ if (scanf(" %1d", &input_service_discovery) < 1)
+ break;
+ printf("input = %d\n", input_service_discovery);
+
+ switch (input_service_discovery) {
+ case 1:
+ service_type = WIFI_DIRECT_SERVICE_TYPE_ALL;
+ break;
+ case 2:
+ service_type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR;
+ break;
+ case 3:
+ service_type = WIFI_DIRECT_SERVICE_TYPE_UPNP;
+ break;
+ case 4:
+ service_type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR;
+ break;
+ case 5:
+ service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO;
+ break;
+ default:
+ printf("ERROR : Invalid input service_type!!!\n");
+ break;
+ }
+
+ if (select_peer(ad)) {
+
+ result = wifi_direct_start_service_discovery(
+ NULL, service_type);
+
+ printf("Service Discovery... broadcast service type[%d]\n",
+ service_type);
+ } else {
+ int i = ad->selected_peer_index;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_start_service_discovery(
+ list[i].mac_address, service_type);
+
+ printf("Service Discovery... peer-index[%d] MAC [%s] service type[%d]\n",
+ i, list[i].mac_address, service_type);
+ }
+
+ printf("wifi_direct_start_service_discovery() result=[%d]\n", result);
+
+ }
+ break;
+
+ case CMD_CANCEL_SERVICE_DISCOVERY:
+ if (ad != NULL) {
+ int input_service_discovery;
+ wifi_direct_service_type_e service_type = WIFI_DIRECT_SERVICE_TYPE_ALL;
+
+ printf("Input service ID:\n");
+
+ if (scanf(" %1d", &input_service_discovery) < 1)
+ break;
+ printf("input = %d\n", input_service_discovery);
+
+ switch (input_service_discovery) {
+ case 1:
+ service_type = WIFI_DIRECT_SERVICE_TYPE_ALL;
+ break;
+ case 2:
+ service_type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR;
+ break;
+ case 3:
+ service_type = WIFI_DIRECT_SERVICE_TYPE_UPNP;
+ break;
+ case 4:
+ service_type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR;
+ break;
+ case 5:
+ service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO;
+ break;
+ default:
+ printf("ERROR : Invalid input service_type!!!\n");
+ break;
+ }
+
+ if (select_peer(ad)) {
+ result = wifi_direct_cancel_service_discovery(
+ NULL, service_type);
+
+ printf("Service Discovery... broadcast service type[%d]\n",
+ service_type);
+ } else {
+ int i = ad->selected_peer_index;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_cancel_service_discovery(
+ list[i].mac_address, service_type);
+
+ printf("Service Discovery... peer-index[%d] MAC [%s] service type[%d]\n",
+ i, list[i].mac_address, service_type);
+ }
+ printf("wifi_direct_cancel_service_discovery() result=[%d]\n", result);
+ }
+ break;
+
+ case CMD_INIT_MIRACAST:
+ if (ad != NULL) {
+ int miracast_enable;
+
+ printf("Input miracast enable: \n");
+ printf("[1] true [2] false\n");
+
+ if (scanf(" %1d", &miracast_enable) < 1)
+ break;
+
+ if (miracast_enable == 1)
+ result = wifi_direct_init_miracast(true);
+ else if (miracast_enable == 2)
+ result = wifi_direct_init_miracast(false);
+ else
+ printf("Invalid input parameter!!!\n");
+
+ printf("wifi_direct_init_miracast() result=[%d] \n", result);
+
+ }
+ break;
+
+ case CMD_GET_PEER_INFO:
+ if (ad != NULL)
+ if (select_peer(ad)) {
+ int i = ad->selected_peer_index;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+ wifi_direct_discovered_peer_info_s* peer_info = NULL;
+
+ result = wifi_direct_get_peer_info(list[i].mac_address, &peer_info);
+ if (peer_info != NULL) {
+ printf("MAC [%s] Owner=[%s] connected=[%d] SSID[%s] ctg=[%d/%d]",
+ peer_info->mac_address,
+ peer_info->is_group_owner ? "YES" : "NO",
+ peer_info->is_connected,
+ peer_info->device_name,
+ peer_info->primary_device_type,
+ peer_info->secondary_device_type
+ );
+ g_free(peer_info->mac_address);
+ g_free(peer_info->interface_address);
+ g_free(peer_info);
+ }
+
+ printf("wifi_direct_get_peer() result=[%d]\n", result);
+ }
+ break;
+ case CMD_SET_PASSPHRASE:
+ {
+ if (ad != NULL) {
+ char passphrase[64] = {0, };
+
+ printf("Input passphrase :\n");
+ if (scanf(" %64[^\n]s", passphrase) < 1)
+ break;
+
+ if (strlen(passphrase) > 0) {
+ printf("passphrase: [%s]\n", passphrase);
+ result = wifi_direct_set_passphrase(passphrase);
+ printf("wifi_direct_set_passphrase() ret=[%d]\n", result);
+ } else
+ printf("invalid passphrase !!\n");
+ }
+ }
+ break;
+ case CMD_GET_PASSPHRASE:
+ {
+ if (ad != NULL) {
+ char* passphrase = NULL;
+
+ result = wifi_direct_get_passphrase(&passphrase);
+ printf("wifi_direct_get_passphrase() result=[%d]\n", result);
+
+ if (NULL != passphrase) {
+ printf("passphrase: [%s]\n", passphrase);
+ free(passphrase);
+ }
+
+ }
+ }
+ break;
+ case CMD_SET_AUTOCONNECTION_PEER:
+ if (ad != NULL) {
+ char * mac_address = NULL;
+ printf("\nEnter Mac_address: ");
+ if (scanf(" %18ms", &mac_address) < 1)
+ break;
+
+ if (strlen(mac_address) > 23) {
+ printf("\nWrong Mac_address");
+
+ } else {
+ int rv = wifi_direct_set_autoconnection_peer(mac_address);
+
+ if (rv == WIFI_DIRECT_ERROR_NONE) {
+ free(mac_address);
+ printf(MAKE_GREEN"SUCCESS %s"RESET_COLOR"\n", __func__);
+ break;
+ }
+ printf(MAKE_RED"FAILED %s : %s"RESET_COLOR"\n", __func__, test_wfd_convert_error_to_string(rv));
+ }
+
+ free(mac_address);
+ }
+ break;
+ case CMD_INIT_DISPLAY:
+ {
+ if (ad != NULL) {
+ result = wifi_direct_init_display();
+ printf("wifi_direct_init_display() result=[%d]\n", result);
+ }
+ }
+ break;
+ case CMD_DEINIT_DISPLAY:
+ {
+ if (ad != NULL) {
+ result = wifi_direct_deinit_display();
+ printf("wifi_direct_deinit_display() result=[%d]\n", result);
+ }
+ }
+ break;
+ case CMD_SET_DISPLAY:
+ {
+ if (ad != NULL) {
+ int rv = WIFI_DIRECT_ERROR_NONE;
+ int use_default = 0;
+
+ printf("Press [0] For Setting Default Values\n");
+ if (scanf(" %1d", &use_default) < 1)
+ break;
+
+ if (use_default == 0) {
+ rv = wifi_direct_set_display(WIFI_DIRECT_DISPLAY_TYPE_SOURCE, 7236, 1);
+ } else {
+ int display_type = 0;
+ int port_number = 0;
+ int hdcp = 0;
+
+ printf("DISPLAY_TYPE----->\n");
+ printf("(0) for WIFI_DISPLAY_TYPE_SOURCE,\n");
+ printf("(1) for WIFI_DISPLAY_TYPE_PRIMARY_SINK,\n");
+ printf("(2) for WIFI_DISPLAY_TYPE_SECONDARY_SINK,\n");
+ printf("(3) WIFI_DISPLAY_TYPE_DUAL_ROLE\n");
+ printf("Please Enter DISPLAY_TYPE -----> ");
+ if (scanf(" %1d", &display_type) < 1)
+ break;
+
+ printf("Please Enter PORT NUMBER -----> ");
+ if (scanf(" %4d", &port_number) < 1)
+ break;
+
+ printf("Please Enter HDCP -----> ");
+ if (scanf(" %1d", &hdcp) < 1)
+ break;
+
+ rv = wifi_direct_set_display(display_type, port_number, hdcp);
+ }
+
+ if (rv == WIFI_DIRECT_ERROR_NONE) {
+ printf(MAKE_GREEN"Success %s : %s"RESET_COLOR"\n", __func__, test_wfd_convert_error_to_string(rv));
+ break;
+ }
+
+ printf(MAKE_RED"FAILED %s : %s"RESET_COLOR"\n", __func__, test_wfd_convert_error_to_string(rv));
+ break;
+ }
+ }
+ break;
+ case CMD_SET_DISPLAY_AVAILABILITY:
+ {
+ if (ad != NULL) {
+ int availability = 0;
+
+ printf("Enter Wi-Fi Display availability : ");
+ if (scanf(" %1d", &availability) < 0)
+ break;
+
+ int rv = wifi_direct_set_display_availability(availability);
+ if (WIFI_DIRECT_ERROR_NONE == rv) {
+ printf(MAKE_GREEN"Set Wi-Fi Display availability Successful"RESET_COLOR"\n");
+ break;
+ }
+ printf(MAKE_RED"Set Wi-Fi Display availability : %s ", test_wfd_convert_error_to_string(rv));
+ printf(RESET_COLOR"\n");
+ break;
+ }
+ }
+ break;
+ case CMD_GET_DISPLAY:
+ {
+ if (ad != NULL) {
+ wifi_direct_display_type_e type;
+ int port;
+ int hdcp;
+
+ result = wifi_direct_get_display(&type, &port, &hdcp);
+
+ printf("wifi_direct_get_display() result=[%d] type=[%d] port=[%d] hdcp=[%d]\n", result, type, port, hdcp);
+ break;
+ }
+ }
+ break;
+ case CMD_GET_DISPLAY_AVAILABILITY:
+ {
+ if (ad != NULL) {
+ bool availability;
+
+ result = wifi_direct_get_display_availability(&availability);
+
+ printf("wifi_direct_get_display_availability() result=[%d] availability=[%d]\n", result, availability);
+ break;
+ }
+ }
+ break;
+ case CMD_GET_PEER_DISPLAY_TYPE:
+ if (ad != NULL) {
+ if (select_peer(ad)) {
+ int i = ad->selected_peer_index;
+ wifi_direct_display_type_e type = WIFI_DIRECT_DISPLAY_TYPE_DUAL;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_get_peer_display_type(list[i].mac_address, &type);
+
+ printf("wifi_direct_get_peer_display_type() result=[%d] type=[%d]\n", result, type);
+ }
+ }
+ break;
+ case CMD_GET_PEER_DISPLAY_AVAILABILITY:
+ if (ad != NULL) {
+ if (select_peer(ad)) {
+ int i = ad->selected_peer_index;
+ bool availability = false;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_get_peer_display_availability(list[i].mac_address, &availability);
+
+ printf("wifi_direct_get_peer_display_availability() result=[%d] availability=[%d]\n", result, availability);
+ }
+ }
+ break;
+ case CMD_GET_PEER_DISPLAY_HDCP:
+ if (ad != NULL) {
+ if (select_peer(ad)) {
+ int i = ad->selected_peer_index;
+ int hdcp;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_get_peer_display_hdcp(list[i].mac_address, &hdcp);
+
+ printf("wifi_direct_get_peer_display_hdcp() result=[%d] hdcp=[%d]\n", result, hdcp);
+ }
+ }
+ break;
+ case CMD_GET_PEER_DISPLAY_PORT:
+ if (ad != NULL) {
+ if (select_peer(ad)) {
+ int i = ad->selected_peer_index;
+ int port;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_get_peer_display_port(list[i].mac_address, &port);
+
+ printf("wifi_direct_get_peer_display_port() result=[%d] port=[%d]\n", result, port);
+ }
+ }
+ break;
+ case CMD_GET_PEER_DISPLAY_THROUGHPUT:
+ if (ad != NULL) {
+ if (select_peer(ad)) {
+ int i = ad->selected_peer_index;
+ int tput;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_get_peer_display_throughput(list[i].mac_address, &tput);
+
+ printf("wifi_direct_get_peer_display_throughput() result=[%d] throughput=[%d]\n", result, tput);
+ }
+ }
+ break;
+ case CMD_GET_SESSION_TIMER:
+ if (ad != NULL) {
+ int session_timer;
+ result = wifi_direct_get_session_timer(&session_timer);
+ printf("wifi_direct_get_session_timer() result=[%d] session_timer[%d]\n",
+ result, session_timer);
+ }
+ break;
+ case CMD_SET_SESSION_TIMER:
+ if (ad != NULL) {
+ int session_timer;
+ printf("Input Session Timer \n");
+ if (scanf(" %2d", &session_timer) < 1)
+ break;
+
+ result = wifi_direct_set_session_timer(session_timer);
+ printf("wifi_direct_set_session_timer() result=[%d] session_timer[%d]\n",
+ result, session_timer);
+ }
+ break;
+ case CMD_SET_AUTO_GROUP_REMOVAL:
+ if (ad != NULL) {
+ int enable;
+ printf("Enter (1 to enable or 0 to Disable): ");
+ if (scanf(" %1d", &enable) < 1)
+ break;
+
+ result = wifi_direct_set_auto_group_removal(enable);
+ printf("wifi_direct_set_auto_group_removal() result=[%d]\n", result);
+ if (enable == true)
+ printf("Enable auto Group Removal!! \n");
+ else
+ printf("Disable auto Group Removal mode!! \n");
+ }
+ break;
+ case CMD_GET_PEER_RSSI:
+ if (ad != NULL) {
+ if (select_peer(ad)) {
+ int i = ad->selected_peer_index;
+ int rssi = 0;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_get_peer_rssi(list[i].mac_address, &rssi);
+
+ printf("wifi_direct_get_peer_rssi() result=[%d] rssi=[%d]\n", result, rssi);
+ }
+ }
+ break;
+ case CMD_ADD_VSIE:
+ {
+ char *vsie = NULL;
+ unsigned int frame_id;
+
+ printf("Input frame_id:\n");
+ if (scanf(" %2u", &frame_id) < 1)
+ break;
+
+ printf("Input vsie:\n");
+ if (scanf(" %100ms", &vsie) < 1)
+ break;
+
+ if (strlen(vsie) <= 0)
+ printf("invalid vsie !!\n");
+ else
+ printf("vsie: [%s]\n", vsie);
+
+ if ((strlen(vsie) > 0)) {
+ result = wifi_direct_add_vsie(frame_id, vsie);
+ printf("wifi_direct_add_vsie() ret=[%d]\n", result);
+ }
+
+ free(vsie);
+ }
+ break;
+ case CMD_GET_VSIE:
+ {
+ char *vsie = NULL;
+ unsigned int frame_id;
+
+ printf("Input frame_id:\n");
+ if (scanf(" %2u", &frame_id) < 1)
+ break;
+
+ wifi_direct_get_vsie(frame_id, &vsie);
+ printf("Received vsie [%s]\n", vsie ? vsie : "NULL");
+ free(vsie);
+ }
+ break;
+ case CMD_REMOVE_VSIE:
+ {
+ char *vsie = NULL;
+ unsigned int frame_id;
+
+ printf("Input frame_id:\n");
+ if (scanf(" %2u", &frame_id) < 1)
+ break;
+
+ printf("Input vsie:\n");
+ if (scanf(" %100ms", &vsie) < 1)
+ break;
+
+ if (strlen(vsie) <= 0)
+ printf("invalid vsie !!\n");
+ else
+ printf("vsie: [%s]\n", vsie);
+
+ if ((strlen(vsie) > 0)) {
+ result = wifi_direct_remove_vsie(frame_id, vsie);
+ printf("wifi_direct_add_vsie() ret=[%d]\n", result);
+ }
+
+ free(vsie);
+ }
+ break;
+ case CMD_GET_PEER_VSIE:
+ if (ad != NULL) {
+ if (select_peer(ad)) {
+ int i = ad->selected_peer_index;
+ char *vsie = NULL;
+ wifi_direct_discovered_peer_info_s* list = ad->peer_list;
+
+ result = wifi_direct_get_peer_vsie(list[i].mac_address,
+ &vsie);
+
+ printf("wifi_direct_get_peer_vsie() result=[%d] vsie=[%s]\n", result, vsie);
+
+ if (vsie)
+ free(vsie);
+ }
+ }
+ 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;
+
+ case CMD_QUIT:
+ printf("Bye\n");
+ g_main_loop_quit(ad->main_loop);
+ break;
+
+ default:
+ usage_full();
+ break;
+ }
+}
+
+static gboolean test_terminal_read_std_input(GIOChannel * source,
+ GIOCondition condition, gpointer user_data)
+{
+ int fd = 0;
+
+ static char buf[1024];
+ int n;
+
+ errno = 0;
+ n = read(fd, buf, 1024);
+ if (n == 0) {
+ printf("Error: read() from stdin returns 0.\n");
+ } else if (n < 0) {
+ char error_buf[100] = {0, };
+ strerror_r(errno, error_buf, sizeof(error_buf));
+ printf("input: read, err=%s\n", error_buf);
+ } else {
+ buf[n - 1] = '\0'; /* remove new line... */
+ printf("\n\n");
+ /* printf("Read [%d]bytes data: [%s]\n", n, buf); */
+ /* printf("Processing it ---------------------\n", n, buf); */
+ process_input(buf, user_data);
+ }
+
+ return TRUE;
+}
+
+int main(int argc, char **argv)
+{
+ GMainLoop *main_loop;
+ struct appdata *ad = NULL;
+
+#if !GLIB_CHECK_VERSION(2, 36, 0)
+ g_type_init();
+#endif
+
+ main_loop = g_main_loop_new(NULL, FALSE);
+
+ ad = (struct appdata*)g_try_malloc0(sizeof(struct appdata));
+ if (!ad)
+ return -1;
+
+ ad->main_loop = main_loop;
+
+ ad->peer_count = 0;
+
+ set_appdata(ad);
+
+ int r = get_param(argc, argv, ad);
+ if (r)
+ return -1;
+
+ int std_input_fd = 0;
+ GIOChannel *gio2 = g_io_channel_unix_new(std_input_fd);
+ g_io_add_watch(gio2, G_IO_IN, (GIOFunc) test_terminal_read_std_input, ad);
+ g_io_channel_unref(gio2);
+
+ usage_full();
+
+ g_main_loop_run(main_loop);
+
+ g_free(ad);
+ return 0;
+}