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