summaryrefslogtreecommitdiffstats
path: root/hcid
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2005-04-16 15:54:26 +0000
committerMarcel Holtmann <marcel@holtmann.org>2005-04-16 15:54:26 +0000
commitbbf5eef59916cd1230ef71dc7b9be055397b0074 (patch)
treed6898c5ceaf4a676643360eae4a871dde258e447 /hcid
parent828029f202d7a7116d663ee9b9465b60c1eac030 (diff)
Add framework for read_link_key()
Diffstat (limited to 'hcid')
-rw-r--r--hcid/hcid.h1
-rw-r--r--hcid/security.c26
-rw-r--r--hcid/storage.c5
3 files changed, 24 insertions, 8 deletions
diff --git a/hcid/hcid.h b/hcid/hcid.h
index bcc43e4a..9c96d91a 100644
--- a/hcid/hcid.h
+++ b/hcid/hcid.h
@@ -112,3 +112,4 @@ gboolean hcid_dbus_init(void);
int write_device_name(const bdaddr_t *local, const bdaddr_t *peer, const char *name);
int write_link_key(const bdaddr_t *local, const bdaddr_t *peer, const unsigned char *key, const int type);
+int read_link_key(const bdaddr_t *local, const bdaddr_t *peer, unsigned char *key);
diff --git a/hcid/security.c b/hcid/security.c
index 92353373..e66e030e 100644
--- a/hcid/security.c
+++ b/hcid/security.c
@@ -114,23 +114,33 @@ static struct link_key *get_link_key(bdaddr_t *sba, bdaddr_t *dba)
static void link_key_request(int dev, bdaddr_t *sba, bdaddr_t *dba)
{
- struct link_key *key = get_link_key(sba, dba);
+ unsigned char key[16];
char sa[18], da[18];
+ int err;
ba2str(sba, sa); ba2str(dba, da);
syslog(LOG_INFO, "link_key_request (sba=%s, dba=%s)", sa, da);
- if (key) {
+ err = read_link_key(sba, dba, key);
+ if (err < 0) {
+ struct link_key *linkkey = get_link_key(sba, dba);
+ if (linkkey) {
+ memcpy(key, linkkey->key, 16);
+ linkkey->time = time(0);
+ err = 0;
+ }
+ }
+
+ if (err < 0) {
+ /* Link key not found */
+ hci_send_cmd(dev, OGF_LINK_CTL, OCF_LINK_KEY_NEG_REPLY, 6, dba);
+ } else {
/* Link key found */
link_key_reply_cp lr;
- memcpy(lr.link_key, key->key, 16);
+ memcpy(lr.link_key, key, 16);
bacpy(&lr.bdaddr, dba);
hci_send_cmd(dev, OGF_LINK_CTL, OCF_LINK_KEY_REPLY,
- LINK_KEY_REPLY_CP_SIZE, &lr);
- key->time = time(0);
- } else {
- /* Link key not found */
- hci_send_cmd(dev, OGF_LINK_CTL, OCF_LINK_KEY_NEG_REPLY, 6, dba);
+ LINK_KEY_REPLY_CP_SIZE, &lr);
}
}
diff --git a/hcid/storage.c b/hcid/storage.c
index a025e674..d38e6aef 100644
--- a/hcid/storage.c
+++ b/hcid/storage.c
@@ -220,3 +220,8 @@ int write_link_key(const bdaddr_t *local, const bdaddr_t *peer, const unsigned c
{
return 0;
}
+
+int read_link_key(const bdaddr_t *local, const bdaddr_t *peer, unsigned char *key)
+{
+ return -ENOENT;
+}