NVIDIA DRIVE OS Linux API Reference

5.1.3.0 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ote_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2018, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
40 #ifndef __OTE_COMMON_H
41 #define __OTE_COMMON_H
42 
43 #include <stdarg.h>
44 #include <stdbool.h>
45 #include <stdint.h>
46 #include <compiler.h>
47 #include <common/ote_error.h>
48 
49 /* Prefix for the UUID based port names, which are now fixed length
50  * strings constructed from this prefix and the formatted TA UUID.
51  *
52  * Port name fixed size is strlen(SERVICE_PORT_NAME_PREFIX)+UUID_STR_SIZE_BYTES).
53  * This size includes the terminating NULL.
54  *
55  * Sample port name (for the trusted_app): com.nvidia.tos.403A0B40-B50D-40a4-A87C-62D253FDA594.
56  *
57  */
58 #define SERVICE_PORT_NAME_PREFIX "com.nvidia.tos"
59 
60 /* Length includes space for the uuid, dashes and NULL termination */
61 #define UUID_STR_SIZE_BYTES ((2U * sizeof(te_service_id_t)) + 4U)
62 
63 /* Max Port Length is the sum of the Prefix + UUID Converted Post fix */
64 #define MAX_PORT_NAME_LENGTH sizeof(SERVICE_PORT_NAME_PREFIX) + UUID_STR_SIZE_BYTES
65 
68 #define OTE_TASK_NAME_MAX_LENGTH 24
69 
82 #define OTE_TASK_PRIVATE_DATA_LENGTH 20
83 
84 /*
85  * Defines maximum chunk size allowed by the trusty kernel to pass in a single
86  * SMC call. This value is referenced from Android Open Source implementation
87  * of secure storage proxy daemon.
88  */
89 #define TIPC_MAX_CHUNK_SIZE 4040
90 
91 /*
92  * Value of ACK that is agreed upon by NS clients and Trusty as
93  * an application level protocol
94  */
95 #define TIPC_CHUNK_MSG_ACK 0xcafefeedU
96 
97 #define WORD_SIZE sizeof(uint32_t)
98 #define ROUNDUP(a, b) (((a) + ((b)-1)) & ~((b)-1))
99 #define ROUNDDOWN(a, b) ((a) & ~((b)-1))
100 
102 typedef struct {
103  uint32_t time_low;
104  uint16_t time_mid;
106  uint8_t clock_seq_and_node[8];
108 
109 #if !defined(CONFIG_TRUSTY)
110 /* Defines a struct used to communicate the status of a service
111  * uuid: ID of the TLK service
112  * valid: true if the service ID corresponds to a TA that is recognized by TLK
113  * active: true if service ID corresponds to an service that is currently running
114  */
115 typedef struct {
117  bool valid;
118  bool active;
120 #endif
121 
123 typedef enum {
135 
137 typedef uint64_t cmnptr_t;
138 
140 typedef union {
141  struct {
142  uint32_t session_id;
143  uint32_t context_id;
145  } client;
146  struct {
147  uint32_t session_id;
148  te_result_origin_t result_origin;
149  } service;
150 } te_session_t;
151 
153 typedef struct {
154  uint32_t index;
156  union {
157  struct {
158  uint32_t val;
159  } Int;
160  struct {
161  cmnptr_t base;
162  uint32_t len;
163  uint32_t type;
164  } Mem;
165  } u;
166  cmnptr_t next;
168 
169 enum {
172 };
173 
178 typedef struct {
179  uint32_t command;
181 
185  cmnptr_t list_head;
186  cmnptr_t list_tail;
187 
188  uint32_t list_count;
189  uint32_t interface_side;
191 
203 
206 enum {
208  TE_ERR = 1U,
209  TE_INFO = 2U,
210  TE_SPEW = 3U,
211  TE_SECURE = 4U,
213  TE_RESULT = 6U,
214 };
215 
224 int te_fprintf(int fd, const char *fmt, ...) __PRINTFLIKE(2,3);
225 int te_vfprintf(int lvl, const char* fmt, va_list ap);
226 
227 /* Definitions for OTE TIPC wrapper */
228 
230 typedef struct {
232  char port_name[MAX_PORT_NAME_LENGTH];
234 
242 te_error_t get_port_name_by_uuid(char *path, uint32_t max_len, te_service_id_t *service);
243 
251 
263 te_error_t te_uuid_to_string(char *ustr, uint32_t ulen,
264  const te_service_id_t *uuid);
265 
272 const char* te_strerror(te_error_t errcode);
273 
288 bool te_validate_range(void* range_base, uint32_t range_size,
289  void* base, uint32_t size);
290 #endif
te_error_t status
Definition: ote_common.h:180
uint32_t interface_side
Definition: ote_common.h:189
uint32_t session_id
Definition: ote_common.h:142
uint32_t list_count
Definition: ote_common.h:188
uint16_t time_mid
Definition: ote_common.h:104
Holds operation object information that is to be delivered to the TLK Secure Service.
Definition: ote_common.h:178
te_service_id_t uuid
Definition: ote_common.h:116
uint32_t context_id
Definition: ote_common.h:143
bool te_validate_range(void *range_base, uint32_t range_size, void *base, uint32_t size)
Implements a range checker which is free from integer overflow.
int te_fprintf(int fd, const char *fmt,...) __PRINTFLIKE(2
For secure tasks: Redirects prints to Trusted Little Kernel (TLK) writes.
uint32_t command
Definition: ote_common.h:179
cmnptr_t list_head
Holds pointers to the head/tail of the list of param_t nodes.
Definition: ote_common.h:185
te_oper_param_type_t type
Definition: ote_common.h:155
cmnptr_t base
Definition: ote_common.h:161
te_oper_param_type_t
Specifies the operation object's parameter types.
Definition: ote_common.h:123
NVIDIA Trusted Little Kernel Interface: Error Handling
te_error_t tipc_error_to_ote_error(int err_num)
Translates TIPC Error Code to an OTE Error Code.
cmnptr_t list_tail
Definition: ote_common.h:186
int int te_vfprintf(int lvl, const char *fmt, va_list ap)
cmnptr_t next
Definition: ote_common.h:166
Holds Unique Task identifiers, including uuid and port name.
Definition: ote_common.h:230
Defines a unique 16-byte ID for each TLK service.
Definition: ote_common.h:102
te_service_id_t uuid
Definition: ote_common.h:231
Holds session information.
Definition: ote_common.h:140
uint64_t cmnptr_t
Holds a pointer large enough to support 32- and 64-bit clients.
Definition: ote_common.h:137
te_result_origin_t
Defines the origin of an error.
Definition: ote_error.h:91
te_error_t te_uuid_to_string(char *ustr, uint32_t ulen, const te_service_id_t *uuid)
Converts UUID to a string format.
uint32_t time_low
Definition: ote_common.h:103
te_result_origin_t result_origin
Definition: ote_common.h:144
#define MAX_PORT_NAME_LENGTH
Definition: ote_common.h:64
uint16_t time_hi_and_version
Definition: ote_common.h:105
te_error_t get_port_name_by_uuid(char *path, uint32_t max_len, te_service_id_t *service)
Returns the port name of a secure task.
te_error_t
Defines Open Trusted Environment (OTE) error codes.
Definition: ote_error.h:45
te_result_origin_t te_get_result_origin(te_session_t *session)
Returns the origin of a returned result.
const char * te_strerror(te_error_t errcode)
Converts an error code to appropriate string description.
Holds the operation object parameters.
Definition: ote_common.h:153
uint32_t index
Definition: ote_common.h:154
uint32_t type
Definition: ote_common.h:163
uint32_t len
Definition: ote_common.h:162
uint32_t val
Definition: ote_common.h:158