You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
301 lines
14 KiB
301 lines
14 KiB
/*
|
|
* Copyright (c) Hisilicon Technologies Co., Ltd. 2018-2019. All rights reserved.
|
|
* Description: head file of hidl for tee
|
|
* Author: NameMagic
|
|
* Create: 2018-03-10
|
|
*/
|
|
|
|
#ifndef VENDOR_HARDWARE_LIBTEEC_V3_0_LIBTEEC_H
|
|
#define VENDOR_HARDWARE_LIBTEEC_V3_0_LIBTEEC_H
|
|
|
|
#include <hidlmemory/mapping.h>
|
|
#include <android/hidl/memory/1.0/IMemory.h>
|
|
#include <private/android_filesystem_config.h>
|
|
#include <hwbinder/IPCThreadState.h>
|
|
#include <dlfcn.h>
|
|
#include <vendor/huanglong/hardware/libteec/3.0/ILibteecGlobal.h>
|
|
#include <vendor/huanglong/hardware/libteec/3.0/ILibteecGlobalNotify.h>
|
|
#include <hidl/MQDescriptor.h>
|
|
#include <hidl/Status.h>
|
|
#include <cutils/list.h>
|
|
#include <cutils/sockets.h>
|
|
#include "tee_client_type.h"
|
|
#include "tee_client_inner.h"
|
|
|
|
namespace vendor {
|
|
namespace huanglong {
|
|
namespace hardware {
|
|
namespace libteec {
|
|
namespace V3_0 {
|
|
namespace implementation {
|
|
using::android::hardware::Return;
|
|
using::android::hardware::hidl_vec;
|
|
using::android::hardware::hidl_string;
|
|
using::vendor::huanglong::hardware::libteec::V3_0::ILibteecGlobal;
|
|
using::vendor::huanglong::hardware::libteec::V3_0::ILibteecGlobalNotify;
|
|
using::android::sp;
|
|
using::android::hardware::hidl_death_recipient;
|
|
using::android::Mutex;
|
|
|
|
const static int MAX_CXTCNT_ONECA = 5;
|
|
const static int BUF_MAX_SIZE = 4096;
|
|
const static int PARAM_NUM = 4;
|
|
#define SYS_HASH_FILE_MAX_SIZE (16 * 1024)
|
|
|
|
typedef enum {
|
|
SYSTEM_CA = 1,
|
|
VENDOR_CA,
|
|
APP_CA,
|
|
MAX_CA,
|
|
} CaType;
|
|
|
|
typedef struct {
|
|
int callingPid;
|
|
uint32_t opsCnt;
|
|
int32_t cxtFd[MAX_CXTCNT_ONECA];
|
|
struct listnode procdataHead;
|
|
} DaemonProcdata;
|
|
|
|
typedef struct {
|
|
int callingPid;
|
|
int tid;
|
|
struct listnode tidHead;
|
|
} TidData;
|
|
|
|
typedef struct {
|
|
uint8_t certs[BUF_MAX_SIZE];
|
|
CaType type;
|
|
uid_t uid;
|
|
pid_t pid;
|
|
int fromHidlSide;
|
|
} CaAuthInfo;
|
|
|
|
typedef struct {
|
|
uint8_t certs[BUF_MAX_SIZE];
|
|
pid_t pid;
|
|
} CaCertInfo;
|
|
|
|
typedef struct {
|
|
CaCertInfo certInfo;
|
|
struct listnode authNode;
|
|
} CaLoginNode;
|
|
|
|
typedef struct {
|
|
int32_t cmdId;
|
|
int32_t pid;
|
|
int32_t ret;
|
|
int32_t originRet;
|
|
TEEC_Operation *operationPtr;
|
|
TEEC_ContextHidl *outContextPtr;
|
|
TEEC_Session *outSessionPtr;
|
|
} InOutPara;
|
|
|
|
typedef struct {
|
|
uint32_t offset;
|
|
uint32_t memSize;
|
|
uint32_t totalSize;
|
|
uint32_t paraType;
|
|
} InputPara;
|
|
|
|
typedef enum {
|
|
TEE_HIDL_FAILURE = -1,
|
|
TEE_HIDL_SUCCESS = 0,
|
|
} LibteecErrCode;
|
|
|
|
typedef struct {
|
|
uint32_t fileSize; /* xml file size */
|
|
uint8_t fileBuf[SYS_HASH_FILE_MAX_SIZE]; /* read xml file data to this buffer */
|
|
} TEEC_XmlParameter;
|
|
|
|
/*
|
|
* GP standard Interfaces
|
|
*/
|
|
using InitializeContextFunc = int32_t (*)(const char *name, TEEC_ContextHidl *context,
|
|
const int32_t type, bool fromHidl, CaAuthInfo *authInfo);
|
|
using OpenSessionFunc = int32_t (*)(int pid, const TaFileInfo *taFile, TEEC_ContextHidl *context,
|
|
TEEC_Session *session, const TEEC_UUID *destination, uint32_t connectionMethod,
|
|
const void *connectionData, TEEC_Operation *operation, uint32_t *returnOrigin);
|
|
using InvokeCommandFunc = int32_t (*)(TEEC_ContextHidl *context, TEEC_Session *session,
|
|
uint32_t commandID, TEEC_Operation *operation, uint32_t *returnOrigin);
|
|
using CloseSessionFunc = void (*)(TEEC_Session *session, TEEC_ContextHidl *context);
|
|
using RegisterSharedMemoryFunc = int32_t (*)(TEEC_ContextHidl *context, TEEC_SharedMemoryHidl *sharedMem);
|
|
using AllocateSharedMemoryFunc = int32_t (*)(TEEC_ContextHidl *context, TEEC_SharedMemoryHidl *sharedMem);
|
|
using ReleaseSharedMemoryFunc = void (*)(TEEC_SharedMemoryHidl *sharedMem);
|
|
using requestCancellation_f = void (*)(TEEC_Operation *operation);
|
|
using ExtTuiSendEventFunc = int32_t (*)(const TEEC_TUI_Parameter *tuiParam, CaAuthInfo *authInfo);
|
|
using GetTEEVersionFunc = uint32_t (*)();
|
|
using ExtSendSysHashXmlFunc = int32_t (*)(const TEEC_XmlParameter *halXmlPtr, CaAuthInfo *authInfo);
|
|
using GetBnContextFunc = TEEC_ContextHidl *(*)(const TEEC_Context *context);
|
|
using PutBnContextFunc = void (*)(TEEC_ContextHidl *context);
|
|
using FindAndRemoveBnContextFunc = TEEC_ContextHidl *(*)(const TEEC_Context *context);
|
|
using GetBnSessionFunc = TEEC_Session *(*)(const TEEC_Session *session, TEEC_ContextHidl *context);
|
|
using PutBnSessionFunc = void (*)(TEEC_Session *session);
|
|
using FindAndRemoveBnSessionFunc = TEEC_Session *(*)(const TEEC_Session *session, TEEC_ContextHidl *context);
|
|
using GetBnShmByOffsetFunc = TEEC_SharedMemoryHidl *(*)(uint32_t shmOffset, TEEC_ContextHidl *context);
|
|
using PutBnShmFunc = void (*)(TEEC_SharedMemoryHidl *shrMem);
|
|
using SendSecfileFunc = int32_t (*)(const char *path, int tzFd, const FILE *fp);
|
|
|
|
struct LibteecGlobal : public ILibteecGlobal, public hidl_death_recipient {
|
|
LibteecGlobal()
|
|
: mHandle(nullptr),
|
|
initializeContextProxy(nullptr),
|
|
openSessionProxy(nullptr),
|
|
invokeCommandProxy(nullptr),
|
|
closeSessionProxy(nullptr),
|
|
registerSharedMemoryProxy(nullptr),
|
|
allocateSharedMemoryProxy(nullptr),
|
|
releaseSharedMemoryProxy(nullptr),
|
|
extTuiSendEventProxy(nullptr),
|
|
getTEEVersionProxy(nullptr),
|
|
extSendSysHashXmlProxy(nullptr),
|
|
getBnContextProxy(nullptr),
|
|
putBnContextProxy(nullptr),
|
|
findAndRemoveBnContextProxy(nullptr),
|
|
getBnSessionProxy(nullptr),
|
|
putBnSessionProxy(nullptr),
|
|
findAndRemoveBnSessionProxy(nullptr),
|
|
getBnShmByOffsetProxy(nullptr),
|
|
putBnShmProxy(nullptr),
|
|
sendSecfileProxy(nullptr)
|
|
{
|
|
ALOGD("Init LibteecGlobal!\n");
|
|
}
|
|
virtual ~LibteecGlobal();
|
|
|
|
virtual Return<void> initializeContext(const hidl_string &name,
|
|
const hidl_vec<uint8_t> &caInfo,
|
|
initializeContext_cb hidlCallBackPtr) override;
|
|
|
|
virtual Return<void> finalizeContext(int32_t pid, const hidl_vec<uint8_t> &halCxtPtr) override;
|
|
|
|
virtual Return<void> openSession(int32_t pid, const hidl_vec<uint8_t> &halCxtPtr,
|
|
const android::hardware::hidl_handle &handle,
|
|
const hidl_string &taPath,
|
|
const hidl_vec<uint8_t> &halUuidPtr, uint32_t halConnMth,
|
|
const hidl_vec<uint8_t> &haConnData, const hidl_vec<uint8_t> &halOptPtr,
|
|
const android::hardware::hidl_memory &opMem,
|
|
openSession_cb hidlCallBackPtr) override;
|
|
|
|
virtual Return<void> closeSession(int32_t pid, const hidl_vec<uint8_t> &halCxtPtr,
|
|
const hidl_vec<uint8_t> &halSessPtr) override;
|
|
|
|
virtual Return<void> invokeCommandHidl(int32_t pid, const hidl_vec<uint8_t> &halCxtPtr,
|
|
const hidl_vec<uint8_t> &halSessPtr,
|
|
uint32_t cmdId, const hidl_vec<uint8_t> &halOptPtr,
|
|
const android::hardware::hidl_memory &opMem,
|
|
invokeCommandHidl_cb hidlCallBackPtr) override;
|
|
|
|
virtual Return<void> registerSharedMemory(int32_t pid, const hidl_vec<uint8_t> &halCxtPtr,
|
|
const hidl_vec<uint8_t> &halMemPtr,
|
|
registerSharedMemory_cb hidlCallBackPtr) override;
|
|
|
|
virtual Return<void> allocateSharedMemory(int32_t pid, const hidl_vec<uint8_t> &halCxtPtr,
|
|
const hidl_vec<uint8_t> &halMemPtr,
|
|
allocateSharedMemory_cb hidlCallBackPtr) override;
|
|
|
|
virtual Return<void> releaseSharedMemory(int32_t pid, const hidl_vec<uint8_t> &halCxtPtr,
|
|
const hidl_vec<uint8_t> &halMemPtr,
|
|
uint32_t shmOffset) override;
|
|
|
|
virtual Return<void> requestCancellation(const hidl_vec<uint8_t> &halOptPtr) override;
|
|
|
|
virtual Return<int32_t> extTuiSendEvent(int32_t pid, int32_t uid,
|
|
const hidl_vec<uint8_t> &halTuiPtr) override;
|
|
|
|
virtual Return<int32_t> handleMultiUserMsg(const hidl_vec<uint8_t> &multiUserRecvMsg) override;
|
|
|
|
void serviceDied(uint64_t cookie, const::android::wp<::android::hidl::base::V1_0::IBase> &who) override;
|
|
virtual Return<void> processCaDied(int32_t pid) override;
|
|
|
|
virtual Return<void> setCallBack(const ::android::sp<ILibteecGlobalNotify> ¬ify) override;
|
|
virtual Return<uint32_t> iGetTEEVersionHidl() override;
|
|
virtual Return<int32_t> extSendSystemHashXml(const hidl_vec<uint8_t> &halXmlPtr,
|
|
const hidl_vec<uint8_t> &authInfo) override;
|
|
|
|
virtual Return<int32_t> secfileSendEvent(int32_t pid, const android::hardware::hidl_handle &handle,
|
|
const hidl_string &libPath,
|
|
const hidl_vec<uint8_t> &halCxtPtr,
|
|
const hidl_vec<uint8_t> &halSessPtr) override;
|
|
|
|
private:
|
|
virtual Return<DaemonProcdata *> CallGetProcDataPtr(int pid);
|
|
virtual Return<int32_t> CallInitializeContextProxy(const hidl_string &name,
|
|
CaAuthInfo *authInfo, TEEC_ContextHidl **outHidlContext);
|
|
virtual Return<int32_t> CallFinalizeContextProxy(const TEEC_Context *contextPtr);
|
|
virtual Return<int32_t> CallGetBnContextProxy(const hidl_vec<uint8_t> &halCxtPtr,
|
|
int pid, TEEC_Session **outHidlSession, TEEC_ContextHidl **outHidlContext);
|
|
virtual Return<int32_t> SubOpenSession(const TaFileInfo *taFile,
|
|
const hidl_vec<uint8_t> &halOptPtr, const android::hardware::hidl_memory &opMem,
|
|
const hidl_vec<uint8_t> &halUuidPtr, const hidl_vec<uint8_t> &haConnData, InOutPara *paraInOut);
|
|
virtual Return<int32_t> CallOpenSessionProxy(const hidl_vec<uint8_t> &halUuidPtr,
|
|
const TaFileInfo *taFile, TEEC_ContextHidl *outContext, TEEC_Session *outSession,
|
|
InOutPara *paraInOut, const hidl_vec<uint8_t> &haConnData);
|
|
virtual Return<void> CallCloseSessionProxy(TEEC_Session *outSession,
|
|
TEEC_ContextHidl *outContext, int pid);
|
|
virtual Return<int32_t> CallGetBnProxy(int pid, const hidl_vec<uint8_t> &halCxtPtr,
|
|
const hidl_vec<uint8_t> &halSessPtr, TEEC_ContextHidl **outHidlContext, TEEC_Session **outHidlSession);
|
|
virtual Return<int32_t> SubInvokeCommand(const hidl_vec<uint8_t> &halOptPtr,
|
|
const android::hardware::hidl_memory &opMem, InOutPara *paraInOut);
|
|
virtual Return<int32_t> CallInvokeCommandProxy(TEEC_ContextHidl *outContext,
|
|
TEEC_Session *outSession,
|
|
TEEC_Operation *operation,
|
|
InOutPara *paraInOut);
|
|
virtual Return<int32_t> CallRegisterSharedMemoryProxy(const hidl_vec<uint8_t> &halMemPtr,
|
|
TEEC_ContextHidl *outContext,
|
|
TEEC_SharedMemoryHidl *outRegShm);
|
|
virtual Return<int32_t> GetSharedMemoryContextAndFd(const hidl_vec<uint8_t> &halCxtPtr,
|
|
int32_t pid, TEEC_ContextHidl **outContext, int *fd);
|
|
virtual Return<int32_t> CallAllocateSharedMemoryProxy(const hidl_vec<uint8_t> &halMemPtr,
|
|
TEEC_ContextHidl *outContext,
|
|
TEEC_SharedMemoryHidl *outAllocShm);
|
|
virtual Return<void> CallReleaseSharedMemoryProxy(const hidl_vec<uint8_t> &halCxtPtr,
|
|
TEEC_SharedMemoryHidl *outShm);
|
|
virtual Return<int32_t> CheckInputPidUid(int pid, uid_t uid);
|
|
virtual Return<TEEC_Result> DecodeHidlMemory(TEEC_ContextHidl *outContext, TEEC_Operation *operation,
|
|
TEEC_SharedMemory *shm, TEEC_SharedMemoryHidl *shmHidl[], uint32_t shmSize, uint8_t *data, size_t memSize);
|
|
virtual Return<TEEC_Result> FillShareMemoryBuffer(TEEC_SharedMemory *shareMemBuf,
|
|
TEEC_SharedMemoryHidl **shmHidl, uint8_t *data, InputPara *inputPara,
|
|
TEEC_ContextHidl *outContext, TEEC_Parameter *params);
|
|
virtual void PutAllocShrMem(TEEC_SharedMemoryHidl *shmHidl[], uint32_t shmNum);
|
|
virtual Return<FILE *> GetFpFromHandle(const android::hardware::hidl_handle &handle,
|
|
native_handle_t *&tempHandle) const;
|
|
virtual Return<void> CleanProcDataForOneCa(DaemonProcdata *procData);
|
|
virtual Return<int32_t> CheckAndOpenHandle();
|
|
bool IsValidContext(const TEEC_Context *context, int pid);
|
|
bool IsValidContextWithoutLock(const TEEC_Context *context, int pid);
|
|
virtual Return<int32_t> GetOperationFromHidlVec(const hidl_vec<uint8_t> &halOptPtr,
|
|
TEEC_Operation *operation);
|
|
void *mHandle;
|
|
Mutex mHandleLock;
|
|
Mutex mProcDataLock;
|
|
InitializeContextFunc initializeContextProxy;
|
|
OpenSessionFunc openSessionProxy;
|
|
InvokeCommandFunc invokeCommandProxy;
|
|
CloseSessionFunc closeSessionProxy;
|
|
RegisterSharedMemoryFunc registerSharedMemoryProxy;
|
|
AllocateSharedMemoryFunc allocateSharedMemoryProxy;
|
|
ReleaseSharedMemoryFunc releaseSharedMemoryProxy;
|
|
ExtTuiSendEventFunc extTuiSendEventProxy;
|
|
GetTEEVersionFunc getTEEVersionProxy;
|
|
ExtSendSysHashXmlFunc extSendSysHashXmlProxy;
|
|
GetBnContextFunc getBnContextProxy;
|
|
PutBnContextFunc putBnContextProxy;
|
|
FindAndRemoveBnContextFunc findAndRemoveBnContextProxy;
|
|
GetBnSessionFunc getBnSessionProxy;
|
|
PutBnSessionFunc putBnSessionProxy;
|
|
FindAndRemoveBnSessionFunc findAndRemoveBnSessionProxy;
|
|
GetBnShmByOffsetFunc getBnShmByOffsetProxy;
|
|
PutBnShmFunc putBnShmProxy;
|
|
SendSecfileFunc sendSecfileProxy;
|
|
};
|
|
|
|
extern "C" ILibteecGlobal *HIDL_FETCH_ILibteecGlobal(const char *name);
|
|
} // namespace implementation
|
|
} // namespace V3_0
|
|
} // namespace libteec
|
|
} // namespace hardware
|
|
} // namespace huanglong
|
|
} // namespace vendor
|
|
|
|
#endif // VENDOR_HARDWARE_LIBTEEC_V3_0_LIBTEEC_H
|