• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without
7  * restriction, including without limitation the rights to use, copy,
8  * modify, merge, publish, distribute, sublicense, and/or sell copies
9  * of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
25 #ifndef TRUSTY_INTERFACE_STORAGE_H_
26 #define TRUSTY_INTERFACE_STORAGE_H_
27 
28 /*
29  * The contents of this file are copied from
30  * trusty/lib/interface/storage/include/interface/storage/storage.h.
31  * It is required to stay in sync for struct formats and enum values.
32  */
33 
34 #include <trusty/sysdeps.h>
35 
36 /*
37  * @STORAGE_DISK_PROXY_PORT: Port used by non-secure proxy server
38  */
39 #define STORAGE_DISK_PROXY_PORT "com.android.trusty.storage.proxy"
40 
41 enum storage_cmd {
42     STORAGE_REQ_SHIFT = 1,
43     STORAGE_RESP_BIT = 1,
44 
45     STORAGE_RESP_MSG_ERR = STORAGE_RESP_BIT,
46 
47     STORAGE_FILE_DELETE = 1 << STORAGE_REQ_SHIFT,
48     STORAGE_FILE_OPEN = 2 << STORAGE_REQ_SHIFT,
49     STORAGE_FILE_CLOSE = 3 << STORAGE_REQ_SHIFT,
50     STORAGE_FILE_READ = 4 << STORAGE_REQ_SHIFT,
51     STORAGE_FILE_WRITE = 5 << STORAGE_REQ_SHIFT,
52     STORAGE_FILE_GET_SIZE = 6 << STORAGE_REQ_SHIFT,
53     STORAGE_FILE_SET_SIZE = 7 << STORAGE_REQ_SHIFT,
54 
55     STORAGE_RPMB_SEND = 8 << STORAGE_REQ_SHIFT,
56 
57     /* transaction support */
58     STORAGE_END_TRANSACTION = 9 << STORAGE_REQ_SHIFT,
59 };
60 
61 /**
62  * enum storage_err - error codes for storage protocol
63  * @STORAGE_NO_ERROR:           all OK
64  * @STORAGE_ERR_GENERIC:        unknown error. Can occur when there's an
65  *                              internal server error, e.g. the server runs out
66  *                              of memory or is in a bad state.
67  * @STORAGE_ERR_NOT_VALID:      input not valid. May occur if the arguments
68  *                              passed into the command are not valid, for
69  *                              example if the file handle passed in is not a
70  *                              valid one.
71  * @STORAGE_ERR_UNIMPLEMENTED:  the command passed in is not recognized
72  * @STORAGE_ERR_ACCESS:         the file is not accessible in the requested mode
73  * @STORAGE_ERR_NOT_FOUND:      the file was not found
74  * @STORAGE_ERR_EXIST           the file exists when it shouldn't as in with
75  *                              OPEN_CREATE | OPEN_EXCLUSIVE.
76  * @STORAGE_ERR_TRANSACT        returned by various operations to indicate that
77  *                              current transaction is in error state. Such
78  *                              state could be only cleared by sending
79  *                              STORAGE_END_TRANSACTION message.
80  */
81 enum storage_err {
82     STORAGE_NO_ERROR = 0,
83     STORAGE_ERR_GENERIC = 1,
84     STORAGE_ERR_NOT_VALID = 2,
85     STORAGE_ERR_UNIMPLEMENTED = 3,
86     STORAGE_ERR_ACCESS = 4,
87     STORAGE_ERR_NOT_FOUND = 5,
88     STORAGE_ERR_EXIST = 6,
89     STORAGE_ERR_TRANSACT = 7,
90 };
91 
92 /**
93  * enum storage_msg_flag - protocol-level flags in struct storage_msg
94  * @STORAGE_MSG_FLAG_BATCH:             if set, command belongs to a batch
95  *                                      transaction. No response will be sent by
96  *                                      the server until it receives a command
97  *                                      with this flag unset, at which point a
98  *                                      cummulative result for all messages sent
99  *                                      with STORAGE_MSG_FLAG_BATCH will be
100  *                                      sent. This is only supported by the
101  *                                      non-secure disk proxy server.
102  * @STORAGE_MSG_FLAG_PRE_COMMIT:        if set, indicates that server need to
103  *                                      commit pending changes before processing
104  *                                      this message.
105  * @STORAGE_MSG_FLAG_POST_COMMIT:       if set, indicates that server need to
106  *                                      commit pending changes after processing
107  *                                      this message.
108  * @STORAGE_MSG_FLAG_TRANSACT_COMPLETE: if set, indicates that server need to
109  *                                      commit current transaction after
110  *                                      processing this message. It is an alias
111  *                                      for STORAGE_MSG_FLAG_POST_COMMIT.
112  */
113 enum storage_msg_flag {
114     STORAGE_MSG_FLAG_BATCH = 0x1,
115     STORAGE_MSG_FLAG_PRE_COMMIT = 0x2,
116     STORAGE_MSG_FLAG_POST_COMMIT = 0x4,
117     STORAGE_MSG_FLAG_TRANSACT_COMPLETE = STORAGE_MSG_FLAG_POST_COMMIT,
118 };
119 
120 /*
121  * The following declarations are the message-specific contents of
122  * the 'payload' element inside struct storage_msg.
123  */
124 
125 /**
126  * struct storage_rpmb_send_req - request format for STORAGE_RPMB_SEND
127  * @reliable_write_size:        size in bytes of reliable write region
128  * @write_size:                 size in bytes of write region
129  * @read_size:                  number of bytes to read for a read request
130  * @__reserved:                 unused, must be set to 0
131  * @payload:                    start of reliable write region, followed by
132  *                              write region.
133  *
134  * Only used in proxy<->server interface.
135  */
136 struct storage_rpmb_send_req {
137     uint32_t reliable_write_size;
138     uint32_t write_size;
139     uint32_t read_size;
140     uint32_t __reserved;
141     uint8_t payload[0];
142 };
143 
144 /**
145  * struct storage_rpmb_send_resp: response type for STORAGE_RPMB_SEND
146  * @data: the data frames frames retrieved from the MMC.
147  */
148 struct storage_rpmb_send_resp {
149     uint8_t data[0];
150 };
151 
152 /**
153  * struct storage_msg - generic req/resp format for all storage commands
154  * @cmd:        one of enum storage_cmd
155  * @op_id:      client chosen operation identifier for an instance
156  *              of a command or atomic grouping of commands (transaction).
157  * @flags:      one or many of enum storage_msg_flag or'ed together.
158  * @size:       total size of the message including this header
159  * @result:     one of enum storage_err
160  * @__reserved: unused, must be set to 0.
161  * @payload:    beginning of command specific message format
162  */
163 struct storage_msg {
164     uint32_t cmd;
165     uint32_t op_id;
166     uint32_t flags;
167     uint32_t size;
168     int32_t result;
169     uint32_t __reserved;
170     uint8_t payload[0];
171 };
172 
173 #endif /* TRUSTY_INTERFACE_STORAGE_H_ */
174