direct-io.hg

changeset 8132:28ce48573771

Merged.
author emellor@leeni.uk.xensource.com
date Wed Nov 30 19:55:08 2005 +0000 (2005-11-30)
parents 6a2acc1cc505 58d46463413e
children 82f61375cd74 e6d64c356d63
files
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_32	Wed Nov 30 19:54:28 2005 +0000
     1.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_32	Wed Nov 30 19:55:08 2005 +0000
     1.3 @@ -432,7 +432,7 @@ CONFIG_IOSCHED_NOOP=y
     1.4  CONFIG_IOSCHED_AS=y
     1.5  CONFIG_IOSCHED_DEADLINE=y
     1.6  CONFIG_IOSCHED_CFQ=y
     1.7 -# CONFIG_ATA_OVER_ETH is not set
     1.8 +CONFIG_ATA_OVER_ETH=m
     1.9  
    1.10  #
    1.11  # ATA/ATAPI/MFM/RLL support
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Wed Nov 30 19:54:28 2005 +0000
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Wed Nov 30 19:55:08 2005 +0000
     2.3 @@ -88,10 +88,10 @@ static inline void flush_plugged_queue(v
     2.4   * handle returned must be used to unmap the frame. This is needed to
     2.5   * drop the ref count on the frame.
     2.6   */
     2.7 -static u16 pending_grant_handles[MMAP_PAGES];
     2.8 +static grant_handle_t pending_grant_handles[MMAP_PAGES];
     2.9  #define pending_handle(_idx, _i) \
    2.10      (pending_grant_handles[((_idx) * BLKIF_MAX_SEGMENTS_PER_REQUEST) + (_i)])
    2.11 -#define BLKBACK_INVALID_HANDLE (0xFFFF)
    2.12 +#define BLKBACK_INVALID_HANDLE (~0)
    2.13  
    2.14  #ifdef CONFIG_XEN_BLKDEV_TAP_BE
    2.15  /*
    2.16 @@ -114,7 +114,7 @@ static void fast_flush_area(int idx, int
    2.17  {
    2.18  	struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST];
    2.19  	unsigned int i, invcount = 0;
    2.20 -	u16 handle;
    2.21 +	grant_handle_t handle;
    2.22  	int ret;
    2.23  
    2.24  	for (i = 0; i < nr_pages; i++) {
    2.25 @@ -335,7 +335,6 @@ static void dispatch_rw_block_io(blkif_t
    2.26  {
    2.27  	extern void ll_rw_block(int rw, int nr, struct buffer_head * bhs[]); 
    2.28  	int operation = (req->operation == BLKIF_OP_WRITE) ? WRITE : READ;
    2.29 -	unsigned long fas = 0;
    2.30  	int i, pending_idx = pending_ring[MASK_PEND_IDX(pending_cons)];
    2.31  	pending_req_t *pending_req;
    2.32  	struct gnttab_map_grant_ref map[BLKIF_MAX_SEGMENTS_PER_REQUEST];
    2.33 @@ -362,16 +361,17 @@ static void dispatch_rw_block_io(blkif_t
    2.34  	preq.nr_sects      = 0;
    2.35  
    2.36  	for (i = 0; i < nseg; i++) {
    2.37 -		fas         = req->frame_and_sects[i];
    2.38 -		seg[i].nsec = blkif_last_sect(fas) - blkif_first_sect(fas) + 1;
    2.39 +		seg[i].nsec = req->seg[i].last_sect -
    2.40 +			req->seg[i].first_sect + 1;
    2.41  
    2.42 -		if (seg[i].nsec <= 0)
    2.43 +		if ((req->seg[i].last_sect >= (PAGE_SIZE >> 9)) ||
    2.44 +		    (seg[i].nsec <= 0))
    2.45  			goto bad_descriptor;
    2.46  		preq.nr_sects += seg[i].nsec;
    2.47  
    2.48  		map[i].host_addr = MMAP_VADDR(pending_idx, i);
    2.49  		map[i].dom = blkif->domid;
    2.50 -		map[i].ref = blkif_gref_from_fas(fas);
    2.51 +		map[i].ref = req->seg[i].gref;
    2.52  		map[i].flags = GNTMAP_host_map;
    2.53  		if ( operation == WRITE )
    2.54  			map[i].flags |= GNTMAP_readonly;
    2.55 @@ -381,7 +381,7 @@ static void dispatch_rw_block_io(blkif_t
    2.56  	BUG_ON(ret);
    2.57  
    2.58  	for (i = 0; i < nseg; i++) {
    2.59 -		if (likely(map[i].handle >= 0)) {
    2.60 +		if (likely(map[i].status == 0)) {
    2.61  			pending_handle(pending_idx, i) = map[i].handle;
    2.62  #ifdef __ia64__
    2.63  			MMAP_VADDR(pending_idx,i) = gnttab_map_vaddr(map[i]);
    2.64 @@ -390,9 +390,8 @@ static void dispatch_rw_block_io(blkif_t
    2.65  				pending_idx, i)) >> PAGE_SHIFT,
    2.66  				FOREIGN_FRAME(map[i].dev_bus_addr>>PAGE_SHIFT));
    2.67  #endif
    2.68 -			fas        = req->frame_and_sects[i];
    2.69 -			seg[i].buf = map[i].dev_bus_addr | 
    2.70 -				(blkif_first_sect(fas) << 9);
    2.71 +			seg[i].buf = map[i].dev_bus_addr |
    2.72 +				(req->seg[i].first_sect << 9);
    2.73  		} else {
    2.74  			errors++;
    2.75  		}
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/common.h	Wed Nov 30 19:54:28 2005 +0000
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/common.h	Wed Nov 30 19:55:08 2005 +0000
     3.3 @@ -66,8 +66,8 @@ typedef struct blkif_st {
     3.4  
     3.5  	struct work_struct free_work;
     3.6  
     3.7 -	u16         shmem_handle;
     3.8 -	grant_ref_t shmem_ref;
     3.9 +	grant_handle_t shmem_handle;
    3.10 +	grant_ref_t    shmem_ref;
    3.11  } blkif_t;
    3.12  
    3.13  blkif_t *alloc_blkif(domid_t domid);
     4.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Wed Nov 30 19:54:28 2005 +0000
     4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Wed Nov 30 19:55:08 2005 +0000
     4.3 @@ -43,9 +43,9 @@ static int map_frontend_page(blkif_t *bl
     4.4  	unlock_vm_area(blkif->blk_ring_area);
     4.5  	BUG_ON(ret);
     4.6  
     4.7 -	if (op.handle < 0) {
     4.8 +	if (op.status) {
     4.9  		DPRINTK(" Grant table operation failure !\n");
    4.10 -		return op.handle;
    4.11 +		return op.status;
    4.12  	}
    4.13  
    4.14  	blkif->shmem_ref = shared_page;
     5.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Wed Nov 30 19:54:28 2005 +0000
     5.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Wed Nov 30 19:55:08 2005 +0000
     5.3 @@ -32,7 +32,6 @@
     5.4   * IN THE SOFTWARE.
     5.5   */
     5.6  
     5.7 -
     5.8  #if 1
     5.9  #define ASSERT(p)							   \
    5.10  	if (!(p)) { printk("Assertion '%s' failed, line %d, file %s", #p , \
    5.11 @@ -41,7 +40,6 @@
    5.12  #define ASSERT(_p)
    5.13  #endif
    5.14  
    5.15 -
    5.16  #include <linux/version.h>
    5.17  #include "block.h"
    5.18  #include <linux/cdrom.h>
    5.19 @@ -54,16 +52,14 @@
    5.20  #include <asm-xen/gnttab.h>
    5.21  #include <asm/hypervisor.h>
    5.22  
    5.23 -
    5.24  #define BLKIF_STATE_DISCONNECTED 0
    5.25  #define BLKIF_STATE_CONNECTED    1
    5.26  #define BLKIF_STATE_SUSPENDED    2
    5.27  
    5.28  #define MAXIMUM_OUTSTANDING_BLOCK_REQS \
    5.29 -    (BLKIF_MAX_SEGMENTS_PER_REQUEST * BLKIF_RING_SIZE)
    5.30 +    (BLKIF_MAX_SEGMENTS_PER_REQUEST * BLK_RING_SIZE)
    5.31  #define GRANT_INVALID_REF	0
    5.32  
    5.33 -
    5.34  static void connect(struct blkfront_info *);
    5.35  static void blkfront_closing(struct xenbus_device *);
    5.36  static int blkfront_remove(struct xenbus_device *);
    5.37 @@ -551,8 +547,11 @@ static int blkif_queue_request(struct re
    5.38  			info->shadow[id].frame[ring_req->nr_segments] =
    5.39  				mfn_to_pfn(buffer_mfn);
    5.40  
    5.41 -			ring_req->frame_and_sects[ring_req->nr_segments] =
    5.42 -				blkif_fas_from_gref(ref, fsect, lsect);
    5.43 +			ring_req->seg[ring_req->nr_segments] =
    5.44 +				(struct blkif_request_segment) {
    5.45 +					.gref       = ref,
    5.46 +					.first_sect = fsect, 
    5.47 +					.last_sect  = lsect };
    5.48  
    5.49  			ring_req->nr_segments++;
    5.50  		}
    5.51 @@ -699,8 +698,7 @@ static void blkif_completion(struct blk_
    5.52  {
    5.53  	int i;
    5.54  	for (i = 0; i < s->req.nr_segments; i++)
    5.55 -		gnttab_end_foreign_access(
    5.56 -			blkif_gref_from_fas(s->req.frame_and_sects[i]), 0, 0UL);
    5.57 +		gnttab_end_foreign_access(s->req.seg[i].gref, 0, 0UL);
    5.58  }
    5.59  
    5.60  static void blkif_recover(struct blkfront_info *info)
    5.61 @@ -740,7 +738,7 @@ static void blkif_recover(struct blkfron
    5.62  		/* Rewrite any grant references invalidated by susp/resume. */
    5.63  		for (j = 0; j < req->nr_segments; j++)
    5.64  			gnttab_grant_foreign_access_ref(
    5.65 -				blkif_gref_from_fas(req->frame_and_sects[j]),
    5.66 +				req->seg[j].gref,
    5.67  				info->xbdev->otherend_id,
    5.68  				pfn_to_mfn(info->shadow[req->id].frame[j]),
    5.69  				rq_data_dir(
     6.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c	Wed Nov 30 19:54:28 2005 +0000
     6.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c	Wed Nov 30 19:55:08 2005 +0000
     6.3 @@ -33,6 +33,9 @@
     6.4  #include <linux/blkdev.h>
     6.5  #include <linux/list.h>
     6.6  
     6.7 +#define BLKIF_MAJOR(dev) ((dev)>>8)
     6.8 +#define BLKIF_MINOR(dev) ((dev) & 0xff)
     6.9 +
    6.10  /*
    6.11   * For convenience we distinguish between ide, scsi and 'other' (i.e.,
    6.12   * potentially combinations of the two) in the naming scheme and in a few other
     7.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Wed Nov 30 19:54:28 2005 +0000
     7.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Wed Nov 30 19:55:08 2005 +0000
     7.3 @@ -177,8 +177,8 @@ extern inline domid_t ID_TO_DOM(unsigned
     7.4   */
     7.5  struct grant_handle_pair
     7.6  {
     7.7 -	u16  kernel;
     7.8 -	u16  user;
     7.9 +	grant_handle_t kernel;
    7.10 +	grant_handle_t user;
    7.11  };
    7.12  static struct grant_handle_pair pending_grant_handles[MMAP_PAGES];
    7.13  #define pending_handle(_idx, _i) \
    7.14 @@ -713,7 +713,7 @@ static void dispatch_rw_block_io(blkif_t
    7.15  		/* Map the remote page to kernel. */
    7.16  		map[op].host_addr = kvaddr;
    7.17  		map[op].dom   = blkif->domid;
    7.18 -		map[op].ref   = blkif_gref_from_fas(req->frame_and_sects[i]);
    7.19 +		map[op].ref   = req->seg[i].gref;
    7.20  		map[op].flags = GNTMAP_host_map;
    7.21  		/* This needs a bit more thought in terms of interposition: 
    7.22  		 * If we want to be able to modify pages during write using 
    7.23 @@ -733,7 +733,7 @@ static void dispatch_rw_block_io(blkif_t
    7.24  
    7.25  		map[op].host_addr = ptep;
    7.26  		map[op].dom       = blkif->domid;
    7.27 -		map[op].ref       = blkif_gref_from_fas(req->frame_and_sects[i]);
    7.28 +		map[op].ref       = req->seg[i].gref;
    7.29  		map[op].flags     = GNTMAP_host_map | GNTMAP_application_map
    7.30  			| GNTMAP_contains_pte;
    7.31  		/* Above interposition comment applies here as well. */
    7.32 @@ -755,17 +755,17 @@ static void dispatch_rw_block_io(blkif_t
    7.33  		uvaddr = MMAP_VADDR(user_vstart, pending_idx, i/2);
    7.34  		kvaddr = MMAP_VADDR(mmap_vstart, pending_idx, i/2);
    7.35  
    7.36 -		if (unlikely(map[i].handle < 0)) {
    7.37 +		if (unlikely(map[i].status)) {
    7.38  			DPRINTK("Error on kernel grant mapping (%d)\n",
    7.39 -				map[i].handle);
    7.40 -			ret = map[i].handle;
    7.41 +				map[i].status);
    7.42 +			ret = map[i].status;
    7.43  			cancel = 1;
    7.44  		}
    7.45  
    7.46 -		if (unlikely(map[i+1].handle < 0)) {
    7.47 +		if (unlikely(map[i+1].status)) {
    7.48  			DPRINTK("Error on user grant mapping (%d)\n",
    7.49 -				map[i+1].handle);
    7.50 -			ret = map[i+1].handle;
    7.51 +				map[i+1].status);
    7.52 +			ret = map[i+1].status;
    7.53  			cancel = 1;
    7.54  		}
    7.55  
     8.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/common.h	Wed Nov 30 19:54:28 2005 +0000
     8.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/common.h	Wed Nov 30 19:55:08 2005 +0000
     8.3 @@ -64,7 +64,7 @@ typedef struct blkif_st {
     8.4  
     8.5  	struct work_struct free_work;
     8.6  
     8.7 -	u16              shmem_handle;
     8.8 +	grant_handle_t   shmem_handle;
     8.9  	grant_ref_t      shmem_ref;
    8.10  } blkif_t;
    8.11  
     9.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c	Wed Nov 30 19:54:28 2005 +0000
     9.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c	Wed Nov 30 19:55:08 2005 +0000
     9.3 @@ -43,9 +43,9 @@ static int map_frontend_page(blkif_t *bl
     9.4  	unlock_vm_area(blkif->blk_ring_area);
     9.5  	BUG_ON(ret);
     9.6  
     9.7 -	if (op.handle < 0) {
     9.8 +	if (op.status) {
     9.9  		DPRINTK(" Grant table operation failure !\n");
    9.10 -		return op.handle;
    9.11 +		return op.status;
    9.12  	}
    9.13  
    9.14  	blkif->shmem_ref    = shared_page;
    10.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/common.h	Wed Nov 30 19:54:28 2005 +0000
    10.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/common.h	Wed Nov 30 19:55:08 2005 +0000
    10.3 @@ -45,9 +45,9 @@ typedef struct netif_st {
    10.4  	u8               fe_dev_addr[6];
    10.5  
    10.6  	/* Physical parameters of the comms window. */
    10.7 -	u16              tx_shmem_handle;
    10.8 +	grant_handle_t   tx_shmem_handle;
    10.9  	grant_ref_t      tx_shmem_ref; 
   10.10 -	u16              rx_shmem_handle;
   10.11 +	grant_handle_t   rx_shmem_handle;
   10.12  	grant_ref_t      rx_shmem_ref; 
   10.13  	unsigned int     evtchn;
   10.14  	unsigned int     irq;
    11.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Wed Nov 30 19:54:28 2005 +0000
    11.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Wed Nov 30 19:55:08 2005 +0000
    11.3 @@ -127,9 +127,9 @@ static int map_frontend_pages(
    11.4  	unlock_vm_area(netif->comms_area);
    11.5  	BUG_ON(ret);
    11.6  
    11.7 -	if (op.handle < 0) { 
    11.8 +	if (op.status) { 
    11.9  		DPRINTK(" Gnttab failure mapping tx_ring_ref!\n");
   11.10 -		return op.handle;
   11.11 +		return op.status;
   11.12  	}
   11.13  
   11.14  	netif->tx_shmem_ref    = tx_ring_ref;
   11.15 @@ -145,9 +145,9 @@ static int map_frontend_pages(
   11.16  	unlock_vm_area(netif->comms_area);
   11.17  	BUG_ON(ret);
   11.18  
   11.19 -	if (op.handle < 0) { 
   11.20 +	if (op.status) {
   11.21  		DPRINTK(" Gnttab failure mapping rx_ring_ref!\n");
   11.22 -		return op.handle;
   11.23 +		return op.status;
   11.24  	}
   11.25  
   11.26  	netif->rx_shmem_ref    = rx_ring_ref;
    12.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Wed Nov 30 19:54:28 2005 +0000
    12.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Wed Nov 30 19:55:08 2005 +0000
    12.3 @@ -68,7 +68,7 @@ static PEND_RING_IDX dealloc_prod, deall
    12.4  
    12.5  static struct sk_buff_head tx_queue;
    12.6  
    12.7 -static u16 grant_tx_ref[MAX_PENDING_REQS];
    12.8 +static grant_handle_t grant_tx_handle[MAX_PENDING_REQS];
    12.9  static gnttab_unmap_grant_ref_t tx_unmap_ops[MAX_PENDING_REQS];
   12.10  static gnttab_map_grant_ref_t tx_map_ops[MAX_PENDING_REQS];
   12.11  
   12.12 @@ -412,7 +412,7 @@ inline static void net_tx_action_dealloc
   12.13  		pending_idx = dealloc_ring[MASK_PEND_IDX(dc++)];
   12.14  		gop->host_addr    = MMAP_VADDR(pending_idx);
   12.15  		gop->dev_bus_addr = 0;
   12.16 -		gop->handle       = grant_tx_ref[pending_idx];
   12.17 +		gop->handle       = grant_tx_handle[pending_idx];
   12.18  		gop++;
   12.19  	}
   12.20  	ret = HYPERVISOR_grant_table_op(
   12.21 @@ -592,7 +592,7 @@ static void net_tx_action(unsigned long 
   12.22  		       sizeof(txreq));
   12.23  
   12.24  		/* Check the remap error code. */
   12.25 -		if (unlikely(mop->handle < 0)) {
   12.26 +		if (unlikely(mop->status)) {
   12.27  			printk(KERN_ALERT "#### netback grant fails\n");
   12.28  			make_tx_response(netif, txreq.id, NETIF_RSP_ERROR);
   12.29  			netif_put(netif);
   12.30 @@ -605,7 +605,7 @@ static void net_tx_action(unsigned long 
   12.31  		set_phys_to_machine(
   12.32  			__pa(MMAP_VADDR(pending_idx)) >> PAGE_SHIFT,
   12.33  			FOREIGN_FRAME(mop->dev_bus_addr >> PAGE_SHIFT));
   12.34 -		grant_tx_ref[pending_idx] = mop->handle;
   12.35 +		grant_tx_handle[pending_idx] = mop->handle;
   12.36  
   12.37  		data_len = (txreq.size > PKT_PROT_LEN) ?
   12.38  			PKT_PROT_LEN : txreq.size;
    13.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h	Wed Nov 30 19:54:28 2005 +0000
    13.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h	Wed Nov 30 19:55:08 2005 +0000
    13.3 @@ -54,7 +54,7 @@ typedef struct tpmif_st {
    13.4  
    13.5  	struct work_struct work;
    13.6  
    13.7 -	u16 shmem_handle;
    13.8 +	grant_handle_t shmem_handle;
    13.9  	grant_ref_t shmem_ref;
   13.10  } tpmif_t;
   13.11  
    14.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Wed Nov 30 19:54:28 2005 +0000
    14.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Wed Nov 30 19:55:08 2005 +0000
    14.3 @@ -91,9 +91,9 @@ map_frontend_page(tpmif_t *tpmif, unsign
    14.4  	unlock_vm_area(tpmif->tx_area);
    14.5  	BUG_ON(ret);
    14.6  
    14.7 -	if (op.handle < 0) {
    14.8 +	if (op.status) {
    14.9  		DPRINTK(" Grant table operation failure !\n");
   14.10 -		return op.handle;
   14.11 +		return op.status;
   14.12  	}
   14.13  
   14.14  	tpmif->shmem_ref = shared_page;
    15.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c	Wed Nov 30 19:54:28 2005 +0000
    15.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c	Wed Nov 30 19:55:08 2005 +0000
    15.3 @@ -249,7 +249,7 @@ static int
    15.4  	 * and send it to the front end.
    15.5  	 */
    15.6  	tpmif_t *tpmif = pak->tpmif;
    15.7 -	u16 handle;
    15.8 +	grant_handle_t handle;
    15.9  	int rc = 0;
   15.10  	unsigned int i = 0;
   15.11  	unsigned int offset = 0;
   15.12 @@ -290,7 +290,7 @@ static int
   15.13  
   15.14  		handle = map_op.handle;
   15.15  
   15.16 -		if (map_op.handle < 0) {
   15.17 +		if (map_op.status) {
   15.18  			DPRINTK(" Grant table operation failure !\n");
   15.19  			return 0;
   15.20  		}
   15.21 @@ -427,7 +427,7 @@ packet_read_shmem(struct packet *pak,
   15.22  	u32 i = (last_read / PAGE_SIZE);
   15.23  	u32 pg_offset = last_read & (PAGE_SIZE - 1);
   15.24  	u32 to_copy;
   15.25 -	u16 handle;
   15.26 +	grant_handle_t handle;
   15.27  
   15.28  	tpmif_tx_request_t *tx;
   15.29  	tx = &tpmif->tx->ring[0].req;
   15.30 @@ -455,7 +455,7 @@ packet_read_shmem(struct packet *pak,
   15.31  			BUG();
   15.32  		}
   15.33  
   15.34 -		if (map_op.handle < 0) {
   15.35 +		if (map_op.status) {
   15.36  			DPRINTK(" Grant table operation failure !\n");
   15.37  			return -EFAULT;
   15.38  		}
    16.1 --- a/tools/blktap/blkdump.c	Wed Nov 30 19:54:28 2005 +0000
    16.2 +++ b/tools/blktap/blkdump.c	Wed Nov 30 19:55:08 2005 +0000
    16.3 @@ -11,7 +11,6 @@
    16.4  int request_print(blkif_request_t *req)
    16.5  {
    16.6      int i;
    16.7 -    unsigned long fas;
    16.8      
    16.9      if ( (req->operation == BLKIF_OP_READ) ||
   16.10           (req->operation == BLKIF_OP_WRITE) )
   16.11 @@ -24,12 +23,10 @@ int request_print(blkif_request_t *req)
   16.12          
   16.13          
   16.14          for (i=0; i < req->nr_segments; i++) {
   16.15 -            fas = req->frame_and_sects[i];
   16.16 -            printf("              (pf: 0x%8lx start: %lu stop: %lu)\n",
   16.17 -                    (fas & PAGE_MASK),
   16.18 -                    blkif_first_sect(fas),
   16.19 -                    blkif_last_sect(fas)
   16.20 -                    );
   16.21 +            printf("              (gref: 0x%8x start: %u stop: %u)\n",
   16.22 +                   req->seg[i].gref,
   16.23 +                   req->seg[i].first_sect,
   16.24 +                   req->seg[i].last_sect);
   16.25          }
   16.26              
   16.27      } else {
    17.1 --- a/tools/blktap/blktaplib.c	Wed Nov 30 19:54:28 2005 +0000
    17.2 +++ b/tools/blktap/blktaplib.c	Wed Nov 30 19:55:08 2005 +0000
    17.3 @@ -244,8 +244,8 @@ int blktap_listen(void)
    17.4      RING_IDX          rp, i, pfd_count; 
    17.5      
    17.6      /* pending rings */
    17.7 -    blkif_request_t req_pending[BLKIF_RING_SIZE];
    17.8 -    /* blkif_response_t rsp_pending[BLKIF_RING_SIZE] */;
    17.9 +    blkif_request_t req_pending[BLK_RING_SIZE];
   17.10 +    /* blkif_response_t rsp_pending[BLK_RING_SIZE] */;
   17.11      
   17.12      /* handler hooks: */
   17.13      request_hook_t   *req_hook;
    18.1 --- a/tools/blktap/blktaplib.h	Wed Nov 30 19:54:28 2005 +0000
    18.2 +++ b/tools/blktap/blktaplib.h	Wed Nov 30 19:55:08 2005 +0000
    18.3 @@ -18,11 +18,13 @@
    18.4  #include <xen/io/domain_controller.h>
    18.5  #include <xs.h>
    18.6  
    18.7 +#define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, PAGE_SIZE)
    18.8 +
    18.9  /* /dev/xen/blktap resides at device number major=10, minor=202        */ 
   18.10  #define BLKTAP_MINOR 202
   18.11  
   18.12  /* size of the extra VMA area to map in attached pages. */
   18.13 -#define BLKTAP_VMA_PAGES BLKIF_RING_SIZE
   18.14 +#define BLKTAP_VMA_PAGES BLK_RING_SIZE
   18.15  
   18.16  /* blktap IOCTLs:                                                      */
   18.17  #define BLKTAP_IOCTL_KICK_FE         1
    19.1 --- a/tools/blktap/parallax/parallax.c	Wed Nov 30 19:54:28 2005 +0000
    19.2 +++ b/tools/blktap/parallax/parallax.c	Wed Nov 30 19:55:08 2005 +0000
    19.3 @@ -280,8 +280,7 @@ int parallax_probe(blkif_request_t *req,
    19.4        goto err;
    19.5  
    19.6      /* Make sure the buffer is page-sized. */
    19.7 -    if ( (blkif_first_sect(req->frame_and_sects[0]) != 0) ||
    19.8 -       (blkif_last_sect (req->frame_and_sects[0]) != 7) )
    19.9 +    if ( (req->seg[0].first_sect != 0) || (req->seg[0].last_sect != 7) )
   19.10        goto err;
   19.11  
   19.12      /* fill the list of devices */
   19.13 @@ -350,17 +349,16 @@ static void read_cb(struct io_ret r, voi
   19.14      /* Calculate read size and offset within the read block. */
   19.15  
   19.16      offset = (param->sector << SECTOR_SHIFT) % BLOCK_SIZE;
   19.17 -    size = ( blkif_last_sect (req->frame_and_sects[segment]) -
   19.18 -             blkif_first_sect(req->frame_and_sects[segment]) + 1
   19.19 -        ) << SECTOR_SHIFT;
   19.20 -    start = blkif_first_sect(req->frame_and_sects[segment]) 
   19.21 -        << SECTOR_SHIFT;
   19.22 +    size = (req->seg[segment].last_sect - req->seg[segment].first_sect + 1) <<
   19.23 +        SECTOR_SHIFT;
   19.24 +    start = req->seg[segment].first_sect << SECTOR_SHIFT;
   19.25  
   19.26      DPRINTF("ParallaxRead: sect: %lld (%ld,%ld),  "
   19.27              "vblock %llx, "
   19.28              "size %lx\n", 
   19.29 -            param->sector, blkif_first_sect(p->req->frame_and_sects[segment]),
   19.30 -            blkif_last_sect (p->req->frame_and_sects[segment]),
   19.31 +            param->sector,
   19.32 +            p->req->seg[segment].first_sect,
   19.33 +            p->req->seg[segment].last_sect,
   19.34              param->vblock, size); 
   19.35  
   19.36      memcpy(dpage + start, spage + offset, size);
   19.37 @@ -506,16 +504,15 @@ int parallax_write(blkif_request_t *req,
   19.38          /* Calculate read size and offset within the read block. */
   19.39          
   19.40          offset = (sector << SECTOR_SHIFT) % BLOCK_SIZE;
   19.41 -        size = ( blkif_last_sect (req->frame_and_sects[i]) -
   19.42 -                 blkif_first_sect(req->frame_and_sects[i]) + 1
   19.43 -            ) << SECTOR_SHIFT;
   19.44 -        start = blkif_first_sect(req->frame_and_sects[i]) << SECTOR_SHIFT;
   19.45 +        size = (req->seg[i].last_sect - req->seg[i].first_sect + 1) <<
   19.46 +            SECTOR_SHIFT;
   19.47 +        start = req->seg[i].first_sect << SECTOR_SHIFT;
   19.48  
   19.49          DPRINTF("ParallaxWrite: sect: %lld (%ld,%ld),  "
   19.50                  "vblock %llx, gblock %llx, "
   19.51                  "size %lx\n", 
   19.52 -                sector, blkif_first_sect(req->frame_and_sects[i]),
   19.53 -                blkif_last_sect (req->frame_and_sects[i]),
   19.54 +                sector, 
   19.55 +                req->seg[i].first_sect, req->seg[i].last_sect,
   19.56                  vblock, gblock, size); 
   19.57        
   19.58          /* XXX: For now we just freak out if they try to write a   */
    20.1 --- a/tools/blktap/ublkback/ublkbacklib.c	Wed Nov 30 19:54:28 2005 +0000
    20.2 +++ b/tools/blktap/ublkback/ublkbacklib.c	Wed Nov 30 19:55:08 2005 +0000
    20.3 @@ -233,8 +233,7 @@ int ublkback_request(blkif_t *blkif, blk
    20.4      case BLKIF_OP_WRITE:
    20.5      {
    20.6          unsigned long size;
    20.7 -        
    20.8 -        
    20.9 +
   20.10          batch_count++;
   20.11  
   20.12          idx = ID_TO_IDX(req->id);
   20.13 @@ -247,18 +246,17 @@ int ublkback_request(blkif_t *blkif, blk
   20.14              
   20.15              sector = req->sector_number + (8*i);
   20.16              
   20.17 -            size = blkif_last_sect (req->frame_and_sects[i]) -
   20.18 -                   blkif_first_sect(req->frame_and_sects[i]) + 1;
   20.19 +            size = req->seg[i].last_sect - req->seg[i].first_sect + 1;
   20.20              
   20.21 -            if (blkif_first_sect(req->frame_and_sects[i]) != 0)
   20.22 -            DPRINTF("iWR: sec_nr: %10llu sec: %10llu (%1lu,%1lu) pos: %15lu\n",
   20.23 -                    req->sector_number, sector, 
   20.24 -                    blkif_first_sect(req->frame_and_sects[i]),
   20.25 -                    blkif_last_sect (req->frame_and_sects[i]),
   20.26 -                    (long)(sector << SECTOR_SHIFT));
   20.27 +            if (req->seg[i].first_sect != 0)
   20.28 +                DPRINTF("iWR: sec_nr: %10llu sec: %10llu (%1lu,%1lu) "
   20.29 +                        "pos: %15lu\n",
   20.30 +                        req->sector_number, sector, 
   20.31 +                        req->seg[i].first_sect, req->seg[i].last_sect,
   20.32 +                        (long)(sector << SECTOR_SHIFT));
   20.33                          
   20.34              spage  = (char *)MMAP_VADDR(ID_TO_IDX(req->id), i);
   20.35 -            spage += blkif_first_sect(req->frame_and_sects[i]) << SECTOR_SHIFT;
   20.36 +            spage += req->seg[i].first_sect << SECTOR_SHIFT;
   20.37              
   20.38              /*convert size and sector to byte offsets */
   20.39              size   <<= SECTOR_SHIFT;
   20.40 @@ -297,19 +295,17 @@ int ublkback_request(blkif_t *blkif, blk
   20.41              
   20.42              sector  = req->sector_number + (8*i);
   20.43              
   20.44 -            size = blkif_last_sect (req->frame_and_sects[i]) -
   20.45 -                   blkif_first_sect(req->frame_and_sects[i]) + 1;
   20.46 -            
   20.47 +            size = req->seg[i].last_sect - req->seg[i].first_sect + 1;
   20.48 +
   20.49              dpage  = (char *)MMAP_VADDR(ID_TO_IDX(req->id), i);
   20.50 -            dpage += blkif_first_sect(req->frame_and_sects[i]) << SECTOR_SHIFT;
   20.51 +            dpage += req->seg[i].first_sect << SECTOR_SHIFT;
   20.52              
   20.53 -            if (blkif_first_sect(req->frame_and_sects[i]) != 0)
   20.54 -            DPRINTF("iRD : sec_nr: %10llu sec: %10llu (%1lu,%1lu) "
   20.55 -                    "pos: %15lu dpage: %p\n", 
   20.56 -                    req->sector_number, sector, 
   20.57 -                    blkif_first_sect(req->frame_and_sects[i]),
   20.58 -                    blkif_last_sect (req->frame_and_sects[i]),
   20.59 -                    (long)(sector << SECTOR_SHIFT), dpage);
   20.60 +            if (req->seg[i].first_sect != 0)
   20.61 +                DPRINTF("iRD : sec_nr: %10llu sec: %10llu (%1lu,%1lu) "
   20.62 +                        "pos: %15lu dpage: %p\n", 
   20.63 +                        req->sector_number, sector, 
   20.64 +                        req->seg[i].first_sect, req->seg[i].last_sect,
   20.65 +                        (long)(sector << SECTOR_SHIFT), dpage);
   20.66              
   20.67              /*convert size and sector to byte offsets */
   20.68              size   <<= SECTOR_SHIFT;
    21.1 --- a/tools/examples/block	Wed Nov 30 19:54:28 2005 +0000
    21.2 +++ b/tools/examples/block	Wed Nov 30 19:55:08 2005 +0000
    21.3 @@ -89,29 +89,34 @@ check_sharing()
    21.4      fi
    21.5    done
    21.6  
    21.7 -  for file in /sys/devices/xen-backend/*/physical_device
    21.8 -  do
    21.9 -    if [ -e "$file" ] # Cope with no devices, i.e. the * above did not expand.
   21.10 -    then
   21.11 -      local d=$(cat "$file")
   21.12 -      if [ "$d" == "$devmm" ]
   21.13 -      then
   21.14 -        if [ "$mode" == 'w' ]
   21.15 -        then
   21.16 -          echo 'guest'
   21.17 -          return
   21.18 -        else
   21.19 -          local m=$(cat "${file/physical_device/mode}")
   21.20 +##
   21.21 +## XXX SMH: the below causes live migration on localhost to fail sometimes
   21.22 +## since the source domain may still appear to be using a local device. 
   21.23 +## For now simply comment it out - a proper fix will come in due course. 
   21.24  
   21.25 -          if expr index "$m" 'w' >/dev/null
   21.26 -          then
   21.27 -            echo 'guest'
   21.28 -            return
   21.29 -          fi
   21.30 -        fi
   21.31 -      fi
   21.32 -    fi
   21.33 -  done
   21.34 +#   for file in /sys/devices/xen-backend/*/physical_device
   21.35 +#   do
   21.36 +#     if [ -e "$file" ] # Cope with no devices, i.e. the * above did not expand.
   21.37 +#     then
   21.38 +#       local d=$(cat "$file")
   21.39 +#       if [ "$d" == "$devmm" ]
   21.40 +#       then
   21.41 +#         if [ "$mode" == 'w' ]
   21.42 +#         then
   21.43 +#           echo 'guest'
   21.44 +#           return
   21.45 +#         else
   21.46 +#           local m=$(cat "${file/physical_device/mode}")
   21.47 +
   21.48 +#           if expr index "$m" 'w' >/dev/null
   21.49 +#           then
   21.50 +#             echo 'guest'
   21.51 +#             return
   21.52 +#           fi
   21.53 +#         fi
   21.54 +#       fi
   21.55 +#     fi
   21.56 +#   done
   21.57  
   21.58    echo 'ok'
   21.59  }
    22.1 --- a/tools/ioemu/vl.c	Wed Nov 30 19:54:28 2005 +0000
    22.2 +++ b/tools/ioemu/vl.c	Wed Nov 30 19:55:08 2005 +0000
    22.3 @@ -1176,7 +1176,6 @@ CharDriverState *qemu_chr_open_stdio(voi
    22.4  int store_console_dev(int domid, char *pts)
    22.5  {
    22.6      int xc_handle;
    22.7 -    unsigned int len = 0;
    22.8      struct xs_handle *xs;
    22.9      char *path;
   22.10  
   22.11 @@ -1218,15 +1217,19 @@ int store_console_dev(int domid, char *p
   22.12  #if defined(__linux__)
   22.13  CharDriverState *qemu_chr_open_pty(void)
   22.14  {
   22.15 -    char slave_name[1024];
   22.16      int master_fd, slave_fd;
   22.17 -
   22.18 -    /* Not satisfying */
   22.19 -    if (openpty(&master_fd, &slave_fd, slave_name, NULL, NULL) < 0) {
   22.20 +    struct termios term;
   22.21 +
   22.22 +    if (openpty(&master_fd, &slave_fd, NULL, NULL, NULL) < 0)
   22.23          return NULL;
   22.24 -    }
   22.25 -    fprintf(stderr, "char device redirected to %s\n", slave_name);
   22.26 -    store_console_dev(domid, slave_name);
   22.27 +
   22.28 +    /* Set raw attributes on the pty. */
   22.29 +    cfmakeraw(&term);
   22.30 +    tcsetattr(slave_fd, TCSAFLUSH, &term);
   22.31 +
   22.32 +    fprintf(stderr, "char device redirected to %s\n", ptsname(slave_fd));
   22.33 +    store_console_dev(domid, ptsname(slave_fd));
   22.34 +
   22.35      return qemu_chr_open_fd(master_fd, master_fd);
   22.36  }
   22.37  #else
    23.1 --- a/tools/libxc/xc_domain.c	Wed Nov 30 19:54:28 2005 +0000
    23.2 +++ b/tools/libxc/xc_domain.c	Wed Nov 30 19:55:08 2005 +0000
    23.3 @@ -365,9 +365,9 @@ int xc_domain_get_vcpu_info(int xc_handl
    23.4  
    23.5  int xc_domain_ioport_permission(int xc_handle,
    23.6                                  uint32_t domid,
    23.7 -                                uint16_t first_port,
    23.8 -                                uint16_t nr_ports,
    23.9 -                                uint16_t allow_access)
   23.10 +                                uint32_t first_port,
   23.11 +                                uint32_t nr_ports,
   23.12 +                                uint32_t allow_access)
   23.13  {
   23.14      DECLARE_DOM0_OP;
   23.15  
    24.1 --- a/tools/libxc/xc_gnttab.c	Wed Nov 30 19:54:28 2005 +0000
    24.2 +++ b/tools/libxc/xc_gnttab.c	Wed Nov 30 19:55:08 2005 +0000
    24.3 @@ -42,9 +42,10 @@ do_gnttab_op(int xc_handle,
    24.4  int xc_gnttab_map_grant_ref(int         xc_handle,
    24.5                              uint64_t    host_virt_addr,
    24.6                              uint32_t    dom,
    24.7 -                            uint16_t    ref,
    24.8 +                            grant_ref_t ref,
    24.9                              uint16_t    flags,
   24.10 -                            int16_t    *handle,
   24.11 +                            int16_t    *status,
   24.12 +                            grant_handle_t *handle,
   24.13                              uint64_t   *dev_bus_addr)
   24.14  {
   24.15      struct gnttab_map_grant_ref op;
   24.16 @@ -58,6 +59,7 @@ int xc_gnttab_map_grant_ref(int         
   24.17      if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_map_grant_ref,
   24.18                              &op, 1)) == 0 )
   24.19      {
   24.20 +        *status         = op.status;
   24.21          *handle         = op.handle;
   24.22          *dev_bus_addr   = op.dev_bus_addr;
   24.23      }
   24.24 @@ -69,7 +71,7 @@ int xc_gnttab_map_grant_ref(int         
   24.25  int xc_gnttab_unmap_grant_ref(int       xc_handle,
   24.26                                uint64_t  host_virt_addr,
   24.27                                uint64_t  dev_bus_addr,
   24.28 -                              uint16_t  handle,
   24.29 +                              grant_handle_t handle,
   24.30                                int16_t  *status)
   24.31  {
   24.32      struct gnttab_unmap_grant_ref op;
    25.1 --- a/tools/libxc/xenctrl.h	Wed Nov 30 19:54:28 2005 +0000
    25.2 +++ b/tools/libxc/xenctrl.h	Wed Nov 30 19:55:08 2005 +0000
    25.3 @@ -13,6 +13,7 @@
    25.4  #include <sys/ptrace.h>
    25.5  #include <xen/xen.h>
    25.6  #include <xen/dom0_ops.h>
    25.7 +#include <xen/grant_table.h>
    25.8  #include <xen/version.h>
    25.9  #include <xen/event_channel.h>
   25.10  #include <xen/sched.h>
   25.11 @@ -374,9 +375,9 @@ int xc_domain_memory_decrease_reservatio
   25.12  
   25.13  int xc_domain_ioport_permission(int xc_handle,
   25.14                                  uint32_t domid,
   25.15 -                                uint16_t first_port,
   25.16 -                                uint16_t nr_ports,
   25.17 -                                uint16_t allow_access);
   25.18 +                                uint32_t first_port,
   25.19 +                                uint32_t nr_ports,
   25.20 +                                uint32_t allow_access);
   25.21  
   25.22  unsigned long xc_make_page_below_4G(int xc_handle, uint32_t domid, 
   25.23  				    unsigned long mfn);
   25.24 @@ -475,15 +476,16 @@ int xc_grant_interface_close(int xc_hand
   25.25  int xc_gnttab_map_grant_ref(int      xc_handle,
   25.26                              uint64_t host_virt_addr,
   25.27                              uint32_t dom,
   25.28 -                            uint16_t ref,
   25.29 +                            grant_ref_t ref,
   25.30                              uint16_t flags,
   25.31 -                            int16_t *handle,
   25.32 +                            int16_t *status,
   25.33 +                            grant_handle_t *handle,
   25.34                              uint64_t *dev_bus_addr);
   25.35  
   25.36  int xc_gnttab_unmap_grant_ref(int  xc_handle,
   25.37                                uint64_t  host_virt_addr,
   25.38                                uint64_t  dev_bus_addr,
   25.39 -                              uint16_t  handle,
   25.40 +                              grant_handle_t handle,
   25.41                                int16_t *status);
   25.42  
   25.43  int xc_gnttab_setup_table(int        xc_handle,
    26.1 --- a/tools/vtpm_manager/crypto/Makefile	Wed Nov 30 19:54:28 2005 +0000
    26.2 +++ b/tools/vtpm_manager/crypto/Makefile	Wed Nov 30 19:55:08 2005 +0000
    26.3 @@ -1,19 +1,19 @@
    26.4 -XEN_ROOT = ../../..
    26.5 -include $(XEN_ROOT)/tools/vtpm_manager/Rules.mk
    26.6 -
    26.7 -BIN		= libtcpaCrypto.a
    26.8 -
    26.9 -all: build
   26.10 -
   26.11 -build: $(BIN)
   26.12 -
   26.13 -install: build
   26.14 -
   26.15 -clean:
   26.16 -	rm -f *.a *.so *.o *.rpm $(DEP_FILES)
   26.17 -
   26.18 -mrproper: clean
   26.19 -	rm -f *~
   26.20 -
   26.21 -$(BIN): $(OBJS)
   26.22 -	$(AR) rcs $(BIN) $(OBJS)
   26.23 +XEN_ROOT = ../../..
   26.24 +include $(XEN_ROOT)/tools/vtpm_manager/Rules.mk
   26.25 +
   26.26 +BIN		= libtcpaCrypto.a
   26.27 +
   26.28 +all: build
   26.29 +
   26.30 +build: $(BIN)
   26.31 +
   26.32 +install: build
   26.33 +
   26.34 +clean:
   26.35 +	rm -f *.a *.so *.o *.rpm $(DEP_FILES)
   26.36 +
   26.37 +mrproper: clean
   26.38 +	rm -f *~
   26.39 +
   26.40 +$(BIN): $(OBJS)
   26.41 +	$(AR) rcs $(BIN) $(OBJS)
    27.1 --- a/tools/vtpm_manager/manager/Makefile	Wed Nov 30 19:54:28 2005 +0000
    27.2 +++ b/tools/vtpm_manager/manager/Makefile	Wed Nov 30 19:55:08 2005 +0000
    27.3 @@ -1,27 +1,27 @@
    27.4 -XEN_ROOT = ../../..
    27.5 -include $(XEN_ROOT)/tools/vtpm_manager/Rules.mk
    27.6 -
    27.7 -BIN		= vtpm_managerd
    27.8 -
    27.9 -all: build
   27.10 -
   27.11 -build: $(BIN)
   27.12 -
   27.13 -install: build
   27.14 -	if [ ! -d "$(DESTDIR)/var/vtpm/fifos" ]; \
   27.15 -		then mkdir -p $(DESTDIR)/var/vtpm/fifos; \
   27.16 -	fi
   27.17 -	$(INSTALL_PROG) $(BIN) $(TOOLS_INSTALL_DIR)
   27.18 -
   27.19 -clean:
   27.20 -	rm -f *.a *.so *.o *.rpm $(DEP_FILES)
   27.21 -
   27.22 -mrproper: clean
   27.23 -	rm -f $(BIN) *~
   27.24 -
   27.25 -$(BIN): $(OBJS)
   27.26 -	$(CC) $(LDFLAGS) $^ $(LIBS) -o $@
   27.27 -
   27.28 -# libraries
   27.29 -LIBS += ../tcs/libTCS.a ../util/libTCGUtils.a ../crypto/libtcpaCrypto.a
   27.30 -LIBS += -lcrypto -lpthread -lrt -lm
   27.31 +XEN_ROOT = ../../..
   27.32 +include $(XEN_ROOT)/tools/vtpm_manager/Rules.mk
   27.33 +
   27.34 +BIN		= vtpm_managerd
   27.35 +
   27.36 +all: build
   27.37 +
   27.38 +build: $(BIN)
   27.39 +
   27.40 +install: build
   27.41 +	if [ ! -d "$(DESTDIR)/var/vtpm/fifos" ]; \
   27.42 +		then mkdir -p $(DESTDIR)/var/vtpm/fifos; \
   27.43 +	fi
   27.44 +	$(INSTALL_PROG) $(BIN) $(TOOLS_INSTALL_DIR)
   27.45 +
   27.46 +clean:
   27.47 +	rm -f *.a *.so *.o *.rpm $(DEP_FILES)
   27.48 +
   27.49 +mrproper: clean
   27.50 +	rm -f $(BIN) *~
   27.51 +
   27.52 +$(BIN): $(OBJS)
   27.53 +	$(CC) $(LDFLAGS) $^ $(LIBS) -o $@
   27.54 +
   27.55 +# libraries
   27.56 +LIBS += ../tcs/libTCS.a ../util/libTCGUtils.a ../crypto/libtcpaCrypto.a
   27.57 +LIBS += -lcrypto -lpthread -lrt -lm
    28.1 --- a/tools/vtpm_manager/manager/tpmpassthrough.c	Wed Nov 30 19:54:28 2005 +0000
    28.2 +++ b/tools/vtpm_manager/manager/tpmpassthrough.c	Wed Nov 30 19:55:08 2005 +0000
    28.3 @@ -1,110 +1,110 @@
    28.4 -// ===================================================================
    28.5 -// 
    28.6 -// Copyright (c) 2005, Intel Corp.
    28.7 -// All rights reserved.
    28.8 -//
    28.9 -// Redistribution and use in source and binary forms, with or without 
   28.10 -// modification, are permitted provided that the following conditions 
   28.11 -// are met:
   28.12 -//
   28.13 -//   * Redistributions of source code must retain the above copyright 
   28.14 -//     notice, this list of conditions and the following disclaimer.
   28.15 -//   * Redistributions in binary form must reproduce the above 
   28.16 -//     copyright notice, this list of conditions and the following 
   28.17 -//     disclaimer in the documentation and/or other materials provided 
   28.18 -//     with the distribution.
   28.19 -//   * Neither the name of Intel Corporation nor the names of its 
   28.20 -//     contributors may be used to endorse or promote products derived
   28.21 -//     from this software without specific prior written permission.
   28.22 -//
   28.23 -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
   28.24 -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
   28.25 -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
   28.26 -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
   28.27 -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   28.28 -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   28.29 -// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
   28.30 -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   28.31 -// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
   28.32 -// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
   28.33 -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   28.34 -// OF THE POSSIBILITY OF SUCH DAMAGE.
   28.35 -// ===================================================================
   28.36 -// 
   28.37 -// tpmpassthrough.c
   28.38 -// 
   28.39 -//  Functions regarding passing DMI requests to HWTPM
   28.40 -//
   28.41 -// ==================================================================
   28.42 -
   28.43 -#include "tcg.h"
   28.44 -#include "vtpm_manager.h"
   28.45 -#include "vtpmpriv.h"
   28.46 -#include "vtsp.h"
   28.47 -#include "log.h"
   28.48 -
   28.49 -TPM_RESULT VTPM_Handle_TPM_Command( VTPM_DMI_RESOURCE *dmi,
   28.50 -				    buffer_t *inbuf,  
   28.51 -				    buffer_t *outbuf) {
   28.52 -  
   28.53 -  TPM_RESULT status = TPM_SUCCESS;
   28.54 -  TPM_COMMAND_CODE *ord;               
   28.55 -  
   28.56 -  ord = (TPM_COMMAND_CODE *) (inbuf->bytes + sizeof(TPM_TAG) + sizeof(UINT32));
   28.57 -  
   28.58 -  switch (*ord) {
   28.59 -    
   28.60 -    // Forbidden for DMI use
   28.61 -  case TPM_ORD_TakeOwnership:
   28.62 -  case TPM_ORD_ChangeAuthOwner:
   28.63 -  case TPM_ORD_DirWriteAuth:
   28.64 -  case TPM_ORD_DirRead:
   28.65 -  case TPM_ORD_AuthorizeMigrationKey:
   28.66 -  case TPM_ORD_CreateMaintenanceArchive:
   28.67 -  case TPM_ORD_LoadMaintenanceArchive:
   28.68 -  case TPM_ORD_KillMaintenanceFeature:
   28.69 -  case TPM_ORD_LoadManuMaintPub:
   28.70 -  case TPM_ORD_ReadManuMaintPub:
   28.71 -  case TPM_ORD_SelfTestFull:
   28.72 -  case TPM_ORD_SelfTestStartup:
   28.73 -  case TPM_ORD_CertifySelfTest:
   28.74 -  case TPM_ORD_ContinueSelfTest:
   28.75 -  case TPM_ORD_GetTestResult:
   28.76 -  case TPM_ORD_Reset:
   28.77 -  case TPM_ORD_OwnerClear:
   28.78 -  case TPM_ORD_DisableOwnerClear:
   28.79 -  case TPM_ORD_ForceClear:
   28.80 -  case TPM_ORD_DisableForceClear:
   28.81 -  case TPM_ORD_GetCapabilityOwner:
   28.82 -  case TPM_ORD_OwnerSetDisable:
   28.83 -  case TPM_ORD_PhysicalEnable:
   28.84 -  case TPM_ORD_PhysicalDisable:
   28.85 -  case TPM_ORD_SetOwnerInstall:
   28.86 -  case TPM_ORD_PhysicalSetDeactivated:
   28.87 -  case TPM_ORD_SetTempDeactivated:
   28.88 -  case TPM_ORD_CreateEndorsementKeyPair:
   28.89 -  case TPM_ORD_GetAuditEvent:
   28.90 -  case TPM_ORD_GetAuditEventSigned:
   28.91 -  case TPM_ORD_GetOrdinalAuditStatus:
   28.92 -  case TPM_ORD_SetOrdinalAuditStatus:
   28.93 -  case TPM_ORD_SetRedirection:
   28.94 -  case TPM_ORD_FieldUpgrade:
   28.95 -  case TSC_ORD_PhysicalPresence:
   28.96 -    status = TPM_DISABLED_CMD;
   28.97 -    goto abort_egress;
   28.98 -    break;
   28.99 -    
  28.100 -  } // End ORD Switch
  28.101 -  
  28.102 -  // Call TCS with command
  28.103 -  
  28.104 -  TPMTRY(TPM_IOERROR, VTSP_RawTransmit( dmi->TCSContext,inbuf, outbuf) );
  28.105 -  
  28.106 -  goto egress;
  28.107 -  
  28.108 - abort_egress:
  28.109 -  vtpmloginfo(VTPM_LOG_VTPM, "TPM Command Failed in tpmpassthrough.\n");
  28.110 - egress:
  28.111 -  
  28.112 -  return status;
  28.113 -}
  28.114 +// ===================================================================
  28.115 +// 
  28.116 +// Copyright (c) 2005, Intel Corp.
  28.117 +// All rights reserved.
  28.118 +//
  28.119 +// Redistribution and use in source and binary forms, with or without 
  28.120 +// modification, are permitted provided that the following conditions 
  28.121 +// are met:
  28.122 +//
  28.123 +//   * Redistributions of source code must retain the above copyright 
  28.124 +//     notice, this list of conditions and the following disclaimer.
  28.125 +//   * Redistributions in binary form must reproduce the above 
  28.126 +//     copyright notice, this list of conditions and the following 
  28.127 +//     disclaimer in the documentation and/or other materials provided 
  28.128 +//     with the distribution.
  28.129 +//   * Neither the name of Intel Corporation nor the names of its 
  28.130 +//     contributors may be used to endorse or promote products derived
  28.131 +//     from this software without specific prior written permission.
  28.132 +//
  28.133 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
  28.134 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
  28.135 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
  28.136 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
  28.137 +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  28.138 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28.139 +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  28.140 +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.141 +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  28.142 +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  28.143 +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  28.144 +// OF THE POSSIBILITY OF SUCH DAMAGE.
  28.145 +// ===================================================================
  28.146 +// 
  28.147 +// tpmpassthrough.c
  28.148 +// 
  28.149 +//  Functions regarding passing DMI requests to HWTPM
  28.150 +//
  28.151 +// ==================================================================
  28.152 +
  28.153 +#include "tcg.h"
  28.154 +#include "vtpm_manager.h"
  28.155 +#include "vtpmpriv.h"
  28.156 +#include "vtsp.h"
  28.157 +#include "log.h"
  28.158 +
  28.159 +TPM_RESULT VTPM_Handle_TPM_Command( VTPM_DMI_RESOURCE *dmi,
  28.160 +				    buffer_t *inbuf,  
  28.161 +				    buffer_t *outbuf) {
  28.162 +  
  28.163 +  TPM_RESULT status = TPM_SUCCESS;
  28.164 +  TPM_COMMAND_CODE *ord;               
  28.165 +  
  28.166 +  ord = (TPM_COMMAND_CODE *) (inbuf->bytes + sizeof(TPM_TAG) + sizeof(UINT32));
  28.167 +  
  28.168 +  switch (*ord) {
  28.169 +    
  28.170 +    // Forbidden for DMI use
  28.171 +  case TPM_ORD_TakeOwnership:
  28.172 +  case TPM_ORD_ChangeAuthOwner:
  28.173 +  case TPM_ORD_DirWriteAuth:
  28.174 +  case TPM_ORD_DirRead:
  28.175 +  case TPM_ORD_AuthorizeMigrationKey:
  28.176 +  case TPM_ORD_CreateMaintenanceArchive:
  28.177 +  case TPM_ORD_LoadMaintenanceArchive:
  28.178 +  case TPM_ORD_KillMaintenanceFeature:
  28.179 +  case TPM_ORD_LoadManuMaintPub:
  28.180 +  case TPM_ORD_ReadManuMaintPub:
  28.181 +  case TPM_ORD_SelfTestFull:
  28.182 +  case TPM_ORD_SelfTestStartup:
  28.183 +  case TPM_ORD_CertifySelfTest:
  28.184 +  case TPM_ORD_ContinueSelfTest:
  28.185 +  case TPM_ORD_GetTestResult:
  28.186 +  case TPM_ORD_Reset:
  28.187 +  case TPM_ORD_OwnerClear:
  28.188 +  case TPM_ORD_DisableOwnerClear:
  28.189 +  case TPM_ORD_ForceClear:
  28.190 +  case TPM_ORD_DisableForceClear:
  28.191 +  case TPM_ORD_GetCapabilityOwner:
  28.192 +  case TPM_ORD_OwnerSetDisable:
  28.193 +  case TPM_ORD_PhysicalEnable:
  28.194 +  case TPM_ORD_PhysicalDisable:
  28.195 +  case TPM_ORD_SetOwnerInstall:
  28.196 +  case TPM_ORD_PhysicalSetDeactivated:
  28.197 +  case TPM_ORD_SetTempDeactivated:
  28.198 +  case TPM_ORD_CreateEndorsementKeyPair:
  28.199 +  case TPM_ORD_GetAuditEvent:
  28.200 +  case TPM_ORD_GetAuditEventSigned:
  28.201 +  case TPM_ORD_GetOrdinalAuditStatus:
  28.202 +  case TPM_ORD_SetOrdinalAuditStatus:
  28.203 +  case TPM_ORD_SetRedirection:
  28.204 +  case TPM_ORD_FieldUpgrade:
  28.205 +  case TSC_ORD_PhysicalPresence:
  28.206 +    status = TPM_DISABLED_CMD;
  28.207 +    goto abort_egress;
  28.208 +    break;
  28.209 +    
  28.210 +  } // End ORD Switch
  28.211 +  
  28.212 +  // Call TCS with command
  28.213 +  
  28.214 +  TPMTRY(TPM_IOERROR, VTSP_RawTransmit( dmi->TCSContext,inbuf, outbuf) );
  28.215 +  
  28.216 +  goto egress;
  28.217 +  
  28.218 + abort_egress:
  28.219 +  vtpmloginfo(VTPM_LOG_VTPM, "TPM Command Failed in tpmpassthrough.\n");
  28.220 + egress:
  28.221 +  
  28.222 +  return status;
  28.223 +}
    29.1 --- a/tools/vtpm_manager/manager/vtpm_manager.h	Wed Nov 30 19:54:28 2005 +0000
    29.2 +++ b/tools/vtpm_manager/manager/vtpm_manager.h	Wed Nov 30 19:55:08 2005 +0000
    29.3 @@ -1,137 +1,137 @@
    29.4 -// ===================================================================
    29.5 -// 
    29.6 -// Copyright (c) 2005, Intel Corp.
    29.7 -// All rights reserved.
    29.8 -//
    29.9 -// Redistribution and use in source and binary forms, with or without 
   29.10 -// modification, are permitted provided that the following conditions 
   29.11 -// are met:
   29.12 -//
   29.13 -//   * Redistributions of source code must retain the above copyright 
   29.14 -//     notice, this list of conditions and the following disclaimer.
   29.15 -//   * Redistributions in binary form must reproduce the above 
   29.16 -//     copyright notice, this list of conditions and the following 
   29.17 -//     disclaimer in the documentation and/or other materials provided 
   29.18 -//     with the distribution.
   29.19 -//   * Neither the name of Intel Corporation nor the names of its 
   29.20 -//     contributors may be used to endorse or promote products derived
   29.21 -//     from this software without specific prior written permission.
   29.22 -//
   29.23 -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
   29.24 -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
   29.25 -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
   29.26 -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
   29.27 -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   29.28 -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   29.29 -// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
   29.30 -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   29.31 -// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
   29.32 -// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
   29.33 -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   29.34 -// OF THE POSSIBILITY OF SUCH DAMAGE.
   29.35 -// ===================================================================
   29.36 -// 
   29.37 -// vtpm_manager.h
   29.38 -// 
   29.39 -//  Public Interface header for VTPM Manager
   29.40 -//
   29.41 -// ==================================================================
   29.42 -
   29.43 -#ifndef __VTPM_MANAGER_H__
   29.44 -#define __VTPM_MANAGER_H__
   29.45 -
   29.46 -#include "tcg.h"
   29.47 -
   29.48 -#define VTPM_TAG_REQ 0x01c1
   29.49 -#define VTPM_TAG_RSP 0x01c4
   29.50 -#define COMMAND_BUFFER_SIZE 4096
   29.51 -
   29.52 -// Header sizes. Note Header MAY include the DMI
   29.53 -#define VTPM_COMMAND_HEADER_SIZE_SRV ( sizeof(UINT32) + sizeof(TPM_TAG) + sizeof(UINT32) + sizeof(TPM_COMMAND_CODE))
   29.54 -#define VTPM_COMMAND_HEADER_SIZE_CLT (                  sizeof(TPM_TAG) + sizeof(UINT32) + sizeof(TPM_COMMAND_CODE))
   29.55 -
   29.56 -// ********************** Public Functions *************************
   29.57 -TPM_RESULT VTPM_Init_Service(); // Start VTPM Service
   29.58 -void VTPM_Stop_Service();  // Stop VTPM Service
   29.59 -#ifdef VTPM_MULTI_VM
   29.60 -int VTPM_Service_Handler();
   29.61 -#else
   29.62 -void *VTPM_Service_Handler(void *threadTypePtr);
   29.63 -#endif
   29.64 -
   29.65 -//************************ Command Codes ****************************
   29.66 -#define VTPM_ORD_OPEN              1   // ULM Creates New DMI
   29.67 -#define VTPM_ORD_CLOSE             2   // ULM Closes a DMI
   29.68 -#define VTPM_ORD_DELETE            3   // ULM Permemently Deletes DMI
   29.69 -#define VTPM_ORD_SAVENVM          4   // DMI requests Secrets Unseal
   29.70 -#define VTPM_ORD_LOADNVM          5   // DMI requests Secrets Saved
   29.71 -#define VTPM_ORD_TPMCOMMAND       6   // DMI issues HW TPM Command
   29.72 -
   29.73 -//************************ Return Codes ****************************
   29.74 -#define VTPM_SUCCESS               0
   29.75 -#define VTPM_FAIL                  1
   29.76 -#define VTPM_UNSUPPORTED           2
   29.77 -#define VTPM_FORBIDDEN             3
   29.78 -#define VTPM_RESTORE_CONTEXT_FAILED    4
   29.79 -#define VTPM_INVALID_REQUEST       5
   29.80 -
   29.81 -/******************* Command Parameter API *************************
   29.82 -
   29.83 -VTPM Command Format
   29.84 -  dmi: 4 bytes                  // Source of message. 
   29.85 -                                // WARNING: This is prepended by the channel. 
   29.86 -                                // Thus it is received by VTPM Manager, 
   29.87 -                                // but not sent by DMI
   29.88 -  tpm tag: 2 bytes
   29.89 -  command size: 4 bytes         // Size of command including header but not DMI
   29.90 -  ord: 4 bytes                  // Command ordinal above
   29.91 -  parameters: size - 10 bytes   // Command Parameter
   29.92 -
   29.93 -VTPM Response Format
   29.94 -  tpm tag: 2 bytes
   29.95 -  response_size: 4 bytes
   29.96 -  status: 4 bytes         
   29.97 -  parameters: size - 10 bytes
   29.98 -
   29.99 -
  29.100 -VTPM_Open:
  29.101 -  Input Parameters:
  29.102 -    Domain_type: 1 byte
  29.103 -    domain_id: 4 bytes
  29.104 -    instance_id: 4 bytes
  29.105 -  Output Parameters:
  29.106 -    None
  29.107 -    
  29.108 -VTPM_Close
  29.109 -  Input Parameters:
  29.110 -    instance_id: 4 bytes
  29.111 -  Output Parameters:
  29.112 -    None
  29.113 -
  29.114 -VTPM_Delete
  29.115 -  Input Parameters:
  29.116 -    instance_id: 4 bytes
  29.117 -  Output Parameters:
  29.118 -    None
  29.119 -
  29.120 -VTPM_SaveNVM
  29.121 -  Input Parameters:
  29.122 -    data: n bytes (Header indicates size of data)
  29.123 -  Output Parameters:
  29.124 -    None
  29.125 -
  29.126 -VTPM_LoadNVM
  29.127 -  Input Parameters:
  29.128 -    None
  29.129 -  Output Parameters:
  29.130 -    data: n bytes (Header indicates size of data)
  29.131 -
  29.132 -VTPM_TPMCommand
  29.133 -  Input Parameters:
  29.134 -    TPM Command Byte Stream: n bytes 
  29.135 -  Output Parameters:
  29.136 -    TPM Reponse Byte Stream: n bytes 
  29.137 -
  29.138 -*********************************************************************/
  29.139 -
  29.140 -#endif //_VTPM_MANAGER_H_
  29.141 +// ===================================================================
  29.142 +// 
  29.143 +// Copyright (c) 2005, Intel Corp.
  29.144 +// All rights reserved.
  29.145 +//
  29.146 +// Redistribution and use in source and binary forms, with or without 
  29.147 +// modification, are permitted provided that the following conditions 
  29.148 +// are met:
  29.149 +//
  29.150 +//   * Redistributions of source code must retain the above copyright 
  29.151 +//     notice, this list of conditions and the following disclaimer.
  29.152 +//   * Redistributions in binary form must reproduce the above 
  29.153 +//     copyright notice, this list of conditions and the following 
  29.154 +//     disclaimer in the documentation and/or other materials provided 
  29.155 +//     with the distribution.
  29.156 +//   * Neither the name of Intel Corporation nor the names of its 
  29.157 +//     contributors may be used to endorse or promote products derived
  29.158 +//     from this software without specific prior written permission.
  29.159 +//
  29.160 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
  29.161 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
  29.162 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
  29.163 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
  29.164 +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  29.165 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  29.166 +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  29.167 +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29.168 +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  29.169 +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  29.170 +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  29.171 +// OF THE POSSIBILITY OF SUCH DAMAGE.
  29.172 +// ===================================================================
  29.173 +// 
  29.174 +// vtpm_manager.h
  29.175 +// 
  29.176 +//  Public Interface header for VTPM Manager
  29.177 +//
  29.178 +// ==================================================================
  29.179 +
  29.180 +#ifndef __VTPM_MANAGER_H__
  29.181 +#define __VTPM_MANAGER_H__
  29.182 +
  29.183 +#include "tcg.h"
  29.184 +
  29.185 +#define VTPM_TAG_REQ 0x01c1
  29.186 +#define VTPM_TAG_RSP 0x01c4
  29.187 +#define COMMAND_BUFFER_SIZE 4096
  29.188 +
  29.189 +// Header sizes. Note Header MAY include the DMI
  29.190 +#define VTPM_COMMAND_HEADER_SIZE_SRV ( sizeof(UINT32) + sizeof(TPM_TAG) + sizeof(UINT32) + sizeof(TPM_COMMAND_CODE))
  29.191 +#define VTPM_COMMAND_HEADER_SIZE_CLT (                  sizeof(TPM_TAG) + sizeof(UINT32) + sizeof(TPM_COMMAND_CODE))
  29.192 +
  29.193 +// ********************** Public Functions *************************
  29.194 +TPM_RESULT VTPM_Init_Service(); // Start VTPM Service
  29.195 +void VTPM_Stop_Service();  // Stop VTPM Service
  29.196 +#ifdef VTPM_MULTI_VM
  29.197 +int VTPM_Service_Handler();
  29.198 +#else
  29.199 +void *VTPM_Service_Handler(void *threadTypePtr);
  29.200 +#endif
  29.201 +
  29.202 +//************************ Command Codes ****************************
  29.203 +#define VTPM_ORD_OPEN              1   // ULM Creates New DMI
  29.204 +#define VTPM_ORD_CLOSE             2   // ULM Closes a DMI
  29.205 +#define VTPM_ORD_DELETE            3   // ULM Permemently Deletes DMI
  29.206 +#define VTPM_ORD_SAVENVM          4   // DMI requests Secrets Unseal
  29.207 +#define VTPM_ORD_LOADNVM          5   // DMI requests Secrets Saved
  29.208 +#define VTPM_ORD_TPMCOMMAND       6   // DMI issues HW TPM Command
  29.209 +
  29.210 +//************************ Return Codes ****************************
  29.211 +#define VTPM_SUCCESS               0
  29.212 +#define VTPM_FAIL                  1
  29.213 +#define VTPM_UNSUPPORTED           2
  29.214 +#define VTPM_FORBIDDEN             3
  29.215 +#define VTPM_RESTORE_CONTEXT_FAILED    4
  29.216 +#define VTPM_INVALID_REQUEST       5
  29.217 +
  29.218 +/******************* Command Parameter API *************************
  29.219 +
  29.220 +VTPM Command Format
  29.221 +  dmi: 4 bytes                  // Source of message. 
  29.222 +                                // WARNING: This is prepended by the channel. 
  29.223 +                                // Thus it is received by VTPM Manager, 
  29.224 +                                // but not sent by DMI
  29.225 +  tpm tag: 2 bytes
  29.226 +  command size: 4 bytes         // Size of command including header but not DMI
  29.227 +  ord: 4 bytes                  // Command ordinal above
  29.228 +  parameters: size - 10 bytes   // Command Parameter
  29.229 +
  29.230 +VTPM Response Format
  29.231 +  tpm tag: 2 bytes
  29.232 +  response_size: 4 bytes
  29.233 +  status: 4 bytes         
  29.234 +  parameters: size - 10 bytes
  29.235 +
  29.236 +
  29.237 +VTPM_Open:
  29.238 +  Input Parameters:
  29.239 +    Domain_type: 1 byte
  29.240 +    domain_id: 4 bytes
  29.241 +    instance_id: 4 bytes
  29.242 +  Output Parameters:
  29.243 +    None
  29.244 +    
  29.245 +VTPM_Close
  29.246 +  Input Parameters:
  29.247 +    instance_id: 4 bytes
  29.248 +  Output Parameters:
  29.249 +    None
  29.250 +
  29.251 +VTPM_Delete
  29.252 +  Input Parameters:
  29.253 +    instance_id: 4 bytes
  29.254 +  Output Parameters:
  29.255 +    None
  29.256 +
  29.257 +VTPM_SaveNVM
  29.258 +  Input Parameters:
  29.259 +    data: n bytes (Header indicates size of data)
  29.260 +  Output Parameters:
  29.261 +    None
  29.262 +
  29.263 +VTPM_LoadNVM
  29.264 +  Input Parameters:
  29.265 +    None
  29.266 +  Output Parameters:
  29.267 +    data: n bytes (Header indicates size of data)
  29.268 +
  29.269 +VTPM_TPMCommand
  29.270 +  Input Parameters:
  29.271 +    TPM Command Byte Stream: n bytes 
  29.272 +  Output Parameters:
  29.273 +    TPM Reponse Byte Stream: n bytes 
  29.274 +
  29.275 +*********************************************************************/
  29.276 +
  29.277 +#endif //_VTPM_MANAGER_H_
    30.1 --- a/tools/vtpm_manager/manager/vtpmd.c	Wed Nov 30 19:54:28 2005 +0000
    30.2 +++ b/tools/vtpm_manager/manager/vtpmd.c	Wed Nov 30 19:55:08 2005 +0000
    30.3 @@ -1,134 +1,134 @@
    30.4 -// ===================================================================
    30.5 -// 
    30.6 -// Copyright (c) 2005, Intel Corp.
    30.7 -// All rights reserved.
    30.8 -//
    30.9 -// Redistribution and use in source and binary forms, with or without 
   30.10 -// modification, are permitted provided that the following conditions 
   30.11 -// are met:
   30.12 -//
   30.13 -//   * Redistributions of source code must retain the above copyright 
   30.14 -//     notice, this list of conditions and the following disclaimer.
   30.15 -//   * Redistributions in binary form must reproduce the above 
   30.16 -//     copyright notice, this list of conditions and the following 
   30.17 -//     disclaimer in the documentation and/or other materials provided 
   30.18 -//     with the distribution.
   30.19 -//   * Neither the name of Intel Corporation nor the names of its 
   30.20 -//     contributors may be used to endorse or promote products derived
   30.21 -//     from this software without specific prior written permission.
   30.22 -//
   30.23 -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
   30.24 -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
   30.25 -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
   30.26 -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
   30.27 -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   30.28 -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   30.29 -// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
   30.30 -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   30.31 -// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
   30.32 -// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
   30.33 -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   30.34 -// OF THE POSSIBILITY OF SUCH DAMAGE.
   30.35 -// ===================================================================
   30.36 -// 
   30.37 -// vtpmd.c
   30.38 -// 
   30.39 -//  Application
   30.40 -//
   30.41 -// ===================================================================
   30.42 -
   30.43 -#include <stdio.h>
   30.44 -#include <signal.h>
   30.45 -#include <sys/types.h>
   30.46 -#include <unistd.h>
   30.47 -#include "vtpm_manager.h"
   30.48 -#include "vtpmpriv.h"
   30.49 -#include "tcg.h"
   30.50 -#include "log.h"
   30.51 -
   30.52 -#ifndef VTPM_MULTI_VM
   30.53 - #include <pthread.h>
   30.54 -#endif
   30.55 -
   30.56 -void signal_handler(int reason) {
   30.57 -#ifndef VTPM_MULTI_VM
   30.58 -
   30.59 -  if (pthread_equal(pthread_self(), vtpm_globals->master_pid)) {
   30.60 -    if (reason >= 0) { // Reason is a signal
   30.61 -      vtpmloginfo(VTPM_LOG_VTPM, "VTPM Manager shutting down for signal %d.\n", reason);
   30.62 -    } else  {// Reason is a TPM_RESULT * -1
   30.63 -      vtpmloginfo(VTPM_LOG_VTPM,"VTPM Manager shuting down for: %s\n", tpm_get_error_name(-1 * reason) );
   30.64 -    }
   30.65 -    
   30.66 -    return;
   30.67 -  } else {
   30.68 -    vtpmloginfo(VTPM_LOG_VTPM, "Child shutting down\n");
   30.69 -    pthread_exit(NULL);
   30.70 -  }
   30.71 -#else
   30.72 -  VTPM_Stop_Service();
   30.73 -  exit(-1);
   30.74 -#endif
   30.75 -}
   30.76 -
   30.77 -struct sigaction ctl_c_handler;
   30.78 -
   30.79 -int main(int argc, char **argv) {
   30.80 -
   30.81 -  vtpmloginfo(VTPM_LOG_VTPM, "Starting VTPM.\n");
   30.82 -  
   30.83 -  if (VTPM_Init_Service() != TPM_SUCCESS) {
   30.84 -    vtpmlogerror(VTPM_LOG_VTPM, "Closing vtpmd due to error during startup.\n");
   30.85 -    return -1;
   30.86 -  }
   30.87 -  
   30.88 -  ctl_c_handler.sa_handler = signal_handler;
   30.89 -  sigemptyset(&ctl_c_handler.sa_mask);
   30.90 -  ctl_c_handler.sa_flags = 0;    
   30.91 -  
   30.92 -  if (sigaction(SIGINT, &ctl_c_handler, NULL) == -1) 
   30.93 -    vtpmlogerror(VTPM_LOG_VTPM, "Could not install SIGINT handler. Ctl+break will not stop service gently.\n");
   30.94 -  
   30.95 -  // For easier debuggin with gdb
   30.96 -  if (sigaction(SIGHUP, &ctl_c_handler, NULL) == -1) 
   30.97 -    vtpmlogerror(VTPM_LOG_VTPM, "Could not install SIGHUP handler. Ctl+break will not stop service gently.\n");    
   30.98 -  
   30.99 -#ifdef VTPM_MULTI_VM
  30.100 -  TPM_RESULT status = VTPM_Service_Handler();
  30.101 -    
  30.102 -  if (status != TPM_SUCCESS) 
  30.103 -    vtpmlogerror(VTPM_LOG_VTPM, "VTPM Manager exited with status %s. It never should exit.\n", tpm_get_error_name(status));
  30.104 -  
  30.105 -  return -1;
  30.106 -#else
  30.107 -  sigset_t sig_mask;
  30.108 -      
  30.109 -  sigemptyset(&sig_mask);
  30.110 -  sigaddset(&sig_mask, SIGPIPE);
  30.111 -  sigprocmask(SIG_BLOCK, &sig_mask, NULL);
  30.112 -  //pthread_mutex_init(&vtpm_globals->dmi_mutex, NULL);
  30.113 -  pthread_t be_thread, dmi_thread;
  30.114 -  int betype_be, dmitype_dmi;
  30.115 -  
  30.116 -  vtpm_globals->master_pid = pthread_self();
  30.117 -  
  30.118 -  betype_be = BE_LISTENER_THREAD;
  30.119 -  if (pthread_create(&be_thread, NULL, VTPM_Service_Handler, &betype_be) != 0) {
  30.120 -    vtpmlogerror(VTPM_LOG_VTPM, "Failed to launch BE Thread.\n");
  30.121 -    exit(-1);
  30.122 -  }
  30.123 -  
  30.124 -  dmitype_dmi = DMI_LISTENER_THREAD;
  30.125 -  if (pthread_create(&dmi_thread, NULL, VTPM_Service_Handler, &dmitype_dmi) != 0) {
  30.126 -    vtpmlogerror(VTPM_LOG_VTPM, "Failed to launch DMI Thread.\n");
  30.127 -    exit(-1);
  30.128 -  }
  30.129 -  
  30.130 -  //Join the other threads until exit time.
  30.131 -  pthread_join(be_thread, NULL);
  30.132 -  pthread_join(dmi_thread, NULL);
  30.133 -  
  30.134 -  VTPM_Stop_Service();
  30.135 -  return 0;
  30.136 -#endif
  30.137 -}
  30.138 +// ===================================================================
  30.139 +// 
  30.140 +// Copyright (c) 2005, Intel Corp.
  30.141 +// All rights reserved.
  30.142 +//
  30.143 +// Redistribution and use in source and binary forms, with or without 
  30.144 +// modification, are permitted provided that the following conditions 
  30.145 +// are met:
  30.146 +//
  30.147 +//   * Redistributions of source code must retain the above copyright 
  30.148 +//     notice, this list of conditions and the following disclaimer.
  30.149 +//   * Redistributions in binary form must reproduce the above 
  30.150 +//     copyright notice, this list of conditions and the following 
  30.151 +//     disclaimer in the documentation and/or other materials provided 
  30.152 +//     with the distribution.
  30.153 +//   * Neither the name of Intel Corporation nor the names of its 
  30.154 +//     contributors may be used to endorse or promote products derived
  30.155 +//     from this software without specific prior written permission.
  30.156 +//
  30.157 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
  30.158 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
  30.159 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
  30.160 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
  30.161 +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  30.162 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  30.163 +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  30.164 +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  30.165 +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  30.166 +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  30.167 +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  30.168 +// OF THE POSSIBILITY OF SUCH DAMAGE.
  30.169 +// ===================================================================
  30.170 +// 
  30.171 +// vtpmd.c
  30.172 +// 
  30.173 +//  Application
  30.174 +//
  30.175 +// ===================================================================
  30.176 +
  30.177 +#include <stdio.h>
  30.178 +#include <signal.h>
  30.179 +#include <sys/types.h>
  30.180 +#include <unistd.h>
  30.181 +#include "vtpm_manager.h"
  30.182 +#include "vtpmpriv.h"
  30.183 +#include "tcg.h"
  30.184 +#include "log.h"
  30.185 +
  30.186 +#ifndef VTPM_MULTI_VM
  30.187 + #include <pthread.h>
  30.188 +#endif
  30.189 +
  30.190 +void signal_handler(int reason) {
  30.191 +#ifndef VTPM_MULTI_VM
  30.192 +
  30.193 +  if (pthread_equal(pthread_self(), vtpm_globals->master_pid)) {
  30.194 +    if (reason >= 0) { // Reason is a signal
  30.195 +      vtpmloginfo(VTPM_LOG_VTPM, "VTPM Manager shutting down for signal %d.\n", reason);
  30.196 +    } else  {// Reason is a TPM_RESULT * -1
  30.197 +      vtpmloginfo(VTPM_LOG_VTPM,"VTPM Manager shuting down for: %s\n", tpm_get_error_name(-1 * reason) );
  30.198 +    }
  30.199 +    
  30.200 +    return;
  30.201 +  } else {
  30.202 +    vtpmloginfo(VTPM_LOG_VTPM, "Child shutting down\n");
  30.203 +    pthread_exit(NULL);
  30.204 +  }
  30.205 +#else
  30.206 +  VTPM_Stop_Service();
  30.207 +  exit(-1);
  30.208 +#endif
  30.209 +}
  30.210 +
  30.211 +struct sigaction ctl_c_handler;
  30.212 +
  30.213 +int main(int argc, char **argv) {
  30.214 +
  30.215 +  vtpmloginfo(VTPM_LOG_VTPM, "Starting VTPM.\n");
  30.216 +  
  30.217 +  if (VTPM_Init_Service() != TPM_SUCCESS) {
  30.218 +    vtpmlogerror(VTPM_LOG_VTPM, "Closing vtpmd due to error during startup.\n");
  30.219 +    return -1;
  30.220 +  }
  30.221 +  
  30.222 +  ctl_c_handler.sa_handler = signal_handler;
  30.223 +  sigemptyset(&ctl_c_handler.sa_mask);
  30.224 +  ctl_c_handler.sa_flags = 0;    
  30.225 +  
  30.226 +  if (sigaction(SIGINT, &ctl_c_handler, NULL) == -1) 
  30.227 +    vtpmlogerror(VTPM_LOG_VTPM, "Could not install SIGINT handler. Ctl+break will not stop service gently.\n");
  30.228 +  
  30.229 +  // For easier debuggin with gdb
  30.230 +  if (sigaction(SIGHUP, &ctl_c_handler, NULL) == -1) 
  30.231 +    vtpmlogerror(VTPM_LOG_VTPM, "Could not install SIGHUP handler. Ctl+break will not stop service gently.\n");    
  30.232 +  
  30.233 +#ifdef VTPM_MULTI_VM
  30.234 +  TPM_RESULT status = VTPM_Service_Handler();
  30.235 +    
  30.236 +  if (status != TPM_SUCCESS) 
  30.237 +    vtpmlogerror(VTPM_LOG_VTPM, "VTPM Manager exited with status %s. It never should exit.\n", tpm_get_error_name(status));
  30.238 +  
  30.239 +  return -1;
  30.240 +#else
  30.241 +  sigset_t sig_mask;
  30.242 +      
  30.243 +  sigemptyset(&sig_mask);
  30.244 +  sigaddset(&sig_mask, SIGPIPE);
  30.245 +  sigprocmask(SIG_BLOCK, &sig_mask, NULL);
  30.246 +  //pthread_mutex_init(&vtpm_globals->dmi_mutex, NULL);
  30.247 +  pthread_t be_thread, dmi_thread;
  30.248 +  int betype_be, dmitype_dmi;
  30.249 +  
  30.250 +  vtpm_globals->master_pid = pthread_self();
  30.251 +  
  30.252 +  betype_be = BE_LISTENER_THREAD;
  30.253 +  if (pthread_create(&be_thread, NULL, VTPM_Service_Handler, &betype_be) != 0) {
  30.254 +    vtpmlogerror(VTPM_LOG_VTPM, "Failed to launch BE Thread.\n");
  30.255 +    exit(-1);
  30.256 +  }
  30.257 +  
  30.258 +  dmitype_dmi = DMI_LISTENER_THREAD;
  30.259 +  if (pthread_create(&dmi_thread, NULL, VTPM_Service_Handler, &dmitype_dmi) != 0) {
  30.260 +    vtpmlogerror(VTPM_LOG_VTPM, "Failed to launch DMI Thread.\n");
  30.261 +    exit(-1);
  30.262 +  }
  30.263 +  
  30.264 +  //Join the other threads until exit time.
  30.265 +  pthread_join(be_thread, NULL);
  30.266 +  pthread_join(dmi_thread, NULL);
  30.267 +  
  30.268 +  VTPM_Stop_Service();
  30.269 +  return 0;
  30.270 +#endif
  30.271 +}
    31.1 --- a/tools/vtpm_manager/manager/vtpmpriv.h	Wed Nov 30 19:54:28 2005 +0000
    31.2 +++ b/tools/vtpm_manager/manager/vtpmpriv.h	Wed Nov 30 19:55:08 2005 +0000
    31.3 @@ -1,151 +1,151 @@
    31.4 -// ===================================================================
    31.5 -// 
    31.6 -// Copyright (c) 2005, Intel Corp.
    31.7 -// All rights reserved.
    31.8 -//
    31.9 -// Redistribution and use in source and binary forms, with or without 
   31.10 -// modification, are permitted provided that the following conditions 
   31.11 -// are met:
   31.12 -//
   31.13 -//   * Redistributions of source code must retain the above copyright 
   31.14 -//     notice, this list of conditions and the following disclaimer.
   31.15 -//   * Redistributions in binary form must reproduce the above 
   31.16 -//     copyright notice, this list of conditions and the following 
   31.17 -//     disclaimer in the documentation and/or other materials provided 
   31.18 -//     with the distribution.
   31.19 -//   * Neither the name of Intel Corporation nor the names of its 
   31.20 -//     contributors may be used to endorse or promote products derived
   31.21 -//     from this software without specific prior written permission.
   31.22 -//
   31.23 -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
   31.24 -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
   31.25 -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
   31.26 -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
   31.27 -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   31.28 -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   31.29 -// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
   31.30 -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   31.31 -// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
   31.32 -// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
   31.33 -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   31.34 -// OF THE POSSIBILITY OF SUCH DAMAGE.
   31.35 -// ===================================================================
   31.36 -// 
   31.37 -// vtpmpriv.h
   31.38 -// 
   31.39 -//  Structures and functions private to the manager
   31.40 -//
   31.41 -// ==================================================================
   31.42 -
   31.43 -#ifndef __VTPMPRIV_H__
   31.44 -#define __VTPMPRIV_H__
   31.45 -
   31.46 -#include "tcg.h"
   31.47 -#include "tcs.h"
   31.48 -#include "buffer.h"
   31.49 -#include "crypto.h"
   31.50 -
   31.51 -#define STATE_FILE    "/var/vtpm/VTPM"
   31.52 -#define DMI_NVM_FILE  "/var/vtpm/vtpm_dm_%d.data"
   31.53 -#define VTPM_BE_DEV   "/dev/vtpm0"
   31.54 -#define VTPM_CTL_DM   0
   31.55 -
   31.56 -#ifndef VTPM_MUTLI_VM
   31.57 - #include <sys/types.h>
   31.58 - #define GUEST_TX_FIFO "/var/vtpm/fifos/guest-to-%d.fifo"
   31.59 - #define GUEST_RX_FIFO "/var/vtpm/fifos/guest-from-all.fifo"
   31.60 -
   31.61 - #define VTPM_TX_FIFO  "/var/vtpm/fifos/vtpm-to-%d.fifo"
   31.62 - #define VTPM_RX_FIFO  "/var/vtpm/fifos/vtpm-from-all.fifo"
   31.63 -
   31.64 - #define BE_LISTENER_THREAD 1
   31.65 - #define DMI_LISTENER_THREAD 2
   31.66 -
   31.67 - // Seconds until DMI timeout. Timeouts result in DMI being out
   31.68 - // of sync, which may require a reboot of DMI and guest to recover
   31.69 - // from. Don't set this to low. Also note that DMI may issue a TPM
   31.70 - // call so we should expect time to process at DMI + TPM processing.
   31.71 - #define DMI_TIMEOUT 90 
   31.72 -#endif
   31.73 -
   31.74 -
   31.75 -// ------------------------ Private Structures -----------------------
   31.76 -typedef struct VTPM_DMI_RESOURCE_T {
   31.77 -  // I/O info for Manager to talk to DMI's over FIFOs
   31.78 -#ifndef VTPM_MUTLI_VM
   31.79 -  int                   guest_tx_fh;          // open GUEST_TX_FIFO
   31.80 -  int                   vtpm_tx_fh;           // open VTPM_TX_FIFO
   31.81 -  char                  *guest_tx_fname;      // open GUEST_TX_FIFO
   31.82 -  char                  *vtpm_tx_fname;       // open VTPM_TX_FIFO
   31.83 -  
   31.84 -  pid_t                 dmi_pid;
   31.85 -#endif
   31.86 -  // Non-persistent Information
   31.87 -  bool                  connected;
   31.88 -  UINT32                dmi_domain_id;
   31.89 -  TCS_CONTEXT_HANDLE    TCSContext;     // TCS Handle
   31.90 -  char                  *NVMLocation;   // NULL term string indicating location
   31.91 -                                        // of NVM.
   31.92 -  // Persistent Information about DMI
   31.93 -  UINT32                dmi_id;
   31.94 -  TPM_DIGEST            NVM_measurement;  // Equal to the SHA1 of the blob
   31.95 -  TPM_DIGEST            DMI_measurement;  // Correct measurement of the owning DMI
   31.96 -} VTPM_DMI_RESOURCE;
   31.97 -
   31.98 -typedef struct tdVTPM_GLOBALS {
   31.99 -  // Non-persistent data
  31.100 -  int                 be_fh;                  // File handle to ipc used to communicate with backend
  31.101 -#ifndef VTPM_MULTI_VM
  31.102 -  int                 vtpm_rx_fh;
  31.103 -  int                 guest_rx_fh;
  31.104 -  
  31.105 -  pid_t               master_pid;
  31.106 -#endif
  31.107 -  struct hashtable    *dmi_map;               // Table of all DMI's known indexed by persistent instance #
  31.108 -#ifndef VTPM_MULTI_VM
  31.109 -  pthread_mutex_t     dmi_map_mutex;          // 
  31.110 -#endif
  31.111 -  TCS_CONTEXT_HANDLE  manager_tcs_handle;     // TCS Handle used by manager
  31.112 -  TPM_HANDLE          storageKeyHandle;       // Key used by persistent store
  31.113 -  CRYPTO_INFO         storageKey;             // For software encryption
  31.114 -  TCS_AUTH            keyAuth;                // OIAP session for storageKey 
  31.115 -  BOOL                DMI_table_dirty;        // Indicates that a command
  31.116 -                                              // has updated the DMI table
  31.117 -
  31.118 -    
  31.119 -  // Persistent Data
  31.120 -  TPM_AUTHDATA        owner_usage_auth;       // OwnerAuth of real TPM
  31.121 -  TPM_AUTHDATA        srk_usage_auth;         // SRK Auth of real TPM    
  31.122 -  buffer_t            storageKeyWrap;         // Wrapped copy of storageKey
  31.123 -
  31.124 -  TPM_AUTHDATA        storage_key_usage_auth; 
  31.125 -    
  31.126 -}VTPM_GLOBALS;
  31.127 -
  31.128 -//Global dmi map
  31.129 -extern VTPM_GLOBALS *vtpm_globals;
  31.130 -
  31.131 -// ********************** Command Handler Prototypes ***********************
  31.132 -TPM_RESULT VTPM_Handle_Load_NVM(       VTPM_DMI_RESOURCE *myDMI, 
  31.133 -                                        const buffer_t *inbuf, 
  31.134 -                                        buffer_t *outbuf);
  31.135 -
  31.136 -TPM_RESULT VTPM_Handle_Save_NVM(       VTPM_DMI_RESOURCE *myDMI, 
  31.137 -                                        const buffer_t *inbuf, 
  31.138 -                                        buffer_t *outbuf);
  31.139 -
  31.140 -TPM_RESULT VTPM_Handle_TPM_Command(    VTPM_DMI_RESOURCE *dmi, 
  31.141 -                                        buffer_t *inbuf, 
  31.142 -                                        buffer_t *outbuf);
  31.143 -
  31.144 -TPM_RESULT VTPM_Handle_New_DMI(const buffer_t *param_buf);
  31.145 -                                
  31.146 -TPM_RESULT VTPM_Handle_Close_DMI(const buffer_t *param_buf);
  31.147 -                                   
  31.148 -TPM_RESULT VTPM_Handle_Delete_DMI(const buffer_t *param_buf);
  31.149 -
  31.150 -TPM_RESULT VTPM_SaveService(void);
  31.151 -TPM_RESULT VTPM_LoadService(void);
  31.152 -
  31.153 -TPM_RESULT close_dmi( VTPM_DMI_RESOURCE *dmi_res);
  31.154 -#endif // __VTPMPRIV_H__
  31.155 +// ===================================================================
  31.156 +// 
  31.157 +// Copyright (c) 2005, Intel Corp.
  31.158 +// All rights reserved.
  31.159 +//
  31.160 +// Redistribution and use in source and binary forms, with or without 
  31.161 +// modification, are permitted provided that the following conditions 
  31.162 +// are met:
  31.163 +//
  31.164 +//   * Redistributions of source code must retain the above copyright 
  31.165 +//     notice, this list of conditions and the following disclaimer.
  31.166 +//   * Redistributions in binary form must reproduce the above 
  31.167 +//     copyright notice, this list of conditions and the following 
  31.168 +//     disclaimer in the documentation and/or other materials provided 
  31.169 +//     with the distribution.
  31.170 +//   * Neither the name of Intel Corporation nor the names of its 
  31.171 +//     contributors may be used to endorse or promote products derived
  31.172 +//     from this software without specific prior written permission.
  31.173 +//
  31.174 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
  31.175 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
  31.176 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
  31.177 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
  31.178 +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  31.179 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  31.180 +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  31.181 +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31.182 +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  31.183 +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  31.184 +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  31.185 +// OF THE POSSIBILITY OF SUCH DAMAGE.
  31.186 +// ===================================================================
  31.187 +// 
  31.188 +// vtpmpriv.h
  31.189 +// 
  31.190 +//  Structures and functions private to the manager
  31.191 +//
  31.192 +// ==================================================================
  31.193 +
  31.194 +#ifndef __VTPMPRIV_H__
  31.195 +#define __VTPMPRIV_H__
  31.196 +
  31.197 +#include "tcg.h"
  31.198 +#include "tcs.h"
  31.199 +#include "buffer.h"
  31.200 +#include "crypto.h"
  31.201 +
  31.202 +#define STATE_FILE    "/var/vtpm/VTPM"
  31.203 +#define DMI_NVM_FILE  "/var/vtpm/vtpm_dm_%d.data"
  31.204 +#define VTPM_BE_DEV   "/dev/vtpm0"
  31.205 +#define VTPM_CTL_DM   0
  31.206 +
  31.207 +#ifndef VTPM_MUTLI_VM
  31.208 + #include <sys/types.h>
  31.209 + #define GUEST_TX_FIFO "/var/vtpm/fifos/guest-to-%d.fifo"
  31.210 + #define GUEST_RX_FIFO "/var/vtpm/fifos/guest-from-all.fifo"
  31.211 +
  31.212 + #define VTPM_TX_FIFO  "/var/vtpm/fifos/vtpm-to-%d.fifo"
  31.213 + #define VTPM_RX_FIFO  "/var/vtpm/fifos/vtpm-from-all.fifo"
  31.214 +
  31.215 + #define BE_LISTENER_THREAD 1
  31.216 + #define DMI_LISTENER_THREAD 2
  31.217 +
  31.218 + // Seconds until DMI timeout. Timeouts result in DMI being out
  31.219 + // of sync, which may require a reboot of DMI and guest to recover
  31.220 + // from. Don't set this to low. Also note that DMI may issue a TPM
  31.221 + // call so we should expect time to process at DMI + TPM processing.
  31.222 + #define DMI_TIMEOUT 90 
  31.223 +#endif
  31.224 +
  31.225 +
  31.226 +// ------------------------ Private Structures -----------------------
  31.227 +typedef struct VTPM_DMI_RESOURCE_T {
  31.228 +  // I/O info for Manager to talk to DMI's over FIFOs
  31.229 +#ifndef VTPM_MUTLI_VM
  31.230 +  int                   guest_tx_fh;          // open GUEST_TX_FIFO
  31.231 +  int                   vtpm_tx_fh;           // open VTPM_TX_FIFO
  31.232 +  char                  *guest_tx_fname;      // open GUEST_TX_FIFO
  31.233 +  char                  *vtpm_tx_fname;       // open VTPM_TX_FIFO
  31.234 +  
  31.235 +  pid_t                 dmi_pid;
  31.236 +#endif
  31.237 +  // Non-persistent Information
  31.238 +  bool                  connected;
  31.239 +  UINT32                dmi_domain_id;
  31.240 +  TCS_CONTEXT_HANDLE    TCSContext;     // TCS Handle
  31.241 +  char                  *NVMLocation;   // NULL term string indicating location
  31.242 +                                        // of NVM.
  31.243 +  // Persistent Information about DMI
  31.244 +  UINT32                dmi_id;
  31.245 +  TPM_DIGEST            NVM_measurement;  // Equal to the SHA1 of the blob
  31.246 +  TPM_DIGEST            DMI_measurement;  // Correct measurement of the owning DMI
  31.247 +} VTPM_DMI_RESOURCE;
  31.248 +
  31.249 +typedef struct tdVTPM_GLOBALS {
  31.250 +  // Non-persistent data
  31.251 +  int                 be_fh;                  // File handle to ipc used to communicate with backend
  31.252 +#ifndef VTPM_MULTI_VM
  31.253 +  int                 vtpm_rx_fh;
  31.254 +  int                 guest_rx_fh;
  31.255 +  
  31.256 +  pid_t               master_pid;
  31.257 +#endif
  31.258 +  struct hashtable    *dmi_map;               // Table of all DMI's known indexed by persistent instance #
  31.259 +#ifndef VTPM_MULTI_VM
  31.260 +  pthread_mutex_t     dmi_map_mutex;          // 
  31.261 +#endif
  31.262 +  TCS_CONTEXT_HANDLE  manager_tcs_handle;     // TCS Handle used by manager
  31.263 +  TPM_HANDLE          storageKeyHandle;       // Key used by persistent store
  31.264 +  CRYPTO_INFO         storageKey;             // For software encryption
  31.265 +  TCS_AUTH            keyAuth;                // OIAP session for storageKey 
  31.266 +  BOOL                DMI_table_dirty;        // Indicates that a command
  31.267 +                                              // has updated the DMI table
  31.268 +
  31.269 +    
  31.270 +  // Persistent Data
  31.271 +  TPM_AUTHDATA        owner_usage_auth;       // OwnerAuth of real TPM
  31.272 +  TPM_AUTHDATA        srk_usage_auth;         // SRK Auth of real TPM    
  31.273 +  buffer_t            storageKeyWrap;         // Wrapped copy of storageKey
  31.274 +
  31.275 +  TPM_AUTHDATA        storage_key_usage_auth; 
  31.276 +    
  31.277 +}VTPM_GLOBALS;
  31.278 +
  31.279 +//Global dmi map
  31.280 +extern VTPM_GLOBALS *vtpm_globals;
  31.281 +
  31.282 +// ********************** Command Handler Prototypes ***********************
  31.283 +TPM_RESULT VTPM_Handle_Load_NVM(       VTPM_DMI_RESOURCE *myDMI, 
  31.284 +                                        const buffer_t *inbuf, 
  31.285 +                                        buffer_t *outbuf);
  31.286 +
  31.287 +TPM_RESULT VTPM_Handle_Save_NVM(       VTPM_DMI_RESOURCE *myDMI, 
  31.288 +                                        const buffer_t *inbuf, 
  31.289 +                                        buffer_t *outbuf);
  31.290 +
  31.291 +TPM_RESULT VTPM_Handle_TPM_Command(    VTPM_DMI_RESOURCE *dmi, 
  31.292 +                                        buffer_t *inbuf, 
  31.293 +                                        buffer_t *outbuf);
  31.294 +
  31.295 +TPM_RESULT VTPM_Handle_New_DMI(const buffer_t *param_buf);
  31.296 +                                
  31.297 +TPM_RESULT VTPM_Handle_Close_DMI(const buffer_t *param_buf);
  31.298 +                                   
  31.299 +TPM_RESULT VTPM_Handle_Delete_DMI(const buffer_t *param_buf);
  31.300 +
  31.301 +TPM_RESULT VTPM_SaveService(void);
  31.302 +TPM_RESULT VTPM_LoadService(void);
  31.303 +
  31.304 +TPM_RESULT close_dmi( VTPM_DMI_RESOURCE *dmi_res);
  31.305 +#endif // __VTPMPRIV_H__
    32.1 --- a/tools/vtpm_manager/manager/vtsp.c	Wed Nov 30 19:54:28 2005 +0000
    32.2 +++ b/tools/vtpm_manager/manager/vtsp.c	Wed Nov 30 19:55:08 2005 +0000
    32.3 @@ -1,810 +1,810 @@
    32.4 -// ===================================================================
    32.5 -// 
    32.6 -// Copyright (c) 2005, Intel Corp.
    32.7 -// All rights reserved.
    32.8 -//
    32.9 -// Redistribution and use in source and binary forms, with or without 
   32.10 -// modification, are permitted provided that the following conditions 
   32.11 -// are met:
   32.12 -//
   32.13 -//   * Redistributions of source code must retain the above copyright 
   32.14 -//     notice, this list of conditions and the following disclaimer.
   32.15 -//   * Redistributions in binary form must reproduce the above 
   32.16 -//     copyright notice, this list of conditions and the following 
   32.17 -//     disclaimer in the documentation and/or other materials provided 
   32.18 -//     with the distribution.
   32.19 -//   * Neither the name of Intel Corporation nor the names of its 
   32.20 -//     contributors may be used to endorse or promote products derived
   32.21 -//     from this software without specific prior written permission.
   32.22 -//
   32.23 -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
   32.24 -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
   32.25 -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
   32.26 -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
   32.27 -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   32.28 -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   32.29 -// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
   32.30 -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   32.31 -// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
   32.32 -// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
   32.33 -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   32.34 -// OF THE POSSIBILITY OF SUCH DAMAGE.
   32.35 -// ===================================================================
   32.36 -// 
   32.37 -// vtsp.c
   32.38 -// 
   32.39 -//  Higher level interface to TCS for use in service.
   32.40 -//
   32.41 -// ==================================================================
   32.42 -
   32.43 -#include <string.h>
   32.44 -#include "tcg.h"
   32.45 -#include "tcs.h"
   32.46 -#include "bsg.h"
   32.47 -#include "log.h"
   32.48 -#include "crypto.h"
   32.49 -#include "vtsp.h"
   32.50 -#include "buffer.h"
   32.51 -
   32.52 -#define  RSA_KEY_SIZE 0x0800
   32.53 -
   32.54 -/***********************************************************************************
   32.55 - * GenerateAuth: Generate authorization info to be sent back to application
   32.56 - *
   32.57 - * Parameters: outParamDigestText  The concatenation of output parameters to be SHA1ed
   32.58 - *    outParamDigestTextSize Size of inParamDigestText
   32.59 - *    HMACkey     Key to be used for HMACing
   32.60 - *          For OIAP use key.authUsage or PersistStore.ownerAuth
   32.61 - *          For OSAP use shared secret
   32.62 - *    pAuth     Authorization information from the application
   32.63 - *
   32.64 - * Return:  TPM_SUCCESS   Authorization data created
   32.65 - *    TPM_AUTHFAIL   Invalid (NULL) HMACkey presented for OSAP
   32.66 - *************************************************************************************/
   32.67 -TPM_RESULT GenerateAuth( /*[IN]*/ const BYTE *inParamDigestText,
   32.68 -			 /*[IN]*/ UINT32 inParamDigestTextSize,
   32.69 -			 /*[IN]*/ const TPM_SECRET *HMACkey,  
   32.70 -			 /*[IN,OUT]*/ TCS_AUTH *auth) {
   32.71 -    
   32.72 -  if (inParamDigestText == NULL || auth == NULL) 
   32.73 -    return (TPM_AUTHFAIL);
   32.74 -  else {
   32.75 -    
   32.76 -    //Generate new OddNonce
   32.77 -    Crypto_GetRandom(auth->NonceOdd.nonce, sizeof(TPM_NONCE));
   32.78 -    
   32.79 -    // Create SHA1 inParamDigest
   32.80 -    TPM_DIGEST inParamDigest;
   32.81 -    Crypto_SHA1Full(inParamDigestText, inParamDigestTextSize, (BYTE *) &inParamDigest);
   32.82 -    
   32.83 -    // Create HMAC text. (Concat inParamsDigest with inAuthSetupParams).
   32.84 -    BYTE hmacText[sizeof(TPM_DIGEST) + (2 * sizeof(TPM_NONCE)) + sizeof(BOOL)];
   32.85 -    
   32.86 -    BSG_PackList(   hmacText, 4, 
   32.87 -		    BSG_TPM_DIGEST, &inParamDigest,
   32.88 -		    BSG_TPM_NONCE, &(auth->NonceEven),
   32.89 -		    BSG_TPM_NONCE, &(auth->NonceOdd), 
   32.90 -		    BSG_TYPE_BOOL, &(auth->fContinueAuthSession) );
   32.91 -    
   32.92 -    Crypto_HMAC((BYTE *) hmacText, sizeof(hmacText), (BYTE *) HMACkey, sizeof(TPM_DIGEST), (BYTE *) &(auth->HMAC));
   32.93 -    
   32.94 -    return(TPM_SUCCESS);
   32.95 -    
   32.96 -  }
   32.97 -}
   32.98 -
   32.99 -/***********************************************************************************
  32.100 - * VerifyAuth: Verify the authdata for a command requiring authorization
  32.101 - *
  32.102 - * Parameters: inParamDigestText  The concatenation of parameters to be SHA1ed
  32.103 - *    inParamDigestTextSize Size of inParamDigestText
  32.104 - *    authDataUsage   AuthDataUsage for the Entity being used
  32.105 - *          Key->authDataUsage or TPM_AUTH_OWNER
  32.106 - *    HMACkey     Key to be used for HMACing
  32.107 - *          For OIAP use key.authUsage or PersistStore.ownerAuth
  32.108 - *          For OSAP use NULL (It will be aquired from the Auth Session)
  32.109 - *          If unknown (default), assume OIAP
  32.110 - *    sessionAuth    A TCS_AUTH info for the session
  32.111 - *    pAuth     Authorization information from the application
  32.112 - *              hContext        If specified, on failed Auth, VerifyAuth will
  32.113 - *                                      generate a new OIAP session in place of themselves
  32.114 - *                                      destroyed session.
  32.115 - *
  32.116 - * Return:  TPM_SUCCESS   Authorization Verified
  32.117 - *    TPM_AUTHFAIL   Authorization Failed
  32.118 - *    TPM_FAIL    Failure during SHA1 routines
  32.119 - *************************************************************************************/
  32.120 -TPM_RESULT VerifyAuth( /*[IN]*/ const BYTE *outParamDigestText,
  32.121 -		       /*[IN]*/ UINT32 outParamDigestTextSize,
  32.122 -		       /*[IN]*/ const TPM_SECRET *HMACkey,  
  32.123 -		       /*[IN,OUT]*/ TCS_AUTH *auth,
  32.124 -		       /*[IN]*/  TCS_CONTEXT_HANDLE hContext) {
  32.125 -  if (outParamDigestText == NULL || auth == NULL) 
  32.126 -    return (TPM_AUTHFAIL);
  32.127 -  
  32.128 -  
  32.129 -  // Create SHA1 inParamDigest
  32.130 -  TPM_DIGEST outParamDigest;
  32.131 -  Crypto_SHA1Full(outParamDigestText, outParamDigestTextSize, (BYTE *) &outParamDigest);
  32.132 -  
  32.133 -  // Create HMAC text. (Concat inParamsDigest with inAuthSetupParams).
  32.134 -  TPM_DIGEST hm;
  32.135 -  BYTE hmacText[sizeof(TPM_DIGEST) + (2 * sizeof(TPM_NONCE)) + sizeof(BOOL)];
  32.136 -  
  32.137 -  BSG_PackList(   hmacText, 4, 
  32.138 -		  BSG_TPM_DIGEST, &outParamDigest,
  32.139 -		  BSG_TPM_NONCE, &(auth->NonceEven),
  32.140 -		  BSG_TPM_NONCE, &(auth->NonceOdd), 
  32.141 -		  BSG_TYPE_BOOL, &(auth->fContinueAuthSession) );
  32.142 -  
  32.143 -  Crypto_HMAC((BYTE *) hmacText, sizeof(hmacText),
  32.144 -	      (BYTE *) HMACkey, sizeof(TPM_DIGEST), (BYTE *) &hm);
  32.145 -    
  32.146 -  // Compare correct HMAC with provided one.
  32.147 -  if (memcmp (&hm, &(auth->HMAC), sizeof(TPM_DIGEST)) == 0)  // 0 indicates equality
  32.148 -    return (TPM_SUCCESS);
  32.149 -  else {
  32.150 -    VTSP_OIAP( hContext, auth);
  32.151 -    return (TPM_AUTHFAIL);
  32.152 -  }
  32.153 -}
  32.154 -
  32.155 -TPM_RESULT VTSP_OIAP(const TCS_CONTEXT_HANDLE hContext,
  32.156 -		     TCS_AUTH *auth) {
  32.157 -  
  32.158 -  vtpmloginfo(VTPM_LOG_VTSP, "OIAP.\n");
  32.159 -  TPM_RESULT status = TPM_SUCCESS;                           
  32.160 -  TPMTRYRETURN( TCSP_OIAP(hContext,
  32.161 -			  &auth->AuthHandle,
  32.162 -			  &auth->NonceEven) );
  32.163 -  goto egress;
  32.164 -  
  32.165 - abort_egress:
  32.166 -  
  32.167 - egress:
  32.168 -  
  32.169 -  return status;
  32.170 -}
  32.171 -
  32.172 -TPM_RESULT VTSP_OSAP(const TCS_CONTEXT_HANDLE hContext,
  32.173 -		     const TPM_ENTITY_TYPE entityType,
  32.174 -		     const UINT32 entityValue,
  32.175 -		     const TPM_AUTHDATA *usageAuth,
  32.176 -		     TPM_SECRET *sharedSecret, 
  32.177 -		     TCS_AUTH *auth) {
  32.178 -  
  32.179 -  vtpmloginfo(VTPM_LOG_VTSP, "OSAP.\n");
  32.180 -  TPM_RESULT status = TPM_SUCCESS;
  32.181 -  TPM_NONCE nonceEvenOSAP, nonceOddOSAP;
  32.182 -  
  32.183 -  Crypto_GetRandom((BYTE *) &nonceOddOSAP, sizeof(TPM_NONCE) ); 
  32.184 -  
  32.185 -  TPMTRYRETURN( TCSP_OSAP(    hContext,
  32.186 -			      entityType,
  32.187 -			      entityValue, 
  32.188 -			      nonceOddOSAP,
  32.189 -			      &auth->AuthHandle, 
  32.190 -			      &auth->NonceEven, 
  32.191 -			      &nonceEvenOSAP) );
  32.192 -  
  32.193 -  // Calculating Session Secret
  32.194 -  BYTE sharedSecretText[TPM_DIGEST_SIZE * 2];
  32.195 -  
  32.196 -  BSG_PackList(  sharedSecretText, 2,
  32.197 -		 BSG_TPM_NONCE, &nonceEvenOSAP,
  32.198 -		 BSG_TPM_NONCE, &nonceOddOSAP);
  32.199 -  
  32.200 -  Crypto_HMAC(sharedSecretText, sizeof(sharedSecretText), (BYTE *) usageAuth, TPM_DIGEST_SIZE, (BYTE *) sharedSecret);       
  32.201 -    
  32.202 -  goto egress;
  32.203 -  
  32.204 - abort_egress:
  32.205 -  
  32.206 - egress:
  32.207 -  
  32.208 -  return status;
  32.209 -}
  32.210 -
  32.211 -
  32.212 -
  32.213 -TPM_RESULT VTSP_ReadPubek(   const TCS_CONTEXT_HANDLE hContext,
  32.214 -                             CRYPTO_INFO *crypto_info) {
  32.215 -  
  32.216 -  TPM_RESULT status;
  32.217 -  TPM_NONCE antiReplay;
  32.218 -  TPM_DIGEST   checksum;
  32.219 -  BYTE *pubEKtext;
  32.220 -  UINT32 pubEKtextsize;
  32.221 -  
  32.222 -  vtpmloginfo(VTPM_LOG_VTSP, "Reading Public EK.\n");
  32.223 -  
  32.224 -  // GenerateAuth new nonceOdd    
  32.225 -  Crypto_GetRandom(&antiReplay, sizeof(TPM_NONCE) );
  32.226 -  
  32.227 -  
  32.228 -  TPMTRYRETURN( TCSP_ReadPubek(  hContext,
  32.229 -				 antiReplay,
  32.230 -				 &pubEKtextsize,
  32.231 -				 &pubEKtext,
  32.232 -				 &checksum) );
  32.233 -  
  32.234 -  
  32.235 -  // Extract the remaining output parameters
  32.236 -  TPM_PUBKEY pubEK;
  32.237 -  
  32.238 -  BSG_Unpack(BSG_TPM_PUBKEY, pubEKtext, (BYTE *) &pubEK);
  32.239 -  
  32.240 -  // Build CryptoInfo for the bindingKey
  32.241 -  TPM_RSA_KEY_PARMS rsaKeyParms;
  32.242 -  
  32.243 -  BSG_Unpack(BSG_TPM_RSA_KEY_PARMS, 
  32.244 -	     pubEK.algorithmParms.parms, 
  32.245 -	     &rsaKeyParms);
  32.246 -  
  32.247 -  Crypto_RSABuildCryptoInfoPublic(rsaKeyParms.exponentSize, 
  32.248 -				  rsaKeyParms.exponent, 
  32.249 -				  pubEK.pubKey.keyLength, 
  32.250 -				  pubEK.pubKey.key, 
  32.251 -				  crypto_info);
  32.252 -    
  32.253 -  // Destroy rsaKeyParms
  32.254 -  BSG_Destroy(BSG_TPM_RSA_KEY_PARMS, &rsaKeyParms);
  32.255 -
  32.256 -  // Set encryption scheme
  32.257 -  crypto_info->encScheme = CRYPTO_ES_RSAESOAEP_SHA1_MGF1;
  32.258 -  //crypto_info->encScheme = pubEK.algorithmParms.encScheme;
  32.259 -  crypto_info->algorithmID = pubEK.algorithmParms.algorithmID;
  32.260 -  
  32.261 -  goto egress;
  32.262 -  
  32.263 - abort_egress:
  32.264 -  
  32.265 - egress:
  32.266 -  
  32.267 -  return status;
  32.268 -}
  32.269 -
  32.270 -TPM_RESULT VTSP_TakeOwnership(   const TCS_CONTEXT_HANDLE hContext,
  32.271 -                                 const TPM_AUTHDATA *ownerAuth, 
  32.272 -                                 const TPM_AUTHDATA *srkAuth,
  32.273 -                                 CRYPTO_INFO *ek_cryptoInfo,
  32.274 -                                 TCS_AUTH *auth) {
  32.275 -  
  32.276 -  vtpmloginfo(VTPM_LOG_VTSP, "Taking Ownership of TPM.\n");
  32.277 -  
  32.278 -  TPM_RESULT status = TPM_SUCCESS;
  32.279 -  TPM_COMMAND_CODE command = TPM_ORD_TakeOwnership;
  32.280 -  TPM_PROTOCOL_ID proto_id = TPM_PID_OWNER;
  32.281 -  BYTE *new_srk;
  32.282 -  
  32.283 -  BYTE *paramText;        // Digest to make Auth.
  32.284 -  UINT32 paramTextSize;
  32.285 -  
  32.286 -  // vars for srkpubkey parameter
  32.287 -  TPM_KEY srkPub;
  32.288 -  TPM_KEY_PARMS srkKeyInfo = {TPM_ALG_RSA, TPM_ES_RSAESOAEP_SHA1_MGF1, TPM_SS_NONE, 12, 0};
  32.289 -  BYTE srkRSAkeyInfo[12] = { 0x00, 0x00, (RSA_KEY_SIZE >> 8), 0x00,   0x00, 0x00, 0x00, 0x02,   0x00, 0x00, 0x00, 0x00};
  32.290 -  srkKeyInfo.parms = (BYTE *) &srkRSAkeyInfo;
  32.291 -  
  32.292 -  struct pack_buf_t srkText;
  32.293 -  
  32.294 -  // GenerateAuth new nonceOdd    
  32.295 -  Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
  32.296 -  
  32.297 -  //These values are accurate for an enc(AuthData).
  32.298 -  struct pack_buf_t encOwnerAuth, encSrkAuth;
  32.299 -  
  32.300 -  encOwnerAuth.data = (BYTE *)malloc(sizeof(BYTE) * 256);
  32.301 -  encSrkAuth.data = (BYTE *)malloc(sizeof(BYTE) * 256);
  32.302 -  
  32.303 -  if (encOwnerAuth.data == NULL || encSrkAuth.data == NULL) {
  32.304 -    vtpmloginfo(VTPM_LOG_VTSP, "Could not malloc encrypted auths.\n");
  32.305 -    status = TPM_RESOURCES;
  32.306 -    goto abort_egress;
  32.307 -  }
  32.308 -  
  32.309 -  Crypto_RSAEnc(ek_cryptoInfo, sizeof(TPM_SECRET), (BYTE *) ownerAuth, &encOwnerAuth.size, encOwnerAuth.data);
  32.310 -  Crypto_RSAEnc(ek_cryptoInfo, sizeof(TPM_SECRET), (BYTE *) srkAuth, &encSrkAuth.size, encSrkAuth.data);
  32.311 -  
  32.312 -  
  32.313 -  // Build srk public key struct
  32.314 -  srkPub.ver = TPM_STRUCT_VER_1_1;
  32.315 -  srkPub.keyUsage = TPM_KEY_STORAGE;
  32.316 -  srkPub.keyFlags = 0x00;
  32.317 -  srkPub.authDataUsage = TPM_AUTH_ALWAYS;
  32.318 -  memcpy(&srkPub.algorithmParms, &srkKeyInfo, sizeof(TPM_KEY_PARMS));
  32.319 -  srkPub.PCRInfoSize = 0;
  32.320 -  srkPub.PCRInfo = 0;
  32.321 -  srkPub.pubKey.keyLength= 0;
  32.322 -  srkPub.encDataSize = 0;
  32.323 -  
  32.324 -  srkText.data = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
  32.325 -  srkText.size = BSG_Pack(BSG_TPM_KEY, (BYTE *) &srkPub, srkText.data);
  32.326 -  
  32.327 -  paramText = (BYTE *) malloc(sizeof(BYTE) *  TCPA_MAX_BUFFER_LENGTH);
  32.328 -  
  32.329 -  paramTextSize = BSG_PackList(paramText, 5,
  32.330 -			       BSG_TPM_COMMAND_CODE,&command,
  32.331 -			       BSG_TPM_PROTOCOL_ID, &proto_id,
  32.332 -			       BSG_TPM_SIZE32_DATA, &encOwnerAuth,
  32.333 -			       BSG_TPM_SIZE32_DATA, &encSrkAuth,
  32.334 -			       BSG_TPM_KEY, &srkPub);
  32.335 -  
  32.336 -  TPMTRYRETURN( GenerateAuth( paramText, paramTextSize, ownerAuth, auth) );
  32.337 -  
  32.338 -  new_srk = srkText.data;
  32.339 -  TPMTRYRETURN( TCSP_TakeOwnership ( hContext,
  32.340 -				     proto_id,
  32.341 -				     encOwnerAuth.size, 
  32.342 -				     encOwnerAuth.data,
  32.343 -				     encSrkAuth.size,
  32.344 -				     encSrkAuth.data,
  32.345 -				     &srkText.size,
  32.346 -				     &new_srk, 
  32.347 -				     auth ) );
  32.348 -  
  32.349 -  
  32.350 -  paramTextSize = BSG_PackList(paramText, 2, 
  32.351 -			       BSG_TPM_RESULT, &status,
  32.352 -			       BSG_TPM_COMMAND_CODE, &command);
  32.353 -  memcpy(paramText + paramTextSize, new_srk, srkText.size);
  32.354 -  paramTextSize += srkText.size;
  32.355 -  
  32.356 -  
  32.357 -  TPMTRYRETURN( VerifyAuth(  paramText, paramTextSize,
  32.358 -			     ownerAuth, auth, 
  32.359 -			     hContext) );
  32.360 -  
  32.361 -  goto egress;
  32.362 -  
  32.363 - abort_egress:
  32.364 -  
  32.365 - egress:
  32.366 -  
  32.367 -  free(srkText.data);
  32.368 -  free(encSrkAuth.data);
  32.369 -  free(encOwnerAuth.data);
  32.370 -  free(paramText);
  32.371 -  
  32.372 -  TCS_FreeMemory(hContext, new_srk);
  32.373 -  
  32.374 -  return status;
  32.375 -}
  32.376 -
  32.377 -TPM_RESULT VTSP_DisablePubekRead( const TCS_CONTEXT_HANDLE    hContext,
  32.378 -                                  const TPM_AUTHDATA          *ownerAuth, 
  32.379 -                                  TCS_AUTH                    *auth) {
  32.380 -  
  32.381 -  vtpmloginfo(VTPM_LOG_VTSP, "Disabling Pubek Read.\n");
  32.382 -  
  32.383 -  TPM_RESULT status = TPM_SUCCESS;
  32.384 -  TPM_COMMAND_CODE command = TPM_ORD_DisablePubekRead;
  32.385 -  
  32.386 -  BYTE *paramText;        // Digest to make Auth.
  32.387 -  UINT32 paramTextSize;
  32.388 -    
  32.389 -  // Generate HMAC   
  32.390 -  Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
  32.391 -  
  32.392 -  paramText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
  32.393 -  
  32.394 -  paramTextSize = BSG_PackList(paramText, 1,
  32.395 -			       BSG_TPM_COMMAND_CODE, &command);
  32.396 -  
  32.397 -  TPMTRYRETURN( GenerateAuth( paramText, paramTextSize,
  32.398 -			      ownerAuth, auth) );
  32.399 -  
  32.400 -  // Call TCS
  32.401 -  TPMTRYRETURN( TCSP_DisablePubekRead ( hContext, // in
  32.402 -                                        auth) );
  32.403 -  
  32.404 -  // Verify Auth
  32.405 -  paramTextSize = BSG_PackList(paramText, 2,
  32.406 -			       BSG_TPM_RESULT, &status,
  32.407 -			       BSG_TPM_COMMAND_CODE, &command);
  32.408 -  
  32.409 -  TPMTRYRETURN( VerifyAuth( paramText, paramTextSize,
  32.410 -			    ownerAuth, auth, 
  32.411 -			    hContext) );
  32.412 -  goto egress;
  32.413 -  
  32.414 - abort_egress:
  32.415 - egress:
  32.416 -  free(paramText);
  32.417 -  return status;
  32.418 -}
  32.419 -
  32.420 -TPM_RESULT VTSP_CreateWrapKey(  const TCS_CONTEXT_HANDLE hContext,
  32.421 -                                const TPM_KEY_USAGE      usage,
  32.422 -                                const TPM_AUTHDATA       *newKeyAuth,
  32.423 -                                const TCS_KEY_HANDLE     parentHandle, 
  32.424 -                                const TPM_AUTHDATA       *osapSharedSecret,
  32.425 -                                buffer_t                 *pubKeyBuf,
  32.426 -                                TCS_AUTH                 *auth) {
  32.427 -  
  32.428 -  int i;
  32.429 -  TPM_RESULT status = TPM_SUCCESS;
  32.430 -  TPM_COMMAND_CODE command = TPM_ORD_CreateWrapKey;
  32.431 -  
  32.432 -  vtpmloginfo(VTPM_LOG_VTSP, "Creating new key of type %d.\n", usage);
  32.433 -  
  32.434 -  // vars for Calculate encUsageAuth
  32.435 -  BYTE *paramText;      
  32.436 -  UINT32 paramTextSize;
  32.437 -  
  32.438 -  // vars for Calculate encUsageAuth
  32.439 -  BYTE XORbuffer[sizeof(TPM_SECRET) + sizeof(TPM_NONCE)];
  32.440 -  TPM_DIGEST XORKey1;
  32.441 -  UINT32 XORbufferSize;
  32.442 -  TPM_SECRET encUsageAuth, encMigrationAuth;
  32.443 -  
  32.444 -  // vars for Flatten newKey prototype
  32.445 -  BYTE *flatKey = (BYTE *) malloc(sizeof(BYTE) *  TCPA_MAX_BUFFER_LENGTH);
  32.446 -  UINT32 flatKeySize = TCPA_MAX_BUFFER_LENGTH;                                    
  32.447 -  struct pack_buf_t newKeyText;
  32.448 -  
  32.449 -  // Fill in newKey
  32.450 -  TPM_KEY newKey;
  32.451 -  
  32.452 -  BYTE RSAkeyInfo[12] = { 0x00, 0x00, (RSA_KEY_SIZE >> 8), 0x00,   0x00, 0x00, 0x00, 0x02,   0x00, 0x00, 0x00, 0x00};
  32.453 -  newKey.algorithmParms.algorithmID = TPM_ALG_RSA;
  32.454 -  newKey.algorithmParms.parms = (BYTE *) &RSAkeyInfo;
  32.455 -  newKey.algorithmParms.parmSize = 12;
  32.456 -  
  32.457 -  switch (usage) {
  32.458 -  case TPM_KEY_SIGNING:
  32.459 -    vtpmloginfo(VTPM_LOG_VTSP, "Creating Signing Key...\n");
  32.460 -    newKey.keyUsage = TPM_KEY_SIGNING;
  32.461 -    newKey.algorithmParms.encScheme = TPM_ES_NONE;
  32.462 -    newKey.algorithmParms.sigScheme = TPM_SS_RSASSAPKCS1v15_SHA1;
  32.463 -    break;
  32.464 -  case TPM_KEY_STORAGE:
  32.465 -    vtpmloginfo(VTPM_LOG_VTSP, "Creating Storage Key...\n");
  32.466 -    newKey.keyUsage = TPM_KEY_STORAGE;
  32.467 -    newKey.algorithmParms.encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1;
  32.468 -    newKey.algorithmParms.sigScheme = TPM_SS_NONE;
  32.469 -    break;
  32.470 -  case TPM_KEY_BIND:
  32.471 -    vtpmloginfo(VTPM_LOG_VTSP, "Creating Binding Key...\n");
  32.472 -    newKey.keyUsage = TPM_KEY_BIND;
  32.473 -    newKey.algorithmParms.encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1;
  32.474 -    newKey.algorithmParms.sigScheme = TPM_SS_NONE;
  32.475 -    break;
  32.476 -  default:
  32.477 -    vtpmloginfo(VTPM_LOG_VTSP, "Cannot create key. Invalid Key Type.\n");
  32.478 -    status = TPM_BAD_PARAMETER;
  32.479 -    goto abort_egress;
  32.480 -  }
  32.481 -  
  32.482 -  
  32.483 -  newKey.ver = TPM_STRUCT_VER_1_1;
  32.484 -  
  32.485 -  newKey.keyFlags = 0;
  32.486 -  newKey.authDataUsage = TPM_AUTH_ALWAYS;
  32.487 -  newKey.pubKey.keyLength= 0;
  32.488 -  newKey.encDataSize = 0;
  32.489 -  newKey.encData = NULL;
  32.490 -  
  32.491 -  // FIXME: Support PCR bindings
  32.492 -  newKey.PCRInfoSize = 0;
  32.493 -  newKey.PCRInfo = NULL;
  32.494 -  
  32.495 -  // Calculate encUsageAuth                                    
  32.496 -  XORbufferSize = BSG_PackList(  XORbuffer, 2, 
  32.497 -				 BSG_TPM_SECRET, osapSharedSecret,
  32.498 -				 BSG_TPM_NONCE, &auth->NonceEven);
  32.499 -  Crypto_SHA1Full(XORbuffer, XORbufferSize, (BYTE *) &XORKey1);
  32.500 -  
  32.501 -  // FIXME: No support for migratable keys.
  32.502 -  for (i=0; i < TPM_DIGEST_SIZE; i++) 
  32.503 -    ((BYTE *) &encUsageAuth)[i] = ((BYTE *) &XORKey1)[i] ^ ((BYTE *) newKeyAuth)[i];
  32.504 -  
  32.505 -  // Flatten newKey prototype
  32.506 -  flatKeySize = BSG_Pack(BSG_TPM_KEY, (BYTE *) &newKey, flatKey);
  32.507 -  newKeyText.data = flatKey;
  32.508 -  newKeyText.size = flatKeySize;
  32.509 -  
  32.510 -  // GenerateAuth new nonceOdd    
  32.511 -  Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
  32.512 -  
  32.513 -  // Generate HMAC
  32.514 -  paramText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
  32.515 -  
  32.516 -  paramTextSize = BSG_PackList(paramText, 3,
  32.517 -			       BSG_TPM_COMMAND_CODE, &command,
  32.518 -			       BSG_TPM_AUTHDATA, &encUsageAuth,
  32.519 -			       BSG_TPM_AUTHDATA, &encMigrationAuth);
  32.520 -  memcpy(paramText + paramTextSize, newKeyText.data, newKeyText.size);
  32.521 -  paramTextSize += newKeyText.size;
  32.522 -  
  32.523 -  
  32.524 -  TPMTRYRETURN( GenerateAuth( paramText, paramTextSize,
  32.525 -			      osapSharedSecret, auth) );
  32.526 -  
  32.527 -  // Call TCS
  32.528 -  TPMTRYRETURN( TCSP_CreateWrapKey(  hContext, 
  32.529 -				     parentHandle,
  32.530 -				     encUsageAuth,
  32.531 -				     encMigrationAuth,
  32.532 -				     &newKeyText.size,
  32.533 -				     &newKeyText.data,
  32.534 -				     auth) );
  32.535 -  
  32.536 -  // Verify Auth
  32.537 -  paramTextSize = BSG_PackList(paramText, 2,
  32.538 -			       BSG_TPM_RESULT, &status,
  32.539 -			       BSG_TPM_COMMAND_CODE, &command);
  32.540 -  memcpy(paramText + paramTextSize, newKeyText.data, newKeyText.size);
  32.541 -  paramTextSize += newKeyText.size;
  32.542 -  
  32.543 -  TPMTRYRETURN( VerifyAuth( paramText, paramTextSize,
  32.544 -			    osapSharedSecret, auth, 0) );
  32.545 -  
  32.546 -  // Unpack/return key structure
  32.547 -  TPMTRYRETURN(buffer_init(pubKeyBuf, 0, 0) );
  32.548 -  TPMTRYRETURN(buffer_append_raw(pubKeyBuf, newKeyText.size, newKeyText.data) );
  32.549 -  
  32.550 -  goto egress;
  32.551 -  
  32.552 - abort_egress:
  32.553 -  
  32.554 - egress:
  32.555 -  
  32.556 -  free(flatKey);
  32.557 -  free(paramText);
  32.558 -  TCS_FreeMemory(hContext, newKeyText.data);
  32.559 -  
  32.560 -  return status;
  32.561 -}
  32.562 -
  32.563 -TPM_RESULT VTSP_LoadKey(const TCS_CONTEXT_HANDLE    hContext,
  32.564 -                        const TCS_KEY_HANDLE        hUnwrappingKey,
  32.565 -                        const buffer_t              *rgbWrappedKeyBlob,
  32.566 -                        const TPM_AUTHDATA          *parentAuth,
  32.567 -                        TPM_HANDLE                  *newKeyHandle,
  32.568 -                        TCS_AUTH                    *auth,
  32.569 -                        CRYPTO_INFO                 *cryptoinfo /*= NULL*/) {
  32.570 -  
  32.571 -  
  32.572 -  vtpmloginfo(VTPM_LOG_VTSP, "Loading Key.\n%s","");
  32.573 -  
  32.574 -  TPM_RESULT status = TPM_SUCCESS;
  32.575 -  TPM_COMMAND_CODE command = TPM_ORD_LoadKey;
  32.576 -  
  32.577 -  BYTE *paramText;        // Digest to make Auth.
  32.578 -  UINT32 paramTextSize;
  32.579 -  
  32.580 -  if ((rgbWrappedKeyBlob == NULL) || (parentAuth == NULL) || 
  32.581 -      (newKeyHandle==NULL) || (auth==NULL)) {
  32.582 -    status = TPM_BAD_PARAMETER;
  32.583 -    goto abort_egress;
  32.584 -  }
  32.585 -  
  32.586 -  // Generate Extra TCS Parameters
  32.587 -  TPM_HANDLE phKeyHMAC;
  32.588 -  
  32.589 -  // Generate HMAC
  32.590 -  Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
  32.591 -  
  32.592 -  paramText = (BYTE *) malloc(sizeof(BYTE) *  TCPA_MAX_BUFFER_LENGTH);
  32.593 -  
  32.594 -  paramTextSize = BSG_PackList(paramText, 1,
  32.595 -			       BSG_TPM_COMMAND_CODE, &command);
  32.596 -  
  32.597 -  memcpy(paramText + paramTextSize, rgbWrappedKeyBlob->bytes, buffer_len(rgbWrappedKeyBlob));
  32.598 -  paramTextSize += buffer_len(rgbWrappedKeyBlob);
  32.599 -  
  32.600 -  TPMTRYRETURN( GenerateAuth( paramText, paramTextSize,
  32.601 -			      parentAuth, auth) );
  32.602 -  
  32.603 -  // Call TCS
  32.604 -  TPMTRYRETURN( TCSP_LoadKeyByBlob(  hContext,
  32.605 -				     hUnwrappingKey,
  32.606 -				     buffer_len(rgbWrappedKeyBlob),
  32.607 -				     rgbWrappedKeyBlob->bytes,
  32.608 -				     auth,
  32.609 -				     newKeyHandle,
  32.610 -				     &phKeyHMAC) );
  32.611 -  
  32.612 -  // Verify Auth
  32.613 -  paramTextSize = BSG_PackList(paramText, 3,
  32.614 -			       BSG_TPM_RESULT, &status,
  32.615 -			       BSG_TPM_COMMAND_CODE, &command,
  32.616 -			       BSG_TPM_HANDLE, newKeyHandle);
  32.617 -  
  32.618 -  TPMTRYRETURN( VerifyAuth( paramText, paramTextSize,
  32.619 -			    parentAuth, auth, 
  32.620 -			    hContext) );
  32.621 -  
  32.622 -  // Unpack/return key structure
  32.623 -  if (cryptoinfo != NULL) {
  32.624 -    TPM_KEY newKey;
  32.625 -    
  32.626 -    BSG_Unpack(BSG_TPM_KEY, rgbWrappedKeyBlob->bytes , &newKey);
  32.627 -    TPM_RSA_KEY_PARMS rsaKeyParms;
  32.628 -    
  32.629 -    BSG_Unpack(BSG_TPM_RSA_KEY_PARMS, 
  32.630 -	       newKey.algorithmParms.parms, 
  32.631 -	       &rsaKeyParms);
  32.632 -    
  32.633 -    Crypto_RSABuildCryptoInfoPublic(rsaKeyParms.exponentSize, 
  32.634 -				    rsaKeyParms.exponent, 
  32.635 -				    newKey.pubKey.keyLength, 
  32.636 -				    newKey.pubKey.key, 
  32.637 -				    cryptoinfo);
  32.638 -    
  32.639 -    // Destroy rsaKeyParms
  32.640 -    BSG_Destroy(BSG_TPM_RSA_KEY_PARMS, &rsaKeyParms);
  32.641 -    
  32.642 -    // Set encryption scheme
  32.643 -    cryptoinfo->encScheme = CRYPTO_ES_RSAESOAEP_SHA1_MGF1;
  32.644 -  }
  32.645 -  
  32.646 -  goto egress;
  32.647 -  
  32.648 - abort_egress:
  32.649 -  
  32.650 - egress:
  32.651 -  
  32.652 -  free(paramText);
  32.653 -  return status;
  32.654 -}
  32.655 -
  32.656 -TPM_RESULT VTSP_Unbind( const TCS_CONTEXT_HANDLE    hContext,
  32.657 -                        const TPM_KEY_HANDLE        key_handle,
  32.658 -                        const buffer_t              *bound_data,
  32.659 -                        const TPM_AUTHDATA          *usage_auth,
  32.660 -                        buffer_t                    *clear_data,
  32.661 -                        TCS_AUTH                    *auth) {
  32.662 -  
  32.663 -  vtpmloginfo(VTPM_LOG_VTSP, "Unbinding %d bytes of data.\n", buffer_len(bound_data));
  32.664 -  
  32.665 -  TPM_RESULT status = TPM_SUCCESS;
  32.666 -  TPM_COMMAND_CODE command = TPM_ORD_UnBind;
  32.667 -  
  32.668 -  BYTE *paramText;        // Digest to make Auth.
  32.669 -  UINT32 paramTextSize;
  32.670 -  
  32.671 -  // Generate Extra TCS Parameters
  32.672 -  struct pack_buf_t clear_data32;
  32.673 -  BYTE *clear_data_text;
  32.674 -  UINT32 clear_data_size;
  32.675 -  
  32.676 -  // Generate HMAC   
  32.677 -  Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
  32.678 -  
  32.679 -  struct pack_buf_t bound_data32 = {bound_data->size, bound_data->bytes};
  32.680 -  
  32.681 -  paramText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
  32.682 -  
  32.683 -  paramTextSize = BSG_PackList(paramText, 2,
  32.684 -			       BSG_TPM_COMMAND_CODE, &command,
  32.685 -			       BSG_TPM_SIZE32_DATA, &bound_data32);
  32.686 -  
  32.687 -  TPMTRYRETURN( GenerateAuth( paramText, paramTextSize,
  32.688 -			      usage_auth, auth) );
  32.689 -  
  32.690 -  // Call TCS
  32.691 -  TPMTRYRETURN( TCSP_UnBind( hContext,
  32.692 -			     key_handle,
  32.693 -			     buffer_len(bound_data),
  32.694 -			     bound_data->bytes,
  32.695 -			     auth,
  32.696 -			     &clear_data_size,
  32.697 -			     &clear_data_text) );
  32.698 -  
  32.699 -  
  32.700 -  // Verify Auth
  32.701 -  clear_data32.size = clear_data_size;
  32.702 -  clear_data32.data = clear_data_text;
  32.703 -  paramTextSize = BSG_PackList(paramText, 3,
  32.704 -			       BSG_TPM_RESULT, &status,
  32.705 -			       BSG_TPM_COMMAND_CODE, &command,
  32.706 -			       BSG_TPM_SIZE32_DATA, &clear_data32);
  32.707 -  
  32.708 -  TPMTRYRETURN( VerifyAuth( paramText, paramTextSize,
  32.709 -			    usage_auth, auth, 
  32.710 -			    hContext) );
  32.711 -  
  32.712 -  // Unpack/return key structure
  32.713 -  TPMTRYRETURN(buffer_init(clear_data, 0, 0));
  32.714 -  TPMTRYRETURN(buffer_append_raw (clear_data, clear_data_size, clear_data_text) );
  32.715 -  
  32.716 -  goto egress;
  32.717 -  
  32.718 - abort_egress:
  32.719 -  
  32.720 - egress:
  32.721 -  
  32.722 -  free(paramText);
  32.723 -  TCS_FreeMemory(hContext, clear_data_text);
  32.724 -  
  32.725 -  return status;
  32.726 -}
  32.727 -
  32.728 -TPM_RESULT VTSP_Bind(   CRYPTO_INFO *cryptoInfo, 
  32.729 -			const buffer_t *inData, 
  32.730 -			buffer_t *outData)               
  32.731 -{
  32.732 -  vtpmloginfo(VTPM_LOG_VTSP, "Binding %d bytes of data.\n", buffer_len(inData));
  32.733 -  TPM_BOUND_DATA boundData;
  32.734 -  UINT32 i;
  32.735 -  
  32.736 -  // Fill boundData's accessory information
  32.737 -  boundData.ver = TPM_STRUCT_VER_1_1;
  32.738 -  boundData.payload = TPM_PT_BIND;
  32.739 -  boundData.payloadData = inData->bytes;
  32.740 -  
  32.741 -  // Pack boundData before encryption
  32.742 -  BYTE* flatBoundData = (BYTE *)malloc(sizeof(BYTE) * 
  32.743 -				       (sizeof(TPM_VERSION) +
  32.744 -					sizeof(TPM_PAYLOAD_TYPE) +
  32.745 -					buffer_len(inData)));
  32.746 -  if (flatBoundData == NULL) {
  32.747 -    return TPM_NOSPACE;
  32.748 -  }
  32.749 -  UINT32 flatBoundDataSize = 0;
  32.750 -  flatBoundDataSize = BSG_PackList(  flatBoundData, 2, 
  32.751 -				     BSG_TPM_VERSION, &boundData.ver, 
  32.752 -				     BSG_TYPE_BYTE, &boundData.payload);
  32.753 -  
  32.754 -  memcpy(flatBoundData+flatBoundDataSize, inData->bytes, buffer_len(inData));
  32.755 -  flatBoundDataSize += buffer_len(inData);
  32.756 -  
  32.757 -  BYTE out_tmp[RSA_KEY_SIZE/8]; // RSAEnc does not do blocking, So this is what will come out.
  32.758 -  UINT32 out_tmp_size;
  32.759 -  
  32.760 -  // Encrypt flatBoundData
  32.761 -  Crypto_RSAEnc( cryptoInfo, 
  32.762 -		 flatBoundDataSize, 
  32.763 -		 flatBoundData, 
  32.764 -		 &out_tmp_size, 
  32.765 -		 out_tmp);
  32.766 -  
  32.767 -  if (out_tmp_size > RSA_KEY_SIZE/8) {
  32.768 -    // The result of RSAEnc should be a fixed size based on key size.
  32.769 -    vtpmlogerror(VTPM_LOG_VTSP, "Enc buffer just overflowed.\n");
  32.770 -  }
  32.771 -  
  32.772 -  buffer_init(outData, 0, NULL);
  32.773 -  buffer_append_raw(outData, out_tmp_size, out_tmp);
  32.774 -  
  32.775 -  vtpmloginfo(VTPM_LOG_TXDATA, "Bind Generated[%d] = 0x", out_tmp_size);
  32.776 -  for(i = 0 ; i < out_tmp_size ; i++) {
  32.777 -    vtpmloginfomore(VTPM_LOG_TXDATA, "%2.2x ", out_tmp[i]);
  32.778 -  }
  32.779 -  vtpmloginfomore(VTPM_LOG_TXDATA, "\n");
  32.780 -  
  32.781 -  // Free flatBoundData
  32.782 -  free(flatBoundData);
  32.783 -  
  32.784 -  return TPM_SUCCESS;
  32.785 -}
  32.786 -
  32.787 -// Function Reaches into unsupported TCS command, beware.
  32.788 -TPM_RESULT VTSP_RawTransmit(const TCS_CONTEXT_HANDLE    hContext,
  32.789 -                            const buffer_t *inbuf,
  32.790 -                            buffer_t *outbuf ) {
  32.791 -  
  32.792 -  vtpmloginfo(VTPM_LOG_VTSP, "Passthrough in use.\n");
  32.793 -  TPM_RESULT status = TPM_SUCCESS;
  32.794 -  
  32.795 -  // Generate Extra TCS Parameters
  32.796 -  BYTE *resultText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
  32.797 -  UINT32 resultTextSize =  TCPA_MAX_BUFFER_LENGTH;
  32.798 -  
  32.799 -  // Call TCS                          
  32.800 -  TPMTRYRETURN( TCSP_RawTransmitData(buffer_len(inbuf), inbuf->bytes, 
  32.801 -				     &resultTextSize, resultText) );
  32.802 -  
  32.803 -  // Unpack/return key structure
  32.804 -  TPMTRYRETURN(buffer_init (outbuf, resultTextSize, resultText) );                                
  32.805 -  goto egress;
  32.806 -  
  32.807 - abort_egress:
  32.808 -  
  32.809 - egress:
  32.810 -  TCS_FreeMemory(hContext, resultText);
  32.811 -  free(resultText);
  32.812 -  return status;
  32.813 -}
  32.814 +// ===================================================================
  32.815 +// 
  32.816 +// Copyright (c) 2005, Intel Corp.
  32.817 +// All rights reserved.
  32.818 +//
  32.819 +// Redistribution and use in source and binary forms, with or without 
  32.820 +// modification, are permitted provided that the following conditions 
  32.821 +// are met:
  32.822 +//
  32.823 +//   * Redistributions of source code must retain the above copyright 
  32.824 +//     notice, this list of conditions and the following disclaimer.
  32.825 +//   * Redistributions in binary form must reproduce the above 
  32.826 +//     copyright notice, this list of conditions and the following 
  32.827 +//     disclaimer in the documentation and/or other materials provided 
  32.828 +//     with the distribution.
  32.829 +//   * Neither the name of Intel Corporation nor the names of its 
  32.830 +//     contributors may be used to endorse or promote products derived
  32.831 +//     from this software without specific prior written permission.
  32.832 +//
  32.833 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
  32.834 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
  32.835 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
  32.836 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
  32.837 +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  32.838 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  32.839 +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  32.840 +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32.841 +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  32.842 +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  32.843 +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  32.844 +// OF THE POSSIBILITY OF SUCH DAMAGE.
  32.845 +// ===================================================================
  32.846 +// 
  32.847 +// vtsp.c
  32.848 +// 
  32.849 +//  Higher level interface to TCS for use in service.
  32.850 +//
  32.851 +// ==================================================================
  32.852 +
  32.853 +#include <string.h>
  32.854 +#include "tcg.h"
  32.855 +#include "tcs.h"
  32.856 +#include "bsg.h"
  32.857 +#include "log.h"
  32.858 +#include "crypto.h"
  32.859 +#include "vtsp.h"
  32.860 +#include "buffer.h"
  32.861 +
  32.862 +#define  RSA_KEY_SIZE 0x0800
  32.863 +
  32.864 +/***********************************************************************************
  32.865 + * GenerateAuth: Generate authorization info to be sent back to application
  32.866 + *
  32.867 + * Parameters: outParamDigestText  The concatenation of output parameters to be SHA1ed
  32.868 + *    outParamDigestTextSize Size of inParamDigestText
  32.869 + *    HMACkey     Key to be used for HMACing
  32.870 + *          For OIAP use key.authUsage or PersistStore.ownerAuth
  32.871 + *          For OSAP use shared secret
  32.872 + *    pAuth     Authorization information from the application
  32.873 + *
  32.874 + * Return:  TPM_SUCCESS   Authorization data created
  32.875 + *    TPM_AUTHFAIL   Invalid (NULL) HMACkey presented for OSAP
  32.876 + *************************************************************************************/
  32.877 +TPM_RESULT GenerateAuth( /*[IN]*/ const BYTE *inParamDigestText,
  32.878 +			 /*[IN]*/ UINT32 inParamDigestTextSize,
  32.879 +			 /*[IN]*/ const TPM_SECRET *HMACkey,  
  32.880 +			 /*[IN,OUT]*/ TCS_AUTH *auth) {
  32.881 +    
  32.882 +  if (inParamDigestText == NULL || auth == NULL) 
  32.883 +    return (TPM_AUTHFAIL);
  32.884 +  else {
  32.885 +    
  32.886 +    //Generate new OddNonce
  32.887 +    Crypto_GetRandom(auth->NonceOdd.nonce, sizeof(TPM_NONCE));
  32.888 +    
  32.889 +    // Create SHA1 inParamDigest
  32.890 +    TPM_DIGEST inParamDigest;
  32.891 +    Crypto_SHA1Full(inParamDigestText, inParamDigestTextSize, (BYTE *) &inParamDigest);
  32.892 +    
  32.893 +    // Create HMAC text. (Concat inParamsDigest with inAuthSetupParams).
  32.894 +    BYTE hmacText[sizeof(TPM_DIGEST) + (2 * sizeof(TPM_NONCE)) + sizeof(BOOL)];
  32.895 +    
  32.896 +    BSG_PackList(   hmacText, 4, 
  32.897 +		    BSG_TPM_DIGEST, &inParamDigest,
  32.898 +		    BSG_TPM_NONCE, &(auth->NonceEven),
  32.899 +		    BSG_TPM_NONCE, &(auth->NonceOdd), 
  32.900 +		    BSG_TYPE_BOOL, &(auth->fContinueAuthSession) );
  32.901 +    
  32.902 +    Crypto_HMAC((BYTE *) hmacText, sizeof(hmacText), (BYTE *) HMACkey, sizeof(TPM_DIGEST), (BYTE *) &(auth->HMAC));
  32.903 +    
  32.904 +    return(TPM_SUCCESS);
  32.905 +    
  32.906 +  }
  32.907 +}
  32.908 +
  32.909 +/***********************************************************************************
  32.910 + * VerifyAuth: Verify the authdata for a command requiring authorization
  32.911 + *
  32.912 + * Parameters: inParamDigestText  The concatenation of parameters to be SHA1ed
  32.913 + *    inParamDigestTextSize Size of inParamDigestText
  32.914 + *    authDataUsage   AuthDataUsage for the Entity being used
  32.915 + *          Key->authDataUsage or TPM_AUTH_OWNER
  32.916 + *    HMACkey     Key to be used for HMACing
  32.917 + *          For OIAP use key.authUsage or PersistStore.ownerAuth
  32.918 + *          For OSAP use NULL (It will be aquired from the Auth Session)
  32.919 + *          If unknown (default), assume OIAP
  32.920 + *    sessionAuth    A TCS_AUTH info for the session
  32.921 + *    pAuth     Authorization information from the application
  32.922 + *              hContext        If specified, on failed Auth, VerifyAuth will
  32.923 + *                                      generate a new OIAP session in place of themselves
  32.924 + *                                      destroyed session.
  32.925 + *
  32.926 + * Return:  TPM_SUCCESS   Authorization Verified
  32.927 + *    TPM_AUTHFAIL   Authorization Failed
  32.928 + *    TPM_FAIL    Failure during SHA1 routines
  32.929 + *************************************************************************************/
  32.930 +TPM_RESULT VerifyAuth( /*[IN]*/ const BYTE *outParamDigestText,
  32.931 +		       /*[IN]*/ UINT32 outParamDigestTextSize,
  32.932 +		       /*[IN]*/ const TPM_SECRET *HMACkey,  
  32.933 +		       /*[IN,OUT]*/ TCS_AUTH *auth,
  32.934 +		       /*[IN]*/  TCS_CONTEXT_HANDLE hContext) {
  32.935 +  if (outParamDigestText == NULL || auth == NULL) 
  32.936 +    return (TPM_AUTHFAIL);
  32.937 +  
  32.938 +  
  32.939 +  // Create SHA1 inParamDigest
  32.940 +  TPM_DIGEST outParamDigest;
  32.941 +  Crypto_SHA1Full(outParamDigestText, outParamDigestTextSize, (BYTE *) &outParamDigest);
  32.942 +  
  32.943 +  // Create HMAC text. (Concat inParamsDigest with inAuthSetupParams).
  32.944 +  TPM_DIGEST hm;
  32.945 +  BYTE hmacText[sizeof(TPM_DIGEST) + (2 * sizeof(TPM_NONCE)) + sizeof(BOOL)];
  32.946 +  
  32.947 +  BSG_PackList(   hmacText, 4, 
  32.948 +		  BSG_TPM_DIGEST, &outParamDigest,
  32.949 +		  BSG_TPM_NONCE, &(auth->NonceEven),
  32.950 +		  BSG_TPM_NONCE, &(auth->NonceOdd), 
  32.951 +		  BSG_TYPE_BOOL, &(auth->fContinueAuthSession) );
  32.952 +  
  32.953 +  Crypto_HMAC((BYTE *) hmacText, sizeof(hmacText),
  32.954 +	      (BYTE *) HMACkey, sizeof(TPM_DIGEST), (BYTE *) &hm);
  32.955 +    
  32.956 +  // Compare correct HMAC with provided one.
  32.957 +  if (memcmp (&hm, &(auth->HMAC), sizeof(TPM_DIGEST)) == 0)  // 0 indicates equality
  32.958 +    return (TPM_SUCCESS);
  32.959 +  else {
  32.960 +    VTSP_OIAP( hContext, auth);
  32.961 +    return (TPM_AUTHFAIL);
  32.962 +  }
  32.963 +}
  32.964 +
  32.965 +TPM_RESULT VTSP_OIAP(const TCS_CONTEXT_HANDLE hContext,
  32.966 +		     TCS_AUTH *auth) {
  32.967 +  
  32.968 +  vtpmloginfo(VTPM_LOG_VTSP, "OIAP.\n");
  32.969 +  TPM_RESULT status = TPM_SUCCESS;                           
  32.970 +  TPMTRYRETURN( TCSP_OIAP(hContext,
  32.971 +			  &auth->AuthHandle,
  32.972 +			  &auth->NonceEven) );
  32.973 +  goto egress;
  32.974 +  
  32.975 + abort_egress:
  32.976 +  
  32.977 + egress:
  32.978 +  
  32.979 +  return status;
  32.980 +}
  32.981 +
  32.982 +TPM_RESULT VTSP_OSAP(const TCS_CONTEXT_HANDLE hContext,
  32.983 +		     const TPM_ENTITY_TYPE entityType,
  32.984 +		     const UINT32 entityValue,
  32.985 +		     const TPM_AUTHDATA *usageAuth,
  32.986 +		     TPM_SECRET *sharedSecret, 
  32.987 +		     TCS_AUTH *auth) {
  32.988 +  
  32.989 +  vtpmloginfo(VTPM_LOG_VTSP, "OSAP.\n");
  32.990 +  TPM_RESULT status = TPM_SUCCESS;
  32.991 +  TPM_NONCE nonceEvenOSAP, nonceOddOSAP;
  32.992 +  
  32.993 +  Crypto_GetRandom((BYTE *) &nonceOddOSAP, sizeof(TPM_NONCE) ); 
  32.994 +  
  32.995 +  TPMTRYRETURN( TCSP_OSAP(    hContext,
  32.996 +			      entityType,
  32.997 +			      entityValue, 
  32.998 +			      nonceOddOSAP,
  32.999 +			      &auth->AuthHandle, 
 32.1000 +			      &auth->NonceEven, 
 32.1001 +			      &nonceEvenOSAP) );
 32.1002 +  
 32.1003 +  // Calculating Session Secret
 32.1004 +  BYTE sharedSecretText[TPM_DIGEST_SIZE * 2];
 32.1005 +  
 32.1006 +  BSG_PackList(  sharedSecretText, 2,
 32.1007 +		 BSG_TPM_NONCE, &nonceEvenOSAP,
 32.1008 +		 BSG_TPM_NONCE, &nonceOddOSAP);
 32.1009 +  
 32.1010 +  Crypto_HMAC(sharedSecretText, sizeof(sharedSecretText), (BYTE *) usageAuth, TPM_DIGEST_SIZE, (BYTE *) sharedSecret);       
 32.1011 +    
 32.1012 +  goto egress;
 32.1013 +  
 32.1014 + abort_egress:
 32.1015 +  
 32.1016 + egress:
 32.1017 +  
 32.1018 +  return status;
 32.1019 +}
 32.1020 +
 32.1021 +
 32.1022 +
 32.1023 +TPM_RESULT VTSP_ReadPubek(   const TCS_CONTEXT_HANDLE hContext,
 32.1024 +                             CRYPTO_INFO *crypto_info) {
 32.1025 +  
 32.1026 +  TPM_RESULT status;
 32.1027 +  TPM_NONCE antiReplay;
 32.1028 +  TPM_DIGEST   checksum;
 32.1029 +  BYTE *pubEKtext;
 32.1030 +  UINT32 pubEKtextsize;
 32.1031 +  
 32.1032 +  vtpmloginfo(VTPM_LOG_VTSP, "Reading Public EK.\n");
 32.1033 +  
 32.1034 +  // GenerateAuth new nonceOdd    
 32.1035 +  Crypto_GetRandom(&antiReplay, sizeof(TPM_NONCE) );
 32.1036 +  
 32.1037 +  
 32.1038 +  TPMTRYRETURN( TCSP_ReadPubek(  hContext,
 32.1039 +				 antiReplay,
 32.1040 +				 &pubEKtextsize,
 32.1041 +				 &pubEKtext,
 32.1042 +				 &checksum) );
 32.1043 +  
 32.1044 +  
 32.1045 +  // Extract the remaining output parameters
 32.1046 +  TPM_PUBKEY pubEK;
 32.1047 +  
 32.1048 +  BSG_Unpack(BSG_TPM_PUBKEY, pubEKtext, (BYTE *) &pubEK);
 32.1049 +  
 32.1050 +  // Build CryptoInfo for the bindingKey
 32.1051 +  TPM_RSA_KEY_PARMS rsaKeyParms;
 32.1052 +  
 32.1053 +  BSG_Unpack(BSG_TPM_RSA_KEY_PARMS, 
 32.1054 +	     pubEK.algorithmParms.parms, 
 32.1055 +	     &rsaKeyParms);
 32.1056 +  
 32.1057 +  Crypto_RSABuildCryptoInfoPublic(rsaKeyParms.exponentSize, 
 32.1058 +				  rsaKeyParms.exponent, 
 32.1059 +				  pubEK.pubKey.keyLength, 
 32.1060 +				  pubEK.pubKey.key, 
 32.1061 +				  crypto_info);
 32.1062 +    
 32.1063 +  // Destroy rsaKeyParms
 32.1064 +  BSG_Destroy(BSG_TPM_RSA_KEY_PARMS, &rsaKeyParms);
 32.1065 +
 32.1066 +  // Set encryption scheme
 32.1067 +  crypto_info->encScheme = CRYPTO_ES_RSAESOAEP_SHA1_MGF1;
 32.1068 +  //crypto_info->encScheme = pubEK.algorithmParms.encScheme;
 32.1069 +  crypto_info->algorithmID = pubEK.algorithmParms.algorithmID;
 32.1070 +  
 32.1071 +  goto egress;
 32.1072 +  
 32.1073 + abort_egress:
 32.1074 +  
 32.1075 + egress:
 32.1076 +  
 32.1077 +  return status;
 32.1078 +}
 32.1079 +
 32.1080 +TPM_RESULT VTSP_TakeOwnership(   const TCS_CONTEXT_HANDLE hContext,
 32.1081 +                                 const TPM_AUTHDATA *ownerAuth, 
 32.1082 +                                 const TPM_AUTHDATA *srkAuth,
 32.1083 +                                 CRYPTO_INFO *ek_cryptoInfo,
 32.1084 +                                 TCS_AUTH *auth) {
 32.1085 +  
 32.1086 +  vtpmloginfo(VTPM_LOG_VTSP, "Taking Ownership of TPM.\n");
 32.1087 +  
 32.1088 +  TPM_RESULT status = TPM_SUCCESS;
 32.1089 +  TPM_COMMAND_CODE command = TPM_ORD_TakeOwnership;
 32.1090 +  TPM_PROTOCOL_ID proto_id = TPM_PID_OWNER;
 32.1091 +  BYTE *new_srk;
 32.1092 +  
 32.1093 +  BYTE *paramText;        // Digest to make Auth.
 32.1094 +  UINT32 paramTextSize;
 32.1095 +  
 32.1096 +  // vars for srkpubkey parameter
 32.1097 +  TPM_KEY srkPub;
 32.1098 +  TPM_KEY_PARMS srkKeyInfo = {TPM_ALG_RSA, TPM_ES_RSAESOAEP_SHA1_MGF1, TPM_SS_NONE, 12, 0};
 32.1099 +  BYTE srkRSAkeyInfo[12] = { 0x00, 0x00, (RSA_KEY_SIZE >> 8), 0x00,   0x00, 0x00, 0x00, 0x02,   0x00, 0x00, 0x00, 0x00};
 32.1100 +  srkKeyInfo.parms = (BYTE *) &srkRSAkeyInfo;
 32.1101 +  
 32.1102 +  struct pack_buf_t srkText;
 32.1103 +  
 32.1104 +  // GenerateAuth new nonceOdd    
 32.1105 +  Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
 32.1106 +  
 32.1107 +  //These values are accurate for an enc(AuthData).
 32.1108 +  struct pack_buf_t encOwnerAuth, encSrkAuth;
 32.1109 +  
 32.1110 +  encOwnerAuth.data = (BYTE *)malloc(sizeof(BYTE) * 256);
 32.1111 +  encSrkAuth.data = (BYTE *)malloc(sizeof(BYTE) * 256);
 32.1112 +  
 32.1113 +  if (encOwnerAuth.data == NULL || encSrkAuth.data == NULL) {
 32.1114 +    vtpmloginfo(VTPM_LOG_VTSP, "Could not malloc encrypted auths.\n");
 32.1115 +    status = TPM_RESOURCES;
 32.1116 +    goto abort_egress;
 32.1117 +  }
 32.1118 +  
 32.1119 +  Crypto_RSAEnc(ek_cryptoInfo, sizeof(TPM_SECRET), (BYTE *) ownerAuth, &encOwnerAuth.size, encOwnerAuth.data);
 32.1120 +  Crypto_RSAEnc(ek_cryptoInfo, sizeof(TPM_SECRET), (BYTE *) srkAuth, &encSrkAuth.size, encSrkAuth.data);
 32.1121 +  
 32.1122 +  
 32.1123 +  // Build srk public key struct
 32.1124 +  srkPub.ver = TPM_STRUCT_VER_1_1;
 32.1125 +  srkPub.keyUsage = TPM_KEY_STORAGE;
 32.1126 +  srkPub.keyFlags = 0x00;
 32.1127 +  srkPub.authDataUsage = TPM_AUTH_ALWAYS;
 32.1128 +  memcpy(&srkPub.algorithmParms, &srkKeyInfo, sizeof(TPM_KEY_PARMS));
 32.1129 +  srkPub.PCRInfoSize = 0;
 32.1130 +  srkPub.PCRInfo = 0;
 32.1131 +  srkPub.pubKey.keyLength= 0;
 32.1132 +  srkPub.encDataSize = 0;
 32.1133 +  
 32.1134 +  srkText.data = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
 32.1135 +  srkText.size = BSG_Pack(BSG_TPM_KEY, (BYTE *) &srkPub, srkText.data);
 32.1136 +  
 32.1137 +  paramText = (BYTE *) malloc(sizeof(BYTE) *  TCPA_MAX_BUFFER_LENGTH);
 32.1138 +  
 32.1139 +  paramTextSize = BSG_PackList(paramText, 5,
 32.1140 +			       BSG_TPM_COMMAND_CODE,&command,
 32.1141 +			       BSG_TPM_PROTOCOL_ID, &proto_id,
 32.1142 +			       BSG_TPM_SIZE32_DATA, &encOwnerAuth,
 32.1143 +			       BSG_TPM_SIZE32_DATA, &encSrkAuth,
 32.1144 +			       BSG_TPM_KEY, &srkPub);
 32.1145 +  
 32.1146 +  TPMTRYRETURN( GenerateAuth( paramText, paramTextSize, ownerAuth, auth) );
 32.1147 +  
 32.1148 +  new_srk = srkText.data;
 32.1149 +  TPMTRYRETURN( TCSP_TakeOwnership ( hContext,
 32.1150 +				     proto_id,
 32.1151 +				     encOwnerAuth.size, 
 32.1152 +				     encOwnerAuth.data,
 32.1153 +				     encSrkAuth.size,
 32.1154 +				     encSrkAuth.data,
 32.1155 +				     &srkText.size,
 32.1156 +				     &new_srk, 
 32.1157 +				     auth ) );
 32.1158 +  
 32.1159 +  
 32.1160 +  paramTextSize = BSG_PackList(paramText, 2, 
 32.1161 +			       BSG_TPM_RESULT, &status,
 32.1162 +			       BSG_TPM_COMMAND_CODE, &command);
 32.1163 +  memcpy(paramText + paramTextSize, new_srk, srkText.size);
 32.1164 +  paramTextSize += srkText.size;
 32.1165 +  
 32.1166 +  
 32.1167 +  TPMTRYRETURN( VerifyAuth(  paramText, paramTextSize,
 32.1168 +			     ownerAuth, auth, 
 32.1169 +			     hContext) );
 32.1170 +  
 32.1171 +  goto egress;
 32.1172 +  
 32.1173 + abort_egress:
 32.1174 +  
 32.1175 + egress:
 32.1176 +  
 32.1177 +  free(srkText.data);
 32.1178 +  free(encSrkAuth.data);
 32.1179 +  free(encOwnerAuth.data);
 32.1180 +  free(paramText);
 32.1181 +  
 32.1182 +  TCS_FreeMemory(hContext, new_srk);
 32.1183 +  
 32.1184 +  return status;
 32.1185 +}
 32.1186 +
 32.1187 +TPM_RESULT VTSP_DisablePubekRead( const TCS_CONTEXT_HANDLE    hContext,
 32.1188 +                                  const TPM_AUTHDATA          *ownerAuth, 
 32.1189 +                                  TCS_AUTH                    *auth) {
 32.1190 +  
 32.1191 +  vtpmloginfo(VTPM_LOG_VTSP, "Disabling Pubek Read.\n");
 32.1192 +  
 32.1193 +  TPM_RESULT status = TPM_SUCCESS;
 32.1194 +  TPM_COMMAND_CODE command = TPM_ORD_DisablePubekRead;
 32.1195 +  
 32.1196 +  BYTE *paramText;        // Digest to make Auth.
 32.1197 +  UINT32 paramTextSize;
 32.1198 +    
 32.1199 +  // Generate HMAC   
 32.1200 +  Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
 32.1201 +  
 32.1202 +  paramText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
 32.1203 +  
 32.1204 +  paramTextSize = BSG_PackList(paramText, 1,
 32.1205 +			       BSG_TPM_COMMAND_CODE, &command);
 32.1206 +  
 32.1207 +  TPMTRYRETURN( GenerateAuth( paramText, paramTextSize,
 32.1208 +			      ownerAuth, auth) );
 32.1209 +  
 32.1210 +  // Call TCS
 32.1211 +  TPMTRYRETURN( TCSP_DisablePubekRead ( hContext, // in
 32.1212 +                                        auth) );
 32.1213 +  
 32.1214 +  // Verify Auth
 32.1215 +  paramTextSize = BSG_PackList(paramText, 2,
 32.1216 +			       BSG_TPM_RESULT, &status,
 32.1217 +			       BSG_TPM_COMMAND_CODE, &command);
 32.1218 +  
 32.1219 +  TPMTRYRETURN( VerifyAuth( paramText, paramTextSize,
 32.1220 +			    ownerAuth, auth, 
 32.1221 +			    hContext) );
 32.1222 +  goto egress;
 32.1223 +  
 32.1224 + abort_egress:
 32.1225 + egress:
 32.1226 +  free(paramText);
 32.1227 +  return status;
 32.1228 +}
 32.1229 +
 32.1230 +TPM_RESULT VTSP_CreateWrapKey(  const TCS_CONTEXT_HANDLE hContext,
 32.1231 +                                const TPM_KEY_USAGE      usage,
 32.1232 +                                const TPM_AUTHDATA       *newKeyAuth,
 32.1233 +                                const TCS_KEY_HANDLE     parentHandle, 
 32.1234 +                                const TPM_AUTHDATA       *osapSharedSecret,
 32.1235 +                                buffer_t                 *pubKeyBuf,
 32.1236 +                                TCS_AUTH                 *auth) {
 32.1237 +  
 32.1238 +  int i;
 32.1239 +  TPM_RESULT status = TPM_SUCCESS;
 32.1240 +  TPM_COMMAND_CODE command = TPM_ORD_CreateWrapKey;
 32.1241 +  
 32.1242 +  vtpmloginfo(VTPM_LOG_VTSP, "Creating new key of type %d.\n", usage);
 32.1243 +  
 32.1244 +  // vars for Calculate encUsageAuth
 32.1245 +  BYTE *paramText;      
 32.1246 +  UINT32 paramTextSize;
 32.1247 +  
 32.1248 +  // vars for Calculate encUsageAuth
 32.1249 +  BYTE XORbuffer[sizeof(TPM_SECRET) + sizeof(TPM_NONCE)];
 32.1250 +  TPM_DIGEST XORKey1;
 32.1251 +  UINT32 XORbufferSize;
 32.1252 +  TPM_SECRET encUsageAuth, encMigrationAuth;
 32.1253 +  
 32.1254 +  // vars for Flatten newKey prototype
 32.1255 +  BYTE *flatKey = (BYTE *) malloc(sizeof(BYTE) *  TCPA_MAX_BUFFER_LENGTH);
 32.1256 +  UINT32 flatKeySize = TCPA_MAX_BUFFER_LENGTH;                                    
 32.1257 +  struct pack_buf_t newKeyText;
 32.1258 +  
 32.1259 +  // Fill in newKey
 32.1260 +  TPM_KEY newKey;
 32.1261 +  
 32.1262 +  BYTE RSAkeyInfo[12] = { 0x00, 0x00, (RSA_KEY_SIZE >> 8), 0x00,   0x00, 0x00, 0x00, 0x02,   0x00, 0x00, 0x00, 0x00};
 32.1263 +  newKey.algorithmParms.algorithmID = TPM_ALG_RSA;
 32.1264 +  newKey.algorithmParms.parms = (BYTE *) &RSAkeyInfo;
 32.1265 +  newKey.algorithmParms.parmSize = 12;
 32.1266 +  
 32.1267 +  switch (usage) {
 32.1268 +  case TPM_KEY_SIGNING:
 32.1269 +    vtpmloginfo(VTPM_LOG_VTSP, "Creating Signing Key...\n");
 32.1270 +    newKey.keyUsage = TPM_KEY_SIGNING;
 32.1271 +    newKey.algorithmParms.encScheme = TPM_ES_NONE;
 32.1272 +    newKey.algorithmParms.sigScheme = TPM_SS_RSASSAPKCS1v15_SHA1;
 32.1273 +    break;
 32.1274 +  case TPM_KEY_STORAGE:
 32.1275 +    vtpmloginfo(VTPM_LOG_VTSP, "Creating Storage Key...\n");
 32.1276 +    newKey.keyUsage = TPM_KEY_STORAGE;
 32.1277 +    newKey.algorithmParms.encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1;
 32.1278 +    newKey.algorithmParms.sigScheme = TPM_SS_NONE;
 32.1279 +    break;
 32.1280 +  case TPM_KEY_BIND:
 32.1281 +    vtpmloginfo(VTPM_LOG_VTSP, "Creating Binding Key...\n");
 32.1282 +    newKey.keyUsage = TPM_KEY_BIND;
 32.1283 +    newKey.algorithmParms.encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1;
 32.1284 +    newKey.algorithmParms.sigScheme = TPM_SS_NONE;
 32.1285 +    break;
 32.1286 +  default:
 32.1287 +    vtpmloginfo(VTPM_LOG_VTSP, "Cannot create key. Invalid Key Type.\n");
 32.1288 +    status = TPM_BAD_PARAMETER;
 32.1289 +    goto abort_egress;
 32.1290 +  }
 32.1291 +  
 32.1292 +  
 32.1293 +  newKey.ver = TPM_STRUCT_VER_1_1;
 32.1294 +  
 32.1295 +  newKey.keyFlags = 0;
 32.1296 +  newKey.authDataUsage = TPM_AUTH_ALWAYS;
 32.1297 +  newKey.pubKey.keyLength= 0;
 32.1298 +  newKey.encDataSize = 0;
 32.1299 +  newKey.encData = NULL;
 32.1300 +  
 32.1301 +  // FIXME: Support PCR bindings
 32.1302 +  newKey.PCRInfoSize = 0;
 32.1303 +  newKey.PCRInfo = NULL;
 32.1304 +  
 32.1305 +  // Calculate encUsageAuth                                    
 32.1306 +  XORbufferSize = BSG_PackList(  XORbuffer, 2, 
 32.1307 +				 BSG_TPM_SECRET, osapSharedSecret,
 32.1308 +				 BSG_TPM_NONCE, &auth->NonceEven);
 32.1309 +  Crypto_SHA1Full(XORbuffer, XORbufferSize, (BYTE *) &XORKey1);
 32.1310 +  
 32.1311 +  // FIXME: No support for migratable keys.
 32.1312 +  for (i=0; i < TPM_DIGEST_SIZE; i++) 
 32.1313 +    ((BYTE *) &encUsageAuth)[i] = ((BYTE *) &XORKey1)[i] ^ ((BYTE *) newKeyAuth)[i];
 32.1314 +  
 32.1315 +  // Flatten newKey prototype
 32.1316 +  flatKeySize = BSG_Pack(BSG_TPM_KEY, (BYTE *) &newKey, flatKey);
 32.1317 +  newKeyText.data = flatKey;
 32.1318 +  newKeyText.size = flatKeySize;
 32.1319 +  
 32.1320 +  // GenerateAuth new nonceOdd    
 32.1321 +  Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
 32.1322 +  
 32.1323 +  // Generate HMAC
 32.1324 +  paramText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
 32.1325 +  
 32.1326 +  paramTextSize = BSG_PackList(paramText, 3,
 32.1327 +			       BSG_TPM_COMMAND_CODE, &command,
 32.1328 +			       BSG_TPM_AUTHDATA, &encUsageAuth,
 32.1329 +			       BSG_TPM_AUTHDATA, &encMigrationAuth);
 32.1330 +  memcpy(paramText + paramTextSize, newKeyText.data, newKeyText.size);
 32.1331 +  paramTextSize += newKeyText.size;
 32.1332 +  
 32.1333 +  
 32.1334 +  TPMTRYRETURN( GenerateAuth( paramText, paramTextSize,
 32.1335 +			      osapSharedSecret, auth) );
 32.1336 +  
 32.1337 +  // Call TCS
 32.1338 +  TPMTRYRETURN( TCSP_CreateWrapKey(  hContext, 
 32.1339 +				     parentHandle,
 32.1340 +				     encUsageAuth,
 32.1341 +				     encMigrationAuth,
 32.1342 +				     &newKeyText.size,
 32.1343 +				     &newKeyText.data,
 32.1344 +				     auth) );
 32.1345 +  
 32.1346 +  // Verify Auth
 32.1347 +  paramTextSize = BSG_PackList(paramText, 2,
 32.1348 +			       BSG_TPM_RESULT, &status,
 32.1349 +			       BSG_TPM_COMMAND_CODE, &command);
 32.1350 +  memcpy(paramText + paramTextSize, newKeyText.data, newKeyText.size);
 32.1351 +  paramTextSize += newKeyText.size;
 32.1352 +  
 32.1353 +  TPMTRYRETURN( VerifyAuth( paramText, paramTextSize,
 32.1354 +			    osapSharedSecret, auth, 0) );
 32.1355 +  
 32.1356 +  // Unpack/return key structure
 32.1357 +  TPMTRYRETURN(buffer_init(pubKeyBuf, 0, 0) );
 32.1358 +  TPMTRYRETURN(buffer_append_raw(pubKeyBuf, newKeyText.size, newKeyText.data) );
 32.1359 +  
 32.1360 +  goto egress;
 32.1361 +  
 32.1362 + abort_egress:
 32.1363 +  
 32.1364 + egress:
 32.1365 +  
 32.1366 +  free(flatKey);
 32.1367 +  free(paramText);
 32.1368 +  TCS_FreeMemory(hContext, newKeyText.data);
 32.1369 +  
 32.1370 +  return status;
 32.1371 +}
 32.1372 +
 32.1373 +TPM_RESULT VTSP_LoadKey(const TCS_CONTEXT_HANDLE    hContext,
 32.1374 +                        const TCS_KEY_HANDLE        hUnwrappingKey,
 32.1375 +                        const buffer_t              *rgbWrappedKeyBlob,
 32.1376 +                        const TPM_AUTHDATA          *parentAuth,
 32.1377 +                        TPM_HANDLE                  *newKeyHandle,
 32.1378 +                        TCS_AUTH                    *auth,
 32.1379 +                        CRYPTO_INFO                 *cryptoinfo /*= NULL*/) {
 32.1380 +  
 32.1381 +  
 32.1382 +  vtpmloginfo(VTPM_LOG_VTSP, "Loading Key.\n%s","");
 32.1383 +  
 32.1384 +  TPM_RESULT status = TPM_SUCCESS;
 32.1385 +  TPM_COMMAND_CODE command = TPM_ORD_LoadKey;
 32.1386 +  
 32.1387 +  BYTE *paramText;        // Digest to make Auth.
 32.1388 +  UINT32 paramTextSize;
 32.1389 +  
 32.1390 +  if ((rgbWrappedKeyBlob == NULL) || (parentAuth == NULL) || 
 32.1391 +      (newKeyHandle==NULL) || (auth==NULL)) {
 32.1392 +    status = TPM_BAD_PARAMETER;
 32.1393 +    goto abort_egress;
 32.1394 +  }
 32.1395 +  
 32.1396 +  // Generate Extra TCS Parameters
 32.1397 +  TPM_HANDLE phKeyHMAC;
 32.1398 +  
 32.1399 +  // Generate HMAC
 32.1400 +  Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
 32.1401 +  
 32.1402 +  paramText = (BYTE *) malloc(sizeof(BYTE) *  TCPA_MAX_BUFFER_LENGTH);
 32.1403 +  
 32.1404 +  paramTextSize = BSG_PackList(paramText, 1,
 32.1405 +			       BSG_TPM_COMMAND_CODE, &command);
 32.1406 +  
 32.1407 +  memcpy(paramText + paramTextSize, rgbWrappedKeyBlob->bytes, buffer_len(rgbWrappedKeyBlob));
 32.1408 +  paramTextSize += buffer_len(rgbWrappedKeyBlob);
 32.1409 +  
 32.1410 +  TPMTRYRETURN( GenerateAuth( paramText, paramTextSize,
 32.1411 +			      parentAuth, auth) );
 32.1412 +  
 32.1413 +  // Call TCS
 32.1414 +  TPMTRYRETURN( TCSP_LoadKeyByBlob(  hContext,
 32.1415 +				     hUnwrappingKey,
 32.1416 +				     buffer_len(rgbWrappedKeyBlob),
 32.1417 +				     rgbWrappedKeyBlob->bytes,
 32.1418 +				     auth,
 32.1419 +				     newKeyHandle,
 32.1420 +				     &phKeyHMAC) );
 32.1421 +  
 32.1422 +  // Verify Auth
 32.1423 +  paramTextSize = BSG_PackList(paramText, 3,
 32.1424 +			       BSG_TPM_RESULT, &status,
 32.1425 +			       BSG_TPM_COMMAND_CODE, &command,
 32.1426 +			       BSG_TPM_HANDLE, newKeyHandle);
 32.1427 +  
 32.1428 +  TPMTRYRETURN( VerifyAuth( paramText, paramTextSize,
 32.1429 +			    parentAuth, auth, 
 32.1430 +			    hContext) );
 32.1431 +  
 32.1432 +  // Unpack/return key structure
 32.1433 +  if (cryptoinfo != NULL) {
 32.1434 +    TPM_KEY newKey;
 32.1435 +    
 32.1436 +    BSG_Unpack(BSG_TPM_KEY, rgbWrappedKeyBlob->bytes , &newKey);
 32.1437 +    TPM_RSA_KEY_PARMS rsaKeyParms;
 32.1438 +    
 32.1439 +    BSG_Unpack(BSG_TPM_RSA_KEY_PARMS, 
 32.1440 +	       newKey.algorithmParms.parms, 
 32.1441 +	       &rsaKeyParms);
 32.1442 +    
 32.1443 +    Crypto_RSABuildCryptoInfoPublic(rsaKeyParms.exponentSize, 
 32.1444 +				    rsaKeyParms.exponent, 
 32.1445 +				    newKey.pubKey.keyLength, 
 32.1446 +				    newKey.pubKey.key, 
 32.1447 +				    cryptoinfo);
 32.1448 +    
 32.1449 +    // Destroy rsaKeyParms
 32.1450 +    BSG_Destroy(BSG_TPM_RSA_KEY_PARMS, &rsaKeyParms);
 32.1451 +    
 32.1452 +    // Set encryption scheme
 32.1453 +    cryptoinfo->encScheme = CRYPTO_ES_RSAESOAEP_SHA1_MGF1;
 32.1454 +  }
 32.1455 +  
 32.1456 +  goto egress;
 32.1457 +  
 32.1458 + abort_egress:
 32.1459 +  
 32.1460 + egress:
 32.1461 +  
 32.1462 +  free(paramText);
 32.1463 +  return status;
 32.1464 +}
 32.1465 +
 32.1466 +TPM_RESULT VTSP_Unbind( const TCS_CONTEXT_HANDLE    hContext,
 32.1467 +                        const TPM_KEY_HANDLE        key_handle,
 32.1468 +                        const buffer_t              *bound_data,
 32.1469 +                        const TPM_AUTHDATA          *usage_auth,
 32.1470 +                        buffer_t                    *clear_data,
 32.1471 +                        TCS_AUTH                    *auth) {
 32.1472 +  
 32.1473 +  vtpmloginfo(VTPM_LOG_VTSP, "Unbinding %d bytes of data.\n", buffer_len(bound_data));
 32.1474 +  
 32.1475 +  TPM_RESULT status = TPM_SUCCESS;
 32.1476 +  TPM_COMMAND_CODE command = TPM_ORD_UnBind;
 32.1477 +  
 32.1478 +  BYTE *paramText;        // Digest to make Auth.
 32.1479 +  UINT32 paramTextSize;
 32.1480 +  
 32.1481 +  // Generate Extra TCS Parameters
 32.1482 +  struct pack_buf_t clear_data32;
 32.1483 +  BYTE *clear_data_text;
 32.1484 +  UINT32 clear_data_size;
 32.1485 +  
 32.1486 +  // Generate HMAC   
 32.1487 +  Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
 32.1488 +  
 32.1489 +  struct pack_buf_t bound_data32 = {bound_data->size, bound_data->bytes};
 32.1490 +  
 32.1491 +  paramText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
 32.1492 +  
 32.1493 +  paramTextSize = BSG_PackList(paramText, 2,
 32.1494 +			       BSG_TPM_COMMAND_CODE, &command,
 32.1495 +			       BSG_TPM_SIZE32_DATA, &bound_data32);
 32.1496 +  
 32.1497 +  TPMTRYRETURN( GenerateAuth( paramText, paramTextSize,
 32.1498 +			      usage_auth, auth) );
 32.1499 +  
 32.1500 +  // Call TCS
 32.1501 +  TPMTRYRETURN( TCSP_UnBind( hContext,
 32.1502 +			     key_handle,
 32.1503 +			     buffer_len(bound_data),
 32.1504 +			     bound_data->bytes,
 32.1505 +			     auth,
 32.1506 +			     &clear_data_size,
 32.1507 +			     &clear_data_text) );
 32.1508 +  
 32.1509 +  
 32.1510 +  // Verify Auth
 32.1511 +  clear_data32.size = clear_data_size;
 32.1512 +  clear_data32.data = clear_data_text;
 32.1513 +  paramTextSize = BSG_PackList(paramText, 3,
 32.1514 +			       BSG_TPM_RESULT, &status,
 32.1515 +			       BSG_TPM_COMMAND_CODE, &command,
 32.1516 +			       BSG_TPM_SIZE32_DATA, &clear_data32);
 32.1517 +  
 32.1518 +  TPMTRYRETURN( VerifyAuth( paramText, paramTextSize,
 32.1519 +			    usage_auth, auth, 
 32.1520 +			    hContext) );
 32.1521 +  
 32.1522 +  // Unpack/return key structure
 32.1523 +  TPMTRYRETURN(buffer_init(clear_data, 0, 0));
 32.1524 +  TPMTRYRETURN(buffer_append_raw (clear_data, clear_data_size, clear_data_text) );
 32.1525 +  
 32.1526 +  goto egress;
 32.1527 +  
 32.1528 + abort_egress:
 32.1529 +  
 32.1530 + egress:
 32.1531 +  
 32.1532 +  free(paramText);
 32.1533 +  TCS_FreeMemory(hContext, clear_data_text);
 32.1534 +  
 32.1535 +  return status;
 32.1536 +}
 32.1537 +
 32.1538 +TPM_RESULT VTSP_Bind(   CRYPTO_INFO *cryptoInfo, 
 32.1539 +			const buffer_t *inData, 
 32.1540 +			buffer_t *outData)               
 32.1541 +{
 32.1542 +  vtpmloginfo(VTPM_LOG_VTSP, "Binding %d bytes of data.\n", buffer_len(inData));
 32.1543 +  TPM_BOUND_DATA boundData;
 32.1544 +  UINT32 i;
 32.1545 +  
 32.1546 +  // Fill boundData's accessory information
 32.1547 +  boundData.ver = TPM_STRUCT_VER_1_1;
 32.1548 +  boundData.payload = TPM_PT_BIND;
 32.1549 +  boundData.payloadData = inData->bytes;
 32.1550 +  
 32.1551 +  // Pack boundData before encryption
 32.1552 +  BYTE* flatBoundData = (BYTE *)malloc(sizeof(BYTE) * 
 32.1553 +				       (sizeof(TPM_VERSION) +
 32.1554 +					sizeof(TPM_PAYLOAD_TYPE) +
 32.1555 +					buffer_len(inData)));
 32.1556 +  if (flatBoundData == NULL) {
 32.1557 +    return TPM_NOSPACE;
 32.1558 +  }
 32.1559 +  UINT32 flatBoundDataSize = 0;
 32.1560 +  flatBoundDataSize = BSG_PackList(  flatBoundData, 2, 
 32.1561 +				     BSG_TPM_VERSION, &boundData.ver, 
 32.1562 +				     BSG_TYPE_BYTE, &boundData.payload);
 32.1563 +  
 32.1564 +  memcpy(flatBoundData+flatBoundDataSize, inData->bytes, buffer_len(inData));
 32.1565 +  flatBoundDataSize += buffer_len(inData);
 32.1566 +  
 32.1567 +  BYTE out_tmp[RSA_KEY_SIZE/8]; // RSAEnc does not do blocking, So this is what will come out.
 32.1568 +  UINT32 out_tmp_size;
 32.1569 +  
 32.1570 +  // Encrypt flatBoundData
 32.1571 +  Crypto_RSAEnc( cryptoInfo, 
 32.1572 +		 flatBoundDataSize, 
 32.1573 +		 flatBoundData, 
 32.1574 +		 &out_tmp_size, 
 32.1575 +		 out_tmp);
 32.1576 +  
 32.1577 +  if (out_tmp_size > RSA_KEY_SIZE/8) {
 32.1578 +    // The result of RSAEnc should be a fixed size based on key size.
 32.1579 +    vtpmlogerror(VTPM_LOG_VTSP, "Enc buffer just overflowed.\n");
 32.1580 +  }
 32.1581 +  
 32.1582 +  buffer_init(outData, 0, NULL);
 32.1583 +  buffer_append_raw(outData, out_tmp_size, out_tmp);
 32.1584 +  
 32.1585 +  vtpmloginfo(VTPM_LOG_TXDATA, "Bind Generated[%d] = 0x", out_tmp_size);
 32.1586 +  for(i = 0 ; i < out_tmp_size ; i++) {
 32.1587 +    vtpmloginfomore(VTPM_LOG_TXDATA, "%2.2x ", out_tmp[i]);
 32.1588 +  }
 32.1589 +  vtpmloginfomore(VTPM_LOG_TXDATA, "\n");
 32.1590 +  
 32.1591 +  // Free flatBoundData
 32.1592 +  free(flatBoundData);
 32.1593 +  
 32.1594 +  return TPM_SUCCESS;
 32.1595 +}
 32.1596 +
 32.1597 +// Function Reaches into unsupported TCS command, beware.
 32.1598 +TPM_RESULT VTSP_RawTransmit(const TCS_CONTEXT_HANDLE    hContext,
 32.1599 +                            const buffer_t *inbuf,
 32.1600 +                            buffer_t *outbuf ) {
 32.1601 +  
 32.1602 +  vtpmloginfo(VTPM_LOG_VTSP, "Passthrough in use.\n");
 32.1603 +  TPM_RESULT status = TPM_SUCCESS;
 32.1604 +  
 32.1605 +  // Generate Extra TCS Parameters
 32.1606 +  BYTE *resultText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
 32.1607 +  UINT32 resultTextSize =  TCPA_MAX_BUFFER_LENGTH;
 32.1608 +  
 32.1609 +  // Call TCS                          
 32.1610 +  TPMTRYRETURN( TCSP_RawTransmitData(buffer_len(inbuf), inbuf->bytes, 
 32.1611 +				     &resultTextSize, resultText) );
 32.1612 +  
 32.1613 +  // Unpack/return key structure
 32.1614 +  TPMTRYRETURN(buffer_init (outbuf, resultTextSize, resultText) );                                
 32.1615 +  goto egress;
 32.1616 +  
 32.1617 + abort_egress:
 32.1618 +  
 32.1619 + egress:
 32.1620 +  TCS_FreeMemory(hContext, resultText);
 32.1621 +  free(resultText);
 32.1622 +  return status;
 32.1623 +}
    33.1 --- a/tools/vtpm_manager/manager/vtsp.h	Wed Nov 30 19:54:28 2005 +0000
    33.2 +++ b/tools/vtpm_manager/manager/vtsp.h	Wed Nov 30 19:55:08 2005 +0000
    33.3 @@ -1,102 +1,102 @@
    33.4 -// ===================================================================
    33.5 -// 
    33.6 -// Copyright (c) 2005, Intel Corp.
    33.7 -// All rights reserved.
    33.8 -//
    33.9 -// Redistribution and use in source and binary forms, with or without 
   33.10 -// modification, are permitted provided that the following conditions 
   33.11 -// are met:
   33.12 -//
   33.13 -//   * Redistributions of source code must retain the above copyright 
   33.14 -//     notice, this list of conditions and the following disclaimer.
   33.15 -//   * Redistributions in binary form must reproduce the above 
   33.16 -//     copyright notice, this list of conditions and the following 
   33.17 -//     disclaimer in the documentation and/or other materials provided 
   33.18 -//     with the distribution.
   33.19 -//   * Neither the name of Intel Corporation nor the names of its 
   33.20 -//     contributors may be used to endorse or promote products derived
   33.21 -//     from this software without specific prior written permission.
   33.22 -//
   33.23 -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
   33.24 -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
   33.25 -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
   33.26 -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
   33.27 -// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   33.28 -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   33.29 -// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
   33.30 -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   33.31 -// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
   33.32 -// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
   33.33 -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   33.34 -// OF THE POSSIBILITY OF SUCH DAMAGE.
   33.35 -// ===================================================================
   33.36 -// 
   33.37 -// vtsp.h
   33.38 -// 
   33.39 -//  Higher level interface to TCS.
   33.40 -//
   33.41 -// ==================================================================
   33.42 -
   33.43 -#ifndef __VTSP_H__
   33.44 -#define __VTSP_H__
   33.45 -
   33.46 -#include "tcg.h"
   33.47 -#include "tcs.h"
   33.48 -
   33.49 -#define KEY_BUFFER_SIZE 2048
   33.50 -
   33.51 -TPM_RESULT VTSP_RawTransmit(const TCS_CONTEXT_HANDLE    hContext,
   33.52 -                            const buffer_t *inbuf,
   33.53 -                            buffer_t *outbuf );
   33.54 -
   33.55 -TPM_RESULT VTSP_OIAP(  const TCS_CONTEXT_HANDLE hContext,
   33.56 -                       TCS_AUTH *auth);
   33.57 -                       
   33.58 -TPM_RESULT VTSP_OSAP(  const TCS_CONTEXT_HANDLE hContext,
   33.59 -                       const TPM_ENTITY_TYPE entityType,
   33.60 -                       const UINT32 entityValue,
   33.61 -                       const TPM_AUTHDATA *usageAuth,
   33.62 -                       TPM_SECRET *sharedsecret, 
   33.63 -                       TCS_AUTH *auth);
   33.64 -
   33.65 -TPM_RESULT VTSP_ReadPubek(   const TCS_CONTEXT_HANDLE hContext,
   33.66 -                             CRYPTO_INFO *cypto_info);
   33.67 -
   33.68 -TPM_RESULT VTSP_TakeOwnership(   const TCS_CONTEXT_HANDLE hContext,
   33.69 -                                 const TPM_AUTHDATA *ownerAuth, 
   33.70 -                                 const TPM_AUTHDATA *srkAuth,
   33.71 -                                 CRYPTO_INFO *ek_cryptoInfo,
   33.72 -                                 TCS_AUTH *auth);
   33.73 -                               
   33.74 -TPM_RESULT VTSP_DisablePubekRead( const TCS_CONTEXT_HANDLE    hContext,
   33.75 -                                  const TPM_AUTHDATA *ownerAuth, 
   33.76 -                                  TCS_AUTH                    *auth);
   33.77 -                               
   33.78 -TPM_RESULT VTSP_CreateWrapKey(  const TCS_CONTEXT_HANDLE hContext,
   33.79 -                                const TPM_KEY_USAGE      usage,
   33.80 -                                const TPM_AUTHDATA       *newKeyAuth,
   33.81 -                                const TCS_KEY_HANDLE     parentHandle, 
   33.82 -                                const TPM_AUTHDATA       *osapSharedSecret,
   33.83 -                                buffer_t                 *pubKeyBuf,
   33.84 -                                TCS_AUTH                 *auth);
   33.85 -
   33.86 -TPM_RESULT VTSP_LoadKey(const TCS_CONTEXT_HANDLE    hContext,
   33.87 -                        const TCS_KEY_HANDLE        hUnwrappingKey,
   33.88 -                        const buffer_t              *rgbWrappedKeyBlob,
   33.89 -                        const TPM_AUTHDATA          *parentAuth,
   33.90 -                        TPM_HANDLE                  *newKeyHandle,
   33.91 -                        TCS_AUTH                    *pAuth,
   33.92 -                        CRYPTO_INFO                 *cryptoinfo);
   33.93 -
   33.94 -TPM_RESULT VTSP_Unbind( const TCS_CONTEXT_HANDLE    hContext,
   33.95 -                        const TPM_KEY_HANDLE        key_handle,
   33.96 -                        const buffer_t              *bound_data,
   33.97 -                        const TPM_AUTHDATA          *usage_auth,
   33.98 -                        buffer_t                    *clear_data,
   33.99 -                        TCS_AUTH                    *auth);
  33.100 -                        
  33.101 -TPM_RESULT VTSP_Bind(   CRYPTO_INFO *cryptoInfo,
  33.102 -            const buffer_t *inData, 
  33.103 -            buffer_t *outData);
  33.104 -                        
  33.105 -#endif //_VTSP_H_
  33.106 +// ===================================================================
  33.107 +// 
  33.108 +// Copyright (c) 2005, Intel Corp.
  33.109 +// All rights reserved.
  33.110 +//
  33.111 +// Redistribution and use in source and binary forms, with or without 
  33.112 +// modification, are permitted provided that the following conditions 
  33.113 +// are met:
  33.114 +//
  33.115 +//   * Redistributions of source code must retain the above copyright 
  33.116 +//     notice, this list of conditions and the following disclaimer.
  33.117 +//   * Redistributions in binary form must reproduce the above 
  33.118 +//     copyright notice, this list of conditions and the following 
  33.119 +//     disclaimer in the documentation and/or other materials provided 
  33.120 +//     with the distribution.
  33.121 +//   * Neither the name of Intel Corporation nor the names of its 
  33.122 +//     contributors may be used to endorse or promote products derived
  33.123 +//     from this software without specific prior written permission.
  33.124 +//
  33.125 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
  33.126 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
  33.127 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
  33.128 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
  33.129 +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  33.130 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  33.131 +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  33.132 +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33.133 +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  33.134 +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  33.135 +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  33.136 +// OF THE POSSIBILITY OF SUCH DAMAGE.
  33.137 +// ===================================================================
  33.138 +// 
  33.139 +// vtsp.h
  33.140 +// 
  33.141 +//  Higher level interface to TCS.
  33.142 +//
  33.143 +// ==================================================================
  33.144 +
  33.145 +#ifndef __VTSP_H__
  33.146 +#define __VTSP_H__
  33.147 +
  33.148 +#include "tcg.h"
  33.149 +#include "tcs.h"
  33.150 +
  33.151 +#define KEY_BUFFER_SIZE 2048
  33.152 +
  33.153 +TPM_RESULT VTSP_RawTransmit(const TCS_CONTEXT_HANDLE    hContext,
  33.154 +                            const buffer_t *inbuf,
  33.155 +                            buffer_t *outbuf );
  33.156 +
  33.157 +TPM_RESULT VTSP_OIAP(  const TCS_CONTEXT_HANDLE hContext,
  33.158 +                       TCS_AUTH *auth);
  33.159 +                       
  33.160 +TPM_RESULT VTSP_OSAP(  const TCS_CONTEXT_HANDLE hContext,
  33.161 +                       const TPM_ENTITY_TYPE entityType,
  33.162 +                       const UINT32 entityValue,
  33.163 +                       const TPM_AUTHDATA *usageAuth,
  33.164 +                       TPM_SECRET *sharedsecret, 
  33.165 +                       TCS_AUTH *auth);
  33.166 +
  33.167 +TPM_RESULT VTSP_ReadPubek(   const TCS_CONTEXT_HANDLE hContext,
  33.168 +                             CRYPTO_INFO *cypto_info);
  33.169 +
  33.170 +TPM_RESULT VTSP_TakeOwnership(   const TCS_CONTEXT_HANDLE hContext,
  33.171 +                                 const TPM_AUTHDATA *ownerAuth, 
  33.172 +                                 const TPM_AUTHDATA *srkAuth,
  33.173 +                                 CRYPTO_INFO *ek_cryptoInfo,
  33.174 +                                 TCS_AUTH *auth);
  33.175 +                               
  33.176 +TPM_RESULT VTSP_DisablePubekRead( const TCS_CONTEXT_HANDLE    hContext,
  33.177 +                                  const TPM_AUTHDATA *ownerAuth, 
  33.178 +                                  TCS_AUTH                    *auth);
  33.179 +                               
  33.180 +TPM_RESULT VTSP_CreateWrapKey(  const TCS_CONTEXT_HANDLE hContext,
  33.181 +                                const TPM_KEY_USAGE      usage,
  33.182 +                                const TPM_AUTHDATA       *newKeyAuth,
  33.183 +                                const TCS_KEY_HANDLE     parentHandle, 
  33.184 +                                const TPM_AUTHDATA       *osapSharedSecret,
  33.185 +                                buffer_t                 *pubKeyBuf,
  33.186 +                                TCS_AUTH                 *auth);
  33.187 +
  33.188 +TPM_RESULT VTSP_LoadKey(const TCS_CONTEXT_HANDLE    hContext,
  33.189 +                        const TCS_KEY_HANDLE        hUnwrappingKey,
  33.190 +                        const buffer_t              *rgbWrappedKeyBlob,
  33.191 +                        const TPM_AUTHDATA          *parentAuth,
  33.192 +                        TPM_HANDLE                  *newKeyHandle,
  33.193 +                        TCS_AUTH                    *pAuth,
  33.194 +                        CRYPTO_INFO                 *cryptoinfo);
  33.195 +
  33.196 +TPM_RESULT VTSP_Unbind( const TCS_CONTEXT_HANDLE    hContext,
  33.197 +                        const TPM_KEY_HANDLE        key_handle,
  33.198 +                        const buffer_t              *bound_data,
  33.199 +                        const TPM_AUTHDATA          *usage_auth,
  33.200 +                        buffer_t                    *clear_data,
  33.201 +                        TCS_AUTH                    *auth);
  33.202 +                        
  33.203 +TPM_RESULT VTSP_Bind(   CRYPTO_INFO *cryptoInfo,
  33.204 +            const buffer_t *inData, 
  33.205 +            buffer_t *outData);
  33.206 +                        
  33.207 +#endif //_VTSP_H_
    34.1 --- a/tools/vtpm_manager/util/Makefile	Wed Nov 30 19:54:28 2005 +0000
    34.2 +++ b/tools/vtpm_manager/util/Makefile	Wed Nov 30 19:55:08 2005 +0000
    34.3 @@ -1,19 +1,19 @@
    34.4 -XEN_ROOT = ../../..
    34.5 -include $(XEN_ROOT)/tools/vtpm_manager/Rules.mk
    34.6 -
    34.7 -BIN		= libTCGUtils.a
    34.8 -
    34.9 -all: build
   34.10 -
   34.11 -build: $(BIN)
   34.12 -
   34.13 -install: build
   34.14 -
   34.15 -clean:
   34.16 -	rm -f *.a *.so *.o *.rpm $(DEP_FILES)
   34.17 -
   34.18 -mrproper: clean
   34.19 -	rm -f *~
   34.20 -
   34.21 -$(BIN): $(OBJS)
   34.22 -	$(AR) rcs $(BIN) $(OBJS)
   34.23 +XEN_ROOT = ../../..
   34.24 +include $(XEN_ROOT)/tools/vtpm_manager/Rules.mk
   34.25 +
   34.26 +BIN		= libTCGUtils.a
   34.27 +
   34.28 +all: build
   34.29 +
   34.30 +build: $(BIN)
   34.31 +
   34.32 +install: build
   34.33 +
   34.34 +clean:
   34.35 +	rm -f *.a *.so *.o *.rpm $(DEP_FILES)
   34.36 +
   34.37 +mrproper: clean
   34.38 +	rm -f *~
   34.39 +
   34.40 +$(BIN): $(OBJS)
   34.41 +	$(AR) rcs $(BIN) $(OBJS)
    35.1 --- a/tools/vtpm_manager/util/depend	Wed Nov 30 19:54:28 2005 +0000
    35.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.3 @@ -1,7 +0,0 @@
    35.4 -hashtable.o: hashtable.c hashtable.h hashtable_private.h
    35.5 -hashtable_itr.o: hashtable_itr.c hashtable.h hashtable_private.h \
    35.6 -  hashtable_itr.h
    35.7 -bsg.o: bsg.c tcg.h ../crypto/crypto.h ../crypto/sym_crypto.h buffer.h \
    35.8 -  bsg.h log.h
    35.9 -log.o: log.c buffer.h tcg.h
   35.10 -buffer.o: buffer.c tcg.h bsg.h buffer.h
    36.1 --- a/xen/arch/x86/dm/i8259.c	Wed Nov 30 19:54:28 2005 +0000
    36.2 +++ b/xen/arch/x86/dm/i8259.c	Wed Nov 30 19:55:08 2005 +0000
    36.3 @@ -31,7 +31,7 @@
    36.4  #include <xen/sched.h>
    36.5  #include <public/io/ioreq.h>
    36.6  #include <asm/vmx.h>
    36.7 -#include <public/io/vmx_vpic.h>
    36.8 +#include <asm/vmx_vpic.h>
    36.9  #include <asm/current.h>
   36.10  #include <asm/vmx_vioapic.h>
   36.11  #include <asm/vmx_vlapic.h>
    37.1 --- a/xen/arch/x86/dm/vmx_vioapic.c	Wed Nov 30 19:54:28 2005 +0000
    37.2 +++ b/xen/arch/x86/dm/vmx_vioapic.c	Wed Nov 30 19:55:08 2005 +0000
    37.3 @@ -39,7 +39,7 @@
    37.4  #include <xen/sched.h>
    37.5  #include <public/io/ioreq.h>
    37.6  #include <asm/vmx.h>
    37.7 -#include <public/io/vmx_vpic.h>
    37.8 +#include <asm/vmx_vpic.h>
    37.9  #include <asm/current.h>
   37.10  
   37.11  static void ioapic_enable(vmx_vioapic_t *s, uint8_t enable)
    38.1 --- a/xen/arch/x86/dom0_ops.c	Wed Nov 30 19:54:28 2005 +0000
    38.2 +++ b/xen/arch/x86/dom0_ops.c	Wed Nov 30 19:55:08 2005 +0000
    38.3 @@ -144,7 +144,7 @@ long arch_do_dom0_op(dom0_op_t *op, dom0
    38.4          unsigned int p;
    38.5  
    38.6          ret = -EINVAL;
    38.7 -        if ( (fp + np) >= 65536 )
    38.8 +        if ( (fp + np) > 65536 )
    38.9              break;
   38.10  
   38.11          ret = -ESRCH;
    39.1 --- a/xen/arch/x86/shadow.c	Wed Nov 30 19:54:28 2005 +0000
    39.2 +++ b/xen/arch/x86/shadow.c	Wed Nov 30 19:55:08 2005 +0000
    39.3 @@ -2154,7 +2154,8 @@ static void shadow_update_pagetables(str
    39.4  #elif CONFIG_PAGING_LEVELS == 4
    39.5          smfn = shadow_l4_table(d, gpfn, gmfn);
    39.6  #endif
    39.7 -    }
    39.8 +    }else
    39.9 +        shadow_sync_all(d);
   39.10      if ( !get_shadow_ref(smfn) )
   39.11          BUG();
   39.12      old_smfn = pagetable_get_pfn(v->arch.shadow_table);
    40.1 --- a/xen/arch/x86/shadow32.c	Wed Nov 30 19:54:28 2005 +0000
    40.2 +++ b/xen/arch/x86/shadow32.c	Wed Nov 30 19:55:08 2005 +0000
    40.3 @@ -2911,6 +2911,8 @@ void __update_pagetables(struct vcpu *v)
    40.4       */
    40.5      if ( unlikely(!(smfn = __shadow_status(d, gpfn, PGT_base_page_table))) )
    40.6          smfn = shadow_l2_table(d, gpfn, gmfn);
    40.7 +    else
    40.8 +        shadow_sync_all(d);
    40.9      if ( !get_shadow_ref(smfn) )
   40.10          BUG();
   40.11      old_smfn = pagetable_get_pfn(v->arch.shadow_table);
    41.1 --- a/xen/arch/x86/vmx.c	Wed Nov 30 19:54:28 2005 +0000
    41.2 +++ b/xen/arch/x86/vmx.c	Wed Nov 30 19:55:08 2005 +0000
    41.3 @@ -43,8 +43,8 @@
    41.4  #endif
    41.5  #include <public/sched.h>
    41.6  #include <public/io/ioreq.h>
    41.7 -#include <public/io/vmx_vpic.h>
    41.8 -#include <public/io/vmx_vlapic.h>
    41.9 +#include <asm/vmx_vpic.h>
   41.10 +#include <asm/vmx_vlapic.h>
   41.11  
   41.12  int hvm_enabled;
   41.13  
    42.1 --- a/xen/arch/x86/vmx_intercept.c	Wed Nov 30 19:54:28 2005 +0000
    42.2 +++ b/xen/arch/x86/vmx_intercept.c	Wed Nov 30 19:55:08 2005 +0000
    42.3 @@ -21,7 +21,7 @@
    42.4  #include <xen/types.h>
    42.5  #include <asm/vmx.h>
    42.6  #include <asm/vmx_platform.h>
    42.7 -#include <asm/vmx_virpit.h>
    42.8 +#include <asm/vmx_vpit.h>
    42.9  #include <asm/vmx_intercept.h>
   42.10  #include <asm/vmx_vlapic.h>
   42.11  #include <public/io/ioreq.h>
    43.1 --- a/xen/arch/x86/vmx_io.c	Wed Nov 30 19:54:28 2005 +0000
    43.2 +++ b/xen/arch/x86/vmx_io.c	Wed Nov 30 19:55:08 2005 +0000
    43.3 @@ -32,13 +32,12 @@
    43.4  #include <asm/vmx.h>
    43.5  #include <asm/vmx_vmcs.h>
    43.6  #include <asm/vmx_platform.h>
    43.7 -#include <asm/vmx_virpit.h>
    43.8 +#include <asm/vmx_vpit.h>
    43.9  #include <asm/apic.h>
   43.10  #include <asm/shadow.h>
   43.11 -
   43.12 +#include <asm/vmx_vpic.h>
   43.13  #include <asm/vmx_vlapic.h>
   43.14  #include <public/io/ioreq.h>
   43.15 -#include <public/io/vmx_vpic.h>
   43.16  
   43.17  #ifdef CONFIG_VMX
   43.18  #if defined (__i386__)
    44.1 --- a/xen/common/domain.c	Wed Nov 30 19:54:28 2005 +0000
    44.2 +++ b/xen/common/domain.c	Wed Nov 30 19:55:08 2005 +0000
    44.3 @@ -293,11 +293,7 @@ void domain_pause(struct domain *d)
    44.4      struct vcpu *v;
    44.5  
    44.6      for_each_vcpu( d, v )
    44.7 -    {
    44.8 -        BUG_ON(v == current);
    44.9 -        atomic_inc(&v->pausecnt);
   44.10 -        vcpu_sleep_sync(v);
   44.11 -    }
   44.12 +        vcpu_pause(v);
   44.13  
   44.14      sync_pagetable_state(d);
   44.15  }
    45.1 --- a/xen/common/grant_table.c	Wed Nov 30 19:54:28 2005 +0000
    45.2 +++ b/xen/common/grant_table.c	Wed Nov 30 19:55:08 2005 +0000
    45.3 @@ -114,13 +114,13 @@ static int
    45.4                     (GNTMAP_device_map|GNTMAP_host_map)) == 0) )
    45.5      {
    45.6          DPRINTK("Bad ref (%d) or flags (%x).\n", ref, dev_hst_ro_flags);
    45.7 -        (void)__put_user(GNTST_bad_gntref, &uop->handle);
    45.8 +        (void)__put_user(GNTST_bad_gntref, &uop->status);
    45.9          return GNTST_bad_gntref;
   45.10      }
   45.11  
   45.12      if ( acm_pre_grant_map_ref(dom) )
   45.13      {
   45.14 -        (void)__put_user(GNTST_permission_denied, &uop->handle);
   45.15 +        (void)__put_user(GNTST_permission_denied, &uop->status);
   45.16          return GNTST_permission_denied;
   45.17      }
   45.18  
   45.19 @@ -130,7 +130,7 @@ static int
   45.20          if ( rd != NULL )
   45.21              put_domain(rd);
   45.22          DPRINTK("Could not find domain %d\n", dom);
   45.23 -        (void)__put_user(GNTST_bad_domain, &uop->handle);
   45.24 +        (void)__put_user(GNTST_bad_domain, &uop->status);
   45.25          return GNTST_bad_domain;
   45.26      }
   45.27  
   45.28 @@ -145,7 +145,7 @@ static int
   45.29          {
   45.30              put_domain(rd);
   45.31              DPRINTK("Maptrack table is at maximum size.\n");
   45.32 -            (void)__put_user(GNTST_no_device_space, &uop->handle);
   45.33 +            (void)__put_user(GNTST_no_device_space, &uop->status);
   45.34              return GNTST_no_device_space;
   45.35          }
   45.36  
   45.37 @@ -155,7 +155,7 @@ static int
   45.38          {
   45.39              put_domain(rd);
   45.40              DPRINTK("No more map handles available.\n");
   45.41 -            (void)__put_user(GNTST_no_device_space, &uop->handle);
   45.42 +            (void)__put_user(GNTST_no_device_space, &uop->status);
   45.43              return GNTST_no_device_space;
   45.44          }
   45.45  
   45.46 @@ -370,6 +370,7 @@ static int
   45.47  
   45.48      (void)__put_user((u64)frame << PAGE_SHIFT, &uop->dev_bus_addr);
   45.49      (void)__put_user(handle, &uop->handle);
   45.50 +    (void)__put_user(GNTST_okay, &uop->status);
   45.51  
   45.52      put_domain(rd);
   45.53      return rc;
   45.54 @@ -377,7 +378,7 @@ static int
   45.55  
   45.56   unlock_out:
   45.57      spin_unlock(&rd->grant_table->lock);
   45.58 -    (void)__put_user(rc, &uop->handle);
   45.59 +    (void)__put_user(rc, &uop->status);
   45.60      put_maptrack_handle(ld->grant_table, handle);
   45.61      return rc;
   45.62  }
   45.63 @@ -400,7 +401,7 @@ static int
   45.64  {
   45.65      domid_t          dom;
   45.66      grant_ref_t      ref;
   45.67 -    u16              handle;
   45.68 +    grant_handle_t   handle;
   45.69      struct domain   *ld, *rd;
   45.70      active_grant_entry_t *act;
   45.71      grant_entry_t   *sha;
   45.72 @@ -957,7 +958,7 @@ gnttab_release_mappings(
   45.73      grant_table_t        *gt = d->grant_table;
   45.74      grant_mapping_t      *map;
   45.75      grant_ref_t           ref;
   45.76 -    u16                   handle;
   45.77 +    grant_handle_t        handle;
   45.78      struct domain        *rd;
   45.79      active_grant_entry_t *act;
   45.80      grant_entry_t        *sha;
    46.1 --- a/xen/include/asm-x86/shadow.h	Wed Nov 30 19:54:28 2005 +0000
    46.2 +++ b/xen/include/asm-x86/shadow.h	Wed Nov 30 19:55:08 2005 +0000
    46.3 @@ -317,7 +317,7 @@ struct out_of_sync_entry {
    46.4      unsigned long gpfn;    /* why is this here? */
    46.5      unsigned long gmfn;
    46.6      unsigned long snapshot_mfn;
    46.7 -    unsigned long writable_pl1e; /* NB: this is a machine address */
    46.8 +    physaddr_t writable_pl1e; /* NB: this is a machine address */
    46.9      unsigned long va;
   46.10  };
   46.11  
    47.1 --- a/xen/include/asm-x86/vmx_platform.h	Wed Nov 30 19:54:28 2005 +0000
    47.2 +++ b/xen/include/asm-x86/vmx_platform.h	Wed Nov 30 19:55:08 2005 +0000
    47.3 @@ -22,10 +22,10 @@
    47.4  
    47.5  #include <public/xen.h>
    47.6  #include <asm/e820.h>
    47.7 -#include <asm/vmx_virpit.h>
    47.8 +#include <asm/vmx_vpit.h>
    47.9  #include <asm/vmx_intercept.h>
   47.10  #include <asm/vmx_vioapic.h>
   47.11 -#include <public/io/vmx_vpic.h>
   47.12 +#include <asm/vmx_vpic.h>
   47.13  
   47.14  #define MAX_OPERAND_NUM 2
   47.15  
    48.1 --- a/xen/include/asm-x86/vmx_virpit.h	Wed Nov 30 19:54:28 2005 +0000
    48.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    48.3 @@ -1,55 +0,0 @@
    48.4 -#ifndef _VMX_VIRPIT_H
    48.5 -#define _VMX_VIRPIT_H
    48.6 -
    48.7 -#include <xen/config.h>
    48.8 -#include <xen/init.h>
    48.9 -#include <xen/lib.h>
   48.10 -#include <xen/time.h>
   48.11 -#include <xen/errno.h>
   48.12 -#include <xen/ac_timer.h>
   48.13 -#include <asm/vmx_vmcs.h>
   48.14 -#include <public/io/vmx_vpic.h>
   48.15 -
   48.16 -#define PIT_FREQ 1193181
   48.17 -
   48.18 -#define LSByte 0
   48.19 -#define MSByte 1
   48.20 -#define LSByte_multiple 2
   48.21 -#define MSByte_multiple 3
   48.22 -
   48.23 -struct vmx_virpit {
   48.24 -    /* for simulation of counter 0 in mode 2*/
   48.25 -    u64 period_cycles;	                /* pit frequency in cpu cycles */
   48.26 -    u64 inject_point; /* the time inject virt intr */
   48.27 -    s_time_t scheduled;                 /* scheduled timer interrupt */
   48.28 -    struct ac_timer pit_timer;  /* periodic timer for mode 2*/
   48.29 -    unsigned int channel;  /* the pit channel, counter 0~2 */
   48.30 -    unsigned int pending_intr_nr; /* the couner for pending timer interrupts */
   48.31 -    u32 period;		/* pit frequency in ns */
   48.32 -    int first_injected;                 /* flag to prevent shadow window */
   48.33 -    int ticking;    /* indicating it is ticking */
   48.34 -
   48.35 -    /* virtual PIT state for handle related I/O */
   48.36 -    int read_state;
   48.37 -    int count_LSB_latched;
   48.38 -    int count_MSB_latched;
   48.39 -
   48.40 -    unsigned int count;  /* the 16 bit channel count */
   48.41 -    unsigned int init_val; /* the init value for the counter */
   48.42 -};
   48.43 -
   48.44 -/* to hook the ioreq packet to get the PIT initializaiton info */
   48.45 -extern void vmx_hooks_assist(struct vcpu *v);
   48.46 -
   48.47 -static __inline__ s_time_t get_pit_scheduled(
   48.48 -    struct vcpu *v, 
   48.49 -    struct vmx_virpit *vpit)
   48.50 -{
   48.51 -    if ( is_irq_enabled(v, 0) ) {
   48.52 -        return vpit->scheduled;
   48.53 -    }
   48.54 -    else
   48.55 -        return -1;
   48.56 -}
   48.57 -
   48.58 -#endif /* _VMX_VIRPIT_H_ */
    49.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    49.2 +++ b/xen/include/asm-x86/vmx_vpic.h	Wed Nov 30 19:55:08 2005 +0000
    49.3 @@ -0,0 +1,85 @@
    49.4 +/*
    49.5 + * QEMU System Emulator header
    49.6 + * 
    49.7 + * Copyright (c) 2003 Fabrice Bellard
    49.8 + * Copyright (c) 2005 Intel Corp
    49.9 + * 
   49.10 + * Permission is hereby granted, free of charge, to any person obtaining a copy
   49.11 + * of this software and associated documentation files (the "Software"), to deal
   49.12 + * in the Software without restriction, including without limitation the rights
   49.13 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   49.14 + * copies of the Software, and to permit persons to whom the Software is
   49.15 + * furnished to do so, subject to the following conditions:
   49.16 + *
   49.17 + * The above copyright notice and this permission notice shall be included in
   49.18 + * all copies or substantial portions of the Software.
   49.19 + *
   49.20 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   49.21 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   49.22 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
   49.23 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   49.24 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   49.25 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   49.26 + * THE SOFTWARE.
   49.27 + */
   49.28 +
   49.29 +#ifndef _VMX_VPIC_H
   49.30 +#define _VMX_VPIC_H
   49.31 +
   49.32 +#define hw_error(x)  do {} while (0);
   49.33 +
   49.34 +
   49.35 +/* i8259.c */
   49.36 +typedef struct IOAPICState IOAPICState;
   49.37 +typedef struct PicState {
   49.38 +    uint8_t last_irr; /* edge detection */
   49.39 +    uint8_t irr; /* interrupt request register */
   49.40 +    uint8_t imr; /* interrupt mask register */
   49.41 +    uint8_t isr; /* interrupt service register */
   49.42 +    uint8_t priority_add; /* highest irq priority */
   49.43 +    uint8_t irq_base;
   49.44 +    uint8_t read_reg_select;
   49.45 +    uint8_t poll;
   49.46 +    uint8_t special_mask;
   49.47 +    uint8_t init_state;
   49.48 +    uint8_t auto_eoi;
   49.49 +    uint8_t rotate_on_auto_eoi;
   49.50 +    uint8_t special_fully_nested_mode;
   49.51 +    uint8_t init4; /* true if 4 byte init */
   49.52 +    uint8_t elcr; /* PIIX edge/trigger selection*/
   49.53 +    uint8_t elcr_mask;
   49.54 +    struct vmx_virpic *pics_state;
   49.55 +} PicState;
   49.56 +
   49.57 +struct vmx_virpic {
   49.58 +    /* 0 is master pic, 1 is slave pic */
   49.59 +    /* XXX: better separation between the two pics */
   49.60 +    PicState pics[2];
   49.61 +    void (*irq_request)(int *opaque, int level);
   49.62 +    void *irq_request_opaque;
   49.63 +    /* IOAPIC callback support */
   49.64 +    void (*alt_irq_func)(void *opaque, int irq_num, int level);
   49.65 +    void *alt_irq_opaque;
   49.66 +};
   49.67 +
   49.68 +
   49.69 +void pic_set_irq(struct vmx_virpic *s, int irq, int level);
   49.70 +void pic_set_irq_new(void *opaque, int irq, int level);
   49.71 +void pic_init(struct vmx_virpic *s, 
   49.72 +              void (*irq_request)(),
   49.73 +              void *irq_request_opaque);
   49.74 +void pic_set_alt_irq_func(struct vmx_virpic *s, 
   49.75 +                          void(*alt_irq_func)(),
   49.76 +                          void *alt_irq_opaque);
   49.77 +int pic_read_irq(struct vmx_virpic *s);
   49.78 +void pic_update_irq(struct vmx_virpic *s);
   49.79 +uint32_t pic_intack_read(struct vmx_virpic *s);
   49.80 +void register_pic_io_hook (void);
   49.81 +int cpu_get_pic_interrupt(struct vcpu *v, int *type);
   49.82 +int is_pit_irq(struct vcpu *v, int irq, int type);
   49.83 +int is_irq_enabled(struct vcpu *v, int irq);
   49.84 +void do_pic_irqs (struct vmx_virpic *s, uint16_t irqs);
   49.85 +void do_pic_irqs_clear (struct vmx_virpic *s, uint16_t irqs);
   49.86 +
   49.87 +/* APIC */
   49.88 +#endif  /* _VMX_VPIC_H */  
    50.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    50.2 +++ b/xen/include/asm-x86/vmx_vpit.h	Wed Nov 30 19:55:08 2005 +0000
    50.3 @@ -0,0 +1,55 @@
    50.4 +#ifndef _VMX_VIRPIT_H
    50.5 +#define _VMX_VIRPIT_H
    50.6 +
    50.7 +#include <xen/config.h>
    50.8 +#include <xen/init.h>
    50.9 +#include <xen/lib.h>
   50.10 +#include <xen/time.h>
   50.11 +#include <xen/errno.h>
   50.12 +#include <xen/ac_timer.h>
   50.13 +#include <asm/vmx_vmcs.h>
   50.14 +#include <asm/vmx_vpic.h>
   50.15 +
   50.16 +#define PIT_FREQ 1193181
   50.17 +
   50.18 +#define LSByte 0
   50.19 +#define MSByte 1
   50.20 +#define LSByte_multiple 2
   50.21 +#define MSByte_multiple 3
   50.22 +
   50.23 +struct vmx_virpit {
   50.24 +    /* for simulation of counter 0 in mode 2*/
   50.25 +    u64 period_cycles;	                /* pit frequency in cpu cycles */
   50.26 +    u64 inject_point; /* the time inject virt intr */
   50.27 +    s_time_t scheduled;                 /* scheduled timer interrupt */
   50.28 +    struct ac_timer pit_timer;  /* periodic timer for mode 2*/
   50.29 +    unsigned int channel;  /* the pit channel, counter 0~2 */
   50.30 +    unsigned int pending_intr_nr; /* the couner for pending timer interrupts */
   50.31 +    u32 period;		/* pit frequency in ns */
   50.32 +    int first_injected;                 /* flag to prevent shadow window */
   50.33 +    int ticking;    /* indicating it is ticking */
   50.34 +
   50.35 +    /* virtual PIT state for handle related I/O */
   50.36 +    int read_state;
   50.37 +    int count_LSB_latched;
   50.38 +    int count_MSB_latched;
   50.39 +
   50.40 +    unsigned int count;  /* the 16 bit channel count */
   50.41 +    unsigned int init_val; /* the init value for the counter */
   50.42 +};
   50.43 +
   50.44 +/* to hook the ioreq packet to get the PIT initializaiton info */
   50.45 +extern void vmx_hooks_assist(struct vcpu *v);
   50.46 +
   50.47 +static __inline__ s_time_t get_pit_scheduled(
   50.48 +    struct vcpu *v, 
   50.49 +    struct vmx_virpit *vpit)
   50.50 +{
   50.51 +    if ( is_irq_enabled(v, 0) ) {
   50.52 +        return vpit->scheduled;
   50.53 +    }
   50.54 +    else
   50.55 +        return -1;
   50.56 +}
   50.57 +
   50.58 +#endif /* _VMX_VIRPIT_H_ */
    51.1 --- a/xen/include/public/acm_ops.h	Wed Nov 30 19:54:28 2005 +0000
    51.2 +++ b/xen/include/public/acm_ops.h	Wed Nov 30 19:55:08 2005 +0000
    51.3 @@ -63,7 +63,7 @@ struct acm_getssid {
    51.4          ssidref_t    ssidref;
    51.5      } id;
    51.6      void *ssidbuf;
    51.7 -    uint16_t ssidbuf_size;
    51.8 +    uint32_t ssidbuf_size;
    51.9  };
   51.10  
   51.11  #define ACM_GETDECISION        8
    52.1 --- a/xen/include/public/dom0_ops.h	Wed Nov 30 19:54:28 2005 +0000
    52.2 +++ b/xen/include/public/dom0_ops.h	Wed Nov 30 19:55:08 2005 +0000
    52.3 @@ -19,7 +19,7 @@
    52.4   * This makes sure that old versions of dom0 tools will stop working in a
    52.5   * well-defined way (rather than crashing the machine, for instance).
    52.6   */
    52.7 -#define DOM0_INTERFACE_VERSION   0xAAAA1012
    52.8 +#define DOM0_INTERFACE_VERSION   0xAAAA1014
    52.9  
   52.10  /************************************************************************/
   52.11  
   52.12 @@ -98,7 +98,7 @@ typedef struct {
   52.13  typedef struct {
   52.14      /* IN variables. */
   52.15      domid_t               domain;
   52.16 -    uint16_t              vcpu;
   52.17 +    uint32_t              vcpu;
   52.18      /* IN/OUT parameters */
   52.19      vcpu_guest_context_t *ctxt;
   52.20  } dom0_setdomaininfo_t;
   52.21 @@ -107,7 +107,7 @@ typedef struct {
   52.22  typedef struct {
   52.23      /* IN variables. */
   52.24      uint32_t write;
   52.25 -    uint32_t cpu_mask;
   52.26 +    cpumap_t cpu_mask;
   52.27      uint32_t msr;
   52.28      uint32_t in1;
   52.29      uint32_t in2;
   52.30 @@ -116,21 +116,6 @@ typedef struct {
   52.31      uint32_t out2;
   52.32  } dom0_msr_t;
   52.33  
   52.34 -#define DOM0_DEBUG            16
   52.35 -typedef struct {
   52.36 -    /* IN variables. */
   52.37 -    domid_t  domain;
   52.38 -    uint8_t  opcode;
   52.39 -    uint32_t in1;
   52.40 -    uint32_t in2;
   52.41 -    uint32_t in3;
   52.42 -    uint32_t in4;
   52.43 -    /* OUT variables. */
   52.44 -    uint32_t status;
   52.45 -    uint32_t out1;
   52.46 -    uint32_t out2;
   52.47 -} dom0_debug_t;
   52.48 -
   52.49  /*
   52.50   * Set clock such that it would read <secs,nsecs> after 00:00:00 UTC,
   52.51   * 1 January, 1970 if the current system time was <system_time>.
   52.52 @@ -182,8 +167,8 @@ typedef struct {
   52.53  typedef struct {
   52.54      /* IN variables. */
   52.55      domid_t   domain;
   52.56 -    uint16_t  vcpu;
   52.57 -    cpumap_t cpumap;
   52.58 +    uint32_t  vcpu;
   52.59 +    cpumap_t  cpumap;
   52.60  } dom0_pincpudomain_t;
   52.61  
   52.62  /* Get trace buffers machine base address */
   52.63 @@ -196,9 +181,9 @@ typedef struct {
   52.64  #define DOM0_TBUF_SET_SIZE     3
   52.65  #define DOM0_TBUF_ENABLE       4
   52.66  #define DOM0_TBUF_DISABLE      5
   52.67 -    uint8_t op;
   52.68 +    uint32_t      op;
   52.69      /* IN/OUT variables */
   52.70 -    unsigned long cpu_mask;
   52.71 +    cpumap_t      cpu_mask;
   52.72      uint32_t      evt_mask;
   52.73      /* OUT variables */
   52.74      unsigned long buffer_mfn;
   52.75 @@ -327,7 +312,7 @@ typedef struct {
   52.76  #define DOM0_PERFCCONTROL_OP_RESET 1   /* Reset all counters to zero. */
   52.77  #define DOM0_PERFCCONTROL_OP_QUERY 2   /* Get perfctr information. */
   52.78  typedef struct {
   52.79 -    uint8_t      name[80];             /*  name of perf counter */
   52.80 +    uint8_t      name[80];             /* name of perf counter */
   52.81      uint32_t     nr_vals;              /* number of values for this counter */
   52.82      uint32_t     vals[64];             /* array of values */
   52.83  } dom0_perfc_desc_t;
   52.84 @@ -349,16 +334,16 @@ typedef struct {
   52.85  #define DOM0_IOPORT_PERMISSION   36
   52.86  typedef struct {
   52.87      domid_t  domain;                  /* domain to be affected */
   52.88 -    uint16_t first_port;              /* first port int range */
   52.89 -    uint16_t nr_ports;                /* size of port range */
   52.90 -    uint16_t allow_access;            /* allow or deny access to range? */
   52.91 +    uint32_t first_port;              /* first port int range */
   52.92 +    uint32_t nr_ports;                /* size of port range */
   52.93 +    uint8_t  allow_access;            /* allow or deny access to range? */
   52.94  } dom0_ioport_permission_t;
   52.95  
   52.96  #define DOM0_GETVCPUCONTEXT      37
   52.97  typedef struct {
   52.98      /* IN variables. */
   52.99      domid_t  domain;                  /* domain to be affected */
  52.100 -    uint16_t vcpu;                    /* vcpu # */
  52.101 +    uint32_t vcpu;                    /* vcpu # */
  52.102      /* OUT variables. */
  52.103      vcpu_guest_context_t *ctxt;
  52.104  } dom0_getvcpucontext_t;
  52.105 @@ -367,7 +352,7 @@ typedef struct {
  52.106  typedef struct {
  52.107      /* IN variables. */
  52.108      domid_t  domain;                  /* domain to be affected */
  52.109 -    uint16_t vcpu;                    /* vcpu # */
  52.110 +    uint32_t vcpu;                    /* vcpu # */
  52.111      /* OUT variables. */
  52.112      uint8_t  online;                  /* currently online (not hotplugged)? */
  52.113      uint8_t  blocked;                 /* blocked waiting for an event? */
  52.114 @@ -381,35 +366,36 @@ typedef struct {
  52.115  typedef struct {
  52.116      /* IN variables. */
  52.117      domid_t               first_domain;
  52.118 -    unsigned int          max_domains;
  52.119 +    uint32_t              max_domains;
  52.120      dom0_getdomaininfo_t *buffer;
  52.121      /* OUT variables. */
  52.122 -    unsigned int          num_domains;
  52.123 +    uint32_t              num_domains;
  52.124  } dom0_getdomaininfolist_t;
  52.125  
  52.126  #define DOM0_PLATFORM_QUIRK      39  
  52.127  #define QUIRK_NOIRQBALANCING  1
  52.128  typedef struct {
  52.129      /* IN variables. */
  52.130 -    int quirk_id;
  52.131 +    uint32_t quirk_id;
  52.132  } dom0_platform_quirk_t;
  52.133  
  52.134  #define DOM0_PHYSICAL_MEMORY_MAP 40
  52.135  typedef struct {
  52.136      /* IN variables. */
  52.137 -    int max_map_entries;
  52.138 +    uint32_t max_map_entries;
  52.139      /* OUT variables. */
  52.140 -    int nr_map_entries;
  52.141 +    uint32_t nr_map_entries;
  52.142      struct dom0_memory_map_entry {
  52.143          uint64_t start, end;
  52.144 -        int is_ram;
  52.145 +        uint32_t flags; /* reserved */
  52.146 +        uint8_t  is_ram;
  52.147      } *memory_map;
  52.148  } dom0_physical_memory_map_t;
  52.149  
  52.150  #define DOM0_MAX_VCPUS 41
  52.151  typedef struct {
  52.152 -    domid_t domain;             /* domain to be affected */
  52.153 -    unsigned int max;           /* maximum number of vcpus */
  52.154 +    domid_t  domain;        /* domain to be affected */
  52.155 +    uint32_t max;           /* maximum number of vcpus */
  52.156  } dom0_max_vcpus_t;
  52.157  
  52.158  #define DOM0_SETDOMAINHANDLE 44
  52.159 @@ -433,7 +419,6 @@ typedef struct {
  52.160          dom0_getdomaininfo_t     getdomaininfo;
  52.161          dom0_getpageframeinfo_t  getpageframeinfo;
  52.162          dom0_msr_t               msr;
  52.163 -        dom0_debug_t             debug;
  52.164          dom0_settime_t           settime;
  52.165          dom0_readconsole_t       readconsole;
  52.166          dom0_pincpudomain_t      pincpudomain;
    53.1 --- a/xen/include/public/grant_table.h	Wed Nov 30 19:54:28 2005 +0000
    53.2 +++ b/xen/include/public/grant_table.h	Wed Nov 30 19:55:08 2005 +0000
    53.3 @@ -73,14 +73,14 @@
    53.4   */
    53.5  typedef struct grant_entry {
    53.6      /* GTF_xxx: various type and flag information.  [XEN,GST] */
    53.7 -    uint16_t     flags;
    53.8 +    uint16_t flags;
    53.9      /* The domain being granted foreign privileges. [GST] */
   53.10 -    domid_t domid;
   53.11 +    domid_t  domid;
   53.12      /*
   53.13       * GTF_permit_access: Frame that @domid is allowed to map and access. [GST]
   53.14       * GTF_accept_transfer: Frame whose ownership transferred by @domid. [XEN]
   53.15       */
   53.16 -    uint32_t     frame;
   53.17 +    uint32_t frame;
   53.18  } grant_entry_t;
   53.19  
   53.20  /*
   53.21 @@ -131,7 +131,12 @@ typedef struct grant_entry {
   53.22  /*
   53.23   * Reference to a grant entry in a specified domain's grant table.
   53.24   */
   53.25 -typedef uint16_t grant_ref_t;
   53.26 +typedef uint32_t grant_ref_t;
   53.27 +
   53.28 +/*
   53.29 + * Handle to track a mapping created via a grant reference.
   53.30 + */
   53.31 +typedef uint32_t grant_handle_t;
   53.32  
   53.33  /*
   53.34   * GNTTABOP_map_grant_ref: Map the grant entry (<dom>,<ref>) for access
   53.35 @@ -154,11 +159,12 @@ typedef uint16_t grant_ref_t;
   53.36  typedef struct gnttab_map_grant_ref {
   53.37      /* IN parameters. */
   53.38      uint64_t host_addr;
   53.39 -    domid_t  dom;
   53.40 +    uint32_t flags;               /* GNTMAP_* */
   53.41      grant_ref_t ref;
   53.42 -    uint16_t flags;               /* GNTMAP_* */
   53.43 +    domid_t  dom;
   53.44      /* OUT parameters. */
   53.45 -    int16_t  handle;              /* +ve: handle; -ve: GNTST_* */
   53.46 +    int16_t  status;              /* GNTST_* */
   53.47 +    grant_handle_t handle;
   53.48      uint64_t dev_bus_addr;
   53.49  } gnttab_map_grant_ref_t;
   53.50  
   53.51 @@ -178,7 +184,7 @@ typedef struct gnttab_unmap_grant_ref {
   53.52      /* IN parameters. */
   53.53      uint64_t host_addr;
   53.54      uint64_t dev_bus_addr;
   53.55 -    uint16_t handle;
   53.56 +    grant_handle_t handle;
   53.57      /* OUT parameters. */
   53.58      int16_t  status;              /* GNTST_* */
   53.59  } gnttab_unmap_grant_ref_t;
   53.60 @@ -196,7 +202,7 @@ typedef struct gnttab_unmap_grant_ref {
   53.61  typedef struct gnttab_setup_table {
   53.62      /* IN parameters. */
   53.63      domid_t  dom;
   53.64 -    uint16_t nr_frames;
   53.65 +    uint32_t nr_frames;
   53.66      /* OUT parameters. */
   53.67      int16_t  status;              /* GNTST_* */
   53.68      unsigned long *frame_list;
   53.69 @@ -283,7 +289,8 @@ typedef struct {
   53.70      "invalid virtual address",                  \
   53.71      "invalid device address",                   \
   53.72      "no spare translation slot in the I/O MMU", \
   53.73 -    "permission denied"                         \
   53.74 +    "permission denied",                        \
   53.75 +    "bad page"                                  \
   53.76  }
   53.77  
   53.78  #endif /* __XEN_PUBLIC_GRANT_TABLE_H__ */
    54.1 --- a/xen/include/public/io/blkif.h	Wed Nov 30 19:54:28 2005 +0000
    54.2 +++ b/xen/include/public/io/blkif.h	Wed Nov 30 19:55:08 2005 +0000
    54.3 @@ -19,9 +19,6 @@
    54.4  #define BLKIF_OP_READ      0
    54.5  #define BLKIF_OP_WRITE     1
    54.6  
    54.7 -/* NB. Ring size must be small enough for sizeof(blkif_ring_t) <= PAGE_SIZE. */
    54.8 -#define BLKIF_RING_SIZE        64
    54.9 -
   54.10  /*
   54.11   * Maximum scatter/gather segments per request.
   54.12   * This is carefully chosen so that sizeof(blkif_ring_t) <= PAGE_SIZE.
   54.13 @@ -33,24 +30,18 @@ typedef struct blkif_request {
   54.14      uint8_t        operation;    /* BLKIF_OP_???                         */
   54.15      uint8_t        nr_segments;  /* number of segments                   */
   54.16      blkif_vdev_t   handle;       /* only for read/write requests         */
   54.17 -    unsigned long  id;           /* private guest value, echoed in resp  */
   54.18 +    uint64_t       id;           /* private guest value, echoed in resp  */
   54.19      blkif_sector_t sector_number;/* start sector idx on disk (r/w only)  */
   54.20 -    /* @f_a_s[4:0]=last_sect ; @f_a_s[9:5]=first_sect                        */
   54.21 -    /* @f_a_s[:16]= grant reference (16 bits)                                */
   54.22 -    /* @first_sect: first sector in frame to transfer (inclusive).           */
   54.23 -    /* @last_sect: last sector in frame to transfer (inclusive).             */
   54.24 -    unsigned long  frame_and_sects[BLKIF_MAX_SEGMENTS_PER_REQUEST];
   54.25 +    struct blkif_request_segment {
   54.26 +        grant_ref_t gref;        /* reference to I/O buffer frame        */
   54.27 +        /* @first_sect: first sector in frame to transfer (inclusive).   */
   54.28 +        /* @last_sect: last sector in frame to transfer (inclusive).     */
   54.29 +        uint8_t     first_sect, last_sect;
   54.30 +    } seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
   54.31  } blkif_request_t;
   54.32  
   54.33 -#define blkif_fas(_addr, _fs, _ls) ((_addr)|((_fs)<<5)|(_ls))
   54.34 -#define blkif_first_sect(_fas) (((_fas)>>5)&31)
   54.35 -#define blkif_last_sect(_fas)  ((_fas)&31)
   54.36 -
   54.37 -#define blkif_fas_from_gref(_gref, _fs, _ls) (((_gref)<<16)|((_fs)<<5)|(_ls))
   54.38 -#define blkif_gref_from_fas(_fas) ((_fas)>>16)
   54.39 -
   54.40  typedef struct blkif_response {
   54.41 -    unsigned long   id;              /* copied from request */
   54.42 +    uint64_t        id;              /* copied from request */
   54.43      uint8_t         operation;       /* copied from request */
   54.44      int16_t         status;          /* BLKIF_RSP_???       */
   54.45  } blkif_response_t;
   54.46 @@ -58,9 +49,6 @@ typedef struct blkif_response {
   54.47  #define BLKIF_RSP_ERROR  -1 /* non-specific 'error' */
   54.48  #define BLKIF_RSP_OKAY    0 /* non-specific 'okay'  */
   54.49  
   54.50 -#define BLKIF_MAJOR(dev) ((dev)>>8)
   54.51 -#define BLKIF_MINOR(dev) ((dev) & 0xff)
   54.52 -
   54.53  /*
   54.54   * Generate blkif ring structures and types.
   54.55   */
    55.1 --- a/xen/include/public/io/tpmif.h	Wed Nov 30 19:54:28 2005 +0000
    55.2 +++ b/xen/include/public/io/tpmif.h	Wed Nov 30 19:55:08 2005 +0000
    55.3 @@ -18,7 +18,7 @@
    55.4  
    55.5  typedef struct {
    55.6      unsigned long addr;   /* Machine address of packet.   */
    55.7 -    int      ref;         /* grant table access reference */
    55.8 +    grant_ref_t ref;      /* grant table access reference */
    55.9      uint16_t id;          /* Echoed in response message.  */
   55.10      uint16_t size;        /* Packet size in bytes.        */
   55.11  } tpmif_tx_request_t;
    56.1 --- a/xen/include/public/io/vmx_vlapic.h	Wed Nov 30 19:54:28 2005 +0000
    56.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    56.3 @@ -1,58 +0,0 @@
    56.4 -#ifndef _VMX_VLAPIC_H
    56.5 -#define _VMX_VLAPIC_H
    56.6 -
    56.7 -/*
    56.8 -   We extended one bit for PIC type
    56.9 - */
   56.10 -#define VLAPIC_DELIV_MODE_FIXED          0x0
   56.11 -#define VLAPIC_DELIV_MODE_LPRI           0x1
   56.12 -#define VLAPIC_DELIV_MODE_SMI            0x2
   56.13 -#define VLAPIC_DELIV_MODE_NMI            0x4
   56.14 -#define VLAPIC_DELIV_MODE_INIT           0x5
   56.15 -#define VLAPIC_DELIV_MODE_STARTUP        0x6
   56.16 -#define VLAPIC_DELIV_MODE_EXT            0x7
   56.17 -#define VLAPIC_DELIV_MODE_MASK            0x8
   56.18 -
   56.19 -#define VLAPIC_MSG_LEVEL                4
   56.20 -
   56.21 -#define INTR_EXT   0
   56.22 -#define INTR_APIC   1
   56.23 -#define INTR_LAPIC  2
   56.24 -
   56.25 -#define VL_STATE_EOI    1
   56.26 -#define VL_STATE_EXT_LOCK   2
   56.27 -#define VL_STATE_MSG_LOCK   3
   56.28 -#define VL_STATE_EOI_LOCK   3
   56.29 -
   56.30 -#define VLOCAL_APIC_MAX_INTS             256
   56.31 -#define VLAPIC_INT_COUNT                (VLOCAL_APIC_MAX_INTS/(BITS_PER_BYTE * sizeof(uint64_t)))
   56.32 -#define VLAPIC_INT_COUNT_32             (VLOCAL_APIC_MAX_INTS/(BITS_PER_BYTE * sizeof(uint32_t)))
   56.33 -
   56.34 -typedef struct {
   56.35 -    /* interrupt for PIC and ext type IOAPIC interrupt */
   56.36 -    uint64_t   vl_ext_intr[VLAPIC_INT_COUNT];
   56.37 -    uint64_t   vl_ext_intr_mask[VLAPIC_INT_COUNT];
   56.38 -    uint64_t   vl_apic_intr[VLAPIC_INT_COUNT];
   56.39 -    uint64_t   vl_apic_tmr[VLAPIC_INT_COUNT];
   56.40 -    uint64_t   vl_eoi[VLAPIC_INT_COUNT];
   56.41 -    uint32_t   vl_lapic_id;
   56.42 -    uint32_t   direct_intr;
   56.43 -    uint32_t   vl_apr;
   56.44 -    uint32_t   vl_logical_dest;
   56.45 -    uint32_t   vl_dest_format;
   56.46 -    uint32_t   vl_arb_id;
   56.47 -    uint32_t   vl_state;
   56.48 -    uint32_t   apic_msg_count;
   56.49 -} vlapic_info;
   56.50 -
   56.51 -#endif /* _VMX_VLAPIC_H_ */
   56.52 -
   56.53 -/*
   56.54 - * Local variables:
   56.55 - * mode: C
   56.56 - * c-set-style: "BSD"
   56.57 - * c-basic-offset: 4
   56.58 - * tab-width: 4
   56.59 - * indent-tabs-mode: nil
   56.60 - * End:
   56.61 - */
    57.1 --- a/xen/include/public/io/vmx_vpic.h	Wed Nov 30 19:54:28 2005 +0000
    57.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    57.3 @@ -1,85 +0,0 @@
    57.4 -/*
    57.5 - * QEMU System Emulator header
    57.6 - * 
    57.7 - * Copyright (c) 2003 Fabrice Bellard
    57.8 - * Copyright (c) 2005 Intel Corp
    57.9 - * 
   57.10 - * Permission is hereby granted, free of charge, to any person obtaining a copy
   57.11 - * of this software and associated documentation files (the "Software"), to deal
   57.12 - * in the Software without restriction, including without limitation the rights
   57.13 - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   57.14 - * copies of the Software, and to permit persons to whom the Software is
   57.15 - * furnished to do so, subject to the following conditions:
   57.16 - *
   57.17 - * The above copyright notice and this permission notice shall be included in
   57.18 - * all copies or substantial portions of the Software.
   57.19 - *
   57.20 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   57.21 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   57.22 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
   57.23 - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   57.24 - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   57.25 - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   57.26 - * THE SOFTWARE.
   57.27 - */
   57.28 -
   57.29 -#ifndef _VMX_VPIC_H
   57.30 -#define _VMX_VPIC_H
   57.31 -
   57.32 -#define hw_error(x)  do {} while (0);
   57.33 -
   57.34 -
   57.35 -/* i8259.c */
   57.36 -typedef struct IOAPICState IOAPICState;
   57.37 -typedef struct PicState {
   57.38 -    uint8_t last_irr; /* edge detection */
   57.39 -    uint8_t irr; /* interrupt request register */
   57.40 -    uint8_t imr; /* interrupt mask register */
   57.41 -    uint8_t isr; /* interrupt service register */
   57.42 -    uint8_t priority_add; /* highest irq priority */
   57.43 -    uint8_t irq_base;
   57.44 -    uint8_t read_reg_select;
   57.45 -    uint8_t poll;
   57.46 -    uint8_t special_mask;
   57.47 -    uint8_t init_state;
   57.48 -    uint8_t auto_eoi;
   57.49 -    uint8_t rotate_on_auto_eoi;
   57.50 -    uint8_t special_fully_nested_mode;
   57.51 -    uint8_t init4; /* true if 4 byte init */
   57.52 -    uint8_t elcr; /* PIIX edge/trigger selection*/
   57.53 -    uint8_t elcr_mask;
   57.54 -    struct vmx_virpic *pics_state;
   57.55 -} PicState;
   57.56 -
   57.57 -struct vmx_virpic {
   57.58 -    /* 0 is master pic, 1 is slave pic */
   57.59 -    /* XXX: better separation between the two pics */
   57.60 -    PicState pics[2];
   57.61 -    void (*irq_request)(int *opaque, int level);
   57.62 -    void *irq_request_opaque;
   57.63 -    /* IOAPIC callback support */
   57.64 -    void (*alt_irq_func)(void *opaque, int irq_num, int level);
   57.65 -    void *alt_irq_opaque;
   57.66 -};
   57.67 -
   57.68 -
   57.69 -void pic_set_irq(struct vmx_virpic *s, int irq, int level);
   57.70 -void pic_set_irq_new(void *opaque, int irq, int level);
   57.71 -void pic_init(struct vmx_virpic *s, 
   57.72 -              void (*irq_request)(),
   57.73 -              void *irq_request_opaque);
   57.74 -void pic_set_alt_irq_func(struct vmx_virpic *s, 
   57.75 -                          void(*alt_irq_func)(),
   57.76 -                          void *alt_irq_opaque);
   57.77 -int pic_read_irq(struct vmx_virpic *s);
   57.78 -void pic_update_irq(struct vmx_virpic *s);
   57.79 -uint32_t pic_intack_read(struct vmx_virpic *s);
   57.80 -void register_pic_io_hook (void);
   57.81 -int cpu_get_pic_interrupt(struct vcpu *v, int *type);
   57.82 -int is_pit_irq(struct vcpu *v, int irq, int type);
   57.83 -int is_irq_enabled(struct vcpu *v, int irq);
   57.84 -void do_pic_irqs (struct vmx_virpic *s, uint16_t irqs);
   57.85 -void do_pic_irqs_clear (struct vmx_virpic *s, uint16_t irqs);
   57.86 -
   57.87 -/* APIC */
   57.88 -#endif  /* _VMX_VPIC_H */  
    58.1 --- a/xen/include/public/sched_ctl.h	Wed Nov 30 19:54:28 2005 +0000
    58.2 +++ b/xen/include/public/sched_ctl.h	Wed Nov 30 19:55:08 2005 +0000
    58.3 @@ -48,8 +48,8 @@ struct sched_adjdom_cmd {
    58.4              uint64_t period;
    58.5              uint64_t slice;
    58.6              uint64_t latency;
    58.7 -            uint16_t extratime;
    58.8 -            uint16_t weight;
    58.9 +            uint32_t extratime;
   58.10 +            uint32_t weight;
   58.11          } sedf;
   58.12  
   58.13      } u;
    59.1 --- a/xen/include/public/xen.h	Wed Nov 30 19:54:28 2005 +0000
    59.2 +++ b/xen/include/public/xen.h	Wed Nov 30 19:55:08 2005 +0000
    59.3 @@ -410,9 +410,9 @@ typedef struct start_info {
    59.4      unsigned long shared_info;  /* MACHINE address of shared info struct. */
    59.5      uint32_t flags;             /* SIF_xxx flags.                         */
    59.6      unsigned long store_mfn;    /* MACHINE page number of shared page.    */
    59.7 -    uint16_t store_evtchn;      /* Event channel for store communication. */
    59.8 +    uint32_t store_evtchn;      /* Event channel for store communication. */
    59.9      unsigned long console_mfn;  /* MACHINE address of console page.       */
   59.10 -    uint16_t console_evtchn;    /* Event channel for console messages.    */
   59.11 +    uint32_t console_evtchn;    /* Event channel for console messages.    */
   59.12      /* THE FOLLOWING ARE ONLY FILLED IN ON INITIAL BOOT (NOT RESUME).     */
   59.13      unsigned long pt_base;      /* VIRTUAL address of page directory.     */
   59.14      unsigned long nr_pt_frames; /* Number of bootstrap p.t. frames.       */