Skip to content

Conversation

@kcxt
Copy link
Member

@kcxt kcxt commented Jul 18, 2022

Export the whole QMI header, and add qmi_tlv to libqrtr so projects using the "accessor" style QMI code generator don't have to vendor it.

I've made some changes to the qmi_tlv_* interface which are reflected in my fork of qmic: https://github.com/calebccff/qmic/tree/nested_structs, I'll also be opening a PR for that soon, any feedback on the qmi_tlv_* interface would be good before opening that.

kcxt added 2 commits July 18, 2022 10:02
Allow clients to read the whole packet header instead of just the
message ID, also extend qmi_decode_header with a second getter to
fetch all of the header properties

const struct qmi_header *qmi_get_header(const struct qrtr_packet *pkt);
int qmi_decode_header(const struct qrtr_packet *pkt, unsigned int *msg_id);
int qmi_decode_header2(const struct qrtr_packet *pkt, unsigned int *msg_id, unsigned char *type,
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems that either you could expose the struct qmi_header and qmi_get_head() or implement this qmi_decode_header2(), I don't think we need both ways to do the same thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

{
const struct qmi_header *qmi = qmi_get_header(pkt);

*msg_id = qmi->msg_id;
Copy link
Collaborator

Choose a reason for hiding this comment

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

qmi_get_header() will return NULL on failure, in which cause this will fault. Better check for !qmi and return -EINVAL in this case.

{
const struct qmi_header *qmi = qmi_get_header(pkt);
if (!qmi)
return -1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Currently these errors return -EINVAL, it could be argued that returning -1 and setting errno is more idiomatic - but I think you should stick to the current semantics.

lib/logging.h Outdated
} while(0)

#ifdef __cplusplus
extern "C" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would indicate that patch 2 doesn't build. Can you please update that instead?

#include <stdlib.h>
#include <syslog.h>

#ifdef __cplusplus
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please provide a commit message with a motivation of why this change is done - same with the last patch.

@kcxt kcxt force-pushed the caleb/qrild-fixes branch from e12dfab to 4246d2a Compare July 19, 2022 14:30
@kcxt kcxt force-pushed the caleb/qrild-fixes branch 2 times, most recently from 7c8e14e to a354790 Compare August 3, 2022 15:11
@kcxt kcxt force-pushed the caleb/qrild-fixes branch from a354790 to 8ade7c5 Compare August 3, 2022 16:18
@konradybcio konradybcio requested a review from andersson April 9, 2024 09:27

if (qmi->msg_len != pkt->data_len - sizeof(*qmi)) {
LOGW("[RMTFS] Invalid length of incoming qmi request\n");
return -EINVAL;
Copy link
Contributor

Choose a reason for hiding this comment

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

While being correct, this is unrelated to qmi_header rework. Please split to a separate commit.

lib/qmi_tlv.c Outdated
printf("<<< msg_len : %u\n", pkt->msg_len);
printf("<<< msg_id : 0x%04x\n", pkt->msg_id);
printf("<<< txn_id : %u\n", pkt->txn_id);
printf("<<< TLVs:\n");
Copy link
Contributor

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.

lib/qmi_tlv.c Outdated

struct qmi_tlv *qmi_tlv_decode(void *buf, size_t len)
{
struct qmi_header *pkt = buf;
Copy link
Contributor

Choose a reason for hiding this comment

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

Squash this commit into the previous one.


return 0;
}

Copy link
Contributor

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

lib/libqrtr.h Outdated
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
Contributor

Choose a reason for hiding this comment

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

-EINVAL

lib/qmi_tlv.c Outdated
printf("<<< txn_id : 0x%1$04x (%1$u)\n", pkt->txn_id);
printf("<<< TLVs:\n");
while (offset < tlv->size - sizeof(struct qmi_header)) {
// I do not understand why this -1 is needed
Copy link
Contributor

Choose a reason for hiding this comment

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

Huh?

lib/qmi_tlv.c Outdated
for (; k < LINE_LENGTH; k++) {
line[li++] = ' ';
line[li++] = ' ';
line[li++] = ' ';
Copy link
Contributor

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?

lib/libqrtr.h Outdated
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
Contributor

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.

struct qmi_tlv_msg_name {
int msg_id;
const char *msg_name;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Who is the user of this struct?

@kcxt
Copy link
Member Author

kcxt commented Apr 10, 2024

@lumag thanks for reviewing all this, I'll see if i can clean it up a bit.

the tlv dump feature can be kept i guess, it's certainly nice to have. although it's not immensely useful without the qmic changes to include the name of the message and of each value, otherwise you stil have to manually decode the output.

and at this point the full fat freedesktop libqmi is probably better.

@lumag
Copy link
Contributor

lumag commented May 21, 2024

@calebccff I think we are still using qrtr in some of our tools. Would you suggest switching to libqmi and possibly abandoning qrtr completely?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants