Bluetooth: HCI command synchronization
Subsystems (2)
Luiz Augusto von Dentz
maintainerv8 cover Bluetooth: HCI command synchronization
From: Luiz Augusto von Dentz <[email protected]>
This is the initial work to move away from the current design of batch up commands with hci_req_run to be executed asynchronously to instead run them synchronously which enables handling errors properly.
It specially targets enabling the so called LL Privacy feature and simplifying Suspend/Resume code paths since those are the most complicated ones involving multiple state machines (Connection, Advertising, Scanning and Adv Monitor) which requires a bunch commands to be send making the code very complicated to follow.
As a result of these changes the LL Privacy is enabled for the peripheral role, previously only central role had support for it, so it is possible to have advertising sets when LL Privacy is enabled.
Suspend/Resume have been reworked so it no longer needs a state machine to track its progress, the whole process of suspending is handled by hci_suspend_sync and hci_resume_sync for resuming, we also took the time to document the source code to make clear what is their expected behavior.
In order to properly test these changes a number of new tests are being introduced see:
https://patchwork.kernel.org/project/bluetooth/list/?series=565857
v6: Fix CI findings, fix using ERR_PTR/PTR_ERR to pass parameters as user_data and change the use of hci_dev *dev to hci_dev *hdev.
v7: More fixes for CI findings.
v8: Even more fixes for CI findings.
Brian Gix (13):
Bluetooth: hci_sync: Convert MGMT_OP_SET_FAST_CONNECTABLE
Bluetooth: hci_sync: Enable synch'd set_bredr
Bluetooth: hci_sync: Convert MGMT_OP_GET_CONN_INFO
Bluetooth: hci_sync: Convert MGMT_OP_SET_SECURE_CONN
Bluetooth: hci_sync: Convert MGMT_OP_GET_CLOCK_INFO
Bluetooth: hci_sync: Convert MGMT_OP_SET_LE
Bluetooth: hci_sync: Convert MGMT_OP_READ_LOCAL_OOB_DATA
Bluetooth: hci_sync: Convert MGMT_OP_READ_LOCAL_OOB_EXT_DATA
Bluetooth: hci_sync: Convert MGMT_OP_SET_LOCAL_NAME
Bluetooth: hci_sync: Convert MGMT_OP_SET_PHY_CONFIGURATION
Bluetooth: hci_sync: Convert MGMT_OP_SET_ADVERTISING
Bluetooth: hci_sync: Convert adv_expire
Bluetooth: hci_sync: Convert MGMT_OP_SSP
Luiz Augusto von Dentz (9):
Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 1
Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 2
Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 3
Bluetooth: hci_sync: Enable advertising when LL privacy is enabled
Bluetooth: hci_sync: Rework background scan
Bluetooth: hci_sync: Convert MGMT_SET_POWERED
Bluetooth: hci_sync: Convert MGMT_OP_START_DISCOVERY
Bluetooth: hci_sync: Rework init stages
Bluetooth: hci_sync: Rework hci_suspend_notifier
Marcel Holtmann (1):
Bluetooth: Add helper for serialized HCI command execution
include/net/bluetooth/bluetooth.h | 2 + include/net/bluetooth/hci_core.h | 21 +- include/net/bluetooth/hci_sync.h | 98 + net/bluetooth/Makefile | 2 +- net/bluetooth/hci_conn.c | 20 +- net/bluetooth/hci_core.c | 1333 +------- net/bluetooth/hci_event.c | 153 +- net/bluetooth/hci_request.c | 338 +- net/bluetooth/hci_request.h | 10 + net/bluetooth/hci_sync.c | 4788 +++++++++++++++++++++++++++++ net/bluetooth/mgmt.c | 2050 ++++++------ net/bluetooth/mgmt_util.c | 15 +- net/bluetooth/mgmt_util.h | 4 + net/bluetooth/msft.c | 511 +-- net/bluetooth/msft.h | 15 +- 15 files changed, 6370 insertions(+), 2990 deletions(-) create mode 100644 include/net/bluetooth/hci_sync.h create mode 100644 net/bluetooth/hci_sync.c
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 1/23 Bluetooth: Add helper for serialized HCI command execution
From: Marcel Holtmann <[email protected]>
The usage of __hci_cmd_sync() within the hdev->setup() callback allows for a nice and simple serialized execution of HCI commands. More importantly it allows for result processing before issueing the next command.
With the current usage of hci_req_run() it is possible to batch up commands and execute them, but it is impossible to react to their results or errors.
This is an attempt to generalize the hdev->setup() handling and provide a simple way of running multiple HCI commands from a single function context.
There are multiple struct work that are decdicated to certain tasks already used right now. It is add a lot of bloat to hci_dev struct and extra handling code. So it might be possible to put all of these behind a common HCI command infrastructure and just execute the HCI commands from the same work context in a serialized fashion.
For example updating the white list and resolving list can be done now without having to know the list size ahead of time. Also preparing for suspend or resume shouldn't require a state machine anymore. There are other tasks that should be simplified as well.
--- include/net/bluetooth/hci_core.h | 11 +- include/net/bluetooth/hci_sync.h | 42 ++++ net/bluetooth/Makefile | 2 +- net/bluetooth/hci_core.c | 23 +-- net/bluetooth/hci_request.c | 68 ------- net/bluetooth/hci_request.h | 4 + net/bluetooth/hci_sync.c | 330 +++++++++++++++++++++++++++++++ 7 files changed, 385 insertions(+), 95 deletions(-) create mode 100644 include/net/bluetooth/hci_sync.h create mode 100644 net/bluetooth/hci_sync.c
include/net/bluetooth/hci_core.h +4 -7
@@ -30,6 +30,7 @@#include <linux/rculist.h> #include <net/bluetooth/hci.h> +#include <net/bluetooth/hci_sync.h> #include <net/bluetooth/hci_sock.h> /* HCI priority */
@@ -475,6 +476,9 @@ struct hci_dev {struct work_struct power_on;struct delayed_work power_off;struct work_struct error_reset; +struct work_struct cmd_sync_work; +struct list_head cmd_sync_work_list; +struct mutex cmd_sync_work_lock;__u16 discov_timeout;struct delayed_work discov_off;
@@ -1690,10 +1694,6 @@ static inline int hci_check_conn_params(u16 min, u16 max, u16 latency,int hci_register_cb (struct hci_cb *hcb);int hci_unregister_cb (struct hci_cb *hcb); -struct sk_buff *__hci_cmd_sync (struct hci_dev *hdev,u16 opcode,u32 plen, -const void *param,u32 timeout); -struct sk_buff *__hci_cmd_sync_ev (struct hci_dev *hdev,u16 opcode,u32 plen, -const void *param,u8 event,u32 timeout);int __hci_cmd_send (struct hci_dev *hdev,u16 opcode,u32 plen,const void *param);
@@ -1704,9 +1704,6 @@ void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);void *hci_sent_cmd_data (struct hci_dev *hdev,__u16 opcode); -struct sk_buff *hci_cmd_sync (struct hci_dev *hdev,u16 opcode,u32 plen, -const void *param,u32 timeout); -u32 hci_conn_get_phy (struct hci_conn *conn);/* ----- HCI Sockets ----- */
include/net/bluetooth/hci_sync.h new file +42 -0
42 lines not on this page · raw message
net/bluetooth/Makefile +1 -1
@@ -15,7 +15,7 @@ bluetooth_6lowpan-y := 6lowpan.o bluetooth-y := af_bluetooth.o hci_core.o hci_conn.o hci_event.o mgmt.o \ hci_sock.o hci_sysfs.o l2cap_core.o l2cap_sock.o smp.o lib.o \ ecdh_helper.o hci_request.o mgmt_util.o mgmt_config.o hci_codec.o \ - eir.o + eir.o hci_sync.o bluetooth-$(CONFIG_BT_BREDR) += sco.o bluetooth-$(CONFIG_BT_HS) += a2mp.o amp.o
net/bluetooth/hci_core.c +4 -19
@@ -3747,6 +3747,8 @@ struct hci_dev *hci_alloc_dev_priv(int sizeof_priv)INIT_WORK (&hdev->error_reset, hci_error_reset);INIT_WORK (&hdev->suspend_prepare, hci_prepare_suspend); +hci_cmd_sync_init (hdev); +INIT_DELAYED_WORK (&hdev->power_off, hci_power_off);skb_queue_head_init (&hdev->rx_q);
@@ -3905,6 +3907,8 @@ void hci_unregister_dev(struct hci_dev *hdev)cancel_work_sync (&hdev->power_on); +hci_cmd_sync_clear (hdev); +if (!test_bit (HCI_QUIRK_NO_SUSPEND_NOTIFIER , &hdev->quirks)) {hci_suspend_clear_tasks (hdev);unregister_pm_notifier (&hdev->suspend_notifier);
@@ -4271,25 +4275,6 @@ void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode)return hdev->sent_cmd->data +HCI_COMMAND_HDR_SIZE ; } -/* Send HCI command and wait for command complete event */ -struct sk_buff *hci_cmd_sync (struct hci_dev *hdev,u16 opcode,u32 plen, -const void *param,u32 timeout) -{ -struct sk_buff *skb; - -if (!test_bit (HCI_UP , &hdev->flags)) -return ERR_PTR (-ENETDOWN ); - -bt_dev_dbg (hdev,"opcode 0x%4.4x plen %d" , opcode, plen); - -hci_req_sync_lock (hdev); - skb =__hci_cmd_sync (hdev, opcode, plen, param, timeout); -hci_req_sync_unlock (hdev); - -return skb; -} -EXPORT_SYMBOL (hci_cmd_sync); -/* Send ACL data */ static void hci_add_acl_hdr (struct sk_buff *skb,__u16 handle,__u16 flags) {
net/bluetooth/hci_request.c +0 -68
80 lines not on this page · raw message
net/bluetooth/hci_request.h +4 -0
@@ -25,6 +25,10 @@#define hci_req_sync_lock (hdev) mutex_lock(&hdev->req_lock)#define hci_req_sync_unlock (hdev) mutex_unlock(&hdev->req_lock) +#define HCI_REQ_DONE 0 +#define HCI_REQ_PEND 1 +#define HCI_REQ_CANCELED 2 +struct hci_request {struct hci_dev *hdev;struct sk_buff_head cmd_q;
net/bluetooth/hci_sync.c new file +330 -0
330 lines not on this page · raw message
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 2/23 Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 1
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This make use of hci_cmd_sync_queue for the following MGMT commands:
Set Device Class
Set Device ID
Add UUID
Remove UUID
tools/mgmt-tester -s "Set Device Class"
Test Summary
------------
Set Device Class - Success 1 Passed Set Device Class - Success 2 Passed Set Device Class - Invalid parameters 1 Passed
Total: 3, Passed: 3 (100.0%), Failed: 0, Not Run: 0 Overall execution time: 0.0599 seconds
tools/mgmt-tester -s "Set Device ID"
Test Summary
------------
Set Device ID - Success 1 Passed Set Device ID - Success 2 Passed Set Device ID - Disable Passed Set Device ID - Power off and Power on Passed Set Device ID - SSP off and Power on Passed Set Device ID - Invalid Parameter Passed
Total: 6, Passed: 6 (100.0%), Failed: 0, Not Run: 0 Overall execution time: 0.107 seconds
tools/mgmt-tester -s "Add UUID"
Test Summary
------------
Add UUID - UUID-16 1 Passed Add UUID - UUID-16 multiple 1 Passed Add UUID - UUID-16 partial 1 Passed Add UUID - UUID-32 1 Passed Add UUID - UUID-32 multiple 1 Passed Add UUID - UUID-32 partial 1 Passed Add UUID - UUID-128 1 Passed Add UUID - UUID-128 multiple 1 Passed Add UUID - UUID-128 partial 1 Passed Add UUID - UUID mix Passed
Total: 10, Passed: 10 (100.0%), Failed: 0, Not Run: 0 Overall execution time: 0.198 seconds
tools/mgmt-tester -s "Remove UUID"
Test Summary
------------
Remove UUID - Success 1 Passed Remove UUID - All UUID - Success 2 Passed Remove UUID - Power Off - Success 3 Passed Remove UUID - Power Off and On - Success 4 Passed Remove UUID - Not Exist - Invalid Params 1 Passed
Total: 5, Passed: 5 (100.0%), Failed: 0, Not Run: 0 Overall execution time: 0.0908 seconds
--- include/net/bluetooth/hci_sync.h | 3 + net/bluetooth/hci_request.c | 4 +- net/bluetooth/hci_request.h | 6 + net/bluetooth/hci_sync.c | 72 ++++++++++++ net/bluetooth/mgmt.c | 192 +++++++++++++++---------------- net/bluetooth/mgmt_util.c | 15 ++- net/bluetooth/mgmt_util.h | 3 + 7 files changed, 193 insertions(+), 102 deletions(-)
include/net/bluetooth/hci_sync.h +3 -0
@@ -40,3 +40,6 @@ void hci_cmd_sync_clear(struct hci_dev *hdev);int hci_cmd_sync_queue (struct hci_dev *hdev,hci_cmd_sync_work_func_t func,void *data,hci_cmd_sync_work_destroy_t destroy); + +int hci_update_eir_sync (struct hci_dev *hdev); +int hci_update_class_sync (struct hci_dev *hdev);
net/bluetooth/hci_request.c +2 -2
@@ -97,8 +97,8 @@ int hci_req_run_skb(struct hci_request *req, hci_req_complete_skb_t complete)return req_run (req,NULL , complete); } -static void hci_req_sync_complete (struct hci_dev *hdev,u8 result,u16 opcode, -struct sk_buff *skb) +void hci_req_sync_complete (struct hci_dev *hdev,u8 result,u16 opcode, +struct sk_buff *skb) {bt_dev_dbg (hdev,"result 0x%2.2x" , result);
net/bluetooth/hci_request.h +6 -0
@@ -22,6 +22,10 @@#include <asm/unaligned.h> +#define HCI_REQ_DONE 0 +#define HCI_REQ_PEND 1 +#define HCI_REQ_CANCELED 2 +#define hci_req_sync_lock (hdev) mutex_lock(&hdev->req_lock)#define hci_req_sync_unlock (hdev) mutex_unlock(&hdev->req_lock)
@@ -44,6 +48,8 @@ void hci_req_purge(struct hci_request *req);bool hci_req_status_pend (struct hci_dev *hdev);int hci_req_run (struct hci_request *req,hci_req_complete_t complete);int hci_req_run_skb (struct hci_request *req,hci_req_complete_skb_t complete); +void hci_req_sync_complete (struct hci_dev *hdev,u8 result,u16 opcode, +struct sk_buff *skb);void hci_req_add (struct hci_request *req,u16 opcode,u32 plen,const void *param); void hci_req_add_ev(struct hci_request *req, u16 opcode, u32 plen,
net/bluetooth/hci_sync.c +72 -0
81 lines not on this page · raw message
net/bluetooth/mgmt.c +93 -99
311 lines not on this page · raw message
net/bluetooth/mgmt_util.c +14 -1
@@ -227,7 +227,7 @@ void mgmt_pending_foreach(u16 opcode, struct hci_dev *hdev, } } -struct mgmt_pending_cmd *mgmt_pending_add (struct sock *sk,u16 opcode, +struct mgmt_pending_cmd *mgmt_pending_new (struct sock *sk,u16 opcode,struct hci_dev *hdev,void *data,u16 len) {
@@ -251,6 +251,19 @@ struct mgmt_pending_cmd *mgmt_pending_add(struct sock *sk, u16 opcode, cmd->sk = sk;sock_hold (sk); +return cmd; +} + +struct mgmt_pending_cmd *mgmt_pending_add (struct sock *sk,u16 opcode, +struct hci_dev *hdev, +void *data,u16 len) +{ +struct mgmt_pending_cmd *cmd; + + cmd =mgmt_pending_new (sk, opcode, hdev, data, len); +if (!cmd) +return NULL ; +list_add (&cmd->list, &hdev->mgmt_pending);return cmd;
net/bluetooth/mgmt_util.h +3 -0
@@ -49,5 +49,8 @@ void mgmt_pending_foreach(u16 opcode, struct hci_dev *hdev,struct mgmt_pending_cmd *mgmt_pending_add (struct sock *sk,u16 opcode,struct hci_dev *hdev,void *data,u16 len); +struct mgmt_pending_cmd *mgmt_pending_new (struct sock *sk,u16 opcode, +struct hci_dev *hdev, +void *data,u16 len);void mgmt_pending_free (struct mgmt_pending_cmd *cmd);void mgmt_pending_remove (struct mgmt_pending_cmd *cmd);
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 3/23 Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 2
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This make use of hci_cmd_sync_queue for the following MGMT commands:
Add Advertising
Remove Advertising
Add Extended Advertising Parameters
Add Extended Advertising Data
mgmt-tester -s "Add Advertising"
Test Summary
------------
Add Advertising - Failure: LE off Passed Add Advertising - Invalid Params 1 (AD too long) Passed Add Advertising - Invalid Params 2 (Malformed len) Passed Add Advertising - Invalid Params 3 (Malformed len) Passed Add Advertising - Invalid Params 4 (Malformed len) Passed Add Advertising - Invalid Params 5 (AD too long) Passed Add Advertising - Invalid Params 6 (ScRsp too long) Passed Add Advertising - Invalid Params 7 (Malformed len) Passed Add Advertising - Invalid Params 8 (Malformed len) Passed Add Advertising - Invalid Params 9 (Malformed len) Passed
Add Advertising - Invalid Params 10 (ScRsp too long) Passed
Add Advertising - Rejected (Timeout, !Powered) Passed
Add Advertising - Success 1 (Powered, Add Adv Inst) Passed Add Advertising - Success 2 (!Powered, Add Adv Inst) Passed
Add Advertising - Success 3 (!Powered, Adv Enable) Passed Add Advertising - Success 4 (Set Adv on override) Passed Add Advertising - Success 5 (Set Adv off override) Passed Add Advertising - Success 6 (Scan Rsp Dta, Adv ok) Passed Add Advertising - Success 7 (Scan Rsp Dta, Scan ok) Passed Add Advertising - Success 8 (Connectable Flag) Passed Add Advertising - Success 9 (General Discov Flag) Passed Add Advertising - Success 10 (Limited Discov Flag) Passed Add Advertising - Success 11 (Managed Flags) Passed Add Advertising - Success 12 (TX Power Flag) Passed Add Advertising - Success 13 (ADV_SCAN_IND) Passed Add Advertising - Success 14 (ADV_NONCONN_IND) Passed Add Advertising - Success 15 (ADV_IND) Passed Add Advertising - Success 16 (Connectable -> on) Passed Add Advertising - Success 17 (Connectable -> off) Passed Add Advertising - Success 18 (Power -> off, Remove) Passed Add Advertising - Success 19 (Power -> off, Keep) Passed Add Advertising - Success 20 (Add Adv override) Passed Add Advertising - Success 21 (Timeout expires) Passed Add Advertising - Success 22 (LE -> off, Remove) Passed Add Advertising - Success (Empty ScRsp) Passed Add Advertising - Success (ScRsp only) Passed Add Advertising - Invalid Params (ScRsp too long) Passed Add Advertising - Success (ScRsp appear) Passed Add Advertising - Invalid Params (ScRsp appear long) Passed Add Advertising - Success (Appear is null) Passed Add Advertising - Success (Name is null) Passed Add Advertising - Success (Complete name) Passed Add Advertising - Success (Shortened name) Passed Add Advertising - Success (Short name) Passed Add Advertising - Success (Name + data) Passed Add Advertising - Invalid Params (Name + data) Passed Add Advertising - Success (Name+data+appear) Passed
Total: 47, Passed: 47 (100.0%), Failed: 0, Not Run: 0 Overall execution time: 2.17 seconds
mgmt-tester -s "Remove Advertising"
Test Summary
------------
Remove Advertising - Invalid Params 1 Passed Remove Advertising - Success 1 Passed Remove Advertising - Success 2 Passed
Total: 3, Passed: 3 (100.0%), Failed: 0, Not Run: 0 Overall execution time: 0.0585 seconds
mgmt-tester -s "Ext Adv MGMT Params"
Test Summary:
------------
Ext Adv MGMT Params - Unpowered Passed Ext Adv MGMT Params - Invalid parameters Passed Ext Adv MGMT Params - Success Passed Ext Adv MGMT Params - (5.0) Success Passed
Total: 4, Passed: 4 (100.0%), Failed: 0, Not Run: 0 Overall execution time: 0.0746 seconds
mgmt-tester -s "Ext Adv MGMT -"
Test Summary
------------
Ext Adv MGMT - Data set without Params Passed Ext Adv MGMT - AD Data (5.0) Invalid parameters Passed Ext Adv MGMT - AD Data (5.0) Success Passed Ext Adv MGMT - AD Scan Response (5.0) Success Passed
Total: 4, Passed: 4 (100.0%), Failed: 0, Not Run: 0 Overall execution time: 0.0805 seconds
--- include/net/bluetooth/bluetooth.h | 2 + include/net/bluetooth/hci_sync.h | 20 + net/bluetooth/hci_event.c | 57 ++ net/bluetooth/hci_sync.c | 890 ++++++++++++++++++++++++++++++ net/bluetooth/mgmt.c | 391 +++++++------ 5 files changed, 1158 insertions(+), 202 deletions(-)
include/net/bluetooth/bluetooth.h +2 -0
@@ -380,6 +380,7 @@ typedef void (*hci_req_complete_skb_t)(struct hci_dev *hdev, u8 status,#define HCI_REQ_SKB BIT(1)struct hci_ctrl { +struct sock *sk;u16 opcode;u8 req_flags;u8 req_event;
@@ -405,6 +406,7 @@ struct bt_skb_cb {#define hci_skb_pkt_type (skb) bt_cb((skb))->pkt_type#define hci_skb_expect (skb) bt_cb((skb))->expect#define hci_skb_opcode (skb) bt_cb((skb))->hci.opcode +#define hci_skb_sk (skb) bt_cb((skb))->hci.skstatic inline struct sk_buff *bt_skb_alloc (unsigned int len,gfp_t how) {
include/net/bluetooth/hci_sync.h +20 -0
@@ -43,3 +43,23 @@ int hci_cmd_sync_queue(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,int hci_update_eir_sync (struct hci_dev *hdev);int hci_update_class_sync (struct hci_dev *hdev); + +int hci_update_eir_sync (struct hci_dev *hdev); +int hci_update_class_sync (struct hci_dev *hdev); + +int hci_update_random_address_sync (struct hci_dev *hdev,bool require_privacy, +bool rpa,u8 *own_addr_type); + +int hci_update_scan_rsp_data_sync (struct hci_dev *hdev,u8 instance); +int hci_update_adv_data_sync (struct hci_dev *hdev,u8 instance); +int hci_schedule_adv_instance_sync (struct hci_dev *hdev,u8 instance, +bool force); + +int hci_setup_ext_adv_instance_sync (struct hci_dev *hdev,u8 instance); +int hci_start_ext_adv_sync (struct hci_dev *hdev,u8 instance); +int hci_enable_ext_advertising_sync (struct hci_dev *hdev,u8 instance); +int hci_enable_advertising_sync (struct hci_dev *hdev); + +int hci_remove_advertising_sync (struct hci_dev *hdev,struct sock *sk, +u8 instance,bool force); +int hci_disable_advertising_sync (struct hci_dev *hdev);
net/bluetooth/hci_event.c +57 -0
69 lines not on this page · raw message
net/bluetooth/hci_sync.c +890 -0
905 lines not on this page · raw message
net/bluetooth/mgmt.c +189 -202
582 lines not on this page · raw message
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 4/23 Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 3
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This make use of hci_cmd_sync_queue for the following MGMT commands:
Add Device
Remove Device
Tested with:
mgmt-tester -s "Add Device"
Test Summary
------------
Add Device - Invalid Params 1 Passed Add Device - Invalid Params 2 Passed Add Device - Invalid Params 3 Passed Add Device - Invalid Params 4 Passed Add Device - Success 1 Passed Add Device - Success 2 Passed Add Device - Success 3 Passed Add Device - Success 4 Passed Add Device - Success 5 Passed Add Device - Success 6 - Add to whitelist Passed Add Device - Success 7 - Add to resolv list Passed Add Device - Success 8 - Enable resolv list Passed
Total: 12, Passed: 12 (100.0%), Failed: 0, Not Run: 0 Overall execution time: 0.209 seconds
mgmt-tester -s "Remove Device"
Test Summary
------------
Remove Device - Invalid Params 1 Passed Remove Device - Invalid Params 2 Passed Remove Device - Invalid Params 3 Passed Remove Device - Success 1 Passed Remove Device - Success 2 Passed Remove Device - Success 3 Passed Remove Device - Success 4 Passed Remove Device - Success 5 Passed Remove Device - Success 6 - All Devices Passed Remove Device - Success 7 - Remove from whitelist Passed Remove Device - Success 8 - Remove from resolv list Passed
Total: 11, Passed: 11 (100.0%), Failed: 0, Not Run: 0 Overall execution time: 4.26 seconds
--- include/net/bluetooth/hci_sync.h | 2 + net/bluetooth/hci_sync.c | 617 +++++++++++++++++++++++++++++++ net/bluetooth/mgmt.c | 19 +- 3 files changed, 634 insertions(+), 4 deletions(-)
include/net/bluetooth/hci_sync.h +2 -0
@@ -63,3 +63,5 @@ int hci_enable_advertising_sync(struct hci_dev *hdev);int hci_remove_advertising_sync (struct hci_dev *hdev,struct sock *sk,u8 instance,bool force);int hci_disable_advertising_sync (struct hci_dev *hdev); + +int hci_update_passive_scan_sync (struct hci_dev *hdev);
net/bluetooth/hci_sync.c +617 -0
620 lines not on this page · raw message
net/bluetooth/mgmt.c +15 -4
@@ -6927,6 +6927,11 @@ static void device_added(struct sock *sk, struct hci_dev *hdev,mgmt_event (MGMT_EV_DEVICE_ADDED , hdev, &ev,sizeof (ev), sk); } +static int add_device_sync (struct hci_dev *hdev,void *data) +{ +return hci_update_passive_scan_sync (hdev); +} +static int add_device (struct sock *sk,struct hci_dev *hdev,void *data,u16 len) {
@@ -7009,7 +7014,9 @@ static int add_device(struct sock *sk, struct hci_dev *hdev, current_flags = params->current_flags; } -hci_update_background_scan (hdev); + err =hci_cmd_sync_queue (hdev, add_device_sync,NULL ,NULL ); +if (err <0 ) + goto unlock; added:device_added (sk, hdev, &cp->addr.bdaddr, cp->addr.type, cp->action);
@@ -7036,6 +7043,11 @@ static void device_removed(struct sock *sk, struct hci_dev *hdev,mgmt_event (MGMT_EV_DEVICE_REMOVED , hdev, &ev,sizeof (ev), sk); } +static int remove_device_sync (struct hci_dev *hdev,void *data) +{ +return hci_update_passive_scan_sync (hdev); +} +static int remove_device (struct sock *sk,struct hci_dev *hdev,void *data,u16 len) {
@@ -7115,7 +7127,6 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev,list_del (¶ms->action);list_del (¶ms->list);kfree (params); -hci_update_background_scan (hdev);device_removed (sk, hdev, &cp->addr.bdaddr, cp->addr.type); }else {
@@ -7152,10 +7163,10 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev, }bt_dev_dbg (hdev,"All LE connection parameters were removed" ); - -hci_update_background_scan (hdev); } +hci_cmd_sync_queue (hdev, remove_device_sync,NULL ,NULL ); + complete: err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE, MGMT_STATUS_SUCCESS, &cp->addr,
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 5/23 Bluetooth: hci_sync: Enable advertising when LL privacy is enabled
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This enables advertising when LL privacy is enabled and changes the command sequence when resolving list is updated to also account for when advertising is enabled using the following sequence:
If there are devices to scan:
Disable Scanning -> Update Accept List -> use_ll_privacy((Disable Advertising) -> Disable Resolving List -> Update Resolving List -> Enable Resolving List -> (Enable Advertising)) -> Enable Scanning
Otherwise:
Disable Scanning
Errors during the Update Accept List stage are handled gracefully by restoring any previous state (e.g. advertising) and disabling the use of accept list as either accept list or resolving list could not be updated.
Tested with:
mgmt-tester -s "LL Privacy"
Test Summary
------------
LL Privacy - Add Device 1 (Add to WL) Passed LL Privacy - Add Device 2 (Add to RL) Passed LL Privacy - Add Device 3 (Enable RL) Passed LL Privacy - Add Device 4 (2 Devices to WL) Passed LL Privacy - Add Device 5 (2 Devices to RL) Passed LL Privacy - Add Device 6 (RL is full) Passed LL Privacy - Add Device 7 (WL is full) Passed LL Privacy - Add Device 8 (Disable Adv) Passed LL Privacy - Add Device 9 (Multi Adv) Passed LL Privacy - Add Device 10 (Multi Dev and Multi Adv) Passed LL Privacy - Remove Device 1 (Remove from WL) Passed LL Privacy - Remove Device 2 (Remove from RL) Passed LL Privacy - Remove Device 3 (Disable RL) Passed LL Privacy - Remove Device 4 (Disable Adv) Passed LL Privacy - Remove Device 5 (Multi Adv) Passed LL Privacy - Start Discovery 1 (Disable RL) Passed LL Privacy - Start Discovery 2 (Disable RL) Passed
Total: 18, Passed: 18 (100.0%), Failed: 0, Not Run: 0
--- include/net/bluetooth/hci_core.h | 5 +- include/net/bluetooth/hci_sync.h | 1 + net/bluetooth/hci_event.c | 4 +- net/bluetooth/hci_request.c | 26 +-- net/bluetooth/hci_sync.c | 268 ++++++++++++++++++++++--------- net/bluetooth/mgmt.c | 39 +---- 6 files changed, 213 insertions(+), 130 deletions(-)
include/net/bluetooth/hci_core.h +4 -1
@@ -1465,8 +1465,11 @@ void hci_conn_del_sysfs(struct hci_conn *conn);#define scan_coded (dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_CODED) || \ ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_CODED)) +#define ll_privacy_capable (dev) ((dev)->le_features[0] & HCI_LE_LL_PRIVACY) +/* Use LL Privacy based address resolution if supported */ -#define use_ll_privacy (dev) ((dev)->le_features[0] & HCI_LE_LL_PRIVACY) +#define use_ll_privacy (dev) (ll_privacy_capable(dev) && \ + hci_dev_test_flag(dev, HCI_ENABLE_LL_PRIVACY))/* Use enhanced synchronous connection if command is supported */ #define enhanced_sco_capable (dev) ((dev)->commands[29] & 0x08)
include/net/bluetooth/hci_sync.h +1 -0
@@ -65,3 +65,4 @@ int hci_remove_advertising_sync(struct hci_dev *hdev, struct sock *sk,int hci_disable_advertising_sync (struct hci_dev *hdev);int hci_update_passive_scan_sync (struct hci_dev *hdev); +int hci_update_passive_scan (struct hci_dev *hdev);
net/bluetooth/hci_event.c +1 -3
@@ -5499,9 +5499,7 @@ static void hci_le_enh_conn_complete_evt(struct hci_dev *hdev,le16_to_cpu (ev->latency), le16_to_cpu(ev->supervision_timeout)); -if (use_ll_privacy (hdev) && -hci_dev_test_flag (hdev,HCI_ENABLE_LL_PRIVACY ) && -hci_dev_test_flag (hdev,HCI_LL_RPA_RESOLUTION )) +if (hci_dev_test_flag (hdev,HCI_LL_RPA_RESOLUTION ))hci_req_disable_address_resolution (hdev); }
net/bluetooth/hci_request.c +8 -18
@@ -511,9 +511,7 @@ void hci_req_add_le_scan_disable(struct hci_request *req, bool rpa_le_conn) }/* Disable address resolution */ -if (use_ll_privacy (hdev) && -hci_dev_test_flag (hdev,HCI_ENABLE_LL_PRIVACY ) && -hci_dev_test_flag (hdev,HCI_LL_RPA_RESOLUTION ) && !rpa_le_conn) { +if (hci_dev_test_flag (hdev,HCI_LL_RPA_RESOLUTION ) && !rpa_le_conn) {__u8 enable =0x00 ;hci_req_add (req,HCI_OP_LE_SET_ADDR_RESOLV_ENABLE ,1 , &enable);
@@ -532,8 +530,7 @@ static void del_from_accept_list(struct hci_request *req, bdaddr_t *bdaddr, cp.bdaddr_type);hci_req_add (req,HCI_OP_LE_DEL_FROM_ACCEPT_LIST ,sizeof (cp), &cp); -if (use_ll_privacy (req->hdev) && -hci_dev_test_flag (req->hdev,HCI_ENABLE_LL_PRIVACY )) { +if (use_ll_privacy (req->hdev)) {struct smp_irk *irk; irk =hci_find_irk_by_addr (req->hdev, bdaddr, bdaddr_type);
@@ -586,8 +583,7 @@ static int add_to_accept_list(struct hci_request *req, cp.bdaddr_type);hci_req_add (req,HCI_OP_LE_ADD_TO_ACCEPT_LIST ,sizeof (cp), &cp); -if (use_ll_privacy (hdev) && -hci_dev_test_flag (hdev,HCI_ENABLE_LL_PRIVACY )) { +if (use_ll_privacy (hdev)) {struct smp_irk *irk; irk = hci_find_irk_by_addr(hdev, ¶ms->addr,
@@ -626,8 +622,7 @@ static u8 update_accept_list(struct hci_request *req)*/ bool allow_rpa = hdev->suspended; -if (use_ll_privacy (hdev) && -hci_dev_test_flag (hdev,HCI_ENABLE_LL_PRIVACY )) +if (use_ll_privacy (hdev)) allow_rpa = true;/* Go through the current accept list programmed into the
@@ -716,9 +711,7 @@ static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval,return ; } -if (use_ll_privacy (hdev) && -hci_dev_test_flag (hdev,HCI_ENABLE_LL_PRIVACY ) && - addr_resolv) { +if (use_ll_privacy (hdev) && addr_resolv) {u8 enable =0x01 ;hci_req_add (req,HCI_OP_LE_SET_ADDR_RESOLV_ENABLE ,1 , &enable);
@@ -1480,8 +1473,7 @@ void hci_req_disable_address_resolution(struct hci_dev *hdev)struct hci_request req;__u8 enable =0x00 ; -if (!use_ll_privacy (hdev) && - !hci_dev_test_flag (hdev,HCI_LL_RPA_RESOLUTION )) +if (!hci_dev_test_flag (hdev,HCI_LL_RPA_RESOLUTION ))return ;hci_req_init (&req, hdev);
@@ -1624,8 +1616,7 @@ int hci_get_random_address(struct hci_dev *hdev, bool require_privacy,/* If Controller supports LL Privacy use own address type is * 0x03 */ -if (use_ll_privacy (hdev) && -hci_dev_test_flag (hdev,HCI_ENABLE_LL_PRIVACY )) +if (use_ll_privacy (hdev)) *own_addr_type =ADDR_LE_DEV_RANDOM_RESOLVED ;else *own_addr_type =ADDR_LE_DEV_RANDOM ;
@@ -2092,8 +2083,7 @@ int hci_update_random_address(struct hci_request *req, bool require_privacy,/* If Controller supports LL Privacy use own address type is * 0x03 */ -if (use_ll_privacy (hdev) && -hci_dev_test_flag (hdev,HCI_ENABLE_LL_PRIVACY )) +if (use_ll_privacy (hdev)) *own_addr_type =ADDR_LE_DEV_RANDOM_RESOLVED ;else *own_addr_type =ADDR_LE_DEV_RANDOM ;
net/bluetooth/hci_sync.c +196 -72
460 lines not on this page · raw message
net/bluetooth/mgmt.c +3 -36
@@ -839,12 +839,7 @@ static u32 get_supported_settings(struct hci_dev *hdev) settings |=MGMT_SETTING_SECURE_CONN ; settings |=MGMT_SETTING_PRIVACY ; settings |=MGMT_SETTING_STATIC_ADDRESS ; - -/* When the experimental feature for LL Privacy support is -* enabled, then advertising is no longer supported. -*/ -if (!hci_dev_test_flag (hdev,HCI_ENABLE_LL_PRIVACY )) - settings |=MGMT_SETTING_ADVERTISING ; + settings |=MGMT_SETTING_ADVERTISING ; } if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) ||
@@ -3846,7 +3841,7 @@ static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev, idx++; } -if (hdev &&use_ll_privacy (hdev)) { +if (hdev &&ll_privacy_capable (hdev)) {if (hci_dev_test_flag (hdev,HCI_ENABLE_LL_PRIVACY )) flags =BIT (0 ) |BIT (1 );else
@@ -5621,13 +5616,6 @@ static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data,return mgmt_cmd_status (sk, hdev->id,MGMT_OP_SET_ADVERTISING , status); -/* Enabling the experimental LL Privay support disables support for -* advertising. -*/ -if (hci_dev_test_flag (hdev,HCI_ENABLE_LL_PRIVACY )) -return mgmt_cmd_status (sk, hdev->id,MGMT_OP_SET_ADVERTISING , -MGMT_STATUS_NOT_SUPPORTED ); -if (cp->val !=0x00 && cp->val !=0x01 && cp->val !=0x02 )return mgmt_cmd_status (sk, hdev->id,MGMT_OP_SET_ADVERTISING ,MGMT_STATUS_INVALID_PARAMS );
@@ -7723,13 +7711,6 @@ static int read_adv_features(struct sock *sk, struct hci_dev *hdev,return mgmt_cmd_status (sk, hdev->id,MGMT_OP_READ_ADV_FEATURES ,MGMT_STATUS_REJECTED ); -/* Enabling the experimental LL Privay support disables support for -* advertising. -*/ -if (hci_dev_test_flag (hdev,HCI_ENABLE_LL_PRIVACY )) -return mgmt_cmd_status (sk, hdev->id,MGMT_OP_READ_ADV_FEATURES , -MGMT_STATUS_NOT_SUPPORTED ); -hci_dev_lock (hdev); rp_len =sizeof (*rp) + hdev->adv_instance_cnt;
@@ -7969,13 +7950,6 @@ static int add_advertising(struct sock *sk, struct hci_dev *hdev,return mgmt_cmd_status (sk, hdev->id,MGMT_OP_ADD_ADVERTISING , status); -/* Enabling the experimental LL Privay support disables support for -* advertising. -*/ -if (hci_dev_test_flag (hdev,HCI_ENABLE_LL_PRIVACY )) -return mgmt_cmd_status (sk, hdev->id,MGMT_OP_ADD_ADVERTISING , -MGMT_STATUS_NOT_SUPPORTED ); -if (cp->instance <1 || cp->instance > hdev->le_num_of_adv_sets)return mgmt_cmd_status (sk, hdev->id,MGMT_OP_ADD_ADVERTISING ,MGMT_STATUS_INVALID_PARAMS );
@@ -8471,13 +8445,6 @@ static int remove_advertising(struct sock *sk, struct hci_dev *hdev,bt_dev_dbg (hdev,"sock %p" , sk); -/* Enabling the experimental LL Privay support disables support for -* advertising. -*/ -if (hci_dev_test_flag (hdev,HCI_ENABLE_LL_PRIVACY )) -return mgmt_cmd_status (sk, hdev->id,MGMT_OP_REMOVE_ADVERTISING , -MGMT_STATUS_NOT_SUPPORTED ); -hci_dev_lock (hdev);if (cp->instance && !hci_find_adv_instance (hdev, cp->instance)) {
@@ -8788,7 +8755,7 @@ void mgmt_power_on(struct hci_dev *hdev, int err)if (!err) {restart_le_actions (hdev); -hci_update_background_scan (hdev); +hci_update_passive_scan (hdev); }mgmt_pending_foreach (MGMT_OP_SET_POWERED , hdev, settings_rsp, &match);
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 6/23 Bluetooth: hci_sync: Rework background scan
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This replaces the use of hci_update_background_scan with hci_update_passive_scan which runs from cmd_work_sync and deal properly with resolving list when LL privacy is enabled.
--- net/bluetooth/hci_conn.c | 6 +++--- net/bluetooth/hci_core.c | 14 +++++++------- net/bluetooth/hci_event.c | 4 ++-- net/bluetooth/hci_sync.c | 9 +++++++++ net/bluetooth/mgmt.c | 8 ++++---- net/bluetooth/msft.c | 2 +- 6 files changed, 26 insertions(+), 17 deletions(-)
net/bluetooth/hci_conn.c +3 -3
@@ -108,7 +108,7 @@ static void hci_connect_le_scan_cleanup(struct hci_conn *conn)break ; } -hci_update_background_scan (hdev); +hci_update_passive_scan (hdev); }static void hci_conn_cleanup (struct hci_conn *conn)
@@ -913,7 +913,7 @@ void hci_le_conn_failed(struct hci_conn *conn, u8 status)/* Since we may have temporarily stopped the background scanning in * favor of connection establishment, we should restart it. */ -hci_update_background_scan (hdev); +hci_update_passive_scan (hdev);/* Re-enable advertising in case this was a failed connection * attempt as a peripheral.
@@ -1411,7 +1411,7 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst, conn->conn_timeout = conn_timeout; conn->conn_reason = conn_reason; -hci_update_background_scan (hdev); +hci_update_passive_scan (hdev); done:hci_conn_hold (conn);
net/bluetooth/hci_core.c +7 -7
@@ -975,7 +975,7 @@ void hci_discovery_set_state(struct hci_dev *hdev, int state)switch (state) {case DISCOVERY_STOPPED : -hci_update_background_scan (hdev); +hci_update_passive_scan (hdev);if (old_state !=DISCOVERY_STARTING )mgmt_discovering (hdev,0 );
@@ -1850,7 +1850,7 @@ int hci_dev_reset_stat(__u16 dev)return ret; } -static void hci_update_scan_state (struct hci_dev *hdev,u8 scan) +static void hci_update_passive_scan_state (struct hci_dev *hdev,u8 scan) {bool conn_changed, discov_changed;
@@ -1951,7 +1951,7 @@ int hci_dev_cmd(unsigned int cmd, void __user *arg)* get correctly modified as this was a non-mgmt change. */ if (!err) -hci_update_scan_state (hdev, dr.dev_opt); +hci_update_passive_scan_state (hdev, dr.dev_opt);break ;case HCISETLINKPOL :
@@ -3096,7 +3096,7 @@ bool hci_add_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor,switch (hci_get_adv_monitor_offload_ext (hdev)) {case HCI_ADV_MONITOR_EXT_NONE : -hci_update_background_scan (hdev); +hci_update_passive_scan (hdev);bt_dev_dbg (hdev,"%s add monitor status %d" , hdev->name, *err);/* Message was not forwarded to controller - not an error */ return false;
@@ -3160,7 +3160,7 @@ bool hci_remove_single_adv_monitor(struct hci_dev *hdev, u16 handle, int *err) pending =hci_remove_adv_monitor (hdev, monitor, handle, err);if (!*err && !pending) -hci_update_background_scan (hdev); +hci_update_passive_scan (hdev);bt_dev_dbg (hdev,"%s remove monitor handle %d, status %d, %spending" , hdev->name, handle, *err, pending ?"" :"not " );
@@ -3192,7 +3192,7 @@ bool hci_remove_all_adv_monitor(struct hci_dev *hdev, int *err) }if (update) -hci_update_background_scan (hdev); +hci_update_passive_scan (hdev);bt_dev_dbg (hdev,"%s remove all monitors status %d, %spending" , hdev->name, *err, pending ?"" :"not " );
@@ -3486,7 +3486,7 @@ void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type)hci_conn_params_free (params); -hci_update_background_scan (hdev); +hci_update_passive_scan (hdev);BT_DBG ("addr %pMR (type %u)" , addr, addr_type); }
net/bluetooth/hci_event.c +2 -2
@@ -3026,7 +3026,7 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)case HCI_AUTO_CONN_ALWAYS :list_del_init (¶ms->action);list_add (¶ms->action, &hdev->pend_le_conns); -hci_update_background_scan (hdev); +hci_update_passive_scan (hdev);break ;default :
@@ -5469,7 +5469,7 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status, } unlock: -hci_update_background_scan (hdev); +hci_update_passive_scan (hdev);hci_dev_unlock (hdev); }
net/bluetooth/hci_sync.c +9 -0
@@ -2029,5 +2029,14 @@ static int update_passive_scan_sync(struct hci_dev *hdev, void *data)int hci_update_passive_scan (struct hci_dev *hdev) { +/* Only queue if it would have any effect */ +if (!test_bit (HCI_UP , &hdev->flags) || +test_bit (HCI_INIT , &hdev->flags) || +hci_dev_test_flag (hdev,HCI_SETUP ) || +hci_dev_test_flag (hdev,HCI_CONFIG ) || +hci_dev_test_flag (hdev,HCI_AUTO_OFF ) || +hci_dev_test_flag (hdev,HCI_UNREGISTER )) +return 0 ; +return hci_cmd_sync_queue (hdev, update_passive_scan_sync,NULL ,NULL ); }
net/bluetooth/mgmt.c +4 -4
@@ -1585,7 +1585,7 @@ static int set_connectable_update_settings(struct hci_dev *hdev,if (changed) {hci_req_update_scan (hdev); -hci_update_background_scan (hdev); +hci_update_passive_scan (hdev);return new_settings (hdev, sk); }
@@ -1943,7 +1943,7 @@ static void le_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode)__hci_req_update_scan_rsp_data (&req,0x00 ); }hci_req_run (&req,NULL ); -hci_update_background_scan (hdev); +hci_update_passive_scan (hdev); } unlock:
@@ -4488,7 +4488,7 @@ int mgmt_add_adv_patterns_monitor_complete(struct hci_dev *hdev, u8 status) hdev->adv_monitors_cnt++;if (monitor->state ==ADV_MONITOR_STATE_NOT_REGISTERED ) monitor->state =ADV_MONITOR_STATE_REGISTERED ; -hci_update_background_scan (hdev); +hci_update_passive_scan (hdev); } err = mgmt_cmd_complete(cmd->sk, cmd->index, cmd->opcode,
@@ -4714,7 +4714,7 @@ int mgmt_remove_adv_monitor_complete(struct hci_dev *hdev, u8 status) rp.monitor_handle = cp->monitor_handle;if (!status) -hci_update_background_scan (hdev); +hci_update_passive_scan (hdev); err =mgmt_cmd_complete (cmd->sk, cmd->index, cmd->opcode,mgmt_status (status), &rp,sizeof (rp));
net/bluetooth/msft.c +1 -1
@@ -168,7 +168,7 @@ static void reregister_monitor(struct hci_dev *hdev, int handle)if (!monitor) {/* All monitors have been reregistered */ msft->reregistering = false; -hci_update_background_scan (hdev); +hci_update_passive_scan (hdev);return ; }
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 7/23 Bluetooth: hci_sync: Convert MGMT_SET_POWERED
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This make use of hci_cmd_sync_queue when MGMT_SET_POWERED is used so all commands are run within hdev->cmd_sync_work instead of hdev->power_on_work and hdev->power_off_work.
In addition to that the power on sequence now takes into account if local IRK needs to be programmed in the resolving list.
Tested with:
tools/mgmt-tester -s "Set powered"
Test Summary
------------
Set powered on - Success Passed Set powered on - Invalid parameters 1 Passed Set powered on - Invalid parameters 2 Passed Set powered on - Invalid parameters 3 Passed Set powered on - Invalid index Passed Set powered on - Privacy and Advertising Passed Set powered off - Success Passed Set powered off - Class of Device Passed Set powered off - Invalid parameters 1 Passed Set powered off - Invalid parameters 2 Passed Set powered off - Invalid parameters 3 Passed
Total: 11, Passed: 11 (100.0%), Failed: 0, Not Run: 0
--- include/net/bluetooth/hci_sync.h | 6 + net/bluetooth/hci_core.c | 45 ++- net/bluetooth/hci_request.c | 3 +- net/bluetooth/hci_sync.c | 584 ++++++++++++++++++++++++++++++- net/bluetooth/mgmt.c | 145 ++++---- 5 files changed, 685 insertions(+), 98 deletions(-)
include/net/bluetooth/hci_sync.h +6 -0
@@ -66,3 +66,9 @@ int hci_disable_advertising_sync(struct hci_dev *hdev);int hci_update_passive_scan_sync (struct hci_dev *hdev);int hci_update_passive_scan (struct hci_dev *hdev); + +int hci_dev_open_sync (struct hci_dev *hdev); +int hci_dev_close_sync (struct hci_dev *hdev); + +int hci_powered_update_sync (struct hci_dev *hdev); +int hci_set_powered_sync (struct hci_dev *hdev,u8 val);
net/bluetooth/hci_core.c +33 -12
100 lines not on this page · raw message
net/bluetooth/hci_request.c +2 -1
@@ -1794,7 +1794,8 @@ int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance)hci_req_add (req,HCI_OP_LE_SET_EXT_ADV_PARAMS ,sizeof (cp), &cp); -if (own_addr_type ==ADDR_LE_DEV_RANDOM && +if ((own_addr_type ==ADDR_LE_DEV_RANDOM || + own_addr_type ==ADDR_LE_DEV_RANDOM_RESOLVED ) &&bacmp (&random_addr,BDADDR_ANY )) {struct hci_cp_le_set_adv_set_rand_addr cp;
net/bluetooth/hci_sync.c +581 -3
617 lines not on this page · raw message
net/bluetooth/mgmt.c +63 -82
191 lines not on this page · raw message
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 8/23 Bluetooth: hci_sync: Convert MGMT_OP_START_DISCOVERY
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This make use of hci_cmd_sync_queue for MGMT_OP_START_DISCOVERY, MGMT_OP_START_SERVICE_DISCOVERY and MGMT_OP_STOP_DISCOVERY to use hci_cmd_sync_queue so they no longer depend on hdev->discov_update work to send any commands.
Tested with:
tools/mgmt-tester -s "Start Discovery"
Test Summary
------------
Start Discovery - Not powered 1 Passed Start Discovery - Invalid parameters 1 Passed Start Discovery - Not supported 1 Passed Start Discovery - Success 1 Passed Start Discovery - Success 2 Passed Start Discovery - Power Off 1 Passed Start Discovery BREDR LE - (Ext Scan Enable) Passed Start Discovery LE - (Ext Scan Enable) Passed Start Discovery LE - (Ext Scan Param) Passed Start Discovery - (2m, Scan Param) Passed Start Discovery - (coded, Scan Param) Passed Start Discovery - (1m, 2m, coded, Scan Param) Passed LL Privacy - Start Discovery 1 (Disable RL) Passed LL Privacy - Start Discovery 2 (Disable RL) Passed
Total: 14, Passed: 14 (100.0%), Failed: 0, Not Run: 0
tools/mgmt-tester -s "Start Service"
Test Summary
------------
Start Service Discovery - Not powered 1 Passed Start Service Discovery - Invalid parameters 1 Passed Start Service Discovery - Not supported 1 Passed Start Service Discovery - Success 1 Passed Start Service Discovery - Success 2 Passed
Total: 5, Passed: 5 (100.0%), Failed: 0, Not Run: 0
tools/mgmt-tester -s "Stop Discovery"
Test Summary
------------
Stop Discovery - Success 1 Passed Stop Discovery - BR/EDR (Inquiry) Success 1 Passed Stop Discovery - Rejected 1 Passed Stop Discovery - Invalid parameters 1 Passed Stop Discovery - (Ext Scan Disable) Passed
Total: 5, Passed: 5 (100.0%), Failed: 0, Not Run: 0
--- include/net/bluetooth/hci_sync.h | 4 + net/bluetooth/hci_conn.c | 4 +- net/bluetooth/hci_event.c | 15 +- net/bluetooth/hci_sync.c | 238 +++++++++++++++++++++++++++++-- net/bluetooth/mgmt.c | 105 ++++++++++---- 5 files changed, 310 insertions(+), 56 deletions(-)
include/net/bluetooth/hci_sync.h +4 -0
@@ -59,6 +59,7 @@ int hci_setup_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance);int hci_start_ext_adv_sync (struct hci_dev *hdev,u8 instance);int hci_enable_ext_advertising_sync (struct hci_dev *hdev,u8 instance);int hci_enable_advertising_sync (struct hci_dev *hdev); +int hci_enable_advertising (struct hci_dev *hdev);int hci_remove_advertising_sync (struct hci_dev *hdev,struct sock *sk,u8 instance,bool force);
@@ -72,3 +73,6 @@ int hci_dev_close_sync(struct hci_dev *hdev);int hci_powered_update_sync (struct hci_dev *hdev);int hci_set_powered_sync (struct hci_dev *hdev,u8 val); + +int hci_start_discovery_sync (struct hci_dev *hdev); +int hci_stop_discovery_sync (struct hci_dev *hdev);
net/bluetooth/hci_conn.c +2 -2
@@ -915,10 +915,10 @@ void hci_le_conn_failed(struct hci_conn *conn, u8 status)*/ hci_update_passive_scan (hdev); -/* Re-enable advertising in case this was a failed connection +/* Enable advertising in case this was a failed connection * attempt as a peripheral. */ -hci_req_reenable_advertising (hdev); +hci_enable_advertising (hdev); }static void create_le_conn_complete (struct hci_dev *hdev,u8 status,u16 opcode)
net/bluetooth/hci_event.c +3 -12
@@ -1512,16 +1512,10 @@ static void le_set_scan_enable_complete(struct hci_dev *hdev, u8 enable)/* The HCI_LE_SCAN_INTERRUPTED flag indicates that we * interrupted scanning due to a connect request. Mark -* therefore discovery as stopped. If this was not -* because of a connect request advertising might have -* been disabled because of active scanning, so -* re-enable it again if necessary. +* therefore discovery as stopped. */ if (hci_dev_test_and_clear_flag (hdev,HCI_LE_SCAN_INTERRUPTED ))hci_discovery_set_state (hdev,DISCOVERY_STOPPED ); -else if (!hci_dev_test_flag (hdev,HCI_LE_ADV ) && - hdev->discovery.state ==DISCOVERY_FINDING ) -hci_req_reenable_advertising (hdev);break ;
@@ -2438,7 +2432,7 @@ static void hci_cs_disconnect(struct hci_dev *hdev, u8 status)if (conn->type ==LE_LINK && conn->role ==HCI_ROLE_SLAVE ) { hdev->cur_adv_instance = conn->adv_instance; -hci_req_reenable_advertising (hdev); +hci_enable_advertising (hdev); }/* If the disconnection failed for any reason, the upper layer
@@ -3048,7 +3042,7 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)*/ if (conn->type ==LE_LINK && conn->role ==HCI_ROLE_SLAVE ) { hdev->cur_adv_instance = conn->adv_instance; -hci_req_reenable_advertising (hdev); +hci_enable_advertising (hdev); }hci_conn_del (conn);
@@ -5498,9 +5492,6 @@ static void hci_le_enh_conn_complete_evt(struct hci_dev *hdev,le16_to_cpu (ev->interval),le16_to_cpu (ev->latency), le16_to_cpu(ev->supervision_timeout)); - -if (hci_dev_test_flag (hdev,HCI_LL_RPA_RESOLUTION )) -hci_req_disable_address_resolution (hdev); }static void hci_le_ext_adv_term_evt (struct hci_dev *hdev,struct sk_buff *skb)
net/bluetooth/hci_sync.c +226 -12
300 lines not on this page · raw message
net/bluetooth/mgmt.c +75 -30
174 lines not on this page · raw message
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 9/23 Bluetooth: hci_sync: Convert MGMT_OP_SET_FAST_CONNECTABLE
In reply to Luiz Augusto von DentzFrom: Brian Gix <[email protected]>
This creates a synchronized Write Fast Connectable call and attaches it to the MGMT_OP_SET_FAST_CONNECTABLE management opcode.
--- include/net/bluetooth/hci_sync.h | 2 + net/bluetooth/hci_sync.c | 2 +- net/bluetooth/mgmt.c | 70 ++++++++++++++------------------ 3 files changed, 33 insertions(+), 41 deletions(-)
include/net/bluetooth/hci_sync.h +2 -0
@@ -68,6 +68,8 @@ int hci_disable_advertising_sync(struct hci_dev *hdev);int hci_update_passive_scan_sync (struct hci_dev *hdev);int hci_update_passive_scan (struct hci_dev *hdev); +int hci_write_fast_connectable_sync (struct hci_dev *hdev,bool enable); +int hci_dev_open_sync (struct hci_dev *hdev);int hci_dev_close_sync (struct hci_dev *hdev);
net/bluetooth/hci_sync.c +1 -1
@@ -2193,7 +2193,7 @@ static int hci_write_auth_enable_sync(struct hci_dev *hdev) HCI_CMD_TIMEOUT); } -static int hci_write_fast_connectable_sync (struct hci_dev *hdev,bool enable) +int hci_write_fast_connectable_sync (struct hci_dev *hdev,bool enable) {struct hci_cp_write_page_scan_activity cp;u8 type;
net/bluetooth/mgmt.c +30 -40
120 lines not on this page · raw message
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 10/23 Bluetooth: hci_sync: Enable synch'd set_bredr
In reply to Luiz Augusto von DentzFrom: Brian Gix <[email protected]>
Uses previously written:
hci_write_fast_connectable_sync
hci_update_scan_sync
hci_update_adv_data_sync
--- include/net/bluetooth/hci_sync.h | 1 + net/bluetooth/hci_sync.c | 2 +- net/bluetooth/mgmt.c | 72 ++++++++++++++++---------------- 3 files changed, 37 insertions(+), 38 deletions(-)
include/net/bluetooth/hci_sync.h +1 -0
@@ -69,6 +69,7 @@ int hci_update_passive_scan_sync(struct hci_dev *hdev);int hci_update_passive_scan (struct hci_dev *hdev);int hci_write_fast_connectable_sync (struct hci_dev *hdev,bool enable); +int hci_update_scan_sync (struct hci_dev *hdev);int hci_dev_open_sync (struct hci_dev *hdev);int hci_dev_close_sync (struct hci_dev *hdev);
net/bluetooth/hci_sync.c +1 -1
@@ -2262,7 +2262,7 @@ static int hci_write_scan_enable_sync(struct hci_dev *hdev, u8 val) HCI_CMD_TIMEOUT); } -static int hci_update_scan_sync (struct hci_dev *hdev) +int hci_update_scan_sync (struct hci_dev *hdev) {u8 scan;
net/bluetooth/mgmt.c +35 -37
107 lines not on this page · raw message
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 11/23 Bluetooth: hci_sync: Convert MGMT_OP_GET_CONN_INFO
In reply to Luiz Augusto von DentzFrom: Brian Gix <[email protected]>
Synchronous version of MGMT_OP_GET_CONN_INFO
Implements:
hci_read_rssi_sync
hci_read_tx_power_sync
--- include/net/bluetooth/hci_sync.h | 2 + net/bluetooth/hci_sync.c | 19 ++++ net/bluetooth/mgmt.c | 148 ++++++++++++------------------- 3 files changed, 79 insertions(+), 90 deletions(-)
include/net/bluetooth/hci_sync.h +2 -0
@@ -67,6 +67,8 @@ int hci_disable_advertising_sync(struct hci_dev *hdev);int hci_update_passive_scan_sync (struct hci_dev *hdev);int hci_update_passive_scan (struct hci_dev *hdev); +int hci_read_rssi_sync (struct hci_dev *hdev,__le16 handle); +int hci_read_tx_power_sync (struct hci_dev *hdev,__le16 handle,u8 type);int hci_write_fast_connectable_sync (struct hci_dev *hdev,bool enable);int hci_update_scan_sync (struct hci_dev *hdev);
net/bluetooth/hci_sync.c +19 -0
@@ -1309,6 +1309,25 @@ int hci_remove_advertising_sync(struct hci_dev *hdev, struct sock *sk,return 0 ; } +int hci_read_rssi_sync (struct hci_dev *hdev,__le16 handle) +{ +struct hci_cp_read_rssi cp; + + cp.handle = handle; +return __hci_cmd_sync_status (hdev,HCI_OP_READ_RSSI , +sizeof (cp), &cp,HCI_CMD_TIMEOUT ); +} + +int hci_read_tx_power_sync (struct hci_dev *hdev,__le16 handle,u8 type) +{ +struct hci_cp_read_tx_power cp; + + cp.handle = handle; + cp.type = type; +return __hci_cmd_sync_status (hdev,HCI_OP_READ_TX_POWER , +sizeof (cp), &cp,HCI_CMD_TIMEOUT ); +} +int hci_disable_advertising_sync (struct hci_dev *hdev) {u8 enable =0x00 ;
net/bluetooth/mgmt.c +58 -90
207 lines not on this page · raw message
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 12/23 Bluetooth: hci_sync: Convert MGMT_OP_SET_SECURE_CONN
In reply to Luiz Augusto von DentzFrom: Brian Gix <[email protected]>
Synchronous version of MGMT_OP_SET_SECURE_CONN.
--- include/net/bluetooth/hci_sync.h | 1 + net/bluetooth/hci_sync.c | 18 ++++++++- net/bluetooth/mgmt.c | 66 ++++++++++++++++---------------- 3 files changed, 49 insertions(+), 36 deletions(-)
include/net/bluetooth/hci_sync.h +1 -0
@@ -69,6 +69,7 @@ int hci_update_passive_scan_sync(struct hci_dev *hdev);int hci_update_passive_scan (struct hci_dev *hdev);int hci_read_rssi_sync (struct hci_dev *hdev,__le16 handle);int hci_read_tx_power_sync (struct hci_dev *hdev,__le16 handle,u8 type); +int hci_write_sc_support_sync (struct hci_dev *hdev,u8 val);int hci_write_fast_connectable_sync (struct hci_dev *hdev,bool enable);int hci_update_scan_sync (struct hci_dev *hdev);
net/bluetooth/hci_sync.c +16 -2
@@ -2104,13 +2104,27 @@ int hci_update_passive_scan(struct hci_dev *hdev)return hci_cmd_sync_queue (hdev, update_passive_scan_sync,NULL ,NULL ); } -static int hci_write_sc_support_sync (struct hci_dev *hdev,u8 val) +int hci_write_sc_support_sync (struct hci_dev *hdev,u8 val) { +int err; +if (!bredr_sc_enabled (hdev) ||lmp_host_sc_capable (hdev))return 0 ; -return __hci_cmd_sync_status (hdev,HCI_OP_WRITE_SC_SUPPORT , + err =__hci_cmd_sync_status (hdev,HCI_OP_WRITE_SC_SUPPORT ,sizeof (val), &val,HCI_CMD_TIMEOUT ); + +if (!err) { +if (val) { + hdev->features[1 ][0 ] |=LMP_HOST_SC ; +hci_dev_set_flag (hdev,HCI_SC_ENABLED ); + }else { + hdev->features[1 ][0 ] &= ~LMP_HOST_SC ; +hci_dev_clear_flag (hdev,HCI_SC_ENABLED ); + } + } + +return err; }static int hci_write_ssp_mode_sync (struct hci_dev *hdev,u8 mode)
net/bluetooth/mgmt.c +32 -34
112 lines not on this page · raw message
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 13/23 Bluetooth: hci_sync: Convert MGMT_OP_GET_CLOCK_INFO
In reply to Luiz Augusto von DentzFrom: Brian Gix <[email protected]>
Synchronous version of MGMT_OP_GET_CLOCK_INFO.
--- include/net/bluetooth/hci_sync.h | 1 + net/bluetooth/hci_sync.c | 6 ++ net/bluetooth/mgmt.c | 121 +++++++++++++------------------ 3 files changed, 58 insertions(+), 70 deletions(-)
include/net/bluetooth/hci_sync.h +1 -0
@@ -70,6 +70,7 @@ int hci_update_passive_scan(struct hci_dev *hdev);int hci_read_rssi_sync (struct hci_dev *hdev,__le16 handle);int hci_read_tx_power_sync (struct hci_dev *hdev,__le16 handle,u8 type);int hci_write_sc_support_sync (struct hci_dev *hdev,u8 val); +int hci_read_clock_sync (struct hci_dev *hdev,struct hci_cp_read_clock *cp);int hci_write_fast_connectable_sync (struct hci_dev *hdev,bool enable);int hci_update_scan_sync (struct hci_dev *hdev);
net/bluetooth/hci_sync.c +6 -0
@@ -1318,6 +1318,12 @@ int hci_read_rssi_sync(struct hci_dev *hdev, __le16 handle) sizeof(cp), &cp, HCI_CMD_TIMEOUT); } +int hci_read_clock_sync (struct hci_dev *hdev,struct hci_cp_read_clock *cp) +{ +return __hci_cmd_sync_status (hdev,HCI_OP_READ_CLOCK , +sizeof (*cp), cp,HCI_CMD_TIMEOUT ); +} +int hci_read_tx_power_sync (struct hci_dev *hdev,__le16 handle,u8 type) {struct hci_cp_read_tx_power cp;
net/bluetooth/mgmt.c +51 -70
177 lines not on this page · raw message
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 14/23 Bluetooth: hci_sync: Convert MGMT_OP_SET_LE
In reply to Luiz Augusto von DentzFrom: Brian Gix <[email protected]>
Uses:
hci_disable_advertising_sync
hci_remove_ext_adv_instance_sync
hci_write_le_host_supported_sync
hci_setup_ext_adv_instance_sync
hci_update_scan_rsp_data_sync
--- include/net/bluetooth/hci_sync.h | 4 ++ net/bluetooth/hci_sync.c | 3 +- net/bluetooth/mgmt.c | 85 ++++++++++++++++---------------- 3 files changed, 48 insertions(+), 44 deletions(-)
include/net/bluetooth/hci_sync.h +4 -0
@@ -75,6 +75,10 @@ int hci_read_clock_sync(struct hci_dev *hdev, struct hci_cp_read_clock *cp);int hci_write_fast_connectable_sync (struct hci_dev *hdev,bool enable);int hci_update_scan_sync (struct hci_dev *hdev); +int hci_write_le_host_supported_sync (struct hci_dev *hdev,u8 le,u8 simul); +int hci_remove_ext_adv_instance_sync (struct hci_dev *hdev,u8 instance, +struct sock *sk); +int hci_dev_open_sync (struct hci_dev *hdev);int hci_dev_close_sync (struct hci_dev *hdev);
net/bluetooth/hci_sync.c +1 -2
@@ -2149,8 +2149,7 @@ static int hci_write_ssp_mode_sync(struct hci_dev *hdev, u8 mode)return hci_write_sc_support_sync (hdev,0x01 ); } -static int hci_write_le_host_supported_sync (struct hci_dev *hdev,u8 le, -u8 simul) +int hci_write_le_host_supported_sync (struct hci_dev *hdev,u8 le,u8 simul) {struct hci_cp_write_le_host_supported cp;
net/bluetooth/mgmt.c +43 -42
133 lines not on this page · raw message
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 15/23 Bluetooth: hci_sync: Convert MGMT_OP_READ_LOCAL_OOB_DATA
In reply to Luiz Augusto von DentzFrom: Brian Gix <[email protected]>
New functions:
hci_read_local_oob_data_sync
This function requires all of the data from the cmd cmplt event to be passed up to the caller via the skb.
mgmt-tester paths:
Read Local OOB Data - Not powered
Read Local OOB Data - Legacy pairing
Read Local OOB Data - Success SSP
Read Local OOB Data - Success SC
--- include/net/bluetooth/hci_sync.h | 2 + net/bluetooth/hci_sync.c | 9 ++++ net/bluetooth/mgmt.c | 72 ++++++++++++++++++++------------ net/bluetooth/mgmt_util.h | 1 + 4 files changed, 58 insertions(+), 26 deletions(-)
include/net/bluetooth/hci_sync.h +2 -0
@@ -78,6 +78,8 @@ int hci_update_scan_sync(struct hci_dev *hdev);int hci_write_le_host_supported_sync (struct hci_dev *hdev,u8 le,u8 simul);int hci_remove_ext_adv_instance_sync (struct hci_dev *hdev,u8 instance,struct sock *sk); +struct sk_buff *hci_read_local_oob_data_sync (struct hci_dev *hdev,bool ext, +struct sock *sk);int hci_dev_open_sync (struct hci_dev *hdev);int hci_dev_close_sync (struct hci_dev *hdev);
net/bluetooth/hci_sync.c +9 -0
@@ -1703,6 +1703,15 @@ static int hci_resume_advertising_sync(struct hci_dev *hdev)return err; } +struct sk_buff *hci_read_local_oob_data_sync (struct hci_dev *hdev, +bool extended,struct sock *sk) +{ +u16 opcode = extended ?HCI_OP_READ_LOCAL_OOB_EXT_DATA : +HCI_OP_READ_LOCAL_OOB_DATA ; + +return __hci_cmd_sync_sk (hdev, opcode,0 ,NULL ,0 ,HCI_CMD_TIMEOUT , sk); +} +/* Device must not be scanning when updating the accept list. * * Update is done using the following sequence:
net/bluetooth/mgmt.c +46 -26
110 lines not on this page · raw message
net/bluetooth/mgmt_util.h +1 -0
@@ -27,6 +27,7 @@ struct mgmt_pending_cmd {void *param;size_t param_len;struct sock *sk; +struct sk_buff *skb;void *user_data;int (*cmd_complete)(struct mgmt_pending_cmd *cmd,u8 status); };
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 16/23 Bluetooth: hci_sync: Convert MGMT_OP_READ_LOCAL_OOB_EXT_DATA
In reply to Luiz Augusto von DentzFrom: Brian Gix <[email protected]>
Uses existing *_sync functions
mgmt-test paths:
Read Local OOB Ext Data - Invalid index Read Local OOB Ext Data - Legacy pairing Read Local OOB Ext Data - Success SSP Read Local OOB Ext Data - Success SC
--- net/bluetooth/mgmt.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-)
net/bluetooth/mgmt.c +20 -17
@@ -7364,21 +7364,27 @@ static int set_public_address(struct sock *sk, struct hci_dev *hdev,return err; } -static void read_local_oob_ext_data_complete (struct hci_dev *hdev,u8 status, -u16 opcode,struct sk_buff *skb) +static void read_local_oob_ext_data_complete (struct hci_dev *hdev,void *data, +int err) {const struct mgmt_cp_read_local_oob_ext_data *mgmt_cp;struct mgmt_rp_read_local_oob_ext_data *mgmt_rp;u8 *h192, *r192, *h256, *r256; -struct mgmt_pending_cmd *cmd; +struct mgmt_pending_cmd *cmd = data; +struct sk_buff *skb = cmd->skb; +u8 status =mgmt_status (err);u16 eir_len; -int err; -bt_dev_dbg (hdev,"status %u" , status); +if (!status) { +if (!skb) + status =MGMT_STATUS_FAILED ; +else if (IS_ERR (skb)) + status =mgmt_status (PTR_ERR (skb)); +else + status =mgmt_status (skb->data[0 ]); + } - cmd =pending_find (MGMT_OP_READ_LOCAL_OOB_EXT_DATA , hdev); -if (!cmd) -return ; +bt_dev_dbg (hdev,"status %u" , status); mgmt_cp = cmd->param;
@@ -7390,7 +7396,7 @@ static void read_local_oob_ext_data_complete(struct hci_dev *hdev, u8 status, r192 =NULL ; h256 =NULL ; r256 =NULL ; - }else if (opcode ==HCI_OP_READ_LOCAL_OOB_DATA ) { + }else if (!bredr_sc_enabled (hdev)) {struct hci_rp_read_local_oob_data *rp;if (skb->len !=sizeof (*rp)) {
@@ -7471,6 +7477,9 @@ static void read_local_oob_ext_data_complete(struct hci_dev *hdev, u8 status, mgmt_rp,sizeof (*mgmt_rp) + eir_len, HCI_MGMT_OOB_DATA_EVENTS, cmd->sk); done: +if (skb && !IS_ERR (skb)) +kfree_skb (skb); +kfree (mgmt_rp);mgmt_pending_remove (cmd); }
@@ -7479,7 +7488,6 @@ static int read_local_ssp_oob_req(struct hci_dev *hdev, struct sock *sk, struct mgmt_cp_read_local_oob_ext_data *cp) {struct mgmt_pending_cmd *cmd; -struct hci_request req;int err; cmd = mgmt_pending_add(sk, MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev,
@@ -7487,14 +7495,9 @@ static int read_local_ssp_oob_req(struct hci_dev *hdev, struct sock *sk,if (!cmd)return -ENOMEM ; -hci_req_init (&req, hdev); - -if (bredr_sc_enabled (hdev)) -hci_req_add (&req,HCI_OP_READ_LOCAL_OOB_EXT_DATA ,0 ,NULL ); -else -hci_req_add (&req,HCI_OP_READ_LOCAL_OOB_DATA ,0 ,NULL ); + err =hci_cmd_sync_queue (hdev, read_local_oob_data_sync, cmd, + read_local_oob_ext_data_complete); - err =hci_req_run_skb (&req, read_local_oob_ext_data_complete);if (err <0 ) {mgmt_pending_remove (cmd);return err;
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 17/23 Bluetooth: hci_sync: Convert MGMT_OP_SET_LOCAL_NAME
In reply to Luiz Augusto von DentzFrom: Brian Gix <[email protected]>
Uses existing *_sync functions, but made hci_update_name_sync non-static.
mgmt-test paths:
Set Advertising on - Local name 1
Set Advertising on - Name + Appear 1
Set Local Name - Success 1
Set Local Name - Success 2
Set Local Name - Success 3
Add Advertising - Success (Empty ScRsp) Add Advertising - Success (Complete name) Add Advertising - Success (Shortened name) Add Advertising - Success (Short name)
Add Advertising - Success (Name + data) Add Advertising - Invalid Params (Name + data) Add Advertising - Success (Name+data+appear) Read Ext Controller Info 3
Read Ext Controller Info 4
Read Ext Controller Info 5
Add Ext Advertising - Success (Empty ScRsp) Add Ext Advertising - Success (Complete name) Add Ext Advertising - Success (Shortened name) Add Ext Advertising - Success (Short name) Add Ext Advertising - Success (Name + data) Add Ext Advertising - Invalid Params (Name + data) Add Ext Advertising - Success (Name+data+appear)
--- include/net/bluetooth/hci_sync.h | 1 + net/bluetooth/hci_sync.c | 2 +- net/bluetooth/mgmt.c | 65 ++++++++++++++++---------------- 3 files changed, 34 insertions(+), 34 deletions(-)
include/net/bluetooth/hci_sync.h +1 -0
@@ -46,6 +46,7 @@ int hci_update_class_sync(struct hci_dev *hdev);int hci_update_eir_sync (struct hci_dev *hdev);int hci_update_class_sync (struct hci_dev *hdev); +int hci_update_name_sync (struct hci_dev *hdev);int hci_update_random_address_sync (struct hci_dev *hdev,bool require_privacy,bool rpa,u8 *own_addr_type);
net/bluetooth/hci_sync.c +1 -1
@@ -2341,7 +2341,7 @@ int hci_update_scan_sync(struct hci_dev *hdev)return hci_write_scan_enable_sync (hdev, scan); } -static int hci_update_name_sync (struct hci_dev *hdev) +int hci_update_name_sync (struct hci_dev *hdev) {struct hci_cp_write_local_name cp;
net/bluetooth/mgmt.c +32 -33
101 lines not on this page · raw message
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 18/23 Bluetooth: hci_sync: Convert MGMT_OP_SET_PHY_CONFIGURATION
In reply to Luiz Augusto von DentzFrom: Brian Gix <[email protected]>
mgmt-test paths:
Set PHY 2m Success
Set PHY coded Succcess
Set PHY 1m 2m coded Succcess
Set PHY 2m tx success
Set PHY 2m rx success
Set PHY Invalid Param
Start Discovery - (2m, Scan Param)
Start Discovery - (coded, Scan Param)
Start Discovery - (1m, 2m, coded, Scan Param)
--- net/bluetooth/mgmt.c | 116 ++++++++++++++++++++++++------------------- 1 file changed, 66 insertions(+), 50 deletions(-)
net/bluetooth/mgmt.c +66 -50
@@ -3414,23 +3414,26 @@ int mgmt_phy_configuration_changed(struct hci_dev *hdev, struct sock *skip) sizeof(ev), skip); } -static void set_default_phy_complete (struct hci_dev *hdev,u8 status, -u16 opcode,struct sk_buff *skb) +static void set_default_phy_complete (struct hci_dev *hdev,void *data,int err) { -struct mgmt_pending_cmd *cmd; - -bt_dev_dbg (hdev,"status 0x%02x" , status); +struct mgmt_pending_cmd *cmd = data; +struct sk_buff *skb = cmd->skb; +u8 status =mgmt_status (err); -hci_dev_lock (hdev); +if (!status) { +if (!skb) + status =MGMT_STATUS_FAILED ; +else if (IS_ERR (skb)) + status =mgmt_status (PTR_ERR (skb)); +else + status =mgmt_status (skb->data[0 ]); + } - cmd =pending_find (MGMT_OP_SET_PHY_CONFIGURATION , hdev); -if (!cmd) - goto unlock; +bt_dev_dbg (hdev,"status %d" , status);if (status) {mgmt_cmd_status (cmd->sk, hdev->id, -MGMT_OP_SET_PHY_CONFIGURATION , -mgmt_status (status)); +MGMT_OP_SET_PHY_CONFIGURATION , status); }else { mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_SET_PHY_CONFIGURATION, 0,
@@ -3439,19 +3442,56 @@ static void set_default_phy_complete(struct hci_dev *hdev, u8 status,mgmt_phy_configuration_changed (hdev, cmd->sk); } +if (skb && !IS_ERR (skb)) +kfree_skb (skb); +mgmt_pending_remove (cmd); +} -unlock: -hci_dev_unlock (hdev); +static int set_default_phy_sync (struct hci_dev *hdev,void *data) +{ +struct mgmt_pending_cmd *cmd = data; +struct mgmt_cp_set_phy_configuration *cp = cmd->param; +struct hci_cp_le_set_default_phy cp_phy; +u32 selected_phys =__le32_to_cpu (cp->selected_phys); + +memset (&cp_phy,0 ,sizeof (cp_phy)); + +if (!(selected_phys &MGMT_PHY_LE_TX_MASK )) + cp_phy.all_phys |=0x01 ; + +if (!(selected_phys &MGMT_PHY_LE_RX_MASK )) + cp_phy.all_phys |=0x02 ; + +if (selected_phys &MGMT_PHY_LE_1M_TX ) + cp_phy.tx_phys |=HCI_LE_SET_PHY_1M ; + +if (selected_phys &MGMT_PHY_LE_2M_TX ) + cp_phy.tx_phys |=HCI_LE_SET_PHY_2M ; + +if (selected_phys &MGMT_PHY_LE_CODED_TX ) + cp_phy.tx_phys |=HCI_LE_SET_PHY_CODED ; + +if (selected_phys &MGMT_PHY_LE_1M_RX ) + cp_phy.rx_phys |=HCI_LE_SET_PHY_1M ; + +if (selected_phys &MGMT_PHY_LE_2M_RX ) + cp_phy.rx_phys |=HCI_LE_SET_PHY_2M ; + +if (selected_phys &MGMT_PHY_LE_CODED_RX ) + cp_phy.rx_phys |=HCI_LE_SET_PHY_CODED ; + + cmd->skb =__hci_cmd_sync (hdev,HCI_OP_LE_SET_DEFAULT_PHY , +sizeof (cp_phy), &cp_phy,HCI_CMD_TIMEOUT ); + +return 0 ; }static int set_phy_configuration (struct sock *sk,struct hci_dev *hdev,void *data,u16 len) {struct mgmt_cp_set_phy_configuration *cp = data; -struct hci_cp_le_set_default_phy cp_phy;struct mgmt_pending_cmd *cmd; -struct hci_request req;u32 selected_phys, configurable_phys, supported_phys, unconfigure_phys;u16 pkt_type = (HCI_DH1 |HCI_DM1 );bool changed = false;
@@ -3555,44 +3595,20 @@ static int set_phy_configuration(struct sock *sk, struct hci_dev *hdev, cmd =mgmt_pending_add (sk,MGMT_OP_SET_PHY_CONFIGURATION , hdev, data, len); -if (!cmd) { +if (!cmd) err = -ENOMEM ; - goto unlock; - } - -hci_req_init (&req, hdev); - -memset (&cp_phy,0 ,sizeof (cp_phy)); - -if (!(selected_phys &MGMT_PHY_LE_TX_MASK )) - cp_phy.all_phys |=0x01 ; - -if (!(selected_phys &MGMT_PHY_LE_RX_MASK )) - cp_phy.all_phys |=0x02 ; - -if (selected_phys &MGMT_PHY_LE_1M_TX ) - cp_phy.tx_phys |=HCI_LE_SET_PHY_1M ; - -if (selected_phys &MGMT_PHY_LE_2M_TX ) - cp_phy.tx_phys |=HCI_LE_SET_PHY_2M ; - -if (selected_phys &MGMT_PHY_LE_CODED_TX ) - cp_phy.tx_phys |=HCI_LE_SET_PHY_CODED ; - -if (selected_phys &MGMT_PHY_LE_1M_RX ) - cp_phy.rx_phys |=HCI_LE_SET_PHY_1M ; - -if (selected_phys &MGMT_PHY_LE_2M_RX ) - cp_phy.rx_phys |=HCI_LE_SET_PHY_2M ; - -if (selected_phys &MGMT_PHY_LE_CODED_RX ) - cp_phy.rx_phys |=HCI_LE_SET_PHY_CODED ; +else + err =hci_cmd_sync_queue (hdev, set_default_phy_sync, cmd, + set_default_phy_complete); -hci_req_add (&req,HCI_OP_LE_SET_DEFAULT_PHY ,sizeof (cp_phy), &cp_phy); +if (err <0 ) { + err =mgmt_cmd_status (sk, hdev->id, +MGMT_OP_SET_PHY_CONFIGURATION , +MGMT_STATUS_FAILED ); - err =hci_req_run_skb (&req, set_default_phy_complete); -if (err <0 ) -mgmt_pending_remove (cmd); +if (cmd) +mgmt_pending_remove (cmd); + } unlock:hci_dev_unlock (hdev);
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 19/23 Bluetooth: hci_sync: Convert MGMT_OP_SET_ADVERTISING
In reply to Luiz Augusto von DentzFrom: Brian Gix <[email protected]>
mgmt-test paths:
Set powered on - Privacy and Advertising Set Advertising on - Success 2
Set Advertising on - Appearance 1 Set Advertising on - Local name 1 Set Advertising on - Name + Appear 1 Add Advertising - Success 4
Add Advertising - Success 5
Add Ext Advertising - Success 4 Add Ext Advertising - Success 5
--- net/bluetooth/mgmt.c | 103 ++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 55 deletions(-)
net/bluetooth/mgmt.c +48 -55
@@ -5608,29 +5608,25 @@ static int set_device_id(struct sock *sk, struct hci_dev *hdev, void *data,return err; } -static void enable_advertising_instance (struct hci_dev *hdev,u8 status, -u16 opcode) +static void enable_advertising_instance (struct hci_dev *hdev,int err) { -bt_dev_dbg (hdev,"status %u" , status); +if (err) +bt_dev_err (hdev,"failed to re-configure advertising %d" , err); +else +bt_dev_dbg (hdev,"status %d" , err); } -static void set_advertising_complete (struct hci_dev *hdev,u8 status, -u16 opcode) +static void set_advertising_complete (struct hci_dev *hdev,void *data,int err) {struct cmd_lookup match = {NULL , hdev }; -struct hci_request req;u8 instance;struct adv_info *adv_instance; -int err; - -hci_dev_lock (hdev); +u8 status =mgmt_status (err);if (status) { -u8 mgmt_err =mgmt_status (status); -mgmt_pending_foreach (MGMT_OP_SET_ADVERTISING , hdev, - cmd_status_rsp, &mgmt_err); - goto unlock; + cmd_status_rsp, &status); +return ; }if (hci_dev_test_flag (hdev,HCI_LE_ADV ))
@@ -5662,30 +5658,55 @@ static void set_advertising_complete(struct hci_dev *hdev, u8 status,*/ if (hci_dev_test_flag (hdev,HCI_ADVERTISING ) ||list_empty (&hdev->adv_instances)) - goto unlock; +return ; instance = hdev->cur_adv_instance;if (!instance) { adv_instance =list_first_entry_or_null (&hdev->adv_instances, struct adv_info, list);if (!adv_instance) - goto unlock; +return ; instance = adv_instance->instance; } -hci_req_init (&req, hdev); + err =hci_schedule_adv_instance_sync (hdev, instance, true); + +enable_advertising_instance (hdev, err); +} - err =__hci_req_schedule_adv_instance (&req, instance, true); +static int set_adv_sync (struct hci_dev *hdev,void *data) +{ +struct mgmt_pending_cmd *cmd = data; +struct mgmt_mode *cp = cmd->param; +u8 val = !!cp->val; -if (!err) - err =hci_req_run (&req, enable_advertising_instance); +if (cp->val ==0x02 ) +hci_dev_set_flag (hdev,HCI_ADVERTISING_CONNECTABLE ); +else +hci_dev_clear_flag (hdev,HCI_ADVERTISING_CONNECTABLE ); -if (err) -bt_dev_err (hdev,"failed to re-configure advertising" ); +cancel_adv_timeout (hdev); -unlock: -hci_dev_unlock (hdev); +if (val) { +/* Switch to instance "0" for the Set Advertising setting. +* We cannot use update_[adv|scan_rsp]_data() here as the +* HCI_ADVERTISING flag is not yet set. +*/ + hdev->cur_adv_instance =0x00 ; + +if (ext_adv_capable (hdev)) { +hci_start_ext_adv_sync (hdev,0x00 ); + }else { +hci_update_adv_data_sync (hdev,0x00 ); +hci_update_scan_rsp_data_sync (hdev,0x00 ); +hci_enable_advertising_sync (hdev); + } + }else { +hci_disable_advertising_sync (hdev); + } + +return 0 ; } static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data,
@@ -5693,7 +5714,6 @@ static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data, {struct mgmt_mode *cp = data;struct mgmt_pending_cmd *cmd; -struct hci_request req;u8 val, status;int err;
@@ -5759,40 +5779,13 @@ static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data, } cmd =mgmt_pending_add (sk,MGMT_OP_SET_ADVERTISING , hdev, data, len); -if (!cmd) { +if (!cmd) err = -ENOMEM ; - goto unlock; - } - -hci_req_init (&req, hdev); - -if (cp->val ==0x02 ) -hci_dev_set_flag (hdev,HCI_ADVERTISING_CONNECTABLE );else -hci_dev_clear_flag (hdev,HCI_ADVERTISING_CONNECTABLE ); - -cancel_adv_timeout (hdev); + err =hci_cmd_sync_queue (hdev, set_adv_sync, cmd, + set_advertising_complete); -if (val) { -/* Switch to instance "0" for the Set Advertising setting. -* We cannot use update_[adv|scan_rsp]_data() here as the -* HCI_ADVERTISING flag is not yet set. -*/ - hdev->cur_adv_instance =0x00 ; - -if (ext_adv_capable (hdev)) { -__hci_req_start_ext_adv (&req,0x00 ); - }else { -__hci_req_update_adv_data (&req,0x00 ); -__hci_req_update_scan_rsp_data (&req,0x00 ); -__hci_req_enable_advertising (&req); - } - }else { -__hci_req_disable_advertising (&req); - } - - err =hci_req_run (&req, set_advertising_complete); -if (err <0 ) +if (err <0 && cmd)mgmt_pending_remove (cmd); unlock:
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 20/23 Bluetooth: hci_sync: Convert adv_expire
In reply to Luiz Augusto von DentzFrom: Brian Gix <[email protected]>
mgmt-test paths:
Set Advertising on - Appearance 1
Set Advertising on - Local name 1
Set Advertising on - Name + Appear 1
Set Local Name - Success 2
Set Local Name - Success 3
Add Advertising - Success (Empty ScRsp)
Add Advertising - Success (ScRsp appear)
Add Advertising - Invalid Params (ScRsp appear long) Add Advertising - Success (Complete name)
Add Advertising - Success (Shortened name)
Add Advertising - Success (Short name)
Add Advertising - Success (Name + data)
Add Advertising - Invalid Params (Name + data) Add Advertising - Success (Name+data+appear) Set appearance - BR/EDR LE
Set appearance - LE only
Add Ext Advertising - Success (Empty ScRsp)
Add Ext Advertising - Success (ScRsp appear) Add Ext Advertising - Invalid Params (ScRsp appear long) Add Ext Advertising - Success (Complete name) Add Ext Advertising - Success (Shortened name) Add Ext Advertising - Success (Short name)
Add Ext Advertising - Success (Name + data)
Add Ext Advertising - Invalid Params (Name + data) Add Ext Advertising - Success (Name+data+appear)
--- net/bluetooth/mgmt.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-)
net/bluetooth/mgmt.c +19 -14
@@ -3217,33 +3217,32 @@ static int user_passkey_neg_reply(struct sock *sk, struct hci_dev *hdev, HCI_OP_USER_PASSKEY_NEG_REPLY, 0); } -static void adv_expire (struct hci_dev *hdev,u32 flags) +static int adv_expire_sync (struct hci_dev *hdev,u32 flags) {struct adv_info *adv_instance; -struct hci_request req; -int err; adv_instance =hci_find_adv_instance (hdev, hdev->cur_adv_instance);if (!adv_instance) -return ; +return 0 ;/* stop if current instance doesn't need to be changed */ if (!(adv_instance->flags & flags)) -return ; +return 0 ;cancel_adv_timeout (hdev); adv_instance =hci_get_next_instance (hdev, adv_instance->instance);if (!adv_instance) -return ; +return 0 ; -hci_req_init (&req, hdev); - err =__hci_req_schedule_adv_instance (&req, adv_instance->instance, - true); -if (err) -return ; +hci_schedule_adv_instance_sync (hdev, adv_instance->instance, true); -hci_req_run (&req,NULL ); +return 0 ; +} + +static int name_changed_sync (struct hci_dev *hdev,void *data) +{ +return adv_expire_sync (hdev,MGMT_ADV_FLAG_LOCAL_NAME ); }static void set_name_complete (struct hci_dev *hdev,void *data,int err)
@@ -3262,7 +3261,7 @@ static void set_name_complete(struct hci_dev *hdev, void *data, int err) cp, sizeof(*cp));if (hci_dev_test_flag (hdev,HCI_LE_ADV )) -adv_expire (hdev,MGMT_ADV_FLAG_LOCAL_NAME ); +hci_cmd_sync_queue (hdev, name_changed_sync,NULL ,NULL ); }mgmt_pending_remove (cmd);
@@ -3347,6 +3346,11 @@ static int set_local_name(struct sock *sk, struct hci_dev *hdev, void *data,return err; } +static int appearance_changed_sync (struct hci_dev *hdev,void *data) +{ +return adv_expire_sync (hdev,MGMT_ADV_FLAG_APPEARANCE ); +} +static int set_appearance (struct sock *sk,struct hci_dev *hdev,void *data,u16 len) {
@@ -3368,7 +3372,8 @@ static int set_appearance(struct sock *sk, struct hci_dev *hdev, void *data, hdev->appearance = appearance;if (hci_dev_test_flag (hdev,HCI_LE_ADV )) -adv_expire (hdev,MGMT_ADV_FLAG_APPEARANCE ); +hci_cmd_sync_queue (hdev, appearance_changed_sync,NULL , +NULL );ext_info_changed (hdev, sk); }
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 21/23 Bluetooth: hci_sync: Convert MGMT_OP_SSP
In reply to Luiz Augusto von DentzFrom: Brian Gix <[email protected]>
mgmt-tester paths:
Set SSP on - Success 2
Set Device ID - SSP off and Power on
--- include/net/bluetooth/hci_core.h | 1 - include/net/bluetooth/hci_sync.h | 1 + net/bluetooth/hci_event.c | 4 +- net/bluetooth/hci_sync.c | 7 +- net/bluetooth/mgmt.c | 150 +++++++++++++++---------------- 5 files changed, 80 insertions(+), 83 deletions(-)
include/net/bluetooth/hci_core.h +0 -1
@@ -1806,7 +1806,6 @@ int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 entered);void mgmt_auth_failed (struct hci_conn *conn,u8 status);void mgmt_auth_enable_complete (struct hci_dev *hdev,u8 status); -void mgmt_ssp_enable_complete (struct hci_dev *hdev,u8 enable,u8 status);void mgmt_set_class_of_dev_complete (struct hci_dev *hdev,u8 *dev_class,u8 status);void mgmt_set_local_name_complete (struct hci_dev *hdev,u8 *name,u8 status);
include/net/bluetooth/hci_sync.h +1 -0
@@ -47,6 +47,7 @@ int hci_update_class_sync(struct hci_dev *hdev);int hci_update_eir_sync (struct hci_dev *hdev);int hci_update_class_sync (struct hci_dev *hdev);int hci_update_name_sync (struct hci_dev *hdev); +int hci_write_ssp_mode_sync (struct hci_dev *hdev,u8 mode);int hci_update_random_address_sync (struct hci_dev *hdev,bool require_privacy,bool rpa,u8 *own_addr_type);
net/bluetooth/hci_event.c +1 -3
@@ -545,9 +545,7 @@ static void hci_cc_write_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb) hdev->features[1 ][0 ] &= ~LMP_HOST_SSP ; } -if (hci_dev_test_flag (hdev,HCI_MGMT )) -mgmt_ssp_enable_complete (hdev, sent->mode, status); -else if (!status) { +if (!status) {if (sent->mode)hci_dev_set_flag (hdev,HCI_SSP_ENABLED );else
net/bluetooth/hci_sync.c +6 -1
@@ -2142,7 +2142,7 @@ int hci_write_sc_support_sync(struct hci_dev *hdev, u8 val)return err; } -static int hci_write_ssp_mode_sync (struct hci_dev *hdev,u8 mode) +int hci_write_ssp_mode_sync (struct hci_dev *hdev,u8 mode) {int err;
@@ -2150,6 +2150,11 @@ static int hci_write_ssp_mode_sync(struct hci_dev *hdev, u8 mode) lmp_host_ssp_capable(hdev))return 0 ; +if (!mode &&hci_dev_test_flag (hdev,HCI_USE_DEBUG_KEYS )) { +__hci_cmd_sync_status (hdev,HCI_OP_WRITE_SSP_DEBUG_MODE , +sizeof (mode), &mode,HCI_CMD_TIMEOUT ); + } + err =__hci_cmd_sync_status (hdev,HCI_OP_WRITE_SSP_MODE ,sizeof (mode), &mode,HCI_CMD_TIMEOUT );if (err)
net/bluetooth/mgmt.c +72 -78
171 lines not on this page · raw message
Signature · 1 line
2.31.1
Luiz Augusto von Dentz
maintainerPATCH v8 22/23 Bluetooth: hci_sync: Rework init stages
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This moves the init stages to use the hci_sync infra and in addition to that have the stages as function tables so it is easier to change the command sequence.
--- include/net/bluetooth/hci_sync.h | 1 + net/bluetooth/hci_core.c | 1203 +---------------- net/bluetooth/hci_sync.c | 2053 +++++++++++++++++++++++++++--- 3 files changed, 1854 insertions(+), 1403 deletions(-)
include/net/bluetooth/hci_sync.h +1 -0
@@ -83,6 +83,7 @@ int hci_remove_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance,struct sk_buff *hci_read_local_oob_data_sync (struct hci_dev *hdev,bool ext,struct sock *sk); +int hci_reset_sync (struct hci_dev *hdev);int hci_dev_open_sync (struct hci_dev *hdev);int hci_dev_close_sync (struct hci_dev *hdev);
net/bluetooth/hci_core.c +1 -1202
1,227 lines not on this page · raw message
net/bluetooth/hci_sync.c +1852 -201
1,766 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.31.1
Part of the diff is not shown here. View the raw message.
Luiz Augusto von Dentz
maintainerPATCH v8 23/23 Bluetooth: hci_sync: Rework hci_suspend_notifier
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This makes hci_suspend_notifier use the hci_*_sync which can be executed synchronously which is allowed in the suspend_notifier and simplifies a lot of the handling since the status of each command can be checked inline so no other work need to be scheduled thus can be performed without using of a state machine.
--- include/net/bluetooth/hci_core.h | 4 - include/net/bluetooth/hci_sync.h | 3 + net/bluetooth/hci_conn.c | 10 - net/bluetooth/hci_core.c | 106 +------ net/bluetooth/hci_event.c | 71 +++-- net/bluetooth/hci_request.c | 237 -------------- net/bluetooth/hci_sync.c | 294 +++++++++++++++++- net/bluetooth/mgmt.c | 39 +-- net/bluetooth/msft.c | 509 ++++++++++++++++++------------- net/bluetooth/msft.h | 15 +- 10 files changed, 650 insertions(+), 638 deletions(-)
include/net/bluetooth/hci_core.h +0 -4
@@ -523,7 +523,6 @@ struct hci_dev {bool advertising_paused;struct notifier_block suspend_notifier; -struct work_struct suspend_prepare;enum suspended_state suspend_state_next;enum suspended_state suspend_state;bool scanning_paused;
@@ -532,9 +531,6 @@ struct hci_dev {bdaddr_t wake_addr;u8 wake_addr_type; -wait_queue_head_t suspend_wait_q; -DECLARE_BITMAP (suspend_tasks, __SUSPEND_NUM_TASKS); -struct hci_conn_hash conn_hash;struct list_head mgmt_pending;
include/net/bluetooth/hci_sync.h +3 -0
@@ -92,3 +92,6 @@ int hci_set_powered_sync(struct hci_dev *hdev, u8 val);int hci_start_discovery_sync (struct hci_dev *hdev);int hci_stop_discovery_sync (struct hci_dev *hdev); + +int hci_suspend_sync (struct hci_dev *hdev); +int hci_resume_sync (struct hci_dev *hdev);
net/bluetooth/hci_conn.c +0 -10
@@ -900,16 +900,6 @@ void hci_le_conn_failed(struct hci_conn *conn, u8 status)hci_conn_del (conn); -/* The suspend notifier is waiting for all devices to disconnect and an -* LE connect cancel will result in an hci_le_conn_failed. Once the last -* connection is deleted, we should also wake the suspend queue to -* complete suspend operations. -*/ -if (list_empty (&hdev->conn_hash.list) && -test_and_clear_bit (SUSPEND_DISCONNECTING , hdev->suspend_tasks)) { -wake_up (&hdev->suspend_wait_q); - } -/* Since we may have temporarily stopped the background scanning in * favor of connection establishment, we should restart it. */
net/bluetooth/hci_core.c +12 -94
155 lines not on this page · raw message
net/bluetooth/hci_event.c +53 -18
105 lines not on this page · raw message
net/bluetooth/hci_request.c +0 -237
261 lines not on this page · raw message
net/bluetooth/hci_sync.c +278 -16
376 lines not on this page · raw message
net/bluetooth/mgmt.c +1 -38
@@ -5171,13 +5171,6 @@ void mgmt_start_discovery_complete(struct hci_dev *hdev, u8 status) }hci_dev_unlock (hdev); - -/* Handle suspend notifier */ -if (test_and_clear_bit (SUSPEND_UNPAUSE_DISCOVERY , - hdev->suspend_tasks)) { -bt_dev_dbg (hdev,"Unpaused discovery" ); -wake_up (&hdev->suspend_wait_q); - } } static bool discovery_type_is_valid(struct hci_dev *hdev, uint8_t type,
@@ -5217,14 +5210,7 @@ static void start_discovery_complete(struct hci_dev *hdev, void *data, int err) cmd->param, 1);mgmt_pending_free (cmd); -/* Handle suspend notifier */ -if (test_and_clear_bit (SUSPEND_UNPAUSE_DISCOVERY , - hdev->suspend_tasks)) { -bt_dev_dbg (hdev,"Unpaused discovery" ); -wake_up (&hdev->suspend_wait_q); - } - -hci_discovery_set_state (hdev, err ?DISCOVERY_STOPPED : +hci_discovery_set_state (hdev, err ?DISCOVERY_STOPPED :DISCOVERY_FINDING ); }
@@ -5446,12 +5432,6 @@ void mgmt_stop_discovery_complete(struct hci_dev *hdev, u8 status) }hci_dev_unlock (hdev); - -/* Handle suspend notifier */ -if (test_and_clear_bit (SUSPEND_PAUSE_DISCOVERY , hdev->suspend_tasks)) { -bt_dev_dbg (hdev,"Paused discovery" ); -wake_up (&hdev->suspend_wait_q); - } }static void stop_discovery_complete (struct hci_dev *hdev,void *data,int err)
@@ -5464,12 +5444,6 @@ static void stop_discovery_complete(struct hci_dev *hdev, void *data, int err) cmd->param, 1);mgmt_pending_free (cmd); -/* Handle suspend notifier */ -if (test_and_clear_bit (SUSPEND_PAUSE_DISCOVERY , hdev->suspend_tasks)) { -bt_dev_dbg (hdev,"Paused discovery" ); -wake_up (&hdev->suspend_wait_q); - } -if (!err)hci_discovery_set_state (hdev,DISCOVERY_STOPPED ); }
@@ -5709,17 +5683,6 @@ static void set_advertising_complete(struct hci_dev *hdev, void *data, int err)if (match.sk)sock_put (match.sk); -/* Handle suspend notifier */ -if (test_and_clear_bit (SUSPEND_PAUSE_ADVERTISING , - hdev->suspend_tasks)) { -bt_dev_dbg (hdev,"Paused advertising" ); -wake_up (&hdev->suspend_wait_q); - }else if (test_and_clear_bit (SUSPEND_UNPAUSE_ADVERTISING , - hdev->suspend_tasks)) { -bt_dev_dbg (hdev,"Unpaused advertising" ); -wake_up (&hdev->suspend_wait_q); - } -/* If "Set Advertising" was just disabled and instance advertising was * set up earlier, then re-enable multi-instance advertising. */
net/bluetooth/msft.c +292 -217
588 lines not on this page · raw message
net/bluetooth/msft.h +11 -4
@@ -24,8 +24,8 @@ int msft_remove_monitor(struct hci_dev *hdev, struct adv_monitor *monitor, u16 handle);void msft_req_add_set_filter_enable (struct hci_request *req,bool enable);int msft_set_filter_enable (struct hci_dev *hdev,bool enable); -void msft_suspend (struct hci_dev *hdev); -void msft_resume (struct hci_dev *hdev); +int msft_suspend_sync (struct hci_dev *hdev); +int msft_resume_sync (struct hci_dev *hdev);bool msft_curve_validity (struct hci_dev *hdev);#else
@@ -61,8 +61,15 @@ static inline int msft_set_filter_enable(struct hci_dev *hdev, bool enable)return -EOPNOTSUPP ; } -static inline void msft_suspend (struct hci_dev *hdev) {} -static inline void msft_resume (struct hci_dev *hdev) {} +static inline int msft_suspend_sync (struct hci_dev *hdev) +{ +return -EOPNOTSUPP ; +} + +static inline int msft_resume_sync (struct hci_dev *hdev) +{ +return -EOPNOTSUPP ; +}static inline bool msft_curve_validity (struct hci_dev *hdev) {
Signature · 1 line
2.31.1
Marcel Holtmann
maintainerHi Luiz,
Quoted 74 lines
This is the initial work to move away from the current design of batch up commands with
hci_req_runto be executed asynchronously to instead run them synchronously which enables handling errors properly.It specially targets enabling the so called LL Privacy feature and simplifying Suspend/Resume code paths since those are the most complicated ones involving multiple state machines (Connection, Advertising, Scanning and Adv Monitor) which requires a bunch commands to be send making the code very complicated to follow.
As a result of these changes the LL Privacy is enabled for the peripheral role, previously only central role had support for it, so it is possible to have advertising sets when LL Privacy is enabled.
Suspend/Resume have been reworked so it no longer needs a state machine to track its progress, the whole process of suspending is handled by
hci_suspend_syncandhci_resume_syncfor resuming, we also took the time to document the source code to make clear what is their expected behavior.In order to properly test these changes a number of new tests are being introduced see:
https://patchwork.kernel.org/project/bluetooth/list/?series=565857
v6: Fix CI findings, fix using ERR_PTR/PTR_ERR to pass parameters as
user_dataand change the use ofhci_dev*dev tohci_dev*hdev.
v7: More fixes for CI findings.
v8: Even more fixes for CI findings.Brian Gix (13):
Bluetooth:hci_sync: ConvertMGMT_OP_SET_FAST_CONNECTABLE
Bluetooth:hci_sync: Enable synch'dset_bredr
Bluetooth:hci_sync: ConvertMGMT_OP_GET_CONN_INFO
Bluetooth:hci_sync: ConvertMGMT_OP_SET_SECURE_CONN
Bluetooth:hci_sync: ConvertMGMT_OP_GET_CLOCK_INFO
Bluetooth:hci_sync: ConvertMGMT_OP_SET_LE
Bluetooth:hci_sync: ConvertMGMT_OP_READ_LOCAL_OOB_DATA
Bluetooth:hci_sync: ConvertMGMT_OP_READ_LOCAL_OOB_EXT_DATA
Bluetooth:hci_sync: ConvertMGMT_OP_SET_LOCAL_NAME
Bluetooth:hci_sync: ConvertMGMT_OP_SET_PHY_CONFIGURATION
Bluetooth:hci_sync: ConvertMGMT_OP_SET_ADVERTISING
Bluetooth:hci_sync: Convertadv_expire
Bluetooth:hci_sync: ConvertMGMT_OP_SSPLuiz Augusto von Dentz (9):
Bluetooth:hci_sync: Make use ofhci_cmd_sync_queueset 1
Bluetooth:hci_sync: Make use ofhci_cmd_sync_queueset 2
Bluetooth:hci_sync: Make use ofhci_cmd_sync_queueset 3
Bluetooth:hci_sync: Enable advertising when LL privacy is enabled
Bluetooth:hci_sync: Rework background scan
Bluetooth:hci_sync: ConvertMGMT_SET_POWERED
Bluetooth:hci_sync: ConvertMGMT_OP_START_DISCOVERY
Bluetooth:hci_sync: Rework init stages
Bluetooth:hci_sync: Reworkhci_suspend_notifierMarcel Holtmann (1):
Bluetooth: Add helper for serialized HCI command executioninclude/net/bluetooth/bluetooth.h | 2 + include/net/bluetooth/hci_core.h | 21 +- include/net/bluetooth/hci_sync.h | 98 + net/bluetooth/Makefile | 2 +- net/bluetooth/hci_conn.c | 20 +- net/bluetooth/hci_core.c | 1333 +------- net/bluetooth/hci_event.c | 153 +- net/bluetooth/hci_request.c | 338 +- net/bluetooth/hci_request.h | 10 + net/bluetooth/hci_sync.c | 4788 +++++++++++++++++++++++++++++ net/bluetooth/mgmt.c | 2050 ++++++------ net/bluetooth/mgmt_util.c | 15 +- net/bluetooth/mgmt_util.h | 4 + net/bluetooth/msft.c | 511 +-- net/bluetooth/msft.h | 15 +- 15 files changed, 6370 insertions(+), 2990 deletions(-)
Quoted 2 lines
create mode 100644
include/net/bluetooth/hci_sync.hcreate mode 100644net/bluetooth/hci_sync.c
all 23 patches have been applied to bluetooth-next tree.
Regards
Marcel