• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2017 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 package com.android.verifiedboot.storage;
18 
19 import com.android.verifiedboot.globalstate.owner.OwnerInterface;
20 import com.android.verifiedboot.storage.BackupInterface;
21 
22 // The base interface for all locks.  As the іnterface clobbers a number
23 // of common methods it might make more sense as a base class, but this
24 // seems fine enough for now.
25 public interface LockInterface extends BackupInterface {
26     // 0 means unlocked and non-zero means locks.
27     public final static byte LOCK_UNLOCKED = (byte) 0;
28 
29     /**
30      * @return 0, as short, if initialized, or a non-zero error
31      *         based on the error state.
32      */
initialized()33     short initialized();
34 
35     /**
36      * Return the bytes needed by this lock.
37      *
38      * Must be callable prior to initialize.
39      *
40      * @return size, as short, of storage required for {@link #setStorage}.
41      */
getStorageNeeded()42     short getStorageNeeded();
43 
44     /**
45      * Sets the backing store to use for state and global state dependency.
46      *
47      * @param globalStateOwner OwnerInterface implementation for policy checking.
48      * @param extStorage  external array to use for storage
49      * @param extStorageOffset where to begin storing data
50      *
51      * This should be called before use.
52      */
initialize(OwnerInterface globalStateOwner, byte[] extStorage, short extStorageOffset)53     void initialize(OwnerInterface globalStateOwner, byte[] extStorage, short extStorageOffset);
54 
55     /**
56      * Emits the lock byte into the array.
57      *
58      * @param lockOut lock value as a byte. 0x0 is unlocked, !0x0 is locked.
59      * @param lockOffset offset to write the lock byte.
60      * @return 0x0 on success or an error code otherwise.
61      */
get(byte[] lockOut, short lockOffset)62     short get(byte[] lockOut, short lockOffset);
63 
64     /**
65      * Returns the offset into the external storage for the lock byte.
66      *
67      * @return The offset into the external storage for metadata or 0xffff
68      *         on error.
69      *
70      */
lockOffset()71     short lockOffset();
72 
73     /**
74      * Returns the offset into the external storage for the metadata.
75      *
76      * @return The offset into the external storage for metadata or 0xffff
77      *         on error.
78      *
79      */
metadataOffset()80     short metadataOffset();
81 
82     /**
83      * Returns length of metadata.
84      *
85      * @return length of metadata or 0xffff on error.
86      */
metadataLength()87     short metadataLength();
88 
89 
90     /**
91      * Returns true if the lock state can be set.
92      *
93      * @param val New lock byte. Non-zero values are considered "locked".
94      * @return 0x0 if the lock state was set to |val| and an error code otherwise.
95      */
set(byte val)96     short set(byte val);
97 
98     /**
99      * Returns true if the lock is changed with associated metadata.
100      *
101      * @param lockValue New lock byte value
102      * @param lockMeta array to copy metadata from
103      * @param lockMetaOffset offset to start copying from
104      * @param lockMetaLength bytes to copy
105      * @return 0x0 is successful and an error code if not.
106      */
setWithMetadata(byte lockValue, byte[] lockMeta, short lockMetaOffset, short lockMetaLength)107     short setWithMetadata(byte lockValue, byte[] lockMeta, short lockMetaOffset, short lockMetaLength);
108 }
109