Skip to contentSkip to conversation

Bluetooth: Implement advertising report meta event

RFC Superseded [email protected] 3 participants 4 messages Feb 14, 2011 – Feb 15, 2011

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC 1/5 Bluetooth: Implement advertising report meta event

From: Anderson Briglia <[email protected]>

This patch implements new LE meta event in order to handle advertising reports.

---
 include/net/bluetooth/hci.h |   18 ++++++++++++++++++
 net/bluetooth/hci_event.c   |   22 ++++++++++++++++++++++
 2 files changed, 40 insertions(+), 0 deletions(-)
include/net/bluetooth/hci.h +18 -0
index 46438f4..5180555 100644
@@ -980,6 +980,24 @@ struct hci_ev_le_conn_complete {
 	__u8     clk_accurancy;
 } __packed;
 
+#define ADV_IND		0x00
+#define ADV_DIRECT_IND	0x01
+#define ADV_SCAN_IND	0x02
+#define ADV_NONCONN_IND	0x03
+#define SCAN_RSP	0x04
+
+#define ADDR_DEV_PUBLIC	0x00
+#define ADDR_DEV_RANDOM	0x01
+
+#define HCI_EV_LE_ADVERTISING_REPORT	0x02
+struct hci_ev_le_advertising_info {
+	__u8	 evt_type;
+	__u8	 bdaddr_type;
+	bdaddr_t bdaddr;
+	__u8	 length;
+	__u8	 data[0];
+} __packed;
+
 #define HCI_EV_LE_LTK_REQ		0x05
 struct hci_ev_le_ltk_req {
 	__le16	handle;
net/bluetooth/hci_event.c +22 -0
index 99c75f4..987f5de 100644
@@ -2498,6 +2498,25 @@ static inline void hci_le_ltk_request_evt(struct hci_dev *hdev,
 	hci_dev_unlock(hdev);
 }
 
+static inline void hci_le_adv_report_evt(struct hci_dev *hdev,
+						struct sk_buff *skb)
+{
+	struct hci_ev_le_advertising_info *ev;
+	u8 num_reports, i;
+
+	num_reports = (u8) skb->data[0];
+
+	ev = (struct hci_ev_le_advertising_info *) (skb->data + 1);
+
+	BT_DBG("adv from: %s", batostr(&ev->bdaddr));
+
+	for (i = 1; i < num_reports; i++) {
+		ev = (struct hci_ev_le_advertising_info *)
+					(ev->data + ev->length + 1);
+		BT_DBG("adv from: %s", batostr(&ev->bdaddr));
+	}
+}
+
 static inline void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	struct hci_ev_le_meta *le_ev = (void *) skb->data;
@@ -2513,6 +2532,9 @@ static inline void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb)
 		hci_le_ltk_request_evt(hdev, skb);
 		break;
 
+	case HCI_EV_LE_ADVERTISING_REPORT:
+		hci_le_adv_report_evt(hdev, skb);
+
 	default:
 		break;
 	}
Signature · 1 line
1.7.1
#1 lore raw

Hi Briglia,

Quoted 45 lines · On Mon, Feb 14, 2011 at 6:59 PM, <[email protected]> wrote:

From: Anderson Briglia <[email protected]>

This patch implements new LE meta event in order to handle advertising reports.

---
 include/net/bluetooth/hci.h |   18 ++++++++++++++++++ net/bluetooth/hci_event.c   |   22 ++++++++++++++++++++++

 2 files changed, 40 insertions(+), 0 deletions(-)
include/net/bluetooth/hci.h +18 -0
index 46438f4..5180555 100644
@@ -980,6 +980,24 @@ struct hci_ev_le_conn_complete {
        __u8     clk_accurancy;
  } __packed;
 
+#define ADV_IND                0x00
+#define ADV_DIRECT_IND 0x01
+#define ADV_SCAN_IND   0x02
+#define ADV_NONCONN_IND        0x03
+#define SCAN_RSP       0x04
+
+#define ADDR_DEV_PUBLIC        0x00
+#define ADDR_DEV_RANDOM        0x01
+
+#define HCI_EV_LE_ADVERTISING_REPORT   0x02
+struct hci_ev_le_advertising_info {
+       __u8     evt_type;
+       __u8     bdaddr_type;
+       bdaddr_t bdaddr;
+       __u8     length;
+       __u8     data[0];
+} __packed;
+
  #define HCI_EV_LE_LTK_REQ              0x05
  struct hci_ev_le_ltk_req {
        __le16  handle;
net/bluetooth/hci_event.c +0 -0
index 99c75f4..987f5de 100644

net/bluetooth/hci_event.c static inline void hci_le_ltk_request_evt(struct hci_dev *hdev, · line 2507

Quoted 10 lines
net/bluetooth/hci_event.c +7 -0
@@ -2498,6 +2498,25 @@ static inline void hci_le_ltk_request_evt(struct hci_dev *hdev,
        hci_dev_unlock(hdev);
  }
 
+static inline void hci_le_adv_report_evt(struct hci_dev *hdev,
+                                               struct sk_buff *skb)
+{
+       struct hci_ev_le_advertising_info *ev;
+       u8 num_reports, i;
+
+       num_reports = (u8) skb->data[0];

I think this cast is unnecessary.

net/bluetooth/hci_event.c static inline void hci_le_ltk_request_evt(struct hci_dev *hdev, · line 2509

Quoted 2 lines
net/bluetooth/hci_event.c +2 -0
+
+       ev = (struct hci_ev_le_advertising_info *) (skb->data + 1);

What about a slightly shorter line (well I didn't count the chars):

ev = (struct hci_ev_le_advertising_info *) &skb->data[1];

net/bluetooth/hci_event.c static inline void hci_le_ltk_request_evt(struct hci_dev *hdev, · line 2517

Quoted 8 lines
net/bluetooth/hci_event.c +8 -0
+
+       BT_DBG("adv from: %s", batostr(&ev->bdaddr));
+
+       for (i = 1; i < num_reports; i++) {
+               ev = (struct hci_ev_le_advertising_info *)
+                                       (ev->data + ev->length + 1);
+               BT_DBG("adv from: %s", batostr(&ev->bdaddr));
+       }

What about (not sure if it is shorter, just a suggestion):

ev = (struct hci_ev_le_advertising_info *) &ev->data[ev->length + 1];

net/bluetooth/hci_event.c static inline void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb) · line 2537

Quoted 12 lines
net/bluetooth/hci_event.c +5 -0
+}
+
  static inline void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb)
  {
        struct hci_ev_le_meta *le_ev = (void *) skb->data;
@@ -2513,6 +2532,9 @@ static inline void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb)
                hci_le_ltk_request_evt(hdev, skb);
                break;
 
+       case HCI_EV_LE_ADVERTISING_REPORT:
+               hci_le_adv_report_evt(hdev, skb);
+

missing a "break" here.

Quoted 11 lines

       default:
               break;
       }
--
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Signature · 3 lines
Anderson Lizardo
OpenBossa Labs - INdT
Manaus - Brazil
#2 lore raw

Thanks for reviewing. I'll add that missing "break", but the other tips are not so relevant since we should gain just 2 characters.

Quoted 111 lines · Anderson Lizardo

Hi Briglia,

Quoted 45 lines · On Mon, Feb 14, 2011 at 6:59 PM,  <[email protected]> wrote:

From: Anderson Briglia <[email protected]>

This patch implements new LE meta event in order to handle advertising reports.

---
 include/net/bluetooth/hci.h |   18 ++++++++++++++++++ net/bluetooth/hci_event.c   |   22 ++++++++++++++++++++++

 2 files changed, 40 insertions(+), 0 deletions(-)
include/net/bluetooth/hci.h +18 -0
index 46438f4..5180555 100644
@@ -980,6 +980,24 @@ struct hci_ev_le_conn_complete {
        __u8     clk_accurancy;
  } __packed;
 
+#define ADV_IND                0x00
+#define ADV_DIRECT_IND 0x01
+#define ADV_SCAN_IND   0x02
+#define ADV_NONCONN_IND        0x03
+#define SCAN_RSP       0x04
+
+#define ADDR_DEV_PUBLIC        0x00
+#define ADDR_DEV_RANDOM        0x01
+
+#define HCI_EV_LE_ADVERTISING_REPORT   0x02
+struct hci_ev_le_advertising_info {
+       __u8     evt_type;
+       __u8     bdaddr_type;
+       bdaddr_t bdaddr;
+       __u8     length;
+       __u8     data[0];
+} __packed;
+
  #define HCI_EV_LE_LTK_REQ              0x05
  struct hci_ev_le_ltk_req {
        __le16  handle;
net/bluetooth/hci_event.c +0 -0
index 99c75f4..987f5de 100644

net/bluetooth/hci_event.c static inline void hci_le_ltk_request_evt(struct hci_dev *hdev, · line 2507

Quoted 10 lines
net/bluetooth/hci_event.c +7 -0
@@ -2498,6 +2498,25 @@ static inline void hci_le_ltk_request_evt(struct hci_dev *hdev,
        hci_dev_unlock(hdev);
  }
 
+static inline void hci_le_adv_report_evt(struct hci_dev *hdev,
+                                               struct sk_buff *skb)
+{
+       struct hci_ev_le_advertising_info *ev;
+       u8 num_reports, i;
+
+       num_reports = (u8) skb->data[0];

I think this cast is unnecessary.

net/bluetooth/hci_event.c static inline void hci_le_ltk_request_evt(struct hci_dev *hdev, · line 2509

Quoted 2 lines
net/bluetooth/hci_event.c +2 -0
+
+       ev = (struct hci_ev_le_advertising_info *) (skb->data + 1);

What about a slightly shorter line (well I didn't count the chars):

ev = (struct hci_ev_le_advertising_info *) &skb->data[1];

net/bluetooth/hci_event.c static inline void hci_le_ltk_request_evt(struct hci_dev *hdev, · line 2517

Quoted 8 lines
net/bluetooth/hci_event.c +8 -0
+
+       BT_DBG("adv from: %s", batostr(&ev->bdaddr));
+
+       for (i = 1; i < num_reports; i++) {
+               ev = (struct hci_ev_le_advertising_info *)
+                                       (ev->data + ev->length + 1);
+               BT_DBG("adv from: %s", batostr(&ev->bdaddr));
+       }

What about (not sure if it is shorter, just a suggestion):

ev = (struct hci_ev_le_advertising_info *) &ev->data[ev->length + 1];

net/bluetooth/hci_event.c static inline void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb) · line 2537

Quoted 12 lines
net/bluetooth/hci_event.c +5 -0
+}
+
  static inline void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb)
  {
        struct hci_ev_le_meta *le_ev = (void *) skb->data;
@@ -2513,6 +2532,9 @@ static inline void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb)
                hci_le_ltk_request_evt(hdev, skb);
                break;
 
+       case HCI_EV_LE_ADVERTISING_REPORT:
+               hci_le_adv_report_evt(hdev, skb);
+

missing a "break" here.

Quoted 11 lines

       default:
               break;
       }
--
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Quoted 4 lines

--
Anderson Lizardo
OpenBossa Labs - INdT
Manaus - Brazil

--
INdT - Instituto Nokia de tecnologia
+55 2126 1122
http://techblog.briglia.net

#3 lore raw

Hi Briglia,

Top posting is not allowed in this mailing list. Please stop it.

Quoted 73 lines · Anderson Briglia

Thanks for reviewing. I'll add that missing "break", but the other tips are not so relevant since we should gain just 2 characters.

Quoted 68 lines · Anderson Lizardo

Hi Briglia,

Quoted 45 lines · On Mon, Feb 14, 2011 at 6:59 PM,  <[email protected]> wrote:

From: Anderson Briglia <[email protected]>

This patch implements new LE meta event in order to handle advertising reports.

---
 include/net/bluetooth/hci.h |   18 ++++++++++++++++++ net/bluetooth/hci_event.c   |   22 ++++++++++++++++++++++

 2 files changed, 40 insertions(+), 0 deletions(-)
include/net/bluetooth/hci.h +18 -0
index 46438f4..5180555 100644
@@ -980,6 +980,24 @@ struct hci_ev_le_conn_complete {
        __u8     clk_accurancy;
  } __packed;
 
+#define ADV_IND                0x00
+#define ADV_DIRECT_IND 0x01
+#define ADV_SCAN_IND   0x02
+#define ADV_NONCONN_IND        0x03
+#define SCAN_RSP       0x04
+
+#define ADDR_DEV_PUBLIC        0x00
+#define ADDR_DEV_RANDOM        0x01
+
+#define HCI_EV_LE_ADVERTISING_REPORT   0x02
+struct hci_ev_le_advertising_info {
+       __u8     evt_type;
+       __u8     bdaddr_type;
+       bdaddr_t bdaddr;
+       __u8     length;
+       __u8     data[0];
+} __packed;
+
  #define HCI_EV_LE_LTK_REQ              0x05
  struct hci_ev_le_ltk_req {
        __le16  handle;
net/bluetooth/hci_event.c +0 -0
index 99c75f4..987f5de 100644

net/bluetooth/hci_event.c static inline void hci_le_ltk_request_evt(struct hci_dev *hdev, · line 2507

Quoted 10 lines
net/bluetooth/hci_event.c +7 -0
@@ -2498,6 +2498,25 @@ static inline void hci_le_ltk_request_evt(struct hci_dev *hdev,
        hci_dev_unlock(hdev);
  }
 
+static inline void hci_le_adv_report_evt(struct hci_dev *hdev,
+                                               struct sk_buff *skb)
+{
+       struct hci_ev_le_advertising_info *ev;
+       u8 num_reports, i;
+
+       num_reports = (u8) skb->data[0];

I think this cast is unnecessary.

net/bluetooth/hci_event.c static inline void hci_le_ltk_request_evt(struct hci_dev *hdev, · line 2509

Quoted 2 lines
net/bluetooth/hci_event.c +2 -0
+
+       ev = (struct hci_ev_le_advertising_info *) (skb->data + 1);

What about a slightly shorter line (well I didn't count the chars):

ev = (struct hci_ev_le_advertising_info *) &skb->data[1];

Use (void *) cast here.

Quoted 12 lines
Quoted 12 lines

net/bluetooth/hci_event.c static inline void hci_le_ltk_request_evt(struct hci_dev *hdev, · line 2517

Quoted 9 lines
net/bluetooth/hci_event.c +8 -0
+
+       BT_DBG("adv from: %s", batostr(&ev->bdaddr));
+
+       for (i = 1; i < num_reports; i++) {
+               ev = (struct hci_ev_le_advertising_info *)
+                                       (ev->data + ev->length + 1);
+               BT_DBG("adv from: %s", batostr(&ev->bdaddr));
+       }

What about (not sure if it is shorter, just a suggestion):

Quoted 1 line
Quoted 1 line

ev = (struct hci_ev_le_advertising_info *) &ev->data[ev->length + 1];

Same here.

Signature · 2 lines
Gustavo F. Padovan
http://profusion.mobi