All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ] service: Add initiator argument to service_accept
Date: Wed, 11 May 2022 17:55:15 -0700	[thread overview]
Message-ID: <20220512005515.844857-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20220512005515.844857-1-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds initiator argument to service_accept so profiles accepting
the connection can use btd_service_is_initiator to determine if the
connection was initiated locally (central) or remotely (peripheral).
---
 src/device.c  | 18 ++++++++++++++++--
 src/service.c |  4 +++-
 src/service.h |  2 +-
 3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/src/device.c b/src/device.c
index b0309a1e7..a39eb8c64 100644
--- a/src/device.c
+++ b/src/device.c
@@ -158,6 +158,7 @@ struct bearer_state {
 	bool bonded;
 	bool connected;
 	bool svc_resolved;
+	bool initiator;
 };
 
 struct csrk_info {
@@ -297,6 +298,16 @@ static struct bearer_state *get_state(struct btd_device *dev,
 		return &dev->le_state;
 }
 
+static bool get_initiator(struct btd_device *dev)
+{
+	if (dev->le_state.connected)
+		return dev->le_state.initiator;
+	if (dev->bredr_state.connected)
+		return dev->bredr_state.initiator;
+
+	return false;
+}
+
 static GSList *find_service_with_profile(GSList *list, struct btd_profile *p)
 {
 	GSList *l;
@@ -3256,6 +3267,7 @@ void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type)
 		return;
 
 	state->connected = false;
+	state->initiator = false;
 	device->general_connect = FALSE;
 
 	device_set_svc_refreshed(device, false);
@@ -4169,7 +4181,7 @@ done:
 	}
 
 	/* Notify driver about the new connection */
-	service_accept(service);
+	service_accept(service, get_initiator(device));
 }
 
 static void device_add_gatt_services(struct btd_device *device)
@@ -4191,7 +4203,7 @@ static void device_accept_gatt_profiles(struct btd_device *device)
 	GSList *l;
 
 	for (l = device->services; l != NULL; l = g_slist_next(l))
-		service_accept(l->data);
+		service_accept(l->data, get_initiator(device));
 }
 
 static void device_remove_gatt_service(struct btd_device *device,
@@ -5899,6 +5911,8 @@ int device_connect_le(struct btd_device *dev)
 
 	/* Keep this, so we can cancel the connection */
 	dev->att_io = io;
+	/* Set as initiator */
+	dev->le_state.initiator = true;
 
 	return 0;
 }
diff --git a/src/service.c b/src/service.c
index 14a4c292b..7c4dc8fe0 100644
--- a/src/service.c
+++ b/src/service.c
@@ -172,7 +172,7 @@ void service_remove(struct btd_service *service)
 	btd_service_unref(service);
 }
 
-int service_accept(struct btd_service *service)
+int service_accept(struct btd_service *service, bool initiator)
 {
 	char addr[18];
 	int err;
@@ -198,6 +198,8 @@ int service_accept(struct btd_service *service)
 		return -ECONNABORTED;
 	}
 
+	service->initiator = initiator;
+
 	err = service->profile->accept(service);
 	if (!err)
 		goto done;
diff --git a/src/service.h b/src/service.h
index fa930f985..dc0d1d132 100644
--- a/src/service.h
+++ b/src/service.h
@@ -35,7 +35,7 @@ struct btd_service *service_create(struct btd_device *device,
 int service_probe(struct btd_service *service);
 void service_remove(struct btd_service *service);
 
-int service_accept(struct btd_service *service);
+int service_accept(struct btd_service *service, bool initiator);
 int service_set_connecting(struct btd_service *service);
 
 /* Connection control API */
-- 
2.35.1


  reply	other threads:[~2022-05-12  0:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-12  0:55 [PATCH BlueZ] gatt-db: Allow passing Characteristic Value to gatt_db_attribute_get_char_data Luiz Augusto von Dentz
2022-05-12  0:55 ` Luiz Augusto von Dentz [this message]
2022-05-12  3:06   ` [BlueZ] service: Add initiator argument to service_accept bluez.test.bot
2022-05-13  0:00   ` [PATCH BlueZ] " patchwork-bot+bluetooth
2022-05-12  3:16 ` [BlueZ] gatt-db: Allow passing Characteristic Value to gatt_db_attribute_get_char_data bluez.test.bot
2022-05-13  0:00 ` [PATCH BlueZ] " patchwork-bot+bluetooth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220512005515.844857-2-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.