1 /* 2 * Copyright (c) 2013 Google Inc. All rights reserved 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining 5 * a copy of this software and associated documentation files 6 * (the "Software"), to deal in the Software without restriction, 7 * including without limitation the rights to use, copy, modify, merge, 8 * publish, distribute, sublicense, and/or sell copies of the Software, 9 * and to permit persons to whom the Software is furnished to do so, 10 * 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 NONINFRINGEMENT. 18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 */ 23 24 #pragma once 25 26 #include <lk/compiler.h> 27 #include <stddef.h> 28 #include <stdint.h> 29 #include <sys/uio.h> 30 #include <uapi/trusty_ipc.h> 31 #include <uapi/trusty_uuid.h> 32 33 __BEGIN_CDECLS 34 35 /* 36 * handle_t is an opaque 32 bit value that is used to reference an 37 * object (like ipc port or channel) in kernel space 38 */ 39 typedef int32_t handle_t; 40 41 /* 42 * Invalid IPC handle 43 */ 44 #define INVALID_IPC_HANDLE ((handle_t)-1) 45 46 /* 47 * Specify this timeout value to wait forever. 48 */ 49 #define INFINITE_TIME UINT32_MAX 50 51 /* 52 * Combination of these flags sets additional options 53 * for port_create syscall. 54 */ 55 enum { 56 /* allow Trusted Apps to connect to this port */ 57 IPC_PORT_ALLOW_TA_CONNECT = 0x1, 58 /* allow non-secure clients to connect to this port */ 59 IPC_PORT_ALLOW_NS_CONNECT = 0x2, 60 }; 61 62 /* 63 * Options for connect syscall 64 */ 65 enum { 66 IPC_CONNECT_WAIT_FOR_PORT = 0x1, 67 IPC_CONNECT_ASYNC = 0x2, 68 }; 69 70 /* 71 * IPC message 72 */ 73 typedef struct ipc_msg { 74 uint32_t num_iov; 75 struct iovec* iov; 76 77 uint32_t num_handles; 78 handle_t* handles; 79 } ipc_msg_t; 80 81 typedef struct ipc_msg_info { 82 size_t len; 83 uint32_t id; 84 uint32_t num_handles; 85 } ipc_msg_info_t; 86 87 /* 88 * Combination of these values is used for event field 89 * ot uevent_t structure. 90 */ 91 enum { 92 IPC_HANDLE_POLL_NONE = 0x0, 93 IPC_HANDLE_POLL_READY = 0x1, 94 IPC_HANDLE_POLL_ERROR = 0x2, 95 IPC_HANDLE_POLL_HUP = 0x4, 96 IPC_HANDLE_POLL_MSG = 0x8, 97 IPC_HANDLE_POLL_SEND_UNBLOCKED = 0x10, 98 }; 99 100 /* 101 * Values for cmd parameter of handle_set_ctrl call 102 */ 103 enum { 104 HSET_ADD = 0x0, /* adds new handle to handle set */ 105 HSET_DEL = 0x1, /* deletes handle from handle set */ 106 HSET_MOD = 0x2, /* modifies handle attributes in handle set */ 107 }; 108 109 /* 110 * Is used by wait and wait_any calls to return information 111 * about event. 112 */ 113 typedef struct uevent { 114 handle_t handle; /* handle this event is related too */ 115 uint32_t event; /* combination of IPC_HANDLE_POLL_XXX flags */ 116 void* cookie; /* cookie aasociated with handle */ 117 } uevent_t; 118 119 #define UEVENT_INITIAL_VALUE(event) \ 120 { 0, 0, 0 } 121 122 handle_t port_create(const char* path, 123 uint32_t num_recv_bufs, 124 uint32_t recv_buf_size, 125 uint32_t flags); 126 handle_t connect(const char* path, uint32_t flags); 127 handle_t accept(handle_t handle, uuid_t* peer_uuid); 128 int close(handle_t handle); 129 int set_cookie(handle_t handle, void* cookie); 130 handle_t handle_set_create(void); 131 int handle_set_ctrl(handle_t handle, uint32_t cmd, struct uevent* evt); 132 int wait(handle_t handle, uevent_t* event, uint32_t timeout_msecs); 133 int wait_any(uevent_t* event, uint32_t timeout_msecs); 134 int get_msg(handle_t handle, ipc_msg_info_t* msg_info); 135 ssize_t read_msg(handle_t handle, 136 uint32_t msg_id, 137 uint32_t offset, 138 ipc_msg_t* msg); 139 int put_msg(handle_t handle, uint32_t msg_id); 140 ssize_t send_msg(handle_t handle, ipc_msg_t* msg); 141 handle_t dup(handle_t handle); 142 143 __END_CDECLS 144