All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 01/11] shared/att: Auto retry if request fails
@ 2015-06-23 12:53 Luiz Augusto von Dentz
  2015-06-23 12:53 ` [PATCH BlueZ 02/11] shared/att: Add BT_ATT_SECURITY_AUTO Luiz Augusto von Dentz
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2015-06-23 12:53 UTC (permalink / raw)
  To: linux-bluetooth

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

This adds auto retry logic to requests when a security error happen,
it will first attempt to elevate the security to match the requirement
and then retry sending the request once again.
---
 src/shared/att.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 54 insertions(+), 4 deletions(-)

diff --git a/src/shared/att.c b/src/shared/att.c
index f9a5817..e8be4cc 100644
--- a/src/shared/att.c
+++ b/src/shared/att.c
@@ -576,6 +576,55 @@ static bool disconnect_cb(struct io *io, void *user_data)
 	return false;
 }
 
+static bool change_security(struct bt_att *att, uint8_t ecode)
+{
+	int security;
+
+	security = bt_att_get_security(att);
+	if (ecode == BT_ATT_ERROR_INSUFFICIENT_ENCRYPTION &&
+					security < BT_ATT_SECURITY_MEDIUM)
+		security = BT_ATT_SECURITY_MEDIUM;
+	else if (ecode == BT_ATT_ERROR_AUTHENTICATION &&
+					security < BT_ATT_SECURITY_HIGH)
+		security = BT_ATT_SECURITY_HIGH;
+	else
+		return false;
+
+	return bt_att_set_security(att, security);
+}
+
+static bool handle_error_rsp(struct bt_att *att, uint8_t *pdu,
+					ssize_t pdu_len, uint8_t *opcode)
+{
+	const struct bt_att_pdu_error_rsp *rsp;
+	struct att_send_op *op = att->pending_req;
+
+	if (pdu_len != sizeof(*rsp)) {
+		*opcode = 0;
+		return false;
+	}
+
+	rsp = (void *) pdu;
+
+	*opcode = rsp->opcode;
+
+	/* Only try to change security on L2CAP */
+	if (!att->io_on_l2cap)
+		return false;
+
+	/* Attempt to change security */
+	if (!change_security(att, rsp->ecode))
+		return false;
+
+	util_debug(att->debug_callback, att->debug_data,
+						"Retrying operation %p", op);
+
+	att->pending_req = NULL;
+
+	/* Push operation back to request queue */
+	return queue_push_head(att->req_queue, op);
+}
+
 static void handle_rsp(struct bt_att *att, uint8_t opcode, uint8_t *pdu,
 								ssize_t pdu_len)
 {
@@ -601,10 +650,11 @@ static void handle_rsp(struct bt_att *att, uint8_t opcode, uint8_t *pdu,
 	 * the request is malformed, end the current request with failure.
 	 */
 	if (opcode == BT_ATT_OP_ERROR_RSP) {
-		if (pdu_len != 4)
-			goto fail;
-
-		req_opcode = pdu[0];
+		/* Return if error response cause a retry */
+		if (handle_error_rsp(att, pdu, pdu_len, &req_opcode)) {
+			wakeup_writer(att);
+			return;
+		}
 	} else if (!(req_opcode = get_req_opcode(opcode)))
 		goto fail;
 
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH BlueZ 02/11] shared/att: Add BT_ATT_SECURITY_AUTO
  2015-06-23 12:53 [PATCH BlueZ 01/11] shared/att: Auto retry if request fails Luiz Augusto von Dentz
@ 2015-06-23 12:53 ` Luiz Augusto von Dentz
  2015-06-23 12:53 ` [PATCH BlueZ 03/11] unit/test-gatt: Use auto security Luiz Augusto von Dentz
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2015-06-23 12:53 UTC (permalink / raw)
  To: linux-bluetooth

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

This security level enables auto elevation (on by default), this would be
useful for unit tests since it can now control this behavior (default for
non L2CAP transport is BT_ATT_SECURITY_LOW).
---
 src/shared/att-types.h |  2 +-
 src/shared/att.c       | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/shared/att-types.h b/src/shared/att-types.h
index ee20992..d474495 100644
--- a/src/shared/att-types.h
+++ b/src/shared/att-types.h
@@ -27,7 +27,7 @@
 #define __packed __attribute__((packed))
 #endif
 
-#define BT_ATT_SECURITY_NONE	0
+#define BT_ATT_SECURITY_AUTO	0
 #define BT_ATT_SECURITY_LOW	1
 #define BT_ATT_SECURITY_MEDIUM	2
 #define BT_ATT_SECURITY_HIGH	3
diff --git a/src/shared/att.c b/src/shared/att.c
index e8be4cc..70f5d72 100644
--- a/src/shared/att.c
+++ b/src/shared/att.c
@@ -581,6 +581,9 @@ static bool change_security(struct bt_att *att, uint8_t ecode)
 	int security;
 
 	security = bt_att_get_security(att);
+	if (security != BT_ATT_SECURITY_AUTO)
+		return false;
+
 	if (ecode == BT_ATT_ERROR_INSUFFICIENT_ENCRYPTION &&
 					security < BT_ATT_SECURITY_MEDIUM)
 		security = BT_ATT_SECURITY_MEDIUM;
@@ -608,10 +611,6 @@ static bool handle_error_rsp(struct bt_att *att, uint8_t *pdu,
 
 	*opcode = rsp->opcode;
 
-	/* Only try to change security on L2CAP */
-	if (!att->io_on_l2cap)
-		return false;
-
 	/* Attempt to change security */
 	if (!change_security(att, rsp->ecode))
 		return false;
@@ -1416,7 +1415,8 @@ bool bt_att_set_security(struct bt_att *att, int level)
 {
 	struct bt_security sec;
 
-	if (!att || level < BT_ATT_SECURITY_LOW || level > BT_ATT_SECURITY_HIGH)
+	if (!att || level < BT_ATT_SECURITY_AUTO ||
+						level > BT_ATT_SECURITY_HIGH)
 		return false;
 
 	if (!att->io_on_l2cap) {
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH BlueZ 03/11] unit/test-gatt: Use auto security
  2015-06-23 12:53 [PATCH BlueZ 01/11] shared/att: Auto retry if request fails Luiz Augusto von Dentz
  2015-06-23 12:53 ` [PATCH BlueZ 02/11] shared/att: Add BT_ATT_SECURITY_AUTO Luiz Augusto von Dentz
@ 2015-06-23 12:53 ` Luiz Augusto von Dentz
  2015-06-23 12:53 ` [PATCH BlueZ 04/11] unit/test-gatt: Add /TP/GAR/CL/BI-04-C/auto test Luiz Augusto von Dentz
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2015-06-23 12:53 UTC (permalink / raw)
  To: linux-bluetooth

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

If the test don't expect any errors to happen use set security to auto so
bt_att will take care of elevating the security whenever needed.
---
 unit/test-gatt.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index bb6a270..9a9fa60 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -630,6 +630,10 @@ static void client_ready_cb(bool success, uint8_t att_ecode, void *user_data)
 	if (context->data->step) {
 		const struct test_step *step = context->data->step;
 
+		/* Auto elevate security for test that don't expect error */
+		if (!step->expected_att_ecode)
+			bt_att_set_security(context->att, BT_ATT_SECURITY_AUTO);
+
 		step->func(context);
 		return;
 	}
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH BlueZ 04/11] unit/test-gatt: Add /TP/GAR/CL/BI-04-C/auto test
  2015-06-23 12:53 [PATCH BlueZ 01/11] shared/att: Auto retry if request fails Luiz Augusto von Dentz
  2015-06-23 12:53 ` [PATCH BlueZ 02/11] shared/att: Add BT_ATT_SECURITY_AUTO Luiz Augusto von Dentz
  2015-06-23 12:53 ` [PATCH BlueZ 03/11] unit/test-gatt: Use auto security Luiz Augusto von Dentz
@ 2015-06-23 12:53 ` Luiz Augusto von Dentz
  2015-06-23 12:53 ` [PATCH BlueZ 05/11] unit/test-gatt: Add /TP/GAR/CL/BI-16-C/auto test Luiz Augusto von Dentz
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2015-06-23 12:53 UTC (permalink / raw)
  To: linux-bluetooth

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

/TP/GAR/CL/BI-04-C/auto is similar to TP/GAR/CL/BI-04-C but automatically
elevates the security level and retry.
---
 unit/test-gatt.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 9a9fa60..2d9128e 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -2691,6 +2691,14 @@ int main(int argc, char *argv[])
 			raw_pdu(0x0a, 0x03, 0x00),
 			raw_pdu(0x01, 0x0a, 0x03, 0x00, 0x05));
 
+	define_test_client("/TP/GAR/CL/BI-04-C/auto", test_client, service_db_1,
+			&test_read_1,
+			SERVICE_DATA_1_PDUS,
+			raw_pdu(0x0a, 0x03, 0x00),
+			raw_pdu(0x01, 0x0a, 0x03, 0x00, 0x05),
+			raw_pdu(0x0a, 0x03, 0x00),
+			raw_pdu(0x0b, 0x01, 0x02, 0x03));
+
 	define_test_client("/TP/GAR/CL/BI-05-C", test_client, service_db_1,
 			&test_read_6,
 			SERVICE_DATA_1_PDUS,
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH BlueZ 05/11] unit/test-gatt: Add /TP/GAR/CL/BI-16-C/auto test
  2015-06-23 12:53 [PATCH BlueZ 01/11] shared/att: Auto retry if request fails Luiz Augusto von Dentz
                   ` (2 preceding siblings ...)
  2015-06-23 12:53 ` [PATCH BlueZ 04/11] unit/test-gatt: Add /TP/GAR/CL/BI-04-C/auto test Luiz Augusto von Dentz
@ 2015-06-23 12:53 ` Luiz Augusto von Dentz
  2015-06-23 12:53 ` [PATCH BlueZ 06/11] unit/test-gatt: Add /TP/GAR/CL/BI-21-C/auto test Luiz Augusto von Dentz
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2015-06-23 12:53 UTC (permalink / raw)
  To: linux-bluetooth

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

/TP/GAR/CL/BI-16-C/auto is similar to /TP/GAR/CL/BI-16-C but
automatically elevates the security level and retry.
---
 unit/test-gatt.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 2d9128e..5d1650f 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -3041,6 +3041,14 @@ int main(int argc, char *argv[])
 			raw_pdu(0x0c, 0x03, 0x00, 0x00, 0x00),
 			raw_pdu(0x01, 0x0c, 0x03, 0x00, 0x05));
 
+	define_test_client("/TP/GAR/CL/BI-16-C/auto", test_client, service_db_1,
+			&test_long_read_1,
+			SERVICE_DATA_1_PDUS,
+			raw_pdu(0x0c, 0x03, 0x00, 0x00, 0x00),
+			raw_pdu(0x01, 0x0c, 0x03, 0x00, 0x05),
+			raw_pdu(0x0c, 0x03, 0x00, 0x00, 0x00),
+			raw_pdu(0x0d, 0x01, 0x02, 0x03));
+
 	define_test_client("/TP/GAR/CL/BI-17-C", test_client, service_db_1,
 			&test_long_read_8,
 			SERVICE_DATA_1_PDUS,
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH BlueZ 06/11] unit/test-gatt: Add /TP/GAR/CL/BI-21-C/auto test
  2015-06-23 12:53 [PATCH BlueZ 01/11] shared/att: Auto retry if request fails Luiz Augusto von Dentz
                   ` (3 preceding siblings ...)
  2015-06-23 12:53 ` [PATCH BlueZ 05/11] unit/test-gatt: Add /TP/GAR/CL/BI-16-C/auto test Luiz Augusto von Dentz
@ 2015-06-23 12:53 ` Luiz Augusto von Dentz
  2015-06-23 12:53 ` [PATCH BlueZ 07/11] unit/test-gatt: Add /TP/GAR/CL/BI-26-C/auto test Luiz Augusto von Dentz
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2015-06-23 12:53 UTC (permalink / raw)
  To: linux-bluetooth

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

/TP/GAR/CL/BI-21-C/auto is similar to /TP/GAR/CL/BI-21-C but
automatically elevates the security level and retry.
---
 unit/test-gatt.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 5d1650f..a131501 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -3079,6 +3079,14 @@ int main(int argc, char *argv[])
 			raw_pdu(0x0e, 0x03, 0x00, 0x07, 0x00),
 			raw_pdu(0x01, 0x0e, 0x03, 0x00, 0x05));
 
+	define_test_client("/TP/GAR/CL/BI-21-C/auto", test_client, service_db_1,
+			&test_multiple_read_1,
+			SERVICE_DATA_1_PDUS,
+			raw_pdu(0x0e, 0x03, 0x00, 0x07, 0x00),
+			raw_pdu(0x01, 0x0e, 0x03, 0x00, 0x05),
+			raw_pdu(0x0e, 0x03, 0x00, 0x07, 0x00),
+			raw_pdu(0x0f, 0x01, 0x02, 0x03));
+
 	define_test_client("/TP/GAR/CL/BI-22-C", test_client, service_db_1,
 			&test_multiple_read_6,
 			SERVICE_DATA_1_PDUS,
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH BlueZ 07/11] unit/test-gatt: Add /TP/GAR/CL/BI-26-C/auto test
  2015-06-23 12:53 [PATCH BlueZ 01/11] shared/att: Auto retry if request fails Luiz Augusto von Dentz
                   ` (4 preceding siblings ...)
  2015-06-23 12:53 ` [PATCH BlueZ 06/11] unit/test-gatt: Add /TP/GAR/CL/BI-21-C/auto test Luiz Augusto von Dentz
@ 2015-06-23 12:53 ` Luiz Augusto von Dentz
  2015-06-23 12:53 ` [PATCH BlueZ 08/11] unit/test-gatt: Add /TP/GAR/CL/BI-32-C/auto test Luiz Augusto von Dentz
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2015-06-23 12:53 UTC (permalink / raw)
  To: linux-bluetooth

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

/TP/GAR/CL/BI-26-C/auto is similar to /TP/GAR/CL/BI-26-C but
automatically elevates the security level and retry.
---
 unit/test-gatt.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index a131501..69dcbf9 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -3282,6 +3282,14 @@ int main(int argc, char *argv[])
 			raw_pdu(0x0a, 0x04, 0x00),
 			raw_pdu(0x01, 0x0a, 0x04, 0x00, 0x05));
 
+	define_test_client("/TP/GAR/CL/BI-26-C/auto", test_client, service_db_1,
+			&test_read_7,
+			SERVICE_DATA_1_PDUS,
+			raw_pdu(0x0a, 0x04, 0x00),
+			raw_pdu(0x01, 0x0a, 0x04, 0x00, 0x05),
+			raw_pdu(0x0a, 0x04, 0x00),
+			raw_pdu(0x0b, 0x01, 0x02, 0x03));
+
 	define_test_client("/TP/GAR/CL/BI-27-C", test_client, service_db_1,
 			&test_read_11,
 			SERVICE_DATA_1_PDUS,
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH BlueZ 08/11] unit/test-gatt: Add /TP/GAR/CL/BI-32-C/auto test
  2015-06-23 12:53 [PATCH BlueZ 01/11] shared/att: Auto retry if request fails Luiz Augusto von Dentz
                   ` (5 preceding siblings ...)
  2015-06-23 12:53 ` [PATCH BlueZ 07/11] unit/test-gatt: Add /TP/GAR/CL/BI-26-C/auto test Luiz Augusto von Dentz
@ 2015-06-23 12:53 ` Luiz Augusto von Dentz
  2015-06-23 12:53 ` [PATCH BlueZ 09/11] unit/test-gatt: Add /TP/GAW/CL/BI-05-C/auto test Luiz Augusto von Dentz
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2015-06-23 12:53 UTC (permalink / raw)
  To: linux-bluetooth

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

/TP/GAR/CL/BI-32-C/auto is similar to /TP/GAR/CL/BI-32-C but
automatically elevates the security level and retry.
---
 unit/test-gatt.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 69dcbf9..2737bd4 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -3442,6 +3442,14 @@ int main(int argc, char *argv[])
 			raw_pdu(0x0c, 0x04, 0x00, 0x00, 0x00),
 			raw_pdu(0x01, 0x0c, 0x04, 0x00, 0x05));
 
+	define_test_client("/TP/GAR/CL/BI-32-C/auto", test_client, service_db_1,
+			&test_long_read_9,
+			SERVICE_DATA_1_PDUS,
+			raw_pdu(0x0c, 0x04, 0x00, 0x00, 0x00),
+			raw_pdu(0x01, 0x0c, 0x04, 0x00, 0x05),
+			raw_pdu(0x0c, 0x04, 0x00, 0x00, 0x00),
+			raw_pdu(0x0d, 0x01, 0x02, 0x03));
+
 	define_test_client("/TP/GAR/CL/BI-33-C", test_client, service_db_1,
 			&test_long_read_15,
 			SERVICE_DATA_1_PDUS,
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH BlueZ 09/11] unit/test-gatt: Add /TP/GAW/CL/BI-05-C/auto test
  2015-06-23 12:53 [PATCH BlueZ 01/11] shared/att: Auto retry if request fails Luiz Augusto von Dentz
                   ` (6 preceding siblings ...)
  2015-06-23 12:53 ` [PATCH BlueZ 08/11] unit/test-gatt: Add /TP/GAR/CL/BI-32-C/auto test Luiz Augusto von Dentz
@ 2015-06-23 12:53 ` Luiz Augusto von Dentz
  2015-06-23 12:53 ` [PATCH BlueZ 10/11] unit/test-gatt: Add /TP/GAW/CL/BI-18-C/auto test Luiz Augusto von Dentz
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2015-06-23 12:53 UTC (permalink / raw)
  To: linux-bluetooth

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

/TP/GAW/CL/BI-05-C/auto is similar to /TP/GAW/CL/BI-05-C but
automatically elevates the security level and retry.
---
 unit/test-gatt.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 2737bd4..6df6342 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -3515,6 +3515,14 @@ int main(int argc, char *argv[])
 			raw_pdu(0x12, 0x07, 0x00, 0x01, 0x02, 0x03),
 			raw_pdu(0x01, 0x12, 0x07, 0x00, 0x05));
 
+	define_test_client("/TP/GAW/CL/BI-05-C/auto", test_client, service_db_1,
+			&test_write_1,
+			SERVICE_DATA_1_PDUS,
+			raw_pdu(0x12, 0x07, 0x00, 0x01, 0x02, 0x03),
+			raw_pdu(0x01, 0x12, 0x07, 0x00, 0x05),
+			raw_pdu(0x12, 0x07, 0x00, 0x01, 0x02, 0x03),
+			raw_pdu(0x13));
+
 	define_test_client("/TP/GAW/CL/BI-06-C", test_client, service_db_1,
 			&test_write_6,
 			SERVICE_DATA_1_PDUS,
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH BlueZ 10/11] unit/test-gatt: Add /TP/GAW/CL/BI-18-C/auto test
  2015-06-23 12:53 [PATCH BlueZ 01/11] shared/att: Auto retry if request fails Luiz Augusto von Dentz
                   ` (7 preceding siblings ...)
  2015-06-23 12:53 ` [PATCH BlueZ 09/11] unit/test-gatt: Add /TP/GAW/CL/BI-05-C/auto test Luiz Augusto von Dentz
@ 2015-06-23 12:53 ` Luiz Augusto von Dentz
  2015-06-23 12:53 ` [PATCH BlueZ 11/11] unit/test-gatt: Add /TP/GAW/CL/BI-23-C/auto test Luiz Augusto von Dentz
  2015-06-24 12:09 ` [PATCH BlueZ 01/11] shared/att: Auto retry if request fails Luiz Augusto von Dentz
  10 siblings, 0 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2015-06-23 12:53 UTC (permalink / raw)
  To: linux-bluetooth

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

/TP/GAW/CL/BI-18-C/auto is similar to /TP/GAW/CL/BI-18-C but
automatically elevates the security level and retry.
---
 unit/test-gatt.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 6df6342..82b6576 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -3943,6 +3943,16 @@ int main(int argc, char *argv[])
 			raw_pdu(0x18, 0x00),
 			raw_pdu(0x19));
 
+	define_test_client("/TP/GAW/CL/BI-18-C/auto", test_client, service_db_1,
+			&test_reliable_write_1,
+			SERVICE_DATA_1_PDUS,
+			raw_pdu(0x16, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03),
+			raw_pdu(0x01, 0x16, 0x07, 0x00, 0x05),
+			raw_pdu(0x16, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03),
+			raw_pdu(0x17, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03),
+			raw_pdu(0x18, 0x01),
+			raw_pdu(0x19));
+
 	define_test_client("/TP/GAW/CL/BI-19-C", test_client, service_db_1,
 			&test_reliable_write_6,
 			SERVICE_DATA_1_PDUS,
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH BlueZ 11/11] unit/test-gatt: Add /TP/GAW/CL/BI-23-C/auto test
  2015-06-23 12:53 [PATCH BlueZ 01/11] shared/att: Auto retry if request fails Luiz Augusto von Dentz
                   ` (8 preceding siblings ...)
  2015-06-23 12:53 ` [PATCH BlueZ 10/11] unit/test-gatt: Add /TP/GAW/CL/BI-18-C/auto test Luiz Augusto von Dentz
@ 2015-06-23 12:53 ` Luiz Augusto von Dentz
  2015-06-24 12:09 ` [PATCH BlueZ 01/11] shared/att: Auto retry if request fails Luiz Augusto von Dentz
  10 siblings, 0 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2015-06-23 12:53 UTC (permalink / raw)
  To: linux-bluetooth

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

/TP/GAW/CL/BI-23-C/auto is similar to /TP/GAW/CL/BI-23-C but
automatically elevates the security level and retry.
---
 unit/test-gatt.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 82b6576..326a32c 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -4059,6 +4059,14 @@ int main(int argc, char *argv[])
 			raw_pdu(0x12, 0x08, 0x00, 0x01, 0x02, 0x03),
 			raw_pdu(0x01, 0x12, 0x08, 0x00, 0x05));
 
+	define_test_client("/TP/GAW/CL/BI-23-C/auto", test_client, service_db_1,
+			&test_write_7,
+			SERVICE_DATA_1_PDUS,
+			raw_pdu(0x12, 0x08, 0x00, 0x01, 0x02, 0x03),
+			raw_pdu(0x01, 0x12, 0x08, 0x00, 0x05),
+			raw_pdu(0x12, 0x08, 0x00, 0x01, 0x02, 0x03),
+			raw_pdu(0x13));
+
 	define_test_client("/TP/GAW/CL/BI-24-C", test_client, service_db_1,
 			&test_write_12,
 			SERVICE_DATA_1_PDUS,
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH BlueZ 01/11] shared/att: Auto retry if request fails
  2015-06-23 12:53 [PATCH BlueZ 01/11] shared/att: Auto retry if request fails Luiz Augusto von Dentz
                   ` (9 preceding siblings ...)
  2015-06-23 12:53 ` [PATCH BlueZ 11/11] unit/test-gatt: Add /TP/GAW/CL/BI-23-C/auto test Luiz Augusto von Dentz
@ 2015-06-24 12:09 ` Luiz Augusto von Dentz
  10 siblings, 0 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2015-06-24 12:09 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

On Tue, Jun 23, 2015 at 3:53 PM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> This adds auto retry logic to requests when a security error happen,
> it will first attempt to elevate the security to match the requirement
> and then retry sending the request once again.
> ---
>  src/shared/att.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 54 insertions(+), 4 deletions(-)
>
> diff --git a/src/shared/att.c b/src/shared/att.c
> index f9a5817..e8be4cc 100644
> --- a/src/shared/att.c
> +++ b/src/shared/att.c
> @@ -576,6 +576,55 @@ static bool disconnect_cb(struct io *io, void *user_data)
>         return false;
>  }
>
> +static bool change_security(struct bt_att *att, uint8_t ecode)
> +{
> +       int security;
> +
> +       security = bt_att_get_security(att);
> +       if (ecode == BT_ATT_ERROR_INSUFFICIENT_ENCRYPTION &&
> +                                       security < BT_ATT_SECURITY_MEDIUM)
> +               security = BT_ATT_SECURITY_MEDIUM;
> +       else if (ecode == BT_ATT_ERROR_AUTHENTICATION &&
> +                                       security < BT_ATT_SECURITY_HIGH)
> +               security = BT_ATT_SECURITY_HIGH;
> +       else
> +               return false;
> +
> +       return bt_att_set_security(att, security);
> +}
> +
> +static bool handle_error_rsp(struct bt_att *att, uint8_t *pdu,
> +                                       ssize_t pdu_len, uint8_t *opcode)
> +{
> +       const struct bt_att_pdu_error_rsp *rsp;
> +       struct att_send_op *op = att->pending_req;
> +
> +       if (pdu_len != sizeof(*rsp)) {
> +               *opcode = 0;
> +               return false;
> +       }
> +
> +       rsp = (void *) pdu;
> +
> +       *opcode = rsp->opcode;
> +
> +       /* Only try to change security on L2CAP */
> +       if (!att->io_on_l2cap)
> +               return false;
> +
> +       /* Attempt to change security */
> +       if (!change_security(att, rsp->ecode))
> +               return false;
> +
> +       util_debug(att->debug_callback, att->debug_data,
> +                                               "Retrying operation %p", op);
> +
> +       att->pending_req = NULL;
> +
> +       /* Push operation back to request queue */
> +       return queue_push_head(att->req_queue, op);
> +}
> +
>  static void handle_rsp(struct bt_att *att, uint8_t opcode, uint8_t *pdu,
>                                                                 ssize_t pdu_len)
>  {
> @@ -601,10 +650,11 @@ static void handle_rsp(struct bt_att *att, uint8_t opcode, uint8_t *pdu,
>          * the request is malformed, end the current request with failure.
>          */
>         if (opcode == BT_ATT_OP_ERROR_RSP) {
> -               if (pdu_len != 4)
> -                       goto fail;
> -
> -               req_opcode = pdu[0];
> +               /* Return if error response cause a retry */
> +               if (handle_error_rsp(att, pdu, pdu_len, &req_opcode)) {
> +                       wakeup_writer(att);
> +                       return;
> +               }
>         } else if (!(req_opcode = get_req_opcode(opcode)))
>                 goto fail;
>
> --
> 2.1.0

Applied.


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-06-24 12:09 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-23 12:53 [PATCH BlueZ 01/11] shared/att: Auto retry if request fails Luiz Augusto von Dentz
2015-06-23 12:53 ` [PATCH BlueZ 02/11] shared/att: Add BT_ATT_SECURITY_AUTO Luiz Augusto von Dentz
2015-06-23 12:53 ` [PATCH BlueZ 03/11] unit/test-gatt: Use auto security Luiz Augusto von Dentz
2015-06-23 12:53 ` [PATCH BlueZ 04/11] unit/test-gatt: Add /TP/GAR/CL/BI-04-C/auto test Luiz Augusto von Dentz
2015-06-23 12:53 ` [PATCH BlueZ 05/11] unit/test-gatt: Add /TP/GAR/CL/BI-16-C/auto test Luiz Augusto von Dentz
2015-06-23 12:53 ` [PATCH BlueZ 06/11] unit/test-gatt: Add /TP/GAR/CL/BI-21-C/auto test Luiz Augusto von Dentz
2015-06-23 12:53 ` [PATCH BlueZ 07/11] unit/test-gatt: Add /TP/GAR/CL/BI-26-C/auto test Luiz Augusto von Dentz
2015-06-23 12:53 ` [PATCH BlueZ 08/11] unit/test-gatt: Add /TP/GAR/CL/BI-32-C/auto test Luiz Augusto von Dentz
2015-06-23 12:53 ` [PATCH BlueZ 09/11] unit/test-gatt: Add /TP/GAW/CL/BI-05-C/auto test Luiz Augusto von Dentz
2015-06-23 12:53 ` [PATCH BlueZ 10/11] unit/test-gatt: Add /TP/GAW/CL/BI-18-C/auto test Luiz Augusto von Dentz
2015-06-23 12:53 ` [PATCH BlueZ 11/11] unit/test-gatt: Add /TP/GAW/CL/BI-23-C/auto test Luiz Augusto von Dentz
2015-06-24 12:09 ` [PATCH BlueZ 01/11] shared/att: Auto retry if request fails Luiz Augusto von Dentz

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.