35 Commits

Author SHA1 Message Date
Konrad Dybcio
f803b4d573 meson.build: Set v1.1 version
Signed-off-by: Konrad Dybcio <konrad.dybcio@linaro.org>
v1.1
2024-07-23 14:22:35 +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>
v1.0
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