Skip to contentSkip to conversation

obexd: Fix can't receive small files sent by windows

PATCH Superseded xinpeng wang 3 participants 3 messages Mar 25, 2022 Bluetooth drivers

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 obexd: Fix can't receive small files sent by windows

When obexd receives a file, it parses the filename and other parameters when processing the packet for the first time, store filename in obex_session and emit the dbus signal, The signal will be pending first. then when this file is received, transfer_complete reset obex_session is called.

When using a computer with Windows 10 installed to send a file to bluez, obexd will read the data through read_stream; if it is a small file, the data processed for the first time is marked as final, and transfer_complete reset obex_session will be called when the data is processed for the first time. At this point, the dbus signal is still pending, and the dbus method that requests the file path has not been processed. This will cause the upper application to not be able to transfer files from the cache directory to the directory specified by the user.

To solve this problem, emit Filename's dbus signal and force it when status=active.

Ways to reproduce the problem:
1. Use the computer with windows 10 installed to send a small file to the computer with ubuntu installed;
2. file size < 10k;
3. After sending, in most cases, the file is located in the ~/.cache/obexd/ directory. Normally, the file should be located in the ~/Download directory.

To fix this, after applying this commit, it also needs to be modified by the upper-level application. Modified to read Filename from dbus signal if there is Filename in dbus signal. Otherwise, use the dbus method to request Filename.

---
v2: Add the steps to reproduce the bug in the submission information.

 obexd/src/manager.c | 6 +++++-
 obexd/src/obex.c    | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)
obexd/src/manager.c +5 -1
index 01741fe62..2c180dc44 100644
@@ -533,8 +533,12 @@ void manager_emit_transfer_property(struct obex_transfer *transfer,
 void manager_emit_transfer_started(struct obex_transfer *transfer)
 {
 	transfer->status = TRANSFER_STATUS_ACTIVE;
+	if (!transfer->path)
+		return;
 
-	manager_emit_transfer_property(transfer, "Status");
+	g_dbus_emit_property_changed_full(connection, transfer->path,
+					TRANSFER_INTERFACE, "Status",
+					G_DBUS_PROPERTY_CHANGED_FLAG_FLUSH);
 }
 
 static void emit_transfer_completed(struct obex_transfer *transfer,
obexd/src/obex.c +1 -0
index 3a68fd66c..c0d9e160a 100644
@@ -720,6 +720,7 @@ int obex_put_stream_start(struct obex_session *os, const char *filename)
 		manager_emit_transfer_property(os->service_data, "Size");
 
 	os->path = g_strdup(filename);
+	manager_emit_transfer_property(os->service_data, "Filename");
 
 	return 0;
 }
Signature · 1 line
2.20.1
Acked-by on v2 1/1
#1 lore raw

Dear Xinpeng,

Am 25.03.22 um 08:13 schrieb xinpeng wang:

Quoted 61 lines

When obexd receives a file, it parses the filename and other parameters when processing the packet for the first time, store filename in obex_session and emit the dbus signal, The signal will be pending first. then when this file is received, transfer_complete reset obex_session is called.

When using a computer with Windows 10 installed to send a file to bluez, obexd will read the data through read_stream; if it is a small file, the data processed for the first time is marked as final, and transfer_complete reset obex_session will be called when the data is processed for the first time. At this point, the dbus signal is still pending, and the dbus method that requests the file path has not been processed. This will cause the upper application to not be able to transfer files from the cache directory to the directory specified by the user.

To solve this problem, emit Filename's dbus signal and force it when status=active.

Ways to reproduce the problem:
1. Use the computer with windows 10 installed to send a small file to the computer with ubuntu installed;
2. file size < 10k;
3. After sending, in most cases, the file is located in the ~/.cache/obexd/ directory. Normally, the file should be located in the ~/Download directory.

To fix this, after applying this commit, it also needs to be modified by the upper-level application. Modified to read Filename from dbus signal if there is Filename in dbus signal. Otherwise, use the dbus method to request Filename.

---
v2: Add the steps to reproduce the bug in the submission information.

  obexd/src/manager.c | 6 +++++-
  obexd/src/obex.c    | 1 +
  2 files changed, 6 insertions(+), 1 deletion(-)
obexd/src/manager.c +5 -1
index 01741fe62..2c180dc44 100644
@@ -533,8 +533,12 @@ void manager_emit_transfer_property(struct obex_transfer *transfer,
  void manager_emit_transfer_started(struct obex_transfer *transfer)
  {
  	transfer->status = TRANSFER_STATUS_ACTIVE;
+	if (!transfer->path)
+		return;
 
-	manager_emit_transfer_property(transfer, "Status");
+	g_dbus_emit_property_changed_full(connection, transfer->path,
+					TRANSFER_INTERFACE, "Status",
+					G_DBUS_PROPERTY_CHANGED_FLAG_FLUSH);
  }
 
  static void emit_transfer_completed(struct obex_transfer *transfer,
obexd/src/obex.c +0 -0
index 3a68fd66c..c0d9e160a 100644

obexd/src/obex.c int obex_put_stream_start(struct obex_session *os, const char *filename) · line 726

Quoted 7 lines
obexd/src/obex.c +1 -0
@@ -720,6 +720,7 @@ int obex_put_stream_start(struct obex_session *os, const char *filename)
  		manager_emit_transfer_property(os->service_data, "Size");
 
  	os->path = g_strdup(filename);
+	manager_emit_transfer_property(os->service_data, "Filename");
 
  	return 0;
  }

Awesome. Thank you.

Kind regards,

Paul

#2 lore raw

Hi Paul, Xinpeng,

Quoted 22 lines · Paul Menzel

Dear Xinpeng,

Am 25.03.22 um 08:13 schrieb xinpeng wang:

Quoted 17 lines

When obexd receives a file, it parses the filename and other parameters when processing the packet for the first time, store filename in obex_session and emit the dbus signal, The signal will be pending first. then when this file is received, transfer_complete reset obex_session is called.

When using a computer with Windows 10 installed to send a file to bluez, obexd will read the data through read_stream; if it is a small file, the data processed for the first time is marked as final, and transfer_complete reset obex_session will be called when the data is processed for the first time. At this point, the dbus signal is still pending, and the dbus method that requests the file path has not been processed. This will cause the upper application to not be able to transfer files from the cache directory to the directory specified by the user.

To solve this problem, emit Filename's dbus signal and force it when status=active.

It would be great to have the obexctl output with and without the change, also does it change anything with respect of bigger files that are not completed with a single packet?

Quoted 7 lines
Quoted 7 lines

Ways to reproduce the problem:
1. Use the computer with windows 10 installed to send a small file to the computer with ubuntu installed;
2. file size < 10k;
3. After sending, in most cases, the file is located in the ~/.cache/obexd/ directory. Normally, the file should be located in the ~/Download directory.

Quoted 6 lines
Quoted 6 lines

To fix this, after applying this commit, it also needs to be modified by the upper-level application. Modified to read Filename from dbus signal if there is Filename in dbus signal. Otherwise, use the dbus method to request Filename.

We don't use Signed-off-by for userspace.

Quoted 46 lines
Quoted 30 lines

---
v2: Add the steps to reproduce the bug in the submission information.

  obexd/src/manager.c | 6 +++++-
  obexd/src/obex.c    | 1 +
  2 files changed, 6 insertions(+), 1 deletion(-)
obexd/src/manager.c +5 -1
index 01741fe62..2c180dc44 100644
@@ -533,8 +533,12 @@ void manager_emit_transfer_property(struct obex_transfer *transfer,
  void manager_emit_transfer_started(struct obex_transfer *transfer)
  {
      transfer->status = TRANSFER_STATUS_ACTIVE;
+     if (!transfer->path)
+             return;
 
-     manager_emit_transfer_property(transfer, "Status");
+     g_dbus_emit_property_changed_full(connection, transfer->path,
+                                     TRANSFER_INTERFACE, "Status",
+                                     G_DBUS_PROPERTY_CHANGED_FLAG_FLUSH);
  }
 
  static void emit_transfer_completed(struct obex_transfer *transfer,
obexd/src/obex.c +0 -0
index 3a68fd66c..c0d9e160a 100644

obexd/src/obex.c int obex_put_stream_start(struct obex_session *os, const char *filename) · line 726

Quoted 7 lines
obexd/src/obex.c +1 -0
@@ -720,6 +720,7 @@ int obex_put_stream_start(struct obex_session *os, const char *filename)
              manager_emit_transfer_property(os->service_data, "Size");
 
      os->path = g_strdup(filename);
+     manager_emit_transfer_property(os->service_data, "Filename");
 
      return 0;
  }

Awesome. Thank you.

Kind regards,

Paul

Signature · 1 line
Luiz Augusto von Dentz