Skip to contentSkip to conversation

Bluetooth: Add support for Start Limited Discovery

PATCH In review Johan Hedberg 2 participants 4 messages Jan 5, 2016

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

v2 cover Bluetooth: Add support for Start Limited Discovery

v2: Use u16 instead of uint16_t for start_discovery_internal()

Hi,

These two patches implement support for the Start Limited Discovery mgmt command (that's been specified a long time ago but no-one picked up the task to implement it so far).

Johan

---
Johan Hedberg (2):
Bluetooth: Change eir_has_data_type() to more generic eir_get_data()
Bluetooth: Add support for Start Limited Discovery command

 include/net/bluetooth/hci_core.h | 31 +++++++++++++++-------
 include/net/bluetooth/mgmt.h     |  2 ++
 net/bluetooth/hci_event.c        |  6 ++---
 net/bluetooth/hci_request.c	  | 11 +++++---
 net/bluetooth/mgmt.c             | 56 ++++++++++++++++++++++++++++++++-------
 5 files changed, 80 insertions(+), 26 deletions(-)
#1 lore raw

PATCH v2 1/2 Bluetooth: Change eir_has_data_type() to more generic eir_get_data()

From: Johan Hedberg <[email protected]>

To make the EIR parsing helper more general purpose, make it return the found data and its length rather than just saying whether the data was present or not.

---
 include/net/bluetooth/hci_core.h | 30 ++++++++++++++++++++----------
 net/bluetooth/hci_event.c        |  6 +++---
 net/bluetooth/mgmt.c             |  3 ++-
 3 files changed, 25 insertions(+), 14 deletions(-)
include/net/bluetooth/hci_core.h +20 -10
index c95e0326c41a..372e2a7c4ada 100644
@@ -1283,31 +1283,41 @@ static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status,
 	mutex_unlock(&hci_cb_list_lock);
 }
 
-static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type)
+static inline void *eir_get_data(u8 *eir, size_t eir_len, u8 type,
+				 size_t *data_len)
 {
 	size_t parsed = 0;
 
-	if (data_len < 2)
-		return false;
+	if (eir_len < 2)
+		return NULL;
 
-	while (parsed < data_len - 1) {
-		u8 field_len = data[0];
+	while (parsed < eir_len - 1) {
+		u8 field_len = eir[0];
 
 		if (field_len == 0)
 			break;
 
 		parsed += field_len + 1;
 
-		if (parsed > data_len)
+		if (parsed > eir_len)
 			break;
 
-		if (data[1] == type)
-			return true;
+		if (eir[1] != type) {
+			eir += field_len + 1;
+			continue;
+		}
+
+		/* Zero length data */
+		if (field_len == 1)
+			return NULL;
 
-		data += field_len + 1;
+		if (data_len)
+			*data_len = field_len - 1;
+
+		return &eir[2];
 	}
 
-	return false;
+	return NULL;
 }
 
 static inline bool hci_bdaddr_is_rpa(bdaddr_t *bdaddr, u8 addr_type)
net/bluetooth/hci_event.c +3 -3
index 7554da5b7a8f..c162af5d16bf 100644
@@ -3833,9 +3833,9 @@ static void hci_extended_inquiry_result_evt(struct hci_dev *hdev,
 		data.ssp_mode		= 0x01;
 
 		if (hci_dev_test_flag(hdev, HCI_MGMT))
-			name_known = eir_has_data_type(info->data,
-						       sizeof(info->data),
-						       EIR_NAME_COMPLETE);
+			name_known = eir_get_data(info->data,
+						  sizeof(info->data),
+						  EIR_NAME_COMPLETE, NULL);
 		else
 			name_known = true;
 
net/bluetooth/mgmt.c +2 -1
index 621f6fdd0dd1..3297a4ecc05e 100644
@@ -7266,7 +7266,8 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
 		/* Copy EIR or advertising data into event */
 		memcpy(ev->eir, eir, eir_len);
 
-	if (dev_class && !eir_has_data_type(ev->eir, eir_len, EIR_CLASS_OF_DEV))
+	if (dev_class && !eir_get_data(ev->eir, eir_len, EIR_CLASS_OF_DEV,
+				       NULL))
 		eir_len = eir_append_data(ev->eir, eir_len, EIR_CLASS_OF_DEV,
 					  dev_class, 3);
 
Signature · 1 line
2.5.0
#2 lore raw

PATCH v2 2/2 Bluetooth: Add support for Start Limited Discovery command

In reply to Johan Hedberg

From: Johan Hedberg <[email protected]>

This patch implements the mgmt Start Limited Discovery command. Most of existing Start Discovery code is reused since the only difference is the presence of a 'limited' flag as part of the discovery state.

---
 include/net/bluetooth/hci_core.h |  1 +
 include/net/bluetooth/mgmt.h     |  2 ++
 net/bluetooth/hci_request.c      | 11 ++++++---
 net/bluetooth/mgmt.c             | 53 +++++++++++++++++++++++++++++++++-------
 4 files changed, 55 insertions(+), 12 deletions(-)
include/net/bluetooth/hci_core.h +1 -0
index 372e2a7c4ada..d4f82edb5cff 100644
@@ -77,6 +77,7 @@ struct discovery_state {
 	u8			last_adv_data_len;
 	bool			report_invalid_rssi;
 	bool			result_filtering;
+	bool			limited;
 	s8			rssi;
 	u16			uuid_count;
 	u8			(*uuids)[16];
include/net/bluetooth/mgmt.h +2 -0
index af17774c9416..ea73e0826aa7 100644
@@ -584,6 +584,8 @@ struct mgmt_rp_get_adv_size_info {
 	__u8	max_scan_rsp_len;
 } __packed;
 
+#define MGMT_OP_START_LIMITED_DISCOVERY	0x0041
+
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	__le16	opcode;
net/bluetooth/hci_request.c +8 -3
index 9997c31ef987..794299c4673a 100644
@@ -1737,8 +1737,8 @@ static int le_scan_disable(struct hci_request *req, unsigned long opt)
 static int bredr_inquiry(struct hci_request *req, unsigned long opt)
 {
 	u8 length = opt;
-	/* General inquiry access code (GIAC) */
-	u8 lap[3] = { 0x33, 0x8b, 0x9e };
+	u8 giac[3] = { 0x33, 0x8b, 0x9e };
+	u8 liac[3] = { 0x00, 0x8b, 0x9e };
 	struct hci_cp_inquiry cp;
 
 	BT_DBG("%s", req->hdev->name);
@@ -1748,7 +1748,12 @@ static int bredr_inquiry(struct hci_request *req, unsigned long opt)
 	hci_dev_unlock(req->hdev);
 
 	memset(&cp, 0, sizeof(cp));
-	memcpy(&cp.lap, lap, sizeof(cp.lap));
+
+	if (req->hdev->discovery.limited)
+		memcpy(&cp.lap, liac, sizeof(cp.lap));
+	else
+		memcpy(&cp.lap, giac, sizeof(cp.lap));
+
 	cp.length = length;
 
 	hci_req_add(req, HCI_OP_INQUIRY, sizeof(cp), &cp);
net/bluetooth/mgmt.c +44 -9

112 lines not on this page · raw message

Signature · 1 line
2.5.0
maintainer
#3 lore raw
In reply to Johan Hedberg

Hi Johan,

Quoted 11 lines

These two patches implement support for the Start Limited Discovery mgmt command (that's been specified a long time ago but no-one picked up the task to implement it so far).

Johan

---
Johan Hedberg (2):
Bluetooth: Change eir_has_data_type() to more generic eir_get_data()
Bluetooth: Add support for Start Limited Discovery command

Quoted 6 lines
include/net/bluetooth/hci_core.h | 31 +++++++++++++++-------
include/net/bluetooth/mgmt.h     |  2 ++
net/bluetooth/hci_event.c        |  6 ++---
net/bluetooth/hci_request.c	  | 11 +++++---
net/bluetooth/mgmt.c             | 56 ++++++++++++++++++++++++++++++++-------
5 files changed, 80 insertions(+), 26 deletions(-)

both patches have been applied to bluetooth-next tree.

Regards

Marcel