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);
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);
93 return TcgResultSuccess;
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);
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);
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);
179 return TcgResultSuccess;
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;
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;
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;
281 }
while (TcgToken.Type != TcgTokenTypeEndOfData);
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;
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";
362 UINT16 ComIdExtension,
363 UINT32 HostSessionId,
366 UINT32 HostChallengeLength,
367 const VOID *HostChallenge,
372 ERROR_CHECK (
TcgStartPacket (CreateStruct, 0x0, 0x0, 0x0, 0x0, 0x0));
374 ERROR_CHECK (
TcgStartMethodCall (CreateStruct, TCG_UID_SMUID, TCG_UID_SM_START_SESSION));
376 ERROR_CHECK (
TcgAddUINT32 (CreateStruct, HostSessionId));
381 if ((HostChallenge !=
NULL) && (HostChallengeLength != 0)) {
389 if (HostSigningAuthority != 0) {
392 ERROR_CHECK (
TcgAddTcgUid (CreateStruct, HostSigningAuthority));
402 return TcgResultSuccess;
421 UINT16 ComIdExtension,
422 UINT32 HostSessionId,
423 UINT32 *TperSessionId
429 UINT16 ParseExtComId;
432 UINT32 RecvHostSessionId;
434 NULL_CHECK (ParseStruct);
435 NULL_CHECK (TperSessionId);
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;
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;
497 UINT16 ComIdExtension,
498 UINT32 HostSessionId,
503 ERROR_CHECK (
TcgStartPacket (CreateStruct, TpSessionId, HostSessionId, 0x0, 0x0, 0x0));
510 return TcgResultSuccess;
535 ERROR_CHECK (
TcgAddUINT32 (CreateStruct, ColumnNumber));
536 return TcgResultSuccess;
556 return TcgResultSuccess;
580 UINT16 ComIdExtension,
584 const VOID *Password,
590 ERROR_CHECK (
TcgStartPacket (CreateStruct, TperSession, HostSession, 0x0, 0x0, 0x0));
598 return TcgResultSuccess;
621 UINT16 ComIdExtension,
629 ERROR_CHECK (
TcgStartPacket (CreateStruct, TperSession, HostSession, 0x0, 0x0, 0x0));
637 return TcgResultSuccess;
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;
686 ERROR_CHECK (
TcgStartPacket (CreateStruct, TperSession, HostSession, 0x0, 0x0, 0x0));
691 ERROR_CHECK (
TcgAddByteSequence (CreateStruct, HalfUidAuthorityObjectRef,
sizeof (HalfUidAuthorityObjectRef),
FALSE));
695 ERROR_CHECK (
TcgAddByteSequence (CreateStruct, HalfUidAuthorityObjectRef,
sizeof (HalfUidAuthorityObjectRef),
FALSE));
708 return TcgResultSuccess;
725 TCG_LEVEL0_ENUM_CALLBACK Callback,
730 const UINT8 *DiscoveryBufferPtr;
737 BytesLeft =
SwapBytes32 (DiscoveryHeader->LengthBE);
742 if (BytesLeft == 0) {
767 if (BytesLeft < FeatLength) {
774 if (Callback (DiscoveryHeader, Feat, FeatLength, Context)) {
781 BytesLeft -= FeatLength;
782 DiscoveryBufferPtr += FeatLength;
809 if (
SwapBytes16 (Feature->FeatureCode_BE) == FindCtx->FeatureCode ) {
810 FindCtx->Feature = Feature;
811 FindCtx->FeatureSize = FeatureSize;
837 FindCtx.FeatureCode = FeatureCode;
838 FindCtx.Feature =
NULL;
839 FindCtx.FeatureSize = 0;
842 if (FeatureSize !=
NULL) {
843 *FeatureSize = FindCtx.FeatureSize;
846 return FindCtx.Feature;
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) {
902 if ((LockDescriptor !=
NULL) && (Size >=
sizeof (*LockDescriptor))) {
903 DEBUG ((DEBUG_INFO,
"locked: %d\n", LockDescriptor->Locked));
904 return LockDescriptor->Locked;
UINT16 EFIAPI SwapBytes16(IN UINT16 Value)
UINT32 EFIAPI SwapBytes32(IN UINT32 Value)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define DEBUG(Expression)
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 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)