2014-03-17 08:08:46

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 01/12] android/avrcp-lib: Change API to register callbacks instead of PDU handlers

From: Luiz Augusto von Dentz <[email protected]>

This adds avrcp_register_player function to register callbacks for
requests and responses, the fundamental difference is that the
callbacks are called after the original PDU is parsed and the parameter
are converted to host byte order making us able to unit test the
parsing itself.
---
android/avrcp-lib.c | 27 +++++++++++++++++++++++++++
android/avrcp-lib.h | 11 +++++++++++
2 files changed, 38 insertions(+)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 7b043ce..ca01b50 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -73,6 +73,7 @@ struct avrcp_header {

struct avrcp {
struct avctp *conn;
+ struct avrcp_player *player;

size_t tx_mtu;
uint8_t *tx_buf;
@@ -89,6 +90,13 @@ struct avrcp {
void *destroy_data;
};

+struct avrcp_player {
+ const struct avrcp_control_ind *ind;
+ const struct avrcp_control_cfm *cfm;
+
+ void *user_data;
+};
+
void avrcp_shutdown(struct avrcp *session)
{
if (session->conn) {
@@ -107,6 +115,7 @@ void avrcp_shutdown(struct avrcp *session)
if (session->destroy)
session->destroy(session->destroy_data);

+ g_free(session->player);
g_free(session->tx_buf);
g_free(session);
}
@@ -162,6 +171,9 @@ static ssize_t handle_vendordep_pdu(struct avctp *conn, uint8_t transaction,
switch (ret) {
case -EAGAIN:
return ret;
+ case -ENOSYS:
+ pdu->params[0] = AVRCP_STATUS_INVALID_PARAM;
+ goto reject;
case -EINVAL:
pdu->params[0] = AVRCP_STATUS_INVALID_PARAM;
goto reject;
@@ -249,6 +261,21 @@ void avrcp_set_destroy_cb(struct avrcp *session, avrcp_destroy_cb_t cb,
session->destroy_data = user_data;
}

+void avrcp_register_player(struct avrcp *session,
+ const struct avrcp_control_ind *ind,
+ const struct avrcp_control_cfm *cfm,
+ void *user_data)
+{
+ struct avrcp_player *player;
+
+ player = g_new0(struct avrcp_player, 1);
+ player->ind = ind;
+ player->cfm = cfm;
+ player->user_data = user_data;
+
+ session->player = player;
+}
+
void avrcp_set_control_handlers(struct avrcp *session,
const struct avrcp_control_handler *handlers,
void *user_data)
diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index 4adf4bf..6e33a75 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -100,6 +100,12 @@ struct avrcp_control_handler {
uint16_t params_len, uint8_t *params, void *user_data);
};

+struct avrcp_control_ind {
+};
+
+struct avrcp_control_cfm {
+};
+
struct avrcp_passthrough_handler {
uint8_t op;
bool (*func) (struct avrcp *session, bool pressed, void *user_data);
@@ -123,6 +129,11 @@ struct avrcp *avrcp_new(int fd, size_t imtu, size_t omtu, uint16_t version);
void avrcp_shutdown(struct avrcp *session);
void avrcp_set_destroy_cb(struct avrcp *session, avrcp_destroy_cb_t cb,
void *user_data);
+
+void avrcp_register_player(struct avrcp *session,
+ const struct avrcp_control_ind *ind,
+ const struct avrcp_control_cfm *cfm,
+ void *user_data);
void avrcp_set_control_handlers(struct avrcp *session,
const struct avrcp_control_handler *handlers,
void *user_data);
--
1.8.5.3



2014-03-17 13:01:12

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH BlueZ 01/12] android/avrcp-lib: Change API to register callbacks instead of PDU handlers

Hi,

On Mon, Mar 17, 2014 at 11:22 AM, Luiz Augusto von Dentz
<[email protected]> wrote:
> Hi Andrei,
>
> On Mon, Mar 17, 2014 at 10:38 AM, Andrei Emeltchenko
> <[email protected]> wrote:
>> Hi Luiz,
>>
>> On Mon, Mar 17, 2014 at 10:08:46AM +0200, Luiz Augusto von Dentz wrote:
>>> From: Luiz Augusto von Dentz <[email protected]>
>>>
>>> This adds avrcp_register_player function to register callbacks for
>>> requests and responses, the fundamental difference is that the
>>> callbacks are called after the original PDU is parsed and the parameter
>>> are converted to host byte order making us able to unit test the
>>> parsing itself.

Pushed.

2014-03-17 09:25:42

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH BlueZ 02/12] android/avrcp-lib: Add support for parsing GetCapabilities PDU

Hi Andrei,

On Mon, Mar 17, 2014 at 10:42 AM, Andrei Emeltchenko
<[email protected]> wrote:
> On Mon, Mar 17, 2014 at 10:08:47AM +0200, Luiz Augusto von Dentz wrote:
>> From: Luiz Augusto von Dentz <[email protected]>
>>
>> ---
>> android/avrcp-lib.c | 32 ++++++++++++++++++++++++++++++++
>> android/avrcp-lib.h | 2 ++
>> 2 files changed, 34 insertions(+)
>>
>> diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
>> index ca01b50..9c19092 100644
>> --- a/android/avrcp-lib.c
>> +++ b/android/avrcp-lib.c
>> @@ -261,6 +261,37 @@ void avrcp_set_destroy_cb(struct avrcp *session, avrcp_destroy_cb_t cb,
>> session->destroy_data = user_data;
>> }
>>
>> +static ssize_t get_capabilities(struct avrcp *session, uint8_t transaction,
>
> Should it be handle_get_capabilities() to make it consistent with the
> other code.

I deliberately changed the name to avoid copying code around without
checking and to match the exact name that is used for the callback.

2014-03-17 09:22:22

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH BlueZ 01/12] android/avrcp-lib: Change API to register callbacks instead of PDU handlers

Hi Andrei,

On Mon, Mar 17, 2014 at 10:38 AM, Andrei Emeltchenko
<[email protected]> wrote:
> Hi Luiz,
>
> On Mon, Mar 17, 2014 at 10:08:46AM +0200, Luiz Augusto von Dentz wrote:
>> From: Luiz Augusto von Dentz <[email protected]>
>>
>> This adds avrcp_register_player function to register callbacks for
>> requests and responses, the fundamental difference is that the
>> callbacks are called after the original PDU is parsed and the parameter
>> are converted to host byte order making us able to unit test the
>> parsing itself.
>> ---
>> android/avrcp-lib.c | 27 +++++++++++++++++++++++++++
>> android/avrcp-lib.h | 11 +++++++++++
>> 2 files changed, 38 insertions(+)
>>
>> diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
>> index 7b043ce..ca01b50 100644
>> --- a/android/avrcp-lib.c
>> +++ b/android/avrcp-lib.c
>> @@ -73,6 +73,7 @@ struct avrcp_header {
>>
>> struct avrcp {
>> struct avctp *conn;
>> + struct avrcp_player *player;
>>
>> size_t tx_mtu;
>> uint8_t *tx_buf;
>> @@ -89,6 +90,13 @@ struct avrcp {
>> void *destroy_data;
>> };
>>
>> +struct avrcp_player {
>> + const struct avrcp_control_ind *ind;
>> + const struct avrcp_control_cfm *cfm;
>> +
>> + void *user_data;
>> +};
>> +
>> void avrcp_shutdown(struct avrcp *session)
>> {
>> if (session->conn) {
>> @@ -107,6 +115,7 @@ void avrcp_shutdown(struct avrcp *session)
>> if (session->destroy)
>> session->destroy(session->destroy_data);
>>
>> + g_free(session->player);
>
> The player seems not allocated by default, so it should not be clean here.
> I would also make player_unregister() to make it consistent with
> player_register()

Well it is NULL by default which is handled by g_free, regarding
having a dedicated unregister function I thought about that but there
is no need to call it since currently it only support one player, but
perhaps if the player user_data needs to be freed without freeing the
whole session but I don't think I came across such use case.

2014-03-17 08:54:54

by Andrei Emeltchenko

[permalink] [raw]
Subject: Re: [PATCH BlueZ 03/12] android/avrcp-lib: Add support for parsing ListPlayerAttributes PDU

Hi Luiz,

On Mon, Mar 17, 2014 at 10:47:53AM +0200, Andrei Emeltchenko wrote:
> Hi Luiz,
>
> On Mon, Mar 17, 2014 at 10:08:48AM +0200, Luiz Augusto von Dentz wrote:
> > From: Luiz Augusto von Dentz <[email protected]>
> >
> > ---
> > android/avrcp-lib.c | 18 ++++++++++++++++++
> > android/avrcp-lib.h | 2 ++
> > 2 files changed, 20 insertions(+)
> >
> > diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
> > index 9c19092..547d429 100644
> > --- a/android/avrcp-lib.c
> > +++ b/android/avrcp-lib.c
> > @@ -285,10 +285,28 @@ static ssize_t get_capabilities(struct avrcp *session, uint8_t transaction,
> > return -EINVAL;
> > }
> >
> > +static ssize_t list_attributes(struct avrcp *session, uint8_t transaction,
> > + uint16_t params_len, uint8_t *params,
> > + void *user_data)
> > +{
> > + struct avrcp_player *player = user_data;
> > +
> > + DBG("");
> > +
> > + if (!player->ind || !player->ind->list_attributes)
> > + return -ENOSYS;
> > +
> > + return player->ind->list_attributes(session, transaction,
> > + player->user_data);
> > +}
> > +
> > static const struct avrcp_control_handler player_handlers[] = {
> > { AVRCP_GET_CAPABILITIES,
> > AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
> > get_capabilities },
> > + { AVRCP_LIST_PLAYER_ATTRIBUTES,
> > + AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
> > + list_attributes },
> > { },
> > };
> >
> > diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
> > index 34c88c5..0043362 100644
> > --- a/android/avrcp-lib.h
> > +++ b/android/avrcp-lib.h
> > @@ -103,6 +103,8 @@ struct avrcp_control_handler {
> > struct avrcp_control_ind {
> > int (*get_capabilities) (struct avrcp *session, uint8_t transaction,
> > void *user_data);
> > + int (*list_attributes) (struct avrcp *session, uint8_t transaction,
>
> Should the functions above be at least dummy defined?

Please discard this, ok as now.

Best regards
Andrei Emeltchenko


2014-03-17 08:47:53

by Andrei Emeltchenko

[permalink] [raw]
Subject: Re: [PATCH BlueZ 03/12] android/avrcp-lib: Add support for parsing ListPlayerAttributes PDU

Hi Luiz,

On Mon, Mar 17, 2014 at 10:08:48AM +0200, Luiz Augusto von Dentz wrote:
> From: Luiz Augusto von Dentz <[email protected]>
>
> ---
> android/avrcp-lib.c | 18 ++++++++++++++++++
> android/avrcp-lib.h | 2 ++
> 2 files changed, 20 insertions(+)
>
> diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
> index 9c19092..547d429 100644
> --- a/android/avrcp-lib.c
> +++ b/android/avrcp-lib.c
> @@ -285,10 +285,28 @@ static ssize_t get_capabilities(struct avrcp *session, uint8_t transaction,
> return -EINVAL;
> }
>
> +static ssize_t list_attributes(struct avrcp *session, uint8_t transaction,
> + uint16_t params_len, uint8_t *params,
> + void *user_data)
> +{
> + struct avrcp_player *player = user_data;
> +
> + DBG("");
> +
> + if (!player->ind || !player->ind->list_attributes)
> + return -ENOSYS;
> +
> + return player->ind->list_attributes(session, transaction,
> + player->user_data);
> +}
> +
> static const struct avrcp_control_handler player_handlers[] = {
> { AVRCP_GET_CAPABILITIES,
> AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
> get_capabilities },
> + { AVRCP_LIST_PLAYER_ATTRIBUTES,
> + AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
> + list_attributes },
> { },
> };
>
> diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
> index 34c88c5..0043362 100644
> --- a/android/avrcp-lib.h
> +++ b/android/avrcp-lib.h
> @@ -103,6 +103,8 @@ struct avrcp_control_handler {
> struct avrcp_control_ind {
> int (*get_capabilities) (struct avrcp *session, uint8_t transaction,
> void *user_data);
> + int (*list_attributes) (struct avrcp *session, uint8_t transaction,

Should the functions above be at least dummy defined?

Best regards
Andrei Emeltchenko


> + void *user_data);
> };
>
> struct avrcp_control_cfm {
> --
> 1.8.5.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2014-03-17 08:42:11

by Andrei Emeltchenko

[permalink] [raw]
Subject: Re: [PATCH BlueZ 02/12] android/avrcp-lib: Add support for parsing GetCapabilities PDU

On Mon, Mar 17, 2014 at 10:08:47AM +0200, Luiz Augusto von Dentz wrote:
> From: Luiz Augusto von Dentz <[email protected]>
>
> ---
> android/avrcp-lib.c | 32 ++++++++++++++++++++++++++++++++
> android/avrcp-lib.h | 2 ++
> 2 files changed, 34 insertions(+)
>
> diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
> index ca01b50..9c19092 100644
> --- a/android/avrcp-lib.c
> +++ b/android/avrcp-lib.c
> @@ -261,6 +261,37 @@ void avrcp_set_destroy_cb(struct avrcp *session, avrcp_destroy_cb_t cb,
> session->destroy_data = user_data;
> }
>
> +static ssize_t get_capabilities(struct avrcp *session, uint8_t transaction,

Should it be handle_get_capabilities() to make it consistent with the
other code.

Best regards
Andrei Emeltchenko

> + uint16_t params_len, uint8_t *params,
> + void *user_data)
> +{
> + struct avrcp_player *player = user_data;
> +
> + if (!params || params_len != 1)
> + return -EINVAL;
> +
> + switch (params[0]) {
> + case CAP_COMPANY_ID:
> + params[1] = 1;
> + hton24(&params[2], IEEEID_BTSIG);
> + return 5;
> + case CAP_EVENTS_SUPPORTED:
> + if (!player->ind || !player->ind->get_capabilities)
> + return -ENOSYS;
> + return player->ind->get_capabilities(session, transaction,
> + player->user_data);
> + }
> +
> + return -EINVAL;
> +}
> +
> +static const struct avrcp_control_handler player_handlers[] = {
> + { AVRCP_GET_CAPABILITIES,
> + AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
> + get_capabilities },
> + { },
> +};
> +
> void avrcp_register_player(struct avrcp *session,
> const struct avrcp_control_ind *ind,
> const struct avrcp_control_cfm *cfm,
> @@ -273,6 +304,7 @@ void avrcp_register_player(struct avrcp *session,
> player->cfm = cfm;
> player->user_data = user_data;
>
> + avrcp_set_control_handlers(session, player_handlers, player);
> session->player = player;
> }
>
> diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
> index 6e33a75..34c88c5 100644
> --- a/android/avrcp-lib.h
> +++ b/android/avrcp-lib.h
> @@ -101,6 +101,8 @@ struct avrcp_control_handler {
> };
>
> struct avrcp_control_ind {
> + int (*get_capabilities) (struct avrcp *session, uint8_t transaction,
> + void *user_data);
> };
>
> struct avrcp_control_cfm {
> --
> 1.8.5.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2014-03-17 08:38:39

by Andrei Emeltchenko

[permalink] [raw]
Subject: Re: [PATCH BlueZ 01/12] android/avrcp-lib: Change API to register callbacks instead of PDU handlers

Hi Luiz,

On Mon, Mar 17, 2014 at 10:08:46AM +0200, Luiz Augusto von Dentz wrote:
> From: Luiz Augusto von Dentz <[email protected]>
>
> This adds avrcp_register_player function to register callbacks for
> requests and responses, the fundamental difference is that the
> callbacks are called after the original PDU is parsed and the parameter
> are converted to host byte order making us able to unit test the
> parsing itself.
> ---
> android/avrcp-lib.c | 27 +++++++++++++++++++++++++++
> android/avrcp-lib.h | 11 +++++++++++
> 2 files changed, 38 insertions(+)
>
> diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
> index 7b043ce..ca01b50 100644
> --- a/android/avrcp-lib.c
> +++ b/android/avrcp-lib.c
> @@ -73,6 +73,7 @@ struct avrcp_header {
>
> struct avrcp {
> struct avctp *conn;
> + struct avrcp_player *player;
>
> size_t tx_mtu;
> uint8_t *tx_buf;
> @@ -89,6 +90,13 @@ struct avrcp {
> void *destroy_data;
> };
>
> +struct avrcp_player {
> + const struct avrcp_control_ind *ind;
> + const struct avrcp_control_cfm *cfm;
> +
> + void *user_data;
> +};
> +
> void avrcp_shutdown(struct avrcp *session)
> {
> if (session->conn) {
> @@ -107,6 +115,7 @@ void avrcp_shutdown(struct avrcp *session)
> if (session->destroy)
> session->destroy(session->destroy_data);
>
> + g_free(session->player);

The player seems not allocated by default, so it should not be clean here.
I would also make player_unregister() to make it consistent with
player_register()

Best regards
Andrei Emeltchenko

> g_free(session->tx_buf);
> g_free(session);
> }
> @@ -162,6 +171,9 @@ static ssize_t handle_vendordep_pdu(struct avctp *conn, uint8_t transaction,
> switch (ret) {
> case -EAGAIN:
> return ret;
> + case -ENOSYS:
> + pdu->params[0] = AVRCP_STATUS_INVALID_PARAM;
> + goto reject;
> case -EINVAL:
> pdu->params[0] = AVRCP_STATUS_INVALID_PARAM;
> goto reject;
> @@ -249,6 +261,21 @@ void avrcp_set_destroy_cb(struct avrcp *session, avrcp_destroy_cb_t cb,
> session->destroy_data = user_data;
> }
>
> +void avrcp_register_player(struct avrcp *session,
> + const struct avrcp_control_ind *ind,
> + const struct avrcp_control_cfm *cfm,
> + void *user_data)
> +{
> + struct avrcp_player *player;
> +
> + player = g_new0(struct avrcp_player, 1);
> + player->ind = ind;
> + player->cfm = cfm;
> + player->user_data = user_data;
> +
> + session->player = player;
> +}
> +
> void avrcp_set_control_handlers(struct avrcp *session,
> const struct avrcp_control_handler *handlers,
> void *user_data)
> diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
> index 4adf4bf..6e33a75 100644
> --- a/android/avrcp-lib.h
> +++ b/android/avrcp-lib.h
> @@ -100,6 +100,12 @@ struct avrcp_control_handler {
> uint16_t params_len, uint8_t *params, void *user_data);
> };
>
> +struct avrcp_control_ind {
> +};
> +
> +struct avrcp_control_cfm {
> +};
> +
> struct avrcp_passthrough_handler {
> uint8_t op;
> bool (*func) (struct avrcp *session, bool pressed, void *user_data);
> @@ -123,6 +129,11 @@ struct avrcp *avrcp_new(int fd, size_t imtu, size_t omtu, uint16_t version);
> void avrcp_shutdown(struct avrcp *session);
> void avrcp_set_destroy_cb(struct avrcp *session, avrcp_destroy_cb_t cb,
> void *user_data);
> +
> +void avrcp_register_player(struct avrcp *session,
> + const struct avrcp_control_ind *ind,
> + const struct avrcp_control_cfm *cfm,
> + void *user_data);
> void avrcp_set_control_handlers(struct avrcp *session,
> const struct avrcp_control_handler *handlers,
> void *user_data);
> --
> 1.8.5.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2014-03-17 08:08:57

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 12/12] android/avrcp-lib: Add support for parsing SetAddressedPlayer PDU

From: Luiz Augusto von Dentz <[email protected]>

---
android/avrcp-lib.c | 24 ++++++++++++++++++++++++
android/avrcp-lib.h | 2 ++
2 files changed, 26 insertions(+)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 91f51b5..083d7af 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -530,6 +530,27 @@ static ssize_t register_notification(struct avrcp *session, uint8_t transaction,
player->user_data);
}

+static ssize_t set_addressed(struct avrcp *session, uint8_t transaction,
+ uint16_t params_len, uint8_t *params,
+ void *user_data)
+{
+ struct avrcp_player *player = user_data;
+ uint16_t id;
+
+ DBG("");
+
+ if (!params || params_len != 2)
+ return -EINVAL;
+
+ if (!player->ind || !player->ind->set_addressed)
+ return -ENOSYS;
+
+ id = bt_get_be16(params);
+
+ return player->ind->set_addressed(session, transaction, id,
+ player->user_data);
+}
+
static const struct avrcp_control_handler player_handlers[] = {
{ AVRCP_GET_CAPABILITIES,
AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
@@ -561,6 +582,9 @@ static const struct avrcp_control_handler player_handlers[] = {
{ AVRCP_REGISTER_NOTIFICATION,
AVC_CTYPE_NOTIFY, AVC_CTYPE_INTERIM,
register_notification },
+ { AVRCP_SET_ADDRESSED_PLAYER,
+ AVC_CTYPE_CONTROL, AVC_CTYPE_STABLE,
+ set_addressed },
{ },
};

diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index 256576d..54bdf4f 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -159,6 +159,8 @@ struct avrcp_control_ind {
int (*register_notification) (struct avrcp *session,
uint8_t transaction, uint8_t event,
uint32_t interval, void *user_data);
+ int (*set_addressed) (struct avrcp *session, uint8_t transaction,
+ uint16_t id, void *user_data);
};

struct avrcp_control_cfm {
--
1.8.5.3


2014-03-17 08:08:56

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 11/12] android/avrcp-lib: Add support for parsing ResgisterNotification PDU

From: Luiz Augusto von Dentz <[email protected]>

---
android/avrcp-lib.c | 25 +++++++++++++++++++++++++
android/avrcp-lib.h | 3 +++
2 files changed, 28 insertions(+)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index d32f791..91f51b5 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -508,6 +508,28 @@ static ssize_t get_element_attributes(struct avrcp *session,
player->user_data);
}

+static ssize_t register_notification(struct avrcp *session, uint8_t transaction,
+ uint16_t params_len, uint8_t *params,
+ void *user_data)
+{
+ struct avrcp_player *player = user_data;
+ uint32_t interval;
+
+ DBG("");
+
+ if (!params || params_len != 5)
+ return -EINVAL;
+
+ if (!player->ind || !player->ind->register_notification)
+ return -ENOSYS;
+
+ interval = bt_get_be32(&params[1]);
+
+ return player->ind->register_notification(session, transaction,
+ params[0], interval,
+ player->user_data);
+}
+
static const struct avrcp_control_handler player_handlers[] = {
{ AVRCP_GET_CAPABILITIES,
AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
@@ -536,6 +558,9 @@ static const struct avrcp_control_handler player_handlers[] = {
{ AVRCP_GET_ELEMENT_ATTRIBUTES,
AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
get_element_attributes },
+ { AVRCP_REGISTER_NOTIFICATION,
+ AVC_CTYPE_NOTIFY, AVC_CTYPE_INTERIM,
+ register_notification },
{ },
};

diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index 9257de7..256576d 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -156,6 +156,9 @@ struct avrcp_control_ind {
uint8_t transaction, uint64_t uid,
uint8_t number, uint32_t *attrs,
void *user_data);
+ int (*register_notification) (struct avrcp *session,
+ uint8_t transaction, uint8_t event,
+ uint32_t interval, void *user_data);
};

struct avrcp_control_cfm {
--
1.8.5.3


2014-03-17 08:08:54

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 09/12] android/avrcp-lib: Add support for parsing GetPlayStatus PDU

From: Luiz Augusto von Dentz <[email protected]>

---
android/avrcp-lib.c | 18 ++++++++++++++++++
android/avrcp-lib.h | 2 ++
2 files changed, 20 insertions(+)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 2bb84e4..9577bf0 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -459,6 +459,21 @@ static ssize_t set_value(struct avrcp *session, uint8_t transaction,
&params[1], player->user_data);
}

+static ssize_t get_play_status(struct avrcp *session, uint8_t transaction,
+ uint16_t params_len, uint8_t *params,
+ void *user_data)
+{
+ struct avrcp_player *player = user_data;
+
+ DBG("");
+
+ if (!player->ind || !player->ind->get_play_status)
+ return -ENOSYS;
+
+ return player->ind->get_play_status(session, transaction,
+ player->user_data);
+}
+
static const struct avrcp_control_handler player_handlers[] = {
{ AVRCP_GET_CAPABILITIES,
AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
@@ -481,6 +496,9 @@ static const struct avrcp_control_handler player_handlers[] = {
{ AVRCP_SET_PLAYER_VALUE,
AVC_CTYPE_CONTROL, AVC_CTYPE_STABLE,
set_value },
+ { AVRCP_GET_PLAY_STATUS,
+ AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
+ get_play_status },
{ },
};

diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index feac9af..71d710f 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -139,6 +139,8 @@ struct avrcp_control_ind {
int (*set_value) (struct avrcp *session, uint8_t transaction,
uint8_t number, uint8_t *attrs,
void *user_data);
+ int (*get_play_status) (struct avrcp *session, uint8_t transaction,
+ void *user_data);
};

struct avrcp_control_cfm {
--
1.8.5.3


2014-03-17 08:08:55

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 10/12] android/avrcp-lib: Add support for parsing GetElementAttributes PDU

From: Luiz Augusto von Dentz <[email protected]>

---
android/avrcp-lib.c | 37 +++++++++++++++++++++++++++++++++++++
android/avrcp-lib.h | 15 +++++++++++++++
2 files changed, 52 insertions(+)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 9577bf0..d32f791 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -474,6 +474,40 @@ static ssize_t get_play_status(struct avrcp *session, uint8_t transaction,
player->user_data);
}

+static ssize_t get_element_attributes(struct avrcp *session,
+ uint8_t transaction,
+ uint16_t params_len,
+ uint8_t *params,
+ void *user_data)
+{
+ struct avrcp_player *player = user_data;
+ uint64_t uid;
+ uint32_t attrs[AVRCP_MEDIA_ATTRIBUTE_LAST];
+ int i;
+
+ DBG("");
+
+ if (!params || params_len != 9 + params[8] * 4)
+ return -EINVAL;
+
+ uid = bt_get_be64(params);
+
+ for (i = 0; i < params[8]; i++) {
+ attrs[i] = bt_get_be32(&params[9 + i * 4]);
+
+ if (attrs[i] < AVRCP_MEDIA_ATTRIBUTE_TITLE ||
+ attrs[i] > AVRCP_MEDIA_ATTRIBUTE_DURATION)
+ return -EINVAL;
+ }
+
+ if (!player->ind || !player->ind->get_element_attributes)
+ return -ENOSYS;
+
+ return player->ind->get_element_attributes(session, transaction, uid,
+ params[8], attrs,
+ player->user_data);
+}
+
static const struct avrcp_control_handler player_handlers[] = {
{ AVRCP_GET_CAPABILITIES,
AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
@@ -499,6 +533,9 @@ static const struct avrcp_control_handler player_handlers[] = {
{ AVRCP_GET_PLAY_STATUS,
AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
get_play_status },
+ { AVRCP_GET_ELEMENT_ATTRIBUTES,
+ AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
+ get_element_attributes },
{ },
};

diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index 71d710f..9257de7 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -104,6 +104,17 @@
#define AVRCP_SCAN_ALL 0x02
#define AVRCP_SCAN_GROUP 0x03

+/* media attributes */
+#define AVRCP_MEDIA_ATTRIBUTE_ILLEGAL 0x00
+#define AVRCP_MEDIA_ATTRIBUTE_TITLE 0x01
+#define AVRCP_MEDIA_ATTRIBUTE_ARTIST 0x02
+#define AVRCP_MEDIA_ATTRIBUTE_ALBUM 0x03
+#define AVRCP_MEDIA_ATTRIBUTE_TRACK 0x04
+#define AVRCP_MEDIA_ATTRIBUTE_N_TRACKS 0x05
+#define AVRCP_MEDIA_ATTRIBUTE_GENRE 0x06
+#define AVRCP_MEDIA_ATTRIBUTE_DURATION 0x07
+#define AVRCP_MEDIA_ATTRIBUTE_LAST AVRCP_MEDIA_ATTRIBUTE_DURATION
+
/* Company IDs for vendor dependent commands */
#define IEEEID_BTSIG 0x001958

@@ -141,6 +152,10 @@ struct avrcp_control_ind {
void *user_data);
int (*get_play_status) (struct avrcp *session, uint8_t transaction,
void *user_data);
+ int (*get_element_attributes) (struct avrcp *session,
+ uint8_t transaction, uint64_t uid,
+ uint8_t number, uint32_t *attrs,
+ void *user_data);
};

struct avrcp_control_cfm {
--
1.8.5.3


2014-03-17 08:08:52

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 07/12] android/avrcp-lib: Add support for parsing GetCurrentPlayerValue PDU

From: Luiz Augusto von Dentz <[email protected]>

---
android/avrcp-lib.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index ad551cd..f6bcbdf 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -411,6 +411,27 @@ static ssize_t get_value_text(struct avrcp *session, uint8_t transaction,
player->user_data);
}

+static ssize_t get_value(struct avrcp *session, uint8_t transaction,
+ uint16_t params_len, uint8_t *params,
+ void *user_data)
+{
+ struct avrcp_player *player = user_data;
+
+ DBG("");
+
+ if (!params || params_len < 1 + params[0])
+ return -EINVAL;
+
+ if (!check_attributes(params[0], &params[1]))
+ return -EINVAL;
+
+ if (!player->ind || !player->ind->get_value)
+ return -ENOSYS;
+
+ return player->ind->get_value(session, transaction, params[0],
+ &params[1], player->user_data);
+}
+
static const struct avrcp_control_handler player_handlers[] = {
{ AVRCP_GET_CAPABILITIES,
AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
@@ -427,6 +448,9 @@ static const struct avrcp_control_handler player_handlers[] = {
{ AVRCP_GET_PLAYER_VALUE_TEXT,
AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
get_value_text },
+ { AVRCP_GET_CURRENT_PLAYER_VALUE,
+ AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
+ get_value },
{ },
};

--
1.8.5.3


2014-03-17 08:08:53

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 08/12] android/avrcp-lib: Add support for parsing SetPlayerValue PDU

From: Luiz Augusto von Dentz <[email protected]>

---
android/avrcp-lib.c | 30 ++++++++++++++++++++++++++++++
android/avrcp-lib.h | 3 +++
2 files changed, 33 insertions(+)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index f6bcbdf..2bb84e4 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -432,6 +432,33 @@ static ssize_t get_value(struct avrcp *session, uint8_t transaction,
&params[1], player->user_data);
}

+static ssize_t set_value(struct avrcp *session, uint8_t transaction,
+ uint16_t params_len, uint8_t *params,
+ void *user_data)
+{
+ struct avrcp_player *player = user_data;
+ int i;
+
+ DBG("");
+
+ if (!params || params_len != params[0] * 2 + 1)
+ return -EINVAL;
+
+ for (i = 0; i < params[0]; i++) {
+ uint8_t attr = params[i * 2 + 1];
+ uint8_t val = params[i * 2 + 2];
+
+ if (!check_value(attr, 1, &val))
+ return -EINVAL;
+ }
+
+ if (!player->ind || !player->ind->set_value)
+ return -ENOSYS;
+
+ return player->ind->set_value(session, transaction, params[0],
+ &params[1], player->user_data);
+}
+
static const struct avrcp_control_handler player_handlers[] = {
{ AVRCP_GET_CAPABILITIES,
AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
@@ -451,6 +478,9 @@ static const struct avrcp_control_handler player_handlers[] = {
{ AVRCP_GET_CURRENT_PLAYER_VALUE,
AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
get_value },
+ { AVRCP_SET_PLAYER_VALUE,
+ AVC_CTYPE_CONTROL, AVC_CTYPE_STABLE,
+ set_value },
{ },
};

diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index b4ce2f4..feac9af 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -136,6 +136,9 @@ struct avrcp_control_ind {
int (*get_value) (struct avrcp *session, uint8_t transaction,
uint8_t number, uint8_t *attrs,
void *user_data);
+ int (*set_value) (struct avrcp *session, uint8_t transaction,
+ uint8_t number, uint8_t *attrs,
+ void *user_data);
};

struct avrcp_control_cfm {
--
1.8.5.3


2014-03-17 08:08:51

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 06/12] android/avrcp-lib: Add support for parsing GetPlayerValueText PDU

From: Luiz Augusto von Dentz <[email protected]>

---
android/avrcp-lib.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++
android/avrcp-lib.h | 6 ++++++
2 files changed, 64 insertions(+)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 3275992..ad551cd 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -356,6 +356,61 @@ static ssize_t list_values(struct avrcp *session, uint8_t transaction,
player->user_data);
}

+static bool check_value(uint8_t attr, uint8_t number, const uint8_t *values)
+{
+ int i;
+
+ for (i = 0; i < number; i++) {
+ /* Check for invalid value */
+ switch (attr) {
+ case AVRCP_ATTRIBUTE_EQUALIZER:
+ if (values[i] < AVRCP_EQUALIZER_OFF ||
+ values[i] > AVRCP_EQUALIZER_ON)
+ return false;
+ case AVRCP_ATTRIBUTE_REPEAT_MODE:
+ if (values[i] < AVRCP_REPEAT_MODE_OFF ||
+ values[i] > AVRCP_REPEAT_MODE_GROUP)
+ return false;
+ case AVRCP_ATTRIBUTE_SHUFFLE:
+ if (values[i] < AVRCP_SHUFFLE_OFF ||
+ values[i] > AVRCP_SHUFFLE_GROUP)
+ return false;
+ case AVRCP_ATTRIBUTE_SCAN:
+ if (values[i] < AVRCP_SCAN_OFF ||
+ values[i] > AVRCP_SCAN_GROUP)
+ return false;
+ }
+ }
+
+ return true;
+}
+
+static ssize_t get_value_text(struct avrcp *session, uint8_t transaction,
+ uint16_t params_len, uint8_t *params,
+ void *user_data)
+{
+ struct avrcp_player *player = user_data;
+
+ DBG("");
+
+ if (params_len != 2 + params[1])
+ return -EINVAL;
+
+ if (params[0] > AVRCP_ATTRIBUTE_LAST ||
+ params[0] == AVRCP_ATTRIBUTE_ILEGAL)
+ return -EINVAL;
+
+ if (!check_value(params[0], params[1], &params[2]))
+ return -EINVAL;
+
+ if (!player->ind || !player->ind->get_value_text)
+ return -ENOSYS;
+
+ return player->ind->get_value_text(session, transaction, params[0],
+ params[1], &params[2],
+ player->user_data);
+}
+
static const struct avrcp_control_handler player_handlers[] = {
{ AVRCP_GET_CAPABILITIES,
AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
@@ -369,6 +424,9 @@ static const struct avrcp_control_handler player_handlers[] = {
{ AVRCP_LIST_PLAYER_VALUES,
AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
list_values },
+ { AVRCP_GET_PLAYER_VALUE_TEXT,
+ AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
+ get_value_text },
{ },
};

diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index 2844000..b4ce2f4 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -130,6 +130,12 @@ struct avrcp_control_ind {
void *user_data);
int (*list_values) (struct avrcp *session, uint8_t transaction,
uint8_t attr, void *user_data);
+ int (*get_value_text) (struct avrcp *session, uint8_t transaction,
+ uint8_t attr, uint8_t number,
+ uint8_t *values, void *user_data);
+ int (*get_value) (struct avrcp *session, uint8_t transaction,
+ uint8_t number, uint8_t *attrs,
+ void *user_data);
};

struct avrcp_control_cfm {
--
1.8.5.3


2014-03-17 08:08:50

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 05/12] android/avrcp-lib: Add support for parsing ListPlayerValues PDU

From: Luiz Augusto von Dentz <[email protected]>

---
android/avrcp-lib.c | 25 +++++++++++++++++++++++++
android/avrcp-lib.h | 22 ++++++++++++++++++++++
2 files changed, 47 insertions(+)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index e0b1cd7..3275992 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -334,6 +334,28 @@ static ssize_t get_attribute_text(struct avrcp *session, uint8_t transaction,
&params[1], player->user_data);
}

+static ssize_t list_values(struct avrcp *session, uint8_t transaction,
+ uint16_t params_len, uint8_t *params,
+ void *user_data)
+{
+ struct avrcp_player *player = user_data;
+
+ DBG("");
+
+ if (!params || params_len != 1)
+ return -EINVAL;
+
+ if (params[0] > AVRCP_ATTRIBUTE_LAST ||
+ params[0] == AVRCP_ATTRIBUTE_ILEGAL)
+ return -EINVAL;
+
+ if (!player->ind || !player->ind->list_values)
+ return -ENOSYS;
+
+ return player->ind->list_values(session, transaction, params[0],
+ player->user_data);
+}
+
static const struct avrcp_control_handler player_handlers[] = {
{ AVRCP_GET_CAPABILITIES,
AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
@@ -344,6 +366,9 @@ static const struct avrcp_control_handler player_handlers[] = {
{ AVRCP_GET_PLAYER_ATTRIBUTE_TEXT,
AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
get_attribute_text },
+ { AVRCP_LIST_PLAYER_VALUES,
+ AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
+ list_values },
{ },
};

diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index 9b24509..2844000 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -84,6 +84,26 @@
#define AVRCP_ATTRIBUTE_SCAN 0x04
#define AVRCP_ATTRIBUTE_LAST AVRCP_ATTRIBUTE_SCAN

+/* equalizer values */
+#define AVRCP_EQUALIZER_OFF 0x01
+#define AVRCP_EQUALIZER_ON 0x02
+
+/* repeat mode values */
+#define AVRCP_REPEAT_MODE_OFF 0x01
+#define AVRCP_REPEAT_MODE_SINGLE 0x02
+#define AVRCP_REPEAT_MODE_ALL 0x03
+#define AVRCP_REPEAT_MODE_GROUP 0x04
+
+/* shuffle values */
+#define AVRCP_SHUFFLE_OFF 0x01
+#define AVRCP_SHUFFLE_ALL 0x02
+#define AVRCP_SHUFFLE_GROUP 0x03
+
+/* scan values */
+#define AVRCP_SCAN_OFF 0x01
+#define AVRCP_SCAN_ALL 0x02
+#define AVRCP_SCAN_GROUP 0x03
+
/* Company IDs for vendor dependent commands */
#define IEEEID_BTSIG 0x001958

@@ -108,6 +128,8 @@ struct avrcp_control_ind {
int (*get_attribute_text) (struct avrcp *session, uint8_t transaction,
uint8_t number, uint8_t *attrs,
void *user_data);
+ int (*list_values) (struct avrcp *session, uint8_t transaction,
+ uint8_t attr, void *user_data);
};

struct avrcp_control_cfm {
--
1.8.5.3


2014-03-17 08:08:49

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 04/12] android/avrcp-lib: Add support for parsing GetPlayerAttributeText PDU

From: Luiz Augusto von Dentz <[email protected]>

---
android/avrcp-lib.c | 37 +++++++++++++++++++++++++++++++++++++
android/avrcp-lib.h | 3 +++
2 files changed, 40 insertions(+)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 547d429..e0b1cd7 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -300,6 +300,40 @@ static ssize_t list_attributes(struct avrcp *session, uint8_t transaction,
player->user_data);
}

+static bool check_attributes(uint8_t number, const uint8_t *attrs)
+{
+ int i;
+
+ for (i = 0; i < number; i++) {
+ if (attrs[i] > AVRCP_ATTRIBUTE_LAST ||
+ attrs[i] == AVRCP_ATTRIBUTE_ILEGAL)
+ return false;
+ }
+
+ return true;
+}
+
+static ssize_t get_attribute_text(struct avrcp *session, uint8_t transaction,
+ uint16_t params_len, uint8_t *params,
+ void *user_data)
+{
+ struct avrcp_player *player = user_data;
+
+ DBG("");
+
+ if (!params || params_len != 1 + params[0])
+ return -EINVAL;
+
+ if (!check_attributes(params[0], &params[1]))
+ return -EINVAL;
+
+ if (!player->ind || !player->ind->get_attribute_text)
+ return -ENOSYS;
+
+ return player->ind->get_attribute_text(session, transaction, params[0],
+ &params[1], player->user_data);
+}
+
static const struct avrcp_control_handler player_handlers[] = {
{ AVRCP_GET_CAPABILITIES,
AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
@@ -307,6 +341,9 @@ static const struct avrcp_control_handler player_handlers[] = {
{ AVRCP_LIST_PLAYER_ATTRIBUTES,
AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
list_attributes },
+ { AVRCP_GET_PLAYER_ATTRIBUTE_TEXT,
+ AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
+ get_attribute_text },
{ },
};

diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index 0043362..9b24509 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -105,6 +105,9 @@ struct avrcp_control_ind {
void *user_data);
int (*list_attributes) (struct avrcp *session, uint8_t transaction,
void *user_data);
+ int (*get_attribute_text) (struct avrcp *session, uint8_t transaction,
+ uint8_t number, uint8_t *attrs,
+ void *user_data);
};

struct avrcp_control_cfm {
--
1.8.5.3


2014-03-17 08:08:48

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 03/12] android/avrcp-lib: Add support for parsing ListPlayerAttributes PDU

From: Luiz Augusto von Dentz <[email protected]>

---
android/avrcp-lib.c | 18 ++++++++++++++++++
android/avrcp-lib.h | 2 ++
2 files changed, 20 insertions(+)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 9c19092..547d429 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -285,10 +285,28 @@ static ssize_t get_capabilities(struct avrcp *session, uint8_t transaction,
return -EINVAL;
}

+static ssize_t list_attributes(struct avrcp *session, uint8_t transaction,
+ uint16_t params_len, uint8_t *params,
+ void *user_data)
+{
+ struct avrcp_player *player = user_data;
+
+ DBG("");
+
+ if (!player->ind || !player->ind->list_attributes)
+ return -ENOSYS;
+
+ return player->ind->list_attributes(session, transaction,
+ player->user_data);
+}
+
static const struct avrcp_control_handler player_handlers[] = {
{ AVRCP_GET_CAPABILITIES,
AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
get_capabilities },
+ { AVRCP_LIST_PLAYER_ATTRIBUTES,
+ AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
+ list_attributes },
{ },
};

diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index 34c88c5..0043362 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -103,6 +103,8 @@ struct avrcp_control_handler {
struct avrcp_control_ind {
int (*get_capabilities) (struct avrcp *session, uint8_t transaction,
void *user_data);
+ int (*list_attributes) (struct avrcp *session, uint8_t transaction,
+ void *user_data);
};

struct avrcp_control_cfm {
--
1.8.5.3


2014-03-17 08:08:47

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 02/12] android/avrcp-lib: Add support for parsing GetCapabilities PDU

From: Luiz Augusto von Dentz <[email protected]>

---
android/avrcp-lib.c | 32 ++++++++++++++++++++++++++++++++
android/avrcp-lib.h | 2 ++
2 files changed, 34 insertions(+)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index ca01b50..9c19092 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -261,6 +261,37 @@ void avrcp_set_destroy_cb(struct avrcp *session, avrcp_destroy_cb_t cb,
session->destroy_data = user_data;
}

+static ssize_t get_capabilities(struct avrcp *session, uint8_t transaction,
+ uint16_t params_len, uint8_t *params,
+ void *user_data)
+{
+ struct avrcp_player *player = user_data;
+
+ if (!params || params_len != 1)
+ return -EINVAL;
+
+ switch (params[0]) {
+ case CAP_COMPANY_ID:
+ params[1] = 1;
+ hton24(&params[2], IEEEID_BTSIG);
+ return 5;
+ case CAP_EVENTS_SUPPORTED:
+ if (!player->ind || !player->ind->get_capabilities)
+ return -ENOSYS;
+ return player->ind->get_capabilities(session, transaction,
+ player->user_data);
+ }
+
+ return -EINVAL;
+}
+
+static const struct avrcp_control_handler player_handlers[] = {
+ { AVRCP_GET_CAPABILITIES,
+ AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
+ get_capabilities },
+ { },
+};
+
void avrcp_register_player(struct avrcp *session,
const struct avrcp_control_ind *ind,
const struct avrcp_control_cfm *cfm,
@@ -273,6 +304,7 @@ void avrcp_register_player(struct avrcp *session,
player->cfm = cfm;
player->user_data = user_data;

+ avrcp_set_control_handlers(session, player_handlers, player);
session->player = player;
}

diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index 6e33a75..34c88c5 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -101,6 +101,8 @@ struct avrcp_control_handler {
};

struct avrcp_control_ind {
+ int (*get_capabilities) (struct avrcp *session, uint8_t transaction,
+ void *user_data);
};

struct avrcp_control_cfm {
--
1.8.5.3