1 #define SIGNALMAGIC (0x326d7054) //Tpm2
2 #define MAX_TPM_MESSAGE_SIZE (sizeof(unsigned int) + 2048)
3 
4 typedef enum
5 {
6     SignalNothing = 0,
7     SignalShutdown,
8     SignalReset,
9     SignalSetClock,
10         // IN {UINT32 time}
11     SignalCancelOn,
12     SignalCancelOff,
13     SignalCommand,
14         // IN {BYTE Locality, UINT32 InBufferSize, BYTE[InBufferSize] InBuffer}
15         // OUT {UINT32 OutBufferSize, BYTE[OutBufferSize] OutBuffer}
16     SignalResponse,
17         // OUT {UINT32 OutBufferSize, BYTE[OutBufferSize] OutBuffer}
18 } signalCode_t;
19 
20 typedef struct
21 {
22     unsigned int magic;
23     signalCode_t signal;
24     unsigned int dataSize;
25 } signalHdr_t;
26 
27 typedef union
28 {
29     struct
30     {
31         unsigned int time;
32     } SignalSetClockPayload;
33     struct
34     {
35         unsigned int locality;
36         unsigned int cmdSize;
37         unsigned char cmd[1];
38     } SignalCommandPayload;
39 } signalPayload_t, *pSignalPayload_t;
40 
41 typedef union
42 {
43     signalHdr_t s;
44     unsigned char b[sizeof(signalHdr_t)];
45 } signalWrapper_t, *pSignalWrapper_t;
46 
47 typedef struct tpmOperationsFlags_t
48 {
49     unsigned char resetRequested : 1;
50     unsigned char powerOffRequested : 1;
51     unsigned char executionRequested : 1;
52     unsigned char responseRequested : 1;
53 } tpmOperationsFlags_t;
54 
55 typedef struct tpmOperation_t
56 {
57     tpmOperationsFlags_t flags;
58     int cmdSize;
59     int receivingCmd;
60     int rspSize;
61     unsigned char msgBuf[MAX_TPM_MESSAGE_SIZE];
62 } tpmOperation_t;
63 
64 extern volatile tpmOperation_t tpmOp;
65 
66 int BlueButtonTransitionDetected(void);
67 void SetDutyCycleIndicator(bool on);
68 void KillUSBLink(void);
69 void SetRealTimeClock(time_t tm);
70 void ReadMcuInfo(unsigned char* serial, uint16_t *flashSize, uint16_t *mcuType, uint16_t *mcuRev);
71 void PerformSystemReset(void);
72 void HAL_Delay(uint32_t Delay);
73 uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len);
74 
75 bool TpmInitializeDevice(void);
76 bool TpmOperationsLoop(void);
77 void TpmConnectionReset(void);
78 bool TpmSignalEvent(uint8_t* Buf, uint32_t *Len);
79