Skip to contentSkip to conversation

Bluetooth: Include ADV_IND report in Device Connected event

PATCH Superseded Alfonso Acosta 2 participants 2 messages Oct 3, 2014 – Oct 4, 2014

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Bluetooth: Include ADV_IND report in Device Connected event

There are scenarios when autoconnecting to a device after the reception of an ADV_IND report (action 0x02), in which userland might want to examine the report's contents.

For instance, the Service Data might have changed and it would be useful to know ahead of time before starting any GATT procedures. Also, the ADV_IND may contain Manufacturer Specific data which would be lost if not propagated to userland. In fact, this patch results from the need to rebond with a device lacking persistent storage which notifies about losing its LTK in ADV_IND reports.

This patch appends the ADV_IND report which triggered the autoconnection to the EIR Data in the Device Connected event.

---
 include/net/bluetooth/hci_core.h |  5 ++++-
 net/bluetooth/hci_event.c        | 42 ++++++++++++++++++++++++++--------------
 net/bluetooth/l2cap_core.c       |  2 +-
 net/bluetooth/mgmt.c             | 26 ++++++++++++++++++-------
 4 files changed, 52 insertions(+), 23 deletions(-)
include/net/bluetooth/hci_core.h +4 -1
index f1407fe..aa3a960 100644
@@ -398,6 +398,8 @@ struct hci_conn {
 	__u16		le_conn_interval;
 	__u16		le_conn_latency;
 	__u16		le_supv_timeout;
+	__u8		le_adv_data[HCI_MAX_AD_LENGTH];
+	__u8		le_adv_data_len;
 	__s8		rssi;
 	__s8		tx_power;
 	__s8		max_tx_power;
@@ -1311,7 +1313,8 @@ void mgmt_discoverable_timeout(struct hci_dev *hdev);
 void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
 		       bool persistent);
 void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn,
-			   u32 flags, u8 *name, u8 name_len);
+			   u32 flags, u8 *name, u8 name_len,
+			   u8 *adv, u8 adv_len);
 void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
 			      u8 link_type, u8 addr_type, u8 reason,
 			      bool mgmt_connected);
net/bluetooth/hci_event.c +28 -14

129 lines not on this page · raw message

net/bluetooth/l2cap_core.c +1 -1
index 2ff5591..98be19b 100644
@@ -3873,7 +3873,7 @@ static int l2cap_connect_req(struct l2cap_conn *conn,
 	hci_dev_lock(hdev);
 	if (test_bit(HCI_MGMT, &hdev->dev_flags) &&
 	    !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &hcon->flags))
-		mgmt_device_connected(hdev, hcon, 0, NULL, 0);
+		mgmt_device_connected(hdev, hcon, 0, NULL, 0, NULL, 0);
 	hci_dev_unlock(hdev);
 
 	l2cap_connect(conn, cmd, data, L2CAP_CONN_RSP, 0);
net/bluetooth/mgmt.c +19 -7
index fc275dc..b97cb9e 100644
@@ -6172,7 +6172,8 @@ static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type, u8 *data,
 }
 
 void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn,
-			   u32 flags, u8 *name, u8 name_len)
+			   u32 flags, u8 *name, u8 name_len,
+			   u8 *adv, u8 adv_len)
 {
 	char buf[512];
 	struct mgmt_ev_device_connected *ev = (void *) buf;
@@ -6183,13 +6184,24 @@ void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn,
 
 	ev->flags = __cpu_to_le32(flags);
 
-	if (name_len > 0)
-		eir_len = eir_append_data(ev->eir, 0, EIR_NAME_COMPLETE,
-					  name, name_len);
+	/* We must ensure that the EIR Data fields are ordered and
+	 * unique. Keep it simple for now and avoid the problem by not
+	 * adding any BR/EDR data to the LE adv.
+	 */
+	if (adv) {
+		memcpy(&ev->eir[eir_len], adv, adv_len);
+		eir_len = adv_len;
+	} else {
+		if (name_len > 0)
+			eir_len = eir_append_data(ev->eir, 0, EIR_NAME_COMPLETE,
+						  name, name_len);
 
-	if (conn->dev_class && memcmp(conn->dev_class, "\0\0\0", 3) != 0)
-		eir_len = eir_append_data(ev->eir, eir_len,
-					  EIR_CLASS_OF_DEV, conn->dev_class, 3);
+		if (conn->dev_class &&
+		    memcmp(conn->dev_class, "\0\0\0", 3) != 0)
+			eir_len = eir_append_data(ev->eir, eir_len,
+						  EIR_CLASS_OF_DEV,
+						  conn->dev_class, 3);
+	}
 
 	ev->eir_len = cpu_to_le16(eir_len);
 
Signature · 1 line
1.9.1
#1 lore raw

Hi Alfonso,

include/net/bluetooth/hci_core.h void mgmt_discoverable_timeout(struct hci_dev *hdev); · line 1317

Quoted 4 lines · Alfonso Acosta

void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn,

include/net/bluetooth/hci_core.h +2 -1
-			   u32 flags, u8 *name, u8 name_len);
+			   u32 flags, u8 *name, u8 name_len,
+			   u8 *adv, u8 adv_len);

Now that you're already passing the full hci_conn to this function I guess it's a bit pointless to add new parameters to it which would anyway come from that same hci_conn object.

Quoted 9 lines

void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn,

net/bluetooth/mgmt.c +2 -1
-			   u32 flags, u8 *name, u8 name_len)
+			   u32 flags, u8 *name, u8 name_len,
+			   u8 *adv, u8 adv_len)
 {
 	char buf[512];
 	struct mgmt_ev_device_connected *ev = (void *) buf;
@@ -6183,13 +6184,24 @@ void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn,
 

net/bluetooth/mgmt.c void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn, · line 6191

Quoted 10 lines
net/bluetooth/mgmt.c +5 -3
 	ev->flags = __cpu_to_le32(flags);
 
-	if (name_len > 0)
-		eir_len = eir_append_data(ev->eir, 0, EIR_NAME_COMPLETE,
-					  name, name_len);
+	/* We must ensure that the EIR Data fields are ordered and
+	 * unique. Keep it simple for now and avoid the problem by not
+	 * adding any BR/EDR data to the LE adv.
+	 */
+	if (adv) {

And once you do the earlier fix I suppose this check becomes:

	if (conn->le_adv_data_len > 0) {

Besides this one issue with the unnecessary extra parameters both of your patches look good to me.

Johan