From: Marcel Holtmann <marcel@holtmann.org>
To: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH v2 3/7] Bluetooth: Use the updated key structures for handling LTKs
Date: Thu, 02 Feb 2012 16:23:22 -0800 [thread overview]
Message-ID: <1328228602.2062.21.camel@aeonflux> (raw)
In-Reply-To: <1328227685-27245-4-git-send-email-vinicius.gomes@openbossa.org>
Hi Vinicius,
> This updates all the users of the older way, that was using the
> link_keys list to store the SMP keys, to use the new way.
>
> This includes defining new types for the keys, we have a type for each
> combination of STK/LTK and Master/Slave.
>
> Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
> ---
> include/net/bluetooth/hci_core.h | 11 +++--
> net/bluetooth/hci_core.c | 76 ++++++++++++++++---------------------
> net/bluetooth/hci_event.c | 11 ++++-
> net/bluetooth/smp.c | 38 +++++++++++-------
> 4 files changed, 71 insertions(+), 65 deletions(-)
>
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index c998176..3f22f03 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -658,12 +658,13 @@ int hci_link_keys_clear(struct hci_dev *hdev);
> struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
> int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key,
> bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len);
> -struct link_key *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8]);
> -struct link_key *hci_find_link_key_type(struct hci_dev *hdev,
> - bdaddr_t *bdaddr, u8 type);
> +struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8]);
> +int hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type, u8 type,
> + int new_key, u8 authenticated, u8 tk[16],
> + u8 enc_size, u16 ediv, u8 rand[8]);
> +struct smp_ltk *hci_find_ltk_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
> + u8 addr_type);
> int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr);
> -int hci_add_ltk(struct hci_dev *hdev, int new_key, bdaddr_t *bdaddr,
> - u8 key_size, __le16 ediv, u8 rand[8], u8 ltk[16]);
> int hci_smp_ltks_clear(struct hci_dev *hdev);
> int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
>
> diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> index a28e637..ff519b5 100644
> --- a/net/bluetooth/hci_core.c
> +++ b/net/bluetooth/hci_core.c
> @@ -1222,41 +1222,35 @@ static int hci_persistent_key(struct hci_dev *hdev, struct hci_conn *conn,
> return 0;
> }
>
> -struct link_key *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8])
> +struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8])
> {
> - struct link_key *k;
> -
> - list_for_each_entry(k, &hdev->link_keys, list) {
> - struct key_master_id *id;
> + struct smp_ltk *k;
>
> - if (k->type != HCI_LK_SMP_LTK)
> + list_for_each_entry(k, &hdev->long_term_keys, list) {
> + if (k->ediv != ediv ||
> + memcmp(rand, k->rand, sizeof(k->rand)))
> continue;
>
> - if (k->dlen != sizeof(*id))
> - continue;
> -
> - id = (void *) &k->data;
> - if (id->ediv == ediv &&
> - (memcmp(rand, id->rand, sizeof(id->rand)) == 0))
> - return k;
> + return k;
> }
>
> return NULL;
> }
> EXPORT_SYMBOL(hci_find_ltk);
>
> -struct link_key *hci_find_link_key_type(struct hci_dev *hdev,
> - bdaddr_t *bdaddr, u8 type)
> +struct smp_ltk *hci_find_ltk_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
> + u8 addr_type)
minor nitpick with naming here. It should be find_ltk_by_addr. That way
it is consistent with similar calls in the Bluetooth subsystem.
Also in theory we might be better using "lookup" than "find", but you
can fix that one later one. Otherwise this looks fine.
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Regards
Marcel
next prev parent reply other threads:[~2012-02-03 0:23 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-03 0:07 [PATCH v2 0/7] New MGMT messages for SMP Long Term Keys Vinicius Costa Gomes
2012-02-03 0:07 ` [PATCH v2 1/7] Bluetooth: Fix doing some useless casts when receiving MGMT commands Vinicius Costa Gomes
2012-02-03 0:20 ` Marcel Holtmann
2012-02-03 0:08 ` [PATCH v2 2/7] Bluetooth: Add new structures for handling SMP Long Term Keys Vinicius Costa Gomes
2012-02-03 0:08 ` [PATCH v2 3/7] Bluetooth: Use the updated key structures for handling LTKs Vinicius Costa Gomes
2012-02-03 0:23 ` Marcel Holtmann [this message]
2012-02-03 0:08 ` [PATCH v2 4/7] Bluetooth: Add MGMT handlers for dealing with SMP LTK's Vinicius Costa Gomes
2012-02-03 0:24 ` Marcel Holtmann
2012-02-03 0:08 ` [PATCH v2 5/7] Bluetooth: Add support for removing LTK's when pairing is removed Vinicius Costa Gomes
2012-02-03 0:08 ` [PATCH v2 6/7] Bluetooth: Clean up structures left unused Vinicius Costa Gomes
2012-02-03 0:08 ` [PATCH v2 7/7] Bluetooth: Add support for notifying userspace of new LTK's Vinicius Costa Gomes
2012-02-03 1:25 ` [PATCH v2 0/7] New MGMT messages for SMP Long Term Keys Johan Hedberg
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=1328228602.2062.21.camel@aeonflux \
--to=marcel@holtmann.org \
--cc=linux-bluetooth@vger.kernel.org \
--cc=vinicius.gomes@openbossa.org \
/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;
as well as URLs for NNTP newsgroup(s).