[PATCH 3/3] Bluetooth: Process extended ADV report event

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch enables Extended ADV report event if extended scanning
is supported in the controller and process the same.

The new features are not handled and for now its as good as
legacy ADV report.

> HCI Event: LE Meta Event (0x3e) plen 53
      LE Extended Advertising Report (0x0d)
        Num reports: 1
        Entry 0
          Event type: 0x0013
            Props: 0x0013
              Connectable
              Scannable
              Use legacy advertising PDUs
            Data status: Complete
          Legacy PDU Type: ADV_IND (0x0013)
          Address type: Random (0x01)
          Address: DB:7E:2E:1A:85:E8 (Static)
          Primary PHY: LE 1M
          Secondary PHY: LE 1M
          SID: 0x00
          TX power: 0 dBm
          RSSI: -90 dBm (0xa6)
          Periodic advertising invteral: 0.00 msec (0x0000)
          Direct address type: Public (0x00)
          Direct address: 00:00:00:00:00:00 (OUI 00-00-00)
          Data length: 0x1b
        0f 09 44 65 73 69 67 6e 65 72 20 4d 6f 75 73 65  ..Designer Mouse
        03 19 c2 03 02 01 05 03 03 12 18                 ...........

Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@xxxxxxxxx>
---
 include/net/bluetooth/hci.h | 26 +++++++++++++++++++++++
 net/bluetooth/hci_core.c    |  7 ++++++
 net/bluetooth/hci_event.c   | 52 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 6dba592..a4ab295 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -1917,6 +1917,15 @@ struct hci_ev_le_conn_complete {
 #define LE_ADV_SCAN_IND                0x02
 #define LE_ADV_NONCONN_IND     0x03
 #define LE_ADV_SCAN_RSP                0x04
+#define LE_ADV_INVALID         0x05
+
+/* Legacy event types in extended adv report */
+#define LE_LEGACY_ADV_IND              0x0013
+#define LE_LEGACY_ADV_DIRECT_IND       0x0015
+#define LE_LEGACY_ADV_SCAN_IND         0x0012
+#define LE_LEGACY_NONCONN_IND          0x0010
+#define LE_LEGACY_SCAN_RSP_ADV         0x001b
+#define LE_LEGACY_SCAN_RSP_ADV_SCAN    0x001a

 #define ADDR_LE_DEV_PUBLIC     0x00
 #define ADDR_LE_DEV_RANDOM     0x01
@@ -1981,6 +1990,23 @@ struct hci_ev_le_direct_adv_info {
        __s8     rssi;
 } __packed;

+#define HCI_EV_LE_EXT_ADV_REPORT    0x0d
+struct hci_ev_le_ext_adv_report {
+       __le16   evt_type;
+       __u8     bdaddr_type;
+       bdaddr_t bdaddr;
+       __u8     primary_phy;
+       __u8     secondary_phy;
+       __u8     sid;
+       __u8     tx_power;
+       __s8     rssi;
+       __le16   interval;
+       __u8     direct_addr_type;
+       bdaddr_t direct_addr;
+       __u8     length;
+       __u8     data[0];
+} __packed;
+
 /* Internal events generated by Bluetooth stack */
 #define HCI_EV_STACK_INTERNAL  0xfd
 struct hci_ev_stack_internal {
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 6bc679c..eb5999a 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -704,6 +704,13 @@ static int hci_init3_req(struct hci_request *req,
unsigned long opt)
                if (hdev->commands[35] & (0x20 | 0x40))
                        events[1] |= 0x08;        /* LE PHY Update Complete */

+               /* If the controller supports LE Set Extended Scan param and
+                * LE Set Extended Scan enable commands, enable the
+                * corresponding event.
+                */
+               if (hdev->commands[37] & 0x20 && hdev->commands[37] & 0x40)
+                       events[1] |= 0x10;      /* LE Extended adv report */
+
                hci_req_add(req, HCI_OP_LE_SET_EVENT_MASK, sizeof(events),
                            events);

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 72e7de2..9e0cd51 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -5001,6 +5001,54 @@ static void hci_le_adv_report_evt(struct
hci_dev *hdev, struct sk_buff *skb)
        hci_dev_unlock(hdev);
 }

+static u8 convert_legacy_evt_type(u16 evt_type)
+{
+       switch (evt_type) {
+       case LE_LEGACY_ADV_IND:
+               return LE_ADV_IND;
+       case LE_LEGACY_ADV_DIRECT_IND:
+               return LE_ADV_DIRECT_IND;
+       case LE_LEGACY_ADV_SCAN_IND:
+               return LE_ADV_SCAN_IND;
+       case LE_LEGACY_NONCONN_IND:
+               return LE_ADV_NONCONN_IND;
+       case LE_LEGACY_SCAN_RSP_ADV:
+       case LE_LEGACY_SCAN_RSP_ADV_SCAN:
+               return LE_ADV_SCAN_RSP;
+       }
+
+       BT_ERR_RATELIMITED("Unknown advertising packet type: 0x%02x",
+                                  evt_type);
+
+       return LE_ADV_INVALID;
+}
+
+static void hci_le_ext_adv_report_evt(struct hci_dev *hdev, struct
sk_buff *skb)
+{
+       u8 num_reports = skb->data[0];
+       void *ptr = &skb->data[1];
+
+       hci_dev_lock(hdev);
+
+       while (num_reports--) {
+               struct hci_ev_le_ext_adv_report *ev = ptr;
+               u8 legacy_evt_type;
+               u16 evt_type;
+
+               evt_type = __le16_to_cpu(ev->evt_type);
+               legacy_evt_type = convert_legacy_evt_type(evt_type);
+               if (legacy_evt_type != LE_ADV_INVALID) {
+                       process_adv_report(hdev, legacy_evt_type, &ev->bdaddr,
+                                          ev->bdaddr_type, NULL, 0, ev->rssi,
+                                          ev->data, ev->length);
+               }
+
+               ptr += sizeof(*ev) + ev->length + 1;
+       }
+
+       hci_dev_unlock(hdev);
+}
+
 static void hci_le_remote_feat_complete_evt(struct hci_dev *hdev,
                                            struct sk_buff *skb)
 {
@@ -5233,6 +5281,10 @@ static void hci_le_meta_evt(struct hci_dev
*hdev, struct sk_buff *skb)
                hci_le_direct_adv_report_evt(hdev, skb);
                break;

+       case HCI_EV_LE_EXT_ADV_REPORT:
+               hci_le_ext_adv_report_evt(hdev, skb);
+               break;
+
        default:
                break;
        }
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux