Line | Count | Source (jump to first uncovered line) |
1 | | // 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 "Tpm.h" |
9 | | #include "InternalRoutines.h" |
10 | | // |
11 | | // |
12 | | // Functions |
13 | | // |
14 | | // HandleGetType() |
15 | | // |
16 | | // This function returns the type of a handle which is the MSO of the handle. |
17 | | // |
18 | | TPM_HT |
19 | | HandleGetType( |
20 | | TPM_HANDLE handle // IN: a handle to be checked |
21 | | ) |
22 | 405 | { |
23 | | // return the upper bytes of input data |
24 | 405 | return (TPM_HT) ((handle & HR_RANGE_MASK) >> HR_SHIFT); |
25 | 405 | } |
26 | | // |
27 | | // |
28 | | // NextPermanentHandle() |
29 | | // |
30 | | // This function returns the permanent handle that is equal to the input value or is the next higher value. If |
31 | | // there is no handle with the input value and there is no next higher value, it returns 0: |
32 | | // |
33 | | // Return Value Meaning |
34 | | // |
35 | | TPM_HANDLE |
36 | | NextPermanentHandle( |
37 | | TPM_HANDLE inHandle // IN: the handle to check |
38 | | ) |
39 | 0 | { |
40 | | // If inHandle is below the start of the range of permanent handles |
41 | | // set it to the start and scan from there |
42 | 0 | if(inHandle < TPM_RH_FIRST) |
43 | 0 | inHandle = TPM_RH_FIRST; |
44 | | // scan from input value untill we find an implemented permanent handle |
45 | | // or go out of range |
46 | 0 | for(; inHandle <= TPM_RH_LAST; inHandle++) |
47 | 0 | { |
48 | 0 | switch (inHandle) |
49 | 0 | { |
50 | 0 | case TPM_RH_OWNER: |
51 | 0 | case TPM_RH_NULL: |
52 | 0 | case TPM_RS_PW: |
53 | 0 | case TPM_RH_LOCKOUT: |
54 | 0 | case TPM_RH_ENDORSEMENT: |
55 | 0 | case TPM_RH_PLATFORM: |
56 | 0 | case TPM_RH_PLATFORM_NV: |
57 | | #ifdef VENDOR_PERMANENT |
58 | | case VENDOR_PERMANENT: |
59 | | #endif |
60 | 0 | return inHandle; |
61 | 0 | break; |
62 | 0 | default: |
63 | 0 | break; |
64 | 0 | } |
65 | 0 | } |
66 | | // Out of range on the top |
67 | 0 | return 0; |
68 | 0 | } |
69 | | // |
70 | | // |
71 | | // PermanentCapGetHandles() |
72 | | // |
73 | | // This function returns a list of the permanent handles of PCR, started from handle. If handle is larger than |
74 | | // the largest permanent handle, an empty list will be returned with more set to NO. |
75 | | // |
76 | | // Return Value Meaning |
77 | | // |
78 | | // YES if there are more handles available |
79 | | // NO all the available handles has been returned |
80 | | // |
81 | | TPMI_YES_NO |
82 | | PermanentCapGetHandles( |
83 | | TPM_HANDLE handle, // IN: start handle |
84 | | UINT32 count, // IN: count of returned handle |
85 | | TPML_HANDLE *handleList // OUT: list of handle |
86 | | ) |
87 | 0 | { |
88 | 0 | TPMI_YES_NO more = NO; |
89 | 0 | UINT32 i; |
90 | 0 | pAssert(HandleGetType(handle) == TPM_HT_PERMANENT); |
91 | | // Initialize output handle list |
92 | 0 | handleList->count = 0; |
93 | | // The maximum count of handles we may return is MAX_CAP_HANDLES |
94 | 0 | if(count > MAX_CAP_HANDLES) count = MAX_CAP_HANDLES; |
95 | | // Iterate permanent handle range |
96 | 0 | for(i = NextPermanentHandle(handle); |
97 | 0 | i != 0; i = NextPermanentHandle(i+1)) |
98 | 0 | { |
99 | 0 | if(handleList->count < count) |
100 | 0 | { |
101 | | // If we have not filled up the return list, add this permanent |
102 | | // handle to it |
103 | 0 | handleList->handle[handleList->count] = i; |
104 | 0 | handleList->count++; |
105 | 0 | } |
106 | 0 | else |
107 | 0 | { |
108 | | // If the return list is full but we still have permanent handle |
109 | | // available, report this and stop iterating |
110 | 0 | more = YES; |
111 | 0 | break; |
112 | 0 | } |
113 | 0 | } |
114 | 0 | return more; |
115 | 0 | } |