Files
OpenCellular/common/extension.c
Bill Richardson 12da6c23fb Cr50: Add TPM-compliant commands for console lock
This allows custom TPM commands to be declared using the a
DECLARE_VENDOR_COMMAND macro instead of the original (and still
unchanged) DECLARE_EXTENSION_COMMAND macro.

The new commands are nearly identical, but they are encapsulated
using the vendor-specific protocols described in the TPMv2 spec.
Our original extensions use a non-standard command code, and
return a non-standard struct on completion, which can be
confusing to standard TPM drivers and tools.

Demonstrating the use of the new macros, this adds commands to
obtain the state of the Cr50 restricted console lock, or to set
the lock. There is intentionally no command to unlock the
console.

Note that this CL just adds the commands to the Cr50. We still
need to provide a nice userspace utility for the AP to use.

BUG=chrome-os-partner:58230
BUG=chrome-os-partner:57940
BRANCH=none
TEST=make buildall; load, boot, test, and update again on Reef

On Reef, I can use the trunks_send tool to send the raw TPM bytes
to invoke these commands:

Get the lock state:

  # trunks_send 80 01 00 00 00 0C 20 00 00 00 00 10
  80010000000D00000000001000

The last byte 00 indicates that the lock is NOT set, so set it:

  # trunks_send 80 01 00 00 00 0C 20 00 00 00 00 10
  80010000000C000000000011

Success. On the Cr50 console, I see it take effect:

  [480.080444 The console is locked]

Query the state again:

  # trunks_send 80 01 00 00 00 0C 20 00 00 00 00 10
  80010000000D00000000001001

and now the last byte 01 indicates that the console is locked.

And of course the existing extension commands still work as
before. In addition to uploading firmware, I can use the
usb_updater from my build machine to query the running firmware
version:

  $ ./extra/usb_updater/usb_updater -f
  open_device 18d1:5014
  found interface 4 endpoint 5, chunk_len 64
  READY
  -------
  start
  Target running protocol version 5
  Offsets: backup RO at 0x40000, backup RW at 0x4000
  Keyids: RO 0x3716ee6b, RW 0xb93d6539
  Current versions:
  RO 0.0.10
  RW 0.0.9
  $

Change-Id: I7fb1d888bf808c2ef0b2b07c782e926063cc2cc4
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/409692
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2016-11-11 23:11:51 -08:00

37 lines
978 B
C

/* Copyright 2015 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "byteorder.h"
#include "console.h"
#include "extension.h"
#include "link_defs.h"
#define CPRINTF(format, args...) cprintf(CC_EXTENSION, format, ## args)
uint32_t extension_route_command(uint16_t command_code,
void *buffer,
size_t in_size,
size_t *out_size)
{
struct extension_command *cmd_p;
struct extension_command *end_p;
cmd_p = (struct extension_command *)&__extension_cmds;
end_p = (struct extension_command *)&__extension_cmds_end;
while (cmd_p != end_p) {
if (cmd_p->command_code == command_code)
return cmd_p->handler(command_code, buffer,
in_size, out_size);
cmd_p++;
}
CPRINTF("%s: handler %d not found\n", __func__, command_code);
/* This covers the case of the handler not found. */
*out_size = 0;
return VENDOR_RC_NO_SUCH_COMMAND;
}