-
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?
Changes from 1 commit
ca18508
d86dacc
4246d2a
9e9b6ba
8ade7c5
b501651
bec5bb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,21 +36,6 @@ | |
#include "libqrtr.h" | ||
#include "logging.h" | ||
|
||
/** | ||
* qmi_header - wireformat header of QMI messages | ||
* @type: type of message | ||
* @txn_id: transaction id | ||
* @msg_id: message id | ||
* @msg_len: length of message payload following header | ||
*/ | ||
struct qmi_header { | ||
uint8_t type; | ||
uint16_t txn_id; | ||
uint16_t msg_id; | ||
uint16_t msg_len; | ||
} __attribute__((packed)); | ||
|
||
|
||
#define QMI_ENCDEC_ENCODE_TLV(type, length, p_dst) do { \ | ||
*p_dst++ = type; \ | ||
*p_dst++ = ((uint8_t)((length) & 0xFF)); \ | ||
|
@@ -794,20 +779,44 @@ ssize_t qmi_encode_message(struct qrtr_packet *pkt, int type, int msg_id, | |
return pkt->data_len; | ||
} | ||
|
||
int qmi_decode_header(const struct qrtr_packet *pkt, unsigned int *msg_id) | ||
const struct qmi_header *qmi_get_header(const struct qrtr_packet *pkt) | ||
{ | ||
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 commentThe 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. |
||
LOGW("[QRTR] Invalid length of incoming qmi request\n"); | ||
return NULL; | ||
} | ||
|
||
return qmi; | ||
} | ||
|
||
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 commentThe 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. |
||
|
||
return 0; | ||
} | ||
|
||
int qmi_decode_header2(const struct qrtr_packet *pkt, unsigned int *msg_id, unsigned char *type, | ||
unsigned short *txn_id) | ||
{ | ||
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 commentThe 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. |
||
|
||
if (type) | ||
*type = qmi->type; | ||
if (msg_id) | ||
*msg_id = qmi->msg_id; | ||
if (txn_id) | ||
*txn_id = qmi->txn_id; | ||
|
||
return 0; | ||
} | ||
|
||
/** | ||
* qmi_decode_message() - Decode QMI encoded message to C structure | ||
* @buf: Buffer with encoded message | ||
|
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