• 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 <stdbool.h>
20 #include <stdint.h>
21 
22 #include "device_auth.h"
23 #include "serializer.h"
24 
25 #ifdef __cplusplus
26 extern "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 
39 typedef struct {
40     int32_t type;
41     int32_t valSz;
42     uint8_t *val;
43     int32_t idx;
44 } IpcDataInfo;
45 
46 enum {
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 
61 typedef int32_t (*IpcServiceCall)(const IpcDataInfo *, int32_t, uintptr_t);
62 
63 int32_t IpcEncodeCallReplay(uintptr_t replayCache, int32_t type, const uint8_t *result, int32_t resultSz);
64 uint32_t SetIpcCallMap(uintptr_t ipcInstance, IpcServiceCall method, int32_t methodId);
65 
66 void SetCbCtxToDataCtx(uintptr_t callCtx, int32_t cbIdx);
67 int32_t CreateCallCtx(uintptr_t *callCtx, uintptr_t *cbCtx);
68 void DestroyCallCtx(uintptr_t *callCtx, uintptr_t *cbCtx);
69 int32_t DoBinderCall(uintptr_t callCtx, int32_t methodId, bool withSync);
70 int32_t SetCallRequestParamInfo(uintptr_t callCtx, int32_t type, const uint8_t *param, int32_t paramSz);
71 
72 int32_t CreateServiceInstance(uintptr_t *ipcInstance);
73 void DestroyServiceInstance(uintptr_t *ipcInstance);
74 
75 int32_t AddDevAuthServiceToManager(uintptr_t *serviceCtx);
76 void DecodeCallReply(uintptr_t callCtx, IpcDataInfo *replyCache, int32_t cacheNum);
77 
78 int32_t InitIpcCallBackList(void);
79 void DeInitIpcCallBackList(void);
80 void InitDeviceAuthCbCtx(DeviceAuthCallback *ctx, int32_t type);
81 void InitDevAuthListenerCbCtx(DataChangeListener *ctx);
82 int32_t AddIpcCallBackByAppId(const char *appId, const uint8_t *cbPtr, int32_t cbSz, int32_t type);
83 void DelIpcCallBackByAppId(const char *appId, int32_t type);
84 int32_t AddIpcCallBackByReqId(int64_t reqId, const uint8_t *cbPtr, int32_t cbSz, int32_t type);
85 void DelIpcCallBackByReqId(int64_t reqId, int32_t type, bool withLock);
86 
87 int32_t DecodeIpcData(uintptr_t data, int32_t *type, uint8_t **val, int32_t *valSz);
88 void ProcCbHook(int32_t callbackId, uintptr_t cbHook,
89     const IpcDataInfo *cbDataCache, int32_t cacheNum, uintptr_t replyCtx);
90 
91 int32_t GetIpcRequestParamByType(const IpcDataInfo *ipcParams, int32_t paramNum,
92     int32_t type, uint8_t *paramCache, int32_t *cacheLen);
93 int32_t AddReqIdByAppId(const char *appId, int64_t reqId);
94 void AddIpcCbObjByAppId(const char *appId, int32_t objIdx, int32_t type);
95 void AddIpcCbObjByReqId(int64_t reqId, int32_t objIdx, int32_t type);
96 
97 bool IsCallbackMethod(int32_t methodId);
98 void ResetIpcCallBackNodeByNodeId(int32_t nodeIdx);
99 IpcIo *InitIpcDataCache(uint32_t buffSz);
100 int32_t GetIpcIoDataLength(const IpcIo *io);
101 int32_t InitProxyAdapt(void);
102 void UnInitProxyAdapt(void);
103 void ServiceInit(void);
104 void ShowIpcSvcInfo(const SvcIdentity *svc);
105 int32_t IpcIoBufferOffset(void);
106 
107 #ifdef __cplusplus
108 }
109 #endif
110 #endif
111