1 /* 2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this list of 9 * conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 * of conditions and the following disclaimer in the documentation and/or other materials 13 * provided with the distribution. 14 * 15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 16 * to endorse or promote products derived from this software without specific prior written 17 * permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef _TC_NS_CLIENT_H_ 33 #define _TC_NS_CLIENT_H_ 34 35 #include <linux/fs.h> 36 #include "teek_client_type.h" 37 38 #ifdef SECURITY_AUTH_ENHANCE 39 #define SCRAMBLING_KEY_LEN 4 40 #define TOKEN_BUFFER_LEN 42 /* token(32byte) + timestamp(8byte) + kernal_api(1byte) + sync(1byte) */ 41 #define TIMESTAMP_BUFFER_INDEX 32 42 #define KERNAL_API_INDEX 40 43 #define SYNC_INDEX 41 44 #define UUID_LEN 16 45 #define PARAM_NUM 4 46 #define ADDR_TRANS_NUM 32 47 #define TEE_PARAM_ONE 0 48 #define TEE_PARAM_TWO 1 49 #define TEE_PARAM_THREE 2 50 #define TEE_PARAM_FOUR 3 51 52 #define TIMESTAMP_LEN_DEFAULT \ 53 ((KERNAL_API_INDEX) - (TIMESTAMP_BUFFER_INDEX)) 54 #define KERNAL_API_LEN \ 55 ((TOKEN_BUFFER_LEN) - (KERNAL_API_INDEX)) 56 #define TIMESTAMP_SAVE_INDEX 16 57 #endif 58 59 #ifndef ZERO_SIZE_PTR 60 #define ZERO_SIZE_PTR ((void *)16) 61 #define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= (unsigned long)ZERO_SIZE_PTR) 62 #endif 63 64 typedef struct { 65 unsigned int method; 66 unsigned int mdata; 67 } TcNsClientLogin; 68 69 typedef union { 70 struct { 71 unsigned int buffer; 72 unsigned int bufferH; 73 unsigned int offset; 74 unsigned int offsetH; 75 unsigned int sizeAddr; 76 unsigned int sizeAddrH; 77 } memref; 78 struct { 79 unsigned int aAddr; 80 unsigned int aHaddr; 81 unsigned int bAddr; 82 unsigned int bHaddr; 83 } value; 84 } TcNsClientParam; 85 86 typedef struct { 87 int code; 88 unsigned int origin; 89 } TcNsClientReturn; 90 91 typedef struct { 92 unsigned char uuid[UUID_LEN]; 93 unsigned int sessionId; 94 unsigned int cmdId; 95 TcNsClientReturn returns; 96 TcNsClientLogin login; 97 TcNsClientParam params[PARAM_NUM]; 98 unsigned int paramTypes; 99 unsigned char started; 100 #ifdef SECURITY_AUTH_ENHANCE 101 void* teecToken; 102 unsigned int tokenLen; 103 #endif 104 unsigned int callingPid; 105 unsigned int fileSize; 106 union { 107 char *fileBuffer; 108 unsigned long long fileAddr; 109 }; 110 } TcNsClientContext; 111 112 typedef struct { 113 unsigned int seconds; 114 unsigned int millis; 115 } TcNsClientTime; 116 117 enum SecfileTypeT { 118 LOAD_TA = 0, 119 LOAD_SERVICE, 120 LOAD_LIB, 121 }; 122 123 struct LoadSecfileIoctlStruct { 124 enum SecfileTypeT secfileType; 125 unsigned char uuid[UUID_LEN]; 126 unsigned int fileSize; 127 union { 128 char *fileBuffer; 129 unsigned long long file_addr; 130 }; 131 }; 132 133 struct AgentIoctlArgs { 134 unsigned int id; 135 unsigned int bufferSize; 136 union { 137 void *buffer; 138 unsigned long long addr; 139 }; 140 }; 141 142 #define TST_CMD_01 1 143 #define TST_CMD_02 2 144 #define TST_CMD_03 3 145 #define TST_CMD_04 4 146 #define TST_CMD_05 5 147 148 #define MAX_SHA_256_SZ 32 149 150 #define TC_NS_CLIENT_IOCTL_SES_OPEN_REQ \ 151 _IOW(TC_NS_CLIENT_IOC_MAGIC, 1, TcNsClientContext) 152 #define TC_NS_CLIENT_IOCTL_SES_CLOSE_REQ \ 153 _IOWR(TC_NS_CLIENT_IOC_MAGIC, 2, TcNsClientContext) 154 #define TC_NS_CLIENT_IOCTL_SEND_CMD_REQ \ 155 _IOWR(TC_NS_CLIENT_IOC_MAGIC, 3, TcNsClientContext) 156 #define TC_NS_CLIENT_IOCTL_SHRD_MEM_RELEASE \ 157 _IOWR(TC_NS_CLIENT_IOC_MAGIC, 4, unsigned int) 158 #define TC_NS_CLIENT_IOCTL_WAIT_EVENT \ 159 _IO(TC_NS_CLIENT_IOC_MAGIC, 5) 160 #define TC_NS_CLIENT_IOCTL_SEND_EVENT_RESPONSE \ 161 _IO(TC_NS_CLIENT_IOC_MAGIC, 6) 162 #define TC_NS_CLIENT_IOCTL_REGISTER_AGENT \ 163 _IOWR(TC_NS_CLIENT_IOC_MAGIC, 7, struct AgentIoctlArgs) 164 #define TC_NS_CLIENT_IOCTL_UNREGISTER_AGENT \ 165 _IO(TC_NS_CLIENT_IOC_MAGIC, 8) 166 #define TC_NS_CLIENT_IOCTL_LOAD_APP_REQ \ 167 _IOWR(TC_NS_CLIENT_IOC_MAGIC, 9, struct LoadSecfileIoctlStruct) 168 #define TC_NS_CLIENT_IOCTL_NEED_LOAD_APP \ 169 _IOWR(TC_NS_CLIENT_IOC_MAGIC, 10, TcNsClientContext) 170 #define TC_NS_CLIENT_IOCTL_ALLOC_EXCEPTING_MEM \ 171 _IOWR(TC_NS_CLIENT_IOC_MAGIC, 12, unsigned int) 172 #define TC_NS_CLIENT_IOCTL_CANCEL_CMD_REQ \ 173 _IOWR(TC_NS_CLIENT_IOC_MAGIC, 13, TcNsClientContext) 174 #define TC_NS_CLIENT_IOCTL_LOGIN \ 175 _IO(TC_NS_CLIENT_IOC_MAGIC, 14) 176 #define TC_NS_CLIENT_IOCTL_TST_CMD_REQ \ 177 _IOWR(TC_NS_CLIENT_IOC_MAGIC, 15, int) 178 #define TC_NS_CLIENT_IOCTL_TUI_EVENT \ 179 _IOWR(TC_NS_CLIENT_IOC_MAGIC, 16, int) 180 #define TC_NS_CLIENT_IOCTL_SYC_SYS_TIME \ 181 _IOWR(TC_NS_CLIENT_IOC_MAGIC, 17, TcNsClientTime) 182 #define TC_NS_CLIENT_IOCTL_SET_NATIVECA_IDENTITY \ 183 _IOWR(TC_NS_CLIENT_IOC_MAGIC, 18, int) 184 #define TC_NS_CLIENT_IOCTL_LOAD_TTF_FILE_AND_NOTCH_HEIGHT \ 185 _IOWR(TC_NS_CLIENT_IOC_MAGIC, 19, unsigned int) 186 #define TC_NS_CLIENT_IOCTL_LATEINIT \ 187 _IO(TC_NS_CLIENT_IOC_MAGIC, 20) 188 #define TC_NS_CLIENT_IOCTL_GET_TEE_VERSION \ 189 _IOWR(TC_NS_CLIENT_IOC_MAGIC, 21, unsigned int) 190 #define TC_NS_CLIENT_IOCTL_UNMAP_SHARED_MEM \ 191 _IOWR(TC_NS_CLIENT_IOC_MAGIC, 22, unsigned int) 192 193 #endif 194