summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Hendricks <dhendrix@chromium.org>2012-04-25 11:40:11 -0700
committerDavid Hendricks <dhendrix@chromium.org>2012-04-25 14:51:33 -0700
commitef9424dd1058d1f49692ecf10d7b1b207b175e15 (patch)
treed8f4db5a65adb85ec36ae03ad1b67f49d2344bcb
parent83082746a9a463ad6a964cfc2f2abd0bf08d95fb (diff)
downloadchrome-ec-ef9424dd1058d1f49692ecf10d7b1b207b175e15.tar.gz
simplified message protocol
This simplifies the messaging protocol. Messages will now only have the raw content plus a checksum byte at the end. We will worry about needs of the transport layer (e.g. preamble/postamble bytes) on the host driver side, and will not support variable-length commands for now. There is also a protocol version command, which is now command number 0x00, which returns a 4-byte protocol version followed by a 1-byte checksum. BUG=none TEST=tested on daisy using mkbp kernel driver Signed-off-by: David Hendricks <dhendrix@chromium.org> Change-Id: I8fcc693cd50bc2b515164ea7a2a941cdd8333e73
-rw-r--r--common/message.c32
-rw-r--r--include/message.h31
2 files changed, 23 insertions, 40 deletions
diff --git a/common/message.c b/common/message.c
index 6828273e78..0040f479f4 100644
--- a/common/message.c
+++ b/common/message.c
@@ -13,9 +13,12 @@
#include "keyboard_scan.h"
#include "util.h"
-/* Our ID message - Matrix KeyBoard Protocol */
-static const char proto_id[] = "Google Chrome MKBP v1";
+/* EC ID */
+/* (TODO(dhendrix): Define this in board-specific code */
+static const char ec_id[] = "Google Chrome EC";
+/* Protocol version (least significant byte in lowest byte position) */
+static const uint8_t proto_ver[] = { 1, 0, 0, 0 };
/**
* Get the response to a given command
@@ -34,12 +37,15 @@ static int message_get_response(int cmd, uint8_t **buffp, int max_len)
* Invalid commands are ignored, just returning a stream of 0xff
* bytes.
*/
- switch (cmd & MSG_CMD_MASK) {
+ switch (cmd) {
+ case CMDC_PROTO_VER:
+ *buffp = (uint8_t *)proto_ver;
+ return sizeof(proto_ver);
case CMDC_NOP:
return 0;
case CMDC_ID:
- *buffp = (char *)proto_id;
- return sizeof(proto_id) - 1;
+ *buffp = (char *)ec_id;
+ return sizeof(ec_id) - 1;
case CMDC_KEY_STATE:
return keyboard_get_scan(buffp, max_len);
default:
@@ -55,10 +61,9 @@ int message_process_cmd(int cmd, uint8_t *out_msg, int max_len)
int msg_len;
int need_copy;
int sum = 0;
- int len;
int i;
- msg = out_msg + MSG_HEADER_BYTES;
+ msg = out_msg;
msg_len = message_get_response(cmd, &msg, max_len - MSG_PROTO_BYTES);
if (msg_len < 0)
return msg_len;
@@ -69,25 +74,18 @@ int message_process_cmd(int cmd, uint8_t *out_msg, int max_len)
*/
if (msg_len + MSG_PROTO_BYTES > max_len)
msg_len = max_len - MSG_PROTO_BYTES;
- len = msg_len + MSG_PROTO_BYTES;
ASSERT(msg_len >= 0 && msg_len < 0xffff);
- need_copy = msg != out_msg + MSG_HEADER_BYTES;
+ need_copy = msg != out_msg;
ASSERT(!need_copy ||
msg + msg_len < out_msg ||
msg > out_msg + sizeof(out_msg));
- out_msg[0] = MSG_HEADER;
- out_msg[1] = len & 0xff;
- out_msg[2] = (len >> 8) & 0xff;
- sum += MSG_HEADER + len + (len >> 8);
-
for (i = 0; i < msg_len; i++) {
if (need_copy)
- out_msg[i + 3] = msg[i];
+ out_msg[i] = msg[i];
sum += msg[i];
}
- out_msg[i + 3] = sum & 0xff;
- out_msg[i + 4] = MSG_PREAMBLE;
+ out_msg[i] = sum;
return msg_len + MSG_PROTO_BYTES;
}
diff --git a/include/message.h b/include/message.h
index 0930eb24f1..439c6df67e 100644
--- a/include/message.h
+++ b/include/message.h
@@ -11,28 +11,19 @@
/* Command interface between EC and AP */
enum {
- /* Mask to convert a command byte into a command */
- MSG_CMD_MASK = 0x7f,
-
- /* The bytes which appear before the header in a message */
- MSG_PREAMBLE = 0xff,
-
- /* The header byte, which follows the preamble */
- MSG_HEADER = 0xec,
-
- MSG_HEADER_BYTES = 3,
- MSG_TRAILER_BYTES = 2,
- MSG_PROTO_BYTES = MSG_HEADER_BYTES + MSG_TRAILER_BYTES,
+ MSG_TRAILER_BYTES = 1,
+ MSG_PROTO_BYTES = MSG_TRAILER_BYTES,
};
/* The command codes that we understand */
enum message_cmd_t {
- /* control / status messages */
+ /* EC control/status messages */
+ CMDC_PROTO_VER = 0x00, /* Protocol version */
CMDC_NOP, /* No operation / ping */
CMDC_ID, /* Read EC ID */
- /* functional messages */
- CMDC_KEY_STATE = 0x20, /* Read key state */
+ /* Functional messages */
+ CMDC_KEY_STATE = 0x20, /* Read key state */
};
@@ -44,15 +35,9 @@ enum message_cmd_t {
*
* The format of a reply is a sequence of bytes:
*
- * <hdr> <len_lo> <len_hi> <msg bytes> <sum> <preamble bytes>
- *
- * The hdr byte is just a tag to indicate that the real message follows. It
- * signals the end of any preamble required by the interface.
- *
- * The 16-bit length is the entire packet size, including the header, length
- * bytes, message payload, checksum, and postamble byte.
+ * <msg bytes> <sum>
*
- * The checksum is calculated as the sum of the header, len byte and message.
+ * The checksum is calculated as the sum of all message bytes
*
* @param cmd Command to process (CMD_...)
* @param buff Pointer to buffer to store reponse