static void __bt_adapter_state_change_callback(int bt_status);
static int __bt_adapter_state_handle_request(gboolean enable);
static int __bt_adapter_state_discovery_request(gboolean enable,
- unsigned short max_response, unsigned short duration, unsigned int mask);
+ unsigned short max_response, unsigned short duration, unsigned int mask,
+ gboolean is_custom, bt_discovery_role_type_t role);
static void __bt_adapter_discovery_state_change_callback(int bt_discovery_status);
static gboolean __bt_is_service_request_present(int service_function);
int _bt_start_discovery(unsigned short max_response,
unsigned short duration, unsigned int cod_mask)
{
- return __bt_adapter_state_discovery_request(TRUE, max_response, duration, cod_mask);
+ return __bt_adapter_state_discovery_request(TRUE, max_response, duration,
+ cod_mask, FALSE, 0x00);
+}
+
+int _bt_start_custom_discovery(bt_discovery_role_type_t role)
+{
+ return __bt_adapter_state_discovery_request(TRUE, 0, 0, 0, TRUE, role);
}
int _bt_cancel_discovery(void)
{
- return __bt_adapter_state_discovery_request(FALSE, 0, 0, 0);
+ return __bt_adapter_state_discovery_request(FALSE, 0, 0, 0, FALSE, 0x00);
}
gboolean _bt_is_discovering(void)
return result;
}
+int _bt_get_profile_connected_devices(char *profile_uuid, GArray **addr_list)
+{
+ BT_DBG("+");
+ GDBusConnection *conn;
+ GDBusProxy *manager_proxy;
+ GVariant *result = NULL;
+ GVariant *result1 = NULL;
+ GVariantIter *iter = NULL;
+ GError *error = NULL;
+ char *object_path = NULL;
+ GVariantIter *interface_iter;
+ char *interface_str = NULL;
+ GDBusProxy *device_proxy = NULL;
+ gboolean is_connected = FALSE;
+
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ manager_proxy = _bt_get_manager_proxy();
+ retv_if(manager_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL);
+
+ if (!result) {
+ if (error != NULL) {
+ BT_ERR("Failed to GetManagedObjects (Error: %s)", error->message);
+ g_clear_error(&error);
+ error = NULL;
+ } else
+ BT_ERR("Failed to Failed to GetManagedObjects");
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ /* signature of GetManagedObjects: a{oa{sa{sv}}} */
+ g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
+
+ /* Parse the signature: oa{sa{sv}}} */
+ while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path, &interface_iter)) {
+ if (object_path == NULL)
+ continue;
+
+ while (g_variant_iter_loop(interface_iter, "{sa{sv}}",
+ &interface_str, NULL)) {
+ if (g_strcmp0(interface_str, "org.bluez.Device1") == 0) {
+ BT_DBG("Found a device: %s", object_path);
+ g_free(interface_str);
+
+ device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME,
+ object_path, BT_DEVICE_INTERFACE, NULL, NULL);
+
+ if (device_proxy == NULL) {
+ BT_DBG("Device don't have this service");
+ break;
+ }
+
+ result1 = g_dbus_proxy_call_sync(device_proxy, "IsConnectedProfile",
+ g_variant_new("(s)", profile_uuid),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (result1 == NULL) {
+ BT_ERR("Error occured in Proxy call");
+ if (error) {
+ BT_ERR("Error occured in Proxy call [%s]\n", error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+ g_object_unref(device_proxy);
+ break;
+ }
+ g_variant_get(result1, "(b)", &is_connected);
+
+ if (is_connected == TRUE) {
+ char address[BT_ADDRESS_STRING_SIZE];
+ bluetooth_device_address_t *addr = NULL;
+
+ _bt_convert_device_path_to_address(object_path, address);
+
+ addr = g_malloc0(sizeof(bluetooth_device_address_t));
+ _bt_convert_addr_string_to_type(addr->addr, address);
+
+ g_array_append_vals(*addr_list, addr,
+ sizeof(bluetooth_device_address_t));
+ }
+
+ g_variant_unref(result1);
+ g_object_unref(device_proxy);
+
+ break;
+ }
+ }
+ }
+
+ g_variant_unref(result);
+ g_variant_iter_free(iter);
+
+ BT_DBG("-");
+ return BLUETOOTH_ERROR_NONE;
+}
+
static void __bt_handle_pending_a2dp_init(service_uuid_t *service_list, unsigned int count)
{
int ret;
}
static int __bt_adapter_state_discovery_request(gboolean enable,
- unsigned short max_response, unsigned short duration, unsigned int mask)
+ unsigned short max_response, unsigned short duration,
+ unsigned int mask, gboolean is_custom,
+ bt_discovery_role_type_t role)
{
int result = BLUETOOTH_ERROR_NONE;
return BLUETOOTH_ERROR_NOT_IN_OPERATION;
else {
BT_DBG("max_resp: %u, duration: %u, cod: 0x%X", max_response, duration, mask);
- result = adapter_start_inquiry(duration);
+
+ if (!is_custom)
+ result = adapter_start_inquiry(duration);
+ else
+ result = adapter_start_custom_inquiry(role);
+
if (result != OAL_STATUS_SUCCESS) {
BT_ERR("Start Discovery failed: %d", result);
result = BLUETOOTH_ERROR_INTERNAL;
return BLUETOOTH_ERROR_NOT_IN_OPERATION;
else {
BT_DBG("max_resp: %u, duration: %u, cod: 0x%X", max_response, duration, mask);
- result = adapter_start_inquiry(duration);
+ if (!is_custom)
+ result = adapter_start_inquiry(duration);
+ else
+ result = adapter_start_custom_inquiry(role);
if (result != OAL_STATUS_SUCCESS) {
BT_ERR("Start Discovery failed: %d", result);
result = BLUETOOTH_ERROR_INTERNAL;