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 <stdbool.h> 20#include <stdint.h> 21 22#include "device_auth.h" 23#include "serializer.h" 24 25#ifdef __cplusplus 26extern "C" { 27#endif 28 29#define MAX_REQUEST_PARAMS_NUM 8 30#define CB_TYPE_DEV_AUTH 1 31#define CB_TYPE_TMP_DEV_AUTH 2 32#define CB_TYPE_LISTENER 3 33 34#ifndef IPC_DATA_BUFF_MAX_SZ 35#define IPC_DATA_BUFF_MAX_SZ 2048 36#endif 37#define IPC_STACK_BUFF_SZ 512 38 39typedef struct { 40 int32_t type; 41 int32_t valSz; 42 uint8_t *val; 43 int32_t idx; 44} IpcDataInfo; 45 46enum { 47 CB_ID_ON_TRANS = 1, 48 CB_ID_SESS_KEY_DONE, 49 CB_ID_ON_FINISH, 50 CB_ID_ON_ERROR, 51 CB_ID_ON_REQUEST, 52 CB_ID_ON_GROUP_CREATED, 53 CB_ID_ON_GROUP_DELETED, 54 CB_ID_ON_DEV_BOUND, 55 CB_ID_ON_DEV_UNBOUND, 56 CB_ID_ON_DEV_UNTRUSTED, 57 CB_ID_ON_LAST_GROUP_DELETED, 58 CB_ID_ON_TRUST_DEV_NUM_CHANGED, 59}; 60 61typedef int32_t (*IpcServiceCall)(const IpcDataInfo *, int32_t, uintptr_t); 62 63int32_t IpcEncodeCallReply(uintptr_t replayCache, int32_t type, const uint8_t *result, int32_t resultSz); 64uint32_t SetIpcCallMap(uintptr_t ipcInstance, IpcServiceCall method, int32_t methodId); 65 66void SetCbCtxToDataCtx(uintptr_t callCtx, int32_t cbIdx); 67int32_t CreateCallCtx(uintptr_t *callCtx, uintptr_t *cbCtx); 68void DestroyCallCtx(uintptr_t *callCtx, uintptr_t *cbCtx); 69int32_t DoBinderCall(uintptr_t callCtx, int32_t methodId, bool withSync); 70int32_t SetCallRequestParamInfo(uintptr_t callCtx, int32_t type, const uint8_t *param, int32_t paramSz); 71 72int32_t CreateServiceInstance(uintptr_t *ipcInstance); 73void DestroyServiceInstance(uintptr_t ipcInstance); 74 75int32_t AddDevAuthServiceToManager(uintptr_t serviceInstance); 76void DecodeCallReply(uintptr_t callCtx, IpcDataInfo *replyCache, int32_t cacheNum); 77 78int32_t InitIpcCallBackList(void); 79void DeInitIpcCallBackList(void); 80void InitDeviceAuthCbCtx(DeviceAuthCallback *ctx, int32_t type); 81void InitDevAuthListenerCbCtx(DataChangeListener *ctx); 82int32_t AddIpcCallBackByAppId(const char *appId, const uint8_t *cbPtr, int32_t cbSz, int32_t type); 83void DelIpcCallBackByAppId(const char *appId, int32_t type); 84int32_t AddIpcCallBackByReqId(int64_t reqId, const uint8_t *cbPtr, int32_t cbSz, int32_t type); 85void DelIpcCallBackByReqId(int64_t reqId, int32_t type, bool withLock); 86 87int32_t DecodeIpcData(uintptr_t data, int32_t *type, uint8_t **val, int32_t *valSz); 88void ProcCbHook(int32_t callbackId, uintptr_t cbHook, 89 const IpcDataInfo *cbDataCache, int32_t cacheNum, uintptr_t replyCtx); 90 91int32_t GetIpcRequestParamByType(const IpcDataInfo *ipcParams, int32_t paramNum, 92 int32_t type, uint8_t *paramCache, int32_t *cacheLen); 93int32_t AddReqIdByAppId(const char *appId, int64_t reqId); 94void AddIpcCbObjByAppId(const char *appId, int32_t objIdx, int32_t type); 95void AddIpcCbObjByReqId(int64_t reqId, int32_t objIdx, int32_t type); 96 97bool IsCallbackMethod(int32_t methodId); 98void ResetIpcCallBackNodeByNodeId(int32_t nodeIdx); 99IpcIo *InitIpcDataCache(uint32_t buffSz); 100int32_t GetIpcIoDataLength(const IpcIo *io); 101int32_t InitProxyAdapt(void); 102void UnInitProxyAdapt(void); 103void ServiceInit(void); 104void ShowIpcSvcInfo(const SvcIdentity *svc); 105int32_t IpcIoBufferOffset(void); 106 107#ifdef __cplusplus 108} 109#endif 110#endif 111