Skip to contentSkip to conversation

Periodic Inquiry Handling

RFC In review Andre Guedes 2 participants 10 messages Mar 20, 2012 – Mar 21, 2012

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

cover Periodic Inquiry Handling

Hi all,

This patch series implements some Marcel's considerations about Periodic Inquiry handling.

The main points are:
* Track if periodic inquiry enabled or not;
* Fail start discovery if periodic inquiry is enabled;
* Ignore inquiry result events from periodic inquiry.

These considerations were given in "[PATCH v4 01/14] Bluetooth: Periodic Inquiry and mgmt discovering event" email.

BR,

Andre

Andre Guedes (4):
Bluetooth: Add Periodic Inquiry command complete handler
Bluetooth: Add HCI_PINQUIRY to dev_flags
Bluetooth: Check HCI_PINQUIRY in start_discovery
Bluetooth: Ignore inquiry results from periodic inquiry

 include/net/bluetooth/hci.h |    3 +++
 net/bluetooth/hci_event.c   |   30 +++++++++++++++++++++++++++++-
 net/bluetooth/mgmt.c        |    6 ++++++
 3 files changed, 38 insertions(+), 1 deletion(-)
Signature · 1 line
1.7.9.4
#1 lore raw

RFC 1/4 Bluetooth: Add Periodic Inquiry command complete handler

This patch adds a handler function to Periodic Inquiry command complete event.

---
 include/net/bluetooth/hci.h |    2 ++
 net/bluetooth/hci_event.c   |   11 +++++++++++
 2 files changed, 13 insertions(+)
include/net/bluetooth/hci.h +2 -0
index dbbb593..d74645e 100644
@@ -324,6 +324,8 @@ struct hci_cp_inquiry {
 
 #define HCI_OP_INQUIRY_CANCEL		0x0402
 
+#define HCI_OP_PERIODIC_INQ		0x0403
+
 #define HCI_OP_EXIT_PERIODIC_INQ	0x0404
 
 #define HCI_OP_CREATE_CONN		0x0405
net/bluetooth/hci_event.c +11 -0
index 04d39f4..af0c5a2 100644
@@ -70,6 +70,13 @@ static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb)
 	hci_conn_check_pending(hdev);
 }
 
+static void hci_cc_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb)
+{
+	__u8 status = *((__u8 *) skb->data);
+
+	BT_DBG("%s status 0x%x", hdev->name, status);
+}
+
 static void hci_cc_exit_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	__u8 status = *((__u8 *) skb->data);
@@ -2154,6 +2161,10 @@ static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *sk
 		hci_cc_inquiry_cancel(hdev, skb);
 		break;
 
+	case HCI_OP_PERIODIC_INQ:
+		hci_cc_periodic_inq(hdev, skb);
+		break;
+
 	case HCI_OP_EXIT_PERIODIC_INQ:
 		hci_cc_exit_periodic_inq(hdev, skb);
 		break;
Signature · 1 line
1.7.9.4
#3 lore raw

RFC 2/4 Bluetooth: Add HCI_PINQUIRY to dev_flags

In reply to Andre Guedes

This patch adds the HCI_PINQUIRY flag to dev_flags. This flag tracks if periodic inquiry is enabled or not.

---
 include/net/bluetooth/hci.h |    1 +
 net/bluetooth/hci_event.c   |   10 +++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)
include/net/bluetooth/hci.h +1 -0
index d74645e..b3e89bf 100644
@@ -102,6 +102,7 @@ enum {
 	HCI_DISCOVERABLE,
 	HCI_LINK_SECURITY,
 	HCI_PENDING_CLASS,
+	HCI_PINQUIRY,
 };
 
 /* HCI ioctl defines */
net/bluetooth/hci_event.c +9 -1
index af0c5a2..4d13843 100644
@@ -75,6 +75,11 @@ static void hci_cc_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb)
 	__u8 status = *((__u8 *) skb->data);
 
 	BT_DBG("%s status 0x%x", hdev->name, status);
+
+	if (status)
+		return;
+
+	set_bit(HCI_PINQUIRY, &hdev->dev_flags);
 }
 
 static void hci_cc_exit_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb)
@@ -86,6 +91,8 @@ static void hci_cc_exit_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb)
 	if (status)
 		return;
 
+	clear_bit(HCI_PINQUIRY, &hdev->dev_flags);
+
 	hci_conn_check_pending(hdev);
 }
 
@@ -200,7 +207,8 @@ static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
 	hci_req_complete(hdev, HCI_OP_RESET, status);
 
 	/* Reset all non-persistent flags */
-	hdev->dev_flags &= ~(BIT(HCI_LE_SCAN) | BIT(HCI_PENDING_CLASS));
+	hdev->dev_flags &= ~(BIT(HCI_LE_SCAN) | BIT(HCI_PENDING_CLASS) |
+							BIT(HCI_PINQUIRY));
 
 	hdev->discovery.state = DISCOVERY_STOPPED;
 }
Signature · 1 line
1.7.9.4
#6 lore raw

RFC 3/4 Bluetooth: Check HCI_PINQUIRY in start_discovery

In reply to Andre Guedes

This patch adds a HCI_PINQUIRY check to start_discovery. If periodic inquiry is enabled, we fail MGMT Start Discovery command with MGMT_STATUS_BUSY code.

---
 net/bluetooth/mgmt.c |    6 ++++++
 1 file changed, 6 insertions(+)
net/bluetooth/mgmt.c +6 -0
index b8f9016..a3365ba 100644
@@ -2317,6 +2317,12 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
 		goto failed;
 	}
 
+	if (test_bit(HCI_PINQUIRY, &hdev->dev_flags)) {
+		err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY,
+				 MGMT_STATUS_BUSY);
+		goto failed;
+	}
+
 	if (hdev->discovery.state != DISCOVERY_STOPPED) {
 		err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY,
 				 MGMT_STATUS_BUSY);
Signature · 1 line
1.7.9.4
#8 lore raw

RFC 4/4 Bluetooth: Ignore inquiry results from periodic inquiry

In reply to Andre Guedes

This patch changes inquiry result function handlers so they ignore inquiry result events if periodic inquiry is enabled.

---
 net/bluetooth/hci_event.c |    9 +++++++++
 1 file changed, 9 insertions(+)
net/bluetooth/hci_event.c +9 -0
index 4d13843..f1b9f2e 100644
@@ -1723,6 +1723,9 @@ static inline void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *
 	if (!num_rsp)
 		return;
 
+	if (test_bit(HCI_PINQUIRY, &hdev->dev_flags))
+		return;
+
 	hci_dev_lock(hdev);
 
 	for (; num_rsp; num_rsp--, info++) {
@@ -2824,6 +2827,9 @@ static inline void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, struct
 	if (!num_rsp)
 		return;
 
+	if (test_bit(HCI_PINQUIRY, &hdev->dev_flags))
+		return;
+
 	hci_dev_lock(hdev);
 
 	if ((skb->len - 1) / num_rsp != sizeof(struct inquiry_info_with_rssi)) {
@@ -2995,6 +3001,9 @@ static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct
 	if (!num_rsp)
 		return;
 
+	if (test_bit(HCI_PINQUIRY, &hdev->dev_flags))
+		return;
+
 	hci_dev_lock(hdev);
 
 	for (; num_rsp; num_rsp--, info++) {
Signature · 1 line
1.7.9.4
maintainer Acked-by on v1 2/4
#4 lore raw

Re: [RFC 2/4] Bluetooth: Add HCI_PINQUIRY to dev_flags

In reply to Andre Guedes

Hi Andre,

Quoted 14 lines

This patch adds the HCI_PINQUIRY flag to dev_flags. This flag tracks if periodic inquiry is enabled or not.

---
 include/net/bluetooth/hci.h |    1 +
 net/bluetooth/hci_event.c   |   10 +++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)
include/net/bluetooth/hci.h +0 -0
index d74645e..b3e89bf 100644

include/net/bluetooth/hci.h enum { · line 105

Quoted 4 lines
include/net/bluetooth/hci.h +1 -0
@@ -102,6 +102,7 @@ enum {
 	HCI_DISCOVERABLE,
 	HCI_LINK_SECURITY,
 	HCI_PENDING_CLASS,
+	HCI_PINQUIRY,

call this HCI_PERIODIC_INQ. Since PINQUIRY is horrible to distinguish from INQUIRY.

Quoted 29 lines
include/net/bluetooth/hci.h +0 -0
 };
 
 /* HCI ioctl defines */
net/bluetooth/hci_event.c +7 -0
index af0c5a2..4d13843 100644
@@ -75,6 +75,11 @@ static void hci_cc_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb)
 	__u8 status = *((__u8 *) skb->data);
 
 	BT_DBG("%s status 0x%x", hdev->name, status);
+
+	if (status)
+		return;
+
+	set_bit(HCI_PINQUIRY, &hdev->dev_flags);
 }
 
 static void hci_cc_exit_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb)
@@ -86,6 +91,8 @@ static void hci_cc_exit_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb)
 	if (status)
 		return;
 
+	clear_bit(HCI_PINQUIRY, &hdev->dev_flags);
+
 	hci_conn_check_pending(hdev);
 }
 

net/bluetooth/hci_event.c static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb) · line 211

Quoted 6 lines
net/bluetooth/hci_event.c +2 -1
@@ -200,7 +207,8 @@ static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
 	hci_req_complete(hdev, HCI_OP_RESET, status);
 
 	/* Reset all non-persistent flags */
-	hdev->dev_flags &= ~(BIT(HCI_LE_SCAN) | BIT(HCI_PENDING_CLASS));
+	hdev->dev_flags &= ~(BIT(HCI_LE_SCAN) | BIT(HCI_PENDING_CLASS) |
+							BIT(HCI_PINQUIRY));

And as homework for another patch, we should have a simple mask define for persistent or non-persistent flags that is defined right next to the enum. This will otherwise get out of control.

net/bluetooth/hci_event.c static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb) · line 214

Quoted 3 lines
net/bluetooth/hci_event.c +0 -0
 	hdev->discovery.state = DISCOVERY_STOPPED;
 }

Other than the flag name change, this looks fine.

Regards

Marcel

maintainer Acked-by on v1 3/4
#7 lore raw

Re: [RFC 3/4] Bluetooth: Check HCI_PINQUIRY in start_discovery

In reply to Andre Guedes

Hi Andre,

Quoted 8 lines

This patch adds a HCI_PINQUIRY check to start_discovery. If periodic inquiry is enabled, we fail MGMT Start Discovery command with MGMT_STATUS_BUSY code.

---
 net/bluetooth/mgmt.c |    6 ++++++
 1 file changed, 6 insertions(+)

besides the pending flag name change, this is fine as well.

Regards

Marcel

maintainer Acked-by on v1 4/4
#9 lore raw

Re: [RFC 4/4] Bluetooth: Ignore inquiry results from periodic inquiry

In reply to Andre Guedes

Hi Andre,

Quoted 7 lines

This patch changes inquiry result function handlers so they ignore inquiry result events if periodic inquiry is enabled.

---
 net/bluetooth/hci_event.c |    9 +++++++++
 1 file changed, 9 insertions(+)

also flag name change here as well please.

Regards

Marcel

#5 lore raw

Re: [RFC 2/4] Bluetooth: Add HCI_PINQUIRY to dev_flags

In reply to Marcel Holtmann

Hi Marcel,

On Tue, Mar 20, 2012 at 12:53 PM, Marcel Holtmann <[email protected]> wro= te:

Quoted 11 lines

Hi Andre,

Quoted 9 lines

This patch adds the HCI_PINQUIRY flag to dev_flags. This flag tracks if periodic inquiry is enabled or not.

---
=A0include/net/bluetooth/hci.h | =A0 =A01 + =A0net/bluetooth/hci_event.c =A0 | =A0 10 +++++++++- =A02 files changed, 10 insertions(+), 1 deletion(-)

Quoted 12 lines

include/net/bluetooth/hci.h enum { · line 105

Quoted 9 lines
include/net/bluetooth/hci.h +1 -0
index d74645e..b3e89bf 100644
@@ -102,6 +102,7 @@ enum {
 =A0 =A0 =A0 HCI_DISCOVERABLE,
 =A0 =A0 =A0 HCI_LINK_SECURITY,
 =A0 =A0 =A0 HCI_PENDING_CLASS,
+ =A0 =A0 HCI_PINQUIRY,

call this HCI_PERIODIC_INQ. Since PINQUIRY is horrible to distinguish from INQUIRY.

Ok, I'll rename it.

Quoted 8 lines

net/bluetooth/hci_event.c static void hci_cc_periodic_inq(struct hci_dev *hdev,=

Quoted 8 lines
include/net/bluetooth/hci.h +0 -0
 =A0};
 

=A0/* HCI ioctl defines */

net/bluetooth/hci_event.c +0 -0
index af0c5a2..4d13843 100644
@@ -75,6 +75,11 @@ static void hci_cc_periodic_inq(struct hci_dev *hdev,=

struct sk_buff *skb)

Quoted 11 lines
Quoted 11 lines
net/bluetooth/hci_event.c +5 -0
 =A0 =A0 =A0 __u8 status =3D *((__u8 *) skb->data);
 
 =A0 =A0 =A0 BT_DBG("%s status 0x%x", hdev->name, status);
+
+ =A0 =A0 if (status)
+ =A0 =A0 =A0 =A0 =A0 =A0 return;
+
+ =A0 =A0 set_bit(HCI_PINQUIRY, &hdev->dev_flags);
 =A0}
 

=A0static void hci_cc_exit_periodic_inq(struct hci_dev *hdev, struct sk_=

buff *skb)

Quoted 1 line

net/bluetooth/hci_event.c static void hci_cc_exit_periodic_inq(struct hci_dev *h=

Quoted 1 line
net/bluetooth/hci_event.c +0 -0
@@ -86,6 +91,8 @@ static void hci_cc_exit_periodic_inq(struct hci_dev *h=

dev, struct sk_buff *skb)

Quoted 9 lines

net/bluetooth/hci_event.c static void hci_cc_reset(struct hci_dev *hdev, struc=

Quoted 9 lines
net/bluetooth/hci_event.c +2 -0
 =A0 =A0 =A0 if (status)
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return;
 
+ =A0 =A0 clear_bit(HCI_PINQUIRY, &hdev->dev_flags);
+
 =A0 =A0 =A0 hci_conn_check_pending(hdev);
 =A0}
 
@@ -200,7 +207,8 @@ static void hci_cc_reset(struct hci_dev *hdev, struc=

t sk_buff *skb)

Quoted 4 lines
Quoted 4 lines
net/bluetooth/hci_event.c +0 -0
 =A0 =A0 =A0 hci_req_complete(hdev, HCI_OP_RESET, status);
 

=A0 =A0 =A0 /* Reset all non-persistent flags */
- =A0 =A0 hdev->dev_flags &=3D ~(BIT(HCI_LE_SCAN) | BIT(HCI_PENDING_CLAS=

S));

Quoted 1 line
Quoted 1 line

+ =A0 =A0 hdev->dev_flags &=3D ~(BIT(HCI_LE_SCAN) | BIT(HCI_PENDING_CLAS=

S) |

Quoted 1 line
Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 BIT(HCI_PINQUIRY));

Quoted 6 lines

And as homework for another patch, we should have a simple mask define for persistent or non-persistent flags that is defined right next to the enum. This will otherwise get out of control.

Quoted 1 line
Quoted 6 lines
Quoted 2 lines

=A0 =A0 =A0 hdev->discovery.state =3D DISCOVERY_STOPPED; =A0}

Other than the flag name change, this looks fine.

I'm gonna rename the flag, fix subsequent patches and send a new version of this series as PATCH.

BR,

Andre