blob: 66ba9ed2919b893f453b51821684095522cbcc4c [file] [log] [blame]
Vadim Bendebury56797522015-05-20 10:32:25 -07001// This file was extracted from the TCG Published
2// Trusted Platform Module Library
3// Part 4: Supporting Routines
4// Family "2.0"
5// Level 00 Revision 01.16
6// October 30, 2014
7
8#include <stdlib.h>
9#include <stdio.h>
10#include <stdint.h>
11#include <ctype.h>
12#include <windows.h>
13#include <strsafe.h>
14#include "string.h"
15#include "TpmTcpProtocol.h"
16#include "..\tpm\include\TpmBuildSwitches.h"
17#include "..\tpm\include\prototypes\Manufacture_fp.h"
18#define PURPOSE \
19"TPM Reference Simulator.\nCopyright Microsoft 2010, 2011.\n"
20#define DEFAULT_TPM_PORT 2321
21void* MainPointer;
22int _plat__NVEnable(void* platParameters);
23void _plat__NVDisable();
24int StartTcpServer(int PortNumber);
25//
26//
27// Functions
28//
29// Usage()
30//
31// This function prints the proper calling sequence for the simulator.
32//
33void
34Usage(
35 char *pszProgramName
36 )
37{
38 fprintf_s(stderr, "%s", PURPOSE);
39 fprintf_s(stderr, "Usage:\n");
40 fprintf_s(stderr, "%s - Starts the TPM server listening on port %d\n",
41 pszProgramName, DEFAULT_TPM_PORT);
42 fprintf_s(stderr,
43 "%s PortNum - Starts the TPM server listening on port PortNum\n",
44 pszProgramName);
45 fprintf_s(stderr, "%s ? - This message\n", pszProgramName);
46 exit(1);
47}
48//
49//
50// main()
51//
52// This is the main entry point for the simulator.
53// main: register the interface, start listening for clients
54//
55void __cdecl
56main(
57 int argc,
58 char *argv[]
59 )
60{
61 int portNum = DEFAULT_TPM_PORT;
62 if(argc>2)
63 {
64 Usage(argv[0]);
65 }
66 if(argc==2)
67 {
68 if(strcmp(argv[1], "?") ==0)
69 {
70 Usage(argv[0]);
71 }
72 portNum = atoi(argv[1]);
73 if(portNum <=0 || portNum>65535)
74 {
75 Usage(argv[0]);
76 }
77 }
78 _plat__NVEnable(NULL);
79 if(TPM_Manufacture(1) != 0)
80 {
81 exit(1);
82 }
83 // Coverage test - repeated manufacturing attempt
84 if(TPM_Manufacture(0) != 1)
85 {
86 exit(2);
87 }
88 // Coverage test - re-manufacturing
89 TPM_TearDown();
90 if(TPM_Manufacture(1) != 0)
91 {
92 exit(3);
93 }
94 // Disable NV memory
95 _plat__NVDisable();
96 StartTcpServer(portNum);
97 return;
98}