Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCHv3 1/4] android/hal-msg: Add defines of HAL_GATT_AUTHENTICATION values
@ 2014-06-18  9:08 Marcin Kraglak
  2014-06-18  9:08 ` [PATCHv3 2/4] android/gatt: Set security level if user requested Marcin Kraglak
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Marcin Kraglak @ 2014-06-18  9:08 UTC (permalink / raw)
  To: linux-bluetooth

These values are are used in read characteristic/write characteristic
functions in gatt_client.
---
 android/hal-msg.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/android/hal-msg.h b/android/hal-msg.h
index 2c21a85..57872c6 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -1610,3 +1610,7 @@ struct hal_ev_gatt_server_rsp_confirmation {
 #define HAL_GATT_PERMISSION_WRITE_ENCRYPTED_MITM	0x0040
 #define HAL_GATT_PERMISSION_WRITE_SIGNED		0x0080
 #define HAL_GATT_PERMISSION_WRITE_SIGNED_MITM		0x0100
+
+#define HAL_GATT_AUTHENTICATION_NONE		0
+#define HAL_GATT_AUTHENTICATION_NO_MITM		1
+#define HAL_GATT_AUTHENTICATION_MITM		2
-- 
1.9.3


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

* [PATCHv3 2/4] android/gatt: Set security level if user requested
  2014-06-18  9:08 [PATCHv3 1/4] android/hal-msg: Add defines of HAL_GATT_AUTHENTICATION values Marcin Kraglak
@ 2014-06-18  9:08 ` Marcin Kraglak
  2014-06-18  9:08 ` [PATCHv3 3/4] android/gatt:Add test command to increase security on link Marcin Kraglak
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Marcin Kraglak @ 2014-06-18  9:08 UTC (permalink / raw)
  To: linux-bluetooth

Set security level if user requested. It is used when frameworks receives
INSUFFICIENT_ENCRYPTION or INSUFFICIENT_AUTHENTICATIONS errors on read/write
requests and tries to elevate security.
---
 android/gatt.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/android/gatt.c b/android/gatt.c
index b256077..4540e95 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -2731,6 +2731,49 @@ static int get_sec_level(struct gatt_device *dev)
 	return sec_level;
 }
 
+static bool set_security(struct gatt_device *device, int auth_type)
+{
+	int req_sec_level, sec_level;
+	GError *gerr = NULL;
+	GIOChannel *io;
+
+	switch (auth_type) {
+	case HAL_GATT_AUTHENTICATION_MITM:
+		req_sec_level = BT_SECURITY_HIGH;
+		break;
+	case HAL_GATT_AUTHENTICATION_NO_MITM:
+		req_sec_level = BT_SECURITY_MEDIUM;
+		break;
+	case HAL_GATT_AUTHENTICATION_NONE:
+		req_sec_level = BT_SECURITY_LOW;
+		break;
+	default:
+		error("gatt: Invalid auth_type value: %d", auth_type);
+		return false;
+	}
+
+	sec_level = get_sec_level(device);
+	if (sec_level < 0)
+		return false;
+
+	if (req_sec_level <= sec_level)
+		return true;
+
+	io = g_attrib_get_channel(device->attrib);
+	if (!io)
+		return false;
+
+	bt_io_set(io, &gerr, BT_IO_OPT_SEC_LEVEL, req_sec_level,
+							BT_IO_OPT_INVALID);
+	if (gerr) {
+		error("%s\n", gerr->message);
+		g_error_free(gerr);
+		return false;
+	}
+
+	return true;
+}
+
 static void handle_client_read_characteristic(const void *buf, uint16_t len)
 {
 	const struct hal_cmd_gatt_client_read_characteristic *cmd = buf;
@@ -2771,6 +2814,13 @@ static void handle_client_read_characteristic(const void *buf, uint16_t len)
 		goto failed;
 	}
 
+	if (!set_security(conn->device, cmd->auth_req)) {
+		error("gatt: Failed to set security %d", cmd->auth_req);
+		status = HAL_STATUS_FAILED;
+		free(cb_data);
+		goto failed;
+	}
+
 	if (!gatt_read_char(conn->device->attrib, ch->ch.value_handle,
 						read_char_cb, cb_data)) {
 		error("gatt: Cannot read characteristic with inst_id: %d",
@@ -2898,6 +2948,12 @@ static void handle_client_write_characteristic(const void *buf, uint16_t len)
 		}
 	}
 
+	if (!set_security(conn->device, cmd->auth_req)) {
+		error("gatt: Failed to set security %d", cmd->auth_req);
+		status = HAL_STATUS_FAILED;
+		goto failed;
+	}
+
 	switch (cmd->write_type) {
 	case GATT_WRITE_TYPE_NO_RESPONSE:
 		res = gatt_write_cmd(conn->device->attrib, ch->ch.value_handle,
@@ -3099,6 +3155,13 @@ static void handle_client_read_descriptor(const void *buf, uint16_t len)
 		goto failed;
 	}
 
+	if (!set_security(conn->device, cmd->auth_req)) {
+		error("gatt: Failed to set security %d", cmd->auth_req);
+		status = HAL_STATUS_FAILED;
+		free(cb_data);
+		goto failed;
+	}
+
 	if (!gatt_read_char(conn->device->attrib, descr->handle, read_desc_cb,
 								cb_data)) {
 		free(cb_data);
@@ -3224,6 +3287,12 @@ static void handle_client_write_descriptor(const void *buf, uint16_t len)
 		}
 	}
 
+	if (!set_security(conn->device, cmd->auth_req)) {
+		error("gatt: Failed to set security %d", cmd->auth_req);
+		status = HAL_STATUS_FAILED;
+		goto failed;
+	}
+
 	switch (cmd->write_type) {
 	case GATT_WRITE_TYPE_NO_RESPONSE:
 		res = gatt_write_cmd(conn->device->attrib, descr->handle,
-- 
1.9.3


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

* [PATCHv3 3/4] android/gatt:Add test command to increase security on link
  2014-06-18  9:08 [PATCHv3 1/4] android/hal-msg: Add defines of HAL_GATT_AUTHENTICATION values Marcin Kraglak
  2014-06-18  9:08 ` [PATCHv3 2/4] android/gatt: Set security level if user requested Marcin Kraglak
@ 2014-06-18  9:08 ` Marcin Kraglak
  2014-06-18  9:08 ` [PATCHv3 4/4] android/pts: Update PTS GAP results Marcin Kraglak
  2014-06-18 13:36 ` [PATCHv3 1/4] android/hal-msg: Add defines of HAL_GATT_AUTHENTICATION values Szymon Janc
  3 siblings, 0 replies; 5+ messages in thread
From: Marcin Kraglak @ 2014-06-18  9:08 UTC (permalink / raw)
  To: linux-bluetooth

---
 android/gatt.c    | 17 +++++++++++++++++
 android/hal-msg.h |  1 +
 2 files changed, 18 insertions(+)

diff --git a/android/gatt.c b/android/gatt.c
index 4540e95..814dc50 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -3762,6 +3762,20 @@ static uint8_t test_read_write(bdaddr_t *bdaddr, bt_uuid_t *uuid, uint16_t op,
 	return HAL_STATUS_SUCCESS;
 }
 
+static uint8_t test_increase_security(bdaddr_t *bdaddr, uint16_t u1)
+{
+	struct gatt_device *device;
+
+	device = find_device_by_addr(bdaddr);
+	if (!device)
+		return HAL_STATUS_FAILED;
+
+	if (!set_security(device, u1))
+		return HAL_STATUS_FAILED;
+
+	return HAL_STATUS_SUCCESS;
+}
+
 static void handle_client_test_command(const void *buf, uint16_t len)
 {
 	const struct hal_cmd_gatt_client_test_command *cmd = buf;
@@ -3813,6 +3827,9 @@ static void handle_client_test_command(const void *buf, uint16_t len)
 		status = test_read_write(&bdaddr, &uuid, cmd->u1, cmd->u2,
 						cmd->u3, cmd->u4, cmd->u5);
 		break;
+	case GATT_CLIENT_TEST_CMD_INCREASE_SECURITY:
+		status = test_increase_security(&bdaddr, cmd->u1);
+		break;
 	case GATT_CLIENT_TEST_CMD_PAIRING_CONFIG:
 	default:
 		status = HAL_STATUS_FAILED;
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 57872c6..af859c6 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -756,6 +756,7 @@ struct hal_cmd_gatt_client_set_adv_data {
 #define GATT_CLIENT_TEST_CMD_DISCOVER		0x04
 #define GATT_CLIENT_TEST_CMD_READ		0xe0
 #define GATT_CLIENT_TEST_CMD_WRITE		0xe1
+#define GATT_CLIENT_TEST_CMD_INCREASE_SECURITY	0xe2
 #define GATT_CLIENT_TEST_CMD_PAIRING_CONFIG	0xf0
 
 #define HAL_OP_GATT_CLIENT_TEST_COMMAND		0x16
-- 
1.9.3


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

* [PATCHv3 4/4] android/pts: Update PTS GAP results
  2014-06-18  9:08 [PATCHv3 1/4] android/hal-msg: Add defines of HAL_GATT_AUTHENTICATION values Marcin Kraglak
  2014-06-18  9:08 ` [PATCHv3 2/4] android/gatt: Set security level if user requested Marcin Kraglak
  2014-06-18  9:08 ` [PATCHv3 3/4] android/gatt:Add test command to increase security on link Marcin Kraglak
@ 2014-06-18  9:08 ` Marcin Kraglak
  2014-06-18 13:36 ` [PATCHv3 1/4] android/hal-msg: Add defines of HAL_GATT_AUTHENTICATION values Szymon Janc
  3 siblings, 0 replies; 5+ messages in thread
From: Marcin Kraglak @ 2014-06-18  9:08 UTC (permalink / raw)
  To: linux-bluetooth

---
 android/pts-gap.txt | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/android/pts-gap.txt b/android/pts-gap.txt
index bb943af..e09f73d 100644
--- a/android/pts-gap.txt
+++ b/android/pts-gap.txt
@@ -222,7 +222,10 @@ TC_SEC_AUT_BV_21_C	PASS	haltest: gattc register_client
 				gattc connect
 				bluetooth create_bond
 				gattc connect
-TC_SEC_AUT_BV_22_C	INC	Link security level elevation - not implemented
+TC_SEC_AUT_BV_22_C	PASS	btmgmt io-cap 3
+				haltest: gattc register_client
+				gattc listen
+				gattc test_command 226 <addr> <u1> 1
 TC_SEC_AUT_BV_23_C	PASS	haltest: gatts register_server
 				gatts add_service 2 <uuid> 3
 				gatts add_characteristic 2 <service_handle>
@@ -273,8 +276,25 @@ TC_SEC_CSIGN_BI_02_C	PASS	haltest:
 				gatts start_service
 				gatts disconnect
 				gattc disconnect
-TC_SEC_CSIGN_BI_03_C	INC	Link security level elevation - not implemented
-TC_SEC_CSIGN_BI_04_C	INC	Link security level elevation - not implemented
+TC_SEC_CSIGN_BI_03_C	PASS	haltest:
+				gatts add_service
+				gatts add_characteristic:
+						<properties> 64
+						<permissions> 128
+				gatts start_service
+				gattc listen
+				bluetooth ssp_reply
+				gatts disconnect
+				bluetooth remove_bond
+TC_SEC_CSIGN_BI_04_C	PASS	haltest:
+				gatts add_service
+				gatts add_characteristic:
+						<properties> 64
+						<permissions> 256
+				gatts start_service
+				gattc listen
+				bluetooth ssp_reply
+				gatts disconnect
 TC_PRIV_CONN_BV_01_C	INC	Privacy feature - not implemented
 TC_PRIV_CONN_BV_02_C	INC	Privacy feature - not implemented
 TC_PRIV_CONN_BV_03_C	INC	Privacy feature - not implemented
-- 
1.9.3


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

* Re: [PATCHv3 1/4] android/hal-msg: Add defines of HAL_GATT_AUTHENTICATION values
  2014-06-18  9:08 [PATCHv3 1/4] android/hal-msg: Add defines of HAL_GATT_AUTHENTICATION values Marcin Kraglak
                   ` (2 preceding siblings ...)
  2014-06-18  9:08 ` [PATCHv3 4/4] android/pts: Update PTS GAP results Marcin Kraglak
@ 2014-06-18 13:36 ` Szymon Janc
  3 siblings, 0 replies; 5+ messages in thread
From: Szymon Janc @ 2014-06-18 13:36 UTC (permalink / raw)
  To: Marcin Kraglak; +Cc: linux-bluetooth

Hi Marcin,

On Wednesday 18 of June 2014 11:08:16 Marcin Kraglak wrote:
> These values are are used in read characteristic/write characteristic
> functions in gatt_client.
> ---
>  android/hal-msg.h | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/android/hal-msg.h b/android/hal-msg.h
> index 2c21a85..57872c6 100644
> --- a/android/hal-msg.h
> +++ b/android/hal-msg.h
> @@ -1610,3 +1610,7 @@ struct hal_ev_gatt_server_rsp_confirmation {
>  #define HAL_GATT_PERMISSION_WRITE_ENCRYPTED_MITM	0x0040
>  #define HAL_GATT_PERMISSION_WRITE_SIGNED		0x0080
>  #define HAL_GATT_PERMISSION_WRITE_SIGNED_MITM		0x0100
> +
> +#define HAL_GATT_AUTHENTICATION_NONE		0
> +#define HAL_GATT_AUTHENTICATION_NO_MITM		1
> +#define HAL_GATT_AUTHENTICATION_MITM		2
> 

All patches applied, thanks.

-- 
Best regards, 
Szymon Janc

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

end of thread, other threads:[~2014-06-18 13:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-18  9:08 [PATCHv3 1/4] android/hal-msg: Add defines of HAL_GATT_AUTHENTICATION values Marcin Kraglak
2014-06-18  9:08 ` [PATCHv3 2/4] android/gatt: Set security level if user requested Marcin Kraglak
2014-06-18  9:08 ` [PATCHv3 3/4] android/gatt:Add test command to increase security on link Marcin Kraglak
2014-06-18  9:08 ` [PATCHv3 4/4] android/pts: Update PTS GAP results Marcin Kraglak
2014-06-18 13:36 ` [PATCHv3 1/4] android/hal-msg: Add defines of HAL_GATT_AUTHENTICATION values Szymon Janc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox