2 Provide functions to provide tcg storage core spec related functions.
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include <Library/TcgStorageCoreLib.h>
11 #include <Library/BaseLib.h>
12 #include <Library/BaseMemoryLib.h>
13 #include <Library/DebugLib.h>
17 TCG_LEVEL0_FEATURE_DESCRIPTOR_HEADER
*Feature
;
19 } TCG_FIND_FEATURE_CTX
;
22 Returns a human-readable string representing a method status return code.
24 @param[in] MethodStatus Method status to translate to a string
27 @retval return the string info.
31 TcgMethodStatusString (
35 switch (MethodStatus
) {
36 #define C(status) case TCG_METHOD_STATUS_CODE_ ## status: return #status
44 C (NO_SESSIONS_AVAILABLE
);
45 C (UNIQUENESS_CONFLICT
);
46 C (INSUFFICIENT_SPACE
);
47 C (INSUFFICIENT_ROWS
);
48 C (INVALID_PARAMETER
);
52 C (TRANSACTION_FAILURE
);
53 C (RESPONSE_OVERFLOW
);
54 C (AUTHORITY_LOCKED_OUT
);
63 adds call token and method Header (invoking id, and method id).
65 @param CreateStruct The input create structure.
66 @param InvokingId Invoking id.
67 @param MethodId Method id.
73 TCG_CREATE_STRUCT
*CreateStruct
,
78 NULL_CHECK (CreateStruct
);
80 if ((CreateStruct
->ComPacket
== NULL
) ||
81 (CreateStruct
->CurPacket
== NULL
) ||
82 (CreateStruct
->CurSubPacket
== NULL
)
85 DEBUG ((DEBUG_INFO
, "unexpected state: ComPacket=%p CurPacket=%p CurSubPacket=%p\n", CreateStruct
->ComPacket
, CreateStruct
->CurPacket
, CreateStruct
->CurSubPacket
));
86 return (TcgResultFailureInvalidAction
);
89 ERROR_CHECK (TcgAddCall (CreateStruct
));
90 ERROR_CHECK (TcgAddTcgUid (CreateStruct
, InvokingId
));
91 ERROR_CHECK (TcgAddTcgUid (CreateStruct
, MethodId
));
93 return TcgResultSuccess
;
97 Adds START LIST token.
99 @param CreateStruct The input create structure.
105 TCG_CREATE_STRUCT
*CreateStruct
108 NULL_CHECK (CreateStruct
);
110 if ((CreateStruct
->ComPacket
== NULL
) ||
111 (CreateStruct
->CurPacket
== NULL
) ||
112 (CreateStruct
->CurSubPacket
== NULL
)
115 DEBUG ((DEBUG_INFO
, "unexpected state: ComPacket=%p CurPacket=%p CurSubPacket=%p\n", CreateStruct
->ComPacket
, CreateStruct
->CurPacket
, CreateStruct
->CurSubPacket
));
116 return (TcgResultFailureInvalidAction
);
119 return TcgAddStartList (CreateStruct
);
125 @param CreateStruct The input create structure.
131 TCG_CREATE_STRUCT
*CreateStruct
134 NULL_CHECK (CreateStruct
);
136 if ((CreateStruct
->ComPacket
== NULL
) ||
137 (CreateStruct
->CurPacket
== NULL
) ||
138 (CreateStruct
->CurSubPacket
== NULL
)
141 DEBUG ((DEBUG_INFO
, "unexpected state: ComPacket=%p CurPacket=%p CurSubPacket=%p\n", CreateStruct
->ComPacket
, CreateStruct
->CurPacket
, CreateStruct
->CurSubPacket
));
142 return (TcgResultFailureInvalidAction
);
145 return TcgAddEndList (CreateStruct
);
149 Adds END Data token and method list.
151 @param CreateStruct The input create structure.
157 TCG_CREATE_STRUCT
*CreateStruct
160 NULL_CHECK (CreateStruct
);
162 if ((CreateStruct
->ComPacket
== NULL
) ||
163 (CreateStruct
->CurPacket
== NULL
) ||
164 (CreateStruct
->CurSubPacket
== NULL
)
167 DEBUG ((DEBUG_INFO
, "unexpected state: ComPacket=%p CurPacket=%p CurSubPacket=%p\n", CreateStruct
->ComPacket
, CreateStruct
->CurPacket
, CreateStruct
->CurSubPacket
));
168 return (TcgResultFailureInvalidAction
);
171 ERROR_CHECK (TcgAddEndOfData (CreateStruct
));
173 ERROR_CHECK (TcgAddStartList (CreateStruct
));
174 ERROR_CHECK (TcgAddUINT8 (CreateStruct
, 0x00)); // expected to complete properly
175 ERROR_CHECK (TcgAddUINT8 (CreateStruct
, 0x00)); // reserved
176 ERROR_CHECK (TcgAddUINT8 (CreateStruct
, 0x00)); // reserved
177 ERROR_CHECK (TcgAddEndList (CreateStruct
));
179 return TcgResultSuccess
;
183 Retrieves the comID and Extended comID of the ComPacket in the Tcg response.
184 It is intended to be used to confirm the received Tcg response is intended for user that received it.
186 @param [in] ParseStruct Structure used to parse received TCG response.
187 @param [in/out] ComId comID retrieved from received ComPacket.
188 @param [in/out] ComIdExtension Extended comID retrieved from received ComPacket
194 const TCG_PARSE_STRUCT
*ParseStruct
,
196 UINT16
*ComIdExtension
199 NULL_CHECK (ParseStruct
);
201 NULL_CHECK (ComIdExtension
);
203 if (ParseStruct
->ComPacket
== NULL
) {
204 DEBUG ((DEBUG_INFO
, "unexpected state: ComPacket=%p\n", ParseStruct
->ComPacket
));
205 return TcgResultFailureInvalidAction
;
208 *ComId
= SwapBytes16 (ParseStruct
->ComPacket
->ComIDBE
);
209 *ComIdExtension
= SwapBytes16 (ParseStruct
->ComPacket
->ComIDExtensionBE
);
211 return TcgResultSuccess
;
215 Checks if the ComIDs of the response match the expected values.
217 @param[in] ParseStruct Structure used to parse received TCG response
218 @param[in] ExpectedComId Expected comID
219 @param[in] ExpectedComIdExtension Expected extended comID
225 const TCG_PARSE_STRUCT
*ParseStruct
,
226 UINT16 ExpectedComId
,
227 UINT16 ExpectedComIdExtension
231 UINT16 ParseComIdExtension
;
233 ERROR_CHECK (TcgGetComIds (ParseStruct
, &ParseComId
, &ParseComIdExtension
));
234 if ((ParseComId
!= ExpectedComId
) || (ParseComIdExtension
!= ExpectedComIdExtension
)) {
235 DEBUG ((DEBUG_INFO
, "Com ID: Actual 0x%02X Expected 0x%02X\n", ParseComId
, ExpectedComId
));
236 DEBUG ((DEBUG_INFO
, "Extended Com ID: 0x%02X Expected 0x%02X\n", ParseComIdExtension
, ExpectedComIdExtension
));
237 return TcgResultFailure
;
240 return TcgResultSuccess
;
244 Returns the method status of the current subpacket. Does not affect the current position
245 in the ComPacket. In other words, it can be called whenever you have a valid SubPacket.
247 @param [in/out] ParseStruct Structure used to parse received TCG response
248 @param [in/out] MethodStatus Method status retrieved of the current SubPacket
254 const TCG_PARSE_STRUCT
*ParseStruct
,
258 TCG_PARSE_STRUCT TmpParseStruct
;
260 UINT8 Reserved1
, Reserved2
;
262 NULL_CHECK (ParseStruct
);
263 NULL_CHECK (MethodStatus
);
265 if ((ParseStruct
->ComPacket
== NULL
) ||
266 (ParseStruct
->CurPacket
== NULL
) ||
267 (ParseStruct
->CurSubPacket
== NULL
)
270 DEBUG ((DEBUG_INFO
, "unexpected state: ComPacket=%p CurPacket=%p CurSubPacket=%p\n", ParseStruct
->ComPacket
, ParseStruct
->CurPacket
, ParseStruct
->CurSubPacket
));
271 return TcgResultFailureInvalidAction
;
274 // duplicate ParseStruct, then don't need to "reset" location cur ptr
275 CopyMem (&TmpParseStruct
, ParseStruct
, sizeof (TCG_PARSE_STRUCT
));
277 // method status list exists after the end method call in the subpacket
278 // skip tokens until ENDDATA is found
280 ERROR_CHECK (TcgGetNextToken (&TmpParseStruct
, &TcgToken
));
281 } while (TcgToken
.Type
!= TcgTokenTypeEndOfData
);
283 // only reach here if enddata is found
284 // at this point, the curptr is pointing at method status list beginning
285 ERROR_CHECK (TcgGetNextStartList (&TmpParseStruct
));
286 ERROR_CHECK (TcgGetNextUINT8 (&TmpParseStruct
, MethodStatus
));
287 ERROR_CHECK (TcgGetNextUINT8 (&TmpParseStruct
, &Reserved1
));
288 ERROR_CHECK (TcgGetNextUINT8 (&TmpParseStruct
, &Reserved2
));
289 ERROR_CHECK (TcgGetNextEndList (&TmpParseStruct
));
291 if (Reserved1
!= 0) {
292 DEBUG ((DEBUG_INFO
, "Method status reserved1 = 0x%02X (expected 0)\n", Reserved1
));
293 return TcgResultFailure
;
296 if (Reserved2
!= 0) {
297 DEBUG ((DEBUG_INFO
, "Method status reserved2 = 0x%02X (expected 0)\n", Reserved1
));
298 return TcgResultFailure
;
301 return TcgResultSuccess
;
305 Return the toke type string info.
307 @param Type Input the type info.
309 @retval Return the string for this type.
319 case TcgTokenTypeReserved
: return "Reserved";
320 case TcgTokenTypeTinyAtom
: return "Tiny Atom";
321 case TcgTokenTypeShortAtom
: return "Short Atom";
322 case TcgTokenTypeMediumAtom
: return "Medium Atom";
323 case TcgTokenTypeLongAtom
: return "Long Atom";
324 case TcgTokenTypeStartList
: return "Start List";
325 case TcgTokenTypeEndList
: return "End List";
326 case TcgTokenTypeStartName
: return "Start Name";
327 case TcgTokenTypeEndName
: return "End Name";
328 case TcgTokenTypeCall
: return "Call";
329 case TcgTokenTypeEndOfData
: return "End of Data";
330 case TcgTokenTypeEndOfSession
: return "End of Session";
331 case TcgTokenTypeStartTransaction
: return "Start Transaction";
332 case TcgTokenTypeEndTransaction
: return "End Transaction";
333 case TcgTokenTypeEmptyAtom
: return "Empty atom";
341 Adds Start Session call to the data structure. This creates the entire ComPacket structure and
342 returns the size of the entire compacket in the size parameter.
344 @param [in/out] CreateStruct Structure used to add the start session call
345 @param [in/out] Size Describes the size of the entire ComPacket (header and payload). Filled out by function.
346 @param [in] ComId ComID for the ComPacket
347 @param [in] ComIdExtension Extended ComID for the ComPacket
348 @param [in] HostSessionId Host Session ID
349 @param [in] SpId Security Provider to start session with
350 @param [in] Write Write option for start session. TRUE = start session requests write access
351 @param [in] HostChallengeLength Length of the host challenge. Length should be 0 if hostChallenge is NULL
352 @param [in] HostChallenge Host challenge for Host Signing Authority. If NULL, then no Host Challenge shall be sent.
353 @param [in] HostSigningAuthority Host Signing Authority used for start session. If NULL, then no Host Signing Authority shall be sent.
358 TcgCreateStartSession (
359 TCG_CREATE_STRUCT
*CreateStruct
,
362 UINT16 ComIdExtension
,
363 UINT32 HostSessionId
,
366 UINT32 HostChallengeLength
,
367 const VOID
*HostChallenge
,
368 TCG_UID HostSigningAuthority
371 ERROR_CHECK (TcgStartComPacket (CreateStruct
, ComId
, ComIdExtension
));
372 ERROR_CHECK (TcgStartPacket (CreateStruct
, 0x0, 0x0, 0x0, 0x0, 0x0));
373 ERROR_CHECK (TcgStartSubPacket (CreateStruct
, 0x0));
374 ERROR_CHECK (TcgStartMethodCall (CreateStruct
, TCG_UID_SMUID
, TCG_UID_SM_START_SESSION
));
375 ERROR_CHECK (TcgStartParameters (CreateStruct
));
376 ERROR_CHECK (TcgAddUINT32 (CreateStruct
, HostSessionId
));
377 ERROR_CHECK (TcgAddTcgUid (CreateStruct
, SpId
));
378 ERROR_CHECK (TcgAddBOOLEAN (CreateStruct
, Write
));
380 // optional parameters
381 if ((HostChallenge
!= NULL
) && (HostChallengeLength
!= 0)) {
382 ERROR_CHECK (TcgAddStartName (CreateStruct
));
383 ERROR_CHECK (TcgAddUINT8 (CreateStruct
, 0x00)); // TODO Create Enum for Method Optional Parameters?
384 ERROR_CHECK (TcgAddByteSequence (CreateStruct
, HostChallenge
, HostChallengeLength
, FALSE
));
385 ERROR_CHECK (TcgAddEndName (CreateStruct
));
388 // optional parameters
389 if (HostSigningAuthority
!= 0) {
390 ERROR_CHECK (TcgAddStartName (CreateStruct
));
391 ERROR_CHECK (TcgAddUINT8 (CreateStruct
, 0x03)); // TODO Create Enum for Method Optional Parameters?
392 ERROR_CHECK (TcgAddTcgUid (CreateStruct
, HostSigningAuthority
));
393 ERROR_CHECK (TcgAddEndName (CreateStruct
));
396 ERROR_CHECK (TcgEndParameters (CreateStruct
));
397 ERROR_CHECK (TcgEndMethodCall (CreateStruct
));
398 ERROR_CHECK (TcgEndSubPacket (CreateStruct
));
399 ERROR_CHECK (TcgEndPacket (CreateStruct
));
400 ERROR_CHECK (TcgEndComPacket (CreateStruct
, Size
));
402 return TcgResultSuccess
;
406 Parses the Sync Session response contained in the parseStruct to retrieve Tper session ID. If the Sync Session response
407 parameters do not match the comID, extended ComID and host session ID then a failure is returned.
409 @param[in/out] ParseStruct Structure used to parse received TCG response, contains Sync Session response.
410 @param[in] ComId Expected ComID that is compared to actual ComID of response
411 @param[in] ComIdExtension Expected Extended ComID that is compared to actual Extended ComID of response
412 @param[in] HostSessionId Expected Host Session ID that is compared to actual Host Session ID of response
413 @param[in/out] TperSessionId Tper Session ID retrieved from the Sync Session response.
418 TcgParseSyncSession (
419 const TCG_PARSE_STRUCT
*ParseStruct
,
421 UINT16 ComIdExtension
,
422 UINT32 HostSessionId
,
423 UINT32
*TperSessionId
427 TCG_PARSE_STRUCT TmpParseStruct
;
429 UINT16 ParseExtComId
;
432 UINT32 RecvHostSessionId
;
434 NULL_CHECK (ParseStruct
);
435 NULL_CHECK (TperSessionId
);
437 CopyMem (&TmpParseStruct
, ParseStruct
, sizeof (TCG_PARSE_STRUCT
));
439 // verify method status is good
440 ERROR_CHECK (TcgGetMethodStatus (&TmpParseStruct
, &MethodStatus
));
441 METHOD_STATUS_ERROR_CHECK (MethodStatus
, TcgResultFailure
);
444 ERROR_CHECK (TcgGetComIds (&TmpParseStruct
, &ParseComId
, &ParseExtComId
));
446 if ((ComId
!= ParseComId
) || (ComIdExtension
!= ParseExtComId
)) {
447 DEBUG ((DEBUG_INFO
, "unmatched comid (exp: 0x%X recv: 0x%X) or comid extension (exp: 0x%X recv: 0x%X)\n", ComId
, ParseComId
, ComIdExtension
, ParseExtComId
));
448 return TcgResultFailure
;
451 ERROR_CHECK (TcgGetNextCall (&TmpParseStruct
));
452 ERROR_CHECK (TcgGetNextTcgUid (&TmpParseStruct
, &InvokingUID
));
453 ERROR_CHECK (TcgGetNextTcgUid (&TmpParseStruct
, &MethodUID
));
454 ERROR_CHECK (TcgGetNextStartList (&TmpParseStruct
));
455 ERROR_CHECK (TcgGetNextUINT32 (&TmpParseStruct
, &RecvHostSessionId
));
456 ERROR_CHECK (TcgGetNextUINT32 (&TmpParseStruct
, TperSessionId
));
457 ERROR_CHECK (TcgGetNextEndList (&TmpParseStruct
));
458 ERROR_CHECK (TcgGetNextEndOfData (&TmpParseStruct
));
460 if (InvokingUID
!= TCG_UID_SMUID
) {
461 DEBUG ((DEBUG_INFO
, "Invoking UID did not match UID_SMUID\n"));
462 return TcgResultFailure
;
465 if (MethodUID
!= TCG_UID_SM_SYNC_SESSION
) {
466 DEBUG ((DEBUG_INFO
, "Method UID did not match UID_SM_SYNC_SESSION\n"));
467 return TcgResultFailure
;
470 if (HostSessionId
!= RecvHostSessionId
) {
471 DEBUG ((DEBUG_INFO
, "unmatched HostSessionId (exp: 0x%X recv: 0x%X)\n", HostSessionId
, RecvHostSessionId
));
472 return TcgResultFailure
;
475 return TcgResultSuccess
;
480 Creates ComPacket with EndSession.
481 This assumes a start session has already been opened.
483 @param [in/out] CreateStruct Structure used to add Endsession
484 @param [in/out] Size Describes the size of the entire ComPacket (header and payload). Filled out by function.
485 @param [in] ComId ComID for the ComPacket
486 @param [in] ComIdExtension Extended ComID for the ComPacket
487 @param [in] HostSessionId Host Session ID for the Packet
488 @param [in] TpSessionId Tper Session ID for the Packet
493 TcgCreateEndSession (
494 TCG_CREATE_STRUCT
*CreateStruct
,
497 UINT16 ComIdExtension
,
498 UINT32 HostSessionId
,
502 ERROR_CHECK (TcgStartComPacket (CreateStruct
, ComId
, ComIdExtension
));
503 ERROR_CHECK (TcgStartPacket (CreateStruct
, TpSessionId
, HostSessionId
, 0x0, 0x0, 0x0));
504 ERROR_CHECK (TcgStartSubPacket (CreateStruct
, 0x0));
505 ERROR_CHECK (TcgAddEndOfSession (CreateStruct
));
506 ERROR_CHECK (TcgEndSubPacket (CreateStruct
));
507 ERROR_CHECK (TcgEndPacket (CreateStruct
));
508 ERROR_CHECK (TcgEndComPacket (CreateStruct
, Size
));
510 return TcgResultSuccess
;
516 @param CreateStruct Input create structure.
517 @param Row Input the row info.
518 @param ColumnNumber the column info.
524 TCG_CREATE_STRUCT
*CreateStruct
,
529 ERROR_CHECK (TcgStartMethodCall (CreateStruct
, Row
, TCG_UID_METHOD_SET
));
530 ERROR_CHECK (TcgStartParameters (CreateStruct
));
531 ERROR_CHECK (TcgAddStartName (CreateStruct
));
532 ERROR_CHECK (TcgAddUINT8 (CreateStruct
, 0x01)); // "Values"
533 ERROR_CHECK (TcgAddStartList (CreateStruct
));
534 ERROR_CHECK (TcgAddStartName (CreateStruct
));
535 ERROR_CHECK (TcgAddUINT32 (CreateStruct
, ColumnNumber
));
536 return TcgResultSuccess
;
542 @param CreateStruct Input create structure.
548 TCG_CREATE_STRUCT
*CreateStruct
551 ERROR_CHECK (TcgAddEndName (CreateStruct
));
552 ERROR_CHECK (TcgAddEndList (CreateStruct
));
553 ERROR_CHECK (TcgAddEndName (CreateStruct
));
554 ERROR_CHECK (TcgEndParameters (CreateStruct
));
555 ERROR_CHECK (TcgEndMethodCall (CreateStruct
));
556 return TcgResultSuccess
;
560 Creates ComPacket with a Method call that sets the PIN column for the row specified.
561 This assumes a start session has already been opened with the desired SP.
563 @param [in/out] CreateStruct Structure used to add method call.
564 @param [in/out] Size Describes the size of the entire ComPacket (header and payload). Filled out by function.
565 @param [in] ComId ComID for the ComPacket
566 @param [in] ComIdExtension Extended ComID for the ComPacket
567 @param [in] TperSession Tper Session ID for the Packet
568 @param [in] HostSession Host Session ID for the Packet
569 @param [in] SidRow UID of row of current SP to set PIN column
570 @param [in] Password value of PIN to set
571 @param [in] PasswordSize Size of PIN
577 TCG_CREATE_STRUCT
*CreateStruct
,
580 UINT16 ComIdExtension
,
584 const VOID
*Password
,
588 // set new SID Password
589 ERROR_CHECK (TcgStartComPacket (CreateStruct
, ComId
, ComIdExtension
));
590 ERROR_CHECK (TcgStartPacket (CreateStruct
, TperSession
, HostSession
, 0x0, 0x0, 0x0));
591 ERROR_CHECK (TcgStartSubPacket (CreateStruct
, 0x0));
592 ERROR_CHECK (TcgStartMethodSet (CreateStruct
, SidRow
, 0x03)); // "PIN"
593 ERROR_CHECK (TcgAddByteSequence (CreateStruct
, Password
, PasswordSize
, FALSE
));
594 ERROR_CHECK (TcgEndMethodSet (CreateStruct
));
595 ERROR_CHECK (TcgEndSubPacket (CreateStruct
));
596 ERROR_CHECK (TcgEndPacket (CreateStruct
));
597 ERROR_CHECK (TcgEndComPacket (CreateStruct
, Size
));
598 return TcgResultSuccess
;
602 Creates ComPacket with a Method call that sets the "Enabled" column for the row specified using the value specified.
603 This assumes a start session has already been opened with the desired SP.
605 @param [in/out] CreateStruct Structure used to add method call
606 @param [in/out] Size Describes the size of the entire ComPacket (header and payload). Filled out by function.
607 @param [in] ComId ComID for the ComPacket
608 @param [in] ComIdExtension Extended ComID for the ComPacket
609 @param [in] TperSession Tper Session ID for the Packet
610 @param [in] HostSession Host Session ID for the Packet
611 @param [in] AuthorityUid Authority UID to modify the "Enabled" column for
612 @param [in] Enabled Value to set the "Enabled" column to
617 TcgSetAuthorityEnabled (
618 TCG_CREATE_STRUCT
*CreateStruct
,
621 UINT16 ComIdExtension
,
624 TCG_UID AuthorityUid
,
628 ERROR_CHECK (TcgStartComPacket (CreateStruct
, ComId
, ComIdExtension
));
629 ERROR_CHECK (TcgStartPacket (CreateStruct
, TperSession
, HostSession
, 0x0, 0x0, 0x0));
630 ERROR_CHECK (TcgStartSubPacket (CreateStruct
, 0x0));
631 ERROR_CHECK (TcgStartMethodSet (CreateStruct
, AuthorityUid
, 0x05)); // "Enabled"
632 ERROR_CHECK (TcgAddBOOLEAN (CreateStruct
, Enabled
));
633 ERROR_CHECK (TcgEndMethodSet (CreateStruct
));
634 ERROR_CHECK (TcgEndSubPacket (CreateStruct
));
635 ERROR_CHECK (TcgEndPacket (CreateStruct
));
636 ERROR_CHECK (TcgEndComPacket (CreateStruct
, Size
));
637 return TcgResultSuccess
;
643 @param CreateStruct Input create structure.
644 @param Size size info.
645 @param ComId ComId info.
646 @param ComIdExtension ComId extension info.
647 @param TperSession Tper session data.
648 @param HostSession Host session data.
649 @param AceRow Ace row info.
650 @param Authority1 Authority 1 info.
651 @param LogicalOperator Logical operator info.
652 @param Authority2 Authority 2 info.
654 @retval Return the action result.
660 TCG_CREATE_STRUCT
*CreateStruct
,
663 UINT16 ComIdExtension
,
668 BOOLEAN LogicalOperator
,
672 UINT8 HalfUidAuthorityObjectRef
[4];
673 UINT8 HalfUidBooleanAce
[4];
675 HalfUidAuthorityObjectRef
[0] = 0x0;
676 HalfUidAuthorityObjectRef
[1] = 0x0;
677 HalfUidAuthorityObjectRef
[2] = 0xC;
678 HalfUidAuthorityObjectRef
[3] = 0x5;
680 HalfUidBooleanAce
[0] = 0x0;
681 HalfUidBooleanAce
[1] = 0x0;
682 HalfUidBooleanAce
[2] = 0x4;
683 HalfUidBooleanAce
[3] = 0xE;
685 ERROR_CHECK (TcgStartComPacket (CreateStruct
, ComId
, ComIdExtension
));
686 ERROR_CHECK (TcgStartPacket (CreateStruct
, TperSession
, HostSession
, 0x0, 0x0, 0x0));
687 ERROR_CHECK (TcgStartSubPacket (CreateStruct
, 0x0));
688 ERROR_CHECK (TcgStartMethodSet (CreateStruct
, AceRow
, 0x03)); // "BooleanExpr"
689 ERROR_CHECK (TcgAddStartList (CreateStruct
));
690 ERROR_CHECK (TcgAddStartName (CreateStruct
));
691 ERROR_CHECK (TcgAddByteSequence (CreateStruct
, HalfUidAuthorityObjectRef
, sizeof (HalfUidAuthorityObjectRef
), FALSE
));
692 ERROR_CHECK (TcgAddTcgUid (CreateStruct
, Authority1
));
693 ERROR_CHECK (TcgAddEndName (CreateStruct
));
694 ERROR_CHECK (TcgAddStartName (CreateStruct
));
695 ERROR_CHECK (TcgAddByteSequence (CreateStruct
, HalfUidAuthorityObjectRef
, sizeof (HalfUidAuthorityObjectRef
), FALSE
));
696 ERROR_CHECK (TcgAddTcgUid (CreateStruct
, Authority2
));
697 ERROR_CHECK (TcgAddEndName (CreateStruct
));
699 ERROR_CHECK (TcgAddStartName (CreateStruct
));
700 ERROR_CHECK (TcgAddByteSequence (CreateStruct
, HalfUidBooleanAce
, sizeof (HalfUidBooleanAce
), FALSE
));
701 ERROR_CHECK (TcgAddBOOLEAN (CreateStruct
, LogicalOperator
));
702 ERROR_CHECK (TcgAddEndName (CreateStruct
));
703 ERROR_CHECK (TcgAddEndList (CreateStruct
));
704 ERROR_CHECK (TcgEndMethodSet (CreateStruct
));
705 ERROR_CHECK (TcgEndSubPacket (CreateStruct
));
706 ERROR_CHECK (TcgEndPacket (CreateStruct
));
707 ERROR_CHECK (TcgEndComPacket (CreateStruct
, Size
));
708 return TcgResultSuccess
;
712 Enum level 0 discovery.
714 @param DiscoveryHeader Discovery header.
715 @param Callback Callback function.
716 @param Context The context for the function.
718 @retval return true if the callback return TRUE, else return FALSE.
723 TcgEnumLevel0Discovery (
724 const TCG_LEVEL0_DISCOVERY_HEADER
*DiscoveryHeader
,
725 TCG_LEVEL0_ENUM_CALLBACK Callback
,
730 const UINT8
*DiscoveryBufferPtr
;
732 TCG_LEVEL0_FEATURE_DESCRIPTOR_HEADER
*Feat
;
735 // Total bytes including descriptors but not including the Length field
737 BytesLeft
= SwapBytes32 (DiscoveryHeader
->LengthBE
);
740 // If discovery Header is not valid, exit
742 if (BytesLeft
== 0) {
747 // Subtract the Length of the Header, except the Length field, which is not included
749 BytesLeft
-= (sizeof (TCG_LEVEL0_DISCOVERY_HEADER
) - sizeof (DiscoveryHeader
->LengthBE
));
752 // Move ptr to first descriptor
754 DiscoveryBufferPtr
= (const UINT8
*)DiscoveryHeader
+ sizeof (TCG_LEVEL0_DISCOVERY_HEADER
);
756 while (BytesLeft
> sizeof (TCG_LEVEL0_FEATURE_DESCRIPTOR_HEADER
)) {
758 // Pointer to beginning of descriptor (including common Header)
760 Feat
= (TCG_LEVEL0_FEATURE_DESCRIPTOR_HEADER
*)DiscoveryBufferPtr
;
762 FeatLength
= Feat
->Length
+ sizeof (TCG_LEVEL0_FEATURE_DESCRIPTOR_HEADER
);
765 // Not enough bytes left for Feature descriptor
767 if (BytesLeft
< FeatLength
) {
772 // Report the Feature to the callback
774 if (Callback (DiscoveryHeader
, Feat
, FeatLength
, Context
)) {
779 // Descriptor Length only describes Data after common Header
781 BytesLeft
-= FeatLength
;
782 DiscoveryBufferPtr
+= FeatLength
;
789 The callback function for Get Feature function.
791 @param DiscoveryHeader Input discovery header.
792 @param Feature Input Feature.
793 @param FeatureSize Input Feature size.
794 @param Context The context.
799 TcgFindFeatureCallback (
800 const TCG_LEVEL0_DISCOVERY_HEADER
*DiscoveryHeader
,
801 TCG_LEVEL0_FEATURE_DESCRIPTOR_HEADER
*Feature
,
806 TCG_FIND_FEATURE_CTX
*FindCtx
;
808 FindCtx
= (TCG_FIND_FEATURE_CTX
*)Context
;
809 if ( SwapBytes16 (Feature
->FeatureCode_BE
) == FindCtx
->FeatureCode
) {
810 FindCtx
->Feature
= Feature
;
811 FindCtx
->FeatureSize
= FeatureSize
;
812 return TRUE
; // done enumerating features
815 return FALSE
; // continue enumerating
819 Get Feature code from the header.
821 @param DiscoveryHeader The discovery header.
822 @param FeatureCode return the Feature code.
823 @param FeatureSize return the Feature size.
825 @retval return the Feature code data.
827 TCG_LEVEL0_FEATURE_DESCRIPTOR_HEADER
*
830 const TCG_LEVEL0_DISCOVERY_HEADER
*DiscoveryHeader
,
835 TCG_FIND_FEATURE_CTX FindCtx
;
837 FindCtx
.FeatureCode
= FeatureCode
;
838 FindCtx
.Feature
= NULL
;
839 FindCtx
.FeatureSize
= 0;
841 TcgEnumLevel0Discovery (DiscoveryHeader
, TcgFindFeatureCallback
, &FindCtx
);
842 if (FeatureSize
!= NULL
) {
843 *FeatureSize
= FindCtx
.FeatureSize
;
846 return FindCtx
.Feature
;
850 Determines if the protocol provided is part of the provided supported protocol list.
852 @param[in] ProtocolList Supported protocol list to investigate
853 @param[in] Protocol Protocol value to determine if supported
855 @return TRUE = protocol is supported, FALSE = protocol is not supported
859 TcgIsProtocolSupported (
860 const TCG_SUPPORTED_SECURITY_PROTOCOLS
*ProtocolList
,
867 ListLength
= SwapBytes16 (ProtocolList
->ListLength_BE
);
869 if (ListLength
> sizeof (ProtocolList
->List
)) {
870 DEBUG ((DEBUG_INFO
, "WARNING: list Length is larger than max allowed Value; truncating\n"));
871 ListLength
= sizeof (ProtocolList
->List
);
874 for (Index
= 0; Index
< ListLength
; Index
++) {
875 if (ProtocolList
->List
[Index
] == Protocol
) {
884 Check whether lock or not.
888 @retval TRUE if lock, FALSE if not lock.
893 const TCG_LEVEL0_DISCOVERY_HEADER
*Discovery
897 TCG_LOCKING_FEATURE_DESCRIPTOR
*LockDescriptor
;
900 LockDescriptor
= (TCG_LOCKING_FEATURE_DESCRIPTOR
*)TcgGetFeature (Discovery
, TCG_FEATURE_LOCKING
, &Size
);
902 if ((LockDescriptor
!= NULL
) && (Size
>= sizeof (*LockDescriptor
))) {
903 DEBUG ((DEBUG_INFO
, "locked: %d\n", LockDescriptor
->Locked
));
904 return LockDescriptor
->Locked
;
908 // Descriptor was not found