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 <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/861207
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
Vadim Bendebury
2018-01-10 18:51:20 -08:00
committed by chrome-bot
parent b95b487cbc
commit d9831e6015

View File

@@ -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);
}