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
|
2008-02-02 11:37:05 +08:00
|
|
|
* Copyright (C) 2004-2008 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>
|
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"
|
|
|
|
|
|
|
|
#include "dbus-service.h"
|
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"
|
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;
|
|
|
|
|
|
|
|
struct audio_sdp_data {
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *device;
|
2007-05-19 09:18:39 +08:00
|
|
|
|
2007-05-31 17:23:17 +08:00
|
|
|
DBusMessage *msg; /* Method call or NULL */
|
2007-05-19 09:18:39 +08:00
|
|
|
|
2007-05-31 17:23:17 +08:00
|
|
|
GSList *records; /* sdp_record_t * */
|
2007-05-19 09:18:39 +08:00
|
|
|
|
|
|
|
audio_sdp_state_t state;
|
2007-08-27 20:05:10 +08:00
|
|
|
|
|
|
|
create_dev_cb_t cb;
|
|
|
|
void *cb_data;
|
2007-05-19 09:18:39 +08:00
|
|
|
};
|
|
|
|
|
2007-04-12 06:46:22 +08:00
|
|
|
static DBusConnection *connection = NULL;
|
|
|
|
|
2008-05-29 16:05:16 +08:00
|
|
|
static struct audio_device *default_hs = NULL;
|
|
|
|
static struct audio_device *default_dev = NULL;
|
2007-04-10 19:44:10 +08:00
|
|
|
|
2007-05-15 20:45:35 +08:00
|
|
|
static GSList *devices = NULL;
|
2007-04-09 07:19:19 +08:00
|
|
|
|
2008-04-21 20:49:16 +08:00
|
|
|
static uint32_t hsp_ag_record_id = 0;
|
|
|
|
static uint32_t hfp_ag_record_id = 0;
|
2007-07-21 02:03:20 +08:00
|
|
|
|
2008-04-21 20:49:16 +08:00
|
|
|
static uint32_t hsp_hs_record_id = 0;
|
|
|
|
|
|
|
|
static GIOChannel *hsp_ag_server = NULL;
|
|
|
|
static GIOChannel *hfp_ag_server = NULL;
|
|
|
|
|
|
|
|
static GIOChannel *hsp_hs_server = NULL;
|
2007-07-21 02:03:20 +08:00
|
|
|
|
2008-01-16 17:08:26 +08:00
|
|
|
static struct enabled_interfaces enabled = {
|
|
|
|
.headset = TRUE,
|
|
|
|
.gateway = FALSE,
|
|
|
|
.sink = TRUE,
|
|
|
|
.source = FALSE,
|
|
|
|
.control = TRUE,
|
|
|
|
};
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2008-06-02 22:34:58 +08:00
|
|
|
static DBusMessage *get_records(uuid_t *uuid, struct audio_sdp_data *data);
|
2007-05-19 09:18:39 +08:00
|
|
|
|
2008-05-29 16:05:16 +08:00
|
|
|
static struct audio_device *create_device(const bdaddr_t *bda)
|
2007-05-15 20:45:35 +08:00
|
|
|
{
|
|
|
|
static int device_id = 0;
|
2007-06-23 04:58:12 +08:00
|
|
|
char path[128];
|
2007-05-15 20:45:35 +08:00
|
|
|
|
2007-06-23 04:58:12 +08:00
|
|
|
snprintf(path, sizeof(path) - 1,
|
2007-05-15 20:45:35 +08:00
|
|
|
"%s/device%d", AUDIO_MANAGER_PATH, device_id++);
|
|
|
|
|
2007-06-23 04:58:12 +08:00
|
|
|
return device_register(connection, path, bda);
|
2007-05-19 09:18:39 +08:00
|
|
|
}
|
|
|
|
|
2008-05-29 16:05:16 +08:00
|
|
|
static void destroy_device(struct audio_device *device)
|
2007-10-02 23:48:22 +08:00
|
|
|
{
|
2008-06-03 23:10:20 +08:00
|
|
|
g_dbus_unregister_all_interfaces(connection, device->path);
|
2007-10-02 23:48:22 +08:00
|
|
|
}
|
|
|
|
|
2008-05-29 16:05:16 +08:00
|
|
|
static void remove_device(struct audio_device *device)
|
2007-05-19 09:18:39 +08:00
|
|
|
{
|
2007-06-24 03:29:13 +08:00
|
|
|
if (device == default_dev) {
|
|
|
|
debug("Removing default device");
|
|
|
|
default_dev = NULL;
|
|
|
|
}
|
|
|
|
|
2007-08-13 05:34:50 +08:00
|
|
|
if (device == default_hs) {
|
|
|
|
debug("Removing default headset");
|
|
|
|
default_hs = NULL;
|
|
|
|
}
|
|
|
|
|
2007-05-19 09:18:39 +08:00
|
|
|
devices = g_slist_remove(devices, device);
|
2007-06-24 03:29:13 +08:00
|
|
|
|
2007-10-02 23:48:22 +08:00
|
|
|
destroy_device(device);
|
2007-05-19 09:18:39 +08:00
|
|
|
}
|
|
|
|
|
2008-05-29 16:05:16 +08:00
|
|
|
static gboolean add_device(struct audio_device *device, gboolean send_signals)
|
2007-05-19 09:18:39 +08:00
|
|
|
{
|
2007-08-27 22:47:51 +08:00
|
|
|
if (!send_signals)
|
|
|
|
goto add;
|
|
|
|
|
2008-06-08 03:30:24 +08:00
|
|
|
g_dbus_emit_signal(connection, AUDIO_MANAGER_PATH,
|
2007-08-27 22:36:05 +08:00
|
|
|
AUDIO_MANAGER_INTERFACE,
|
|
|
|
"DeviceCreated",
|
|
|
|
DBUS_TYPE_STRING, &device->path,
|
|
|
|
DBUS_TYPE_INVALID);
|
|
|
|
|
|
|
|
if (device->headset)
|
2008-06-08 03:30:24 +08:00
|
|
|
g_dbus_emit_signal(connection,
|
2007-08-27 22:36:05 +08:00
|
|
|
AUDIO_MANAGER_PATH,
|
|
|
|
AUDIO_MANAGER_INTERFACE,
|
|
|
|
"HeadsetCreated",
|
|
|
|
DBUS_TYPE_STRING, &device->path,
|
|
|
|
DBUS_TYPE_INVALID);
|
2007-08-27 22:47:51 +08:00
|
|
|
add:
|
2007-08-27 22:36:05 +08:00
|
|
|
|
2007-06-24 03:29:13 +08:00
|
|
|
if (default_dev == NULL && g_slist_length(devices) == 0) {
|
|
|
|
debug("Selecting default device");
|
2007-06-19 05:08:35 +08:00
|
|
|
default_dev = device;
|
2007-06-24 03:29:13 +08:00
|
|
|
}
|
2007-06-19 05:08:35 +08:00
|
|
|
|
2007-08-13 05:34:50 +08:00
|
|
|
if (!default_hs && device->headset && !devices)
|
|
|
|
default_hs = device;
|
|
|
|
|
2007-05-15 20:45:35 +08:00
|
|
|
devices = g_slist_append(devices, device);
|
|
|
|
|
2007-05-19 09:18:39 +08:00
|
|
|
return TRUE;
|
2007-05-15 20:45:35 +08:00
|
|
|
}
|
|
|
|
|
2007-05-31 17:23:17 +08:00
|
|
|
static uint16_t get_service_uuid(const sdp_record_t *record)
|
|
|
|
{
|
|
|
|
sdp_list_t *classes;
|
|
|
|
uuid_t uuid;
|
|
|
|
uint16_t uuid16 = 0;
|
|
|
|
|
|
|
|
if (sdp_get_service_classes(record, &classes) < 0) {
|
|
|
|
error("Unable to get service classes from record");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&uuid, classes->data, sizeof(uuid));
|
2007-06-23 04:58:12 +08:00
|
|
|
|
2007-05-31 17:23:17 +08:00
|
|
|
if (!sdp_uuid128_to_uuid(&uuid)) {
|
|
|
|
error("Not a 16 bit UUID");
|
|
|
|
sdp_list_free(classes, free);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uuid.type == SDP_UUID32) {
|
2007-06-23 04:58:12 +08:00
|
|
|
if (uuid.value.uuid32 > 0xFFFF) {
|
2007-05-31 17:23:17 +08:00
|
|
|
error("Not a 16 bit UUID");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
uuid16 = (uint16_t) uuid.value.uuid32;
|
|
|
|
} else
|
|
|
|
uuid16 = uuid.value.uuid16;
|
|
|
|
|
|
|
|
done:
|
|
|
|
sdp_list_free(classes, free);
|
|
|
|
|
|
|
|
return uuid16;
|
|
|
|
}
|
|
|
|
|
2008-01-08 16:58:14 +08:00
|
|
|
gboolean server_is_enabled(uint16_t svc)
|
2007-07-21 02:03:20 +08:00
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
switch (svc) {
|
|
|
|
case HEADSET_SVCLASS_ID:
|
2008-04-21 20:49:16 +08:00
|
|
|
ret = (hsp_ag_server != NULL);
|
|
|
|
break;
|
|
|
|
case HEADSET_AGW_SVCLASS_ID:
|
|
|
|
ret = (hsp_hs_server != NULL);
|
2007-07-21 02:03:20 +08:00
|
|
|
break;
|
|
|
|
case HANDSFREE_SVCLASS_ID:
|
2008-04-21 20:49:16 +08:00
|
|
|
ret = (hfp_ag_server != NULL);
|
|
|
|
break;
|
|
|
|
case HANDSFREE_AGW_SVCLASS_ID:
|
|
|
|
ret = FALSE;
|
2007-07-21 02:03:20 +08:00
|
|
|
break;
|
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:
|
|
|
|
ret = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-05-29 16:05:16 +08:00
|
|
|
static void handle_record(sdp_record_t *record, struct audio_device *device)
|
2007-05-19 09:18:39 +08:00
|
|
|
{
|
2007-06-24 02:21:23 +08:00
|
|
|
gboolean is_default;
|
2007-05-19 09:18:39 +08:00
|
|
|
uint16_t uuid16;
|
|
|
|
|
2007-05-31 17:23:17 +08:00
|
|
|
uuid16 = get_service_uuid(record);
|
2007-05-19 09:18:39 +08:00
|
|
|
|
2007-07-21 02:03:20 +08:00
|
|
|
if (!server_is_enabled(uuid16))
|
|
|
|
return;
|
|
|
|
|
2007-05-19 09:18:39 +08:00
|
|
|
switch (uuid16) {
|
|
|
|
case HEADSET_SVCLASS_ID:
|
|
|
|
debug("Found Headset record");
|
|
|
|
if (device->headset)
|
2007-06-23 04:58:12 +08:00
|
|
|
headset_update(device, record, uuid16);
|
2007-05-19 09:18:39 +08:00
|
|
|
else
|
2007-06-23 04:58:12 +08:00
|
|
|
device->headset = headset_init(device,
|
2007-06-28 02:31:08 +08:00
|
|
|
record, uuid16);
|
2007-05-19 09:18:39 +08:00
|
|
|
break;
|
|
|
|
case HEADSET_AGW_SVCLASS_ID:
|
|
|
|
debug("Found Headset AG record");
|
|
|
|
break;
|
|
|
|
case HANDSFREE_SVCLASS_ID:
|
|
|
|
debug("Found Hansfree record");
|
2007-06-19 05:08:35 +08:00
|
|
|
if (device->headset)
|
2007-06-23 04:58:12 +08:00
|
|
|
headset_update(device, record, uuid16);
|
2007-06-19 05:08:35 +08:00
|
|
|
else
|
2007-06-23 04:58:12 +08:00
|
|
|
device->headset = headset_init(device,
|
2007-06-28 02:31:08 +08:00
|
|
|
record, uuid16);
|
2007-05-19 09:18:39 +08:00
|
|
|
break;
|
|
|
|
case HANDSFREE_AGW_SVCLASS_ID:
|
|
|
|
debug("Found Handsfree AG record");
|
|
|
|
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:
|
|
|
|
debug("Found AV Remote");
|
2007-10-23 15:54:36 +08:00
|
|
|
if (device->control == NULL)
|
|
|
|
device->control = control_init(device);
|
|
|
|
if (device->sink && sink_is_active(device))
|
|
|
|
avrcp_connect(device);
|
2007-05-19 09:18:39 +08:00
|
|
|
break;
|
|
|
|
case AV_REMOTE_TARGET_SVCLASS_ID:
|
|
|
|
debug("Found AV Target");
|
2007-10-23 15:54:36 +08:00
|
|
|
if (device->control == NULL)
|
|
|
|
device->control = control_init(device);
|
|
|
|
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-24 02:21:23 +08:00
|
|
|
|
|
|
|
is_default = (default_dev == device) ? TRUE : FALSE;
|
|
|
|
|
|
|
|
device_store(device, is_default);
|
2007-05-31 17:23:17 +08:00
|
|
|
}
|
2007-05-19 09:18:39 +08:00
|
|
|
|
|
|
|
static void finish_sdp(struct audio_sdp_data *data, gboolean success)
|
|
|
|
{
|
2007-06-23 04:58:12 +08:00
|
|
|
const char *addr;
|
2007-05-31 17:23:17 +08:00
|
|
|
DBusMessage *reply = NULL;
|
2007-06-19 05:08:35 +08:00
|
|
|
DBusError derr;
|
2007-05-19 09:18:39 +08:00
|
|
|
|
|
|
|
debug("Audio service discovery completed with %s",
|
|
|
|
success ? "success" : "failure");
|
|
|
|
|
2007-10-02 23:48:22 +08:00
|
|
|
if (!success)
|
2007-05-19 09:18:39 +08:00
|
|
|
goto done;
|
|
|
|
|
2007-05-31 17:23:17 +08:00
|
|
|
if (!data->msg)
|
|
|
|
goto update;
|
|
|
|
|
2007-06-19 05:08:35 +08:00
|
|
|
dbus_error_init(&derr);
|
2007-08-12 07:59:24 +08:00
|
|
|
dbus_message_get_args(data->msg, &derr,
|
|
|
|
DBUS_TYPE_STRING, &addr,
|
|
|
|
DBUS_TYPE_INVALID);
|
2007-06-19 05:08:35 +08:00
|
|
|
|
|
|
|
if (dbus_error_is_set(&derr)) {
|
2007-05-31 17:23:17 +08:00
|
|
|
error("Unable to get message args");
|
|
|
|
success = FALSE;
|
2007-11-26 21:43:17 +08:00
|
|
|
error_failed(connection, data->msg, derr.message);
|
2007-06-19 05:08:35 +08:00
|
|
|
dbus_error_free(&derr);
|
2007-05-31 17:23:17 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2007-05-31 19:47:29 +08:00
|
|
|
/* Return error if no audio related service records were found */
|
|
|
|
if (!data->records) {
|
|
|
|
debug("No audio audio related service records were found");
|
|
|
|
success = FALSE;
|
2007-11-26 21:43:17 +08:00
|
|
|
error_not_supported(connection, data->msg);
|
2007-05-31 19:48:02 +08:00
|
|
|
goto done;
|
2007-05-31 19:47:29 +08:00
|
|
|
}
|
|
|
|
|
2007-05-19 09:18:39 +08:00
|
|
|
reply = dbus_message_new_method_return(data->msg);
|
|
|
|
if (!reply) {
|
|
|
|
success = FALSE;
|
2007-11-26 21:43:17 +08:00
|
|
|
error_failed(connection, data->msg, "Out of memory");
|
2007-05-19 09:18:39 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2007-05-31 17:23:17 +08:00
|
|
|
update:
|
2007-05-19 09:18:39 +08:00
|
|
|
g_slist_foreach(data->records, (GFunc) handle_record, data->device);
|
|
|
|
|
2007-08-27 22:36:05 +08:00
|
|
|
if (!g_slist_find(devices, data->device))
|
2007-08-27 22:47:51 +08:00
|
|
|
add_device(data->device, TRUE);
|
2007-08-27 22:36:05 +08:00
|
|
|
|
2007-05-31 17:23:17 +08:00
|
|
|
if (reply) {
|
2007-06-23 04:58:12 +08:00
|
|
|
dbus_message_append_args(reply, DBUS_TYPE_STRING,
|
|
|
|
&data->device->path,
|
|
|
|
DBUS_TYPE_INVALID);
|
2008-06-06 18:20:21 +08:00
|
|
|
dbus_connection_send(connection, reply, NULL);
|
|
|
|
dbus_message_unref(reply);
|
2007-05-31 17:23:17 +08:00
|
|
|
}
|
2007-05-19 09:18:39 +08:00
|
|
|
|
|
|
|
done:
|
2007-08-27 20:05:10 +08:00
|
|
|
if (success) {
|
|
|
|
if (data->cb)
|
|
|
|
data->cb(data->device, data->cb_data);
|
|
|
|
} else {
|
2007-09-27 15:53:29 +08:00
|
|
|
if (data->cb)
|
|
|
|
data->cb(NULL, data->cb_data);
|
2007-10-02 23:48:22 +08:00
|
|
|
if (!g_slist_find(devices, data->device))
|
|
|
|
destroy_device(data->device);
|
2007-08-27 20:05:10 +08:00
|
|
|
}
|
2007-05-31 17:23:17 +08:00
|
|
|
if (data->msg)
|
|
|
|
dbus_message_unref(data->msg);
|
2007-05-19 09:18:39 +08:00
|
|
|
g_slist_foreach(data->records, (GFunc) sdp_record_free, NULL);
|
|
|
|
g_slist_free(data->records);
|
|
|
|
g_free(data);
|
|
|
|
}
|
|
|
|
|
2008-04-30 04:37:12 +08:00
|
|
|
static void get_records_cb(sdp_list_t *recs, int err, gpointer user_data)
|
2007-05-19 09:18:39 +08:00
|
|
|
{
|
2008-04-30 04:37:12 +08:00
|
|
|
struct audio_sdp_data *data = user_data;
|
|
|
|
sdp_list_t *seq;
|
|
|
|
uuid_t uuid;
|
2007-05-19 09:18:39 +08:00
|
|
|
|
2008-04-30 04:37:12 +08:00
|
|
|
if (err < 0) {
|
|
|
|
error_connection_attempt_failed(connection, data->msg, -err);
|
2007-05-19 09:18:39 +08:00
|
|
|
finish_sdp(data, FALSE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-30 04:37:12 +08:00
|
|
|
for (seq = recs; seq; seq = seq->next) {
|
|
|
|
sdp_record_t *rec = (sdp_record_t *) seq->data;
|
2007-05-19 09:18:39 +08:00
|
|
|
|
2008-04-30 04:37:12 +08:00
|
|
|
if (!rec)
|
|
|
|
break;
|
2007-05-19 09:18:39 +08:00
|
|
|
|
2008-04-30 04:37:12 +08:00
|
|
|
data->records = g_slist_append(data->records, rec);
|
2007-05-19 09:18:39 +08:00
|
|
|
}
|
|
|
|
|
2008-04-30 04:37:12 +08:00
|
|
|
sdp_list_free(recs, NULL);
|
2007-05-19 09:18:39 +08:00
|
|
|
|
|
|
|
data->state++;
|
|
|
|
|
|
|
|
switch (data->state) {
|
|
|
|
case ADVANCED_AUDIO:
|
2008-04-30 04:37:12 +08:00
|
|
|
sdp_uuid16_create(&uuid, ADVANCED_AUDIO_SVCLASS_ID);
|
2007-05-19 09:18:39 +08:00
|
|
|
break;
|
|
|
|
case AV_REMOTE:
|
2008-04-30 04:37:12 +08:00
|
|
|
sdp_uuid16_create(&uuid, AV_REMOTE_SVCLASS_ID);
|
2007-05-19 09:18:39 +08:00
|
|
|
break;
|
|
|
|
default:
|
2008-04-30 04:37:12 +08:00
|
|
|
finish_sdp(data, TRUE);
|
|
|
|
return;
|
2007-06-19 05:08:35 +08:00
|
|
|
}
|
2007-05-19 09:18:39 +08:00
|
|
|
|
2008-04-30 04:37:12 +08:00
|
|
|
get_records(&uuid, data);
|
2007-05-19 09:18:39 +08:00
|
|
|
}
|
|
|
|
|
2008-06-02 22:34:58 +08:00
|
|
|
static DBusMessage *get_records(uuid_t *uuid, struct audio_sdp_data *data)
|
2007-05-19 09:18:39 +08:00
|
|
|
{
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *device = data->device;
|
2008-06-06 21:10:31 +08:00
|
|
|
DBusMessage *reply = NULL;
|
2008-04-30 04:37:12 +08:00
|
|
|
int err;
|
2007-05-19 09:18:39 +08:00
|
|
|
|
2008-04-30 04:37:12 +08:00
|
|
|
err = bt_search_service(&device->src, &device->dst, uuid,
|
|
|
|
get_records_cb, data, NULL);
|
|
|
|
if (!err)
|
2008-06-06 21:10:31 +08:00
|
|
|
return NULL;
|
2007-05-19 09:18:39 +08:00
|
|
|
|
2008-04-30 04:37:12 +08:00
|
|
|
if (data->msg)
|
2008-06-06 21:10:31 +08:00
|
|
|
reply = g_dbus_create_error(data->msg,
|
|
|
|
ERROR_INTERFACE ".ConnectionAttemptFailed",
|
|
|
|
strerror(-err));
|
2007-05-19 09:18:39 +08:00
|
|
|
|
|
|
|
finish_sdp(data, FALSE);
|
2008-04-30 04:37:12 +08:00
|
|
|
|
2008-06-06 21:10:31 +08:00
|
|
|
return reply;
|
2007-05-19 09:18:39 +08:00
|
|
|
}
|
|
|
|
|
2008-06-02 22:34:58 +08:00
|
|
|
static DBusMessage *resolve_services(DBusMessage *msg,
|
|
|
|
struct audio_device *device,
|
|
|
|
create_dev_cb_t cb,
|
|
|
|
void *user_data)
|
2007-05-19 09:18:39 +08:00
|
|
|
{
|
|
|
|
struct audio_sdp_data *sdp_data;
|
2008-04-30 04:37:12 +08:00
|
|
|
uuid_t uuid;
|
2007-05-19 09:18:39 +08:00
|
|
|
|
|
|
|
sdp_data = g_new0(struct audio_sdp_data, 1);
|
2007-05-28 18:32:05 +08:00
|
|
|
if (msg)
|
|
|
|
sdp_data->msg = dbus_message_ref(msg);
|
2007-05-19 09:18:39 +08:00
|
|
|
sdp_data->device = device;
|
2007-08-27 20:05:10 +08:00
|
|
|
sdp_data->cb = cb;
|
|
|
|
sdp_data->cb_data = user_data;
|
2007-05-19 09:18:39 +08:00
|
|
|
|
2008-04-30 04:37:12 +08:00
|
|
|
sdp_uuid16_create(&uuid, GENERIC_AUDIO_SVCLASS_ID);
|
|
|
|
|
|
|
|
return get_records(&uuid, sdp_data);
|
2007-05-15 20:45:35 +08:00
|
|
|
}
|
|
|
|
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *manager_device_connected(const bdaddr_t *bda, const char *uuid)
|
2007-05-15 20:45:35 +08:00
|
|
|
{
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *device;
|
2007-05-15 20:45:35 +08:00
|
|
|
const char *path;
|
2007-08-13 05:34:50 +08:00
|
|
|
gboolean headset = FALSE, created = FALSE;
|
2007-05-15 20:45:35 +08:00
|
|
|
|
2007-08-24 07:37:15 +08:00
|
|
|
device = manager_find_device(bda, NULL, FALSE);
|
2007-05-19 09:18:39 +08:00
|
|
|
if (!device) {
|
|
|
|
device = create_device(bda);
|
2007-08-30 16:12:20 +08:00
|
|
|
if (!device)
|
|
|
|
return NULL;
|
2007-08-27 22:47:51 +08:00
|
|
|
if (!add_device(device, TRUE)) {
|
2007-10-02 23:48:22 +08:00
|
|
|
destroy_device(device);
|
2007-05-19 09:18:39 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-05-20 03:21:28 +08:00
|
|
|
created = TRUE;
|
2007-05-19 09:18:39 +08:00
|
|
|
}
|
2007-05-15 20:45:35 +08:00
|
|
|
|
2007-11-14 03:12:44 +08:00
|
|
|
if (!strcmp(uuid, HSP_AG_UUID) || !strcmp(uuid, HFP_AG_UUID)) {
|
2007-08-13 05:34:50 +08:00
|
|
|
if (device->headset)
|
|
|
|
return device;
|
|
|
|
|
2008-01-08 16:58:14 +08:00
|
|
|
device->headset = headset_init(device, NULL, 0);
|
2007-05-15 20:45:35 +08:00
|
|
|
|
2007-08-13 05:34:50 +08:00
|
|
|
if (!device->headset)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
headset = TRUE;
|
2007-10-23 15:54:36 +08:00
|
|
|
} else if (!strcmp(uuid, A2DP_SOURCE_UUID)) {
|
2007-08-13 05:34:50 +08:00
|
|
|
if (device->sink)
|
|
|
|
return device;
|
|
|
|
|
|
|
|
device->sink = sink_init(device);
|
|
|
|
|
|
|
|
if (!device->sink)
|
|
|
|
return NULL;
|
2007-10-23 15:54:36 +08:00
|
|
|
} else if (!strcmp(uuid, AVRCP_TARGET_UUID)) {
|
|
|
|
if (device->control)
|
|
|
|
return device;
|
|
|
|
|
|
|
|
device->control = control_init(device);
|
|
|
|
|
|
|
|
if (!device->control)
|
|
|
|
return NULL;
|
2007-08-13 05:34:50 +08:00
|
|
|
} else
|
2007-05-15 20:45:35 +08:00
|
|
|
return NULL;
|
|
|
|
|
2007-06-23 04:58:12 +08:00
|
|
|
path = device->path;
|
2007-04-11 16:56:50 +08:00
|
|
|
|
2007-05-31 17:23:17 +08:00
|
|
|
if (created) {
|
2008-06-08 03:30:24 +08:00
|
|
|
g_dbus_emit_signal(connection, AUDIO_MANAGER_PATH,
|
2007-05-20 03:21:28 +08:00
|
|
|
AUDIO_MANAGER_INTERFACE,
|
|
|
|
"DeviceCreated",
|
|
|
|
DBUS_TYPE_STRING, &path,
|
|
|
|
DBUS_TYPE_INVALID);
|
2007-10-02 23:48:22 +08:00
|
|
|
resolve_services(NULL, device, NULL, NULL);
|
2007-05-31 17:23:17 +08:00
|
|
|
}
|
2007-05-20 03:21:28 +08:00
|
|
|
|
2007-08-13 05:34:50 +08:00
|
|
|
if (headset)
|
2008-06-08 03:30:24 +08:00
|
|
|
g_dbus_emit_signal(connection, AUDIO_MANAGER_PATH,
|
2007-08-13 05:34:50 +08:00
|
|
|
AUDIO_MANAGER_INTERFACE,
|
|
|
|
"HeadsetCreated",
|
|
|
|
DBUS_TYPE_STRING, &path,
|
|
|
|
DBUS_TYPE_INVALID);
|
|
|
|
|
|
|
|
if (headset && !default_hs) {
|
|
|
|
default_hs = device;
|
2008-06-08 03:30:24 +08:00
|
|
|
g_dbus_emit_signal(connection, AUDIO_MANAGER_PATH,
|
2007-08-13 05:34:50 +08:00
|
|
|
AUDIO_MANAGER_INTERFACE,
|
|
|
|
"DefaultHeadsetChanged",
|
|
|
|
DBUS_TYPE_STRING, &path,
|
|
|
|
DBUS_TYPE_INVALID);
|
|
|
|
}
|
2007-04-11 19:19:58 +08:00
|
|
|
|
2007-06-19 05:08:35 +08:00
|
|
|
if (!default_dev) {
|
|
|
|
default_dev = device;
|
2008-06-08 03:30:24 +08:00
|
|
|
g_dbus_emit_signal(connection, AUDIO_MANAGER_PATH,
|
2007-05-10 06:12:20 +08:00
|
|
|
AUDIO_MANAGER_INTERFACE,
|
2007-08-13 05:34:50 +08:00
|
|
|
"DefaultDeviceChanged",
|
2007-05-15 20:45:35 +08:00
|
|
|
DBUS_TYPE_STRING, &path,
|
2007-05-10 06:12:20 +08:00
|
|
|
DBUS_TYPE_INVALID);
|
2007-04-11 19:19:58 +08:00
|
|
|
}
|
2007-04-10 19:44:10 +08:00
|
|
|
|
2007-05-15 20:45:35 +08:00
|
|
|
return device;
|
2007-04-13 19:51:00 +08:00
|
|
|
}
|
|
|
|
|
2007-08-30 16:12:20 +08:00
|
|
|
gboolean manager_create_device(bdaddr_t *bda, create_dev_cb_t cb,
|
2007-08-27 20:05:10 +08:00
|
|
|
void *user_data)
|
|
|
|
{
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *dev;
|
2007-08-27 20:05:10 +08:00
|
|
|
|
|
|
|
dev = create_device(bda);
|
2007-08-30 16:12:20 +08:00
|
|
|
if (!dev)
|
|
|
|
return FALSE;
|
|
|
|
|
2007-10-02 23:48:22 +08:00
|
|
|
resolve_services(NULL, dev, cb, user_data);
|
2007-08-30 16:12:20 +08:00
|
|
|
|
|
|
|
return TRUE;
|
2007-08-27 20:05:10 +08:00
|
|
|
}
|
|
|
|
|
2008-06-02 22:34:58 +08:00
|
|
|
static DBusMessage *am_create_device(DBusConnection *conn,
|
|
|
|
DBusMessage *msg,
|
|
|
|
void *data)
|
2007-04-10 19:44:10 +08:00
|
|
|
{
|
2007-05-31 17:23:17 +08:00
|
|
|
const char *address, *path;
|
2007-04-10 19:44:10 +08:00
|
|
|
bdaddr_t bda;
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *device;
|
2007-05-31 17:23:17 +08:00
|
|
|
DBusMessage *reply;
|
2007-04-10 19:44:10 +08:00
|
|
|
|
2008-06-06 21:10:31 +08:00
|
|
|
if (!dbus_message_get_args(msg, NULL,
|
2007-08-12 07:59:24 +08:00
|
|
|
DBUS_TYPE_STRING, &address,
|
2008-06-06 21:10:31 +08:00
|
|
|
DBUS_TYPE_INVALID))
|
|
|
|
return NULL;
|
2007-05-15 20:45:35 +08:00
|
|
|
|
|
|
|
str2ba(address, &bda);
|
|
|
|
|
2007-08-24 07:37:15 +08:00
|
|
|
device = manager_find_device(&bda, NULL, FALSE);
|
2007-05-31 17:23:17 +08:00
|
|
|
if (!device) {
|
|
|
|
device = create_device(&bda);
|
2007-10-02 23:48:22 +08:00
|
|
|
return resolve_services(msg, device, NULL, NULL);
|
2007-05-15 20:45:35 +08:00
|
|
|
}
|
|
|
|
|
2007-06-23 04:58:12 +08:00
|
|
|
path = device->path;
|
2007-05-31 17:23:17 +08:00
|
|
|
|
|
|
|
reply = dbus_message_new_method_return(msg);
|
|
|
|
if (!reply)
|
2008-06-02 22:34:58 +08:00
|
|
|
return NULL;
|
2007-05-15 20:45:35 +08:00
|
|
|
|
2007-05-31 17:23:17 +08:00
|
|
|
dbus_message_append_args(reply, DBUS_TYPE_STRING, &path,
|
|
|
|
DBUS_TYPE_INVALID);
|
|
|
|
|
2008-06-02 22:34:58 +08:00
|
|
|
return reply;
|
2007-05-15 20:45:35 +08:00
|
|
|
}
|
|
|
|
|
2008-06-02 22:34:58 +08:00
|
|
|
static DBusMessage *am_list_devices(DBusConnection *conn,
|
2007-05-18 17:15:54 +08:00
|
|
|
DBusMessage *msg,
|
|
|
|
void *data)
|
|
|
|
{
|
2007-05-19 03:10:08 +08:00
|
|
|
DBusMessageIter iter, array_iter;
|
|
|
|
DBusMessage *reply;
|
2007-05-31 17:23:17 +08:00
|
|
|
DBusError derr;
|
2007-05-19 03:10:08 +08:00
|
|
|
GSList *l;
|
2007-08-27 21:28:14 +08:00
|
|
|
gboolean hs_only = FALSE;
|
|
|
|
|
2007-05-31 17:23:17 +08:00
|
|
|
dbus_error_init(&derr);
|
2007-06-19 05:08:35 +08:00
|
|
|
|
|
|
|
if (dbus_message_is_method_call(msg, AUDIO_MANAGER_INTERFACE,
|
2007-08-27 21:28:14 +08:00
|
|
|
"ListHeadsets"))
|
|
|
|
hs_only = TRUE;
|
2007-06-19 05:08:35 +08:00
|
|
|
else
|
2007-08-27 21:28:14 +08:00
|
|
|
hs_only = FALSE;
|
2007-05-19 03:10:08 +08:00
|
|
|
|
|
|
|
reply = dbus_message_new_method_return(msg);
|
|
|
|
if (!reply)
|
2008-06-02 22:34:58 +08:00
|
|
|
return NULL;
|
2007-05-19 03:10:08 +08:00
|
|
|
|
|
|
|
dbus_message_iter_init_append(reply, &iter);
|
|
|
|
|
|
|
|
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
|
|
|
|
DBUS_TYPE_STRING_AS_STRING, &array_iter);
|
|
|
|
|
|
|
|
for (l = devices; l != NULL; l = l->next) {
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *device = l->data;
|
2007-05-19 03:10:08 +08:00
|
|
|
|
2007-08-27 21:28:14 +08:00
|
|
|
if (hs_only && !device->headset)
|
2007-05-31 17:23:17 +08:00
|
|
|
continue;
|
|
|
|
|
2007-05-19 03:10:08 +08:00
|
|
|
dbus_message_iter_append_basic(&array_iter,
|
2007-06-23 04:58:12 +08:00
|
|
|
DBUS_TYPE_STRING, &device->path);
|
2007-05-19 03:10:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dbus_message_iter_close_container(&iter, &array_iter);
|
|
|
|
|
2008-06-02 22:34:58 +08:00
|
|
|
return reply;
|
2007-05-18 17:15:54 +08:00
|
|
|
}
|
|
|
|
|
2007-05-15 20:45:35 +08:00
|
|
|
static gint device_path_cmp(gconstpointer a, gconstpointer b)
|
|
|
|
{
|
2008-05-29 16:05:16 +08:00
|
|
|
const struct audio_device *device = a;
|
2007-05-15 20:45:35 +08:00
|
|
|
const char *path = b;
|
|
|
|
|
2007-06-23 04:58:12 +08:00
|
|
|
return strcmp(device->path, path);
|
2007-05-15 20:45:35 +08:00
|
|
|
}
|
|
|
|
|
2008-06-02 22:34:58 +08:00
|
|
|
static DBusMessage *am_remove_device(DBusConnection *conn,
|
|
|
|
DBusMessage *msg,
|
|
|
|
void *data)
|
2007-04-10 19:44:10 +08:00
|
|
|
{
|
2007-04-11 16:56:50 +08:00
|
|
|
DBusMessage *reply;
|
|
|
|
GSList *match;
|
2007-05-15 20:45:35 +08:00
|
|
|
const char *path;
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *device;
|
2007-04-11 16:56:50 +08:00
|
|
|
|
2008-06-02 22:34:58 +08:00
|
|
|
if (!dbus_message_get_args(msg, NULL,
|
2007-04-11 16:56:50 +08:00
|
|
|
DBUS_TYPE_STRING, &path,
|
2008-06-02 22:34:58 +08:00
|
|
|
DBUS_TYPE_INVALID))
|
|
|
|
return NULL;
|
2007-04-11 16:56:50 +08:00
|
|
|
|
2007-05-15 20:45:35 +08:00
|
|
|
match = g_slist_find_custom(devices, path, device_path_cmp);
|
2007-04-11 16:56:50 +08:00
|
|
|
if (!match)
|
2008-06-02 22:34:58 +08:00
|
|
|
return g_dbus_create_error(msg, ERROR_INTERFACE ".DoesNotExists",
|
|
|
|
"Device does not exists");
|
2007-04-11 16:56:50 +08:00
|
|
|
|
|
|
|
reply = dbus_message_new_method_return(msg);
|
|
|
|
if (!reply)
|
2008-06-02 22:34:58 +08:00
|
|
|
return NULL;
|
2007-04-11 16:56:50 +08:00
|
|
|
|
2007-05-15 20:45:35 +08:00
|
|
|
device = match->data;
|
2007-08-14 01:16:12 +08:00
|
|
|
device_remove_stored(device);
|
2007-08-27 20:05:10 +08:00
|
|
|
remove_device(device);
|
2007-04-11 16:56:50 +08:00
|
|
|
|
2007-08-14 01:16:12 +08:00
|
|
|
/* Fallback to a valid default */
|
|
|
|
if (default_dev == NULL) {
|
2007-05-10 06:12:20 +08:00
|
|
|
const char *param;
|
2007-05-15 20:45:35 +08:00
|
|
|
GSList *l;
|
|
|
|
|
2007-08-24 07:37:15 +08:00
|
|
|
default_dev = manager_find_device(BDADDR_ANY, NULL, TRUE);
|
2007-04-11 19:19:58 +08:00
|
|
|
|
2007-08-27 22:17:39 +08:00
|
|
|
if (!default_dev && devices) {
|
2007-08-14 01:16:12 +08:00
|
|
|
l = devices;
|
|
|
|
default_dev = (g_slist_last(l))->data;
|
2007-05-15 20:45:35 +08:00
|
|
|
}
|
|
|
|
|
2007-06-23 04:58:12 +08:00
|
|
|
param = default_dev ? default_dev->path : "";
|
2007-05-10 06:12:20 +08:00
|
|
|
|
2008-06-08 03:30:24 +08:00
|
|
|
g_dbus_emit_signal(conn, AUDIO_MANAGER_PATH,
|
2007-05-10 06:12:20 +08:00
|
|
|
AUDIO_MANAGER_INTERFACE,
|
|
|
|
"DefaultHeadsetChanged",
|
|
|
|
DBUS_TYPE_STRING, ¶m,
|
|
|
|
DBUS_TYPE_INVALID);
|
2007-08-14 01:16:12 +08:00
|
|
|
|
2008-06-08 03:30:24 +08:00
|
|
|
g_dbus_emit_signal(conn, AUDIO_MANAGER_PATH,
|
2007-08-14 01:16:12 +08:00
|
|
|
AUDIO_MANAGER_INTERFACE,
|
|
|
|
"DefaultDeviceChanged",
|
|
|
|
DBUS_TYPE_STRING, ¶m,
|
|
|
|
DBUS_TYPE_INVALID);
|
|
|
|
|
2007-08-29 20:19:12 +08:00
|
|
|
if (default_dev)
|
|
|
|
device_store(default_dev, TRUE);
|
2007-04-11 16:56:50 +08:00
|
|
|
}
|
|
|
|
|
2008-06-08 03:30:24 +08:00
|
|
|
g_dbus_emit_signal(conn, AUDIO_MANAGER_PATH,
|
2007-05-10 06:12:20 +08:00
|
|
|
AUDIO_MANAGER_INTERFACE,
|
|
|
|
"HeadsetRemoved",
|
|
|
|
DBUS_TYPE_STRING, &path,
|
|
|
|
DBUS_TYPE_INVALID);
|
2007-04-11 19:19:58 +08:00
|
|
|
|
2008-06-08 03:30:24 +08:00
|
|
|
g_dbus_emit_signal(conn, AUDIO_MANAGER_PATH,
|
2007-05-19 03:13:13 +08:00
|
|
|
AUDIO_MANAGER_INTERFACE,
|
|
|
|
"DeviceRemoved",
|
|
|
|
DBUS_TYPE_STRING, &path,
|
|
|
|
DBUS_TYPE_INVALID);
|
|
|
|
|
2008-06-02 22:34:58 +08:00
|
|
|
return reply;
|
2007-04-10 19:44:10 +08:00
|
|
|
}
|
|
|
|
|
2008-06-02 22:34:58 +08:00
|
|
|
static DBusMessage *am_find_by_addr(DBusConnection *conn,
|
|
|
|
DBusMessage *msg,
|
|
|
|
void *data)
|
2007-06-04 18:30:45 +08:00
|
|
|
{
|
2007-06-23 04:58:12 +08:00
|
|
|
const char *address;
|
2007-06-04 18:30:45 +08:00
|
|
|
DBusMessage *reply;
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *device;
|
2007-06-04 18:30:45 +08:00
|
|
|
bdaddr_t bda;
|
|
|
|
|
2008-06-02 22:34:58 +08:00
|
|
|
if (!dbus_message_get_args(msg, NULL,
|
2007-06-04 18:30:45 +08:00
|
|
|
DBUS_TYPE_STRING, &address,
|
2008-06-02 22:34:58 +08:00
|
|
|
DBUS_TYPE_INVALID))
|
|
|
|
return NULL;
|
2007-06-04 18:30:45 +08:00
|
|
|
|
|
|
|
str2ba(address, &bda);
|
2007-08-24 07:37:15 +08:00
|
|
|
device = manager_find_device(&bda, NULL, FALSE);
|
2007-06-04 18:30:45 +08:00
|
|
|
|
|
|
|
if (!device)
|
2008-06-02 22:34:58 +08:00
|
|
|
return g_dbus_create_error(msg, ERROR_INTERFACE ".DoesNotExists",
|
|
|
|
"Device does not exists");
|
2007-06-04 18:30:45 +08:00
|
|
|
|
|
|
|
reply = dbus_message_new_method_return(msg);
|
|
|
|
if (!reply)
|
2008-06-02 22:34:58 +08:00
|
|
|
return NULL;
|
2007-06-04 18:30:45 +08:00
|
|
|
|
2007-06-23 04:58:12 +08:00
|
|
|
dbus_message_append_args(reply, DBUS_TYPE_STRING, &device->path,
|
2007-06-04 18:30:45 +08:00
|
|
|
DBUS_TYPE_INVALID);
|
|
|
|
|
2008-06-02 22:34:58 +08:00
|
|
|
return reply;
|
2007-06-04 18:30:45 +08:00
|
|
|
}
|
|
|
|
|
2008-06-02 22:34:58 +08:00
|
|
|
static DBusMessage *am_default_device(DBusConnection *conn,
|
|
|
|
DBusMessage *msg,
|
|
|
|
void *data)
|
2007-04-10 19:44:10 +08:00
|
|
|
{
|
|
|
|
DBusMessage *reply;
|
2007-04-11 16:56:50 +08:00
|
|
|
|
2007-06-19 05:08:35 +08:00
|
|
|
if (!default_dev)
|
2008-06-02 22:34:58 +08:00
|
|
|
return g_dbus_create_error(msg, ERROR_INTERFACE ".DoesNotExists",
|
|
|
|
"Device does not exists");
|
2007-06-19 05:08:35 +08:00
|
|
|
|
|
|
|
if (default_dev->headset == NULL &&
|
|
|
|
dbus_message_is_method_call(msg, AUDIO_MANAGER_INTERFACE,
|
2007-06-24 03:29:13 +08:00
|
|
|
"DefaultHeadset"))
|
2008-06-02 22:34:58 +08:00
|
|
|
return g_dbus_create_error(msg, ERROR_INTERFACE ".DoesNotExists",
|
|
|
|
"Device does not exists");
|
2007-04-10 19:44:10 +08:00
|
|
|
|
|
|
|
reply = dbus_message_new_method_return(msg);
|
|
|
|
if (!reply)
|
2008-06-02 22:34:58 +08:00
|
|
|
return NULL;
|
2007-04-10 19:44:10 +08:00
|
|
|
|
2007-06-23 04:58:12 +08:00
|
|
|
dbus_message_append_args(reply, DBUS_TYPE_STRING, &default_dev->path,
|
2007-04-10 19:44:10 +08:00
|
|
|
DBUS_TYPE_INVALID);
|
|
|
|
|
2008-06-02 22:34:58 +08:00
|
|
|
return reply;
|
2007-04-10 19:44:10 +08:00
|
|
|
}
|
|
|
|
|
2008-06-02 22:34:58 +08:00
|
|
|
static DBusMessage *am_change_default_device(DBusConnection *conn,
|
|
|
|
DBusMessage *msg,
|
|
|
|
void *data)
|
2007-04-10 19:44:10 +08:00
|
|
|
{
|
2007-04-11 16:56:50 +08:00
|
|
|
DBusMessage *reply;
|
|
|
|
GSList *match;
|
|
|
|
const char *path;
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *device;
|
2007-04-11 16:56:50 +08:00
|
|
|
|
2008-06-02 22:34:58 +08:00
|
|
|
if (!dbus_message_get_args(msg, NULL,
|
2007-04-11 16:56:50 +08:00
|
|
|
DBUS_TYPE_STRING, &path,
|
2008-06-02 22:34:58 +08:00
|
|
|
DBUS_TYPE_INVALID))
|
|
|
|
return NULL;
|
2007-04-11 16:56:50 +08:00
|
|
|
|
2007-05-15 20:45:35 +08:00
|
|
|
match = g_slist_find_custom(devices, path, device_path_cmp);
|
2007-04-11 16:56:50 +08:00
|
|
|
if (!match)
|
2008-06-02 22:34:58 +08:00
|
|
|
return g_dbus_create_error(msg, ERROR_INTERFACE ".DoesNotExists",
|
|
|
|
"Device does not exists");
|
2007-04-11 16:56:50 +08:00
|
|
|
|
|
|
|
reply = dbus_message_new_method_return(msg);
|
|
|
|
if (!reply)
|
2008-06-02 22:34:58 +08:00
|
|
|
return NULL;
|
2007-04-11 16:56:50 +08:00
|
|
|
|
2007-06-19 05:08:35 +08:00
|
|
|
device = match->data;
|
2007-04-11 16:56:50 +08:00
|
|
|
|
2007-06-19 05:08:35 +08:00
|
|
|
if (!dbus_message_is_method_call(msg, AUDIO_MANAGER_INTERFACE,
|
|
|
|
"ChangeDefaultHeadset"))
|
2008-06-08 03:30:24 +08:00
|
|
|
g_dbus_emit_signal(conn, AUDIO_MANAGER_PATH,
|
2007-06-19 05:08:35 +08:00
|
|
|
AUDIO_MANAGER_INTERFACE,
|
|
|
|
"DefaultDeviceChanged",
|
2007-06-23 04:58:12 +08:00
|
|
|
DBUS_TYPE_STRING, &device->path,
|
2007-06-19 05:08:35 +08:00
|
|
|
DBUS_TYPE_INVALID);
|
|
|
|
else if (device->headset)
|
2008-06-08 03:30:24 +08:00
|
|
|
g_dbus_emit_signal(conn, AUDIO_MANAGER_PATH,
|
2007-06-19 05:08:35 +08:00
|
|
|
AUDIO_MANAGER_INTERFACE,
|
|
|
|
"DefaultHeadsetChanged",
|
2007-06-23 04:58:12 +08:00
|
|
|
DBUS_TYPE_STRING, &device->path,
|
2007-06-19 05:08:35 +08:00
|
|
|
DBUS_TYPE_INVALID);
|
|
|
|
else
|
2008-06-02 22:34:58 +08:00
|
|
|
return g_dbus_create_error(msg, ERROR_INTERFACE ".DoesNotExists",
|
|
|
|
"Device does not exists");
|
2007-04-11 19:19:58 +08:00
|
|
|
|
2007-06-19 05:08:35 +08:00
|
|
|
default_dev = device;
|
2007-06-24 02:21:23 +08:00
|
|
|
device_store(device, TRUE);
|
2008-06-02 22:34:58 +08:00
|
|
|
|
|
|
|
return reply;
|
2007-04-10 19:44:10 +08:00
|
|
|
}
|
|
|
|
|
2008-06-02 22:34:58 +08:00
|
|
|
static GDBusMethodTable manager_methods[] = {
|
|
|
|
{ "CreateDevice", "s", "s", am_create_device,
|
|
|
|
G_DBUS_METHOD_FLAG_ASYNC },
|
|
|
|
{ "RemoveDevice", "s", "", am_remove_device },
|
|
|
|
{ "ListDevices", "", "as", am_list_devices },
|
|
|
|
{ "DefaultDevice", "", "s", am_default_device },
|
|
|
|
{ "ChangeDefaultDevice", "s", "", am_change_default_device },
|
|
|
|
{ "CreateHeadset", "s", "s", am_create_device,
|
|
|
|
G_DBUS_METHOD_FLAG_ASYNC },
|
|
|
|
{ "RemoveHeadset", "s", "", am_remove_device },
|
|
|
|
{ "ListHeadsets", "", "as", am_list_devices },
|
|
|
|
{ "FindDeviceByAddress", "s", "s", am_find_by_addr },
|
|
|
|
{ "DefaultHeadset", "", "s", am_default_device },
|
|
|
|
{ "ChangeDefaultHeadset", "s", "", am_change_default_device },
|
|
|
|
{ }
|
2007-05-09 23:51:02 +08:00
|
|
|
};
|
2007-04-10 19:44:10 +08:00
|
|
|
|
2008-06-02 22:34:58 +08:00
|
|
|
static GDBusSignalTable manager_signals[] = {
|
2007-05-19 02:26:56 +08:00
|
|
|
{ "DeviceCreated", "s" },
|
2007-05-18 17:15:54 +08:00
|
|
|
{ "DeviceRemoved", "s" },
|
2007-05-09 23:51:02 +08:00
|
|
|
{ "HeadsetCreated", "s" },
|
|
|
|
{ "HeadsetRemoved", "s" },
|
2007-06-19 05:08:35 +08:00
|
|
|
{ "DefaultDeviceChanged", "s" },
|
2007-05-09 23:51:02 +08:00
|
|
|
{ "DefaultHeadsetChanged", "s" },
|
2008-06-02 22:34:58 +08:00
|
|
|
{ }
|
2007-04-10 19:44:10 +08:00
|
|
|
};
|
|
|
|
|
2007-06-23 07:50:24 +08:00
|
|
|
static void parse_stored_devices(char *key, char *value, void *data)
|
|
|
|
{
|
2007-10-09 21:31:57 +08:00
|
|
|
bdaddr_t *src = data;
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *device;
|
2007-06-23 07:50:24 +08:00
|
|
|
bdaddr_t dst;
|
|
|
|
|
2007-06-24 02:21:23 +08:00
|
|
|
if (!key || !value || strcmp(key, "default") == 0)
|
2007-06-23 07:50:24 +08:00
|
|
|
return;
|
|
|
|
|
2007-06-24 03:29:13 +08:00
|
|
|
str2ba(key, &dst);
|
2007-11-22 04:24:11 +08:00
|
|
|
device = manager_find_device(&dst, NULL, FALSE);
|
2007-07-11 02:10:35 +08:00
|
|
|
|
|
|
|
if (device)
|
|
|
|
return;
|
|
|
|
|
|
|
|
info("Loading device %s (%s)", key, value);
|
2007-06-23 07:50:24 +08:00
|
|
|
|
2007-06-24 03:29:13 +08:00
|
|
|
device = create_device(&dst);
|
|
|
|
if (!device)
|
2007-06-23 07:50:24 +08:00
|
|
|
return;
|
|
|
|
|
2007-10-09 21:31:57 +08:00
|
|
|
/* Change storage to source adapter */
|
|
|
|
bacpy(&device->store, src);
|
|
|
|
|
2008-01-16 17:08:26 +08:00
|
|
|
if (enabled.headset && strstr(value, "headset"))
|
2008-01-08 16:58:14 +08:00
|
|
|
device->headset = headset_init(device, NULL, 0);
|
2008-01-16 17:08:26 +08:00
|
|
|
if (enabled.sink && strstr(value, "sink"))
|
2007-08-11 19:05:24 +08:00
|
|
|
device->sink = sink_init(device);
|
2008-01-16 17:08:26 +08:00
|
|
|
if (enabled.control && strstr(value, "control"))
|
2007-10-23 15:54:36 +08:00
|
|
|
device->control = control_init(device);
|
2007-08-27 22:47:51 +08:00
|
|
|
add_device(device, FALSE);
|
2007-06-23 07:50:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void register_devices_stored(const char *adapter)
|
|
|
|
{
|
|
|
|
char filename[PATH_MAX + 1];
|
2007-06-24 03:29:13 +08:00
|
|
|
struct stat st;
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *device;
|
2007-07-11 02:10:35 +08:00
|
|
|
bdaddr_t default_src;
|
2007-06-23 07:50:24 +08:00
|
|
|
bdaddr_t dst;
|
2007-08-24 07:37:15 +08:00
|
|
|
bdaddr_t src;
|
2007-06-23 08:17:30 +08:00
|
|
|
char *addr;
|
2007-07-11 02:10:35 +08:00
|
|
|
int dev_id;
|
2007-06-23 07:50:24 +08:00
|
|
|
|
|
|
|
create_name(filename, PATH_MAX, STORAGEDIR, adapter, "audio");
|
|
|
|
|
|
|
|
str2ba(adapter, &src);
|
|
|
|
|
2007-06-24 03:29:13 +08:00
|
|
|
if (stat(filename, &st) < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!(st.st_mode & __S_IFREG))
|
|
|
|
return;
|
|
|
|
|
|
|
|
textfile_foreach(filename, parse_stored_devices, &src);
|
2007-06-23 07:50:24 +08:00
|
|
|
|
2007-07-11 02:10:35 +08:00
|
|
|
bacpy(&default_src, BDADDR_ANY);
|
2007-08-11 23:11:13 +08:00
|
|
|
dev_id = hci_get_route(&default_src);
|
2007-10-25 05:22:40 +08:00
|
|
|
if (dev_id < 0 || hci_devba(dev_id, &default_src) < 0)
|
2007-08-21 00:57:03 +08:00
|
|
|
return;
|
2007-08-24 07:37:15 +08:00
|
|
|
|
2007-07-11 02:10:35 +08:00
|
|
|
if (bacmp(&default_src, &src) != 0)
|
|
|
|
return;
|
|
|
|
|
2007-06-24 03:29:13 +08:00
|
|
|
addr = textfile_get(filename, "default");
|
|
|
|
if (!addr)
|
|
|
|
return;
|
2007-06-24 02:57:42 +08:00
|
|
|
|
2007-06-24 03:29:13 +08:00
|
|
|
str2ba(addr, &dst);
|
2007-11-22 04:24:11 +08:00
|
|
|
device = manager_find_device(&dst, NULL, FALSE);
|
2007-06-23 07:50:24 +08:00
|
|
|
|
2007-06-24 03:29:13 +08:00
|
|
|
if (device) {
|
|
|
|
info("Setting %s as default device", addr);
|
|
|
|
default_dev = device;
|
2007-06-23 07:50:24 +08:00
|
|
|
}
|
2007-06-24 03:29:13 +08:00
|
|
|
|
|
|
|
free(addr);
|
2007-06-23 07:50:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void register_stored(void)
|
|
|
|
{
|
|
|
|
char dirname[PATH_MAX + 1];
|
|
|
|
struct dirent *de;
|
|
|
|
DIR *dir;
|
|
|
|
|
|
|
|
snprintf(dirname, PATH_MAX, "%s", STORAGEDIR);
|
|
|
|
|
|
|
|
dir = opendir(dirname);
|
|
|
|
if (!dir)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while ((de = readdir(dir)) != NULL) {
|
|
|
|
if (!isdigit(de->d_name[0]))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Device objects */
|
|
|
|
register_devices_stored(de->d_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir(dir);
|
|
|
|
}
|
|
|
|
|
2008-06-02 22:34:58 +08:00
|
|
|
static void manager_unregister(void *data)
|
2007-06-28 01:03:07 +08:00
|
|
|
{
|
|
|
|
info("Unregistered manager path");
|
|
|
|
|
|
|
|
if (devices) {
|
2007-07-19 19:28:42 +08:00
|
|
|
g_slist_foreach(devices, (GFunc) remove_device, NULL);
|
2007-06-28 01:03:07 +08:00
|
|
|
g_slist_free(devices);
|
|
|
|
devices = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
profile.version = 0x0100;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-04-21 20:49:16 +08:00
|
|
|
static sdp_record_t *hsp_hs_record(uint8_t ch)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
sdp_uuid16_create(&svclass_uuid, HEADSET_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);
|
|
|
|
sdp_set_service_classes(record, svclass_id);
|
|
|
|
|
|
|
|
sdp_uuid16_create(&profile.uuid, HEADSET_PROFILE_ID);
|
|
|
|
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);
|
|
|
|
|
|
|
|
sdp_set_info_attr(record, "Headset", 0, 0);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-04-14 22:41:42 +08:00
|
|
|
static void 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;
|
2007-07-21 02:03:20 +08:00
|
|
|
const char *uuid;
|
|
|
|
|
2008-01-08 16:58:14 +08:00
|
|
|
if (get_hfp_active(device))
|
2007-07-21 02:03:20 +08:00
|
|
|
uuid = HFP_AG_UUID;
|
2008-01-08 16:58:14 +08:00
|
|
|
else
|
|
|
|
uuid = HSP_AG_UUID;
|
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);
|
|
|
|
if (dbus_error_has_name(derr, DBUS_ERROR_NO_REPLY)) {
|
2007-07-21 02:03:20 +08:00
|
|
|
debug("Canceling authorization request");
|
2008-05-01 21:52:26 +08:00
|
|
|
if (service_cancel_auth(&device->dst) < 0)
|
2008-04-14 22:41:42 +08:00
|
|
|
manager_cancel_authorize(&device->dst, uuid,
|
|
|
|
NULL);
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
headset_set_state(device, HEADSET_STATE_DISCONNECTED);
|
|
|
|
} else {
|
|
|
|
char hs_address[18];
|
|
|
|
|
2008-02-19 16:20:22 +08:00
|
|
|
headset_set_authorized(device);
|
2007-07-21 02:03:20 +08:00
|
|
|
|
|
|
|
ba2str(&device->dst, hs_address);
|
|
|
|
|
|
|
|
debug("Accepted headset connection from %s for %s",
|
|
|
|
hs_address, device->path);
|
2008-04-26 05:49:44 +08:00
|
|
|
headset_set_state(device, HEADSET_STATE_CONNECTED);
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
2008-04-14 22:41:42 +08:00
|
|
|
}
|
|
|
|
|
2008-05-16 04:37:45 +08:00
|
|
|
static void ag_io_cb(GIOChannel *chan, int err, const bdaddr_t *src,
|
|
|
|
const bdaddr_t *dst, gpointer data)
|
2007-07-21 02:03:20 +08:00
|
|
|
{
|
|
|
|
const char *uuid;
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *device;
|
2008-01-08 16:58:14 +08:00
|
|
|
gboolean hfp_active;
|
2007-07-21 02:03:20 +08:00
|
|
|
|
2008-05-16 04:37:45 +08:00
|
|
|
if (err < 0) {
|
|
|
|
error("accept: %s (%d)", strerror(-err), -err);
|
|
|
|
return;
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
|
|
|
|
2008-04-21 20:49:16 +08:00
|
|
|
if (chan == hsp_ag_server) {
|
2008-01-08 16:58:14 +08:00
|
|
|
hfp_active = FALSE;
|
2007-08-13 05:34:50 +08:00
|
|
|
uuid = HSP_AG_UUID;
|
|
|
|
} else {
|
2008-01-08 16:58:14 +08:00
|
|
|
hfp_active = TRUE;
|
2007-08-13 05:34:50 +08:00
|
|
|
uuid = HFP_AG_UUID;
|
|
|
|
}
|
|
|
|
|
2008-05-16 04:37:45 +08:00
|
|
|
device = manager_device_connected(dst, uuid);
|
|
|
|
if (!device)
|
|
|
|
goto drop;
|
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) {
|
2007-07-21 02:03:20 +08:00
|
|
|
error("Allocating new GIOChannel failed!");
|
2008-05-16 04:37:45 +08:00
|
|
|
goto drop;
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
|
|
|
|
2008-06-17 03:43:09 +08:00
|
|
|
if (!service_req_auth(&device->src, &device->dst, uuid, auth_cb,
|
2008-04-14 22:41:42 +08:00
|
|
|
device) == 0)
|
2008-05-16 04:37:45 +08:00
|
|
|
headset_close_rfcomm(device);
|
2007-07-21 02:03:20 +08:00
|
|
|
|
2008-06-17 03:43:09 +08:00
|
|
|
headset_set_state(device, HEADSET_STATE_CONNECT_IN_PROGRESS);
|
|
|
|
|
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:
|
|
|
|
g_io_channel_close(chan);
|
|
|
|
g_io_channel_unref(chan);
|
|
|
|
return;
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
|
|
|
|
2008-05-16 04:37:45 +08:00
|
|
|
static void hs_io_cb(GIOChannel *chan, int err, const bdaddr_t *src,
|
|
|
|
const bdaddr_t *dst, void *data)
|
2008-04-21 20:49:16 +08:00
|
|
|
{
|
|
|
|
/*Stub*/
|
2008-05-16 04:37:45 +08:00
|
|
|
return;
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
|
|
|
|
2008-01-16 17:08:26 +08:00
|
|
|
static int headset_server_init(DBusConnection *conn, GKeyFile *config)
|
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-03-06 01:43:54 +08:00
|
|
|
gboolean hfp = TRUE, master = TRUE;
|
2008-01-16 17:08:26 +08:00
|
|
|
GError *err = NULL;
|
2008-05-16 04:37:45 +08:00
|
|
|
uint32_t features, flags;
|
2007-07-21 02:03:20 +08:00
|
|
|
|
2008-04-21 20:49:16 +08:00
|
|
|
if (!enabled.headset)
|
2007-08-11 19:05:24 +08:00
|
|
|
return 0;
|
|
|
|
|
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);
|
|
|
|
g_error_free(err);
|
|
|
|
err = NULL;
|
|
|
|
} else
|
|
|
|
master = tmp;
|
|
|
|
|
2008-03-06 01:45:44 +08:00
|
|
|
tmp = g_key_file_get_boolean(config, "Headset", "HFP",
|
2008-03-06 01:43:54 +08:00
|
|
|
&err);
|
|
|
|
if (err) {
|
|
|
|
debug("audio.conf: %s", err->message);
|
|
|
|
g_error_free(err);
|
|
|
|
err = NULL;
|
|
|
|
} else
|
|
|
|
hfp = tmp;
|
|
|
|
}
|
|
|
|
|
2008-05-16 04:37:45 +08:00
|
|
|
flags = RFCOMM_LM_SECURE;
|
|
|
|
|
|
|
|
if (master)
|
|
|
|
flags |= RFCOMM_LM_MASTER;
|
|
|
|
|
|
|
|
hsp_ag_server = bt_rfcomm_listen(BDADDR_ANY, chan, flags, ag_io_cb,
|
|
|
|
NULL);
|
2008-04-21 20:49:16 +08:00
|
|
|
if (!hsp_ag_server)
|
2007-07-21 02:03:20 +08:00
|
|
|
return -1;
|
|
|
|
|
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");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
if (add_record_to_server(BDADDR_ANY, 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-04-21 20:49:16 +08:00
|
|
|
g_io_channel_unref(hsp_ag_server);
|
|
|
|
hsp_ag_server = NULL;
|
2007-07-21 02:03:20 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2008-04-21 20:49:16 +08:00
|
|
|
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-03-04 21:24:38 +08:00
|
|
|
if (!hfp)
|
2007-07-21 02:03:20 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
chan = DEFAULT_HF_AG_CHANNEL;
|
|
|
|
|
2008-05-16 04:37:45 +08:00
|
|
|
hfp_ag_server = bt_rfcomm_listen(BDADDR_ANY, chan, flags, ag_io_cb,
|
|
|
|
NULL);
|
2008-04-21 20:49:16 +08:00
|
|
|
if (!hfp_ag_server)
|
2007-07-21 02:03:20 +08:00
|
|
|
return -1;
|
|
|
|
|
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");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
if (add_record_to_server(BDADDR_ANY, record) < 0) {
|
|
|
|
error("Unable to register HF AG service record");
|
|
|
|
sdp_record_free(record);
|
2008-04-21 20:49:16 +08:00
|
|
|
g_io_channel_unref(hfp_ag_server);
|
|
|
|
hfp_ag_server = NULL;
|
2007-07-21 02:03:20 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2008-04-21 20:49:16 +08:00
|
|
|
hfp_ag_record_id = record->handle;
|
2007-07-21 02:03:20 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-21 20:49:16 +08:00
|
|
|
static int gateway_server_init(DBusConnection *conn, GKeyFile *config)
|
|
|
|
{
|
|
|
|
uint8_t chan = DEFAULT_HSP_HS_CHANNEL;
|
|
|
|
sdp_record_t *record;
|
|
|
|
gboolean master = TRUE;
|
|
|
|
GError *err = NULL;
|
2008-05-16 04:37:45 +08:00
|
|
|
uint32_t flags;
|
2008-04-21 20:49:16 +08:00
|
|
|
|
|
|
|
if (!enabled.gateway)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (config) {
|
|
|
|
gboolean tmp;
|
|
|
|
|
|
|
|
tmp = g_key_file_get_boolean(config, "General", "Master",
|
|
|
|
&err);
|
|
|
|
if (err) {
|
|
|
|
debug("audio.conf: %s", err->message);
|
|
|
|
g_error_free(err);
|
|
|
|
err = NULL;
|
|
|
|
} else
|
|
|
|
master = tmp;
|
|
|
|
}
|
|
|
|
|
2008-05-16 04:37:45 +08:00
|
|
|
flags = RFCOMM_LM_SECURE;
|
|
|
|
|
|
|
|
if (master)
|
|
|
|
flags |= RFCOMM_LM_MASTER;
|
|
|
|
|
|
|
|
hsp_hs_server = bt_rfcomm_listen(BDADDR_ANY, chan, flags, hs_io_cb,
|
|
|
|
NULL);
|
2008-04-21 20:49:16 +08:00
|
|
|
if (!hsp_hs_server)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
record = hsp_hs_record(chan);
|
|
|
|
if (!record) {
|
|
|
|
error("Unable to allocate new service record");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (add_record_to_server(BDADDR_ANY, record) < 0) {
|
|
|
|
error("Unable to register HSP HS service record");
|
|
|
|
sdp_record_free(record);
|
|
|
|
g_io_channel_unref(hsp_hs_server);
|
|
|
|
hsp_hs_server = NULL;
|
|
|
|
return -1;
|
|
|
|
}
|
2008-05-16 04:37:45 +08:00
|
|
|
|
2008-04-21 20:49:16 +08:00
|
|
|
hsp_hs_record_id = record->handle;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-21 02:03:20 +08:00
|
|
|
static void server_exit(void)
|
|
|
|
{
|
2008-04-21 20:49:16 +08:00
|
|
|
if (hsp_ag_record_id) {
|
|
|
|
remove_record_from_server(hsp_ag_record_id);
|
|
|
|
hsp_ag_record_id = 0;
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
|
|
|
|
2008-04-21 20:49:16 +08:00
|
|
|
if (hsp_ag_server) {
|
|
|
|
g_io_channel_unref(hsp_ag_server);
|
|
|
|
hsp_ag_server = NULL;
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
|
|
|
|
2008-04-21 20:49:16 +08:00
|
|
|
if (hsp_hs_record_id) {
|
|
|
|
remove_record_from_server(hsp_hs_record_id);
|
|
|
|
hsp_hs_record_id = 0;
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
|
|
|
|
2008-04-21 20:49:16 +08:00
|
|
|
if (hsp_hs_server) {
|
|
|
|
g_io_channel_unref(hsp_hs_server);
|
|
|
|
hsp_hs_server = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hfp_ag_record_id) {
|
|
|
|
remove_record_from_server(hfp_ag_record_id);
|
|
|
|
hfp_ag_record_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hfp_ag_server) {
|
|
|
|
g_io_channel_unref(hfp_ag_server);
|
|
|
|
hfp_ag_server = NULL;
|
2007-07-21 02:03:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
int audio_manager_init(DBusConnection *conn, GKeyFile *config)
|
2007-03-10 06:32:47 +08:00
|
|
|
{
|
2008-05-16 20:49:57 +08:00
|
|
|
char **list;
|
|
|
|
int i;
|
2007-08-28 17:54:21 +08:00
|
|
|
|
2007-07-21 02:03:20 +08:00
|
|
|
connection = dbus_connection_ref(conn);
|
|
|
|
|
2008-05-16 20:49:57 +08:00
|
|
|
if (!config)
|
|
|
|
goto proceed;
|
|
|
|
|
|
|
|
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
|
|
|
|
2008-05-16 20:49:57 +08:00
|
|
|
proceed:
|
2008-01-16 17:08:26 +08:00
|
|
|
if (enabled.headset) {
|
|
|
|
if (headset_server_init(conn, config) < 0)
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2008-04-21 20:49:16 +08:00
|
|
|
if (enabled.gateway) {
|
|
|
|
if (gateway_server_init(conn, config) < 0)
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2008-01-23 21:27:30 +08:00
|
|
|
if (enabled.source || enabled.sink) {
|
|
|
|
if (a2dp_init(conn, config) < 0)
|
|
|
|
goto failed;
|
|
|
|
}
|
2007-08-17 06:05:55 +08:00
|
|
|
|
2008-03-06 01:43:54 +08:00
|
|
|
if (enabled.control && avrcp_init(conn, config) < 0)
|
2007-10-22 22:11:04 +08:00
|
|
|
goto failed;
|
|
|
|
|
2008-06-02 22:34:58 +08:00
|
|
|
if (!g_dbus_register_interface(conn, AUDIO_MANAGER_PATH,
|
|
|
|
AUDIO_MANAGER_INTERFACE,
|
|
|
|
manager_methods, manager_signals,
|
|
|
|
NULL, NULL, manager_unregister)) {
|
2007-05-09 23:51:02 +08:00
|
|
|
error("Failed to register %s interface to %s",
|
|
|
|
AUDIO_MANAGER_INTERFACE, AUDIO_MANAGER_PATH);
|
2007-07-21 02:03:20 +08:00
|
|
|
goto failed;
|
2007-05-09 23:51:02 +08:00
|
|
|
}
|
|
|
|
|
2007-06-23 07:50:24 +08:00
|
|
|
info("Registered manager path:%s", AUDIO_MANAGER_PATH);
|
|
|
|
|
|
|
|
register_stored();
|
|
|
|
|
2007-03-10 06:32:47 +08:00
|
|
|
return 0;
|
2007-07-21 02:03:20 +08:00
|
|
|
failed:
|
2008-03-28 07:07:19 +08:00
|
|
|
audio_manager_exit();
|
2007-07-21 02:03:20 +08:00
|
|
|
return -1;
|
2007-03-10 06:32:47 +08:00
|
|
|
}
|
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
void audio_manager_exit(void)
|
2007-03-10 06:32:47 +08:00
|
|
|
{
|
2007-07-21 02:03:20 +08:00
|
|
|
server_exit();
|
|
|
|
|
2008-06-03 23:10:20 +08:00
|
|
|
g_dbus_unregister_interface(connection, AUDIO_MANAGER_PATH,
|
|
|
|
AUDIO_MANAGER_INTERFACE);
|
2007-04-12 06:46:22 +08:00
|
|
|
|
|
|
|
dbus_connection_unref(connection);
|
2007-04-09 07:19:19 +08:00
|
|
|
|
2007-04-12 06:46:22 +08:00
|
|
|
connection = NULL;
|
2007-03-10 06:32:47 +08:00
|
|
|
}
|
2007-06-07 01:58:19 +08:00
|
|
|
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *manager_default_device(void)
|
2007-06-07 01:58:19 +08:00
|
|
|
{
|
2007-06-23 04:58:12 +08:00
|
|
|
return default_dev;
|
2007-06-07 01:58:19 +08:00
|
|
|
}
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *manager_get_connected_device(void)
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
for (l = devices; l != NULL; l = g_slist_next(l)) {
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *device = l->data;
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2007-08-21 16:02:07 +08:00
|
|
|
if ((device->sink || device->source) &&
|
|
|
|
avdtp_is_connected(&device->src, &device->dst))
|
2007-08-11 19:05:24 +08:00
|
|
|
return device;
|
|
|
|
|
|
|
|
if (device->headset && headset_is_active(device))
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-08-21 14:48:14 +08:00
|
|
|
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *manager_find_device(const bdaddr_t *bda, const char *interface,
|
2007-08-24 07:37:15 +08:00
|
|
|
gboolean connected)
|
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
if (!bacmp(bda, BDADDR_ANY) && !interface && !connected)
|
|
|
|
return default_dev;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
if (bacmp(bda, BDADDR_ANY) && bacmp(&dev->dst, bda))
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (connected && !device_is_connected(dev, interface))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|