[RFC 3/8] android/bluetooth: Refactor start/stop discovery

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

 



From: Jakub Tyszkowski <jakub.tyszkowski@xxxxxxxxx>

Pass discovery type to discovery stop/start routine so it can be used
also for LE only scan.
---
 android/bluetooth.c | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/android/bluetooth.c b/android/bluetooth.c
index acd2dd2..8f66dd1 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -80,6 +80,10 @@
 #define BASELEN_REMOTE_DEV_PROP (sizeof(struct hal_ev_remote_device_props) \
 					+ sizeof(struct hal_property))
 
+#define SCAN_TYPE_BREDR (1 << BDADDR_BREDR)
+#define SCAN_TYPE_LE ((1 << BDADDR_LE_PUBLIC) | (1 << BDADDR_LE_RANDOM))
+#define SCAN_TYPE_DUAL (SCAN_TYPE_BREDR | SCAN_TYPE_LE)
+
 struct device {
 	bdaddr_t bdaddr;
 	uint8_t bdaddr_type;
@@ -2448,17 +2452,26 @@ static void get_adapter_properties(void)
 	get_adapter_discoverable_timeout();
 }
 
-static bool start_discovery(void)
+static uint8_t get_adapter_discovering_type(void)
 {
-	struct mgmt_cp_start_discovery cp;
+	uint8_t type;
 
 	if (adapter.current_settings & MGMT_SETTING_BREDR)
-		cp.type = 1 << BDADDR_BREDR;
+		type = SCAN_TYPE_BREDR;
 	else
-		cp.type = 0;
+		type = 0;
 
 	if (adapter.current_settings & MGMT_SETTING_LE)
-		cp.type |= (1 << BDADDR_LE_PUBLIC) | (1 << BDADDR_LE_RANDOM);
+		type |= SCAN_TYPE_LE;
+
+	return type;
+}
+
+static bool start_discovery(uint8_t type)
+{
+	struct mgmt_cp_start_discovery cp;
+
+	cp.type = get_adapter_discovering_type() & type;
 
 	DBG("type=0x%x", cp.type);
 
@@ -2478,17 +2491,11 @@ static void cancel_pending_confirm_name(gpointer data, gpointer user_data)
 	dev->confirm_id = 0;
 }
 
-static bool stop_discovery(void)
+static bool stop_discovery(uint8_t type)
 {
 	struct mgmt_cp_stop_discovery cp;
 
-	if (adapter.current_settings & MGMT_SETTING_BREDR)
-		cp.type = 1 << BDADDR_BREDR;
-	else
-		cp.type = 0;
-
-	if (adapter.current_settings & MGMT_SETTING_LE)
-		cp.type |= (1 << BDADDR_LE_PUBLIC) | (1 << BDADDR_LE_RANDOM);
+	cp.type = get_adapter_discovering_type() & type;
 
 	DBG("type=0x%x", cp.type);
 
@@ -3182,7 +3189,7 @@ static void handle_start_discovery_cmd(const void *buf, uint16_t len)
 		goto reply;
 	}
 
-	if (!start_discovery()) {
+	if (!start_discovery(SCAN_TYPE_DUAL)) {
 		status = HAL_STATUS_FAILED;
 		goto reply;
 	}
@@ -3207,7 +3214,7 @@ static void handle_cancel_discovery_cmd(const void *buf, uint16_t len)
 		goto reply;
 	}
 
-	if (!stop_discovery()) {
+	if (!stop_discovery(SCAN_TYPE_DUAL)) {
 		status = HAL_STATUS_FAILED;
 		goto reply;
 	}
-- 
1.8.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