TianoCore EDK2 master
Loading...
Searching...
No Matches
TcgStorageCore.h
Go to the documentation of this file.
1
14#ifndef _TCG_STORAGE_CORE_H_
15#define _TCG_STORAGE_CORE_H_
16
17#include <Base.h>
18
19#pragma pack(1)
20
22typedef UINT64 TCG_UID;
23
24#define TCG_TO_UID(b0, b1, b2, b3, b4, b5, b6, b7) (TCG_UID)(\
25 (UINT64)(b0) | \
26 ((UINT64)(b1) << 8) | \
27 ((UINT64)(b2) << 16) | \
28 ((UINT64)(b3) << 24) | \
29 ((UINT64)(b4) << 32) | \
30 ((UINT64)(b5) << 40) | \
31 ((UINT64)(b6) << 48) | \
32 ((UINT64)(b7) << 56))
33
34typedef struct {
35 UINT32 ReservedBE;
36 UINT16 ComIDBE;
37 UINT16 ComIDExtensionBE;
38 UINT32 OutstandingDataBE;
39 UINT32 MinTransferBE;
40 UINT32 LengthBE;
41 UINT8 Payload[0];
43
44typedef struct {
45 UINT32 TperSessionNumberBE;
46 UINT32 HostSessionNumberBE;
47 UINT32 SequenceNumberBE;
48 UINT16 ReservedBE;
49 UINT16 AckTypeBE;
50 UINT32 AcknowledgementBE;
51 UINT32 LengthBE;
52 UINT8 Payload[0];
54
55#define TCG_SUBPACKET_ALIGNMENT 4// 4-byte alignment per spec
56
57typedef struct {
58 UINT8 ReservedBE[6];
59 UINT16 KindBE;
60 UINT32 LengthBE;
61 UINT8 Payload[0];
63
64#define SUBPACKET_KIND_DATA 0x0000
65#define SUBPACKET_KIND_CREDIT_CONTROL 0x8001
66
67#define TCG_ATOM_TYPE_INTEGER 0x0
68#define TCG_ATOM_TYPE_BYTE 0x1
69typedef struct {
70 UINT8 Data : 6;
71 UINT8 Sign : 1;
72 UINT8 IsZero : 1;
74
75typedef union {
76 UINT8 Raw;
77 TCG_TINY_ATOM_BITS TinyAtomBits;
79
80typedef struct {
81 UINT8 Length : 4;
82 UINT8 SignOrCont : 1;
83 UINT8 ByteOrInt : 1;
84 UINT8 IsZero : 1;
85 UINT8 IsOne : 1;
87
88typedef union {
89 UINT8 RawHeader;
90 TCG_SHORT_ATOM_BITS ShortAtomBits;
92
93#define TCG_MEDIUM_ATOM_LENGTH_HIGH_SHIFT 0x8
94#define TCG_MEDIUM_ATOM_LENGTH_HIGH_MASK 0x7
95
96typedef struct {
97 UINT8 LengthHigh : 3;
98 UINT8 SignOrCont : 1;
99 UINT8 ByteOrInt : 1;
100 UINT8 IsZero : 1;
101 UINT8 IsOne1 : 1;
102 UINT8 IsOne2 : 1;
103 UINT8 LengthLow;
105
106typedef union {
107 UINT16 RawHeader;
108 TCG_MEDIUM_ATOM_BITS MediumAtomBits;
110
111#define TCG_LONG_ATOM_LENGTH_HIGH_SHIFT 16
112#define TCG_LONG_ATOM_LENGTH_MID_SHIFT 8
113
114typedef struct {
115 UINT8 SignOrCont : 1;
116 UINT8 ByteOrInt : 1;
117 UINT8 Reserved : 2;
118 UINT8 IsZero : 1;
119 UINT8 IsOne1 : 1;
120 UINT8 IsOne2 : 1;
121 UINT8 IsOne3 : 1;
122 UINT8 LengthHigh;
123 UINT8 LengthMid;
124 UINT8 LengthLow;
126
127typedef union {
128 UINT32 RawHeader;
129 TCG_LONG_ATOM_BITS LongAtomBits;
131
132// TCG Core Spec v2 - Table 04 - Token Types
133typedef enum {
134 TcgTokenTypeReserved,
135 TcgTokenTypeTinyAtom,
136 TcgTokenTypeShortAtom,
137 TcgTokenTypeMediumAtom,
138 TcgTokenTypeLongAtom,
139 TcgTokenTypeStartList,
140 TcgTokenTypeEndList,
141 TcgTokenTypeStartName,
142 TcgTokenTypeEndName,
143 TcgTokenTypeCall,
144 TcgTokenTypeEndOfData,
145 TcgTokenTypeEndOfSession,
146 TcgTokenTypeStartTransaction,
147 TcgTokenTypeEndTransaction,
148 TcgTokenTypeEmptyAtom,
149} TCG_TOKEN_TYPE;
150
151#pragma pack()
152
153#define TCG_TOKEN_SHORTATOM_MAX_BYTE_SIZE 0x0F
154#define TCG_TOKEN_MEDIUMATOM_MAX_BYTE_SIZE 0x7FF
155#define TCG_TOKEN_LONGATOM_MAX_BYTE_SIZE 0xFFFFFF
156
157#define TCG_TOKEN_TINYATOM_UNSIGNED_MAX_VALUE 0x3F
158#define TCG_TOKEN_TINYATOM_SIGNED_MAX_VALUE 0x1F
159#define TCG_TOKEN_TINYATOM_SIGNED_MIN_VALUE -32
160
161// TOKEN TYPES
162#define TCG_TOKEN_TINYATOM 0x00
163#define TCG_TOKEN_TINYSIGNEDATOM 0x40
164#define TCG_TOKEN_SHORTATOM 0x80
165#define TCG_TOKEN_SHORTSIGNEDATOM 0x90
166#define TCG_TOKEN_SHORTBYTESATOM 0xA0
167#define TCG_TOKEN_MEDIUMATOM 0xC0
168#define TCG_TOKEN_MEDIUMSIGNEDATOM 0xC8
169#define TCG_TOKEN_MEDIUMBYTESATOM 0xD0
170#define TCG_TOKEN_LONGATOM 0xE0
171#define TCG_TOKEN_LONGSIGNEDATOM 0xE1
172#define TCG_TOKEN_LONGBYTESATOM 0xE2
173#define TCG_TOKEN_STARTLIST 0xF0
174#define TCG_TOKEN_ENDLIST 0xF1
175#define TCG_TOKEN_STARTNAME 0xF2
176#define TCG_TOKEN_ENDNAME 0xF3
177// 0xF4 - 0xF7 TCG Reserved
178#define TCG_TOKEN_CALL 0xF8
179#define TCG_TOKEN_ENDDATA 0xF9
180#define TCG_TOKEN_ENDSESSION 0xFA
181#define TCG_TOKEN_STARTTRANSACTION 0xFB
182#define TCG_TOKEN_ENDTRANSACTION 0xFC
183// 0xFD - 0xFE TCG Reserved
184#define TCG_TOKEN_EMPTY 0xFF
185
186// CELLBLOCK reserved Names
187#define TCG_CELL_BLOCK_TABLE_NAME (UINT8)0x00
188#define TCG_CELL_BLOCK_START_ROW_NAME (UINT8)0x01
189#define TCG_CELL_BLOCK_END_ROW_NAME (UINT8)0x02
190#define TCG_CELL_BLOCK_START_COLUMN_NAME (UINT8)0x03
191#define TCG_CELL_BLOCK_END_COLUMN_NAME (UINT8)0x04
192
193// METHOD STATUS CODES
194#define TCG_METHOD_STATUS_CODE_SUCCESS 0x00
195#define TCG_METHOD_STATUS_CODE_NOT_AUTHORIZED 0x01
196#define TCG_METHOD_STATUS_CODE_OBSOLETE 0x02
197#define TCG_METHOD_STATUS_CODE_SP_BUSY 0x03
198#define TCG_METHOD_STATUS_CODE_SP_FAILED 0x04
199#define TCG_METHOD_STATUS_CODE_SP_DISABLED 0x05
200#define TCG_METHOD_STATUS_CODE_SP_FROZEN 0x06
201#define TCG_METHOD_STATUS_CODE_NO_SESSIONS_AVAILABLE 0x07
202#define TCG_METHOD_STATUS_CODE_UNIQUENESS_CONFLICT 0x08
203#define TCG_METHOD_STATUS_CODE_INSUFFICIENT_SPACE 0x09
204#define TCG_METHOD_STATUS_CODE_INSUFFICIENT_ROWS 0x0A
205#define TCG_METHOD_STATUS_CODE_INVALID_PARAMETER 0x0C
206#define TCG_METHOD_STATUS_CODE_OBSOLETE2 0x0D
207#define TCG_METHOD_STATUS_CODE_OBSOLETE3 0x0E
208#define TCG_METHOD_STATUS_CODE_TPER_MALFUNCTION 0x0F
209#define TCG_METHOD_STATUS_CODE_TRANSACTION_FAILURE 0x10
210#define TCG_METHOD_STATUS_CODE_RESPONSE_OVERFLOW 0x11
211#define TCG_METHOD_STATUS_CODE_AUTHORITY_LOCKED_OUT 0x12
212#define TCG_METHOD_STATUS_CODE_FAIL 0x3F
213
214// Feature Codes
215#define TCG_FEATURE_INVALID (UINT16)0x0000
216#define TCG_FEATURE_TPER (UINT16)0x0001
217#define TCG_FEATURE_LOCKING (UINT16)0x0002
218#define TCG_FEATURE_GEOMETRY_REPORTING (UINT16)0x0003
219#define TCG_FEATURE_SINGLE_USER_MODE (UINT16)0x0201
220#define TCG_FEATURE_DATASTORE_TABLE (UINT16)0x0202
221#define TCG_FEATURE_OPAL_SSC_V1_0_0 (UINT16)0x0200
222#define TCG_FEATURE_OPAL_SSC_V2_0_0 (UINT16)0x0203
223#define TCG_FEATURE_OPAL_SSC_LITE (UINT16)0x0301
224#define TCG_FEATURE_PYRITE_SSC (UINT16)0x0302
225#define TCG_FEATURE_PYRITE_SSC_V2_0_0 (UINT16)0x0303
226#define TCG_FEATURE_BLOCK_SID (UINT16)0x0402
227#define TCG_FEATURE_DATA_REMOVAL (UINT16)0x0404
228
229// ACE Expression values
230#define TCG_ACE_EXPRESSION_AND 0x0
231#define TCG_ACE_EXPRESSION_OR 0x1
232
233/****************************************************************************
234TRUSTED RECEIVE - supported security protocols list (SP_Specific = 0000h)
235ATA 8 Rev6a Table 68 7.57.6.2
236****************************************************************************/
237// Security Protocol IDs
238#define TCG_SECURITY_PROTOCOL_INFO 0x00
239#define TCG_OPAL_SECURITY_PROTOCOL_1 0x01
240#define TCG_OPAL_SECURITY_PROTOCOL_2 0x02
241#define TCG_SECURITY_PROTOCOL_TCG3 0x03
242#define TCG_SECURITY_PROTOCOL_TCG4 0x04
243#define TCG_SECURITY_PROTOCOL_TCG5 0x05
244#define TCG_SECURITY_PROTOCOL_TCG6 0x06
245#define TCG_SECURITY_PROTOCOL_CBCS 0x07
246#define TCG_SECURITY_PROTOCOL_TAPE_DATA 0x20
247#define TCG_SECURITY_PROTOCOL_DATA_ENCRYPT_CONFIG 0x21
248#define TCG_SECURITY_PROTOCOL_SA_CREATION_CAPS 0x40
249#define TCG_SECURITY_PROTOCOL_IKEV2_SCSI 0x41
250#define TCG_SECURITY_PROTOCOL_JEDEC_UFS 0xEC
251#define TCG_SECURITY_PROTOCOL_SDCARD_SECURITY 0xED
252#define TCG_SECURITY_PROTOCOL_IEEE_1667 0xEE
253#define TCG_SECURITY_PROTOCOL_ATA_DEVICE_SERVER_PASS 0xEF
254
255// Security Protocol Specific IDs
256#define TCG_SP_SPECIFIC_PROTOCOL_LIST 0x0000
257#define TCG_SP_SPECIFIC_PROTOCOL_LEVEL0_DISCOVERY 0x0001
258
259#define TCG_RESERVED_COMID 0x0000
260
261// Defined in TCG Storage Feature Set:Block SID Authentication spec,
262// ComId used for BlockSid command is hardcode 0x0005.
263#define TCG_BLOCKSID_COMID 0x0005
264
265#pragma pack(1)
266typedef struct {
267 UINT8 Reserved[6];
268 UINT16 ListLength_BE; // 6 - 7
269 UINT8 List[504]; // 8...
271
272// Level 0 Discovery
273typedef struct {
274 UINT32 LengthBE; // number of valid bytes in discovery response, not including length field
275 UINT16 VerMajorBE;
276 UINT16 VerMinorBE;
277 UINT8 Reserved[8];
278 UINT8 VendorUnique[32];
280
282 UINT16 FeatureCode_BE;
283 UINT8 Reserved : 4;
284 UINT8 Version : 4;
285 UINT8 Length; // length of feature dependent data in bytes
287
288typedef struct {
290 UINT8 LockingSupported : 1;
291 UINT8 LockingEnabled : 1; // means the locking security provider (SP) is enabled
292 UINT8 Locked : 1; // means at least 1 locking range is enabled
293 UINT8 MediaEncryption : 1;
294 UINT8 MbrEnabled : 1;
295 UINT8 MbrDone : 1;
296 UINT8 Reserved : 2;
297 UINT8 Reserved515[11];
299
300typedef struct {
302 UINT8 SIDValueState : 1;
303 UINT8 SIDBlockedState : 1;
304 UINT8 Reserved4 : 6;
305 UINT8 HardwareReset : 1;
306 UINT8 Reserved5 : 7;
307 UINT8 Reserved615[10];
309
310typedef struct {
312 UINT8 SyncSupported : 1;
313 UINT8 AsyncSupported : 1;
314 UINT8 AckNakSupported : 1;
315 UINT8 BufferMgmtSupported : 1;
316 UINT8 StreamingSupported : 1;
317 UINT8 Reserved4b5 : 1;
318 UINT8 ComIdMgmtSupported : 1;
319 UINT8 Reserved4b7 : 1;
320 UINT8 Reserved515[11];
322
323#pragma pack()
324
325// Special Purpose UIDs
326#define TCG_UID_NULL TCG_TO_UID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
327#define TCG_UID_THIS_SP TCG_TO_UID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01)
328#define TCG_UID_SMUID TCG_TO_UID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF)
329
330// Session Manager Method UIDS
331#define TCG_UID_SM_PROPERTIES TCG_TO_UID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x01)
332#define TCG_UID_SM_START_SESSION TCG_TO_UID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x02)
333#define TCG_UID_SM_SYNC_SESSION TCG_TO_UID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x03)
334#define TCG_UID_SM_START_TRUSTED_SESSION TCG_TO_UID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x04)
335#define TCG_UID_SM_SYNC_TRUSTED_SESSION TCG_TO_UID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x05)
336#define TCG_UID_SM_CLOSE_SESSION TCG_TO_UID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x06)
337
338// MethodID UIDs
339#define TCG_UID_METHOD_DELETE_SP TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01)
340#define TCG_UID_METHOD_CREATE_TABLE TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x02)
341#define TCG_UID_METHOD_DELETE TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x03)
342#define TCG_UID_METHOD_CREATE_ROW TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04)
343#define TCG_UID_METHOD_DELETE_ROW TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x05)
344#define TCG_UID_METHOD_NEXT TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x08)
345#define TCG_UID_METHOD_GET_FREE_SPACE TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x09)
346#define TCG_UID_METHOD_GET_FREE_ROWS TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0A)
347#define TCG_UID_METHOD_DELETE_METHOD TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0B)
348#define TCG_UID_METHOD_GET_ACL TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0D)
349#define TCG_UID_METHOD_ADD_ACE TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0E)
350#define TCG_UID_METHOD_REMOVE_ACE TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0F)
351#define TCG_UID_METHOD_GEN_KEY TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x10)
352#define TCG_UID_METHOD_GET_PACKAGE TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x12)
353#define TCG_UID_METHOD_SET_PACKAGE TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x13)
354#define TCG_UID_METHOD_GET TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x16)
355#define TCG_UID_METHOD_SET TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x17)
356#define TCG_UID_METHOD_AUTHENTICATE TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x1C)
357#define TCG_UID_METHOD_ISSUE_SP TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x02, 0x01)
358#define TCG_UID_METHOD_GET_CLOCK TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x04, 0x01)
359#define TCG_UID_METHOD_RESET_CLOCK TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x04, 0x02)
360#define TCG_UID_METHOD_SET_CLOCK_HIGH TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x04, 0x03)
361#define TCG_UID_METHOD_SET_LAG_HIGH TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x04, 0x04)
362#define TCG_UID_METHOD_SET_CLOCK_LOW TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x04, 0x05)
363#define TCG_UID_METHOD_SET_LAG_LOW TCG_TO_UID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x06)
364#define TCG_UID_METHOD_INCREMENT_COUNTER TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x04, 0x07)
365#define TCG_UID_METHOD_RANDOM TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x01)
366#define TCG_UID_METHOD_SALT TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x02)
367#define TCG_UID_METHOD_DECRYPT_INIT TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x03)
368#define TCG_UID_METHOD_DECRYPT TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x04)
369#define TCG_UID_METHOD_DECRYPT_FINALIZE TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x05)
370#define TCG_UID_METHOD_ENCRYPT_INIT TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x06)
371#define TCG_UID_METHOD_ENCRYPT TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x07)
372#define TCG_UID_METHOD_ENCRYPT_FINALIZE TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x08)
373#define TCG_UID_METHOD_HMAC_INIT TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x09)
374#define TCG_UID_METHOD_HMAC TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x0A)
375#define TCG_UID_METHOD_HMAC_FINALIZE TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x0B)
376#define TCG_UID_METHOD_HASH_INIT TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x0C)
377#define TCG_UID_METHOD_HASH TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x0D)
378#define TCG_UID_METHOD_HASH_FINALIZE TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x0E)
379#define TCG_UID_METHOD_SIGN TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x0F)
380#define TCG_UID_METHOD_VERIFY TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x10)
381#define TCG_UID_METHOD_XOR TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x11)
382#define TCG_UID_METHOD_ADD_LOG TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x0A, 0x01)
383#define TCG_UID_METHOD_CREATE_LOG TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x0A, 0x02)
384#define TCG_UID_METHOD_CLEAR_LOG TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x0A, 0x03)
385#define TCG_UID_METHOD_FLUSH_LOG TCG_TO_UID(0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x0A, 0x04)
386
387#endif // TCG_H_
UINT64 TCG_UID
UID in host native byte order.