[PATCH 23/32] Avoid multiple links with the same device

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

 



---
 health/hdp.c |   42 ++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/health/hdp.c b/health/hdp.c
index d6a8758..ed26fe5 100644
--- a/health/hdp.c
+++ b/health/hdp.c
@@ -117,7 +117,8 @@ static int hdp_instance_idcmp(gconstpointer instance, gconstpointer p)
 	return -1;
 }
 
-static int hdp_link_mcl_cmp(gconstpointer link, gconstpointer mcl){
+static int hdp_link_mcl_cmp(gconstpointer link, gconstpointer mcl)
+{
 	const struct hdp_link *hdpl = link;
 
 	if (hdpl->mcl == mcl)
@@ -125,6 +126,17 @@ static int hdp_link_mcl_cmp(gconstpointer link, gconstpointer mcl){
 	return -1;
 }
 
+static int hdp_link_addr_cmp(gconstpointer link, gconstpointer addr)
+{
+	const struct hdp_link *hdpl = link;
+	const bdaddr_t *dst;
+        bdaddr_t mcl_addr;
+
+	dst = addr;
+	mcl_addr = mcap_mcl_get_addr(hdpl->mcl);
+	return bacmp(addr, &mcl_addr);
+}
+
 static void set_health_link_path(struct hdp_link *hdpl)
 {
 	char path[MAX_PATH_LENGTH + 1];
@@ -534,12 +546,27 @@ fail:
 	g_dbus_send_message(device->conn, reply);
 }
 
+static struct hdp_link *get_health_link(struct hdp_instance *hdpi,
+						struct hdp_device *device)
+{
+	bdaddr_t dst;
+	GSList *l;
+
+	device_get_address(device->dev, &dst);
+	l = g_slist_find_custom(hdpi->hlink, &dst, hdp_link_addr_cmp);
+	if (l)
+		return l->data;
+	return NULL;
+}
+
 static DBusMessage *hdp_connect(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
 	struct hdp_device *device = user_data;
 	struct hdp_connection_cb *cb_data;
 	struct btd_adapter *adapter;
+	struct hdp_instance *hdpi;
+	struct hdp_link *hdpl;
 	bdaddr_t src, dst;
 	uint32_t lid, rid;
 	uuid_t uuid;
@@ -561,9 +588,20 @@ static DBusMessage *hdp_connect(DBusConnection *conn,
 					   ERROR_INTERFACE ".InvalidArguments",
 					   "Invalid local health instance id");
 
+	hdpi = l->data;
+	hdpl = get_health_link(hdpi, device);
+	if (hdpl) {
+		if (hdpl->closed) {
+			DBG("Need a reconection");
+			/* TODO: Reconnect */;
+		} else
+			return g_dbus_create_reply(msg, DBUS_TYPE_OBJECT_PATH,
+						&hdpl->path, DBUS_TYPE_INVALID);
+	}
+
 	cb_data = g_new0(struct hdp_connection_cb, 1);
 	cb_data->device = device;
-	cb_data->hdpi = l->data;
+	cb_data->hdpi = hdpi;
 	cb_data->rem_id = rid;
 	cb_data->msg = dbus_message_ref(msg);
 
-- 
1.6.3.3

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