1 /*
2  * Copyright 2016 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 AVB_MANAGER_H_
18 #define AVB_MANAGER_H_
19 
20 #include <stdio.h>
21 
22 #include <UniquePtr.h>
23 
24 #include "avb_messages.h"
25 #include "secure_storage_interface.h"
26 
27 #define TLOG_TAG "avb"
28 #include <trusty_log.h>
29 
30 extern const unsigned int kRollbackSlotMax;
31 
32 namespace avb {
33 
34 // Implements request callbacks
35 class AvbManager {
36 public:
37     // AvbManager takes ownership of |storage|, so |storage| will be deleted
38     // when AvbManager is destructed.
AvbManager(SecureStorageInterface * storage)39     AvbManager(SecureStorageInterface* storage) : storage_(storage) {}
40 
41     void ReadRollbackIndex(const RollbackIndexRequest& request,
42                            RollbackIndexResponse* response);
43     void WriteRollbackIndex(const RollbackIndexRequest& request,
44                             RollbackIndexResponse* response);
45     // Client is responsible for managing versioning, by sending an initial
46     // "GetVersion" request. Note this means that the "GetVersion" request
47     // cannot be versioned.
48     void GetVersion(const GetVersionRequest& request,
49                     GetVersionResponse* response);
50     // The Avb service provides storage for Android Things permanent attributes
51     // structure, but these must still be verified against write-once fuses.
52     void ReadPermanentAttributes(const ReadPermanentAttributesRequest& request,
53                                  ReadPermanentAttributesResponse* response);
54     void WritePermanentAttributes(
55             const WritePermanentAttributesRequest& request,
56             WritePermanentAttributesResponse* response);
57     void ReadLockState(const ReadLockStateRequest& request,
58                        ReadLockStateResponse* response);
59     void WriteLockState(const WriteLockStateRequest& request,
60                         WriteLockStateResponse* response);
61 
62 private:
63     int DeleteRollbackIndexFiles();
64 
65     UniquePtr<SecureStorageInterface> storage_;
66 };
67 
68 }  // namespace avb
69 
70 #endif  // AVB_MANAGER_H_
71