Skip to contentSkip to conversation

core: Wait for services to be resolved before doing authorization

PATCH In review Luiz Augusto von Dentz 2 participants 5 messages Mar 20, 2014 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/2 core: Wait for services to be resolved before doing authorization

From: Luiz Augusto von Dentz <[email protected]>

This makes btd_request_authorization to wait until services are resolved before proceeding with authorization, if the services could not be resolved it still proceeds with authorization since some profile may not have a record to be resolved.

---
 src/adapter.c | 38 ++++++++++++++++++++++++++++++--------
 1 file changed, 30 insertions(+), 8 deletions(-)
src/adapter.c +30 -8
index 56bee35..bc95136 100644
@@ -138,6 +138,7 @@ struct watch_client {
 
 struct service_auth {
 	guint id;
+	unsigned int svc_id;
 	service_auth_cb cb;
 	void *user_data;
 	const char *uuid;
@@ -1056,6 +1057,10 @@ static void service_auth_cancel(struct service_auth *auth)
 {
 	DBusError derr;
 
+	if (auth->svc_id > 0)
+		device_remove_svc_complete_callback(auth->device,
+								auth->svc_id);
+
 	dbus_error_init(&derr);
 	dbus_set_error_const(&derr, ERROR_INTERFACE ".Canceled", NULL);
 
@@ -4607,6 +4612,10 @@ static gboolean process_auth_queue(gpointer user_data)
 		struct btd_device *device = auth->device;
 		const char *dev_path;
 
+		/* Wait services to be resolved before asking authorization */
+		if (auth->svc_id > 0)
+			return TRUE;
+
 		if (device_is_trusted(device) == TRUE) {
 			auth->cb(NULL, auth->user_data);
 			goto next;
@@ -4643,6 +4652,22 @@ next:
 	return FALSE;
 }
 
+static void svc_complete(struct btd_device *dev, int err, void *user_data)
+{
+	struct service_auth *auth = user_data;
+	struct btd_adapter *adapter = auth->adapter;
+
+	auth->svc_id = 0;
+
+	if (adapter->auths->length != 1)
+		return;
+
+	if (adapter->auth_idle_id != 0)
+		return;
+
+	adapter->auth_idle_id = g_idle_add(process_auth_queue, adapter);
+}
+
 static int adapter_authorize(struct btd_adapter *adapter, const bdaddr_t *dst,
 					const char *uuid, service_auth_cb cb,
 					void *user_data)
@@ -4669,17 +4694,10 @@ static int adapter_authorize(struct btd_adapter *adapter, const bdaddr_t *dst,
 	auth->device = device;
 	auth->adapter = adapter;
 	auth->id = ++id;
+	auth->svc_id = device_wait_for_svc_complete(device, svc_complete, auth);
 
 	g_queue_push_tail(adapter->auths, auth);
 
-	if (adapter->auths->length != 1)
-		return auth->id;
-
-	if (adapter->auth_idle_id != 0)
-		return auth->id;
-
-	adapter->auth_idle_id = g_idle_add(process_auth_queue, adapter);
-
 	return auth->id;
 }
 
@@ -4738,6 +4756,10 @@ int btd_cancel_authorization(guint id)
 	if (auth == NULL)
 		return -EPERM;
 
+	if (auth->svc_id > 0)
+		device_remove_svc_complete_callback(auth->device,
+								auth->svc_id);
+
 	g_queue_remove(auth->adapter->auths, auth);
 
 	if (auth->agent)
Signature · 1 line
1.8.5.3
author maintainer
#1 lore raw

PATCH 1/1 obexd/client: Fix not being able cancel GET requests

From: Luiz Augusto von Dentz <[email protected]>

In case of GET operation the code does not use g_obex_get_req_pkt since the beggining to be able to read the header from the first response, this means that the request should be cancel with g_obex_cancel_req not with g_obex_cancel_transfer.

---
 obexd/client/transfer.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
obexd/client/transfer.c +16 -2
index 6295b83..3564a34 100644
@@ -80,6 +80,7 @@ struct obc_transfer {
 	char *name;		/* Transfer object name */
 	char *type;		/* Transfer object type */
 	int fd;
+	guint req;
 	guint xfer;
 	gint64 size;
 	gint64 transferred;
@@ -158,6 +159,14 @@ static DBusMessage *obc_transfer_cancel(DBusConnection *connection,
 				ERROR_INTERFACE ".InProgress",
 				"Cancellation already in progress");
 
+	if (transfer->req > 0) {
+		if (!g_obex_cancel_req(transfer->obex, transfer->req, TRUE))
+			return g_dbus_create_error(message,
+						ERROR_INTERFACE ".Failed",
+						"Failed");
+		transfer->req = 0;
+	}
+
 	if (transfer->xfer == 0) {
 		struct transfer_callback *callback = transfer->callback;
 
@@ -383,6 +392,9 @@ static void obc_transfer_free(struct obc_transfer *transfer)
 {
 	DBG("%p", transfer);
 
+	if (transfer->req > 0)
+		g_obex_cancel_req(transfer->obex, transfer->req, TRUE);
+
 	if (transfer->xfer)
 		g_obex_cancel_transfer(transfer->xfer, NULL, NULL);
 
@@ -694,6 +706,8 @@ static void get_xfer_progress_first(GObex *obex, GError *err, GObexPacket *rsp,
 				transfer->status == TRANSFER_STATUS_SUSPENDED)
 		return;
 
+	transfer->req = 0;
+
 	req = g_obex_packet_new(G_OBEX_OP_GET, TRUE, G_OBEX_HDR_INVALID);
 
 	transfer->xfer = g_obex_get_req_pkt(obex, req, get_xfer_progress,
@@ -783,11 +797,11 @@ static gboolean transfer_start_get(struct obc_transfer *transfer, GError **err)
 		g_obex_packet_add_header(req, hdr);
 	}
 
-	transfer->xfer = g_obex_send_req(transfer->obex, req,
+	transfer->req = g_obex_send_req(transfer->obex, req,
 						FIRST_PACKET_TIMEOUT,
 						get_xfer_progress_first,
 						transfer, err);
-	if (transfer->xfer == 0)
+	if (transfer->req == 0)
 		return FALSE;
 
 	if (transfer->path == NULL)
Signature · 1 line
1.8.5.3
author maintainer
#3 lore raw

PATCH 2/2 core/profile: Remove code for waiting services to be resolved

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This remove code related to waiting service to be resolved as it is now part of btd_request_authorization.

---
 src/profile.c | 56 --------------------------------------------------------
 1 file changed, 56 deletions(-)
src/profile.c +0 -56
index ecbb1c5..4fdf940 100644
@@ -619,7 +619,6 @@ struct ext_io {
 	uint8_t chan;
 
 	guint auth_id;
-	unsigned int svc_id;
 	DBusPendingCall *pending;
 };
 
@@ -708,10 +707,6 @@ static void ext_io_destroy(gpointer p)
 	if (ext_io->auth_id != 0)
 		btd_cancel_authorization(ext_io->auth_id);
 
-	if (ext_io->svc_id != 0)
-		device_remove_svc_complete_callback(ext_io->device,
-							ext_io->svc_id);
-
 	if (ext_io->pending) {
 		dbus_pending_call_cancel(ext_io->pending);
 		dbus_pending_call_unref(ext_io->pending);
@@ -1017,12 +1012,6 @@ static void ext_auth(DBusError *err, void *user_data)
 		goto drop;
 	}
 
-	if (conn->svc_id > 0) {
-		DBG("Connection from %s authorized but still waiting for SDP",
-									addr);
-		return;
-	}
-
 	if (!bt_io_accept(conn->io, ext_connect, conn, NULL, &gerr)) {
 		error("bt_io_accept: %s", gerr->message);
 		g_error_free(gerr);
@@ -1077,47 +1066,6 @@ static struct ext_io *create_conn(struct ext_io *server, GIOChannel *io,
 	return conn;
 }
 
-static void ext_svc_complete(struct btd_device *dev, int err, void *user_data)
-{
-	struct ext_io *conn = user_data;
-	struct ext_profile *ext = conn->ext;
-	const bdaddr_t *bdaddr;
-	GError *gerr = NULL;
-	char addr[18];
-
-	conn->svc_id = 0;
-
-	bdaddr = device_get_address(dev);
-	ba2str(bdaddr, addr);
-
-	if (err < 0) {
-		error("Service resolving failed for %s: %s (%d)",
-						addr, strerror(-err), -err);
-		goto drop;
-	}
-
-	DBG("Services resolved for %s", addr);
-
-	if (conn->auth_id > 0) {
-		DBG("Services resolved but still waiting for authorization");
-		return;
-	}
-
-	if (!bt_io_accept(conn->io, ext_connect, conn, NULL, &gerr)) {
-		error("bt_io_accept: %s", gerr->message);
-		g_error_free(gerr);
-		goto drop;
-	}
-
-	DBG("%s authorized to connect to %s", addr, ext->name);
-
-	return;
-
-drop:
-	ext->conns = g_slist_remove(ext->conns, conn);
-	ext_io_destroy(conn);
-}
-
 static void ext_confirm(GIOChannel *io, gpointer user_data)
 {
 	struct ext_io *server = user_data;
@@ -1156,10 +1104,6 @@ static void ext_confirm(GIOChannel *io, gpointer user_data)
 
 	ext->conns = g_slist_append(ext->conns, conn);
 
-	conn->svc_id = device_wait_for_svc_complete(conn->device,
-							ext_svc_complete,
-							conn);
-
 	DBG("%s authorizing connection from %s", ext->name, addr);
 }
 
Signature · 1 line
1.8.5.3
#4 lore raw
In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 7 lines · Luiz Augusto von Dentz

This makes btd_request_authorization to wait until services are resolved before proceeding with authorization, if the services could not be resolved it still proceeds with authorization since some profile may not have a record to be resolved.

---
 src/adapter.c | 38 ++++++++++++++++++++++++++++++--------
 1 file changed, 30 insertions(+), 8 deletions(-)

Both patches have been applied. Thanks.

Johan

#2 lore raw

Re: [PATCH BlueZ] obexd/client: Fix not being able cancel GET requests

In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 7 lines · Luiz Augusto von Dentz

In case of GET operation the code does not use g_obex_get_req_pkt since the beggining to be able to read the header from the first response, this means that the request should be cancel with g_obex_cancel_req not with g_obex_cancel_transfer.

---
 obexd/client/transfer.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

Applied. Thanks.

Johan