Setting Up a Binary Version of the Simulator
Download the simulator from research.microsoft.com/en-US/ downloads/35116857-e544-4003-8e7b-584182dc6833/default.aspx. Unzip the file into the directory of your choice.
Running the Simulator
Search for the simulator binary, simulator.exe, in the install directory, and start it. In some settings, you may need to configure the port numbers that the simulator listens to for commands. You can do this on the simulator command line.
The simulator uses two ports:
• TPM command port: Used for sending TPM commands and receiving TPM responses. The default port is 2321; if you need to change this, you can set it on the command line as follows:
> simulator <portNum>
• Platform command port: Used for platform commands such as power on/off. The platform command port is always one greater than the TPM command port. For example, the default platform port number is 2322; and if you use the command-line option to set the TPM command port, the platform port is 1 greater than the command-line value.
There are two reasons to use a port other than the default port:
• If the network you're running on is using the default port for some other use
• If you want to run two instances of the simulator on the same machine, in which case you need to run one on a different port
Testing the Simulator
Let's look at three ways to test that the simulator is working: a simple Python script, TSS. net, and the system API test code.
To test that the simulator is running correctly, you can use this Python script:
#!/usr/bin/python import os
from socket import socket, AF_INET, SOCK_STREAM
platformSock = socket(AF_INET, SOCK_STREAM) platformSock.connect(('localhost', 2322))
# Power on the TPM platformSock.send(' 1')
tpmSock = socket(AF_INET, SOCK_STREAM) tpmSock.connect(('localhost', 2321))
# Send TPM_SEND_COMMAND
# Send locality tpmSock.send('x03')
# Send # of bytes tpmSock.send('x00x00x00x0c')
# Send tag tpmSock.send('x80x01')
# Send command size tpmSock.send('x00x00x00x0c')
# Send command code: TPMStartup tpmSock.send('x00x00x01x44')
# Send TPM SU tpmSock.send('x00x00')
# Receive the size of the response, the response, and 4 bytes of 0's reply=tpmSock.recv(18)
for c in reply:
print "%#x " % ord(c)
The script sends the TPM startup command to the TPM. If the startup command works correctly, you should see the following output from the for loop print statement:
>>>for c in reply:
... print "%#x " % ord(c)
0x0 0x0 0x0 0xa 0x80
0x1 0x0 0x0 0x0 0xa 0x0 0x0 0x1 0x0 0x0 0x0 0x0 0x0
If you're getting this result, the simulator is running correctly.
TSS.net is a C# library of code for communicating with the TPM. Download it from
https://tpm2lib.codeplex.com, install it, and run a code example as described shortly.
System API Test Code
Follow the directions in the section “TSS 2.0” for the System API library and test code. If any TPM 2.0 command is successfully sent to the TPM, the simulator is working.