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
23extern "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
31typedef struct {
32    int32_t type;
33    int32_t valSz;
34    uint8_t *val;
35    int32_t idx;
36} IpcDataInfo;
37
38enum {
39    CB_ID_ON_TRANS = 1,
40    CB_ID_SESS_KEY_DONE,
41    CB_ID_ON_FINISH,
42    CB_ID_ON_ERROR,
43    CB_ID_ON_REQUEST,
44    CB_ID_ON_GROUP_CREATED,
45    CB_ID_ON_GROUP_DELETED,
46    CB_ID_ON_DEV_BOUND,
47    CB_ID_ON_DEV_UNBOUND,
48    CB_ID_ON_DEV_UNTRUSTED,
49    CB_ID_ON_LAST_GROUP_DELETED,
50    CB_ID_ON_TRUST_DEV_NUM_CHANGED,
51};
52
53typedef int32_t (*IpcServiceCall)(const IpcDataInfo *, int32_t, uintptr_t);
54
55int32_t IpcEncodeCallReply(uintptr_t replayCache, int32_t type, const uint8_t *result, int32_t resultSz);
56uint32_t SetIpcCallMap(uintptr_t ipcInstance, IpcServiceCall method, int32_t methodId);
57
58void SetCbCtxToDataCtx(uintptr_t callCtx, int32_t cbIdx);
59int32_t CreateCallCtx(uintptr_t *callCtx, uintptr_t *cbCtx);
60void DestroyCallCtx(uintptr_t *callCtx, uintptr_t *cbCtx);
61int32_t DoBinderCall(uintptr_t callCtx, int32_t methodId, bool withSync);
62int32_t SetCallRequestParamInfo(uintptr_t callCtx, int32_t type, const uint8_t *param, int32_t paramSz);
63
64int32_t CreateServiceInstance(uintptr_t *ipcInstance);
65void DestroyServiceInstance(uintptr_t ipcInstance);
66
67int32_t AddDevAuthServiceToManager(uintptr_t serviceInstance);
68void DecodeCallReply(uintptr_t callCtx, IpcDataInfo *replyCache, int32_t cacheNum);
69
70int32_t InitIpcCallBackList(void);
71void DeInitIpcCallBackList(void);
72void InitDeviceAuthCbCtx(DeviceAuthCallback *ctx, int32_t type);
73void InitDevAuthListenerCbCtx(DataChangeListener *ctx);
74int32_t AddIpcCallBackByAppId(const char *appId, const uint8_t *cbPtr, int32_t cbSz, int32_t type);
75void DelIpcCallBackByAppId(const char *appId, int32_t type);
76int32_t AddIpcCallBackByReqId(int64_t reqId, const uint8_t *cbPtr, int32_t cbSz, int32_t type);
77void DelIpcCallBackByReqId(int64_t reqId, int32_t type, bool withLock);
78
79int32_t DecodeIpcData(uintptr_t data, int32_t *type, uint8_t **val, int32_t *valSz);
80void ProcCbHook(int32_t callbackId, uintptr_t cbHook,
81    const IpcDataInfo *cbDataCache, int32_t cacheNum, uintptr_t replyCtx);
82
83int32_t GetIpcRequestParamByType(const IpcDataInfo *ipcParams, int32_t paramNum,
84    int32_t type, uint8_t *paramCache, int32_t *cacheLen);
85int32_t AddReqIdByAppId(const char *appId, int64_t reqId);
86void AddIpcCbObjByAppId(const char *appId, int32_t objIdx, int32_t type);
87void AddIpcCbObjByReqId(int64_t reqId, int32_t objIdx, int32_t type);
88
89bool IsCallbackMethod(int32_t methodId);
90void ResetIpcCallBackNodeByNodeId(int32_t nodeIdx);
91int32_t InitProxyAdapt(void);
92void UnInitProxyAdapt(void);
93
94#ifdef __cplusplus
95}
96#endif
97#endif
98