2007-03-10 06:32:47 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* BlueZ - Bluetooth protocol stack for Linux
|
|
|
|
*
|
2007-10-24 01:17:47 +08:00
|
|
|
* Copyright (C) 2006-2007 Nokia Corporation
|
2009-01-02 02:33:20 +08:00
|
|
|
* Copyright (C) 2004-2009 Marcel Holtmann <marcel@holtmann.org>
|
2007-03-10 06:32:47 +08:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2007-04-09 09:14:21 +08:00
|
|
|
#include <stdio.h>
|
2007-05-19 09:18:39 +08:00
|
|
|
#include <stdlib.h>
|
2007-05-31 17:23:17 +08:00
|
|
|
#include <stdarg.h>
|
2007-04-09 09:14:21 +08:00
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
2008-09-10 20:35:45 +08:00
|
|
|
#include <fcntl.h>
|
2007-04-10 19:44:10 +08:00
|
|
|
#include <stdint.h>
|
2007-06-23 07:50:24 +08:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <ctype.h>
|
2007-07-21 02:03:20 +08:00
|
|
|
#include <signal.h>
|
2007-04-09 09:14:21 +08:00
|
|
|
|
2007-04-10 19:44:10 +08:00
|
|
|
#include <bluetooth/bluetooth.h>
|
2007-06-23 07:50:24 +08:00
|
|
|
#include <bluetooth/hci.h>
|
|
|
|
#include <bluetooth/hci_lib.h>
|
2007-04-10 19:44:10 +08:00
|
|
|
#include <bluetooth/rfcomm.h>
|
2007-05-19 09:18:39 +08:00
|
|
|
#include <bluetooth/sdp.h>
|
|
|
|
#include <bluetooth/sdp_lib.h>
|
2007-04-10 19:44:10 +08:00
|
|
|
|
2007-04-09 09:14:21 +08:00
|
|
|
#include <glib.h>
|
2007-04-09 07:19:19 +08:00
|
|
|
#include <dbus/dbus.h>
|
2008-05-09 06:19:14 +08:00
|
|
|
#include <gdbus.h>
|
2007-04-09 07:19:19 +08:00
|
|
|
|
2008-05-01 21:52:26 +08:00
|
|
|
#include "glib-helper.h"
|
2009-02-19 06:17:54 +08:00
|
|
|
#include "btio.h"
|
2008-10-08 20:09:25 +08:00
|
|
|
#include "../src/manager.h"
|
2008-07-30 02:35:12 +08:00
|
|
|
#include "../src/adapter.h"
|
|
|
|
#include "../src/device.h"
|
2008-05-01 21:52:26 +08:00
|
|
|
|
2007-04-09 09:14:21 +08:00
|
|
|
#include "logging.h"
|
2007-06-23 07:50:24 +08:00
|
|
|
#include "textfile.h"
|
2007-08-13 16:14:22 +08:00
|
|
|
#include "ipc.h"
|
2007-08-13 07:58:15 +08:00
|
|
|
#include "device.h"
|
2007-06-23 04:58:12 +08:00
|
|
|
#include "error.h"
|
2007-08-11 19:05:24 +08:00
|
|
|
#include "avdtp.h"
|
2007-08-13 16:14:22 +08:00
|
|
|
#include "a2dp.h"
|
2007-08-13 07:58:15 +08:00
|
|
|
#include "headset.h"
|
|
|
|
#include "gateway.h"
|
|
|
|
#include "sink.h"
|
2007-10-22 22:11:04 +08:00
|
|
|
#include "control.h"
|
2007-08-13 07:58:15 +08:00
|
|
|
#include "manager.h"
|
2008-03-28 07:07:19 +08:00
|
|
|
#include "sdpd.h"
|
2008-09-03 19:06:40 +08:00
|
|
|
#include "telephony.h"
|
2007-03-10 06:32:47 +08:00
|
|
|
|
2007-05-31 17:23:17 +08:00
|
|
|
typedef enum {
|
|
|
|
HEADSET = 1 << 0,
|
|
|
|
GATEWAY = 1 << 1,
|
|
|
|
SINK = 1 << 2,
|
|
|
|
SOURCE = 1 << 3,
|
|
|
|
CONTROL = 1 << 4,
|
|
|
|
TARGET = 1 << 5,
|
|
|
|
INVALID = 1 << 6
|
|
|
|
} audio_service_type;
|
|
|
|
|
2007-05-19 09:18:39 +08:00
|
|
|
typedef enum {
|
|
|
|
GENERIC_AUDIO = 0,
|
|
|
|
ADVANCED_AUDIO,
|
|
|
|
AV_REMOTE,
|
|
|
|
GET_RECORDS
|
|
|
|
} audio_sdp_state_t;
|
|
|
|
|
2008-08-13 05:59:36 +08:00
|
|
|
struct audio_adapter {
|
2009-05-27 03:20:20 +08:00
|
|
|
struct btd_adapter *btd_adapter;
|
2008-08-13 05:59:36 +08:00
|
|
|
uint32_t hsp_ag_record_id;
|
|
|
|
uint32_t hfp_ag_record_id;
|
2009-04-03 11:49:47 +08:00
|
|
|
uint32_t hfp_hs_record_id;
|
2008-08-13 05:59:36 +08:00
|
|
|
GIOChannel *hsp_ag_server;
|
|
|
|
GIOChannel *hfp_ag_server;
|
2009-04-03 11:49:47 +08:00
|
|
|
GIOChannel *hfp_hs_server;
|
2009-05-27 03:20:20 +08:00
|
|
|
gint ref;
|
2007-05-19 09:18:39 +08:00
|
|
|
};
|
|
|
|
|
2009-03-28 01:10:04 +08:00
|
|
|
static gboolean auto_connect = TRUE;
|
2008-10-24 17:19:47 +08:00
|
|
|
static int max_connected_headsets = 1;
|
2007-04-12 06:46:22 +08:00
|
|
|
static DBusConnection *connection = NULL;
|
2008-08-13 05:59:36 +08:00
|
|
|
static GKeyFile *config = NULL;
|
|
|
|
static GSList *adapters = NULL;
|
2007-05-15 20:45:35 +08:00
|
|
|
static GSList *devices = NULL;
|
2007-04-09 07:19:19 +08:00
|
|
|
|
2008-01-16 17:08:26 +08:00
|
|
|
static struct enabled_interfaces enabled = {
|
2008-10-10 20:53:30 +08:00
|
|
|
.hfp = TRUE,
|
2008-01-16 17:08:26 +08:00
|
|
|
.headset = TRUE,
|
|
|
|
.gateway = FALSE,
|
|
|
|
.sink = TRUE,
|
|
|
|
.source = FALSE,
|
|
|
|
.control = TRUE,
|
|
|
|
};
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
static struct audio_adapter *find_adapter(GSList *list,
|
|
|
|
struct btd_adapter *btd_adapter)
|
2008-08-13 05:59:36 +08:00
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
for (l = list; l; l = l->next) {
|
|
|
|
struct audio_adapter *adapter = l->data;
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
if (adapter->btd_adapter == btd_adapter)
|
2008-08-13 05:59:36 +08:00
|
|
|
return adapter;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean server_is_enabled(bdaddr_t *src, uint16_t svc)
|
2007-07-21 02:03:20 +08:00
|
|
|
{
|
|
|
|
switch (svc) {
|
|
|
|
case HEADSET_SVCLASS_ID:
|
2008-10-10 20:53:30 +08:00
|
|
|
return enabled.headset;
|
2008-04-21 20:49:16 +08:00
|
|
|
case HEADSET_AGW_SVCLASS_ID:
|
2009-06-20 03:08:49 +08:00
|
|
|
return FALSE;
|
2007-07-21 02:03:20 +08:00
|
|
|
case HANDSFREE_SVCLASS_ID:
|
2008-10-10 20:53:30 +08:00
|
|
|
return enabled.headset && enabled.hfp;
|
2008-04-21 20:49:16 +08:00
|
|
|
case HANDSFREE_AGW_SVCLASS_ID:
|
2009-04-03 11:49:47 +08:00
|
|
|
return enabled.gateway;
|
2007-08-11 19:05:24 +08:00
|
|
|
case AUDIO_SINK_SVCLASS_ID:
|
2008-01-16 17:08:26 +08:00
|
|
|
return enabled.sink;
|
2007-10-22 22:11:04 +08:00
|
|
|
case AV_REMOTE_TARGET_SVCLASS_ID:
|
|
|
|
case AV_REMOTE_SVCLASS_ID:
|
2008-01-16 17:08:26 +08:00
|
|
|
return enabled.control;
|
2007-07-21 02:03:20 +08:00
|
|
|
default:
|
2008-10-10 20:53:30 +08:00
|
|
|
return FALSE;
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-09 20:11:16 +08:00
|
|
|
static void handle_uuid(const char *uuidstr, struct audio_device *device)
|
2007-05-19 09:18:39 +08:00
|
|
|
{
|
2008-10-09 20:11:16 +08:00
|
|
|
uuid_t uuid;
|
2007-05-19 09:18:39 +08:00
|
|
|
uint16_t uuid16;
|
|
|
|
|
2008-10-09 20:11:16 +08:00
|
|
|
if (bt_string2uuid(&uuid, uuidstr) < 0) {
|
|
|
|
error("%s not detected as an UUID-128", uuidstr);
|
|
|
|
return;
|
|
|
|
}
|
2007-05-19 09:18:39 +08:00
|
|
|
|
2008-10-09 20:11:16 +08:00
|
|
|
if (!sdp_uuid128_to_uuid(&uuid) && uuid.type != SDP_UUID16) {
|
|
|
|
error("Could not convert %s to a UUID-16", uuidstr);
|
2007-07-21 02:03:20 +08:00
|
|
|
return;
|
2008-10-09 20:11:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uuid16 = uuid.value.uuid16;
|
|
|
|
|
|
|
|
if (!server_is_enabled(&device->src, uuid16)) {
|
|
|
|
debug("audio handle_uuid: server not enabled for %s (0x%04x)",
|
|
|
|
uuidstr, uuid16);
|
|
|
|
return;
|
|
|
|
}
|
2007-07-21 02:03:20 +08:00
|
|
|
|
2007-05-19 09:18:39 +08:00
|
|
|
switch (uuid16) {
|
|
|
|
case HEADSET_SVCLASS_ID:
|
|
|
|
debug("Found Headset record");
|
|
|
|
if (device->headset)
|
2008-10-09 20:11:16 +08:00
|
|
|
headset_update(device, uuid16, uuidstr);
|
2007-05-19 09:18:39 +08:00
|
|
|
else
|
2008-10-09 20:11:16 +08:00
|
|
|
device->headset = headset_init(device, uuid16,
|
|
|
|
uuidstr);
|
2007-05-19 09:18:39 +08:00
|
|
|
break;
|
|
|
|
case HEADSET_AGW_SVCLASS_ID:
|
|
|
|
debug("Found Headset AG record");
|
|
|
|
break;
|
|
|
|
case HANDSFREE_SVCLASS_ID:
|
2008-10-08 22:36:43 +08:00
|
|
|
debug("Found Handsfree record");
|
2007-06-19 05:08:35 +08:00
|
|
|
if (device->headset)
|
2008-10-09 20:11:16 +08:00
|
|
|
headset_update(device, uuid16, uuidstr);
|
2007-06-19 05:08:35 +08:00
|
|
|
else
|
2008-10-09 20:11:16 +08:00
|
|
|
device->headset = headset_init(device, uuid16,
|
|
|
|
uuidstr);
|
2007-05-19 09:18:39 +08:00
|
|
|
break;
|
|
|
|
case HANDSFREE_AGW_SVCLASS_ID:
|
|
|
|
debug("Found Handsfree AG record");
|
2009-04-03 11:49:47 +08:00
|
|
|
if (device->gateway == NULL)
|
|
|
|
device->gateway = gateway_init(device);
|
2007-05-19 09:18:39 +08:00
|
|
|
break;
|
|
|
|
case AUDIO_SINK_SVCLASS_ID:
|
|
|
|
debug("Found Audio Sink");
|
2007-08-11 19:05:24 +08:00
|
|
|
if (device->sink == NULL)
|
|
|
|
device->sink = sink_init(device);
|
2007-05-19 09:18:39 +08:00
|
|
|
break;
|
|
|
|
case AUDIO_SOURCE_SVCLASS_ID:
|
|
|
|
debug("Found Audio Source");
|
|
|
|
break;
|
|
|
|
case AV_REMOTE_SVCLASS_ID:
|
|
|
|
case AV_REMOTE_TARGET_SVCLASS_ID:
|
2009-04-23 06:27:27 +08:00
|
|
|
debug("Found AV %s", uuid16 == AV_REMOTE_SVCLASS_ID ?
|
|
|
|
"Remote" : "Target");
|
|
|
|
if (device->control)
|
|
|
|
control_update(device, uuid16);
|
|
|
|
else
|
|
|
|
device->control = control_init(device, uuid16);
|
2007-10-23 15:54:36 +08:00
|
|
|
if (device->sink && sink_is_active(device))
|
|
|
|
avrcp_connect(device);
|
2007-05-19 09:18:39 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
debug("Unrecognized UUID: 0x%04X", uuid16);
|
|
|
|
break;
|
|
|
|
}
|
2007-06-28 01:03:07 +08:00
|
|
|
}
|
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
static sdp_record_t *hsp_ag_record(uint8_t ch)
|
2007-07-21 02:03:20 +08:00
|
|
|
{
|
|
|
|
sdp_list_t *svclass_id, *pfseq, *apseq, *root;
|
|
|
|
uuid_t root_uuid, svclass_uuid, ga_svclass_uuid;
|
|
|
|
uuid_t l2cap_uuid, rfcomm_uuid;
|
|
|
|
sdp_profile_desc_t profile;
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_record_t *record;
|
2007-07-21 02:03:20 +08:00
|
|
|
sdp_list_t *aproto, *proto[2];
|
|
|
|
sdp_data_t *channel;
|
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
record = sdp_record_alloc();
|
|
|
|
if (!record)
|
|
|
|
return NULL;
|
2007-07-21 02:03:20 +08:00
|
|
|
|
|
|
|
sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP);
|
|
|
|
root = sdp_list_append(0, &root_uuid);
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_set_browse_groups(record, root);
|
2007-07-21 02:03:20 +08:00
|
|
|
|
|
|
|
sdp_uuid16_create(&svclass_uuid, HEADSET_AGW_SVCLASS_ID);
|
|
|
|
svclass_id = sdp_list_append(0, &svclass_uuid);
|
|
|
|
sdp_uuid16_create(&ga_svclass_uuid, GENERIC_AUDIO_SVCLASS_ID);
|
|
|
|
svclass_id = sdp_list_append(svclass_id, &ga_svclass_uuid);
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_set_service_classes(record, svclass_id);
|
2007-07-21 02:03:20 +08:00
|
|
|
|
|
|
|
sdp_uuid16_create(&profile.uuid, HEADSET_PROFILE_ID);
|
2009-03-03 06:19:08 +08:00
|
|
|
profile.version = 0x0102;
|
2007-07-21 02:03:20 +08:00
|
|
|
pfseq = sdp_list_append(0, &profile);
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_set_profile_descs(record, pfseq);
|
2007-07-21 02:03:20 +08:00
|
|
|
|
|
|
|
sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID);
|
|
|
|
proto[0] = sdp_list_append(0, &l2cap_uuid);
|
|
|
|
apseq = sdp_list_append(0, proto[0]);
|
|
|
|
|
|
|
|
sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID);
|
|
|
|
proto[1] = sdp_list_append(0, &rfcomm_uuid);
|
|
|
|
channel = sdp_data_alloc(SDP_UINT8, &ch);
|
|
|
|
proto[1] = sdp_list_append(proto[1], channel);
|
|
|
|
apseq = sdp_list_append(apseq, proto[1]);
|
|
|
|
|
|
|
|
aproto = sdp_list_append(0, apseq);
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_set_access_protos(record, aproto);
|
2007-07-21 02:03:20 +08:00
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_set_info_attr(record, "Headset Audio Gateway", 0, 0);
|
2007-07-21 02:03:20 +08:00
|
|
|
|
|
|
|
sdp_data_free(channel);
|
|
|
|
sdp_list_free(proto[0], 0);
|
|
|
|
sdp_list_free(proto[1], 0);
|
|
|
|
sdp_list_free(apseq, 0);
|
|
|
|
sdp_list_free(pfseq, 0);
|
|
|
|
sdp_list_free(aproto, 0);
|
|
|
|
sdp_list_free(root, 0);
|
|
|
|
sdp_list_free(svclass_id, 0);
|
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
return record;
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
|
|
|
|
2009-04-03 11:49:47 +08:00
|
|
|
static sdp_record_t *hfp_hs_record(uint8_t ch)
|
2008-04-21 20:49:16 +08:00
|
|
|
{
|
|
|
|
sdp_list_t *svclass_id, *pfseq, *apseq, *root;
|
|
|
|
uuid_t root_uuid, svclass_uuid, ga_svclass_uuid;
|
|
|
|
uuid_t l2cap_uuid, rfcomm_uuid;
|
|
|
|
sdp_profile_desc_t profile;
|
|
|
|
sdp_record_t *record;
|
|
|
|
sdp_list_t *aproto, *proto[2];
|
|
|
|
sdp_data_t *channel;
|
|
|
|
|
|
|
|
record = sdp_record_alloc();
|
|
|
|
if (!record)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP);
|
|
|
|
root = sdp_list_append(0, &root_uuid);
|
|
|
|
sdp_set_browse_groups(record, root);
|
|
|
|
|
2009-04-03 11:49:47 +08:00
|
|
|
sdp_uuid16_create(&svclass_uuid, HANDSFREE_SVCLASS_ID);
|
2008-04-21 20:49:16 +08:00
|
|
|
svclass_id = sdp_list_append(0, &svclass_uuid);
|
|
|
|
sdp_uuid16_create(&ga_svclass_uuid, GENERIC_AUDIO_SVCLASS_ID);
|
|
|
|
svclass_id = sdp_list_append(svclass_id, &ga_svclass_uuid);
|
|
|
|
sdp_set_service_classes(record, svclass_id);
|
|
|
|
|
2009-04-03 11:49:47 +08:00
|
|
|
sdp_uuid16_create(&profile.uuid, HANDSFREE_PROFILE_ID);
|
2008-04-21 20:49:16 +08:00
|
|
|
profile.version = 0x0100;
|
|
|
|
pfseq = sdp_list_append(0, &profile);
|
|
|
|
sdp_set_profile_descs(record, pfseq);
|
|
|
|
|
|
|
|
sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID);
|
|
|
|
proto[0] = sdp_list_append(0, &l2cap_uuid);
|
|
|
|
apseq = sdp_list_append(0, proto[0]);
|
|
|
|
|
|
|
|
sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID);
|
|
|
|
proto[1] = sdp_list_append(0, &rfcomm_uuid);
|
|
|
|
channel = sdp_data_alloc(SDP_UINT8, &ch);
|
|
|
|
proto[1] = sdp_list_append(proto[1], channel);
|
|
|
|
apseq = sdp_list_append(apseq, proto[1]);
|
|
|
|
|
|
|
|
aproto = sdp_list_append(0, apseq);
|
|
|
|
sdp_set_access_protos(record, aproto);
|
|
|
|
|
2009-04-03 11:49:47 +08:00
|
|
|
sdp_set_info_attr(record, "Hands-Free", 0, 0);
|
2008-04-21 20:49:16 +08:00
|
|
|
|
|
|
|
sdp_data_free(channel);
|
|
|
|
sdp_list_free(proto[0], 0);
|
|
|
|
sdp_list_free(proto[1], 0);
|
|
|
|
sdp_list_free(apseq, 0);
|
|
|
|
sdp_list_free(pfseq, 0);
|
|
|
|
sdp_list_free(aproto, 0);
|
|
|
|
sdp_list_free(root, 0);
|
|
|
|
sdp_list_free(svclass_id, 0);
|
|
|
|
|
|
|
|
return record;
|
|
|
|
}
|
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
static sdp_record_t *hfp_ag_record(uint8_t ch, uint32_t feat)
|
2007-07-21 02:03:20 +08:00
|
|
|
{
|
|
|
|
sdp_list_t *svclass_id, *pfseq, *apseq, *root;
|
|
|
|
uuid_t root_uuid, svclass_uuid, ga_svclass_uuid;
|
|
|
|
uuid_t l2cap_uuid, rfcomm_uuid;
|
|
|
|
sdp_profile_desc_t profile;
|
|
|
|
sdp_list_t *aproto, *proto[2];
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_record_t *record;
|
2007-07-21 02:03:20 +08:00
|
|
|
sdp_data_t *channel, *features;
|
|
|
|
uint8_t netid = 0x01;
|
2008-01-23 02:01:19 +08:00
|
|
|
uint16_t sdpfeat;
|
2007-07-21 02:03:20 +08:00
|
|
|
sdp_data_t *network = sdp_data_alloc(SDP_UINT8, &netid);
|
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
record = sdp_record_alloc();
|
|
|
|
if (!record)
|
|
|
|
return NULL;
|
2007-07-21 02:03:20 +08:00
|
|
|
|
|
|
|
sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP);
|
|
|
|
root = sdp_list_append(0, &root_uuid);
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_set_browse_groups(record, root);
|
2007-07-21 02:03:20 +08:00
|
|
|
|
|
|
|
sdp_uuid16_create(&svclass_uuid, HANDSFREE_AGW_SVCLASS_ID);
|
|
|
|
svclass_id = sdp_list_append(0, &svclass_uuid);
|
|
|
|
sdp_uuid16_create(&ga_svclass_uuid, GENERIC_AUDIO_SVCLASS_ID);
|
|
|
|
svclass_id = sdp_list_append(svclass_id, &ga_svclass_uuid);
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_set_service_classes(record, svclass_id);
|
2007-07-21 02:03:20 +08:00
|
|
|
|
|
|
|
sdp_uuid16_create(&profile.uuid, HANDSFREE_PROFILE_ID);
|
|
|
|
profile.version = 0x0105;
|
|
|
|
pfseq = sdp_list_append(0, &profile);
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_set_profile_descs(record, pfseq);
|
2007-07-21 02:03:20 +08:00
|
|
|
|
|
|
|
sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID);
|
|
|
|
proto[0] = sdp_list_append(0, &l2cap_uuid);
|
|
|
|
apseq = sdp_list_append(0, proto[0]);
|
|
|
|
|
|
|
|
sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID);
|
|
|
|
proto[1] = sdp_list_append(0, &rfcomm_uuid);
|
|
|
|
channel = sdp_data_alloc(SDP_UINT8, &ch);
|
|
|
|
proto[1] = sdp_list_append(proto[1], channel);
|
|
|
|
apseq = sdp_list_append(apseq, proto[1]);
|
|
|
|
|
2008-01-23 02:01:19 +08:00
|
|
|
sdpfeat = (uint16_t) feat & 0xF;
|
|
|
|
features = sdp_data_alloc(SDP_UINT16, &sdpfeat);
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_attr_add(record, SDP_ATTR_SUPPORTED_FEATURES, features);
|
2007-07-21 02:03:20 +08:00
|
|
|
|
|
|
|
aproto = sdp_list_append(0, apseq);
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_set_access_protos(record, aproto);
|
2007-07-21 02:03:20 +08:00
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_set_info_attr(record, "Hands-Free Audio Gateway", 0, 0);
|
2007-07-21 02:03:20 +08:00
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_attr_add(record, SDP_ATTR_EXTERNAL_NETWORK, network);
|
2007-07-21 02:03:20 +08:00
|
|
|
|
|
|
|
sdp_data_free(channel);
|
|
|
|
sdp_list_free(proto[0], 0);
|
|
|
|
sdp_list_free(proto[1], 0);
|
|
|
|
sdp_list_free(apseq, 0);
|
|
|
|
sdp_list_free(pfseq, 0);
|
|
|
|
sdp_list_free(aproto, 0);
|
|
|
|
sdp_list_free(root, 0);
|
|
|
|
sdp_list_free(svclass_id, 0);
|
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
return record;
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
|
|
|
|
2009-04-03 11:49:47 +08:00
|
|
|
static void headset_auth_cb(DBusError *derr, void *user_data)
|
2007-07-21 02:03:20 +08:00
|
|
|
{
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *device = user_data;
|
2009-02-20 03:08:20 +08:00
|
|
|
GError *err = NULL;
|
|
|
|
GIOChannel *io;
|
2007-07-21 02:03:20 +08:00
|
|
|
|
2008-04-14 22:41:42 +08:00
|
|
|
if (derr && dbus_error_is_set(derr)) {
|
|
|
|
error("Access denied: %s", derr->message);
|
2007-07-21 02:03:20 +08:00
|
|
|
headset_set_state(device, HEADSET_STATE_DISCONNECTED);
|
2009-02-20 03:08:20 +08:00
|
|
|
return;
|
|
|
|
}
|
2007-07-21 02:03:20 +08:00
|
|
|
|
2009-02-20 03:08:20 +08:00
|
|
|
io = headset_get_rfcomm(device);
|
2008-09-04 22:36:51 +08:00
|
|
|
|
2009-02-20 03:08:20 +08:00
|
|
|
if (!bt_io_accept(io, headset_connect_cb, device, NULL, &err)) {
|
|
|
|
error("bt_io_accept: %s", err->message);
|
|
|
|
g_error_free(err);
|
|
|
|
headset_set_state(device, HEADSET_STATE_DISCONNECTED);
|
|
|
|
return;
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
2008-04-14 22:41:42 +08:00
|
|
|
}
|
|
|
|
|
2009-02-20 03:08:20 +08:00
|
|
|
static void ag_confirm(GIOChannel *chan, gpointer data)
|
2007-07-21 02:03:20 +08:00
|
|
|
{
|
2008-10-09 20:11:16 +08:00
|
|
|
const char *server_uuid, *remote_uuid;
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *device;
|
2008-01-08 16:58:14 +08:00
|
|
|
gboolean hfp_active;
|
2009-02-19 06:17:54 +08:00
|
|
|
bdaddr_t src, dst;
|
|
|
|
int perr;
|
2009-02-20 03:08:20 +08:00
|
|
|
GError *err = NULL;
|
2009-02-19 06:17:54 +08:00
|
|
|
uint8_t ch;
|
2007-07-21 02:03:20 +08:00
|
|
|
|
2009-02-20 03:08:20 +08:00
|
|
|
bt_io_get(chan, BT_IO_RFCOMM, &err,
|
2009-02-19 06:17:54 +08:00
|
|
|
BT_IO_OPT_SOURCE_BDADDR, &src,
|
|
|
|
BT_IO_OPT_DEST_BDADDR, &dst,
|
2009-02-20 02:30:22 +08:00
|
|
|
BT_IO_OPT_CHANNEL, &ch,
|
2009-02-19 06:17:54 +08:00
|
|
|
BT_IO_OPT_INVALID);
|
2009-02-20 03:08:20 +08:00
|
|
|
if (err) {
|
|
|
|
error("%s", err->message);
|
2009-02-20 03:22:48 +08:00
|
|
|
g_error_free(err);
|
2009-02-19 06:17:54 +08:00
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ch == DEFAULT_HS_AG_CHANNEL) {
|
2008-01-08 16:58:14 +08:00
|
|
|
hfp_active = FALSE;
|
2008-10-09 20:11:16 +08:00
|
|
|
server_uuid = HSP_AG_UUID;
|
|
|
|
remote_uuid = HSP_HS_UUID;
|
2007-08-13 05:34:50 +08:00
|
|
|
} else {
|
2008-01-08 16:58:14 +08:00
|
|
|
hfp_active = TRUE;
|
2008-10-09 20:11:16 +08:00
|
|
|
server_uuid = HFP_AG_UUID;
|
|
|
|
remote_uuid = HFP_HS_UUID;
|
2007-08-13 05:34:50 +08:00
|
|
|
}
|
|
|
|
|
2009-04-12 01:01:00 +08:00
|
|
|
device = manager_get_device(&src, &dst, TRUE);
|
2008-05-16 04:37:45 +08:00
|
|
|
if (!device)
|
|
|
|
goto drop;
|
2007-07-21 02:03:20 +08:00
|
|
|
|
2009-06-03 05:53:06 +08:00
|
|
|
if (!manager_allow_headset_connection(device)) {
|
2008-10-24 20:20:36 +08:00
|
|
|
debug("Refusing headset: too many existing connections");
|
2008-10-24 17:19:47 +08:00
|
|
|
goto drop;
|
2008-10-24 20:20:36 +08:00
|
|
|
}
|
2008-10-24 17:19:47 +08:00
|
|
|
|
2008-12-02 20:45:22 +08:00
|
|
|
if (!device->headset) {
|
2008-10-09 21:00:09 +08:00
|
|
|
btd_device_add_uuid(device->btd_dev, remote_uuid);
|
2008-12-02 20:45:22 +08:00
|
|
|
if (!device->headset)
|
|
|
|
goto drop;
|
|
|
|
}
|
2008-10-08 20:44:54 +08:00
|
|
|
|
2007-07-21 02:03:20 +08:00
|
|
|
if (headset_get_state(device) > HEADSET_STATE_DISCONNECTED) {
|
|
|
|
debug("Refusing new connection since one already exists");
|
2008-05-16 04:37:45 +08:00
|
|
|
goto drop;
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
|
|
|
|
2008-02-19 16:20:22 +08:00
|
|
|
set_hfp_active(device, hfp_active);
|
|
|
|
|
2008-05-16 04:37:45 +08:00
|
|
|
if (headset_connect_rfcomm(device, chan) < 0) {
|
2009-02-25 22:31:08 +08:00
|
|
|
error("headset_connect_rfcomm failed");
|
2008-05-16 04:37:45 +08:00
|
|
|
goto drop;
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
|
|
|
|
2008-09-04 22:36:51 +08:00
|
|
|
headset_set_state(device, HEADSET_STATE_CONNECT_IN_PROGRESS);
|
|
|
|
|
2009-06-15 22:59:18 +08:00
|
|
|
perr = audio_device_request_authorization(device, server_uuid,
|
|
|
|
headset_auth_cb, device);
|
2009-02-19 06:17:54 +08:00
|
|
|
if (perr < 0) {
|
|
|
|
debug("Authorization denied: %s", strerror(-perr));
|
2008-09-04 22:36:51 +08:00
|
|
|
headset_set_state(device, HEADSET_STATE_DISCONNECTED);
|
2008-06-18 03:37:36 +08:00
|
|
|
return;
|
|
|
|
}
|
2007-07-21 02:03:20 +08:00
|
|
|
|
2009-03-28 01:10:04 +08:00
|
|
|
device->auto_connect = auto_connect;
|
|
|
|
|
2008-05-16 04:37:45 +08:00
|
|
|
return;
|
2007-07-21 02:03:20 +08:00
|
|
|
|
2008-05-16 04:37:45 +08:00
|
|
|
drop:
|
2009-02-20 02:58:15 +08:00
|
|
|
g_io_channel_shutdown(chan, TRUE, NULL);
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
|
|
|
|
2009-04-03 11:49:47 +08:00
|
|
|
static void gateway_auth_cb(DBusError *derr, void *user_data)
|
|
|
|
{
|
|
|
|
struct audio_device *device = user_data;
|
|
|
|
|
|
|
|
if (derr && dbus_error_is_set(derr))
|
|
|
|
error("Access denied: %s", derr->message);
|
|
|
|
else {
|
|
|
|
char ag_address[18];
|
|
|
|
|
|
|
|
ba2str(&device->dst, ag_address);
|
|
|
|
debug("Accepted AG connection from %s for %s",
|
|
|
|
ag_address, device->path);
|
|
|
|
|
|
|
|
gateway_start_service(device);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hf_io_cb(GIOChannel *chan, gpointer data)
|
2008-04-21 20:49:16 +08:00
|
|
|
{
|
2009-04-03 11:49:47 +08:00
|
|
|
bdaddr_t src, dst;
|
|
|
|
GError *err = NULL;
|
|
|
|
uint8_t ch;
|
|
|
|
const char *server_uuid, *remote_uuid;
|
|
|
|
uint16_t svclass;
|
|
|
|
struct audio_device *device;
|
|
|
|
int perr;
|
|
|
|
|
|
|
|
bt_io_get(chan, BT_IO_RFCOMM, &err,
|
|
|
|
BT_IO_OPT_SOURCE_BDADDR, &src,
|
|
|
|
BT_IO_OPT_DEST_BDADDR, &dst,
|
|
|
|
BT_IO_OPT_CHANNEL, &ch,
|
|
|
|
BT_IO_OPT_INVALID);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
error("%s", err->message);
|
|
|
|
g_error_free(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
server_uuid = HFP_HS_UUID;
|
|
|
|
remote_uuid = HFP_AG_UUID;
|
|
|
|
svclass = HANDSFREE_AGW_SVCLASS_ID;
|
|
|
|
|
2009-04-12 01:01:00 +08:00
|
|
|
device = manager_get_device(&src, &dst, TRUE);
|
2009-04-03 11:49:47 +08:00
|
|
|
if (!device)
|
|
|
|
goto drop;
|
|
|
|
|
|
|
|
if (!device->gateway) {
|
|
|
|
btd_device_add_uuid(device->btd_dev, remote_uuid);
|
|
|
|
if (!device->gateway)
|
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gateway_is_connected(device)) {
|
|
|
|
debug("Refusing new connection since one already exists");
|
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gateway_connect_rfcomm(device, chan) < 0) {
|
|
|
|
error("Allocating new GIOChannel failed!");
|
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
2009-06-15 22:59:18 +08:00
|
|
|
perr = audio_device_request_authorization(device, server_uuid,
|
|
|
|
gateway_auth_cb, device);
|
2009-04-03 11:49:47 +08:00
|
|
|
if (perr < 0) {
|
|
|
|
debug("Authorization denied!");
|
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
drop:
|
2009-06-30 17:10:52 +08:00
|
|
|
g_io_channel_shutdown(chan, TRUE, NULL);
|
2009-04-03 11:49:47 +08:00
|
|
|
g_io_channel_unref(chan);
|
2008-05-16 04:37:45 +08:00
|
|
|
return;
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
|
|
|
|
2008-08-13 05:59:36 +08:00
|
|
|
static int headset_server_init(struct audio_adapter *adapter)
|
2007-07-21 02:03:20 +08:00
|
|
|
{
|
|
|
|
uint8_t chan = DEFAULT_HS_AG_CHANNEL;
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_record_t *record;
|
2008-10-10 20:53:30 +08:00
|
|
|
gboolean master = TRUE;
|
2008-01-16 17:08:26 +08:00
|
|
|
GError *err = NULL;
|
2009-02-19 06:17:54 +08:00
|
|
|
uint32_t features;
|
|
|
|
GIOChannel *io;
|
2009-05-27 03:20:20 +08:00
|
|
|
bdaddr_t src;
|
2007-07-21 02:03:20 +08:00
|
|
|
|
2008-03-06 01:43:54 +08:00
|
|
|
if (config) {
|
|
|
|
gboolean tmp;
|
|
|
|
|
2008-03-06 01:51:48 +08:00
|
|
|
tmp = g_key_file_get_boolean(config, "General", "Master",
|
2008-03-06 01:43:54 +08:00
|
|
|
&err);
|
|
|
|
if (err) {
|
|
|
|
debug("audio.conf: %s", err->message);
|
2008-10-24 18:44:16 +08:00
|
|
|
g_clear_error(&err);
|
2008-03-06 01:43:54 +08:00
|
|
|
} else
|
|
|
|
master = tmp;
|
|
|
|
}
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
adapter_get_address(adapter->btd_adapter, &src);
|
|
|
|
|
2009-02-20 03:08:20 +08:00
|
|
|
io = bt_io_listen(BT_IO_RFCOMM, NULL, ag_confirm, adapter, NULL, &err,
|
2009-05-27 03:20:20 +08:00
|
|
|
BT_IO_OPT_SOURCE_BDADDR, &src,
|
2009-02-19 06:17:54 +08:00
|
|
|
BT_IO_OPT_CHANNEL, chan,
|
|
|
|
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
|
|
|
|
BT_IO_OPT_MASTER, master,
|
|
|
|
BT_IO_OPT_INVALID);
|
|
|
|
if (!io)
|
2008-09-10 20:35:45 +08:00
|
|
|
goto failed;
|
2007-07-21 02:03:20 +08:00
|
|
|
|
2009-02-19 06:17:54 +08:00
|
|
|
adapter->hsp_ag_server = io;
|
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
record = hsp_ag_record(chan);
|
|
|
|
if (!record) {
|
2007-07-21 02:03:20 +08:00
|
|
|
error("Unable to allocate new service record");
|
2008-09-10 20:35:45 +08:00
|
|
|
goto failed;
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
if (add_record_to_server(&src, record) < 0) {
|
2007-07-21 02:03:20 +08:00
|
|
|
error("Unable to register HS AG service record");
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_record_free(record);
|
2008-09-10 20:35:45 +08:00
|
|
|
goto failed;
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
2008-08-13 05:59:36 +08:00
|
|
|
adapter->hsp_ag_record_id = record->handle;
|
2007-07-21 02:03:20 +08:00
|
|
|
|
2008-03-12 22:34:13 +08:00
|
|
|
features = headset_config_init(config);
|
|
|
|
|
2008-10-10 20:53:30 +08:00
|
|
|
if (!enabled.hfp)
|
2007-07-21 02:03:20 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
chan = DEFAULT_HF_AG_CHANNEL;
|
|
|
|
|
2009-02-20 03:08:20 +08:00
|
|
|
io = bt_io_listen(BT_IO_RFCOMM, NULL, ag_confirm, adapter, NULL, &err,
|
2009-05-27 03:20:20 +08:00
|
|
|
BT_IO_OPT_SOURCE_BDADDR, &src,
|
2009-02-19 06:17:54 +08:00
|
|
|
BT_IO_OPT_CHANNEL, chan,
|
|
|
|
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
|
|
|
|
BT_IO_OPT_MASTER, master,
|
|
|
|
BT_IO_OPT_INVALID);
|
|
|
|
if (!io)
|
2008-09-10 20:35:45 +08:00
|
|
|
goto failed;
|
2007-07-21 02:03:20 +08:00
|
|
|
|
2009-02-19 06:17:54 +08:00
|
|
|
adapter->hfp_ag_server = io;
|
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
record = hfp_ag_record(chan, features);
|
|
|
|
if (!record) {
|
2007-07-21 02:03:20 +08:00
|
|
|
error("Unable to allocate new service record");
|
2008-09-10 20:35:45 +08:00
|
|
|
goto failed;
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
if (add_record_to_server(&src, record) < 0) {
|
2008-03-28 07:07:19 +08:00
|
|
|
error("Unable to register HF AG service record");
|
|
|
|
sdp_record_free(record);
|
2008-09-10 20:35:45 +08:00
|
|
|
goto failed;
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
2008-08-13 05:59:36 +08:00
|
|
|
adapter->hfp_ag_record_id = record->handle;
|
2007-07-21 02:03:20 +08:00
|
|
|
|
|
|
|
return 0;
|
2008-09-10 20:35:45 +08:00
|
|
|
|
|
|
|
failed:
|
2009-02-19 06:17:54 +08:00
|
|
|
error("%s", err->message);
|
2009-02-20 03:22:48 +08:00
|
|
|
g_error_free(err);
|
2008-09-10 20:35:45 +08:00
|
|
|
if (adapter->hsp_ag_server) {
|
2009-02-20 02:58:15 +08:00
|
|
|
g_io_channel_shutdown(adapter->hsp_ag_server, TRUE, NULL);
|
2008-09-10 20:35:45 +08:00
|
|
|
g_io_channel_unref(adapter->hsp_ag_server);
|
|
|
|
adapter->hsp_ag_server = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (adapter->hfp_ag_server) {
|
2009-02-20 02:58:15 +08:00
|
|
|
g_io_channel_shutdown(adapter->hfp_ag_server, TRUE, NULL);
|
2008-09-10 20:35:45 +08:00
|
|
|
g_io_channel_unref(adapter->hfp_ag_server);
|
|
|
|
adapter->hfp_ag_server = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
|
|
|
|
2008-08-13 05:59:36 +08:00
|
|
|
static int gateway_server_init(struct audio_adapter *adapter)
|
2008-04-21 20:49:16 +08:00
|
|
|
{
|
2009-04-03 11:49:47 +08:00
|
|
|
uint8_t chan = DEFAULT_HFP_HS_CHANNEL;
|
2008-04-21 20:49:16 +08:00
|
|
|
sdp_record_t *record;
|
|
|
|
gboolean master = TRUE;
|
|
|
|
GError *err = NULL;
|
2009-02-19 06:17:54 +08:00
|
|
|
GIOChannel *io;
|
2009-05-27 03:20:20 +08:00
|
|
|
bdaddr_t src;
|
2008-04-21 20:49:16 +08:00
|
|
|
|
|
|
|
if (config) {
|
|
|
|
gboolean tmp;
|
|
|
|
|
|
|
|
tmp = g_key_file_get_boolean(config, "General", "Master",
|
|
|
|
&err);
|
|
|
|
if (err) {
|
|
|
|
debug("audio.conf: %s", err->message);
|
2008-10-24 18:44:16 +08:00
|
|
|
g_clear_error(&err);
|
2008-04-21 20:49:16 +08:00
|
|
|
} else
|
|
|
|
master = tmp;
|
|
|
|
}
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
adapter_get_address(adapter->btd_adapter, &src);
|
|
|
|
|
2009-04-03 11:49:47 +08:00
|
|
|
io = bt_io_listen(BT_IO_RFCOMM, NULL, hf_io_cb, adapter, NULL, &err,
|
2009-05-27 03:20:20 +08:00
|
|
|
BT_IO_OPT_SOURCE_BDADDR, &src,
|
2009-02-19 06:17:54 +08:00
|
|
|
BT_IO_OPT_CHANNEL, chan,
|
|
|
|
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
|
|
|
|
BT_IO_OPT_MASTER, master,
|
|
|
|
BT_IO_OPT_INVALID);
|
|
|
|
if (!io) {
|
|
|
|
error("%s", err->message);
|
|
|
|
g_error_free(err);
|
2008-04-21 20:49:16 +08:00
|
|
|
return -1;
|
2009-02-19 06:17:54 +08:00
|
|
|
}
|
|
|
|
|
2009-04-03 11:49:47 +08:00
|
|
|
adapter->hfp_hs_server = io;
|
|
|
|
record = hfp_hs_record(chan);
|
2008-04-21 20:49:16 +08:00
|
|
|
if (!record) {
|
|
|
|
error("Unable to allocate new service record");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
if (add_record_to_server(&src, record) < 0) {
|
2009-04-03 11:49:47 +08:00
|
|
|
error("Unable to register HFP HS service record");
|
2008-04-21 20:49:16 +08:00
|
|
|
sdp_record_free(record);
|
2009-04-03 11:49:47 +08:00
|
|
|
g_io_channel_unref(adapter->hfp_hs_server);
|
|
|
|
adapter->hfp_hs_server = NULL;
|
2008-04-21 20:49:16 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2008-05-16 04:37:45 +08:00
|
|
|
|
2009-04-03 11:49:47 +08:00
|
|
|
adapter->hfp_hs_record_id = record->handle;
|
2008-04-21 20:49:16 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-09 20:11:16 +08:00
|
|
|
static int audio_probe(struct btd_device *device, GSList *uuids)
|
2008-07-29 04:15:27 +08:00
|
|
|
{
|
2008-09-04 18:33:43 +08:00
|
|
|
struct btd_adapter *adapter = device_get_adapter(device);
|
2008-07-29 04:15:27 +08:00
|
|
|
bdaddr_t src, dst;
|
2008-10-09 20:11:16 +08:00
|
|
|
struct audio_device *audio_dev;
|
2008-07-29 04:15:27 +08:00
|
|
|
|
2008-09-08 16:09:38 +08:00
|
|
|
adapter_get_address(adapter, &src);
|
2008-09-08 20:25:14 +08:00
|
|
|
device_get_address(device, &dst);
|
2008-07-29 04:15:27 +08:00
|
|
|
|
2009-04-12 01:01:00 +08:00
|
|
|
audio_dev = manager_get_device(&src, &dst, TRUE);
|
2008-10-09 20:11:16 +08:00
|
|
|
if (!audio_dev) {
|
2008-10-08 20:09:25 +08:00
|
|
|
debug("audio_probe: unable to get a device object");
|
|
|
|
return -1;
|
2008-07-29 04:15:27 +08:00
|
|
|
}
|
|
|
|
|
2008-10-09 20:11:16 +08:00
|
|
|
g_slist_foreach(uuids, (GFunc) handle_uuid, audio_dev);
|
2008-07-29 04:15:27 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-14 02:04:56 +08:00
|
|
|
static void audio_remove(struct btd_device *device)
|
2008-07-29 04:15:27 +08:00
|
|
|
{
|
|
|
|
struct audio_device *dev;
|
2009-03-14 02:13:44 +08:00
|
|
|
const char *path;
|
2008-07-29 04:15:27 +08:00
|
|
|
|
2009-03-14 02:13:44 +08:00
|
|
|
path = device_get_path(device);
|
2009-03-19 22:50:26 +08:00
|
|
|
|
2009-03-14 02:13:44 +08:00
|
|
|
dev = manager_find_device(path, NULL, NULL, NULL, FALSE);
|
2008-07-29 04:15:27 +08:00
|
|
|
if (!dev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
devices = g_slist_remove(devices, dev);
|
|
|
|
|
2009-01-09 04:18:07 +08:00
|
|
|
audio_device_unregister(dev);
|
2008-07-29 04:15:27 +08:00
|
|
|
}
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
static struct audio_adapter *audio_adapter_ref(struct audio_adapter *adp)
|
2008-08-13 05:59:36 +08:00
|
|
|
{
|
2009-05-27 03:20:20 +08:00
|
|
|
adp->ref++;
|
2008-08-13 05:59:36 +08:00
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
debug("audio_adapter_ref(%p): ref=%d", adp, adp->ref);
|
2008-08-13 05:59:36 +08:00
|
|
|
|
|
|
|
return adp;
|
|
|
|
}
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
static void audio_adapter_unref(struct audio_adapter *adp)
|
|
|
|
{
|
|
|
|
adp->ref--;
|
|
|
|
|
|
|
|
debug("audio_adapter_unref(%p): ref=%d", adp, adp->ref);
|
|
|
|
|
|
|
|
if (adp->ref > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
adapters = g_slist_remove(adapters, adp);
|
|
|
|
btd_adapter_unref(adp->btd_adapter);
|
|
|
|
g_free(adp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct audio_adapter *audio_adapter_create(struct btd_adapter *adapter)
|
2008-08-13 05:59:36 +08:00
|
|
|
{
|
|
|
|
struct audio_adapter *adp;
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
adp = g_new0(struct audio_adapter, 1);
|
|
|
|
adp->btd_adapter = btd_adapter_ref(adapter);
|
|
|
|
|
|
|
|
return audio_adapter_ref(adp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct audio_adapter *audio_adapter_get(struct btd_adapter *adapter)
|
|
|
|
{
|
|
|
|
struct audio_adapter *adp;
|
2008-08-13 05:59:36 +08:00
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
adp = find_adapter(adapters, adapter);
|
2008-08-13 05:59:36 +08:00
|
|
|
if (!adp) {
|
2009-05-27 03:20:20 +08:00
|
|
|
adp = audio_adapter_create(adapter);
|
2008-08-13 05:59:36 +08:00
|
|
|
if (!adp)
|
|
|
|
return NULL;
|
|
|
|
adapters = g_slist_append(adapters, adp);
|
2009-05-27 03:20:20 +08:00
|
|
|
} else
|
|
|
|
audio_adapter_ref(adp);
|
2008-08-13 05:59:36 +08:00
|
|
|
|
|
|
|
return adp;
|
|
|
|
}
|
|
|
|
|
2008-09-04 18:33:43 +08:00
|
|
|
static int headset_server_probe(struct btd_adapter *adapter)
|
2008-08-13 05:59:36 +08:00
|
|
|
{
|
|
|
|
struct audio_adapter *adp;
|
|
|
|
const gchar *path = adapter_get_path(adapter);
|
2009-05-27 03:20:20 +08:00
|
|
|
int ret;
|
2008-08-13 05:59:36 +08:00
|
|
|
|
|
|
|
DBG("path %s", path);
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
adp = audio_adapter_get(adapter);
|
2008-08-13 05:59:36 +08:00
|
|
|
if (!adp)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
ret = headset_server_init(adp);
|
|
|
|
if (ret < 0) {
|
|
|
|
audio_adapter_unref(adp);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2008-08-13 05:59:36 +08:00
|
|
|
}
|
|
|
|
|
2008-09-04 18:33:43 +08:00
|
|
|
static void headset_server_remove(struct btd_adapter *adapter)
|
2008-08-13 05:59:36 +08:00
|
|
|
{
|
|
|
|
struct audio_adapter *adp;
|
|
|
|
const gchar *path = adapter_get_path(adapter);
|
|
|
|
|
|
|
|
DBG("path %s", path);
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
adp = find_adapter(adapters, adapter);
|
2008-08-13 05:59:36 +08:00
|
|
|
if (!adp)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (adp->hsp_ag_record_id) {
|
|
|
|
remove_record_from_server(adp->hsp_ag_record_id);
|
|
|
|
adp->hsp_ag_record_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (adp->hsp_ag_server) {
|
2009-04-29 00:53:48 +08:00
|
|
|
g_io_channel_shutdown(adp->hsp_ag_server, TRUE, NULL);
|
2008-08-13 05:59:36 +08:00
|
|
|
g_io_channel_unref(adp->hsp_ag_server);
|
|
|
|
adp->hsp_ag_server = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (adp->hfp_ag_record_id) {
|
|
|
|
remove_record_from_server(adp->hfp_ag_record_id);
|
|
|
|
adp->hfp_ag_record_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (adp->hfp_ag_server) {
|
2009-04-29 00:53:48 +08:00
|
|
|
g_io_channel_shutdown(adp->hfp_ag_server, TRUE, NULL);
|
2008-08-13 05:59:36 +08:00
|
|
|
g_io_channel_unref(adp->hfp_ag_server);
|
|
|
|
adp->hfp_ag_server = NULL;
|
|
|
|
}
|
2009-05-27 03:20:20 +08:00
|
|
|
|
|
|
|
audio_adapter_unref(adp);
|
2008-08-13 05:59:36 +08:00
|
|
|
}
|
|
|
|
|
2008-09-04 18:33:43 +08:00
|
|
|
static int gateway_server_probe(struct btd_adapter *adapter)
|
2008-08-13 05:59:36 +08:00
|
|
|
{
|
|
|
|
struct audio_adapter *adp;
|
|
|
|
const gchar *path = adapter_get_path(adapter);
|
2009-05-27 03:20:20 +08:00
|
|
|
int ret;
|
2008-08-13 05:59:36 +08:00
|
|
|
|
|
|
|
DBG("path %s", path);
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
adp = audio_adapter_get(adapter);
|
2008-08-13 05:59:36 +08:00
|
|
|
if (!adp)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
ret = gateway_server_init(adp);
|
|
|
|
if (ret < 0) {
|
|
|
|
audio_adapter_ref(adp);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2008-08-13 05:59:36 +08:00
|
|
|
}
|
|
|
|
|
2008-09-04 18:33:43 +08:00
|
|
|
static void gateway_server_remove(struct btd_adapter *adapter)
|
2008-08-13 05:59:36 +08:00
|
|
|
{
|
|
|
|
struct audio_adapter *adp;
|
|
|
|
const gchar *path = adapter_get_path(adapter);
|
|
|
|
|
|
|
|
DBG("path %s", path);
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
adp = find_adapter(adapters, adapter);
|
2008-08-13 05:59:36 +08:00
|
|
|
if (!adp)
|
|
|
|
return;
|
|
|
|
|
2009-04-03 11:49:47 +08:00
|
|
|
if (adp->hfp_hs_record_id) {
|
|
|
|
remove_record_from_server(adp->hfp_hs_record_id);
|
|
|
|
adp->hfp_hs_record_id = 0;
|
2008-08-13 05:59:36 +08:00
|
|
|
}
|
|
|
|
|
2009-04-03 11:49:47 +08:00
|
|
|
if (adp->hfp_hs_server) {
|
|
|
|
g_io_channel_unref(adp->hfp_hs_server);
|
|
|
|
adp->hfp_hs_server = NULL;
|
2008-08-13 05:59:36 +08:00
|
|
|
}
|
2009-05-27 03:20:20 +08:00
|
|
|
|
|
|
|
audio_adapter_ref(adp);
|
2008-08-13 05:59:36 +08:00
|
|
|
}
|
|
|
|
|
2008-09-04 18:33:43 +08:00
|
|
|
static int a2dp_server_probe(struct btd_adapter *adapter)
|
2008-08-13 05:59:36 +08:00
|
|
|
{
|
|
|
|
struct audio_adapter *adp;
|
|
|
|
const gchar *path = adapter_get_path(adapter);
|
2009-05-27 03:20:20 +08:00
|
|
|
bdaddr_t src;
|
|
|
|
int ret;
|
2008-08-13 05:59:36 +08:00
|
|
|
|
|
|
|
DBG("path %s", path);
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
adp = audio_adapter_get(adapter);
|
2008-08-13 05:59:36 +08:00
|
|
|
if (!adp)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
adapter_get_address(adapter, &src);
|
|
|
|
|
|
|
|
ret = a2dp_register(connection, &src, config);
|
|
|
|
if (ret < 0) {
|
|
|
|
audio_adapter_unref(adp);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2008-09-09 05:20:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void a2dp_server_remove(struct btd_adapter *adapter)
|
|
|
|
{
|
|
|
|
struct audio_adapter *adp;
|
|
|
|
const gchar *path = adapter_get_path(adapter);
|
2009-05-27 03:20:20 +08:00
|
|
|
bdaddr_t src;
|
2008-09-09 05:20:29 +08:00
|
|
|
|
|
|
|
DBG("path %s", path);
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
adp = find_adapter(adapters, adapter);
|
2008-09-09 05:20:29 +08:00
|
|
|
if (!adp)
|
|
|
|
return;
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
adapter_get_address(adapter, &src);
|
|
|
|
a2dp_unregister(&src);
|
|
|
|
audio_adapter_unref(adp);
|
2008-08-13 05:59:36 +08:00
|
|
|
}
|
|
|
|
|
2008-09-04 18:33:43 +08:00
|
|
|
static int avrcp_server_probe(struct btd_adapter *adapter)
|
2008-08-13 05:59:36 +08:00
|
|
|
{
|
|
|
|
struct audio_adapter *adp;
|
|
|
|
const gchar *path = adapter_get_path(adapter);
|
2009-05-27 03:20:20 +08:00
|
|
|
bdaddr_t src;
|
2008-08-13 05:59:36 +08:00
|
|
|
|
|
|
|
DBG("path %s", path);
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
adp = audio_adapter_get(adapter);
|
2008-08-13 05:59:36 +08:00
|
|
|
if (!adp)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
adapter_get_address(adapter, &src);
|
|
|
|
|
|
|
|
return avrcp_register(connection, &src, config);
|
2008-09-09 05:20:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void avrcp_server_remove(struct btd_adapter *adapter)
|
|
|
|
{
|
|
|
|
struct audio_adapter *adp;
|
|
|
|
const gchar *path = adapter_get_path(adapter);
|
2009-05-27 03:20:20 +08:00
|
|
|
bdaddr_t src;
|
2008-09-09 05:20:29 +08:00
|
|
|
|
|
|
|
DBG("path %s", path);
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
adp = find_adapter(adapters, adapter);
|
2008-09-09 05:20:29 +08:00
|
|
|
if (!adp)
|
|
|
|
return;
|
|
|
|
|
2009-05-27 03:20:20 +08:00
|
|
|
adapter_get_address(adapter, &src);
|
|
|
|
avrcp_unregister(&src);
|
|
|
|
audio_adapter_unref(adp);
|
2008-08-13 05:59:36 +08:00
|
|
|
}
|
|
|
|
|
2008-07-29 04:15:27 +08:00
|
|
|
static struct btd_device_driver audio_driver = {
|
|
|
|
.name = "audio",
|
|
|
|
.uuids = BTD_UUIDS(HSP_HS_UUID, HFP_HS_UUID, HSP_AG_UUID, HFP_AG_UUID,
|
|
|
|
ADVANCED_AUDIO_UUID, A2DP_SOURCE_UUID, A2DP_SINK_UUID,
|
|
|
|
AVRCP_TARGET_UUID, AVRCP_REMOTE_UUID),
|
|
|
|
.probe = audio_probe,
|
|
|
|
.remove = audio_remove,
|
|
|
|
};
|
|
|
|
|
2008-08-13 05:59:36 +08:00
|
|
|
static struct btd_adapter_driver headset_server_driver = {
|
|
|
|
.name = "audio-headset",
|
|
|
|
.probe = headset_server_probe,
|
|
|
|
.remove = headset_server_remove,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct btd_adapter_driver gateway_server_driver = {
|
|
|
|
.name = "audio-gateway",
|
|
|
|
.probe = gateway_server_probe,
|
|
|
|
.remove = gateway_server_remove,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct btd_adapter_driver a2dp_server_driver = {
|
|
|
|
.name = "audio-a2dp",
|
|
|
|
.probe = a2dp_server_probe,
|
2008-09-09 05:20:29 +08:00
|
|
|
.remove = a2dp_server_remove,
|
2008-08-13 05:59:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct btd_adapter_driver avrcp_server_driver = {
|
|
|
|
.name = "audio-control",
|
|
|
|
.probe = avrcp_server_probe,
|
2008-09-09 05:20:29 +08:00
|
|
|
.remove = avrcp_server_remove,
|
2008-08-13 05:59:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int audio_manager_init(DBusConnection *conn, GKeyFile *conf)
|
2007-03-10 06:32:47 +08:00
|
|
|
{
|
2008-05-16 20:49:57 +08:00
|
|
|
char **list;
|
|
|
|
int i;
|
2008-10-10 20:53:30 +08:00
|
|
|
gboolean b;
|
2009-03-28 01:10:04 +08:00
|
|
|
GError *err = NULL;
|
2007-08-28 17:54:21 +08:00
|
|
|
|
2007-07-21 02:03:20 +08:00
|
|
|
connection = dbus_connection_ref(conn);
|
|
|
|
|
2008-08-13 05:59:36 +08:00
|
|
|
if (!conf)
|
2008-05-16 20:49:57 +08:00
|
|
|
goto proceed;
|
|
|
|
|
2008-08-13 05:59:36 +08:00
|
|
|
config = conf;
|
|
|
|
|
2008-05-16 20:49:57 +08:00
|
|
|
list = g_key_file_get_string_list(config, "General", "Enable",
|
|
|
|
NULL, NULL);
|
|
|
|
for (i = 0; list && list[i] != NULL; i++) {
|
|
|
|
if (g_str_equal(list[i], "Headset"))
|
|
|
|
enabled.headset = TRUE;
|
|
|
|
else if (g_str_equal(list[i], "Gateway"))
|
|
|
|
enabled.gateway = TRUE;
|
|
|
|
else if (g_str_equal(list[i], "Sink"))
|
|
|
|
enabled.sink = TRUE;
|
|
|
|
else if (g_str_equal(list[i], "Source"))
|
|
|
|
enabled.source = TRUE;
|
|
|
|
else if (g_str_equal(list[i], "Control"))
|
|
|
|
enabled.control = TRUE;
|
|
|
|
}
|
|
|
|
g_strfreev(list);
|
|
|
|
|
|
|
|
list = g_key_file_get_string_list(config, "General", "Disable",
|
|
|
|
NULL, NULL);
|
|
|
|
for (i = 0; list && list[i] != NULL; i++) {
|
|
|
|
if (g_str_equal(list[i], "Headset"))
|
|
|
|
enabled.headset = FALSE;
|
|
|
|
else if (g_str_equal(list[i], "Gateway"))
|
|
|
|
enabled.gateway = FALSE;
|
|
|
|
else if (g_str_equal(list[i], "Sink"))
|
|
|
|
enabled.sink = FALSE;
|
|
|
|
else if (g_str_equal(list[i], "Source"))
|
|
|
|
enabled.source = FALSE;
|
|
|
|
else if (g_str_equal(list[i], "Control"))
|
|
|
|
enabled.control = FALSE;
|
2008-01-16 17:08:26 +08:00
|
|
|
}
|
2008-05-16 20:49:57 +08:00
|
|
|
g_strfreev(list);
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2009-03-28 01:10:04 +08:00
|
|
|
b = g_key_file_get_boolean(config, "General", "AutoConnect", &err);
|
2008-10-10 20:53:30 +08:00
|
|
|
if (err) {
|
|
|
|
debug("audio.conf: %s", err->message);
|
2008-10-24 18:44:16 +08:00
|
|
|
g_clear_error(&err);
|
2008-10-10 20:53:30 +08:00
|
|
|
} else
|
2009-03-28 01:10:04 +08:00
|
|
|
auto_connect = b;
|
|
|
|
|
|
|
|
b = g_key_file_get_boolean(config, "Headset", "HFP",
|
|
|
|
&err);
|
|
|
|
if (err)
|
|
|
|
g_clear_error(&err);
|
|
|
|
else
|
2008-10-10 20:53:30 +08:00
|
|
|
enabled.hfp = b;
|
|
|
|
|
2008-10-24 17:19:47 +08:00
|
|
|
err = NULL;
|
|
|
|
i = g_key_file_get_integer(config, "Headset", "MaxConnected",
|
|
|
|
&err);
|
|
|
|
if (err) {
|
|
|
|
debug("audio.conf: %s", err->message);
|
2008-10-24 18:44:16 +08:00
|
|
|
g_clear_error(&err);
|
2008-10-24 17:19:47 +08:00
|
|
|
} else
|
|
|
|
max_connected_headsets = i;
|
|
|
|
|
2008-05-16 20:49:57 +08:00
|
|
|
proceed:
|
2008-09-03 19:06:40 +08:00
|
|
|
if (enabled.headset) {
|
|
|
|
telephony_init();
|
2008-08-13 05:59:36 +08:00
|
|
|
btd_register_adapter_driver(&headset_server_driver);
|
2008-09-03 19:06:40 +08:00
|
|
|
}
|
2008-01-16 17:08:26 +08:00
|
|
|
|
2008-08-13 05:59:36 +08:00
|
|
|
if (enabled.gateway)
|
|
|
|
btd_register_adapter_driver(&gateway_server_driver);
|
2008-04-21 20:49:16 +08:00
|
|
|
|
2008-08-13 05:59:36 +08:00
|
|
|
if (enabled.source || enabled.sink)
|
|
|
|
btd_register_adapter_driver(&a2dp_server_driver);
|
2007-08-17 06:05:55 +08:00
|
|
|
|
2008-08-13 05:59:36 +08:00
|
|
|
if (enabled.control)
|
|
|
|
btd_register_adapter_driver(&avrcp_server_driver);
|
2007-10-22 22:11:04 +08:00
|
|
|
|
2008-07-29 04:15:27 +08:00
|
|
|
btd_register_device_driver(&audio_driver);
|
2007-06-23 07:50:24 +08:00
|
|
|
|
2007-03-10 06:32:47 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
void audio_manager_exit(void)
|
2007-03-10 06:32:47 +08:00
|
|
|
{
|
2009-03-12 22:44:38 +08:00
|
|
|
/* Bail out early if we haven't been initialized */
|
|
|
|
if (connection == NULL)
|
|
|
|
return;
|
|
|
|
|
2007-04-12 06:46:22 +08:00
|
|
|
dbus_connection_unref(connection);
|
2009-03-12 22:44:38 +08:00
|
|
|
connection = NULL;
|
2007-04-09 07:19:19 +08:00
|
|
|
|
2009-03-12 22:44:38 +08:00
|
|
|
if (config) {
|
2008-08-13 05:59:36 +08:00
|
|
|
g_key_file_free(config);
|
2009-03-12 22:44:38 +08:00
|
|
|
config = NULL;
|
|
|
|
}
|
2008-08-13 05:59:36 +08:00
|
|
|
|
2008-09-03 19:06:40 +08:00
|
|
|
if (enabled.headset) {
|
2008-08-13 05:59:36 +08:00
|
|
|
btd_unregister_adapter_driver(&headset_server_driver);
|
2008-09-03 19:06:40 +08:00
|
|
|
telephony_exit();
|
|
|
|
}
|
2008-08-13 05:59:36 +08:00
|
|
|
|
|
|
|
if (enabled.gateway)
|
|
|
|
btd_unregister_adapter_driver(&gateway_server_driver);
|
|
|
|
|
|
|
|
if (enabled.source || enabled.sink)
|
|
|
|
btd_unregister_adapter_driver(&a2dp_server_driver);
|
|
|
|
|
|
|
|
if (enabled.control)
|
|
|
|
btd_unregister_adapter_driver(&avrcp_server_driver);
|
|
|
|
|
2008-07-29 04:15:27 +08:00
|
|
|
btd_unregister_device_driver(&audio_driver);
|
2007-06-07 01:58:19 +08:00
|
|
|
}
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2009-03-14 02:13:44 +08:00
|
|
|
struct audio_device *manager_find_device(const char *path,
|
|
|
|
const bdaddr_t *src,
|
2009-03-19 22:50:26 +08:00
|
|
|
const bdaddr_t *dst,
|
|
|
|
const char *interface,
|
2007-08-24 07:37:15 +08:00
|
|
|
gboolean connected)
|
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
for (l = devices; l != NULL; l = l->next) {
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *dev = l->data;
|
2007-08-24 07:37:15 +08:00
|
|
|
|
2009-03-14 02:13:44 +08:00
|
|
|
if ((path && (strcmp(path, "")) && strcmp(dev->path, path)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((src && bacmp(src, BDADDR_ANY)) && bacmp(&dev->src, src))
|
2009-03-19 22:50:26 +08:00
|
|
|
continue;
|
|
|
|
|
2009-03-14 02:13:44 +08:00
|
|
|
if ((dst && bacmp(dst, BDADDR_ANY)) && bacmp(&dev->dst, dst))
|
2007-08-24 07:37:15 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (interface && !strcmp(AUDIO_HEADSET_INTERFACE, interface)
|
2007-10-23 15:54:36 +08:00
|
|
|
&& !dev->headset)
|
2007-08-24 07:37:15 +08:00
|
|
|
continue;
|
|
|
|
|
2009-04-03 11:49:47 +08:00
|
|
|
if (interface && !strcmp(AUDIO_GATEWAY_INTERFACE, interface)
|
|
|
|
&& !dev->gateway)
|
|
|
|
continue;
|
|
|
|
|
2007-08-24 07:37:15 +08:00
|
|
|
if (interface && !strcmp(AUDIO_SINK_INTERFACE, interface)
|
2007-10-23 15:54:36 +08:00
|
|
|
&& !dev->sink)
|
2007-08-24 07:37:15 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (interface && !strcmp(AUDIO_SOURCE_INTERFACE, interface)
|
2007-10-23 15:54:36 +08:00
|
|
|
&& !dev->source)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (interface && !strcmp(AUDIO_CONTROL_INTERFACE, interface)
|
|
|
|
&& !dev->control)
|
2007-08-24 07:37:15 +08:00
|
|
|
continue;
|
|
|
|
|
2009-01-09 04:18:07 +08:00
|
|
|
if (connected && !audio_device_is_connected(dev, interface))
|
2007-08-24 07:37:15 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-10-08 20:09:25 +08:00
|
|
|
|
2008-10-08 20:44:54 +08:00
|
|
|
struct audio_device *manager_get_device(const bdaddr_t *src,
|
2009-04-12 01:01:00 +08:00
|
|
|
const bdaddr_t *dst,
|
|
|
|
gboolean create)
|
2008-10-08 20:09:25 +08:00
|
|
|
{
|
|
|
|
struct audio_device *dev;
|
2008-10-09 21:00:09 +08:00
|
|
|
struct btd_adapter *adapter;
|
|
|
|
struct btd_device *device;
|
|
|
|
char addr[18];
|
|
|
|
const char *path;
|
2008-10-08 20:09:25 +08:00
|
|
|
|
2009-03-14 02:13:44 +08:00
|
|
|
dev = manager_find_device(NULL, src, dst, NULL, FALSE);
|
2008-10-08 20:09:25 +08:00
|
|
|
if (dev)
|
|
|
|
return dev;
|
|
|
|
|
2009-04-12 01:01:00 +08:00
|
|
|
if (!create)
|
|
|
|
return NULL;
|
|
|
|
|
2008-10-09 21:00:09 +08:00
|
|
|
ba2str(src, addr);
|
2008-10-08 20:09:25 +08:00
|
|
|
|
2008-10-09 21:00:09 +08:00
|
|
|
adapter = manager_find_adapter(src);
|
|
|
|
if (!adapter) {
|
|
|
|
error("Unable to get a btd_adapter object for %s",
|
|
|
|
addr);
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-10-08 20:09:25 +08:00
|
|
|
|
2008-10-09 21:00:09 +08:00
|
|
|
ba2str(dst, addr);
|
2008-10-08 20:09:25 +08:00
|
|
|
|
2008-10-09 21:00:09 +08:00
|
|
|
device = adapter_get_device(connection, adapter, addr);
|
|
|
|
if (!device) {
|
|
|
|
error("Unable to get btd_device object for %s", addr);
|
|
|
|
return NULL;
|
2008-10-08 20:09:25 +08:00
|
|
|
}
|
|
|
|
|
2008-10-09 21:00:09 +08:00
|
|
|
path = device_get_path(device);
|
|
|
|
|
2009-04-23 02:41:53 +08:00
|
|
|
dev = audio_device_register(connection, device, path, src, dst);
|
2008-10-08 20:09:25 +08:00
|
|
|
if (!dev)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
devices = g_slist_append(devices, dev);
|
|
|
|
|
|
|
|
return dev;
|
|
|
|
}
|
2008-10-24 17:19:47 +08:00
|
|
|
|
2009-06-03 05:53:06 +08:00
|
|
|
gboolean manager_allow_headset_connection(struct audio_device *device)
|
2008-10-24 17:19:47 +08:00
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
int connected = 0;
|
|
|
|
|
|
|
|
for (l = devices; l != NULL; l = l->next) {
|
|
|
|
struct audio_device *dev = l->data;
|
|
|
|
struct headset *hs = dev->headset;
|
|
|
|
|
2009-06-03 05:53:06 +08:00
|
|
|
if (dev == device)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (bacmp(&dev->src, &device->src))
|
2008-10-24 17:19:47 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!hs)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (headset_get_state(dev) > HEADSET_STATE_DISCONNECTED)
|
|
|
|
connected++;
|
|
|
|
|
2008-10-24 20:20:36 +08:00
|
|
|
if (connected >= max_connected_headsets)
|
2008-10-24 17:19:47 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|