diff options
author | Randall Spangler <rspangler@chromium.org> | 2018-05-18 14:27:42 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-05-22 21:57:12 -0700 |
commit | 9df26ce0f2a97bbc58b1807483fd22005e253b0f (patch) | |
tree | 651d4ff123841cdc0630b423e91e61395f894b68 /chip | |
parent | 4ec57f14091c42e2f9502d1c17146a06fa105a88 (diff) | |
download | chrome-ec-9df26ce0f2a97bbc58b1807483fd22005e253b0f.tar.gz |
cr50: Refactor tracking vendor command origin
Added flags parameter to extension_route_command(). The caller now
specifies whether the command comes from the USB interface or the AP.
Moved USB-specific shuffling of response to embed result code into
usb_upgrade.c, so extension_route_command() can be more generic.
No change to permissions/behavior for existing commands.
ccd_command_wrapper() still sends vendor commands as if they come from
the AP. That's fixed in the next CL.
Reduces code size by 128 bytes
BUG=b:79983505
BRANCH=cr50
TEST=manual
Build with DEBUG_EXTENSION defined, to turn on printing each command
'ccd lock' comes from AP and works
From host, 'gscutil -I' comes from USB and fails
From AP, 'gscutil -t -I' comes from AP and works
Change-Id: I7136bb54073de9c5951a174c308151b1871c56f3
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1068101
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Diffstat (limited to 'chip')
-rw-r--r-- | chip/g/usb_upgrade.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/chip/g/usb_upgrade.c b/chip/g/usb_upgrade.c index aeafd819fa..3c3982af05 100644 --- a/chip/g/usb_upgrade.c +++ b/chip/g/usb_upgrade.c @@ -106,6 +106,35 @@ static int valid_transfer_start(struct consumer const *consumer, size_t count, return 0; return 1; } + +static void usb_extension_route_command(uint16_t command_code, + uint8_t *buffer, + size_t in_size, + size_t *out_size) +{ + uint32_t rv; + size_t buf_size; + + /* + * 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, + VENDOR_CMD_FROM_USB); + /* + * Copy actual response, if any, one byte up, to free room for + * the return code. + */ + if (buf_size) + memmove(buffer + 1, buffer, buf_size); + *out_size = buf_size + 1; + + buffer[0] = rv; /* We care about LSB only. */ +} + static int try_vendor_command(struct consumer const *consumer, size_t count) { struct update_frame_header ufh; |