* [PATCH 1/3] Bluetooth: Fix indicating discovery state when canceling inquiry
@ 2014-06-10 11:05 johan.hedberg
2014-06-10 11:05 ` [PATCH 2/3] Bluetooth: Refactor discovery stopping into its own function johan.hedberg
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: johan.hedberg @ 2014-06-10 11:05 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@intel.com>
When inquiry is canceled through the HCI_Cancel_Inquiry command there is
no Inquiry Complete event generated. Instead, all we get is the command
complete for the HCI_Inquiry_Cancel command. This means that we must
call the hci_discovery_set_state() function from the respective command
complete handler in order to ensure that user space knows the correct
discovery state.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/hci_event.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 3415c3468f15..ec1b17467133 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -48,6 +48,10 @@ static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb)
smp_mb__after_clear_bit(); /* wake_up_bit advises about this barrier */
wake_up_bit(&hdev->flags, HCI_INQUIRY);
+ hci_dev_lock(hdev);
+ hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
+ hci_dev_unlock(hdev);
+
hci_conn_check_pending(hdev);
}
--
1.9.3
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/3] Bluetooth: Refactor discovery stopping into its own function 2014-06-10 11:05 [PATCH 1/3] Bluetooth: Fix indicating discovery state when canceling inquiry johan.hedberg @ 2014-06-10 11:05 ` johan.hedberg 2014-06-10 11:59 ` Marcel Holtmann 2014-06-10 11:05 ` [PATCH 3/3] Bluetooth: Reuse hci_stop_discovery function when cleaning up HCI state johan.hedberg 2014-06-10 11:59 ` [PATCH 1/3] Bluetooth: Fix indicating discovery state when canceling inquiry Marcel Holtmann 2 siblings, 1 reply; 6+ messages in thread From: johan.hedberg @ 2014-06-10 11:05 UTC (permalink / raw) To: linux-bluetooth From: Johan Hedberg <johan.hedberg@intel.com> We'll need to reuse the same logic for stopping discovery also when cleaning up HCI state when powering off. This patch refactors the code out to its own function that can later (in a subsequent patch) be used also for the power off case. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> --- net/bluetooth/mgmt.c | 93 +++++++++++++++++++++++++++------------------------- 1 file changed, 49 insertions(+), 44 deletions(-) diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 0fce54412ffd..be6f03219121 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -1047,6 +1047,43 @@ static void clean_up_hci_complete(struct hci_dev *hdev, u8 status) } } +static void hci_stop_discovery(struct hci_request *req) +{ + struct hci_dev *hdev = req->hdev; + struct hci_cp_remote_name_req_cancel cp; + struct inquiry_entry *e; + + switch (hdev->discovery.state) { + case DISCOVERY_FINDING: + if (test_bit(HCI_INQUIRY, &hdev->flags)) { + hci_req_add(req, HCI_OP_INQUIRY_CANCEL, 0, NULL); + } else { + cancel_delayed_work(&hdev->le_scan_disable); + hci_req_add_le_scan_disable(req); + } + + break; + + case DISCOVERY_RESOLVING: + e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, + NAME_PENDING); + if (!e) + return; + + bacpy(&cp.bdaddr, &e->data.bdaddr); + hci_req_add(req, HCI_OP_REMOTE_NAME_REQ_CANCEL, sizeof(cp), + &cp); + + break; + + default: + /* Passive scanning */ + if (test_bit(HCI_LE_SCAN, &hdev->dev_flags)) + hci_req_add_le_scan_disable(req); + break; + } +} + static int clean_up_hci_state(struct hci_dev *hdev) { struct hci_request req; @@ -3574,8 +3611,6 @@ static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data, { struct mgmt_cp_stop_discovery *mgmt_cp = data; struct pending_cmd *cmd; - struct hci_cp_remote_name_req_cancel cp; - struct inquiry_entry *e; struct hci_request req; int err; @@ -3605,52 +3640,22 @@ static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data, hci_req_init(&req, hdev); - switch (hdev->discovery.state) { - case DISCOVERY_FINDING: - if (test_bit(HCI_INQUIRY, &hdev->flags)) { - hci_req_add(&req, HCI_OP_INQUIRY_CANCEL, 0, NULL); - } else { - cancel_delayed_work(&hdev->le_scan_disable); - - hci_req_add_le_scan_disable(&req); - } - - break; - - case DISCOVERY_RESOLVING: - e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, - NAME_PENDING); - if (!e) { - mgmt_pending_remove(cmd); - err = cmd_complete(sk, hdev->id, - MGMT_OP_STOP_DISCOVERY, 0, - &mgmt_cp->type, - sizeof(mgmt_cp->type)); - hci_discovery_set_state(hdev, DISCOVERY_STOPPED); - goto unlock; - } - - bacpy(&cp.bdaddr, &e->data.bdaddr); - hci_req_add(&req, HCI_OP_REMOTE_NAME_REQ_CANCEL, sizeof(cp), - &cp); + hci_stop_discovery(&req); - break; - - default: - BT_DBG("unknown discovery state %u", hdev->discovery.state); - - mgmt_pending_remove(cmd); - err = cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, - MGMT_STATUS_FAILED, &mgmt_cp->type, - sizeof(mgmt_cp->type)); + err = hci_req_run(&req, stop_discovery_complete); + if (!err) { + hci_discovery_set_state(hdev, DISCOVERY_STOPPING); goto unlock; } - err = hci_req_run(&req, stop_discovery_complete); - if (err < 0) - mgmt_pending_remove(cmd); - else - hci_discovery_set_state(hdev, DISCOVERY_STOPPING); + mgmt_pending_remove(cmd); + + /* If no HCI commands were sent we're done */ + if (err == -ENODATA) { + err = cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, 0, + &mgmt_cp->type, sizeof(mgmt_cp->type)); + hci_discovery_set_state(hdev, DISCOVERY_STOPPED); + } unlock: hci_dev_unlock(hdev); -- 1.9.3 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] Bluetooth: Refactor discovery stopping into its own function 2014-06-10 11:05 ` [PATCH 2/3] Bluetooth: Refactor discovery stopping into its own function johan.hedberg @ 2014-06-10 11:59 ` Marcel Holtmann 0 siblings, 0 replies; 6+ messages in thread From: Marcel Holtmann @ 2014-06-10 11:59 UTC (permalink / raw) To: Johan Hedberg; +Cc: linux-bluetooth Hi Johan, > We'll need to reuse the same logic for stopping discovery also when > cleaning up HCI state when powering off. This patch refactors the code > out to its own function that can later (in a subsequent patch) be used > also for the power off case. > > Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> > --- > net/bluetooth/mgmt.c | 93 +++++++++++++++++++++++++++------------------------- > 1 file changed, 49 insertions(+), 44 deletions(-) patch has been applied to bluetooth-next tree. Regards Marcel ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/3] Bluetooth: Reuse hci_stop_discovery function when cleaning up HCI state 2014-06-10 11:05 [PATCH 1/3] Bluetooth: Fix indicating discovery state when canceling inquiry johan.hedberg 2014-06-10 11:05 ` [PATCH 2/3] Bluetooth: Refactor discovery stopping into its own function johan.hedberg @ 2014-06-10 11:05 ` johan.hedberg 2014-06-10 11:59 ` Marcel Holtmann 2014-06-10 11:59 ` [PATCH 1/3] Bluetooth: Fix indicating discovery state when canceling inquiry Marcel Holtmann 2 siblings, 1 reply; 6+ messages in thread From: johan.hedberg @ 2014-06-10 11:05 UTC (permalink / raw) To: linux-bluetooth From: Johan Hedberg <johan.hedberg@intel.com> When cleaning up the HCI state as part of the power-off procedure we can reuse the hci_stop_discovery() function instead of explicitly sending HCI command related to discovery. The added benefit of this is that it takes care of canceling name resolving and inquiry which were not previously covered by the code. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> --- net/bluetooth/mgmt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index be6f03219121..6107e037cd8e 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -1100,9 +1100,7 @@ static int clean_up_hci_state(struct hci_dev *hdev) if (test_bit(HCI_ADVERTISING, &hdev->dev_flags)) disable_advertising(&req); - if (test_bit(HCI_LE_SCAN, &hdev->dev_flags)) { - hci_req_add_le_scan_disable(&req); - } + hci_stop_discovery(&req); list_for_each_entry(conn, &hdev->conn_hash.list, list) { struct hci_cp_disconnect dc; -- 1.9.3 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] Bluetooth: Reuse hci_stop_discovery function when cleaning up HCI state 2014-06-10 11:05 ` [PATCH 3/3] Bluetooth: Reuse hci_stop_discovery function when cleaning up HCI state johan.hedberg @ 2014-06-10 11:59 ` Marcel Holtmann 0 siblings, 0 replies; 6+ messages in thread From: Marcel Holtmann @ 2014-06-10 11:59 UTC (permalink / raw) To: Johan Hedberg; +Cc: linux-bluetooth Hi Johan, > When cleaning up the HCI state as part of the power-off procedure we can > reuse the hci_stop_discovery() function instead of explicitly sending > HCI command related to discovery. The added benefit of this is that it > takes care of canceling name resolving and inquiry which were not > previously covered by the code. > > Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> > --- > net/bluetooth/mgmt.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) patch has been applied to bluetooth-next tree. Regards Marcel ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] Bluetooth: Fix indicating discovery state when canceling inquiry 2014-06-10 11:05 [PATCH 1/3] Bluetooth: Fix indicating discovery state when canceling inquiry johan.hedberg 2014-06-10 11:05 ` [PATCH 2/3] Bluetooth: Refactor discovery stopping into its own function johan.hedberg 2014-06-10 11:05 ` [PATCH 3/3] Bluetooth: Reuse hci_stop_discovery function when cleaning up HCI state johan.hedberg @ 2014-06-10 11:59 ` Marcel Holtmann 2 siblings, 0 replies; 6+ messages in thread From: Marcel Holtmann @ 2014-06-10 11:59 UTC (permalink / raw) To: Johan Hedberg; +Cc: linux-bluetooth Hi Johan, > When inquiry is canceled through the HCI_Cancel_Inquiry command there is > no Inquiry Complete event generated. Instead, all we get is the command > complete for the HCI_Inquiry_Cancel command. This means that we must > call the hci_discovery_set_state() function from the respective command > complete handler in order to ensure that user space knows the correct > discovery state. > > Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> > --- > net/bluetooth/hci_event.c | 4 ++++ > 1 file changed, 4 insertions(+) patch has been applied to bluetooth-next tree. Regards Marcel ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-06-10 11:59 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-06-10 11:05 [PATCH 1/3] Bluetooth: Fix indicating discovery state when canceling inquiry johan.hedberg 2014-06-10 11:05 ` [PATCH 2/3] Bluetooth: Refactor discovery stopping into its own function johan.hedberg 2014-06-10 11:59 ` Marcel Holtmann 2014-06-10 11:05 ` [PATCH 3/3] Bluetooth: Reuse hci_stop_discovery function when cleaning up HCI state johan.hedberg 2014-06-10 11:59 ` Marcel Holtmann 2014-06-10 11:59 ` [PATCH 1/3] Bluetooth: Fix indicating discovery state when canceling inquiry Marcel Holtmann
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox