Home | History | Annotate | Download | only in trusty
      1 <html devsite><head>
      2     <title>Trusty API </title>
      3     <meta name="project_path" value="/_project.yaml"/>
      4     <meta name="book_path" value="/_book.yaml"/>
      5   </head>
      6   <body>
      7   <!--
      8       Copyright 2017 The Android Open Source Project
      9 
     10       Licensed under the Apache License, Version 2.0 (the "License");
     11       you may not use this file except in compliance with the License.
     12       You may obtain a copy of the License at
     13 
     14           http://www.apache.org/licenses/LICENSE-2.0
     15 
     16       Unless required by applicable law or agreed to in writing, software
     17       distributed under the License is distributed on an "AS IS" BASIS,
     18       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     19       See the License for the specific language governing permissions and
     20       limitations under the License.
     21   -->
     22 
     23 <p><a href="index.html">Trusty</a> API  Trusty  (IPC)  API </p>
     24 
     25 <h2 id="ports_and_channels"></h2>
     26 
     27 <p>Trusty  ID  DNS  <code>com.google.servicename</code></p>
     28 
     29 <p></p>
     30 
     31 <p> Trusty </p>
     32 
     33 <p></p>
     34 
     35 <h2 id="handle_api">Handle API</h2>
     36 
     37 <p> UNIX </p>
     38 
     39 <p> <code>set_cookie()</code> </p>
     40 
     41 <h3 id="methods_handle_api">Handle API </h3>
     42 
     43 <p> <code>INVALID_IPC_HANDLE #define,</code></p>
     44 
     45 <h4 id="set_cookie">set_cookie()</h4>
     46 
     47 <p></p>
     48 
     49 <pre class="prettyprint">
     50 long set_cookie(uint32_t handle, void *cookie)
     51 </pre>
     52 
     53 <p>[] <code>handle</code> API </p>
     54 
     55 <p>[] <code>cookie</code> Trusty </p>
     56 
     57 <p>[] <code>NO_ERROR</code> <code>&lt; 0</code> </p>
     58 
     59 <p> Cookie </p>
     60 
     61 <p> <code>wait()</code>  <code>wait_any()</code> </p>
     62 
     63 <h4 id="wait">wait()</h4>
     64 
     65 <p></p>
     66 
     67 <pre class="prettyprint">
     68 long wait(uint32_t handle_id, uevent_t *event, unsigned long timeout_msecs)
     69 </pre>
     70 
     71 <p>[] <code>handle_id</code> API </p>
     72 
     73 <p>[] <code>event</code></p>
     74 
     75 <p>[] <code>timeout_msecs</code>-1 </p>
     76 
     77 <p>[] <code>NO_ERROR</code> <code>ERR_TIMED_OUT</code> <code>&lt; 0</code></p>
     78 
     79 <h4 id="wait_any">wait_any()</h4>
     80 
     81 <p></p>
     82 
     83 <pre class="prettyprint">
     84 long wait_any(uevent_t *event, unsigned long timeout_msecs);
     85 </pre>
     86 
     87 <p>[] <code>event</code></p>
     88 
     89 <p>[] <code>timeout_msecs</code>-1 </p>
     90 
     91 <p>[] <code>NO_ERROR</code> <code>ERR_TIMED_OUT</code> <code>&lt; 0</code></p>
     92 
     93 <p> (<code>retval == NO_ERROR</code>)<code>wait()</code>  <code>wait_any()</code>  <code>uevent_t</code> </p>
     94 
     95 <pre class="prettyprint">
     96 typedef struct uevent {
     97     uint32_t handle; /* handle this event is related to */
     98     uint32_t event;  /* combination of IPC_HANDLE_POLL_XXX flags */
     99     void    *cookie; /* cookie associated with this handle */
    100 } uevent_t;
    101 </pre>
    102 
    103 <p><code>event</code> </p>
    104 
    105 <pre class="prettyprint">
    106 enum {
    107   IPC_HANDLE_POLL_NONE    = 0x0,
    108   IPC_HANDLE_POLL_READY   = 0x1,
    109   IPC_HANDLE_POLL_ERROR   = 0x2,
    110   IPC_HANDLE_POLL_HUP     = 0x4,
    111   IPC_HANDLE_POLL_MSG     = 0x8,
    112   IPC_HANDLE_POLL_SEND_UNBLOCKED = 0x10,
    113    more values[TBD]
    114 };
    115 </pre>
    116 
    117 <p><code>IPC_HANDLE_POLL_NONE</code> - </p>
    118 
    119 <p><code>IPC_HANDLE_POLL_ERROR</code> - </p>
    120 
    121 <p><code>IPC_HANDLE_POLL_READY</code> - </p>
    122 
    123 <ul>
    124   <li></li><li> <code>connect()</code></li></ul>
    125 
    126 <p></p>
    127 
    128 <ul>
    129   <li><code>IPC_HANDLE_POLL_HUP</code> - </li><li><code>IPC_HANDLE_POLL_MSG</code> - </li><li><code>IPC_HANDLE_POLL_SEND_UNBLOCKED</code> -  <code>send_msg()</code> </li></ul>
    130 
    131 <p></p>
    132 
    133 <p><code>IPC_HANDLE_POLL_SEND_UNBLOCKED</code> </p>
    134 
    135 <p> <code>close()</code> </p>
    136 
    137 <h4 id="close">close()</h4>
    138 
    139 <p></p>
    140 
    141 <pre class="prettyprint">
    142 long close(uint32_t handle_id);
    143 </pre>
    144 
    145 <p>[] <code>handle_id</code></p>
    146 
    147 <p>[] 0</p>
    148 
    149 <h2 id="server_api">Server API</h2>
    150 
    151 <p><strong></strong></p>
    152 
    153 <h3 id="methods_server_api">Server API </h3>
    154 
    155 <h4 id="port_create">port_create()</h4>
    156 
    157 <p></p>
    158 
    159 <pre class="prettyprint">
    160 long port_create (const char *path, uint num_recv_bufs, size_t recv_buf_size,
    161 uint32_t flags)
    162 </pre>
    163 
    164 <p>[] <code>path</code></p>
    165 
    166 <p>[] <code>num_recv_bufs</code> 1 1  1  1</p>
    167 
    168 <p>[] <code>recv_buf_size</code></p>
    169 
    170 <p>[] <code>flags</code></p>
    171 
    172 <p></p>
    173 
    174 <p><code>IPC_PORT_ALLOW_TA_CONNECT</code> - </p>
    175 
    176 <p><code>IPC_PORT_ALLOW_NS_CONNECT</code> - </p>
    177 
    178 <p>[]</p>
    179 
    180 <p> <code>wait()</code>  <code>wait_any()</code>  <code>uevent_t</code>  <code>event</code>  <code>IPC_HANDLE_POLL_READY</code>  <code>accept()</code> </p>
    181 
    182 <h4 id="accept">accept()</h4>
    183 
    184 <p></p>
    185 
    186 <pre class="prettyprint">
    187 long accept(uint32_t handle_id, uuid_t *peer_uuid);
    188 </pre>
    189 
    190 <p>[] <code>handle_id</code></p>
    191 
    192 <p>[] <code>peer_uuid</code> UUID  <code>uuud_t</code> </p>
    193 
    194 <p>[]</p>
    195 
    196 <h2 id="client_api">Client API</h2>
    197 
    198 <p> Client API </p>
    199 
    200 <h3 id="methods_client_api">Client API </h3>
    201 
    202 <h4 id="connect">connect()</h4>
    203 
    204 <p></p>
    205 
    206 <pre class="prettyprint">
    207 long connect(const char *path, uint flags);
    208 </pre>
    209 
    210 <p>[] <code>path</code> Trusty </p>
    211 
    212 <p>[] <code>flags</code></p>
    213 
    214 <p>[]</p>
    215 
    216 <p> <code>flags</code><code>flags</code>  0 <code>connect()</code> </p>
    217 
    218 <p></p>
    219 
    220 <pre class="prettyprint">
    221 enum {
    222 IPC_CONNECT_WAIT_FOR_PORT = 0x1,
    223 IPC_CONNECT_ASYNC = 0x2,
    224 };
    225 </pre>
    226 
    227 <p><code>IPC_CONNECT_WAIT_FOR_PORT</code> -  <code>connect()</code> </p>
    228 
    229 <p><code>IPC_CONNECT_ASYNC</code> -  <code>uevent_t</code>  event  <code>IPC_HANDLE_POLL_READY</code>  <code>wait()</code>  <code>wait_any()</code></p>
    230 
    231 <h2 id="messaging_api">Messaging API</h2>
    232 
    233 <p> Messaging API  Messaging API </p>
    234 
    235 <p> <code>connect()</code>  <code>accept()</code> </p>
    236 
    237 <h4 id="structure_of_a_trusty_message">Trusty </h4>
    238 
    239 <p> Trusty API </p>
    240 
    241 <pre class="prettyprint">
    242 /*
    243  *  IPC message
    244  */
    245 typedef struct iovec {
    246         void   *base;
    247         size_t  len;
    248 } iovec_t;
    249 
    250 typedef struct ipc_msg {
    251         uint     num_iov; /* number of iovs in this message */
    252         iovec_t  *iov;    /* pointer to iov array */
    253 
    254         uint     num_handles; /* reserved, currently not supported */
    255         handle_t *handles;    /* reserved, currently not supported */
    256 } ipc_msg_t;
    257 </pre>
    258 
    259 <p> <code>iovec_t</code> Trusty  <code>iov</code> - <code>iov</code> </p>
    260 
    261 <h3 id="methods_messaging_api">Messaging API </h3>
    262 
    263 <h4 id="send_msg">send_msg()</h4>
    264 
    265 <p></p>
    266 
    267 <pre class="prettyprint">
    268 long send_msg(uint32_t handle, ipc_msg_t *msg);
    269 </pre>
    270 
    271 <p>[] <code>handle</code></p>
    272 
    273 <p>[] <code>msg</code> <code>ipc_msg_t structure</code></p>
    274 
    275 <p>[]</p>
    276 
    277 <p>/ <code>ERR_NOT_ENOUGH_BUFFER</code>  <code>wait()</code>  <code>wait_any()</code>  <code>uevent_t</code>  <code>event</code>  <code>IPC_HANDLE_POLL_SEND_UNBLOCKED</code> </p>
    278 
    279 <h4 id="get_msg">get_msg()</h4>
    280 
    281 <p></p>
    282 
    283 <p></p>
    284 
    285 <pre class="prettyprint">
    286 long get_msg(uint32_t handle, ipc_msg_info_t *msg_info);
    287 </pre>
    288 
    289 <p>[] <code>handle</code></p>
    290 
    291 <p>[] <code>msg_info</code></p>
    292 
    293 <pre class="prettyprint">
    294 typedef struct ipc_msg_info {
    295         size_t    len;  /* total message length */
    296         uint32_t  id;   /* message id */
    297 } ipc_msg_info_t;
    298 </pre>
    299 
    300 <p> ID</p>
    301 
    302 <p>[] <code>NO_ERROR</code></p>
    303 
    304 <h4 id="read_msg">read_msg()</h4>
    305 
    306 <p> ID </p>
    307 
    308 <pre class="prettyprint">
    309 long read_msg(uint32_t handle, uint32_t msg_id, uint32_t offset, ipc_msg_t
    310 *msg);
    311 </pre>
    312 
    313 <p>[] <code>handle</code></p>
    314 
    315 <p>[] <code>msg_id</code> ID</p>
    316 
    317 <p>[] <code>offset</code></p>
    318 
    319 <p>[] <code>msg</code> <code>ipc_msg_t</code> </p>
    320 
    321 <p>[] <code>dst</code> </p>
    322 
    323 <p> <code>read_msg</code> </p>
    324 
    325 <h4 id="put_msg">put_msg()</h4>
    326 
    327 <p> ID </p>
    328 
    329 <pre class="prettyprint">
    330 long put_msg(uint32_t handle, uint32_t msg_id);
    331 </pre>
    332 
    333 <p>[] <code>handle</code></p>
    334 
    335 <p>[] <code>msg_id</code> ID</p>
    336 
    337 <p>[] <code>NO_ERROR</code></p>
    338 
    339 <p></p>
    340 
    341 <h2 id="file_descriptor_api">File Descriptor API</h2>
    342 
    343 <p>File Descriptor API  <code>read()</code><code>write()</code>  <code>ioctl()</code>  IPC Trusty  File Descriptor API  API </p>
    344 
    345 <p> 3 </p>
    346 
    347 <ul>
    348   <li>0 -  <code>fd</code>  <code>fd</code> 0  <code>ioctl()</code> <code>ERR_NOT_SUPPORTED</code> 
    349   </li><li>1 -  LK  UART /<code>read()</code>  <code>ioctl()</code>  <code>ERR_NOT_SUPPORTED</code> 
    350   </li><li>2 -  UART <code>read()</code>  <code>ioctl()</code>  <code>ERR_NOT_SUPPORTED</code> 
    351 </li></ul>
    352 
    353 <p> <code>fds</code></p>
    354 
    355 <h3 id="methods_file_descriptor_api">File Descriptor API </h3>
    356 
    357 <h4 id="read">read()</h4>
    358 
    359 <p> <code>count</code> </p>
    360 
    361 <pre class="prettyprint">
    362 long read(uint32_t fd, void *buf, uint32_t count);
    363 </pre>
    364 
    365 <p>[] <code>fd</code></p>
    366 
    367 <p>[] <code>buf</code></p>
    368 
    369 <p>[] <code>count</code></p>
    370 
    371 <p>[]</p>
    372 
    373 <h4 id="write">write()</h4>
    374 
    375 <p> <code>count</code> </p>
    376 
    377 <pre class="prettyprint">
    378 long write(uint32_t fd, void *buf, uint32_t count);
    379 </pre>
    380 
    381 <p>[] <code>fd</code></p>
    382 
    383 <p>[] <code>buf</code></p>
    384 
    385 <p>[] <code>count</code></p>
    386 
    387 <p>[]</p>
    388 
    389 <h4 id="ioctl">ioctl()</h4>
    390 
    391 <p> <code>ioctl</code> </p>
    392 
    393 <pre class="prettyprint">
    394 long ioctl(uint32_t fd, uint32_t cmd, void *args);
    395 </pre>
    396 
    397 <p>[] <code>fd</code> <code>ioctl()</code></p>
    398 
    399 <p>[] <code>cmd</code><code>ioctl</code> </p>
    400 
    401 <p>[in/out] <code>args</code> <code>ioctl()</code> </p>
    402 
    403 <h2 id="miscellaneous_api">Miscellaneous API</h2>
    404 
    405 <h3 id="methods_misc_api">Miscellaneous API </h3>
    406 
    407 <h4 id="gettime">gettime()</h4>
    408 
    409 <p></p>
    410 
    411 <pre class="prettyprint">
    412 long gettime(uint32_t clock_id, uint32_t flags, uint64_t *time);
    413 </pre>
    414 
    415 <p>[] <code>clock_id</code> 0</p>
    416 
    417 <p>[] <code>flags</code> 0</p>
    418 
    419 <p>[] <code>time</code> <code>int64_t</code> </p>
    420 
    421 <p>[] <code>NO_ERROR</code></p>
    422 
    423 <h4 id="nanosleep">nanosleep()</h4>
    424 
    425 <p></p>
    426 
    427 <pre class="prettyprint">
    428 long nanosleep(uint32_t clock_id, uint32_t flags, uint64_t sleep_time)
    429 </pre>
    430 
    431 <p>[] <code>clock_id</code> 0</p>
    432 
    433 <p>[] <code>flags</code> 0</p>
    434 
    435 <p>[] <code>sleep_time</code></p>
    436 
    437 <p>[] <code>NO_ERROR</code></p>
    438 
    439 <h2 id="example_of_a_trusted_application_server"></h2>
    440 
    441 <p> API </p>
    442 
    443 <pre class="prettyprint">
    444 #include &lt;assert.h&gt;
    445 #include &lt;err.h&gt;
    446 #include &lt;stddef.h&gt;
    447 #include &lt;stdio.h&gt;
    448 #include &lt;stdlib.h&gt;
    449 #include &lt;string.h&gt;
    450 #include &lt;trusty_std.h&gt;
    451 
    452 #include &lt;app/echo/uuids.h&gt;
    453 
    454 #define LOG_TAG "echo_srv"
    455 
    456 #define TLOGE(fmt, ...) \
    457     fprintf(stderr, "%s: %d: " fmt, LOG_TAG, __LINE__,  ## __VA_ARGS__)
    458 
    459 #define MAX_ECHO_MSG_SIZE  64
    460 
    461 static const char *srv_name = "com.android.echo.srv.echo";
    462 
    463 static uint8_t msg_buf[MAX_ECHO_MSG_SIZE];
    464 
    465 /*
    466  *  Message handler
    467  */
    468 static int handle_msg(handle_t chan)
    469 {
    470   int rc;
    471   iovec_t iov;
    472   ipc_msg_t msg;
    473   ipc_msg_info_t msg_inf;
    474 
    475   iov.base = msg_buf;
    476   iov.len  = sizeof(msg_buf);
    477 
    478   msg.num_iov = 1;
    479   msg.iov = &amp;iov;
    480   msg.num_handles = 0;
    481   msg.handles  = NULL;
    482 
    483   /* get message info */
    484   rc = get_msg(chan, &amp;msg_inf);
    485   if (rc == ERR_NO_MSG)
    486     return NO_ERROR; /* no new messages */
    487 
    488   if (rc != NO_ERROR) {
    489     TLOGE("failed (%d) to get_msg for chan (%d)\n",
    490           rc, chan);
    491     return rc;
    492   }
    493 
    494   /* read msg content */
    495   rc = read_msg(chan, msg_inf.id, 0, &amp;msg);
    496   if (rc &lt; 0) {
    497     TLOGE("failed (%d) to read_msg for chan (%d)\n",
    498           rc, chan);
    499     return rc;
    500   }
    501 
    502   /* update number of bytes received */
    503   iov.len = (size_t) rc;
    504 
    505   /* send message back to the caller */
    506   rc = send_msg(chan, &amp;msg);
    507   if (rc &lt; 0) {
    508     TLOGE("failed (%d) to send_msg for chan (%d)\n",
    509           rc, chan);
    510     return rc;
    511   }
    512 
    513   /* retire message */
    514   rc = put_msg(chan, msg_inf.id);
    515   if ( rc != NO_ERROR) {
    516     TLOGE("failed (%d) to put_msg for chan (%d)\n",
    517           rc, chan);
    518     return rc;
    519   }
    520 
    521   return NO_ERROR;
    522 }
    523 
    524 /*
    525  *  Channel event handler
    526  */
    527 static void handle_channel_event(const uevent_t *ev)
    528 {
    529   int rc;
    530 
    531   if (ev-&gt;event &amp; IPC_HANDLE_POLL_MSG) {
    532     rc = handle_msg(ev-&gt;handle);
    533     if (rc != NO_ERROR) {
    534       /* report an error and close channel */
    535       TLOGE("failed (%d) to handle event on channel %d\n",
    536              rc, ev-&gt;handle);
    537       close(ev-&gt;handle);
    538     }
    539     return;
    540   }
    541   if (ev-&gt;event &amp; IPC_HANDLE_POLL_HUP) {
    542     /* closed by peer. */
    543     close(ev-&gt;handle);
    544     return;
    545   }
    546 }
    547 
    548 /*
    549  *  Port event handler
    550  */
    551 static void handle_port_event(const uevent_t *ev)
    552 {
    553   uuid_t peer_uuid;
    554 
    555   if ((ev-&gt;event &amp; IPC_HANDLE_POLL_ERROR) ||
    556       (ev-&gt;event &amp; IPC_HANDLE_POLL_HUP) ||
    557       (ev-&gt;event &amp; IPC_HANDLE_POLL_MSG) ||
    558       (ev-&gt;event &amp; IPC_HANDLE_POLL_SEND_UNBLOCKED)) {
    559     /* should never happen with port handles */
    560     TLOGE("error event (0x%x) for port (%d)\n",
    561            ev-&gt;event, ev-&gt;handle);
    562     abort();
    563   }
    564   if (ev-&gt;event &amp; IPC_HANDLE_POLL_READY) {
    565     /* incoming connection: accept it */
    566     int rc = accept(ev-&gt;handle, &amp;peer_uuid);
    567     if (rc &lt; 0) {
    568       TLOGE("failed (%d) to accept on port %d\n",
    569              rc, ev-&gt;handle);
    570       return;
    571     }
    572   }
    573 }
    574 
    575 /*
    576  *  Main application entry point
    577  */
    578 int main(void)
    579 {
    580   int rc;
    581   handle_t port;
    582 
    583   /* Initialize service */
    584   rc = port_create(srv_name, 1, MAX_ECHO_MSG_SIZE,
    585        IPC_PORT_ALLOW_NS_CONNECT |
    586        IPC_PORT_ALLOW_TA_CONNECT );
    587   if (rc &lt; 0) {
    588     TLOGE("Failed (%d) to create port %s\n",
    589           rc, srv_name);
    590     abort();
    591   }
    592   port = (handle_t)rc;
    593 
    594   /* enter main event loop */
    595   while (true) {
    596     uevent_t ev;
    597 
    598     ev.handle = INVALID_IPC_HANDLE;
    599     ev.event  = 0;
    600     ev.cookie = NULL;
    601 
    602     /* wait forever */
    603     rc = wait_any(&amp;ev, -1);
    604     if (rc == NO_ERROR) {
    605       /* got an event */
    606       if (ev.handle == port) {
    607         handle_port_event(&amp;ev);
    608       } else {
    609         handle_channel_event(&amp;ev);
    610       }
    611     } else {
    612       TLOGE("wait_any returned (%d)\n", rc);
    613       abort();
    614     }
    615   }
    616   return 0;
    617 }
    618 </pre>
    619 
    620 <h2 id="example_of_a_trusted_application_client"></h2>
    621 
    622 <p> Trusty Messaging API <code>sync_connect()</code>  <code>connect()</code> </p>
    623 
    624 <pre class="prettyprint">
    625 /*
    626  *  Local wrapper on top of an async connect that provides a
    627  *  synchronous connect with timeout.
    628  */
    629 int sync_connect(const char *path, uint timeout)
    630 {
    631   int rc;
    632   uevent_t evt;
    633   handle_t chan;
    634 
    635   rc = connect(path, IPC_CONNECT_ASYNC | IPC_CONNECT_WAIT_FOR_PORT);
    636   if (rc &gt;= 0) {
    637     chan = (handle_t) rc;
    638     rc = wait(chan, &amp;evt, timeout);
    639     if (rc == 0) {
    640       rc = ERR_BAD_STATE;
    641       if (evt.handle == chan) {
    642         if (evt.event &amp; IPC_HANDLE_POLL_READY)
    643           return chan;
    644         if (evt.event &amp; IPC_HANDLE_POLL_HUP)
    645           rc = ERR_CHANNEL_CLOSED;
    646       }
    647     }
    648     close(chan);
    649   }
    650   return rc;
    651 }
    652 </pre>
    653 
    654 <p><code>run_end_to_end_msg_test()</code>  10000 </p>
    655 
    656 <pre class="prettyprint">
    657 static int run_echo_test(void)
    658 {
    659   int rc;
    660   handle_t chan;
    661   uevent_t uevt;
    662   uint8_t tx_buf[64];
    663   uint8_t rx_buf[64];
    664   ipc_msg_info_t inf;
    665   ipc_msg_t   tx_msg;
    666   iovec_t     tx_iov;
    667   ipc_msg_t   rx_msg;
    668   iovec_t     rx_iov;
    669 
    670   /* prepare tx message buffer */
    671   tx_iov.base = tx_buf;
    672   tx_iov.len  = sizeof(tx_buf);
    673   tx_msg.num_iov = 1;
    674   tx_msg.iov     = &amp;tx_iov;
    675   tx_msg.num_handles = 0;
    676   tx_msg.handles = NULL;
    677 
    678   memset (tx_buf, 0x55, sizeof(tx_buf));
    679 
    680   /* prepare rx message buffer */
    681   rx_iov.base = rx_buf;
    682   rx_iov.len  = sizeof(rx_buf);
    683   rx_msg.num_iov = 1;
    684   rx_msg.iov     = &amp;rx_iov;
    685   rx_msg.num_handles = 0;
    686   rx_msg.handles = NULL;
    687 
    688   /* open connection to echo service */
    689   rc = sync_connect(srv_name, 1000);
    690   if(rc &lt; 0)
    691     return rc;
    692 
    693   /* got channel */
    694   chan = (handle_t)rc;
    695 
    696   /* send/receive 10000 messages asynchronously. */
    697   uint tx_cnt = 10000;
    698   uint rx_cnt = 10000;
    699 
    700   while (tx_cnt || rx_cnt) {
    701     /* send messages until all buffers are full */
    702 while (tx_cnt) {
    703     rc = send_msg(chan, &amp;tx_msg);
    704       if (rc == ERR_NOT_ENOUGH_BUFFER)
    705       break;  /* no more space */
    706     if (rc != 64) {
    707       if (rc &gt; 0) {
    708         /* incomplete send */
    709         rc = ERR_NOT_VALID;
    710 }
    711       goto abort_test;
    712 }
    713     tx_cnt--;
    714   }
    715 
    716   /* wait for reply msg or room */
    717   rc = wait(chan, &amp;uevt, 1000);
    718   if (rc != NO_ERROR)
    719     goto abort_test;
    720 
    721   /* drain all messages */
    722   while (rx_cnt) {
    723     /* get a reply */
    724       rc = get_msg(chan, &amp;inf);
    725     if (rc == ERR_NO_MSG)
    726         break;  /* no more messages  */
    727   if (rc != NO_ERROR)
    728 goto abort_test;
    729 
    730   /* read reply data */
    731     rc = read_msg(chan, inf.id, 0, &amp;rx_msg);
    732   if (rc != 64) {
    733     /* unexpected reply length */
    734     rc = ERR_NOT_VALID;
    735     goto abort_test;
    736 }
    737 
    738   /* discard reply */
    739   rc = put_msg(chan, inf.id);
    740   if (rc != NO_ERROR)
    741     goto abort_test;
    742   rx_cnt--;
    743   }
    744 }
    745 
    746 abort_test:
    747   close(chan);
    748   return rc;
    749 }
    750 </pre>
    751 
    752 <h2 id="non-secure_world_apis_and_applications"> API </h2>
    753 
    754 <p> <code>IPC_PORT_ALLOW_NS_CONNECT</code>  Trusty </p>
    755 
    756 <p> APIClient API  Trusty-IPC </p>
    757 
    758 <h3 id="user_space_trusty_ipc_client_api"> Trusty IPC Client API</h3>
    759 
    760 <p> Trusty IPC Client API  <code>fd</code> </p>
    761 
    762 <p> <code>tipc_connect()</code> Trusty <code>tipc_connect()</code>  <code>TIPC_IOC_CONNECT ioctl()</code>  <code>argp</code> </p>
    763 
    764 <pre class="prettyprint">
    765 #define TIPC_IOC_MAGIC  'r'
    766 #define TIPC_IOC_CONNECT  _IOW(TIPC_IOC_MAGIC, 0x80, char *)
    767 </pre>
    768 
    769 <p> <code>tipc_close()</code> </p>
    770 
    771 <p> <code>tipc_connect()</code> </p>
    772 
    773 <ul>
    774   <li></li><li> <code>write()</code> </li><li> <code>poll()</code>  <code>select()</code> </li><li></li></ul>
    775 
    776 <p> <code>fd</code>  Trusty Trusty-IPC  <code>write()</code>  Trusty  IPC  <code>IPC_HANDLE_POLL_MSG</code> Trusty  <code>read()</code> </p>
    777 
    778 <h4 id="tipc_connect">tipc_connect()</h4>
    779 
    780 <p> <code>tipc</code>  Trusty </p>
    781 
    782 <pre class="prettyprint">
    783 int tipc_connect(const char *dev_name, const char *srv_name);
    784 </pre>
    785 
    786 <p>[] <code>dev_name</code> Trusty IPC </p>
    787 
    788 <p>[] <code>srv_name</code> Trusty </p>
    789 
    790 <p>[] -1</p>
    791 
    792 <h4 id="tipc_close">tipc_close()</h4>
    793 
    794 <p> Trusty </p>
    795 
    796 <pre class="prettyprint">
    797 int tipc_close(int fd);
    798 </pre>
    799 
    800 <p>[] <code>fd</code> <code>tipc_connect()</code> </p>
    801 
    802 <h2 id="kernel_trusty_ipc_client_api"> Trusty IPC Client API</h2>
    803 
    804 <p> Trusty IPC Client API  Trusty IPC API  API </p>
    805 
    806 <p> API  <code>tipc_create_channel()</code>  <code>struct tipc_chan</code>  <code>tipc_chan_connect()</code>  Trusty IPC  <code>tipc_chan_shutdown()</code>  <code>tipc_chan_destroy()</code> </p>
    807 
    808 <p> <code>handle_event()</code> </p>
    809 
    810 <ul>
    811   <li> <code>tipc_chan_get_txbuf_timeout()</code> </li><li></li><li> <code>tipc_chan_queue_msg()</code>  Trusty </li></ul>
    812 
    813 <p> <code>tipc_chan_put_txbuf()</code> </p>
    814 
    815 <p> <code>handle_msg()</code>  Trusty-IPC <code>rx</code>  <code>rx</code> API </p>
    816 
    817 <p><code>handle_msg()</code>  <code>struct tipc_msg_buf</code>  <code>tipc_chan_get_rxbuf()</code>  <code>rx</code>  <code>tipc_chan_put_rxbuf()</code> </p>
    818 
    819 <h3 id="methods_ktic_api"> Trusty IPC Client API </h3>
    820 
    821 <h4 id="tipc_create_channel">tipc_create_channel()</h4>
    822 
    823 <p> Trusty-IPC  Trusty IPC </p>
    824 
    825 <pre class="prettyprint">
    826 struct tipc_chan *tipc_create_channel(struct device *dev,
    827                           const struct tipc_chan_ops *ops,
    828                               void *cb_arg);
    829 </pre>
    830 
    831 <p>[] <code>dev</code> Trusty-IPC</p>
    832 
    833 <p>[] <code>ops</code> <code>struct tipc_chan_ops</code></p>
    834 
    835 <p>[] <code>cb_arg</code> <code>tipc_chan_ops</code> </p>
    836 
    837 <p>[] <code>struct tipc_chan</code>  <code>ERR_PTR(err)</code></p>
    838 
    839 <p></p>
    840 
    841 <p> <code>void (*handle_event)(void *cb_arg, int event)</code> </p>
    842 
    843 <p>[] <code>cb_arg</code> <code>tipc_create_channel()</code> </p>
    844 
    845 <p>[] <code>event</code></p>
    846 
    847 <ul>
    848   <li><code>TIPC_CHANNEL_CONNECTED</code> - </li><li><code>TIPC_CHANNEL_DISCONNECTED</code> - </li><li><code>TIPC_CHANNEL_SHUTDOWN</code> - </li></ul>
    849 
    850 <p> <code>struct tipc_msg_buf *(*handle_msg)(void *cb_arg, struct tipc_msg_buf *mb)</code> </p>
    851 
    852 <ul>
    853   <li>[] <code>cb_arg</code> <code>tipc_create_channel()</code> </li><li>[] <code>mb</code> <code>struct tipc_msg_buf</code></li><li>[] <code>struct tipc_msg_buf</code>  <code>mb</code>  <code>tipc_chan_get_rxbuf()</code> </li></ul>
    854 
    855 <h4 id="tipc_chan_connect">tipc_chan_connect()</h4>
    856 
    857 <p> Trusty IPC </p>
    858 
    859 <pre class="prettyprint">
    860 int tipc_chan_connect(struct tipc_chan *chan, const char *port);
    861 </pre>
    862 
    863 <p>[] <code>chan</code> <code>tipc_create_chan()</code> </p>
    864 
    865 <p>[] <code>port</code></p>
    866 
    867 <p>[] 0</p>
    868 
    869 <p> <code>handle_event</code> </p>
    870 
    871 <h4 id="tipc_chan_shutdown">tipc_chan_shutdown()</h4>
    872 
    873 <p> <code>tipc_chan_connect()</code>  Trusty IPC </p>
    874 
    875 <pre class="prettyprint">
    876 int tipc_chan_shutdown(struct tipc_chan *chan);
    877 </pre>
    878 
    879 <p>[] <code>chan</code> <code>tipc_create_chan()</code> </p>
    880 
    881 <h4 id="tipc_chan_destroy">tipc_chan_destroy()</h4>
    882 
    883 <p> Trusty IPC </p>
    884 
    885 <pre class="prettyprint">
    886 void tipc_chan_destroy(struct tipc_chan *chan);
    887 </pre>
    888 
    889 <p>[] <code>chan</code> <code>tipc_create_chan()</code> </p>
    890 
    891 <h4 id="tipc_chan_get_txbuf_timeout">tipc_chan_get_txbuf_timeout()</h4>
    892 
    893 <p></p>
    894 
    895 <pre class="prettyprint">
    896 struct tipc_msg_buf *
    897 tipc_chan_get_txbuf_timeout(struct tipc_chan *chan, long timeout);
    898 </pre>
    899 
    900 <p>[] <code>chan</code></p>
    901 
    902 <p>[] <code>chan</code><code>tx</code> </p>
    903 
    904 <p>[] <code>ERR_PTR(err)</code></p>
    905 
    906 <h4 id="tipc_chan_queue_msg">tipc_chan_queue_msg()</h4>
    907 
    908 <p> Trusty IPC </p>
    909 
    910 <pre class="prettyprint">
    911 int tipc_chan_queue_msg(struct tipc_chan *chan, struct tipc_msg_buf *mb);
    912 </pre>
    913 
    914 <p>[] <code>chan</code></p>
    915 
    916 <p>[] <code>mb:</code>  <code>tipc_chan_get_txbuf_timeout()</code> </p>
    917 
    918 <p>[] 0</p>
    919 
    920 <h4 id="tipc_chan_put_txbuf">tipc_chan_put_txbuf()</h4>
    921 
    922 <p> <code>tipc_chan_get_txbuf_timeout()</code>  <code>Tx</code> </p>
    923 
    924 <pre class="prettyprint">
    925 void tipc_chan_put_txbuf(struct tipc_chan *chan,
    926                          struct tipc_msg_buf *mb);
    927 </pre>
    928 
    929 <p>[] <code>chan</code></p>
    930 
    931 <p>[] <code>mb</code></p>
    932 
    933 <p>[]</p>
    934 
    935 <h4 id="tipc_chan_get_rxbuf">tipc_chan_get_rxbuf()</h4>
    936 
    937 <p></p>
    938 
    939 <pre class="prettyprint">
    940 struct tipc_msg_buf *tipc_chan_get_rxbuf(struct tipc_chan *chan);
    941 </pre>
    942 
    943 <p>[] <code>chan</code></p>
    944 
    945 <p>[] <code>ERR_PTR(err)</code></p>
    946 
    947 <h4 id="tipc_chan_put_rxbuf">tipc_chan_put_rxbuf()</h4>
    948 
    949 <p> <code>tipc_chan_get_rxbuf()</code> </p>
    950 
    951 <pre class="prettyprint">
    952 void tipc_chan_put_rxbuf(struct tipc_chan *chan,
    953                          struct tipc_msg_buf *mb);
    954 </pre>
    955 
    956 <p>[] <code>chan</code></p>
    957 
    958 <p>[] <code>mb</code></p>
    959 
    960 <p>[]</p>
    961 
    962 </body></html>