128 Commits
Author SHA1 Message Date
Madrajib Lab 23c12c167e Replace scatter-gather with direct copy for NHDLC framing
Replace iovec-based packet assembly with direct linear copy in
queue_push_ndlc_flow(). The scatter-gather approach was creating
temporary stack variables and looping through iovecs unnecessarily
for simple header + msg + tail construction.

Scatter-gather makes sense for zero-copy I/O, not for building
new packets from scratch.

Signed-off-by: Madrajib Lab <madhabsharma94@gmail.com>
2026-07-09 14:02:31 -05:00
Sibi Sankar d4ab57d6ce send_data: Fix abstract socket path copy truncation
strncpy() stops at the first null byte, which truncates the abstract
socket name "\0diag" to an empty string. This will result in a
"Diag response: Bad command" failure, fix this by using memcpy to
copy the full 5 bytes including the leading null that marks the
abstract namespace.

Signed-off-by: Sibi Sankar <sibi.sankar@oss.qualcomm.com>
2026-07-09 13:59:33 -05:00
Sibi Sankar 3e34ab0bde diag-router: Add support for SoC Control Processor (SoCCP)
Register a QRTR peripheral for the SoC control processor so diag-router
can communicate with the soccp subsystem. One can rely on the following
commands to trigger SSR on SoCCP using send_data.

error fatal: send_data 75 37 03 152 00
wdog bite: send_data 75 37 03 152 01
Software exception (Null pointer): send_data 75 37 03 152 02
software exception (div by 0): send_data 75 37 03 152 03

Signed-off-by: Sibi Sankar <sibi.sankar@oss.qualcomm.com>
2026-07-09 13:58:53 -05:00
Kyle Deng 5fdaf60c10 diag-router: Add support for non-HDLC mode
Added the support of NHDLC mode.DIAG packets using the newer
non‑HDLC framing format instead of full HDLC encoding to
reduce overhead and redundancy on reliable transports like USB.

Signed-off-by: Kyle Deng <chunkai.deng@oss.qualcomm.com>
2026-04-10 15:08:02 -05:00
Kyle Deng 5361d91987 diag: Added queue push using scatter-gather for frame build
Introduce a new queue push mechanism to build NHDLC frames and enqueue
them via the scatter-gather push function. This approach reduces memory
copies and improves performance for framed message transmission.

Signed-off-by: Kyle Deng <chunkai.deng@oss.qualcomm.com>
2026-04-10 15:08:02 -05:00
Alexander Couzens 24fbec9683 unix: correct bind address of unix domain sockets
strncpy() will directly stop at the \0 of "\0diag".
This will result in a completely zero'ed address.

Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
2026-01-23 20:13:39 -06:00
KyleDengChunkai 29277ef0bc apps_cmds: Add support for get diag ID command
Adding support for the diag-id command response

Signed-off-by: Kyle Deng <quic_chunkaid@quicinc.com>
2025-03-24 17:18:28 -05:00
KyleDengChunkai f2c7d9164a diag_cntl: Add support for diag id v2 and v3 control commands
Adding support for Diag-ID handshake and storing the information.
Diag-ID indicates and indexes the identity of the clients.

Signed-off-by: Kyle Deng <quic_chunkaid@quicinc.com>
2025-03-24 17:18:28 -05:00
Jami Kettunen d06e599d19 unix: Include string.h
This fixes a bunch of implicit function declaration issues under musl
libc.
2021-03-29 14:39:07 -07:00
Khem Raj 048dc8e78d Disable use of __NR_io_getevents when not defined
Architectures like riscv32 do not define this syscall, therefore return
ENOSYS on such architectures

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2021-01-21 09:04:25 -08:00
Bjorn Andersson 1716a44f82 watch: Don't wake up every 10 seconds
The artifical timeout of 10 seconds on select() seems to be a
development remnant and causes a system in sleep to wake up
unnecessarily. Remove this and rely on the registered wake events.

Reported-by: Sreelakshmi Gownipalli <sgownipa@codeaurora.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2020-09-15 12:25:33 -05:00
Bjorn Andersson cc5dc0dec3 peripherals: Create and use flow context
Introduce a flow control context per peripheral and pass this to
dm_broadcast() for data channels in order for any queued messages to be
accounted for in the flow control context.

Associate the same flow control context with the read watcher for the
peripheral's incoming data descriptors to make the watch runner
selectively read from the given peripheral only when the number of
outstanding, queued, messages are below the threshold.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2020-03-20 12:25:24 -07:00
Bjorn Andersson 040982dbda dm: Allow broadcasters to pass a flow context
Allow users of dm_broadcast() to pass a flow context, which will
associate the created mbufs with the given flow.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2020-02-19 16:00:01 -08:00
Bjorn Andersson a3395140dd watch: Allow flow context to be associated with readq
Allow a flow context to be associated to a read queue and consider the
flow blockage when deciding to evaluate the associated file descriptor
for incoming data.

This allows clients to associate a read queue with the same flow context
as they will associate mbufs to be flow controlled with.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2020-02-19 15:59:46 -08:00
Bjorn Andersson d2c595e988 mbuf/watch: Introduce flow control context
Introduce helpers for creating flow control object and allow these to be
associated with mbufs. The flow is incremented as the object is added to
a queue and decremented as the object is transmitted off the queue.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2020-02-19 15:59:33 -08:00
Bjorn Andersson 3eaf16dd4f qrtr: Remove writeq when remote goes away
The writeq needs to be removed when the remote goes away, so that we're
not trying to operate on stale queues.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-05-30 06:26:28 -07:00
Evan Green bf8035f68b watch: Fix buffer overflow
diag_ffs_recv copies mbuf->offset bytes into a fixed 16k buffer.
watch_handle_eventfd sets pending_aio->offset to ev->res, assuming
that ev->res represents the number of bytes read. But res can be
negative in error cases. This causes diag_ffs_recv to copy a very
large amount into a 16k buffer, smashing the stack.

Avoid populating pending_aio->offset if the result is failure.
Also, it appears that if the status code is EAGAIN, the I/O is
actually still in the system, and comes back later.

Signed-off-by: Evan Green <evangreen86@gmail.com>
2019-01-24 10:29:16 -08:00
Evan Green 2861875311 README: Configuration string should be diag_dun
For some reason, this string seems to need to be set to diag_dun rather
than DIAG to get QXDM and other tools fired up.

Signed-off-by: Evan Green <evangreen86@gmail.com>
2019-01-19 12:29:42 -08:00
Evan Green 29db5d80b0 common_cmds: Fix warning about address of packed member
Our compiler complains about the following:

router/common_cmds.c:142:49: warning: taking address of
packed member 'num_items' of class or structure 'diag_log_cmd_mask' may
result in an unaligned pointer value [-Waddress-of-packed-member]

Avoid directly passing the address of this member to a subroutine, and
instead do the passing via a local.

Signed-off-by: Evan Green <evangreen86@gmail.com>
2019-01-19 12:29:42 -08:00
Evan Green 73ca38f017 build: Honor CFLAGS
If CFLAGS is set in the environment, it should be used. The Makefile
was previously clobbering it. Now it adds -Wall -g -O2 only if CFLAGS
was not specified.

Signed-off-by: Evan Green <evangreen86@gmail.com>
2019-01-19 12:29:42 -08:00
Sreelakshmi Gownipalli f46fe32948 diag: Add support for version number command
This commit has following changes
1) Add version number command support.
2) Set the event mask state correctly.
3) Check for packet header for the packets received on
   data channel.
4) Send mask update control packets after sending feature mask to
   peripheral.

Signed-off-by: Sreelakshmi Gownipalli <sgownipa@codeaurora.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-01-12 23:33:16 -08:00
Bjorn Andersson 5ef6b6b0c5 qrtr: Register the DCI and not DCI_CMD instance
The DIAG client is supposed to register the DCI, while the remote will
register DCI_CMD. Update this to trigger the SDM845 modem to actually
initiate the communication, something that 8996 isn't so picky about.

Also add a comment describing the unusual handling of instance
identifier in DIAG.

Fixes: c96d6445c7 ("qrtr: Introduce initial qrtr support")
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-10-02 09:29:21 -07:00
Khem Raj 54375d90a4 Fix build with musl
Include needed headers to fix following errors

| router/dm.h:41:1: error: unknown type name 'ssize_t'; did you mean 'size_t'?
|  ssize_t dm_send(struct diag_client *dm, const void *ptr, size_t len);
|  ^~~~~~~

tools/send_data.c:55:9: error: variable 'tv' has initializer but
incomplete type
  struct timeval tv = {5, 0};
         ^~~~~~~

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2018-09-25 14:01:54 -07:00
Bjorn Andersson 9de0697ec5 readme: Add initial version
Add initial version with some notes on how to set up USB ConfigFS
GadgetFS and launch diag-router.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-08-06 14:59:30 -07:00
Bjorn Andersson 17b41035f8 make: Enable QRTR and UDEV by default
Default to support both QRTR based and RPMSG based communication, rather
than none. This default configuration allow us to run the binary on both
SDM845 and DB820c; but still make it possible to disable the RPMSG based
peripheral support when the host doesn't have the cross compile
environment for libudev.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-08-01 23:56:11 -07:00