Commit Graph

44 Commits

Author SHA1 Message Date
Dmitry Baryshkov
533779cb8a
Merge pull request #24 from nik012003/master
tqftpserv.service.in: remove dependency on qrtr-ns.service
2024-11-21 18:13:30 +02:00
Nicola Guerrera
cab8b18f9a
tqftpserv.service.in: remove dependency on qrtr-ns.service
QRTR is built in to the kernel now, the other packages (such as rmtfs) have since removed qrtr-ns as a service dependency

Signed-off-by: Nicola Guerrera <guerrera.nicola@gmail.com>
2024-11-09 00:22:37 +01:00
Dmitry Baryshkov
859c6e3969
Merge pull request #23 from a-wai/firmware-updates
translate: lookup firmware files under /lib/firmware/updates
2024-10-19 19:37:05 +03:00
Dmitry Baryshkov
bbfff09e16
Merge pull request #22 from evelikov/zstd-followups
Follow-up zstd fixes
2024-10-16 17:33:58 +03:00
Arnaud Ferraris
4744c0ce07 translate: lookup firmware files under /lib/firmware/updates
`/lib/firmware/updates` is a legitimate location for firmware files,
`tqftpserv` should look there as well.
2024-09-25 10:52:52 +02:00
Emil Velikov
f9da0667fb Fix Android build without zstd
Bit of a blind fix, since I don't have an Android dev setup nearby.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2024-09-21 16:10:16 +01:00
Emil Velikov
0f7fd27524 Use context-less zstd decompression API
Currently we pre-allocate around 128K of zstd state ahead of time,
keeping if for the whole daemon lifetime... Even if we don't need to
decompress any files. As mentioned by Dmitry:

    Granted that tqftpserv handles only few files during the whole
    lifetime and most of devices don't have swap, I think it's fine to
    use non-context versions of the functions. Let's free the memory for
    other software.

Swap ZSTD_decompressDCtx() for ZSTD_decompress() which will allocate and
free the state when needed.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2024-09-21 16:09:21 +01:00
Emil Velikov
95d0c67322 Explicitly open zstd file as read-only
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2024-09-19 12:53:27 +01:00
Emil Velikov
085a87c279 Clear memory leaks during zstd decompression
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2024-09-19 12:48:16 +01:00
Konrad Dybcio
48e143d273 meson.build: Set v1.1 version
Signed-off-by: Konrad Dybcio <konrad.dybcio@linaro.org>
2024-07-23 14:25:36 +02:00
Stefan Hansson
0197df8e61 Add support for zstd-compressed readonly files
We need this to load compressed files from linux-firmware.

Closes https://github.com/linux-msm/tqftpserv/issues/19

Signed-off-by: Stefan Hansson <newbyte@postmarketos.org>
Tested-by: Nikita Travkin <nikita@trvn.ru>
2024-07-23 14:20:00 +02:00
Alexey Minnekhanov
47e8957271 meson.build: Make systemd dep optional
Some distros still don't use SystemD (yet), make it optional.

It is not required to build the binary, just to install systemd
unit file.

Signed-off-by: Alexey Minnekhanov <alexey.min@gmail.com>
2024-04-30 23:51:30 +02:00
Konrad Dybcio
5f9f263ae2 treewide: meson 2024-04-23 19:38:37 +02:00
Konrad Dybcio
3a10a7dd6f treewide: use SPDX license IDs 2024-04-08 23:53:19 +02:00
Luca Weiss
a09948e5e3 tqftpserv: don't print "End of Transfer" as an error
On newer modems, the firmware seems to use a stat-like operation
relatively often which end the transfer with error 9 "End of Transfer".

In practise we're getting a RRQ with the tsize option set, we'll query
the file size from the filesystem, respond with the updated tsize in
OACK, then the modem will send us OP_ERROR with code 9 "End of
Transfer".

Since that's expected in this operation, let's not make it look like an
error to not confuse users/developers trying to debug the modem.
2024-04-08 23:17:36 +02:00
Luca Weiss
588a8d3c8f tqftpserv: add rsize & offset options to RRQ print
Since new modems send multiple file requests with different rsize and
offset on a single file, it's useful to print those also.
2024-04-08 23:17:36 +02:00
Luca Weiss
e167336fca tqftpserv: handle rsize & offset options
The rsize (number of bytes the client wants to receive) and offset (the
offset in bytes from the start of file) are used on newer modems (such
as SM7225 or QCM6490), so let's support them properly.

Some examples to illustrate the usage:
* rsize=160 seek=52: we should send 160 bytes starting at byte 52 in the
  requested file. With blksize=7680 this is a single 160(+4) sized
  packet.
* rsize=313028 seek=81920: we should send in total 313028 bytes,
  starting at byte 81920. With blksize=7680 and wsize=10 this spans
  multiple windows of 10 packets each, that example would be packed into
  41 packets with an ACK between every 10 windows - and a final ACK at
  the end.
* rsize=53760 blksize=7680: We send 7 packets of 7680 bytes each, then
  we send 1 packet with 0 bytes of data (only 4 bytes header) and then
  get an ACK on packet 8.
2024-04-08 23:17:36 +02:00
Luca Weiss
69c7cfcf73 tqftpserv: add seek option parsing
Actual handling will be added in follow-up commits as rsize is also not
currently handled, and both are quite interconnected.
2024-04-08 23:17:36 +02:00
Luca Weiss
2dd48a2899 tqftpserv: allow sending data packet with 0-byte data payload
If the client requests a file that's completely empty, it makes sense to
send a response to that request with - well - 0 bytes of data and just
the 4-byte header.

But also if the client requests for example a file of rsize=53760 and
blksize=7680, then will send 7 full packets of data in the window, but
afterwards we still need to send an empty packet (just the 4 bytes of
header) to make sure the client understands that we've sent all the
requested data. Otherwise it's going to time out and re-request the
blocks and we're stuck in a loop.

So consider pread return value of 0 to not be an error and send a
response packet back.
2024-04-08 23:17:36 +02:00
Luca Weiss
98d162c9ff translate: Fix firmware path for 'fallback' case
The dirname() function can and will modify the parameter, so if we call
dirname() twice on the same firmware_value parameter we will get
separate results messing up our names.

Copy the firmware_value value before passing it to dirname(). Also let's
just do this operation once to save copy-pasting some code.

Fixes: a4c755d ("Use firmware path from sysfs")
2024-04-08 22:31:59 +02:00
Konrad Dybcio
37669ab1e2
Merge pull request #12 from minlexx/respect-firmware-sysfs-path
Use firmware path from sysfs
2024-03-27 21:27:08 +01:00
Alexey Minnekhanov
a4c755db17 Use firmware path from sysfs
Some linux distributions adjust path fro kernel to load
firmware from using /sys/module/firmware_class/parameters/path.
Kernel supports it, teach tqftpserv to respect it too.

Signed-off-by: Alexey Minnekhanov <alexeymin@postmarketos.org>
2024-03-24 00:00:31 +03:00
Bjorn Andersson
289214a5d1
Merge pull request #11 from z3ntu/misc-improvements
Some improvements for error handling
2024-01-22 09:57:48 -06:00
Luca Weiss
00fe2775de tqftpserv: add docs for options
The explanation is spread throughout various RFCs or the code - or at
least for rsize based on strace'ing the communication.
2024-01-19 11:52:32 +01:00
Luca Weiss
fb20008c86 translate: don't try to close already closed class_fd
After calling fdopendir "the file descriptor is under the control of the
system" and calling closedir(class_dir) already closes class_fd, so
let's not try to close it again.

Just close class_fd when fdopendir fails and remove the close call from
the regular exit path.
2024-01-18 15:33:46 +01:00
Luca Weiss
a540a1c307 tqftpserv: also print value for unknown options 2023-02-10 13:17:28 +01:00
Luca Weiss
3fa49eafe0 tqftpserv: handle OP_ERROR code
When we get an error from the remote we should print it, for example:

  [TQFTP] received error:  8 - Expected OACK for UNLINK
2023-02-10 12:13:00 +01:00
Luca Weiss
aaba76c6ba tqftpserv: also print error code on read error
Along with the error message we also get a uint16 error code that we can
print.
2023-02-10 12:10:46 +01:00
John Stultz
de42697a24 translate: Null terminate firmware_value string
Null terminate firmware_value string to prevent
strlen() read past the end of buffer.

Change-Id: I57cd01c4d0c58c6057872bc4b36129f09bc034a3
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
2023-01-17 22:57:14 -06:00
Amit Pundir
538efb3096 translate: Use /data/vendor for temporary files
On AOSP, /tmp is not available. Use /data/vendor instead
for temporary files.

Change-Id: I1d6ebd669573b3c3134e6da943ea9355ed83a3fe
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
2023-01-17 22:57:14 -06:00
Sireesh Kodali
48b9e1cbb1 tqftpserv: add support for TFTP options on WRQs 2023-01-17 22:56:21 -06:00
Jami Kettunen
3488007880 Makefile: allow $(CFLAGS), $(LDFLAGS) override
The caller might have specified CFLAGS or LDFLAGS. Let's respect those.
2023-01-17 22:54:25 -06:00
Amit Pundir
783425b550 ANDROID: Add Android.bp makefile
Add Android.bp makefile to build tqftpserv for AOSP.

Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2020-02-07 10:43:39 -08:00
Khem Raj
2324458f18 include limits.h for PATH_MAX
Signed-off-by: Khem Raj <raj.khem@gmail.com>
2019-12-02 13:45:16 -08:00
Bjorn Andersson
fe53d2a810 tqftpserv: Implement path translation
The tftp clients in the modem requests files from either /readwrite or
/readonly/firmware/image, but as the wlanmdsp.mbn file requested is
signed with a vendor specific key these paths needs to be translated.

/readwrite is translated to /tmp/tqftpserv for now and the
/readonly/firmware/image is translated to a search for the requested
file alongside any of the remoteproc firmware files. The result is that
the wlanmdsp.mbn can be stored in linux-firmware alongside it's
device/vendor specific modem firmware.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-10-26 11:14:03 -07:00
Bjorn Andersson
75a7a89398 tqftpserv.service: Add systemd service
Add tqftpserv.service and install this.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-07-25 11:36:16 -07:00
Bjorn Andersson
6348c52f20 tqftpserv: Remove the spamming of stdout
Some mechanism for toggling the verbosity of the prints should be
introduced, but for now just comment out all the debug prints.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-06-10 16:40:11 -07:00
Bjorn Andersson
7167c88ead tqftpserv: Don't close socket at EOF
When during a read we close the socket as we send the last block the
remote will be notified about the closure and consider the transfer
incomplete. Leave the socket open until we receive a EOF error from the
remote side.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-06-10 16:36:13 -07:00
Bjorn Andersson
2ae2758cba Add LICENSE file
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-03-15 11:34:42 -07:00
Ben Chan
4fa490847a tqftpserv: fix memory leak in tftp_send_error() 2018-07-26 06:10:31 -07:00
Ben Chan
a175e68796 tqftpserv: remove duplicated initialization in handle_rrq() 2018-07-26 06:09:47 -07:00
Bjorn Andersson
9c4bc44c44 tqftpserv: Fix invalid include directives
The two include files was dropped during development but lingered in my
repository, remove the include of them - and define MAX(x, y).

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-10 19:02:52 -07:00
Bjorn Andersson
e4894436dd tqftpserv: Initial prototype implementation
Introduce a prototype of the tqftpserv, a server implementing trivial
file transfer protocol over AF_QIPCRTR.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-06-29 15:57:40 -07:00
Bjorn Andersson
73a4053779 ... 2018-06-29 15:54:40 -07:00