linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] service: Add btd_service_is_initiator
@ 2021-09-16 20:40 Luiz Augusto von Dentz
  2021-09-16 20:40 ` [PATCH v2 2/2] policy: Use btd_service_is_initiator Luiz Augusto von Dentz
  2021-09-16 21:34 ` [v2,1/2] service: Add btd_service_is_initiator bluez.test.bot
  0 siblings, 2 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2021-09-16 20:40 UTC (permalink / raw)
  To: linux-bluetooth

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

Since BTD_SERVICE_STATE_CONNECTING is being used for both initiator and
responder case it is no longer possible to use the state distint when
the service connection was initiated locally or not, so to fix this a
new flag is introduce to track when btd_service_connect has been
called.
---
 src/service.c | 10 ++++++++++
 src/service.h |  1 +
 2 files changed, 11 insertions(+)

diff --git a/src/service.c b/src/service.c
index 84fbb208a..14a4c292b 100644
--- a/src/service.c
+++ b/src/service.c
@@ -42,6 +42,7 @@ struct btd_service {
 	btd_service_state_t	state;
 	int			err;
 	bool			is_allowed;
+	bool			initiator;
 };
 
 struct service_state_callback {
@@ -96,6 +97,9 @@ static void change_state(struct btd_service *service, btd_service_state_t state,
 
 		cb->cb(service, old, state, cb->user_data);
 	}
+
+	if (state == BTD_SERVICE_STATE_DISCONNECTED)
+		service->initiator = false;
 }
 
 struct btd_service *btd_service_ref(struct btd_service *service)
@@ -261,6 +265,7 @@ int btd_service_connect(struct btd_service *service)
 
 	err = profile->connect(service);
 	if (err == 0) {
+		service->initiator = true;
 		change_state(service, BTD_SERVICE_STATE_CONNECTING, 0);
 		return 0;
 	}
@@ -343,6 +348,11 @@ int btd_service_get_error(const struct btd_service *service)
 	return service->err;
 }
 
+bool btd_service_is_initiator(const struct btd_service *service)
+{
+	return service->initiator;
+}
+
 unsigned int btd_service_add_state_cb(btd_service_state_cb cb, void *user_data)
 {
 	struct service_state_callback *state_cb;
diff --git a/src/service.h b/src/service.h
index 5a2a02447..fa930f985 100644
--- a/src/service.h
+++ b/src/service.h
@@ -47,6 +47,7 @@ struct btd_device *btd_service_get_device(const struct btd_service *service);
 struct btd_profile *btd_service_get_profile(const struct btd_service *service);
 btd_service_state_t btd_service_get_state(const struct btd_service *service);
 int btd_service_get_error(const struct btd_service *service);
+bool btd_service_is_initiator(const struct btd_service *service);
 
 unsigned int btd_service_add_state_cb(btd_service_state_cb cb,
 							void *user_data);
-- 
2.31.1


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

* [PATCH v2 2/2] policy: Use btd_service_is_initiator
  2021-09-16 20:40 [PATCH v2 1/2] service: Add btd_service_is_initiator Luiz Augusto von Dentz
@ 2021-09-16 20:40 ` Luiz Augusto von Dentz
  2021-09-16 21:34 ` [v2,1/2] service: Add btd_service_is_initiator bluez.test.bot
  1 sibling, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2021-09-16 20:40 UTC (permalink / raw)
  To: linux-bluetooth

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

Instead of using BTD_SERVICE_STATE_CONNECTING use
btd_service_is_initiator to determine if the service initiated the
connection and then proceed to connect other service immediately.

Fixes: https://github.com/bluez/bluez/issues/205
---
 plugins/policy.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/plugins/policy.c b/plugins/policy.c
index bf93df096..051db82e1 100644
--- a/plugins/policy.c
+++ b/plugins/policy.c
@@ -279,7 +279,7 @@ static void sink_cb(struct btd_service *service, btd_service_state_t old_state,
 		/* Check if service initiate the connection then proceed
 		 * immediatelly otherwise set timer
 		 */
-		if (old_state == BTD_SERVICE_STATE_CONNECTING)
+		if (btd_service_is_initiator(service))
 			policy_connect(data, controller);
 		else if (btd_service_get_state(controller) !=
 						BTD_SERVICE_STATE_CONNECTED)
@@ -315,7 +315,7 @@ static void hs_cb(struct btd_service *service, btd_service_state_t old_state,
 		/* Check if service initiate the connection then proceed
 		 * immediately otherwise set timer
 		 */
-		if (old_state == BTD_SERVICE_STATE_CONNECTING)
+		if (btd_service_is_initiator(service))
 			policy_connect(data, sink);
 		else if (btd_service_get_state(sink) !=
 						BTD_SERVICE_STATE_CONNECTED)
@@ -430,7 +430,7 @@ static void source_cb(struct btd_service *service,
 		/* Check if service initiate the connection then proceed
 		 * immediatelly otherwise set timer
 		 */
-		if (old_state == BTD_SERVICE_STATE_CONNECTING)
+		if (btd_service_is_initiator(service))
 			policy_connect(data, target);
 		else if (btd_service_get_state(target) !=
 						BTD_SERVICE_STATE_CONNECTED)
-- 
2.31.1


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

* RE: [v2,1/2] service: Add btd_service_is_initiator
  2021-09-16 20:40 [PATCH v2 1/2] service: Add btd_service_is_initiator Luiz Augusto von Dentz
  2021-09-16 20:40 ` [PATCH v2 2/2] policy: Use btd_service_is_initiator Luiz Augusto von Dentz
@ 2021-09-16 21:34 ` bluez.test.bot
  1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2021-09-16 21:34 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz

[-- Attachment #1: Type: text/plain, Size: 884 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=548445

---Test result---

Test Summary:
CheckPatch                    PASS      2.81 seconds
GitLint                       PASS      1.91 seconds
Prep - Setup ELL              PASS      50.54 seconds
Build - Prep                  PASS      0.54 seconds
Build - Configure             PASS      9.26 seconds
Build - Make                  PASS      222.81 seconds
Make Check                    PASS      9.35 seconds
Make Distcheck                PASS      254.55 seconds
Build w/ext ELL - Configure   PASS      8.89 seconds
Build w/ext ELL - Make        PASS      206.22 seconds



---
Regards,
Linux Bluetooth


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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-16 20:40 [PATCH v2 1/2] service: Add btd_service_is_initiator Luiz Augusto von Dentz
2021-09-16 20:40 ` [PATCH v2 2/2] policy: Use btd_service_is_initiator Luiz Augusto von Dentz
2021-09-16 21:34 ` [v2,1/2] service: Add btd_service_is_initiator bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).