1 /*
2  * Copyright (c) 2016-2017, Linaro Limited
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef __OPTEE_MSG_SUPPLICANT_H
29 #define __OPTEE_MSG_SUPPLICANT_H
30 
31 /*
32  * Load a TA into memory
33  */
34 #define OPTEE_MSG_RPC_CMD_LOAD_TA	0
35 
36 /*
37  * Replay Protected Memory Block access
38  */
39 #define OPTEE_MSG_RPC_CMD_RPMB		1
40 
41 /*
42  * File system access
43  */
44 #define OPTEE_MSG_RPC_CMD_FS		2
45 
46 /*
47  * Define protocol for messages with .cmd == OPTEE_MSG_RPC_CMD_FS and first
48  * parameter has the attribute OPTEE_MSG_ATTR_TYPE_VALUE_INPUT.
49  */
50 
51 /*
52  * Open a file
53  *
54  * [in]     param[0].u.value.a	OPTEE_MRF_OPEN
55  * [in]     param[1].u.tmem	a string holding the file name
56  * [out]    param[2].u.value.a	file descriptor of open file
57  */
58 #define OPTEE_MRF_OPEN			0
59 
60 /*
61  * Create a file
62  *
63  * [in]     param[0].u.value.a	OPTEE_MRF_CREATE
64  * [in]     param[1].u.tmem	a string holding the file name
65  * [out]    param[2].u.value.a	file descriptor of open file
66  */
67 #define OPTEE_MRF_CREATE		1
68 
69 /*
70  * Close a file
71  *
72  * [in]     param[0].u.value.a	OPTEE_MRF_CLOSE
73  * [in]     param[0].u.value.b	file descriptor of open file.
74  */
75 #define OPTEE_MRF_CLOSE			2
76 
77 /*
78  * Read from a file
79  *
80  * [in]     param[0].u.value.a	OPTEE_MRF_READ
81  * [in]     param[0].u.value.b	file descriptor of open file
82  * [in]     param[0].u.value.c	offset into file
83  * [out]    param[1].u.tmem	buffer to hold returned data
84  */
85 #define OPTEE_MRF_READ			3
86 
87 /*
88  * Write to a file
89  *
90  * [in]     param[0].u.value.a	OPTEE_MRF_WRITE
91  * [in]     param[0].u.value.b	file descriptor of open file
92  * [in]     param[0].u.value.c	offset into file
93  * [in]     param[1].u.tmem	buffer holding data to be written
94  */
95 #define OPTEE_MRF_WRITE			4
96 
97 /*
98  * Truncate a file
99  *
100  * [in]     param[0].u.value.a	OPTEE_MRF_TRUNCATE
101  * [in]     param[0].u.value.b	file descriptor of open file
102  * [in]     param[0].u.value.c	length of file.
103  */
104 #define OPTEE_MRF_TRUNCATE		5
105 
106 /*
107  * Remove a file
108  *
109  * [in]  param[0].u.value.a	OPTEE_MRF_REMOVE
110  * [in]  param[1].u.tmem	a string holding the file name
111  */
112 #define OPTEE_MRF_REMOVE		6
113 
114 /*
115  * Rename a file
116  *
117  * [in]  param[0].u.value.a	OPTEE_MRF_RENAME
118  * [in]  param[0].u.value.b	true if existing target should be removed
119  * [in]  param[1].u.tmem	a string holding the old file name
120  * [in]  param[2].u.tmem	a string holding the new file name
121  */
122 #define OPTEE_MRF_RENAME		7
123 
124 /*
125  * Opens a directory for file listing
126  *
127  * [in]  param[0].u.value.a	OPTEE_MRF_OPENDIR
128  * [in]  param[1].u.tmem	a string holding the name of the directory
129  * [out] param[2].u.value.a	handle to open directory
130  */
131 #define OPTEE_MRF_OPENDIR		8
132 
133 /*
134  * Closes a directory handle
135  *
136  * [in]  param[0].u.value.a	OPTEE_MRF_CLOSEDIR
137  * [in]  param[0].u.value.b	handle to open directory
138  */
139 #define OPTEE_MRF_CLOSEDIR		9
140 
141 /*
142  * Read next file name of directory
143  *
144  *
145  * [in]  param[0].u.value.a	OPTEE_MRF_READDIR
146  * [in]  param[0].u.value.b	handle to open directory
147  * [out] param[1].u.tmem	a string holding the file name
148  */
149 #define OPTEE_MRF_READDIR		10
150 
151 /*
152  * End of definitions for messages with .cmd == OPTEE_MSG_RPC_CMD_FS
153  */
154 
155 /*
156  * Command Ids 3, 4 and 5 of OPTEE_MSG_RPC_CMD_xxx macros are reserved for use
157  * by the kernel driver.
158  */
159 
160 /*
161  * Shared memory allocation
162  */
163 #define OPTEE_MSG_RPC_CMD_SHM_ALLOC	6
164 #define OPTEE_MSG_RPC_CMD_SHM_FREE	7
165 
166 /*
167  * Was OPTEE_MSG_RPC_CMD_SQL_FS, which isn't supported any longer
168  */
169 #define OPTEE_MSG_RPC_CMD_SQL_FS_RESERVED	8
170 
171 /*
172  * GPROF support management commands
173  */
174 #define OPTEE_MSG_RPC_CMD_GPROF		9
175 
176 /*
177  * Socket commands
178  */
179 #define OPTEE_MSG_RPC_CMD_SOCKET	10
180 
181 /*
182  * Function tracing support management commands
183  */
184 #define OPTEE_MSG_RPC_CMD_FTRACE	11
185 
186 /*
187  * Plugin commands
188  */
189 #define OPTEE_MSG_RPC_CMD_PLUGIN	12
190 
191 /*
192  * Define protocol for messages with .cmd == OPTEE_MSG_RPC_CMD_SOCKET
193  */
194 
195 #define OPTEE_MRC_SOCKET_TIMEOUT_NONBLOCKING	0
196 #define OPTEE_MRC_SOCKET_TIMEOUT_BLOCKING	0xffffffff
197 
198 /*
199  * Open socket
200  *
201  * [in]     param[0].u.value.a	OPTEE_MRC_SOCKET_OPEN
202  * [in]     param[0].u.value.b	TA instance id
203  * [in]     param[1].u.value.a	server port number
204  * [in]     param[1].u.value.b	protocol, TEE_ISOCKET_PROTOCOLID_*
205  * [in]     param[1].u.value.c	ip version TEE_IP_VERSION_* from tee_ipsocket.h
206  * [in]     param[2].u.tmem	server address
207  * [out]    param[3].u.value.a	socket handle (32-bit)
208  */
209 #define OPTEE_MRC_SOCKET_OPEN	0
210 
211 /*
212  * Close socket
213  *
214  * [in]     param[0].u.value.a	OPTEE_MRC_SOCKET_CLOSE
215  * [in]     param[0].u.value.b	TA instance id
216  * [in]     param[0].u.value.c	socket handle
217  */
218 #define OPTEE_MRC_SOCKET_CLOSE	1
219 
220 /*
221  * Close all sockets
222  *
223  * [in]     param[0].u.value.a	OPTEE_MRC_SOCKET_CLOSE_ALL
224  * [in]     param[0].u.value.b	TA instance id
225  */
226 #define OPTEE_MRC_SOCKET_CLOSE_ALL 2
227 
228 /*
229  * Send data on socket
230  *
231  * [in]     param[0].u.value.a	OPTEE_MRC_SOCKET_SEND
232  * [in]     param[0].u.value.b	TA instance id
233  * [in]     param[0].u.value.c	socket handle
234  * [in]     param[1].u.tmem	buffer to transmit
235  * [in]     param[2].u.value.a	timeout ms or OPTEE_MRC_SOCKET_TIMEOUT_*
236  * [out]    param[2].u.value.b	number of transmitted bytes
237  */
238 #define OPTEE_MRC_SOCKET_SEND	3
239 
240 /*
241  * Receive data on socket
242  *
243  * [in]     param[0].u.value.a	OPTEE_MRC_SOCKET_RECV
244  * [in]     param[0].u.value.b	TA instance id
245  * [in]     param[0].u.value.c	socket handle
246  * [out]    param[1].u.tmem	buffer to receive
247  * [in]     param[2].u.value.a	timeout ms or OPTEE_MRC_SOCKET_TIMEOUT_*
248  */
249 #define OPTEE_MRC_SOCKET_RECV	4
250 
251 /*
252  * Perform IOCTL on socket
253  *
254  * [in]     param[0].u.value.a	OPTEE_MRC_SOCKET_IOCTL
255  * [in]     param[0].u.value.b	TA instance id
256  * [in]     param[0].u.value.c	socket handle
257  * [in/out] param[1].u.tmem	buffer
258  * [in]     param[2].u.value.a	ioctl command
259  */
260 #define OPTEE_MRC_SOCKET_IOCTL	5
261 
262 /*
263  * End of definitions for messages with .cmd == OPTEE_MSG_RPC_CMD_SOCKET
264  */
265 
266 /*
267  * Define protocol for messages with .cmd == OPTEE_MSG_RPC_CMD_PLUGIN
268  */
269 
270 /*
271  * Invoke a tee-supplicant plugin.
272  *
273  * [in]     param[0].u.value.a	OPTEE_INVOKE_PLUGIN
274  * [in]     param[0].u.value.b	uuid.d1
275  * [in]     param[0].u.value.c	uuid.d2
276  * [in]     param[1].u.value.a	uuid.d3
277  * [in]     param[1].u.value.b	uuid.d4
278  * [in]     param[1].u.value.c	cmd for plugin
279  * [in]     param[2].u.value.a	sub_cmd for plugin
280  * [out]    param[2].u.value.b  length of the outbuf (param[3]),
281  *                              if out is needed.
282  * [in/out] param[3].u.tmem	buffer holding data for plugin
283  *
284  * UUID serialized into octets:
285  * b0  b1  b2  b3   b4  b5  b6  b7   b8  b9  b10  b11   b12  b13  b14  b15
286  *       d1       |       d2       |        d3        |         d4
287  *
288  * The endianness of words d1, d2, d3 and d4 from SWd is little-endian.
289  * d1 word contains [b3 b2 b1 b0]
290  * d2 word contains [b7 b6 b5 b4]
291  * d3 word contains [b11 b10 b9 b8]
292  * d4 word contains [b15 b14 b13 b12]
293  */
294 #define OPTEE_INVOKE_PLUGIN	0
295 
296 /*
297  * End of definitions for messages with .cmd == OPTEE_MSG_RPC_CMD_PLUGIN
298  */
299 
300 #endif /*__OPTEE_MSG_SUPPLICANT_H*/
301