Skip to content
This repository was archived by the owner on Oct 30, 2021. It is now read-only.

Commit c215e93

Browse files
jaganathkrholtmann
authored andcommitted
Bluetooth: Process extended ADV report event
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@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent a2344b9 commit c215e93

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

include/net/bluetooth/hci.h

+26
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,15 @@ struct hci_ev_le_conn_complete {
19251925
#define LE_ADV_SCAN_IND 0x02
19261926
#define LE_ADV_NONCONN_IND 0x03
19271927
#define LE_ADV_SCAN_RSP 0x04
1928+
#define LE_ADV_INVALID 0x05
1929+
1930+
/* Legacy event types in extended adv report */
1931+
#define LE_LEGACY_ADV_IND 0x0013
1932+
#define LE_LEGACY_ADV_DIRECT_IND 0x0015
1933+
#define LE_LEGACY_ADV_SCAN_IND 0x0012
1934+
#define LE_LEGACY_NONCONN_IND 0x0010
1935+
#define LE_LEGACY_SCAN_RSP_ADV 0x001b
1936+
#define LE_LEGACY_SCAN_RSP_ADV_SCAN 0x001a
19281937

19291938
#define ADDR_LE_DEV_PUBLIC 0x00
19301939
#define ADDR_LE_DEV_RANDOM 0x01
@@ -1989,6 +1998,23 @@ struct hci_ev_le_direct_adv_info {
19891998
__s8 rssi;
19901999
} __packed;
19912000

2001+
#define HCI_EV_LE_EXT_ADV_REPORT 0x0d
2002+
struct hci_ev_le_ext_adv_report {
2003+
__le16 evt_type;
2004+
__u8 bdaddr_type;
2005+
bdaddr_t bdaddr;
2006+
__u8 primary_phy;
2007+
__u8 secondary_phy;
2008+
__u8 sid;
2009+
__u8 tx_power;
2010+
__s8 rssi;
2011+
__le16 interval;
2012+
__u8 direct_addr_type;
2013+
bdaddr_t direct_addr;
2014+
__u8 length;
2015+
__u8 data[0];
2016+
} __packed;
2017+
19922018
/* Internal events generated by Bluetooth stack */
19932019
#define HCI_EV_STACK_INTERNAL 0xfd
19942020
struct hci_ev_stack_internal {

net/bluetooth/hci_core.c

+9
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,15 @@ static int hci_init3_req(struct hci_request *req, unsigned long opt)
695695
if (hdev->commands[35] & (0x20 | 0x40))
696696
events[1] |= 0x08; /* LE PHY Update Complete */
697697

698+
/* If the controller supports LE Set Extended Scan Parameters
699+
* and LE Set Extended Scan Enable commands, enable the
700+
* corresponding event.
701+
*/
702+
if (use_ext_scan(hdev))
703+
events[1] |= 0x10; /* LE Extended Advertising
704+
* Report
705+
*/
706+
698707
hci_req_add(req, HCI_OP_LE_SET_EVENT_MASK, sizeof(events),
699708
events);
700709

net/bluetooth/hci_event.c

+52
Original file line numberDiff line numberDiff line change
@@ -5048,6 +5048,54 @@ static void hci_le_adv_report_evt(struct hci_dev *hdev, struct sk_buff *skb)
50485048
hci_dev_unlock(hdev);
50495049
}
50505050

5051+
static u8 convert_legacy_evt_type(u16 evt_type)
5052+
{
5053+
switch (evt_type) {
5054+
case LE_LEGACY_ADV_IND:
5055+
return LE_ADV_IND;
5056+
case LE_LEGACY_ADV_DIRECT_IND:
5057+
return LE_ADV_DIRECT_IND;
5058+
case LE_LEGACY_ADV_SCAN_IND:
5059+
return LE_ADV_SCAN_IND;
5060+
case LE_LEGACY_NONCONN_IND:
5061+
return LE_ADV_NONCONN_IND;
5062+
case LE_LEGACY_SCAN_RSP_ADV:
5063+
case LE_LEGACY_SCAN_RSP_ADV_SCAN:
5064+
return LE_ADV_SCAN_RSP;
5065+
}
5066+
5067+
BT_ERR_RATELIMITED("Unknown advertising packet type: 0x%02x",
5068+
evt_type);
5069+
5070+
return LE_ADV_INVALID;
5071+
}
5072+
5073+
static void hci_le_ext_adv_report_evt(struct hci_dev *hdev, struct sk_buff *skb)
5074+
{
5075+
u8 num_reports = skb->data[0];
5076+
void *ptr = &skb->data[1];
5077+
5078+
hci_dev_lock(hdev);
5079+
5080+
while (num_reports--) {
5081+
struct hci_ev_le_ext_adv_report *ev = ptr;
5082+
u8 legacy_evt_type;
5083+
u16 evt_type;
5084+
5085+
evt_type = __le16_to_cpu(ev->evt_type);
5086+
legacy_evt_type = convert_legacy_evt_type(evt_type);
5087+
if (legacy_evt_type != LE_ADV_INVALID) {
5088+
process_adv_report(hdev, legacy_evt_type, &ev->bdaddr,
5089+
ev->bdaddr_type, NULL, 0, ev->rssi,
5090+
ev->data, ev->length);
5091+
}
5092+
5093+
ptr += sizeof(*ev) + ev->length + 1;
5094+
}
5095+
5096+
hci_dev_unlock(hdev);
5097+
}
5098+
50515099
static void hci_le_remote_feat_complete_evt(struct hci_dev *hdev,
50525100
struct sk_buff *skb)
50535101
{
@@ -5280,6 +5328,10 @@ static void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb)
52805328
hci_le_direct_adv_report_evt(hdev, skb);
52815329
break;
52825330

5331+
case HCI_EV_LE_EXT_ADV_REPORT:
5332+
hci_le_ext_adv_report_evt(hdev, skb);
5333+
break;
5334+
52835335
default:
52845336
break;
52855337
}

0 commit comments

Comments
 (0)