Bluetooth: Connection parameter support
Subsystems (2)
cover Bluetooth: Connection parameter support
Hi,
This patch set implements the Load Connection Parameters command and contains other connection parameter related fixes and improvements.
Johan
----------------------------------------------------------------
Johan Hedberg (10):
Bluetooth: Rename hci_conn_params_clear to hci_conn_params_clear_all
Bluetooth: Add specific connection parameter clear functions
Bluetooth: Add new auto_conn value matching mgmt action 0x00
Bluetooth: Remove only enabled entries with Remove Device command
Bluetooth: Add Load Connection Parameters command
Bluetooth: Fix missing update of conn params
Bluetooth: Make hci_le_conn_update return any updated parameters
Bluetooth: Pass store hint to mgmt_new_conn_param
Bluetooth: Make is_identity_address a global function
Bluetooth: Set store_hint to 0 for non-identity addresses
include/net/bluetooth/hci_core.h | 26 ++++++-- include/net/bluetooth/mgmt.h | 15 +++++ net/bluetooth/hci_conn.c | 7 ++- net/bluetooth/hci_core.c | 53 +++++++++++----- net/bluetooth/hci_event.c | 22 ++++++- net/bluetooth/l2cap_core.c | 15 ++++- net/bluetooth/mgmt.c | 113 +++++++++++++++++++++++++++++++++-- 7 files changed, 218 insertions(+), 33 deletions(-)
PATCH 1/10 Bluetooth: Rename hci_conn_params_clear to hci_conn_params_clear_all
From: Johan Hedberg <[email protected]>
We'll soon have specific clear functions for clearing enabled or disabled entries, so rename the function that removes everything to clear_all().
--- include/net/bluetooth/hci_core.h | 2 +- net/bluetooth/hci_core.c | 4 ++-- net/bluetooth/mgmt.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
include/net/bluetooth/hci_core.h +1 -1
@@ -861,7 +861,7 @@ struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev,int hci_conn_params_set (struct hci_dev *hdev,bdaddr_t *addr,u8 addr_type,u8 auto_connect);void hci_conn_params_del (struct hci_dev *hdev,bdaddr_t *addr,u8 addr_type); -void hci_conn_params_clear (struct hci_dev *hdev); +void hci_conn_params_clear_all (struct hci_dev *hdev);struct bdaddr_list *hci_pend_le_conn_lookup (struct hci_dev *hdev,bdaddr_t *addr,u8 addr_type);
net/bluetooth/hci_core.c +2 -2
@@ -3580,7 +3580,7 @@ void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type) }/* This function requires the caller holds hdev->lock */ -void hci_conn_params_clear (struct hci_dev *hdev) +void hci_conn_params_clear_all (struct hci_dev *hdev) {struct hci_conn_params *params, *tmp;
@@ -4037,7 +4037,7 @@ void hci_unregister_dev(struct hci_dev *hdev)hci_smp_irks_clear (hdev);hci_remote_oob_data_clear (hdev);hci_white_list_clear (hdev); -hci_conn_params_clear (hdev); +hci_conn_params_clear_all (hdev);hci_dev_unlock (hdev);hci_dev_put (hdev);
net/bluetooth/mgmt.c +1 -1
@@ -5104,7 +5104,7 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev, goto unlock; } -hci_conn_params_clear (hdev); +hci_conn_params_clear_all (hdev); } err = cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE,
Signature · 1 line
1.9.3
PATCH 2/10 Bluetooth: Add specific connection parameter clear functions
In reply to [email protected]From: Johan Hedberg <[email protected]>
In some circumstances we'll need to either clear only the enabled parameters or only the disabled ones. This patch adds convenience functions for this purpose.
--- include/net/bluetooth/hci_core.h | 2 ++ net/bluetooth/hci_core.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+)
include/net/bluetooth/hci_core.h +2 -0
@@ -862,6 +862,8 @@ int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type, u8 auto_connect);void hci_conn_params_del (struct hci_dev *hdev,bdaddr_t *addr,u8 addr_type);void hci_conn_params_clear_all (struct hci_dev *hdev); +void hci_conn_params_clear_disabled (struct hci_dev *hdev); +void hci_conn_params_clear_enabled (struct hci_dev *hdev);struct bdaddr_list *hci_pend_le_conn_lookup (struct hci_dev *hdev,bdaddr_t *addr,u8 addr_type);
net/bluetooth/hci_core.c +34 -0
@@ -3580,6 +3580,40 @@ void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type) }/* This function requires the caller holds hdev->lock */ +void hci_conn_params_clear_disabled (struct hci_dev *hdev) +{ +struct hci_conn_params *params, *tmp; + +list_for_each_entry_safe (params, tmp, &hdev->le_conn_params, list) { +if (params->auto_connect !=HCI_AUTO_CONN_DISABLED ) +continue ; +list_del (¶ms->list); +kfree (params); + } + +hci_pend_le_conns_clear (hdev); + +BT_DBG ("All LE disabled connection parameters were removed" ); +} + +/* This function requires the caller holds hdev->lock */ +void hci_conn_params_clear_enabled (struct hci_dev *hdev) +{ +struct hci_conn_params *params, *tmp; + +list_for_each_entry_safe (params, tmp, &hdev->le_conn_params, list) { +if (params->auto_connect ==HCI_AUTO_CONN_DISABLED ) +continue ; +list_del (¶ms->list); +kfree (params); + } + +hci_pend_le_conns_clear (hdev); + +BT_DBG ("All enabled LE connection parameters were removed" ); +} + +/* This function requires the caller holds hdev->lock */ void hci_conn_params_clear_all (struct hci_dev *hdev) {struct hci_conn_params *params, *tmp;
Signature · 1 line
1.9.3
PATCH 3/10 Bluetooth: Add new auto_conn value matching mgmt action 0x00
In reply to [email protected]From: Johan Hedberg <[email protected]>
The 0x00 action value of mgmt means "scan and report" but do not connect. This is different from HCI_AUTO_CONN_DISABLED so we need a new value for it.
--- include/net/bluetooth/hci_core.h | 1 + net/bluetooth/hci_core.c | 1 + net/bluetooth/mgmt.c | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-)
include/net/bluetooth/hci_core.h +1 -0
@@ -449,6 +449,7 @@ struct hci_conn_params {enum {HCI_AUTO_CONN_DISABLED , +HCI_AUTO_CONN_REPORT ,HCI_AUTO_CONN_ALWAYS ,HCI_AUTO_CONN_LINK_LOSS , } auto_connect;
net/bluetooth/hci_core.c +1 -0
@@ -3547,6 +3547,7 @@ int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type,switch (auto_connect) {case HCI_AUTO_CONN_DISABLED : +case HCI_AUTO_CONN_REPORT :case HCI_AUTO_CONN_LINK_LOSS :hci_pend_le_conn_del (hdev, addr, addr_type);break ;
net/bluetooth/mgmt.c +1 -1
@@ -5034,7 +5034,7 @@ static int add_device(struct sock *sk, struct hci_dev *hdev,if (cp->action) auto_conn =HCI_AUTO_CONN_ALWAYS ;else - auto_conn =HCI_AUTO_CONN_DISABLED ; + auto_conn =HCI_AUTO_CONN_REPORT ;/* If the connection parameters don't exist for this device, * they will be created and configured with defaults.
Signature · 1 line
1.9.3
PATCH 4/10 Bluetooth: Remove only enabled entries with Remove Device command
In reply to [email protected]From: Johan Hedberg <[email protected]>
The Remove Device mgmt command is supposed to undo what the Add Device command does. An entry added by Add Device cannot have the HCI_AUTO_CONN_DISABLED auto_connect value, so we should treat this as an invalid entry to remove. This patch adds the necessary pieces to the Remove Device command handler so that it only removes entries which were added by Add Device.
--- net/bluetooth/mgmt.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
net/bluetooth/mgmt.c +21 -2
@@ -5079,6 +5079,7 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev,hci_dev_lock (hdev);if (bacmp (&cp->addr.bdaddr,BDADDR_ANY )) { +struct hci_conn_params *params;u8 addr_type;if (!bdaddr_type_is_le (cp->addr.type)) {
@@ -5093,7 +5094,25 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev,else addr_type =ADDR_LE_DEV_RANDOM ; -hci_conn_params_del (hdev, &cp->addr.bdaddr, addr_type); + params =hci_conn_params_lookup (hdev, &cp->addr.bdaddr, + addr_type); +if (!params) { + err =cmd_complete (sk, hdev->id,MGMT_OP_REMOVE_DEVICE , +MGMT_STATUS_INVALID_PARAMS , + &cp->addr,sizeof (cp->addr)); + goto unlock; + } + +if (params->auto_connect ==HCI_AUTO_CONN_DISABLED ) { + err =cmd_complete (sk, hdev->id,MGMT_OP_REMOVE_DEVICE , +MGMT_STATUS_INVALID_PARAMS , + &cp->addr,sizeof (cp->addr)); + goto unlock; + } + +hci_pend_le_conn_del (hdev, &cp->addr.bdaddr, addr_type); +list_del (¶ms->list); +kfree (params);device_removed (sk, hdev, &cp->addr.bdaddr, cp->addr.type); }else {
@@ -5104,7 +5123,7 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev, goto unlock; } -hci_conn_params_clear_all (hdev); +hci_conn_params_clear_enabled (hdev); } err = cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE,
Signature · 1 line
1.9.3
PATCH 5/10 Bluetooth: Add Load Connection Parameters command
In reply to [email protected]From: Johan Hedberg <[email protected]>
This patch implements the new Load Connection Parameters mgmt command that's intended to load the desired connection parameters for LE devices.
--- include/net/bluetooth/mgmt.h | 15 +++++++++ net/bluetooth/mgmt.c | 79 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+)
include/net/bluetooth/mgmt.h +15 -0
@@ -449,6 +449,21 @@ struct mgmt_cp_remove_device { } __packed;#define MGMT_REMOVE_DEVICE_SIZE MGMT_ADDR_INFO_SIZE +struct mgmt_conn_param { +struct mgmt_addr_info addr; +__le16 min_interval; +__le16 max_interval; +__le16 latency; +__le16 timeout; +} __packed; + +#define MGMT_OP_LOAD_CONN_PARAM 0x0035 +struct mgmt_cp_load_conn_param { +__le16 param_count; +struct mgmt_conn_param params[0 ]; +} __packed; +#define MGMT_LOAD_CONN_PARAM_SIZE 2 +#define MGMT_EV_CMD_COMPLETE 0x0001struct mgmt_ev_cmd_complete {__le16 opcode;
net/bluetooth/mgmt.c +79 -0
97 lines not on this page · raw message
Signature · 1 line
1.9.3
PATCH 6/10 Bluetooth: Fix missing update of conn params
In reply to [email protected]From: Johan Hedberg <[email protected]>
We should update any stored connection parameters when we receive the LE Remove Connection Parameter Request HCI event. This patch adds the necessary code to the function that handles the event.
--- net/bluetooth/hci_event.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
net/bluetooth/hci_event.c +13 -1
@@ -4417,9 +4417,21 @@ static void hci_le_remote_conn_param_req_evt(struct hci_dev *hdev,return send_conn_param_neg_reply (hdev, handle,HCI_ERROR_INVALID_LL_PARAMS ); -if (test_bit (HCI_CONN_MASTER , &hcon->flags)) +if (test_bit (HCI_CONN_MASTER , &hcon->flags)) { +struct hci_conn_params *params; + + params =hci_conn_params_lookup (hdev, &hcon->dst, + hcon->dst_type); +if (params) { + params->conn_min_interval = min; + params->conn_max_interval = max; + params->conn_latency = latency; + params->supervision_timeout = timeout; + } +mgmt_new_conn_param (hdev, &hcon->dst, hcon->dst_type, min, max, latency, timeout); + } cp.handle = ev->handle; cp.interval_min = ev->interval_min;
Signature · 1 line
1.9.3
PATCH 7/10 Bluetooth: Make hci_le_conn_update return any updated parameters
In reply to [email protected]From: Johan Hedberg <[email protected]>
By returning the updated parameters (if there were any) makes it possible for the calling function to do extra decisions, such as setting the store_hint on a subsequent mgmt event.
--- include/net/bluetooth/hci_core.h | 5 +++-- net/bluetooth/hci_conn.c | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-)
include/net/bluetooth/hci_core.h +3 -2
@@ -1368,8 +1368,9 @@ struct hci_sec_filter {#define hci_req_lock (d) mutex_lock(&d->req_lock)#define hci_req_unlock (d) mutex_unlock(&d->req_lock) -void hci_le_conn_update (struct hci_conn *conn,u16 min,u16 max, -u16 latency,u16 to_multiplier); +struct hci_conn_params *hci_le_conn_update (struct hci_conn *conn,u16 min, +u16 max,u16 latency, +u16 to_multiplier);void hci_le_start_enc (struct hci_conn *conn,__le16 ediv,__le64 rand,__u8 ltk[16 ]);
net/bluetooth/hci_conn.c +5 -2
@@ -213,8 +213,9 @@ bool hci_setup_sync(struct hci_conn *conn, __u16 handle)return true; } -void hci_le_conn_update (struct hci_conn *conn,u16 min,u16 max, -u16 latency,u16 to_multiplier) +struct hci_conn_params *hci_le_conn_update (struct hci_conn *conn,u16 min, +u16 max,u16 latency, +u16 to_multiplier) {struct hci_dev *hdev = conn->hdev;struct hci_conn_params *params;
@@ -242,6 +243,8 @@ void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, cp.max_ce_len =cpu_to_le16 (0x0000 );hci_send_cmd (hdev,HCI_OP_LE_CONN_UPDATE ,sizeof (cp), &cp); + +return params; } void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand,
Signature · 1 line
1.9.3
PATCH 8/10 Bluetooth: Pass store hint to mgmt_new_conn_param
In reply to [email protected]From: Johan Hedberg <[email protected]>
The calling functions of mgmt_new_conn_param have more information about the parameters, such as whether the kernel is tracking them or not. It makes therefore sense to have them pass an initial store_hint value to the mgmt_new_conn_param function.
--- include/net/bluetooth/hci_core.h | 4 ++-- net/bluetooth/hci_event.c | 8 ++++++-- net/bluetooth/l2cap_core.c | 15 +++++++++++++-- net/bluetooth/mgmt.c | 6 +++--- 4 files changed, 24 insertions(+), 9 deletions(-)
include/net/bluetooth/hci_core.h +2 -2
@@ -1335,8 +1335,8 @@ void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk);void mgmt_new_csrk (struct hci_dev *hdev,struct smp_csrk *csrk,bool persistent);void mgmt_new_conn_param (struct hci_dev *hdev,bdaddr_t *bdaddr, -u8 bdaddr_type,u16 min_interval,u16 max_interval, -u16 latency,u16 timeout); +u8 bdaddr_type,u8 store_hint,u16 min_interval, +u16 max_interval,u16 latency,u16 timeout);void mgmt_reenable_advertising (struct hci_dev *hdev);void mgmt_smp_complete (struct hci_conn *conn,bool complete);
net/bluetooth/hci_event.c +6 -2
@@ -4419,6 +4419,7 @@ static void hci_le_remote_conn_param_req_evt(struct hci_dev *hdev,if (test_bit (HCI_CONN_MASTER , &hcon->flags)) {struct hci_conn_params *params; +u8 store_hint; params =hci_conn_params_lookup (hdev, &hcon->dst, hcon->dst_type);
@@ -4427,10 +4428,13 @@ static void hci_le_remote_conn_param_req_evt(struct hci_dev *hdev, params->conn_max_interval = max; params->conn_latency = latency; params->supervision_timeout = timeout; + store_hint =0x01 ; + }else { + store_hint =0x00 ; } -mgmt_new_conn_param (hdev, &hcon->dst, hcon->dst_type, min, max, - latency, timeout); +mgmt_new_conn_param (hdev, &hcon->dst, hcon->dst_type, + store_hint, min, max, latency, timeout); } cp.handle = ev->handle;
net/bluetooth/l2cap_core.c +13 -2
@@ -5250,10 +5250,21 @@ static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn, sizeof(rsp), &rsp);if (!err) { +struct hci_conn_params *params; +u8 store_hint; + + params =hci_le_conn_update (hcon, min, max, latency, + to_multiplier); +/* If we're tracking these parameters the set store_hint */ +if (params) + store_hint =0x01 ; +else + store_hint =0x00 ; +mgmt_new_conn_param (hcon->hdev, &hcon->dst, hcon->dst_type, - min, max, latency, to_multiplier); + store_hint, min, max, latency, + to_multiplier); -hci_le_conn_update (hcon, min, max, latency, to_multiplier); }return 0 ;
net/bluetooth/mgmt.c +3 -3
@@ -5790,15 +5790,15 @@ void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk, }void mgmt_new_conn_param (struct hci_dev *hdev,bdaddr_t *bdaddr, -u8 bdaddr_type,u16 min_interval,u16 max_interval, -u16 latency,u16 timeout) +u8 bdaddr_type,u8 store_hint,u16 min_interval, +u16 max_interval,u16 latency,u16 timeout) {struct mgmt_ev_new_conn_param ev;memset (&ev,0 ,sizeof (ev));bacpy (&ev.addr.bdaddr, bdaddr); ev.addr.type =link_to_bdaddr (LE_LINK , bdaddr_type); - ev.store_hint =0x00 ; + ev.store_hint = store_hint; ev.min_interval =cpu_to_le16 (min_interval); ev.max_interval =cpu_to_le16 (max_interval); ev.latency =cpu_to_le16 (latency);
Signature · 1 line
1.9.3
PATCH 9/10 Bluetooth: Make is_identity_address a global function
In reply to [email protected]From: Johan Hedberg <[email protected]>
There are more places that can take advantage of is_identity_address() besides hci_core.c. This patch moves the function to hci_core.h and gives it the appropriate hci_ prefix.
--- include/net/bluetooth/hci_core.h | 12 ++++++++++++ net/bluetooth/hci_core.c | 14 +------------- 2 files changed, 13 insertions(+), 13 deletions(-)
include/net/bluetooth/hci_core.h +12 -0
@@ -1179,6 +1179,18 @@ static inline bool hci_bdaddr_is_rpa(bdaddr_t *bdaddr, u8 addr_type)return false; } +static inline bool hci_is_identity_address (bdaddr_t *addr,u8 addr_type) +{ +if (addr_type ==ADDR_LE_DEV_PUBLIC ) +return true; + +/* Check for Random Static address type */ +if ((addr->b[5 ] &0xc0 ) ==0xc0 ) +return true; + +return false; +} +static inline struct smp_irk *hci_get_irk (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 addr_type) {
net/bluetooth/hci_core.c +1 -13
@@ -3412,18 +3412,6 @@ static bool is_connected(struct hci_dev *hdev, bdaddr_t *addr, u8 type)return true; } -static bool is_identity_address (bdaddr_t *addr,u8 addr_type) -{ -if (addr_type ==ADDR_LE_DEV_PUBLIC ) -return true; - -/* Check for Random Static address type */ -if ((addr->b[5 ] &0xc0 ) ==0xc0 ) -return true; - -return false; -} -/* This function requires the caller holds hdev->lock */ struct bdaddr_list *hci_pend_le_conn_lookup (struct hci_dev *hdev,bdaddr_t *addr,u8 addr_type)
@@ -3504,7 +3492,7 @@ struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev, {struct hci_conn_params *params; -if (!is_identity_address (addr, addr_type)) +if (!hci_is_identity_address (addr, addr_type))return NULL ; params =hci_conn_params_lookup (hdev, addr, addr_type);
Signature · 1 line
1.9.3
PATCH 10/10 Bluetooth: Set store_hint to 0 for non-identity addresses
In reply to [email protected]From: Johan Hedberg <[email protected]>
If we don't have an identity address for connection parameters it's not very valuable to store them persistently. Therefore, set the store_hint to 0 in case we don't have an identity address.
--- net/bluetooth/mgmt.c | 3 +++ 1 file changed, 3 insertions(+)
net/bluetooth/mgmt.c +3 -0
@@ -5795,6 +5795,9 @@ void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr, {struct mgmt_ev_new_conn_param ev; +if (!hci_is_identity_address (bdaddr, bdaddr_type)) + store_hint =0x00 ; +memset (&ev,0 ,sizeof (ev));bacpy (&ev.addr.bdaddr, bdaddr); ev.addr.type =link_to_bdaddr (LE_LINK , bdaddr_type);
Signature · 1 line
1.9.3