Commit Graph

64 Commits

Author SHA1 Message Date
Eyal Ilsar
fbe328fa96 diag: masks: Use realloc() to increase mask in diag_cmd_get_event_mask()
Rather than calling malloc() and free() use realloc() to increase mask
size in diag_cmd_get_event_mask().

Signed-off-by: Eyal Ilsar <eilsar@codeaurora.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-04-04 11:44:44 -07:00
Eyal Ilsar
49614e6675 diag: masks: Use realloc() to resize masks set by diag_cmd_set_msg_mask()
Rather than calling malloc()/calloc(). memcpy() and free() call realloc()
when mask size is increased in the call to diag_cmd_set_msg_mask().

Signed-off-by: Eyal Ilsar <eilsar@codeaurora.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-04-04 11:44:43 -07:00
Eyal Ilsar
0a8e622328 diag: masks: Revise mask bits to bytes mapping macros
Masks operations require transition from bitmap cardinality to size and
vice versa.

Replaced the macros LOG_ITEMS_TO_SIZE() and EVENT_COUNT_TO_BYTES() that
obfuscated this fact with a utility macro BITS_TO_BYTES().

Removed unused reverse mapping LOG_SIZE_TO_ITEMS().

Signed-off-by: Eyal Ilsar <eilsar@codeaurora.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-04-04 11:44:42 -07:00
Eyal Ilsar
f76672f603 diag: masks: Fix APPS_EVENT_LAST_ID to reflect event id and not mask size
The APPS_EVENT_LAST_ID constant used to define the maximal event id was
incorrectly specified in bytes. Changed the value to support the correct
number of events.

Signed-off-by: Eyal Ilsar <eilsar@codeaurora.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-02-13 14:33:34 -08:00
Bjorn Andersson
660818d6c1 diag_cntl: Fix leaking feature mask packet
The feature mask was not freed after being put on the queue.

Use alloca() to keep the allocation on the stack in order to not leak
the heap object and migrate the other functions to use the same.

Reported-by: Eyal Ilsar <eilsar@codeaurora.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-02-07 14:27:29 -08:00
Eyal Ilsar
9f2cdef205 diag: router: Fix memory leak in hdlc_enqueue()
Added the missing free() of the temporary buffer created by hdlc_encode()
to hold the encoded data after it is enqueued.

Signed-off-by: Eyal Ilsar <eilsar@codeaurora.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-02-07 14:19:07 -08:00
Bjorn Andersson
98ba5ef812 dm: Move struct diag_client into DM
Now that the DM operations fully abstracts the handling of the DM we can
move the struct diag_client into the DM implementation.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-24 22:26:58 -08:00
Bjorn Andersson
d2634ef6d4 dm: Move initialization of the diag_clients to DM
Further more common DM-related to the DM, in order to hide more of the
inner workings of the diag_client struct.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-24 22:25:34 -08:00
Bjorn Andersson
cb56261b55 dm: Move common receive function to DM
The recveive function is currently the same for all DM transports, so
move the common code into the DM.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-24 22:25:18 -08:00
Bjorn Andersson
cb2dcc4ccb dm: Transition all senders to use dm_send()
Transition all calls to hdlc_enqueue on the client out-queue to use
dm_send(). This reduces the need for clients to know the workings of the
transmition and knowledge of the diag_client struct.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-24 22:10:29 -08:00
Bjorn Andersson
365aa41212 dm: Introduce Diagnostic Monitor abstraction
Move common helpers related to "diag clients" into a "Diagnostics
Monitor" implementation. This becomes necessary in order to support
non-HDLC encoding between the DM and device transparently to the
rest of the implementation.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-24 22:10:17 -08:00
Bjorn Andersson
31dd6573b9 hdlc: Decode HDLC data from a circular buffer
In order to support any sort of fragmentation in a stream based
transport, such as TCP/IP, the data is read into a circular buffer and
the HDLC decoder is turned into a reentrant consumer of said circular
buffer.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-24 21:38:46 -08:00
Bjorn Andersson
ce085f6055 circ_buf: Introduce circular buffer structure
This introduces a circular buffer and a read operation to store stream
data, from e.g. a TCP stream.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-24 21:38:46 -08:00
Bjorn Andersson
02ad780abc peripheral: Split data receive path in hdlc and raw
Split the two code paths related to handling of HDLC encoded vs raw
packets coming from the remote processor, this in order to facilitate
further rework of the HDLC decoder.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-24 21:38:46 -08:00
Bjorn Andersson
e57aa9a1ad dm: Encode forwarded responses
As we don't support dropping the HDLC encoding on the pipe between diag
and the DM we should encode the messages before putting them on the
wire. This was accidentally changed in a previous commit, but QXDM on
Mac doesn't seem to care about this.

Fixes: ed3c97ac76 ("diag: Add dynamic peripheral support")
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-23 22:15:48 -08:00
Bjorn Andersson
c43b1b8ba4 peripheral: Abstract encoding logic related to send
The choice of encoding for outgoing messages is that of the peripheral,
so move this to the peripheral implementation to hide this from the
router.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-23 21:47:13 -08:00
Bjorn Andersson
851aa55136 uart: Correct file descriptor for read watch
As the code was moved around the wrong variable was used as read file
descriptor. Fix this.

Fixes: 258e749d6f ("diag: transport: Add support for UART connection to host PC")
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-23 21:47:06 -08:00
Bjorn Andersson
dc9107f918 common_cmds: Remove uneccesary conditional
The masks in the request object can't be NULL, so remove the
conditional.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-23 21:46:27 -08:00
Bjorn Andersson
1be63d9bf8 common_cmds: Free mask pointer and use alloca()
The mask pointer was not freed, do this and simplify the code by
replacing the malloc with alloca().

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-23 21:45:13 -08:00
Bjorn Andersson
b639558f83 app_cmds: Fix memory leak and simplify implementation
The response object wasn't freed, use alloca() instead to allocate the
object on the stack. Also replace strncpy with strcpy as we specifically
allocate buffers sized to the two strings.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-23 21:41:48 -08:00
Bjorn Andersson
098f30c1c1 app_cmds: Cleanup DIAG_CMD_DIAG_VERSION_ID handler
The version id response consists of a command id and a hard coded
version id, so simplify the implementation.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-23 21:40:33 -08:00
Bjorn Andersson
7eeb864ca0 doc: Add udev rules example
This example of udev rules creates creates human readable names for
rpmsg_char control and endpoint device nodes as well as automatically
create endpoint devices for the various DIAG related channels found on
MSM8916.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-23 17:08:43 -08:00
Bjorn Andersson
ffe331aeb4 common_cmds: Correct and clean up OP_GET_BUILD_MASK
The response definition for OP_GET_BUILD_MASK was missing the range,
so add this and the associated logic. And while reworking that tidy up
the implementation a little bit.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-23 16:36:09 -08:00
Eyal Ilsar
27e54af3d3 diag: peripheral: Move data and command channel handlers to peripheral
Moved the incoming peripheral packet handling to the scope of the
peripheral.  Note that kept the essentially identical handlers separate
for debugging and possible future deviation in handling.

Signed-off-by: Eyal Ilsar <eilsar@codeaurora.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-23 16:36:09 -08:00
Eyal Ilsar
5b69368b97 diag: control: Add handling of deregistering control command (cmdid=27)
Implemented and registered handler for deregistering control command.

Signed-off-by: Eyal Ilsar <eilsar@codeaurora.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-23 16:36:09 -08:00