Skip to contentSkip to conversation

Bluetooth: Add marker to hci_req_ctrl

PATCH In review Jakub Pawlowski 2 participants 6 messages Jan 7, 2015 – Jan 9, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v6 1/3 Bluetooth: Add marker to hci_req_ctrl

This patch add marker field to hci_req_ctrl struct. It can be used to mark packets, so that they can be distinguished later and alter processing. Example: packet that disable LE scan can be marked. It would mean, that it's part of scan restart, and would be processed differently.

---
 include/net/bluetooth/bluetooth.h | 1 +
 1 file changed, 1 insertion(+)
include/net/bluetooth/bluetooth.h +1 -0
index 58695ff..7ae372d 100644
@@ -277,6 +277,7 @@ typedef void (*hci_req_complete_t)(struct hci_dev *hdev, u8 status);
 
 struct hci_req_ctrl {
 	bool			start;
+	bool			marker;
 	u8			event;
 	hci_req_complete_t	complete;
 };
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#1 lore raw

PATCH v6 2/3 Bluetooth: Add le_scan_restart

Currently there is no way to restart le scan, and it's needed in service scan method. The way it work: it disable, and then enable le scan on controller. During this restart marker is set to make sure we won't remove disable scan work from workqueue.

---
 include/net/bluetooth/hci_core.h |  1 +
 net/bluetooth/hci_core.c         | 44 ++++++++++++++++++++++++++++++++++++++++
 net/bluetooth/hci_event.c        |  8 +++++---
 net/bluetooth/hci_request.c      | 12 +++++++++--
 net/bluetooth/hci_request.h      |  2 ++
 5 files changed, 62 insertions(+), 5 deletions(-)
include/net/bluetooth/hci_core.h +1 -0
index 89f4e3c..2ea1f46 100644
@@ -349,6 +349,7 @@ struct hci_dev {
 	unsigned long		dev_flags;
 
 	struct delayed_work	le_scan_disable;
+	struct delayed_work	le_scan_restart;
 
 	__s8			adv_tx_power;
 	__u8			adv_data[HCI_MAX_AD_LENGTH];
net/bluetooth/hci_core.c +44 -0

68 lines not on this page · raw message

net/bluetooth/hci_event.c +5 -3
index 0881efd..9f3f1a9 100644
@@ -1176,10 +1176,12 @@ static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
 					  d->last_adv_data_len, NULL, 0);
 		}
 
-		/* Cancel this timer so that we don't try to disable scanning
-		 * when it's already disabled.
+		/* If marker is set, don't cancel this timer, because we're just
+		 * restarting scan. Otherwise cancel it so that we don't try to
+		 * disable scanning when it's already disabled.
 		 */
-		cancel_delayed_work(&hdev->le_scan_disable);
+		if (!bt_cb(hdev->sent_cmd)->req.marker)
+			cancel_delayed_work(&hdev->le_scan_disable);
 
 		clear_bit(HCI_LE_SCAN, &hdev->dev_flags);
 
net/bluetooth/hci_request.c +10 -2
index 324c641..626bc99 100644
@@ -93,8 +93,8 @@ struct sk_buff *hci_prepare_cmd(struct hci_dev *hdev, u16 opcode, u32 plen,
 }
 
 /* Queue a command to an asynchronous HCI request */
-void hci_req_add_ev(struct hci_request *req, u16 opcode, u32 plen,
-		    const void *param, u8 event)
+void hci_req_add_ev_marker(struct hci_request *req, u16 opcode, u32 plen,
+			   const void *param, u8 event, bool marker)
 {
 	struct hci_dev *hdev = req->hdev;
 	struct sk_buff *skb;
@@ -119,10 +119,18 @@ void hci_req_add_ev(struct hci_request *req, u16 opcode, u32 plen,
 		bt_cb(skb)->req.start = true;
 
 	bt_cb(skb)->req.event = event;
+	bt_cb(skb)->req.marker = marker;
 
 	skb_queue_tail(&req->cmd_q, skb);
 }
 
+/* Queue a command to an asynchronous HCI request */
+void hci_req_add_ev(struct hci_request *req, u16 opcode, u32 plen,
+		    const void *param, u8 event)
+{
+	hci_req_add_ev_marker(req, opcode, plen, param, event, false);
+}
+
 void hci_req_add(struct hci_request *req, u16 opcode, u32 plen,
 		 const void *param)
 {
net/bluetooth/hci_request.h +2 -0
index adf074d..2baa534 100644
@@ -36,6 +36,8 @@ 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,
 		    const void *param, u8 event);
+void hci_req_add_ev_marker(struct hci_request *req, u16 opcode, u32 plen,
+			   const void *param, u8 event, bool marker);
 void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status);
 
 struct sk_buff *hci_prepare_cmd(struct hci_dev *hdev, u16 opcode, u32 plen,
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#5 lore raw

PATCH v6 3/3 Bluetooth: Add restarting to service discovery

In reply to Jakub Pawlowski

When using LE_SCAN_FILTER_DUP_ENABLE, some controllers would send advertising report from each LE device only once. That means that we don't get any updates on RSSI value, and makes Service Discovery very slow. This patch adds restarting scan when in Service Discovery, and device with filtered uuid is found, but it's not in RSSI range to send event yet. This way if device moves into range, we will quickly get RSSI update.

---
 include/net/bluetooth/hci_core.h |  1 +
 net/bluetooth/mgmt.c             | 43 ++++++++++++++++++++++++++++++++++++----
 2 files changed, 40 insertions(+), 4 deletions(-)
include/net/bluetooth/hci_core.h +1 -0
index 2ea1f46..2408208 100644
@@ -1325,6 +1325,7 @@ void hci_sock_dev_event(struct hci_dev *hdev, int event);
 #define DISCOV_INTERLEAVED_TIMEOUT	5120	/* msec */
 #define DISCOV_INTERLEAVED_INQUIRY_LEN	0x04
 #define DISCOV_BREDR_INQUIRY_LEN	0x08
+#define DISCOV_LE_RESTART_DELAY		200	/* msec */
 
 int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len);
 int mgmt_new_settings(struct hci_dev *hdev);
net/bluetooth/mgmt.c +39 -4

77 lines not on this page · raw message

Signature · 1 line
2.2.0.rc0.207.ga3a616c
#2 lore raw

Re: [PATCH v6 2/3] Bluetooth: Add le_scan_restart

In reply to Jakub Pawlowski

Hi Jakub,

net/bluetooth/hci_event.c static void hci_cc_le_set_scan_enable(struct hci_dev *hdev, · line 1186

Quoted 5 lines · Jakub Pawlowski
net/bluetooth/hci_event.c +2 -1
-		cancel_delayed_work(&hdev->le_scan_disable);
+		if (!bt_cb(hdev->sent_cmd)->req.marker)
+			cancel_delayed_work(&hdev->le_scan_disable);
 
 		clear_bit(HCI_LE_SCAN, &hdev->dev_flags);

Modifying the generic HCI request framework for this single purpose doesn't make much sense to me. Also, the details of the bt_cb(skb)->req struct are considered an implementation detail of the HCI request specific handling and should not be directly touched by other code.

It looks to me like this marker has the same purpose as the flag you had in some earlier revision of this set? For such a use-case a flag would still be the best option. However, I'm wondering whether we can remove the need for this completely. Can't you just let the code cancel the delayed work and the re-schedule it again once the scanning gets re-enabled (with some extra code decrease the timeout some appropriate amount for each time scanning gets restarted).

Johan

#3 lore raw

Re: [PATCH v6 2/3] Bluetooth: Add le_scan_restart

Hi Johan,

Quoted 7 lines · Johan Hedberg

Hi Jakub,

Quoted 4 lines · Jakub Pawlowski
net/bluetooth/hci_event.c +2 -1
-             cancel_delayed_work(&hdev->le_scan_disable);
+             if (!bt_cb(hdev->sent_cmd)->req.marker)
+                     cancel_delayed_work(&hdev->le_scan_disable);
Quoted 6 lines
Quoted 1 line
              clear_bit(HCI_LE_SCAN, &hdev->dev_flags);

Modifying the generic HCI request framework for this single purpose doesn't make much sense to me. Also, the details of the bt_cb(skb)->req struct are considered an implementation detail of the HCI request specific handling and should not be directly touched by other code.

Description of cb field of skbuff says it can be used by every layer:
" @cb: Control buffer. Free for use by every layer. Put private vars here" ( http://lxr.free-electrons.com/source/include/linux/skbuff.h#L445
)
I fought I can just add something there, and use it.
I agree that this field doesn't fit struct hci_req_ctrl , but that was only place where there are free bits, otherwise the struct gets too big and don't fit cb field.

Quoted 4 lines

It looks to me like this marker has the same purpose as the flag you had in some earlier revision of this set? For such a use-case a flag would still be the best option.

Yes, it have same meaning as this eariler version flag. The problem with flag was that I can't set it when I create request, it need to be set when the request is being executed, otherwise I can get race condition. In case of this marker field, there is no option to have race condition.

Quoted 5 lines

However, I'm wondering whether we can remove
the need for this completely. Can't you just let the code cancel the delayed work and the re-schedule it again once the scanning gets re-enabled (with some extra code decrease the timeout some appropriate amount for each time scanning gets restarted).

1. I can't get remaining time from workqueue, so I'll have to remember when it was started.
2. When I do restart I'll still need some flag to know wether it was my internal restart, or wether someone just stopped and then started the scan, so I'll still need some flag, and way to set it.

I have one more idea on how to make it work, I'll send patch soon.

Quoted 2 lines

Johan

#4 lore raw

Re: [PATCH v6 2/3] Bluetooth: Add le_scan_restart

Quoted 43 lines · Jakub Pawlowski

Hi Johan,

Quoted 7 lines · Johan Hedberg

Hi Jakub,

Quoted 4 lines · Jakub Pawlowski
net/bluetooth/hci_event.c +2 -1
-             cancel_delayed_work(&hdev->le_scan_disable);
+             if (!bt_cb(hdev->sent_cmd)->req.marker)
+                     cancel_delayed_work(&hdev->le_scan_disable);
Quoted 6 lines
Quoted 1 line
              clear_bit(HCI_LE_SCAN, &hdev->dev_flags);

Modifying the generic HCI request framework for this single purpose doesn't make much sense to me. Also, the details of the bt_cb(skb)->req struct are considered an implementation detail of the HCI request specific handling and should not be directly touched by other code.

Description of cb field of skbuff says it can be used by every layer:
" @cb: Control buffer. Free for use by every layer. Put private vars here" ( http://lxr.free-electrons.com/source/include/linux/skbuff.h#L445
)
I fought I can just add something there, and use it.
I agree that this field doesn't fit struct hci_req_ctrl , but that was only place where there are free bits, otherwise the struct gets too big and don't fit cb field.

Quoted 4 lines

It looks to me like this marker has the same purpose as the flag you had in some earlier revision of this set? For such a use-case a flag would still be the best option.

Yes, it have same meaning as this eariler version flag. The problem with flag was that I can't set it when I create request, it need to be set when the request is being executed, otherwise I can get race condition. In case of this marker field, there is no option to have race condition.

Quoted 5 lines

However, I'm wondering whether we can remove
the need for this completely. Can't you just let the code cancel the delayed work and the re-schedule it again once the scanning gets re-enabled (with some extra code decrease the timeout some appropriate amount for each time scanning gets restarted).

Quoted 8 lines

1. I can't get remaining time from workqueue, so I'll have to remember when it was started.
2. When I do restart I'll still need some flag to know wether it was my internal restart, or wether someone just stopped and then started the scan, so I'll still need some flag, and way to set it.

I have one more idea on how to make it work, I'll send patch soon.

Ok I figured out how you wanted it, it's much simpler now, I'll send patches now.
Thanks!

Quoted 2 lines
Quoted 2 lines

Johan