mirror of
https://github.com/openharmony/security_deviceauth.git
synced 2026-08-26 19:50:40 -04:00
@@ -17,7 +17,7 @@
|
||||
#define IPC_CALLBACK_STUB_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <serializer.h>
|
||||
#include "ipc_skeleton.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -28,7 +28,7 @@ typedef struct {
|
||||
bool registered;
|
||||
} StubDevAuthCb;
|
||||
|
||||
int32_t CbStubOnRemoteRequest(const IpcContext *ctx, void *ipcMsg, IpcIo *data, void *arg);
|
||||
int32_t CbStubOnRemoteRequest(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ int32_t SetRemoteObject(const SvcIdentity *object);
|
||||
void AddCbDeathRecipient(int32_t cbStubIdx, int32_t cbDataIdx);
|
||||
void ResetRemoteObject(int32_t idx);
|
||||
void ActCallback(int32_t objIdx, int32_t callbackId, uintptr_t cbHook, IpcIo *dataParcel, IpcIo *reply);
|
||||
int32_t OnRemoteRequest(IServerProxy *iProxy, int32_t reqId, void *origin, IpcIo *req, IpcIo *reply);
|
||||
int32_t OnRemoteInvoke(IServerProxy *iProxy, int32_t reqId, void *origin, IpcIo *req, IpcIo *reply);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "ipc_dev_auth_stub.h"
|
||||
#include "ipc_sdk.h"
|
||||
#include "ipc_service.h"
|
||||
#include "liteipc_adapter.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "securec.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -57,6 +57,7 @@ static HcMutex g_cbListLock;
|
||||
|
||||
static StubDevAuthCb g_sdkCbStub;
|
||||
static IClientProxy *g_proxyInstance = NULL;
|
||||
static IpcObjectStub g_objectStub;
|
||||
|
||||
static void SetIpcCallBackNodeDefault(IpcCallBackNode *node)
|
||||
{
|
||||
@@ -450,7 +451,7 @@ static void OnTransmitStub(uintptr_t cbHook, const IpcDataInfo *cbDataCache, int
|
||||
(void)GetIpcRequestParamByType(cbDataCache, cacheNum,
|
||||
PARAM_TYPE_COMM_DATA, (uint8_t *)&data, (int32_t *)(&dataLen));
|
||||
bRet = onTransmitHook(requestId, data, dataLen);
|
||||
(bRet == true) ? IpcIoPushInt32(reply, HC_SUCCESS) : IpcIoPushInt32(reply, HC_ERROR);
|
||||
(bRet == true) ? WriteInt32(reply, HC_SUCCESS) : WriteInt32(reply, HC_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -468,7 +469,7 @@ static void OnSessKeyStub(uintptr_t cbHook, const IpcDataInfo *cbDataCache, int3
|
||||
(void)GetIpcRequestParamByType(cbDataCache, cacheNum, PARAM_TYPE_SESS_KEY,
|
||||
(uint8_t *)(&keyData), (int32_t *)(&dataLen));
|
||||
onSessKeyHook(requestId, keyData, dataLen);
|
||||
IpcIoPushInt32(reply, HC_SUCCESS);
|
||||
WriteInt32(reply, HC_SUCCESS);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -487,7 +488,7 @@ static void OnFinishStub(uintptr_t cbHook, const IpcDataInfo *cbDataCache, int32
|
||||
(void)GetIpcRequestParamByType(cbDataCache, cacheNum, PARAM_TYPE_OPCODE, (uint8_t *)(&opCode), &inOutLen);
|
||||
(void)GetIpcRequestParamByType(cbDataCache, cacheNum, PARAM_TYPE_COMM_DATA, (uint8_t *)(&data), NULL);
|
||||
onFinishHook(requestId, opCode, data);
|
||||
IpcIoPushInt32(reply, HC_SUCCESS);
|
||||
WriteInt32(reply, HC_SUCCESS);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -508,7 +509,7 @@ static void OnErrorStub(uintptr_t cbHook, const IpcDataInfo *cbDataCache, int32_
|
||||
(void)GetIpcRequestParamByType(cbDataCache, cacheNum, PARAM_TYPE_ERRCODE, (uint8_t *)(&errCode), &inOutLen);
|
||||
(void)GetIpcRequestParamByType(cbDataCache, cacheNum, PARAM_TYPE_ERR_INFO, (uint8_t *)(&errInfo), NULL);
|
||||
onErrorHook(requestId, opCode, errCode, errInfo);
|
||||
IpcIoPushInt32(reply, HC_SUCCESS);
|
||||
WriteInt32(reply, HC_SUCCESS);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -529,11 +530,11 @@ static void OnRequestStub(uintptr_t cbHook, const IpcDataInfo *cbDataCache, int3
|
||||
(void)GetIpcRequestParamByType(cbDataCache, cacheNum, PARAM_TYPE_REQ_INFO, (uint8_t *)(&reqParams), NULL);
|
||||
reqResult = onReqHook(requestId, opCode, reqParams);
|
||||
if (reqResult == NULL) {
|
||||
IpcIoPushInt32(reply, HC_ERROR);
|
||||
WriteInt32(reply, HC_ERROR);
|
||||
return;
|
||||
}
|
||||
IpcIoPushInt32(reply, HC_SUCCESS);
|
||||
IpcIoPushString(reply, (const char *)(reqResult));
|
||||
WriteInt32(reply, HC_SUCCESS);
|
||||
WriteString(reply, (const char *)(reqResult));
|
||||
HcFree(reqResult);
|
||||
reqResult = NULL;
|
||||
return;
|
||||
@@ -547,7 +548,7 @@ static void OnGroupCreatedStub(uintptr_t cbHook, const IpcDataInfo *cbDataCache,
|
||||
onGroupCreatedHook = (void (*)(const char *))(cbHook);
|
||||
(void)GetIpcRequestParamByType(cbDataCache, cacheNum, PARAM_TYPE_GROUP_INFO, (uint8_t *)(&groupInfo), NULL);
|
||||
onGroupCreatedHook(groupInfo);
|
||||
IpcIoPushInt32(reply, HC_SUCCESS);
|
||||
WriteInt32(reply, HC_SUCCESS);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -559,7 +560,7 @@ static void OnGroupDeletedStub(uintptr_t cbHook, const IpcDataInfo *cbDataCache,
|
||||
onDelGroupHook = (void (*)(const char *))(cbHook);
|
||||
(void)GetIpcRequestParamByType(cbDataCache, cacheNum, PARAM_TYPE_GROUP_INFO, (uint8_t *)(&groupInfo), NULL);
|
||||
onDelGroupHook(groupInfo);
|
||||
IpcIoPushInt32(reply, HC_SUCCESS);
|
||||
WriteInt32(reply, HC_SUCCESS);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -573,7 +574,7 @@ static void OnDevBoundStub(uintptr_t cbHook, const IpcDataInfo *cbDataCache, int
|
||||
(void)GetIpcRequestParamByType(cbDataCache, cacheNum, PARAM_TYPE_UDID, (uint8_t *)(&udid), NULL);
|
||||
(void)GetIpcRequestParamByType(cbDataCache, cacheNum, PARAM_TYPE_GROUP_INFO, (uint8_t *)(&groupInfo), NULL);
|
||||
onDevBoundHook(udid, groupInfo);
|
||||
IpcIoPushInt32(reply, HC_SUCCESS);
|
||||
WriteInt32(reply, HC_SUCCESS);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -587,7 +588,7 @@ static void OnDevUnboundStub(uintptr_t cbHook, const IpcDataInfo *cbDataCache, i
|
||||
(void)GetIpcRequestParamByType(cbDataCache, cacheNum, PARAM_TYPE_UDID, (uint8_t *)(&udid), NULL);
|
||||
(void)GetIpcRequestParamByType(cbDataCache, cacheNum, PARAM_TYPE_GROUP_INFO, (uint8_t *)(&groupInfo), NULL);
|
||||
onDevUnBoundHook(udid, groupInfo);
|
||||
IpcIoPushInt32(reply, HC_SUCCESS);
|
||||
WriteInt32(reply, HC_SUCCESS);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -599,7 +600,7 @@ static void OnDevUnTrustStub(uintptr_t cbHook, const IpcDataInfo *cbDataCache, i
|
||||
onDevUnTrustHook = (void (*)(const char *))(cbHook);
|
||||
(void)GetIpcRequestParamByType(cbDataCache, cacheNum, PARAM_TYPE_UDID, (uint8_t *)(&udid), NULL);
|
||||
onDevUnTrustHook(udid);
|
||||
IpcIoPushInt32(reply, HC_SUCCESS);
|
||||
WriteInt32(reply, HC_SUCCESS);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -615,7 +616,7 @@ static void OnDelLastGroupStub(uintptr_t cbHook, const IpcDataInfo *cbDataCache,
|
||||
inOutLen = sizeof(groupType);
|
||||
(void)GetIpcRequestParamByType(cbDataCache, cacheNum, PARAM_TYPE_GROUP_TYPE, (uint8_t *)(&groupType), &inOutLen);
|
||||
onDelLastGroupHook(udid, groupType);
|
||||
IpcIoPushInt32(reply, HC_SUCCESS);
|
||||
WriteInt32(reply, HC_SUCCESS);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -630,7 +631,7 @@ static void OnTrustDevNumChangedStub(uintptr_t cbHook,
|
||||
inOutLen = sizeof(devNum);
|
||||
(void)GetIpcRequestParamByType(cbDataCache, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)(&devNum), &inOutLen);
|
||||
onTrustDevNumChangedHook(devNum);
|
||||
IpcIoPushInt32(reply, HC_SUCCESS);
|
||||
WriteInt32(reply, HC_SUCCESS);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -669,9 +670,10 @@ static uint32_t EncodeCallData(IpcIo *dataParcel, int32_t type, const uint8_t *p
|
||||
paramTmp = (const uint8_t *)(&zeroVal);
|
||||
paramSz = sizeof(zeroVal);
|
||||
}
|
||||
IpcIoPushInt32(dataParcel, type);
|
||||
IpcIoPushFlatObj(dataParcel, (const void *)(paramTmp), (uint32_t)paramSz);
|
||||
if (!IpcIoAvailable(dataParcel)) {
|
||||
WriteInt32(dataParcel, type);
|
||||
WriteUint32(dataParcel, (uint32_t)paramSz);
|
||||
bool ret = WriteBuffer(dataParcel, (const void *)(paramTmp), (uint32_t)paramSz);
|
||||
if (!ret) {
|
||||
return (uint32_t)(HC_ERROR);
|
||||
}
|
||||
return (uint32_t)(HC_SUCCESS);
|
||||
@@ -712,7 +714,9 @@ static bool GaCbOnTransmitWithType(int64_t requestId, const uint8_t *data, uint3
|
||||
UnLockCallbackList();
|
||||
HcFree((void *)dataParcel);
|
||||
LOGI("process done, request id: %lld", requestId);
|
||||
if (IpcIoAvailable(&reply) && (IpcIoPopInt32(&reply) == HC_SUCCESS)) {
|
||||
int32_t value;
|
||||
ReadInt32(&reply, &value);
|
||||
if (value == HC_SUCCESS) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -916,11 +920,9 @@ static char *GaCbOnRequestWithType(int64_t requestId, int32_t operationCode, con
|
||||
ActCallback(node->proxyId, CB_ID_ON_REQUEST, (uintptr_t)(node->cbCtx.devAuth.onRequest), dataParcel, &reply);
|
||||
UnLockCallbackList();
|
||||
HcFree((void *)dataParcel);
|
||||
if (IpcIoAvailable(&reply)) {
|
||||
ret = IpcIoPopInt32(&reply);
|
||||
if (ret == HC_SUCCESS) {
|
||||
dPtr = (const char *)IpcIoPopString(&reply, NULL);
|
||||
}
|
||||
ReadInt32(&reply, &ret);
|
||||
if (ret == HC_SUCCESS) {
|
||||
dPtr = (const char *)ReadString(&reply, NULL);
|
||||
}
|
||||
LOGI("process done, request id: %lld, %s result", requestId, (dPtr != NULL) ? "valid" : "invalid");
|
||||
return (dPtr != NULL) ? strdup(dPtr) : NULL;
|
||||
@@ -1460,14 +1462,17 @@ int32_t IpcEncodeCallReplay(uintptr_t replayCache, int32_t type, const uint8_t *
|
||||
unsigned long valZero = 0ul;
|
||||
|
||||
replyParcel = (IpcIo *)(replayCache);
|
||||
IpcIoPushInt32(replyParcel, type);
|
||||
WriteInt32(replyParcel, type);
|
||||
bool value;
|
||||
if ((result != NULL) && (resultSz > 0)) {
|
||||
IpcIoPushFlatObj(replyParcel, (const void *)result, (uint32_t)resultSz);
|
||||
WriteUint32(replyParcel, (uint32_t)resultSz);
|
||||
value = WriteBuffer(replyParcel, (const void *)result, (uint32_t)resultSz);
|
||||
} else {
|
||||
IpcIoPushFlatObj(replyParcel, (const void *)(&valZero), sizeof(valZero));
|
||||
WriteUint32(replyParcel, sizeof(valZero));
|
||||
value = WriteBuffer(replyParcel, (const void *)(&valZero), sizeof(valZero));
|
||||
}
|
||||
if (!IpcIoAvailable(replyParcel)) {
|
||||
ret = HC_ERROR;
|
||||
if (!value) {
|
||||
return HC_FALSE;
|
||||
}
|
||||
LOGI("reply type %d, %s", type, (ret == HC_SUCCESS) ? "success" : "failed");
|
||||
return ret;
|
||||
@@ -1481,11 +1486,9 @@ int32_t DecodeIpcData(uintptr_t data, int32_t *type, uint8_t **val, int32_t *val
|
||||
if (dataPtr->bufferLeft <= 0) {
|
||||
return HC_SUCCESS;
|
||||
}
|
||||
*type = IpcIoPopInt32(dataPtr);
|
||||
*val = (uint8_t *)IpcIoPopFlatObj(dataPtr, (uint32_t *)valSz);
|
||||
if (!IpcIoAvailable(dataPtr)) {
|
||||
return HC_ERROR;
|
||||
}
|
||||
ReadInt32(dataPtr, type);
|
||||
ReadUint32(dataPtr, (uint32_t *)valSz);
|
||||
*val = (uint8_t *)ReadBuffer(dataPtr, *valSz);
|
||||
return HC_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1496,7 +1499,7 @@ void DecodeCallReply(uintptr_t callCtx, IpcDataInfo *replyCache, int32_t cacheNu
|
||||
uint32_t replyLen;
|
||||
|
||||
ProxyDevAuthData *dataCache = (ProxyDevAuthData *)(callCtx);
|
||||
replyLen = IpcIoPopUint32(dataCache->reply);
|
||||
ReadUint32(dataCache->reply, &replyLen);
|
||||
LOGI("to decode data length %u", replyLen);
|
||||
if (replyLen == 0) {
|
||||
return;
|
||||
@@ -1621,11 +1624,6 @@ IpcIo *InitIpcDataCache(uint32_t buffSz)
|
||||
buf = (uint8_t *)ioPtr + sizeof(IpcIo);
|
||||
/* ipcio inited with 4 svc objects */
|
||||
IpcIoInit(ioPtr, (void *)buf, buffSz, 4);
|
||||
if (!IpcIoAvailable(ioPtr)) {
|
||||
LOGE("IpcIoInit failed");
|
||||
HcFree((void *)ioPtr);
|
||||
return NULL;
|
||||
}
|
||||
return ioPtr;
|
||||
}
|
||||
|
||||
@@ -1634,7 +1632,7 @@ int32_t GetIpcIoDataLength(const IpcIo *io)
|
||||
uintptr_t beginPos;
|
||||
uintptr_t endPos;
|
||||
|
||||
if ((io == NULL) || !IpcIoAvailable((IpcIo *)io)) {
|
||||
if (io == NULL) {
|
||||
return 0;
|
||||
}
|
||||
beginPos = (uintptr_t)(io->bufferBase + IpcIoBufferOffset());
|
||||
@@ -1650,8 +1648,6 @@ void ShowIpcSvcInfo(const SvcIdentity *svc)
|
||||
|
||||
int32_t InitProxyAdapt(void)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
if (g_proxyInstance == NULL) {
|
||||
g_proxyInstance = (IClientProxy *)GetProxyInstance(DEV_AUTH_SERVICE_NAME);
|
||||
if (g_proxyInstance == NULL) {
|
||||
@@ -1662,11 +1658,13 @@ int32_t InitProxyAdapt(void)
|
||||
}
|
||||
|
||||
if (!g_sdkCbStub.registered) {
|
||||
ret = RegisterIpcCallback(CbStubOnRemoteRequest, 0, IPC_WAIT_FOREVER, &(g_sdkCbStub.stubIdentity), NULL);
|
||||
if (ret != 0) {
|
||||
LOGE("register ipc cb failed");
|
||||
return HC_ERR_IPC_INIT;
|
||||
}
|
||||
g_objectStub.func = CbStubOnRemoteRequest;
|
||||
g_objectStub.args = NULL;
|
||||
g_objectStub.isRemote = false;
|
||||
g_sdkCbStub.stubIdentity.handle = IPC_INVALID_HANDLE;
|
||||
g_sdkCbStub.stubIdentity.token = SERVICE_TYPE_ANONYMOUS;
|
||||
g_sdkCbStub.stubIdentity.cookie = (uintptr_t)&g_objectStub;
|
||||
|
||||
ShowIpcSvcInfo(&(g_sdkCbStub.stubIdentity));
|
||||
LOGI("register ipc cb success");
|
||||
g_sdkCbStub.registered = true;
|
||||
@@ -1677,9 +1675,6 @@ int32_t InitProxyAdapt(void)
|
||||
void UnInitProxyAdapt(void)
|
||||
{
|
||||
g_proxyInstance = NULL;
|
||||
if (UnregisterIpcCallback(g_sdkCbStub.stubIdentity)) {
|
||||
LOGW("un-register ipc cb failed");
|
||||
}
|
||||
g_sdkCbStub.registered = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "hc_log.h"
|
||||
#include "hc_types.h"
|
||||
#include "ipc_adapt.h"
|
||||
#include "liteipc_adapter.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "securec.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -28,12 +28,6 @@ static void CbProxyFormReplyData(int32_t reqRetVal, IpcIo *replyDst, const IpcIo
|
||||
{
|
||||
errno_t eno;
|
||||
|
||||
if (!IpcIoAvailable((IpcIo *)replySrc)) {
|
||||
LOGE("reply context is not available");
|
||||
*(int32_t *)(replyDst->bufferCur) = -1;
|
||||
replyDst->bufferLeft = sizeof(int32_t);
|
||||
return;
|
||||
}
|
||||
if (reqRetVal != 0) {
|
||||
*(int32_t *)(replyDst->bufferCur) = reqRetVal;
|
||||
replyDst->bufferLeft = sizeof(int32_t);
|
||||
@@ -65,29 +59,29 @@ void CbProxySendRequest(SvcIdentity sid, int32_t callbackId, uintptr_t cbHook, I
|
||||
if (reqData == NULL) {
|
||||
return;
|
||||
}
|
||||
IpcIoPushInt32(reqData, callbackId);
|
||||
IpcIoPushUintptr(reqData, cbHook);
|
||||
WriteInt32(reqData, callbackId);
|
||||
WritePointer(reqData, cbHook);
|
||||
dataSz = GetIpcIoDataLength((const IpcIo *)data);
|
||||
LOGI("to form callback params data length(%d)", dataSz);
|
||||
if (dataSz > 0) {
|
||||
IpcIoPushFlatObj(reqData, data->bufferBase + IpcIoBufferOffset(), dataSz);
|
||||
}
|
||||
if (!IpcIoAvailable(reqData)) {
|
||||
LOGE("form send data failed");
|
||||
HcFree((void *)reqData);
|
||||
return;
|
||||
WriteUint32(reqData, dataSz);
|
||||
bool value = WriteBuffer(reqData, data->bufferBase + IpcIoBufferOffset(), dataSz);
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* callFlag: ipc mode is blocking or non blocking. */
|
||||
int32_t callFlag = ((reply != NULL) ? LITEIPC_FLAG_DEFAULT : LITEIPC_FLAG_ONEWAY);
|
||||
ret = SendRequest(NULL, sid, DEV_AUTH_CALLBACK_REQUEST, reqData, &replyTmp, callFlag, &outMsg);
|
||||
LOGI("SendRequest(%d) done, return(%d)", callFlag, ret);
|
||||
MessageOption option;
|
||||
MessageOptionInit(&option);
|
||||
option.flags = ((reply != NULL) ? TF_OP_SYNC : TF_OP_ASYNC);
|
||||
ret = SendRequest(sid, DEV_AUTH_CALLBACK_REQUEST, reqData, &replyTmp, option, &outMsg);
|
||||
LOGI("SendRequest(%d) done, return(%d)", option.flags, ret);
|
||||
HcFree((void *)reqData);
|
||||
if (reply == NULL) {
|
||||
FreeBuffer(NULL, (void *)outMsg);
|
||||
return;
|
||||
}
|
||||
CbProxyFormReplyData(ret, reply, &replyTmp);
|
||||
FreeBuffer(NULL, (void *)outMsg);
|
||||
FreeBuffer((void *)outMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "hc_log.h"
|
||||
#include "ipc_adapt.h"
|
||||
#include "ipc_iface.h"
|
||||
#include "liteipc_adapter.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "securec.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -37,7 +37,8 @@ static void DoCallBack(int32_t callbackId, uintptr_t cbHook, IpcIo *data, IpcIo
|
||||
return;
|
||||
}
|
||||
|
||||
(void)IpcIoPopUint32(data); /* skip flat object length information */
|
||||
uint32_t len = 0;
|
||||
ReadUint32(data, &len); /* skip flat object length information */
|
||||
for (i = 0; i < MAX_REQUEST_PARAMS_NUM; i++) {
|
||||
ret = DecodeIpcData((uintptr_t)(data), &(cbDataCache[i].type),
|
||||
&(cbDataCache[i].val), &(cbDataCache[i].valSz));
|
||||
@@ -50,68 +51,30 @@ static void DoCallBack(int32_t callbackId, uintptr_t cbHook, IpcIo *data, IpcIo
|
||||
return;
|
||||
}
|
||||
|
||||
static int32_t CbStubOnRemoteReply(void *ipcMsg, IpcIo *reply)
|
||||
int32_t CbStubOnRemoteRequest(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option)
|
||||
{
|
||||
uint32_t flag = 0;
|
||||
int32_t ret = 0;
|
||||
IpcIo replyErr;
|
||||
uint8_t replyBuff[16] = {0}; /* length of reply buffer - 16 */
|
||||
|
||||
/* flag: ipc mode is blocking or non blocking. */
|
||||
GetFlag(ipcMsg, &flag);
|
||||
if (flag != LITEIPC_FLAG_DEFAULT) {
|
||||
/* Ipc mode is non blocking. */
|
||||
LOGI("callback - async call(%u)", flag);
|
||||
/* If the system is based on liteipc, the ipcMsg memory needs to be cleaned manually. */
|
||||
FreeBuffer(NULL, ipcMsg);
|
||||
return 0;
|
||||
}
|
||||
/* Ipc mode is blocking. */
|
||||
if (!IpcIoAvailable(reply)) {
|
||||
IpcIoInit(&replyErr, replyBuff, sizeof(replyBuff), 0);
|
||||
IpcIoPushInt32(&replyErr, HC_ERR_IPC_INTERNAL_FAILED);
|
||||
LOGI("callback - SendReply error code(%d)", HC_ERR_IPC_INTERNAL_FAILED);
|
||||
ret = SendReply(NULL, ipcMsg, &replyErr);
|
||||
} else {
|
||||
LOGI("callback - SendReply done");
|
||||
ret = SendReply(NULL, ipcMsg, reply);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t CbStubOnRemoteRequest(const IpcContext *ctx, void *ipcMsg, IpcIo *data, void *arg)
|
||||
{
|
||||
uint32_t code = 0;
|
||||
int32_t callbackId;
|
||||
uintptr_t cbHook = 0x0;
|
||||
IpcIo reply;
|
||||
uint8_t replyBuff[1024] = {0}; /* length of reply buffer - 1024 */
|
||||
int32_t ret = 0;
|
||||
(void)ctx;
|
||||
(void)arg;
|
||||
|
||||
LOGI("enter invoking callback...");
|
||||
if ((ipcMsg == NULL) || (data == NULL)) {
|
||||
if (data == NULL) {
|
||||
LOGE("invalid param");
|
||||
return -1;
|
||||
}
|
||||
|
||||
GetCode(ipcMsg, &code);
|
||||
LOGI("receive ipc transact code(%u)", code);
|
||||
IpcIoInit(&reply, replyBuff, sizeof(replyBuff), 0);
|
||||
switch (code) {
|
||||
case DEV_AUTH_CALLBACK_REQUEST:
|
||||
callbackId = IpcIoPopInt32(data);
|
||||
cbHook = IpcIoPopUintptr(data);
|
||||
DoCallBack(callbackId, cbHook, data, &reply);
|
||||
ReadInt32(data, &callbackId);
|
||||
cbHook = ReadPointer(data);
|
||||
DoCallBack(callbackId, cbHook, data, reply);
|
||||
break;
|
||||
default:
|
||||
LOGE("Invoke callback cmd code(%u) error", code);
|
||||
break;
|
||||
}
|
||||
ret = CbStubOnRemoteReply(ipcMsg, &reply);
|
||||
LOGI("Invoke callback done, result(%d)", ret);
|
||||
return ret;
|
||||
LOGI("Invoke callback done, result(%d)", HC_SUCCESS);
|
||||
return HC_SUCCESS;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "common_defs.h"
|
||||
#include "device_auth_defines.h"
|
||||
#include "hc_log.h"
|
||||
#include "liteipc_adapter.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "ipc_adapt.h"
|
||||
#include "ipc_sdk.h"
|
||||
#include "securec.h"
|
||||
@@ -51,11 +51,11 @@ int32_t EncodeCallRequest(ProxyDevAuthData *dataCtx, int32_t type, const uint8_t
|
||||
IpcIo *ioPtr = NULL;
|
||||
LOGI("type %d, paramSz %d", type, paramSz);
|
||||
ioPtr = dataCtx->tmpData;
|
||||
IpcIoPushInt32(ioPtr, type);
|
||||
IpcIoPushFlatObj(ioPtr, param, paramSz);
|
||||
if (!IpcIoAvailable(ioPtr)) {
|
||||
LOGE("request data serialized failed");
|
||||
return HC_ERROR;
|
||||
WriteInt32(ioPtr, type);
|
||||
WriteUint32(ioPtr, paramSz);
|
||||
bool ret = WriteBuffer(ioPtr, param, paramSz);
|
||||
if (!ret) {
|
||||
return HC_FALSE;
|
||||
}
|
||||
dataCtx->paramCnt++;
|
||||
return HC_SUCCESS;
|
||||
@@ -75,10 +75,14 @@ int32_t FinalCallRequest(ProxyDevAuthData *dataCtx, int32_t methodId)
|
||||
LOGI("method id %d, param num %d, data length %d, flag %u, io offset %d",
|
||||
methodId, dataCtx->paramCnt, dataLen, ioPtr->flag, dataCtx->ioBuffOffset);
|
||||
/* request data length = number of params + params information */
|
||||
IpcIoPushInt32(ioPtr, methodId);
|
||||
IpcIoPushInt32(ioPtr, dataLen + sizeof(int32_t));
|
||||
IpcIoPushInt32(ioPtr, dataCtx->paramCnt);
|
||||
IpcIoPushFlatObj(ioPtr, (const uint8_t *)(dataCtx->tmpData->bufferBase + dataCtx->ioBuffOffset), dataLen);
|
||||
WriteInt32(ioPtr, methodId);
|
||||
WriteInt32(ioPtr, dataLen + sizeof(int32_t));
|
||||
WriteInt32(ioPtr, dataCtx->paramCnt);
|
||||
WriteUint32(ioPtr, dataLen);
|
||||
bool ret = WriteBuffer(ioPtr, (const uint8_t *)(dataCtx->tmpData->bufferBase + dataCtx->ioBuffOffset), dataLen);
|
||||
if (!ret) {
|
||||
return HC_FALSE;
|
||||
}
|
||||
if (dataCtx->withCallback) {
|
||||
SvcIdentity badSvc = {0};
|
||||
ShowIpcSvcInfo(&(dataCtx->cbSvc));
|
||||
@@ -88,15 +92,13 @@ int32_t FinalCallRequest(ProxyDevAuthData *dataCtx, int32_t methodId)
|
||||
dataCtx->withCallback = false;
|
||||
return HC_ERROR;
|
||||
}
|
||||
IpcIoPushInt32(ioPtr, PARAM_TYPE_CB_OBJECT);
|
||||
IpcIoPushSvc(ioPtr, &(dataCtx->cbSvc));
|
||||
WriteInt32(ioPtr, PARAM_TYPE_CB_OBJECT);
|
||||
if (!WriteRemoteObject(ioPtr, &(dataCtx->cbSvc))) {
|
||||
return HC_FALSE;
|
||||
}
|
||||
LOGI("ipc call with callback, data flag %u", ioPtr->flag);
|
||||
}
|
||||
dataCtx->withCallback = false;
|
||||
if (!IpcIoAvailable(ioPtr)) {
|
||||
LOGE("request data serialized failed");
|
||||
return HC_ERROR;
|
||||
}
|
||||
return HC_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -110,10 +112,6 @@ static int32_t CliInvokeRetCallback(IOwner owner, int32_t code, IpcIo *reply)
|
||||
LOGE("invalid params");
|
||||
return -1;
|
||||
}
|
||||
if (!IpcIoAvailable(reply)) {
|
||||
LOGE("invalid reply data");
|
||||
return -1;
|
||||
}
|
||||
dstReply = (IpcIo *)owner;
|
||||
eno = memcpy_s(dstReply->bufferCur, dstReply->bufferLeft, reply->bufferCur, reply->bufferLeft);
|
||||
if (eno != EOK) {
|
||||
@@ -140,10 +138,8 @@ int32_t ActCall(const IClientProxy *clientInst, ProxyDevAuthData *dataCtx)
|
||||
dataCtx->data, (IOwner)(dataCtx->reply), CliInvokeRetCallback);
|
||||
LOGI("invoke call done, ipc result(%d)", ipcRet);
|
||||
ret = HC_ERROR;
|
||||
if (IpcIoAvailable(dataCtx->reply)) {
|
||||
ret = IpcIoPopInt32(dataCtx->reply);
|
||||
LOGI("service call result(%d)", ret);
|
||||
}
|
||||
ReadInt32(dataCtx->reply, &ret);
|
||||
LOGI("service call result(%d)", ret);
|
||||
return ((ipcRet == 0) && (ret == HC_SUCCESS)) ? HC_SUCCESS : HC_ERR_IPC_INTERNAL_FAILED;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "hc_log.h"
|
||||
#include "hc_mutex.h"
|
||||
#include "hc_types.h"
|
||||
#include "liteipc_adapter.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "ipc_adapt.h"
|
||||
#include "ipc_callback_proxy.h"
|
||||
#include "ipc_sdk.h"
|
||||
@@ -49,27 +49,20 @@ int32_t g_callMapElemNum = 0;
|
||||
|
||||
#define IPC_IO_BUFF_SZ 1024
|
||||
|
||||
static int32_t BinderLiteProcess(SvcIdentity **svc, int32_t procType)
|
||||
static int32_t BinderLiteProcess(SvcIdentity svc, int32_t procType)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
#ifdef __LINUX__
|
||||
switch (procType) {
|
||||
case BINDER_TYPE_ACQUIRE:
|
||||
ret = BinderAcquire((*svc)->ipcContext, (*svc)->handle);
|
||||
break;
|
||||
case BINDER_TYPE_ACQUIRE_AND_FREE:
|
||||
ret = BinderAcquire((*svc)->ipcContext, (*svc)->handle);
|
||||
HcFree((void *)(*svc));
|
||||
*svc = NULL;
|
||||
break;
|
||||
case BINDER_TYPE_RELEASE:
|
||||
(void)BinderRelease((*svc)->ipcContext, (*svc)->handle);
|
||||
(void)ReleaseSvc(svc);
|
||||
break;
|
||||
default:
|
||||
LOGW("internal error: unknown processing type");
|
||||
}
|
||||
#endif
|
||||
return (ret == 0) ? HC_SUCCESS : HC_ERROR;
|
||||
return HC_SUCCESS;
|
||||
}
|
||||
|
||||
void ResetCallMap(void)
|
||||
@@ -104,19 +97,20 @@ static int32_t DecodeCallRequest(IpcIo *data, IpcDataInfo *paramsCache, int32_t
|
||||
int32_t i;
|
||||
int32_t ret;
|
||||
|
||||
dataLen = IpcIoPopInt32(data);
|
||||
ReadInt32(data, &dataLen);
|
||||
if (dataLen <= 0) {
|
||||
return HC_ERR_IPC_BAD_MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
*inParamNum = IpcIoPopInt32(data);
|
||||
ReadInt32(data, inParamNum);
|
||||
if ((*inParamNum < 0) || (*inParamNum > cacheNum)) {
|
||||
LOGE("param number invalid, inParamNum(%d)", *inParamNum);
|
||||
return HC_ERR_IPC_BAD_PARAM_NUM;
|
||||
}
|
||||
LOGI("request data length(%d), param number: %d", dataLen - sizeof(int32_t), *inParamNum);
|
||||
|
||||
(void)IpcIoPopUint32(data); /* skip flat object length information */
|
||||
uint32_t len = 0;
|
||||
ReadUint32(data, &len); /* skip flat object length information */
|
||||
for (i = 0; i < *inParamNum; i++) {
|
||||
ret = DecodeIpcData((uintptr_t)data, &(paramsCache[i].type), &(paramsCache[i].val), &(paramsCache[i].valSz));
|
||||
if (ret != HC_SUCCESS) {
|
||||
@@ -130,7 +124,7 @@ static int32_t DecodeCallRequest(IpcIo *data, IpcDataInfo *paramsCache, int32_t
|
||||
|
||||
static int32_t GetMethodId(IpcIo *data, int32_t *methodId)
|
||||
{
|
||||
*methodId = IpcIoPopInt32(data);
|
||||
ReadInt32(data, methodId);
|
||||
LOGI("GetMethodId, id code %d", *methodId);
|
||||
return HC_SUCCESS;
|
||||
}
|
||||
@@ -138,23 +132,23 @@ static int32_t GetMethodId(IpcIo *data, int32_t *methodId)
|
||||
static void WithObject(int32_t methodId, IpcIo *data, IpcDataInfo *ipcData, int32_t *cnt)
|
||||
{
|
||||
if (IsCallbackMethod(methodId)) {
|
||||
ipcData->type = IpcIoPopInt32(data);
|
||||
ReadInt32(data, &(ipcData->type));
|
||||
ipcData->valSz = 0;
|
||||
SvcIdentity *tmp = IpcIoPopSvc(data);
|
||||
if (!tmp || (ipcData->type != PARAM_TYPE_CB_OBJECT)) {
|
||||
SvcIdentity tmp;
|
||||
bool ret = ReadRemoteObject(data, &tmp);
|
||||
if (!ret || (ipcData->type != PARAM_TYPE_CB_OBJECT)) {
|
||||
LOGE("should with remote object, but failed, param type %d", ipcData->type);
|
||||
return;
|
||||
}
|
||||
ShowIpcSvcInfo(tmp);
|
||||
ipcData->idx = SetRemoteObject(tmp);
|
||||
ShowIpcSvcInfo(&tmp);
|
||||
ipcData->idx = SetRemoteObject(&tmp);
|
||||
if (ipcData->idx >= 0) {
|
||||
if (BinderLiteProcess(&tmp, BINDER_TYPE_ACQUIRE_AND_FREE) == HC_SUCCESS) {
|
||||
if (BinderLiteProcess(tmp, BINDER_TYPE_ACQUIRE_AND_FREE) == HC_SUCCESS) {
|
||||
ipcData->val = (uint8_t *)(&(ipcData->idx));
|
||||
LOGI("object trans success, set id %d", ipcData->idx);
|
||||
(*cnt)++;
|
||||
}
|
||||
}
|
||||
tmp = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -214,7 +208,7 @@ static struct {
|
||||
{DevAuthRequestCall, DEV_AUTH_CALL_REQUEST},
|
||||
};
|
||||
|
||||
int32_t OnRemoteRequest(IServerProxy *iProxy, int32_t reqId, void *origin, IpcIo *req, IpcIo *reply)
|
||||
int32_t OnRemoteInvoke(IServerProxy *iProxy, int32_t reqId, void *origin, IpcIo *req, IpcIo *reply)
|
||||
{
|
||||
int32_t i;
|
||||
int32_t n;
|
||||
@@ -238,11 +232,16 @@ int32_t OnRemoteRequest(IServerProxy *iProxy, int32_t reqId, void *origin, IpcIo
|
||||
if (callCtx) {
|
||||
ret = callCtx(origin, req, &replyTmp);
|
||||
}
|
||||
IpcIoPushInt32(reply, ret);
|
||||
WriteInt32(reply, ret);
|
||||
if (reply != NULL) {
|
||||
n = GetIpcIoDataLength(&replyTmp);
|
||||
if (n > 0) {
|
||||
IpcIoPushFlatObj(reply, (const void *)(replyTmp.bufferBase + IpcIoBufferOffset()), n);
|
||||
WriteUint32(reply, n);
|
||||
bool ret = WriteBuffer(reply, (const void *)(replyTmp.bufferBase + IpcIoBufferOffset()), n);
|
||||
if (!ret) {
|
||||
LOGI("WriteBuffer faild");
|
||||
return HC_ERROR;
|
||||
}
|
||||
LOGI("form service result done, result length(%d)", n);
|
||||
}
|
||||
}
|
||||
@@ -253,7 +252,6 @@ int32_t OnRemoteRequest(IServerProxy *iProxy, int32_t reqId, void *origin, IpcIo
|
||||
int32_t SetCallMap(IpcServiceCall method, int32_t methodId)
|
||||
{
|
||||
int32_t len;
|
||||
errno_t eno;
|
||||
IpcServiceCallMap *callMapTmp = NULL;
|
||||
|
||||
if ((1 + g_callMapElemNum) > g_maxCallMapSz) {
|
||||
@@ -271,7 +269,7 @@ int32_t SetCallMap(IpcServiceCall method, int32_t methodId)
|
||||
}
|
||||
(void)memset_s(g_callMapTable, len, 0, len);
|
||||
if (callMapTmp != NULL) {
|
||||
eno = memcpy_s(g_callMapTable, len, callMapTmp, (sizeof(IpcServiceCallMap) * g_callMapElemNum));
|
||||
errno_t eno = memcpy_s(g_callMapTable, len, callMapTmp, (sizeof(IpcServiceCallMap) * g_callMapElemNum));
|
||||
if (eno != EOK) {
|
||||
HcFree((void *)g_callMapTable);
|
||||
g_callMapTable = callMapTmp;
|
||||
@@ -313,13 +311,12 @@ int32_t SetRemoteObject(const SvcIdentity *object)
|
||||
return idx;
|
||||
}
|
||||
|
||||
static int32_t ClientDeathCallback(const IpcContext *context, void *ipcMsg, IpcIo *data, void *arg)
|
||||
static void ClientDeathCallback(void *arg)
|
||||
{
|
||||
int32_t callbackIdx = (int32_t)arg;
|
||||
|
||||
LOGI("remote is not actively, to reset local resource");
|
||||
ResetIpcCallBackNodeByNodeId(callbackIdx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AddCbDeathRecipient(int32_t objIdx, int32_t cbDataIdx)
|
||||
@@ -335,7 +332,7 @@ void AddCbDeathRecipient(int32_t objIdx, int32_t cbDataIdx)
|
||||
UnLockCbStubTable();
|
||||
return;
|
||||
}
|
||||
ret = RegisterDeathCallback(NULL, g_cbStub[objIdx].cbStub, ClientDeathCallback, (void *)cbDataIdx, &cbId);
|
||||
ret = AddDeathRecipient(g_cbStub[objIdx].cbStub, ClientDeathCallback, (void *)cbDataIdx, &cbId);
|
||||
if (ret == 0) {
|
||||
g_cbStub[objIdx].cbDieId = cbId;
|
||||
}
|
||||
@@ -353,9 +350,9 @@ void ResetRemoteObject(int32_t idx)
|
||||
UnLockCbStubTable();
|
||||
return;
|
||||
}
|
||||
UnregisterDeathCallback(g_cbStub[idx].cbStub, g_cbStub[idx].cbDieId);
|
||||
SvcIdentity *tmpStub = &g_cbStub[idx].cbStub;
|
||||
(void)BinderLiteProcess(&tmpStub, BINDER_TYPE_RELEASE);
|
||||
RemoveDeathRecipient(g_cbStub[idx].cbStub, g_cbStub[idx].cbDieId);
|
||||
SvcIdentity tmpStub = g_cbStub[idx].cbStub;
|
||||
(void)BinderLiteProcess(tmpStub, BINDER_TYPE_RELEASE);
|
||||
(void)memset_s(&(g_cbStub[idx].cbStub), sizeof(g_cbStub[idx].cbStub), 0, sizeof(g_cbStub[idx].cbStub));
|
||||
g_cbStub[idx].inUse = false;
|
||||
UnLockCbStubTable();
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "device_auth_defines.h"
|
||||
#include "hc_log.h"
|
||||
#include "ipc_dev_auth_stub.h"
|
||||
#include "liteipc_adapter.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "ohos_init.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -69,7 +69,7 @@ void ServiceInit(void)
|
||||
.MessageHandle = MessageHandle,
|
||||
.GetTaskConfig = GetTaskConfig,
|
||||
SERVER_IPROXY_IMPL_BEGIN,
|
||||
.Invoke = OnRemoteRequest,
|
||||
.Invoke = OnRemoteInvoke,
|
||||
IPROXY_END,
|
||||
};
|
||||
|
||||
|
||||
+3
-4
@@ -73,7 +73,6 @@ if (os_level == "mini" || os_level == "small") {
|
||||
"//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
"${frameworks_path}/inc/lite",
|
||||
"//foundation/communication/ipc_lite/interfaces/kits",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr",
|
||||
]
|
||||
|
||||
@@ -94,7 +93,7 @@ if (os_level == "mini" || os_level == "small") {
|
||||
"${deps_adapter_path}:${hal_module_name}",
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
|
||||
"//build/lite/config/component/cJSON:cjson_shared",
|
||||
"//foundation/communication/ipc_lite:liteipc_adapter",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/c/ipc:ipc_single",
|
||||
"//foundation/distributedschedule/samgr_lite/samgr:samgr",
|
||||
"//third_party/bounds_checking_function:libsec_shared",
|
||||
"//utils/native/lite:utils",
|
||||
@@ -109,7 +108,7 @@ if (os_level == "mini" || os_level == "small") {
|
||||
"//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
"${frameworks_path}/inc/lite",
|
||||
"//foundation/communication/ipc_lite/interfaces/kits",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/c/ipc/include",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr",
|
||||
]
|
||||
|
||||
@@ -126,7 +125,7 @@ if (os_level == "mini" || os_level == "small") {
|
||||
deps = [
|
||||
"${deps_adapter_path}:${hal_module_name}",
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
|
||||
"//foundation/communication/ipc_lite:liteipc_adapter",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/c/ipc:ipc_single",
|
||||
"//foundation/distributedschedule/samgr_lite/samgr:samgr",
|
||||
"//third_party/bounds_checking_function:libsec_shared",
|
||||
"//utils/native/lite:utils",
|
||||
|
||||
Reference in New Issue
Block a user