-
Notifications
You must be signed in to change notification settings - Fork 31
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
base: master
Are you sure you want to change the base?
Conversation
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
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
int qmi_decode_header(const struct qrtr_packet *pkt, unsigned int *msg_id) | ||
{ | ||
const struct qmi_header *qmi = qmi_get_header(pkt); | ||
|
||
*msg_id = qmi->msg_id; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
@@ -38,7 +38,7 @@ void qlog(int priority, const char *format, ...) __PRINTF__(2, 3); | |||
} while(0) | |||
|
|||
#ifdef __cplusplus | |||
extern "C" { |
There was a problem hiding this comment.
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?
@@ -5,6 +5,10 @@ | |||
#include <stdlib.h> | |||
#include <syslog.h> | |||
|
|||
#ifdef __cplusplus |
There was a problem hiding this comment.
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.
e12dfab
to
4246d2a
Compare
7c8e14e
to
a354790
Compare
a354790
to
8ade7c5
Compare
{ | ||
const struct qmi_header *qmi = pkt->data; | ||
|
||
if (qmi->msg_len != pkt->data_len - sizeof(*qmi)) { | ||
LOGW("[RMTFS] Invalid length of incoming qmi request\n"); | ||
return -EINVAL; |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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
@@ -43,7 +43,6 @@ struct qmi_tlv *qmi_tlv_init(uint16_t txn, uint32_t msg_id, uint32_t msg_type) | |||
|
|||
struct qmi_tlv *qmi_tlv_decode(void *buf, size_t len) | |||
{ | |||
struct qmi_header *pkt = buf; |
There was a problem hiding this comment.
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; | ||
} | ||
|
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
@@ -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"); | |||
while (offset < tlv->size - sizeof(struct qmi_header)) { | |||
// I do not understand why this -1 is needed |
There was a problem hiding this comment.
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++] = ' '; |
There was a problem hiding this comment.
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
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); |
There was a problem hiding this comment.
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; | ||
}; |
There was a problem hiding this comment.
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?
@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. |
@calebccff I think we are still using qrtr in some of our tools. Would you suggest switching to libqmi and possibly abandoning qrtr completely? |
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.