peer->has_asp_services = 1;
else
peer->has_asp_services = 0;
+ } else if (g_strcmp0(key, "AdvertiseASPService") == 0) {
+ if (value != NULL && g_variant_get_size(value) != 0)
+ peer->has_asp2_services = 1;
+ else
+ peer->has_asp2_services = 0;
#endif /* TIZEN_FEATURE_ASP */
} else {
__WDP_LOG_FUNC_EXIT__;
return res;
}
+
+
+int ws_get_advertise_asp_service(const char *peer_path, GList **asp_services)
+{
+ __WDP_LOG_FUNC_ENTER__;
+ GDBusConnection *g_dbus = NULL;
+ GVariant *param = NULL;
+ GVariant *reply = NULL;
+ GVariant *temp = NULL;
+ GError *error = NULL;
+ GVariantIter *iter = NULL;
+ wfd_oem_advertise_service_s *service;
+ wfd_oem_asp_service_s *seek = NULL;
+ unsigned char desc[7];
+ unsigned int adv_id;
+ unsigned int config_method;
+ unsigned char length;
+ char *service_type = NULL;
+ char *instance_name = NULL;
+ unsigned char instance_length = 0;
+ int cnt;
+ int res = 0;
+
+ if (!g_pd) {
+ WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
+ return -1;
+ }
+
+ g_dbus = g_pd->g_dbus;
+ if (!g_dbus) {
+ WDP_LOGE("DBus connection is NULL");
+ return -1;
+ }
+
+ param = g_variant_new("(ss)", SUPPLICANT_P2P_PEER, "AdvertiseASPService");
+ DEBUG_G_VARIANT("Params : ", param);
+
+ reply = g_dbus_connection_call_sync(
+ g_dbus,
+ SUPPLICANT_SERVICE, /* bus name */
+ peer_path, /* object path */
+ DBUS_PROPERTIES_INTERFACE, /* interface name */
+ DBUS_PROPERTIES_METHOD_GET, /* method name */
+ param, /* GVariant *params */
+ NULL, /* reply_type */
+ G_DBUS_CALL_FLAGS_NONE, /* flags */
+ SUPPLICANT_TIMEOUT , /* timeout */
+ NULL, /* cancellable */
+ &error); /* error */
+
+ if (error != NULL) {
+ WDP_LOGE("Error! Failed to get peer advertise service: [%s]",
+ error->message);
+ g_error_free(error);
+ if (reply)
+ g_variant_unref(reply);
+ __WDP_LOG_FUNC_EXIT__;
+ return -1;
+ }
+
+ if (reply != NULL) {
+ DEBUG_G_VARIANT("Reply : ", reply);
+
+ /* replay will have the format <(<ay>,)>
+ * So, you need to remove tuple out side of variant and
+ * variant out side of byte array
+ * */
+ temp = g_variant_get_child_value(reply, 0);
+ temp = g_variant_get_child_value(temp, 0);
+ g_variant_get(temp, "ay", &iter);
+ if (iter == NULL) {
+ g_variant_unref(reply);
+ WDP_LOGE("Failed to get iterator");
+ return -1;
+ }
+
+ while (1) {
+ /* 4byte advertisement ID, 2 byte config method, 1byte length */
+
+ cnt = 0;
+ memset(desc, 0x0, 7);
+ while (cnt < 7 && g_variant_iter_loop(iter, "y", &desc[cnt]))
+ cnt++;
+
+ if (cnt != 7 || desc[6] == 0) {
+ WDP_LOGE("Invalid descriptor header length cnt [%d]", cnt);
+ g_variant_unref(reply);
+ return res;
+ }
+
+ adv_id = desc[3] << 24 | desc[2] << 16 | desc[1] << 8 | desc[0];
+ config_method = desc[4] << 8 | desc[4];
+ length = desc[6];
+ service_type = g_try_malloc0(length + 1);
+ if (service_type == NULL) {
+ WDP_LOGE("g_try_malloc0 failed");
+ g_variant_unref(reply);
+ return res;
+ }
+ WDP_LOGD("adv_id[%u] config_method[%u] length[%hhu]", adv_id, config_method, length);
+
+ cnt = 0;
+ while (cnt < length + 1 && g_variant_iter_loop(iter, "y", &service_type[cnt]))
+ cnt++;
+
+ if (cnt != length + 1) {
+ WDP_LOGE("Length doesn't matched with header value cnt [%d]", cnt);
+ g_variant_unref(reply);
+ g_free(service_type);
+ return res;
+ }
+
+ instance_length = (unsigned char)service_type[length];
+ service_type[length] = '\0';
+
+ if(instance_length != 0) {
+ instance_name = g_try_malloc0(instance_length + 1);
+ if (instance_name == NULL) {
+ WDP_LOGE("g_try_malloc0 failed");
+ g_variant_unref(reply);
+ g_free(service_type);
+ return res;
+ }
+ WDP_LOGD("instnace name length[%hhu]", instance_length);
+
+ cnt = 0;
+ while (cnt < instance_length && g_variant_iter_loop(iter, "y", &instance_name[cnt]))
+ cnt++;
+
+ if (cnt != instance_length) {
+ WDP_LOGE("Length doesn't matched with header value cnt [%d]", cnt);
+ g_variant_unref(reply);
+ g_free(service_type);
+ g_free(instance_name);
+ return res;
+ }
+ }
+
+ service = NULL;
+ service = (wfd_oem_advertise_service_s *)
+ g_try_malloc0(sizeof(wfd_oem_advertise_service_s));
+ if (service == NULL) {
+ WDP_LOGE("g_try_malloc0 failed");
+ g_variant_unref(reply);
+ g_free(service_type);
+ g_free(instance_name);
+ return res;
+ }
+ service->adv_id = adv_id;
+ service->config_method = config_method;
+ service->service_type_length = length;
+ service->service_type = service_type;
+ service->instance_name_length = instance_length;
+ service->instance_name = instance_name;
+
+GLIST_ITER_START(seek_list, seek)
+ if (g_strcmp0(seek->service_type, service->service_type) == 0) {
+ /* TODO: We need to support for instance name also hear */
+ WDP_LOGD("service type matched [%s] search_id [%llu]",
+ service->service_type, seek->search_id);
+ } else {
+ seek = NULL;
+ }
+GLIST_ITER_END()
+
+ if (seek != NULL && seek->service_info != NULL) {
+ WDP_LOGD("service info exists, service discovery will be performed");
+ } else {
+ WDP_LOGD("service info doesn't exists. Add service to list");
+ if (seek)
+ service->search_id = seek->search_id;
+ *asp_services = g_list_append(*asp_services, service);
+ }
+ }
+ g_variant_unref(reply);
+ }
+ __WDP_LOG_FUNC_EXIT__;
+ return res;
+}
#endif /* TIZEN_FEATURE_ASP */
static void _ws_process_device_found_properties(GDBusConnection *connection,
#if defined(TIZEN_FEATURE_ASP)
if (edata->has_asp_services)
ws_get_advertise_service(peer_path, (GList **)&(event.asp_services));
+ if (edata->has_asp2_services)
+ ws_get_advertise_asp_service(peer_path, (GList **)&(event.asp2_services));
#endif /* TIZEN_FEATURE_ASP */
if (g_pd->callback->peer_found_cb)
g_free(service);
}
}
+ if (event.asp2_services != NULL) {
+ GList *l;
+ wfd_oem_advertise_service_s *service;
+ for (l = (GList *)event.asp2_services; l != NULL; l = l->next) {
+ service = (wfd_oem_advertise_service_s *)l->data;
+ event.asp_services = g_list_remove(l, service);
+ g_free(service->service_type);
+ g_free(service->instance_name);
+ g_free(service);
+ }
+ }
#endif /* TIZEN_FEATURE_ASP */
g_free(event.edata);
"SearchResult",
params);
}
+
+ for (list = (GList *)event->asp2_services; list != NULL; list = list->next) {
+ service = (wfd_oem_advertise_service_s *)list->data;
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(builder, "{sv}", "search_id", g_variant_new("t", service->search_id));
+ g_variant_builder_add(builder, "{sv}", "service_mac", g_variant_new("s", peer_mac_address));
+ g_variant_builder_add(builder, "{sv}", "device_name", g_variant_new("s", edata->name));
+ g_variant_builder_add(builder, "{sv}", "advertisement_id", g_variant_new("u", service->adv_id));
+ g_variant_builder_add(builder, "{sv}", "config_method", g_variant_new("u", service->config_method));
+ if (service->service_type)
+ g_variant_builder_add(builder, "{sv}", "service_type", g_variant_new("s", service->service_type));
+ if (service->instance_name)
+ g_variant_builder_add(builder, "{sv}", "instance_name", g_variant_new("s", service->instance_name));
+ params = g_variant_new("(a{sv})", builder);
+ g_variant_builder_unref(builder);
+
+ wfd_manager_dbus_emit_signal(WFD_MANAGER_ASP_INTERFACE,
+ "SearchResult",
+ params);
+ }
#endif
__WDS_LOG_FUNC_EXIT__;
return;