Home | History | Annotate | Download | only in tee_client_api
      1 /**
      2  * Copyright(c) 2011 Trusted Logic.   All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  *
      8  *  * Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  *  * Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in
     12  *    the documentation and/or other materials provided with the
     13  *    distribution.
     14  *  * Neither the name Trusted Logic nor the names of its
     15  *    contributors may be used to endorse or promote products derived
     16  *    from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #ifndef __SCHANNEL6_PROTOCOL_H__
     32 #define __SCHANNEL6_PROTOCOL_H__
     33 
     34 #include "s_type.h"
     35 
     36 /**
     37  * Time representation.
     38  */
     39 typedef uint64_t SCTIME;
     40 
     41 #define SCTIME_IMMEDIATE ((uint64_t) 0x0000000000000000ULL)
     42 #define SCTIME_INFINITE  ((uint64_t) 0xFFFFFFFFFFFFFFFFULL)
     43 
     44 /*
     45  * Message types
     46  */
     47 #define SCX_CREATE_DEVICE_CONTEXT   0x02
     48 #define SCX_DESTROY_DEVICE_CONTEXT  0xFD
     49 #define SCX_REGISTER_SHARED_MEMORY  0xF7
     50 #define SCX_RELEASE_SHARED_MEMORY   0xF9
     51 #define SCX_OPEN_CLIENT_SESSION     0xF0
     52 #define SCX_CLOSE_CLIENT_SESSION    0xF2
     53 #define SCX_INVOKE_CLIENT_COMMAND   0xF5
     54 #define SCX_CANCEL_CLIENT_OPERATION 0xF4
     55 #define SCX_MANAGEMENT              0xFE
     56 
     57 /*
     58  * Shared mem flags
     59  */
     60 #define SCX_SHARED_MEM_FLAG_INPUT   1
     61 #define SCX_SHARED_MEM_FLAG_OUTPUT  2
     62 #define SCX_SHARED_MEM_FLAG_INOUT   3
     63 
     64 /*
     65  * Parameter types
     66  */
     67 #define SCX_PARAM_TYPE_NONE                     0x0
     68 #define SCX_PARAM_TYPE_VALUE_INPUT              0x1
     69 #define SCX_PARAM_TYPE_VALUE_OUTPUT             0x2
     70 #define SCX_PARAM_TYPE_VALUE_INOUT              0x3
     71 #define SCX_PARAM_TYPE_MEMREF_TEMP_INPUT        0x5
     72 #define SCX_PARAM_TYPE_MEMREF_TEMP_OUTPUT       0x6
     73 #define SCX_PARAM_TYPE_MEMREF_TEMP_INOUT        0x7
     74 #define SCX_PARAM_TYPE_MEMREF_INPUT             0xD
     75 #define SCX_PARAM_TYPE_MEMREF_OUTPUT            0xE
     76 #define SCX_PARAM_TYPE_MEMREF_INOUT             0xF
     77 
     78 #define SCX_PARAM_TYPE_INPUT_FLAG                0x1
     79 #define SCX_PARAM_TYPE_OUTPUT_FLAG               0x2
     80 #define SCX_PARAM_TYPE_MEMREF_FLAG               0x4
     81 #define SCX_PARAM_TYPE_REGISTERED_MEMREF_FLAG    0x8
     82 
     83 #define SCX_PARAM_TYPE_IS_TMPREF(nParamType) (((nParamType) & (SCX_PARAM_TYPE_MEMREF_FLAG | SCX_PARAM_TYPE_REGISTERED_MEMREF_FLAG)) == SCX_PARAM_TYPE_MEMREF_FLAG)
     84 
     85 #define SCX_MAKE_PARAM_TYPES(t0, t1, t2, t3) ((t0) | ((t1) << 4) | ((t2) << 8) | ((t3) << 12))
     86 #define SCX_GET_PARAM_TYPE(t, i) (((t) >> (4*i)) & 0xF)
     87 
     88 /*
     89  * return origins
     90  */
     91 #define SCX_ORIGIN_COMMS       2
     92 #define SCX_ORIGIN_TEE         3
     93 #define SCX_ORIGIN_TRUSTED_APP 4
     94 
     95 /*
     96  * Login types
     97  */
     98 #include "schannel6_logins.h"
     99 
    100 /*
    101  * Limits and sizes
    102  */
    103 
    104 /* Maximum number of L1 descriptors covered by a registered shared memory block.
    105    Must be kept in synch with TF_MAX_COARSE_PAGES in tf_protocol.h
    106    in the Linux kernel driver. */
    107 #define SCHANNEL6_MAX_DESCRIPTORS_PER_REGISTERED_SHARED_MEM 128
    108 
    109 /**
    110  * Command parameters.
    111  */
    112 typedef struct
    113 {
    114    uint32_t    a;
    115    uint32_t    b;
    116 }SCHANNEL6_COMMAND_PARAM_VALUE;
    117 
    118 typedef struct
    119 {
    120    uint32_t    nDescriptor;
    121    uint32_t    nSize;
    122    uint32_t    nOffset;     /* Socket: 4 weak bits of the address (for alignement checks) */
    123 
    124 }SCHANNEL6_COMMAND_PARAM_TEMP_MEMREF;
    125 
    126 typedef struct
    127 {
    128    S_HANDLE    hBlock;
    129    uint32_t    nSize;
    130    uint32_t    nOffset;
    131 
    132 }SCHANNEL6_COMMAND_PARAM_MEMREF;
    133 
    134 typedef union
    135 {
    136    SCHANNEL6_COMMAND_PARAM_VALUE        sValue;
    137    SCHANNEL6_COMMAND_PARAM_TEMP_MEMREF  sTempMemref;
    138    SCHANNEL6_COMMAND_PARAM_MEMREF       sMemref;
    139 
    140 } SCHANNEL6_COMMAND_PARAM;
    141 
    142 typedef struct
    143 {
    144    uint32_t a;
    145    uint32_t b;
    146 } SCHANNEL6_ANSWER_PARAM_VALUE;
    147 
    148 typedef struct
    149 {
    150    uint32_t _ignored;
    151    uint32_t nSize;
    152 } SCHANNEL6_ANSWER_PARAM_SIZE;
    153 
    154 typedef union
    155 {
    156    SCHANNEL6_ANSWER_PARAM_SIZE  sSize;
    157    SCHANNEL6_ANSWER_PARAM_VALUE sValue;
    158 } SCHANNEL6_ANSWER_PARAM;
    159 
    160 /**
    161  * Command messages.
    162  */
    163  typedef struct
    164 {
    165    uint8_t                       nMessageSize;
    166    uint8_t                       nMessageType;
    167    uint16_t                      nMessageInfo;
    168    uint32_t                      nOperationID; /* an opaque Normal World identifier for the operation */
    169 }SCHANNEL6_COMMAND_HEADER;
    170 
    171 typedef struct
    172 {
    173    uint8_t                       nMessageSize;
    174    uint8_t                       nMessageType;
    175    uint16_t                      nMessageInfo_RFU;
    176    uint32_t                      nOperationID; /* an opaque Normal World identifier for the operation */
    177    uint32_t                      nDeviceContextID; /* an opaque Normal World identifier for the device context */
    178 }SCHANNEL6_CREATE_DEVICE_CONTEXT_COMMAND;
    179 
    180 typedef struct
    181 {
    182    uint8_t                       nMessageSize;
    183    uint8_t                       nMessageType;
    184    uint16_t                      nParamTypes;
    185    uint32_t                      nOperationID; /* an opaque Normal World identifier for the operation */
    186    S_HANDLE                      hDeviceContext;
    187    S_HANDLE                      hClientSession;
    188    uint64_t                      sTimeout;
    189    uint32_t                      nCancellationID;
    190    uint32_t                      nClientCommandIdentifier;
    191    SCHANNEL6_COMMAND_PARAM       sParams[4];
    192 }SCHANNEL6_INVOKE_CLIENT_COMMAND_COMMAND;
    193 
    194 typedef struct
    195 {
    196    uint8_t                       nMessageSize;
    197    uint8_t                       nMessageType;
    198    uint16_t                      nParamTypes;
    199    uint32_t                      nOperationID; /* an opaque Normal World identifier for the operation */
    200    S_HANDLE                      hDeviceContext;
    201    uint32_t                      nCancellationID;
    202    SCTIME                        sTimeout;
    203    S_UUID                        sDestinationUUID;
    204    SCHANNEL6_COMMAND_PARAM       sParams[4];
    205    uint32_t                      nLoginType;
    206    uint8_t                       sLoginData[20]; /* Size depends on the login type. */
    207 
    208 }SCHANNEL6_OPEN_CLIENT_SESSION_COMMAND;
    209 
    210 typedef struct
    211 {
    212    uint8_t                       nMessageSize;
    213    uint8_t                       nMessageType;
    214    uint16_t                      nMemoryFlags;
    215    uint32_t                      nOperationID; /* an opaque Normal World identifier for the operation */
    216    S_HANDLE                      hDeviceContext;
    217    uint32_t                      nBlockID;
    218    uint32_t                      nSharedMemSize;
    219    uint32_t                      nSharedMemStartOffset;
    220    uint32_t                      nSharedMemDescriptors[SCHANNEL6_MAX_DESCRIPTORS_PER_REGISTERED_SHARED_MEM];
    221 
    222 }SCHANNEL6_REGISTER_SHARED_MEMORY_COMMAND;
    223 
    224 typedef struct
    225 {
    226    uint8_t                       nMessageSize;
    227    uint8_t                       nMessageType;
    228    uint16_t                      nMessageInfo_RFU;
    229    uint32_t                      nOperationID; /* an opaque Normal World identifier for the operation */
    230    S_HANDLE                      hDeviceContext;
    231    S_HANDLE                      hBlock;
    232 
    233 }SCHANNEL6_RELEASE_SHARED_MEMORY_COMMAND;
    234 
    235 typedef struct
    236 {
    237    uint8_t                       nMessageSize;
    238    uint8_t                       nMessageType;
    239    uint16_t                      nMessageInfo_RFU;
    240    uint32_t                      nOperationID; /* an opaque Normal World identifier for the operation */
    241    S_HANDLE                      hDeviceContext;
    242    S_HANDLE                      hClientSession;
    243    uint32_t                      nCancellationID;
    244 
    245 }SCHANNEL6_CANCEL_CLIENT_OPERATION_COMMAND;
    246 
    247 typedef struct
    248 {
    249    uint8_t                       nMessageSize;
    250    uint8_t                       nMessageType;
    251    uint16_t                      nMessageInfo_RFU;
    252    uint32_t                      nOperationID; /* an opaque Normal World identifier for the operation */
    253    S_HANDLE                      hDeviceContext;
    254    S_HANDLE                      hClientSession;
    255 
    256 }SCHANNEL6_CLOSE_CLIENT_SESSION_COMMAND;
    257 
    258 typedef struct
    259 {
    260    uint8_t                       nMessageSize;
    261    uint8_t                       nMessageType;
    262    uint16_t                      nMessageInfo_RFU;
    263    uint32_t                      nOperationID; /* an opaque Normal World identifier for the operation */
    264    S_HANDLE                      hDeviceContext;
    265 
    266 }SCHANNEL6_DESTROY_DEVICE_CONTEXT_COMMAND;
    267 
    268 #define SCHANNEL6_MANAGEMENT_COMMAND_HIBERNATE            1
    269 #define SCHANNEL6_MANAGEMENT_COMMAND_SHUTDOWN             2
    270 #define SCHANNEL6_MANAGEMENT_COMMAND_PREPARE_FOR_CORE_OFF 3
    271 #define SCHANNEL6_MANAGEMENT_COMMAND_RESUME_FROM_CORE_OFF 4
    272 
    273 typedef struct
    274 {
    275    uint8_t                       nMessageSize;
    276    uint8_t                       nMessageType;
    277    uint16_t                      nCommand;
    278    uint32_t                      nOperationID; /* an opaque Normal World identifier for the operation */
    279    uint32_t                      nW3BSize;
    280    uint32_t                      nW3BStartOffset;
    281 #ifdef SCHANNEL_TRUSTZONE
    282    uint32_t                      nSharedMemDescriptors[128];
    283 #endif
    284 }SCHANNEL6_MANAGEMENT_COMMAND;
    285 
    286 typedef union
    287 {
    288    SCHANNEL6_COMMAND_HEADER                            sHeader;
    289    SCHANNEL6_CREATE_DEVICE_CONTEXT_COMMAND             sCreateDeviceContext;
    290    SCHANNEL6_DESTROY_DEVICE_CONTEXT_COMMAND            sDestroyDeviceContext;
    291    SCHANNEL6_OPEN_CLIENT_SESSION_COMMAND               sOpenClientSession;
    292    SCHANNEL6_CLOSE_CLIENT_SESSION_COMMAND              sCloseClientSession;
    293    SCHANNEL6_REGISTER_SHARED_MEMORY_COMMAND            sRegisterSharedMemory;
    294    SCHANNEL6_RELEASE_SHARED_MEMORY_COMMAND             sReleaseSharedMemory;
    295    SCHANNEL6_INVOKE_CLIENT_COMMAND_COMMAND             sInvokeClientCommand;
    296    SCHANNEL6_CANCEL_CLIENT_OPERATION_COMMAND           sCancelClientOperation;
    297    SCHANNEL6_MANAGEMENT_COMMAND                        sManagement;
    298 
    299 }SCHANNEL6_COMMAND;
    300 
    301 /**
    302  * Answer messages.
    303  */
    304 typedef struct
    305 {
    306    uint8_t                   nMessageSize;
    307    uint8_t                   nMessageType;
    308    uint16_t                  nMessageInfo;
    309    uint32_t                  nOperationID;
    310    uint32_t                  nErrorCode;
    311 }SCHANNEL6_ANSWER_HEADER;
    312 
    313 typedef struct
    314 {
    315    uint8_t                   nMessageSize;
    316    uint8_t                   nMessageType;
    317    uint16_t                  nMessageInfo_RFU;
    318    uint32_t                  nOperationID;
    319    uint32_t                  nErrorCode;
    320    S_HANDLE                  hDeviceContext;
    321 }SCHANNEL6_CREATE_DEVICE_CONTEXT_ANSWER;
    322 
    323 typedef struct
    324 {
    325    uint8_t                   nMessageSize;
    326    uint8_t                   nMessageType;
    327    uint8_t                   nReturnOrigin;
    328    uint8_t                   __nReserved;
    329    uint32_t                  nOperationID;
    330    uint32_t                  nErrorCode;
    331    SCHANNEL6_ANSWER_PARAM    sAnswers[4];
    332 
    333 }SCHANNEL6_INVOKE_CLIENT_COMMAND_ANSWER;
    334 
    335 typedef struct
    336 {
    337    uint8_t                   nMessageSize;
    338    uint8_t                   nMessageType;
    339    uint8_t                   nReturnOrigin;
    340    uint8_t                   __nReserved;
    341    uint32_t                  nOperationID;
    342    uint32_t                  nErrorCode;
    343    S_HANDLE                  hClientSession;
    344    SCHANNEL6_ANSWER_PARAM    sAnswers[4];
    345 }SCHANNEL6_OPEN_CLIENT_SESSION_ANSWER;
    346 
    347 typedef struct
    348 {
    349    uint8_t                   nMessageSize;
    350    uint8_t                   nMessageType;
    351    uint16_t                  nMessageInfo_RFU;
    352    uint32_t                  nOperationID;
    353    uint32_t                  nErrorCode;
    354 }SCHANNEL6_CLOSE_CLIENT_SESSION_ANSWER;
    355 
    356 typedef struct
    357 {
    358    uint8_t                   nMessageSize;
    359    uint8_t                   nMessageType;
    360    uint16_t                  nMessageInfo_RFU;
    361    uint32_t                  nOperationID;
    362    uint32_t                  nErrorCode;
    363    S_HANDLE                  hBlock;
    364 
    365 }SCHANNEL6_REGISTER_SHARED_MEMORY_ANSWER;
    366 
    367 typedef struct
    368 {
    369    uint8_t                   nMessageSize;
    370    uint8_t                   nMessageType;
    371    uint16_t                  nMessageInfo_RFU;
    372    uint32_t                  nOperationID;
    373    uint32_t                  nErrorCode;
    374    uint32_t                  nBlockID;
    375 
    376 }SCHANNEL6_RELEASE_SHARED_MEMORY_ANSWER;
    377 
    378 typedef struct
    379 {
    380    uint8_t                   nMessageSize;
    381    uint8_t                   nMessageType;
    382    uint16_t                  nMessageInfo_RFU;
    383    uint32_t                  nOperationID;
    384    uint32_t                  nErrorCode;
    385    uint32_t                  nDeviceContextID;
    386 
    387 }SCHANNEL6_DESTROY_DEVICE_CONTEXT_ANSWER;
    388 
    389 typedef struct
    390 {
    391    uint8_t                   nMessageSize;
    392    uint8_t                   nMessageType;
    393    uint16_t                  nMessageInfo_RFU;
    394    uint32_t                  nOperationID;
    395    uint32_t                  nErrorCode;
    396 
    397 }SCHANNEL6_CANCEL_CLIENT_OPERATION_ANSWER;
    398 
    399 typedef struct
    400 {
    401    uint8_t                   nMessageSize;
    402    uint8_t                   nMessageType;
    403    uint16_t                  nMessageInfo_RFU;
    404    uint32_t                  nOperationID;
    405    uint32_t                  nErrorCode;
    406 
    407 }SCHANNEL6_MANAGEMENT_ANSWER;
    408 
    409 typedef union
    410 {
    411    SCHANNEL6_ANSWER_HEADER                    sHeader;
    412    SCHANNEL6_CREATE_DEVICE_CONTEXT_ANSWER     sCreateDeviceContext;
    413    SCHANNEL6_OPEN_CLIENT_SESSION_ANSWER       sOpenClientSession;
    414    SCHANNEL6_REGISTER_SHARED_MEMORY_ANSWER    sRegisterSharedMemory;
    415    SCHANNEL6_RELEASE_SHARED_MEMORY_ANSWER     sReleaseSharedMemory;
    416    SCHANNEL6_INVOKE_CLIENT_COMMAND_ANSWER     sInvokeClientCommand;
    417    SCHANNEL6_DESTROY_DEVICE_CONTEXT_ANSWER    sDestroyDeviceContext;
    418    SCHANNEL6_CANCEL_CLIENT_OPERATION_ANSWER   sCancelClientOperation;
    419    SCHANNEL6_CLOSE_CLIENT_SESSION_ANSWER      sCloseClientSession;
    420    SCHANNEL6_MANAGEMENT_ANSWER                sManagement;
    421 
    422 }SCHANNEL6_ANSWER;
    423 
    424 
    425 #endif /* __SCHANNEL6_PROTOCOL_H__ */
    426