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-12-05 00:45:58 +0000
commite2b5736eea47208c2115f865572de114c57281d5 (patch)
treeac13cd356bbf4805e982a4135b5d2d88c5c27c5b
parentfb9afbca596d19d1ce9c17ea954d257b4163fc6e (diff)
downloadchrome-ec-e2b5736eea47208c2115f865572de114c57281d5.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> Reviewed-on: https://chromium-review.googlesource.com/c/1333221 Reviewed-by: Marco Chen <marcochen@chromium.org> Commit-Queue: Marco Chen <marcochen@chromium.org> Tested-by: Marco Chen <marcochen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/1359940 Reviewed-by: Chia-Hsiu Chang <chia-hsiu.chang@quanta.corp-partner.google.com> Tested-by: Chia-Hsiu Chang <chia-hsiu.chang@quanta.corp-partner.google.com> Commit-Queue: Chia-Hsiu Chang <chia-hsiu.chang@quanta.corp-partner.google.com>
-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 88943dd276..4b58b84434 100644
--- a/common/ccd_config.c
+++ b/common/ccd_config.c
@@ -804,25 +804,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;
@@ -832,9 +829,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);
/*
@@ -842,7 +839,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;
@@ -852,6 +849,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;