summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2018-01-05 16:47:04 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2018-02-01 00:48:11 +0000
commit3db335a6985315fb8a38fdbdce736870268fe6c2 (patch)
tree58b1c4b9c49c026c698d844d8963061a92aaefbb
parente2fc92801dabfc7f062453e3adc5fd5f1c9c5893 (diff)
downloadchrome-ec-3db335a6985315fb8a38fdbdce736870268fe6c2.tar.gz
ccd: Refactor routing CCD commands through TPM task
Currently only 'ccd password' command is processed using TPM vendor command. More CCD commands are going to be processed the same way. This patch refactors the code to make it easier to add more subcommands. BRANCH=cr50 BUG=b:62537474 TEST=verified that 'ccd password' still works both from crosh and CLI. Change-Id: Id55da51d6edc5652591ad30160a4102b3026a186 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/854708 Reviewed-by: Randall Spangler <rspangler@chromium.org> (cherry picked from commit 17a167cda16420def302cd10c0c214e61f9f5406) Reviewed-on: https://chromium-review.googlesource.com/896755
-rw-r--r--common/ccd_config.c49
1 files changed, 32 insertions, 17 deletions
diff --git a/common/ccd_config.c b/common/ccd_config.c
index 6d19d972d2..cbbf11570e 100644
--- a/common/ccd_config.c
+++ b/common/ccd_config.c
@@ -803,25 +803,22 @@ static int do_ccd_password(char *password)
return ccd_set_password(password);
}
-static int command_ccd_password(int argc, char **argv)
+/*
+ * Prepare a message containing a TPM vendor command, have the TPM task
+ * process the message and report the result to the caller.
+ *
+ * Message header is always the same, the caller supplies the subcommand code
+ * and payload, if any.
+ */
+static int send_vendor_command(enum ccd_vendor_subcommands subcmd,
+ void *payload, size_t size)
{
- struct ccd_vendor_cmd_header *vch;
int rv;
- size_t password_size;
+ struct ccd_vendor_cmd_header *vch;
size_t command_size;
- if (argc < 2)
- return EC_ERROR_PARAM_COUNT;
-
- password_size = strlen(argv[1]);
-
- if (password_size > CCD_MAX_PASSWORD_SIZE) {
- ccprintf("Password can not be longer than %d characters\n",
- CCD_MAX_PASSWORD_SIZE);
- return EC_ERROR_PARAM1;
- }
- command_size = sizeof(*vch) + password_size;
+ command_size = sizeof(*vch) + size;
rv = shared_mem_acquire(command_size, (char **)&vch);
if (rv != EC_SUCCESS)
return rv;
@@ -831,9 +828,9 @@ static int command_ccd_password(int argc, char **argv)
vch->tpm_header.size = htobe32(command_size);
vch->tpm_header.command_code = htobe32(TPM_CC_VENDOR_BIT_MASK);
vch->tpm_header.subcommand_code = htobe16(VENDOR_CC_CCD);
- vch->ccd_subcommand = CCDV_PASSWORD;
+ vch->ccd_subcommand = subcmd;
- memcpy(vch + 1, argv[1], password_size);
+ memcpy(vch + 1, payload, size);
tpm_alt_extension(&vch->tpm_header, command_size);
/*
@@ -841,7 +838,7 @@ static int command_ccd_password(int argc, char **argv)
* error code is the first byte after the header.
*/
if (vch->tpm_header.command_code) {
- ccprintf("Password setting error %d\n", vch->ccd_subcommand);
+ ccprintf("Command error %d\n", vch->ccd_subcommand);
rv = EC_ERROR_UNKNOWN;
} else {
rv = EC_SUCCESS;
@@ -851,6 +848,24 @@ static int command_ccd_password(int argc, char **argv)
return EC_SUCCESS;
}
+static int command_ccd_password(int argc, char **argv)
+{
+ size_t password_size;
+
+ if (argc < 2)
+ return EC_ERROR_PARAM_COUNT;
+
+ password_size = strlen(argv[1]);
+
+ if (password_size > CCD_MAX_PASSWORD_SIZE) {
+ ccprintf("Password can not be longer than %d characters\n",
+ CCD_MAX_PASSWORD_SIZE);
+ return EC_ERROR_PARAM1;
+ }
+
+ return send_vendor_command(CCDV_PASSWORD, argv[1], password_size);
+}
+
static int command_ccd_open(int argc, char **argv)
{
int is_long = 1;