summaryrefslogtreecommitdiffstats
path: root/mboxd_msg.c
diff options
context:
space:
mode:
authorAndrew Jeffery <andrew@aj.id.au>2017-04-24 16:13:06 +0930
committerAndrew Jeffery <andrew@aj.id.au>2017-04-26 11:34:00 +0930
commit55dede6b30694145ac0d8e79cc13172077183f17 (patch)
tree154c0ceda3ca128ab9f7e548e1a3f85374ee3160 /mboxd_msg.c
parent121dc0d6bc3ce93017cb20433016c66ef7580985 (diff)
downloadphosphor-mboxd-55dede6b30694145ac0d8e79cc13172077183f17.tar.gz
phosphor-mboxd-55dede6b30694145ac0d8e79cc13172077183f17.zip
mbox: Clarify sequence number constraints
And implement the specified behaviour. Change-Id: I268d5896aa8dda3875cd79f4ff18929c8e3aea49 Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Diffstat (limited to 'mboxd_msg.c')
-rw-r--r--mboxd_msg.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/mboxd_msg.c b/mboxd_msg.c
index 9f8aba1..a5bcf62 100644
--- a/mboxd_msg.c
+++ b/mboxd_msg.c
@@ -650,19 +650,27 @@ static int mbox_handle_ack(struct mbox_context *context, union mbox_regs *req,
}
/*
- * check_cmd_valid() - Check if the given command is a valid mbox command code
+ * check_req_valid() - Check if the given request is a valid mbox request
* @context: The mbox context pointer
- * @cmd: The command code
+ * @cmd: The request registers
*
- * Return: 0 if command is valid otherwise negative error code
+ * Return: 0 if request is valid otherwise negative error code
*/
-static int check_cmd_valid(struct mbox_context *context, int cmd)
+static int check_req_valid(struct mbox_context *context, union mbox_regs *req)
{
- if (cmd <= 0 || cmd > NUM_MBOX_CMDS) {
+ uint8_t cmd = req->msg.command;
+ uint8_t seq = req->msg.seq;
+
+ if (cmd > NUM_MBOX_CMDS) {
MSG_ERR("Unknown mbox command: %d\n", cmd);
return -MBOX_R_PARAM_ERROR;
}
+ if (seq == context->prev_seq && cmd != MBOX_C_GET_MBOX_INFO) {
+ MSG_ERR("Invalid sequence number: %d\n", seq);
+ return -MBOX_R_SEQ_ERROR;
+ }
+
if (context->state & STATE_SUSPENDED) {
if (cmd != MBOX_C_GET_MBOX_INFO && cmd != MBOX_C_ACK) {
MSG_ERR("Cannot use that cmd while suspended: %d\n",
@@ -714,7 +722,7 @@ static int handle_mbox_req(struct mbox_context *context, union mbox_regs *req)
int rc = 0, len;
MSG_OUT("Got data in with command %d\n", req->msg.command);
- rc = check_cmd_valid(context, req->msg.command);
+ rc = check_req_valid(context, req);
if (rc < 0) {
resp.response = -rc;
} else {
@@ -727,6 +735,8 @@ static int handle_mbox_req(struct mbox_context *context, union mbox_regs *req)
}
}
+ context->prev_seq = req->msg.seq;
+
MSG_OUT("Writing response to MBOX regs: %d\n", resp.response);
len = write(context->fds[MBOX_FD].fd, &resp, sizeof(resp));
if (len < sizeof(resp)) {
OpenPOWER on IntegriCloud