summaryrefslogtreecommitdiff
path: root/attrib
diff options
context:
space:
mode:
authorLukasz Rymanowski <lukasz.rymanowski@tieto.com>2014-05-29 15:49:37 +0200
committerJohan Hedberg <johan.hedberg@intel.com>2014-05-30 13:26:14 +0300
commit514e224641d79b33cc2cf082dff55b311dfe6721 (patch)
treeec0c7667c6d0ce9745dfecd0ad9a6adc88da535b /attrib
parent26304dcc445016e00fd497e8d5e8c68979759eab (diff)
downloadbluez-514e224641d79b33cc2cf082dff55b311dfe6721.tar.gz
android/gatt: Fix signed write command encoding
As per spec (BT spec 4.1 Vol[3], Part F, chapter 3.4.5.4) we need to take opcode, handle and parameters to generate signature. In order to support it signing is moved to att.c, place where pdu is encoded
Diffstat (limited to 'attrib')
-rw-r--r--attrib/att.c11
-rw-r--r--attrib/att.h6
-rw-r--r--attrib/gatt.c11
-rw-r--r--attrib/gatt.h4
4 files changed, 23 insertions, 9 deletions
diff --git a/attrib/att.c b/attrib/att.c
index e7d568241..268045824 100644
--- a/attrib/att.c
+++ b/attrib/att.c
@@ -561,9 +561,10 @@ uint16_t dec_write_cmd(const uint8_t *pdu, size_t len, uint16_t *handle,
return len;
}
-uint16_t enc_signed_write_cmd(uint16_t handle,
- const uint8_t *value, size_t vlen,
- const uint8_t signature[12],
+uint16_t enc_signed_write_cmd(uint16_t handle, const uint8_t *value,
+ size_t vlen, struct bt_crypto *crypto,
+ const uint8_t csrk[16],
+ uint32_t sign_cnt,
uint8_t *pdu, size_t len)
{
const uint16_t hdr_len = sizeof(pdu[0]) + sizeof(handle);
@@ -581,7 +582,9 @@ uint16_t enc_signed_write_cmd(uint16_t handle,
if (vlen > 0)
memcpy(&pdu[hdr_len], value, vlen);
- memcpy(&pdu[hdr_len + vlen], signature, ATT_SIGNATURE_LEN);
+ if (!bt_crypto_sign_att(crypto, csrk, pdu, hdr_len + vlen, sign_cnt,
+ &pdu[hdr_len + vlen]))
+ return 0;
return min_len + vlen;
}
diff --git a/attrib/att.h b/attrib/att.h
index c92cd5d6e..2311aafb6 100644
--- a/attrib/att.h
+++ b/attrib/att.h
@@ -22,6 +22,8 @@
*
*/
+#include "src/shared/crypto.h"
+
/* Len of signature in write signed packet */
#define ATT_SIGNATURE_LEN 12
@@ -134,7 +136,9 @@ uint16_t dec_write_cmd(const uint8_t *pdu, size_t len, uint16_t *handle,
uint8_t *value, size_t *vlen);
uint16_t enc_signed_write_cmd(uint16_t handle,
const uint8_t *value, size_t vlen,
- const uint8_t signature[12],
+ struct bt_crypto *crypto,
+ const uint8_t csrk[16],
+ uint32_t sign_cnt,
uint8_t *pdu, size_t len);
uint16_t dec_signed_write_cmd(const uint8_t *pdu, size_t len,
uint16_t *handle,
diff --git a/attrib/gatt.c b/attrib/gatt.c
index ce0800361..27fb0b3ca 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -1067,7 +1067,9 @@ guint gatt_write_cmd(GAttrib *attrib, uint16_t handle, const uint8_t *value,
guint gatt_signed_write_cmd(GAttrib *attrib, uint16_t handle,
const uint8_t *value, int vlen,
- const uint8_t signature[12],
+ struct bt_crypto *crypto,
+ const uint8_t csrk[16],
+ uint32_t sign_cnt,
GDestroyNotify notify,
gpointer user_data)
{
@@ -1076,8 +1078,11 @@ guint gatt_signed_write_cmd(GAttrib *attrib, uint16_t handle,
guint16 plen;
buf = g_attrib_get_buffer(attrib, &buflen);
- plen = enc_signed_write_cmd(handle, value, vlen, signature, buf,
- buflen);
+ plen = enc_signed_write_cmd(handle, value, vlen, crypto, csrk, sign_cnt,
+ buf, buflen);
+ if (plen == 0)
+ return 0;
+
return g_attrib_send(attrib, 0, buf, plen, NULL, user_data, notify);
}
diff --git a/attrib/gatt.h b/attrib/gatt.h
index 2d869e3cd..f6db10fe3 100644
--- a/attrib/gatt.h
+++ b/attrib/gatt.h
@@ -107,7 +107,9 @@ guint gatt_write_cmd(GAttrib *attrib, uint16_t handle, const uint8_t *value,
guint gatt_signed_write_cmd(GAttrib *attrib, uint16_t handle,
const uint8_t *value, int vlen,
- const uint8_t signature[12],
+ struct bt_crypto *crypto,
+ const uint8_t csrk[16],
+ uint32_t sign_cnt,
GDestroyNotify notify,
gpointer user_data);
guint gatt_read_char_by_uuid(GAttrib *attrib, uint16_t start, uint16_t end,