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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>