2014-01-23 21:04:12 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* BlueZ - Bluetooth protocol stack for Linux
|
|
|
|
*
|
2014-02-12 02:42:56 +08:00
|
|
|
* Copyright (C) 2013-2014 Intel Corporation. All rights reserved.
|
2014-01-23 21:04:12 +08:00
|
|
|
*
|
|
|
|
*
|
2014-02-12 02:42:56 +08:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2014-01-23 21:04:12 +08:00
|
|
|
*
|
2014-02-12 02:42:56 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2014-01-23 21:04:12 +08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2014-02-12 02:42:56 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2014-01-23 21:04:12 +08:00
|
|
|
*
|
2014-02-12 02:42:56 +08:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2014-01-23 21:04:12 +08:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2014-03-06 20:55:57 +08:00
|
|
|
#include <stdlib.h>
|
2014-01-23 21:04:12 +08:00
|
|
|
#include <stdbool.h>
|
2014-03-01 23:30:34 +08:00
|
|
|
#include <errno.h>
|
2014-01-23 21:04:12 +08:00
|
|
|
#include <glib.h>
|
|
|
|
|
2014-01-23 23:58:05 +08:00
|
|
|
#include "btio/btio.h"
|
2014-01-23 21:04:12 +08:00
|
|
|
#include "lib/bluetooth.h"
|
2014-01-23 21:31:45 +08:00
|
|
|
#include "lib/sdp.h"
|
|
|
|
#include "lib/sdp_lib.h"
|
2014-03-04 23:34:34 +08:00
|
|
|
#include "src/sdp-client.h"
|
2014-03-25 03:25:23 +08:00
|
|
|
#include "src/shared/util.h"
|
2014-01-23 21:04:12 +08:00
|
|
|
#include "src/log.h"
|
2014-03-04 23:34:34 +08:00
|
|
|
|
2014-02-26 22:32:14 +08:00
|
|
|
#include "avctp.h"
|
2014-02-13 23:20:07 +08:00
|
|
|
#include "avrcp-lib.h"
|
2014-01-23 21:04:12 +08:00
|
|
|
#include "hal-msg.h"
|
2014-03-02 01:03:34 +08:00
|
|
|
#include "ipc-common.h"
|
2014-01-23 21:04:12 +08:00
|
|
|
#include "ipc.h"
|
2014-02-24 20:44:12 +08:00
|
|
|
#include "bluetooth.h"
|
|
|
|
#include "avrcp.h"
|
2014-03-05 20:48:00 +08:00
|
|
|
#include "utils.h"
|
2014-01-23 21:04:12 +08:00
|
|
|
|
2014-01-23 21:31:45 +08:00
|
|
|
#define L2CAP_PSM_AVCTP 0x17
|
|
|
|
|
|
|
|
#define AVRCP_FEATURE_CATEGORY_1 0x0001
|
|
|
|
#define AVRCP_FEATURE_CATEGORY_2 0x0002
|
|
|
|
#define AVRCP_FEATURE_CATEGORY_3 0x0004
|
|
|
|
#define AVRCP_FEATURE_CATEGORY_4 0x0008
|
|
|
|
|
2014-01-23 21:04:12 +08:00
|
|
|
static bdaddr_t adapter_addr;
|
2014-01-23 21:31:45 +08:00
|
|
|
static uint32_t record_id = 0;
|
2014-01-23 23:58:05 +08:00
|
|
|
static GSList *devices = NULL;
|
|
|
|
static GIOChannel *server = NULL;
|
2014-02-24 20:44:12 +08:00
|
|
|
static struct ipc *hal_ipc = NULL;
|
2014-01-23 23:58:05 +08:00
|
|
|
|
2014-03-02 01:03:34 +08:00
|
|
|
struct avrcp_request {
|
|
|
|
struct avrcp_device *dev;
|
|
|
|
uint8_t pdu_id;
|
2014-03-05 04:43:22 +08:00
|
|
|
uint8_t event_id;
|
2014-03-02 01:03:34 +08:00
|
|
|
uint8_t transaction;
|
|
|
|
};
|
|
|
|
|
2014-01-23 23:58:05 +08:00
|
|
|
struct avrcp_device {
|
|
|
|
bdaddr_t dst;
|
2014-03-04 23:34:34 +08:00
|
|
|
uint16_t version;
|
|
|
|
uint16_t features;
|
2014-02-13 23:20:07 +08:00
|
|
|
struct avrcp *session;
|
2014-02-05 18:26:57 +08:00
|
|
|
GIOChannel *io;
|
2014-03-02 01:03:34 +08:00
|
|
|
GQueue *queue;
|
2014-01-23 23:58:05 +08:00
|
|
|
};
|
2014-01-23 21:04:12 +08:00
|
|
|
|
2014-03-05 04:43:22 +08:00
|
|
|
static struct avrcp_request *pop_request(uint8_t pdu_id, uint8_t event_id,
|
|
|
|
bool peek)
|
2014-03-02 01:03:34 +08:00
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
for (l = devices; l; l = g_slist_next(l)) {
|
|
|
|
struct avrcp_device *dev = l->data;
|
|
|
|
GList *reqs = g_queue_peek_head_link(dev->queue);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; reqs; reqs = g_list_next(reqs), i++) {
|
|
|
|
struct avrcp_request *req = reqs->data;
|
|
|
|
|
2014-03-05 04:43:22 +08:00
|
|
|
if (req->pdu_id != pdu_id || req->event_id != event_id)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!peek)
|
2014-03-02 01:03:34 +08:00
|
|
|
g_queue_pop_nth(dev->queue, i);
|
2014-03-05 04:43:22 +08:00
|
|
|
|
|
|
|
return req;
|
2014-03-02 01:03:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-02-20 00:58:47 +08:00
|
|
|
static void handle_get_play_status(const void *buf, uint16_t len)
|
|
|
|
{
|
2014-03-02 01:03:34 +08:00
|
|
|
const struct hal_cmd_avrcp_get_play_status *cmd = buf;
|
|
|
|
uint8_t status;
|
|
|
|
struct avrcp_request *req;
|
|
|
|
int ret;
|
|
|
|
|
2014-02-20 00:58:47 +08:00
|
|
|
DBG("");
|
|
|
|
|
2014-03-05 04:43:22 +08:00
|
|
|
req = pop_request(AVRCP_GET_PLAY_STATUS, 0, false);
|
2014-03-02 01:03:34 +08:00
|
|
|
if (!req) {
|
|
|
|
status = HAL_STATUS_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = avrcp_get_play_status_rsp(req->dev->session, req->transaction,
|
|
|
|
cmd->position, cmd->duration,
|
|
|
|
cmd->status);
|
|
|
|
if (ret < 0) {
|
|
|
|
status = HAL_STATUS_FAILED;
|
|
|
|
g_free(req);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = HAL_STATUS_SUCCESS;
|
|
|
|
g_free(req);
|
|
|
|
|
|
|
|
done:
|
2014-02-24 20:44:12 +08:00
|
|
|
ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP,
|
2014-03-02 01:03:34 +08:00
|
|
|
HAL_OP_AVRCP_GET_PLAY_STATUS, status);
|
2014-02-20 00:58:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_list_player_attrs(const void *buf, uint16_t len)
|
|
|
|
{
|
|
|
|
DBG("");
|
|
|
|
|
2014-02-24 20:44:12 +08:00
|
|
|
ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP,
|
|
|
|
HAL_OP_AVRCP_LIST_PLAYER_ATTRS, HAL_STATUS_FAILED);
|
2014-02-20 00:58:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_list_player_values(const void *buf, uint16_t len)
|
|
|
|
{
|
|
|
|
DBG("");
|
|
|
|
|
2014-02-24 20:44:12 +08:00
|
|
|
ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP,
|
|
|
|
HAL_OP_AVRCP_LIST_PLAYER_VALUES, HAL_STATUS_FAILED);
|
2014-02-20 00:58:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_get_player_attrs(const void *buf, uint16_t len)
|
|
|
|
{
|
|
|
|
DBG("");
|
|
|
|
|
2014-02-24 20:44:12 +08:00
|
|
|
ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP,
|
|
|
|
HAL_OP_AVRCP_GET_PLAYER_ATTRS, HAL_STATUS_FAILED);
|
2014-02-20 00:58:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_get_player_attrs_text(const void *buf, uint16_t len)
|
|
|
|
{
|
|
|
|
DBG("");
|
|
|
|
|
2014-02-24 20:44:12 +08:00
|
|
|
ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP,
|
|
|
|
HAL_OP_AVRCP_GET_PLAYER_ATTRS_TEXT, HAL_STATUS_FAILED);
|
2014-02-20 00:58:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_get_player_values_text(const void *buf, uint16_t len)
|
|
|
|
{
|
|
|
|
DBG("");
|
|
|
|
|
2014-02-24 20:44:12 +08:00
|
|
|
ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP,
|
|
|
|
HAL_OP_AVRCP_GET_PLAYER_VALUES_TEXT, HAL_STATUS_FAILED);
|
2014-02-20 00:58:47 +08:00
|
|
|
}
|
|
|
|
|
2014-03-05 04:43:23 +08:00
|
|
|
static size_t write_element_text(uint8_t id, uint8_t text_len, uint8_t *text,
|
|
|
|
uint8_t *pdu)
|
2014-03-02 22:39:36 +08:00
|
|
|
{
|
|
|
|
uint16_t charset = 106;
|
2014-03-05 04:43:23 +08:00
|
|
|
size_t len = 0;
|
2014-03-02 22:39:36 +08:00
|
|
|
|
2014-03-25 03:25:26 +08:00
|
|
|
put_be32(id, pdu);
|
2014-03-02 22:39:36 +08:00
|
|
|
pdu += 4;
|
2014-03-05 04:43:23 +08:00
|
|
|
len += 4;
|
2014-03-02 22:39:36 +08:00
|
|
|
|
2014-03-25 03:25:25 +08:00
|
|
|
put_be16(charset, pdu);
|
2014-03-02 22:39:36 +08:00
|
|
|
pdu += 2;
|
2014-03-05 04:43:23 +08:00
|
|
|
len += 2;
|
2014-03-02 22:39:36 +08:00
|
|
|
|
2014-03-25 03:25:25 +08:00
|
|
|
put_be16(text_len, pdu);
|
2014-03-02 22:39:36 +08:00
|
|
|
pdu += 2;
|
2014-03-05 04:43:23 +08:00
|
|
|
len += 2;
|
2014-03-02 22:39:36 +08:00
|
|
|
|
|
|
|
memcpy(pdu, text, text_len);
|
2014-03-05 04:43:23 +08:00
|
|
|
len += text_len;
|
|
|
|
|
|
|
|
return len;
|
2014-03-02 22:39:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void write_element_attrs(uint8_t *ptr, uint8_t number, uint8_t *pdu,
|
|
|
|
size_t *len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
*pdu = number;
|
|
|
|
pdu++;
|
|
|
|
*len += 1;
|
|
|
|
|
|
|
|
for (i = 0; i < number; i++) {
|
|
|
|
struct hal_avrcp_player_setting_text *text = (void *) ptr;
|
2014-03-05 04:43:23 +08:00
|
|
|
size_t ret;
|
2014-03-02 22:39:36 +08:00
|
|
|
|
2014-03-05 04:43:23 +08:00
|
|
|
ret = write_element_text(text->id, text->len, text->text, pdu);
|
2014-03-02 22:39:36 +08:00
|
|
|
|
|
|
|
ptr += sizeof(*text) + text->len;
|
2014-03-05 04:43:23 +08:00
|
|
|
pdu += ret;
|
|
|
|
*len += ret;
|
2014-03-02 22:39:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-20 00:58:47 +08:00
|
|
|
static void handle_get_element_attrs_text(const void *buf, uint16_t len)
|
|
|
|
{
|
2014-03-02 22:39:36 +08:00
|
|
|
struct hal_cmd_avrcp_get_element_attrs_text *cmd = (void *) buf;
|
|
|
|
uint8_t status;
|
|
|
|
struct avrcp_request *req;
|
|
|
|
uint8_t pdu[IPC_MTU];
|
|
|
|
uint8_t *ptr;
|
|
|
|
size_t pdu_len;
|
|
|
|
int ret;
|
|
|
|
|
2014-02-20 00:58:47 +08:00
|
|
|
DBG("");
|
|
|
|
|
2014-03-05 04:43:22 +08:00
|
|
|
req = pop_request(AVRCP_GET_ELEMENT_ATTRIBUTES, 0, false);
|
2014-03-02 22:39:36 +08:00
|
|
|
if (!req) {
|
|
|
|
status = HAL_STATUS_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr = (uint8_t *) &cmd->values[0];
|
|
|
|
pdu_len = 0;
|
|
|
|
write_element_attrs(ptr, cmd->number, pdu, &pdu_len);
|
|
|
|
|
|
|
|
ret = avrcp_get_element_attrs_rsp(req->dev->session, req->transaction,
|
|
|
|
pdu, pdu_len);
|
|
|
|
if (ret < 0) {
|
|
|
|
status = HAL_STATUS_FAILED;
|
|
|
|
g_free(req);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = HAL_STATUS_SUCCESS;
|
|
|
|
g_free(req);
|
|
|
|
|
|
|
|
done:
|
2014-02-24 20:44:12 +08:00
|
|
|
ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP,
|
2014-03-02 22:39:36 +08:00
|
|
|
HAL_OP_AVRCP_GET_ELEMENT_ATTRS_TEXT, status);
|
2014-02-20 00:58:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_set_player_attrs_value(const void *buf, uint16_t len)
|
|
|
|
{
|
|
|
|
DBG("");
|
|
|
|
|
2014-02-24 20:44:12 +08:00
|
|
|
ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP,
|
|
|
|
HAL_OP_AVRCP_SET_PLAYER_ATTRS_VALUE, HAL_STATUS_FAILED);
|
2014-02-20 00:58:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_register_notification(const void *buf, uint16_t len)
|
|
|
|
{
|
2014-03-02 23:48:55 +08:00
|
|
|
struct hal_cmd_avrcp_register_notification *cmd = (void *) buf;
|
|
|
|
uint8_t status;
|
|
|
|
struct avrcp_request *req;
|
|
|
|
uint8_t pdu[IPC_MTU];
|
|
|
|
size_t pdu_len;
|
2014-03-05 04:43:21 +08:00
|
|
|
uint8_t code;
|
2014-03-05 04:43:22 +08:00
|
|
|
bool peek = false;
|
2014-03-02 23:48:55 +08:00
|
|
|
int ret;
|
|
|
|
|
2014-02-20 00:58:47 +08:00
|
|
|
DBG("");
|
|
|
|
|
2014-03-05 04:43:22 +08:00
|
|
|
switch (cmd->type) {
|
|
|
|
case HAL_AVRCP_EVENT_TYPE_INTERIM:
|
|
|
|
code = AVC_CTYPE_INTERIM;
|
|
|
|
peek = true;
|
|
|
|
break;
|
|
|
|
case HAL_AVRCP_EVENT_TYPE_CHANGED:
|
|
|
|
code = AVC_CTYPE_CHANGED;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
status = HAL_STATUS_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
req = pop_request(AVRCP_REGISTER_NOTIFICATION, cmd->event, peek);
|
2014-03-02 23:48:55 +08:00
|
|
|
if (!req) {
|
|
|
|
status = HAL_STATUS_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdu[0] = cmd->event;
|
|
|
|
pdu_len = 1;
|
|
|
|
|
|
|
|
switch (cmd->event) {
|
|
|
|
case AVRCP_EVENT_STATUS_CHANGED:
|
|
|
|
case AVRCP_EVENT_TRACK_CHANGED:
|
|
|
|
case AVRCP_EVENT_PLAYBACK_POS_CHANGED:
|
|
|
|
memcpy(&pdu[1], cmd->data, cmd->len);
|
|
|
|
pdu_len += cmd->len;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
status = HAL_STATUS_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = avrcp_register_notification_rsp(req->dev->session,
|
2014-03-05 04:43:21 +08:00
|
|
|
req->transaction, code,
|
2014-03-02 23:48:55 +08:00
|
|
|
pdu, pdu_len);
|
|
|
|
if (ret < 0) {
|
|
|
|
status = HAL_STATUS_FAILED;
|
2014-03-05 04:43:22 +08:00
|
|
|
if (!peek)
|
|
|
|
g_free(req);
|
2014-03-02 23:48:55 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = HAL_STATUS_SUCCESS;
|
2014-03-05 04:43:22 +08:00
|
|
|
if (!peek)
|
|
|
|
g_free(req);
|
2014-03-02 23:48:55 +08:00
|
|
|
|
|
|
|
done:
|
2014-02-24 20:44:12 +08:00
|
|
|
ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP,
|
2014-03-02 23:48:55 +08:00
|
|
|
HAL_OP_AVRCP_REGISTER_NOTIFICATION, status);
|
2014-02-20 00:58:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_set_volume(const void *buf, uint16_t len)
|
|
|
|
{
|
2014-03-07 19:16:00 +08:00
|
|
|
struct hal_cmd_avrcp_set_volume *cmd = (void *) buf;
|
|
|
|
struct avrcp_device *dev;
|
|
|
|
uint8_t status;
|
|
|
|
int ret;
|
|
|
|
|
2014-02-20 00:58:47 +08:00
|
|
|
DBG("");
|
|
|
|
|
2014-03-07 19:16:00 +08:00
|
|
|
if (!devices) {
|
|
|
|
error("AVRCP: No device found to set volume");
|
|
|
|
status = HAL_STATUS_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2014-04-29 19:17:25 +08:00
|
|
|
/*
|
|
|
|
* Peek the first device since the HAL cannot really address a specific
|
2014-03-07 19:16:00 +08:00
|
|
|
* device it might mean there could only be one connected.
|
|
|
|
*/
|
|
|
|
dev = devices->data;
|
|
|
|
|
2014-04-03 22:59:27 +08:00
|
|
|
ret = avrcp_set_volume(dev->session, cmd->value & 0x7f);
|
2014-03-07 19:16:00 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
status = HAL_STATUS_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = HAL_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
done:
|
2014-02-24 20:44:12 +08:00
|
|
|
ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP, HAL_OP_AVRCP_SET_VOLUME,
|
2014-03-07 19:16:00 +08:00
|
|
|
status);
|
2014-02-20 00:58:47 +08:00
|
|
|
}
|
|
|
|
|
2014-01-23 21:04:12 +08:00
|
|
|
static const struct ipc_handler cmd_handlers[] = {
|
2014-02-20 00:58:47 +08:00
|
|
|
/* HAL_OP_AVRCP_GET_PLAY_STATUS */
|
|
|
|
{ handle_get_play_status, false,
|
|
|
|
sizeof(struct hal_cmd_avrcp_get_play_status) },
|
|
|
|
/* HAL_OP_AVRCP_LIST_PLAYER_ATTRS */
|
|
|
|
{ handle_list_player_attrs, true,
|
|
|
|
sizeof(struct hal_cmd_avrcp_list_player_attrs) },
|
|
|
|
/* HAL_OP_AVRCP_LIST_PLAYER_VALUES */
|
|
|
|
{ handle_list_player_values, true,
|
|
|
|
sizeof(struct hal_cmd_avrcp_list_player_values) },
|
|
|
|
/* HAL_OP_AVRCP_GET_PLAYER_ATTRS */
|
|
|
|
{ handle_get_player_attrs, true,
|
|
|
|
sizeof(struct hal_cmd_avrcp_get_player_attrs) },
|
|
|
|
/* HAL_OP_AVRCP_GET_PLAYER_ATTRS_TEXT */
|
|
|
|
{ handle_get_player_attrs_text, true,
|
|
|
|
sizeof(struct hal_cmd_avrcp_get_player_attrs_text) },
|
|
|
|
/* HAL_OP_AVRCP_GET_PLAYER_VALUES_TEXT */
|
|
|
|
{ handle_get_player_values_text, true,
|
|
|
|
sizeof(struct hal_cmd_avrcp_get_player_values_text) },
|
|
|
|
/* HAL_OP_AVRCP_GET_ELEMENT_ATTRS_TEXT */
|
|
|
|
{ handle_get_element_attrs_text, true,
|
|
|
|
sizeof(struct hal_cmd_avrcp_get_element_attrs_text) },
|
|
|
|
/* HAL_OP_AVRCP_SET_PLAYER_ATTRS_VALUE */
|
|
|
|
{ handle_set_player_attrs_value, true,
|
|
|
|
sizeof(struct hal_cmd_avrcp_set_player_attrs_value) },
|
|
|
|
/* HAL_OP_AVRCP_REGISTER_NOTIFICATION */
|
|
|
|
{ handle_register_notification, true,
|
|
|
|
sizeof(struct hal_cmd_avrcp_register_notification) },
|
|
|
|
/* HAL_OP_AVRCP_SET_VOLUME */
|
|
|
|
{ handle_set_volume, false, sizeof(struct hal_cmd_avrcp_set_volume) },
|
2014-01-23 21:04:12 +08:00
|
|
|
};
|
|
|
|
|
2014-01-23 21:31:45 +08:00
|
|
|
static sdp_record_t *avrcp_record(void)
|
|
|
|
{
|
|
|
|
sdp_list_t *svclass_id, *pfseq, *apseq, *root;
|
|
|
|
uuid_t root_uuid, l2cap, avctp, avrtg;
|
|
|
|
sdp_profile_desc_t profile[1];
|
|
|
|
sdp_list_t *aproto_control, *proto_control[2];
|
|
|
|
sdp_record_t *record;
|
|
|
|
sdp_data_t *psm, *version, *features;
|
|
|
|
uint16_t lp = L2CAP_PSM_AVCTP;
|
2014-03-18 22:40:04 +08:00
|
|
|
uint16_t avrcp_ver = 0x0105, avctp_ver = 0x0104;
|
2014-03-20 21:27:07 +08:00
|
|
|
uint16_t feat = (AVRCP_FEATURE_CATEGORY_1 |
|
2014-01-23 21:31:45 +08:00
|
|
|
AVRCP_FEATURE_CATEGORY_2 |
|
|
|
|
AVRCP_FEATURE_CATEGORY_3 |
|
|
|
|
AVRCP_FEATURE_CATEGORY_4);
|
|
|
|
|
|
|
|
record = sdp_record_alloc();
|
|
|
|
if (!record)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP);
|
|
|
|
root = sdp_list_append(NULL, &root_uuid);
|
|
|
|
sdp_set_browse_groups(record, root);
|
|
|
|
|
|
|
|
/* Service Class ID List */
|
|
|
|
sdp_uuid16_create(&avrtg, AV_REMOTE_TARGET_SVCLASS_ID);
|
|
|
|
svclass_id = sdp_list_append(NULL, &avrtg);
|
|
|
|
sdp_set_service_classes(record, svclass_id);
|
|
|
|
|
|
|
|
/* Protocol Descriptor List */
|
|
|
|
sdp_uuid16_create(&l2cap, L2CAP_UUID);
|
|
|
|
proto_control[0] = sdp_list_append(NULL, &l2cap);
|
|
|
|
psm = sdp_data_alloc(SDP_UINT16, &lp);
|
|
|
|
proto_control[0] = sdp_list_append(proto_control[0], psm);
|
|
|
|
apseq = sdp_list_append(NULL, proto_control[0]);
|
|
|
|
|
|
|
|
sdp_uuid16_create(&avctp, AVCTP_UUID);
|
|
|
|
proto_control[1] = sdp_list_append(NULL, &avctp);
|
|
|
|
version = sdp_data_alloc(SDP_UINT16, &avctp_ver);
|
|
|
|
proto_control[1] = sdp_list_append(proto_control[1], version);
|
|
|
|
apseq = sdp_list_append(apseq, proto_control[1]);
|
|
|
|
|
|
|
|
aproto_control = sdp_list_append(NULL, apseq);
|
|
|
|
sdp_set_access_protos(record, aproto_control);
|
|
|
|
|
|
|
|
/* Bluetooth Profile Descriptor List */
|
|
|
|
sdp_uuid16_create(&profile[0].uuid, AV_REMOTE_PROFILE_ID);
|
|
|
|
profile[0].version = avrcp_ver;
|
|
|
|
pfseq = sdp_list_append(NULL, &profile[0]);
|
|
|
|
sdp_set_profile_descs(record, pfseq);
|
|
|
|
|
|
|
|
features = sdp_data_alloc(SDP_UINT16, &feat);
|
|
|
|
sdp_attr_add(record, SDP_ATTR_SUPPORTED_FEATURES, features);
|
|
|
|
|
2014-02-21 23:23:48 +08:00
|
|
|
sdp_set_info_attr(record, "AVRCP TG", NULL, NULL);
|
2014-01-23 21:31:45 +08:00
|
|
|
|
|
|
|
sdp_data_free(psm);
|
|
|
|
sdp_data_free(version);
|
|
|
|
sdp_list_free(proto_control[0], NULL);
|
|
|
|
sdp_list_free(proto_control[1], NULL);
|
|
|
|
sdp_list_free(apseq, NULL);
|
|
|
|
sdp_list_free(aproto_control, NULL);
|
|
|
|
sdp_list_free(pfseq, NULL);
|
|
|
|
sdp_list_free(root, NULL);
|
|
|
|
sdp_list_free(svclass_id, NULL);
|
|
|
|
|
|
|
|
return record;
|
|
|
|
}
|
|
|
|
|
2014-01-23 23:58:05 +08:00
|
|
|
static void avrcp_device_free(void *data)
|
|
|
|
{
|
|
|
|
struct avrcp_device *dev = data;
|
|
|
|
|
2014-03-06 20:58:02 +08:00
|
|
|
if (dev->queue) {
|
|
|
|
g_queue_foreach(dev->queue, (GFunc) g_free, NULL);
|
|
|
|
g_queue_free(dev->queue);
|
|
|
|
}
|
2014-03-02 01:03:34 +08:00
|
|
|
|
2014-01-23 23:58:05 +08:00
|
|
|
if (dev->session)
|
2014-02-13 23:20:07 +08:00
|
|
|
avrcp_shutdown(dev->session);
|
2014-01-23 23:58:05 +08:00
|
|
|
|
2014-02-05 18:26:58 +08:00
|
|
|
if (dev->io) {
|
|
|
|
g_io_channel_shutdown(dev->io, FALSE, NULL);
|
|
|
|
g_io_channel_unref(dev->io);
|
|
|
|
}
|
|
|
|
|
2014-01-23 23:58:05 +08:00
|
|
|
g_free(dev);
|
|
|
|
}
|
|
|
|
|
2014-02-06 20:32:18 +08:00
|
|
|
static void avrcp_device_remove(struct avrcp_device *dev)
|
|
|
|
{
|
|
|
|
devices = g_slist_remove(devices, dev);
|
|
|
|
avrcp_device_free(dev);
|
|
|
|
}
|
|
|
|
|
2014-01-23 23:58:05 +08:00
|
|
|
static struct avrcp_device *avrcp_device_new(const bdaddr_t *dst)
|
|
|
|
{
|
|
|
|
struct avrcp_device *dev;
|
|
|
|
|
|
|
|
dev = g_new0(struct avrcp_device, 1);
|
|
|
|
bacpy(&dev->dst, dst);
|
|
|
|
devices = g_slist_prepend(devices, dev);
|
|
|
|
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int device_cmp(gconstpointer s, gconstpointer user_data)
|
|
|
|
{
|
|
|
|
const struct avrcp_device *dev = s;
|
|
|
|
const bdaddr_t *dst = user_data;
|
|
|
|
|
|
|
|
return bacmp(&dev->dst, dst);
|
|
|
|
}
|
|
|
|
|
2014-02-13 23:20:07 +08:00
|
|
|
static struct avrcp_device *avrcp_device_find(const bdaddr_t *dst)
|
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
l = g_slist_find_custom(devices, dst, device_cmp);
|
|
|
|
if (!l)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return l->data;
|
|
|
|
}
|
|
|
|
|
2014-01-23 23:58:05 +08:00
|
|
|
static void disconnect_cb(void *data)
|
|
|
|
{
|
|
|
|
struct avrcp_device *dev = data;
|
|
|
|
|
|
|
|
DBG("");
|
|
|
|
|
|
|
|
dev->session = NULL;
|
|
|
|
|
2014-02-06 20:32:18 +08:00
|
|
|
avrcp_device_remove(dev);
|
2014-01-23 23:58:05 +08:00
|
|
|
}
|
|
|
|
|
2014-03-01 22:29:23 +08:00
|
|
|
static bool handle_fast_forward(struct avrcp *session, bool pressed,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct hal_ev_avrcp_passthrough_cmd ev;
|
|
|
|
|
|
|
|
DBG("pressed %s", pressed ? "true" : "false");
|
|
|
|
|
|
|
|
ev.id = AVC_FAST_FORWARD;
|
|
|
|
ev.state = pressed;
|
|
|
|
|
|
|
|
ipc_send_notif(hal_ipc, HAL_SERVICE_ID_AVRCP,
|
|
|
|
HAL_EV_AVRCP_PASSTHROUGH_CMD, sizeof(ev), &ev);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-01 22:48:34 +08:00
|
|
|
static bool handle_rewind(struct avrcp *session, bool pressed,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct hal_ev_avrcp_passthrough_cmd ev;
|
|
|
|
|
|
|
|
DBG("pressed %s", pressed ? "true" : "false");
|
|
|
|
|
|
|
|
ev.id = AVC_REWIND;
|
|
|
|
ev.state = pressed;
|
|
|
|
|
|
|
|
ipc_send_notif(hal_ipc, HAL_SERVICE_ID_AVRCP,
|
|
|
|
HAL_EV_AVRCP_PASSTHROUGH_CMD, sizeof(ev), &ev);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-01 22:29:23 +08:00
|
|
|
static const struct avrcp_passthrough_handler passthrough_handlers[] = {
|
|
|
|
{ AVC_FAST_FORWARD, handle_fast_forward },
|
2014-03-01 22:48:34 +08:00
|
|
|
{ AVC_REWIND, handle_rewind },
|
2014-03-01 22:29:23 +08:00
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
2014-03-17 01:39:46 +08:00
|
|
|
static int handle_get_capabilities_cmd(struct avrcp *session,
|
|
|
|
uint8_t transaction, void *user_data)
|
2014-03-01 23:30:34 +08:00
|
|
|
{
|
2014-03-17 01:39:46 +08:00
|
|
|
uint8_t events[] = { AVRCP_EVENT_STATUS_CHANGED,
|
|
|
|
AVRCP_EVENT_TRACK_CHANGED,
|
|
|
|
AVRCP_EVENT_PLAYBACK_POS_CHANGED };
|
2014-03-01 23:30:34 +08:00
|
|
|
|
2014-03-17 01:39:46 +08:00
|
|
|
DBG("");
|
2014-03-01 23:30:34 +08:00
|
|
|
|
2014-04-29 19:17:25 +08:00
|
|
|
/*
|
|
|
|
* Android do not provide this info via HAL so the list most
|
2014-03-17 01:39:46 +08:00
|
|
|
* be hardcoded according to what RegisterNotification can
|
2014-04-29 19:17:25 +08:00
|
|
|
* actually handle
|
|
|
|
*/
|
2014-03-17 01:39:46 +08:00
|
|
|
avrcp_get_capabilities_rsp(session, transaction, sizeof(events),
|
|
|
|
events);
|
2014-03-01 23:30:34 +08:00
|
|
|
|
2014-03-17 01:39:46 +08:00
|
|
|
return -EAGAIN;
|
2014-03-01 23:30:34 +08:00
|
|
|
}
|
|
|
|
|
2014-03-02 01:03:34 +08:00
|
|
|
static void push_request(struct avrcp_device *dev, uint8_t pdu_id,
|
2014-03-05 04:43:22 +08:00
|
|
|
uint8_t event_id, uint8_t transaction)
|
2014-03-02 01:03:34 +08:00
|
|
|
{
|
|
|
|
struct avrcp_request *req;
|
|
|
|
|
|
|
|
req = g_new0(struct avrcp_request, 1);
|
|
|
|
req->dev = dev;
|
|
|
|
req->pdu_id = pdu_id;
|
2014-03-05 04:43:22 +08:00
|
|
|
req->event_id = event_id;
|
2014-03-02 01:03:34 +08:00
|
|
|
req->transaction = transaction;
|
|
|
|
|
|
|
|
g_queue_push_tail(dev->queue, req);
|
|
|
|
}
|
|
|
|
|
2014-03-17 01:39:46 +08:00
|
|
|
static int handle_get_play_status_cmd(struct avrcp *session,
|
|
|
|
uint8_t transaction, void *user_data)
|
2014-03-02 01:03:34 +08:00
|
|
|
{
|
|
|
|
struct avrcp_device *dev = user_data;
|
|
|
|
|
|
|
|
DBG("");
|
|
|
|
|
|
|
|
ipc_send_notif(hal_ipc, HAL_SERVICE_ID_AVRCP,
|
|
|
|
HAL_EV_AVRCP_GET_PLAY_STATUS, 0, NULL);
|
|
|
|
|
2014-03-05 04:43:22 +08:00
|
|
|
push_request(dev, AVRCP_GET_PLAY_STATUS, 0, transaction);
|
2014-03-02 01:03:34 +08:00
|
|
|
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
2014-03-17 01:39:46 +08:00
|
|
|
static int handle_get_element_attrs_cmd(struct avrcp *session,
|
|
|
|
uint8_t transaction, uint64_t uid,
|
|
|
|
uint8_t number, uint32_t *attrs,
|
|
|
|
void *user_data)
|
2014-03-02 22:39:36 +08:00
|
|
|
{
|
|
|
|
struct avrcp_device *dev = user_data;
|
|
|
|
uint8_t buf[IPC_MTU];
|
|
|
|
struct hal_ev_avrcp_get_element_attrs *ev = (void *) buf;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
DBG("");
|
|
|
|
|
2014-03-17 01:39:46 +08:00
|
|
|
ev->number = number;
|
2014-03-08 06:43:38 +08:00
|
|
|
/* Set everything in case of empty list */
|
|
|
|
if (ev->number == 0) {
|
|
|
|
for (i = 0; i < HAL_AVRCP_MEDIA_ATTR_DURATION; i++) {
|
|
|
|
/* Skip 0x00 as the attributes start with 0x01 */
|
|
|
|
ev->attrs[i] = i + 1;
|
|
|
|
}
|
|
|
|
ev->number = i;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2014-03-17 01:39:46 +08:00
|
|
|
for (i = 0; i < number; i++)
|
|
|
|
ev->attrs[i] = attrs[i];
|
2014-03-02 22:39:36 +08:00
|
|
|
|
2014-03-08 06:43:38 +08:00
|
|
|
done:
|
2014-03-02 22:39:36 +08:00
|
|
|
ipc_send_notif(hal_ipc, HAL_SERVICE_ID_AVRCP,
|
|
|
|
HAL_EV_AVRCP_GET_ELEMENT_ATTRS,
|
|
|
|
sizeof(*ev) + ev->number, ev);
|
|
|
|
|
2014-03-05 04:43:22 +08:00
|
|
|
push_request(dev, AVRCP_GET_ELEMENT_ATTRIBUTES, 0, transaction);
|
2014-03-02 22:39:36 +08:00
|
|
|
|
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-03-17 01:39:46 +08:00
|
|
|
static int handle_register_notification_cmd(struct avrcp *session,
|
2014-03-02 23:48:55 +08:00
|
|
|
uint8_t transaction,
|
2014-03-17 01:39:46 +08:00
|
|
|
uint8_t event,
|
|
|
|
uint32_t interval,
|
2014-03-02 23:48:55 +08:00
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct avrcp_device *dev = user_data;
|
|
|
|
struct hal_ev_avrcp_register_notification ev;
|
|
|
|
|
|
|
|
DBG("");
|
|
|
|
|
|
|
|
/* TODO: Add any missing events supported by Android */
|
2014-03-17 01:39:46 +08:00
|
|
|
switch (event) {
|
2014-03-02 23:48:55 +08:00
|
|
|
case AVRCP_EVENT_STATUS_CHANGED:
|
|
|
|
case AVRCP_EVENT_TRACK_CHANGED:
|
|
|
|
case AVRCP_EVENT_PLAYBACK_POS_CHANGED:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-03-17 01:39:46 +08:00
|
|
|
ev.event = event;
|
|
|
|
ev.param = interval;
|
2014-03-02 23:48:55 +08:00
|
|
|
|
|
|
|
ipc_send_notif(hal_ipc, HAL_SERVICE_ID_AVRCP,
|
|
|
|
HAL_EV_AVRCP_REGISTER_NOTIFICATION,
|
|
|
|
sizeof(ev), &ev);
|
|
|
|
|
2014-03-17 01:39:46 +08:00
|
|
|
push_request(dev, AVRCP_REGISTER_NOTIFICATION, event, transaction);
|
2014-03-02 23:48:55 +08:00
|
|
|
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
2014-03-17 01:39:46 +08:00
|
|
|
static const struct avrcp_control_ind control_ind = {
|
|
|
|
.get_capabilities = handle_get_capabilities_cmd,
|
|
|
|
.get_play_status = handle_get_play_status_cmd,
|
|
|
|
.get_element_attributes = handle_get_element_attrs_cmd,
|
|
|
|
.register_notification = handle_register_notification_cmd,
|
2014-03-01 23:30:34 +08:00
|
|
|
};
|
|
|
|
|
2014-03-26 20:25:08 +08:00
|
|
|
static bool handle_register_notification_rsp(struct avrcp *session, int err,
|
|
|
|
uint8_t code, uint8_t event,
|
|
|
|
uint8_t *params,
|
|
|
|
void *user_data)
|
2014-03-07 18:44:41 +08:00
|
|
|
{
|
|
|
|
struct avrcp_device *dev = user_data;
|
|
|
|
struct hal_ev_avrcp_volume_changed ev;
|
|
|
|
|
2014-03-26 20:25:08 +08:00
|
|
|
if (err < 0) {
|
|
|
|
error("AVRCP: %s", strerror(-err));
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-07 18:44:41 +08:00
|
|
|
|
2014-03-26 20:25:08 +08:00
|
|
|
if (code != AVC_CTYPE_INTERIM && code != AVC_CTYPE_CHANGED)
|
|
|
|
return false;
|
2014-03-07 18:44:41 +08:00
|
|
|
|
2014-03-26 20:25:08 +08:00
|
|
|
if (event != AVRCP_EVENT_VOLUME_CHANGED)
|
|
|
|
return false;
|
2014-03-07 18:44:41 +08:00
|
|
|
|
2014-03-10 19:56:25 +08:00
|
|
|
ev.type = code;
|
2014-03-26 20:25:08 +08:00
|
|
|
ev.volume = params[0] & 0x7f;
|
2014-03-07 18:44:41 +08:00
|
|
|
|
|
|
|
ipc_send_notif(hal_ipc, HAL_SERVICE_ID_AVRCP,
|
|
|
|
HAL_EV_AVRCP_VOLUME_CHANGED,
|
|
|
|
sizeof(ev), &ev);
|
|
|
|
|
|
|
|
if (code == AVC_CTYPE_INTERIM)
|
2014-03-26 20:25:08 +08:00
|
|
|
return true;
|
2014-03-07 18:44:41 +08:00
|
|
|
|
2014-03-26 20:25:08 +08:00
|
|
|
avrcp_register_notification(dev->session, event, 0);
|
|
|
|
return false;
|
2014-03-07 18:44:41 +08:00
|
|
|
}
|
|
|
|
|
2014-03-19 22:59:07 +08:00
|
|
|
static void handle_get_capabilities_rsp(struct avrcp *session, int err,
|
|
|
|
uint8_t number, uint8_t *events,
|
2014-03-07 18:44:41 +08:00
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct avrcp_device *dev = user_data;
|
2014-03-19 22:59:07 +08:00
|
|
|
int i;
|
2014-03-07 18:44:41 +08:00
|
|
|
|
2014-03-19 22:59:07 +08:00
|
|
|
if (err < 0) {
|
|
|
|
error("AVRCP: %s", strerror(-err));
|
|
|
|
return;
|
|
|
|
}
|
2014-03-07 18:44:41 +08:00
|
|
|
|
2014-03-19 22:59:07 +08:00
|
|
|
for (i = 0; i < number; i++) {
|
|
|
|
if (events[i] != AVRCP_EVENT_VOLUME_CHANGED)
|
2014-03-07 18:44:41 +08:00
|
|
|
continue;
|
|
|
|
|
2014-03-26 20:25:08 +08:00
|
|
|
avrcp_register_notification(dev->session, events[i], 0);
|
2014-03-19 22:59:07 +08:00
|
|
|
break;
|
2014-03-07 18:44:41 +08:00
|
|
|
}
|
|
|
|
|
2014-03-19 22:59:07 +08:00
|
|
|
return;
|
2014-03-07 18:44:41 +08:00
|
|
|
}
|
|
|
|
|
2014-04-03 22:59:27 +08:00
|
|
|
static void handle_set_volume_rsp(struct avrcp *session, int err,
|
|
|
|
uint8_t value, void *user_data)
|
|
|
|
{
|
|
|
|
struct hal_ev_avrcp_volume_changed ev;
|
|
|
|
|
|
|
|
if (err < 0) {
|
|
|
|
ev.volume = 0;
|
|
|
|
ev.type = AVC_CTYPE_REJECTED;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
ev.volume = value;
|
|
|
|
ev.type = AVC_CTYPE_ACCEPTED;
|
|
|
|
|
|
|
|
done:
|
|
|
|
ipc_send_notif(hal_ipc, HAL_SERVICE_ID_AVRCP,
|
|
|
|
HAL_EV_AVRCP_VOLUME_CHANGED,
|
|
|
|
sizeof(ev), &ev);
|
|
|
|
}
|
|
|
|
|
2014-03-19 22:59:07 +08:00
|
|
|
static const struct avrcp_control_cfm control_cfm = {
|
|
|
|
.get_capabilities = handle_get_capabilities_rsp,
|
2014-03-26 20:25:08 +08:00
|
|
|
.register_notification = handle_register_notification_rsp,
|
2014-04-03 22:59:27 +08:00
|
|
|
.set_volume = handle_set_volume_rsp,
|
2014-03-19 22:59:07 +08:00
|
|
|
};
|
|
|
|
|
2014-03-04 23:34:34 +08:00
|
|
|
static int avrcp_device_add_session(struct avrcp_device *dev, int fd,
|
|
|
|
uint16_t imtu, uint16_t omtu)
|
2014-01-23 23:58:05 +08:00
|
|
|
{
|
2014-03-05 20:48:00 +08:00
|
|
|
struct hal_ev_avrcp_remote_features ev;
|
2014-01-23 23:58:05 +08:00
|
|
|
char address[18];
|
2014-03-04 23:34:34 +08:00
|
|
|
|
|
|
|
dev->session = avrcp_new(fd, imtu, omtu, dev->version);
|
|
|
|
if (!dev->session)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
avrcp_set_destroy_cb(dev->session, disconnect_cb, dev);
|
|
|
|
avrcp_set_passthrough_handlers(dev->session, passthrough_handlers,
|
|
|
|
dev);
|
2014-03-19 22:59:07 +08:00
|
|
|
avrcp_register_player(dev->session, &control_ind, &control_cfm, dev);
|
2014-03-04 23:34:34 +08:00
|
|
|
|
|
|
|
dev->queue = g_queue_new();
|
|
|
|
|
|
|
|
ba2str(&dev->dst, address);
|
|
|
|
|
|
|
|
/* FIXME: get the real name of the device */
|
|
|
|
avrcp_init_uinput(dev->session, "bluetooth", address);
|
|
|
|
|
2014-03-05 20:48:00 +08:00
|
|
|
bdaddr2android(&dev->dst, ev.bdaddr);
|
|
|
|
ev.features = HAL_AVRCP_FEATURE_NONE;
|
|
|
|
|
|
|
|
DBG("version 0x%02x", dev->version);
|
|
|
|
|
|
|
|
if (dev->version < 0x0103)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
ev.features |= HAL_AVRCP_FEATURE_METADATA;
|
|
|
|
|
2014-03-07 18:44:41 +08:00
|
|
|
if (dev->version < 0x0104)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
ev.features |= HAL_AVRCP_FEATURE_ABSOLUTE_VOLUME;
|
|
|
|
|
2014-03-19 22:59:07 +08:00
|
|
|
avrcp_get_capabilities(dev->session, CAP_EVENTS_SUPPORTED);
|
2014-03-07 18:44:41 +08:00
|
|
|
|
2014-03-05 20:48:00 +08:00
|
|
|
done:
|
|
|
|
ipc_send_notif(hal_ipc, HAL_SERVICE_ID_AVRCP,
|
|
|
|
HAL_EV_AVRCP_REMOTE_FEATURES,
|
|
|
|
sizeof(ev), &ev);
|
|
|
|
|
2014-03-04 23:34:34 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct avrcp_device *dev = user_data;
|
2014-01-23 23:58:05 +08:00
|
|
|
uint16_t imtu, omtu;
|
2014-03-04 23:34:34 +08:00
|
|
|
char address[18];
|
2014-01-23 23:58:05 +08:00
|
|
|
GError *gerr = NULL;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
error("%s", err->message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_io_get(chan, &gerr,
|
2014-03-04 23:34:34 +08:00
|
|
|
BT_IO_OPT_DEST, address,
|
2014-01-23 23:58:05 +08:00
|
|
|
BT_IO_OPT_IMTU, &imtu,
|
|
|
|
BT_IO_OPT_OMTU, &omtu,
|
|
|
|
BT_IO_OPT_INVALID);
|
|
|
|
if (gerr) {
|
|
|
|
error("%s", gerr->message);
|
|
|
|
g_error_free(gerr);
|
|
|
|
g_io_channel_shutdown(chan, TRUE, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = g_io_channel_unix_get_fd(chan);
|
2014-03-04 23:34:34 +08:00
|
|
|
if (avrcp_device_add_session(dev, fd, imtu, omtu) < 0) {
|
2014-01-23 23:58:05 +08:00
|
|
|
avrcp_device_free(dev);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_io_channel_set_close_on_unref(chan, FALSE);
|
|
|
|
|
2014-02-05 18:26:57 +08:00
|
|
|
if (dev->io) {
|
|
|
|
g_io_channel_unref(dev->io);
|
|
|
|
dev->io = NULL;
|
|
|
|
}
|
|
|
|
|
2014-01-23 23:58:05 +08:00
|
|
|
DBG("%s connected", address);
|
|
|
|
}
|
|
|
|
|
2014-03-04 23:34:34 +08:00
|
|
|
static bool avrcp_device_connect(struct avrcp_device *dev, BtIOConnect cb)
|
|
|
|
{
|
|
|
|
GError *err = NULL;
|
|
|
|
|
|
|
|
dev->io = bt_io_connect(cb, dev, NULL, &err,
|
|
|
|
BT_IO_OPT_SOURCE_BDADDR, &adapter_addr,
|
|
|
|
BT_IO_OPT_DEST_BDADDR, &dev->dst,
|
|
|
|
BT_IO_OPT_PSM, L2CAP_PSM_AVCTP,
|
|
|
|
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
|
|
|
|
BT_IO_OPT_INVALID);
|
|
|
|
if (err) {
|
|
|
|
error("%s", err->message);
|
|
|
|
g_error_free(err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void search_cb(sdp_list_t *recs, int err, gpointer data)
|
|
|
|
{
|
|
|
|
struct avrcp_device *dev = data;
|
|
|
|
sdp_list_t *list;
|
|
|
|
|
|
|
|
DBG("");
|
|
|
|
|
|
|
|
if (err < 0) {
|
|
|
|
error("Unable to get AV_REMOTE_SVCLASS_ID SDP record: %s",
|
|
|
|
strerror(-err));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!recs || !recs->data) {
|
|
|
|
error("No AVRCP records found");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (list = recs; list; list = list->next) {
|
|
|
|
sdp_record_t *rec = list->data;
|
2014-03-06 20:55:57 +08:00
|
|
|
sdp_list_t *l;
|
|
|
|
sdp_profile_desc_t *desc;
|
|
|
|
int features;
|
2014-03-04 23:34:34 +08:00
|
|
|
|
2014-03-06 20:55:57 +08:00
|
|
|
if (sdp_get_profile_descs(rec, &l) < 0)
|
|
|
|
continue;
|
2014-03-04 23:34:34 +08:00
|
|
|
|
2014-03-06 20:55:57 +08:00
|
|
|
desc = l->data;
|
|
|
|
dev->version = desc->version;
|
|
|
|
|
|
|
|
if (sdp_get_int_attr(rec, SDP_ATTR_SUPPORTED_FEATURES,
|
|
|
|
&features) == 0)
|
|
|
|
dev->features = features;
|
|
|
|
|
|
|
|
sdp_list_free(l, free);
|
|
|
|
break;
|
2014-03-04 23:34:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dev->io) {
|
|
|
|
GError *gerr = NULL;
|
|
|
|
if (!bt_io_accept(dev->io, connect_cb, dev, NULL, &gerr)) {
|
|
|
|
error("bt_io_accept: %s", gerr->message);
|
|
|
|
g_error_free(gerr);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!avrcp_device_connect(dev, connect_cb)) {
|
|
|
|
error("Unable to connect to AVRCP");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
avrcp_device_remove(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int avrcp_device_search(struct avrcp_device *dev)
|
|
|
|
{
|
|
|
|
uuid_t uuid;
|
|
|
|
|
|
|
|
sdp_uuid16_create(&uuid, AV_REMOTE_SVCLASS_ID);
|
|
|
|
|
|
|
|
return bt_search_service(&adapter_addr, &dev->dst, &uuid, search_cb,
|
|
|
|
dev, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void confirm_cb(GIOChannel *chan, gpointer data)
|
|
|
|
{
|
|
|
|
struct avrcp_device *dev;
|
|
|
|
char address[18];
|
2014-04-23 20:01:42 +08:00
|
|
|
bdaddr_t dst;
|
2014-03-04 23:34:34 +08:00
|
|
|
GError *err = NULL;
|
|
|
|
|
|
|
|
bt_io_get(chan, &err,
|
|
|
|
BT_IO_OPT_DEST_BDADDR, &dst,
|
|
|
|
BT_IO_OPT_DEST, address,
|
|
|
|
BT_IO_OPT_INVALID);
|
|
|
|
if (err) {
|
|
|
|
error("%s", err->message);
|
|
|
|
g_error_free(err);
|
|
|
|
g_io_channel_shutdown(chan, TRUE, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DBG("incoming connect from %s", address);
|
|
|
|
|
|
|
|
dev = avrcp_device_find(&dst);
|
|
|
|
if (dev && dev->session) {
|
|
|
|
error("AVRCP: Refusing unexpected connect");
|
|
|
|
g_io_channel_shutdown(chan, TRUE, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev = avrcp_device_new(&dst);
|
|
|
|
if (avrcp_device_search(dev) < 0) {
|
|
|
|
error("AVRCP: Failed to search SDP details");
|
|
|
|
avrcp_device_free(dev);
|
|
|
|
g_io_channel_shutdown(chan, TRUE, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->io = g_io_channel_ref(chan);
|
|
|
|
}
|
|
|
|
|
2014-03-03 07:50:44 +08:00
|
|
|
bool bt_avrcp_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode)
|
2014-01-23 21:04:12 +08:00
|
|
|
{
|
2014-01-23 23:58:05 +08:00
|
|
|
GError *err = NULL;
|
2014-01-23 21:31:45 +08:00
|
|
|
sdp_record_t *rec;
|
|
|
|
|
2014-01-23 21:04:12 +08:00
|
|
|
DBG("");
|
|
|
|
|
|
|
|
bacpy(&adapter_addr, addr);
|
|
|
|
|
2014-03-04 23:34:34 +08:00
|
|
|
server = bt_io_listen(NULL, confirm_cb, NULL, NULL, &err,
|
2014-01-23 23:58:05 +08:00
|
|
|
BT_IO_OPT_SOURCE_BDADDR, &adapter_addr,
|
|
|
|
BT_IO_OPT_PSM, L2CAP_PSM_AVCTP,
|
|
|
|
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
|
|
|
|
BT_IO_OPT_INVALID);
|
|
|
|
if (!server) {
|
|
|
|
error("Failed to listen on AVDTP channel: %s", err->message);
|
|
|
|
g_error_free(err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-23 21:31:45 +08:00
|
|
|
rec = avrcp_record();
|
|
|
|
if (!rec) {
|
|
|
|
error("Failed to allocate AVRCP record");
|
2014-01-30 21:23:43 +08:00
|
|
|
goto fail;
|
2014-01-23 21:31:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bt_adapter_add_record(rec, 0) < 0) {
|
|
|
|
error("Failed to register AVRCP record");
|
|
|
|
sdp_record_free(rec);
|
2014-01-30 21:23:43 +08:00
|
|
|
goto fail;
|
2014-01-23 21:31:45 +08:00
|
|
|
}
|
|
|
|
record_id = rec->handle;
|
|
|
|
|
2014-02-24 20:44:12 +08:00
|
|
|
hal_ipc = ipc;
|
|
|
|
|
|
|
|
ipc_register(hal_ipc, HAL_SERVICE_ID_AVRCP, cmd_handlers,
|
2014-01-23 21:04:12 +08:00
|
|
|
G_N_ELEMENTS(cmd_handlers));
|
|
|
|
|
|
|
|
return true;
|
2014-01-30 21:23:43 +08:00
|
|
|
fail:
|
|
|
|
g_io_channel_shutdown(server, TRUE, NULL);
|
|
|
|
g_io_channel_unref(server);
|
|
|
|
server = NULL;
|
|
|
|
|
|
|
|
return false;
|
2014-01-23 21:04:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void bt_avrcp_unregister(void)
|
|
|
|
{
|
|
|
|
DBG("");
|
|
|
|
|
2014-01-23 23:58:05 +08:00
|
|
|
g_slist_free_full(devices, avrcp_device_free);
|
|
|
|
devices = NULL;
|
|
|
|
|
2014-02-24 20:44:12 +08:00
|
|
|
ipc_unregister(hal_ipc, HAL_SERVICE_ID_AVRCP);
|
|
|
|
hal_ipc = NULL;
|
2014-01-23 21:31:45 +08:00
|
|
|
|
|
|
|
bt_adapter_remove_record(record_id);
|
|
|
|
record_id = 0;
|
2014-01-23 23:58:05 +08:00
|
|
|
|
|
|
|
if (server) {
|
|
|
|
g_io_channel_shutdown(server, TRUE, NULL);
|
|
|
|
g_io_channel_unref(server);
|
|
|
|
server = NULL;
|
|
|
|
}
|
2014-01-23 21:04:12 +08:00
|
|
|
}
|
2014-02-05 18:26:57 +08:00
|
|
|
|
|
|
|
void bt_avrcp_connect(const bdaddr_t *dst)
|
|
|
|
{
|
|
|
|
struct avrcp_device *dev;
|
|
|
|
char addr[18];
|
|
|
|
|
|
|
|
DBG("");
|
|
|
|
|
2014-02-13 23:20:07 +08:00
|
|
|
if (avrcp_device_find(dst))
|
2014-02-05 18:26:57 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
dev = avrcp_device_new(dst);
|
2014-03-04 23:34:34 +08:00
|
|
|
if (avrcp_device_search(dev) < 0) {
|
|
|
|
error("AVRCP: Failed to search SDP details");
|
2014-02-05 18:26:57 +08:00
|
|
|
avrcp_device_free(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
ba2str(&dev->dst, addr);
|
|
|
|
DBG("connecting to %s", addr);
|
|
|
|
}
|
2014-02-05 18:26:58 +08:00
|
|
|
|
|
|
|
void bt_avrcp_disconnect(const bdaddr_t *dst)
|
|
|
|
{
|
|
|
|
struct avrcp_device *dev;
|
|
|
|
|
|
|
|
DBG("");
|
|
|
|
|
2014-02-13 23:20:07 +08:00
|
|
|
dev = avrcp_device_find(dst);
|
|
|
|
if (!dev)
|
2014-02-05 18:26:58 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (dev->session) {
|
2014-02-13 23:20:07 +08:00
|
|
|
avrcp_shutdown(dev->session);
|
2014-02-05 18:26:58 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-06 20:32:18 +08:00
|
|
|
avrcp_device_remove(dev);
|
2014-02-05 18:26:58 +08:00
|
|
|
}
|