2 This file is part of PulseAudio.
4 Copyright 2008 Joao Paulo Rechi Vita
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include <pulsecore/core-util.h>
27 #include <modules/dbus-util.h>
29 #include "bluetooth-util.h"
37 struct pa_bluetooth_discovery
{
38 DBusConnection
*connection
;
39 PA_LLIST_HEAD(pa_dbus_pending
, pending
);
43 /* If mode == MODE_FIND look for a specific device by its address.
44 If mode == MODE_GET look for a specific device by its path. */
45 const char *looking_for
;
46 pa_bluetooth_device
*found_device
;
48 /* If looking_for is NULL we do long-time discovery */
50 pa_bluetooth_device_callback_t callback
;
51 struct userdata
*userdata
;
54 static pa_bluetooth_uuid
*uuid_new(const char *uuid
) {
57 u
= pa_xnew(pa_bluetooth_uuid
, 1);
58 u
->uuid
= pa_xstrdup(uuid
);
59 PA_LLIST_INIT(pa_bluetooth_uuid
, u
);
64 static void uuid_free(pa_bluetooth_uuid
*u
) {
71 static pa_bluetooth_device
* device_new(const char *path
) {
72 pa_bluetooth_device
*d
;
74 d
= pa_xnew(pa_bluetooth_device
, 1);
76 d
->device_info_valid
= d
->audio_sink_info_valid
= d
->headset_info_valid
= 0;
81 d
->path
= pa_xstrdup(path
);
84 d
->device_connected
= -1;
85 PA_LLIST_HEAD_INIT(pa_bluetooth_uuid
, d
->uuids
);
90 d
->audio_sink_connected
= -1;
92 d
->headset_connected
= -1;
97 void pa_bluetooth_device_free(pa_bluetooth_device
*d
) {
102 while ((u
= d
->uuids
)) {
103 PA_LLIST_REMOVE(pa_bluetooth_uuid
, d
->uuids
, u
);
110 pa_xfree(d
->address
);
114 static pa_bool_t
device_is_loaded(pa_bluetooth_device
*d
) {
117 /* FIXME: e83621724d7939b97b4f01f0d7e965d61ef8e55e, f1daa282f030e4e2381341e0f65faca47c4b891b is borked, probably needs to be reversed */
119 return d
->device_info_valid
&& (d
->audio_sink_info_valid
|| d
->headset_info_valid
);
122 static pa_bool_t
device_is_audio(pa_bluetooth_device
*d
) {
125 pa_assert(d
->device_info_valid
);
126 pa_assert(d
->audio_sink_info_valid
|| d
->headset_info_valid
);
128 /* FIXME: e83621724d7939b97b4f01f0d7e965d61ef8e55e, f1daa282f030e4e2381341e0f65faca47c4b891b is borked, probably needs to be reversed */
130 return d
->device_info_valid
> 0 &&
131 (d
->audio_sink_info_valid
> 0 || d
->headset_info_valid
> 0);
134 static int parse_device_property(pa_bluetooth_discovery
*y
, pa_bluetooth_device
*d
, DBusMessageIter
*i
) {
136 DBusMessageIter variant_i
;
142 if (dbus_message_iter_get_arg_type(i
) != DBUS_TYPE_STRING
) {
143 pa_log("Property name not a string.");
147 dbus_message_iter_get_basic(i
, &key
);
149 if (!dbus_message_iter_next(i
)) {
150 pa_log("Property value missing");
154 if (dbus_message_iter_get_arg_type(i
) != DBUS_TYPE_VARIANT
) {
155 pa_log("Property value not a variant.");
159 dbus_message_iter_recurse(i
, &variant_i
);
161 /* pa_log_debug("Parsing property org.bluez.Device.%s", key); */
163 switch (dbus_message_iter_get_arg_type(&variant_i
)) {
165 case DBUS_TYPE_STRING
: {
168 dbus_message_iter_get_basic(&variant_i
, &value
);
170 if (pa_streq(key
, "Name")) {
172 d
->name
= pa_xstrdup(value
);
173 } else if (pa_streq(key
, "Alias")) {
175 d
->alias
= pa_xstrdup(value
);
176 } else if (pa_streq(key
, "Address")) {
177 pa_xfree(d
->address
);
178 d
->address
= pa_xstrdup(value
);
181 /* pa_log_debug("Value %s", value); */
186 case DBUS_TYPE_BOOLEAN
: {
189 dbus_message_iter_get_basic(&variant_i
, &value
);
191 if (pa_streq(key
, "Paired"))
193 else if (pa_streq(key
, "Connected"))
194 d
->device_connected
= !!value
;
195 else if (pa_streq(key
, "Trusted"))
196 d
->trusted
= !!value
;
198 /* pa_log_debug("Value %s", pa_yes_no(value)); */
203 case DBUS_TYPE_UINT32
: {
206 dbus_message_iter_get_basic(&variant_i
, &value
);
208 if (pa_streq(key
, "Class"))
209 d
->class = (int) value
;
211 /* pa_log_debug("Value %u", (unsigned) value); */
216 case DBUS_TYPE_ARRAY
: {
219 dbus_message_iter_recurse(&variant_i
, &ai
);
221 if (dbus_message_iter_get_arg_type(&ai
) == DBUS_TYPE_STRING
&&
222 pa_streq(key
, "UUIDs")) {
224 while (dbus_message_iter_get_arg_type(&ai
) != DBUS_TYPE_INVALID
) {
225 pa_bluetooth_uuid
*node
;
228 dbus_message_iter_get_basic(&ai
, &value
);
229 node
= uuid_new(value
);
230 PA_LLIST_PREPEND(pa_bluetooth_uuid
, d
->uuids
, node
);
232 if (!dbus_message_iter_next(&ai
))
244 static int parse_audio_property(pa_bluetooth_discovery
*u
, int *connected
, DBusMessageIter
*i
) {
246 DBusMessageIter variant_i
;
249 pa_assert(connected
);
252 if (dbus_message_iter_get_arg_type(i
) != DBUS_TYPE_STRING
) {
253 pa_log("Property name not a string.");
257 dbus_message_iter_get_basic(i
, &key
);
259 if (!dbus_message_iter_next(i
)) {
260 pa_log("Property value missing");
264 if (dbus_message_iter_get_arg_type(i
) != DBUS_TYPE_VARIANT
) {
265 pa_log("Property value not a variant.");
269 dbus_message_iter_recurse(i
, &variant_i
);
271 /* pa_log_debug("Parsing property org.bluez.{AudioSink|Headset}.%s", key); */
273 switch (dbus_message_iter_get_arg_type(&variant_i
)) {
275 case DBUS_TYPE_BOOLEAN
: {
278 dbus_message_iter_get_basic(&variant_i
, &value
);
280 if (pa_streq(key
, "Connected"))
281 *connected
= !!value
;
283 /* pa_log_debug("Value %s", pa_yes_no(value)); */
292 static void run_callback(pa_bluetooth_discovery
*y
, pa_bluetooth_device
*d
, pa_bool_t good
) {
296 if (y
->mode
!= MODE_DISCOVER
)
299 if (!device_is_loaded(d
))
302 if (!device_is_audio(d
))
305 y
->callback(y
->userdata
, d
, good
);
309 static void get_properties_reply(DBusPendingCall
*pending
, void *userdata
) {
311 DBusMessageIter arg_i
, element_i
;
313 pa_bluetooth_device
*d
;
314 pa_bluetooth_discovery
*y
;
317 pa_assert_se(p
= userdata
);
318 pa_assert_se(y
= p
->context_data
);
319 pa_assert_se(r
= dbus_pending_call_steal_reply(pending
));
321 /* pa_log_debug("Got %s.GetProperties response for %s", */
322 /* dbus_message_get_interface(p->message), */
323 /* dbus_message_get_path(p->message)); */
327 valid
= dbus_message_get_type(r
) == DBUS_MESSAGE_TYPE_ERROR
? -1 : 1;
329 if (dbus_message_is_method_call(p
->message
, "org.bluez.Device", "GetProperties"))
330 d
->device_info_valid
= valid
;
331 else if (dbus_message_is_method_call(p
->message
, "org.bluez.Headset", "GetProperties"))
332 d
->headset_info_valid
= valid
;
333 else if (dbus_message_is_method_call(p
->message
, "org.bluez.AudioSink", "GetProperties"))
334 d
->audio_sink_info_valid
= valid
;
336 if (dbus_message_get_type(r
) == DBUS_MESSAGE_TYPE_ERROR
) {
338 if (!dbus_message_is_error(r
, DBUS_ERROR_UNKNOWN_METHOD
))
339 pa_log("Error from GetProperties reply: %s", dbus_message_get_error_name(r
));
344 if (!dbus_message_iter_init(r
, &arg_i
)) {
345 pa_log("GetProperties reply has no arguments.");
349 if (dbus_message_iter_get_arg_type(&arg_i
) != DBUS_TYPE_ARRAY
) {
350 pa_log("GetProperties argument is not an array.");
354 dbus_message_iter_recurse(&arg_i
, &element_i
);
355 while (dbus_message_iter_get_arg_type(&element_i
) != DBUS_TYPE_INVALID
) {
357 if (dbus_message_iter_get_arg_type(&element_i
) == DBUS_TYPE_DICT_ENTRY
) {
358 DBusMessageIter dict_i
;
360 dbus_message_iter_recurse(&element_i
, &dict_i
);
362 if (dbus_message_has_interface(p
->message
, "org.bluez.Device")) {
363 if (parse_device_property(y
, d
, &dict_i
) < 0)
366 } else if (dbus_message_has_interface(p
->message
, "org.bluez.Headset")) {
367 if (parse_audio_property(y
, &d
->headset_connected
, &dict_i
) < 0)
370 } else if (dbus_message_has_interface(p
->message
, "org.bluez.AudioSink")) {
371 if (parse_audio_property(y
, &d
->audio_sink_connected
, &dict_i
) < 0)
376 if (!dbus_message_iter_next(&element_i
))
381 run_callback(y
, d
, TRUE
);
383 dbus_message_unref(r
);
385 PA_LLIST_REMOVE(pa_dbus_pending
, y
->pending
, p
);
386 pa_dbus_pending_free(p
);
389 static pa_dbus_pending
* send_and_add_to_pending(pa_bluetooth_discovery
*y
, pa_bluetooth_device
*d
, DBusMessage
*m
, DBusPendingCallNotifyFunction func
) {
391 DBusPendingCall
*call
;
396 pa_assert_se(dbus_connection_send_with_reply(y
->connection
, m
, &call
, -1));
398 p
= pa_dbus_pending_new(m
, call
, y
, d
);
399 PA_LLIST_PREPEND(pa_dbus_pending
, y
->pending
, p
);
400 dbus_pending_call_set_notify(call
, func
, p
, NULL
);
405 static void found_device(pa_bluetooth_discovery
*y
, const char* path
) {
407 pa_bluetooth_device
*d
;
412 d
= device_new(path
);
414 if (y
->mode
== MODE_DISCOVER
) {
415 pa_assert(y
->devices
);
416 pa_hashmap_put(y
->devices
, d
->path
, d
);
418 pa_assert(!y
->found_device
);
422 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", path
, "org.bluez.Device", "GetProperties"));
423 send_and_add_to_pending(y
, d
, m
, get_properties_reply
);
425 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", path
, "org.bluez.Headset", "GetProperties"));
426 send_and_add_to_pending(y
, d
, m
, get_properties_reply
);
428 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", path
, "org.bluez.AudioSink", "GetProperties"));
429 send_and_add_to_pending(y
, d
, m
, get_properties_reply
);
432 static void list_devices_reply(DBusPendingCall
*pending
, void *userdata
) {
438 pa_bluetooth_discovery
*y
;
444 pa_assert_se(p
= userdata
);
445 pa_assert_se(y
= p
->context_data
);
446 pa_assert_se(r
= dbus_pending_call_steal_reply(pending
));
448 if (dbus_message_get_type(r
) == DBUS_MESSAGE_TYPE_ERROR
) {
449 pa_log("Error from ListDevices reply: %s", dbus_message_get_error_name(r
));
453 if (!dbus_message_get_args(r
, &e
, DBUS_TYPE_ARRAY
, DBUS_TYPE_OBJECT_PATH
, &paths
, &num
, DBUS_TYPE_INVALID
)) {
454 pa_log("org.bluez.Adapter.ListDevices returned an error: '%s'\n", e
.message
);
459 for (i
= 0; i
< num
; ++i
)
460 found_device(y
, paths
[i
]);
465 dbus_free_string_array (paths
);
467 dbus_message_unref(r
);
469 PA_LLIST_REMOVE(pa_dbus_pending
, y
->pending
, p
);
470 pa_dbus_pending_free(p
);
473 static void find_device_reply(DBusPendingCall
*pending
, void *userdata
) {
478 pa_bluetooth_discovery
*y
;
484 pa_assert_se(p
= userdata
);
485 pa_assert_se(y
= p
->context_data
);
486 pa_assert_se(r
= dbus_pending_call_steal_reply(pending
));
488 if (dbus_message_get_type(r
) == DBUS_MESSAGE_TYPE_ERROR
) {
489 pa_log("Error from FindDevice reply: %s", dbus_message_get_error_name(r
));
493 if (!dbus_message_get_args(r
, &e
, DBUS_TYPE_OBJECT_PATH
, &path
, DBUS_TYPE_INVALID
)) {
494 pa_log("org.bluez.Adapter.FindDevice returned an error: '%s'\n", e
.message
);
497 found_device(y
, path
);
500 dbus_message_unref(r
);
502 PA_LLIST_REMOVE(pa_dbus_pending
, y
->pending
, p
);
503 pa_dbus_pending_free(p
);
506 static void found_adapter(pa_bluetooth_discovery
*y
, const char *path
) {
509 if (y
->mode
== MODE_FIND
) {
510 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", path
, "org.bluez.Adapter", "FindDevice"));
512 pa_assert_se(dbus_message_append_args(m
,
513 DBUS_TYPE_STRING
, &y
->looking_for
,
516 send_and_add_to_pending(y
, NULL
, m
, find_device_reply
);
519 pa_assert(y
->mode
== MODE_DISCOVER
);
521 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", path
, "org.bluez.Adapter", "ListDevices"));
522 send_and_add_to_pending(y
, NULL
, m
, list_devices_reply
);
526 static void list_adapters_reply(DBusPendingCall
*pending
, void *userdata
) {
532 pa_bluetooth_discovery
*y
;
538 pa_assert_se(p
= userdata
);
539 pa_assert_se(y
= p
->context_data
);
540 pa_assert_se(r
= dbus_pending_call_steal_reply(pending
));
542 if (dbus_message_get_type(r
) == DBUS_MESSAGE_TYPE_ERROR
) {
543 pa_log("Error from ListAdapters reply: %s", dbus_message_get_error_name(r
));
547 if (!dbus_message_get_args(r
, &e
, DBUS_TYPE_ARRAY
, DBUS_TYPE_OBJECT_PATH
, &paths
, &num
, DBUS_TYPE_INVALID
)) {
548 pa_log("org.bluez.Manager.ListAdapters returned an error: %s", e
.message
);
553 for (i
= 0; i
< num
; ++i
)
554 found_adapter(y
, paths
[i
]);
559 dbus_free_string_array (paths
);
561 dbus_message_unref(r
);
563 PA_LLIST_REMOVE(pa_dbus_pending
, y
->pending
, p
);
564 pa_dbus_pending_free(p
);
567 static void list_adapters(pa_bluetooth_discovery
*y
) {
571 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", "/", "org.bluez.Manager", "ListAdapters"));
572 send_and_add_to_pending(y
, NULL
, m
, list_adapters_reply
);
575 static DBusHandlerResult
filter_cb(DBusConnection
*bus
, DBusMessage
*m
, void *userdata
) {
577 pa_bluetooth_discovery
*y
;
582 pa_assert_se(y
= userdata
);
584 dbus_error_init(&err
);
586 pa_log_debug("dbus: interface=%s, path=%s, member=%s\n",
587 dbus_message_get_interface(m
),
588 dbus_message_get_path(m
),
589 dbus_message_get_member(m
));
591 if (dbus_message_is_signal(m
, "org.bluez.Adapter", "DeviceRemoved")) {
593 pa_bluetooth_device
*d
;
595 if (!dbus_message_get_args(m
, &err
, DBUS_TYPE_OBJECT_PATH
, &path
, DBUS_TYPE_INVALID
)) {
596 pa_log("Failed to parse org.bluez.Adapter.DeviceRemoved: %s", err
.message
);
600 pa_log_debug("Device %s removed", path
);
602 if ((d
= pa_hashmap_remove(y
->devices
, path
))) {
604 pa_assert_se(y
->mode
== MODE_DISCOVER
);
605 run_callback(y
, d
, FALSE
);
607 pa_bluetooth_device_free(d
);
610 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
612 } else if (dbus_message_is_signal(m
, "org.bluez.Adapter", "DeviceCreated")) {
615 if (!dbus_message_get_args(m
, &err
, DBUS_TYPE_OBJECT_PATH
, &path
, DBUS_TYPE_INVALID
)) {
616 pa_log("Failed to parse org.bluez.Adapter.DeviceCreated: %s", err
.message
);
620 pa_log_debug("Device %s created", path
);
622 found_device(y
, path
);
623 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
625 } else if (dbus_message_is_signal(m
, "org.bluez.Manager", "AdapterAdded")) {
628 if (!dbus_message_get_args(m
, &err
, DBUS_TYPE_OBJECT_PATH
, &path
, DBUS_TYPE_INVALID
)) {
629 pa_log("Failed to parse org.bluez.Manager.AdapterAdded: %s", err
.message
);
633 pa_log_debug("Adapter %s created", path
);
635 found_adapter(y
, path
);
636 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
638 } else if (dbus_message_is_signal(m
, "org.bluez.Headset", "PropertyChanged") ||
639 dbus_message_is_signal(m
, "org.bluez.AudioSink", "PropertyChanged") ||
640 dbus_message_is_signal(m
, "org.bluez.Device", "PropertyChanged")) {
642 pa_bluetooth_device
*d
;
644 if ((d
= pa_hashmap_get(y
->devices
, dbus_message_get_path(m
)))) {
645 DBusMessageIter arg_i
;
647 if (!dbus_message_iter_init(m
, &arg_i
)) {
648 pa_log("Failed to parse PropertyChanged: %s", err
.message
);
652 if (dbus_message_has_interface(m
, "org.bluez.Device")) {
653 if (parse_device_property(y
, d
, &arg_i
) < 0)
656 } else if (dbus_message_has_interface(m
, "org.bluez.Headset")) {
657 if (parse_audio_property(y
, &d
->headset_connected
, &arg_i
) < 0)
659 d
->headset_info_valid
= 1;
661 } else if (dbus_message_has_interface(m
, "org.bluez.AudioSink")) {
662 if (parse_audio_property(y
, &d
->audio_sink_connected
, &arg_i
) < 0)
664 d
->audio_sink_info_valid
= 1;
667 pa_assert_se(y
->mode
== MODE_DISCOVER
);
668 run_callback(y
, d
, TRUE
);
671 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
675 dbus_error_free(&err
);
677 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
680 pa_bluetooth_device
* pa_bluetooth_find_device(DBusConnection
*c
, const char* address
) {
681 pa_bluetooth_discovery y
;
683 memset(&y
, 0, sizeof(y
));
685 y
.looking_for
= address
;
687 PA_LLIST_HEAD_INIT(pa_dbus_pending
, y
.pending
);
691 pa_dbus_sync_pending_list(&y
.pending
);
692 pa_assert(!y
.pending
);
694 if (y
.found_device
) {
695 pa_assert(device_is_loaded(y
.found_device
));
697 if (!device_is_audio(y
.found_device
)) {
698 pa_bluetooth_device_free(y
.found_device
);
703 return y
.found_device
;
706 pa_bluetooth_device
* pa_bluetooth_get_device(DBusConnection
*c
, const char* path
) {
707 pa_bluetooth_discovery y
;
709 memset(&y
, 0, sizeof(y
));
712 PA_LLIST_HEAD_INIT(pa_dbus_pending
, y
.pending
);
714 found_device(&y
, path
);
716 pa_dbus_sync_pending_list(&y
.pending
);
717 pa_assert(!y
.pending
);
719 if (y
.found_device
) {
720 pa_assert(device_is_loaded(y
.found_device
));
722 if (!device_is_audio(y
.found_device
)) {
723 pa_bluetooth_device_free(y
.found_device
);
728 return y
.found_device
;
731 pa_bluetooth_discovery
* pa_bluetooth_discovery_new(DBusConnection
*c
, pa_bluetooth_device_callback_t cb
, struct userdata
*u
) {
733 pa_bluetooth_discovery
*y
;
738 dbus_error_init(&err
);
740 y
= pa_xnew0(pa_bluetooth_discovery
, 1);
741 y
->mode
= MODE_DISCOVER
;
745 y
->devices
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
746 PA_LLIST_HEAD_INIT(pa_dbus_pending
, y
->pending
);
748 /* dynamic detection of bluetooth audio devices */
749 if (!dbus_connection_add_filter(c
, filter_cb
, y
, NULL
)) {
750 pa_log_error("Failed to add filter function");
754 if (pa_dbus_add_matches(
756 "type='signal',sender='org.bluez',interface='org.bluez.Manager',member='AdapterAdded'",
757 "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceRemoved'",
758 "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceCreated'",
759 "type='signal',sender='org.bluez',interface='org.bluez.Device',member='PropertyChanged'",
760 "type='signal',sender='org.bluez',interface='org.bluez.Headset',member='PropertyChanged'",
761 "type='signal',sender='org.bluez',interface='org.bluez.AudioSink',member='PropertyChanged'", NULL
) < 0) {
762 pa_log("Failed to add D-Bus matches: %s", err
.message
);
771 dbus_error_free(&err
);
775 void pa_bluetooth_discovery_free(pa_bluetooth_discovery
*y
) {
776 pa_bluetooth_device
*d
;
780 pa_dbus_free_pending_list(&y
->pending
);
783 while ((d
= pa_hashmap_steal_first(y
->devices
))) {
784 run_callback(y
, d
, FALSE
);
785 pa_bluetooth_device_free(d
);
788 pa_hashmap_free(y
->devices
, NULL
, NULL
);
792 pa_dbus_remove_matches(y
->connection
,
793 "type='signal',sender='org.bluez',interface='org.bluez.Manager',member='AdapterAdded'",
794 "type='signal',sender='org.bluez',interface='org.bluez.Manager',member='AdapterRemoved'",
795 "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceRemoved'",
796 "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceCreated'",
797 "type='signal',sender='org.bluez',interface='org.bluez.Device',member='PropertyChanged'",
798 "type='signal',sender='org.bluez',interface='org.bluez.Headset',member='PropertyChanged'",
799 "type='signal',sender='org.bluez',interface='org.bluez.AudioSink',member='PropertyChanged'", NULL
);
801 dbus_connection_remove_filter(y
->connection
, filter_cb
, y
);
805 void pa_bluetooth_discovery_sync(pa_bluetooth_discovery
*y
) {
808 pa_dbus_sync_pending_list(&y
->pending
);
811 const char*pa_bluetooth_get_form_factor(uint32_t class) {
815 static const char * const table
[] = {
826 if (((class >> 8) & 31) != 4)
829 if ((i
= (class >> 2) & 63) > PA_ELEMENTSOF(table
))
835 pa_log_debug("Unknown Bluetooth minor device class %u", i
);
840 char *pa_bluetooth_cleanup_name(const char *name
) {
842 pa_bool_t space
= FALSE
;
846 while ((*name
>= 1 && *name
<= 32) || *name
>= 127)
849 t
= pa_xstrdup(name
);
851 for (s
= d
= t
; *s
; s
++) {
853 if (*s
<= 32 || *s
>= 127 || *s
== '_') {