All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Tyszkowski <jakub.tyszkowski@tieto.com>
To: linux-bluetooth@vger.kernel.org
Cc: Jakub Tyszkowski <jakub.tyszkowski@tieto.com>
Subject: [PATCHv4 11/13] android/tester: Make HIDHost tests use generic PDU exchange mechanism
Date: Thu,  2 Oct 2014 10:10:59 +0200	[thread overview]
Message-ID: <1412237461-20373-12-git-send-email-jakub.tyszkowski@tieto.com> (raw)
In-Reply-To: <1412237461-20373-1-git-send-email-jakub.tyszkowski@tieto.com>

---
 android/tester-hidhost.c | 225 ++++++++++++++++++++++-------------------------
 1 file changed, 106 insertions(+), 119 deletions(-)

diff --git a/android/tester-hidhost.c b/android/tester-hidhost.c
index 0327369..9173092 100644
--- a/android/tester-hidhost.c
+++ b/android/tester-hidhost.c
@@ -45,143 +45,128 @@
 
 static struct queue *list; /* List of hidhost test cases */
 
-struct emu_cid_data {
-	const int pdu_len;
-	const void *pdu;
-
-	uint16_t sdp_handle;
-	uint16_t sdp_cid;
-	uint16_t ctrl_handle;
-	uint16_t ctrl_cid;
-	uint16_t intr_handle;
-	uint16_t intr_cid;
+#define did_req_pdu	0x06, \
+			0x00, 0x00, \
+			0x00, 0x0f, \
+			0x35, 0x03, \
+			0x19, 0x12, 0x00, 0xff, 0xff, 0x35, 0x05, 0x0a, 0x00, \
+			0x00, 0xff, 0xff, 0x00
+
+#define did_rsp_pdu	0x07, \
+			0x00, 0x00, \
+			0x00, 0x4f, \
+			0x00, 0x4c, \
+			0x35, 0x4a, 0x35, 0x48, 0x09, 0x00, 0x00, 0x0a, 0x00, \
+			0x01, 0x00, 0x00, 0x09, 0x00, 0x01, 0x35, 0x03, 0x19, \
+			0x12, 0x00, 0x09, 0x00, 0x05, 0x35, 0x03, 0x19, 0x10, \
+			0x02, 0x09, 0x00, 0x09, 0x35, 0x08, 0x35, 0x06, 0x19, \
+			0x12, 0x00, 0x09, 0x01, 0x03, 0x09, 0x02, 0x00, 0x09, \
+			0x01, 0x03, 0x09, 0x02, 0x01, 0x09, 0x1d, 0x6b, 0x09, \
+			0x02, 0x02, 0x09, 0x02, 0x46, 0x09, 0x02, 0x03, 0x09, \
+			0x05, 0x0e, 0x09, 0x02, 0x04, 0x28, 0x01, 0x09, 0x02, \
+			0x05, 0x09, 0x00, 0x02, \
+			0x00
+
+#define hid_req_pdu	0x06, \
+			0x00, 0x01, \
+			0x00, 0x0f, \
+			0x35, 0x03, \
+			0x19, 0x11, 0x24, 0xff, 0xff, 0x35, 0x05, 0x0a, 0x00, \
+			0x00, 0xff, 0xff, 0x00
+
+#define hid_rsp_pdu	0x07, \
+			0x00, 0x01, \
+			0x01, 0x71, \
+			0x01, 0x6E, \
+			0x36, 0x01, 0x6b, 0x36, 0x01, 0x68, 0x09, 0x00, 0x00, \
+			0x0a, 0x00, 0x01, 0x00, 0x00, 0x09, 0x00, 0x01, 0x35, \
+			0x03, 0x19, 0x11, 0x24, 0x09, 0x00, 0x04, 0x35, 0x0d, \
+			0x35, 0x06, 0x19, 0x01, 0x00, 0x09, 0x00, 0x11, 0x35, \
+			0x03, 0x19, 0x00, 0x11, 0x09, 0x00, 0x05, 0x35, 0x03, \
+			0x19, 0x10, 0x02, 0x09, 0x00, 0x06, 0x35, 0x09, 0x09, \
+			0x65, 0x6e, 0x09, 0x00, 0x6a, 0x09, 0x01, 0x00, 0x09, \
+			0x00, 0x09, 0x35, 0x08, 0x35, 0x06, 0x19, 0x11, 0x24, \
+			0x09, 0x01, 0x00, 0x09, 0x00, 0x0d, 0x35, 0x0f, 0x35, \
+			0x0d, 0x35, 0x06, 0x19, 0x01, 0x00, 0x09, 0x00, 0x13, \
+			0x35, 0x03, 0x19, 0x00, 0x11, 0x09, 0x01, 0x00, 0x25, \
+			0x1e, 0x4c, 0x6f, 0x67, 0x69, 0x74, 0x65, 0x63, 0x68, \
+			0x20, 0x42, 0x6c, 0x75, 0x65, 0x74, 0x6f, 0x6f, 0x74, \
+			0x68, 0x20, 0x4d, 0x6f, 0x75, 0x73, 0x65, 0x20, 0x4d, \
+			0x35, 0x35, 0x35, 0x62, 0x09, 0x01, 0x01, 0x25, 0x0f, \
+			0x42, 0x6c, 0x75, 0x65, 0x74, 0x6f, 0x6f, 0x74, 0x68, \
+			0x20, 0x4d, 0x6f, 0x75, 0x73, 0x65, 0x09, 0x01, 0x02, \
+			0x25, 0x08, 0x4c, 0x6f, 0x67, 0x69, 0x74, 0x65, 0x63, \
+			0x68, 0x09, 0x02, 0x00, 0x09, 0x01, 0x00, 0x09, 0x02, \
+			0x01, 0x09, 0x01, 0x11, 0x09, 0x02, 0x02, 0x08, 0x80, \
+			0x09, 0x02, 0x03, 0x08, 0x21, 0x09, 0x02, 0x04, 0x28, \
+			0x01, 0x09, 0x02, 0x05, 0x28, 0x01, 0x09, 0x02, 0x06, \
+			0x35, 0x74, 0x35, 0x72, 0x08, 0x22, 0x25, 0x6e, 0x05, \
+			0x01, 0x09, 0x02, 0xa1, 0x01, 0x85, 0x02, 0x09, 0x01, \
+			0xa1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x08, 0x15, \
+			0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x08, 0x81, 0x02, \
+			0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x16, 0x01, 0xf8, \
+			0x26, 0xff, 0x07, 0x75, 0x0c, 0x95, 0x02, 0x81, 0x06, \
+			0x09, 0x38, 0x15, 0x81, 0x25, 0x7f, 0x75, 0x08, 0x95, \
+			0x01, 0x81, 0x06, 0x05, 0x0c, 0x0a, 0x38, 0x02, 0x81, \
+			0x06, 0x05, 0x09, 0x19, 0x09, 0x29, 0x10, 0x15, 0x00, \
+			0x25, 0x01, 0x95, 0x08, 0x75, 0x01, 0x81, 0x02, 0xc0, \
+			0xc0, 0x06, 0x00, 0xff, 0x09, 0x01, 0xa1, 0x01, 0x85, \
+			0x10, 0x75, 0x08, 0x95, 0x06, 0x15, 0x00, 0x26, 0xff, \
+			0x00, 0x09, 0x01, 0x81, 0x00, 0x09, 0x01, 0x91, 0x00, \
+			0xc0, 0x09, 0x02, 0x07, 0x35, 0x08, 0x35, 0x06, 0x09, \
+			0x04, 0x09, 0x09, 0x01, 0x00, 0x09, 0x02, 0x08, 0x28, \
+			0x00, 0x09, 0x02, 0x09, 0x28, 0x01, 0x09, 0x02, 0x0a, \
+			0x28, 0x01, 0x09, 0x02, 0x0b, 0x09, 0x01, 0x00, 0x09, \
+			0x02, 0x0c, 0x09, 0x0c, 0x80, 0x09, 0x02, 0x0d, 0x28, \
+			0x00, 0x09, 0x02, 0x0e, 0x28, 0x01, \
+			0x00
+
+static const struct pdu_set sdp_pdus[] = {
+	{ raw_pdu(did_req_pdu), raw_pdu(did_rsp_pdu) },
+	{ raw_pdu(hid_req_pdu), raw_pdu(hid_rsp_pdu) },
+	{ end_pdu, end_pdu },
 };
 
-static struct emu_cid_data cid_data;
-
-static const struct iovec did_req_pdu = raw_pdu(
-			0x06, /* PDU id */
-			0x00, 0x00, /* Transaction id */
-			0x00, 0x0f, /* Req length */
-			0x35, 0x03, /* Attributes length */
-			0x19, 0x12, 0x00, 0xff, 0xff, 0x35, 0x05, 0x0a, 0x00,
-			0x00, 0xff, 0xff, 0x00); /* no continuation */
-
-static const struct iovec did_rsp_pdu = raw_pdu(
-			0x07, /* PDU id */
-			0x00, 0x00, /* Transaction id */
-			0x00, 0x4f, /* Response length */
-			0x00, 0x4c, /* Attributes length */
-			0x35, 0x4a, 0x35, 0x48, 0x09, 0x00, 0x00, 0x0a, 0x00,
-			0x01, 0x00, 0x00, 0x09, 0x00, 0x01, 0x35, 0x03, 0x19,
-			0x12, 0x00, 0x09, 0x00, 0x05, 0x35, 0x03, 0x19, 0x10,
-			0x02, 0x09, 0x00, 0x09, 0x35, 0x08, 0x35, 0x06, 0x19,
-			0x12, 0x00, 0x09, 0x01, 0x03, 0x09, 0x02, 0x00, 0x09,
-			0x01, 0x03, 0x09, 0x02, 0x01, 0x09, 0x1d, 0x6b, 0x09,
-			0x02, 0x02, 0x09, 0x02, 0x46, 0x09, 0x02, 0x03, 0x09,
-			0x05, 0x0e, 0x09, 0x02, 0x04, 0x28, 0x01, 0x09, 0x02,
-			0x05, 0x09, 0x00, 0x02,
-			0x00); /* no continuation */
-
-static const struct iovec hid_rsp_pdu = raw_pdu(
-			0x07, /* PDU id */
-			0x00, 0x01, /* Transaction id */
-			0x01, 0x71, /* Response length */
-			0x01, 0x6E, /* Attributes length */
-			0x36, 0x01, 0x6b, 0x36, 0x01, 0x68, 0x09, 0x00, 0x00,
-			0x0a, 0x00, 0x01, 0x00, 0x00, 0x09, 0x00, 0x01, 0x35,
-			0x03, 0x19, 0x11, 0x24, 0x09, 0x00, 0x04, 0x35, 0x0d,
-			0x35, 0x06, 0x19, 0x01, 0x00, 0x09, 0x00, 0x11, 0x35,
-			0x03, 0x19, 0x00, 0x11, 0x09, 0x00, 0x05, 0x35, 0x03,
-			0x19, 0x10, 0x02, 0x09, 0x00, 0x06, 0x35, 0x09, 0x09,
-			0x65, 0x6e, 0x09, 0x00, 0x6a, 0x09, 0x01, 0x00, 0x09,
-			0x00, 0x09, 0x35, 0x08, 0x35, 0x06, 0x19, 0x11, 0x24,
-			0x09, 0x01, 0x00, 0x09, 0x00, 0x0d, 0x35, 0x0f, 0x35,
-			0x0d, 0x35, 0x06, 0x19, 0x01, 0x00, 0x09, 0x00, 0x13,
-			0x35, 0x03, 0x19, 0x00, 0x11, 0x09, 0x01, 0x00, 0x25,
-			0x1e, 0x4c, 0x6f, 0x67, 0x69, 0x74, 0x65, 0x63, 0x68,
-			0x20, 0x42, 0x6c, 0x75, 0x65, 0x74, 0x6f, 0x6f, 0x74,
-			0x68, 0x20, 0x4d, 0x6f, 0x75, 0x73, 0x65, 0x20, 0x4d,
-			0x35, 0x35, 0x35, 0x62, 0x09, 0x01, 0x01, 0x25, 0x0f,
-			0x42, 0x6c, 0x75, 0x65, 0x74, 0x6f, 0x6f, 0x74, 0x68,
-			0x20, 0x4d, 0x6f, 0x75, 0x73, 0x65, 0x09, 0x01, 0x02,
-			0x25, 0x08, 0x4c, 0x6f, 0x67, 0x69, 0x74, 0x65, 0x63,
-			0x68, 0x09, 0x02, 0x00, 0x09, 0x01, 0x00, 0x09, 0x02,
-			0x01, 0x09, 0x01, 0x11, 0x09, 0x02, 0x02, 0x08, 0x80,
-			0x09, 0x02, 0x03, 0x08, 0x21, 0x09, 0x02, 0x04, 0x28,
-			0x01, 0x09, 0x02, 0x05, 0x28, 0x01, 0x09, 0x02, 0x06,
-			0x35, 0x74, 0x35, 0x72, 0x08, 0x22, 0x25, 0x6e, 0x05,
-			0x01, 0x09, 0x02, 0xa1, 0x01, 0x85, 0x02, 0x09, 0x01,
-			0xa1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x08, 0x15,
-			0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x08, 0x81, 0x02,
-			0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x16, 0x01, 0xf8,
-			0x26, 0xff, 0x07, 0x75, 0x0c, 0x95, 0x02, 0x81, 0x06,
-			0x09, 0x38, 0x15, 0x81, 0x25, 0x7f, 0x75, 0x08, 0x95,
-			0x01, 0x81, 0x06, 0x05, 0x0c, 0x0a, 0x38, 0x02, 0x81,
-			0x06, 0x05, 0x09, 0x19, 0x09, 0x29, 0x10, 0x15, 0x00,
-			0x25, 0x01, 0x95, 0x08, 0x75, 0x01, 0x81, 0x02, 0xc0,
-			0xc0, 0x06, 0x00, 0xff, 0x09, 0x01, 0xa1, 0x01, 0x85,
-			0x10, 0x75, 0x08, 0x95, 0x06, 0x15, 0x00, 0x26, 0xff,
-			0x00, 0x09, 0x01, 0x81, 0x00, 0x09, 0x01, 0x91, 0x00,
-			0xc0, 0x09, 0x02, 0x07, 0x35, 0x08, 0x35, 0x06, 0x09,
-			0x04, 0x09, 0x09, 0x01, 0x00, 0x09, 0x02, 0x08, 0x28,
-			0x00, 0x09, 0x02, 0x09, 0x28, 0x01, 0x09, 0x02, 0x0a,
-			0x28, 0x01, 0x09, 0x02, 0x0b, 0x09, 0x01, 0x00, 0x09,
-			0x02, 0x0c, 0x09, 0x0c, 0x80, 0x09, 0x02, 0x0d, 0x28,
-			0x00, 0x09, 0x02, 0x0e, 0x28, 0x01,
-			0x00); /* no continuation */
-
-static void hid_sdp_cid_hook_cb(const void *data, uint16_t len, void *user_data)
-{
-	struct test_data *t_data = tester_get_data();
-	struct bthost *bthost = hciemu_client_get_host(t_data->hciemu);
-	struct emu_cid_data *cid_data = user_data;
+static struct emu_l2cap_cid_data sdp_cid_data = {
+	.pdu = sdp_pdus,
+	.is_sdp = TRUE,
+};
 
-	if (!memcmp(did_req_pdu.iov_base, data, len)) {
-		bthost_send_cid_v(bthost, cid_data->sdp_handle,
-					cid_data->sdp_cid, &did_rsp_pdu, 1);
-		return;
-	}
+static struct emu_l2cap_cid_data ctrl_cid_data;
+static struct emu_l2cap_cid_data intr_cid_data;
 
-	bthost_send_cid_v(bthost, cid_data->sdp_handle, cid_data->sdp_cid,
-							&hid_rsp_pdu, 1);
-}
 static void hid_sdp_search_cb(uint16_t handle, uint16_t cid, void *user_data)
 {
-	struct test_data *data = tester_get_data();
-	struct bthost *bthost = hciemu_client_get_host(data->hciemu);
+	struct emu_l2cap_cid_data *cid_data = user_data;
 
-	cid_data.sdp_handle = handle;
-	cid_data.sdp_cid = cid;
+	cid_data->handle = handle;
+	cid_data->cid = cid;
 
-	bthost_add_cid_hook(bthost, handle, cid, hid_sdp_cid_hook_cb,
-								&cid_data);
+	tester_handle_l2cap_data_exchange(cid_data);
 }
 
-static void hid_prepare_reply_protocol_mode(struct emu_cid_data *cid_data)
+static void hid_prepare_reply_protocol_mode(struct emu_l2cap_cid_data *cid_data)
 {
 	struct test_data *t_data = tester_get_data();
 	struct bthost *bthost = hciemu_client_get_host(t_data->hciemu);
 	const struct iovec pdu = raw_pdu(0xa0, 0x00);
 
-	bthost_send_cid_v(bthost, cid_data->ctrl_handle, cid_data->ctrl_cid,
-								&pdu, 1);
+	bthost_send_cid_v(bthost, cid_data->handle, cid_data->cid, &pdu, 1);
 }
 
-static void hid_prepare_reply_report(struct emu_cid_data *cid_data)
+static void hid_prepare_reply_report(struct emu_l2cap_cid_data *cid_data)
 {
 	struct test_data *t_data = tester_get_data();
 	struct bthost *bthost = hciemu_client_get_host(t_data->hciemu);
 	const struct iovec pdu = raw_pdu(0xa2, 0x01, 0x00);
 
-	bthost_send_cid_v(bthost, cid_data->ctrl_handle, cid_data->ctrl_cid,
-								&pdu, 1);
+	bthost_send_cid_v(bthost, cid_data->handle, cid_data->cid, &pdu, 1);
 }
 
 static void hid_ctrl_cid_hook_cb(const void *data, uint16_t len,
 							void *user_data)
 {
-	struct emu_cid_data *cid_data = user_data;
+	struct emu_l2cap_cid_data *cid_data = user_data;
 	uint8_t header = ((uint8_t *) data)[0];
 	struct step *step;
 
@@ -218,12 +203,13 @@ static void hid_ctrl_connect_cb(uint16_t handle, uint16_t cid, void *user_data)
 {
 	struct test_data *data = tester_get_data();
 	struct bthost *bthost = hciemu_client_get_host(data->hciemu);
+	struct emu_l2cap_cid_data *cid_data = user_data;
 
-	cid_data.ctrl_handle = handle;
-	cid_data.ctrl_cid = cid;
+	cid_data->handle = handle;
+	cid_data->cid = cid;
 
 	bthost_add_cid_hook(bthost, handle, cid, hid_ctrl_cid_hook_cb,
-								&cid_data);
+								cid_data);
 }
 
 static void hid_intr_cid_hook_cb(const void *data, uint16_t len,
@@ -247,33 +233,34 @@ static void hid_intr_connect_cb(uint16_t handle, uint16_t cid, void *user_data)
 {
 	struct test_data *data = tester_get_data();
 	struct bthost *bthost = hciemu_client_get_host(data->hciemu);
+	struct emu_l2cap_cid_data *cid_data = user_data;
 
-	cid_data.intr_handle = handle;
-	cid_data.intr_cid = cid;
+	cid_data->handle = handle;
+	cid_data->cid = cid;
 
 	bthost_add_cid_hook(bthost, handle, cid, hid_intr_cid_hook_cb,
-								&cid_data);
+								cid_data);
 }
 
 /* Emulate SDP (PSM = 1) */
 static struct emu_set_l2cap_data l2cap_setup_sdp_data = {
 	.psm = 1,
 	.func = hid_sdp_search_cb,
-	.user_data = NULL,
+	.user_data = &sdp_cid_data,
 };
 
 /* Emulate Control Channel (PSM = 17) */
 static struct emu_set_l2cap_data l2cap_setup_cc_data = {
 	.psm = 17,
 	.func = hid_ctrl_connect_cb,
-	.user_data = NULL,
+	.user_data = &ctrl_cid_data,
 };
 
 /* Emulate Interrupt Channel (PSM = 19) */
 static struct emu_set_l2cap_data l2cap_setup_ic_data = {
 	.psm = 19,
 	.func = hid_intr_connect_cb,
-	.user_data = NULL,
+	.user_data = &intr_cid_data,
 };
 
 static void hidhost_connect_action(void)
-- 
1.9.1


  parent reply	other threads:[~2014-10-02  8:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-02  8:10 [PATCHv4 00/13] android/tester: Unifying the way PDU is handled Jakub Tyszkowski
2014-10-02  8:10 ` [PATCHv4 01/13] android/tester: Replace gatt-tester's pdu structs with io vectors Jakub Tyszkowski
2014-10-02  8:10 ` [PATCHv4 02/13] android/tester: Expose structs holding request pdu and response pdu Jakub Tyszkowski
2014-10-02  8:10 ` [PATCHv4 03/13] android/tester: Make HidHost tests use io vectors for pdu Jakub Tyszkowski
2014-10-02  8:10 ` [PATCHv4 04/13] android/tester: Make PAN " Jakub Tyszkowski
2014-10-02  8:10 ` [PATCHv4 05/13] android/tester: Make HDP " Jakub Tyszkowski
2014-10-02  8:10 ` [PATCHv4 06/13] android/tester: Add generic hook to handle pdu exchange Jakub Tyszkowski
2014-10-02  8:10 ` [PATCHv4 07/13] android/tester: Make A2DP use generic pdu exchange mechanism Jakub Tyszkowski
2014-10-02  8:10 ` [PATCHv4 08/13] android/tester: Make AVRCP tests " Jakub Tyszkowski
2014-10-02  8:10 ` [PATCHv4 09/13] android/tester: Make GATT use generic cid_data Jakub Tyszkowski
2014-10-02  8:10 ` [PATCHv4 10/13] android/tester: Make HDP tests use generic PDU exchange mechanism Jakub Tyszkowski
2014-10-02  8:10 ` Jakub Tyszkowski [this message]
2014-10-02  8:11 ` [PATCHv4 12/13] android/tester: Make PAN " Jakub Tyszkowski
2014-10-02  8:11 ` [PATCHv4 13/13] android/tester: Use generic connect callback for simple cases Jakub Tyszkowski
2014-10-02 11:22 ` [PATCHv4 00/13] android/tester: Unifying the way PDU is handled Luiz Augusto von Dentz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1412237461-20373-12-git-send-email-jakub.tyszkowski@tieto.com \
    --to=jakub.tyszkowski@tieto.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.