aboutsummaryrefslogtreecommitdiffstats
path: root/test/testdyn.c
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2013-06-12 09:19:04 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2013-06-12 09:19:04 +0000
commit649818477a69c38e186a638e810013d860760e26 (patch)
treed9cc954d36a773e8b5ec816160fb7659c6c2298a /test/testdyn.c
parentf08f9497530e3cd82b17260638867cf5e354a742 (diff)
downloadChibiOS-649818477a69c38e186a638e810013d860760e26.tar.gz
ChibiOS-649818477a69c38e186a638e810013d860760e26.tar.bz2
ChibiOS-649818477a69c38e186a638e810013d860760e26.zip
DSPI changes for SPC56ELxx.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5838 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'test/testdyn.c')
0 files changed, 0 insertions, 0 deletions
1 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
diff -uprN tpm_emulator/AUTHORS vtpm/AUTHORS
--- tpm_emulator/AUTHORS	2006-07-24 14:35:35.000000000 -0700
+++ vtpm/AUTHORS	2006-07-24 14:35:35.000000000 -0700
@@ -1,3 +1,3 @@
 Mario Strasser <mast@gmx.net>
 Heiko Stamer <stamer@gaos.org> [DAA]
-INTEL Corp <> [Dropped to Ring3]
+INTEL Corp <> [VTPM Extensions]
diff -uprN tpm_emulator/ChangeLog vtpm/ChangeLog
--- tpm_emulator/ChangeLog	2006-07-24 14:35:35.000000000 -0700
+++ vtpm/ChangeLog	2006-07-24 14:35:35.000000000 -0700
@@ -1,5 +1,6 @@
 ????-??-?? Intel Corp
 	* Moved module out of kernel to run as a ring 3 app
+	* Modified save_to_file and load_from_file to call xen VTPM manager
 
 2006-06-23  Mario Strasser <mast@gmx.net>
 	* tpm_startup.c: behaviour of ST_CLEAR and storage of
diff -uprN tpm_emulator/linux_module.h vtpm/linux_module.h
--- tpm_emulator/linux_module.h	2006-07-24 14:35:35.000000000 -0700
+++ vtpm/linux_module.h	2006-07-24 14:35:35.000000000 -0700
@@ -44,18 +44,21 @@
 #define TPM_DEVICE_NAME   "tpm"
 #define TPM_MODULE_NAME   "tpm_emulator"
 
+/* debug and log output functions */
+extern int dmi_id; 
+
 #ifdef DEBUG
-#define debug(fmt, ...) printf("TPMD: %s:%d: Debug: " fmt "\n", \
-                        __FILE__, __LINE__, ## __VA_ARGS__)
+#define debug(fmt, ...) printf("TPMD[%d]: %s:%d: Debug: " fmt "\n", \
+                        dmi_id, __FILE__, __LINE__, ## __VA_ARGS__)
 #else
 #define debug(fmt, ...) 
 #endif
-#define info(fmt, ...)  printf("TPMD: %s:%d: Info: " fmt "\n", \
-                        __FILE__, __LINE__, ## __VA_ARGS__)
-#define error(fmt, ...) printf("TPMD: %s:%d: Error: " fmt "\n", \
-                        __FILE__, __LINE__, ## __VA_ARGS__)
-#define alert(fmt, ...) printf("TPMD: %s:%d: Alert: " fmt "\n", \
-                        __FILE__, __LINE__, ## __VA_ARGS__)
+#define info(fmt, ...)  printf("TPMD[%d]: %s:%d: Info: " fmt "\n", \
+                        dmi_id, __FILE__, __LINE__, ## __VA_ARGS__)
+#define error(fmt, ...) printf("TPMD[%d]: %s:%d: Error: " fmt "\n", \
+                        dmi_id, __FILE__, __LINE__, ## __VA_ARGS__)
+#define alert(fmt, ...) printf("TPMD[%d]: %s:%d: Alert: " fmt "\n", \
+                        dmi_id, __FILE__, __LINE__, ## __VA_ARGS__)
 
 /* memory allocation */
 
diff -uprN tpm_emulator/Makefile vtpm/Makefile
--- tpm_emulator/Makefile	2006-07-24 14:35:35.000000000 -0700
+++ vtpm/Makefile	2006-07-24 14:35:35.000000000 -0700
@@ -7,7 +7,7 @@
 COMPILE_ARCH    ?= $(shell uname -m | sed -e s/i.86/x86_32/)
 
 # module settings
-BIN            := tpm_emulator
+BIN            := vtpmd
 VERSION_MAJOR  := 0
 VERSION_MINOR  := 4
 VERSION_BUILD  := $(shell date +"%s")
@@ -22,7 +22,7 @@ TOOLS_INSTALL_DIR = $(DESTDIR)/usr/bin
 
 CC      := gcc
 CFLAGS  += -g -Wall $(INCLUDE) -DDEBUG
-CFLAGS  += -I. -Itpm
+CFLAGS  += -I. -Itpm -I../../vtpm_manager/manager
 
 # Is the simulator running in it's own vm?
 #CFLAGS += -DVTPM_MULTI_VM
@@ -62,7 +62,6 @@ $(BIN):	$(src)/crypto/gmp.h $(src)/crypt
 
 install: $(BIN)
 	$(INSTALL_PROG) $(BIN) $(TOOLS_INSTALL_DIR)
-	@if [ ! -d "/var/tpm" ]; then mkdir /var/tpm; fi
 
 clean:
 	rm -f $(src)/crypto/gmp.h $(src)/crypto/libgmp.a $(OBJS)
@@ -98,3 +97,4 @@ version:
 	@echo "#endif /* _TPM_VERSION_H_ */" >> $(src)/tpm_version.h
 
 .PHONY: all install clean dist gmp version
+
diff -uprN tpm_emulator/tpm/tpm_data.c vtpm/tpm/tpm_data.c
--- tpm_emulator/tpm/tpm_data.c	2006-07-24 14:35:35.000000000 -0700
+++ vtpm/tpm/tpm_data.c	2006-07-24 14:35:35.000000000 -0700
@@ -1,6 +1,7 @@
 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
  * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
  *                    Swiss Federal Institute of Technology (ETH) Zurich
+ * Copyright (C) 2005 INTEL Corp
  *
  * This module is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published
@@ -15,10 +16,15 @@
  * $Id: tpm_data.c 98 2006-05-07 14:16:29Z hstamer $
  */
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
 #include "tpm_emulator.h"
 #include "tpm_structures.h"
 #include "tpm_marshalling.h"
-#include "linux_module.h"
+#include "vtpm_manager.h"
 
 TPM_DATA tpmData;
 
@@ -158,45 +164,232 @@ void tpm_release_data(void)
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <unistd.h>
 
-#define TPM_STORAGE_FILE "/var/tpm/tpm_emulator-1.2." STR(VERSION_MAJOR) "." STR(VERSION_MINOR) 
+ static int vtpm_tx_fh=-1, vtpm_rx_fh=-1;
+
+#ifdef VTPM_MUTLI_VM
+ #define DEV_FE "/dev/tpm"
+#else
+ #define VTPM_RX_FIFO_D  "/var/vtpm/fifos/vtpm_rsp_to_%d.fifo"
+ #define VTPM_TX_FIFO  "/var/vtpm/fifos/vtpm_cmd_from_all.fifo"
+
+ extern int dmi_id;
+ static char *vtpm_rx_name=NULL; 
+#endif
 
 static int write_to_file(uint8_t *data, size_t data_length)
 {
-  int res;
-  int fp;
-  fp = open(TPM_STORAGE_FILE, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
-  res = write(fp, data, data_length);
-  close(fp);
-  return (res == data_length) ? 0 : -1;
+  int res, out_data_size, in_header_size;
+  BYTE *ptr, *out_data, *in_header;
+  UINT32 result, len, in_rsp_size;
+  UINT16 tag = VTPM_TAG_REQ;
+	
+  printf("Saving NVM\n");
+  if (vtpm_tx_fh < 0) {
+#ifdef VTPM_MUTLI_VM
+    vtpm_tx_fh = open(DEV_FE, O_RDWR);
+#else
+	vtpm_tx_fh = open(VTPM_TX_FIFO, O_WRONLY);
+#endif
+  }
+
+  if (vtpm_tx_fh < 0) {
+		return -1;
+  }
+ 
+  // Send request to VTPM Manager to encrypt data
+#ifdef VTPM_MUTLI_VM
+  out_data_size = len = VTPM_COMMAND_HEADER_SIZE_CLT + data_length;
+#else
+  out_data_size = len = VTPM_COMMAND_HEADER_SIZE_SRV + data_length;
+#endif
+  
+  out_data = ptr = (BYTE *) malloc(len);
+
+  if (ptr == NULL
+#ifndef VTPM_MUTLI_VM
+      || tpm_marshal_UINT32(&ptr, &len, dmi_id)
+#endif
+	  || tpm_marshal_UINT16(&ptr, &len, tag)
+#ifdef VTPM_MUTLI_VM
+	  || tpm_marshal_UINT32(&ptr, &len, out_data_size)
+#else
+	  || tpm_marshal_UINT32(&ptr, &len, out_data_size - sizeof(uint32_t))
+#endif  
+	  || tpm_marshal_UINT32(&ptr, &len, VTPM_ORD_SAVENVM)
+	  || tpm_marshal_BYTE_ARRAY(&ptr, &len, data, data_length)) {
+	free(out_data);
+	return -1;
+  }
+  
+  printf("\tSending SaveNVM Command.\n");
+  res = write(vtpm_tx_fh, out_data, out_data_size);
+  free(out_data);
+  if (res != out_data_size) return -1;
+
+  if (vtpm_rx_fh < 0) {
+#ifdef VTPM_MUTLI_VM
+    vtpm_rx_fh = vtpm_tx_fh
+#else
+    if (vtpm_rx_name == NULL) {
+      vtpm_rx_name = malloc(10 + strlen(VTPM_RX_FIFO_D));
+      sprintf(vtpm_rx_name, VTPM_RX_FIFO_D, (uint32_t) dmi_id);
+    }
+	vtpm_rx_fh = open(vtpm_rx_name, O_RDONLY);
+#endif
+  }
+
+  if (vtpm_rx_fh < 0) {
+		return -1;
+  }
+  
+  // Read Header of response so we can get the size & status
+#ifdef VTPM_MUTLI_VM
+  in_header_size = len = VTPM_COMMAND_HEADER_SIZE_CLT;
+#else
+  in_header_size = len = VTPM_COMMAND_HEADER_SIZE_SRV;
+#endif
+  in_header = ptr = malloc(in_header_size);
+  
+  printf("\tReading SaveNVM header.\n");
+  res = read(vtpm_rx_fh, in_header, in_header_size);
+
+  if ( (res != in_header_size)
+#ifndef VTPM_MUTLI_VM
+       || tpm_unmarshal_UINT32(&ptr, &len, (UINT32*)&dmi_id)
+#endif
+	   || tpm_unmarshal_UINT16(&ptr, &len, &tag)
+	   || tpm_unmarshal_UINT32(&ptr, &len, &in_rsp_size)
+	   || tpm_unmarshal_UINT32(&ptr, &len, &result) ) {
+	  free(in_header);
+	  return -1;
+  }
+  free(in_header);
+  
+  if (result != VTPM_SUCCESS) {
+      return -1;  
+  }
+
+#ifdef VTPM_MUTLI_VM
+  close(vtpm_tx_fh); close(vtpm_rx_fh);
+#endif
+	  
+  printf("\tFinishing up SaveNVM\n");
+  return (0);
 }
 
 static int read_from_file(uint8_t **data, size_t *data_length)
 {
-  int res;
-  int fp, file_status;
-  struct stat file_info;
-  fp = open(TPM_STORAGE_FILE, O_RDONLY, 0);
-  file_status = fstat(fp, &file_info);
-  if (file_status < 0) {
-    close(fp);
-    return -1;
-  } 
+  int res, out_data_size, in_header_size;
+  uint8_t *ptr, *out_data, *in_header;
+  UINT16 tag = VTPM_TAG_REQ;
+  UINT32 len, in_rsp_size, result;
+#ifdef VTPM_MUTLI_VM
+	int vtpm_rx_fh, vtpm_tx_fh;
+#endif
+	
+  printf("Loading NVM.\n");
+  if (vtpm_tx_fh < 0) {
+#ifdef VTPM_MUTLI_VM
+    vtpm_tx_fh = open(DEV_FE, O_RDWR);
+#else
+	vtpm_tx_fh = open(VTPM_TX_FIFO, O_WRONLY);
+#endif
+  }
 
-  *data_length = file_info.st_size; 
-  *data = tpm_malloc(*data_length);
-  if (*data == NULL) {
-    close(fp);
+  if (vtpm_tx_fh < 0) {
+		return -1;
+  }
+ 
+  // Send request to VTPM Manager to encrypt data
+#ifdef VTPM_MUTLI_VM
+  out_data_size = len = VTPM_COMMAND_HEADER_SIZE_CLT;
+#else
+  out_data_size = len = VTPM_COMMAND_HEADER_SIZE_SRV;
+#endif
+  out_data = ptr = (BYTE *) malloc(len);
+
+  if (ptr == NULL
+#ifndef VTPM_MUTLI_VM
+      || tpm_marshal_UINT32(&ptr, &len, dmi_id)
+#endif  
+      || tpm_marshal_UINT16(&ptr, &len, tag)
+#ifdef VTPM_MUTLI_VM
+      || tpm_marshal_UINT32(&ptr, &len, out_data_size)
+#else
+      || tpm_marshal_UINT32(&ptr, &len, out_data_size - sizeof(uint32_t))
+#endif
+      || tpm_marshal_UINT32(&ptr, &len, VTPM_ORD_LOADNVM)) {
+    free(out_data);
     return -1;
   }
-  res = read(fp, *data, *data_length);
-  close(fp);
+
+  printf("\tSending LoadNVM command\n");
+  res = write(vtpm_tx_fh, out_data, out_data_size);
+  free(out_data);
+  if (res != out_data_size) return -1;
+
+    if (vtpm_rx_fh < 0) {
+#ifdef VTPM_MUTLI_VM
+    vtpm_rx_fh = vtpm_tx_fh;
+#else
+    if (vtpm_rx_name == NULL) {
+      vtpm_rx_name = malloc(10 + strlen(VTPM_RX_FIFO_D));
+      sprintf(vtpm_rx_name, VTPM_RX_FIFO_D, (uint32_t) dmi_id);
+    }
+	vtpm_rx_fh = open(vtpm_rx_name, O_RDONLY);
+#endif
+  }
+
+  if (vtpm_rx_fh < 0) {
+		return -1;
+  }
+  
+  // Read Header of response so we can get the size & status
+#ifdef VTPM_MUTLI_VM
+  in_header_size = len = VTPM_COMMAND_HEADER_SIZE_CLT;
+#else
+  in_header_size = len = VTPM_COMMAND_HEADER_SIZE_SRV;
+#endif
+  in_header = ptr = malloc(in_header_size);
+  
+  printf("\tReading LoadNVM header\n");
+  res = read(vtpm_rx_fh, in_header, in_header_size);
+
+  if ( (res != in_header_size)
+#ifndef VTPM_MUTLI_VM
+       || tpm_unmarshal_UINT32(&ptr, &len, (UINT32*)&dmi_id)
+#endif
+       || tpm_unmarshal_UINT16(&ptr, &len, &tag)
+       || tpm_unmarshal_UINT32(&ptr, &len, &in_rsp_size)
+       || tpm_unmarshal_UINT32(&ptr, &len, &result) ) {
+      free(in_header);
+      return -1;
+  }
+  free(in_header);
+  
+  if (result != VTPM_SUCCESS) {
+      return -1;  
+  }
+
+  // Read Encrypted data from VTPM Manager
+  *data_length = in_rsp_size - VTPM_COMMAND_HEADER_SIZE_CLT;
+  *data = (uint8_t *) malloc(*data_length);
+
+  printf("\tReading clear data from LoadNVM.\n");
+  res = read(vtpm_rx_fh, *data, *data_length);
+#ifdef VTPM_MUTLI_VM
+  close(vtpm_rx_fh);close(vtpm_tx_fh);
+#endif 
+	
+  printf("\tReturing from loading NVM\n");
   if (res != *data_length) {
-    tpm_free(*data);
-    return -1;
+      free(*data);
+      return -1;
+  } else {
+      return 0;
   }
-  return 0;
+
 }
 
 #else
diff -uprN tpm_emulator/tpmd.c vtpm/tpmd.c
--- tpm_emulator/tpmd.c	2006-07-24 14:35:35.000000000 -0700
+++ vtpm/tpmd.c	2006-07-24 14:35:35.000000000 -0700
@@ -23,13 +23,27 @@
 #include <sys/time.h>
 
 #include "tpm_emulator.h"
+#include "vtpm_manager.h"
 
-#define TPM_RX_FNAME "/var/tpm/tpm_in.fifo"
-#define TPM_TX_FNAME "/var/tpm/tpm_out.fifo"
+#ifdef VTPM_MULTI_VM
+ #define DEV_BE "/dev/vtpm"
+#else
+ #define GUEST_RX_FIFO_D "/var/vtpm/fifos/tpm_cmd_to_%d.fifo"
+ #define GUEST_TX_FIFO "/var/vtpm/fifos/tpm_rsp_from_all.fifo"
+#endif
 
+ int dmi_id;
+						
 #define BUFFER_SIZE 2048
 
+static uint8_t ctrl_msg[] = { 0, 0, 0, 0,   // destination
+                              1, 193,       // VTPM_TAG
+                              0, 0, 0, 10,  // Size
+                              0, 0, 0, 0};  // TPM_SUCCESS
+                            
+
 static int devurandom=0;
+
 	  
 void get_random_bytes(void *buf, int nbytes) {
   
@@ -52,18 +66,26 @@ uint64_t tpm_get_ticks(void)
 
 int main(int argc, char **argv)
 {
-  uint8_t in[BUFFER_SIZE], *out;
+  uint8_t in[BUFFER_SIZE], *out, *addressed_out;
   uint32_t out_size;
   int in_size, written;
-  int i;
-  struct stat file_info;
-
-  int tpm_tx_fh=-1, tpm_rx_fh=-1;
+  int i, guest_id=-1;
+ 
+  int vtpm_tx_fh=-1, vtpm_rx_fh=-1;
+#ifdef VTPM_MULTI_VM
   if (argc < 2) {
     printf("Usage: tpmd clear|save|deactivated\n" );
+#else
+  if (argc < 3) {
+    printf("Usage: tpmd clear|save|deactivated vtpmid\n" );
+#endif
 	  return -1;
   }
 
+#ifndef VTPM_MULTI_VM
+  dmi_id = atoi(argv[2]);
+#endif
+
   /* initialize TPM emulator */
   if (!strcmp(argv[1], "clear")) {
     printf("Initializing tpm: %s\n", argv[1]);
@@ -80,46 +102,30 @@ int main(int argc, char **argv)
     return -1;
   }
 
-  if ( stat(TPM_RX_FNAME, &file_info) == -1) {
-    if ( mkfifo(TPM_RX_FNAME, S_IWUSR | S_IRUSR ) ) {
-      printf("Failed to create fifo %s.\n", TPM_RX_FNAME);
-      return -1;
-    }
-  }
-
-  if ( stat(TPM_TX_FNAME, &file_info) == -1) {
-    if ( mkfifo(TPM_TX_FNAME, S_IWUSR | S_IRUSR ) ) {
-      printf("Failed to create fifo %s.\n", TPM_TX_FNAME);
-      return -1;
-    }
-  }
-
+  char *guest_rx_file = malloc(10 + strlen(GUEST_RX_FIFO_D));
+  sprintf(guest_rx_file, GUEST_RX_FIFO_D, (uint32_t) dmi_id);
+  
   while (1) {
 abort_command:
-    if (tpm_rx_fh < 0) {
-      tpm_rx_fh = open(TPM_RX_FNAME, O_RDONLY);
+    if (vtpm_rx_fh < 0) {
+#ifdef VTPM_MUTLI_VM
+	  vtpm_rx_fh = open(DEV_BE, O_RDWR);
+#else
+      vtpm_rx_fh = open(guest_rx_file, O_RDONLY);
+#endif
     }
     
-    if (tpm_rx_fh < 0) {
+    if (vtpm_rx_fh < 0) {
       printf("ERROR: failed to open devices to listen to guest.\n");
       return -1;
     }
     
-    if (tpm_tx_fh < 0) {
-      tpm_tx_fh = open(TPM_TX_FNAME, O_WRONLY);
-    }
-
-    if (tpm_tx_fh < 0) {
-      printf("ERROR: failed to open devices to respond to guest.\n");
-      return -1;
-    }
-
-    in_size = read(tpm_rx_fh, in, BUFFER_SIZE);
+    in_size = read(vtpm_rx_fh, in, BUFFER_SIZE);
     if (in_size < 6) { // Magic size of minium TPM command
       printf("Recv[%d] to small: 0x", in_size);
       if (in_size <= 0) {
-          close(tpm_rx_fh);
-          tpm_rx_fh = -1;
+          close(vtpm_rx_fh);
+          vtpm_rx_fh = -1;
           goto abort_command;
       }
     } else { 
@@ -129,28 +135,73 @@ abort_command:
       printf("\n");
     }
 
-    
-    if (tpm_handle_command(in, in_size, &out, &out_size) != 0) { 
-        printf("ERROR: Handler Failed.\n");
+    if (guest_id == -1) {
+        guest_id = *((uint32_t *) in);
+        *((uint32_t *) ctrl_msg) = *((uint32_t *) in);
+    } else {
+        if (guest_id != *((uint32_t *) in) ) {
+            printf("WARNING: More than one guest attached\n");
+        }
     }
 
-    written = write(tpm_tx_fh, out, out_size);
+    if (vtpm_tx_fh < 0) {
+#ifdef VTPM_MUTLI_VM
+	  vtpm_tx_fh = open(DEV_BE, O_RDWR);
+	  vtpm_rx_fh = vtpm_tx_fh;
+#else
+      vtpm_tx_fh = open(GUEST_TX_FIFO, O_WRONLY);
+#endif
+    }
 
-    if (written != out_size ) {
-      printf("ERROR: Part of response not written %d/%d.\nAttempt: ", written, out_size);
-    } else {
-      printf("Sent[%Zu]: ", out_size);
+    if (vtpm_tx_fh < 0) {
+      printf("ERROR: failed to open devices to respond to guest.\n");
+      return -1;
+    }
+    
+    // Handle command, but we need to skip the identifier
+    if (  BE16_TO_CPU( ((uint16_t *) in)[2] ) == VTPM_TAG_REQ ) { // Control message from xend
+      // This DM doesn't really care about ctrl messages. Just ACK the message
+      written = write(vtpm_tx_fh, ctrl_msg, sizeof(ctrl_msg));
+
+      if (written != sizeof(ctrl_msg)) {
+        printf("ERROR: Part of response not written %d/%Zu.\n", written, sizeof(ctrl_msg));
+      } else {
+        printf("Send Ctrl Message confermation\n");
+      }
+    } else { // Message from Guest
+      if (tpm_handle_command(in + sizeof(uint32_t), in_size - sizeof(uint32_t), &out, &out_size) != 0) { 
+        printf("ERROR: Handler Failed.\n");
+      }
+
+      addressed_out = (uint8_t *) tpm_malloc(sizeof(uint32_t) + out_size);
+      *(uint32_t *) addressed_out = *(uint32_t *) in;
+      memcpy(addressed_out + sizeof(uint32_t), out, out_size);
+
+      written = write(vtpm_tx_fh, addressed_out, out_size + sizeof(uint32_t));
+
+      if (written != out_size + sizeof(uint32_t)) {
+        printf("ERROR: Part of response not written %d/%d.\n", written, out_size);
+        for (i=0; i< out_size+ sizeof(uint32_t); i++)
+          printf("%x ", addressed_out[i]);
+        printf("\n");
+      } else {
+        printf("Sent[%Zu]: ", out_size + sizeof(uint32_t));
+        for (i=0; i< out_size+ sizeof(uint32_t); i++)
+          printf("%x ", addressed_out[i]);
+        printf("\n");
+      }
+      tpm_free(out);
+      tpm_free(addressed_out);
     }
-    for (i=0; i< out_size; i++)
-      printf("%x ", out[i]);
-    printf("\n");
-    tpm_free(out);
 
   } // loop
 
   tpm_emulator_shutdown();
 
-  close(tpm_tx_fh);
-  close(tpm_rx_fh);
+  close(vtpm_tx_fh);
+#ifndef VTPM_MUTLI_VM
+  close(vtpm_rx_fh);
+  free (guest_rx_file);
+#endif
 
 }
Binary files tpm_emulator/tpm_emulator and vtpm/tpm_emulator differ
diff -uprN tpm_emulator/tpm_version.h vtpm/tpm_version.h
--- tpm_emulator/tpm_version.h	2006-07-24 14:35:41.000000000 -0700
+++ vtpm/tpm_version.h	2006-07-24 14:35:35.000000000 -0700
@@ -2,5 +2,5 @@
 #define _TPM_VERSION_H_
 #define VERSION_MAJOR 0
 #define VERSION_MINOR 4
-#define VERSION_BUILD 1153776940
+#define VERSION_BUILD 1153776935
 #endif /* _TPM_VERSION_H_ */
Binary files tpm_emulator/vtpmd and vtpm/vtpmd differ