Diff between 076e5e2ca1b1906118c70aa7009ff4fc384ebf2a and ac3484e900f55d0066f73325fe23b59056e94217

Changed Files

File Additions Deletions Status
android/avrcp-lib.c +63 -1 modified
android/avrcp-lib.h +3 -0 modified

Full Patch

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index c11abcd..ec5ffdb 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -28,6 +28,7 @@
 #include <stdbool.h>
 #include <glib.h>
 #include <errno.h>
+#include <string.h>
 
 #include "lib/bluetooth.h"
 
@@ -44,7 +45,7 @@
 #define AVRCP_PACKET_TYPE_CONTINUING		0x02
 #define AVRCP_PACKET_TYPE_END			0x03
 
-#define AVRCP_CHARSET_UTF8			106
+#define AVRCP_CHARSET_UTF8	0x006a
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 
@@ -1841,6 +1842,67 @@ int avrcp_get_item_attributes(struct avrcp *session, uint8_t scope,
 					get_item_attributes_rsp, session);
 }
 
+static gboolean search_rsp(struct avctp *conn, uint8_t *operands,
+					size_t operand_count, void *user_data)
+{
+	struct avrcp *session = user_data;
+	struct avrcp_player *player = session->player;
+	struct avrcp_browsing_header *pdu;
+	uint16_t counter = 0;
+	uint32_t items = 0;
+	int err;
+
+	DBG("");
+
+	if (!player || !player->cfm || !player->cfm->search)
+		return FALSE;
+
+	pdu = parse_browsing_pdu(operands, operand_count);
+	if (!pdu) {
+		err = -EPROTO;
+		goto done;
+	}
+
+	err = parse_browsing_status(pdu);
+	if (err < 0)
+		goto done;
+
+	if (pdu->params_len < 7) {
+		err = -EPROTO;
+		goto done;
+	}
+
+	counter = get_be16(&pdu->params[1]);
+	items = get_be32(&pdu->params[3]);
+
+	err = 0;
+
+done:
+	player->cfm->search(session, err, counter, items, player->user_data);
+
+	return FALSE;
+}
+
+int avrcp_search(struct avrcp *session, const char *string)
+{
+	uint8_t pdu[255];
+	size_t len;
+
+	if (!string)
+		return -EINVAL;
+
+	len = strnlen(string, 255 - 4);
+
+	put_be16(AVRCP_CHARSET_UTF8, &pdu[0]);
+	put_be16(len, &pdu[2]);
+
+	memcpy(&pdu[4], string, len);
+	len += 4;
+
+	return avrcp_send_browsing_req(session, AVRCP_SEARCH,
+					pdu, len, search_rsp, session);
+}
+
 int avrcp_get_capabilities_rsp(struct avrcp *session, uint8_t transaction,
 						uint8_t number, uint8_t *events)
 {
diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index 02702d7..31a65b4 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -213,6 +213,8 @@ struct avrcp_control_cfm {
 	void (*get_item_attributes) (struct avrcp *session, int err,
 					uint8_t number, uint32_t *attrs,
 					char **text, void *user_data);
+	void (*search) (struct avrcp *session, int err, uint16_t counter,
+					uint32_t items, void *user_data);
 };
 
 struct avrcp_passthrough_handler {
@@ -268,6 +270,7 @@ int avrcp_change_path(struct avrcp *session, uint8_t direction, uint64_t uid,
 int avrcp_get_item_attributes(struct avrcp *session, uint8_t scope,
 				uint64_t uid, uint16_t counter, uint8_t number,
 				uint32_t *attrs);
+int avrcp_search(struct avrcp *session, const char *string);
 
 int avrcp_get_capabilities_rsp(struct avrcp *session, uint8_t transaction,
 					uint8_t number, uint8_t *events);