Bluetooth: Fix initiator/responder addresses for SMP
Subsystems (2)
cover Bluetooth: Fix initiator/responder addresses for SMP
Hi,
I'm presenting this patch set as an alternative to the two patches from Marcel. The main difference is that we trade some more complexity during the connection creation phase with less complexity in looking up the values in SMP when the time comes for calling the smp_c1 function.
One source of extra complexity is the attempt to handle the case of whitelist initiated connections. Since we do not use those I'm not completely sure it's worth to have code for it. If the handling is not needed patch 3/4 gets a bit simpler and patch 2/4 can potentially be dropped (I added that new function mainly to make 3/4 actually readable with this extra whitelist handling logic).
Johan
----------------------------------------------------------------
Johan Hedberg (4):
Bluetooth: Add tracking of advertising address type
Bluetooth: Add hci_copy_identity_address convenience function
Bluetooth: Track LE initiator and responder address information
Bluetooth: Use hdev->init/resp_addr values for smp_c1 function
include/net/bluetooth/hci_core.h | 7 +++ net/bluetooth/hci_core.c | 35 ++++++++--- net/bluetooth/hci_event.c | 114 ++++++++++++++++++++++++++++++----- net/bluetooth/smp.c | 22 ++----- 4 files changed, 136 insertions(+), 42 deletions(-)
PATCH 1/4 Bluetooth: Add tracking of advertising address type
From: Johan Hedberg <[email protected]>
To know the real source address for incoming connections (needed e.g. for SMP) we should store the own_address_type parameter that was used for the last HCI_LE_Write_Advertising_Parameters command. This patch adds a proper command complete handler for the command and stores the address type in a new adv_addr_type variable in the hci_dev struct.
--- include/net/bluetooth/hci_core.h | 1 + net/bluetooth/hci_event.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+)
include/net/bluetooth/hci_core.h +1 -0
@@ -156,6 +156,7 @@ struct hci_dev {bdaddr_t bdaddr;bdaddr_t random_addr;bdaddr_t static_addr; +__u8 adv_addr_type;__u8 dev_name[HCI_MAX_NAME_LENGTH ];__u8 short_name[HCI_MAX_SHORT_NAME_LENGTH ];__u8 eir[HCI_MAX_EIR_LENGTH ];
net/bluetooth/hci_event.c +23 -0
@@ -1078,6 +1078,25 @@ static void hci_cc_write_le_host_supported(struct hci_dev *hdev, } } +static void hci_cc_set_adv_param (struct hci_dev *hdev,struct sk_buff *skb) +{ +struct hci_cp_le_set_adv_param *cp; +u8 status = *((u8 *) skb->data); + +BT_DBG ("%s status 0x%2.2x" , hdev->name, status); + +if (status) +return ; + + cp =hci_sent_cmd_data (hdev,HCI_OP_LE_SET_ADV_PARAM ); +if (!cp) +return ; + +hci_dev_lock (hdev); + hdev->adv_addr_type = cp->own_address_type; +hci_dev_unlock (hdev); +} +static void hci_cc_write_remote_amp_assoc (struct hci_dev *hdev,struct sk_buff *skb) {
@@ -2367,6 +2386,10 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)hci_cc_write_le_host_supported (hdev, skb);break ; +case HCI_OP_LE_SET_ADV_PARAM : +hci_cc_set_adv_param (hdev, skb); +break ; +case HCI_OP_WRITE_REMOTE_AMP_ASSOC :hci_cc_write_remote_amp_assoc (hdev, skb);break ;
Signature · 1 line
1.8.5.3
PATCH 2/4 Bluetooth: Add hci_copy_identity_address convenience function
In reply to [email protected]From: Johan Hedberg <[email protected]>
The number of places needing the local Identity Address are starting to grow so it's better to have a single place for the logic of determining it. This patch adds a convenience function for getting the Identity Address and updates the two current places needing this to use it.
--- include/net/bluetooth/hci_core.h | 2 ++ net/bluetooth/hci_core.c | 35 +++++++++++++++++++++++++---------- net/bluetooth/hci_event.c | 17 +---------------- 3 files changed, 28 insertions(+), 26 deletions(-)
include/net/bluetooth/hci_core.h +2 -0
@@ -1292,6 +1292,8 @@ void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __u8 rand[8],int hci_update_random_address (struct hci_request *req,bool require_privacy,u8 *own_addr_type); +void hci_copy_identity_address (struct hci_dev *hdev,bdaddr_t *bdaddr, +u8 *bdaddr_type);#define SCO_AIRMODE_MASK 0x0003#define SCO_AIRMODE_CVSD 0x0000
net/bluetooth/hci_core.c +25 -10
@@ -582,21 +582,14 @@ DEFINE_SIMPLE_ATTRIBUTE(sniff_max_interval_fops, sniff_max_interval_get,static int identity_show (struct seq_file *f,void *p) {struct hci_dev *hdev = f->private; -bdaddr_t *addr; +bdaddr_t addr;u8 addr_type;hci_dev_lock (hdev); -if (test_bit (HCI_FORCE_STATIC_ADDR , &hdev->dev_flags) || - !bacmp (&hdev->bdaddr,BDADDR_ANY )) { - addr = &hdev->static_addr; - addr_type =ADDR_LE_DEV_RANDOM ; - }else { - addr = &hdev->bdaddr; - addr_type =ADDR_LE_DEV_PUBLIC ; - } +hci_copy_identity_address (hdev, &addr, &addr_type); -seq_printf (f,"%pMR (type %u) %*phN %pMR\n" , addr, addr_type, +seq_printf (f,"%pMR (type %u) %*phN %pMR\n" , &addr, addr_type,16 , hdev->irk, &hdev->rpa);hci_dev_unlock (hdev);
@@ -3636,6 +3629,28 @@ int hci_update_random_address(struct hci_request *req, bool require_privacy,return 0 ; } +/* Copy the Identity Address of the controller. +* +* If the controller has a public BD_ADDR, then by default use that one. +* If this is a LE only controller without a public address, default to +* the static random address. +* +* For debugging purposes it is possible to force controllers with a +* public address to use the static random address instead. +*/ +void hci_copy_identity_address (struct hci_dev *hdev,bdaddr_t *bdaddr, +u8 *bdaddr_type) +{ +if (test_bit (HCI_FORCE_STATIC_ADDR , &hdev->dev_flags) || + !bacmp (&hdev->bdaddr,BDADDR_ANY )) { +bacpy (bdaddr, &hdev->static_addr); + *bdaddr_type =ADDR_LE_DEV_RANDOM ; + }else { +bacpy (bdaddr, &hdev->bdaddr); + *bdaddr_type =ADDR_LE_DEV_PUBLIC ; + } +} +/* Alloc HCI device */ struct hci_dev *hci_alloc_dev (void ) {
net/bluetooth/hci_event.c +1 -16
@@ -3665,23 +3665,8 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)/* Ensure that the hci_conn contains the identity address type * regardless of which address the connection was made with. -* -* If the controller has a public BD_ADDR, then by default -* use that one. If this is a LE only controller without -* a public address, default to the static random address. -* -* For debugging purposes it is possible to force -* controllers with a public address to use the static -* random address instead. */ -if (test_bit (HCI_FORCE_STATIC_ADDR , &hdev->dev_flags) || - !bacmp (&hdev->bdaddr,BDADDR_ANY )) { -bacpy (&conn->src, &hdev->static_addr); - conn->src_type =ADDR_LE_DEV_RANDOM ; - }else { -bacpy (&conn->src, &hdev->bdaddr); - conn->src_type =ADDR_LE_DEV_PUBLIC ; - } +hci_copy_identity_address (hdev, &conn->src, &conn->src_type);/* Lookup the identity address from the stored connection * address and address type.
Signature · 1 line
1.8.5.3
PATCH 3/4 Bluetooth: Track LE initiator and responder address information
In reply to [email protected]From: Johan Hedberg <[email protected]>
For SMP we need the local and remote addresses (and their types) that were used to establish the connection. These may be different from the Identity Addresses or even the current RPA. To guarantee that we have this information available and it is correct track these values separately from the very beginning of the connection.
For outgoing connections we set the values as soon as we get a successful command status for HCI_LE_Create_Connection (for which the patch adds a command status handler function) and for incoming connections as soon as we get a LE Connection Complete HCI event.
--- include/net/bluetooth/hci_core.h | 4 +++ net/bluetooth/hci_event.c | 74 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+)
include/net/bluetooth/hci_core.h +4 -0
@@ -331,6 +331,10 @@ struct hci_conn {__u8 dst_type;bdaddr_t src;__u8 src_type; +bdaddr_t init_addr; +__u8 init_addr_type; +bdaddr_t resp_addr; +__u8 resp_addr_type;__u16 handle;__u16 state;__u8 mode;
net/bluetooth/hci_event.c +74 -0
92 lines not on this page · raw message
Signature · 1 line
1.8.5.3
PATCH 4/4 Bluetooth: Use hdev->init/resp_addr values for smp_c1 function
In reply to [email protected]From: Johan Hedberg <[email protected]>
Now that we have nicely tracked values of the initiator and responder address information we can pass that directly to the smp_c1 function without worrying e.g. about who initiated the connection. This patch updates the two places in smp.c to use the new variables.
--- net/bluetooth/smp.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-)
net/bluetooth/smp.c +6 -16
@@ -445,14 +445,9 @@ static void confirm_work(struct work_struct *work)/* Prevent mutual access to hdev->tfm_aes */ hci_dev_lock (hdev); -if (conn->hcon->out) - ret =smp_c1 (tfm, smp->tk, smp->prnd, smp->preq, smp->prsp, - conn->hcon->src_type, &conn->hcon->src, - conn->hcon->dst_type, &conn->hcon->dst, res); -else - ret =smp_c1 (tfm, smp->tk, smp->prnd, smp->preq, smp->prsp, - conn->hcon->dst_type, &conn->hcon->dst, - conn->hcon->src_type, &conn->hcon->src, res); + ret =smp_c1 (tfm, smp->tk, smp->prnd, smp->preq, smp->prsp, + conn->hcon->init_addr_type, &conn->hcon->init_addr, + conn->hcon->resp_addr_type, &conn->hcon->resp_addr, res);hci_dev_unlock (hdev);
@@ -492,14 +487,9 @@ static void random_work(struct work_struct *work)/* Prevent mutual access to hdev->tfm_aes */ hci_dev_lock (hdev); -if (hcon->out) - ret =smp_c1 (tfm, smp->tk, smp->rrnd, smp->preq, smp->prsp, - hcon->src_type, &hcon->src, - hcon->dst_type, &hcon->dst, res); -else - ret =smp_c1 (tfm, smp->tk, smp->rrnd, smp->preq, smp->prsp, - hcon->dst_type, &hcon->dst, - hcon->src_type, &hcon->src, res); + ret =smp_c1 (tfm, smp->tk, smp->rrnd, smp->preq, smp->prsp, + hcon->init_addr_type, &hcon->init_addr, + hcon->resp_addr_type, &hcon->resp_addr, res);hci_dev_unlock (hdev);
Signature · 1 line
1.8.5.3
Hi Johan,
Quoted 21 lines
I'm presenting this patch set as an alternative to the two patches from Marcel. The main difference is that we trade some more complexity during the connection creation phase with less complexity in looking up the values in SMP when the time comes for calling the
smp_c1function.One source of extra complexity is the attempt to handle the case of whitelist initiated connections. Since we do not use those I'm not completely sure it's worth to have code for it. If the handling is not needed patch 3/4 gets a bit simpler and patch 2/4 can potentially be dropped (I added that new function mainly to make 3/4 actually readable with this extra whitelist handling logic).
Johan
----------------------------------------------------------------
Johan Hedberg (4):
Bluetooth: Add tracking of advertising address type
Bluetooth: Addhci_copy_identity_addressconvenience function
Bluetooth: Track LE initiator and responder address information
Bluetooth: Use hdev->init/resp_addr values forsmp_c1function
Quoted 5 lines
include/net/bluetooth/hci_core.h | 7 +++ net/bluetooth/hci_core.c | 35 ++++++++--- net/bluetooth/hci_event.c | 114 ++++++++++++++++++++++++++++++----- net/bluetooth/smp.c | 22 ++----- 4 files changed, 136 insertions(+), 42 deletions(-)
I applied patch 1 and patch 2 to bluetooth-next tree.
Regards
Marcel