1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef IPC_ADAPT_H 17 #define IPC_ADAPT_H 18 19 #include <stdint.h> 20 #include "device_auth.h" 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 #define MAX_REQUEST_PARAMS_NUM 8 27 #define CB_TYPE_DEV_AUTH 1 28 #define CB_TYPE_TMP_DEV_AUTH 2 29 #define CB_TYPE_LISTENER 3 30 #define CB_TYPE_CRED_LISTENER 4 31 #define CB_TYPE_CRED_DEV_AUTH 5 32 33 typedef struct { 34 int32_t type; 35 int32_t valSz; 36 uint8_t *val; 37 int32_t idx; 38 } IpcDataInfo; 39 40 enum { 41 CB_ID_ON_TRANS = 1, 42 CB_ID_SESS_KEY_DONE, 43 CB_ID_ON_FINISH, 44 CB_ID_ON_ERROR, 45 CB_ID_ON_REQUEST, 46 CB_ID_ON_GROUP_CREATED, 47 CB_ID_ON_GROUP_DELETED, 48 CB_ID_ON_DEV_BOUND, 49 CB_ID_ON_DEV_UNBOUND, 50 CB_ID_ON_DEV_UNTRUSTED, 51 CB_ID_ON_LAST_GROUP_DELETED, 52 CB_ID_ON_TRUST_DEV_NUM_CHANGED, 53 CB_ID_ON_CRED_ADD, 54 CB_ID_ON_CRED_DELETE, 55 CB_ID_ON_CRED_UPDATE, 56 }; 57 58 typedef int32_t (*IpcServiceCall)(const IpcDataInfo *, int32_t, uintptr_t); 59 60 int32_t IpcEncodeCallReply(uintptr_t replayCache, int32_t type, const uint8_t *result, int32_t resultSz); 61 uint32_t SetIpcCallMap(uintptr_t ipcInstance, IpcServiceCall method, int32_t methodId); 62 63 void SetCbCtxToDataCtx(uintptr_t callCtx, int32_t cbIdx); 64 int32_t CreateCallCtx(uintptr_t *callCtx); 65 void DestroyCallCtx(uintptr_t *callCtx); 66 int32_t DoBinderCall(uintptr_t callCtx, int32_t methodId, bool withSync); 67 int32_t SetCallRequestParamInfo(uintptr_t callCtx, int32_t type, const uint8_t *param, int32_t paramSz); 68 69 int32_t CreateServiceInstance(uintptr_t *ipcInstance); 70 void DestroyServiceInstance(uintptr_t ipcInstance); 71 72 int32_t AddDevAuthServiceToManager(uintptr_t serviceInstance); 73 void DecodeCallReply(uintptr_t callCtx, IpcDataInfo *replyCache, int32_t cacheNum); 74 75 int32_t InitIpcCallBackList(void); 76 void DeInitIpcCallBackList(void); 77 void InitDeviceAuthCbCtx(DeviceAuthCallback *ctx, int32_t type); 78 void InitDevAuthListenerCbCtx(DataChangeListener *ctx); 79 int32_t AddIpcCallBackByAppId(const char *appId, const uint8_t *cbPtr, int32_t cbSz, int32_t type); 80 void DelIpcCallBackByAppId(const char *appId, int32_t type); 81 int32_t AddIpcCallBackByReqId(int64_t reqId, const uint8_t *cbPtr, int32_t cbSz, int32_t type); 82 void DelIpcCallBackByReqId(int64_t reqId, int32_t type, bool withLock); 83 84 int32_t DecodeIpcData(uintptr_t data, int32_t *type, uint8_t **val, int32_t *valSz); 85 void ProcCbHook(int32_t callbackId, uintptr_t cbHook, 86 const IpcDataInfo *cbDataCache, int32_t cacheNum, uintptr_t replyCtx); 87 88 int32_t GetIpcRequestParamByType(const IpcDataInfo *ipcParams, int32_t paramNum, 89 int32_t type, uint8_t *paramCache, int32_t *cacheLen); 90 int32_t AddReqIdByAppId(const char *appId, int64_t reqId); 91 void AddIpcCbObjByAppId(const char *appId, int32_t objIdx, int32_t type); 92 void AddIpcCbObjByReqId(int64_t reqId, int32_t objIdx, int32_t type); 93 94 bool IsCallbackMethod(int32_t methodId); 95 void ResetIpcCallBackNodeByNodeId(int32_t nodeIdx); 96 int32_t InitProxyAdapt(void); 97 void UnInitProxyAdapt(void); 98 99 void InitDevAuthCredListenerCbCtx(CredChangeListener *ctx); 100 101 #ifdef __cplusplus 102 } 103 #endif 104 #endif 105