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 #include "ipc_callback_stub.h"
17 #include "common_defs.h"
18 #include "device_auth_defines.h"
19 #include "hc_log.h"
20 #include "ipc_adapt.h"
21 #include "ipc_iface.h"
22 #include "ipc_skeleton.h"
23 #include "securec.h"
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
DoCallBack(int32_t callbackId,uintptr_t cbHook,IpcIo * data,IpcIo * reply)29 static void DoCallBack(int32_t callbackId, uintptr_t cbHook, IpcIo *data, IpcIo *reply)
30 {
31 int32_t ret;
32 int32_t i;
33 IpcDataInfo cbDataCache[MAX_REQUEST_PARAMS_NUM] = { { 0 } };
34
35 if (cbHook == 0x0) {
36 LOGE("Invalid call back hook");
37 return;
38 }
39
40 uint32_t len = 0;
41 ReadUint32(data, &len); /* skip flat object length information */
42 for (i = 0; i < MAX_REQUEST_PARAMS_NUM; i++) {
43 ret = DecodeIpcData((uintptr_t)(data), &(cbDataCache[i].type),
44 &(cbDataCache[i].val), &(cbDataCache[i].valSz));
45 if (ret != HC_SUCCESS) {
46 LOGE("decode failed, ret %d", ret);
47 return;
48 }
49 }
50 ProcCbHook(callbackId, cbHook, cbDataCache, MAX_REQUEST_PARAMS_NUM, (uintptr_t)(reply));
51 return;
52 }
53
CbStubOnRemoteRequest(uint32_t code,IpcIo * data,IpcIo * reply,MessageOption option)54 int32_t CbStubOnRemoteRequest(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option)
55 {
56 int32_t callbackId;
57 uintptr_t cbHook = 0x0;
58
59 LOGI("enter invoking callback...");
60 if (data == NULL) {
61 LOGE("invalid param");
62 return -1;
63 }
64
65 LOGI("receive ipc transact code(%u)", code);
66 switch (code) {
67 case DEV_AUTH_CALLBACK_REQUEST:
68 ReadInt32(data, &callbackId);
69 cbHook = ReadPointer(data);
70 DoCallBack(callbackId, cbHook, data, reply);
71 break;
72 default:
73 LOGE("Invoke callback cmd code(%u) error", code);
74 break;
75 }
76 LOGI("Invoke callback done, result(%d)", HC_SUCCESS);
77 return HC_SUCCESS;
78 }
79
80 #ifdef __cplusplus
81 }
82 #endif
83