Linux bluetooth development
 help / color / mirror / Atom feed
From: Lukasz Rymanowski <lukasz.rymanowski@tieto.com>
To: linux-bluetooth@vger.kernel.org
Cc: szymon.janc@tieto.com, johan.hedberg@gmail.com,
	Lukasz Rymanowski <lukasz.rymanowski@tieto.com>
Subject: [PATCH v3 04/12] android/bluetooth: Expose API to get CSRK for device
Date: Thu, 22 May 2014 21:06:18 +0200	[thread overview]
Message-ID: <1400785586-22710-5-git-send-email-lukasz.rymanowski@tieto.com> (raw)
In-Reply-To: <1400785586-22710-1-git-send-email-lukasz.rymanowski@tieto.com>

GATT will take CSRK key and sign counter each time it needs it to sign
att package or to verify att package
---
 android/bluetooth.c | 31 +++++++++++++++++++++++++++++++
 android/bluetooth.h |  8 ++++++++
 2 files changed, 39 insertions(+)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index 93b9cd7..644a556 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -116,6 +116,14 @@ struct device {
 
 	bool found; /* if device is found in current discovery session */
 	unsigned int confirm_id; /* mgtm command id if command pending */
+
+	bool valid_remote_csrk;
+	uint8_t remote_csrk[16];
+	uint32_t remote_sign_cnt;
+
+	bool valid_local_csrk;
+	uint8_t local_csrk[16];
+	uint32_t local_sign_cnt;
 };
 
 struct browse_req {
@@ -3200,6 +3208,29 @@ bool bt_read_device_rssi(const bdaddr_t *addr, bt_read_device_rssi_done cb,
 	return true;
 }
 
+bool bt_get_csrk(const bdaddr_t *addr, enum bt_csrk_type type, uint8_t key[16],
+							uint32_t *sign_cnt)
+{
+	struct device *dev;
+	bool local = (type == LOCAL_CSRK);
+
+	dev = find_device(addr);
+	if (!dev)
+		return false;
+
+	if (local && dev->valid_local_csrk) {
+		memcpy(key, dev->local_csrk, 16);
+		*sign_cnt = dev->local_sign_cnt;
+	} else if (!local && dev->valid_remote_csrk) {
+		memcpy(key, dev->remote_csrk, 16);
+		*sign_cnt = dev->remote_sign_cnt;
+	} else {
+		return false;
+	}
+
+	return true;
+}
+
 static uint8_t set_adapter_scan_mode(const void *buf, uint16_t len)
 {
 	const uint8_t *mode = buf;
diff --git a/android/bluetooth.h b/android/bluetooth.h
index a0b81a6..9c88f62 100644
--- a/android/bluetooth.h
+++ b/android/bluetooth.h
@@ -21,6 +21,11 @@
  *
  */
 
+enum bt_csrk_type {
+	LOCAL_CSRK,
+	REMOTE_CSRK,
+};
+
 typedef void (*bt_bluetooth_ready)(int err, const bdaddr_t *addr);
 bool bt_bluetooth_start(int index, bool mgmt_dbg, bt_bluetooth_ready cb);
 
@@ -56,3 +61,6 @@ typedef void (*bt_read_device_rssi_done)(uint8_t status, const bdaddr_t *addr,
 						int8_t rssi, void *user_data);
 bool bt_read_device_rssi(const bdaddr_t *addr, bt_read_device_rssi_done cb,
 							void *user_data);
+
+bool bt_get_csrk(const bdaddr_t *addr, enum bt_csrk_type type,
+					uint8_t key[16], uint32_t *sign_cnt);
-- 
1.8.4


  parent reply	other threads:[~2014-05-22 19:06 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-22 19:06 [PATCH v3 00/12] android/gatt: Add support for write signature command Lukasz Rymanowski
2014-05-22 19:06 ` [PATCH v3 01/12] shared/crypto: Extend bt_crypto_sign_att with sign counter Lukasz Rymanowski
2014-05-22 19:06 ` [PATCH v3 02/12] attrib: Add helpers to enc and dec signed write command Lukasz Rymanowski
2014-05-22 19:06 ` [PATCH v3 03/12] attrib/gatt: Add wrapper to send " Lukasz Rymanowski
2014-05-22 19:06 ` Lukasz Rymanowski [this message]
2014-05-22 19:06 ` [PATCH v3 05/12] android/bluetooth: Expose API to update sign counter Lukasz Rymanowski
2014-05-22 19:06 ` [PATCH v3 06/12] android/bluetooth: Add support to read CSRK from the kernel Lukasz Rymanowski
2014-05-22 19:06 ` [PATCH v3 07/12] android/bluetooth: Store CSRK Lukasz Rymanowski
2014-05-22 19:06 ` [PATCH v3 08/12] android/bluetooth: Read CSRK from the storage on startup Lukasz Rymanowski
2014-05-22 19:06 ` [PATCH v3 09/12] android/bluetooth: Store sign counter needed for aes-cmac sign Lukasz Rymanowski
2014-05-22 19:06 ` [PATCH v3 10/12] android/gatt: Add crypto needed for sign write Lukasz Rymanowski
2014-05-22 19:06 ` [PATCH v3 11/12] android/gatt: Add support for signed write command Lukasz Rymanowski
2014-05-22 19:06 ` [PATCH v3 12/12] android/gatt: Add handling signed write from remote device Lukasz Rymanowski
2014-05-26  8:41 ` [PATCH v3 00/12] android/gatt: Add support for write signature command Szymon Janc

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1400785586-22710-5-git-send-email-lukasz.rymanowski@tieto.com \
    --to=lukasz.rymanowski@tieto.com \
    --cc=johan.hedberg@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=szymon.janc@tieto.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox