TianoCore EDK2 master
Loading...
Searching...
No Matches
TcgStorageUtil.c
Go to the documentation of this file.
1
10
11#include <Library/BaseLib.h>
13#include <Library/DebugLib.h>
14
15typedef struct {
16 UINT16 FeatureCode;
18 UINTN FeatureSize;
20
29CHAR8 *
30EFIAPI
32 UINT8 MethodStatus
33 )
34{
35 switch (MethodStatus) {
36 #define C(status) case TCG_METHOD_STATUS_CODE_ ## status: return #status
37 C (SUCCESS);
38 C (NOT_AUTHORIZED);
39 C (OBSOLETE);
40 C (SP_BUSY);
41 C (SP_FAILED);
42 C (SP_DISABLED);
43 C (SP_FROZEN);
44 C (NO_SESSIONS_AVAILABLE);
45 C (UNIQUENESS_CONFLICT);
46 C (INSUFFICIENT_SPACE);
47 C (INSUFFICIENT_ROWS);
48 C (INVALID_PARAMETER);
49 C (OBSOLETE2);
50 C (OBSOLETE3);
51 C (TPER_MALFUNCTION);
52 C (TRANSACTION_FAILURE);
53 C (RESPONSE_OVERFLOW);
54 C (AUTHORITY_LOCKED_OUT);
55 C (FAIL);
56 #undef C
57 }
58
59 return "unknown";
60}
61
71EFIAPI
73 TCG_CREATE_STRUCT *CreateStruct,
74 TCG_UID InvokingId,
75 TCG_UID MethodId
76 )
77{
78 NULL_CHECK (CreateStruct);
79
80 if ((CreateStruct->ComPacket == NULL) ||
81 (CreateStruct->CurPacket == NULL) ||
82 (CreateStruct->CurSubPacket == NULL)
83 )
84 {
85 DEBUG ((DEBUG_INFO, "unexpected state: ComPacket=%p CurPacket=%p CurSubPacket=%p\n", CreateStruct->ComPacket, CreateStruct->CurPacket, CreateStruct->CurSubPacket));
86 return (TcgResultFailureInvalidAction);
87 }
88
89 ERROR_CHECK (TcgAddCall (CreateStruct));
90 ERROR_CHECK (TcgAddTcgUid (CreateStruct, InvokingId));
91 ERROR_CHECK (TcgAddTcgUid (CreateStruct, MethodId));
92
93 return TcgResultSuccess;
94}
95
103EFIAPI
105 TCG_CREATE_STRUCT *CreateStruct
106 )
107{
108 NULL_CHECK (CreateStruct);
109
110 if ((CreateStruct->ComPacket == NULL) ||
111 (CreateStruct->CurPacket == NULL) ||
112 (CreateStruct->CurSubPacket == NULL)
113 )
114 {
115 DEBUG ((DEBUG_INFO, "unexpected state: ComPacket=%p CurPacket=%p CurSubPacket=%p\n", CreateStruct->ComPacket, CreateStruct->CurPacket, CreateStruct->CurSubPacket));
116 return (TcgResultFailureInvalidAction);
117 }
118
119 return TcgAddStartList (CreateStruct);
120}
121
129EFIAPI
131 TCG_CREATE_STRUCT *CreateStruct
132 )
133{
134 NULL_CHECK (CreateStruct);
135
136 if ((CreateStruct->ComPacket == NULL) ||
137 (CreateStruct->CurPacket == NULL) ||
138 (CreateStruct->CurSubPacket == NULL)
139 )
140 {
141 DEBUG ((DEBUG_INFO, "unexpected state: ComPacket=%p CurPacket=%p CurSubPacket=%p\n", CreateStruct->ComPacket, CreateStruct->CurPacket, CreateStruct->CurSubPacket));
142 return (TcgResultFailureInvalidAction);
143 }
144
145 return TcgAddEndList (CreateStruct);
146}
147
155EFIAPI
157 TCG_CREATE_STRUCT *CreateStruct
158 )
159{
160 NULL_CHECK (CreateStruct);
161
162 if ((CreateStruct->ComPacket == NULL) ||
163 (CreateStruct->CurPacket == NULL) ||
164 (CreateStruct->CurSubPacket == NULL)
165 )
166 {
167 DEBUG ((DEBUG_INFO, "unexpected state: ComPacket=%p CurPacket=%p CurSubPacket=%p\n", CreateStruct->ComPacket, CreateStruct->CurPacket, CreateStruct->CurSubPacket));
168 return (TcgResultFailureInvalidAction);
169 }
170
171 ERROR_CHECK (TcgAddEndOfData (CreateStruct));
172
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));
178
179 return TcgResultSuccess;
180}
181
192EFIAPI
194 const TCG_PARSE_STRUCT *ParseStruct,
195 UINT16 *ComId,
196 UINT16 *ComIdExtension
197 )
198{
199 NULL_CHECK (ParseStruct);
200 NULL_CHECK (ComId);
201 NULL_CHECK (ComIdExtension);
202
203 if (ParseStruct->ComPacket == NULL) {
204 DEBUG ((DEBUG_INFO, "unexpected state: ComPacket=%p\n", ParseStruct->ComPacket));
205 return TcgResultFailureInvalidAction;
206 }
207
208 *ComId = SwapBytes16 (ParseStruct->ComPacket->ComIDBE);
209 *ComIdExtension = SwapBytes16 (ParseStruct->ComPacket->ComIDExtensionBE);
210
211 return TcgResultSuccess;
212}
213
223EFIAPI
225 const TCG_PARSE_STRUCT *ParseStruct,
226 UINT16 ExpectedComId,
227 UINT16 ExpectedComIdExtension
228 )
229{
230 UINT16 ParseComId;
231 UINT16 ParseComIdExtension;
232
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;
238 }
239
240 return TcgResultSuccess;
241}
242
252EFIAPI
254 const TCG_PARSE_STRUCT *ParseStruct,
255 UINT8 *MethodStatus
256 )
257{
258 TCG_PARSE_STRUCT TmpParseStruct;
259 TCG_TOKEN TcgToken;
260 UINT8 Reserved1, Reserved2;
261
262 NULL_CHECK (ParseStruct);
263 NULL_CHECK (MethodStatus);
264
265 if ((ParseStruct->ComPacket == NULL) ||
266 (ParseStruct->CurPacket == NULL) ||
267 (ParseStruct->CurSubPacket == NULL)
268 )
269 {
270 DEBUG ((DEBUG_INFO, "unexpected state: ComPacket=%p CurPacket=%p CurSubPacket=%p\n", ParseStruct->ComPacket, ParseStruct->CurPacket, ParseStruct->CurSubPacket));
271 return TcgResultFailureInvalidAction;
272 }
273
274 // duplicate ParseStruct, then don't need to "reset" location cur ptr
275 CopyMem (&TmpParseStruct, ParseStruct, sizeof (TCG_PARSE_STRUCT));
276
277 // method status list exists after the end method call in the subpacket
278 // skip tokens until ENDDATA is found
279 do {
280 ERROR_CHECK (TcgGetNextToken (&TmpParseStruct, &TcgToken));
281 } while (TcgToken.Type != TcgTokenTypeEndOfData);
282
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));
290
291 if (Reserved1 != 0) {
292 DEBUG ((DEBUG_INFO, "Method status reserved1 = 0x%02X (expected 0)\n", Reserved1));
293 return TcgResultFailure;
294 }
295
296 if (Reserved2 != 0) {
297 DEBUG ((DEBUG_INFO, "Method status reserved2 = 0x%02X (expected 0)\n", Reserved1));
298 return TcgResultFailure;
299 }
300
301 return TcgResultSuccess;
302}
303
312CHAR8 *
313EFIAPI
315 TCG_TOKEN_TYPE Type
316 )
317{
318 switch (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";
334 }
335
336 return "Unknown";
337}
338
357EFIAPI
359 TCG_CREATE_STRUCT *CreateStruct,
360 UINT32 *Size,
361 UINT16 ComId,
362 UINT16 ComIdExtension,
363 UINT32 HostSessionId,
364 TCG_UID SpId,
365 BOOLEAN Write,
366 UINT32 HostChallengeLength,
367 const VOID *HostChallenge,
368 TCG_UID HostSigningAuthority
369 )
370{
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));
379
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));
386 }
387
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));
394 }
395
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));
401
402 return TcgResultSuccess;
403}
404
417EFIAPI
419 const TCG_PARSE_STRUCT *ParseStruct,
420 UINT16 ComId,
421 UINT16 ComIdExtension,
422 UINT32 HostSessionId,
423 UINT32 *TperSessionId
424 )
425{
426 UINT8 MethodStatus;
427 TCG_PARSE_STRUCT TmpParseStruct;
428 UINT16 ParseComId;
429 UINT16 ParseExtComId;
430 TCG_UID InvokingUID;
431 TCG_UID MethodUID;
432 UINT32 RecvHostSessionId;
433
434 NULL_CHECK (ParseStruct);
435 NULL_CHECK (TperSessionId);
436
437 CopyMem (&TmpParseStruct, ParseStruct, sizeof (TCG_PARSE_STRUCT));
438
439 // verify method status is good
440 ERROR_CHECK (TcgGetMethodStatus (&TmpParseStruct, &MethodStatus));
441 METHOD_STATUS_ERROR_CHECK (MethodStatus, TcgResultFailure);
442
443 // verify comids
444 ERROR_CHECK (TcgGetComIds (&TmpParseStruct, &ParseComId, &ParseExtComId));
445
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;
449 }
450
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));
459
460 if (InvokingUID != TCG_UID_SMUID) {
461 DEBUG ((DEBUG_INFO, "Invoking UID did not match UID_SMUID\n"));
462 return TcgResultFailure;
463 }
464
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;
468 }
469
470 if (HostSessionId != RecvHostSessionId) {
471 DEBUG ((DEBUG_INFO, "unmatched HostSessionId (exp: 0x%X recv: 0x%X)\n", HostSessionId, RecvHostSessionId));
472 return TcgResultFailure;
473 }
474
475 return TcgResultSuccess;
476}
477
492EFIAPI
494 TCG_CREATE_STRUCT *CreateStruct,
495 UINT32 *Size,
496 UINT16 ComId,
497 UINT16 ComIdExtension,
498 UINT32 HostSessionId,
499 UINT32 TpSessionId
500 )
501{
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));
509
510 return TcgResultSuccess;
511}
512
522EFIAPI
524 TCG_CREATE_STRUCT *CreateStruct,
525 TCG_UID Row,
526 UINT32 ColumnNumber
527 )
528{
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;
537}
538
546EFIAPI
548 TCG_CREATE_STRUCT *CreateStruct
549 )
550{
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;
557}
558
575EFIAPI
577 TCG_CREATE_STRUCT *CreateStruct,
578 UINT32 *Size,
579 UINT16 ComId,
580 UINT16 ComIdExtension,
581 UINT32 TperSession,
582 UINT32 HostSession,
583 TCG_UID SidRow,
584 const VOID *Password,
585 UINT32 PasswordSize
586 )
587{
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;
599}
600
616EFIAPI
618 TCG_CREATE_STRUCT *CreateStruct,
619 UINT32 *Size,
620 UINT16 ComId,
621 UINT16 ComIdExtension,
622 UINT32 TperSession,
623 UINT32 HostSession,
624 TCG_UID AuthorityUid,
625 BOOLEAN Enabled
626 )
627{
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;
638}
639
658EFIAPI
660 TCG_CREATE_STRUCT *CreateStruct,
661 UINT32 *Size,
662 UINT16 ComId,
663 UINT16 ComIdExtension,
664 UINT32 TperSession,
665 UINT32 HostSession,
666 TCG_UID AceRow,
667 TCG_UID Authority1,
668 BOOLEAN LogicalOperator,
669 TCG_UID Authority2
670 )
671{
672 UINT8 HalfUidAuthorityObjectRef[4];
673 UINT8 HalfUidBooleanAce[4];
674
675 HalfUidAuthorityObjectRef[0] = 0x0;
676 HalfUidAuthorityObjectRef[1] = 0x0;
677 HalfUidAuthorityObjectRef[2] = 0xC;
678 HalfUidAuthorityObjectRef[3] = 0x5;
679
680 HalfUidBooleanAce[0] = 0x0;
681 HalfUidBooleanAce[1] = 0x0;
682 HalfUidBooleanAce[2] = 0x4;
683 HalfUidBooleanAce[3] = 0xE;
684
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));
698
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;
709}
710
721BOOLEAN
722EFIAPI
724 const TCG_LEVEL0_DISCOVERY_HEADER *DiscoveryHeader,
725 TCG_LEVEL0_ENUM_CALLBACK Callback,
726 VOID *Context
727 )
728{
729 UINT32 BytesLeft;
730 const UINT8 *DiscoveryBufferPtr;
731 UINT32 FeatLength;
733
734 //
735 // Total bytes including descriptors but not including the Length field
736 //
737 BytesLeft = SwapBytes32 (DiscoveryHeader->LengthBE);
738
739 //
740 // If discovery Header is not valid, exit
741 //
742 if (BytesLeft == 0) {
743 return FALSE;
744 }
745
746 //
747 // Subtract the Length of the Header, except the Length field, which is not included
748 //
749 BytesLeft -= (sizeof (TCG_LEVEL0_DISCOVERY_HEADER) - sizeof (DiscoveryHeader->LengthBE));
750
751 //
752 // Move ptr to first descriptor
753 //
754 DiscoveryBufferPtr = (const UINT8 *)DiscoveryHeader + sizeof (TCG_LEVEL0_DISCOVERY_HEADER);
755
756 while (BytesLeft > sizeof (TCG_LEVEL0_FEATURE_DESCRIPTOR_HEADER)) {
757 //
758 // Pointer to beginning of descriptor (including common Header)
759 //
760 Feat = (TCG_LEVEL0_FEATURE_DESCRIPTOR_HEADER *)DiscoveryBufferPtr;
761
762 FeatLength = Feat->Length + sizeof (TCG_LEVEL0_FEATURE_DESCRIPTOR_HEADER);
763
764 //
765 // Not enough bytes left for Feature descriptor
766 //
767 if (BytesLeft < FeatLength) {
768 break;
769 }
770
771 //
772 // Report the Feature to the callback
773 //
774 if (Callback (DiscoveryHeader, Feat, FeatLength, Context)) {
775 return TRUE;
776 }
777
778 //
779 // Descriptor Length only describes Data after common Header
780 //
781 BytesLeft -= FeatLength;
782 DiscoveryBufferPtr += FeatLength;
783 }
784
785 return FALSE;
786}
787
797BOOLEAN
798EFIAPI
800 const TCG_LEVEL0_DISCOVERY_HEADER *DiscoveryHeader,
802 UINTN FeatureSize,
803 VOID *Context
804 )
805{
806 TCG_FIND_FEATURE_CTX *FindCtx;
807
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
813 }
814
815 return FALSE; // continue enumerating
816}
817
828EFIAPI
830 const TCG_LEVEL0_DISCOVERY_HEADER *DiscoveryHeader,
831 UINT16 FeatureCode,
832 UINTN *FeatureSize
833 )
834{
835 TCG_FIND_FEATURE_CTX FindCtx;
836
837 FindCtx.FeatureCode = FeatureCode;
838 FindCtx.Feature = NULL;
839 FindCtx.FeatureSize = 0;
840
841 TcgEnumLevel0Discovery (DiscoveryHeader, TcgFindFeatureCallback, &FindCtx);
842 if (FeatureSize != NULL) {
843 *FeatureSize = FindCtx.FeatureSize;
844 }
845
846 return FindCtx.Feature;
847}
848
857BOOLEAN
858EFIAPI
860 const TCG_SUPPORTED_SECURITY_PROTOCOLS *ProtocolList,
861 UINT16 Protocol
862 )
863{
864 UINT16 Index;
865 UINT16 ListLength;
866
867 ListLength = SwapBytes16 (ProtocolList->ListLength_BE);
868
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);
872 }
873
874 for (Index = 0; Index < ListLength; Index++) {
875 if (ProtocolList->List[Index] == Protocol) {
876 return TRUE;
877 }
878 }
879
880 return FALSE;
881}
882
890BOOLEAN
891EFIAPI
893 const TCG_LEVEL0_DISCOVERY_HEADER *Discovery
894 )
895{
896 UINTN Size;
897 TCG_LOCKING_FEATURE_DESCRIPTOR *LockDescriptor;
898
899 Size = 0;
900 LockDescriptor = (TCG_LOCKING_FEATURE_DESCRIPTOR *)TcgGetFeature (Discovery, TCG_FEATURE_LOCKING, &Size);
901
902 if ((LockDescriptor != NULL) && (Size >= sizeof (*LockDescriptor))) {
903 DEBUG ((DEBUG_INFO, "locked: %d\n", LockDescriptor->Locked));
904 return LockDescriptor->Locked;
905 }
906
907 //
908 // Descriptor was not found
909 //
910 return FALSE;
911}
UINT64 UINTN
UINT16 EFIAPI SwapBytes16(IN UINT16 Value)
Definition: SwapBytes16.c:25
UINT32 EFIAPI SwapBytes32(IN UINT32 Value)
Definition: SwapBytes32.c:25
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define DEBUG(Expression)
Definition: DebugLib.h:434
UINT64 TCG_UID
UID in host native byte order.
TCG_RESULT EFIAPI TcgGetNextToken(TCG_PARSE_STRUCT *ParseStruct, TCG_TOKEN *TcgToken)
TCG_RESULT EFIAPI TcgAddEndOfSession(TCG_CREATE_STRUCT *CreateStruct)
TCG_RESULT EFIAPI TcgGetNextUINT8(TCG_PARSE_STRUCT *ParseStruct, UINT8 *Value)
TCG_RESULT EFIAPI TcgEndComPacket(TCG_CREATE_STRUCT *CreateStruct, UINT32 *Size)
TCG_RESULT
TCG_RESULT EFIAPI TcgAddByteSequence(TCG_CREATE_STRUCT *CreateStruct, const VOID *Data, UINT32 DataSize, BOOLEAN Continued)
TCG_RESULT EFIAPI TcgStartPacket(TCG_CREATE_STRUCT *CreateStruct, UINT32 Tsn, UINT32 Hsn, UINT32 SeqNumber, UINT16 AckType, UINT32 Ack)
TCG_RESULT EFIAPI TcgAddEndOfData(TCG_CREATE_STRUCT *CreateStruct)
TCG_RESULT EFIAPI TcgGetNextStartList(TCG_PARSE_STRUCT *ParseStruct)
TCG_RESULT EFIAPI TcgGetNextUINT32(TCG_PARSE_STRUCT *ParseStruct, UINT32 *Value)
TCG_RESULT EFIAPI TcgAddEndList(TCG_CREATE_STRUCT *CreateStruct)
TCG_RESULT EFIAPI TcgGetNextCall(TCG_PARSE_STRUCT *ParseStruct)
TCG_RESULT EFIAPI TcgAddTcgUid(TCG_CREATE_STRUCT *CreateStruct, TCG_UID Uid)
TCG_RESULT EFIAPI TcgGetNextTcgUid(TCG_PARSE_STRUCT *ParseStruct, TCG_UID *Uid)
TCG_RESULT EFIAPI TcgGetNextEndList(TCG_PARSE_STRUCT *ParseStruct)
TCG_RESULT EFIAPI TcgAddUINT32(TCG_CREATE_STRUCT *CreateStruct, UINT32 Value)
TCG_RESULT EFIAPI TcgEndSubPacket(TCG_CREATE_STRUCT *CreateStruct)
TCG_RESULT EFIAPI TcgAddStartList(TCG_CREATE_STRUCT *CreateStruct)
TCG_RESULT EFIAPI TcgAddCall(TCG_CREATE_STRUCT *CreateStruct)
TCG_RESULT EFIAPI TcgStartSubPacket(TCG_CREATE_STRUCT *CreateStruct, UINT16 Kind)
TCG_RESULT EFIAPI TcgStartComPacket(TCG_CREATE_STRUCT *CreateStruct, UINT16 ComId, UINT16 ComIdExtension)
TCG_RESULT EFIAPI TcgEndPacket(TCG_CREATE_STRUCT *CreateStruct)
TCG_RESULT EFIAPI TcgAddEndName(TCG_CREATE_STRUCT *CreateStruct)
TCG_RESULT EFIAPI TcgGetNextEndOfData(TCG_PARSE_STRUCT *ParseStruct)
TCG_RESULT EFIAPI TcgAddStartName(TCG_CREATE_STRUCT *CreateStruct)
TCG_RESULT EFIAPI TcgAddBOOLEAN(TCG_CREATE_STRUCT *CreateStruct, BOOLEAN Value)
TCG_RESULT EFIAPI TcgAddUINT8(TCG_CREATE_STRUCT *CreateStruct, UINT8 Value)
TCG_RESULT EFIAPI TcgEndMethodSet(TCG_CREATE_STRUCT *CreateStruct)
TCG_RESULT EFIAPI TcgStartMethodCall(TCG_CREATE_STRUCT *CreateStruct, TCG_UID InvokingId, TCG_UID MethodId)
BOOLEAN EFIAPI TcgIsLocked(const TCG_LEVEL0_DISCOVERY_HEADER *Discovery)
BOOLEAN EFIAPI TcgIsProtocolSupported(const TCG_SUPPORTED_SECURITY_PROTOCOLS *ProtocolList, UINT16 Protocol)
TCG_RESULT EFIAPI TcgCreateEndSession(TCG_CREATE_STRUCT *CreateStruct, UINT32 *Size, UINT16 ComId, UINT16 ComIdExtension, UINT32 HostSessionId, UINT32 TpSessionId)
TCG_RESULT EFIAPI TcgSetAuthorityEnabled(TCG_CREATE_STRUCT *CreateStruct, UINT32 *Size, UINT16 ComId, UINT16 ComIdExtension, UINT32 TperSession, UINT32 HostSession, TCG_UID AuthorityUid, BOOLEAN Enabled)
TCG_LEVEL0_FEATURE_DESCRIPTOR_HEADER *EFIAPI TcgGetFeature(const TCG_LEVEL0_DISCOVERY_HEADER *DiscoveryHeader, UINT16 FeatureCode, UINTN *FeatureSize)
TCG_RESULT EFIAPI TcgCreateSetAce(TCG_CREATE_STRUCT *CreateStruct, UINT32 *Size, UINT16 ComId, UINT16 ComIdExtension, UINT32 TperSession, UINT32 HostSession, TCG_UID AceRow, TCG_UID Authority1, BOOLEAN LogicalOperator, TCG_UID Authority2)
TCG_RESULT EFIAPI TcgCreateStartSession(TCG_CREATE_STRUCT *CreateStruct, UINT32 *Size, UINT16 ComId, UINT16 ComIdExtension, UINT32 HostSessionId, TCG_UID SpId, BOOLEAN Write, UINT32 HostChallengeLength, const VOID *HostChallenge, TCG_UID HostSigningAuthority)
TCG_RESULT EFIAPI TcgCheckComIds(const TCG_PARSE_STRUCT *ParseStruct, UINT16 ExpectedComId, UINT16 ExpectedComIdExtension)
CHAR8 *EFIAPI TcgMethodStatusString(UINT8 MethodStatus)
CHAR8 *EFIAPI TcgTokenTypeString(TCG_TOKEN_TYPE Type)
BOOLEAN EFIAPI TcgEnumLevel0Discovery(const TCG_LEVEL0_DISCOVERY_HEADER *DiscoveryHeader, TCG_LEVEL0_ENUM_CALLBACK Callback, VOID *Context)
BOOLEAN EFIAPI TcgFindFeatureCallback(const TCG_LEVEL0_DISCOVERY_HEADER *DiscoveryHeader, TCG_LEVEL0_FEATURE_DESCRIPTOR_HEADER *Feature, UINTN FeatureSize, VOID *Context)
TCG_RESULT EFIAPI TcgParseSyncSession(const TCG_PARSE_STRUCT *ParseStruct, UINT16 ComId, UINT16 ComIdExtension, UINT32 HostSessionId, UINT32 *TperSessionId)
TCG_RESULT EFIAPI TcgEndMethodCall(TCG_CREATE_STRUCT *CreateStruct)
TCG_RESULT EFIAPI TcgEndParameters(TCG_CREATE_STRUCT *CreateStruct)
TCG_RESULT EFIAPI TcgGetComIds(const TCG_PARSE_STRUCT *ParseStruct, UINT16 *ComId, UINT16 *ComIdExtension)
TCG_RESULT EFIAPI TcgStartParameters(TCG_CREATE_STRUCT *CreateStruct)
TCG_RESULT EFIAPI TcgGetMethodStatus(const TCG_PARSE_STRUCT *ParseStruct, UINT8 *MethodStatus)
TCG_RESULT EFIAPI TcgCreateSetCPin(TCG_CREATE_STRUCT *CreateStruct, UINT32 *Size, UINT16 ComId, UINT16 ComIdExtension, UINT32 TperSession, UINT32 HostSession, TCG_UID SidRow, const VOID *Password, UINT32 PasswordSize)
TCG_RESULT EFIAPI TcgStartMethodSet(TCG_CREATE_STRUCT *CreateStruct, TCG_UID Row, UINT32 ColumnNumber)