Skip to contentSkip to conversation

android/avrcp-lib: Change API to register callbacks instead of PDU handlers

PATCH In review Luiz Augusto von Dentz 2 participants 19 messages Mar 17, 2014 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/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(+)
android/avrcp-lib.c +27 -0
index 7b043ce..ca01b50 100644
@@ -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)
android/avrcp-lib.h +11 -0
index 4adf4bf..6e33a75 100644
@@ -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);
Signature · 1 line
1.8.5.3
author maintainer
#1 lore raw

PATCH 2/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(+)
android/avrcp-lib.c +32 -0
index ca01b50..9c19092 100644
@@ -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;
 }
 
android/avrcp-lib.h +2 -0
index 6e33a75..34c88c5 100644
@@ -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 {
Signature · 1 line
1.8.5.3
author maintainer
#4 lore raw

PATCH 3/12 android/avrcp-lib: Add support for parsing ListPlayerAttributes PDU

In reply to Luiz Augusto von Dentz

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

---
 android/avrcp-lib.c | 18 ++++++++++++++++++
 android/avrcp-lib.h |  2 ++
 2 files changed, 20 insertions(+)
android/avrcp-lib.c +18 -0
index 9c19092..547d429 100644
@@ -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 },
 		{ },
 };
 
android/avrcp-lib.h +2 -0
index 34c88c5..0043362 100644
@@ -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 {
Signature · 1 line
1.8.5.3
author maintainer
#7 lore raw

PATCH 4/12 android/avrcp-lib: Add support for parsing GetPlayerAttributeText PDU

In reply to Luiz Augusto von Dentz

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

---
 android/avrcp-lib.c | 37 +++++++++++++++++++++++++++++++++++++
 android/avrcp-lib.h |  3 +++
 2 files changed, 40 insertions(+)
android/avrcp-lib.c +37 -0
index 547d429..e0b1cd7 100644
@@ -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 },
 		{ },
 };
 
android/avrcp-lib.h +3 -0
index 0043362..9b24509 100644
@@ -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 {
Signature · 1 line
1.8.5.3
author maintainer
#8 lore raw

PATCH 5/12 android/avrcp-lib: Add support for parsing ListPlayerValues PDU

In reply to Luiz Augusto von Dentz

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

---
 android/avrcp-lib.c | 25 +++++++++++++++++++++++++
 android/avrcp-lib.h | 22 ++++++++++++++++++++++
 2 files changed, 47 insertions(+)
android/avrcp-lib.c +25 -0
index e0b1cd7..3275992 100644
@@ -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 },
 		{ },
 };
 
android/avrcp-lib.h +22 -0
index 9b24509..2844000 100644
@@ -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 {
Signature · 1 line
1.8.5.3
author maintainer
#9 lore raw

PATCH 6/12 android/avrcp-lib: Add support for parsing GetPlayerValueText PDU

In reply to Luiz Augusto von Dentz

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

---
 android/avrcp-lib.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 android/avrcp-lib.h |  6 ++++++
 2 files changed, 64 insertions(+)
android/avrcp-lib.c +58 -0
index 3275992..ad551cd 100644
@@ -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 },
 		{ },
 };
 
android/avrcp-lib.h +6 -0
index 2844000..b4ce2f4 100644
@@ -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 {
Signature · 1 line
1.8.5.3
author maintainer
#10 lore raw

PATCH 7/12 android/avrcp-lib: Add support for parsing GetCurrentPlayerValue PDU

In reply to Luiz Augusto von Dentz

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

---
 android/avrcp-lib.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
android/avrcp-lib.c +24 -0
index ad551cd..f6bcbdf 100644
@@ -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 },
 		{ },
 };
 
Signature · 1 line
1.8.5.3
author maintainer
#11 lore raw

PATCH 8/12 android/avrcp-lib: Add support for parsing SetPlayerValue PDU

In reply to Luiz Augusto von Dentz

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

---
 android/avrcp-lib.c | 30 ++++++++++++++++++++++++++++++
 android/avrcp-lib.h |  3 +++
 2 files changed, 33 insertions(+)
android/avrcp-lib.c +30 -0
index f6bcbdf..2bb84e4 100644
@@ -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 },
 		{ },
 };
 
android/avrcp-lib.h +3 -0
index b4ce2f4..feac9af 100644
@@ -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 {
Signature · 1 line
1.8.5.3
author maintainer
#12 lore raw

PATCH 9/12 android/avrcp-lib: Add support for parsing GetPlayStatus PDU

In reply to Luiz Augusto von Dentz

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

---
 android/avrcp-lib.c | 18 ++++++++++++++++++
 android/avrcp-lib.h |  2 ++
 2 files changed, 20 insertions(+)
android/avrcp-lib.c +18 -0
index 2bb84e4..9577bf0 100644
@@ -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 },
 		{ },
 };
 
android/avrcp-lib.h +2 -0
index feac9af..71d710f 100644
@@ -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 {
Signature · 1 line
1.8.5.3
author maintainer
#13 lore raw

PATCH 10/12 android/avrcp-lib: Add support for parsing GetElementAttributes PDU

In reply to Luiz Augusto von Dentz

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

---
 android/avrcp-lib.c | 37 +++++++++++++++++++++++++++++++++++++
 android/avrcp-lib.h | 15 +++++++++++++++
 2 files changed, 52 insertions(+)
android/avrcp-lib.c +37 -0
index 9577bf0..d32f791 100644
@@ -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 },
 		{ },
 };
 
android/avrcp-lib.h +15 -0
index 71d710f..9257de7 100644
@@ -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 {
Signature · 1 line
1.8.5.3
author maintainer
#14 lore raw

PATCH 11/12 android/avrcp-lib: Add support for parsing ResgisterNotification PDU

In reply to Luiz Augusto von Dentz

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

---
 android/avrcp-lib.c | 25 +++++++++++++++++++++++++
 android/avrcp-lib.h |  3 +++
 2 files changed, 28 insertions(+)
android/avrcp-lib.c +25 -0
index d32f791..91f51b5 100644
@@ -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 },
 		{ },
 };
 
android/avrcp-lib.h +3 -0
index 9257de7..256576d 100644
@@ -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 {
Signature · 1 line
1.8.5.3
author maintainer
#15 lore raw

PATCH 12/12 android/avrcp-lib: Add support for parsing SetAddressedPlayer PDU

In reply to Luiz Augusto von Dentz

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

---
 android/avrcp-lib.c | 24 ++++++++++++++++++++++++
 android/avrcp-lib.h |  2 ++
 2 files changed, 26 insertions(+)
android/avrcp-lib.c +24 -0
index 91f51b5..083d7af 100644
@@ -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 },
 		{ },
 };
 
android/avrcp-lib.h +2 -0
index 256576d..54bdf4f 100644
@@ -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 {
Signature · 1 line
1.8.5.3
#16 lore raw
In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 39 lines · Luiz Augusto von Dentz

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(+)
android/avrcp-lib.c +8 -0
index 7b043ce..ca01b50 100644
@@ -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) {

android/avrcp-lib.c void avrcp_shutdown(struct avrcp *session) · line 118

Quoted 4 lines
android/avrcp-lib.c +1 -0
@@ -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

Quoted 71 lines
android/avrcp-lib.c +18 -0
 	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)
android/avrcp-lib.h +11 -0
index 4adf4bf..6e33a75 100644
@@ -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);
Signature · 6 lines
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
#2 lore raw

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

In reply to Luiz Augusto von Dentz
Quoted 12 lines · Luiz Augusto von Dentz

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

---
 android/avrcp-lib.c | 32 ++++++++++++++++++++++++++++++++
 android/avrcp-lib.h |  2 ++
 2 files changed, 34 insertions(+)
android/avrcp-lib.c +0 -0
index ca01b50..9c19092 100644

android/avrcp-lib.c void avrcp_set_destroy_cb(struct avrcp *session, avrcp_destroy_cb_t cb, · line 264

Quoted 4 lines
android/avrcp-lib.c +1 -0
@@ -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

Quoted 61 lines
android/avrcp-lib.c +31 -0
+				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;
 }
 
android/avrcp-lib.h +2 -0
index 6e33a75..34c88c5 100644
@@ -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 {
Signature · 6 lines
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
#5 lore raw

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

In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 45 lines · Luiz Augusto von Dentz

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

---
 android/avrcp-lib.c | 18 ++++++++++++++++++
 android/avrcp-lib.h |  2 ++
 2 files changed, 20 insertions(+)
android/avrcp-lib.c +18 -0
index 9c19092..547d429 100644
@@ -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 },
 		{ },
 };
 
android/avrcp-lib.h +0 -0
index 34c88c5..0043362 100644

android/avrcp-lib.h struct avrcp_control_handler { · line 106

Quoted 4 lines
android/avrcp-lib.h +1 -0
@@ -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

Quoted 11 lines
android/avrcp-lib.h +1 -0
+							void *user_data);
 };
 
 struct avrcp_control_cfm {
Signature · 6 lines
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
#6 lore raw

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

Hi Luiz,

Quoted 43 lines · Andrei Emeltchenko

Hi Luiz,

Quoted 40 lines · Luiz Augusto von Dentz

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

---
 android/avrcp-lib.c | 18 ++++++++++++++++++
 android/avrcp-lib.h |  2 ++
 2 files changed, 20 insertions(+)
android/avrcp-lib.c +18 -0
index 9c19092..547d429 100644
@@ -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 },
 		{ },
 };
 
Quoted 11 lines

android/avrcp-lib.h struct avrcp_control_handler { · line 106

Quoted 9 lines
android/avrcp-lib.h +1 -0
index 34c88c5..0043362 100644
@@ -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

author maintainer
#17 lore raw
In reply to Andrei Emeltchenko

Hi Andrei,

Quoted 45 lines · Andrei Emeltchenko

Hi Luiz,

Quoted 42 lines · Luiz Augusto von Dentz

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(+)
android/avrcp-lib.c +8 -0
index 7b043ce..ca01b50 100644
@@ -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);
 
Quoted 5 lines

android/avrcp-lib.c void avrcp_shutdown(struct avrcp *session) · line 118

Quoted 1 line
android/avrcp-lib.c +1 -0
+     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.

author maintainer
#3 lore raw

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

In reply to Andrei Emeltchenko

Hi Andrei,

Quoted 16 lines · Andrei Emeltchenko
Quoted 15 lines · Luiz Augusto von Dentz

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

---
 android/avrcp-lib.c | 32 ++++++++++++++++++++++++++++++++
 android/avrcp-lib.h |  2 ++
 2 files changed, 34 insertions(+)
android/avrcp-lib.c +0 -0
index ca01b50..9c19092 100644
@@ -261,6 +261,37 @@ void avrcp_set_destroy_cb(struct avrcp *session, avrcp_destroy_cb_t cb,
      session->destroy_data = user_data;
 }
 
Quoted 4 lines

android/avrcp-lib.c void avrcp_set_destroy_cb(struct avrcp *session, avrcp_destroy_cb_t cb, · line 264

Quoted 1 line
android/avrcp-lib.c +1 -0
+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.

author maintainer
#18 lore raw
In reply to Luiz Augusto von Dentz

Hi,

Quoted 14 lines · Luiz Augusto von Dentz

Hi Andrei,

Quoted 10 lines · Andrei Emeltchenko

Hi Luiz,

Quoted 7 lines · Luiz Augusto von Dentz

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.