From f2d506b38fb99eb0c7bcc0f08648c8e8dcb5d302 Mon Sep 17 00:00:00 2001 From: Nishant Chaprana Date: Wed, 26 Apr 2017 15:53:17 +0530 Subject: [PATCH] Added implementation for new APIs. Description: Implementation for below APIs are added:- 1. wifi_direct_add_vsie 2. wifi_direct_get_vsie 3. wifi_direct_remove_vsie 4. wifi_direct_get_connecting_peer_info 5. wifi_direct_start_discovery_specific_freq Change-Id: I0f361ff70dd8cd1171e1599e987291d618884f42 Signed-off-by: Nishant Chaprana --- packaging/capi-network-wifi-direct.spec | 2 +- src/wifi-direct-client-proxy.c | 356 +++++++++++++++++++++++++++----- test/test-wifi-direct.c | 103 +++++++++ 3 files changed, 404 insertions(+), 57 deletions(-) diff --git a/packaging/capi-network-wifi-direct.spec b/packaging/capi-network-wifi-direct.spec index 61adc94..9bc9de9 100644 --- a/packaging/capi-network-wifi-direct.spec +++ b/packaging/capi-network-wifi-direct.spec @@ -3,7 +3,7 @@ Name: capi-network-wifi-direct Summary: Network WiFi-Direct Library -Version: 1.2.79 +Version: 1.2.80 Release: 1 Group: Network & Connectivity/API License: Apache-2.0 diff --git a/src/wifi-direct-client-proxy.c b/src/wifi-direct-client-proxy.c index 0a46cc0..611e361 100644 --- a/src/wifi-direct-client-proxy.c +++ b/src/wifi-direct-client-proxy.c @@ -709,6 +709,65 @@ void __wfd_client_print_persistent_group_info(wfd_persistent_group_info_s *list, WDC_LOGD("------------------------------------------\n"); } #endif + +static void __wfd_client_extract_discovered_peer_info(GVariantIter *iter, + wifi_direct_discovered_peer_info_s *info) { + __WDC_LOG_FUNC_START__; + GVariant *var = NULL; + gchar *key = NULL; + + while (g_variant_iter_loop(iter, "{sv}", &key, &var)) { + if (!g_strcmp0(key, "DeviceName")) { + const char *device_name = NULL; + + g_variant_get(var, "&s", &device_name); + info->device_name = g_strndup(device_name, WIFI_DIRECT_MAX_DEVICE_NAME_LEN+1); + + } else if (!g_strcmp0(key, "DeviceAddress")) { + unsigned char mac_address[MACADDR_LEN] = {0, }; + + wifi_direct_dbus_unpack_ay(mac_address, var, MACADDR_LEN); + info->mac_address = (char*) g_try_malloc0(MACSTR_LEN); + if (info->mac_address) + g_snprintf(info->mac_address, MACSTR_LEN, MACSTR, MAC2STR(mac_address)); + + } else if (!g_strcmp0(key, "InterfaceAddress")) { + unsigned char intf_address[MACADDR_LEN] = {0, }; + + wifi_direct_dbus_unpack_ay(intf_address, var, MACADDR_LEN); + info->interface_address = (char*) g_try_malloc0(MACSTR_LEN); + if (info->interface_address) + g_snprintf(info->interface_address, MACSTR_LEN, MACSTR, MAC2STR(intf_address)); + + } else if (!g_strcmp0(key, "Channel")) { + info->channel = g_variant_get_uint16(var); + + } else if (!g_strcmp0(key, "IsGroupOwner")) { + info->is_group_owner = g_variant_get_boolean(var); + + } else if (!g_strcmp0(key, "IsPersistentGO")) { + info->is_persistent_group_owner = g_variant_get_boolean(var); + + } else if (!g_strcmp0(key, "IsConnected")) { + info->is_connected = g_variant_get_boolean(var); + + } else if (!g_strcmp0(key, "Category")) { + info->primary_device_type = g_variant_get_uint16(var); + + } else if (!g_strcmp0(key, "SubCategory")) { + info->secondary_device_type = g_variant_get_uint16(var); + + } else if (!g_strcmp0(key, "IsWfdDevice")) { +#ifdef TIZEN_FEATURE_WIFI_DISPLAY + info->is_miracast_device = g_variant_get_boolean(var); +#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ + } else { + ;/* Do Nothing */ + } + } + + __WDC_LOG_FUNC_END__; +} //LCOV_EXCL_STOP int wifi_direct_initialize(void) @@ -1327,6 +1386,58 @@ int wifi_direct_start_discovery_specific_channel(bool listen_only, return ret; } +int wifi_direct_start_discovery_specific_freq(bool listen_only, + int timeout, int frequency) +{ + __WDC_LOG_FUNC_START__; + GVariantBuilder *builder = NULL; + GVariant *params = NULL; + GError *error = NULL; + GVariant *reply = NULL; + int ret = WIFI_DIRECT_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (timeout < 0 || frequency <= 0) { + WDC_LOGE("Invalid parameter"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + g_variant_builder_add(builder, "{sv}", "Mode", + g_variant_new("b", listen_only)); + g_variant_builder_add(builder, "{sv}", "Timeout", + g_variant_new("i", timeout)); + g_variant_builder_add(builder, "{sv}", "Frequency", + g_variant_new("i", frequency)); + params = g_variant_new("(a{sv})", builder); + g_variant_builder_unref(builder); + + WDC_LOGI("listen only (%d) timeout (%d) frequency (%d)", listen_only, + timeout, frequency); + + reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE, + "StartDiscovery", params, + &error); + + ret = __net_wifidirect_gerror_to_enum(error); + if (ret == WIFI_DIRECT_ERROR_NONE) { + g_variant_get(reply, "(i)", &ret); + g_variant_unref(reply); + } + + WDC_LOGD("%s() return : [%d]", __func__, ret); + __WDC_LOG_FUNC_END__; + return ret; +} + int wifi_direct_cancel_discovery(void) { __WDC_LOG_FUNC_START__; @@ -1432,8 +1543,6 @@ int wifi_direct_foreach_discovered_peers(wifi_direct_discovered_peer_cb cb, GVariant *reply = NULL; GVariantIter *iter_peers = NULL; GVariantIter *iter_peer = NULL; - GVariant *var = NULL; - gchar *key = NULL; int ret = WIFI_DIRECT_ERROR_NONE; if (g_client_info.is_registered == false) { @@ -1464,66 +1573,19 @@ int wifi_direct_foreach_discovered_peers(wifi_direct_discovered_peer_cb cb, WDC_LOGD("wifi_direct_foreach_discovered_peers() SUCCESS"); //LCOV_EXCL_START while (g_variant_iter_loop(iter_peers, "a{sv}", &iter_peer)) { - wifi_direct_discovered_peer_info_s *peer_list = NULL; + wifi_direct_discovered_peer_info_s *peer_info = NULL; - peer_list = (wifi_direct_discovered_peer_info_s *) g_try_malloc0(sizeof(wifi_direct_discovered_peer_info_s)); - if (!peer_list) { + peer_info = (wifi_direct_discovered_peer_info_s *) + g_try_malloc0(sizeof(wifi_direct_discovered_peer_info_s)); + if (!peer_info) { WDC_LOGE("Failed to allocate memory"); continue; } - while (g_variant_iter_loop(iter_peer, "{sv}", &key, &var)) { - if (!g_strcmp0(key, "DeviceName")) { - const char *device_name = NULL; - - g_variant_get(var, "&s", &device_name); - peer_list->device_name = g_strndup(device_name, WIFI_DIRECT_MAX_DEVICE_NAME_LEN+1); - - } else if (!g_strcmp0(key, "DeviceAddress")) { - unsigned char mac_address[MACADDR_LEN] = {0, }; - - wifi_direct_dbus_unpack_ay(mac_address, var, MACADDR_LEN); - peer_list->mac_address = (char*) g_try_malloc0(MACSTR_LEN); - if (peer_list->mac_address) - g_snprintf(peer_list->mac_address, MACSTR_LEN, MACSTR, MAC2STR(mac_address)); - - } else if (!g_strcmp0(key, "InterfaceAddress")) { - unsigned char intf_address[MACADDR_LEN] = {0, }; - - wifi_direct_dbus_unpack_ay(intf_address, var, MACADDR_LEN); - peer_list->interface_address = (char*) g_try_malloc0(MACSTR_LEN); - if (peer_list->interface_address) - g_snprintf(peer_list->interface_address, MACSTR_LEN, MACSTR, MAC2STR(intf_address)); - - } else if (!g_strcmp0(key, "Channel")) { - peer_list->channel = g_variant_get_uint16(var); - - } else if (!g_strcmp0(key, "IsGroupOwner")) { - peer_list->is_group_owner = g_variant_get_boolean(var); - - } else if (!g_strcmp0(key, "IsPersistentGO")) { - peer_list->is_persistent_group_owner = g_variant_get_boolean(var); - - } else if (!g_strcmp0(key, "IsConnected")) { - peer_list->is_connected = g_variant_get_boolean(var); - - } else if (!g_strcmp0(key, "Category")) { - peer_list->primary_device_type = g_variant_get_uint16(var); - - } else if (!g_strcmp0(key, "SubCategory")) { - peer_list->secondary_device_type = g_variant_get_uint16(var); + __wfd_client_extract_discovered_peer_info(iter_peer, peer_info); + /* __wfd_client_print_entry_list(peer_info, 1); */ - } else if (!g_strcmp0(key, "IsWfdDevice")) { -#ifdef TIZEN_FEATURE_WIFI_DISPLAY - peer_list->is_miracast_device = g_variant_get_boolean(var); -#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ - } else { - ;/* Do Nothing */ - } - } - - /* __wfd_client_print_entry_list(peer_list, 1); */ - if (!cb(peer_list, user_data)) { + if (!cb(peer_info, user_data)) { g_variant_iter_free(iter_peer); break; } @@ -4443,5 +4505,187 @@ int wifi_direct_get_peer_rssi(char *mac_address, int *rssi) return ret; } +int wifi_direct_add_vsie(wifi_direct_vsie_frames_e frame_id, + const char *vsie_str) +{ + __WDC_LOG_FUNC_START__; + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + GError* error = NULL; + GVariant *reply = NULL; + GVariant *params = NULL; + int ret = WIFI_DIRECT_ERROR_NONE; + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is NOT registered."); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!vsie_str) { + WDC_LOGE("NULL Param [vsie_str]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + params = g_variant_new("(is)", frame_id, vsie_str); + reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE, + "AddVsie", params, &error); + + ret = __net_wifidirect_gerror_to_enum(error); + if (ret != WIFI_DIRECT_ERROR_NONE) + return ret; + + g_variant_get(reply, "(i)", &ret); + g_variant_unref(reply); + + WDC_LOGD("%s() return : [%d]", __func__, ret); + __WDC_LOG_FUNC_END__; + return ret; +} + +int wifi_direct_get_vsie(wifi_direct_vsie_frames_e frame_id, char **vsie_str) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + GError* error = NULL; + GVariant *reply = NULL; + GVariant *params = NULL; + const char *val = NULL; + int ret = WIFI_DIRECT_ERROR_NONE; + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is NOT registered."); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!vsie_str) { + WDC_LOGE("NULL Param [vsie_str]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + params = g_variant_new("(i)", frame_id); + reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE, + "GetVsie", params, &error); + + ret = __net_wifidirect_gerror_to_enum(error); + if (ret != WIFI_DIRECT_ERROR_NONE) + return ret; + + g_variant_get(reply, "(i&s)", &ret, &val); + *vsie_str = strdup(val); + g_variant_unref(reply); + + WDC_LOGD("%s() return : [%d] vsie [%s]", __func__, ret, *vsie_str); + __WDC_LOG_FUNC_END__; + return ret; +} + +int wifi_direct_remove_vsie(wifi_direct_vsie_frames_e frame_id, + const char *vsie_str) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + GError* error = NULL; + GVariant *reply = NULL; + GVariant *params = NULL; + int ret = WIFI_DIRECT_ERROR_NONE; + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is NOT registered."); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!vsie_str) { + WDC_LOGE("NULL Param [vsie_str]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + params = g_variant_new("(is)", frame_id, vsie_str); + reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE, + "RemoveVsie", params, &error); + + ret = __net_wifidirect_gerror_to_enum(error); + if (ret != WIFI_DIRECT_ERROR_NONE) + return ret; + + g_variant_get(reply, "(i)", &ret); + g_variant_unref(reply); + + WDC_LOGD("%s() return : [%d]", __func__, ret); + __WDC_LOG_FUNC_END__; + return ret; +} + +int wifi_direct_get_connecting_peer_info( + wifi_direct_discovered_peer_info_s **peer_info) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + GError *error = NULL; + GVariant *reply = NULL; + GVariantIter *iter_peer = NULL; + wifi_direct_discovered_peer_info_s *peer = NULL; + int ret = WIFI_DIRECT_ERROR_NONE; + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!peer_info) { + WDC_LOGE("peer_info is NULL"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE, + "GetConnectingPeer", NULL, + &error); + + ret = __net_wifidirect_gerror_to_enum(error); + if (ret != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return ret; + } + + g_variant_get(reply, "(ia{sv})", &ret, &iter_peer); + if (ret != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_OPERATION_FAILED; + } + + WDC_LOGD("wifi_direct_get_peer() SUCCESS"); + + peer = (wifi_direct_discovered_peer_info_s *) + g_try_malloc0(sizeof(wifi_direct_discovered_peer_info_s)); + if (!peer) { + WDC_LOGE("Failed to allocate memory"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_OPERATION_FAILED; + } + + __wfd_client_extract_discovered_peer_info(iter_peer, peer); + /* __wfd_client_print_entry_list(peer, 1); */ + + *peer_info = peer; + + g_variant_unref(reply); + + WDC_LOGD("%s() return : [%d]", __func__, ret); + __WDC_LOG_FUNC_END__; + return ret; +} //LCOV_EXCL_STOP diff --git a/test/test-wifi-direct.c b/test/test-wifi-direct.c index d7ae819..4a7630a 100644 --- a/test/test-wifi-direct.c +++ b/test/test-wifi-direct.c @@ -76,6 +76,7 @@ enum { 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, */ @@ -174,6 +175,10 @@ enum { CMD_SET_AUTO_GROUP_REMOVAL, CMD_GET_PEER_RSSI, + CMD_ADD_VSIE, + CMD_GET_VSIE, + CMD_REMOVE_VSIE, + CMD_INVALID = 255, }; @@ -191,6 +196,7 @@ menu_str_t g_menu_str[] = { { 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" }, */ @@ -289,6 +295,9 @@ menu_str_t g_menu_str[] = { { 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" }, { -1, NULL }, }; @@ -787,6 +796,22 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st 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"); + } + + } } } break; @@ -1332,6 +1357,18 @@ void process_input(const char *input, gpointer user_data) } 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(); @@ -2488,6 +2525,72 @@ void process_input(const char *input, gpointer user_data) } } 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_FULL_MENU: usage_full(); break; -- 2.7.4