blob: f7c21195ccdc0961024ce91cb91e80e24a8ea43f [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 "InternalRoutines.h"
9//
10//
11// Functions
12//
13// PhysicalPresencePreInstall_Init()
14//
15// This function is used to initialize the array of commands that require confirmation with physical presence.
16// The array is an array of bits that has a correspondence with the command code.
17// This command should only ever be executable in a manufacturing setting or in a simulation.
18//
19void
20PhysicalPresencePreInstall_Init(
21 void
22 )
23{
24 // Clear all the PP commands
25 MemorySet(&gp.ppList, 0,
26//
27 ((TPM_CC_PP_LAST - TPM_CC_PP_FIRST + 1) + 7) / 8);
28 // TPM_CC_PP_Commands always requires PP
29 if(CommandIsImplemented(TPM_CC_PP_Commands))
30 PhysicalPresenceCommandSet(TPM_CC_PP_Commands);
31 // Write PP list to NV
32 NvWriteReserved(NV_PP_LIST, &gp.ppList);
33 return;
34}
35//
36//
37// PhysicalPresenceCommandSet()
38//
39// This function is used to indicate a command that requires PP confirmation.
40//
41void
42PhysicalPresenceCommandSet(
43 TPM_CC commandCode // IN: command code
44 )
45{
46 UINT32 bitPos;
47 // Assume command is implemented. It should be checked before this
48 // function is called
49 pAssert(CommandIsImplemented(commandCode));
50 // If the command is not a PP command, ignore it
51 if(commandCode < TPM_CC_PP_FIRST || commandCode > TPM_CC_PP_LAST)
52 return;
53 bitPos = commandCode - TPM_CC_PP_FIRST;
54 // Set bit
55 gp.ppList[bitPos/8] |= 1 << (bitPos % 8);
56 return;
57}
58//
59//
60// PhysicalPresenceCommandClear()
61//
62// This function is used to indicate a command that no longer requires PP confirmation.
63//
64void
65PhysicalPresenceCommandClear(
66 TPM_CC commandCode // IN: command code
67 )
68{
69 UINT32 bitPos;
70 // Assume command is implemented. It should be checked before this
71 // function is called
72 pAssert(CommandIsImplemented(commandCode));
73 // If the command is not a PP command, ignore it
74 if(commandCode < TPM_CC_PP_FIRST || commandCode > TPM_CC_PP_LAST)
75 return;
76 // if the input code is TPM_CC_PP_Commands, it can not be cleared
77 if(commandCode == TPM_CC_PP_Commands)
78 return;
79 bitPos = commandCode - TPM_CC_PP_FIRST;
80 // Set bit
81 gp.ppList[bitPos/8] |= (1 << (bitPos % 8));
82 // Flip it to off
83 gp.ppList[bitPos/8] ^= (1 << (bitPos % 8));
84 return;
85}
86//
87//
88// PhysicalPresenceIsRequired()
89//
90// This function indicates if PP confirmation is required for a command.
91//
92// Return Value Meaning
93//
94// TRUE if physical presence is required
95// FALSE if physical presence is not required
96//
97BOOL
98PhysicalPresenceIsRequired(
99 TPM_CC commandCode // IN: command code
100 )
101{
102 UINT32 bitPos;
103 // if the input commandCode is not a PP command, return FALSE
104 if(commandCode < TPM_CC_PP_FIRST || commandCode > TPM_CC_PP_LAST)
105 return FALSE;
106 bitPos = commandCode - TPM_CC_PP_FIRST;
107 // Check the bit map. If the bit is SET, PP authorization is required
108 return ((gp.ppList[bitPos/8] & (1 << (bitPos % 8))) != 0);
109}
110//
111//
112// PhysicalPresenceCapGetCCList()
113//
114// This function returns a list of commands that require PP confirmation. The list starts from the first
115// implemented command that has a command code that the same or greater than commandCode.
116//
117// Return Value Meaning
118//
119// YES if there are more command codes available
120// NO all the available command codes have been returned
121//
122TPMI_YES_NO
123PhysicalPresenceCapGetCCList(
124 TPM_CC commandCode, // IN: start command code
125 UINT32 count, // IN: count of returned TPM_CC
126 TPML_CC *commandList // OUT: list of TPM_CC
127 )
128{
129 TPMI_YES_NO more = NO;
130 UINT32 i;
131 // Initialize output handle list
132 commandList->count = 0;
133 // The maximum count of command we may return is MAX_CAP_CC
134 if(count > MAX_CAP_CC) count = MAX_CAP_CC;
135 // Collect PP commands
136 for(i = commandCode; i <= TPM_CC_PP_LAST; i++)
137 {
138 if(PhysicalPresenceIsRequired(i))
139 {
140 if(commandList->count < count)
141 {
142 // If we have not filled up the return list, add this command
143 // code to it
144 commandList->commandCodes[commandList->count] = i;
145 commandList->count++;
146 }
147 else
148 {
149 // If the return list is full but we still have PP command
150 // available, report this and stop iterating
151 more = YES;
152 break;
153 }
154 }
155 }
156 return more;
157}