-
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 all commits
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ extern "C" { | |
#endif | ||
|
||
struct sockaddr_qrtr; | ||
struct qmi_tlv; | ||
|
||
struct qrtr_packet { | ||
int type; | ||
|
@@ -40,6 +41,20 @@ struct qrtr_packet { | |
size_t data_len; | ||
}; | ||
|
||
/** | ||
* 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 DEFINE_QRTR_PACKET(pkt, size) \ | ||
char pkt ## _buf[size]; \ | ||
struct qrtr_packet pkt = { .data = pkt ##_buf, \ | ||
|
@@ -141,14 +156,48 @@ int qrtr_poll(int sock, unsigned int ms); | |
int qrtr_decode(struct qrtr_packet *dest, void *buf, size_t len, | ||
const struct sockaddr_qrtr *sq); | ||
|
||
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, | ||
unsigned short *txn_id); | ||
int qmi_decode_message(void *c_struct, unsigned int *txn, | ||
const struct qrtr_packet *pkt, | ||
int type, int id, struct qmi_elem_info *ei); | ||
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_msg_name { | ||
int msg_id; | ||
const char *msg_name; | ||
}; | ||
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. Who is the user of this struct? |
||
|
||
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_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); | ||
int qmi_tlv_set(struct qmi_tlv *tlv, uint8_t id, void *buf, size_t len); | ||
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); | ||
|
||
|
||
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. I'd say, also squash |
||
/* Initial kernel header didn't expose these */ | ||
#ifndef QRTR_NODE_BCAST | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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. |
||
extern "C" { | ||
#endif | ||
|
||
#if defined(__GNUC__) || defined(__clang__) | ||
#define __PRINTF__(fmt, args) __attribute__((format(__printf__, fmt, args))) | ||
#else | ||
|
@@ -33,4 +37,8 @@ void qlog(int priority, const char *format, ...) __PRINTF__(2, 3); | |
exit(1); \ | ||
} while(0) | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
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