Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc fixes for qrild #21

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/libqrtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,18 @@ void *qmi_tlv_get_array(struct qmi_tlv *tlv, uint8_t id, size_t len_size,
int qmi_tlv_set(struct qmi_tlv *tlv, uint8_t id, void *buf, size_t len);
int qmi_tlv_set_array(struct qmi_tlv *tlv, uint8_t id, size_t len_size,
void *buf, size_t len, size_t size);

struct qmi_response_type_v01 *qmi_tlv_get_result(struct qmi_tlv *tlv);

static inline int qmi_tlv_dump_buf(void *buf, size_t len) {
struct qmi_tlv *tlv = qmi_tlv_decode(buf, len);
if (!tlv)
return -1;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-EINVAL

qmi_tlv_dump(tlv);
qmi_tlv_free(tlv);

return 0;
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say, also squash

/* Initial kernel header didn't expose these */
#ifndef QRTR_NODE_BCAST

Expand Down
22 changes: 18 additions & 4 deletions lib/qmi_tlv.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <ctype.h>
#include <errno.h>
#include <string.h>
#include <stdint.h>
Expand Down Expand Up @@ -227,7 +228,7 @@ struct qmi_response_type_v01 *qmi_tlv_get_result(struct qmi_tlv *tlv)
}

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define LINE_LENGTH 64
#define LINE_LENGTH 40

static inline uint8_t to_hex(uint8_t ch)
{
Expand All @@ -238,7 +239,7 @@ static inline uint8_t to_hex(uint8_t ch)
void qmi_tlv_dump(struct qmi_tlv *tlv) {
struct qmi_tlv_item *item;
struct qmi_header *pkt;
unsigned offset = 0;
unsigned offset = sizeof(struct qmi_header);
void *pkt_data;
int i = 0, li, j, k;
uint8_t ch;
Expand All @@ -254,10 +255,11 @@ void qmi_tlv_dump(struct qmi_tlv *tlv) {
printf("<<< msg_id : 0x%1$04x (%1$u)\n", pkt->msg_id);
printf("<<< txn_id : 0x%1$04x (%1$u)\n", pkt->txn_id);
printf("<<< TLVs:\n");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pass struct FILE to the function and use fprintf + fflush at the end.

while (offset < tlv->size - sizeof(struct qmi_header)) {
// I do not understand why this -1 is needed
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh?

while (offset < tlv->size - 1) {
item = pkt_data + offset;
printf("<<< TLV %d: {id: 0x%02x, len: 0x%02x}\n", i, item->key, item->len);
if (item->len > pkt->msg_len - offset) {
if (item->len > pkt->msg_len + sizeof(struct qmi_header) - offset) {
fprintf(stderr, "Invalid item length!\n");
return;
}
Expand All @@ -271,6 +273,18 @@ void qmi_tlv_dump(struct qmi_tlv *tlv) {
line[li++] = to_hex(ch);
line[li++] = k < linelen - 1 ? ':' : ' ';
}

for (; k < LINE_LENGTH; k++) {
line[li++] = ' ';
line[li++] = ' ';
line[li++] = ' ';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a possibility to overflow it?

}

for (k = 0; k < linelen; k++) {
ch = item->data[j + k];
line[li++] = isprint(ch) ? ch : '.';
}

line[li] = '\0';

printf("%s\n\n", line);
Expand Down