1use crate::{TpmMarshal, TpmResult, TpmSized, TpmWriter, basic::TpmList};
6use core::fmt::Debug;
7
8mod data;
9mod marshal;
10mod unmarshal;
11mod wire;
12
13pub use self::{data::*, marshal::*, wire::*};
14
15pub(crate) use self::unmarshal::TpmDispatch;
16
17use crate::constant::MAX_SESSIONS;
18
19const TPM_HEADER_SIZE: u32 = 10;
20
21pub type TpmAuthCommands = TpmList<crate::data::TpmsAuthCommand, MAX_SESSIONS>;
23
24pub type TpmAuthResponses = TpmList<crate::data::TpmsAuthResponse, MAX_SESSIONS>;
26
27pub trait TpmHeader {
29 const CC: crate::data::TpmCc;
31 const HANDLES: usize;
33}
34
35pub trait TpmFrame: TpmMarshal + TpmMarshalBody + Debug {
37 fn cc(&self) -> crate::data::TpmCc;
39 fn handles(&self) -> usize;
41}
42
43pub trait TpmMarshalBody: TpmSized {
45 fn marshal_handles(&self, writer: &mut TpmWriter) -> TpmResult<()>;
51
52 fn marshal_parameters(&self, writer: &mut TpmWriter) -> TpmResult<()>;
58}
59
60tpm_dispatch! {
61 (TpmNvUndefineSpaceSpecialCommand, TpmNvUndefineSpaceSpecialResponse, NvUndefineSpaceSpecial),
62 (TpmEvictControlCommand, TpmEvictControlResponse, EvictControl),
63 (TpmHierarchyControlCommand, TpmHierarchyControlResponse, HierarchyControl),
64 (TpmNvUndefineSpaceCommand, TpmNvUndefineSpaceResponse, NvUndefineSpace),
65 (TpmChangeEpsCommand, TpmChangeEpsResponse, ChangeEps),
66 (TpmChangePpsCommand, TpmChangePpsResponse, ChangePps),
67 (TpmClearCommand, TpmClearResponse, Clear),
68 (TpmClearControlCommand, TpmClearControlResponse, ClearControl),
69 (TpmClockSetCommand, TpmClockSetResponse, ClockSet),
70 (TpmHierarchyChangeAuthCommand, TpmHierarchyChangeAuthResponse, HierarchyChangeAuth),
71 (TpmNvDefineSpaceCommand, TpmNvDefineSpaceResponse, NvDefineSpace),
72 (TpmPcrAllocateCommand, TpmPcrAllocateResponse, PcrAllocate),
73 (TpmPcrSetAuthPolicyCommand, TpmPcrSetAuthPolicyResponse, PcrSetAuthPolicy),
74 (TpmPpCommandsCommand, TpmPpCommandsResponse, PpCommands),
75 (TpmSetPrimaryPolicyCommand, TpmSetPrimaryPolicyResponse, SetPrimaryPolicy),
76 (TpmFieldUpgradeStartCommand, TpmFieldUpgradeStartResponse, FieldUpgradeStart),
77 (TpmClockRateAdjustCommand, TpmClockRateAdjustResponse, ClockRateAdjust),
78 (TpmCreatePrimaryCommand, TpmCreatePrimaryResponse, CreatePrimary),
79 (TpmNvGlobalWriteLockCommand, TpmNvGlobalWriteLockResponse, NvGlobalWriteLock),
80 (TpmGetCommandAuditDigestCommand, TpmGetCommandAuditDigestResponse, GetCommandAuditDigest),
81 (TpmNvIncrementCommand, TpmNvIncrementResponse, NvIncrement),
82 (TpmNvSetBitsCommand, TpmNvSetBitsResponse, NvSetBits),
83 (TpmNvExtendCommand, TpmNvExtendResponse, NvExtend),
84 (TpmNvWriteCommand, TpmNvWriteResponse, NvWrite),
85 (TpmNvWriteLockCommand, TpmNvWriteLockResponse, NvWriteLock),
86 (TpmDictionaryAttackLockResetCommand, TpmDictionaryAttackLockResetResponse, DictionaryAttackLockReset),
87 (TpmDictionaryAttackParametersCommand, TpmDictionaryAttackParametersResponse, DictionaryAttackParameters),
88 (TpmNvChangeAuthCommand, TpmNvChangeAuthResponse, NvChangeAuth),
89 (TpmPcrEventCommand, TpmPcrEventResponse, PcrEvent),
90 (TpmPcrResetCommand, TpmPcrResetResponse, PcrReset),
91 (TpmSequenceCompleteCommand, TpmSequenceCompleteResponse, SequenceComplete),
92 (TpmSetAlgorithmSetCommand, TpmSetAlgorithmSetResponse, SetAlgorithmSet),
93 (TpmSetCommandCodeAuditStatusCommand, TpmSetCommandCodeAuditStatusResponse, SetCommandCodeAuditStatus),
94 (TpmFieldUpgradeDataCommand, TpmFieldUpgradeDataResponse, FieldUpgradeData),
95 (TpmIncrementalSelfTestCommand, TpmIncrementalSelfTestResponse, IncrementalSelfTest),
96 (TpmSelfTestCommand, TpmSelfTestResponse, SelfTest),
97 (TpmStartupCommand, TpmStartupResponse, Startup),
98 (TpmShutdownCommand, TpmShutdownResponse, Shutdown),
99 (TpmStirRandomCommand, TpmStirRandomResponse, StirRandom),
100 (TpmActivateCredentialCommand, TpmActivateCredentialResponse, ActivateCredential),
101 (TpmCertifyCommand, TpmCertifyResponse, Certify),
102 (TpmPolicyNvCommand, TpmPolicyNvResponse, PolicyNv),
103 (TpmCertifyCreationCommand, TpmCertifyCreationResponse, CertifyCreation),
104 (TpmDuplicateCommand, TpmDuplicateResponse, Duplicate),
105 (TpmGetTimeCommand, TpmGetTimeResponse, GetTime),
106 (TpmGetSessionAuditDigestCommand, TpmGetSessionAuditDigestResponse, GetSessionAuditDigest),
107 (TpmNvReadCommand, TpmNvReadResponse, NvRead),
108 (TpmNvReadLockCommand, TpmNvReadLockResponse, NvReadLock),
109 (TpmObjectChangeAuthCommand, TpmObjectChangeAuthResponse, ObjectChangeAuth),
110 (TpmPolicySecretCommand, TpmPolicySecretResponse, PolicySecret),
111 (TpmRewrapCommand, TpmRewrapResponse, Rewrap),
112 (TpmCreateCommand, TpmCreateResponse, Create),
113 (TpmEcdhZGenCommand, TpmEcdhZGenResponse, EcdhZGen),
114 (TpmHmacCommand, TpmHmacResponse, Hmac),
115 (TpmImportCommand, TpmImportResponse, Import),
116 (TpmLoadCommand, TpmLoadResponse, Load),
117 (TpmQuoteCommand, TpmQuoteResponse, Quote),
118 (TpmRsaDecryptCommand, TpmRsaDecryptResponse, RsaDecrypt),
119 (TpmHmacStartCommand, TpmHmacStartResponse, HmacStart),
120 (TpmSequenceUpdateCommand, TpmSequenceUpdateResponse, SequenceUpdate),
121 (TpmSignCommand, TpmSignResponse, Sign),
122 (TpmUnsealCommand, TpmUnsealResponse, Unseal),
123 (TpmPolicySignedCommand, TpmPolicySignedResponse, PolicySigned),
124 (TpmContextLoadCommand, TpmContextLoadResponse, ContextLoad),
125 (TpmContextSaveCommand, TpmContextSaveResponse, ContextSave),
126 (TpmEcdhKeyGenCommand, TpmEcdhKeyGenResponse, EcdhKeyGen),
127 (TpmEncryptDecryptCommand, TpmEncryptDecryptResponse, EncryptDecrypt),
128 (TpmFlushContextCommand, TpmFlushContextResponse, FlushContext),
129 (TpmLoadExternalCommand, TpmLoadExternalResponse, LoadExternal),
130 (TpmMakeCredentialCommand, TpmMakeCredentialResponse, MakeCredential),
131 (TpmNvReadPublicCommand, TpmNvReadPublicResponse, NvReadPublic),
132 (TpmPolicyAuthorizeCommand, TpmPolicyAuthorizeResponse, PolicyAuthorize),
133 (TpmPolicyAuthValueCommand, TpmPolicyAuthValueResponse, PolicyAuthValue),
134 (TpmPolicyCommandCodeCommand, TpmPolicyCommandCodeResponse, PolicyCommandCode),
135 (TpmPolicyCounterTimerCommand, TpmPolicyCounterTimerResponse, PolicyCounterTimer),
136 (TpmPolicyCpHashCommand, TpmPolicyCpHashResponse, PolicyCpHash),
137 (TpmPolicyLocalityCommand, TpmPolicyLocalityResponse, PolicyLocality),
138 (TpmPolicyNameHashCommand, TpmPolicyNameHashResponse, PolicyNameHash),
139 (TpmPolicyOrCommand, TpmPolicyOrResponse, PolicyOr),
140 (TpmPolicyTicketCommand, TpmPolicyTicketResponse, PolicyTicket),
141 (TpmReadPublicCommand, TpmReadPublicResponse, ReadPublic),
142 (TpmRsaEncryptCommand, TpmRsaEncryptResponse, RsaEncrypt),
143 (TpmStartAuthSessionCommand, TpmStartAuthSessionResponse, StartAuthSession),
144 (TpmVerifySignatureCommand, TpmVerifySignatureResponse, VerifySignature),
145 (TpmEccParametersCommand, TpmEccParametersResponse, EccParameters),
146 (TpmFirmwareReadCommand, TpmFirmwareReadResponse, FirmwareRead),
147 (TpmGetCapabilityCommand, TpmGetCapabilityResponse, GetCapability),
148 (TpmGetRandomCommand, TpmGetRandomResponse, GetRandom),
149 (TpmGetTestResultCommand, TpmGetTestResultResponse, GetTestResult),
150 (TpmHashCommand, TpmHashResponse, Hash),
151 (TpmPcrReadCommand, TpmPcrReadResponse, PcrRead),
152 (TpmPolicyPcrCommand, TpmPolicyPcrResponse, PolicyPcr),
153 (TpmPolicyRestartCommand, TpmPolicyRestartResponse, PolicyRestart),
154 (TpmReadClockCommand, TpmReadClockResponse, ReadClock),
155 (TpmPcrExtendCommand, TpmPcrExtendResponse, PcrExtend),
156 (TpmPcrSetAuthValueCommand, TpmPcrSetAuthValueResponse, PcrSetAuthValue),
157 (TpmNvCertifyCommand, TpmNvCertifyResponse, NvCertify),
158 (TpmEventSequenceCompleteCommand, TpmEventSequenceCompleteResponse, EventSequenceComplete),
159 (TpmHashSequenceStartCommand, TpmHashSequenceStartResponse, HashSequenceStart),
160 (TpmPolicyPhysicalPresenceCommand, TpmPolicyPhysicalPresenceResponse, PolicyPhysicalPresence),
161 (TpmPolicyDuplicationSelectCommand, TpmPolicyDuplicationSelectResponse, PolicyDuplicationSelect),
162 (TpmPolicyGetDigestCommand, TpmPolicyGetDigestResponse, PolicyGetDigest),
163 (TpmTestParmsCommand, TpmTestParmsResponse, TestParms),
164 (TpmCommitCommand, TpmCommitResponse, Commit),
165 (TpmPolicyPasswordCommand, TpmPolicyPasswordResponse, PolicyPassword),
166 (TpmZGen2PhaseCommand, TpmZGen2PhaseResponse, ZGen2Phase),
167 (TpmEcEphemeralCommand, TpmEcEphemeralResponse, EcEphemeral),
168 (TpmPolicyNvWrittenCommand, TpmPolicyNvWrittenResponse, PolicyNvWritten),
169 (TpmPolicyTemplateCommand, TpmPolicyTemplateResponse, PolicyTemplate),
170 (TpmCreateLoadedCommand, TpmCreateLoadedResponse, CreateLoaded),
171 (TpmPolicyAuthorizeNvCommand, TpmPolicyAuthorizeNvResponse, PolicyAuthorizeNv),
172 (TpmEncryptDecrypt2Command, TpmEncryptDecrypt2Response, EncryptDecrypt2),
173 (TpmAcGetCapabilityCommand, TpmAcGetCapabilityResponse, AcGetCapability),
174 (TpmAcSendCommand, TpmAcSendResponse, AcSend),
175 (TpmPolicyAcSendSelectCommand, TpmPolicyAcSendSelectResponse, PolicyAcSendSelect),
176 (TpmActSetTimeoutCommand, TpmActSetTimeoutResponse, ActSetTimeout),
177 (TpmEccEncryptCommand, TpmEccEncryptResponse, EccEncrypt),
178 (TpmEccDecryptCommand, TpmEccDecryptResponse, EccDecrypt),
179 (TpmPolicyCapabilityCommand, TpmPolicyCapabilityResponse, PolicyCapability),
180 (TpmPolicyParametersCommand, TpmPolicyParametersResponse, PolicyParameters),
181 (TpmNvDefineSpace2Command, TpmNvDefineSpace2Response, NvDefineSpace2),
182 (TpmNvReadPublic2Command, TpmNvReadPublic2Response, NvReadPublic2),
183 (TpmSetCapabilityCommand, TpmSetCapabilityResponse, SetCapability),
184 (TpmReadOnlyControlCommand, TpmReadOnlyControlResponse, ReadOnlyControl),
185 (TpmPolicyTransportSpdmCommand, TpmPolicyTransportSpdmResponse, PolicyTransportSpdm),
186 (TpmVendorTcgTestCommand, TpmVendorTcgTestResponse, VendorTcgTest),
187}