From c6fa51ccb4e16629e16e6f9fe7fe862aa9a12c8c Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 22 Jun 2015 11:04:23 +0300 Subject: [PATCH] shared/att: Add BT_ATT_SECURITY_AUTO 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 ee2099261..d474495db 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 e8be4cc2b..70f5d7220 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.47.3