提交 d52c4079 编写于 作者: O openharmony_ci 提交者: Gitee

!318 hichainL0代码合入

Merge pull request !318 from 胡吉翔/security_lite_20210712
# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
#import("//build/lite/config/component/zlite_component.gni")
#import("//build/lite/ndk/ndk.gni")
import("//test/xts/tools/lite/build/suite_lite.gni")
hctest_suite("ActsSecurityHichainTest0") {
suite_name = "acts"
defines = [ "HILINE_E2E_SECURITY_CONFIG" ]
sources = [
"src/hichain_function_test.c",
# "src/hichain_huks_adapt.c",
]
include_dirs = [
"//base/security/huks/interfaces/innerkits/huks_lite/",
"//third_party/cJSON",
"//base/security/deviceauth/interfaces/innerkits/deviceauth_lite",
"//base/security/deviceauth/frameworks/deviceauth_lite/source/huks_adapter",
"//base/security/deviceauth/frameworks/deviceauth_lite/source/base",
"//base/security/deviceauth/frameworks/deviceauth_lite/source/json",
"//base/security/deviceauth/frameworks/deviceauth_lite/source/key_agreement",
"//base/security/deviceauth/frameworks/deviceauth_lite/source/log",
"//base/security/deviceauth/frameworks/deviceauth_lite/source/schedule",
"//base/security/deviceauth/frameworks/deviceauth_lite/source/struct",
"//base/security/deviceauth/frameworks/deviceauth_lite/source/auth_info",
"//third_party/bounds_checking_function/include",
"//kernel/liteos_a/test/kernel/sample/lwip2.0_linux_CI/dependency/include",
"dbg_code",
"gtest",
"//base/security/huks/interfaces/innerkits/huks_lite/",
]
cflags = [ "-Wno-error" ]
}
{
"description": "Config for hcpptest demo test cases",
"environment": [
{
"type": "device",
"label": "ipcamera"
}
],
"kits": [
{
"type": "MountKit",
"server": "NfsServer",
"mount": [
{
"source": "testcases/security",
"target": "/test_root/security"
}
]
}
],
"driver": {
"type": "CppTestLite",
"execute": "/test_root/security/ActsSecurityHichainTest.bin"
}
}
\ No newline at end of file
{
"description": "Config for $module test cases",
"environment": [
{
"type": "device",
"label": "wifiiot"
}
],
"kits": [
{
"type": "DeployKit",
"timeout": "20000",
"burn_file": "$subsystem/$module.bin"
}
],
"driver": {
"type": "CTestLite"
}
}
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DEVICE_AUTH_H
#define DEVICE_AUTH_H
#include <stdint.h>
#include <stdbool.h>
#if defined(_LINUX) || defined(_UNIX)
#define DEVICE_AUTH_API_PUBLIC __attribute__ ((visibility("default")))
#else
#define DEVICE_AUTH_API_PUBLIC
#endif
#define FIELD_GROUP_ID "groupId"
#define FIELD_GROUP_TYPE "groupType"
#define FIELD_GROUP_NAME "groupName"
#define FIELD_PEER_DEVICE_ID "peerDeviceId"
#define FIELD_IS_ADMIN "isAdmin"
#define FIELD_CREDENTIAL_TYPE "credentialType"
#define FIELD_IS_FORCE_DELETE "isForceDelete"
#define FIELD_IS_IGNORE_CHANNEL "isIgnoreChannel"
#define FIELD_CONNECT_PARAMS "connectParams"
#define FIELD_ADD_ID "addId"
#define FIELD_DELETE_ID "deleteId"
#define FIELD_APP_ID "appId"
#define FIELD_SERVICE_TYPE "serviceType"
#define FIELD_PEER_AUTH_STATE "peerAuthState"
#define FIELD_IS_DEVICE_LEVEL "isDeviceLevel"
#define FIELD_ALTERNATIVE "alternative"
#define FIELD_PEER_UDID "peerUdid"
#define FIELD_PEER_CONN_DEVICE_ID "peerConnDeviceId"
#define FIELD_KEY_LENGTH "keyLength"
#define FIELD_IS_CLIENT "isClient"
#define FIELD_SESSION_KEY "sessionKey"
#define FIELD_AUTH_FORM "authForm"
#define FIELD_CONFIRMATION "confirmation"
#define FIELD_GROUP_OWNER "groupOwner"
#define FIELD_PEER_AUTH_ID "peerAuthId"
#define FIELD_PEER_USER_TYPE "peerUserType"
#define FIELD_PEER_USER_ID "peerUserId"
#define FIELD_SERVICE_PKG_NAME "servicePkgName"
#define FIELD_USER_TYPE "userType"
#define FIELD_USER_ID "userId"
#define FIELD_DEVICE_ID "deviceId"
#define FIELD_UID_HASH "uidHash"
#define FIELD_PIN_CODE "pinCode"
#define FIELD_AUTH_ID "authId"
#define FIELD_GROUP_VISIBILITY "groupVisibility"
#define FIELD_EXPIRE_TIME "expireTime"
#define FIELD_IS_DELETE_ALL "isDeleteAll"
typedef enum {
GROUP_CREATE = 0,
GROUP_DISBAND = 1,
MEMBER_INVITE = 2,
MEMBER_JOIN = 3,
MEMBER_DELETE = 4,
ACCOUNT_BIND = 5
} GroupOperationCode;
typedef enum {
CREDENTIAL_SAVE = 0,
CREDENTIAL_CLEAR = 1,
CREDENTIAL_UPDATE = 2,
CREDENTIAL_QUERY = 3,
} CredentialCode;
typedef enum {
DEVICE_TYPE_ACCESSORY = 0,
DEVICE_TYPE_CONTROLLER = 1,
DEVICE_TYPE_PROXY = 2
} UserType;
#define REQUEST_REJECTED 0x80000005
#define REQUEST_ACCEPTED 0x80000006
#define REQUEST_WAITING 0x80000007
typedef struct {
void (*onGroupCreated)(const char *groupInfo);
void (*onGroupDeleted)(const char *groupInfo);
void (*onDeviceBound)(const char *peerUdid, const char *groupInfo);
void (*onDeviceUnBound)(const char *peerUdid, const char *groupInfo);
void (*onDeviceNotTrusted)(const char *peerUdid);
void (*onLastGroupDeleted)(const char *peerUdid, int groupType);
void (*onTrustedDeviceNumChanged)(int curTrustedDeviceNum);
} DataChangeListener;
typedef struct {
bool (*onTransmit)(int64_t requestId, const uint8_t *data, uint32_t dataLen);
void (*onSessionKeyReturned)(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen);
void (*onFinish)(int64_t requestId, int operationCode, const char *returnData);
void (*onError)(int64_t requestId, int operationCode, int errorCode, const char *errorReturn);
char *(*onRequest)(int64_t requestId, int operationCode, const char *reqParams);
} DeviceAuthCallback;
typedef struct {
int32_t (*processData)(int64_t authReqId, const uint8_t *data, uint32_t dataLen,
const DeviceAuthCallback *gaCallback);
int32_t (*queryTrustedDeviceNum)(void);
bool (*isTrustedDevice)(const char *udid);
int32_t (*getAuthState)(int64_t authReqId, const char *groupId, const char *peerUdid,
uint8_t *out, uint32_t *outLen);
int32_t (*authDevice)(int64_t authReqId, const char *authParams, const DeviceAuthCallback *gaCallback);
void (*informDeviceDisconnection)(const char *udid);
} GroupAuthManager;
typedef struct {
int32_t (*regCallback)(const char *appId, const DeviceAuthCallback *callback);
int32_t (*unRegCallback)(const char *appId);
int32_t (*regDataChangeListener)(const char *appId, const DataChangeListener *listener);
int32_t (*unRegDataChangeListener)(const char *appId);
int32_t (*createGroup)(int64_t requestId, const char *appId, const char *createParams);
int32_t (*deleteGroup)(int64_t requestId, const char *appId, const char *disbandParams);
int32_t (*addMemberToGroup)(int64_t requestId, const char *appId, const char *addParams);
int32_t (*deleteMemberFromGroup)(int64_t requestId, const char *appId, const char *deleteParams);
int32_t (*processData)(int64_t requestId, const uint8_t *data, uint32_t dataLen);
int32_t (*confirmRequest)(int64_t requestId, const char *appId, const char *confirmParams);
int32_t (*bindPeer)(int64_t requestId, const char *appId, const char *bindParams);
int32_t (*unbindPeer)(int64_t requestId, const char *appId, const char *unBindParams);
int32_t (*processLiteData)(int64_t requestId, const char *appId, const uint8_t *data, uint32_t dataLen);
int32_t (*authKeyAgree)(int64_t requestId, const char *appId, const char *buildParams);
int32_t (*processKeyAgreeData)(int64_t requestId, const char *appId, const uint8_t *data, uint32_t dataLen);
int32_t (*processCredential)(int operationCode, const char *reqJsonStr, char **returnJsonStr);
int32_t (*getRegisterInfo)(char **returnRegisterInfo);
int32_t (*getLocalConnectInfo)(char **returnInfo);
int32_t (*addGroupManager)(const char *appId, const char *groupId, const char *managerAppId);
int32_t (*addGroupFriend)(const char *appId, const char *groupId, const char *friendAppId);
int32_t (*deleteGroupManager)(const char *appId, const char *groupId, const char *managerAppId);
int32_t (*deleteGroupFriend)(const char *appId, const char *groupId, const char *friendAppId);
int32_t (*getGroupManagers)(const char *appId, const char *groupId, char **returnManagers, uint32_t *returnSize);
int32_t (*getGroupFriends)(const char *appId, const char *groupId, char **returnFriends, uint32_t *returnSize);
int32_t (*getGroupInfoById)(const char *appId, const char *groupId, char **returnGroupInfo);
int32_t (*getGroupInfo)(const char *appId, const char *queryParams, char **returnGroupVec, uint32_t *groupNum);
int32_t (*getJoinedGroups)(const char *appId, int groupType, char **returnGroupVec, uint32_t *groupNum);
int32_t (*getRelatedGroups)(const char *appId, const char *peerDeviceId, char **returnGroupVec, uint32_t *groupNum);
int32_t (*getDeviceInfoById)(const char *appId, const char *deviceId, const char *groupId, char **returnDeviceInfo);
int32_t (*getTrustedDevices)(const char *appId, const char *groupId, char **returnDevInfoVec, uint32_t *deviceNum);
bool (*isDeviceInGroup)(const char *appId, const char *groupId, const char *deviceId);
void (*destroyInfo)(char **returnInfo);
} DeviceGroupManager;
#ifdef __cplusplus
extern "C" {
#endif
DEVICE_AUTH_API_PUBLIC int InitDeviceAuthService();
DEVICE_AUTH_API_PUBLIC void DestroyDeviceAuthService();
DEVICE_AUTH_API_PUBLIC const GroupAuthManager *GetGaInstance();
DEVICE_AUTH_API_PUBLIC const DeviceGroupManager *GetGmInstance();
#ifdef __cplusplus
}
#endif
#endif
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DEVICE_AUTH_DEFINES_H
#define DEVICE_AUTH_DEFINES_H
#define HC_GROUP_FRIEND_MAX_NUM 100 /* Visibility is 1, friend list is available, and max is 100 */
#define HC_GROUP_MANAGER_MAX_NUM 10 /* manager max number is 10, it includes owner and other managers */
enum {
/* common error code, 0x00000000 ~ 0x00000FFF */
HC_SUCCESS = 0x00000000,
HC_ERROR = 0x00000001,
HC_ERR_INVALID_PARAMS = 0x00000002,
HC_ERR_INVALID_LEN = 0x00000003,
HC_ERR_NULL_PTR = 0x00000004,
HC_ERR_ALLOC_MEMORY = 0x00000005,
HC_ERR_MEMORY_COPY = 0x00000006,
HC_HEX_CONVERT_FAILED = 0x00000007,
HC_ERR_NOT_SUPPORT = 0x00000008,
HC_ERR_TIME_OUT = 0x00000009,
HC_ERR_CASE = 0x0000000A,
HC_ERR_BAD_TIMING = 0x0000000B,
HC_ERR_PEER_ERROR = 0x0000000C,
/* error code for huks adapter , 0x00001000 ~ 0x00001FFF */
HC_ERR_KEY_NOT_EXIST = 0x00001001,
HC_ERR_GENERATE_KEY_FAILED = 0x000010002,
HC_ERR_INVALID_PUBLIC_KEY = 0x00001003,
HC_ERR_VERIFY_FAILED = 0x00001004,
HC_ERR_HASH_FAIL = 0x00001005,
/* error code for json util , 0x00002000 ~ 0x00002FFF */
HC_ERR_JSON_FAIL = 0x00002001,
HC_ERR_JSON_CREATE = 0x00002002,
HC_ERR_JSON_GET = 0x00002003,
HC_ERR_JSON_ADD = 0x00002004,
HC_ERR_PACKAGE_JSON_TO_STRING_FAIL = 0x00002005,
/* error code for ipc, 0x00003000 ~ 0x00003FFF */
HC_ERR_IPC_INTERNAL_FAILED = 0x00003001,
HC_ERR_IPC_UNKNOW_OPCODE = 0x00003002,
HC_ERR_IPC_CALL_DATA_LENGTH = 0x00003003,
HC_ERR_IPC_METHOD_ID_INVALID = 0x00003004,
HC_ERR_IPC_BAD_MESSAGE_LENGTH = 0x00003005,
HC_ERR_IPC_BAD_VAL_LENGTH = 0x00003006,
HC_ERR_IPC_BAD_PARAM_NUM = 0x00003007,
HC_ERR_IPC_BAD_MSG_TYPE = 0x00003008,
HC_ERR_IPC_GET_SERVICE = 0x00003009,
HC_ERR_IPC_GET_PROXY = 0x0000300A,
HC_ERR_IPC_INIT = 0x0000300B,
HC_ERR_IPC_BUILD_PARAM = 0x0000300C,
HC_ERR_IPC_PROC_FAILED = 0x0000300D,
HC_ERR_IPC_UNKNOW_REPLAY = 0x0000300E,
HC_ERR_IPC_OUT_DATA_NUM = 0x0000300F,
HC_ERR_IPC_OUT_DATA = 0x00003010,
/* error code for module , 0x00004000 ~ 0x00004FFF */
HC_ERR_MODULE_NOT_FOUNT = 0x00004001,
HC_ERR_UNSUPPORTED_METHOD = 0x00004002,
HC_ERR_UNSUPPORTED_VERSION = 0x00004003,
HC_ERR_UNSUPPORTED_CURVE = 0x00004004,
HC_ERR_BAD_MESSAGE = 0x00004005,
HC_ERR_PROOF_NOT_MATCH = 0x00004006,
HC_ERR_INIT_TASK_FAIL = 0x00004007,
HC_ERR_TASK_IS_NULL = 0x00004008,
HC_ERR_TASK_ID_IS_NOT_MATCH = 0x00004009,
HC_ERR_INVALID_ALG = 0x0000400A,
HC_ERR_IGNORE_MSG = 0x0000400B,
HC_ERR_LOCAL_IDENTITY_NOT_EXIST = 0x0000400C,
/* error code for group , 0x00005000 ~ 0x00005FFF */
HC_ERR_ACCESS_DENIED = 0x00005001,
HC_ERR_CALLBACK_NOT_FOUND = 0x00005002,
HC_ERR_SERVICE_NEED_RESTART = 0x00005003,
HC_ERR_NO_CANDIDATE_GROUP = 0x00005004,
HC_ERR_TRANSMIT_FAIL = 0x00005005,
HC_ERR_REQUEST_EXIST = 0x00005006,
HC_ERR_REQUEST_NOT_FOUND = 0x00005007,
HC_ERR_SESSION_NOT_EXIST = 0x00005008,
HC_ERR_SESSION_ID_CONFLICT = 0x00005009,
HC_ERR_REQ_REJECTED = 0x0000500A,
HC_ERR_SERVER_CONFIRM_FAIL = 0x0000500B,
HC_ERR_CREATE_SESSION_FAIL = 0x0000500C,
HC_ERR_SESSION_IS_FULL = 0x0000500D,
/* error code for database , 0x00006000 ~ 0x00006FFF */
HC_ERR_DB = 0x00006001,
HC_ERR_BEYOND_LIMIT = 0x00006002,
HC_ERR_SAVE_DB_FAILED = 0x00006003,
HC_ERR_FRIEND_NOT_EXIST = 0x00006004,
HC_ERR_MANAGER_NOT_EXIST = 0x00006005,
HC_ERR_GROUP_DUPLICATE = 0x00006006,
HC_ERR_GROUP_NOT_EXIST = 0x00006007,
HC_ERR_DEVICE_NOT_EXIST = 0x00006008,
HC_ERR_DEVICE_DUPLICATE = 0x00006009,
HC_ERR_LOST_DATA = 0x0000600A,
/* error code for broadcast , 0x00007000 ~ 0x00007FFF */
HC_ERR_LISTENER_NOT_EXIST = 0x000070012,
/* error code for channel , 0x00008000 ~ 0x00008FFF */
HC_ERR_CHANNEL_NOT_EXIST = 0x000080012,
HC_ERR_SOFT_BUS = 0x00008002,
/* error code used on DAS service */
INVALID_PARAMETERS = 0xF0000001,
EXCEED_AUTHORITY = 0xF0000002,
TIMEOUT = 0xF0000003,
NOT_REGISTERED = 0xF0000004,
NOT_TRUST_PEER = 0xF0000005,
NOT_TRUST_CONTROLLER = 0xF0000006,
NOT_TRUST_ACCESSORY = 0xF0000007,
OVER_MAX_TRUST_NUM = 0xF0000008,
CONNECTION_INTERRUPTED = 0xF0000009,
UNSUPPORTED_VERSION = 0xF000000A,
BAD_PAYLOAD = 0xF000000B,
ALGORITHM_UNSUPPORTED = 0xF000000C,
PROOF_MISMATCH = 0xF000000D,
UNKOWN = 0xF0000000,
};
#endif
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ipc_sdk.h"
#include "common_defs.h"
#include "device_auth_defines.h"
#include "device_auth.h"
#include "hc_log.h"
#include "hc_mutex.h"
#include "ipc_adapt.h"
#include "securec.h"
#ifdef __cplusplus
extern "C" {
#endif
#define IPC_DATA_CACHES_3 3
#define IPC_DATA_CACHES_4 4
#define REPLAY_CACHE_NUM(caches) (sizeof(caches) / sizeof(IpcDataInfo))
#define IPC_APPID_LEN 128
#define IS_STRING_VALID(str) (((str) != NULL) && ((str)[0] != 0))
#define IS_COMM_DATA_VALID(dPtr, dLen) (((dPtr) != NULL) && ((dLen) > 0) && ((dLen) <= 4096))
typedef struct {
uintptr_t inst;
char appId[IPC_APPID_LEN];
} IpcProxyCbInfo;
static IpcProxyCbInfo g_ipcProxyCbList = {0};
static IpcProxyCbInfo g_ipcListenerCbList = {0};
static HcMutex g_ipcMutex;
static void DelIpcCliCallbackCtx(const char *appId, IpcProxyCbInfo *cbCache)
{
int32_t ret;
if (cbCache->appId[0] == 0) {
return;
}
g_ipcMutex.lock(&g_ipcMutex);
ret = memcmp(appId, cbCache->appId, strlen(cbCache->appId) + 1);
if (ret == 0) {
cbCache->appId[0] = 0;
}
g_ipcMutex.unlock(&g_ipcMutex);
return;
}
static void AddIpcCliCallbackCtx(const char *appId, uintptr_t cbInst, IpcProxyCbInfo *cbCache)
{
errno_t eno;
LOGI("starting ...");
g_ipcMutex.lock(&g_ipcMutex);
eno = memcpy_s(cbCache->appId, IPC_APPID_LEN, appId, strlen(appId) + 1);
if (eno != EOK) {
g_ipcMutex.unlock(&g_ipcMutex);
LOGE("memory copy failed");
return;
}
cbCache->inst = cbInst;
g_ipcMutex.unlock(&g_ipcMutex);
LOGI("success, appid: %s", appId);
return;
}
static void GetIpcReplyByType(const IpcDataInfo *ipcData,
int32_t dataNum, int32_t type, uint8_t *outCache, int32_t *cacheLen)
{
int32_t i;
int32_t ret = HC_ERR_IPC_BAD_MSG_TYPE;
errno_t eno;
LOGI("type %d", type);
for (i = 0; i < dataNum; i++) {
if (ipcData[i].type != type) {
continue;
}
ret = HC_SUCCESS;
switch (type) {
case PARAM_TYPE_REG_INFO:
case PARAM_TYPE_MGR_APPID:
case PARAM_TYPE_FRIEND_APPID:
case PARAM_TYPE_DEVICE_INFO:
case PARAM_TYPE_GROUP_INFO:
*(uint8_t **)outCache = ipcData[i].val;
if (cacheLen != NULL) {
*cacheLen = ipcData[i].valSz;
}
break;
case PARAM_TYPE_IPC_RESULT:
case PARAM_TYPE_IPC_RESULT_NUM:
case PARAM_TYPE_COMM_DATA:
case PARAM_TYPE_DATA_NUM:
eno = memcpy_s(outCache, *cacheLen, ipcData[i].val, ipcData[i].valSz);
if (eno != EOK) {
ret = HC_ERR_MEMORY_COPY;
break;
}
*cacheLen = ipcData[i].valSz;
break;
default:
ret = HC_ERR_IPC_BAD_MSG_TYPE;
LOGE("un-expectation type case");
break;
}
}
LOGI("process done, type %d, result %d", type, ret);
return;
}
static int32_t IpcGmRegCallback(const char *appId, const DeviceAuthCallback *callback)
{
uintptr_t callCtx = 0x0;
int32_t ret;
LOGI("starting ...");
if (!IS_STRING_VALID(appId)) {
LOGE("invalid params");
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEV_AUTH_CB, (const uint8_t *)callback, sizeof(*callback));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_DEV_AUTH_CB);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
SetCbCtxToDataCtx(callCtx, IPC_CALL_BACK_STUB_BIND_ID);
ret = DoBinderCall(callCtx, IPC_CALL_ID_REG_CB, true);
if (ret == HC_SUCCESS) {
AddIpcCliCallbackCtx(appId, 0, &g_ipcProxyCbList);
}
DestroyCallCtx(&callCtx, NULL);
LOGI("process done, ret %d", ret);
return (ret == HC_SUCCESS) ? HC_SUCCESS : HC_ERR_IPC_PROC_FAILED;
}
static int32_t IpcGmUnRegCallback(const char *appId)
{
uintptr_t callCtx = 0x0;
int32_t ret;
LOGI("starting ...");
if (!IS_STRING_VALID(appId)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d", ret);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_UNREG_CB, true);
if (ret == HC_SUCCESS) {
DelIpcCliCallbackCtx(appId, &g_ipcProxyCbList);
}
DestroyCallCtx(&callCtx, NULL);
LOGI("process done, ret %d", HC_SUCCESS);
return HC_SUCCESS;
}
static int32_t IpcGmRegDataChangeListener(const char *appId, const DataChangeListener *listener)
{
uintptr_t callCtx = 0x0;
int32_t ret;
LOGI("starting ...");
if (!IS_STRING_VALID(appId) || (listener == NULL)) {
LOGE("invalid params");
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_LISTERNER, (const uint8_t *)listener, sizeof(*listener));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_LISTERNER);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
SetCbCtxToDataCtx(callCtx, IPC_CALL_BACK_STUB_BIND_ID);
ret = DoBinderCall(callCtx, IPC_CALL_ID_REG_LISTENER, true);
if (ret == HC_SUCCESS) {
AddIpcCliCallbackCtx(appId, 0, &g_ipcListenerCbList);
}
DestroyCallCtx(&callCtx, NULL);
LOGI("process done, ret %d", ret);
return (ret == HC_SUCCESS) ? HC_SUCCESS : HC_ERR_IPC_PROC_FAILED;
}
static int32_t IpcGmUnRegDataChangeListener(const char *appId)
{
uintptr_t callCtx = 0x0;
int32_t ret;
LOGI("starting ...");
if (!IS_STRING_VALID(appId)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d", ret);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_UNREG_LISTENER, true);
if (ret == HC_SUCCESS) {
DelIpcCliCallbackCtx(appId, &g_ipcListenerCbList);
}
DestroyCallCtx(&callCtx, NULL);
LOGI("process done");
return HC_SUCCESS;
}
static int32_t IpcGmCreateGroup(int64_t requestId, const char *appid, const char *createParams)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache = {0};
LOGI("starting ...");
if (!IS_STRING_VALID(createParams) || !IS_STRING_VALID(appid)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appid, strlen(appid) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_CREATE_PARAMS,
(const uint8_t *)createParams, strlen(createParams) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_CREATE_PARAMS);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_CREATE_GROUP, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
DestroyCallCtx(&callCtx, NULL);
LOGI("process done, ret %d", ret);
return ret;
}
static int32_t IpcGmDelGroup(int64_t requestId, const char *appId, const char *delParams)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache = {0};
LOGI("starting ...");
if (!IS_STRING_VALID(delParams) || !IS_STRING_VALID(appId)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEL_PARAMS, (const uint8_t *)delParams, strlen(delParams) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_DEL_PARAMS);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_DEL_GROUP, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
DestroyCallCtx(&callCtx, NULL);
LOGI("process done, ret %d", ret);
return ret;
}
static int32_t IpcGmAddMemberToGroup(int64_t requestId, const char *appId, const char *addParams)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache = {0};
LOGI("starting ...");
if (!IS_STRING_VALID(appId) || !IS_STRING_VALID(addParams)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_ADD_PARAMS, (const uint8_t *)addParams, strlen(addParams) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_ADD_PARAMS);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_ADD_GROUP_MEMBER, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
DestroyCallCtx(&callCtx, NULL);
LOGI("process done, ret %d", ret);
return ret;
}
static int32_t IpcGmDelMemberFromGroup(int64_t requestId, const char *appId, const char *delParams)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache = {0};
LOGI("starting ...");
if (!IS_STRING_VALID(appId) || !IS_STRING_VALID(delParams)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEL_PARAMS, (const uint8_t *)delParams, strlen(delParams) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_DEL_PARAMS);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_DEL_GROUP_MEMBER, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
DestroyCallCtx(&callCtx, NULL);
LOGI("process done, ret %d", ret);
return ret;
}
static int32_t IpcGmProcessData(int64_t requestId, const uint8_t *data, uint32_t dataLen)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache = {0};
LOGI("starting ...");
if (!IS_COMM_DATA_VALID(data, dataLen)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_COMM_DATA, data, dataLen);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_COMM_DATA);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_GM_PROC_DATA, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
DestroyCallCtx(&callCtx, NULL);
LOGI("process done, ret %d", ret);
return ret;
}
static int32_t IpcGmConfirmRequest(int64_t requestId, const char *appId, const char *cfmParams)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache = {0};
LOGI("starting ...");
if (!IS_STRING_VALID(appId) || !IS_STRING_VALID(cfmParams)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQ_CFM, (const uint8_t *)cfmParams, strlen(cfmParams) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQ_CFM);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_CFM_REQUEST, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
DestroyCallCtx(&callCtx, NULL);
LOGI("process done, ret %d", ret);
return ret;
}
static int32_t IpcGmBindPeer(int64_t requestId, const char *appId, const char *bindParams)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache = {0};
LOGI("starting ...");
if (!IS_STRING_VALID(appId) || !IS_STRING_VALID(bindParams)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_BIND, (const uint8_t *)bindParams, strlen(bindParams) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_BIND);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_BIND_PEER, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
DestroyCallCtx(&callCtx, NULL);
LOGI("process done, ret %d", ret);
return ret;
}
static int32_t IpcGmUnBindPeer(int64_t requestId, const char *appId, const char *unBindParams)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache = {0};
LOGI("starting ...");
if (!IS_STRING_VALID(appId) || !IS_STRING_VALID(unBindParams)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_UNBIND, (const uint8_t *)unBindParams, strlen(unBindParams) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_UNBIND);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_UNBIND_PEER, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
DestroyCallCtx(&callCtx, NULL);
LOGI("process done, ret %d", ret);
return ret;
}
static int32_t IpcGmProcessLiteData(int64_t requestId, const char *appId, const uint8_t *data, uint32_t dataLen)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache = {0};
LOGI("starting ...");
if (!IS_COMM_DATA_VALID(data, dataLen) || !IS_STRING_VALID(appId)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&requestId), sizeof(requestId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_COMM_DATA, data, dataLen);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_COMM_DATA);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_PROC_LIGHT_DATA, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
DestroyCallCtx(&callCtx, NULL);
LOGI("process done, ret %d", ret);
return ret;
}
static int32_t IpcGmProcCredential(int32_t operationCode, const char *credential, char **returnJsonStr)
{
LOGI("starting ...");
(void)operationCode;
if (!IS_STRING_VALID(credential) || (returnJsonStr == NULL)) {
LOGE("The input groupType is invalid or credential is NULL!");
return HC_ERR_INVALID_PARAMS;
}
return HC_ERR_NOT_SUPPORT;
}
static int32_t IpcGmGetRegisterInfo(char **registerInfo)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache[IPC_DATA_CACHES_3] = {{0}};
char *outInfo = NULL;
LOGI("starting ...");
if (registerInfo == NULL) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_APPLY_REG_INFO, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
LOGI("process done, ret %d", ret);
if ((ret != HC_SUCCESS) || (inOutLen != sizeof(int32_t))) {
DestroyCallCtx(&callCtx, NULL);
return ret;
}
GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen);
if ((ret < IPC_RESULT_NUM_1) || (inOutLen != sizeof(int32_t))) {
LOGE("done, ret %d", HC_ERR_IPC_OUT_DATA_NUM);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_OUT_DATA_NUM;
}
GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_REG_INFO, (uint8_t *)&outInfo, NULL);
if ((outInfo == NULL) || (strlen(outInfo) == 0)) {
LOGE("done, ret %d", HC_ERR_IPC_OUT_DATA);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_OUT_DATA;
}
*registerInfo = strdup(outInfo);
DestroyCallCtx(&callCtx, NULL);
return (*registerInfo != NULL) ? HC_SUCCESS : HC_ERR_NULL_PTR;
}
static int32_t IpcGmGetLocalConnectInfo(char **outLocalConnInfo)
{
LOGI("starting ...");
if (outLocalConnInfo == NULL) {
return HC_ERR_INVALID_PARAMS;
}
return HC_ERR_NOT_SUPPORT;
}
static int32_t IpcGmAddGroupManager(const char *appId, const char *groupId, const char *managerAppId)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache = {0};
LOGI("starting ...");
if (!IS_STRING_VALID(appId) || !IS_STRING_VALID(groupId) || !IS_STRING_VALID(managerAppId)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, strlen(groupId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_MGR_APPID,
(const uint8_t *)managerAppId, strlen(managerAppId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_MGR_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_ADD_GROUP_MGR, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
DestroyCallCtx(&callCtx, NULL);
LOGI("process done, ret %d", ret);
return ret;
}
static int32_t IpcGmAddGroupFriend(const char *appId, const char *groupId, const char *friendAppId)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache = {0};
LOGI("starting ...");
if (!IS_STRING_VALID(groupId) || !IS_STRING_VALID(friendAppId) || !IS_STRING_VALID(appId)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, strlen(groupId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_FRIEND_APPID,
(const uint8_t *)friendAppId, strlen(friendAppId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_FRIEND_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_ADD_GROUP_FRIEND, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
DestroyCallCtx(&callCtx, NULL);
LOGI("process done, ret %d", ret);
return ret;
}
static int32_t IpcGmDelGroupManager(const char *appId, const char *groupId, const char *managerAppId)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache = {0};
LOGI("starting ...");
if (!IS_STRING_VALID(groupId) || !IS_STRING_VALID(managerAppId) || !IS_STRING_VALID(appId)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, strlen(groupId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_MGR_APPID,
(const uint8_t *)managerAppId, strlen(managerAppId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_MGR_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_DEL_GROUP_MGR, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
DestroyCallCtx(&callCtx, NULL);
LOGI("process done, ret %d", ret);
return ret;
}
static int32_t IpcGmDelGroupFriend(const char *appId, const char *groupId, const char *friendAppId)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache = {0};
LOGI("starting ...");
if (!IS_STRING_VALID(groupId) || !IS_STRING_VALID(friendAppId) || !IS_STRING_VALID(appId)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, strlen(groupId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_FRIEND_APPID,
(const uint8_t *)friendAppId, strlen(friendAppId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_FRIEND_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_DEL_GROUP_FRIEND, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
DestroyCallCtx(&callCtx, NULL);
LOGI("process done, ret %d", ret);
return ret;
}
static int32_t GetGroupManagersIpcResult(const IpcDataInfo *replies, int32_t cacheNum,
char **outManagers, uint32_t *outSize)
{
int32_t inOutLen;
int32_t ret;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen);
if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) {
return HC_ERR_IPC_OUT_DATA_NUM;
}
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_MGR_APPID, (uint8_t *)outManagers, NULL);
if ((*outManagers == NULL) || (strlen(*outManagers) == 0)) {
return HC_ERR_IPC_OUT_DATA;
}
*outManagers = strdup(*outManagers);
if (*outManagers == NULL) {
return HC_ERR_ALLOC_MEMORY;
}
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)outSize, &inOutLen);
return HC_SUCCESS;
}
static int32_t IpcGmGetGroupManagers(const char *appId, const char *groupId, char **outManagers, uint32_t *outSize)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache[IPC_DATA_CACHES_4] = {{0}};
LOGI("starting ...");
if (!IS_STRING_VALID(groupId) || !IS_STRING_VALID(appId) || (outManagers == NULL) || (outSize == NULL)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, strlen(groupId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_GROUP_MGR, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
LOGI("process done, ret %d", ret);
if (ret != HC_SUCCESS) {
DestroyCallCtx(&callCtx, NULL);
return ret;
}
ret = GetGroupManagersIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outManagers, outSize);
LOGI("proc result done, ret %d", ret);
DestroyCallCtx(&callCtx, NULL);
return ret;
}
static int32_t GetGroupFriendsIpcResult(const IpcDataInfo *replies,
int32_t cacheNum, char **outFriends, uint32_t *outSize)
{
int32_t inOutLen;
int32_t ret;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen);
if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) {
return HC_ERR_IPC_OUT_DATA_NUM;
}
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_FRIEND_APPID, (uint8_t *)outFriends, NULL);
if ((*outFriends == NULL) || (strlen(*outFriends) == 0)) {
return HC_ERR_IPC_OUT_DATA;
}
*outFriends = strdup(*outFriends);
if (*outFriends == NULL) {
return HC_ERR_ALLOC_MEMORY;
}
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)outSize, &inOutLen);
return HC_SUCCESS;
}
static int32_t IpcGmGetGroupFriends(const char *appId, const char *groupId, char **outFriends, uint32_t *outSize)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache[IPC_DATA_CACHES_4] = {{0}};
LOGI("starting ...");
if (!IS_STRING_VALID(groupId) || !IS_STRING_VALID(appId) || (outFriends == NULL) || (outSize == NULL)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, strlen(groupId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_GROUP_FRIEND, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
LOGI("process done, ret %d", ret);
if (ret != HC_SUCCESS) {
DestroyCallCtx(&callCtx, NULL);
return ret;
}
ret = GetGroupFriendsIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outFriends, outSize);
LOGI("proc result done, ret %d", ret);
DestroyCallCtx(&callCtx, NULL);
return ret;
}
static int32_t GroupInfoIpcResult(const IpcDataInfo *replies, int32_t cacheNum, char **outGroupInfo)
{
int32_t inOutLen;
int32_t ret;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen);
if ((ret < IPC_RESULT_NUM_1) || (inOutLen != sizeof(int32_t))) {
return HC_ERR_IPC_OUT_DATA_NUM;
}
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_GROUP_INFO, (uint8_t *)outGroupInfo, NULL);
if (*outGroupInfo == NULL) {
return HC_ERR_IPC_OUT_DATA;
}
*outGroupInfo = strdup(*outGroupInfo);
if (*outGroupInfo == NULL) {
return HC_ERR_ALLOC_MEMORY;
}
return HC_SUCCESS;
}
static int32_t IpcGmGetGroupInfoById(const char *appId, const char *groupId, char **outGroupInfo)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache[IPC_DATA_CACHES_3] = {{0}};
LOGI("starting ...");
if (!IS_STRING_VALID(groupId) || !IS_STRING_VALID(appId) || (outGroupInfo == NULL)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, strlen(groupId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_GROUP_INFO, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
LOGI("process done, ret %d", ret);
if (ret != HC_SUCCESS) {
DestroyCallCtx(&callCtx, NULL);
return ret;
}
ret = GroupInfoIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outGroupInfo);
DestroyCallCtx(&callCtx, NULL);
LOGI("proc result done, ret %d", ret);
return ret;
}
static int32_t SearchGroupsIpcResult(const IpcDataInfo *replies,
int32_t cacheNum, char **outGroupVec, uint32_t *groupNum)
{
int32_t ret;
int32_t inOutLen;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen);
if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) {
return HC_ERR_IPC_OUT_DATA_NUM;
}
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_GROUP_INFO, (uint8_t *)outGroupVec, NULL);
if (*outGroupVec == NULL) {
return HC_ERR_IPC_OUT_DATA;
}
*outGroupVec = strdup(*outGroupVec);
if (*outGroupVec == NULL) {
return HC_ERR_ALLOC_MEMORY;
}
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)groupNum, &inOutLen);
return HC_SUCCESS;
}
static int32_t IpcGmGetGroupInfo(const char *appId, const char *queryParams, char **outGroupVec, uint32_t *groupNum)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache[IPC_DATA_CACHES_4] = {{0}};
LOGI("starting ...");
if (!IS_STRING_VALID(queryParams) || !IS_STRING_VALID(appId) || (outGroupVec == NULL) || (groupNum == NULL)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_QUERY_PARAMS,
(const uint8_t *)queryParams, strlen(queryParams) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_QUERY_PARAMS);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_SEARCH_GROUPS, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
LOGI("process done, ret %d", ret);
if (ret != HC_SUCCESS) {
DestroyCallCtx(&callCtx, NULL);
return ret;
}
ret = SearchGroupsIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outGroupVec, groupNum);
LOGI("proc result done, ret %d", ret);
DestroyCallCtx(&callCtx, NULL);
return ret;
}
static int32_t JoinedGroupsIpcResult(const IpcDataInfo *replies,
int32_t cacheNum, char **outGroupVec, uint32_t *groupNum)
{
int32_t ret;
int32_t inOutLen;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen);
if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) {
return HC_ERR_IPC_OUT_DATA_NUM;
}
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_GROUP_INFO, (uint8_t *)outGroupVec, NULL);
if (*outGroupVec == NULL) {
return HC_ERR_IPC_OUT_DATA;
}
*outGroupVec = strdup(*outGroupVec);
if (*outGroupVec == NULL) {
return HC_ERR_ALLOC_MEMORY;
}
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)groupNum, &inOutLen);
return HC_SUCCESS;
}
static int32_t IpcGmGetJoinedGroups(const char *appId, int32_t groupType, char **outGroupVec, uint32_t *groupNum)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache[IPC_DATA_CACHES_4] = {{0}};
LOGI("starting ...");
if (!IS_STRING_VALID(appId) || (outGroupVec == NULL) ||
(groupNum == NULL) || (groupType != ACROSS_ACCOUNT_AUTHORIZE_GROUP)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUP_TYPE, (const uint8_t *)&groupType, sizeof(groupType));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUP_TYPE);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_JOINED_GROUPS, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
LOGI("process done, ret %d", ret);
if (ret != HC_SUCCESS) {
DestroyCallCtx(&callCtx, NULL);
return ret;
}
ret = JoinedGroupsIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outGroupVec, groupNum);
LOGI("proc result done, ret %d", ret);
DestroyCallCtx(&callCtx, NULL);
return ret;
}
static int32_t RelatedGroupsIpcResult(const IpcDataInfo *replies,
int32_t cacheNum, char **outGroupVec, uint32_t *groupNum)
{
int32_t ret;
int32_t inOutLen;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen);
if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) {
return HC_ERR_IPC_OUT_DATA_NUM;
}
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_GROUP_INFO, (uint8_t *)outGroupVec, NULL);
if (*outGroupVec == NULL) {
return HC_ERR_IPC_OUT_DATA;
}
*outGroupVec = strdup(*outGroupVec);
if (*outGroupVec == NULL) {
return HC_ERR_ALLOC_MEMORY;
}
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)groupNum, &inOutLen);
return HC_SUCCESS;
}
static int32_t IpcGmGetRelatedGroups(const char *appId, const char *peerUdid, char **outGroupVec, uint32_t *groupNum)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache[IPC_DATA_CACHES_4] = {{0}};
LOGI("starting ...");
if (!IS_STRING_VALID(appId) || !IS_STRING_VALID(peerUdid) || (outGroupVec == NULL) || (groupNum == NULL)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_UDID, (const uint8_t *)peerUdid, strlen(peerUdid) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_UDID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_RELATED_GROUPS, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
LOGI("process done, ret %d", ret);
if (ret != HC_SUCCESS) {
DestroyCallCtx(&callCtx, NULL);
return ret;
}
ret = RelatedGroupsIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outGroupVec, groupNum);
LOGI("proc result done, ret %d", ret);
DestroyCallCtx(&callCtx, NULL);
return ret;
}
static int32_t DevInfoByIdIpcResult(const IpcDataInfo *replies, int32_t cacheNum, char **outDevInfo)
{
int32_t ret;
int32_t inOutLen;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen);
if ((ret < IPC_RESULT_NUM_1) || (inOutLen != sizeof(int32_t))) {
return HC_ERR_IPC_OUT_DATA_NUM;
}
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DEVICE_INFO, (uint8_t *)outDevInfo, NULL);
if (*outDevInfo == NULL) {
return HC_ERR_IPC_OUT_DATA;
}
*outDevInfo = strdup(*outDevInfo);
if (*outDevInfo == NULL) {
return HC_ERR_ALLOC_MEMORY;
}
return HC_SUCCESS;
}
static int32_t FormParamsForGettingDeviceInfo(const char *appId,
const char *peerUdid, const char *groupId, uintptr_t callCtx)
{
int32_t ret;
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_UDID, (const uint8_t *)peerUdid, strlen(peerUdid) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_UDID);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, strlen(groupId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID);
return HC_ERR_IPC_BUILD_PARAM;
}
return HC_SUCCESS;
}
static int32_t IpcGmGetDeviceInfoById(const char *appId, const char *peerUdid, const char *groupId, char **outDevInfo)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache[IPC_DATA_CACHES_3] = {{0}};
LOGI("starting ...");
if (!IS_STRING_VALID(appId) || !IS_STRING_VALID(peerUdid) || !IS_STRING_VALID(groupId) || (outDevInfo == NULL)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = FormParamsForGettingDeviceInfo(appId, peerUdid, groupId, callCtx);
if (ret != HC_SUCCESS) {
DestroyCallCtx(&callCtx, NULL);
return ret;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_DEV_INFO_BY_ID, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
LOGI("process done, ret %d", ret);
if (ret != HC_SUCCESS) {
DestroyCallCtx(&callCtx, NULL);
return ret;
}
ret = DevInfoByIdIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outDevInfo);
LOGI("proc result done, ret %d", ret);
DestroyCallCtx(&callCtx, NULL);
return ret;
}
static int32_t TrustedDevIpcResult(const IpcDataInfo *replies, int32_t cacheNum, char **outDevInfoVec, uint32_t *devNum)
{
int32_t ret;
int32_t inOutLen;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen);
if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) {
return HC_ERR_IPC_OUT_DATA_NUM;
}
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DEVICE_INFO, (uint8_t *)outDevInfoVec, NULL);
if (*outDevInfoVec == NULL) {
return HC_ERR_IPC_OUT_DATA;
}
*outDevInfoVec = strdup(*outDevInfoVec);
if (*outDevInfoVec == NULL) {
return HC_ERR_ALLOC_MEMORY;
}
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)devNum, &inOutLen);
return HC_SUCCESS;
}
static int32_t IpcGmGetTrustedDevices(const char *appId,
const char *groupId, char **outDevInfoVec, uint32_t *deviceNum)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache[IPC_DATA_CACHES_4] = {{0}};
LOGI("starting ...");
if (!IS_STRING_VALID(appId) || !IS_STRING_VALID(groupId) ||
(outDevInfoVec == NULL) || (deviceNum == NULL)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, strlen(groupId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_TRUST_DEVICES, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
LOGI("process done, ret %d", ret);
if (ret != HC_SUCCESS) {
DestroyCallCtx(&callCtx, NULL);
return ret;
}
ret = TrustedDevIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outDevInfoVec, deviceNum);
LOGI("proc result done, ret %d", ret);
DestroyCallCtx(&callCtx, NULL);
return ret;
}
static bool IpcGmIsDeviceInGroup(const char *appId, const char *groupId, const char *udid)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache = {0};
LOGI("starting ...");
if (!IS_STRING_VALID(appId) || !IS_STRING_VALID(groupId) || !IS_STRING_VALID(udid)) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, strlen(groupId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_UDID, (const uint8_t *)udid, strlen(udid) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_UDID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_IS_DEV_IN_GROUP, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
LOGI("process done, ret %d", ret);
DestroyCallCtx(&callCtx, NULL);
return (ret == HC_SUCCESS) ? true : false;
}
static void IpcGmDestroyInfo(char **returnInfo)
{
if ((returnInfo == NULL) || (*returnInfo == NULL)) {
return;
}
FreeJsonString(*returnInfo);
*returnInfo = NULL;
}
static int32_t IpcGmAuthKeyAgree(int64_t requestId, const char *appId, const char *buildParams)
{
LOGI("starting ...");
if (!IS_STRING_VALID(appId) || !IS_STRING_VALID(buildParams)) {
return HC_ERR_INVALID_PARAMS;
}
(void)requestId;
return HC_ERR_NOT_SUPPORT;
}
static int32_t IpcGmProcessKeyAgreeData(int64_t requestId, const char *appId, const uint8_t *data, uint32_t dataLen)
{
LOGI("starting ...");
if (!IS_STRING_VALID(appId) || !IS_COMM_DATA_VALID(data, dataLen)) {
return HC_ERR_INVALID_PARAMS;
}
(void)requestId;
return HC_ERR_NOT_SUPPORT;
}
static void InitIpcGmMethods(DeviceGroupManager *gmMethodObj)
{
LOGI("starting ...");
gmMethodObj->regCallback = IpcGmRegCallback;
gmMethodObj->unRegCallback = IpcGmUnRegCallback;
gmMethodObj->regDataChangeListener = IpcGmRegDataChangeListener;
gmMethodObj->unRegDataChangeListener = IpcGmUnRegDataChangeListener;
gmMethodObj->createGroup = IpcGmCreateGroup;
gmMethodObj->deleteGroup = IpcGmDelGroup;
gmMethodObj->addMemberToGroup = IpcGmAddMemberToGroup;
gmMethodObj->deleteMemberFromGroup = IpcGmDelMemberFromGroup;
gmMethodObj->processData = IpcGmProcessData;
gmMethodObj->confirmRequest = IpcGmConfirmRequest;
gmMethodObj->bindPeer = IpcGmBindPeer;
gmMethodObj->unbindPeer = IpcGmUnBindPeer;
gmMethodObj->processLiteData = IpcGmProcessLiteData;
gmMethodObj->processCredential = IpcGmProcCredential;
gmMethodObj->getRegisterInfo = IpcGmGetRegisterInfo;
gmMethodObj->getLocalConnectInfo = IpcGmGetLocalConnectInfo;
gmMethodObj->addGroupManager = IpcGmAddGroupManager;
gmMethodObj->addGroupFriend = IpcGmAddGroupFriend;
gmMethodObj->deleteGroupManager = IpcGmDelGroupManager;
gmMethodObj->deleteGroupFriend = IpcGmDelGroupFriend;
gmMethodObj->getGroupManagers = IpcGmGetGroupManagers;
gmMethodObj->getGroupFriends = IpcGmGetGroupFriends;
gmMethodObj->getGroupInfoById = IpcGmGetGroupInfoById;
gmMethodObj->getGroupInfo = IpcGmGetGroupInfo;
gmMethodObj->getJoinedGroups = IpcGmGetJoinedGroups;
gmMethodObj->getRelatedGroups = IpcGmGetRelatedGroups;
gmMethodObj->getDeviceInfoById = IpcGmGetDeviceInfoById;
gmMethodObj->getTrustedDevices = IpcGmGetTrustedDevices;
gmMethodObj->isDeviceInGroup = IpcGmIsDeviceInGroup;
gmMethodObj->destroyInfo = IpcGmDestroyInfo;
gmMethodObj->authKeyAgree = IpcGmAuthKeyAgree;
gmMethodObj->processKeyAgreeData = IpcGmProcessKeyAgreeData;
LOGI("process done");
return;
}
static int32_t IpcGaProcessData(int64_t authReqId,
const uint8_t *data, uint32_t dataLen, const DeviceAuthCallback *callback)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache = {0};
LOGI("starting ...");
if (!IS_COMM_DATA_VALID(data, dataLen) || (callback == NULL)) {
LOGE("invalid params");
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&authReqId), sizeof(authReqId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_REQID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_COMM_DATA, (const uint8_t *)data, dataLen);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_COMM_DATA);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEV_AUTH_CB, (const uint8_t *)callback, sizeof(*callback));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_DEV_AUTH_CB);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
SetCbCtxToDataCtx(callCtx, 0x0);
ret = DoBinderCall(callCtx, IPC_CALL_ID_GA_PROC_DATA, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
LOGI("process done, ret %d", ret);
DestroyCallCtx(&callCtx, NULL);
return ret;
}
static int32_t IpcGaQueryTrustedDeviceNum(void)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache = {0};
LOGI("starting ...");
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_QUERY_TRUST_DEV_NUM, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
LOGI("process done, device num %d", ret);
DestroyCallCtx(&callCtx, NULL);
return ret;
}
static bool IpcGaIsTrustedDevice(const char *udid)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache = {0};
LOGI("starting ...");
if (udid == NULL) {
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
uint32_t udidLen = strlen(udid) + 1;
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_COMM_DATA, (const uint8_t *)udid, udidLen);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_COMM_DATA);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_IS_TRUST_DEVICE, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
LOGI("process done, ret %d", ret);
DestroyCallCtx(&callCtx, NULL);
return (ret == HC_SUCCESS) ? true : false;
}
static int32_t FormParamsForGettingAuthState(int64_t authReqId, const char *groupId,
const char *peerUdid, uintptr_t callCtx)
{
int32_t ret;
int32_t inOutLen;
inOutLen = sizeof(authReqId);
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&authReqId, inOutLen);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, strlen(groupId) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_UDID, (const uint8_t *)peerUdid, strlen(peerUdid) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_UDID);
return HC_ERR_IPC_BUILD_PARAM;
}
return HC_SUCCESS;
}
static int32_t IpcGaGetAuthState(int64_t authReqId, const char *groupId,
const char *peerUdid, uint8_t *out, uint32_t *outLen)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache[IPC_DATA_CACHES_3] = {{0}};
LOGI("starting ...");
if (!IS_STRING_VALID(peerUdid) || !IS_STRING_VALID(groupId) || (out == NULL) || (outLen == NULL)) {
LOGE("invalid params");
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = FormParamsForGettingAuthState(authReqId, groupId, peerUdid, callCtx);
if (ret != HC_SUCCESS) {
DestroyCallCtx(&callCtx, NULL);
return ret;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_AUTH_STATE, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
LOGI("process done, ret %d", ret);
if (ret != HC_SUCCESS) {
DestroyCallCtx(&callCtx, NULL);
return ret;
}
GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_COMM_DATA, out, (int32_t *)outLen);
DestroyCallCtx(&callCtx, NULL);
return ret;
}
static int32_t IpcGaAuthDevice(int64_t authReqId, const char *authParams, const DeviceAuthCallback *callback)
{
uintptr_t callCtx = 0x0;
int32_t ret;
int32_t inOutLen;
IpcDataInfo replyCache = {0};
LOGI("starting ...");
if (!IS_STRING_VALID(authParams) || (callback == NULL)) {
LOGE("invalid params");
return HC_ERR_INVALID_PARAMS;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return HC_ERROR;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return HC_ERR_IPC_INIT;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&authReqId), sizeof(authReqId));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_REQID);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_AUTH_PARAMS, (const uint8_t *)authParams, strlen(authParams) + 1);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_AUTH_PARAMS);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEV_AUTH_CB, (const uint8_t *)callback, sizeof(*callback));
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_DEV_AUTH_CB);
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_BUILD_PARAM;
}
SetCbCtxToDataCtx(callCtx, IPC_CALL_BACK_STUB_AUTH_ID);
ret = DoBinderCall(callCtx, IPC_CALL_ID_AUTH_DEVICE, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call failed");
DestroyCallCtx(&callCtx, NULL);
return HC_ERR_IPC_PROC_FAILED;
}
DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
ret = HC_ERR_IPC_UNKNOW_REPLAY;
inOutLen = sizeof(int32_t);
GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
LOGI("process done, ret %d", ret);
DestroyCallCtx(&callCtx, NULL);
return ret;
}
static void IpcGaInformDeviceDisconn(const char *udid)
{
uintptr_t callCtx = 0x0;
int32_t ret;
LOGI("entering ...");
if (udid == NULL) {
LOGE("invalid params");
return;
}
if (!IsServiceRunning()) {
LOGE("service is not activity");
return;
}
ret = CreateCallCtx(&callCtx, NULL);
if (ret != HC_SUCCESS) {
LOGE("CreateCallCtx failed, ret %d", ret);
return;
}
uint32_t udidLen = strlen(udid) + 1;
ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_COMM_DATA, (const uint8_t *)udid, udidLen);
if (ret != HC_SUCCESS) {
LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_COMM_DATA);
DestroyCallCtx(&callCtx, NULL);
return;
}
ret = DoBinderCall(callCtx, IPC_CALL_ID_INFORM_DEV_DISCONN, true);
if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
LOGE("ipc call error");
DestroyCallCtx(&callCtx, NULL);
return;
}
LOGI("process done");
DestroyCallCtx(&callCtx, NULL);
return;
}
static void InitIpcGaMethods(GroupAuthManager *gaMethodObj)
{
LOGI("entering...");
gaMethodObj->processData = IpcGaProcessData;
gaMethodObj->queryTrustedDeviceNum = IpcGaQueryTrustedDeviceNum;
gaMethodObj->isTrustedDevice = IpcGaIsTrustedDevice;
gaMethodObj->getAuthState = IpcGaGetAuthState;
gaMethodObj->authDevice = IpcGaAuthDevice;
gaMethodObj->informDeviceDisconnection = IpcGaInformDeviceDisconn;
LOGI("process done");
return;
}
DEVICE_AUTH_API_PUBLIC int InitDeviceAuthService(void)
{
InitHcMutex(&g_ipcMutex);
return HC_SUCCESS;
}
DEVICE_AUTH_API_PUBLIC void DestroyDeviceAuthService(void)
{
DestroyHcMutex(&g_ipcMutex);
}
DEVICE_AUTH_API_PUBLIC const GroupAuthManager *GetGaInstance(void)
{
static GroupAuthManager gaInstCtx = {NULL};
static GroupAuthManager *gaInstPtr = NULL;
LOGI("Enter InitIpcMethods...");
if (gaInstPtr == NULL) {
InitIpcGaMethods(&gaInstCtx);
gaInstPtr = &gaInstCtx;
}
LOGI("InitIpcMethods done");
return (const GroupAuthManager *)(gaInstPtr);
}
DEVICE_AUTH_API_PUBLIC const DeviceGroupManager *GetGmInstance(void)
{
static DeviceGroupManager gmInstCtx = {NULL};
static DeviceGroupManager *gmInstPtr = NULL;
LOGI("Enter InitIpcMethods...");
if (gmInstPtr == NULL) {
InitIpcGmMethods(&gmInstCtx);
gmInstPtr = &gmInstCtx;
}
LOGI("InitIpcMethods done");
return (const DeviceGroupManager *)(gmInstPtr);
}
#ifdef __cplusplus
}
#endif
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef IPC_SDK_H
#define IPC_SDK_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define IPC_RESULT_NUM_1 1
#define IPC_RESULT_NUM_2 2
#define IPC_CALL_BACK_STUB_AUTH_ID 0
#define IPC_CALL_BACK_STUB_BIND_ID 1
/* params type for ipc call */
#define PARAM_TYPE_APPID 1
#define PARAM_TYPE_DEV_AUTH_CB 2
#define PARAM_TYPE_LISTERNER 3
#define PARAM_TYPE_REQID 4
#define PARAM_TYPE_CREATE_PARAMS 5
#define PARAM_TYPE_GROUPID 6
#define PARAM_TYPE_UDID 7
#define PARAM_TYPE_ADD_PARAMS 8
#define PARAM_TYPE_DEL_PARAMS 9
#define PARAM_TYPE_COMM_DATA 10
#define PARAM_TYPE_REQ_CFM 11
#define PARAM_TYPE_BIND 12
#define PARAM_TYPE_UNBIND 13
#define PARAM_TYPE_GROUP_TYPE 14
#define PARAM_TYPE_CREDENTIAL 15
#define PARAM_TYPE_MGR_APPID 16
#define PARAM_TYPE_FRIEND_APPID 17
#define PARAM_TYPE_QUERY_PARAMS 18
#define PARAM_TYPE_REG_INFO 19
#define PARAM_TYPE_DATA_NUM 20
#define PARAM_TYPE_SESS_KEY 21
#define PARAM_TYPE_OPCODE 22
#define PARAM_TYPE_IPC_RESULT 23
#define PARAM_TYPE_IPC_RESULT_NUM 24
#define PARAM_TYPE_ERRCODE 25
#define PARAM_TYPE_ERR_INFO 26
#define PARAM_TYPE_REQ_INFO 27
#define PARAM_TYPE_GROUP_INFO 28
#define PARAM_TYPE_DEVICE_INFO 29
#define PARAM_TYPE_AUTH_PARAMS 30
#define PARAM_TYPE_CB_OBJECT 31
enum {
IPC_CALL_ID_REG_CB = 1,
IPC_CALL_ID_UNREG_CB,
IPC_CALL_ID_REG_LISTENER,
IPC_CALL_ID_UNREG_LISTENER,
IPC_CALL_ID_CREATE_GROUP,
IPC_CALL_ID_DEL_GROUP,
IPC_CALL_ID_ADD_GROUP_MEMBER,
IPC_CALL_ID_DEL_GROUP_MEMBER,
IPC_CALL_ID_GM_PROC_DATA,
IPC_CALL_ID_CFM_REQUEST,
IPC_CALL_ID_BIND_PEER,
IPC_CALL_ID_UNBIND_PEER,
IPC_CALL_ID_PROC_LIGHT_DATA,
IPC_CALL_ID_SAVE_CREDENTIAL,
IPC_CALL_ID_APPLY_REG_INFO,
IPC_CALL_ID_ADD_GROUP_MGR,
IPC_CALL_ID_ADD_GROUP_FRIEND,
IPC_CALL_ID_DEL_GROUP_MGR,
IPC_CALL_ID_DEL_GROUP_FRIEND,
IPC_CALL_ID_GET_GROUP_MGR,
IPC_CALL_ID_GET_GROUP_FRIEND,
IPC_CALL_ID_GET_GROUP_INFO,
IPC_CALL_ID_SEARCH_GROUPS,
IPC_CALL_ID_GET_JOINED_GROUPS,
IPC_CALL_ID_GET_RELATED_GROUPS,
IPC_CALL_ID_GET_DEV_INFO_BY_ID,
IPC_CALL_ID_GET_TRUST_DEVICES,
IPC_CALL_ID_IS_DEV_IN_GROUP,
IPC_CALL_ID_DESTROY_INFO,
IPC_CALL_ID_GA_PROC_DATA,
IPC_CALL_ID_QUERY_TRUST_DEV_NUM,
IPC_CALL_ID_IS_TRUST_DEVICE,
IPC_CALL_ID_GET_AUTH_STATE,
IPC_CALL_ID_AUTH_DEVICE,
IPC_CALL_ID_INFORM_DEV_DISCONN
};
#ifdef __cplusplus
}
#endif
#endif
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ipc_service.h"
#include "common_defs.h"
#include "device_auth_defines.h"
#include "device_auth.h"
#include "hc_condition.h"
#include "hc_log.h"
#include "hc_thread.h"
#include "ipc_adapt.h"
#include "ipc_sdk.h"
#include "securec.h"
#ifdef __cplusplus
extern "C" {
#endif
static const int32_t g_ipcResultNum1 = IPC_RESULT_NUM_1;
static const int32_t g_ipcResultNum2 = IPC_RESULT_NUM_2;
static const char *g_serviceAppId = "deviceauth_service";
static DeviceGroupManager g_devGroupMgrMethod = {NULL};
static GroupAuthManager g_groupAuthMgrMethod = {NULL};
static DeviceAuthCallback g_bindCbAdt = {NULL};
static DeviceAuthCallback g_authCbAdt = {NULL};
static DataChangeListener g_listenCbAdt = {NULL};
static int32_t BindRequestIdWithAppId(const char *data)
{
const char *appId = NULL;
int32_t ret;
int64_t requestId = -1;
CJson *dataJson = CreateJsonFromString(data);
if (dataJson == NULL) {
LOGE("failed to create json from string!");
return HC_ERROR;
}
appId = GetStringFromJson(dataJson, FIELD_APP_ID);
if (appId == NULL) {
LOGE("failed to get appId from json object!");
FreeJson(dataJson);
return HC_ERROR;
}
(void)GetInt64FromJson(dataJson, FIELD_REQUEST_ID, &requestId);
ret = AddReqIdByAppId(appId, requestId);
FreeJson(dataJson);
return ret;
}
static int32_t IpcServiceGmRegCallback(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
const char *appId = NULL;
const DeviceAuthCallback *callback = NULL;
int32_t cbObjIdx = -1;
int32_t idxLen;
LOGI("starting ...");
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&callback, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_DEV_AUTH_CB);
return ret;
}
ret = AddIpcCallBackByAppId(appId, (const uint8_t *)callback, sizeof(DeviceAuthCallback), CB_TYPE_DEV_AUTH);
if (ret != HC_SUCCESS) {
LOGE("add ipc callback failed");
return HC_ERROR;
}
idxLen = sizeof(cbObjIdx);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &idxLen);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_CB_OBJECT);
DelIpcCallBackByAppId(appId, CB_TYPE_DEV_AUTH);
return ret;
}
AddIpcCbObjByAppId(appId, cbObjIdx, CB_TYPE_DEV_AUTH);
InitDeviceAuthCbCtx(&g_bindCbAdt, CB_TYPE_DEV_AUTH);
callRet = g_devGroupMgrMethod.regCallback(appId, &g_bindCbAdt);
if (callRet != HC_SUCCESS) {
DelIpcCallBackByAppId(appId, CB_TYPE_DEV_AUTH);
}
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGmUnRegCallback(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet = HC_SUCCESS;
int32_t ret;
const char *appId = NULL;
LOGI("starting ...");
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
DelIpcCallBackByAppId(appId, CB_TYPE_DEV_AUTH);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGmRegDataChangeListener(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
const char *appId = NULL;
const DataChangeListener *callback = NULL;
static int32_t registered = 0;
int32_t cbObjIdx = -1;
int32_t idxLen;
LOGI("starting ...");
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_LISTERNER, (uint8_t *)&callback, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_LISTERNER);
return ret;
}
ret = AddIpcCallBackByAppId(appId, (const uint8_t *)callback, sizeof(DataChangeListener), CB_TYPE_LISTENER);
if (ret != HC_SUCCESS) {
LOGE("add ipc callback failed");
return HC_ERROR;
}
idxLen = sizeof(cbObjIdx);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &idxLen);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_CB_OBJECT);
DelIpcCallBackByAppId(appId, CB_TYPE_DEV_AUTH);
return ret;
}
AddIpcCbObjByAppId(appId, cbObjIdx, CB_TYPE_LISTENER);
callRet = HC_SUCCESS;
if (registered == 0) {
InitDevAuthListenerCbCtx(&g_listenCbAdt);
callRet = g_devGroupMgrMethod.regDataChangeListener(g_serviceAppId, &g_listenCbAdt);
if (callRet == HC_SUCCESS) {
registered = 1;
} else {
DelIpcCallBackByAppId(appId, CB_TYPE_LISTENER);
}
}
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGmUnRegDataChangeListener(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet = HC_SUCCESS;
int32_t ret;
const char *appId = NULL;
LOGI("starting ...");
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
DelIpcCallBackByAppId(appId, CB_TYPE_LISTENER);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGmCreateGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
int64_t requestId = 0;
int32_t inOutLen;
const char *createParams = NULL;
const char *appId = NULL;
LOGI("starting ...");
inOutLen = sizeof(int64_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
if ((ret != HC_SUCCESS) || (inOutLen != sizeof(int64_t))) {
LOGE("get param error, type %d", PARAM_TYPE_REQID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CREATE_PARAMS, (uint8_t *)&createParams, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_CREATE_PARAMS);
return ret;
}
callRet = g_devGroupMgrMethod.createGroup(requestId, appId, createParams);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGmDelGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
int64_t requestId = 0;
int32_t inOutLen;
const char *appId = NULL;
const char *delParams = NULL;
LOGI("starting ...");
inOutLen = sizeof(int64_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
if ((ret != HC_SUCCESS) || (inOutLen != sizeof(int64_t))) {
LOGE("get param error, type %d", PARAM_TYPE_REQID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEL_PARAMS, (uint8_t *)&delParams, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_DEL_PARAMS);
return ret;
}
callRet = g_devGroupMgrMethod.deleteGroup(requestId, appId, delParams);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGmAddMemberToGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
int32_t inOutLen;
int64_t requestId = 0;
const char *addParams = NULL;
const char *appId = NULL;
LOGI("starting ...");
inOutLen = sizeof(int64_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
if ((ret != HC_SUCCESS) || (inOutLen != sizeof(int64_t))) {
LOGE("get param error, type %d", PARAM_TYPE_REQID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_ADD_PARAMS, (uint8_t *)&addParams, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_ADD_PARAMS);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
ret = AddReqIdByAppId(appId, requestId);
if (ret != HC_SUCCESS) {
return ret;
}
callRet = g_devGroupMgrMethod.addMemberToGroup(requestId, appId, addParams);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGmDelMemberFromGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
int32_t inOutLen;
int64_t requestId = 0;
const char *delParams = NULL;
const char *appId = NULL;
LOGI("starting ...");
inOutLen = sizeof(int64_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
if ((ret != HC_SUCCESS) || (inOutLen != sizeof(int64_t))) {
LOGE("get param error, type %d", PARAM_TYPE_REQID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEL_PARAMS, (uint8_t *)&delParams, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_DEL_PARAMS);
return ret;
}
callRet = g_devGroupMgrMethod.deleteMemberFromGroup(requestId, appId, delParams);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGmProcessData(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
int32_t dataLen;
int32_t inOutLen;
int64_t requestId = 0;
const uint8_t *data = NULL;
LOGI("starting ...");
inOutLen = sizeof(int64_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
if ((ret != HC_SUCCESS) || (inOutLen != sizeof(int64_t))) {
LOGE("get param error, type %d", PARAM_TYPE_REQID);
return ret;
}
dataLen = 0;
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_COMM_DATA, (uint8_t *)&data, &dataLen);
if ((ret != HC_SUCCESS) || (dataLen <= 0)) {
LOGE("get param error, type %d, data length %d", PARAM_TYPE_COMM_DATA, dataLen);
return ret;
}
ret = BindRequestIdWithAppId((const char *)data);
if (ret != HC_SUCCESS) {
return ret;
}
callRet = g_devGroupMgrMethod.processData(requestId, data, dataLen);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGmConfirmRequest(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
int32_t inOutLen;
int64_t requestId = 0;
const char *cfmParams = NULL;
const char *appId = NULL;
LOGI("starting ...");
inOutLen = sizeof(int64_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
if ((ret != HC_SUCCESS) || (inOutLen != sizeof(int64_t))) {
LOGE("get param error, type %d", PARAM_TYPE_REQID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&cfmParams, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQ_CFM, (uint8_t *)&cfmParams, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_REQ_CFM);
return ret;
}
callRet = g_devGroupMgrMethod.confirmRequest(requestId, appId, cfmParams);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGmBindPeer(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
int32_t inOutLen;
int64_t requestId = 0;
const char *bindParams = NULL;
const char *appId = NULL;
LOGI("starting ...");
inOutLen = sizeof(int64_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
if ((ret != HC_SUCCESS) || (inOutLen != sizeof(int64_t))) {
LOGE("get param error, type %d", PARAM_TYPE_REQID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_BIND, (uint8_t *)&bindParams, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_BIND);
return ret;
}
callRet = g_devGroupMgrMethod.bindPeer(requestId, appId, bindParams);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGmUnBindPeer(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
int32_t inOutLen;
int64_t requestId = 0;
const char *unBindParams = NULL;
const char *appId = NULL;
LOGI("starting ...");
inOutLen = sizeof(int64_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
if ((ret != HC_SUCCESS) || (inOutLen != sizeof(int64_t))) {
LOGE("get param error, type %d", PARAM_TYPE_REQID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_UNBIND);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_UNBIND, (uint8_t *)&unBindParams, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_UNBIND);
return ret;
}
callRet = g_devGroupMgrMethod.unbindPeer(requestId, appId, unBindParams);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGmProcessLiteData(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
int32_t dataLen;
int32_t inOutLen;
int64_t requestId;
const uint8_t *data = NULL;
const char *appId = NULL;
LOGI("starting ...");
inOutLen = sizeof(int64_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
if ((ret != HC_SUCCESS) || (inOutLen != sizeof(int64_t))) {
LOGE("get param error, type %d", PARAM_TYPE_REQID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if ((ret != HC_SUCCESS) || (appId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
dataLen = 0;
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_COMM_DATA, (uint8_t *)&data, &dataLen);
if ((ret != HC_SUCCESS) || (dataLen <= 0)) {
LOGE("get param error, type %d", PARAM_TYPE_COMM_DATA);
return ret;
}
AddReqIdByAppId(appId, requestId);
callRet = g_devGroupMgrMethod.processLiteData(requestId, appId, data, dataLen);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGmSaveCredential(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
int32_t opCode = 0;
int32_t inOutLen;
const char *credential = NULL;
char *returnJsonStr = NULL;
LOGI("starting ...");
inOutLen = sizeof(int32_t);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OPCODE, (uint8_t *)&opCode, &inOutLen);
if ((ret != HC_SUCCESS) || (inOutLen != sizeof(int32_t))) {
LOGE("get param error, type %d", PARAM_TYPE_OPCODE);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CREDENTIAL, (uint8_t *)&credential, NULL);
if ((ret != HC_SUCCESS) || (credential == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_CREDENTIAL);
return ret;
}
callRet = g_devGroupMgrMethod.processCredential(opCode, credential, &returnJsonStr);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
if ((ret == HC_SUCCESS) && (returnJsonStr != NULL)) {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_REQ_INFO,
(const uint8_t *)returnJsonStr, strlen(returnJsonStr) + 1);
g_devGroupMgrMethod.destroyInfo(&returnJsonStr);
} else {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_REG_INFO, NULL, 0);
}
return (ret == HC_SUCCESS) ? ret : HC_ERROR;
}
static int32_t IpcServiceGmApplyRegisterInfo(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
char *registerInfo = NULL;
(void)ipcParams;
(void)paramNum;
LOGI("starting ...");
callRet = g_devGroupMgrMethod.getRegisterInfo(&registerInfo);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT_NUM,
(const uint8_t *)&g_ipcResultNum1, sizeof(int32_t));
if (registerInfo != NULL) {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_REG_INFO,
(const uint8_t *)registerInfo, strlen(registerInfo) + 1);
g_devGroupMgrMethod.destroyInfo(&registerInfo);
} else {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_REG_INFO, NULL, 0);
}
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return (ret == HC_SUCCESS) ? ret : HC_ERROR;
}
static int32_t IpcServiceGmAddGroupManager(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
const char *appId = NULL;
const char *groupId = NULL;
const char *managerAppId = NULL;
LOGI("starting ...");
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if ((ret != HC_SUCCESS) || (appId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
if ((ret != HC_SUCCESS) || (groupId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_MGR_APPID, (uint8_t *)&managerAppId, NULL);
if ((ret != HC_SUCCESS) || (managerAppId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_MGR_APPID);
return ret;
}
callRet = g_devGroupMgrMethod.addGroupManager(appId, groupId, managerAppId);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGmAddGroupFriend(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
const char *appId = NULL;
const char *groupId = NULL;
const char *friendAppId = NULL;
LOGI("starting ...");
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if ((ret != HC_SUCCESS) || (appId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
if ((ret != HC_SUCCESS) || (groupId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_FRIEND_APPID, (uint8_t *)&friendAppId, NULL);
if ((ret != HC_SUCCESS) || (friendAppId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_FRIEND_APPID);
return ret;
}
callRet = g_devGroupMgrMethod.addGroupFriend(appId, groupId, friendAppId);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGmDelGroupManager(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
const char *appId = NULL;
const char *groupId = NULL;
const char *managerAppId = NULL;
LOGI("starting ...");
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if ((ret != HC_SUCCESS) || (appId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
if ((ret != HC_SUCCESS) || (groupId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_MGR_APPID, (uint8_t *)&managerAppId, NULL);
if ((ret != HC_SUCCESS) || (managerAppId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_MGR_APPID);
return ret;
}
callRet = g_devGroupMgrMethod.deleteGroupManager(appId, groupId, managerAppId);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGmDelGroupFriend(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
const char *appId = NULL;
const char *groupId = NULL;
const char *friendAppId = NULL;
LOGI("starting ...");
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if ((ret != HC_SUCCESS) || (appId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
if ((ret != HC_SUCCESS) || (groupId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_FRIEND_APPID, (uint8_t *)&friendAppId, NULL);
if ((ret != HC_SUCCESS) || (friendAppId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_FRIEND_APPID);
return ret;
}
callRet = g_devGroupMgrMethod.deleteGroupFriend(appId, groupId, friendAppId);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGmGetGroupManagers(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
const char *appId = NULL;
const char *groupId = NULL;
char *managers = NULL;
uint32_t managersNum = 0;
LOGI("starting ...");
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if ((ret != HC_SUCCESS) || (appId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
if ((ret != HC_SUCCESS) || (groupId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
return ret;
}
callRet = g_devGroupMgrMethod.getGroupManagers(appId, groupId, &managers, &managersNum);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT_NUM,
(const uint8_t *)&g_ipcResultNum2, sizeof(int32_t));
if (managers != NULL) {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_MGR_APPID, (const uint8_t *)managers, strlen(managers) + 1);
g_devGroupMgrMethod.destroyInfo(&managers);
} else {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_MGR_APPID, NULL, 0);
}
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&managersNum, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return (ret == HC_SUCCESS) ? ret : HC_ERROR;
}
static int32_t IpcServiceGmGetGroupFriends(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
const char *appId = NULL;
const char *groupId = NULL;
char *friends = NULL;
uint32_t friendsNum = 0;
LOGI("starting ...");
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if ((ret != HC_SUCCESS) || (appId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
if ((ret != HC_SUCCESS) || (groupId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
return ret;
}
callRet = g_devGroupMgrMethod.getGroupFriends(appId, groupId, &friends, &friendsNum);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT_NUM,
(const uint8_t *)&g_ipcResultNum2, sizeof(int32_t));
if (friends != NULL) {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_FRIEND_APPID, (const uint8_t *)friends, strlen(friends) + 1);
g_devGroupMgrMethod.destroyInfo(&friends);
} else {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_FRIEND_APPID, NULL, 0);
}
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&friendsNum, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return (ret == HC_SUCCESS) ? ret : HC_ERROR;
}
static int32_t IpcServiceGmGetGroupInfoById(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
const char *appId = NULL;
const char *groupId = NULL;
char *groupInfo = NULL;
LOGI("starting ...");
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if ((ret != HC_SUCCESS) || (appId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
if ((ret != HC_SUCCESS) || (groupId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
return ret;
}
callRet = g_devGroupMgrMethod.getGroupInfoById(appId, groupId, &groupInfo);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT_NUM,
(const uint8_t *)&g_ipcResultNum1, sizeof(int32_t));
if (groupInfo != NULL) {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)groupInfo, strlen(groupInfo) + 1);
g_devGroupMgrMethod.destroyInfo(&groupInfo);
} else {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_GROUP_INFO, NULL, 0);
}
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return (ret == HC_SUCCESS) ? ret : HC_ERROR;
}
static int32_t IpcServiceGmGetGroupInfo(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
const char *appId = NULL;
const char *queryParams = NULL;
char *outGroups = NULL;
uint32_t groupNum = 0;
LOGI("starting ...");
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if ((ret != HC_SUCCESS) || (appId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_QUERY_PARAMS, (uint8_t *)&queryParams, NULL);
if ((ret != HC_SUCCESS) || (queryParams == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_QUERY_PARAMS);
return ret;
}
callRet = g_devGroupMgrMethod.getGroupInfo(appId, queryParams, &outGroups, &groupNum);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT_NUM,
(const uint8_t *)&g_ipcResultNum2, sizeof(int32_t));
if (outGroups != NULL) {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)outGroups, strlen(outGroups) + 1);
} else {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_GROUP_INFO, NULL, 0);
}
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&groupNum, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
g_devGroupMgrMethod.destroyInfo(&outGroups);
return (ret == HC_SUCCESS) ? ret : HC_ERROR;
}
static int32_t IpcServiceGmGetJoinedGroups(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
int32_t groupType = 0;
const char *appId = NULL;
char *outGroups = NULL;
uint32_t groupNum = 0;
int32_t inOutLen;
LOGI("starting ...");
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if ((ret != HC_SUCCESS) || (appId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
inOutLen = sizeof(groupType);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUP_TYPE, (uint8_t *)&groupType, &inOutLen);
if ((ret != HC_SUCCESS || (inOutLen != sizeof(groupType)))) {
LOGE("get param error, type %d", PARAM_TYPE_GROUP_TYPE);
return ret;
}
callRet = g_devGroupMgrMethod.getJoinedGroups(appId, groupType, &outGroups, &groupNum);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT_NUM,
(const uint8_t *)&g_ipcResultNum2, sizeof(int32_t));
if (outGroups != NULL) {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)outGroups, strlen(outGroups) + 1);
g_devGroupMgrMethod.destroyInfo(&outGroups);
} else {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_GROUP_INFO, NULL, 0);
}
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&groupNum, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return (ret == HC_SUCCESS) ? ret : HC_ERROR;
}
static int32_t IpcServiceGmGetRelatedGroups(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
const char *appId = NULL;
const char *peerUdid = NULL;
char *outGroups = NULL;
uint32_t groupNum = 0;
LOGI("starting ...");
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if ((ret != HC_SUCCESS) || (appId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_UDID, (uint8_t *)&peerUdid, NULL);
if ((ret != HC_SUCCESS) || (peerUdid == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_UDID);
return ret;
}
callRet = g_devGroupMgrMethod.getRelatedGroups(appId, peerUdid, &outGroups, &groupNum);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT_NUM,
(const uint8_t *)&g_ipcResultNum2, sizeof(int32_t));
if (outGroups != NULL) {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)outGroups, strlen(outGroups) + 1);
} else {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_GROUP_INFO, NULL, 0);
}
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&groupNum, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
g_devGroupMgrMethod.destroyInfo(&outGroups);
return (ret == HC_SUCCESS) ? ret : HC_ERROR;
}
static int32_t IpcServiceGmGetDeviceInfoById(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
const char *appId = NULL;
const char *peerUdid = NULL;
const char *groupId = NULL;
char *outDevInfo = NULL;
LOGI("starting ...");
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if ((ret != HC_SUCCESS) || (appId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_UDID, (uint8_t *)&peerUdid, NULL);
if ((ret != HC_SUCCESS) || (peerUdid == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_UDID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
if ((ret != HC_SUCCESS) || (groupId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
return ret;
}
callRet = g_devGroupMgrMethod.getDeviceInfoById(appId, peerUdid, groupId, &outDevInfo);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT_NUM,
(const uint8_t *)&g_ipcResultNum1, sizeof(int32_t));
if (outDevInfo != NULL) {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_DEVICE_INFO,
(const uint8_t *)outDevInfo, strlen(outDevInfo) + 1);
g_devGroupMgrMethod.destroyInfo(&outDevInfo);
} else {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_DEVICE_INFO, NULL, 0);
}
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return (ret == HC_SUCCESS) ? ret : HC_ERROR;
}
static int32_t IpcServiceGmGetTrustedDevices(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
const char *appId = NULL;
const char *groupId = NULL;
char *outDevInfo = NULL;
uint32_t outDevNum = 0;
LOGI("starting ...");
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if ((ret != HC_SUCCESS) || (appId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
if ((ret != HC_SUCCESS) || (groupId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
return ret;
}
callRet = g_devGroupMgrMethod.getTrustedDevices(appId, groupId, &outDevInfo, &outDevNum);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT_NUM,
(const uint8_t *)&g_ipcResultNum2, sizeof(int32_t));
if (outDevInfo != NULL) {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_DEVICE_INFO,
(const uint8_t *)outDevInfo, strlen(outDevInfo) + 1);
} else {
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_DEVICE_INFO, NULL, 0);
}
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&outDevNum, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
g_devGroupMgrMethod.destroyInfo(&outDevInfo);
return (ret == HC_SUCCESS) ? ret : HC_ERROR;
}
static int32_t IpcServiceGmIsDeviceInGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
bool bRet = false;
const char *appId = NULL;
const char *udid = NULL;
const char *groupId = NULL;
LOGI("starting ...");
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
if ((ret != HC_SUCCESS) || (appId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_APPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_UDID, (uint8_t *)&udid, NULL);
if ((ret != HC_SUCCESS) || (udid == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_UDID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
if ((ret != HC_SUCCESS) || (groupId == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
return ret;
}
bRet = g_devGroupMgrMethod.isDeviceInGroup(appId, groupId, udid);
callRet = ((bRet == true) ? HC_SUCCESS : HC_ERROR);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGaProcessData(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
const DeviceAuthCallback *gaCallback = NULL;
int64_t authReqId = 0;
uint8_t *data = NULL;
uint32_t dataLen = 0;
int32_t inOutLen;
int32_t cbObjIdx = -1;
LOGI("starting ...");
inOutLen = sizeof(authReqId);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&authReqId, &inOutLen);
if ((ret != HC_SUCCESS) || (inOutLen != sizeof(authReqId))) {
LOGE("get param error, type %d", PARAM_TYPE_REQID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_COMM_DATA, (uint8_t *)&data, (int32_t *)&dataLen);
if ((ret != HC_SUCCESS) || (data == NULL) || (dataLen == 0)) {
LOGE("get param error, type %d", PARAM_TYPE_COMM_DATA);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&gaCallback, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_DEV_AUTH_CB);
return ret;
}
/* add call back */
ret = AddIpcCallBackByReqId(authReqId, (const uint8_t *)gaCallback,
sizeof(DeviceAuthCallback), CB_TYPE_TMP_DEV_AUTH);
if (ret != HC_SUCCESS) {
LOGE("add ipc callback failed");
return HC_ERROR;
}
inOutLen = sizeof(cbObjIdx);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_CB_OBJECT);
DelIpcCallBackByReqId(authReqId, CB_TYPE_TMP_DEV_AUTH, true);
return ret;
}
AddIpcCbObjByReqId(authReqId, cbObjIdx, CB_TYPE_TMP_DEV_AUTH);
InitDeviceAuthCbCtx(&g_authCbAdt, CB_TYPE_TMP_DEV_AUTH);
callRet = g_groupAuthMgrMethod.processData(authReqId, data, dataLen, &g_authCbAdt);
if (callRet != HC_SUCCESS) {
DelIpcCallBackByReqId(authReqId, CB_TYPE_TMP_DEV_AUTH, true);
}
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGaQueryTrustedDeviceNum(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
(void)ipcParams;
(void)paramNum;
LOGI("starting ...");
callRet = g_groupAuthMgrMethod.queryTrustedDeviceNum();
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGaIsTrustedDevice(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
int32_t udidLen = 0;
bool bRet = false;
const char *udid = NULL;
LOGI("starting ...");
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_COMM_DATA, (uint8_t *)&udid, &udidLen);
if ((ret != HC_SUCCESS) || (udid == NULL) || (udidLen == 0)) {
LOGE("get param error, type %d", PARAM_TYPE_COMM_DATA);
return ret;
}
bRet = g_groupAuthMgrMethod.isTrustedDevice(udid);
callRet = ((bRet == true) ? HC_SUCCESS : HC_ERROR);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGaGetAuthState(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
const char *groupId = NULL;
const char *peerUdid = NULL;
int64_t authReqId = 0;
int32_t inOutLen;
uint8_t out[512] = {0}; /* 512 - buffer size */
uint32_t outLen = sizeof(out);
LOGI("starting ...");
inOutLen = sizeof(authReqId);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&authReqId, &inOutLen);
if ((ret != HC_SUCCESS) || (inOutLen != sizeof(authReqId))) {
LOGE("get param error, type %d", PARAM_TYPE_REQID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_UDID, (uint8_t *)&peerUdid, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_UDID);
return ret;
}
callRet = g_groupAuthMgrMethod.getAuthState(authReqId, groupId, peerUdid, out, &outLen);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_COMM_DATA, (const uint8_t *)out, (int32_t)outLen);
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return (ret == HC_SUCCESS) ? ret : HC_ERROR;
}
static int32_t IpcServiceGaAuthDevice(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet;
int32_t ret;
DeviceAuthCallback *gaCallback = NULL;
int64_t authReqId = 0;
const char *authParams = NULL;
int32_t inOutLen;
int32_t cbObjIdx = -1;
LOGI("starting ...");
inOutLen = sizeof(authReqId);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&authReqId, &inOutLen);
if ((ret != HC_SUCCESS) || (inOutLen != sizeof(authReqId))) {
LOGE("get param error, type %d", PARAM_TYPE_REQID);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_AUTH_PARAMS, (uint8_t *)&authParams, NULL);
if ((ret != HC_SUCCESS) || (authParams == NULL)) {
LOGE("get param error, type %d", PARAM_TYPE_AUTH_PARAMS);
return ret;
}
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&gaCallback, NULL);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_DEV_AUTH_CB);
return ret;
}
/* add call back */
ret = AddIpcCallBackByReqId(authReqId, (const uint8_t *)gaCallback,
sizeof(DeviceAuthCallback), CB_TYPE_TMP_DEV_AUTH);
if (ret != HC_SUCCESS) {
LOGE("add ipc callback failed");
return HC_ERROR;
}
inOutLen = sizeof(cbObjIdx);
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen);
if (ret != HC_SUCCESS) {
LOGE("get param error, type %d", PARAM_TYPE_CB_OBJECT);
DelIpcCallBackByReqId(authReqId, CB_TYPE_TMP_DEV_AUTH, true);
return ret;
}
AddIpcCbObjByReqId(authReqId, cbObjIdx, CB_TYPE_TMP_DEV_AUTH);
InitDeviceAuthCbCtx(&g_authCbAdt, CB_TYPE_TMP_DEV_AUTH);
callRet = g_groupAuthMgrMethod.authDevice(authReqId, authParams, &g_authCbAdt);
if (callRet != HC_SUCCESS) {
DelIpcCallBackByReqId(authReqId, CB_TYPE_TMP_DEV_AUTH, true);
}
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t IpcServiceGaInformDevDisconnection(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
{
int32_t callRet = HC_SUCCESS;
int32_t ret;
int32_t udidLen = 0;
const char *udid = NULL;
LOGI("starting ...");
ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_COMM_DATA, (uint8_t *)&udid, &udidLen);
if ((ret != HC_SUCCESS) || (udid == NULL) || (udidLen == 0)) {
LOGE("get param error, type %d", PARAM_TYPE_COMM_DATA);
return ret;
}
g_groupAuthMgrMethod.informDeviceDisconnection(udid);
ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
return ret;
}
static int32_t AddMethodMap(uintptr_t ipcInstance)
{
uint32_t ret;
ret = SetIpcCallMap(ipcInstance, IpcServiceGmRegCallback, IPC_CALL_ID_REG_CB);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmUnRegCallback, IPC_CALL_ID_UNREG_CB);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmRegDataChangeListener, IPC_CALL_ID_REG_LISTENER);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmUnRegDataChangeListener, IPC_CALL_ID_UNREG_LISTENER);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmCreateGroup, IPC_CALL_ID_CREATE_GROUP);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmDelGroup, IPC_CALL_ID_DEL_GROUP);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmAddMemberToGroup, IPC_CALL_ID_ADD_GROUP_MEMBER);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmDelMemberFromGroup, IPC_CALL_ID_DEL_GROUP_MEMBER);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmProcessData, IPC_CALL_ID_GM_PROC_DATA);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmConfirmRequest, IPC_CALL_ID_CFM_REQUEST);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmBindPeer, IPC_CALL_ID_BIND_PEER);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmUnBindPeer, IPC_CALL_ID_UNBIND_PEER);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmProcessLiteData, IPC_CALL_ID_PROC_LIGHT_DATA);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmSaveCredential, IPC_CALL_ID_SAVE_CREDENTIAL);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmApplyRegisterInfo, IPC_CALL_ID_APPLY_REG_INFO);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmAddGroupManager, IPC_CALL_ID_ADD_GROUP_MGR);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmAddGroupFriend, IPC_CALL_ID_ADD_GROUP_FRIEND);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmDelGroupManager, IPC_CALL_ID_DEL_GROUP_MGR);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmDelGroupFriend, IPC_CALL_ID_DEL_GROUP_FRIEND);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetGroupManagers, IPC_CALL_ID_GET_GROUP_MGR);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetGroupFriends, IPC_CALL_ID_GET_GROUP_FRIEND);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetGroupInfoById, IPC_CALL_ID_GET_GROUP_INFO);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetGroupInfo, IPC_CALL_ID_SEARCH_GROUPS);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetJoinedGroups, IPC_CALL_ID_GET_JOINED_GROUPS);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetRelatedGroups, IPC_CALL_ID_GET_RELATED_GROUPS);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetDeviceInfoById, IPC_CALL_ID_GET_DEV_INFO_BY_ID);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetTrustedDevices, IPC_CALL_ID_GET_TRUST_DEVICES);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGmIsDeviceInGroup, IPC_CALL_ID_IS_DEV_IN_GROUP);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGaProcessData, IPC_CALL_ID_GA_PROC_DATA);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGaQueryTrustedDeviceNum, IPC_CALL_ID_QUERY_TRUST_DEV_NUM);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGaIsTrustedDevice, IPC_CALL_ID_IS_TRUST_DEVICE);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGaGetAuthState, IPC_CALL_ID_GET_AUTH_STATE);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGaAuthDevice, IPC_CALL_ID_AUTH_DEVICE);
ret &= SetIpcCallMap(ipcInstance, IpcServiceGaInformDevDisconnection, IPC_CALL_ID_INFORM_DEV_DISCONN);
LOGI("process done, ret %u", ret);
return ret;
}
void DeMainRescInit(uintptr_t *serviceCtx)
{
if (g_devGroupMgrMethod.unRegDataChangeListener != NULL) {
(void)g_devGroupMgrMethod.unRegDataChangeListener(g_serviceAppId);
}
DeInitIpcCallBackList();
DestroyServiceInstance(serviceCtx);
return;
}
int32_t MainRescInit(void)
{
int32_t ret;
const DeviceGroupManager *gmInst = NULL;
const GroupAuthManager *gaInst = NULL;
LOGI("starting ...");
ret = InitIpcCallBackList();
if (ret != HC_SUCCESS) {
return ret;
}
gmInst = GetGmInstance();
gaInst = GetGaInstance();
if ((gmInst == NULL) || (gaInst == NULL)) {
DeInitIpcCallBackList();
LOGE("MainInit, GetGmInstance failed");
return HC_ERROR;
}
g_devGroupMgrMethod = (DeviceGroupManager)(*gmInst);
g_groupAuthMgrMethod = (GroupAuthManager)(*gaInst);
InitDevAuthListenerCbCtx(&g_listenCbAdt);
ret = gmInst->regDataChangeListener(g_serviceAppId, &g_listenCbAdt);
if (ret != HC_SUCCESS) {
DeInitIpcCallBackList();
LOGE("MainInit, register ipc listener failed, ret %d", ret);
return HC_ERROR;
}
LOGI("process done");
return HC_SUCCESS;
}
int32_t main(int32_t argc, char const *argv[])
{
uintptr_t serviceCtx = 0x0;
int32_t ret;
HcCondition cond;
(void)argc;
(void)argv;
LOGI("device authentication service starting ...");
ret = InitDeviceAuthService();
if (ret != HC_SUCCESS) {
LOGE("device auth service main, InitDeviceAuthService failed, ret %d", ret);
return 1;
}
ret = MainRescInit();
if (ret != HC_SUCCESS) {
DestroyDeviceAuthService();
LOGE("device auth service main, init work failed");
return 1;
}
ret = AddDevAuthServiceToManager(&serviceCtx);
if (ret != HC_SUCCESS) {
DeMainRescInit(&serviceCtx);
DestroyDeviceAuthService();
serviceCtx = 0x0;
LOGE("device auth service main, AddDevAuthServiceToManager failed, ret %d", ret);
return 1;
}
(void)AddMethodMap(serviceCtx);
LOGI("device authentication service register to IPC manager done, service running...");
(void)memset_s(&cond, sizeof(cond), 0, sizeof(cond));
InitHcCond(&cond, NULL);
cond.wait(&cond);
DestroyHcCond(&cond);
return 0;
}
#ifdef __cplusplus
}
#endif
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2012-2018. All rights reserved.
* Description: hichain function test
*/
// #include "hichain_function_test.h"
#include "log.h"
#include "distribution.h"
#include "hichain.h"
#include "hctest.h"
#include "hks_client.h"
#include "hks_types.h"
#include <securec.h>
#include <sys/time.h>
#include <sys/time.h>
#define MAX_SEND_MESSAGE_BUFF 1024
#define PRINT(...)
LITE_TEST_SUIT(security, securityData, HichainFunctionTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL HichainFunctionTestSuiteSetUp(void)
{
int32_t status;
status = hks_init();
if (status != 0) {
status = hks_refresh_key_info();
}
TEST_ASSERT_EQUAL_INT(0, status);
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL HichainFunctionTestSuiteTearDown(void)
{
printf("-+++++++++++++++++++++++++++++++++++++++++++++-\n");
return TRUE;
}
static char g_sendMessageBuf[MAX_SEND_MESSAGE_BUFF];
static struct hc_auth_id g_testClientAuthId = { sizeof("authClient") - 1, "authClient" };
static struct hc_auth_id g_testServerAuthId = { sizeof("authServer") - 1, "authServer" };
static struct hc_pin g_testPin = { sizeof("123456789012345") - 1, "123456789012345" };
static uint32_t g_sendLength = 0;
static int32_t g_serviceResult = 0;
static struct session_identity g_clientIdentity = {
0,
{ sizeof("testClient") - 1, "testClient" },
{ sizeof("testClient") - 1, "testClient" },
0
};
static struct session_identity g_serverIdentity = {
0,
{ sizeof("testServer") - 1, "testServer" },
{ sizeof("testServer") - 1, "testServer" },
0
};
void TransmitDoNothing(const struct session_identity *identity, const void *data, uint32_t length)
{
if (memcpy_s(g_sendMessageBuf, MAX_SEND_MESSAGE_BUFF, data, length) != EOK) {
return;
}
g_sendMessageBuf[length] = 0;
PRINT("Send data: %s\n", g_sendMessageBuf);
g_sendLength = length;
identity = identity;
}
void GetProtocolParams(const struct session_identity *identity, int32_t operationCode, struct hc_pin *pin,
struct operation_parameter *para)
{
(void)identity;
(void)operationCode;
*pin = g_testPin;
para->key_length = 32; // 传入128计算hkdf失败, 暂时改成32
para->peer_auth_id = g_testClientAuthId;
para->self_auth_id = g_testServerAuthId;
}
void SetSessionKey(const struct session_identity *identity, const struct hc_session_key *sessionKey)
{
(void)identity;
(void)sessionKey;
}
void SetServiceResult(const struct session_identity *identity, int32_t result)
{
(void)identity;
g_serviceResult = result;
}
int32_t ConfirmReceiveRequestOK(const struct session_identity *identity, int32_t operationCode)
{
(void)identity;
(void)operationCode;
return 0;
}
void GetProtocolParamsClient(const struct session_identity *identity, int32_t operationCode, struct hc_pin *pin,
struct operation_parameter *para)
{
(void)identity;
(void)operationCode;
*pin = g_testPin;
para->key_length = 32; // 传入128计算hkdf失败, 暂时改成32
para->peer_auth_id = g_testServerAuthId;
para->self_auth_id = g_testClientAuthId;
}
static void HcLogd(const char *tag, const char *func, const char *format, ...)
{
printf("%s Debug: %s: ", tag, func);
va_list args;
va_start(args, format);
(void)vprintf(format, args);
va_end(args);
printf("\n");
}
static void HcLogi(const char *tag, const char *func, const char *format, ...)
{
printf("%s Info: %s: ", tag, func);
va_list args;
va_start(args, format);
(void)vprintf(format, args);
va_end(args);
printf("\n");
}
static void HcLogw(const char *tag, const char *func, const char *format, ...)
{
printf("%s Warning: %s: ", tag, func);
va_list args;
va_start(args, format);
(void)vprintf(format, args);
va_end(args);
printf("\n");
}
static void HcLoge(const char *tag, const char *func, const char *format, ...)
{
PrintTime();
printf("%s Error: %s: ", tag, func);
va_list args;
va_start(args, format);
(void)vprintf(format, args);
va_end(args);
printf("\n");
}
/* *
* @tc.name: IntentParseUriToUri001
* @tc.desc: Binding end key exchange
* @tc.type: FUNC
* @tc.require:
* @tc.author: dingjinyan
*/
LITE_TEST_CASE(HichainFunctionTestSuite, HichainBindPeer, Function | MediumTest | Level1)
{
struct log_func_group g = {HcLogd, HcLogi, HcLogw, HcLoge};
registe_log(&g);
/* 设置回调函数 */
struct hc_call_back callBack = { TransmitDoNothing, GetProtocolParams, SetSessionKey, SetServiceResult,
ConfirmReceiveRequestOK };
struct hc_call_back callBackClient = { TransmitDoNothing, GetProtocolParamsClient, SetSessionKey, SetServiceResult,
ConfirmReceiveRequestOK };
/* 构造函数 */
hc_handle server = get_instance(&g_serverIdentity, HC_ACCESSORY, &callBack);
hc_handle client = get_instance(&g_clientIdentity, HC_CENTRE, &callBackClient);
struct operation_parameter params = { g_testClientAuthId, g_testServerAuthId, 32 };
int32_t ret = start_pake(client, &params);
TEST_ASSERT_EQUAL_INT(ret, HC_OK);
TEST_ASSERT_EQUAL_INT(g_serviceResult, KEY_AGREEMENT_PROCESSING);
struct uint8_buff startRequest = { (uint8_t *)g_sendMessageBuf, g_sendLength, g_sendLength };
ret = receive_data(server, &startRequest);
TEST_ASSERT_EQUAL_INT(ret, HC_OK);
TEST_ASSERT_EQUAL_INT(g_serviceResult, KEY_AGREEMENT_PROCESSING);
struct uint8_buff startResponse = { (uint8_t *)g_sendMessageBuf, g_sendLength, g_sendLength };
ret = receive_data(client, &startResponse);
TEST_ASSERT_EQUAL_INT(ret, HC_OK);
TEST_ASSERT_EQUAL_INT(g_serviceResult, KEY_AGREEMENT_PROCESSING);
struct uint8_buff endRequest = { (uint8_t *)g_sendMessageBuf, g_sendLength, g_sendLength };
ret = receive_data(server, &endRequest);
TEST_ASSERT_EQUAL_INT(ret, HC_OK);
TEST_ASSERT_EQUAL_INT(g_serviceResult, KEY_AGREEMENT_END);
struct uint8_buff endResponse = { (uint8_t *)g_sendMessageBuf, g_sendLength, g_sendLength };
ret = receive_data(client, &endResponse);
TEST_ASSERT_EQUAL_INT(ret, HC_OK);
TEST_ASSERT_EQUAL_INT(g_serviceResult, KEY_AGREEMENT_END);
struct uint8_buff exchangeRequest = { (uint8_t *)g_sendMessageBuf, g_sendLength, g_sendLength };
ret = receive_data(server, &exchangeRequest);
TEST_ASSERT_EQUAL_INT(ret, HC_OK);
TEST_ASSERT_EQUAL_INT(g_serviceResult, END_SUCCESS);
struct uint8_buff exchangeResponse = { (uint8_t *)g_sendMessageBuf, g_sendLength, g_sendLength };
ret = receive_data(client, &exchangeResponse);
TEST_ASSERT_EQUAL_INT(ret, HC_OK);
TEST_ASSERT_EQUAL_INT(g_serviceResult, END_SUCCESS);
destroy(&client);
destroy(&server);
}
RUN_TEST_SUITE(HichainFunctionTestSuite);
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册