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)
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__;
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) {
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;
}
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
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_SET_AUTO_GROUP_REMOVAL,
CMD_GET_PEER_RSSI,
+ CMD_ADD_VSIE,
+ CMD_GET_VSIE,
+ CMD_REMOVE_VSIE,
+
CMD_INVALID = 255,
};
{ 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_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 }, };
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;
}
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();
}
}
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;