mirror of
https://github.com/linux-msm/rmtfs.git
synced 2024-11-23 04:04:29 +08:00
rmtfs: Update tlv prototypes to accept message header
To support creating and parsing requests and indications as well qmic adds an extra parameter to the tlv alloc and decode functions, so that this can be used to generate and validate that the qmi packet header is of the correct type. Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
parent
1f12cea75b
commit
d5e516a6c6
3
Makefile
3
Makefile
@ -9,6 +9,9 @@ OBJS := $(SRCS:.c=.o)
|
||||
$(OUT): $(OBJS)
|
||||
$(CC) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
%.c: %.qmi
|
||||
qmic < $<
|
||||
|
||||
test: $(OUT)
|
||||
./$(OUT)
|
||||
|
||||
|
44
qmi_rmtfs.c
44
qmi_rmtfs.c
@ -4,12 +4,12 @@
|
||||
|
||||
struct rmtfs_open_req *rmtfs_open_req_alloc(unsigned txn)
|
||||
{
|
||||
return (struct rmtfs_open_req*)qmi_tlv_init(txn, 1);
|
||||
return (struct rmtfs_open_req*)qmi_tlv_init(txn, 1, 0);
|
||||
}
|
||||
|
||||
struct rmtfs_open_req *rmtfs_open_req_parse(void *buf, size_t len, unsigned *txn)
|
||||
{
|
||||
return (struct rmtfs_open_req*)qmi_tlv_decode(buf, len, txn);
|
||||
return (struct rmtfs_open_req*)qmi_tlv_decode(buf, len, txn, 0);
|
||||
}
|
||||
|
||||
void *rmtfs_open_req_encode(struct rmtfs_open_req *open_req, size_t *len)
|
||||
@ -46,12 +46,12 @@ int rmtfs_open_req_get_path(struct rmtfs_open_req *open_req, char *buf, size_t b
|
||||
|
||||
struct rmtfs_open_resp *rmtfs_open_resp_alloc(unsigned txn)
|
||||
{
|
||||
return (struct rmtfs_open_resp*)qmi_tlv_init(txn, 1);
|
||||
return (struct rmtfs_open_resp*)qmi_tlv_init(txn, 1, 2);
|
||||
}
|
||||
|
||||
struct rmtfs_open_resp *rmtfs_open_resp_parse(void *buf, size_t len, unsigned *txn)
|
||||
{
|
||||
return (struct rmtfs_open_resp*)qmi_tlv_decode(buf, len, txn);
|
||||
return (struct rmtfs_open_resp*)qmi_tlv_decode(buf, len, txn, 2);
|
||||
}
|
||||
|
||||
void *rmtfs_open_resp_encode(struct rmtfs_open_resp *open_resp, size_t *len)
|
||||
@ -107,12 +107,12 @@ int rmtfs_open_resp_get_caller_id(struct rmtfs_open_resp *open_resp, uint32_t *v
|
||||
|
||||
struct rmtfs_close_req *rmtfs_close_req_alloc(unsigned txn)
|
||||
{
|
||||
return (struct rmtfs_close_req*)qmi_tlv_init(txn, 2);
|
||||
return (struct rmtfs_close_req*)qmi_tlv_init(txn, 2, 0);
|
||||
}
|
||||
|
||||
struct rmtfs_close_req *rmtfs_close_req_parse(void *buf, size_t len, unsigned *txn)
|
||||
{
|
||||
return (struct rmtfs_close_req*)qmi_tlv_decode(buf, len, txn);
|
||||
return (struct rmtfs_close_req*)qmi_tlv_decode(buf, len, txn, 0);
|
||||
}
|
||||
|
||||
void *rmtfs_close_req_encode(struct rmtfs_close_req *close_req, size_t *len)
|
||||
@ -148,12 +148,12 @@ int rmtfs_close_req_get_caller_id(struct rmtfs_close_req *close_req, uint32_t *v
|
||||
|
||||
struct rmtfs_close_resp *rmtfs_close_resp_alloc(unsigned txn)
|
||||
{
|
||||
return (struct rmtfs_close_resp*)qmi_tlv_init(txn, 2);
|
||||
return (struct rmtfs_close_resp*)qmi_tlv_init(txn, 2, 2);
|
||||
}
|
||||
|
||||
struct rmtfs_close_resp *rmtfs_close_resp_parse(void *buf, size_t len, unsigned *txn)
|
||||
{
|
||||
return (struct rmtfs_close_resp*)qmi_tlv_decode(buf, len, txn);
|
||||
return (struct rmtfs_close_resp*)qmi_tlv_decode(buf, len, txn, 2);
|
||||
}
|
||||
|
||||
void *rmtfs_close_resp_encode(struct rmtfs_close_resp *close_resp, size_t *len)
|
||||
@ -188,12 +188,12 @@ struct rmtfs_qmi_result *rmtfs_close_resp_get_result(struct rmtfs_close_resp *cl
|
||||
|
||||
struct rmtfs_iovec_req *rmtfs_iovec_req_alloc(unsigned txn)
|
||||
{
|
||||
return (struct rmtfs_iovec_req*)qmi_tlv_init(txn, 3);
|
||||
return (struct rmtfs_iovec_req*)qmi_tlv_init(txn, 3, 0);
|
||||
}
|
||||
|
||||
struct rmtfs_iovec_req *rmtfs_iovec_req_parse(void *buf, size_t len, unsigned *txn)
|
||||
{
|
||||
return (struct rmtfs_iovec_req*)qmi_tlv_decode(buf, len, txn);
|
||||
return (struct rmtfs_iovec_req*)qmi_tlv_decode(buf, len, txn, 0);
|
||||
}
|
||||
|
||||
void *rmtfs_iovec_req_encode(struct rmtfs_iovec_req *iovec_req, size_t *len)
|
||||
@ -293,12 +293,12 @@ int rmtfs_iovec_req_get_is_force_sync(struct rmtfs_iovec_req *iovec_req, uint8_t
|
||||
|
||||
struct rmtfs_iovec_resp *rmtfs_iovec_resp_alloc(unsigned txn)
|
||||
{
|
||||
return (struct rmtfs_iovec_resp*)qmi_tlv_init(txn, 3);
|
||||
return (struct rmtfs_iovec_resp*)qmi_tlv_init(txn, 3, 2);
|
||||
}
|
||||
|
||||
struct rmtfs_iovec_resp *rmtfs_iovec_resp_parse(void *buf, size_t len, unsigned *txn)
|
||||
{
|
||||
return (struct rmtfs_iovec_resp*)qmi_tlv_decode(buf, len, txn);
|
||||
return (struct rmtfs_iovec_resp*)qmi_tlv_decode(buf, len, txn, 2);
|
||||
}
|
||||
|
||||
void *rmtfs_iovec_resp_encode(struct rmtfs_iovec_resp *iovec_resp, size_t *len)
|
||||
@ -333,12 +333,12 @@ struct rmtfs_qmi_result *rmtfs_iovec_resp_get_result(struct rmtfs_iovec_resp *io
|
||||
|
||||
struct rmtfs_alloc_buf_req *rmtfs_alloc_buf_req_alloc(unsigned txn)
|
||||
{
|
||||
return (struct rmtfs_alloc_buf_req*)qmi_tlv_init(txn, 4);
|
||||
return (struct rmtfs_alloc_buf_req*)qmi_tlv_init(txn, 4, 0);
|
||||
}
|
||||
|
||||
struct rmtfs_alloc_buf_req *rmtfs_alloc_buf_req_parse(void *buf, size_t len, unsigned *txn)
|
||||
{
|
||||
return (struct rmtfs_alloc_buf_req*)qmi_tlv_decode(buf, len, txn);
|
||||
return (struct rmtfs_alloc_buf_req*)qmi_tlv_decode(buf, len, txn, 0);
|
||||
}
|
||||
|
||||
void *rmtfs_alloc_buf_req_encode(struct rmtfs_alloc_buf_req *alloc_buf_req, size_t *len)
|
||||
@ -395,12 +395,12 @@ int rmtfs_alloc_buf_req_get_buff_size(struct rmtfs_alloc_buf_req *alloc_buf_req,
|
||||
|
||||
struct rmtfs_alloc_buf_resp *rmtfs_alloc_buf_resp_alloc(unsigned txn)
|
||||
{
|
||||
return (struct rmtfs_alloc_buf_resp*)qmi_tlv_init(txn, 4);
|
||||
return (struct rmtfs_alloc_buf_resp*)qmi_tlv_init(txn, 4, 2);
|
||||
}
|
||||
|
||||
struct rmtfs_alloc_buf_resp *rmtfs_alloc_buf_resp_parse(void *buf, size_t len, unsigned *txn)
|
||||
{
|
||||
return (struct rmtfs_alloc_buf_resp*)qmi_tlv_decode(buf, len, txn);
|
||||
return (struct rmtfs_alloc_buf_resp*)qmi_tlv_decode(buf, len, txn, 2);
|
||||
}
|
||||
|
||||
void *rmtfs_alloc_buf_resp_encode(struct rmtfs_alloc_buf_resp *alloc_buf_resp, size_t *len)
|
||||
@ -456,12 +456,12 @@ int rmtfs_alloc_buf_resp_get_buff_address(struct rmtfs_alloc_buf_resp *alloc_buf
|
||||
|
||||
struct rmtfs_dev_error_req *rmtfs_dev_error_req_alloc(unsigned txn)
|
||||
{
|
||||
return (struct rmtfs_dev_error_req*)qmi_tlv_init(txn, 5);
|
||||
return (struct rmtfs_dev_error_req*)qmi_tlv_init(txn, 5, 0);
|
||||
}
|
||||
|
||||
struct rmtfs_dev_error_req *rmtfs_dev_error_req_parse(void *buf, size_t len, unsigned *txn)
|
||||
{
|
||||
return (struct rmtfs_dev_error_req*)qmi_tlv_decode(buf, len, txn);
|
||||
return (struct rmtfs_dev_error_req*)qmi_tlv_decode(buf, len, txn, 0);
|
||||
}
|
||||
|
||||
void *rmtfs_dev_error_req_encode(struct rmtfs_dev_error_req *dev_error_req, size_t *len)
|
||||
@ -497,12 +497,12 @@ int rmtfs_dev_error_req_get_caller_id(struct rmtfs_dev_error_req *dev_error_req,
|
||||
|
||||
struct rmtfs_dev_error_resp *rmtfs_dev_error_resp_alloc(unsigned txn)
|
||||
{
|
||||
return (struct rmtfs_dev_error_resp*)qmi_tlv_init(txn, 5);
|
||||
return (struct rmtfs_dev_error_resp*)qmi_tlv_init(txn, 5, 2);
|
||||
}
|
||||
|
||||
struct rmtfs_dev_error_resp *rmtfs_dev_error_resp_parse(void *buf, size_t len, unsigned *txn)
|
||||
{
|
||||
return (struct rmtfs_dev_error_resp*)qmi_tlv_decode(buf, len, txn);
|
||||
return (struct rmtfs_dev_error_resp*)qmi_tlv_decode(buf, len, txn, 2);
|
||||
}
|
||||
|
||||
void *rmtfs_dev_error_resp_encode(struct rmtfs_dev_error_resp *dev_error_resp, size_t *len)
|
||||
@ -558,12 +558,12 @@ int rmtfs_dev_error_resp_get_status(struct rmtfs_dev_error_resp *dev_error_resp,
|
||||
|
||||
struct rmtfs_force_sync *rmtfs_force_sync_alloc(unsigned txn)
|
||||
{
|
||||
return (struct rmtfs_force_sync*)qmi_tlv_init(txn, 6);
|
||||
return (struct rmtfs_force_sync*)qmi_tlv_init(txn, 6, 4);
|
||||
}
|
||||
|
||||
struct rmtfs_force_sync *rmtfs_force_sync_parse(void *buf, size_t len, unsigned *txn)
|
||||
{
|
||||
return (struct rmtfs_force_sync*)qmi_tlv_decode(buf, len, txn);
|
||||
return (struct rmtfs_force_sync*)qmi_tlv_decode(buf, len, txn, 4);
|
||||
}
|
||||
|
||||
void *rmtfs_force_sync_encode(struct rmtfs_force_sync *force_sync, size_t *len)
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
struct qmi_tlv;
|
||||
|
||||
struct qmi_tlv *qmi_tlv_init(unsigned txn, unsigned msg_id);
|
||||
struct qmi_tlv *qmi_tlv_decode(void *buf, size_t len, unsigned *txn);
|
||||
struct qmi_tlv *qmi_tlv_init(unsigned txn, unsigned msg_id, unsigned type);
|
||||
struct qmi_tlv *qmi_tlv_decode(void *buf, size_t len, unsigned *txn, unsigned type);
|
||||
void *qmi_tlv_encode(struct qmi_tlv *tlv, size_t *len);
|
||||
void qmi_tlv_free(struct qmi_tlv *tlv);
|
||||
|
||||
|
@ -25,53 +25,53 @@ struct iovec_entry {
|
||||
u32 num_sector;
|
||||
};
|
||||
|
||||
message open_req {
|
||||
request open_req {
|
||||
required string path = 1;
|
||||
} = 1;
|
||||
|
||||
message open_resp {
|
||||
response open_resp {
|
||||
required qmi_result result = 2;
|
||||
optional u32 caller_id = 0x10;
|
||||
} = 1;
|
||||
|
||||
message close_req {
|
||||
request close_req {
|
||||
required u32 caller_id = 1;
|
||||
} = 2;
|
||||
|
||||
message close_resp {
|
||||
response close_resp {
|
||||
required qmi_result result = 2;
|
||||
} = 2;
|
||||
|
||||
message iovec_req {
|
||||
request iovec_req {
|
||||
required u32 caller_id = 1;
|
||||
required u8 direction = 2;
|
||||
required iovec_entry iovec[] = 3;
|
||||
required u8 is_force_sync = 4;
|
||||
} = 3;
|
||||
|
||||
message iovec_resp {
|
||||
response iovec_resp {
|
||||
required qmi_result result = 2;
|
||||
} = 3;
|
||||
|
||||
message alloc_buf_req {
|
||||
request alloc_buf_req {
|
||||
required u32 caller_id = 1;
|
||||
required u32 buff_size = 2;
|
||||
} = 4;
|
||||
|
||||
message alloc_buf_resp {
|
||||
response alloc_buf_resp {
|
||||
required qmi_result result = 2;
|
||||
optional u64 buff_address = 0x10;
|
||||
} = 4;
|
||||
|
||||
message dev_error_req {
|
||||
request dev_error_req {
|
||||
required u32 caller_id = 1;
|
||||
} = 5;
|
||||
|
||||
message dev_error_resp {
|
||||
response dev_error_resp {
|
||||
required qmi_result result = 2;
|
||||
optional u8 status = 0x10;
|
||||
} = 5;
|
||||
|
||||
message force_sync {
|
||||
indication force_sync {
|
||||
required u32 caller_id[] = 1;
|
||||
} = 6;
|
||||
|
13
qmi_tlv.c
13
qmi_tlv.c
@ -6,10 +6,6 @@
|
||||
|
||||
#include "qmi_rmtfs.h"
|
||||
|
||||
#define QMI_PKT_TYPE_REQUEST 0
|
||||
#define QMI_PKT_TYPE_RESPONSE 2
|
||||
#define QMI_PKT_TYPE_CONTROL 4
|
||||
|
||||
struct qmi_packet {
|
||||
uint8_t flags;
|
||||
uint16_t txn_id;
|
||||
@ -31,7 +27,7 @@ struct qmi_tlv_item {
|
||||
uint8_t data[];
|
||||
} __attribute__((__packed__));
|
||||
|
||||
struct qmi_tlv *qmi_tlv_init(unsigned txn, unsigned msg_id)
|
||||
struct qmi_tlv *qmi_tlv_init(unsigned txn, unsigned msg_id, unsigned msg_type)
|
||||
{
|
||||
struct qmi_packet *pkt;
|
||||
struct qmi_tlv *tlv;
|
||||
@ -44,7 +40,7 @@ struct qmi_tlv *qmi_tlv_init(unsigned txn, unsigned msg_id)
|
||||
tlv->buf = tlv->allocated;
|
||||
|
||||
pkt = tlv->buf;
|
||||
pkt->flags = QMI_PKT_TYPE_RESPONSE;
|
||||
pkt->flags = msg_type;
|
||||
pkt->txn_id = txn;
|
||||
pkt->msg_id = msg_id;
|
||||
pkt->msg_len = 0;
|
||||
@ -52,11 +48,14 @@ struct qmi_tlv *qmi_tlv_init(unsigned txn, unsigned msg_id)
|
||||
return tlv;
|
||||
}
|
||||
|
||||
struct qmi_tlv *qmi_tlv_decode(void *buf, size_t len, unsigned *txn)
|
||||
struct qmi_tlv *qmi_tlv_decode(void *buf, size_t len, unsigned *txn, unsigned msg_type)
|
||||
{
|
||||
struct qmi_packet *pkt = buf;
|
||||
struct qmi_tlv *tlv;
|
||||
|
||||
if (pkt->flags != msg_type)
|
||||
return NULL;
|
||||
|
||||
tlv = malloc(sizeof(struct qmi_tlv));
|
||||
memset(tlv, 0, sizeof(struct qmi_tlv));
|
||||
|
||||
|
4
rmtfs.c
4
rmtfs.c
@ -62,11 +62,11 @@ static void rmtfs_open(int sock, unsigned node, unsigned port, void *msg, size_t
|
||||
struct rmtfs_qmi_result result = {};
|
||||
struct rmtfs_open_resp *resp;
|
||||
struct rmtfs_open_req *req;
|
||||
int caller_id;
|
||||
int caller_id = -1;
|
||||
unsigned txn;
|
||||
size_t len;
|
||||
void *ptr;
|
||||
char path[256];
|
||||
char path[256] = {};
|
||||
int ret;
|
||||
|
||||
req = rmtfs_open_req_parse(msg, msg_len, &txn);
|
||||
|
Loading…
Reference in New Issue
Block a user