[PATCH BlueZ 4/6] tools/btpclient: Add device found event

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

 



This patch adds device found event handler. It's called when rssi
property of device changes and new device interface is added.
---
 tools/btpclient.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/tools/btpclient.c b/tools/btpclient.c
index 095c5ea3e..c0ad03b68 100644
--- a/tools/btpclient.c
+++ b/tools/btpclient.c
@@ -399,6 +399,37 @@ failed:
 	btp_send_error(btp, BTP_GAP_SERVICE, index, status);
 }
 
+static void btp_gap_device_found_ev(struct l_dbus_proxy *proxy)
+{
+	struct btp_device_found_ev ev;
+	const char *str;
+
+	if (!l_dbus_proxy_get_property(proxy, "Address", "s", &str) ||
+					(str2addr(str, ev.address) != 6))
+		return;
+
+	if (!l_dbus_proxy_get_property(proxy, "AddressType", "s", &str))
+		return;
+
+	ev.address_type = strcmp(str, "public") ? BTP_GAP_ADDR_RANDOM :
+							BTP_GAP_ADDR_PUBLIC;
+
+	if (!l_dbus_proxy_get_property(proxy, "RSSI", "n", &ev.rssi))
+		return;
+
+	/* TODO Temporary set all flags */
+	ev.flags = (BTP_EV_GAP_DEVICE_FOUND_FLAG_RSSI |
+					BTP_EV_GAP_DEVICE_FOUND_FLAG_AD |
+					BTP_EV_GAP_DEVICE_FOUND_FLAG_SR);
+
+	/* TODO Add eir to device found event */
+	ev.eir_len = 0;
+
+	btp_send(btp, BTP_GAP_SERVICE, BTP_EV_GAP_DEVICE_FOUND,
+						BTP_INDEX_NON_CONTROLLER,
+						sizeof(ev) + ev.eir_len, &ev);
+}
+
 static void register_gap_service(void)
 {
 	btp_register(btp, BTP_GAP_SERVICE, BTP_OP_GAP_READ_SUPPORTED_COMMANDS,
@@ -661,6 +692,8 @@ static void proxy_added(struct l_dbus_proxy *proxy, void *user_data)
 
 		l_queue_push_tail(adapter->devices, device);
 
+		btp_gap_device_found_ev(proxy);
+
 		return;
 	}
 
@@ -782,6 +815,15 @@ static void property_changed(struct l_dbus_proxy *proxy, const char *name,
 			update_current_settings(adapter, new_settings);
 
 		return;
+	} else if (!strcmp(interface, "org.bluez.Device1")) {
+		if (!strcmp(name, "RSSI")) {
+			uint16_t rssi;
+
+			if (!l_dbus_message_get_arguments(msg, "n", &rssi))
+				return;
+
+			btp_gap_device_found_ev(proxy);
+		}
 	}
 }
 
-- 
2.13.6

--
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