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
|
|
||
| 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, |
There was a problem hiding this comment.
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.
| { | ||
| const struct qmi_header *qmi = qmi_get_header(pkt); | ||
|
|
||
| *msg_id = qmi->msg_id; |
There was a problem hiding this comment.
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.
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" { |
There was a problem hiding this comment.
This would indicate that patch 2 doesn't build. Can you please update that instead?
| #include <stdlib.h> | ||
| #include <syslog.h> | ||
|
|
||
| #ifdef __cplusplus |
There was a problem hiding this comment.
Please provide a commit message with a motivation of why this change is done - same with the last patch.
7c8e14e to
a354790
Compare
|
|
||
| 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.
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.
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; |
There was a problem hiding this comment.
Squash this commit into the previous one.
|
|
||
| return 0; | ||
| } | ||
|
|
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; |
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 |
lib/qmi_tlv.c
Outdated
| for (; k < LINE_LENGTH; k++) { | ||
| line[li++] = ' '; | ||
| line[li++] = ' '; | ||
| line[li++] = ' '; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
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.