117fd14ceSopenharmony_ci/* 217fd14ceSopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd. 317fd14ceSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 417fd14ceSopenharmony_ci * you may not use this file except in compliance with the License. 517fd14ceSopenharmony_ci * You may obtain a copy of the License at 617fd14ceSopenharmony_ci * 717fd14ceSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 817fd14ceSopenharmony_ci * 917fd14ceSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1017fd14ceSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1117fd14ceSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1217fd14ceSopenharmony_ci * See the License for the specific language governing permissions and 1317fd14ceSopenharmony_ci * limitations under the License. 1417fd14ceSopenharmony_ci */ 1517fd14ceSopenharmony_ci 1617fd14ceSopenharmony_ci#ifndef IPC_ADAPT_H 1717fd14ceSopenharmony_ci#define IPC_ADAPT_H 1817fd14ceSopenharmony_ci 1917fd14ceSopenharmony_ci#include <stdbool.h> 2017fd14ceSopenharmony_ci#include <stdint.h> 2117fd14ceSopenharmony_ci 2217fd14ceSopenharmony_ci#include "device_auth.h" 2317fd14ceSopenharmony_ci#include "serializer.h" 2417fd14ceSopenharmony_ci 2517fd14ceSopenharmony_ci#ifdef __cplusplus 2617fd14ceSopenharmony_ciextern "C" { 2717fd14ceSopenharmony_ci#endif 2817fd14ceSopenharmony_ci 2917fd14ceSopenharmony_ci#define MAX_REQUEST_PARAMS_NUM 8 3017fd14ceSopenharmony_ci#define CB_TYPE_DEV_AUTH 1 3117fd14ceSopenharmony_ci#define CB_TYPE_TMP_DEV_AUTH 2 3217fd14ceSopenharmony_ci#define CB_TYPE_LISTENER 3 3317fd14ceSopenharmony_ci 3417fd14ceSopenharmony_ci#ifndef IPC_DATA_BUFF_MAX_SZ 3517fd14ceSopenharmony_ci#define IPC_DATA_BUFF_MAX_SZ 2048 3617fd14ceSopenharmony_ci#endif 3717fd14ceSopenharmony_ci#define IPC_STACK_BUFF_SZ 512 3817fd14ceSopenharmony_ci 3917fd14ceSopenharmony_citypedef struct { 4017fd14ceSopenharmony_ci int32_t type; 4117fd14ceSopenharmony_ci int32_t valSz; 4217fd14ceSopenharmony_ci uint8_t *val; 4317fd14ceSopenharmony_ci int32_t idx; 4417fd14ceSopenharmony_ci} IpcDataInfo; 4517fd14ceSopenharmony_ci 4617fd14ceSopenharmony_cienum { 4717fd14ceSopenharmony_ci CB_ID_ON_TRANS = 1, 4817fd14ceSopenharmony_ci CB_ID_SESS_KEY_DONE, 4917fd14ceSopenharmony_ci CB_ID_ON_FINISH, 5017fd14ceSopenharmony_ci CB_ID_ON_ERROR, 5117fd14ceSopenharmony_ci CB_ID_ON_REQUEST, 5217fd14ceSopenharmony_ci CB_ID_ON_GROUP_CREATED, 5317fd14ceSopenharmony_ci CB_ID_ON_GROUP_DELETED, 5417fd14ceSopenharmony_ci CB_ID_ON_DEV_BOUND, 5517fd14ceSopenharmony_ci CB_ID_ON_DEV_UNBOUND, 5617fd14ceSopenharmony_ci CB_ID_ON_DEV_UNTRUSTED, 5717fd14ceSopenharmony_ci CB_ID_ON_LAST_GROUP_DELETED, 5817fd14ceSopenharmony_ci CB_ID_ON_TRUST_DEV_NUM_CHANGED, 5917fd14ceSopenharmony_ci}; 6017fd14ceSopenharmony_ci 6117fd14ceSopenharmony_citypedef int32_t (*IpcServiceCall)(const IpcDataInfo *, int32_t, uintptr_t); 6217fd14ceSopenharmony_ci 6317fd14ceSopenharmony_ciint32_t IpcEncodeCallReply(uintptr_t replayCache, int32_t type, const uint8_t *result, int32_t resultSz); 6417fd14ceSopenharmony_ciuint32_t SetIpcCallMap(uintptr_t ipcInstance, IpcServiceCall method, int32_t methodId); 6517fd14ceSopenharmony_ci 6617fd14ceSopenharmony_civoid SetCbCtxToDataCtx(uintptr_t callCtx, int32_t cbIdx); 6717fd14ceSopenharmony_ciint32_t CreateCallCtx(uintptr_t *callCtx, uintptr_t *cbCtx); 6817fd14ceSopenharmony_civoid DestroyCallCtx(uintptr_t *callCtx, uintptr_t *cbCtx); 6917fd14ceSopenharmony_ciint32_t DoBinderCall(uintptr_t callCtx, int32_t methodId, bool withSync); 7017fd14ceSopenharmony_ciint32_t SetCallRequestParamInfo(uintptr_t callCtx, int32_t type, const uint8_t *param, int32_t paramSz); 7117fd14ceSopenharmony_ci 7217fd14ceSopenharmony_ciint32_t CreateServiceInstance(uintptr_t *ipcInstance); 7317fd14ceSopenharmony_civoid DestroyServiceInstance(uintptr_t ipcInstance); 7417fd14ceSopenharmony_ci 7517fd14ceSopenharmony_ciint32_t AddDevAuthServiceToManager(uintptr_t serviceInstance); 7617fd14ceSopenharmony_civoid DecodeCallReply(uintptr_t callCtx, IpcDataInfo *replyCache, int32_t cacheNum); 7717fd14ceSopenharmony_ci 7817fd14ceSopenharmony_ciint32_t InitIpcCallBackList(void); 7917fd14ceSopenharmony_civoid DeInitIpcCallBackList(void); 8017fd14ceSopenharmony_civoid InitDeviceAuthCbCtx(DeviceAuthCallback *ctx, int32_t type); 8117fd14ceSopenharmony_civoid InitDevAuthListenerCbCtx(DataChangeListener *ctx); 8217fd14ceSopenharmony_ciint32_t AddIpcCallBackByAppId(const char *appId, const uint8_t *cbPtr, int32_t cbSz, int32_t type); 8317fd14ceSopenharmony_civoid DelIpcCallBackByAppId(const char *appId, int32_t type); 8417fd14ceSopenharmony_ciint32_t AddIpcCallBackByReqId(int64_t reqId, const uint8_t *cbPtr, int32_t cbSz, int32_t type); 8517fd14ceSopenharmony_civoid DelIpcCallBackByReqId(int64_t reqId, int32_t type, bool withLock); 8617fd14ceSopenharmony_ci 8717fd14ceSopenharmony_ciint32_t DecodeIpcData(uintptr_t data, int32_t *type, uint8_t **val, int32_t *valSz); 8817fd14ceSopenharmony_civoid ProcCbHook(int32_t callbackId, uintptr_t cbHook, 8917fd14ceSopenharmony_ci const IpcDataInfo *cbDataCache, int32_t cacheNum, uintptr_t replyCtx); 9017fd14ceSopenharmony_ci 9117fd14ceSopenharmony_ciint32_t GetIpcRequestParamByType(const IpcDataInfo *ipcParams, int32_t paramNum, 9217fd14ceSopenharmony_ci int32_t type, uint8_t *paramCache, int32_t *cacheLen); 9317fd14ceSopenharmony_ciint32_t AddReqIdByAppId(const char *appId, int64_t reqId); 9417fd14ceSopenharmony_civoid AddIpcCbObjByAppId(const char *appId, int32_t objIdx, int32_t type); 9517fd14ceSopenharmony_civoid AddIpcCbObjByReqId(int64_t reqId, int32_t objIdx, int32_t type); 9617fd14ceSopenharmony_ci 9717fd14ceSopenharmony_cibool IsCallbackMethod(int32_t methodId); 9817fd14ceSopenharmony_civoid ResetIpcCallBackNodeByNodeId(int32_t nodeIdx); 9917fd14ceSopenharmony_ciIpcIo *InitIpcDataCache(uint32_t buffSz); 10017fd14ceSopenharmony_ciint32_t GetIpcIoDataLength(const IpcIo *io); 10117fd14ceSopenharmony_ciint32_t InitProxyAdapt(void); 10217fd14ceSopenharmony_civoid UnInitProxyAdapt(void); 10317fd14ceSopenharmony_civoid ServiceInit(void); 10417fd14ceSopenharmony_civoid ShowIpcSvcInfo(const SvcIdentity *svc); 10517fd14ceSopenharmony_ciint32_t IpcIoBufferOffset(void); 10617fd14ceSopenharmony_ci 10717fd14ceSopenharmony_ci#ifdef __cplusplus 10817fd14ceSopenharmony_ci} 10917fd14ceSopenharmony_ci#endif 11017fd14ceSopenharmony_ci#endif 111