[PATCH v2 3/3] unit/test-gatt: Add test for unknown request

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx>

This send an unknown command (0xff) to test that no response is sent
since the spec mandates the server to not respond to commands:

BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F page 2179

  'If a server receives a command that it does not support, indicated
  by the Command Flag of the PDU set to one, then the server shall
  ignore the Command.'
---
 unit/test-gatt.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 371cb46..e0d29c7 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -90,6 +90,11 @@ struct context {
 		.size = sizeof(data(args)),			\
 	}
 
+#define false_pdu()						\
+	{							\
+		.valid = false,					\
+	}
+
 #define define_test(name, function, type, bt_uuid, db,			\
 		test_step, args...)					\
 	do {								\
@@ -403,6 +408,13 @@ static gboolean send_pdu(gpointer user_data)
 	if (pdu->valid && (pdu->size == 0)) {
 		test_debug("(no action expected)", "GATT: ");
 		context->pdu_offset++;
+
+		/* Quit the context if we processed the last PDU */
+		if (!context->data->pdu_list[context->pdu_offset].valid) {
+			context_quit(context);
+			return FALSE;
+		}
+
 		return send_pdu(context);
 	}
 
@@ -4467,5 +4479,11 @@ int main(int argc, char *argv[])
 			raw_pdu(0xbf, 0x00),
 			raw_pdu(0x01, 0xbf, 0x00, 0x00, 0x06));
 
+	define_test_server("/robustness/unkown-command",
+			test_server, service_db_1, NULL,
+			raw_pdu(0x03, 0x00, 0x02),
+			raw_pdu(0xff, 0x00),
+			raw_pdu());
+
 	return tester_run();
 }
-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux