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
23 changes: 13 additions & 10 deletions lib/libqrtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,23 @@ ssize_t qmi_encode_message(struct qrtr_packet *pkt, int type, int msg_id,
int txn_id, const void *c_struct,
struct qmi_elem_info *ei);

struct qmi_tlv {
void *allocated;
void *buf;
size_t size;
int error;
};

struct qmi_tlv_item {
uint8_t key;
uint16_t len;
uint8_t data[];
} __attribute__((__packed__));

struct qmi_tlv *qmi_tlv_init(uint16_t txn, uint32_t msg_id, uint32_t msg_type);
void *qmi_tlv_encode(struct qmi_tlv *tlv, size_t *len);
struct qmi_tlv *qmi_tlv_decode(void *buf, size_t len);
void qmi_tlv_free(struct qmi_tlv *tlv);
void qmi_tlv_dump(struct qmi_tlv *tlv);
Copy link

Choose a reason for hiding this comment

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

Oh, my. I started to like the function and now it is gone. Squash everything together so that the remnants of it won't make me mourn the loss each time I look at the git history.

void *qmi_tlv_get(struct qmi_tlv *tlv, uint8_t id, size_t *len);
void *qmi_tlv_get_array(struct qmi_tlv *tlv, uint8_t id, size_t len_size,
size_t *len, size_t *size);
Expand All @@ -180,15 +192,6 @@ 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;
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
69 changes: 0 additions & 69 deletions lib/qmi_tlv.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,6 @@

#include "libqrtr.h"

struct qmi_tlv {
void *allocated;
void *buf;
size_t size;
int error;
};

struct qmi_tlv_item {
uint8_t key;
uint16_t len;
uint8_t data[];
} __attribute__((__packed__));

struct qmi_tlv *qmi_tlv_init(uint16_t txn, uint32_t msg_id, uint32_t msg_type)
{
struct qmi_header *pkt;
Expand Down Expand Up @@ -236,60 +223,4 @@ static inline uint8_t to_hex(uint8_t ch)
return ch <= 9 ? '0' + ch : 'a' + ch - 10;
}

void qmi_tlv_dump(struct qmi_tlv *tlv) {
struct qmi_tlv_item *item;
struct qmi_header *pkt;
unsigned offset = sizeof(struct qmi_header);
void *pkt_data;
int i = 0, li, j, k;
uint8_t ch;
size_t linelen;
char line[LINE_LENGTH * 4 + 1];

pkt = tlv->buf;
pkt_data = &pkt[0];

printf("<<< Message:\n");
printf("<<< type : %u\n", pkt->type);
printf("<<< msg_len : 0x%1$04x (%1$u)\n", pkt->msg_len);
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");
// I do not understand why this -1 is needed
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 + sizeof(struct qmi_header) - offset) {
fprintf(stderr, "Invalid item length!\n");
return;
}
for (j = 0; j < item->len; j += LINE_LENGTH) {
linelen = MIN(LINE_LENGTH, item->len - j);
li = 0;

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

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

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

line[li] = '\0';

printf("%s\n\n", line);
}
offset += sizeof(struct qmi_tlv_item) + item->len;
i++;
}
}