1 /* 2 * Copyright (C) 2015 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 #pragma once 18 19 #include <stdio.h> 20 21 #include <lib/tipc/tipc.h> 22 #include <lk/list.h> 23 #include <trusty_ipc.h> 24 #include <uapi/trusty_uuid.h> 25 26 struct ipc_context; 27 struct ipc_port_context; 28 struct ipc_channel_context; 29 30 /** 31 * ipc_connect_handler_t - handler for connect events 32 * @parent: the parent port context of the channel to be created 33 * @peer_uuid: the UUID of the connecting peer 34 * @chan_handle: the handle for the connecting channel 35 * 36 * Returns a reference to an ipc_channel_context with its channel 37 * operations initialized. 38 */ 39 typedef struct ipc_channel_context* (*ipc_connect_handler_t)( 40 struct ipc_port_context* parent, 41 const uuid_t* peer_uuid, 42 handle_t chan_handle); 43 44 /** 45 * ipc_msg_handler_t - handler for msg events 46 * @context: the channel context returned from ipc_connect_handler_t 47 * @msg: the received msg buffer 48 * @msg_size: the received msg buffer size 49 * 50 * Returns NO_ERROR on success, error code < 0 on failure. 51 * In case of error, the channel is disconnected. 52 */ 53 typedef int (*ipc_msg_handler_t)(struct ipc_channel_context* context, 54 void* msg, 55 size_t msg_size); 56 57 /** 58 * ipc_disconnect_handler_t - handler for disconnect events 59 * @context: the context to be freed 60 * 61 * This function must not close the channel handle. 62 */ 63 typedef void (*ipc_disconnect_handler_t)(struct ipc_channel_context* context); 64 65 /** 66 * ipc_port_ops 67 * @on_connect: required connect handler 68 */ 69 struct ipc_port_ops { 70 ipc_connect_handler_t on_connect; 71 }; 72 73 /** 74 * ipc_channel_ops 75 * @on_handle_msg: optional msg handler 76 * @on_disconnect: required disconnect handler 77 */ 78 struct ipc_channel_ops { 79 ipc_msg_handler_t on_handle_msg; 80 ipc_disconnect_handler_t on_disconnect; 81 }; 82 83 struct ipc_context { 84 struct tipc_event_handler evt_handler; 85 struct tipc_hset* hset; 86 handle_t handle; 87 }; 88 89 struct ipc_channel_context { 90 struct ipc_context common; 91 struct ipc_channel_ops ops; 92 struct list_node node; 93 }; 94 95 struct ipc_port_context { 96 struct ipc_context common; 97 struct ipc_port_ops ops; 98 struct list_node channels; 99 }; 100 101 /** 102 * sync_ipc_send_msg - send IPC message 103 * @session: the session handle 104 * @tx_iovecs: the buffers to send 105 * @tx_iovec_count: the count of buffers to send 106 * @rx_iovecs: the buffers to receive 107 * @rx_iovec_count: the count of buffers to receive 108 */ 109 int sync_ipc_send_msg(handle_t session, 110 struct iovec* tx_iovecs, 111 unsigned int tx_iovec_count, 112 struct iovec* rx_iovecs, 113 unsigned int rx_iovec_count); 114 115 int ipc_port_create(struct tipc_hset* hset, 116 struct ipc_port_context* contextp, 117 const char* port_name, 118 size_t queue_size, 119 size_t max_buffer_size, 120 uint32_t flags); 121 int ipc_port_destroy(struct ipc_port_context* context); 122