Skip to contentSkip to conversation

device: Fix Connect and ConnectProfile returing InProgress error

PATCH Applied Szymon Janc 1 participant 2 messages Jan 18, 2018 – Jan 19, 2018 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 device: Fix Connect and ConnectProfile returing InProgress error

Calling Connect or ConnectProfile for device without resolved services results in doing SDP browse first. After search is complete code was suppose to continue with profile connection but was always returning "InProgress" error due to browsing request not being cleared yet.

---
 src/device.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)
src/device.c +19 -6
index 72f18b309..1acecce33 100644
@@ -2230,6 +2230,7 @@ static void browse_request_complete(struct browse_req *req, uint8_t type,
 {
 	struct btd_device *dev = req->device;
 	DBusMessage *reply = NULL;
+	DBusMessage *msg;
 
 	if (req->type != type)
 		return;
@@ -2266,19 +2267,31 @@ static void browse_request_complete(struct browse_req *req, uint8_t type,
 		goto done;
 	}
 
-	if (dbus_message_is_method_call(req->msg, DEVICE_INTERFACE, "Connect"))
-		reply = dev_connect(dbus_conn, req->msg, dev);
-	else if (dbus_message_is_method_call(req->msg, DEVICE_INTERFACE,
+	/* if successfully resolved services we need to free browsing request
+	 * before passing message back to connect functions, otherwise
+	 * device->browse is set and "InProgress" error is returned instead
+	 * of actually connecting services
+	 */
+	msg = dbus_message_ref(req->msg);
+	browse_request_free(req);
+	req = NULL;
+
+	if (dbus_message_is_method_call(msg, DEVICE_INTERFACE, "Connect"))
+		reply = dev_connect(dbus_conn, msg, dev);
+	else if (dbus_message_is_method_call(msg, DEVICE_INTERFACE,
 							"ConnectProfile"))
-		reply = connect_profile(dbus_conn, req->msg, dev);
+		reply = connect_profile(dbus_conn, msg, dev);
 	else
-		reply = g_dbus_create_reply(req->msg, DBUS_TYPE_INVALID);
+		reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+
+	dbus_message_unref(msg);
 
 done:
 	if (reply)
 		g_dbus_send_message(dbus_conn, reply);
 
-	browse_request_free(req);
+	if (req)
+		browse_request_free(req);
 }
 
 static void device_set_svc_refreshed(struct btd_device *device, bool value)
Signature · 1 line
2.14.3
author Applied
#1 lore raw
Quoted 48 lines · On Thursday, 18 January 2018 17:37:53 CET Szymon Janc wrote:

Calling Connect or ConnectProfile for device without resolved services results in doing SDP browse first. After search is complete code was suppose to continue with profile connection but was always returning "InProgress" error due to browsing request not being cleared yet.

---
 src/device.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)
src/device.c +17 -5
index 72f18b309..1acecce33 100644
@@ -2230,6 +2230,7 @@ static void browse_request_complete(struct browse_req
 *req, uint8_t type, {
 	struct btd_device *dev = req->device;
 	DBusMessage *reply = NULL;
+	DBusMessage *msg;
 
 	if (req->type != type)
 		return;
@@ -2266,19 +2267,31 @@ static void browse_request_complete(struct
 browse_req *req, uint8_t type, goto done;
 	}
 
-	if (dbus_message_is_method_call(req->msg, DEVICE_INTERFACE, "Connect"))
-		reply = dev_connect(dbus_conn, req->msg, dev);
-	else if (dbus_message_is_method_call(req->msg, DEVICE_INTERFACE,
+	/* if successfully resolved services we need to free browsing request
+	 * before passing message back to connect functions, otherwise
+	 * device->browse is set and "InProgress" error is returned instead
+	 * of actually connecting services
+	 */
+	msg = dbus_message_ref(req->msg);
+	browse_request_free(req);
+	req = NULL;
+
+	if (dbus_message_is_method_call(msg, DEVICE_INTERFACE, "Connect"))
+		reply = dev_connect(dbus_conn, msg, dev);
+	else if (dbus_message_is_method_call(msg, DEVICE_INTERFACE,
 							"ConnectProfile"))
-		reply = connect_profile(dbus_conn, req->msg, dev);
+		reply = connect_profile(dbus_conn, msg, dev);
 	else
-		reply = g_dbus_create_reply(req->msg, DBUS_TYPE_INVALID);
+		reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+
+	dbus_message_unref(msg);
 

src/device.c static void browse_request_complete(struct · line 2297

Quoted 10 lines
src/device.c +2 -1
 done:
 	if (reply)
 		g_dbus_send_message(dbus_conn, reply);
 
-	browse_request_free(req);
+	if (req)
+		browse_request_free(req);
 }
 
 static void device_set_svc_refreshed(struct btd_device *device, bool value)

Applied.

Signature · 2 lines
pozdrawiam
Szymon Janc