1 //
2 // Copyright (C) 2015 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef TPM_MANAGER_SERVER_TPM_NVRAM_H_
18 #define TPM_MANAGER_SERVER_TPM_NVRAM_H_
19 
20 #include <string>
21 #include <vector>
22 
23 #include "tpm_manager/common/tpm_manager.pb.h"
24 
25 namespace tpm_manager {
26 
27 // TpmNvram is an interface for working with TPM NVRAM.
28 class TpmNvram {
29  public:
30   TpmNvram() = default;
31   virtual ~TpmNvram() = default;
32 
33   // Creates an NVRAM space in the TPM. Returns true on success.
34   virtual NvramResult DefineSpace(
35       uint32_t index,
36       size_t size,
37       const std::vector<NvramSpaceAttribute>& attributes,
38       const std::string& authorization_value,
39       NvramSpacePolicy policy) = 0;
40 
41   // Destroys an NVRAM space in the TPM. Returns true on success.
42   virtual NvramResult DestroySpace(uint32_t index) = 0;
43 
44   // Writes |data| to the NVRAM space at |index|. The size of |data| must be
45   // equal or less than the size of the NVRAM space. Returns true on success.
46   virtual NvramResult WriteSpace(uint32_t index,
47                                  const std::string& data,
48                                  const std::string& authorization_value) = 0;
49 
50   // Reads all the |data| in the NVRAM space at |index|. Returns true on
51   // success.
52   virtual NvramResult ReadSpace(uint32_t index,
53                                 std::string* data,
54                                 const std::string& authorization_value) = 0;
55 
56   // Locks the NVRAM space at |index|. Returns true on success.
57   virtual NvramResult LockSpace(uint32_t index,
58                                 bool lock_read,
59                                 bool lock_write,
60                                 const std::string& authorization_value) = 0;
61 
62   // Lists all existing NVRAM spaces. Returns true on success.
63   virtual NvramResult ListSpaces(std::vector<uint32_t>* index_list) = 0;
64 
65   // Provides basic information about a given space. All pointer are optional
66   // and may be NULL. Returns true on success.
67   virtual NvramResult GetSpaceInfo(
68       uint32_t index,
69       size_t* size,
70       bool* is_read_locked,
71       bool* is_write_locked,
72       std::vector<NvramSpaceAttribute>* attributes,
73       NvramSpacePolicy* policy) = 0;
74 };
75 
76 }  // namespace tpm_manager
77 
78 #endif  // TPM_MANAGER_SERVER_TPM_NVRAM_H_
79