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_STATUS_IMPL_H_
18 #define TPM_MANAGER_SERVER_TPM_STATUS_IMPL_H_
19 
20 #include "tpm_manager/server/tpm_status.h"
21 
22 #include <memory>
23 #include <string>
24 
25 #include <base/macros.h>
26 #include <trousers/tss.h>
27 #include <trousers/trousers.h>  // NOLINT(build/include_alpha)
28 
29 #include <tpm_manager/server/tpm_connection.h>
30 
31 namespace tpm_manager {
32 
33 class TpmStatusImpl : public TpmStatus {
34  public:
35   TpmStatusImpl() = default;
36   ~TpmStatusImpl() override = default;
37 
38   // TpmState methods.
39   bool IsTpmEnabled() override;
40   bool IsTpmOwned() override;
41   bool GetDictionaryAttackInfo(int* counter,
42                                int* threshold,
43                                bool* lockout,
44                                int* seconds_remaining) override;
45 
46  private:
47   // This method refreshes the |is_owned_| and |is_enabled_| status of the
48   // Tpm. It can be called multiple times.
49   void RefreshOwnedEnabledInfo();
50   // This method wraps calls to Tspi_TPM_GetCapability. |data| is set to
51   // the raw capability data. If the optional out argument |tpm_result| is
52   // provided, it is set to the result of the |Tspi_TPM_GetCapability| call.
53   bool GetCapability(uint32_t capability,
54                      uint32_t sub_capability,
55                      std::string* data,
56                      TSS_RESULT* tpm_result);
57 
58   TpmConnection tpm_connection_;
59   bool is_enabled_{false};
60   bool is_owned_{false};
61   bool is_enable_initialized_{false};
62 
63   DISALLOW_COPY_AND_ASSIGN(TpmStatusImpl);
64 };
65 
66 }  // namespace tpm_manager
67 
68 #endif  // TPM_MANAGER_SERVER_TPM_STATUS_IMPL_H_
69