1 // This file was extracted from the TCG Published 2 // Trusted Platform Module Library 3 // Part 3: Commands 4 // Family "2.0" 5 // Level 00 Revision 01.16 6 // October 30, 2014 7 8 #include "InternalRoutines.h" 9 #include "SetCommandCodeAuditStatus_fp.h" 10 TPM_RC TPM2_SetCommandCodeAuditStatus(SetCommandCodeAuditStatus_In * in)11TPM2_SetCommandCodeAuditStatus( 12 SetCommandCodeAuditStatus_In *in // IN: input parameter list 13 ) 14 { 15 TPM_RC result; 16 UINT32 i; 17 BOOL changed = FALSE; 18 19 // The command needs NV update. Check if NV is available. 20 // A TPM_RC_NV_UNAVAILABLE or TPM_RC_NV_RATE error may be returned at 21 // this point 22 result = NvIsAvailable(); 23 if(result != TPM_RC_SUCCESS) 24 return result; 25 26 // Internal Data Update 27 28 // Update hash algorithm 29 if( in->auditAlg != TPM_ALG_NULL 30 && in->auditAlg != gp.auditHashAlg) 31 { 32 // Can't change the algorithm and command list at the same time 33 if(in->setList.count != 0 || in->clearList.count != 0) 34 return TPM_RC_VALUE + RC_SetCommandCodeAuditStatus_auditAlg; 35 36 // Change the hash algorithm for audit 37 gp.auditHashAlg = in->auditAlg; 38 39 // Set the digest size to a unique value that indicates that the digest 40 // algorithm has been changed. The size will be cleared to zero in the 41 // command audit processing on exit. 42 gr.commandAuditDigest.t.size = 1; 43 44 // Save the change of command audit data (this sets g_updateNV so that NV 45 // will be updated on exit.) 46 NvWriteReserved(NV_AUDIT_HASH_ALG, &gp.auditHashAlg); 47 48 } else { 49 50 // Process set list 51 for(i = 0; i < in->setList.count; i++) 52 53 // If change is made in CommandAuditSet, set changed flag 54 if(CommandAuditSet(in->setList.commandCodes[i])) 55 changed = TRUE; 56 57 // Process clear list 58 for(i = 0; i < in->clearList.count; i++) 59 // If change is made in CommandAuditClear, set changed flag 60 if(CommandAuditClear(in->clearList.commandCodes[i])) 61 changed = TRUE; 62 63 // if change was made to command list, update NV 64 if(changed) 65 // this sets g_updateNV so that NV will be updated on exit. 66 NvWriteReserved(NV_AUDIT_COMMANDS, &gp.auditComands); 67 } 68 69 return TPM_RC_SUCCESS; 70 } 71