diag: Perform CRC check on incoming HDLC encoded packet

Diag driver receives HDLC encoded data from the tools and decodes
them. This patch adds checks to the received data. It discards the
packet if the CRC is not correct.

Change-Id: Ie53056844d6d1e6777d15a339896bf6842cfae64
CRs-Fixed: 519902
Signed-off-by: Ravi Aravamudhan <aravamud@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
diag: dci: Fix timestamps on dci events

The first event generated by diag on the peripherals will have a
valid timestamp bytes and the subsequent events generated at the
same time will have reduced timestamp bytes to conserve
space in the buffer. Diag driver zeroed out the timestamp bytes
when it encounters DCI events with reduced timestamp bytes. This
patch adds the valid timestamp for those events.

Change-Id: I80b1a7450f605af9bfd8959ea1f26bc9d83b370e
CRs-Fixed: 521415
Signed-off-by: Ravi Aravamudhan <aravamud@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
diag: Check correct status variable to send log mask

Diag driver was incorrectly checking the message mask status to
send the log mask control packet to the peripherals. This patch
checks the correct status variable to send the log mask to the
peripherals.

Change-Id: I6733c930e66cabc77c6cfe62b9aa7cd48b9fe13d
CRs-Fixed: 542074
Signed-off-by: Ravi Aravamudhan <aravamud@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
diag: NRT read wakelocks held for very long time

During on-device logging with '-b' option,
NRT read wakelocks i.e. diag_nrt_modem_read
and diag_nrt_wcnss_read were held for more than
a day's time. This patch releases the wakelocks
even if SMD channel will be closed.

Change-Id: I7d211aaeaeb8d59369a191c5eef54c02a1b4a61d
CRs-Fixed: 513309
Signed-off-by: Mohit Aggarwal <maggarwa@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
diag: Fix for CRC check for Control byte

0x7E packets can be sent twice in a row.The first 0x7E
is the terminator of the previous command and the next
is a null frame that we should ignore. This patch treats
the 0x7E bytes as packet end only.

Change-Id: I2c02240eead9c61ad8aa6bcf9e920bc63a0574cd
CRs-fixed: 549971
Signed-off-by: Katish Paran <kparan@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
diag: dci: Preventing unitialized stack memcpy operation

At certain point in diag driver there can be memcpy operation
for the unintialized stack. Due to uninitilization of memory
user can obatin valuable information on accessing this stack
in userspace. This patch fixes that issue.

Change-Id: I4bfcf156300132dc426dcadce325e0c76c1d0357
CRs-fixed: 565808
Signed-off-by: Katish Paran <kparan@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
diag: Add new polling command

Diag driver should now support a new polling command for the tools
to recognize the target.

Change-Id: Ia7966cc74c5c74693cebfd64b178831e5ca6f2dd
Signed-off-by: Ravi Aravamudhan <aravamud@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
diag: Change format used for printing pointers

Currently, when printing a pointer address the format does not
take advantage of using the pointer conversion specifier. Make
changes to use the pointer conversion specifier.

Change-Id: I27fd10c33952de9e44066c15256c7f29df6c4dd8
Signed-off-by: Ravi Aravamudhan <aravamud@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
diag: Fix for diag debugfs buffer overflow

Diag debugfs buffer has potential buffer overflow scenario which can cause
memory corruption. Added safeguard to prevent this.

Crs-fixed: 585147
Change-Id: Ie1f099bb4bb626adff99ae225966aef70c1bc15e
Signed-off-by: Sreelakshmi Gownipalli <sgownipa@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
diag: dci: Index DCI client table by client id

Diag driver maintains a table of all DCI clients. This table
is currently indexed by the PID of the clients. Make changes
to index the table base on an unique client id.

Change-Id: I57bfab9eae1381882b8eb6270d7ac212e0aaf271
CRs-fixed: 590721
Signed-off-by: Katish Paran <kparan@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>