From d9831e6015ccce99dc77e734368622abde1947fa Mon Sep 17 00:00:00 2001 From: Vadim Bendebury Date: Wed, 10 Jan 2018 18:51:20 -0800 Subject: [PATCH] gsctool: allow password handling function to run on different subcommands With the upcoming addition of ability to manage CCD using gsctool, it is necessary to send user password in several CC_CCD subcommands. This patch modifies the password handler to allow the user to specify the subcommand code to use. VENDOR_RC_IN_PROGRESS is added to the list of acceptable return codes, as this is what could be returned in response to 'ccd unlock' or 'ccd open'. BRANCH=none BUG=b:62537474 TEST=verified that password still could be set and cleared from the CLI and gsctool Change-Id: Ic58f344a728897fb535cd9b7bedd47d28b30f5f8 Signed-off-by: Vadim Bendebury Reviewed-on: https://chromium-review.googlesource.com/861207 Reviewed-by: Randall Spangler --- extra/usb_updater/gsctool.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/extra/usb_updater/gsctool.c b/extra/usb_updater/gsctool.c index 2dc0b6568c..986708255e 100644 --- a/extra/usb_updater/gsctool.c +++ b/extra/usb_updater/gsctool.c @@ -132,7 +132,7 @@ * modes, among other things. * * Protocol version 6 does not change the format of the first PDU response, - * but it indicates the target's ablitiy to channel TPM venfor commands + * but it indicates the target's ablitiy to channel TPM vendor commands * through USB connection. * * When channeling TPM vendor commands the USB frame looks as follows: @@ -1540,7 +1540,8 @@ static int parse_bid(const char *opt, return 1; } -static void process_password(struct transfer_descriptor *td) +static uint32_t common_process_password(struct transfer_descriptor *td, + enum ccd_vendor_subcommands subcmd) { size_t response_size; uint8_t response; @@ -1590,18 +1591,26 @@ static void process_password(struct transfer_descriptor *td) * the newline and free a byte to prepend the subcommand code. */ memmove(password + 1, password, len - 1); - password[0] = CCDV_PASSWORD; + password[0] = subcmd; response_size = sizeof(response); rv = send_vendor_command(td, VENDOR_CC_CCD, password, len, &response, &response_size); free(password); free(password_copy); - if (!rv) + + if ((rv != VENDOR_RC_SUCCESS) && (rv != VENDOR_RC_IN_PROGRESS)) + fprintf(stderr, "Error sending password: rv %d, response %d\n", + rv, response_size ? response : 0); + + return rv; +} + +static void process_password(struct transfer_descriptor *td) +{ + if (common_process_password(td, CCDV_PASSWORD) == VENDOR_RC_SUCCESS) return; - fprintf(stderr, "Error setting password: rv %d, response %d\n", - rv, response_size ? response : 0); exit(update_error); }