summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2017-06-02 16:33:22 -0700
committerBernie Thompson <bhthompson@chromium.org>2017-08-19 00:02:09 +0000
commitc602ccb76b0e493dc12cd4f3c0a799aec5f27c40 (patch)
tree186fd7b978fe8e356dcc057c126c886e680c2f7d
parent36ef897e47b96d5502fd35a47c04d8e742047797 (diff)
downloadchrome-ec-c602ccb76b0e493dc12cd4f3c0a799aec5f27c40.tar.gz
cr50: usb_updater: include return codes into USB response payload
When vendor commands are processed by the TPM device, the result of the command execution is communicated through the TPM response header. When vendor commands are sent through USB the command execution result value is lost, as the USB reply includes only the response payload, (if any), but not the result value. With this patch the single byte result value is prepended to the USB response payload. The recipient will always look for the value in the first byte of the response to find the vendor command execution status. The corresponding change to the Cr50 usb_updater will remove the response code from the payload before considering the command's return data. BRANCH=cr50 BUG=b:35587387,b:35587053 TEST=verified proper existing extension commands processing (post reset, turn update on) by the new version of usb_updater and backwards compatibility with earlier Cr50 RW version (down to 0.0.13). Change-Id: I5c8b3ea71d3cbbaccc06c909754944b3ab04675d Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/525093 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> (cherry picked from commit 51f5875da6b542f7947cd7ca9efdbd61b5d937ce) Reviewed-on: https://chromium-review.googlesource.com/538565 (cherry picked from commit b340947cc03fe9b79bce9e38726f3d8bb0edecd8) Reviewed-on: https://chromium-review.googlesource.com/622213 Reviewed-by: Bernie Thompson <bhthompson@chromium.org> Commit-Queue: Bernie Thompson <bhthompson@chromium.org> Tested-by: Bernie Thompson <bhthompson@chromium.org>
-rw-r--r--common/extension.c44
-rw-r--r--include/extension.h8
2 files changed, 34 insertions, 18 deletions
diff --git a/common/extension.c b/common/extension.c
index f87ad38812..7edbdaf794 100644
--- a/common/extension.c
+++ b/common/extension.c
@@ -7,6 +7,7 @@
#include "console.h"
#include "extension.h"
#include "link_defs.h"
+#include "util.h"
#define CPRINTF(format, args...) cprintf(CC_EXTENSION, format, ## args)
@@ -35,12 +36,14 @@ static uint32_t extension_route_command(uint16_t command_code,
return VENDOR_RC_NO_SUCH_COMMAND;
}
-uint32_t usb_extension_route_command(uint16_t command_code,
- void *buffer,
- size_t in_size,
- size_t *out_size)
+void usb_extension_route_command(uint16_t command_code,
+ void *buffer,
+ size_t in_size,
+ size_t *out_size)
{
- int is_allowed = 0;
+ uint32_t rv;
+ uint8_t *buf = buffer; /* Cache it for easy pointer arithmetics. */
+ size_t buf_size;
switch (command_code) {
#ifdef CR50_DEV
@@ -48,21 +51,34 @@ uint32_t usb_extension_route_command(uint16_t command_code,
#endif /* defined(CR50_DEV) */
case VENDOR_CC_TURN_UPDATE_ON:
case EXTENSION_POST_RESET: /* Always need to be able to reset. */
- is_allowed = 1;
+
+ /*
+ * The return code normally put into the TPM response header
+ * is not present in the USB response. Vendor command return
+ * code is guaranteed to fit in a byte. Let's keep space for
+ * it in the front of the buffer.
+ */
+ buf_size = *out_size - 1;
+ rv = extension_route_command(command_code, buffer,
+ in_size, &buf_size);
+ /*
+ * Copy actual response, if any, one byte up, to free room for
+ * the return code.
+ */
+ if (buf_size)
+ memmove(buf + 1, buf, buf_size);
+ *out_size = buf_size + 1;
break;
default:
+ /* Otherwise, we don't allow this command. */
+ CPRINTF("%s: ignoring vendor cmd %d\n", __func__, command_code);
+ *out_size = 1;
+ rv = VENDOR_RC_NO_SUCH_COMMAND;
break;
}
- if (is_allowed)
- return extension_route_command(command_code, buffer, in_size,
- out_size);
-
- /* Otherwise, we don't allow this command. */
- CPRINTF("%s: ignoring vendor cmd %d\n", __func__, command_code);
- *out_size = 0;
- return VENDOR_RC_NO_SUCH_COMMAND;
+ buf[0] = rv; /* We care about LSB only. */
}
uint32_t tpm_extension_route_command(uint16_t command_code,
diff --git a/include/extension.h b/include/extension.h
index 28a0dc7d06..e5f183eb49 100644
--- a/include/extension.h
+++ b/include/extension.h
@@ -40,10 +40,10 @@ typedef enum vendor_cmd_rc (*extension_handler)(enum vendor_cmd_cc code,
* data returned by the handler. A single byte return
* usually indicates an error and contains the error code.
*/
-uint32_t usb_extension_route_command(uint16_t command_code,
- void *buffer,
- size_t command_size,
- size_t *size);
+void usb_extension_route_command(uint16_t command_code,
+ void *buffer,
+ size_t command_size,
+ size_t *size);
uint32_t tpm_extension_route_command(uint16_t command_code,
void *buffer,
size_t command_size,