1 /* Microsoft Reference Implementation for TPM 2.0
2 *
3 * The copyright in this software is being made available under the BSD License,
4 * included below. This software may be subject to other third party and
5 * contributor rights, including patent rights, and no such rights are granted
6 * under this license.
7 *
8 * Copyright (c) Microsoft Corporation
9 *
10 * All rights reserved.
11 *
12 * BSD License
13 *
14 * Redistribution and use in source and binary forms, with or without modification,
15 * are permitted provided that the following conditions are met:
16 *
17 * Redistributions of source code must retain the above copyright notice, this list
18 * of conditions and the following disclaimer.
19 *
20 * Redistributions in binary form must reproduce the above copyright notice, this
21 * list of conditions and the following disclaimer in the documentation and/or
22 * other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS""
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
28 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35 #include "Tpm.h"
36 #include "FlushContext_fp.h"
37
38 #if CC_FlushContext // Conditional expansion of this file
39
40 /*(See part 3 specification)
41 // Flush a specific object or session
42 */
43 // Return Type: TPM_RC
44 // TPM_RC_HANDLE 'flushHandle' does not reference a loaded object or session
45 TPM_RC
TPM2_FlushContext(FlushContext_In * in)46 TPM2_FlushContext(
47 FlushContext_In *in // IN: input parameter list
48 )
49 {
50 // Internal Data Update
51
52 // Call object or session specific routine to flush
53 switch(HandleGetType(in->flushHandle))
54 {
55 case TPM_HT_TRANSIENT:
56 if(!IsObjectPresent(in->flushHandle))
57 return TPM_RCS_HANDLE + RC_FlushContext_flushHandle;
58 // Flush object
59 FlushObject(in->flushHandle);
60 break;
61 case TPM_HT_HMAC_SESSION:
62 case TPM_HT_POLICY_SESSION:
63 if(!SessionIsLoaded(in->flushHandle)
64 && !SessionIsSaved(in->flushHandle)
65 )
66 return TPM_RCS_HANDLE + RC_FlushContext_flushHandle;
67
68 // If the session to be flushed is the exclusive audit session, then
69 // indicate that there is no exclusive audit session any longer.
70 if(in->flushHandle == g_exclusiveAuditSession)
71 g_exclusiveAuditSession = TPM_RH_UNASSIGNED;
72
73 // Flush session
74 SessionFlush(in->flushHandle);
75 break;
76 default:
77 // This command only takes object or session handle. Other handles
78 // should be filtered out at handle unmarshal
79 FAIL(FATAL_ERROR_INTERNAL);
80 break;
81 }
82
83 return TPM_RC_SUCCESS;
84 }
85
86 #endif // CC_FlushContext