2014-11-17 12:59:14

by Ravi kumar Veeramally

[permalink] [raw]
Subject: [PATCH 1/4] android/avrcp: Rename avrcp_register and avrcp_unregister calls

Android Lollipop has separate interface for AVRCP cotroller. Current
AVRCP interface named it as AVRCP Target.
---
android/avrcp.c | 4 ++--
android/avrcp.h | 4 ++--
android/main.c | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/android/avrcp.c b/android/avrcp.c
index a0d412d..57f60df 100644
--- a/android/avrcp.c
+++ b/android/avrcp.c
@@ -1049,7 +1049,7 @@ static void confirm_cb(GIOChannel *chan, gpointer data)
dev->io = g_io_channel_ref(chan);
}

-bool bt_avrcp_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode)
+bool bt_avrcp_tgt_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode)
{
GError *err = NULL;
sdp_record_t *rec;
@@ -1111,7 +1111,7 @@ fail:
return false;
}

-void bt_avrcp_unregister(void)
+void bt_avrcp_tgt_unregister(void)
{
DBG("");

diff --git a/android/avrcp.h b/android/avrcp.h
index 11e79b7..cd109a7 100644
--- a/android/avrcp.h
+++ b/android/avrcp.h
@@ -21,8 +21,8 @@
*
*/

-bool bt_avrcp_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode);
-void bt_avrcp_unregister(void);
+bool bt_avrcp_tgt_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode);
+void bt_avrcp_tgt_unregister(void);

void bt_avrcp_connect(const bdaddr_t *dst);
void bt_avrcp_disconnect(const bdaddr_t *dst);
diff --git a/android/main.c b/android/main.c
index 58dd9ab..ee1e3a0 100644
--- a/android/main.c
+++ b/android/main.c
@@ -202,7 +202,7 @@ static void service_register(const void *buf, uint16_t len)

break;
case HAL_SERVICE_ID_AVRCP:
- if (!bt_avrcp_register(hal_ipc, &adapter_bdaddr, m->mode)) {
+ if (!bt_avrcp_tgt_register(hal_ipc, &adapter_bdaddr, m->mode)) {
status = HAL_STATUS_FAILED;
goto failed;
}
@@ -284,7 +284,7 @@ static bool unregister_service(uint8_t id)
bt_pan_unregister();
break;
case HAL_SERVICE_ID_AVRCP:
- bt_avrcp_unregister();
+ bt_avrcp_tgt_unregister();
break;
case HAL_SERVICE_ID_HANDSFREE:
bt_handsfree_unregister();
--
2.1.0



2014-11-17 12:59:16

by Ravi kumar Veeramally

[permalink] [raw]
Subject: [PATCH 3/4] android/client: Add AVRCP_CTRL interface to haltest init

Adding AVRCP_CTRL interface to haltest interfaces initialization.
if-rc.c has init() for avrcp target, so defined ctrl_init for avrcp
controller target (Reason behind comparing interface name(rc-ctrl)
to get_interface_method).
---
android/client/haltest.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/android/client/haltest.c b/android/client/haltest.c
index c8cfdc4..2c71124 100644
--- a/android/client/haltest.c
+++ b/android/client/haltest.c
@@ -51,6 +51,7 @@ const struct interface *interfaces[] = {
#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
&hf_client_if,
&mce_if,
+ &ctrl_rc_if,
#endif
NULL
};
@@ -399,6 +400,7 @@ static void init(void)
#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
BT_PROFILE_HANDSFREE_CLIENT_ID,
BT_PROFILE_MAP_CLIENT_ID,
+ BT_PROFILE_AV_RC_CTRL_ID,
#endif
};
const struct method *m;
@@ -421,7 +423,12 @@ static void init(void)

/* Init what is available to init */
for (i = 2; i < NELEM(interfaces) - 1; ++i) {
- m = get_interface_method(interfaces[i]->name, "init");
+ if (!strcmp(interfaces[i]->name, "rc-ctrl"))
+ m = get_interface_method(interfaces[i]->name,
+ "ctrl_init");
+ else
+ m = get_interface_method(interfaces[i]->name, "init");
+
if (m != NULL)
m->func(2, argv);
}
--
2.1.0


2014-11-17 12:59:17

by Ravi kumar Veeramally

[permalink] [raw]
Subject: [PATCH 4/4] android/avrcp: Add support for controller send passthrough command

---
android/avrcp.c | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/android/avrcp.c b/android/avrcp.c
index 335b957..b5676c0 100644
--- a/android/avrcp.c
+++ b/android/avrcp.c
@@ -1193,11 +1193,31 @@ void bt_avrcp_disconnect(const bdaddr_t *dst)

static void handle_send_passthrough(const void *buf, uint16_t len)
{
- DBG("Not Implemented");
+ const struct hal_cmd_avrcp_ctrl_send_passthrough *cmd = buf;
+ struct avrcp_device *dev;
+ bdaddr_t dst;
+ uint8_t status;
+
+ DBG("");
+
+ android2bdaddr(&cmd->bdaddr, &dst);
+ dev = avrcp_device_find(&dst);
+ if (!dev || !dev->session) {
+ status = HAL_STATUS_INVALID;
+ goto reply;
+ }
+
+ if (avrcp_send_passthrough(dev->session, cmd->key_code,
+ cmd->key_state)) {
+ status = HAL_STATUS_FAILED;
+ goto reply;
+ }
+
+ status = HAL_STATUS_SUCCESS;

+reply:
ipc_send_rsp(hal_ipc_ctrl, HAL_SERVICE_ID_AVRCP_CTRL,
- HAL_OP_AVRCP_CTRL_SEND_PASSTHROUGH,
- HAL_STATUS_UNSUPPORTED);
+ HAL_OP_AVRCP_CTRL_SEND_PASSTHROUGH, status);
}

static const struct ipc_handler ctrl_cmd_handlers[] = {
--
2.1.0


2014-11-17 12:59:15

by Ravi kumar Veeramally

[permalink] [raw]
Subject: [PATCH 2/4] android/avrcp: Add initial support for new AVRCP CTRL interface

---
android/avrcp.c | 149 ++++++++++++++++++++++++++++++++++++++++++++------------
android/avrcp.h | 3 ++
android/main.c | 11 +++++
3 files changed, 133 insertions(+), 30 deletions(-)

diff --git a/android/avrcp.c b/android/avrcp.c
index 57f60df..335b957 100644
--- a/android/avrcp.c
+++ b/android/avrcp.c
@@ -60,6 +60,7 @@ static uint32_t record_ct_id = 0;
static GSList *devices = NULL;
static GIOChannel *server = NULL;
static struct ipc *hal_ipc = NULL;
+static struct ipc *hal_ipc_ctrl = NULL;

struct avrcp_request {
struct avrcp_device *dev;
@@ -1049,12 +1050,9 @@ static void confirm_cb(GIOChannel *chan, gpointer data)
dev->io = g_io_channel_ref(chan);
}

-bool bt_avrcp_tgt_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode)
+static bool avrcp_register(const bdaddr_t *addr)
{
GError *err = NULL;
- sdp_record_t *rec;
-
- DBG("");

bacpy(&adapter_addr, addr);

@@ -1069,6 +1067,32 @@ bool bt_avrcp_tgt_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode)
return false;
}

+ return true;
+}
+
+static void avrcp_unregister(void)
+{
+ g_slist_free_full(devices, avrcp_device_free);
+ devices = NULL;
+
+ if (server) {
+ g_io_channel_shutdown(server, TRUE, NULL);
+ g_io_channel_unref(server);
+ server = NULL;
+ }
+}
+
+bool bt_avrcp_tgt_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode)
+{
+ sdp_record_t *rec;
+
+ DBG("");
+
+ if (!server) {
+ if (!avrcp_register(addr))
+ goto fail;
+ }
+
rec = avrcp_tg_record();
if (!rec) {
error("Failed to allocate AVRCP TG record");
@@ -1082,20 +1106,22 @@ bool bt_avrcp_tgt_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode)
}
record_tg_id = rec->handle;

- rec = avrcp_ct_record();
- if (!rec) {
- error("Failed to allocate AVRCP CT record");
- bt_adapter_remove_record(record_tg_id);
- goto fail;
- }
+ if (!record_ct_id) {
+ rec = avrcp_ct_record();
+ if (!rec) {
+ error("Failed to allocate AVRCP CT record");
+ bt_adapter_remove_record(record_tg_id);
+ goto fail;
+ }

- if (bt_adapter_add_record(rec, 0) < 0) {
- error("Failed to register AVRCP CT record");
- bt_adapter_remove_record(record_tg_id);
- sdp_record_free(rec);
- goto fail;
+ if (bt_adapter_add_record(rec, 0) < 0) {
+ error("Failed to register AVRCP CT record");
+ bt_adapter_remove_record(record_tg_id);
+ sdp_record_free(rec);
+ goto fail;
+ }
+ record_ct_id = rec->handle;
}
- record_ct_id = rec->handle;

hal_ipc = ipc;

@@ -1104,10 +1130,7 @@ bool bt_avrcp_tgt_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode)

return true;
fail:
- g_io_channel_shutdown(server, TRUE, NULL);
- g_io_channel_unref(server);
- server = NULL;
-
+ avrcp_unregister();
return false;
}

@@ -1115,23 +1138,19 @@ void bt_avrcp_tgt_unregister(void)
{
DBG("");

- g_slist_free_full(devices, avrcp_device_free);
- devices = NULL;
-
ipc_unregister(hal_ipc, HAL_SERVICE_ID_AVRCP);
hal_ipc = NULL;

bt_adapter_remove_record(record_tg_id);
record_tg_id = 0;

- bt_adapter_remove_record(record_ct_id);
- record_ct_id = 0;
-
- if (server) {
- g_io_channel_shutdown(server, TRUE, NULL);
- g_io_channel_unref(server);
- server = NULL;
+ if (!hal_ipc_ctrl) {
+ bt_adapter_remove_record(record_ct_id);
+ record_ct_id = 0;
}
+
+ if (server)
+ avrcp_unregister();
}

void bt_avrcp_connect(const bdaddr_t *dst)
@@ -1171,3 +1190,73 @@ void bt_avrcp_disconnect(const bdaddr_t *dst)

avrcp_device_remove(dev);
}
+
+static void handle_send_passthrough(const void *buf, uint16_t len)
+{
+ DBG("Not Implemented");
+
+ ipc_send_rsp(hal_ipc_ctrl, HAL_SERVICE_ID_AVRCP_CTRL,
+ HAL_OP_AVRCP_CTRL_SEND_PASSTHROUGH,
+ HAL_STATUS_UNSUPPORTED);
+}
+
+static const struct ipc_handler ctrl_cmd_handlers[] = {
+ /* HAL_OP_AVRCP_CTRL_SEND_PASSTHROUGH */
+ { handle_send_passthrough, false,
+ sizeof(struct hal_cmd_avrcp_ctrl_send_passthrough) },
+};
+
+bool bt_avrcp_ctrl_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode)
+{
+ sdp_record_t *rec;
+
+ DBG("");
+
+ if (!server) {
+ if (!avrcp_register(addr))
+ goto fail;
+ }
+
+ if (!record_ct_id) {
+ rec = avrcp_ct_record();
+ if (!rec) {
+ error("Failed to allocate AVRCP CT record");
+ goto fail;
+ }
+
+ if (bt_adapter_add_record(rec, 0) < 0) {
+ error("Failed to register AVRCP CT record");
+ sdp_record_free(rec);
+ goto fail;
+ }
+ record_ct_id = rec->handle;
+ }
+
+ hal_ipc_ctrl = ipc;
+
+ ipc_register(hal_ipc_ctrl, HAL_SERVICE_ID_AVRCP_CTRL, ctrl_cmd_handlers,
+ G_N_ELEMENTS(ctrl_cmd_handlers));
+
+ return true;
+
+fail:
+ if (!hal_ipc)
+ avrcp_unregister();
+
+ return false;
+}
+
+void bt_avrcp_ctrl_unregister(void)
+{
+ DBG("");
+
+ ipc_unregister(hal_ipc_ctrl, HAL_SERVICE_ID_AVRCP_CTRL);
+ hal_ipc_ctrl = NULL;
+
+ if (!hal_ipc) {
+ bt_adapter_remove_record(record_ct_id);
+ record_ct_id = 0;
+
+ avrcp_unregister();
+ }
+}
diff --git a/android/avrcp.h b/android/avrcp.h
index cd109a7..bcca02a 100644
--- a/android/avrcp.h
+++ b/android/avrcp.h
@@ -23,6 +23,9 @@

bool bt_avrcp_tgt_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode);
void bt_avrcp_tgt_unregister(void);
+bool bt_avrcp_ctrl_register(struct ipc *ipc, const bdaddr_t *addr,
+ uint8_t mode);
+void bt_avrcp_ctrl_unregister(void);

void bt_avrcp_connect(const bdaddr_t *dst);
void bt_avrcp_disconnect(const bdaddr_t *dst);
diff --git a/android/main.c b/android/main.c
index ee1e3a0..ed5e09e 100644
--- a/android/main.c
+++ b/android/main.c
@@ -208,6 +208,14 @@ static void service_register(const void *buf, uint16_t len)
}

break;
+ case HAL_SERVICE_ID_AVRCP_CTRL:
+ if (!bt_avrcp_ctrl_register(hal_ipc, &adapter_bdaddr,
+ m->mode)) {
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+
+ break;
case HAL_SERVICE_ID_HANDSFREE:
if (!bt_handsfree_register(hal_ipc, &adapter_bdaddr, m->mode,
m->max_clients)) {
@@ -286,6 +294,9 @@ static bool unregister_service(uint8_t id)
case HAL_SERVICE_ID_AVRCP:
bt_avrcp_tgt_unregister();
break;
+ case HAL_SERVICE_ID_AVRCP_CTRL:
+ bt_avrcp_ctrl_unregister();
+ break;
case HAL_SERVICE_ID_HANDSFREE:
bt_handsfree_unregister();
break;
--
2.1.0