#include <config.h>
#endif
+#include <pulse/xmalloc.h>
+
#include <pulsecore/core-util.h>
#include <pulsecore/shared.h>
#include <pulsecore/dbus-shared.h>
#include "bluetooth-util.h"
#include "ipc.h"
+#include "a2dp-codecs.h"
#define HFP_AG_ENDPOINT "/MediaEndpoint/HFPAG"
#define A2DP_SOURCE_ENDPOINT "/MediaEndpoint/A2DPSource"
" </interface>" \
"</node>"
-#define MAX_BITPOOL 64
-#define MIN_BITPOOL 2U
-
struct pa_bluetooth_discovery {
PA_REFCNT_DECLARE;
};
static void get_properties_reply(DBusPendingCall *pending, void *userdata);
-static pa_dbus_pending* send_and_add_to_pending(pa_bluetooth_discovery *y, pa_bluetooth_device *d, DBusMessage *m, DBusPendingCallNotifyFunction func);
+static pa_dbus_pending* send_and_add_to_pending(pa_bluetooth_discovery *y, DBusMessage *m, DBusPendingCallNotifyFunction func, void *call_data);
static pa_bt_audio_state_t pa_bt_audio_state_from_string(const char* value) {
pa_assert(value);
dbus_message_iter_get_basic(i, &key);
- if (!dbus_message_iter_next(i)) {
+ if (!dbus_message_iter_next(i)) {
pa_log("Property value missing");
return -1;
}
/* Vudentz said the interfaces are here when the UUIDs are announced */
if (strcasecmp(HSP_AG_UUID, value) == 0 || strcasecmp(HFP_AG_UUID, value) == 0) {
pa_assert_se(m = dbus_message_new_method_call("org.bluez", d->path, "org.bluez.HandsfreeGateway", "GetProperties"));
- send_and_add_to_pending(y, d, m, get_properties_reply);
+ send_and_add_to_pending(y, m, get_properties_reply, d);
} else if (strcasecmp(HSP_HS_UUID, value) == 0 || strcasecmp(HFP_HS_UUID, value) == 0) {
pa_assert_se(m = dbus_message_new_method_call("org.bluez", d->path, "org.bluez.Headset", "GetProperties"));
- send_and_add_to_pending(y, d, m, get_properties_reply);
+ send_and_add_to_pending(y, m, get_properties_reply, d);
} else if (strcasecmp(A2DP_SINK_UUID, value) == 0) {
pa_assert_se(m = dbus_message_new_method_call("org.bluez", d->path, "org.bluez.AudioSink", "GetProperties"));
- send_and_add_to_pending(y, d, m, get_properties_reply);
+ send_and_add_to_pending(y, m, get_properties_reply, d);
} else if (strcasecmp(A2DP_SOURCE_UUID, value) == 0) {
pa_assert_se(m = dbus_message_new_method_call("org.bluez", d->path, "org.bluez.AudioSource", "GetProperties"));
- send_and_add_to_pending(y, d, m, get_properties_reply);
+ send_and_add_to_pending(y, m, get_properties_reply, d);
}
/* this might eventually be racy if .Audio is not there yet, but the State change will come anyway later, so this call is for cold-detection mostly */
pa_assert_se(m = dbus_message_new_method_call("org.bluez", d->path, "org.bluez.Audio", "GetProperties"));
- send_and_add_to_pending(y, d, m, get_properties_reply);
+ send_and_add_to_pending(y, m, get_properties_reply, d);
if (!dbus_message_iter_next(&ai))
break;
dbus_message_iter_get_basic(i, &key);
- if (!dbus_message_iter_next(i)) {
+ if (!dbus_message_iter_next(i)) {
pa_log("Property value missing");
return -1;
}
pa_hashmap_put(y->devices, d->path, d);
pa_assert_se(m = dbus_message_new_method_call("org.bluez", path, "org.bluez.Device", "GetProperties"));
- send_and_add_to_pending(y, d, m, get_properties_reply);
+ send_and_add_to_pending(y, m, get_properties_reply, d);
/* Before we read the other properties (Audio, AudioSink, AudioSource,
* Headset) we wait that the UUID is read */
pa_dbus_pending_free(p);
}
-static pa_dbus_pending* send_and_add_to_pending(pa_bluetooth_discovery *y, pa_bluetooth_device *d, DBusMessage *m, DBusPendingCallNotifyFunction func) {
+static pa_dbus_pending* send_and_add_to_pending(pa_bluetooth_discovery *y, DBusMessage *m, DBusPendingCallNotifyFunction func, void *call_data) {
pa_dbus_pending *p;
DBusPendingCall *call;
pa_assert_se(dbus_connection_send_with_reply(pa_dbus_connection_get(y->connection), m, &call, -1));
- p = pa_dbus_pending_new(pa_dbus_connection_get(y->connection), m, call, y, d);
+ p = pa_dbus_pending_new(pa_dbus_connection_get(y->connection), m, call, y, call_data);
PA_LLIST_PREPEND(pa_dbus_pending, y->pending, p);
dbus_pending_call_set_notify(call, func, p, NULL);
DBusMessage *r;
pa_dbus_pending *p;
pa_bluetooth_discovery *y;
+ char *endpoint;
pa_assert(pending);
pa_assert_se(p = userdata);
pa_assert_se(y = p->context_data);
+ pa_assert_se(endpoint = p->call_data);
pa_assert_se(r = dbus_pending_call_steal_reply(pending));
if (dbus_message_is_error(r, DBUS_ERROR_SERVICE_UNKNOWN)) {
goto finish;
}
+ if (dbus_message_is_error(r, PA_BLUETOOTH_ERROR_NOT_SUPPORTED)) {
+ pa_log_info("Couldn't register endpoint %s, because BlueZ is configured to disable the endpoint type.", endpoint);
+ goto finish;
+ }
+
if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
pa_log("Error from RegisterEndpoint reply: %s", dbus_message_get_error_name(r));
goto finish;
PA_LLIST_REMOVE(pa_dbus_pending, y->pending, p);
pa_dbus_pending_free(p);
+
+ pa_xfree(endpoint);
}
static void list_devices_reply(DBusPendingCall *pending, void *userdata) {
if (pa_streq(uuid, HFP_AG_UUID)) {
uint8_t capability = 0;
- uint8_t *caps = &capability;
- pa_dbus_append_basic_array_variant_dict_entry(&d, "Capabilities", DBUS_TYPE_BYTE, &caps, 1);
+ pa_dbus_append_basic_array_variant_dict_entry(&d, "Capabilities", DBUS_TYPE_BYTE, &capability, 1);
} else {
- sbc_capabilities_raw_t capabilities;
- uint8_t *caps = (uint8_t *) &capabilities;
+ a2dp_sbc_t capabilities;
capabilities.channel_mode = BT_A2DP_CHANNEL_MODE_MONO | BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL |
BT_A2DP_CHANNEL_MODE_STEREO | BT_A2DP_CHANNEL_MODE_JOINT_STEREO;
capabilities.min_bitpool = MIN_BITPOOL;
capabilities.max_bitpool = MAX_BITPOOL;
- pa_dbus_append_basic_array_variant_dict_entry(&d, "Capabilities", DBUS_TYPE_BYTE, &caps, sizeof(capabilities));
+ pa_dbus_append_basic_array_variant_dict_entry(&d, "Capabilities", DBUS_TYPE_BYTE, &capabilities, sizeof(capabilities));
}
dbus_message_iter_close_container(&i, &d);
- send_and_add_to_pending(y, NULL, m, register_endpoint_reply);
+ send_and_add_to_pending(y, m, register_endpoint_reply, pa_xstrdup(endpoint));
}
static void found_adapter(pa_bluetooth_discovery *y, const char *path) {
DBusMessage *m;
pa_assert_se(m = dbus_message_new_method_call("org.bluez", path, "org.bluez.Adapter", "ListDevices"));
- send_and_add_to_pending(y, NULL, m, list_devices_reply);
+ send_and_add_to_pending(y, m, list_devices_reply, NULL);
-#ifdef DBUS_TYPE_UNIX_FD
register_endpoint(y, path, HFP_AG_ENDPOINT, HFP_AG_UUID);
register_endpoint(y, path, A2DP_SOURCE_ENDPOINT, A2DP_SOURCE_UUID);
register_endpoint(y, path, A2DP_SINK_ENDPOINT, A2DP_SINK_UUID);
-#endif
}
static void list_adapters_reply(DBusPendingCall *pending, void *userdata) {
pa_assert(y);
pa_assert_se(m = dbus_message_new_method_call("org.bluez", "/", "org.bluez.Manager", "ListAdapters"));
- send_and_add_to_pending(y, NULL, m, list_adapters_reply);
+ send_and_add_to_pending(y, m, list_adapters_reply, NULL);
}
int pa_bluetooth_transport_parse_property(pa_bluetooth_transport *t, DBusMessageIter *i)
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
} else if (dbus_message_is_signal(m, "org.bluez.MediaTransport", "PropertyChanged")) {
pa_bluetooth_device *d;
- pa_bluetooth_transport *t;
+ pa_bluetooth_transport *t = NULL;
void *state = NULL;
DBusMessageIter arg_i;
return -1;
}
-#ifdef DBUS_TYPE_UNIX_FD
if (!dbus_message_get_args(r, &err, DBUS_TYPE_UNIX_FD, &ret, DBUS_TYPE_UINT16, &i, DBUS_TYPE_UINT16, &o, DBUS_TYPE_INVALID)) {
pa_log("Failed to parse org.bluez.MediaTransport.Acquire(): %s", err.message);
ret = -1;
dbus_error_free(&err);
goto fail;
}
-#endif
if (imtu)
*imtu = i;
const char *path, *dev_path = NULL, *uuid = NULL;
uint8_t *config = NULL;
int size = 0;
- pa_bool_t nrec;
+ pa_bool_t nrec = FALSE;
enum profile p;
DBusMessageIter args, props;
DBusMessage *r;
static DBusMessage *endpoint_select_configuration(DBusConnection *c, DBusMessage *m, void *userdata) {
pa_bluetooth_discovery *y = userdata;
- sbc_capabilities_raw_t *cap, config;
+ a2dp_sbc_t *cap, config;
uint8_t *pconf = (uint8_t *) &config;
int i, size;
DBusMessage *r;
goto fail;
}
-#ifdef DBUS_TYPE_UNIX_FD
pa_assert_se(dbus_connection_register_object_path(pa_dbus_connection_get(y->connection), HFP_AG_ENDPOINT, &vtable_endpoint, y));
pa_assert_se(dbus_connection_register_object_path(pa_dbus_connection_get(y->connection), A2DP_SOURCE_ENDPOINT, &vtable_endpoint, y));
pa_assert_se(dbus_connection_register_object_path(pa_dbus_connection_get(y->connection), A2DP_SINK_ENDPOINT, &vtable_endpoint, y));
-#endif
list_adapters(y);
}
if (y->connection) {
-#ifdef DBUS_TYPE_UNIX_FD
dbus_connection_unregister_object_path(pa_dbus_connection_get(y->connection), HFP_AG_ENDPOINT);
dbus_connection_unregister_object_path(pa_dbus_connection_get(y->connection), A2DP_SOURCE_ENDPOINT);
dbus_connection_unregister_object_path(pa_dbus_connection_get(y->connection), A2DP_SINK_ENDPOINT);
-#endif
pa_dbus_remove_matches(pa_dbus_connection_get(y->connection),
"type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0='org.bluez'",
"type='signal',sender='org.bluez',interface='org.bluez.Manager',member='AdapterAdded'",
if (y->filter_added)
dbus_connection_remove_filter(pa_dbus_connection_get(y->connection), filter_cb, y);
- dbus_connection_remove_filter(pa_dbus_connection_get(y->connection), filter_cb, y);
-
pa_dbus_connection_unref(y->connection);
}