[PATCH v2 11/12] android/gatt: Add support for signed write command

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

 



---
 android/gatt.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/android/gatt.c b/android/gatt.c
index 90f52f4..e36042a 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -2528,6 +2528,38 @@ static void write_char_cb(guint8 status, const guint8 *pdu, guint16 len,
 	free(data);
 }
 
+static bool signed_write_cmd(struct gatt_device *dev, uint16_t handle,
+					const uint8_t *value, uint16_t vlen)
+{
+	uint8_t s[ATT_SIGNATURE_LEN];
+	uint8_t csrk[16];
+	uint32_t sign_cnt;
+
+	memset(csrk, 0, 16);
+
+	if (!bt_get_csrk(&dev->bdaddr, LOCAL_CSRK, csrk, &sign_cnt)) {
+		error("gatt: Could not get csrk key");
+		return false;
+	}
+
+	memset(s, 0, ATT_SIGNATURE_LEN);
+
+	if (!bt_crypto_sign_att(crypto, csrk, value, vlen, sign_cnt, s)) {
+		error("gatt: Could not sign att data");
+		return false;
+	}
+
+	if (!gatt_signed_write_cmd(dev->attrib, handle, value, vlen, s, NULL,
+									NULL)) {
+		error("gatt: Could write signed cmd");
+		return false;
+	}
+
+	bt_update_sign_counter(&dev->bdaddr, LOCAL_CSRK);
+
+	return true;
+}
+
 static void handle_client_write_characteristic(const void *buf, uint16_t len)
 {
 	const struct hal_cmd_gatt_client_write_characteristic *cmd = buf;
@@ -2592,6 +2624,10 @@ static void handle_client_write_characteristic(const void *buf, uint16_t len)
 							cmd->value, cmd->len,
 							write_char_cb, cb_data);
 		break;
+	case GATT_WRITE_TYPE_SIGNED:
+		res = signed_write_cmd(conn->device, ch->ch.value_handle,
+					cmd->value, cmd->len);
+		break;
 	default:
 		error("gatt: Write type %d unsupported", cmd->write_type);
 		status = HAL_STATUS_UNSUPPORTED;
-- 
1.8.4

--
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