Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
Verified Commit 75925cec authored by Ayush Singh's avatar Ayush Singh
Browse files

Remove payload_size from greybus message


Can be calculated from header

Signed-off-by: default avatarAyush Singh <ayushdevel1325@gmail.com>
parent 20052617
Branches
No related merge requests found
Pipeline #5448 passed with stage
in 1 minute and 43 seconds
......@@ -21,10 +21,31 @@
struct gb_message {
void *fifo_reserved;
struct gb_operation_msg_hdr header;
size_t payload_size;
uint8_t payload[];
};
/*
* Return the paylaod length of a greybus message from message header.
*
* @param hdr: greybus header
*
* @return payload length
*/
static inline size_t gb_hdr_payload_len(const struct gb_operation_msg_hdr *hdr) {
return hdr->size - sizeof(struct gb_operation_msg_hdr);
}
/*
* Return the paylaod length of a greybus message.
*
* @param msg: Greybus message
*
* @return payload length
*/
static inline size_t gb_message_payload_len(const struct gb_message *msg) {
return gb_hdr_payload_len(&msg->header);
}
/*
* Check if the greybus message header is a response.
*
......
......@@ -70,7 +70,7 @@ static inline int gb_message_hdlc_send(const struct gb_message *msg)
char buffer[HDLC_MAX_BLOCK_SIZE];
memcpy(buffer, &msg->header, sizeof(struct gb_operation_msg_hdr));
memcpy(&buffer[sizeof(struct gb_operation_msg_hdr)], msg->payload, msg->payload_size);
memcpy(&buffer[sizeof(struct gb_operation_msg_hdr)], msg->payload, gb_message_payload_len(msg));
hdlc_block_send_sync(buffer, msg->header.size, ADDRESS_GREYBUS, 0x03);
......
......@@ -40,7 +40,6 @@ struct gb_message *gb_message_alloc(size_t payload_len, uint8_t message_type, ui
msg->header.id = operation_id;
msg->header.type = message_type;
msg->header.status = status;
msg->payload_size = payload_len;
return msg;
}
......
......@@ -70,14 +70,14 @@ static int hdlc_process_greybus_frame(const char *buffer, size_t buffer_len)
return -1;
}
msg = gb_message_alloc(hdr->size - sizeof(struct gb_operation_msg_hdr), hdr->type, hdr->id,
msg = gb_message_alloc(gb_hdr_payload_len(hdr), hdr->type, hdr->id,
hdr->status);
if (!msg) {
LOG_ERR("Failed to allocate greybus message");
return -1;
}
memcpy(msg->header.pad, hdr->pad, sizeof(uint16_t));
memcpy(msg->payload, &buffer[sizeof(struct gb_operation_msg_hdr)], msg->payload_size);
memcpy(msg->payload, &buffer[sizeof(struct gb_operation_msg_hdr)], gb_message_payload_len(msg));
ret = ap_rx_submit(msg);
if (ret < 0) {
LOG_ERR("Failed add message to AP Queue");
......
......@@ -77,15 +77,15 @@ static struct gb_message *gb_message_receive(int sock, bool *flag)
goto early_exit;
}
msg = gb_message_alloc(hdr.size - sizeof(struct gb_operation_msg_hdr), hdr.type, hdr.id,
msg = gb_message_alloc(gb_hdr_payload_len(&hdr), hdr.type, hdr.id,
hdr.status);
if (!msg) {
LOG_ERR("Failed to allocate node message");
goto early_exit;
}
ret = read_data(sock, msg->payload, msg->payload_size);
if (ret != msg->payload_size) {
ret = read_data(sock, msg->payload, gb_message_payload_len(msg));
if (ret != gb_message_payload_len(msg)) {
*flag = ret == 0;
goto free_msg;
}
......@@ -108,8 +108,8 @@ static int gb_message_send(int sock, const struct gb_message *msg)
goto early_exit;
}
ret = write_data(sock, msg->payload, msg->payload_size);
if (ret != msg->payload_size) {
ret = write_data(sock, msg->payload, gb_message_payload_len(msg));
if (ret != gb_message_payload_len(msg)) {
LOG_ERR("Failed to send Greybus Message Payload to node");
goto early_exit;
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment