Diff between 205746176acee3cbecabd5932270ec75f732c2ff and 242993bf71d7d5a6b95b909943ebb15db62454b6

Changed Files

File Additions Deletions Status
src/shared/gatt-client.c +12 -4 modified

Full Patch

diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index cc972d6..008bd3e 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -2125,6 +2125,8 @@ unsigned int bt_gatt_client_write_without_response(
 					const uint8_t *value, uint16_t length) {
 	uint8_t pdu[2 + length];
 	struct request *req;
+	int security;
+	uint8_t op;
 
 	if (!client)
 		return 0;
@@ -2133,13 +2135,19 @@ unsigned int bt_gatt_client_write_without_response(
 	if (!req)
 		return 0;
 
+	/* Only use signed write if unencrypted */
+	if (signed_write) {
+		security = bt_att_get_sec_level(client->att);
+		op = security > BT_SECURITY_LOW ?  BT_ATT_OP_WRITE_CMD :
+						BT_ATT_OP_SIGNED_WRITE_CMD;
+	} else
+		op = BT_ATT_OP_WRITE_CMD;
+
 	put_le16(value_handle, pdu);
 	memcpy(pdu + 2, value, length);
 
-	req->att_id = bt_att_send(client->att,
-				signed_write ?  BT_ATT_OP_SIGNED_WRITE_CMD :
-				BT_ATT_OP_WRITE_CMD, pdu, sizeof(pdu),
-				NULL, req, request_unref);
+	req->att_id = bt_att_send(client->att, op, pdu, sizeof(pdu), NULL, req,
+								request_unref);
 	if (!req->att_id) {
 		request_unref(req);
 		return 0;