All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] core: Move EIR flags definitions to eir.h
@ 2014-03-21 16:34 Szymon Janc
  2014-03-21 16:34 ` [PATCH 2/3] android/bluetooth: Filter out not discoverable LE devices Szymon Janc
  2014-03-21 16:34 ` [PATCH 3/3] adapter: Fix checking if LE device is discoverable Szymon Janc
  0 siblings, 2 replies; 3+ messages in thread
From: Szymon Janc @ 2014-03-21 16:34 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

---
 src/adapter.c | 15 ++++-----------
 src/eir.h     |  9 +++++++++
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index e3de8cf..ac756c1 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -72,15 +72,6 @@
 
 #define ADAPTER_INTERFACE	"org.bluez.Adapter1"
 
-/* Flags Descriptions */
-#define EIR_LIM_DISC                0x01 /* LE Limited Discoverable Mode */
-#define EIR_GEN_DISC                0x02 /* LE General Discoverable Mode */
-#define EIR_BREDR_UNSUP             0x04 /* BR/EDR Not Supported */
-#define EIR_SIM_CONTROLLER          0x08 /* Simultaneous LE and BR/EDR to Same
-					    Device Capable (Controller) */
-#define EIR_SIM_HOST                0x10 /* Simultaneous LE and BR/EDR to Same
-					    Device Capable (Host) */
-
 #define MODE_OFF		0x00
 #define MODE_CONNECTABLE	0x01
 #define MODE_DISCOVERABLE	0x02
@@ -4309,7 +4300,8 @@ static void update_found_devices(struct btd_adapter *adapter,
 
 	/* Avoid creating LE device if it's not discoverable */
 	if (bdaddr_type != BDADDR_BREDR &&
-			!(eir_data.flags & (EIR_LIM_DISC | EIR_GEN_DISC))) {
+			!(eir_data.flags &
+				(EIR_FLAG_LIM_DISC | EIR_FLAG_GEN_DISC))) {
 		eir_data_free(&eir_data);
 		return;
 	}
@@ -4339,7 +4331,8 @@ static void update_found_devices(struct btd_adapter *adapter,
 
 	device_update_last_seen(dev, bdaddr_type);
 
-	if (bdaddr_type != BDADDR_BREDR && !(eir_data.flags & EIR_BREDR_UNSUP))
+	if (bdaddr_type != BDADDR_BREDR &&
+				!(eir_data.flags & EIR_FLAG_BREDR_UNSUP))
 		device_set_bredr_support(dev, true);
 
 	if (eir_data.name != NULL && eir_data.name_complete)
diff --git a/src/eir.h b/src/eir.h
index 3fa1cb3..326292a 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -38,6 +38,15 @@
 #define EIR_DEVICE_ID               0x10  /* device ID */
 #define EIR_GAP_APPEARANCE          0x19  /* GAP appearance */
 
+/* Flags Descriptions */
+#define EIR_FLAG_LIM_DISC           0x01 /* LE Limited Discoverable Mode */
+#define EIR_FLAG_GEN_DISC           0x02 /* LE General Discoverable Mode */
+#define EIR_FLAG_BREDR_UNSUP        0x04 /* BR/EDR Not Supported */
+#define EIR_FLAG_CONTROLLER         0x08 /* Simultaneous LE and BR/EDR to Same
+					    Device Capable (Controller) */
+#define EIR_FLAG_SIM_HOST           0x10 /* Simultaneous LE and BR/EDR to Same
+					    Device Capable (Host) */
+
 struct eir_data {
 	GSList *services;
 	int flags;
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/3] android/bluetooth: Filter out not discoverable LE devices
  2014-03-21 16:34 [PATCH 1/3] core: Move EIR flags definitions to eir.h Szymon Janc
@ 2014-03-21 16:34 ` Szymon Janc
  2014-03-21 16:34 ` [PATCH 3/3] adapter: Fix checking if LE device is discoverable Szymon Janc
  1 sibling, 0 replies; 3+ messages in thread
From: Szymon Janc @ 2014-03-21 16:34 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

Filter out the LE devices that do not have Discoverable flag or Limited
Discoverable flag set.

Kernel is not adding flags field to EIR if none of flags is set so this
is also treated as non-discoverable if device is LE. For devices that
are connected flags are ignored and Android Framework is always
notified on new device.
---
 android/bluetooth.c | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index d2795e3..5c7ba59 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -1164,8 +1164,16 @@ static bool rssi_above_threshold(int old, int new)
 	return abs(old - new) >= 8;
 }
 
+static bool is_le_discoverable(int flags)
+{
+	if (flags < 0)
+		return false;
+
+	return flags & (EIR_FLAG_LIM_DISC | EIR_FLAG_GEN_DISC);
+}
+
 static void update_new_device(struct device *dev, int8_t rssi,
-						const struct eir_data *eir)
+				const struct eir_data *eir, bool connected)
 {
 	uint8_t buf[IPC_MTU];
 	struct hal_ev_device_found *ev = (void *) buf;
@@ -1213,12 +1221,16 @@ static void update_new_device(struct device *dev, int8_t rssi,
 		ev->num_props++;
 	}
 
+	if (!connected && dev->bdaddr_type != BDADDR_BREDR &&
+					!is_le_discoverable(eir->flags))
+		return;
+
 	ipc_send_notif(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, HAL_EV_DEVICE_FOUND,
 								size, buf);
 }
 
 static void update_device(struct device *dev, int8_t rssi,
-						const struct eir_data *eir)
+				const struct eir_data *eir, bool connected)
 {
 	uint8_t buf[IPC_MTU];
 	struct hal_ev_remote_device_props *ev = (void *) buf;
@@ -1253,6 +1265,10 @@ static void update_device(struct device *dev, int8_t rssi,
 		ev->num_props++;
 	}
 
+	if (!connected && dev->bdaddr_type != BDADDR_BREDR &&
+					!is_le_discoverable(eir->flags))
+		return;
+
 	if (ev->num_props)
 		ipc_send_notif(hal_ipc, HAL_SERVICE_ID_BLUETOOTH,
 					HAL_EV_REMOTE_DEVICE_PROPS, size, buf);
@@ -1260,7 +1276,8 @@ static void update_device(struct device *dev, int8_t rssi,
 
 static void update_found_device(const bdaddr_t *bdaddr, uint8_t bdaddr_type,
 					int8_t rssi, bool confirm,
-					const uint8_t *data, uint8_t data_len)
+					const uint8_t *data, uint8_t data_len,
+					bool connected)
 {
 	struct eir_data eir;
 	struct device *dev;
@@ -1278,9 +1295,9 @@ static void update_found_device(const bdaddr_t *bdaddr, uint8_t bdaddr_type,
 		if (!dev)
 			dev = create_device(bdaddr, bdaddr_type);
 
-		update_new_device(dev, rssi, &eir);
+		update_new_device(dev, rssi, &eir, connected);
 	} else {
-		update_device(dev, rssi, &eir);
+		update_device(dev, rssi, &eir, connected);
 	}
 
 	/* Notify Gatt if its registered for LE events */
@@ -1349,7 +1366,7 @@ static void mgmt_device_found_event(uint16_t index, uint16_t length,
 	confirm_name = flags & MGMT_DEV_FOUND_CONFIRM_NAME;
 
 	update_found_device(&ev->addr.bdaddr, ev->addr.type, ev->rssi,
-						confirm_name, eir, eir_len);
+					confirm_name, eir, eir_len, false);
 }
 
 static void mgmt_device_connected_event(uint16_t index, uint16_t length,
@@ -1364,7 +1381,7 @@ static void mgmt_device_connected_event(uint16_t index, uint16_t length,
 	}
 
 	update_found_device(&ev->addr.bdaddr, ev->addr.type, 0, false,
-					&ev->eir[0], btohs(ev->eir_len));
+					&ev->eir[0], btohs(ev->eir_len), true);
 
 	hal_ev.status = HAL_STATUS_SUCCESS;
 	hal_ev.state = HAL_ACL_STATE_CONNECTED;
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 3/3] adapter: Fix checking if LE device is discoverable
  2014-03-21 16:34 [PATCH 1/3] core: Move EIR flags definitions to eir.h Szymon Janc
  2014-03-21 16:34 ` [PATCH 2/3] android/bluetooth: Filter out not discoverable LE devices Szymon Janc
@ 2014-03-21 16:34 ` Szymon Janc
  1 sibling, 0 replies; 3+ messages in thread
From: Szymon Janc @ 2014-03-21 16:34 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

Kernel is not adding flags field to EIR if none of flags is set.
---
 src/adapter.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index ac756c1..ee3358d 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -4300,8 +4300,8 @@ static void update_found_devices(struct btd_adapter *adapter,
 
 	/* Avoid creating LE device if it's not discoverable */
 	if (bdaddr_type != BDADDR_BREDR &&
-			!(eir_data.flags &
-				(EIR_FLAG_LIM_DISC | EIR_FLAG_GEN_DISC))) {
+				(eir_data.flags < 0 || !(eir_data.flags &
+				(EIR_FLAG_LIM_DISC | EIR_FLAG_GEN_DISC)))) {
 		eir_data_free(&eir_data);
 		return;
 	}
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-03-21 16:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-21 16:34 [PATCH 1/3] core: Move EIR flags definitions to eir.h Szymon Janc
2014-03-21 16:34 ` [PATCH 2/3] android/bluetooth: Filter out not discoverable LE devices Szymon Janc
2014-03-21 16:34 ` [PATCH 3/3] adapter: Fix checking if LE device is discoverable Szymon Janc

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.