direct-io.hg

changeset 10493:8589cdd09636

[VTPM_TOOLS] Hotplug script enabled the vtpm manager and removed the
control messages from the BE.

Signed-off-by: Vincent Scarlata <vincent.r.scarlata@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue Jun 27 11:15:48 2006 +0100 (2006-06-27)
parents 18587d3e94c8
children b12cd185d579
files linux-2.6-xen-sparse/drivers/xen/tpmback/common.h linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c tools/examples/Makefile tools/examples/vtpm-impl tools/vtpm_manager/manager/dmictl.c tools/vtpm_manager/manager/securestorage.c tools/vtpm_manager/manager/vtpm_manager.c tools/vtpm_manager/manager/vtpm_manager.h tools/vtpm_manager/manager/vtpm_manager_handler.c tools/vtpm_manager/manager/vtpmd.c tools/vtpm_manager/manager/vtpmpriv.h tools/vtpm_manager/manager/vtsp.c tools/vtpm_manager/manager/vtsp.h tools/vtpm_manager/tcs/tcs.c tools/vtpm_manager/tcs/tcs.h tools/vtpm_manager/util/tcg.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h	Tue Jun 27 11:14:19 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h	Tue Jun 27 11:15:48 2006 +0100
     1.3 @@ -63,8 +63,6 @@ void tpmif_xenbus_init(void);
     1.4  void tpmif_xenbus_exit(void);
     1.5  int tpmif_map(tpmif_t *tpmif, unsigned long shared_page, unsigned int evtchn);
     1.6  irqreturn_t tpmif_be_int(int irq, void *dev_id, struct pt_regs *regs);
     1.7 -int tpmif_vtpm_open(tpmif_t *tpmif, domid_t domain, u32 instance);
     1.8 -int tpmif_vtpm_close(u32 instance);
     1.9  
    1.10  int vtpm_release_packets(tpmif_t * tpmif, int send_msgs);
    1.11  
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c	Tue Jun 27 11:14:19 2006 +0100
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c	Tue Jun 27 11:15:48 2006 +0100
     2.3 @@ -685,95 +685,6 @@ static struct miscdevice vtpms_miscdevic
     2.4  };
     2.5  
     2.6  /***************************************************************
     2.7 - Virtual TPM functions and data stuctures
     2.8 -***************************************************************/
     2.9 -
    2.10 -static u8 create_cmd[] = {
    2.11 -	1, 193,			/* 0: TPM_TAG_RQU_COMMAMD */
    2.12 -	0, 0, 0, 19,		/* 2: length */
    2.13 -	0, 0, 0, 0x1,		/* 6: VTPM_ORD_OPEN */
    2.14 -	0,			/* 10: VTPM type */
    2.15 -	0, 0, 0, 0,		/* 11: domain id */
    2.16 -	0, 0, 0, 0		/* 15: instance id */
    2.17 -};
    2.18 -
    2.19 -int tpmif_vtpm_open(tpmif_t * tpmif, domid_t domid, u32 instance)
    2.20 -{
    2.21 -	int rc = 0;
    2.22 -	struct packet *pak;
    2.23 -
    2.24 -	pak = packet_alloc(tpmif,
    2.25 -			   sizeof (create_cmd),
    2.26 -			   create_cmd[1],
    2.27 -			   PACKET_FLAG_DISCARD_RESPONSE |
    2.28 -			   PACKET_FLAG_CHECK_RESPONSESTATUS);
    2.29 -	if (pak) {
    2.30 -		u8 buf[sizeof (create_cmd)];
    2.31 -		u32 domid_no = htonl((u32) domid);
    2.32 -		u32 instance_no = htonl(instance);
    2.33 -
    2.34 -		memcpy(buf, create_cmd, sizeof (create_cmd));
    2.35 -
    2.36 -		memcpy(&buf[11], &domid_no, sizeof (u32));
    2.37 -		memcpy(&buf[15], &instance_no, sizeof (u32));
    2.38 -
    2.39 -		/* copy the buffer into the packet */
    2.40 -		rc = packet_set(pak, buf, sizeof (buf));
    2.41 -
    2.42 -		if (rc == 0) {
    2.43 -			pak->tpm_instance = 0;
    2.44 -			rc = vtpm_queue_packet(pak);
    2.45 -		}
    2.46 -		if (rc < 0) {
    2.47 -			/* could not be queued or built */
    2.48 -			packet_free(pak);
    2.49 -		}
    2.50 -	} else {
    2.51 -		rc = -ENOMEM;
    2.52 -	}
    2.53 -	return rc;
    2.54 -}
    2.55 -
    2.56 -static u8 destroy_cmd[] = {
    2.57 -	1, 193,			/* 0: TPM_TAG_RQU_COMMAMD */
    2.58 -	0, 0, 0, 14,		/* 2: length */
    2.59 -	0, 0, 0, 0x2,		/* 6: VTPM_ORD_CLOSE */
    2.60 -	0, 0, 0, 0		/* 10: instance id */
    2.61 -};
    2.62 -
    2.63 -int tpmif_vtpm_close(u32 instid)
    2.64 -{
    2.65 -	int rc = 0;
    2.66 -	struct packet *pak;
    2.67 -
    2.68 -	pak = packet_alloc(NULL,
    2.69 -			   sizeof (destroy_cmd),
    2.70 -			   destroy_cmd[1], PACKET_FLAG_DISCARD_RESPONSE);
    2.71 -	if (pak) {
    2.72 -		u8 buf[sizeof (destroy_cmd)];
    2.73 -		u32 instid_no = htonl(instid);
    2.74 -
    2.75 -		memcpy(buf, destroy_cmd, sizeof (destroy_cmd));
    2.76 -		memcpy(&buf[10], &instid_no, sizeof (u32));
    2.77 -
    2.78 -		/* copy the buffer into the packet */
    2.79 -		rc = packet_set(pak, buf, sizeof (buf));
    2.80 -
    2.81 -		if (rc == 0) {
    2.82 -			pak->tpm_instance = 0;
    2.83 -			rc = vtpm_queue_packet(pak);
    2.84 -		}
    2.85 -		if (rc < 0) {
    2.86 -			/* could not be queued or built */
    2.87 -			packet_free(pak);
    2.88 -		}
    2.89 -	} else {
    2.90 -		rc = -ENOMEM;
    2.91 -	}
    2.92 -	return rc;
    2.93 -}
    2.94 -
    2.95 -/***************************************************************
    2.96   Utility functions
    2.97  ***************************************************************/
    2.98  
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c	Tue Jun 27 11:14:19 2006 +0100
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c	Tue Jun 27 11:15:48 2006 +0100
     3.3 @@ -154,11 +154,6 @@ static void frontend_changed(struct xenb
     3.4  		break;
     3.5  
     3.6  	case XenbusStateClosed:
     3.7 -		/*
     3.8 -		 * Notify the vTPM manager about the front-end
     3.9 -		 * having left.
    3.10 -		 */
    3.11 -		tpmif_vtpm_close(be->instance);
    3.12  		device_unregister(&be->dev->dev);
    3.13  		tpmback_remove(dev);
    3.14  		break;
    3.15 @@ -177,28 +172,10 @@ static void frontend_changed(struct xenb
    3.16  
    3.17  static void maybe_connect(struct backend_info *be)
    3.18  {
    3.19 -	int err;
    3.20 -
    3.21  	if (be->tpmif == NULL || be->tpmif->status == CONNECTED)
    3.22  		return;
    3.23  
    3.24  	connect(be);
    3.25 -
    3.26 -	/*
    3.27 -	 * Notify the vTPM manager about a new front-end.
    3.28 -	 */
    3.29 -	err = tpmif_vtpm_open(be->tpmif,
    3.30 -			      be->frontend_id,
    3.31 -			      be->instance);
    3.32 -	if (err) {
    3.33 -		xenbus_dev_error(be->dev, err,
    3.34 -				 "queueing vtpm open packet");
    3.35 -		/*
    3.36 -		 * Should close down this device and notify FE
    3.37 -		 * about closure.
    3.38 -		 */
    3.39 -		return;
    3.40 -	}
    3.41  }
    3.42  
    3.43  
     4.1 --- a/tools/examples/Makefile	Tue Jun 27 11:14:19 2006 +0100
     4.2 +++ b/tools/examples/Makefile	Tue Jun 27 11:15:48 2006 +0100
     4.3 @@ -32,7 +32,7 @@ XEN_SCRIPTS += external-device-migrate
     4.4  XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh
     4.5  XEN_SCRIPT_DATA += xen-hotplug-common.sh xen-network-common.sh vif-common.sh
     4.6  XEN_SCRIPT_DATA += block-common.sh vtpm-common.sh vtpm-hotplug-common.sh
     4.7 -XEN_SCRIPT_DATA += vtpm-migration.sh
     4.8 +XEN_SCRIPT_DATA += vtpm-migration.sh vtpm-impl
     4.9  
    4.10  XEN_HOTPLUG_DIR = /etc/hotplug
    4.11  XEN_HOTPLUG_SCRIPTS = xen-backend.agent
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/examples/vtpm-impl	Tue Jun 27 11:15:48 2006 +0100
     5.3 @@ -0,0 +1,136 @@
     5.4 +#!/bin/bash
     5.5 +# ===================================================================
     5.6 +# 
     5.7 +# Copyright (c) 2005, Intel Corp.
     5.8 +# All rights reserved.
     5.9 +#
    5.10 +# Redistribution and use in source and binary forms, with or without 
    5.11 +# modification, are permitted provided that the following conditions 
    5.12 +# are met:
    5.13 +#
    5.14 +#   * Redistributions of source code must retain the above copyright 
    5.15 +#     notice, this list of conditions and the following disclaimer.
    5.16 +#   * Redistributions in binary form must reproduce the above 
    5.17 +#     copyright notice, this list of conditions and the following 
    5.18 +#     disclaimer in the documentation and/or other materials provided 
    5.19 +#     with the distribution.
    5.20 +#   * Neither the name of Intel Corporation nor the names of its 
    5.21 +#     contributors may be used to endorse or promote products derived
    5.22 +#     from this software without specific prior written permission.
    5.23 +#
    5.24 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    5.25 +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    5.26 +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
    5.27 +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
    5.28 +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
    5.29 +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    5.30 +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
    5.31 +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    5.32 +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
    5.33 +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
    5.34 +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
    5.35 +# OF THE POSSIBILITY OF SUCH DAMAGE.
    5.36 +# ===================================================================
    5.37 +
    5.38 +VTPM_IMPL_DEFINED=1
    5.39 +
    5.40 +#            |        SRC        |    TAG  |      CMD SIZE     |        ORD       | type| mode
    5.41 +TPM_CMD_OPEN=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x10\\x01\\x00\\x00\\x01\\x01\\x01
    5.42 +TPM_CMD_RESM=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x10\\x01\\x00\\x00\\x01\\x01\\x02
    5.43 +TPM_CMD_CLOS=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x0e\\x01\\x00\\x00\\x02
    5.44 +TPM_CMD_DELE=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x0e\\x01\\x00\\x00\\x03
    5.45 +
    5.46 +TPM_SUCCESS=00000000
    5.47 +
    5.48 +TX_VTPM_MANAGER=/var/vtpm/fifos/from_console.fifo
    5.49 +RX_VTPM_MANAGER=/var/vtpm/fifos/to_console.fifo
    5.50 +
    5.51 +# -------------------- Helpers for binary streams -----------
    5.52 +
    5.53 +function str_to_hex32() {
    5.54 + printf "%0.8x" $1
    5.55 +}
    5.56 +
    5.57 +function hex32_to_bin() {
    5.58 + local inst=$(str_to_hex32 $1);
    5.59 + 
    5.60 + local n1=`echo $inst | sed 's/\(..\)....../\\\\x\1/'`
    5.61 + local n2=`echo $inst | sed 's/..\(..\)..../\\\\x\1/'`
    5.62 + local n3=`echo $inst | sed 's/....\(..\)../\\\\x\1/'`
    5.63 + local n4=`echo $inst | sed 's/......\(..\)/\\\\x\1/'`
    5.64 +
    5.65 + echo "$n1$n2$n3$n4"
    5.66 +}
    5.67 +
    5.68 +function vtpm_manager_cmd() {
    5.69 + local cmd=$1;
    5.70 + local inst=$2;
    5.71 + local inst_bin=$(hex32_to_bin $inst);
    5.72 +
    5.73 + #send cmd to vtpm_manager
    5.74 + printf "$cmd$inst_bin" > $TX_VTPM_MANAGER
    5.75 +
    5.76 + #recv response
    5.77 + local resp_hex=`dd skip=10 bs=1 count=4 if=$RX_VTPM_MANAGER 2> /dev/null | xxd -ps`
    5.78 +
    5.79 + #return whether the command was successful
    5.80 + if [ $resp_hex != $TPM_SUCCESS ]; then
    5.81 +   vtpm_fatal_error=1
    5.82 +   false
    5.83 +  else
    5.84 +   true
    5.85 + fi
    5.86 +}
    5.87 +
    5.88 +# ------------------ Command handlers -----------------
    5.89 +
    5.90 +# Create new vtpm instance & set it up for use
    5.91 +function vtpm_create () {
    5.92 + # Creation is handled implicitly by the manager on first setup
    5.93 + # so just set it up for use
    5.94 + $(vtpm_start $1)
    5.95 +}
    5.96 +
    5.97 +# Setup vtpm instance for use.
    5.98 +function vtpm_start() {
    5.99 + $(vtpm_manager_cmd $TPM_CMD_OPEN $1)
   5.100 +}
   5.101 +
   5.102 +function vtpm_resume() {
   5.103 + $(vtpm_manager_cmd $TPM_CMD_RESM $1)
   5.104 +}
   5.105 +
   5.106 +# Reset the vtpm AKA clear PCRs
   5.107 +function vtpm_reset() {
   5.108 + #not used by current implemenation
   5.109 + true
   5.110 +}
   5.111 +
   5.112 +# Shutdown the vtpm while the vm is down
   5.113 +# This could be a suspend of shutdown
   5.114 +# we cannot distinquish, so save the state
   5.115 +# and decide on startup if we should keep is
   5.116 +function vtpm_suspend() {
   5.117 + $(vtpm_manager_cmd $TPM_CMD_CLOS $1)
   5.118 +}
   5.119 +
   5.120 +
   5.121 +function vtpm_delete() {
   5.122 + local inst=$1
   5.123 + if $(vtpm_manager_cmd $TPM_CMD_DELE $inst); then
   5.124 +   rm -f /var/vtpm/vtpm_dm_$1.data
   5.125 +   true
   5.126 + else 
   5.127 +   vtpm_fatal_error=1
   5.128 +   false
   5.129 + fi
   5.130 +}
   5.131 +
   5.132 +function vtpm_migrate() {
   5.133 + echo "Error: vTPM migration accross machines not implemented."
   5.134 +}
   5.135 +
   5.136 +function vtpm_migrate_recover() {
   5.137 + true
   5.138 +}
   5.139 +
     6.1 --- a/tools/vtpm_manager/manager/dmictl.c	Tue Jun 27 11:14:19 2006 +0100
     6.2 +++ b/tools/vtpm_manager/manager/dmictl.c	Tue Jun 27 11:15:48 2006 +0100
     6.3 @@ -76,14 +76,13 @@ TPM_RESULT VTPM_Handle_New_DMI(const buf
     6.4    
     6.5    VTPM_DMI_RESOURCE *new_dmi=NULL;
     6.6    TPM_RESULT status=TPM_FAIL;
     6.7 -  BYTE type;
     6.8 -  UINT32 dmi_id, domain_id, *dmi_id_key; 
     6.9 +  BYTE type, startup_mode;
    6.10 +  UINT32 dmi_id, *dmi_id_key=NULL; 
    6.11  
    6.12    if (param_buf == NULL) { // Assume creation of Dom 0 control
    6.13 -    type = 0;
    6.14 -    domain_id = VTPM_CTL_DM;
    6.15 +    type = VTPM_TYPE_NON_MIGRATABLE;
    6.16      dmi_id = VTPM_CTL_DM;
    6.17 -  } else if (buffer_len(param_buf) != sizeof(BYTE) + sizeof(UINT32) *2) {
    6.18 +  } else if (buffer_len(param_buf) != sizeof(BYTE) + sizeof(BYTE) + sizeof(UINT32)) {
    6.19      vtpmloginfo(VTPM_LOG_VTPM, "New DMI command wrong length: %d.\n", buffer_len(param_buf));
    6.20      status = TPM_BAD_PARAMETER;
    6.21      goto abort_egress;
    6.22 @@ -91,13 +90,13 @@ TPM_RESULT VTPM_Handle_New_DMI(const buf
    6.23      vtpm_globals->connected_dmis++; // Put this here so we don't count Dom0
    6.24      BSG_UnpackList( param_buf->bytes, 3,
    6.25  		    BSG_TYPE_BYTE, &type,
    6.26 -		    BSG_TYPE_UINT32, &domain_id,
    6.27 +		    BSG_TYPE_BYTE, &startup_mode,
    6.28  		    BSG_TYPE_UINT32,  &dmi_id);
    6.29    }
    6.30 -  
    6.31 +
    6.32    new_dmi = (VTPM_DMI_RESOURCE *) hashtable_search(vtpm_globals->dmi_map, &dmi_id);
    6.33    if (new_dmi == NULL) { 
    6.34 -    vtpmloginfo(VTPM_LOG_VTPM, "Creating new DMI instance %d attached on domain %d.\n", dmi_id, domain_id);
    6.35 +    vtpmloginfo(VTPM_LOG_VTPM, "Creating new DMI instance %d attached.\n", dmi_id );
    6.36      // Brand New DMI. Initialize the persistent pieces
    6.37      if ((new_dmi = (VTPM_DMI_RESOURCE *) malloc (sizeof(VTPM_DMI_RESOURCE))) == NULL) {
    6.38        status = TPM_RESOURCES;
    6.39 @@ -106,32 +105,44 @@ TPM_RESULT VTPM_Handle_New_DMI(const buf
    6.40      memset(new_dmi, 0, sizeof(VTPM_DMI_RESOURCE));
    6.41      new_dmi->dmi_id = dmi_id;
    6.42      new_dmi->connected = FALSE;
    6.43 +
    6.44 +    if (type != VTPM_TYPE_MIGRATED) {
    6.45 +      new_dmi->dmi_type = type;
    6.46 +    } else {
    6.47 +      vtpmlogerror(VTPM_LOG_VTPM, "Creation of VTPM with illegal type.\n");
    6.48 +      status = TPM_BAD_PARAMETER;
    6.49 +      goto free_egress;
    6.50 +    }
    6.51      
    6.52      if ((dmi_id_key = (UINT32 *) malloc (sizeof(UINT32))) == NULL) {
    6.53        status = TPM_RESOURCES;
    6.54 -      goto abort_egress;
    6.55 +      goto free_egress;
    6.56      }      
    6.57      *dmi_id_key = new_dmi->dmi_id;
    6.58      
    6.59      // install into map
    6.60      if (!hashtable_insert(vtpm_globals->dmi_map, dmi_id_key, new_dmi)){
    6.61 -      free(new_dmi);
    6.62 -      free(dmi_id_key);
    6.63 +      vtpmlogerror(VTPM_LOG_VTPM, "Failed to insert instance into table. Aborting.\n", dmi_id);
    6.64        status = TPM_FAIL;
    6.65 -      goto egress;
    6.66 +      goto free_egress;
    6.67      }
    6.68     
    6.69    } else 
    6.70 -    vtpmloginfo(VTPM_LOG_VTPM, "Re-attaching DMI instance %d on domain %d .\n", dmi_id, domain_id);
    6.71 +    vtpmloginfo(VTPM_LOG_VTPM, "Re-attaching DMI instance %d.\n", dmi_id);
    6.72    
    6.73    if (new_dmi->connected) {
    6.74      vtpmlogerror(VTPM_LOG_VTPM, "Attempt to re-attach, currently attached instance %d. Ignoring\n", dmi_id);
    6.75      status = TPM_BAD_PARAMETER;
    6.76 -    goto egress;
    6.77 +    goto abort_egress;
    6.78    }
    6.79    
    6.80 +  if (type == VTPM_TYPE_MIGRATED) {
    6.81 +    vtpmlogerror(VTPM_LOG_VTPM, "Attempt to re-attach previously migrated instance %d without recovering first. Ignoring\n", dmi_id);
    6.82 +    status = TPM_BAD_PARAMETER;
    6.83 +    goto abort_egress;
    6.84 +  }
    6.85 +
    6.86    // Initialize the Non-persistent pieces
    6.87 -  new_dmi->dmi_domain_id = domain_id;
    6.88    new_dmi->NVMLocation = NULL;
    6.89    
    6.90    new_dmi->TCSContext = 0;
    6.91 @@ -144,9 +155,13 @@ TPM_RESULT VTPM_Handle_New_DMI(const buf
    6.92  
    6.93    // Design specific new DMI code. 
    6.94    // Includes: create IPCs, Measuring DMI, and maybe launching DMI
    6.95 -  status = VTPM_New_DMI_Extra(new_dmi);
    6.96 +  status = VTPM_New_DMI_Extra(new_dmi, startup_mode);
    6.97    goto egress;
    6.98    
    6.99 + free_egress:   // Error that requires freeing of newly allocated dmi 
   6.100 +  free(new_dmi);
   6.101 +  free(dmi_id_key);
   6.102 +
   6.103   abort_egress:
   6.104    vtpmlogerror(VTPM_LOG_VTPM, "Failed to create DMI id=%d due to status=%s. Cleaning.\n", dmi_id, tpm_get_error_name(status));
   6.105    close_dmi(new_dmi );
   6.106 @@ -221,7 +236,7 @@ TPM_RESULT VTPM_Handle_Delete_DMI( const
   6.107      goto abort_egress;
   6.108    }
   6.109    
   6.110 -	//TODO: Automatically delete file dmi_res->NVMLocation
   6.111 +  //vtpm scripts delete file dmi_res->NVMLocation for us
   6.112    
   6.113    // Close DMI first
   6.114    TPMTRYRETURN(close_dmi( dmi_res ));
     7.1 --- a/tools/vtpm_manager/manager/securestorage.c	Tue Jun 27 11:14:19 2006 +0100
     7.2 +++ b/tools/vtpm_manager/manager/securestorage.c	Tue Jun 27 11:15:48 2006 +0100
     7.3 @@ -190,8 +190,7 @@ TPM_RESULT VTPM_Handle_Save_NVM(VTPM_DMI
     7.4    long bytes_written;
     7.5    buffer_t sealed_NVM;
     7.6    
     7.7 -  
     7.8 -  vtpmloginfo(VTPM_LOG_VTPM_DEEP, "Save_NVMing[%d]: 0x\n", buffer_len(inbuf));
     7.9 +  vtpmloginfo(VTPM_LOG_VTPM_DEEP, "Saving %d bytes of NVM.\n", buffer_len(inbuf));
    7.10  
    7.11    TPMTRYRETURN( envelope_encrypt(inbuf,
    7.12                                   &vtpm_globals->storageKey,
    7.13 @@ -310,6 +309,7 @@ TPM_RESULT VTPM_SaveManagerData(void) {
    7.14    UINT32 bootKeySize = buffer_len(&vtpm_globals->bootKeyWrap);
    7.15    struct pack_buf_t storage_key_pack = {storageKeySize, vtpm_globals->storageKeyWrap.bytes};
    7.16    struct pack_buf_t boot_key_pack = {bootKeySize, vtpm_globals->bootKeyWrap.bytes};
    7.17 +  BYTE vtpm_manager_gen = VTPM_MANAGER_GEN;
    7.18  
    7.19    struct hashtable_itr *dmi_itr;
    7.20    VTPM_DMI_RESOURCE *dmi_res;
    7.21 @@ -321,7 +321,8 @@ TPM_RESULT VTPM_SaveManagerData(void) {
    7.22    boot_key_size =  sizeof(UINT32) +       // bootkeysize
    7.23                     bootKeySize;           // boot key
    7.24  
    7.25 -  TPMTRYRETURN(buffer_init(&clear_flat_global, 3*sizeof(TPM_DIGEST) + // Auths
    7.26 +  TPMTRYRETURN(buffer_init(&clear_flat_global,sizeof(BYTE) + // manager version
    7.27 +                                              3*sizeof(TPM_DIGEST) + // Auths
    7.28                                                sizeof(UINT32) +// storagekeysize
    7.29                                                storageKeySize, NULL) ); // storage key
    7.30  
    7.31 @@ -332,7 +333,8 @@ TPM_RESULT VTPM_SaveManagerData(void) {
    7.32    boot_key_size = BSG_PackList(flat_boot_key, 1,
    7.33                                 BSG_TPM_SIZE32_DATA, &boot_key_pack);
    7.34  
    7.35 -  BSG_PackList(clear_flat_global.bytes, 3,
    7.36 +  BSG_PackList(clear_flat_global.bytes, 4,
    7.37 +                BSG_TYPE_BYTE,    &vtpm_manager_gen,
    7.38                  BSG_TPM_AUTHDATA, &vtpm_globals->owner_usage_auth,
    7.39                  BSG_TPM_SECRET,   &vtpm_globals->storage_key_usage_auth,
    7.40                  BSG_TPM_SIZE32_DATA, &storage_key_pack);
    7.41 @@ -348,7 +350,7 @@ TPM_RESULT VTPM_SaveManagerData(void) {
    7.42  
    7.43      flat_dmis = (BYTE *) malloc( 
    7.44                       (hashtable_count(vtpm_globals->dmi_map) - 1) * // num DMIS (-1 for Dom0)
    7.45 -                     (sizeof(UINT32) + 2*sizeof(TPM_DIGEST)) ); // Per DMI info
    7.46 +                     (sizeof(UINT32) +sizeof(BYTE) + 2*sizeof(TPM_DIGEST)) ); // Per DMI info
    7.47  
    7.48      dmi_itr = hashtable_iterator(vtpm_globals->dmi_map);
    7.49      do {
    7.50 @@ -360,8 +362,9 @@ TPM_RESULT VTPM_SaveManagerData(void) {
    7.51          continue;
    7.52  
    7.53  
    7.54 -      flat_dmis_size += BSG_PackList( flat_dmis + flat_dmis_size, 3,
    7.55 +      flat_dmis_size += BSG_PackList( flat_dmis + flat_dmis_size, 4,
    7.56                                          BSG_TYPE_UINT32, &dmi_res->dmi_id,
    7.57 +                                        BSG_TYPE_BYTE, &dmi_res->dmi_type,
    7.58                                          BSG_TPM_DIGEST, &dmi_res->NVM_measurement,
    7.59                                          BSG_TPM_DIGEST, &dmi_res->DMI_measurement);
    7.60  
    7.61 @@ -408,6 +411,7 @@ TPM_RESULT VTPM_LoadManagerData(void) {
    7.62    buffer_t  unsealed_data;
    7.63    struct pack_buf_t storage_key_pack, boot_key_pack;
    7.64    UINT32 *dmi_id_key, enc_size;
    7.65 +  BYTE vtpm_manager_gen;
    7.66  
    7.67    VTPM_DMI_RESOURCE *dmi_res;
    7.68    struct stat file_stat;
    7.69 @@ -458,8 +462,14 @@ TPM_RESULT VTPM_LoadManagerData(void) {
    7.70                                   &unsealed_data) );
    7.71    step_size += enc_size;
    7.72  
    7.73 +  if (*unsealed_data.bytes != VTPM_MANAGER_GEN) {
    7.74 +      // Once there is more than one gen, this will include some compatability stuff
    7.75 +      vtpmlogerror(VTPM_LOG_VTPM, "Warning: Manager Data file is gen %d, which this manager is gen %d.\n", vtpm_manager_gen, VTPM_MANAGER_GEN);
    7.76 +  }
    7.77 +
    7.78    // Global Values needing to be saved
    7.79 -  BSG_UnpackList( unsealed_data.bytes, 3,
    7.80 +  BSG_UnpackList( unsealed_data.bytes, 4,
    7.81 +                  BSG_TYPE_BYTE,    &vtpm_manager_gen, 
    7.82                    BSG_TPM_AUTHDATA, &vtpm_globals->owner_usage_auth,
    7.83                    BSG_TPM_SECRET,   &vtpm_globals->storage_key_usage_auth,
    7.84                    BSG_TPM_SIZE32_DATA, &storage_key_pack);
    7.85 @@ -469,7 +479,7 @@ TPM_RESULT VTPM_LoadManagerData(void) {
    7.86  
    7.87    // Per DMI values to be saved
    7.88    while ( step_size < fh_size ){
    7.89 -    if (fh_size - step_size < (long) (sizeof(UINT32) + 2*sizeof(TPM_DIGEST))) {
    7.90 +    if (fh_size - step_size < (long) (sizeof(UINT32) + sizeof(BYTE) + 2*sizeof(TPM_DIGEST))) {
    7.91        vtpmlogerror(VTPM_LOG_VTPM, "Encountered %ld extra bytes at end of manager state.\n", fh_size-step_size);
    7.92        step_size = fh_size;
    7.93      } else {
    7.94 @@ -478,8 +488,9 @@ TPM_RESULT VTPM_LoadManagerData(void) {
    7.95  
    7.96        dmi_res->connected = FALSE;
    7.97  
    7.98 -      step_size += BSG_UnpackList(flat_table + step_size, 3,
    7.99 +      step_size += BSG_UnpackList(flat_table + step_size, 4,
   7.100                                   BSG_TYPE_UINT32, &dmi_res->dmi_id,
   7.101 +                                 BSG_TYPE_BYTE, &dmi_res->dmi_type,
   7.102                                   BSG_TPM_DIGEST, &dmi_res->NVM_measurement,
   7.103                                   BSG_TPM_DIGEST, &dmi_res->DMI_measurement);
   7.104  
     8.1 --- a/tools/vtpm_manager/manager/vtpm_manager.c	Tue Jun 27 11:14:19 2006 +0100
     8.2 +++ b/tools/vtpm_manager/manager/vtpm_manager.c	Tue Jun 27 11:15:48 2006 +0100
     8.3 @@ -168,6 +168,7 @@ TPM_RESULT VTPM_Create_Manager(){
     8.4                                &vtpm_globals->bootKey,
     8.5                                TRUE ) );
     8.6  
     8.7 +  TPMTRYRETURN( VTSP_SaveState(vtpm_globals->manager_tcs_handle) );
     8.8    goto egress;
     8.9    
    8.10   abort_egress:
    8.11 @@ -218,7 +219,7 @@ TPM_RESULT VTPM_Init_Manager() {
    8.12  			   &vtpm_globals->keyAuth) );
    8.13    vtpm_globals->keyAuth.fContinueAuthSession = TRUE;
    8.14  
    8.15 -	// If failed, create new Manager.
    8.16 +  // If failed, create new Manager.
    8.17    serviceStatus = VTPM_LoadManagerData();
    8.18    if (serviceStatus == TPM_IOERROR) {
    8.19      vtpmloginfo(VTPM_LOG_VTPM, "Failed to read manager file. Assuming first time initialization.\n");
     9.1 --- a/tools/vtpm_manager/manager/vtpm_manager.h	Tue Jun 27 11:14:19 2006 +0100
     9.2 +++ b/tools/vtpm_manager/manager/vtpm_manager.h	Tue Jun 27 11:15:48 2006 +0100
     9.3 @@ -73,6 +73,12 @@
     9.4  #define VTPM_RESTORE_CONTEXT_FAILED    4
     9.5  #define VTPM_INVALID_REQUEST       5
     9.6  
     9.7 +//*********************** Parameter Values *************************
     9.8 +#define VTPM_TYPE_NON_MIGRATABLE  0x00
     9.9 +#define VTPM_TYPE_MIGRATABLE      0x01
    9.10 +#define VTPM_TYPE_MIGRATED        0xFF // VTPM has been migrated.
    9.11 +                                       // VTPM can be recovered or deleted only
    9.12 +
    9.13  /******************* Command Parameter API *************************
    9.14  
    9.15  VTPM Command Format
    9.16 @@ -94,8 +100,8 @@ VTPM Response Format
    9.17  
    9.18  VTPM_Open:
    9.19    Input Parameters:
    9.20 -    Domain_type: 1 byte
    9.21 -    domain_id: 4 bytes
    9.22 +    Domain_type: 1 byte 
    9.23 +    startup_mode: 1 byte // Cold Boot = 1, resume = 2, deactive = 3
    9.24      instance_id: 4 bytes
    9.25    Output Parameters:
    9.26      None
    10.1 --- a/tools/vtpm_manager/manager/vtpm_manager_handler.c	Tue Jun 27 11:14:19 2006 +0100
    10.2 +++ b/tools/vtpm_manager/manager/vtpm_manager_handler.c	Tue Jun 27 11:15:48 2006 +0100
    10.3 @@ -78,13 +78,14 @@ TPM_RESULT VTPM_Manager_Handler( vtpm_ip
    10.4                                   BOOL is_priv,
    10.5                                   char *thread_name) {
    10.6    TPM_RESULT      status =  TPM_FAIL; // Should never return
    10.7 -  UINT32          dmi, in_param_size, cmd_size, out_param_size, out_message_size, out_message_size_full;
    10.8 -  BYTE            *cmd_header, *in_param, *out_message;
    10.9 +  UINT32          dmi, in_param_size, cmd_size, out_param_size, out_message_size, reply_size;
   10.10 +  BYTE            *cmd_header=NULL, *in_param=NULL, *out_message=NULL, *reply;
   10.11    buffer_t        *command_buf=NULL, *result_buf=NULL;
   10.12    TPM_TAG         tag;
   10.13    TPM_COMMAND_CODE ord;
   10.14    VTPM_DMI_RESOURCE *dmi_res;
   10.15    int  size_read, size_write, i;
   10.16 +  BOOL add_header=TRUE; // This indicates to prepend a header on result_buf before sending
   10.17    
   10.18    cmd_header = (BYTE *) malloc(VTPM_COMMAND_HEADER_SIZE_SRV);
   10.19    command_buf = (buffer_t *) malloc(sizeof(buffer_t));
   10.20 @@ -100,7 +101,7 @@ TPM_RESULT VTPM_Manager_Handler( vtpm_ip
   10.21      // Read command header 
   10.22      size_read = vtpm_ipc_read(rx_ipc_h, NULL, cmd_header, VTPM_COMMAND_HEADER_SIZE_SRV);
   10.23      if (size_read > 0) {
   10.24 -      vtpmhandlerloginfo(VTPM_LOG_VTPM_DEEP, "RECV[%d}: 0x", size_read);
   10.25 +      vtpmhandlerloginfo(VTPM_LOG_VTPM_DEEP, "RECV[%d]: 0x", size_read);
   10.26        for (i=0; i<size_read; i++) 
   10.27  	vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "%x ", cmd_header[i]);
   10.28      } else {
   10.29 @@ -165,6 +166,7 @@ TPM_RESULT VTPM_Manager_Handler( vtpm_ip
   10.30           (!dmi_res->connected) ) {
   10.31        vtpmhandlerlogerror(VTPM_LOG_VTPM, "Attempted access to non-existent or disconnected DMI %d. Aborting...\n", dmi);
   10.32        status = TPM_BAD_PARAMETER;
   10.33 +      goto abort_with_error;
   10.34      }
   10.35  
   10.36      if (tag == VTPM_TAG_REQ) { 
   10.37 @@ -176,9 +178,14 @@ TPM_RESULT VTPM_Manager_Handler( vtpm_ip
   10.38          status = vtpm_manager_handle_tpm_cmd(fw_tx_ipc_h, fw_rx_ipc_h, dmi_res, cmd_header, command_buf, result_buf, thread_name);
   10.39  
   10.40          // This means calling the DMI failed, not that the cmd failed in the DMI
   10.41 +        // Since the return will be interpretted by a TPM app, all errors are IO_ERRORs to the app
   10.42          if (status != TPM_SUCCESS) { 
   10.43 +          status = TPM_IOERROR;
   10.44  	  goto abort_with_error;
   10.45          }
   10.46 +        // Unlike all other commands, forwarded commands yield a result_buf that includes the DMI's status. This
   10.47 +        // should be forwarded to the caller VM
   10.48 +        add_header = FALSE;
   10.49        } else {
   10.50          // We are not supposed to forward TPM commands at all.
   10.51          int i;
   10.52 @@ -205,38 +212,43 @@ TPM_RESULT VTPM_Manager_Handler( vtpm_ip
   10.53  #ifndef VTPM_MULTI_VM
   10.54   abort_with_error:
   10.55  #endif
   10.56 -    
   10.57 -    // Prepend VTPM header with destination DM stamped
   10.58 -    out_param_size = buffer_len(result_buf);
   10.59 -    out_message_size = VTPM_COMMAND_HEADER_SIZE_CLT + out_param_size;
   10.60 -    out_message_size_full = VTPM_COMMAND_HEADER_SIZE_SRV + out_param_size;
   10.61 -    out_message = (BYTE *) malloc (out_message_size_full);
   10.62 +   
   10.63 +    if (add_header) { 
   10.64 +      // Prepend VTPM header with destination DM stamped
   10.65 +      out_param_size = buffer_len(result_buf);
   10.66 +      out_message_size = VTPM_COMMAND_HEADER_SIZE_CLT + out_param_size;
   10.67 +      reply_size = VTPM_COMMAND_HEADER_SIZE_SRV + out_param_size;
   10.68 +      out_message = (BYTE *) malloc (reply_size);
   10.69 +      reply = out_message;
   10.70      
   10.71 -    BSG_PackList(out_message, 4,
   10.72 -		 BSG_TYPE_UINT32, (BYTE *) &dmi,
   10.73 -		 BSG_TPM_TAG, (BYTE *) &tag,
   10.74 -		 BSG_TYPE_UINT32, (BYTE *) &out_message_size,
   10.75 -		 BSG_TPM_RESULT, (BYTE *) &status);
   10.76 +      BSG_PackList(out_message, 4,
   10.77 +		   BSG_TYPE_UINT32, (BYTE *) &dmi,
   10.78 +		   BSG_TPM_TAG, (BYTE *) &tag,
   10.79 +		   BSG_TYPE_UINT32, (BYTE *) &out_message_size,
   10.80 +		   BSG_TPM_RESULT, (BYTE *) &status);
   10.81      
   10.82 -    if (buffer_len(result_buf) > 0) 
   10.83 -      memcpy(out_message + VTPM_COMMAND_HEADER_SIZE_SRV, result_buf->bytes, out_param_size);
   10.84 -
   10.85 -    //Note: Send message + dmi_id
   10.86 -    size_write = vtpm_ipc_write(tx_ipc_h, dmi_res->tx_vtpm_ipc_h, out_message, out_message_size_full );
   10.87 +      if (buffer_len(result_buf) > 0) 
   10.88 +        memcpy(out_message + VTPM_COMMAND_HEADER_SIZE_SRV, result_buf->bytes, out_param_size);
   10.89 +      //Note: Send message + dmi_id
   10.90 +    } else {
   10.91 +      reply = result_buf->bytes;
   10.92 +      reply_size = buffer_len(result_buf);
   10.93 +    }  
   10.94 +    size_write = vtpm_ipc_write(tx_ipc_h, (dmi_res ? dmi_res->tx_vtpm_ipc_h : NULL), reply, reply_size );
   10.95      if (size_write > 0) {
   10.96        vtpmhandlerloginfo(VTPM_LOG_VTPM_DEEP, "SENT: 0x");
   10.97 -      for (i=0; i < out_message_size_full; i++) 
   10.98 -	vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "%x ", out_message[i]);
   10.99 +      for (i=0; i < reply_size; i++) 
  10.100 +	vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "%x ", reply[i]);
  10.101        
  10.102        vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "\n");            
  10.103      } else {
  10.104        vtpmhandlerlogerror(VTPM_LOG_VTPM, "%s had error writing to ipc. Aborting... \n", thread_name);
  10.105        goto abort_command;
  10.106      }
  10.107 -    free(out_message);
  10.108 +    free(out_message); out_message=NULL;
  10.109      
  10.110 -    if (size_write < (int)out_message_size_full) {
  10.111 -      vtpmhandlerlogerror(VTPM_LOG_VTPM, "%s unable to write full command to ipc (%d/%d)\n", thread_name, size_write, out_message_size_full);
  10.112 +    if (size_write < (int)reply_size) {
  10.113 +      vtpmhandlerlogerror(VTPM_LOG_VTPM, "%s unable to write full command to ipc (%d/%d)\n", thread_name, size_write, reply_size);
  10.114        goto abort_command;
  10.115      }
  10.116      
  10.117 @@ -246,9 +258,7 @@ TPM_RESULT VTPM_Manager_Handler( vtpm_ip
  10.118      //free buffers
  10.119      bzero(cmd_header, VTPM_COMMAND_HEADER_SIZE_SRV);
  10.120      //free(in_param); // This was converted to command_buf. No need to free 
  10.121 -    if (command_buf != result_buf) 
  10.122 -      buffer_free(result_buf);
  10.123 -    
  10.124 +    buffer_free(result_buf);
  10.125      buffer_free(command_buf);
  10.126  
  10.127      // If we have a write lock, save the manager table
  10.128 @@ -258,6 +268,7 @@ TPM_RESULT VTPM_Manager_Handler( vtpm_ip
  10.129      }
  10.130  
  10.131      vtpm_lock_unlock();
  10.132 +    add_header = TRUE; // Reset to the default
  10.133    } // End while(1)
  10.134    
  10.135  }
  10.136 @@ -369,6 +380,7 @@ TPM_RESULT vtpm_manager_handle_tpm_cmd(v
  10.137      dmi_cmd_size = VTPM_COMMAND_HEADER_SIZE_SRV;
  10.138      size_write = vtpm_ipc_write(tx_ipc_h, dmi_res->tx_tpm_ipc_h, cmd_header, VTPM_COMMAND_HEADER_SIZE_SRV );
  10.139      if (size_write > 0) {
  10.140 +      vtpmhandlerloginfo(VTPM_LOG_VTPM_DEEP, "SENT (DMI): 0x");
  10.141        for (i=0; i<VTPM_COMMAND_HEADER_SIZE_SRV; i++) 
  10.142          vtpmhandlerloginfomore(VTPM_LOG_VTPM_DEEP, "%x ", cmd_header[i]);
  10.143  
  10.144 @@ -438,7 +450,8 @@ TPM_RESULT vtpm_manager_handle_tpm_cmd(v
  10.145      vtpmhandlerloginfomore(VTPM_LOG_VTPM, "\n");
  10.146    }
  10.147     
  10.148 -  if (buffer_init_convert(result_buf, adj_param_size, in_param) != TPM_SUCCESS) {
  10.149 +  if ( (buffer_init(result_buf, VTPM_COMMAND_HEADER_SIZE_SRV, cmd_header) != TPM_SUCCESS) || 
  10.150 +       (buffer_append_raw(result_buf, adj_param_size, in_param) != TPM_SUCCESS) ) {
  10.151      vtpmhandlerlogerror(VTPM_LOG_VTPM, "Failed to setup buffers. Aborting...\n");
  10.152      status = TPM_FAIL;
  10.153      goto abort_with_error;
    11.1 --- a/tools/vtpm_manager/manager/vtpmd.c	Tue Jun 27 11:14:19 2006 +0100
    11.2 +++ b/tools/vtpm_manager/manager/vtpmd.c	Tue Jun 27 11:15:48 2006 +0100
    11.3 @@ -64,14 +64,6 @@
    11.4  #define VTPM_TX_HP_FNAME       "/var/vtpm/fifos/to_console.fifo"
    11.5  #define VTPM_RX_HP_FNAME       "/var/vtpm/fifos/from_console.fifo"
    11.6  
    11.7 -
    11.8 -#define GUEST_TX_FIFO "/var/vtpm/fifos/guest-to-%d.fifo"
    11.9 -#define GUEST_RX_FIFO "/var/vtpm/fifos/guest-from-all.fifo"
   11.10 -
   11.11 -#define VTPM_TX_FIFO  "/var/vtpm/fifos/vtpm-to-%d.fifo"
   11.12 -#define VTPM_RX_FIFO  "/var/vtpm/fifos/vtpm-from-all.fifo"
   11.13 -
   11.14 -
   11.15  struct vtpm_thread_params_s {
   11.16    vtpm_ipc_handle_t *tx_ipc_h;
   11.17    vtpm_ipc_handle_t *rx_ipc_h;
   11.18 @@ -113,7 +105,7 @@ void signal_handler(int reason) {
   11.19  
   11.20  struct sigaction ctl_c_handler;
   11.21  
   11.22 -TPM_RESULT VTPM_New_DMI_Extra(VTPM_DMI_RESOURCE *dmi_res) {
   11.23 +TPM_RESULT VTPM_New_DMI_Extra(VTPM_DMI_RESOURCE *dmi_res, BYTE startup_mode) {
   11.24  
   11.25    TPM_RESULT status = TPM_SUCCESS;
   11.26    int fh;
   11.27 @@ -150,14 +142,14 @@ TPM_RESULT VTPM_New_DMI_Extra(VTPM_DMI_R
   11.28  
   11.29      // Measure DMI
   11.30      // FIXME: This will measure DMI. Until then use a fixed DMI_Measurement value
   11.31 -    // Also, this mechanism is specific to 1 VM.
   11.32 +    // Also, this mechanism is specific to 1 VM architecture.
   11.33      /*
   11.34      fh = open(TPM_EMULATOR_PATH, O_RDONLY);
   11.35      stat_ret = fstat(fh, &file_stat);
   11.36      if (stat_ret == 0)
   11.37        dmi_size = file_stat.st_size;
   11.38      else {
   11.39 -      vtpmlogerror(VTPM_LOG_VTPM, "Could not open tpm_emulator!!\n");
   11.40 +      vtpmlogerror(VTPM_LOG_VTPM, "Could not open vtpmd!!\n");
   11.41        status = TPM_IOERROR;
   11.42        goto abort_egress;
   11.43      }
   11.44 @@ -179,10 +171,20 @@ TPM_RESULT VTPM_New_DMI_Extra(VTPM_DMI_R
   11.45        status = TPM_RESOURCES;
   11.46        goto abort_egress;
   11.47      } else if (pid == 0) {
   11.48 -      if ( stat(dmi_res->NVMLocation, &file_info) == -1)
   11.49 +      switch (startup_mode) {
   11.50 +      case TPM_ST_CLEAR:
   11.51          execl (TPM_EMULATOR_PATH, "vtmpd", "clear", dmi_id_str, NULL);
   11.52 -      else
   11.53 +        break;
   11.54 +      case TPM_ST_STATE:
   11.55          execl (TPM_EMULATOR_PATH, "vtpmd", "save", dmi_id_str, NULL);
   11.56 +        break;
   11.57 +      case TPM_ST_DEACTIVATED:
   11.58 +        execl (TPM_EMULATOR_PATH, "vtpmd", "deactivated", dmi_id_str, NULL);
   11.59 +        break;
   11.60 +      default:
   11.61 +        status = TPM_BAD_PARAMETER;
   11.62 +        goto abort_egress;
   11.63 +      }
   11.64  
   11.65        // Returning from these at all is an error.
   11.66        vtpmlogerror(VTPM_LOG_VTPM, "Could not exec to launch vtpm\n");
   11.67 @@ -309,7 +311,7 @@ int main(int argc, char **argv) {
   11.68    be_thread_params.fw_tpm = TRUE;
   11.69    be_thread_params.fw_tx_ipc_h = NULL;
   11.70    be_thread_params.fw_rx_ipc_h = &rx_tpm_ipc_h;
   11.71 -  be_thread_params.is_priv = TRUE;                   //FIXME: Change when HP is up
   11.72 +  be_thread_params.is_priv = FALSE;
   11.73    be_thread_params.thread_name = "Backend Listener";
   11.74  
   11.75    dmi_thread_params.tx_ipc_h = NULL;
   11.76 @@ -318,7 +320,7 @@ int main(int argc, char **argv) {
   11.77    dmi_thread_params.fw_tx_ipc_h = NULL;
   11.78    dmi_thread_params.fw_rx_ipc_h = NULL;
   11.79    dmi_thread_params.is_priv = FALSE; 
   11.80 -  dmi_thread_params.thread_name = "VTPM Listeners";
   11.81 +  dmi_thread_params.thread_name = "VTPM Listener";
   11.82  
   11.83    hp_thread_params.tx_ipc_h = &tx_hp_ipc_h;
   11.84    hp_thread_params.rx_ipc_h = &rx_hp_ipc_h;
   11.85 @@ -345,10 +347,10 @@ int main(int argc, char **argv) {
   11.86    }
   11.87  
   11.88   
   11.89 -//  if (pthread_create(&hp_thread, NULL, vtpm_manager_thread, &hp_thread_params) != 0) {
   11.90 -//    vtpmlogerror(VTPM_LOG_VTPM, "Failed to launch HP Thread.\n");
   11.91 -//    exit(-1);
   11.92 -//  }
   11.93 +  if (pthread_create(&hp_thread, NULL, vtpm_manager_thread, &hp_thread_params) != 0) {
   11.94 +    vtpmlogerror(VTPM_LOG_VTPM, "Failed to launch HP Thread.\n");
   11.95 +    exit(-1);
   11.96 +  }
   11.97   
   11.98    //Join the other threads until exit time.
   11.99    pthread_join(be_thread, NULL);
    12.1 --- a/tools/vtpm_manager/manager/vtpmpriv.h	Tue Jun 27 11:14:19 2006 +0100
    12.2 +++ b/tools/vtpm_manager/manager/vtpmpriv.h	Tue Jun 27 11:15:48 2006 +0100
    12.3 @@ -40,15 +40,19 @@
    12.4  #ifndef __VTPMPRIV_H__
    12.5  #define __VTPMPRIV_H__
    12.6  
    12.7 +#include "vtpm_manager.h"
    12.8  #include "tcg.h"
    12.9  #include "tcs.h"
   12.10  #include "buffer.h"
   12.11  #include "crypto.h"
   12.12  #include "vtpm_ipc.h"
   12.13  
   12.14 -#define STATE_FILE    "/var/vtpm/VTPM"
   12.15 -#define DMI_NVM_FILE  "/var/vtpm/vtpm_dm_%d.data"
   12.16 -#define VTPM_CTL_DM   0
   12.17 +#define VTPM_MANAGER_GEN   2     // This is incremented when the manager's table
   12.18 +                                 // is changed. It's used for backwards compatability
   12.19 +
   12.20 +#define STATE_FILE         "/var/vtpm/VTPM"
   12.21 +#define DMI_NVM_FILE       "/var/vtpm/vtpm_dm_%d.data"
   12.22 +#define VTPM_CTL_DM        0
   12.23  
   12.24  // ------------------------ Private Structures -----------------------
   12.25  typedef struct VTPM_DMI_RESOURCE_T {
   12.26 @@ -70,6 +74,7 @@ typedef struct VTPM_DMI_RESOURCE_T {
   12.27                                          // of NVM.
   12.28    // Persistent Information about DMI
   12.29    UINT32                dmi_id;
   12.30 +  BYTE                  dmi_type;
   12.31    TPM_DIGEST            NVM_measurement;  // Equal to the SHA1 of the blob
   12.32    TPM_DIGEST            DMI_measurement;  // Correct measurement of the owning DMI
   12.33  } VTPM_DMI_RESOURCE;
   12.34 @@ -138,7 +143,7 @@ TPM_RESULT VTPM_Handle_Delete_DMI(const 
   12.35  TPM_RESULT VTPM_SaveManagerData(void);
   12.36  TPM_RESULT VTPM_LoadManagerData(void);
   12.37  
   12.38 -TPM_RESULT VTPM_New_DMI_Extra(VTPM_DMI_RESOURCE *dmi_res);
   12.39 +TPM_RESULT VTPM_New_DMI_Extra(VTPM_DMI_RESOURCE *dmi_res, BYTE startup_mode);
   12.40  
   12.41  TPM_RESULT VTPM_Close_DMI_Extra(VTPM_DMI_RESOURCE *dmi_res);
   12.42  
    13.1 --- a/tools/vtpm_manager/manager/vtsp.c	Tue Jun 27 11:14:19 2006 +0100
    13.2 +++ b/tools/vtpm_manager/manager/vtsp.c	Tue Jun 27 11:15:48 2006 +0100
    13.3 @@ -971,6 +971,17 @@ TPM_RESULT VTSP_Unseal(const TCS_CONTEXT
    13.4    return status;
    13.5  }
    13.6  
    13.7 +TPM_RESULT VTSP_SaveState( const TCS_CONTEXT_HANDLE    hContext) {
    13.8 +
    13.9 +  vtpmloginfo(VTPM_LOG_VTSP, "Calling TPM_SaveState.\n");
   13.10 +
   13.11 +  TPM_RESULT status = TPM_SUCCESS;
   13.12 +
   13.13 +  // Call TCS
   13.14 +  return ( TCSP_SaveState ( hContext ) );
   13.15 +
   13.16 +}
   13.17 +
   13.18  
   13.19  // Function Reaches into unsupported TCS command, beware.
   13.20  TPM_RESULT VTSP_RawTransmit(const TCS_CONTEXT_HANDLE    hContext,
    14.1 --- a/tools/vtpm_manager/manager/vtsp.h	Tue Jun 27 11:14:19 2006 +0100
    14.2 +++ b/tools/vtpm_manager/manager/vtsp.h	Tue Jun 27 11:15:48 2006 +0100
    14.3 @@ -118,4 +118,6 @@ TPM_RESULT VTSP_Unseal(const TCS_CONTEXT
    14.4                         TCS_AUTH                    *auth,
    14.5                         TCS_AUTH                    *dataAuth);
    14.6  
    14.7 +TPM_RESULT VTSP_SaveState( const TCS_CONTEXT_HANDLE    hContext);
    14.8 +
    14.9  #endif //_VTSP_H_
    15.1 --- a/tools/vtpm_manager/tcs/tcs.c	Tue Jun 27 11:14:19 2006 +0100
    15.2 +++ b/tools/vtpm_manager/tcs/tcs.c	Tue Jun 27 11:15:48 2006 +0100
    15.3 @@ -1126,6 +1126,49 @@ TPM_RESULT TCSP_ReadPubek(TCS_CONTEXT_HA
    15.4    return(returnCode);
    15.5  }
    15.6  
    15.7 +
    15.8 +TPM_RESULT TCSP_SaveState(TCS_CONTEXT_HANDLE   hContext)  // in
    15.9 +{
   15.10 +  // setup input/output parameters block
   15.11 +  TPM_TAG tag = TPM_TAG_RQU_COMMAND;
   15.12 +  UINT32 paramSize = 0;
   15.13 +  TPM_COMMAND_CODE ordinal = TPM_ORD_SaveState;
   15.14 +  TPM_RESULT returnCode = TPM_SUCCESS;
   15.15 +
   15.16 +  // setup the TPM driver input and output buffers
   15.17 +  TDDL_RESULT hRes = TDDL_E_FAIL;
   15.18 +  TDDL_UINT32  InLength = TCPA_MAX_BUFFER_LENGTH;
   15.19 +  TDDL_UINT32  OutLength = TCPA_MAX_BUFFER_LENGTH;
   15.20 +
   15.21 +  // Convert Byte Input parameter in the input byte stream InBuf
   15.22 +  InLength = BSG_PackList(InBuf, 3,
   15.23 +                          BSG_TPM_TAG, &tag,
   15.24 +                          BSG_TYPE_UINT32, &paramSize,
   15.25 +                          BSG_TPM_COMMAND_CODE, &ordinal);
   15.26 +  // fill paramSize again as we now have the correct size
   15.27 +  BSG_Pack(BSG_TYPE_UINT32, &InLength, InBuf+2);
   15.28 +
   15.29 +  vtpmloginfo(VTPM_LOG_TCS_DEEP, "Sending paramSize = %d\n", InLength);
   15.30 +
   15.31 +  // call the TPM driver
   15.32 +  if ((hRes = TDDL_TransmitData(InBuf, InLength, OutBuf, &OutLength)) == TDDL_SUCCESS) {
   15.33 +    // unpack OutBuf to get the tag, paramSize, & returnCode
   15.34 +    BSG_UnpackList(OutBuf, 3,
   15.35 +                           BSG_TPM_TAG, &tag,
   15.36 +                           BSG_TYPE_UINT32, &paramSize,
   15.37 +                           BSG_TPM_COMMAND_CODE, &returnCode);
   15.38 +
   15.39 +    if (returnCode == TPM_SUCCESS && tag == TPM_TAG_RSP_COMMAND) {
   15.40 +      vtpmloginfo(VTPM_LOG_TCS_DEEP, "Received paramSize : %d\n", paramSize);
   15.41 +    } else {
   15.42 +      vtpmlogerror(VTPM_LOG_TCS, "TCSP_SaveState Failed with return code %s\n", tpm_get_error_name(returnCode));
   15.43 +    }
   15.44 +  }
   15.45 +
   15.46 +  return(returnCode);
   15.47 +}
   15.48 +
   15.49 +
   15.50  TPM_RESULT TCSP_RawTransmitData(   UINT32 inDataSize,  // in
   15.51  				   BYTE *inData,       // in
   15.52  				   UINT32 *outDataSize,// in/out
    16.1 --- a/tools/vtpm_manager/tcs/tcs.h	Tue Jun 27 11:14:19 2006 +0100
    16.2 +++ b/tools/vtpm_manager/tcs/tcs.h	Tue Jun 27 11:15:48 2006 +0100
    16.3 @@ -229,7 +229,10 @@ TPM_RESULT TCSP_ReadPubek (  TCS_CONTEXT
    16.4  			     );
    16.5  
    16.6  
    16.7 -// Non-Standard TCSP call to give direct access to TransmitData.
    16.8 +// Non-Standard TCSP calls
    16.9 +TPM_RESULT TCSP_SaveState(TCS_CONTEXT_HANDLE   hContext);  // in
   16.10 +
   16.11 +//Give direct access to TransmitData.
   16.12  // Key and Auth Management is done before transfering command to TDDL.
   16.13  TPM_RESULT TCSP_RawTransmitData(UINT32 inDataSize,  // in
   16.14  				BYTE *inData,       // in
    17.1 --- a/tools/vtpm_manager/util/tcg.h	Tue Jun 27 11:14:19 2006 +0100
    17.2 +++ b/tools/vtpm_manager/util/tcg.h	Tue Jun 27 11:15:48 2006 +0100
    17.3 @@ -389,6 +389,11 @@ typedef struct pack_constbuf_t {
    17.4  #define TPM_DELEGATE_ADMIN      TPM_BASE + 77 // Delegation table management not enabled
    17.5  #define TPM_TRANSPORT_EXCLUSIVE    TPM_BASE + 78 // There was a command executed outside of an exclusive transport session
    17.6  
    17.7 +// TPM_STARTUP_TYPE values
    17.8 +#define TPM_ST_CLEAR 0x0001
    17.9 +#define TPM_ST_STATE 0x0002
   17.10 +#define TPM_ST_DEACTIVATED 0x003
   17.11 +
   17.12  // TPM_TAG values
   17.13  #define TPM_TAG_RQU_COMMAND 0x00c1
   17.14  #define TPM_TAG_RQU_AUTH1_COMMAND 0x00c2