diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2005-04-16 15:54:26 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2005-04-16 15:54:26 +0000 |
commit | bbf5eef59916cd1230ef71dc7b9be055397b0074 (patch) | |
tree | d6898c5ceaf4a676643360eae4a871dde258e447 /hcid/security.c | |
parent | 828029f202d7a7116d663ee9b9465b60c1eac030 (diff) |
Add framework for read_link_key()
Diffstat (limited to 'hcid/security.c')
-rw-r--r-- | hcid/security.c | 26 |
1 files changed, 18 insertions, 8 deletions
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); } } |