2 Provide functions to provide tcg storage core spec related functions.
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include <Library/TcgStorageCoreLib.h>
17 #include <Library/BaseLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/DebugLib.h>
23 TCG_LEVEL0_FEATURE_DESCRIPTOR_HEADER
*Feature
;
25 } TCG_FIND_FEATURE_CTX
;
28 Returns a human-readable string representing a method status return code.
30 @param[in] MethodStatus Method status to translate to a string
33 @retval return the string info.
37 TcgMethodStatusString(
41 switch (MethodStatus
) {
42 #define C(status) case TCG_METHOD_STATUS_CODE_ ## status: return #status
50 C(NO_SESSIONS_AVAILABLE
);
51 C(UNIQUENESS_CONFLICT
);
52 C(INSUFFICIENT_SPACE
);
58 C(TRANSACTION_FAILURE
);
60 C(AUTHORITY_LOCKED_OUT
);
69 adds call token and method Header (invoking id, and method id).
71 @param CreateStruct The input create structure.
72 @param InvokingId Invoking id.
73 @param MethodId Method id.
79 TCG_CREATE_STRUCT
*CreateStruct
,
84 NULL_CHECK(CreateStruct
);
86 if (CreateStruct
->ComPacket
== NULL
||
87 CreateStruct
->CurPacket
== NULL
||
88 CreateStruct
->CurSubPacket
== NULL
90 DEBUG ((DEBUG_INFO
, "unexpected state: ComPacket=%p CurPacket=%p CurSubPacket=%p\n", CreateStruct
->ComPacket
, CreateStruct
->CurPacket
, CreateStruct
->CurSubPacket
));
91 return (TcgResultFailureInvalidAction
);
94 ERROR_CHECK(TcgAddCall(CreateStruct
));
95 ERROR_CHECK(TcgAddTcgUid(CreateStruct
, InvokingId
));
96 ERROR_CHECK(TcgAddTcgUid(CreateStruct
, MethodId
));
98 return TcgResultSuccess
;
102 Adds START LIST token.
104 @param CreateStruct The input create structure.
110 TCG_CREATE_STRUCT
*CreateStruct
113 NULL_CHECK(CreateStruct
);
115 if (CreateStruct
->ComPacket
== NULL
||
116 CreateStruct
->CurPacket
== NULL
||
117 CreateStruct
->CurSubPacket
== NULL
119 DEBUG ((DEBUG_INFO
, "unexpected state: ComPacket=%p CurPacket=%p CurSubPacket=%p\n", CreateStruct
->ComPacket
, CreateStruct
->CurPacket
, CreateStruct
->CurSubPacket
));
120 return (TcgResultFailureInvalidAction
);
123 return TcgAddStartList(CreateStruct
);
129 @param CreateStruct The input create structure.
135 TCG_CREATE_STRUCT
*CreateStruct
138 NULL_CHECK(CreateStruct
);
140 if (CreateStruct
->ComPacket
== NULL
||
141 CreateStruct
->CurPacket
== NULL
||
142 CreateStruct
->CurSubPacket
== NULL
144 DEBUG ((DEBUG_INFO
, "unexpected state: ComPacket=%p CurPacket=%p CurSubPacket=%p\n", CreateStruct
->ComPacket
, CreateStruct
->CurPacket
, CreateStruct
->CurSubPacket
));
145 return (TcgResultFailureInvalidAction
);
148 return TcgAddEndList(CreateStruct
);
152 Adds END Data token and method list.
154 @param CreateStruct The input create structure.
160 TCG_CREATE_STRUCT
*CreateStruct
163 NULL_CHECK(CreateStruct
);
165 if (CreateStruct
->ComPacket
== NULL
||
166 CreateStruct
->CurPacket
== NULL
||
167 CreateStruct
->CurSubPacket
== NULL
169 DEBUG ((DEBUG_INFO
, "unexpected state: ComPacket=%p CurPacket=%p CurSubPacket=%p\n", CreateStruct
->ComPacket
, CreateStruct
->CurPacket
, CreateStruct
->CurSubPacket
));
170 return (TcgResultFailureInvalidAction
);
173 ERROR_CHECK(TcgAddEndOfData(CreateStruct
));
175 ERROR_CHECK(TcgAddStartList(CreateStruct
));
176 ERROR_CHECK(TcgAddUINT8(CreateStruct
, 0x00)); // expected to complete properly
177 ERROR_CHECK(TcgAddUINT8(CreateStruct
, 0x00)); // reserved
178 ERROR_CHECK(TcgAddUINT8(CreateStruct
, 0x00)); // reserved
179 ERROR_CHECK(TcgAddEndList(CreateStruct
));
181 return TcgResultSuccess
;
185 Retrieves the comID and Extended comID of the ComPacket in the Tcg response.
186 It is intended to be used to confirm the received Tcg response is intended for user that received it.
188 @param [in] ParseStruct Structure used to parse received TCG response.
189 @param [in/out] ComId comID retrieved from received ComPacket.
190 @param [in/out] ComIdExtension Extended comID retrieved from received ComPacket
196 const TCG_PARSE_STRUCT
*ParseStruct
,
198 UINT16
*ComIdExtension
201 NULL_CHECK(ParseStruct
);
203 NULL_CHECK(ComIdExtension
);
205 if (ParseStruct
->ComPacket
== NULL
) {
206 DEBUG ((DEBUG_INFO
, "unexpected state: ComPacket=%p\n", ParseStruct
->ComPacket
));
207 return TcgResultFailureInvalidAction
;
210 *ComId
= SwapBytes16(ParseStruct
->ComPacket
->ComIDBE
);
211 *ComIdExtension
= SwapBytes16(ParseStruct
->ComPacket
->ComIDExtensionBE
);
213 return TcgResultSuccess
;
217 Checks if the ComIDs of the response match the expected values.
219 @param[in] ParseStruct Structure used to parse received TCG response
220 @param[in] ExpectedComId Expected comID
221 @param[in] ExpectedComIdExtension Expected extended comID
227 const TCG_PARSE_STRUCT
*ParseStruct
,
228 UINT16 ExpectedComId
,
229 UINT16 ExpectedComIdExtension
233 UINT16 ParseComIdExtension
;
235 ERROR_CHECK(TcgGetComIds(ParseStruct
, &ParseComId
, &ParseComIdExtension
));
236 if (ParseComId
!= ExpectedComId
|| ParseComIdExtension
!= ExpectedComIdExtension
) {
237 DEBUG ((DEBUG_INFO
, "Com ID: Actual 0x%02X Expected 0x%02X\n", ParseComId
, ExpectedComId
));
238 DEBUG ((DEBUG_INFO
, "Extended Com ID: 0x%02X Expected 0x%02X\n", ParseComIdExtension
, ExpectedComIdExtension
));
239 return TcgResultFailure
;
241 return TcgResultSuccess
;
245 Returns the method status of the current subpacket. Does not affect the current position
246 in the ComPacket. In other words, it can be called whenever you have a valid SubPacket.
248 @param [in/out] ParseStruct Structure used to parse received TCG response
249 @param [in/out] MethodStatus Method status retrieved of the current SubPacket
255 const TCG_PARSE_STRUCT
*ParseStruct
,
259 TCG_PARSE_STRUCT TmpParseStruct
;
261 UINT8 Reserved1
, Reserved2
;
263 NULL_CHECK(ParseStruct
);
264 NULL_CHECK(MethodStatus
);
266 if (ParseStruct
->ComPacket
== NULL
||
267 ParseStruct
->CurPacket
== NULL
||
268 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
));
387 // optional parameters
388 if (HostSigningAuthority
!= 0) {
389 ERROR_CHECK(TcgAddStartName(CreateStruct
));
390 ERROR_CHECK(TcgAddUINT8(CreateStruct
, 0x03)); //TODO Create Enum for Method Optional Parameters?
391 ERROR_CHECK(TcgAddTcgUid(CreateStruct
, HostSigningAuthority
));
392 ERROR_CHECK(TcgAddEndName(CreateStruct
));
395 ERROR_CHECK(TcgEndParameters(CreateStruct
));
396 ERROR_CHECK(TcgEndMethodCall(CreateStruct
));
397 ERROR_CHECK(TcgEndSubPacket(CreateStruct
));
398 ERROR_CHECK(TcgEndPacket(CreateStruct
));
399 ERROR_CHECK(TcgEndComPacket(CreateStruct
, Size
));
401 return TcgResultSuccess
;
405 Parses the Sync Session response contained in the parseStruct to retrieve Tper session ID. If the Sync Session response
406 parameters do not match the comID, extended ComID and host session ID then a failure is returned.
408 @param[in/out] ParseStruct Structure used to parse received TCG response, contains Sync Session response.
409 @param[in] ComId Expected ComID that is compared to actual ComID of response
410 @param[in] ComIdExtension Expected Extended ComID that is compared to actual Extended ComID of response
411 @param[in] HostSessionId Expected Host Session ID that is compared to actual Host Session ID of response
412 @param[in/out] TperSessionId Tper Session ID retrieved from the Sync Session response.
418 const TCG_PARSE_STRUCT
*ParseStruct
,
420 UINT16 ComIdExtension
,
421 UINT32 HostSessionId
,
422 UINT32
*TperSessionId
426 TCG_PARSE_STRUCT TmpParseStruct
;
428 UINT16 ParseExtComId
;
431 UINT32 RecvHostSessionId
;
433 NULL_CHECK(ParseStruct
);
434 NULL_CHECK(TperSessionId
);
436 CopyMem (&TmpParseStruct
, ParseStruct
, sizeof(TCG_PARSE_STRUCT
));
438 // verify method status is good
439 ERROR_CHECK(TcgGetMethodStatus(&TmpParseStruct
, &MethodStatus
));
440 METHOD_STATUS_ERROR_CHECK (MethodStatus
, TcgResultFailure
);
443 ERROR_CHECK(TcgGetComIds(&TmpParseStruct
, &ParseComId
, &ParseExtComId
));
445 if ((ComId
!= ParseComId
) || (ComIdExtension
!= ParseExtComId
)) {
446 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
));
447 return TcgResultFailure
;
449 ERROR_CHECK(TcgGetNextCall(&TmpParseStruct
));
450 ERROR_CHECK(TcgGetNextTcgUid(&TmpParseStruct
, &InvokingUID
));
451 ERROR_CHECK(TcgGetNextTcgUid(&TmpParseStruct
, &MethodUID
));
452 ERROR_CHECK(TcgGetNextStartList(&TmpParseStruct
));
453 ERROR_CHECK(TcgGetNextUINT32(&TmpParseStruct
, &RecvHostSessionId
));
454 ERROR_CHECK(TcgGetNextUINT32(&TmpParseStruct
, TperSessionId
));
455 ERROR_CHECK(TcgGetNextEndList(&TmpParseStruct
));
456 ERROR_CHECK(TcgGetNextEndOfData(&TmpParseStruct
));
458 if (InvokingUID
!= TCG_UID_SMUID
) {
459 DEBUG ((DEBUG_INFO
, "Invoking UID did not match UID_SMUID\n"));
460 return TcgResultFailure
;
463 if (MethodUID
!= TCG_UID_SM_SYNC_SESSION
) {
464 DEBUG ((DEBUG_INFO
, "Method UID did not match UID_SM_SYNC_SESSION\n"));
465 return TcgResultFailure
;
468 if (HostSessionId
!= RecvHostSessionId
) {
469 DEBUG ((DEBUG_INFO
, "unmatched HostSessionId (exp: 0x%X recv: 0x%X)\n", HostSessionId
, RecvHostSessionId
));
470 return TcgResultFailure
;
473 return TcgResultSuccess
;
478 Creates ComPacket with EndSession.
479 This assumes a start session has already been opened.
481 @param [in/out] CreateStruct Structure used to add Endsession
482 @param [in/out] Size Describes the size of the entire ComPacket (header and payload). Filled out by function.
483 @param [in] ComId ComID for the ComPacket
484 @param [in] ComIdExtension Extended ComID for the ComPacket
485 @param [in] HostSessionId Host Session ID for the Packet
486 @param [in] TpSessionId Tper Session ID for the Packet
492 TCG_CREATE_STRUCT
*CreateStruct
,
495 UINT16 ComIdExtension
,
496 UINT32 HostSessionId
,
500 ERROR_CHECK(TcgStartComPacket(CreateStruct
, ComId
, ComIdExtension
));
501 ERROR_CHECK(TcgStartPacket(CreateStruct
, TpSessionId
, HostSessionId
, 0x0, 0x0, 0x0));
502 ERROR_CHECK(TcgStartSubPacket(CreateStruct
, 0x0));
503 ERROR_CHECK(TcgAddEndOfSession(CreateStruct
));
504 ERROR_CHECK(TcgEndSubPacket(CreateStruct
));
505 ERROR_CHECK(TcgEndPacket(CreateStruct
));
506 ERROR_CHECK(TcgEndComPacket(CreateStruct
, Size
));
508 return TcgResultSuccess
;
514 @param CreateStruct Input create structure.
515 @param Row Input the row info.
516 @param ColumnNumber the column info.
522 TCG_CREATE_STRUCT
*CreateStruct
,
527 ERROR_CHECK(TcgStartMethodCall(CreateStruct
, Row
, TCG_UID_METHOD_SET
));
528 ERROR_CHECK(TcgStartParameters(CreateStruct
));
529 ERROR_CHECK(TcgAddStartName(CreateStruct
));
530 ERROR_CHECK(TcgAddUINT8(CreateStruct
, 0x01)); // "Values"
531 ERROR_CHECK(TcgAddStartList(CreateStruct
));
532 ERROR_CHECK(TcgAddStartName(CreateStruct
));
533 ERROR_CHECK(TcgAddUINT32(CreateStruct
, ColumnNumber
));
534 return TcgResultSuccess
;
540 @param CreateStruct Input create structure.
546 TCG_CREATE_STRUCT
*CreateStruct
549 ERROR_CHECK(TcgAddEndName(CreateStruct
));
550 ERROR_CHECK(TcgAddEndList(CreateStruct
));
551 ERROR_CHECK(TcgAddEndName(CreateStruct
));
552 ERROR_CHECK(TcgEndParameters(CreateStruct
));
553 ERROR_CHECK(TcgEndMethodCall(CreateStruct
));
554 return TcgResultSuccess
;
558 Creates ComPacket with a Method call that sets the PIN column for the row specified.
559 This assumes a start session has already been opened with the desired SP.
561 @param [in/out] CreateStruct Structure used to add method call.
562 @param [in/out] Size Describes the size of the entire ComPacket (header and payload). Filled out by function.
563 @param [in] ComId ComID for the ComPacket
564 @param [in] ComIdExtension Extended ComID for the ComPacket
565 @param [in] TperSession Tper Session ID for the Packet
566 @param [in] HostSession Host Session ID for the Packet
567 @param [in] SidRow UID of row of current SP to set PIN column
568 @param [in] Password value of PIN to set
569 @param [in] PasswordSize Size of PIN
575 TCG_CREATE_STRUCT
*CreateStruct
,
578 UINT16 ComIdExtension
,
582 const VOID
*Password
,
586 // set new SID Password
587 ERROR_CHECK(TcgStartComPacket(CreateStruct
, ComId
, ComIdExtension
));
588 ERROR_CHECK(TcgStartPacket(CreateStruct
, TperSession
, HostSession
, 0x0, 0x0, 0x0));
589 ERROR_CHECK(TcgStartSubPacket(CreateStruct
, 0x0));
590 ERROR_CHECK(TcgStartMethodSet(CreateStruct
, SidRow
, 0x03)); // "PIN"
591 ERROR_CHECK(TcgAddByteSequence(CreateStruct
, Password
, PasswordSize
, FALSE
));
592 ERROR_CHECK(TcgEndMethodSet(CreateStruct
));
593 ERROR_CHECK(TcgEndSubPacket(CreateStruct
));
594 ERROR_CHECK(TcgEndPacket(CreateStruct
));
595 ERROR_CHECK(TcgEndComPacket(CreateStruct
, Size
));
596 return TcgResultSuccess
;
600 Creates ComPacket with a Method call that sets the "Enabled" column for the row specified using the value specified.
601 This assumes a start session has already been opened with the desired SP.
603 @param [in/out] CreateStruct Structure used to add method call
604 @param [in/out] Size Describes the size of the entire ComPacket (header and payload). Filled out by function.
605 @param [in] ComId ComID for the ComPacket
606 @param [in] ComIdExtension Extended ComID for the ComPacket
607 @param [in] TperSession Tper Session ID for the Packet
608 @param [in] HostSession Host Session ID for the Packet
609 @param [in] AuthorityUid Authority UID to modify the "Enabled" column for
610 @param [in] Enabled Value to set the "Enabled" column to
615 TcgSetAuthorityEnabled(
616 TCG_CREATE_STRUCT
*CreateStruct
,
619 UINT16 ComIdExtension
,
622 TCG_UID AuthorityUid
,
626 ERROR_CHECK(TcgStartComPacket(CreateStruct
, ComId
, ComIdExtension
));
627 ERROR_CHECK(TcgStartPacket(CreateStruct
, TperSession
, HostSession
, 0x0, 0x0, 0x0));
628 ERROR_CHECK(TcgStartSubPacket(CreateStruct
, 0x0));
629 ERROR_CHECK(TcgStartMethodSet(CreateStruct
, AuthorityUid
, 0x05)); // "Enabled"
630 ERROR_CHECK(TcgAddBOOLEAN(CreateStruct
, Enabled
));
631 ERROR_CHECK(TcgEndMethodSet(CreateStruct
));
632 ERROR_CHECK(TcgEndSubPacket(CreateStruct
));
633 ERROR_CHECK(TcgEndPacket(CreateStruct
));
634 ERROR_CHECK(TcgEndComPacket(CreateStruct
, Size
));
635 return TcgResultSuccess
;
641 @param CreateStruct Input create structure.
642 @param Size size info.
643 @param ComId ComId info.
644 @param ComIdExtension ComId extension info.
645 @param TperSession Tper session data.
646 @param HostSession Host session data.
647 @param AceRow Ace row info.
648 @param Authority1 Authority 1 info.
649 @param LogicalOperator Logiccal operator info.
650 @param Authority2 Authority 2 info.
652 @retval Return the action result.
658 TCG_CREATE_STRUCT
*CreateStruct
,
661 UINT16 ComIdExtension
,
666 BOOLEAN LogicalOperator
,
670 UINT8 HalfUidAuthorityObjectRef
[4];
671 UINT8 HalfUidBooleanAce
[4];
673 HalfUidAuthorityObjectRef
[0] = 0x0;
674 HalfUidAuthorityObjectRef
[1] = 0x0;
675 HalfUidAuthorityObjectRef
[2] = 0xC;
676 HalfUidAuthorityObjectRef
[3] = 0x5;
678 HalfUidBooleanAce
[0] = 0x0;
679 HalfUidBooleanAce
[1] = 0x0;
680 HalfUidBooleanAce
[2] = 0x4;
681 HalfUidBooleanAce
[3] = 0xE;
683 ERROR_CHECK(TcgStartComPacket(CreateStruct
, ComId
, ComIdExtension
));
684 ERROR_CHECK(TcgStartPacket(CreateStruct
, TperSession
, HostSession
, 0x0, 0x0, 0x0));
685 ERROR_CHECK(TcgStartSubPacket(CreateStruct
, 0x0));
686 ERROR_CHECK(TcgStartMethodSet(CreateStruct
, AceRow
, 0x03)); // "BooleanExpr"
687 ERROR_CHECK(TcgAddStartList(CreateStruct
));
688 ERROR_CHECK(TcgAddStartName(CreateStruct
));
689 ERROR_CHECK(TcgAddByteSequence(CreateStruct
, HalfUidAuthorityObjectRef
, sizeof(HalfUidAuthorityObjectRef
), FALSE
));
690 ERROR_CHECK(TcgAddTcgUid(CreateStruct
, Authority1
));
691 ERROR_CHECK(TcgAddEndName(CreateStruct
));
692 ERROR_CHECK(TcgAddStartName(CreateStruct
));
693 ERROR_CHECK(TcgAddByteSequence(CreateStruct
, HalfUidAuthorityObjectRef
, sizeof(HalfUidAuthorityObjectRef
), FALSE
));
694 ERROR_CHECK(TcgAddTcgUid(CreateStruct
, Authority2
));
695 ERROR_CHECK(TcgAddEndName(CreateStruct
));
697 ERROR_CHECK(TcgAddStartName(CreateStruct
));
698 ERROR_CHECK(TcgAddByteSequence(CreateStruct
, HalfUidBooleanAce
, sizeof(HalfUidBooleanAce
), FALSE
));
699 ERROR_CHECK(TcgAddBOOLEAN(CreateStruct
, LogicalOperator
));
700 ERROR_CHECK(TcgAddEndName(CreateStruct
));
701 ERROR_CHECK(TcgAddEndList(CreateStruct
));
702 ERROR_CHECK(TcgEndMethodSet(CreateStruct
));
703 ERROR_CHECK(TcgEndSubPacket(CreateStruct
));
704 ERROR_CHECK(TcgEndPacket(CreateStruct
));
705 ERROR_CHECK(TcgEndComPacket(CreateStruct
, Size
));
706 return TcgResultSuccess
;
710 Enum level 0 discovery.
712 @param DiscoveryHeader Discovery header.
713 @param Callback Callback function.
714 @param Context The context for the function.
716 @retval return true if the callback return TRUE, else return FALSE.
721 TcgEnumLevel0Discovery(
722 const TCG_LEVEL0_DISCOVERY_HEADER
*DiscoveryHeader
,
723 TCG_LEVEL0_ENUM_CALLBACK Callback
,
728 const UINT8
*DiscoveryBufferPtr
;
730 TCG_LEVEL0_FEATURE_DESCRIPTOR_HEADER
*Feat
;
733 // Total bytes including descriptors but not including the Length field
735 BytesLeft
= SwapBytes32(DiscoveryHeader
->LengthBE
);
738 // If discovery Header is not valid, exit
740 if (BytesLeft
== 0) {
745 // Subtract the Length of the Header, except the Length field, which is not included
747 BytesLeft
-= (sizeof(TCG_LEVEL0_DISCOVERY_HEADER
) - sizeof(DiscoveryHeader
->LengthBE
));
750 // Move ptr to first descriptor
752 DiscoveryBufferPtr
= (const UINT8
*)DiscoveryHeader
+ sizeof(TCG_LEVEL0_DISCOVERY_HEADER
);
754 while (BytesLeft
> sizeof(TCG_LEVEL0_FEATURE_DESCRIPTOR_HEADER
)) {
756 // Pointer to beginning of descriptor (including common Header)
758 Feat
= (TCG_LEVEL0_FEATURE_DESCRIPTOR_HEADER
*)DiscoveryBufferPtr
;
760 FeatLength
= Feat
->Length
+ sizeof(TCG_LEVEL0_FEATURE_DESCRIPTOR_HEADER
);
763 // Not enough bytes left for Feature descriptor
765 if (BytesLeft
< FeatLength
) {
770 // Report the Feature to the callback
772 if (Callback(DiscoveryHeader
, Feat
, FeatLength
, Context
)) {
777 // Descriptor Length only describes Data after common Header
779 BytesLeft
-= FeatLength
;
780 DiscoveryBufferPtr
+= FeatLength
;
787 The callback function for Get Feature function.
789 @param DiscoveryHeader Input discovery header.
790 @param Feature Input Feature.
791 @param FeatureSize Input Feature size.
792 @param Context The context.
797 TcgFindFeatureCallback(
798 const TCG_LEVEL0_DISCOVERY_HEADER
*DiscoveryHeader
,
799 TCG_LEVEL0_FEATURE_DESCRIPTOR_HEADER
*Feature
,
804 TCG_FIND_FEATURE_CTX
* FindCtx
;
806 FindCtx
= (TCG_FIND_FEATURE_CTX
*)Context
;
807 if ( SwapBytes16( Feature
->FeatureCode_BE
) == FindCtx
->FeatureCode
) {
808 FindCtx
->Feature
= Feature
;
809 FindCtx
->FeatureSize
= FeatureSize
;
810 return TRUE
; // done enumerating features
812 return FALSE
; // continue enumerating
816 Get Feature code from the header.
818 @param DiscoveryHeader The discovery header.
819 @param FeatureCode reutrn the Feature code.
820 @param FeatureSize return the Feature size.
822 @retval return the Feature code data.
824 TCG_LEVEL0_FEATURE_DESCRIPTOR_HEADER
*
827 const TCG_LEVEL0_DISCOVERY_HEADER
*DiscoveryHeader
,
832 TCG_FIND_FEATURE_CTX FindCtx
;
834 FindCtx
.FeatureCode
= FeatureCode
;
835 FindCtx
.Feature
= NULL
;
836 FindCtx
.FeatureSize
= 0;
838 TcgEnumLevel0Discovery(DiscoveryHeader
, TcgFindFeatureCallback
, &FindCtx
);
839 if (FeatureSize
!= NULL
) {
840 *FeatureSize
= FindCtx
.FeatureSize
;
842 return FindCtx
.Feature
;
846 Determines if the protocol provided is part of the provided supported protocol list.
848 @param[in] ProtocolList Supported protocol list to investigate
849 @param[in] Protocol Protocol value to determine if supported
851 @return TRUE = protocol is supported, FALSE = protocol is not supported
855 TcgIsProtocolSupported(
856 const TCG_SUPPORTED_SECURITY_PROTOCOLS
*ProtocolList
,
863 ListLength
= SwapBytes16(ProtocolList
->ListLength_BE
);
865 if (ListLength
> sizeof(ProtocolList
->List
)) {
866 DEBUG ((DEBUG_INFO
, "WARNING: list Length is larger than max allowed Value; truncating\n"));
867 ListLength
= sizeof(ProtocolList
->List
);
870 for (Index
= 0; Index
< ListLength
; Index
++) {
871 if (ProtocolList
->List
[Index
] == Protocol
) {
880 Check whether lock or not.
884 @retval TRUE if lock, FALSE if not lock.
889 const TCG_LEVEL0_DISCOVERY_HEADER
*Discovery
893 TCG_LOCKING_FEATURE_DESCRIPTOR
*LockDescriptor
;
896 LockDescriptor
=(TCG_LOCKING_FEATURE_DESCRIPTOR
*) TcgGetFeature (Discovery
, TCG_FEATURE_LOCKING
, &Size
);
898 if (LockDescriptor
!= NULL
&& Size
>= sizeof(*LockDescriptor
)) {
899 DEBUG ((DEBUG_INFO
, "locked: %d\n", LockDescriptor
->Locked
));
900 return LockDescriptor
->Locked
;
904 // Descriptor was not found