134
142
case HEADSET_SVCLASS_ID:
135
143
return enabled.headset;
136
144
case HEADSET_AGW_SVCLASS_ID:
146
case HANDSFREE_SVCLASS_ID:
147
return enabled.headset && enabled.hfp;
148
case HANDSFREE_AGW_SVCLASS_ID:
137
149
return enabled.gateway;
138
case HANDSFREE_SVCLASS_ID:
139
return enabled.headset && enabled.hfp;
140
case HANDSFREE_AGW_SVCLASS_ID:
142
150
case AUDIO_SINK_SVCLASS_ID:
143
151
return enabled.sink;
152
case AUDIO_SOURCE_SVCLASS_ID:
153
return enabled.source;
144
154
case AV_REMOTE_TARGET_SVCLASS_ID:
145
155
case AV_REMOTE_SVCLASS_ID:
146
156
return enabled.control;
184
193
case HEADSET_AGW_SVCLASS_ID:
185
debug("Found Headset AG record");
194
DBG("Found Headset AG record");
187
196
case HANDSFREE_SVCLASS_ID:
188
debug("Found Handsfree record");
197
DBG("Found Handsfree record");
189
198
if (device->headset)
190
199
headset_update(device, uuid16, uuidstr);
192
201
device->headset = headset_init(device, uuid16,
195
204
case HANDSFREE_AGW_SVCLASS_ID:
196
debug("Found Handsfree AG record");
205
DBG("Found Handsfree AG record");
206
if (enabled.gateway && (device->gateway == NULL))
207
device->gateway = gateway_init(device);
198
209
case AUDIO_SINK_SVCLASS_ID:
199
debug("Found Audio Sink");
210
DBG("Found Audio Sink");
200
211
if (device->sink == NULL)
201
212
device->sink = sink_init(device);
203
214
case AUDIO_SOURCE_SVCLASS_ID:
204
debug("Found Audio Source");
215
DBG("Found Audio Source");
216
if (device->source == NULL)
217
device->source = source_init(device);
206
219
case AV_REMOTE_SVCLASS_ID:
207
debug("Found AV Remote");
208
if (device->control == NULL)
209
device->control = control_init(device);
210
if (device->sink && sink_is_active(device))
211
avrcp_connect(device);
213
220
case AV_REMOTE_TARGET_SVCLASS_ID:
214
debug("Found AV Target");
215
if (device->control == NULL)
216
device->control = control_init(device);
221
DBG("Found AV %s", uuid16 == AV_REMOTE_SVCLASS_ID ?
222
"Remote" : "Target");
224
control_update(device, uuid16);
226
device->control = control_init(device, uuid16);
217
227
if (device->sink && sink_is_active(device))
218
228
avrcp_connect(device);
221
debug("Unrecognized UUID: 0x%04X", uuid16);
231
DBG("Unrecognized UUID: 0x%04X", uuid16);
297
307
root = sdp_list_append(0, &root_uuid);
298
308
sdp_set_browse_groups(record, root);
300
sdp_uuid16_create(&svclass_uuid, HEADSET_SVCLASS_ID);
310
sdp_uuid16_create(&svclass_uuid, HANDSFREE_SVCLASS_ID);
301
311
svclass_id = sdp_list_append(0, &svclass_uuid);
302
312
sdp_uuid16_create(&ga_svclass_uuid, GENERIC_AUDIO_SVCLASS_ID);
303
313
svclass_id = sdp_list_append(svclass_id, &ga_svclass_uuid);
304
314
sdp_set_service_classes(record, svclass_id);
306
sdp_uuid16_create(&profile.uuid, HEADSET_PROFILE_ID);
307
profile.version = 0x0100;
316
sdp_uuid16_create(&profile.uuid, HANDSFREE_PROFILE_ID);
317
profile.version = 0x0105;
308
318
pfseq = sdp_list_append(0, &profile);
309
319
sdp_set_profile_descs(record, pfseq);
446
static gboolean hs_preauth_cb(GIOChannel *chan, GIOCondition cond,
449
struct audio_device *device = user_data;
451
DBG("Headset disconnected during authorization");
453
audio_device_cancel_authorization(device, headset_auth_cb, device);
455
headset_set_state(device, HEADSET_STATE_DISCONNECTED);
457
device->hs_preauth_id = 0;
431
462
static void ag_confirm(GIOChannel *chan, gpointer data)
433
464
const char *server_uuid, *remote_uuid;
435
465
struct audio_device *device;
436
466
gboolean hfp_active;
437
467
bdaddr_t src, dst;
454
484
hfp_active = FALSE;
455
485
server_uuid = HSP_AG_UUID;
456
486
remote_uuid = HSP_HS_UUID;
457
svclass = HEADSET_SVCLASS_ID;
459
488
hfp_active = TRUE;
460
489
server_uuid = HFP_AG_UUID;
461
490
remote_uuid = HFP_HS_UUID;
462
svclass = HANDSFREE_SVCLASS_ID;
465
device = manager_get_device(&src, &dst);
493
device = manager_get_device(&src, &dst, TRUE);
469
if (!manager_allow_headset_connection(&device->src)) {
470
debug("Refusing headset: too many existing connections");
497
if (!manager_allow_headset_connection(device)) {
498
DBG("Refusing headset: too many existing connections");
492
headset_set_state(device, HEADSET_STATE_CONNECT_IN_PROGRESS);
520
headset_set_state(device, HEADSET_STATE_CONNECTING);
494
perr = btd_request_authorization(&device->src, &device->dst,
495
server_uuid, auth_cb, device);
522
perr = audio_device_request_authorization(device, server_uuid,
523
headset_auth_cb, device);
497
debug("Authorization denied: %s", strerror(-perr));
525
DBG("Authorization denied: %s", strerror(-perr));
498
526
headset_set_state(device, HEADSET_STATE_DISCONNECTED);
530
device->hs_preauth_id = g_io_add_watch(chan,
531
G_IO_NVAL | G_IO_HUP | G_IO_ERR,
532
hs_preauth_cb, device);
502
534
device->auto_connect = auto_connect;
507
539
g_io_channel_shutdown(chan, TRUE, NULL);
510
static void hs_io_cb(GIOChannel *chan, GError *err, void *data)
542
static void gateway_auth_cb(DBusError *derr, void *user_data)
544
struct audio_device *device = user_data;
546
if (derr && dbus_error_is_set(derr))
547
error("Access denied: %s", derr->message);
551
ba2str(&device->dst, ag_address);
552
DBG("Accepted AG connection from %s for %s",
553
ag_address, device->path);
555
gateway_start_service(device);
559
static void hf_io_cb(GIOChannel *chan, gpointer data)
564
const char *server_uuid, *remote_uuid;
566
struct audio_device *device;
569
bt_io_get(chan, BT_IO_RFCOMM, &err,
570
BT_IO_OPT_SOURCE_BDADDR, &src,
571
BT_IO_OPT_DEST_BDADDR, &dst,
572
BT_IO_OPT_CHANNEL, &ch,
576
error("%s", err->message);
581
server_uuid = HFP_AG_UUID;
582
remote_uuid = HFP_HS_UUID;
583
svclass = HANDSFREE_AGW_SVCLASS_ID;
585
device = manager_get_device(&src, &dst, TRUE);
589
if (!device->gateway) {
590
btd_device_add_uuid(device->btd_dev, remote_uuid);
591
if (!device->gateway)
595
if (gateway_is_connected(device)) {
596
DBG("Refusing new connection since one already exists");
600
if (gateway_connect_rfcomm(device, chan) < 0) {
601
error("Allocating new GIOChannel failed!");
605
perr = audio_device_request_authorization(device, server_uuid,
606
gateway_auth_cb, device);
608
DBG("Authorization denied!");
615
g_io_channel_shutdown(chan, TRUE, NULL);
616
g_io_channel_unref(chan);
516
619
static int headset_server_init(struct audio_adapter *adapter)
528
632
tmp = g_key_file_get_boolean(config, "General", "Master",
531
debug("audio.conf: %s", err->message);
635
DBG("audio.conf: %s", err->message);
532
636
g_clear_error(&err);
641
adapter_get_address(adapter->btd_adapter, &src);
537
643
io = bt_io_listen(BT_IO_RFCOMM, NULL, ag_confirm, adapter, NULL, &err,
538
BT_IO_OPT_SOURCE_BDADDR, &adapter->src,
644
BT_IO_OPT_SOURCE_BDADDR, &src,
539
645
BT_IO_OPT_CHANNEL, chan,
540
646
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
541
647
BT_IO_OPT_MASTER, master,
566
672
chan = DEFAULT_HF_AG_CHANNEL;
568
674
io = bt_io_listen(BT_IO_RFCOMM, NULL, ag_confirm, adapter, NULL, &err,
569
BT_IO_OPT_SOURCE_BDADDR, &adapter->src,
675
BT_IO_OPT_SOURCE_BDADDR, &src,
570
676
BT_IO_OPT_CHANNEL, chan,
571
677
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
572
678
BT_IO_OPT_MASTER, master,
623
730
tmp = g_key_file_get_boolean(config, "General", "Master",
626
debug("audio.conf: %s", err->message);
733
DBG("audio.conf: %s", err->message);
627
734
g_clear_error(&err);
632
io = bt_io_listen(BT_IO_RFCOMM, hs_io_cb, NULL, adapter, NULL, &err,
633
BT_IO_OPT_SOURCE_BDADDR, &adapter->src,
739
adapter_get_address(adapter->btd_adapter, &src);
741
io = bt_io_listen(BT_IO_RFCOMM, NULL, hf_io_cb, adapter, NULL, &err,
742
BT_IO_OPT_SOURCE_BDADDR, &src,
634
743
BT_IO_OPT_CHANNEL, chan,
635
744
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
636
745
BT_IO_OPT_MASTER, master,
644
adapter->hsp_hs_server = io;
646
record = hsp_hs_record(chan);
753
adapter->hfp_hs_server = io;
754
record = hfp_hs_record(chan);
648
756
error("Unable to allocate new service record");
652
if (add_record_to_server(&adapter->src, record) < 0) {
653
error("Unable to register HSP HS service record");
760
if (add_record_to_server(&src, record) < 0) {
761
error("Unable to register HFP HS service record");
654
762
sdp_record_free(record);
655
g_io_channel_unref(adapter->hsp_hs_server);
656
adapter->hsp_hs_server = NULL;
763
g_io_channel_unref(adapter->hfp_hs_server);
764
adapter->hfp_hs_server = NULL;
660
adapter->hsp_hs_record_id = record->handle;
768
adapter->hfp_hs_record_id = record->handle;
696
804
devices = g_slist_remove(devices, dev);
698
806
audio_device_unregister(dev);
701
static struct audio_adapter *create_audio_adapter(const char *path, bdaddr_t *src)
810
static struct audio_adapter *audio_adapter_ref(struct audio_adapter *adp)
814
DBG("%p: ref=%d", adp, adp->ref);
819
static void audio_adapter_unref(struct audio_adapter *adp)
823
DBG("%p: ref=%d", adp, adp->ref);
828
adapters = g_slist_remove(adapters, adp);
829
btd_adapter_unref(adp->btd_adapter);
833
static struct audio_adapter *audio_adapter_create(struct btd_adapter *adapter)
703
835
struct audio_adapter *adp;
705
837
adp = g_new0(struct audio_adapter, 1);
706
adp->path = g_strdup(path);
707
bacpy(&adp->src, src);
838
adp->btd_adapter = btd_adapter_ref(adapter);
840
return audio_adapter_ref(adp);
712
static struct audio_adapter *get_audio_adapter(struct btd_adapter *adapter)
843
static struct audio_adapter *audio_adapter_get(struct btd_adapter *adapter)
714
845
struct audio_adapter *adp;
715
const gchar *path = adapter_get_path(adapter);
718
adapter_get_address(adapter, &src);
720
adp = find_adapter(adapters, path);
847
adp = find_adapter(adapters, adapter);
722
adp = create_audio_adapter(path, &src);
849
adp = audio_adapter_create(adapter);
725
852
adapters = g_slist_append(adapters, adp);
854
audio_adapter_ref(adp);
859
static void state_changed(struct btd_adapter *adapter, gboolean powered)
861
struct audio_adapter *adp;
862
static gboolean telephony = FALSE;
865
DBG("%s powered %s", adapter_get_path(adapter),
866
powered ? "on" : "off");
868
/* ignore powered change, adapter is powering down */
869
if (powered && adapter_powering_down(adapter))
872
adp = find_adapter(adapters, adapter);
876
adp->powered = powered;
879
/* telephony driver already initialized*/
880
if (telephony == TRUE)
887
/* telephony not initialized just ignore power down */
888
if (telephony == FALSE)
891
for (l = adapters; l; l = l->next) {
894
if (adp->powered == TRUE)
731
902
static int headset_server_probe(struct btd_adapter *adapter)
733
904
struct audio_adapter *adp;
734
905
const gchar *path = adapter_get_path(adapter);
736
908
DBG("path %s", path);
738
adp = get_audio_adapter(adapter);
910
adp = audio_adapter_get(adapter);
742
return headset_server_init(adp);
914
err = headset_server_init(adp);
916
audio_adapter_unref(adp);
920
btd_adapter_register_powered_callback(adapter, state_changed);
921
state_changed(adapter, TRUE);
745
926
static void headset_server_remove(struct btd_adapter *adapter)
771
953
if (adp->hfp_ag_server) {
954
g_io_channel_shutdown(adp->hfp_ag_server, TRUE, NULL);
772
955
g_io_channel_unref(adp->hfp_ag_server);
773
956
adp->hfp_ag_server = NULL;
959
btd_adapter_unregister_powered_callback(adapter, state_changed);
961
audio_adapter_unref(adp);
777
964
static int gateway_server_probe(struct btd_adapter *adapter)
779
966
struct audio_adapter *adp;
780
const gchar *path = adapter_get_path(adapter);
782
DBG("path %s", path);
784
adp = get_audio_adapter(adapter);
968
adp = audio_adapter_get(adapter);
796
980
DBG("path %s", path);
798
adp = find_adapter(adapters, path);
982
adp = find_adapter(adapters, adapter);
802
if (adp->hsp_hs_record_id) {
803
remove_record_from_server(adp->hsp_hs_record_id);
804
adp->hsp_hs_record_id = 0;
807
if (adp->hsp_hs_server) {
808
g_io_channel_unref(adp->hsp_hs_server);
809
adp->hsp_hs_server = NULL;
986
if (adp->hfp_hs_record_id) {
987
remove_record_from_server(adp->hfp_hs_record_id);
988
adp->hfp_hs_record_id = 0;
991
if (adp->hfp_hs_server) {
992
g_io_channel_unref(adp->hfp_hs_server);
993
adp->hfp_hs_server = NULL;
996
audio_adapter_unref(adp);
813
999
static int a2dp_server_probe(struct btd_adapter *adapter)
815
1001
struct audio_adapter *adp;
816
1002
const gchar *path = adapter_get_path(adapter);
818
1006
DBG("path %s", path);
820
adp = get_audio_adapter(adapter);
1008
adp = audio_adapter_get(adapter);
824
return a2dp_register(connection, &adp->src, config);
1012
adapter_get_address(adapter, &src);
1014
err = a2dp_register(connection, &src, config);
1016
audio_adapter_unref(adp);
827
1021
static void a2dp_server_remove(struct btd_adapter *adapter)
829
1023
struct audio_adapter *adp;
830
1024
const gchar *path = adapter_get_path(adapter);
832
1027
DBG("path %s", path);
834
adp = find_adapter(adapters, path);
1029
adp = find_adapter(adapters, adapter);
838
return a2dp_unregister(&adp->src);
1033
adapter_get_address(adapter, &src);
1034
a2dp_unregister(&src);
1035
audio_adapter_unref(adp);
841
1038
static int avrcp_server_probe(struct btd_adapter *adapter)
843
1040
struct audio_adapter *adp;
844
1041
const gchar *path = adapter_get_path(adapter);
846
1044
DBG("path %s", path);
848
adp = get_audio_adapter(adapter);
1046
adp = audio_adapter_get(adapter);
852
return avrcp_register(connection, &adp->src, config);
1050
adapter_get_address(adapter, &src);
1052
return avrcp_register(connection, &src, config);
855
1055
static void avrcp_server_remove(struct btd_adapter *adapter)
857
1057
struct audio_adapter *adp;
858
1058
const gchar *path = adapter_get_path(adapter);
860
DBG("path %s", path);
862
adp = find_adapter(adapters, path);
866
return avrcp_unregister(&adp->src);
1061
DBG("path %s", path);
1063
adp = find_adapter(adapters, adapter);
1067
adapter_get_address(adapter, &src);
1068
avrcp_unregister(&src);
1069
audio_adapter_unref(adp);
1072
static int media_server_probe(struct btd_adapter *adapter)
1074
struct audio_adapter *adp;
1075
const gchar *path = adapter_get_path(adapter);
1078
DBG("path %s", path);
1080
adp = audio_adapter_get(adapter);
1084
adapter_get_address(adapter, &src);
1086
return media_register(connection, path, &src);
1089
static void media_server_remove(struct btd_adapter *adapter)
1091
struct audio_adapter *adp;
1092
const gchar *path = adapter_get_path(adapter);
1094
DBG("path %s", path);
1096
adp = find_adapter(adapters, adapter);
1100
media_unregister(path);
1101
audio_adapter_unref(adp);
869
1104
static struct btd_device_driver audio_driver = {