• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 "dbinder_ipc_adapter.h"
17 
18 #include <pthread.h>
19 #include <string.h>
20 
21 #include "securec.h"
22 #include "ipc_skeleton.h"
23 #include "rpc_log.h"
24 #include "rpc_errno.h"
25 
IsSameStub(DBinderServiceStub * stub,const char * serviceName,const char * deviceID,uintptr_t binderObject)26 bool IsSameStub(DBinderServiceStub *stub, const char *serviceName,
27     const char *deviceID, uintptr_t binderObject)
28 {
29     if (stub == NULL) {
30         return false;
31     }
32     return (strcmp(stub->serviceName, serviceName) == 0 && strcmp(stub->deviceID, deviceID) == 0
33         && stub->binderObject == binderObject);
34 }
35 
RpcGetSystemAbility(int32_t systemAbility)36 ProxyObject *RpcGetSystemAbility(int32_t systemAbility)
37 {
38     IpcIo data;
39     uint8_t tmpData[RPC_IPC_LENGTH];
40     IpcIoInit(&data, tmpData, RPC_IPC_LENGTH, 0);
41     RPC_LOG_INFO("GetSystemAbility systemAbility %d", systemAbility);
42     WriteInt32(&data, systemAbility);
43 
44     IpcIo reply;
45     MessageOption option = {
46         .flags = TF_OP_SYNC
47     };
48 
49     RPC_LOG_INFO("get system ability from samgr");
50     uintptr_t ptr;
51     SvcIdentity *identity = (SvcIdentity *)GetContextObject();
52     if (identity == NULL) {
53         return NULL;
54     }
55     int32_t ret = SendRequest(*identity, GET_SYSTEM_ABILITY_TRANSACTION, &data, &reply, option, &ptr);
56     if (ret != ERR_NONE) {
57         RPC_LOG_ERROR("GetSystemAbility failed");
58         FreeBuffer((void *)ptr);
59         return NULL;
60     }
61 
62     SvcIdentity svc;
63     ReadRemoteObject(&reply, &svc);
64 
65     ProxyObject *proxyObject = (ProxyObject *)malloc(sizeof(ProxyObject));
66     if (proxyObject == NULL) {
67         FreeBuffer((void *)ptr);
68         return NULL;
69     }
70     proxyObject->proxy = (SvcIdentity *)malloc(sizeof(SvcIdentity));
71     if (proxyObject->proxy == NULL) {
72         free(proxyObject);
73         FreeBuffer((void *)ptr);
74         return NULL;
75     }
76 
77     if (memcpy_s(proxyObject->proxy, sizeof(SvcIdentity), &svc, sizeof(SvcIdentity)) != EOK) {
78         free(proxyObject->proxy);
79         free(proxyObject);
80         FreeBuffer((void *)ptr);
81         return NULL;
82     }
83 
84     FreeBuffer((void *)ptr);
85     return proxyObject;
86 }