!69 add softbus channel

Merge pull request !69 from 符子坤/master
This commit is contained in:
openharmony_ci
2021-09-02 04:17:27 +00:00
committed by Gitee
39 changed files with 674 additions and 736 deletions
+2 -2
View File
@@ -823,10 +823,10 @@ static int32_t IpcGmGetRegisterInfo(char **registerInfo)
return (*registerInfo != NULL) ? HC_SUCCESS : HC_ERR_NULL_PTR;
}
static int32_t IpcGmGetLocalConnectInfo(char **outLocalConnInfo)
static int32_t IpcGmGetLocalConnectInfo(char *returnInfo, int32_t bufLen)
{
LOGI("starting ...");
if (outLocalConnInfo == NULL) {
if (returnInfo == NULL) {
return HC_ERR_INVALID_PARAMS;
}
+1
View File
@@ -17,6 +17,7 @@
#define COMMON_UTIL_H
#include <stdint.h>
#include "hc_error.h"
#define BYTE_TO_HEX_OPER_LENGTH 2
#define DEC 10
+1
View File
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "cJSON.h"
#include "hc_error.h"
typedef cJSON CJson;
+1 -1
View File
@@ -136,7 +136,7 @@ typedef struct {
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 (*getLocalConnectInfo)(char *returnInfo, int32_t bufLen);
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);
+4 -3
View File
@@ -29,7 +29,7 @@ enum {
HC_ERR_NULL_PTR = 0x00000004,
HC_ERR_ALLOC_MEMORY = 0x00000005,
HC_ERR_MEMORY_COPY = 0x00000006,
HC_HEX_CONVERT_FAILED = 0x00000007,
HC_ERR_CONVERT_FAILED = 0x00000007,
HC_ERR_NOT_SUPPORT = 0x00000008,
HC_ERR_TIME_OUT = 0x00000009,
HC_ERR_CASE = 0x0000000A,
@@ -42,6 +42,7 @@ enum {
HC_ERR_INVALID_PUBLIC_KEY = 0x00001003,
HC_ERR_VERIFY_FAILED = 0x00001004,
HC_ERR_HASH_FAIL = 0x00001005,
HC_ERR_INIT_FAILED = 0x00001006,
/* error code for json util , 0x00002000 ~ 0x00002FFF */
HC_ERR_JSON_FAIL = 0x00002001,
@@ -111,10 +112,10 @@ enum {
HC_ERR_LOST_DATA = 0x0000600A,
/* error code for broadcast , 0x00007000 ~ 0x00007FFF */
HC_ERR_LISTENER_NOT_EXIST = 0x000070012,
HC_ERR_LISTENER_NOT_EXIST = 0x00007001,
/* error code for channel , 0x00008000 ~ 0x00008FFF */
HC_ERR_CHANNEL_NOT_EXIST = 0x000080012,
HC_ERR_CHANNEL_NOT_EXIST = 0x00008001,
HC_ERR_SOFT_BUS = 0x00008002,
/* error code used on DAS service */
+16 -6
View File
@@ -27,7 +27,10 @@ if (defined(ohos_lite)) {
"//third_party/cJSON",
"//utils/native/lite/include",
"//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog",
"//third_party/bounds_checking_function/include"
"//third_party/bounds_checking_function/include",
"//foundation/communication/dsoftbus/interfaces/kits/common",
"//foundation/communication/dsoftbus/interfaces/kits/transport",
"//foundation/communication/dsoftbus/interfaces/inner_kits/transport",
]
sources = deviceauth_files
@@ -39,6 +42,7 @@ if (defined(ohos_lite)) {
"//build/lite/config/component/cJSON:cjson_shared",
"//utils/native/lite:utils",
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
"//foundation/communication/dsoftbus/sdk:softbus_client",
"//third_party/bounds_checking_function:libsec_shared",
]
}
@@ -116,30 +120,36 @@ if (defined(ohos_lite)) {
ohos_static_library("deviceauth") {
subsystem_name = "security"
part_name = "deviceauth_standard"
include_dirs = inc_path
include_dirs += hals_inc_path
include_dirs += [
"//third_party/cJSON",
"//utils/native/base/include",
"${frameworks_path}/inc/standard"
"${frameworks_path}/inc/standard",
"//foundation/communication/dsoftbus/interfaces/kits/common",
"//foundation/communication/dsoftbus/interfaces/kits/transport",
"//foundation/communication/dsoftbus/interfaces/inner_kits/transport",
]
sources = deviceauth_files
cflags = [ "-DHILOG_ENABLE" ]
cflags += build_flags
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
deps = [
"${hals_path}:${hal_module_name}",
"//third_party/cJSON:cjson_static",
"//utils/native/base:utils",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"dsoftbus_standard:softbus_client",
]
}
ohos_prebuilt_etc("auth_service.rc") {
@@ -20,19 +20,23 @@
#include "common_defs.h"
#include "json_utils.h"
int32_t InitChannelManager(void (*onChannelOpened)(int64_t, int64_t, const char *, uint32_t, bool),
void (*onChannelClosed)(int64_t, int64_t),
void (*onMsgReceived)(int64_t, const uint8_t *, uint32_t),
void (*onServiceDied)());
void DestroyChannelManager();
#ifdef __cplusplus
extern "C" {
#endif
int32_t InitChannelManager(void);
void DestroyChannelManager(void);
/* Channel operation interfaces */
ChannelType GetChannelType(const DeviceAuthCallback *callback);
bool CanFindValidChannel(ChannelType channelType, const CJson *jsonParams, const DeviceAuthCallback *callback);
ChannelType GetChannelType(const DeviceAuthCallback *callback, const CJson *jsonParams);
int32_t OpenChannel(ChannelType channelType, const CJson *jsonParams, int64_t requestId, int64_t *returnChannelId);
void CloseChannel(ChannelType channelType, int64_t channelId);
int32_t SendMsg(ChannelType channelType, int64_t requestId, int64_t channelId,
int32_t HcSendMsg(ChannelType channelType, int64_t requestId, int64_t channelId,
const DeviceAuthCallback *callback, const char *data);
void SetAuthResult(ChannelType channelType, int64_t channelId);
int32_t GetLocalConnectInfo(char **returnLocalConnectInfo);
int32_t GetLocalConnectInfo(char *jsonAddrInfo, int32_t bufLen);
#ifdef __cplusplus
}
#endif
#endif
@@ -19,20 +19,23 @@
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
int32_t (*openChannel)(const char *connectParams, int64_t requestId, int64_t *returnChannelId);
void (*closeChannel)(int64_t channelId);
int32_t (*sendMsg)(int64_t channelId, const uint8_t *data, uint32_t dataLen);
void (*setAuthResult)(int64_t channelId);
char *(*getLocalAuthInfo)();
void (*notifyResult)(int64_t channelId);
} SoftBus;
int32_t InitSoftBusChannelModule(void (*onChannelOpened)(int64_t, int64_t, const char *, uint32_t, bool),
void (*onChannelClosed)(int64_t, int64_t),
void (*onMsgReceived)(int64_t, const uint8_t *, uint32_t),
void (*onServiceDied)());
void DestroySoftBusChannelModule();
SoftBus *GetSoftBusInstance();
bool IsSoftBusChannelSupported();
int32_t InitSoftBusChannelModule(void);
void DestroySoftBusChannelModule(void);
SoftBus *GetSoftBusInstance(void);
bool IsSoftBusChannelSupported(void);
#ifdef __cplusplus
}
#endif
#endif
+1
View File
@@ -129,6 +129,7 @@
#define DEFAULT_RETURN_KEY_LENGTH 32
#define ERR_AUTH_FORM 0
#define MAX_BUFFER_LEN 1024
#define MAX_DATA_BUFFER_SIZE 4096
#define MAX_AUTH_ID_LEN 256
typedef enum {
@@ -0,0 +1,32 @@
/*
* 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 TASK_MANAGER_H
#define TASK_MANAGER_H
#include "hc_task_thread.h"
#ifdef __cplusplus
extern "C" {
#endif
int32_t InitTaskManager(void);
void DestroyTaskManager(void);
int32_t PushTask(HcTaskBase *baseTask);
#ifdef __cplusplus
}
#endif
#endif
@@ -14,199 +14,97 @@
*/
#include "channel_manager.h"
#include "callback_manager.h"
#include "device_auth_defines.h"
#include "hc_log.h"
#include "hc_types.h"
#include "soft_bus_channel.h"
int32_t InitChannelManager(void (*onChannelOpened)(int64_t, int64_t, const char *, uint32_t, bool),
void (*onChannelClosed)(int64_t, int64_t),
void (*onMsgReceived)(int64_t, const uint8_t *, uint32_t),
void (*onServiceDied)())
static bool g_initialized = false;
int32_t InitChannelManager(void)
{
if (IsSoftBusChannelSupported()) {
int32_t res = InitSoftBusChannelModule(onChannelOpened, onChannelClosed, onMsgReceived, onServiceDied);
if (res != HC_SUCCESS) {
DestroyChannelManager();
}
return res;
if (g_initialized || !IsSoftBusChannelSupported()) {
return HC_SUCCESS;
}
return HC_SUCCESS;
int32_t res = InitSoftBusChannelModule();
if (res == HC_SUCCESS) {
g_initialized = true;
}
return res;
}
void DestroyChannelManager()
void DestroyChannelManager(void)
{
if (IsSoftBusChannelSupported()) {
if (g_initialized && IsSoftBusChannelSupported()) {
DestroySoftBusChannelModule();
g_initialized = false;
}
}
ChannelType GetChannelType(const DeviceAuthCallback *callback)
ChannelType GetChannelType(const DeviceAuthCallback *callback, const CJson *jsonParams)
{
if (IsSoftBusChannelSupported()) {
const char *connectParams = GetStringFromJson(jsonParams, FIELD_CONNECT_PARAMS);
if (connectParams != NULL) {
return SOFT_BUS;
}
}
if ((callback != NULL) && (callback->onTransmit != NULL)) {
return SERVICE_CHANNEL;
}
if (IsSoftBusChannelSupported()) {
return SOFT_BUS;
}
return NO_CHANNEL;
}
bool CanFindValidChannel(ChannelType channelType, const CJson *jsonParams, const DeviceAuthCallback *callback)
{
switch (channelType) {
case NO_CHANNEL:
return false;
case SERVICE_CHANNEL:
return ((callback != NULL) && (callback->onTransmit != NULL)) ? true : false;
case SOFT_BUS:
if (GetSoftBusInstance() == NULL) {
LOGE("The soft bus module is unavailable!");
return false;
}
const char *connectParams = GetStringFromJson(jsonParams, FIELD_CONNECT_PARAMS);
if (connectParams == NULL) {
LOGE("Failed to get connectParams from jsonParams!");
return false;
}
return true;
default:
LOGE("Enter the exception case!");
return false;
}
}
int32_t OpenChannel(ChannelType channelType, const CJson *jsonParams, int64_t requestId, int64_t *returnChannelId)
{
int64_t channelId = DEFAULT_CHANNEL_ID;
const char *connectParams = NULL;
switch (channelType) {
case NO_CHANNEL:
LOGE("No channel!");
if (channelType == SERVICE_CHANNEL) {
*returnChannelId = DEFAULT_CHANNEL_ID;
return HC_SUCCESS;
} else if (channelType == SOFT_BUS) {
const char *connectParams = GetStringFromJson(jsonParams, FIELD_CONNECT_PARAMS);
if (connectParams == NULL) {
LOGE("Failed to get connectParams from jsonParams!");
return HC_ERR_JSON_GET;
}
int64_t channelId = DEFAULT_CHANNEL_ID;
int32_t result = GetSoftBusInstance()->openChannel(connectParams, requestId, &channelId);
if (result != HC_SUCCESS) {
return HC_ERR_CHANNEL_NOT_EXIST;
case SERVICE_CHANNEL:
LOGI("Use service channel, so we do not need to open it!");
*returnChannelId = channelId;
return HC_SUCCESS;
case SOFT_BUS:
connectParams = GetStringFromJson(jsonParams, FIELD_CONNECT_PARAMS);
if (connectParams == NULL) {
LOGE("Failed to get connectParams from jsonParams!");
return HC_ERR_JSON_GET;
}
SoftBus *softBusInstance = GetSoftBusInstance();
if (softBusInstance == NULL) {
LOGE("The soft bus module is unavailable!");
return HC_ERR_SOFT_BUS;
}
int32_t result = softBusInstance->openChannel(connectParams, requestId, &channelId);
if (result != HC_SUCCESS) {
LOGE("Failed to open soft bus channel!");
return HC_ERR_CHANNEL_NOT_EXIST;
}
*returnChannelId = channelId;
return HC_SUCCESS;
default:
LOGE("Enter the exception case!");
return HC_ERR_CASE;
}
*returnChannelId = channelId;
return HC_SUCCESS;
} else {
return HC_ERR_CHANNEL_NOT_EXIST;
}
}
void CloseChannel(ChannelType channelType, int64_t channelId)
{
SoftBus *softBusInstance = NULL;
switch (channelType) {
case NO_CHANNEL:
LOGE("No channel!");
return;
case SERVICE_CHANNEL:
LOGI("Use service channel, so we do not need to close it!");
return;
case SOFT_BUS:
softBusInstance = GetSoftBusInstance();
if (softBusInstance == NULL) {
LOGI("The soft bus module is unavailable!");
return;
}
softBusInstance->closeChannel(channelId);
return;
default:
LOGI("Enter the exception case!");
return;
if (channelType == SOFT_BUS) {
GetSoftBusInstance()->closeChannel(channelId);
}
}
int32_t SendMsg(ChannelType channelType, int64_t requestId, int64_t channelId,
int32_t HcSendMsg(ChannelType channelType, int64_t requestId, int64_t channelId,
const DeviceAuthCallback *callback, const char *data)
{
SoftBus *softBusInstance = NULL;
switch (channelType) {
case NO_CHANNEL:
LOGE("No channel!");
return HC_ERR_CHANNEL_NOT_EXIST;
case SERVICE_CHANNEL:
if (ProcessTransmitCallback(requestId, (uint8_t *)data, HcStrlen(data) + 1, callback)) {
return HC_SUCCESS;
}
return HC_ERR_TRANSMIT_FAIL;
case SOFT_BUS:
softBusInstance = GetSoftBusInstance();
if (softBusInstance == NULL) {
LOGE("The soft bus module is unavailable!");
return HC_ERR_SOFT_BUS;
}
return softBusInstance->sendMsg(channelId, (uint8_t *)data, HcStrlen(data) + 1);
default:
LOGE("Enter the exception case!");
return HC_ERR_CASE;
if (channelType == SERVICE_CHANNEL) {
if (ProcessTransmitCallback(requestId, (uint8_t *)data, HcStrlen(data) + 1, callback)) {
return HC_SUCCESS;
}
return HC_ERR_TRANSMIT_FAIL;
} else if (channelType == SOFT_BUS) {
return GetSoftBusInstance()->sendMsg(channelId, (uint8_t *)data, HcStrlen(data) + 1);
} else {
return HC_ERR_CHANNEL_NOT_EXIST;
}
}
void SetAuthResult(ChannelType channelType, int64_t channelId)
{
SoftBus *softBusInstance = NULL;
switch (channelType) {
case NO_CHANNEL:
LOGI("No channel!");
return;
case SERVICE_CHANNEL:
return;
case SOFT_BUS:
softBusInstance = GetSoftBusInstance();
if (softBusInstance == NULL) {
LOGI("The soft bus module is unavailable!");
return;
}
softBusInstance->setAuthResult(channelId);
return;
default:
LOGI("Enter the exception case!");
return;
if (channelType == SOFT_BUS) {
GetSoftBusInstance()->notifyResult(channelId);
}
}
int32_t GetLocalConnectInfo(char **returnInfo)
{
if (!IsSoftBusChannelSupported()) {
LOGE("Soft bus not supported!");
return HC_ERR_NOT_SUPPORT;
}
SoftBus *softBusInstance = GetSoftBusInstance();
if (softBusInstance == NULL) {
LOGE("The soft bus module is unavailable!");
return HC_ERR_SOFT_BUS;
}
if (returnInfo != NULL) {
LOGI("We're going to get local connection information!");
*returnInfo = softBusInstance->getLocalAuthInfo();
if (*returnInfo == NULL) {
LOGE("Failed to get local connection information!");
return HC_ERR_SOFT_BUS;
}
LOGI("Get local connection information successfully!");
return HC_SUCCESS;
}
LOGE("The address of the input returnLocalConnectInfo is NULL!");
return HC_ERR_INVALID_PARAMS;
}
@@ -14,230 +14,305 @@
*/
#include "soft_bus_channel.h"
#include "common_defs.h"
#include "device_auth.h"
#include "device_auth_defines.h"
#include "group_manager.h"
#include "hc_log.h"
#include "inner_session.h"
#include "session.h"
#include "session_manager.h"
#include "task_manager.h"
#define ETH_IP "ethIp"
#define ETH_PORT "ethPort"
#define WLAN_IP "wifiIp"
#define WLAN_PORT "wifiPort"
#define BR_MAC "brMac"
#define BLE_MAC "bleMac"
typedef struct {
void (*onChannelOpened)(int64_t channelId, int64_t requestId, const char *deviceId,
uint32_t deviceIdLen, bool isServer);
void (*onChannelClosed)(int64_t channelId, int64_t requestId);
void (*onMsgReceived)(int64_t channelId, const uint8_t *data, uint32_t dataLen);
void (*onServiceDied)();
} IAuthMsgListener;
HcTaskBase base;
int64_t requestId;
int64_t channelId;
CJson *params;
} SoftBusTask;
typedef struct {
int (*addListener)(const char *packageName, const IAuthMsgListener *listener);
int (*removeListener)(const char *packageName);
int64_t (*openAuthChannel)(const char *packageName, const char *authInfo, int64_t requestId);
int (*closeChannel)(int64_t channelId);
int (*sendMsg)(int64_t channelId, const uint8_t *data, uint32_t len);
int (*setAuthResult)(int64_t channelId, const uint8_t *data, uint32_t len);
char *(*getLocalAuthInfo)();
} AuthMsgService;
int64_t requestId;
int64_t channelId;
} ChannelEntry;
#define NORMAL_CHANNEL_ID 1
DECLARE_HC_VECTOR(ChannelEntryVec, ChannelEntry)
IMPLEMENT_HC_VECTOR(ChannelEntryVec, ChannelEntry, 1)
static ChannelEntryVec g_channelVec;
static HcMutex *g_channelMutex = NULL;
static int AddListener(const char *packageName, const IAuthMsgListener *listener)
static int32_t GetReqIdByChannelId(int64_t channelId, int64_t *returnReqId)
{
(void)packageName;
(void)listener;
uint32_t index;
ChannelEntry *entry = NULL;
g_channelMutex->lock(g_channelMutex);
FOR_EACH_HC_VECTOR(g_channelVec, index, entry) {
if ((entry != NULL) && (channelId == entry->channelId)) {
*returnReqId = entry->requestId;
g_channelMutex->unlock(g_channelMutex);
return HC_SUCCESS;
}
}
g_channelMutex->unlock(g_channelMutex);
return HC_ERR_REQUEST_NOT_FOUND;
}
static int32_t AddChannelEntry(int64_t requestId, int64_t channelId)
{
int64_t tmpReqId = DEFAULT_REQUEST_ID;
if (GetReqIdByChannelId(channelId, &tmpReqId) == HC_SUCCESS) {
LOGE("A request to use the channel alreay exists!");
return HC_ERR_REQUEST_EXIST;
}
ChannelEntry entry = {
.channelId = channelId,
.requestId = requestId
};
g_channelMutex->lock(g_channelMutex);
g_channelVec.pushBack(&g_channelVec, &entry);
g_channelMutex->unlock(g_channelMutex);
return HC_SUCCESS;
}
static int RemoveListener(const char *packageName)
static void RemoveChannelEntry(int64_t channelId)
{
(void)packageName;
uint32_t index;
ChannelEntry *entry = NULL;
g_channelMutex->lock(g_channelMutex);
FOR_EACH_HC_VECTOR(g_channelVec, index, entry) {
if ((entry != NULL) && (channelId == entry->channelId)) {
ChannelEntry tmpEntry;
HC_VECTOR_POPELEMENT(&g_channelVec, &tmpEntry, index);
g_channelMutex->unlock(g_channelMutex);
return;
}
}
g_channelMutex->unlock(g_channelMutex);
}
static void DoOnChannelOpened(HcTaskBase *baseTask)
{
if (baseTask == NULL) {
LOGE("The input task is NULL!");
return;
}
SoftBusTask *task = (SoftBusTask *)baseTask;
OnChannelOpened(task->requestId, task->channelId);
}
static void InitSoftBusTask(SoftBusTask *task, int64_t requestId, int64_t channelId)
{
task->base.doAction = DoOnChannelOpened;
task->base.destroy = NULL;
task->channelId = channelId;
task->requestId = requestId;
}
static char *GenRecvData(int64_t channelId, const void *data, uint32_t dataLen, int64_t *requestId)
{
char *dataStr = (char *)HcMalloc(dataLen + 1, 0);
if (dataStr == NULL) {
LOGE("Failed to allocate dataStr memory!");
return NULL;
}
if (memcpy_s(dataStr, dataLen + 1, data, dataLen) != HC_SUCCESS) {
LOGE("Failed to copy data!");
HcFree(dataStr);
return NULL;
}
CJson *recvData = CreateJsonFromString(dataStr);
HcFree(dataStr);
if (recvData == NULL) {
LOGE("Failed to create recvData from string!");
return NULL;
}
if (GetInt64FromJson(recvData, FIELD_REQUEST_ID, requestId) != HC_SUCCESS) {
LOGE("Failed to get requestId from recvData!");
FreeJson(recvData);
return NULL;
}
if (AddByteToJson(recvData, FIELD_CHANNEL_ID, (uint8_t *)&channelId, sizeof(int64_t)) != HC_SUCCESS) {
LOGE("Failed to add channelId to recvData!");
FreeJson(recvData);
return NULL;
}
char *recvDataStr = PackJsonToString(recvData);
FreeJson(recvData);
if (recvDataStr == NULL) {
LOGE("Failed to convert json to string!");
return NULL;
}
return recvDataStr;
}
static int OnChannelOpenedCb(int sessionId, int result)
{
if (GetSessionSide(sessionId) == 0) {
LOGD("Peer device open channel!");
return HC_SUCCESS;
}
int64_t requestId = 0;
if (GetReqIdByChannelId(sessionId, &requestId) != HC_SUCCESS) {
LOGE("The request corresponding to the channel is not found!");
return HC_ERR_REQUEST_NOT_FOUND;
}
if (result != HC_SUCCESS) {
LOGE("[SoftBus][Out]: Failed to open channel! res: %d", result);
DestroySession(requestId);
return HC_ERR_SOFT_BUS;
}
LOGD("[Start]: OnChannelOpened! [ReqId]: %lld, [ChannelId]: %d", requestId, sessionId);
SoftBusTask *task = (SoftBusTask *)HcMalloc(sizeof(SoftBusTask), 0);
if (task == NULL) {
LOGE("Failed to allocate task memory!");
DestroySession(requestId);
return HC_ERR_ALLOC_MEMORY;
}
InitSoftBusTask(task, requestId, sessionId);
if (PushTask((HcTaskBase *)task) != HC_SUCCESS) {
DestroySession(requestId);
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
LOGD("[End]: OnChannelOpened!");
return HC_SUCCESS;
}
static int64_t OpenAuthChannel(const char *packageName, const char *connectParams, int64_t requestId)
static void OnChannelClosedCb(int sessionId)
{
(void)packageName;
(void)connectParams;
(void)requestId;
return NORMAL_CHANNEL_ID;
LOGI("[SoftBus][Out]: OnChannelClosed! sessionId: %d", sessionId);
return;
}
static int CloseChannel(int64_t channelId)
static void OnBytesReceivedCb(int sessionId, const void *data, unsigned int dataLen)
{
(void)channelId;
return HC_SUCCESS;
}
static int SendMsg(int64_t channelId, const uint8_t *data, uint32_t dataLen)
{
(void)channelId;
(void)data;
(void)dataLen;
return HC_SUCCESS;
}
static int SetAuthResult(int64_t channelId, const uint8_t *data, uint32_t dataLen)
{
(void)channelId;
(void)data;
(void)dataLen;
return HC_SUCCESS;
}
static char *GetLocalAuthInfo()
{
return "";
}
static AuthMsgService g_softBusInstance = {
.addListener = AddListener,
.removeListener = RemoveListener,
.openAuthChannel = OpenAuthChannel,
.closeChannel = CloseChannel,
.sendMsg = SendMsg,
.setAuthResult = SetAuthResult,
.getLocalAuthInfo = GetLocalAuthInfo
};
static AuthMsgService *GetInstance(const char *packageName)
{
(void)packageName;
return &g_softBusInstance;
if ((data == NULL) || (dataLen == 0) || (dataLen > MAX_DATA_BUFFER_SIZE)) {
LOGE("Invalid input params!");
return;
}
LOGD("[Start]: OnMsgReceived! [ChannelId]: %d", sessionId);
int64_t requestId = DEFAULT_REQUEST_ID;
char *recvDataStr = GenRecvData(sessionId, data, dataLen, &requestId);
if (recvDataStr == NULL) {
return;
}
(void)GetGmInstance()->processData(requestId, (uint8_t *)recvDataStr, HcStrlen(recvDataStr) + 1);
FreeJsonString(recvDataStr);
}
static int32_t OpenSoftBusChannel(const char *connectParams, int64_t requestId, int64_t *returnChannelId)
{
if (returnChannelId == NULL) {
LOGE("The address of the input returnChannelId is NULL!");
if ((connectParams == NULL) || (returnChannelId == NULL)) {
LOGE("The input connectParams or returnChannelId is NULL!");
return HC_ERR_NULL_PTR;
}
AuthMsgService *instance = GetInstance(GROUP_MANAGER_PACKAGE_NAME);
if (instance == NULL) {
LOGE("Failed to get soft bus instance!");
return HC_ERR_SOFT_BUS;
}
LOGI("Ready to open the soft bus channel!");
int64_t channelId = instance->openAuthChannel(GROUP_MANAGER_PACKAGE_NAME, connectParams, requestId);
LOGD("[SoftBus][In]: OpenChannel!");
int64_t channelId = (int64_t)OpenAuthSession(GROUP_MANAGER_PACKAGE_NAME, NULL, 0, connectParams);
LOGD("[SoftBus][Out]: OpenChannel! [channelId]: %lld", channelId);
/* If the value of channelId is less than 0, the soft bus fails to open the channel */
if (channelId < 0) {
LOGE("Failed to open soft bus channel!");
return HC_ERR_SOFT_BUS;
}
LOGI("Open soft bus channel successfully!");
int32_t res = AddChannelEntry(requestId, channelId);
if (res != HC_SUCCESS) {
return res;
}
*returnChannelId = channelId;
return HC_SUCCESS;
}
static void CloseSoftBusChannel(int64_t channelId)
{
AuthMsgService *instance = GetInstance(GROUP_MANAGER_PACKAGE_NAME);
if (instance == NULL) {
LOGE("Failed to get soft bus instance!");
return;
}
LOGI("Ready to close the soft bus channel!");
int32_t result = instance->closeChannel(channelId);
if (result != HC_SUCCESS) {
LOGE("Failed to close soft bus channel!");
}
LOGI("Close soft bus channel success!");
RemoveChannelEntry(channelId);
LOGD("[SoftBus][In]: CloseSession!");
CloseSession(channelId);
LOGD("[SoftBus][Out]: CloseSession!");
}
static int32_t SendSoftBusMsg(int64_t channelId, const uint8_t *data, uint32_t dataLen)
{
AuthMsgService *instance = GetInstance(GROUP_MANAGER_PACKAGE_NAME);
if (instance == NULL) {
LOGE("Failed to get soft bus instance!");
LOGD("[SoftBus][In]: SendMsg!");
int32_t res = SendBytes(channelId, data, dataLen);
LOGD("[SoftBus][Out]: SendMsg! res: %d", res);
if (res != HC_SUCCESS) {
LOGE("An error occurs when the softbus sends data!");
return HC_ERR_SOFT_BUS;
}
LOGI("The soft bus channel starts to send data!");
int32_t result = instance->sendMsg(channelId, data, dataLen);
if (result != HC_SUCCESS) {
LOGE("An error occurs when the soft bus channel sends data!");
return HC_ERR_SOFT_BUS;
}
LOGI("The soft bus channel sends data successfully!");
return HC_SUCCESS;
}
static void SetSoftBusAuthResult(int64_t channelId)
static void NotifySoftBusBindResult(int64_t channelId)
{
AuthMsgService *instance = GetInstance(GROUP_MANAGER_PACKAGE_NAME);
if (instance == NULL) {
LOGE("Failed to get soft bus instance!");
return;
}
LOGI("Prepare to notify the soft bus authentication result!");
int32_t result = instance->setAuthResult(channelId, NULL, 0);
if (result != HC_SUCCESS) {
LOGE("Failed to notify the soft bus of the authentication result!");
return;
}
LOGI("The soft bus is successfully notified of the authentication result!");
}
static char *GetSoftBusLocalAuthInfo()
{
AuthMsgService *instance = GetInstance(GROUP_MANAGER_PACKAGE_NAME);
if (instance == NULL) {
LOGE("Failed to get soft bus instance!");
return "";
}
return instance->getLocalAuthInfo();
LOGD("[SoftBus][In]: NotifyAuthSuccess!");
NotifyAuthSuccess(channelId);
LOGD("[SoftBus][Out]: NotifyAuthSuccess!");
}
SoftBus g_softBus = {
.openChannel = OpenSoftBusChannel,
.closeChannel = CloseSoftBusChannel,
.sendMsg = SendSoftBusMsg,
.setAuthResult = SetSoftBusAuthResult,
.getLocalAuthInfo = GetSoftBusLocalAuthInfo
.notifyResult = NotifySoftBusBindResult
};
int32_t InitSoftBusChannelModule(void (*onChannelOpened)(int64_t, int64_t, const char *, uint32_t, bool),
void (*onChannelClosed)(int64_t, int64_t),
void (*onMsgReceived)(int64_t, const uint8_t *, uint32_t),
void (*onServiceDied)())
int32_t InitSoftBusChannelModule(void)
{
IAuthMsgListener softBusListener = {
.onChannelOpened = onChannelOpened,
.onChannelClosed = onChannelClosed,
.onMsgReceived = onMsgReceived,
.onServiceDied = onServiceDied
if (g_channelMutex == NULL) {
g_channelMutex = (HcMutex *)HcMalloc(sizeof(HcMutex), 0);
if (g_channelMutex == NULL) {
LOGE("Failed to allocate channel mutex memory!");
return HC_ERR_ALLOC_MEMORY;
}
if (InitHcMutex(g_channelMutex) != HC_SUCCESS) {
LOGE("Init mutex failed!");
HcFree(g_channelMutex);
g_channelMutex = NULL;
return HC_ERR_INIT_FAILED;
}
}
g_channelVec = CREATE_HC_VECTOR(ChannelEntryVec)
ISessionListener softBusListener = {
.OnSessionOpened = OnChannelOpenedCb,
.OnSessionClosed = OnChannelClosedCb,
.OnBytesReceived = OnBytesReceivedCb,
.OnMessageReceived = NULL
};
AuthMsgService *instance = GetInstance(GROUP_MANAGER_PACKAGE_NAME);
if (instance == NULL) {
LOGE("Failed to get soft bus instance!");
return HC_ERR_SOFT_BUS;
}
LOGI("Prepare to add listener callback to soft bus service!");
int32_t result = instance->addListener(GROUP_MANAGER_PACKAGE_NAME, &softBusListener);
if (result != HC_SUCCESS) {
LOGE("Failed to add listener callback to soft bus service!");
return HC_ERR_SOFT_BUS;
}
LOGI("Add listener callback to soft bus service successfully!");
return HC_SUCCESS;
LOGD("[SoftBus][In]: CreateSessionServer!");
int32_t res = CreateSessionServer(GROUP_MANAGER_PACKAGE_NAME, GROUP_MANAGER_PACKAGE_NAME, &softBusListener);
LOGD("[SoftBus][Out]: CreateSessionServer! res: %d", res);
return res;
}
void DestroySoftBusChannelModule()
void DestroySoftBusChannelModule(void)
{
AuthMsgService *instance = GetInstance(GROUP_MANAGER_PACKAGE_NAME);
if (instance == NULL) {
LOGI("Failed to get soft bus instance!");
return;
g_channelMutex->lock(g_channelMutex);
DESTROY_HC_VECTOR(ChannelEntryVec, &g_channelVec)
g_channelMutex->unlock(g_channelMutex);
if (g_channelMutex != NULL) {
DestroyHcMutex(g_channelMutex);
HcFree(g_channelMutex);
g_channelMutex = NULL;
}
LOGI("Prepare to remove listener callback from soft bus service!");
int32_t result = instance->removeListener(GROUP_MANAGER_PACKAGE_NAME);
if (result != HC_SUCCESS) {
LOGI("Failed to remove listener callback from soft bus module!");
}
LOGI("Remove listener callback from soft bus service successfully!");
LOGD("[SoftBus][In]: RemoveSessionServer!");
int32_t res = RemoveSessionServer(GROUP_MANAGER_PACKAGE_NAME, GROUP_MANAGER_PACKAGE_NAME);
LOGD("[SoftBus][Out]: RemoveSessionServer! res: %d", res);
}
SoftBus *GetSoftBusInstance()
SoftBus *GetSoftBusInstance(void)
{
return &g_softBus;
}
bool IsSoftBusChannelSupported()
bool IsSoftBusChannelSupported(void)
{
return true;
}
@@ -14,28 +14,25 @@
*/
#include "soft_bus_channel.h"
#include "device_auth_defines.h"
#include "hc_types.h"
int32_t InitSoftBusChannelModule(void (*onChannelOpened)(int64_t, int64_t, const char *, uint32_t, bool),
void (*onChannelClosed)(int64_t, int64_t),
void (*onMsgReceived)(int64_t, const uint8_t *, uint32_t),
void (*onServiceDied)())
#include "device_auth_defines.h"
int32_t InitSoftBusChannelModule(void)
{
return HC_SUCCESS;
}
void DestroySoftBusChannelModule()
void DestroySoftBusChannelModule(void)
{
return;
}
SoftBus *GetSoftBusInstance()
SoftBus *GetSoftBusInstance(void)
{
return NULL;
}
bool IsSoftBusChannelSupported()
bool IsSoftBusChannelSupported(void)
{
return false;
}
@@ -0,0 +1,71 @@
/*
* 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 "task_manager.h"
#include "device_auth_defines.h"
#include "hc_log.h"
#define STACK_SIZE 4096
static HcTaskThread *g_taskThread = NULL;
int32_t PushTask(HcTaskBase *baseTask)
{
if (g_taskThread == NULL) {
LOGE("Task thread is NULL!");
return HC_ERR_NULL_PTR;
}
g_taskThread->pushTask(g_taskThread, baseTask);
return HC_SUCCESS;
}
int32_t InitTaskManager(void)
{
if (g_taskThread != NULL) {
LOGD("Task thread is running!");
return HC_SUCCESS;
}
g_taskThread = (HcTaskThread *)HcMalloc(sizeof(HcTaskThread), 0);
if (g_taskThread == NULL) {
return HC_ERR_ALLOC_MEMORY;
}
int32_t res = InitHcTaskThread(g_taskThread, STACK_SIZE, "HichainThread");
if (res != HC_SUCCESS) {
LOGE("Failed to init task thread! res: %d", res);
HcFree(g_taskThread);
g_taskThread = NULL;
return HC_ERR_INIT_FAILED;
}
res = g_taskThread->startThread(g_taskThread);
if (res != HC_SUCCESS) {
DestroyHcTaskThread(g_taskThread);
HcFree(g_taskThread);
g_taskThread = NULL;
LOGE("Failed to start thread! res: %d", res);
return HC_ERR_INIT_FAILED;
}
return HC_SUCCESS;
}
void DestroyTaskManager(void)
{
if (g_taskThread != NULL) {
g_taskThread->stopAndClear(g_taskThread);
DestroyHcTaskThread(g_taskThread);
HcFree(g_taskThread);
g_taskThread = NULL;
}
}
+109 -299
View File
@@ -14,23 +14,21 @@
*/
#include "device_auth.h"
#include "alg_loader.h"
#include "callback_manager.h"
#include "channel_manager.h"
#include "common_util.h"
#include "database_manager.h"
#include "dev_auth_module_manager.h"
#include "device_auth_defines.h"
#include "group_auth_manager.h"
#include "group_manager.h"
#include "hc_init_protection.h"
#include "hc_log.h"
#include "hc_task_thread.h"
#include "json_utils.h"
#include "securec.h"
#include "session_manager.h"
#define STACK_SIZE 4096
#include "task_manager.h"
typedef struct {
HcTaskBase base;
@@ -41,7 +39,6 @@ typedef struct {
static GroupAuthManager *g_groupAuthManager = NULL;
static DeviceGroupManager *g_groupManagerInstance = NULL;
static HcTaskThread *g_taskThread = NULL;
static int32_t BindCallbackToTask(GroupManagerTask *task, const CJson *jsonParams)
{
@@ -68,42 +65,6 @@ static int32_t BindCallbackToTask(GroupManagerTask *task, const CJson *jsonParam
return HC_SUCCESS;
}
static char *GenerateRecvData(int64_t channelId, const uint8_t *data, uint32_t dataLen, int64_t *requestId)
{
char *dataStr = (char *)HcMalloc(dataLen + 1, 0);
if (dataStr == NULL) {
LOGE("Failed to allocate dataStr memory!");
return NULL;
}
if (memcpy_s(dataStr, dataLen + 1, data, dataLen) != HC_SUCCESS) {
LOGE("Failed to copy data!");
HcFree(dataStr);
return NULL;
}
CJson *receivedData = CreateJsonFromString(dataStr);
HcFree(dataStr);
if (receivedData == NULL) {
LOGE("Failed to create receivedData json object from string!");
return NULL;
}
if (GetInt64FromJson(receivedData, FIELD_REQUEST_ID, requestId) != HC_SUCCESS) {
LOGE("Failed to get requestId from receivedData!");
return NULL;
}
if (AddByteToJson(receivedData, FIELD_CHANNEL_ID, (uint8_t *)&channelId, sizeof(int64_t)) != HC_SUCCESS) {
LOGE("Failed to add channelId to recvData!");
FreeJson(receivedData);
return NULL;
}
char *receivedDataStr = PackJsonToString(receivedData);
FreeJson(receivedData);
if (receivedDataStr == NULL) {
LOGE("Failed to convert json to string!");
return NULL;
}
return receivedDataStr;
}
static void DoCreateGroup(HcTaskBase *task)
{
if (task == NULL) {
@@ -195,24 +156,6 @@ static void DoConfirmRequest(HcTaskBase *task)
OnConfirmationReceived(realTask->requestId, realTask->jsonParams);
}
static void OnChannelOpenedAction(HcTaskBase *task)
{
if (task == NULL) {
LOGE("The input task is NULL!");
return;
}
GroupManagerTask *realTask = (GroupManagerTask *)task;
LOGI("The task thread starts to execute the task that needs to be executed"
"when the soft bus channel is open! [RequestId]: %" PRId64, realTask->requestId);
CJson *jsonParams = realTask->jsonParams;
int64_t channelId = DEFAULT_CHANNEL_ID;
if (GetByteFromJson(jsonParams, FIELD_CHANNEL_ID, (uint8_t *)&channelId, sizeof(int64_t)) != HC_SUCCESS) {
LOGE("Failed to get channelId from json!");
return;
}
OnChannelOpened(realTask->requestId, channelId);
}
static void DoProcessBindData(HcTaskBase *task)
{
if (task == NULL) {
@@ -307,14 +250,6 @@ static void InitProcessBindDataTask(GroupManagerTask *task, int64_t requestId, C
task->jsonParams = jsonParams;
}
static void InitChannelOpenedTask(GroupManagerTask *task, int64_t requestId, CJson *jsonParams)
{
task->base.doAction = OnChannelOpenedAction;
task->base.destroy = DestroyGroupManagerTask;
task->requestId = requestId;
task->jsonParams = jsonParams;
}
static int32_t InitCreateGroupTask(GroupManagerTask *task, int64_t requestId, CJson *jsonParams)
{
task->base.doAction = DoCreateGroup;
@@ -367,10 +302,6 @@ static int32_t AuthDevice(int64_t authReqId, const char *authParams, const Devic
LOGE("The input auth params is null!");
return HC_ERR_INVALID_PARAMS;
}
if (g_taskThread == NULL) {
LOGE("The task thread is null!");
return HC_ERR_SERVICE_NEED_RESTART;
}
CJson *jsonParams = CreateJsonFromString(authParams);
if (jsonParams == NULL) {
LOGE("Create json from params failed!");
@@ -388,7 +319,11 @@ static int32_t AuthDevice(int64_t authReqId, const char *authParams, const Devic
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
g_taskThread->pushTask(g_taskThread, (HcTaskBase*)task);
if (PushTask((HcTaskBase*)task) != HC_SUCCESS) {
FreeJson(jsonParams);
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
LOGI("Push AuthDevice task successfully.");
return HC_SUCCESS;
}
@@ -401,10 +336,6 @@ static int32_t ProcessData(int64_t authReqId, const uint8_t *data, uint32_t data
LOGE("Invalid input for ProcessData!");
return HC_ERR_INVALID_PARAMS;
}
if (g_taskThread == NULL) {
LOGE("The task thread is null!");
return HC_ERR_SERVICE_NEED_RESTART;
}
CJson *receivedData = CreateJsonFromString((const char *)data);
if (receivedData == NULL) {
LOGE("Create Json for input data failed!");
@@ -422,7 +353,11 @@ static int32_t ProcessData(int64_t authReqId, const uint8_t *data, uint32_t data
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
g_taskThread->pushTask(g_taskThread, (HcTaskBase*)task);
if (PushTask((HcTaskBase*)task) != HC_SUCCESS) {
FreeJson(receivedData);
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
LOGI("Push ProcessData task successfully.");
return HC_SUCCESS;
}
@@ -480,11 +415,11 @@ static int32_t AddServerParamsToJson(bool isClient, int64_t requestId, const cha
static int32_t RegGroupManagerCallback(const char *appId, const DeviceAuthCallback *callback)
{
LOGI("[Start]: Service register GM callback! [AppId]: %s", appId);
if ((appId == NULL) || (callback == NULL)) {
LOGE("The input parameters contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("[Start]: Service register GM callback! [AppId]: %s", appId);
if (!IsGroupManagerSupported()) {
LOGE("Group manager is not supported!");
return HC_ERR_NOT_SUPPORT;
@@ -499,11 +434,11 @@ static int32_t RegGroupManagerCallback(const char *appId, const DeviceAuthCallba
static int32_t UnRegGroupManagerCallback(const char *appId)
{
LOGI("[Start]: Service deregister GM callback! [AppId]: %s", appId);
if (appId == NULL) {
LOGE("The input appId is NULL!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("[Start]: Service deregister GM callback! [AppId]: %s", appId);
if (!IsGroupManagerSupported()) {
LOGE("Group manager is not supported!");
return HC_ERR_NOT_SUPPORT;
@@ -518,16 +453,11 @@ static int32_t UnRegGroupManagerCallback(const char *appId)
static int32_t RequestCreateGroup(int64_t requestId, const char *appId, const char *createParams)
{
LOGI("[Start]: RequestCreateGroup! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
if ((appId == NULL) || (createParams == NULL)) {
LOGE("The input parameters contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
if (g_taskThread == NULL) {
LOGE("Uninitialized task thread!");
return HC_ERR_SERVICE_NEED_RESTART;
}
LOGI("[Start]: RequestCreateGroup! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
CJson *jsonCreateParams = CreateJsonFromString(createParams);
if (jsonCreateParams == NULL) {
LOGE("Failed to create json from string!");
@@ -550,23 +480,22 @@ static int32_t RequestCreateGroup(int64_t requestId, const char *appId, const ch
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
g_taskThread->pushTask(g_taskThread, (HcTaskBase*)task);
if (PushTask((HcTaskBase*)task) != HC_SUCCESS) {
FreeJson(jsonCreateParams);
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
LOGI("[End]: Create the creating group task successfully! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
return HC_SUCCESS;
}
static int32_t RequestDeleteGroup(int64_t requestId, const char *appId, const char *disbandParams)
{
LOGI("[Start]: RequestDeleteGroup! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
if ((appId == NULL) || (disbandParams == NULL)) {
LOGE("The input parameters contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
if (g_taskThread == NULL) {
LOGE("Uninitialized task thread!");
return HC_ERR_SERVICE_NEED_RESTART;
}
LOGI("[Start]: RequestDeleteGroup! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
CJson *jsonDisBandParams = CreateJsonFromString(disbandParams);
if (jsonDisBandParams == NULL) {
LOGE("Failed to create json from string!");
@@ -589,23 +518,22 @@ static int32_t RequestDeleteGroup(int64_t requestId, const char *appId, const ch
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
g_taskThread->pushTask(g_taskThread, (HcTaskBase *)task);
if (PushTask((HcTaskBase*)task) != HC_SUCCESS) {
FreeJson(jsonDisBandParams);
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
LOGI("[End]: Create the deleting group task successfully! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
return HC_SUCCESS;
}
static int32_t RequestAddMemberToGroup(int64_t requestId, const char *appId, const char *addParams)
{
LOGI("[Start]: RequestAddMemberToGroup! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
if ((appId == NULL) || (addParams == NULL)) {
LOGE("The input parameters contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
if (g_taskThread == NULL) {
LOGE("Uninitialized task thread!");
return HC_ERR_SERVICE_NEED_RESTART;
}
LOGI("[Start]: RequestAddMemberToGroup! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
CJson *jsonAddParams = CreateJsonFromString(addParams);
if (jsonAddParams == NULL) {
LOGE("Failed to create json from string!");
@@ -628,23 +556,22 @@ static int32_t RequestAddMemberToGroup(int64_t requestId, const char *appId, con
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
g_taskThread->pushTask(g_taskThread, (HcTaskBase*)task);
if (PushTask((HcTaskBase*)task) != HC_SUCCESS) {
FreeJson(jsonAddParams);
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
LOGI("[End]: Create the adding member task successfully! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
return HC_SUCCESS;
}
static int32_t RequestDeleteMemberFromGroup(int64_t requestId, const char *appId, const char *deleteParams)
{
LOGI("[Start]: RequestDeleteMemberFromGroup! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
if ((appId == NULL) || (deleteParams == NULL)) {
LOGE("The input parameters contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
if (g_taskThread == NULL) {
LOGE("Uninitialized task thread!");
return HC_ERR_SERVICE_NEED_RESTART;
}
LOGI("[Start]: RequestDeleteMemberFromGroup! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
CJson *jsonDeleteParams = CreateJsonFromString(deleteParams);
if (jsonDeleteParams == NULL) {
LOGE("Failed to create json from string!");
@@ -667,23 +594,22 @@ static int32_t RequestDeleteMemberFromGroup(int64_t requestId, const char *appId
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
g_taskThread->pushTask(g_taskThread, (HcTaskBase*)task);
if (PushTask((HcTaskBase*)task) != HC_SUCCESS) {
FreeJson(jsonDeleteParams);
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
LOGI("[End]: Create the deleting member task successfully! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
return HC_SUCCESS;
}
static int32_t RequestProcessBindData(int64_t requestId, const uint8_t *data, uint32_t dataLen)
{
LOGI("[Start]: RequestProcessBindData! [RequestId]: %" PRId64, requestId);
if ((data == NULL) || (dataLen > MAX_DATA_BUFFER_SIZE)) {
if ((data == NULL) || (dataLen == 0) || (dataLen > MAX_DATA_BUFFER_SIZE)) {
LOGE("The input data is invalid!");
return HC_ERR_INVALID_PARAMS;
}
if (g_taskThread == NULL) {
LOGE("The task thread is NULL!");
return HC_ERR_SERVICE_NEED_RESTART;
}
LOGI("[Start]: RequestProcessBindData! [RequestId]: %" PRId64, requestId);
CJson *dataJson = CreateJsonFromString((const char *)data);
if (dataJson == NULL) {
LOGE("Failed to create json from string!");
@@ -698,6 +624,7 @@ static int32_t RequestProcessBindData(int64_t requestId, const uint8_t *data, ui
if (tempRequestId != requestId) {
LOGE("The requestId transferred by the service is inconsistent with that in the packet! "
"[ServiceRequestId]: %" PRId64 ", [RequestId]: %" PRId64, requestId, tempRequestId);
FreeJson(dataJson);
return HC_ERR_INVALID_PARAMS;
}
GroupManagerTask *task = (GroupManagerTask *)HcMalloc(sizeof(GroupManagerTask), 0);
@@ -707,23 +634,22 @@ static int32_t RequestProcessBindData(int64_t requestId, const uint8_t *data, ui
return HC_ERR_ALLOC_MEMORY;
}
InitProcessBindDataTask(task, requestId, dataJson);
g_taskThread->pushTask(g_taskThread, (HcTaskBase*)task);
if (PushTask((HcTaskBase*)task) != HC_SUCCESS) {
FreeJson(dataJson);
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
LOGI("[End]: Create the processing data task successfully! [RequestId]: %" PRId64, requestId);
return HC_SUCCESS;
}
static int32_t ConfirmRequest(int64_t requestId, const char *appId, const char *confirmParams)
{
LOGI("[Start]: ConfirmRequest! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
if ((appId == NULL) || (confirmParams == NULL)) {
LOGE("The input parameters contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
if (g_taskThread == NULL) {
LOGE("Uninitialized task thread!");
return HC_ERR_SERVICE_NEED_RESTART;
}
LOGI("[Start]: ConfirmRequest! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
CJson *jsonConfirmParams = CreateJsonFromString(confirmParams);
if (jsonConfirmParams == NULL) {
LOGE("Failed to create json from string!");
@@ -731,6 +657,7 @@ static int32_t ConfirmRequest(int64_t requestId, const char *appId, const char *
}
if (AddStringToJson(jsonConfirmParams, FIELD_APP_ID, appId) != HC_SUCCESS) {
LOGE("Failed to add appId to json!");
FreeJson(jsonConfirmParams);
return HC_ERR_JSON_FAIL;
}
@@ -745,80 +672,16 @@ static int32_t ConfirmRequest(int64_t requestId, const char *appId, const char *
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
g_taskThread->pushTask(g_taskThread, (HcTaskBase*)task);
if (PushTask((HcTaskBase*)task) != HC_SUCCESS) {
FreeJson(jsonConfirmParams);
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
LOGI("[End]: Create the confirming request task successfully! [AppId]: %s, [RequestId]: %" PRId64,
appId, requestId);
return HC_SUCCESS;
}
static void OnChannelOpenedCallback(int64_t channelId, int64_t requestId, const char *deviceId,
uint32_t deviceIdLen, bool isServer)
{
if (isServer) {
return;
}
if ((deviceId == NULL) || (deviceIdLen > MAX_DATA_BUFFER_SIZE)) {
LOGE("The input parameters is invalid!");
return;
}
if (g_taskThread == NULL) {
LOGE("Uninitialized task thread!");
return;
}
CJson *jsonParams = CreateJson();
if (jsonParams == NULL) {
LOGE("Failed to allocate jsonParams memory!");
return;
}
if (AddByteToJson(jsonParams, FIELD_CHANNEL_ID, (uint8_t *)&channelId, sizeof(int64_t)) != HC_SUCCESS) {
LOGE("Failed to add channelId to jsonParams!");
FreeJson(jsonParams);
return;
}
GroupManagerTask *task = (GroupManagerTask *)HcMalloc(sizeof(GroupManagerTask), 0);
if (task == NULL) {
LOGE("Failed to allocate task memory!");
FreeJson(jsonParams);
return;
}
InitChannelOpenedTask(task, requestId, jsonParams);
g_taskThread->pushTask(g_taskThread, (HcTaskBase*)task);
}
static void OnChannelClosedCallback(int64_t channelId, int64_t requestId)
{
(void)channelId;
(void)requestId;
return;
}
static void OnMsgReceivedCallback(int64_t channelId, const uint8_t *data, uint32_t dataLen)
{
LOGI("Receive data from the peer end!");
if ((data == NULL) || (dataLen > MAX_DATA_BUFFER_SIZE)) {
LOGE("The input data is invalid!");
return;
}
int64_t requestId = DEFAULT_REQUEST_ID;
char *receivedDataStr = GenerateRecvData(channelId, data, dataLen, &requestId);
if (receivedDataStr == NULL) {
return;
}
if (RequestProcessBindData(DEFAULT_REQUEST_ID, (uint8_t *)receivedDataStr,
(uint32_t)(strlen(receivedDataStr) + 1)) != HC_SUCCESS) {
LOGE("Failed to process bind data from softBus!");
}
FreeJsonString(receivedDataStr);
}
static void OnServiceDiedCallback(void)
{
return;
}
static int32_t GetModuleType(const CJson *jsonParams)
{
bool isAccountBind = false;
@@ -866,10 +729,9 @@ static void DoBindPeer(HcTaskBase *task)
GroupManagerTask *realTask = (GroupManagerTask *)task;
LOGI("The task thread starts to execute the binding peer device task! [RequestId]: %" PRId64, realTask->requestId);
int32_t result;
ChannelType channelType = GetChannelType(realTask->callback);
ChannelType channelType = GetChannelType(realTask->callback, realTask->jsonParams);
do {
if ((channelType == NO_CHANNEL) ||
(!CanFindValidChannel(channelType, realTask->jsonParams, realTask->callback))) {
if (channelType == NO_CHANNEL) {
LOGE("No available channels found!");
result = HC_ERR_CHANNEL_NOT_EXIST;
break;
@@ -901,10 +763,9 @@ static void DoUnbindPeer(HcTaskBase *task)
LOGI("The task thread starts to execute the unbinding peer device task! [RequestId]: %" PRId64,
realTask->requestId);
int32_t result;
ChannelType channelType = GetChannelType(realTask->callback);
ChannelType channelType = GetChannelType(realTask->callback, realTask->jsonParams);
do {
if ((channelType == NO_CHANNEL) ||
(!CanFindValidChannel(channelType, realTask->jsonParams, realTask->callback))) {
if (channelType == NO_CHANNEL) {
LOGE("No available channels found!");
result = HC_ERR_CHANNEL_NOT_EXIST;
break;
@@ -935,10 +796,9 @@ static void DoAuthAgreeKey(HcTaskBase *task)
GroupManagerTask *realTask = (GroupManagerTask *)task;
LOGI("The task thread starts to execute the key agreement task! [RequestId]: %" PRId64, realTask->requestId);
int32_t result;
ChannelType channelType = GetChannelType(realTask->callback);
ChannelType channelType = GetChannelType(realTask->callback, realTask->jsonParams);
do {
if ((channelType == NO_CHANNEL) ||
(!CanFindValidChannel(channelType, realTask->jsonParams, realTask->callback))) {
if (channelType == NO_CHANNEL) {
LOGE("No available channels found!");
result = HC_ERR_CHANNEL_NOT_EXIST;
break;
@@ -1048,16 +908,11 @@ static int32_t AddLiteDataToReceivedData(CJson *receivedData, int64_t requestId,
static int32_t RequestProcessLiteData(int64_t requestId, const char *appId, const uint8_t *data, uint32_t dataLen)
{
LOGI("[Start]: RequestProcessLiteData! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
if ((appId == NULL) || (data == NULL) || (dataLen > MAX_DATA_BUFFER_SIZE)) {
LOGE("The input data is NULL or dataLen is beyond max size!");
return HC_ERR_INVALID_PARAMS;
}
if (g_taskThread == NULL) {
LOGE("Uninitialized task thread!");
return HC_ERR_SERVICE_NEED_RESTART;
}
LOGI("[Start]: RequestProcessLiteData! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
CJson *receivedData = CreateJsonFromString((const char *)data);
if (receivedData == NULL) {
LOGE("Failed to create received json object from string!");
@@ -1079,7 +934,11 @@ static int32_t RequestProcessLiteData(int64_t requestId, const char *appId, cons
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
g_taskThread->pushTask(g_taskThread, (HcTaskBase*)task);
if (PushTask((HcTaskBase*)task) != HC_SUCCESS) {
FreeJson(receivedData);
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
LOGI("[End]: Create the processing lite data task successfully! [AppId]: %s, [RequestId]: %" PRId64,
appId, requestId);
return HC_SUCCESS;
@@ -1087,16 +946,11 @@ static int32_t RequestProcessLiteData(int64_t requestId, const char *appId, cons
static int32_t RequestBindPeer(int64_t requestId, const char *appId, const char *bindParams)
{
LOGI("[Start]: RequestBindPeer! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
if ((appId == NULL) || (bindParams == NULL)) {
LOGE("The input parameters contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
if (g_taskThread == NULL) {
LOGE("Uninitialized task thread!");
return HC_ERR_SERVICE_NEED_RESTART;
}
LOGI("[Start]: RequestBindPeer! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
CJson *jsonBindParams = CreateJsonFromString(bindParams);
if (jsonBindParams == NULL) {
LOGE("Failed to create json from string!");
@@ -1119,7 +973,11 @@ static int32_t RequestBindPeer(int64_t requestId, const char *appId, const char
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
g_taskThread->pushTask(g_taskThread, (HcTaskBase*)task);
if (PushTask((HcTaskBase*)task) != HC_SUCCESS) {
FreeJson(jsonBindParams);
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
LOGI("[End]: Create the binding peer device task successfully! [AppId]: %s, [RequestId]: %" PRId64,
appId, requestId);
return HC_SUCCESS;
@@ -1127,16 +985,11 @@ static int32_t RequestBindPeer(int64_t requestId, const char *appId, const char
static int32_t RequestUnbindPeer(int64_t requestId, const char *appId, const char *unBindParams)
{
LOGI("[Start]: RequestUnbindPeer, [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
if ((appId == NULL) || (unBindParams == NULL)) {
LOGE("The input parameters contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
if (g_taskThread == NULL) {
LOGE("Uninitialized task thread!");
return HC_ERR_SERVICE_NEED_RESTART;
}
LOGI("[Start]: RequestUnbindPeer, [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
CJson *jsonUnbindParams = CreateJsonFromString(unBindParams);
if (jsonUnbindParams == NULL) {
LOGE("Failed to create json from string!");
@@ -1159,7 +1012,11 @@ static int32_t RequestUnbindPeer(int64_t requestId, const char *appId, const cha
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
g_taskThread->pushTask(g_taskThread, (HcTaskBase*)task);
if (PushTask((HcTaskBase*)task) != HC_SUCCESS) {
FreeJson(jsonUnbindParams);
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
LOGI("[End]: Create the unbinding peer device task successfully! [AppId]: %s, [RequestId]: %" PRId64,
appId, requestId);
return HC_SUCCESS;
@@ -1167,16 +1024,11 @@ static int32_t RequestUnbindPeer(int64_t requestId, const char *appId, const cha
static int32_t RequestAuthKeyAgree(int64_t requestId, const char *appId, const char *agreeParams)
{
LOGI("[Start]: RequestAuthKeyAgree! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
if ((appId == NULL) || (agreeParams == NULL)) {
LOGE("The input parameters contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
if (g_taskThread == NULL) {
LOGE("Uninitialized task thread!");
return HC_ERR_SERVICE_NEED_RESTART;
}
LOGI("[Start]: RequestAuthKeyAgree! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
CJson *jsonAgreeParams = CreateJsonFromString(agreeParams);
if (jsonAgreeParams == NULL) {
LOGE("Failed to create json from string!");
@@ -1199,23 +1051,22 @@ static int32_t RequestAuthKeyAgree(int64_t requestId, const char *appId, const c
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
g_taskThread->pushTask(g_taskThread, (HcTaskBase*)task);
if (PushTask((HcTaskBase*)task) != HC_SUCCESS) {
FreeJson(jsonAgreeParams);
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
LOGI("[End]: Create the key agreement task successfully! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
return HC_SUCCESS;
}
static int32_t RequestProcessKeyAgreeData(int64_t requestId, const char *appId, const uint8_t *data, uint32_t dataLen)
{
LOGI("[Start]: RequestProcessKeyAgreeData! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
if ((appId == NULL) || (data == NULL) || (dataLen > MAX_DATA_BUFFER_SIZE)) {
LOGE("The input data is NULL or dataLen is beyond max size!");
return HC_ERR_INVALID_PARAMS;
}
if (g_taskThread == NULL) {
LOGE("Uninitialized task thread!");
return HC_ERR_SERVICE_NEED_RESTART;
}
LOGI("[Start]: RequestProcessKeyAgreeData! [AppId]: %s, [RequestId]: %" PRId64, appId, requestId);
CJson *receivedData = CreateJsonFromString((const char *)data);
if (receivedData == NULL) {
LOGE("Failed to create received json object from string!");
@@ -1237,7 +1088,11 @@ static int32_t RequestProcessKeyAgreeData(int64_t requestId, const char *appId,
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
g_taskThread->pushTask(g_taskThread, (HcTaskBase*)task);
if (PushTask((HcTaskBase*)task) != HC_SUCCESS) {
FreeJson(receivedData);
HcFree(task);
return HC_ERR_INIT_TASK_FAIL;
}
LOGI("[End]: Create the processing key agreement data task successfully! [AppId]: %s, [RequestId]: %" PRId64, appId,
requestId);
return HC_SUCCESS;
@@ -1261,11 +1116,11 @@ static int32_t GetRegisterInfo(char **returnRegisterInfo)
static int32_t AddGroupManagerIfAccessible(const char *appId, const char *groupId, const char *managerAppId)
{
LOGI("[Start]: AddGroupManager! [AppId]: %s, [ManagerAppId]: %s", appId, managerAppId);
if ((appId == NULL) || (groupId == NULL) || (managerAppId == NULL)) {
LOGE("The input parameters contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("[Start]: AddGroupManager! [AppId]: %s, [ManagerAppId]: %s", appId, managerAppId);
if (!IsGroupManagerSupported()) {
LOGE("Group manager is not supported!");
return HC_ERR_NOT_SUPPORT;
@@ -1280,11 +1135,11 @@ static int32_t AddGroupManagerIfAccessible(const char *appId, const char *groupI
static int32_t AddGroupFriendIfAccessible(const char *appId, const char *groupId, const char *friendAppId)
{
LOGI("[Start]: AddGroupFriend! [AppId]: %s, [FriendAppId]: %s", appId, friendAppId);
if ((appId == NULL) || (groupId == NULL) || (friendAppId == NULL)) {
LOGE("The input parameters contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("[Start]: AddGroupFriend! [AppId]: %s, [FriendAppId]: %s", appId, friendAppId);
if (!IsGroupManagerSupported()) {
LOGE("Group manager is not supported!");
return HC_ERR_NOT_SUPPORT;
@@ -1299,11 +1154,11 @@ static int32_t AddGroupFriendIfAccessible(const char *appId, const char *groupId
static int32_t DeleteGroupManagerIfAccessible(const char *appId, const char *groupId, const char *managerAppId)
{
LOGI("[Start]: DeleteGroupManager! [AppId]: %s, [ManagerAppId]: %s", appId, managerAppId);
if ((appId == NULL) || (groupId == NULL) || (managerAppId == NULL)) {
LOGE("The input parameters contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("[Start]: DeleteGroupManager! [AppId]: %s, [ManagerAppId]: %s", appId, managerAppId);
if (!IsGroupManagerSupported()) {
LOGE("Group manager is not supported!");
return HC_ERR_NOT_SUPPORT;
@@ -1318,11 +1173,11 @@ static int32_t DeleteGroupManagerIfAccessible(const char *appId, const char *gro
static int32_t DeleteGroupFriendIfAccessible(const char *appId, const char *groupId, const char *friendAppId)
{
LOGI("[Start]: DeleteGroupFriend! [AppId]: %s, [FriendAppId]: %s", appId, friendAppId);
if ((appId == NULL) || (groupId == NULL) || (friendAppId == NULL)) {
LOGE("The input parameters contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("[Start]: DeleteGroupFriend! [AppId]: %s, [FriendAppId]: %s", appId, friendAppId);
if (!IsGroupManagerSupported()) {
LOGE("Group manager is not supported!");
return HC_ERR_NOT_SUPPORT;
@@ -1338,11 +1193,11 @@ static int32_t DeleteGroupFriendIfAccessible(const char *appId, const char *grou
static int32_t GetGroupManagersIfAccessible(const char *appId, const char *groupId, char **returnManagers,
uint32_t *returnSize)
{
LOGI("[Start]: GetGroupManagers! [AppId]: %s", appId);
if ((appId == NULL) || (groupId == NULL) || (returnManagers == NULL) || (returnSize == NULL)) {
LOGE("The input parameters contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("[Start]: GetGroupManagers! [AppId]: %s", appId);
if (!IsGroupManagerSupported()) {
LOGE("Group manager is not supported!");
return HC_ERR_NOT_SUPPORT;
@@ -1358,11 +1213,11 @@ static int32_t GetGroupManagersIfAccessible(const char *appId, const char *group
static int32_t GetGroupFriendsIfAccessible(const char *appId, const char *groupId, char **returnFriends,
uint32_t *returnSize)
{
LOGI("[Start]: GetGroupFriends! [AppId]: %s", appId);
if ((appId == NULL) || (groupId == NULL) || (returnFriends == NULL) || (returnSize == NULL)) {
LOGE("The input parameters contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("[Start]: GetGroupFriends! [AppId]: %s", appId);
if (!IsGroupManagerSupported()) {
LOGE("Group manager is not supported!");
return HC_ERR_NOT_SUPPORT;
@@ -1377,11 +1232,11 @@ static int32_t GetGroupFriendsIfAccessible(const char *appId, const char *groupI
static int32_t RegListener(const char *appId, const DataChangeListener *listener)
{
LOGI("[Start]: Service register listener! [AppId]: %s", appId);
if ((appId == NULL) || (listener == NULL)) {
LOGE("The input parameter contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("[Start]: Service register listener! [AppId]: %s", appId);
if (!IsGroupManagerSupported()) {
LOGE("Group manager is not supported!");
return HC_ERR_NOT_SUPPORT;
@@ -1396,11 +1251,11 @@ static int32_t RegListener(const char *appId, const DataChangeListener *listener
static int32_t UnRegListener(const char *appId)
{
LOGI("[Start]: Service deregister listener! [AppId]: %s", appId);
if (appId == NULL) {
LOGE("The input appId is NULL!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("[Start]: Service deregister listener! [AppId]: %s", appId);
if (!IsGroupManagerSupported()) {
LOGE("Group manager is not supported!");
return HC_ERR_NOT_SUPPORT;
@@ -1415,11 +1270,11 @@ static int32_t UnRegListener(const char *appId)
static int32_t GetAccessibleGroupInfoById(const char *appId, const char *groupId, char **returnGroupInfo)
{
LOGI("[Start]: GetAccessibleGroupInfoById! [AppId]: %s, [GroupId]: %s", appId, groupId);
if ((appId == NULL) || (groupId == NULL) || (returnGroupInfo == NULL)) {
LOGE("The input parameter contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("[Start]: GetAccessibleGroupInfoById! [AppId]: %s, [GroupId]: %s", appId, groupId);
if (!IsGroupManagerSupported()) {
LOGE("Group manager is not supported!");
return HC_ERR_NOT_SUPPORT;
@@ -1435,11 +1290,11 @@ static int32_t GetAccessibleGroupInfoById(const char *appId, const char *groupId
static int32_t GetAccessibleGroupInfo(const char *appId, const char *queryParams, char **returnGroupVec,
uint32_t *groupNum)
{
LOGI("[Start]: GetAccessibleGroupInfo! [AppId]: %s, [QueryParams]: %s", appId, queryParams);
if ((appId == NULL) || (queryParams == NULL) || (returnGroupVec == NULL) || (groupNum == NULL)) {
LOGE("The input parameter contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("[Start]: GetAccessibleGroupInfo! [AppId]: %s, [QueryParams]: %s", appId, queryParams);
if (!IsGroupManagerSupported()) {
LOGE("Group manager is not supported!");
return HC_ERR_NOT_SUPPORT;
@@ -1454,11 +1309,11 @@ static int32_t GetAccessibleGroupInfo(const char *appId, const char *queryParams
static int32_t GetAccessibleJoinedGroups(const char *appId, int groupType, char **returnGroupVec, uint32_t *groupNum)
{
LOGI("[Start]: GetAccessibleJoinedGroups! [AppId]: %s, [GroupType]: %d", appId, groupType);
if ((appId == NULL) || (returnGroupVec == NULL) || (groupNum == NULL)) {
LOGE("The input parameter contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("[Start]: GetAccessibleJoinedGroups! [AppId]: %s, [GroupType]: %d", appId, groupType);
if (!IsGroupManagerSupported()) {
LOGE("Group manager is not supported!");
return HC_ERR_NOT_SUPPORT;
@@ -1474,11 +1329,11 @@ static int32_t GetAccessibleJoinedGroups(const char *appId, int groupType, char
static int32_t GetAccessibleRelatedGroups(const char *appId, const char *peerDeviceId, char **returnGroupVec,
uint32_t *groupNum)
{
LOGI("[Start]: GetAccessibleRelatedGroups! [AppId]: %s", appId);
if ((appId == NULL) || (peerDeviceId == NULL) || (returnGroupVec == NULL) || (groupNum == NULL)) {
LOGE("The input parameter contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("[Start]: GetAccessibleRelatedGroups! [AppId]: %s", appId);
if (!IsGroupManagerSupported()) {
LOGE("Group manager is not supported!");
return HC_ERR_NOT_SUPPORT;
@@ -1494,11 +1349,11 @@ static int32_t GetAccessibleRelatedGroups(const char *appId, const char *peerDev
static int32_t GetAccessibleDeviceInfoById(const char *appId, const char *deviceId, const char *groupId,
char **returnDeviceInfo)
{
LOGI("[Start]: GetAccessibleDeviceInfoById! [AppId]: %s, [GroupId]: %s", appId, groupId);
if ((appId == NULL) || (deviceId == NULL) || (groupId == NULL) || (returnDeviceInfo == NULL)) {
LOGE("The input parameter contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("[Start]: GetAccessibleDeviceInfoById! [AppId]: %s, [GroupId]: %s", appId, groupId);
if (!IsGroupManagerSupported()) {
LOGE("Group manager is not supported!");
return HC_ERR_NOT_SUPPORT;
@@ -1514,11 +1369,11 @@ static int32_t GetAccessibleDeviceInfoById(const char *appId, const char *device
static int32_t GetAccessibleTrustedDevices(const char *appId, const char *groupId, char **returnDevInfoVec,
uint32_t *deviceNum)
{
LOGI("[Start]: GetAccessibleTrustedDevices! [AppId]: %s, [GroupId]: %s", appId, groupId);
if ((appId == NULL) || (groupId == NULL) || (returnDevInfoVec == NULL) || (deviceNum == NULL)) {
LOGE("The input parameter contains NULL value!");
return HC_ERR_INVALID_PARAMS;
}
LOGI("[Start]: GetAccessibleTrustedDevices! [AppId]: %s, [GroupId]: %s", appId, groupId);
if (!IsGroupManagerSupported()) {
LOGE("Group manager is not supported!");
return HC_ERR_NOT_SUPPORT;
@@ -1533,11 +1388,11 @@ static int32_t GetAccessibleTrustedDevices(const char *appId, const char *groupI
static bool IsDeviceInAccessibleGroup(const char *appId, const char *groupId, const char *deviceId)
{
LOGI("[Start]: IsDeviceInAccessibleGroup! [AppId]: %s, [GroupId]: %s", appId, groupId);
if ((appId == NULL) || (groupId == NULL) || (deviceId == NULL)) {
LOGE("The input parameter contains NULL value!");
return false;
}
LOGI("[Start]: IsDeviceInAccessibleGroup! [AppId]: %s, [GroupId]: %s", appId, groupId);
if (!IsGroupManagerSupported()) {
LOGE("Group manager is not supported!");
return false;
@@ -1552,11 +1407,11 @@ static bool IsDeviceInAccessibleGroup(const char *appId, const char *groupId, co
static void DestroyInfo(char **returnInfo)
{
LOGI("[Start]: DestroyInfo!");
if (returnInfo == NULL) {
LOGI("The input returnInfo is NULL!");
return;
}
LOGI("[Start]: DestroyInfo!");
if (!IsGroupManagerSupported()) {
LOGE("Group manager is not supported!");
return;
@@ -1605,33 +1460,6 @@ static int32_t InitAlgorithm()
return res;
}
static int InitAndStartThread()
{
if (g_taskThread != NULL) {
LOGD("Task thread is not null");
}
g_taskThread = HcMalloc(sizeof(HcTaskThread), 0);
if (g_taskThread == NULL) {
return HC_ERR_ALLOC_MEMORY;
}
int32_t res = InitHcTaskThread(g_taskThread, STACK_SIZE, "HichainThread");
if (res != HC_SUCCESS) {
LOGE("Init task thread failed, res:%d", res);
HcFree(g_taskThread);
g_taskThread = NULL;
return HC_ERROR;
}
res = g_taskThread->startThread(g_taskThread);
if (res != HC_SUCCESS) {
DestroyHcTaskThread(g_taskThread);
HcFree(g_taskThread);
g_taskThread = NULL;
LOGE("Start thread failed, res:%d", res);
return HC_ERROR;
}
return res;
}
static void DestroyGmAndGa()
{
if (g_groupAuthManager != NULL) {
@@ -1644,21 +1472,11 @@ static void DestroyGmAndGa()
}
}
static void StopAndDestroyThread()
{
if (g_taskThread != NULL) {
g_taskThread->stopAndClear(g_taskThread);
DestroyHcTaskThread(g_taskThread);
HcFree(g_taskThread);
g_taskThread = NULL;
}
}
DEVICE_AUTH_API_PUBLIC int InitDeviceAuthService()
{
LOGI("[Service]: Start to init device auth service!");
if (CheckInit() == FINISH_INIT) {
LOGI("[End]: [Service]: Init device auth service successfully!");
LOGI("[End]: [Service]: Device auth service is running!");
return HC_SUCCESS;
}
int32_t res = InitAlgorithm();
@@ -1680,14 +1498,8 @@ DEVICE_AUTH_API_PUBLIC int InitDeviceAuthService()
if (res != HC_SUCCESS) {
goto free_module;
}
res = InitChannelManager(OnChannelOpenedCallback,
OnChannelClosedCallback, OnMsgReceivedCallback, OnServiceDiedCallback);
if (res != HC_SUCCESS) {
LOGE("[End]: [Service]: Failed to init channel manage module!");
goto free_group_manager;
}
InitSessionManager();
res = InitAndStartThread();
res = InitTaskManager();
if (res != HC_SUCCESS) {
LOGE("[End]: [Service]: Failed to init worker thread!");
goto free_all;
@@ -1696,9 +1508,7 @@ DEVICE_AUTH_API_PUBLIC int InitDeviceAuthService()
LOGI("[End]: [Service]: Init device auth service successfully!");
return res;
free_all:
DestroyChannelManager();
DestroySessionManager();
free_group_manager:
DestroyGroupManager();
free_module:
DestroyModules();
@@ -1716,12 +1526,12 @@ DEVICE_AUTH_API_PUBLIC void DestroyDeviceAuthService()
LOGI("[End]: [Service]: The service has not been initialized, so it does not need to be destroyed!");
return;
}
DestroyTaskManager();
DestroyChannelManager();
DestroySessionManager();
DestroyGroupManager();
DestroyModules();
DestroyGmAndGa();
StopAndDestroyThread();
SetDeInitStatus();
LOGI("[End]: [Service]: Destroy device auth service successfully!");
}
@@ -1748,7 +1558,7 @@ DEVICE_AUTH_API_PUBLIC const DeviceGroupManager *GetGmInstance()
g_groupManagerInstance->processKeyAgreeData = RequestProcessKeyAgreeData;
g_groupManagerInstance->processCredential = ProcessCredential;
g_groupManagerInstance->getRegisterInfo = GetRegisterInfo;
g_groupManagerInstance->getLocalConnectInfo = GetLocalConnectInfo;
g_groupManagerInstance->getLocalConnectInfo = NULL;
g_groupManagerInstance->addGroupManager = AddGroupManagerIfAccessible;
g_groupManagerInstance->deleteGroupManager = DeleteGroupManagerIfAccessible;
g_groupManagerInstance->getGroupManagers = GetGroupManagersIfAccessible;
+3 -1
View File
@@ -22,6 +22,7 @@ inc_path = [
"${services_path}/common/inc/channel_manager",
"${services_path}/common/inc/channel_manager/soft_bus_channel",
"${services_path}/common/inc/data_base",
"${services_path}/common/inc/task_manager",
"${services_path}/group_auth/inc",
"${services_path}/group_auth/inc/account_unrelated_group_auth",
"${services_path}/group_auth/inc/account_related_group_auth",
@@ -56,8 +57,9 @@ deviceauth_files = [
"${services_path}/common/src/broadcast_manager/broadcast_manager.c",
"${services_path}/common/src/callback_manager/callback_manager.c",
"${services_path}/common/src/channel_manager/channel_manager.c",
"${services_path}/common/src/channel_manager/soft_bus_channel_mock/soft_bus_channel_mock.c",
"${services_path}/common/src/channel_manager/soft_bus_channel/soft_bus_channel.c",
"${services_path}/common/src/data_base/database_manager.c",
"${services_path}/common/src/task_manager/task_manager.c",
"${services_path}/group_auth/src/group_auth_manager/group_auth_manager.c",
"${services_path}/group_auth/src/group_auth_manager/account_unrelated_group_auth/account_unrelated_group_auth.c",
@@ -21,7 +21,6 @@
#include "hc_task_thread.h"
#include "json_utils.h"
#define MAX_DATA_BUFFER_SIZE 4096
#define MAX_UDID_LEN 64
typedef struct {
@@ -380,7 +380,7 @@ static CJson *GenerateGroupErrorMsg(int32_t errorCode, int64_t requestId)
static void InformPeerProcessError(int64_t requestId, const CJson *jsonParams, const DeviceAuthCallback *callback,
int32_t errorCode)
{
ChannelType channelType = GetChannelType(callback);
ChannelType channelType = GetChannelType(callback, jsonParams);
int64_t channelId = DEFAULT_CHANNEL_ID;
if ((channelType == NO_CHANNEL) ||
((channelType == SOFT_BUS) &&
@@ -398,7 +398,7 @@ static void InformPeerProcessError(int64_t requestId, const CJson *jsonParams, c
LOGE("An error occurred when converting json to string!");
return;
}
(void)SendMsg(channelType, requestId, channelId, callback, errorDataStr);
(void)HcSendMsg(channelType, requestId, channelId, callback, errorDataStr);
FreeJsonString(errorDataStr);
}
@@ -535,8 +535,8 @@ static int32_t AddMemberToGroup(int64_t requestId, CJson *jsonParams, const Devi
if (result != HC_SUCCESS) {
break;
}
ChannelType channelType = GetChannelType(callback);
if ((channelType == NO_CHANNEL) || (!CanFindValidChannel(channelType, jsonParams, callback))) {
ChannelType channelType = GetChannelType(callback, jsonParams);
if (channelType == NO_CHANNEL) {
LOGE("No available channels found!");
result = HC_ERR_CHANNEL_NOT_EXIST;
break;
@@ -579,8 +579,8 @@ static int32_t DeleteMemberFromGroupInner(int64_t requestId, CJson *jsonParams,
LOGI("The service requires that the device be forcibly unbound locally instead of being unbound online!");
return HandleLocalUnbind(requestId, jsonParams, callback);
}
ChannelType channelType = GetChannelType(callback);
if ((channelType == NO_CHANNEL) || (!CanFindValidChannel(channelType, jsonParams, callback))) {
ChannelType channelType = GetChannelType(callback, jsonParams);
if (channelType == NO_CHANNEL) {
LOGI("No available channels found!");
if (isForceDelete) {
LOGI("The peer device is forcibly unbound because no available channel is found!");
@@ -96,7 +96,7 @@ int32_t GetHashResult(const uint8_t *info, uint32_t infoLen, char *hash, uint32_
if (result == HC_SUCCESS) {
if (ByteToHexString(infoHash.val, infoHash.length, hash, hashLen) != HC_SUCCESS) {
LOGE("Failed to convert bytes to string!");
result = HC_HEX_CONVERT_FAILED;
result = HC_ERR_CONVERT_FAILED;
}
}
HcFree(infoHash.val);
@@ -17,6 +17,7 @@
#include "account_related_group_manager.h"
#include "account_unrelated_group_manager.h"
#include "broadcast_manager.h"
#include "channel_manager.h"
#include "database_manager.h"
#include "hc_log.h"
@@ -375,6 +376,11 @@ static int32_t RegGroupManagerCallback(const char *appId, const DeviceAuthCallba
LOGE("The input appId or callback is NULL!");
return HC_ERR_INVALID_PARAMS;
}
int32_t res = InitChannelManager();
if (res != HC_SUCCESS) {
LOGE("[End]: [Service]: Failed to init channel manage module!");
return res;
}
if (UpdateCallbackIfExist(appId, callback) == HC_SUCCESS) {
LOGI("[End]: The callback associated with the appId already exists, so we update the callback!");
return HC_SUCCESS;
+3 -2
View File
@@ -23,8 +23,9 @@
int32_t GenerateKeyAlias(const Uint8Buff *pkgName, const Uint8Buff *serviceType, const KeyAliasType keyType,
const Uint8Buff *authId, Uint8Buff *outKeyAlias);
int32_t GetAndCheckAuthIdPeer(const CJson *in, const Uint8Buff *authIdPeer);
int32_t GetAuthIdPeer(const CJson *in, Uint8Buff *authIdPeer);
int32_t GetIdPeerForParams(const CJson *in, const char *peerIdKey, const Uint8Buff *authIdSelf, Uint8Buff *authIdPeer);
int32_t GetAndCheckAuthIdPeer(const CJson *in, const Uint8Buff *authIdSelf, const Uint8Buff *authIdPeer);
int32_t GetAuthIdPeerFromPayload(const CJson *in, const Uint8Buff *authIdSelf, Uint8Buff *authIdPeer);
int32_t GetAndCheckKeyLenOnServer(const CJson *in, uint32_t *returnKeyLen);
void SendErrMsgToSelf(const CJson *in, CJson *out, int errCode);
@@ -29,9 +29,9 @@ void DestroyModules();
int32_t CreateTask(int *taskId, const CJson *in, CJson *out, int moduleType);
int32_t ProcessTask(int taskId, const CJson *in, CJson *out, int *status, int moduleType);
void DestroyTask(int taskId, int moduleType);
int32_t CheckMsgRepeatability(const CJson *in, int moduleType);
// for DAS
int32_t CheckMsgRepeatability(const CJson *in, int moduleType);
int32_t RegisterLocalIdentity(const char *pkgName, const char *serviceType, Uint8Buff *authId, int userType,
int moduleType);
int32_t UnregisterLocalIdentity(const char *pkgName, const char *serviceType, Uint8Buff *authId, int userType,
+46 -28
View File
@@ -332,7 +332,36 @@ err:
return res;
}
int32_t GetAndCheckAuthIdPeer(const CJson *in, const Uint8Buff *authIdPeer)
int32_t GetIdPeerForParams(const CJson *in, const char *peerIdKey, const Uint8Buff *authIdSelf, Uint8Buff *authIdPeer)
{
const char *authIdStr = GetStringFromJson(in, peerIdKey);
if (authIdStr == NULL) {
LOGE("Get peer id from json failed.");
return HC_ERR_JSON_GET;
}
uint32_t authIdLen = HcStrlen(authIdStr) / BYTE_TO_HEX_OPER_LENGTH;
if (authIdLen == 0 || authIdLen > MAX_AUTH_ID_LEN) {
LOGE("Invalid authIdPeerLen.");
return HC_ERR_INVALID_LEN;
}
int32_t res = InitSingleParam(authIdPeer, authIdLen);
if (res != HC_SUCCESS) {
LOGE("InitSingleParam for peer authId failed, res: %d.", res);
return res;
}
if (HexStringToByte(authIdStr, authIdPeer->val, authIdPeer->length) != HC_SUCCESS) {
LOGE("HexStringToByte for authIdPeer failed.");
return HC_ERR_CONVERT_FAILED;
}
if ((authIdSelf->length == authIdPeer->length) &&
memcmp(authIdSelf->val, authIdPeer->val, authIdSelf->length) == 0) {
LOGE("Peer id can not be equal to self id.");
return HC_ERR_INVALID_PARAMS;
}
return HC_SUCCESS;
}
int32_t GetAndCheckAuthIdPeer(const CJson *in, const Uint8Buff *authIdSelf, const Uint8Buff *authIdPeer)
{
const CJson *payload = GetObjFromJson(in, FIELD_PAYLOAD);
if (payload == NULL) {
@@ -354,48 +383,37 @@ int32_t GetAndCheckAuthIdPeer(const CJson *in, const Uint8Buff *authIdPeer)
LOGE("Malloc for authIdPeerTmp failed.");
return HC_ERR_ALLOC_MEMORY;
}
int32_t res = HexStringToByte(authIdStr, authIdPeerTmp, authIdPeerLen);
if (res != HC_SUCCESS) {
LOGE("Convert peer authId from hex string to byte failed, res: %d.", res);
goto err;
if (HexStringToByte(authIdStr, authIdPeerTmp, authIdPeerLen) != HC_SUCCESS) {
LOGE("Convert peer authId from hex string to byte failed, res: %d.", HC_ERR_CONVERT_FAILED);
HcFree(authIdPeerTmp);
return HC_ERR_CONVERT_FAILED;
}
if ((authIdSelf->length == authIdPeer->length) &&
memcmp(authIdSelf->val, authIdPeer->val, authIdSelf->length) == 0) {
LOGE("Peer id can not be equal to self id.");
HcFree(authIdPeerTmp);
return HC_ERR_INVALID_PARAMS;
}
if (memcmp(authIdPeer->val, authIdPeerTmp, authIdPeer->length) != 0) {
LOGE("Peer authId does not match.");
res = HC_ERR_INVALID_PARAMS;
goto err;
HcFree(authIdPeerTmp);
return HC_ERR_INVALID_PARAMS;
}
err:
HcFree(authIdPeerTmp);
return res;
return HC_SUCCESS;
}
int32_t GetAuthIdPeer(const CJson *in, Uint8Buff *authIdPeer)
int32_t GetAuthIdPeerFromPayload(const CJson *in, const Uint8Buff *authIdSelf, Uint8Buff *authIdPeer)
{
const CJson *payload = GetObjFromJson(in, FIELD_PAYLOAD);
if (payload == NULL) {
LOGE("Not have payload.");
return HC_ERR_INVALID_PARAMS;
}
const char *authIdStr = GetStringFromJson(payload, FIELD_PEER_AUTH_ID);
if (authIdStr == NULL) {
LOGE("AuthIdPeer in payload is null.");
return HC_ERR_INVALID_PARAMS;
}
uint32_t authIdLen = HcStrlen(authIdStr) / BYTE_TO_HEX_OPER_LENGTH;
if (authIdLen == 0 || authIdLen > MAX_AUTH_ID_LEN) {
LOGE("Invalid authIdPeerLen");
return HC_ERR_INVALID_PARAMS;
}
int32_t res = InitSingleParam(authIdPeer, authIdLen);
int res = GetIdPeerForParams(payload, FIELD_PEER_AUTH_ID, authIdSelf, authIdPeer);
if (res != HC_SUCCESS) {
LOGE("InitSingleParam for peer authId failed, res: %d.", res);
return res;
LOGE("GetIdPeerForParams failed, res: %d.", res);
}
res = HexStringToByte(authIdStr, authIdPeer->val, authIdPeer->length);
if (res != HC_SUCCESS) {
LOGE("HexStringToByte for authIdPeer failed.");
}
return res;
}
@@ -38,9 +38,7 @@ PriorityMap g_bindPriorityList[BIND_PRIORITY_LEN] = {
};
PriorityMap g_authPriorityList[AUTH_PRIORITY_LEN] = {
{ PSK_SPEKE | NEW_EC_SPEKE, NEW_PAKE },
{ PSK_SPEKE | NEW_DL_SPEKE, NEW_PAKE },
{ PSK_SPEKE | EC_SPEKE, PAKE },
{ PSK_SPEKE | DL_SPEKE, PAKE },
{ ISO_ALG, ISO }
};
@@ -143,7 +141,8 @@ static ProtocolType GetBindPrototolType(VersionStruct *curVersion)
static ProtocolType GetAuthPrototolType(VersionStruct *curVersion)
{
if (IsVersionEqual(curVersion, &g_defaultVersion)) {
return STS;
LOGE("Not support STS.");
return UNSUPPORTED;
} else {
for (int i = 0; i < AUTH_PRIORITY_LEN; i++) {
if ((curVersion->third & g_authPriorityList[i].alg) == g_authPriorityList[i].alg) {
@@ -137,9 +137,9 @@ err:
static int ParseServerStartMessage(IsoParams *params, const CJson *in, uint8_t *peerToken)
{
if (params->opCode == OP_BIND) {
RETURN_IF_ERR(GetAuthIdPeer(in, &(params->baseParams.authIdPeer)));
RETURN_IF_ERR(GetAuthIdPeerFromPayload(in, &(params->baseParams.authIdSelf), &(params->baseParams.authIdPeer)));
} else {
RETURN_IF_ERR(GetAndCheckAuthIdPeer(in, &(params->baseParams.authIdPeer)));
RETURN_IF_ERR(GetAndCheckAuthIdPeer(in, &(params->baseParams.authIdSelf), &(params->baseParams.authIdPeer)));
}
RETURN_IF_ERR(GetByteFromJson(in, FIELD_ISO_SALT, params->baseParams.randPeer.val,
params->baseParams.randPeer.length));
@@ -88,9 +88,11 @@ static int IsoServerStart(SymBaseCurTask *task, IsoParams *params, const CJson *
}
Uint8Buff selfTokenBuf = { selfToken, ISO_TOKEN_LEN };
if (params->opCode == OP_BIND) {
GOTO_ERR_AND_SET_RET(GetAuthIdPeer(in, &(params->baseParams.authIdPeer)), res);
GOTO_ERR_AND_SET_RET(GetAuthIdPeerFromPayload(in, &(params->baseParams.authIdSelf),
&(params->baseParams.authIdPeer)), res);
} else {
GOTO_ERR_AND_SET_RET(GetAndCheckAuthIdPeer(in, &(params->baseParams.authIdPeer)), res);
GOTO_ERR_AND_SET_RET(GetAndCheckAuthIdPeer(in, &(params->baseParams.authIdSelf),
&(params->baseParams.authIdPeer)), res);
GOTO_ERR_AND_SET_RET(GetAndCheckKeyLenOnServer(in, &(params->keyLen)), res);
}
GOTO_ERR_AND_SET_RET(GetByteFromJson(in, FIELD_ISO_SALT, params->baseParams.randPeer.val,
@@ -184,7 +184,6 @@ int GenEncResult(const IsoParams *params, int message, CJson *out, const char *a
GOTO_ERR_AND_SET_RET(AddIntToJson(sendToSelf, FIELD_OPERATION_CODE, params->opCode), res);
GOTO_ERR_AND_SET_RET(AddObjToJson(out, FIELD_SEND_TO_PEER, sendToPeer), res);
GOTO_ERR_AND_SET_RET(AddObjToJson(out, FIELD_SEND_TO_SELF, sendToSelf), res);
GOTO_ERR_AND_SET_RET(AddIntToJson(out, FIELD_CREDENTIAL_TYPE, SYMMETRIC), res);
err:
FreeJson(sendToPeer);
FreeJson(sendToSelf);
@@ -105,7 +105,7 @@ static int ParseMsgForClientConfirm(PakeParams *params, const CJson *in)
return res;
}
if (params->opCode == AUTHENTICATE || params->opCode == OP_UNBIND) {
res = GetAndCheckAuthIdPeer(in, &(params->baseParams.idPeer));
res = GetAndCheckAuthIdPeer(in, &(params->baseParams.idSelf), &(params->baseParams.idPeer));
if (res != HC_SUCCESS) {
LOGE("GetAndCheckAuthIdPeer failed, res: %d.", res);
return res;
@@ -83,7 +83,7 @@ static int PakeResponse(AsyBaseCurTask *task, PakeParams *params, const CJson *i
}
// parse differentiated data
if (params->opCode == AUTHENTICATE || params->opCode == OP_UNBIND) {
res = GetAndCheckAuthIdPeer(in, &(params->baseParams.idPeer));
res = GetAndCheckAuthIdPeer(in, &(params->baseParams.idSelf), &(params->baseParams.idPeer));
if (res != HC_SUCCESS) {
LOGE("GetAndCheckAuthIdPeer failed, res: %d.", res);
return res;
@@ -304,20 +304,10 @@ static int32_t ParseAuthInfo(PakeParams *pakeParams, const StandardBindExchangeP
GOTO_ERR_AND_SET_RET(GetByteFromJson(authInfoJson, FIELD_AUTH_PK, exchangeParams->pubKeyPeer.val,
exchangeParams->pubKeyPeer.length), res);
const char *authId = GetStringFromJson(authInfoJson, FIELD_AUTH_ID);
if (authId == NULL) {
LOGE("get authId failed");
res = HC_ERROR;
goto err;
}
res = InitSingleParam(&pakeParams->baseParams.idPeer, strlen(authId) / BYTE_TO_HEX_OPER_LENGTH);
res = GetIdPeerForParams(authInfoJson, FIELD_AUTH_ID,
&pakeParams->baseParams.idSelf, &pakeParams->baseParams.idPeer);
if (res != HC_SUCCESS) {
LOGE("InitSingleParam for idPeer failed.");
goto err;
}
res = HexStringToByte(authId, pakeParams->baseParams.idPeer.val, pakeParams->baseParams.idPeer.length);
if (res != HC_SUCCESS) {
LOGE("Convert idPeer from hex string to byte failed.");
LOGE("GetIdPeerForParams failed, res: %d.", res);
goto err;
}
err:
@@ -163,10 +163,16 @@ static int32_t ParseRmvInfo(PakeParams *pakeParams, StandardUnbindExchangeParams
{
int32_t res;
CJson *rmvInfoJson = CreateJsonFromString((char *)exchangeParams->rmvInfo.val);
if (rmvInfoJson == NULL) {
LOGE("Create rmvInfoJson failed.");
return HC_ERR_JSON_CREATE;
}
GOTO_ERR_AND_SET_RET(GetIntFromJson(rmvInfoJson, FIELD_RMV_TYPE, &(pakeParams->userTypePeer)), res);
GOTO_ERR_AND_SET_RET(GetByteFromJson(rmvInfoJson, FIELD_RMV_ID, pakeParams->baseParams.idPeer.val,
pakeParams->baseParams.idPeer.length), res);
res = GetIdPeerForParams(rmvInfoJson, FIELD_RMV_ID, &pakeParams->baseParams.idSelf, &pakeParams->baseParams.idPeer);
if (res != HC_SUCCESS) {
LOGE("GetIdPeerForParams failed, res: %d.", res);
goto err;
}
err:
FreeJson(rmvInfoJson);
return res;
+11 -7
View File
@@ -210,7 +210,7 @@ static int NegotiateAndProcessTask(Task *task, const CJson *in, CJson *out, int
return HC_ERR_UNSUPPORTED_VERSION;
}
ProtocolType protocolType = GetPrototolType(&(task->versionInfo.curVersion), task->versionInfo.opCode);
LOGI("client create protocolType:%d", protocolType);
LOGI("Client select protocolType:%d", protocolType);
SubTaskBase *subTask = NULL;
uint32_t index = 0;
@@ -227,8 +227,8 @@ static int NegotiateAndProcessTask(Task *task, const CJson *in, CJson *out, int
ptr = task->vec.getp(&(task->vec), index);
}
if (subTask == NULL) {
LOGE("Not find subTask.");
return HC_ERROR;
LOGE("Can't find subTask.");
return HC_ERR_NOT_SUPPORT;
}
subTask->curVersion = task->versionInfo.curVersion;
res = subTask->process(subTask, in, out, status);
@@ -341,13 +341,16 @@ static int CreateSingleSubTask(Task *task, const CJson *in, CJson *out)
task->versionInfo.versionStatus = VERSION_DECIDED;
ProtocolType protocolType = GetPrototolType(&(task->versionInfo.curVersion), task->versionInfo.opCode);
LOGI("server create protocolType:%d", protocolType);
LOGI("Server create protocolType:%d", protocolType);
uint32_t index;
void **ptr = NULL;
FOR_EACH_HC_VECTOR(g_protocolTypeVec, index, ptr) {
if ((ptr == NULL) || ((*ptr) == NULL)) {
continue;
}
DasProtocolType *temp = (DasProtocolType *)(*ptr);
if ((ptr != NULL) && ((*ptr) != NULL) && (temp->type == protocolType)) {
if (temp->type == protocolType) {
SubTaskBase *subTask = temp->createSubTask(in, out);
if (subTask == NULL) {
LOGE("Create subTask failed");
@@ -355,11 +358,12 @@ static int CreateSingleSubTask(Task *task, const CJson *in, CJson *out)
}
subTask->curVersion = task->versionInfo.curVersion;
task->vec.pushBackT(&(task->vec), (void *)subTask);
break;
return HC_SUCCESS;
}
}
return HC_SUCCESS;
LOGE("Can't find protocolType.");
return HC_ERR_NOT_SUPPORT;
}
Task *CreateTaskT(int *taskId, const CJson *in, CJson *out)
@@ -246,7 +246,7 @@ int32_t ProcessTask(int taskId, const CJson *in, CJson *out, int *status, int mo
if (res != HC_SUCCESS) {
LOGE("AddSingleVersionToJson failed, res:%d", res);
} else {
LOGI("Create task success.");
LOGI("Process task success.");
}
return res;
}
@@ -129,6 +129,7 @@ int IsoClientCheckAndGenToken(const IsoBaseParams *params, const Uint8Buff *peer
return res;
}
if (memcmp(peerToken->val, outHmac.val, outHmac.length) != 0) {
LOGE("Compare hmac token failed.");
return HC_ERR_PROOF_NOT_MATCH;
}
return IsoCalPeerToken(params, selfToken);
@@ -149,6 +150,7 @@ int IsoClientGenSessionKey(IsoBaseParams *params, int returnResult, const uint8_
return res;
}
if (memcmp(outHmacBuf.val, hmac, hmacLen) != 0) {
LOGE("Compare hmac result failed.");
return HC_ERR_PROOF_NOT_MATCH;
}
@@ -178,6 +180,7 @@ int IsoClientGenSessionKey(IsoBaseParams *params, int returnResult, const uint8_
res = params->loader->computeHkdf(&pskBuf, &hkdfSaltBuf, &keyInfoBuf, &params->sessionKey, false);
if (res != 0) {
LOGE("compute hkdf failed, res:%d", res);
FreeAndCleanKey(&params->sessionKey);
}
HcFree(hkdfSalt);
return res;
@@ -201,6 +204,7 @@ int IsoServerGenSessionKeyAndCalToken(IsoBaseParams *params, const Uint8Buff *to
return res;
}
if (memcmp(tokenFromPeer->val, outHmac.val, outHmac.length) != 0) {
LOGE("Compare hmac token failed.");
return HC_ERR_PROOF_NOT_MATCH;
}
@@ -231,8 +235,7 @@ int IsoServerGenSessionKeyAndCalToken(IsoBaseParams *params, const Uint8Buff *to
res = params->loader->computeHkdf(&pskBuf, &hkdfSaltBuf, &keyInfoBuf, &(params->sessionKey), false);
HcFree(hkdfSalt);
if (res != 0) {
HcFree(params->sessionKey.val);
params->sessionKey.val = NULL;
FreeAndCleanKey(&params->sessionKey);
return res;
}
@@ -240,8 +243,7 @@ int IsoServerGenSessionKeyAndCalToken(IsoBaseParams *params, const Uint8Buff *to
Uint8Buff messageBuf = { (uint8_t *)&returnCode, sizeof(int) };
res = params->loader->computeHmac(&pskBuf, &messageBuf, tokenToPeer, false);
if (res != 0) {
HcFree(params->sessionKey.val);
params->sessionKey.val = NULL;
FreeAndCleanKey(&params->sessionKey);
}
return res;
}
@@ -143,9 +143,9 @@ static int32_t PrepareClient(const CJson *jsonParams, BindSession *session)
return OpenChannel(session->channelType, jsonParams, session->requestId, &session->channelId);
}
static void InitClientChannel(const DeviceAuthCallback *callback, BindSession *session)
static void InitClientChannel(const DeviceAuthCallback *callback, const CJson *jsonParams, BindSession *session)
{
session->channelType = GetChannelType(callback);
session->channelType = GetChannelType(callback, jsonParams);
}
Session *CreateClientBindSession(CJson *jsonParams, const DeviceAuthCallback *callback)
@@ -185,7 +185,7 @@ Session *CreateClientBindSession(CJson *jsonParams, const DeviceAuthCallback *ca
return NULL;
}
InitBindSession(TYPE_CLIENT_BIND_SESSION, operationCode, requestId, callback, session);
InitClientChannel(callback, session);
InitClientChannel(callback, jsonParams, session);
/* The client bind session needs to receive a message indicating that the channel is open. */
session->onChannelOpened = OnBindChannelOpened;
@@ -1255,7 +1255,7 @@ int32_t SendBindSessionData(const BindSession *session, const CJson *sendData)
LOGE("An error occurred when converting json to string!");
return HC_ERR_JSON_FAIL;
}
int32_t result = SendMsg(session->channelType, session->requestId,
int32_t result = HcSendMsg(session->channelType, session->requestId,
session->channelId, session->base.callback, sendDataStr);
FreeJsonString(sendDataStr);
return result;
@@ -65,9 +65,9 @@ static int32_t LitePrepareClient(const CJson *jsonParams, LiteBindSession *sessi
return OpenChannel(session->channelType, jsonParams, session->requestId, &session->channelId);
}
static void InitClientChannel(const DeviceAuthCallback *callback, LiteBindSession *session)
static void InitClientChannel(const DeviceAuthCallback *callback, const CJson *jsonParams, LiteBindSession *session)
{
session->channelType = GetChannelType(callback);
session->channelType = GetChannelType(callback, jsonParams);
}
Session *CreateLiteClientBindSession(CJson *jsonParams, const DeviceAuthCallback *callback)
@@ -91,7 +91,7 @@ Session *CreateLiteClientBindSession(CJson *jsonParams, const DeviceAuthCallback
return NULL;
}
InitLiteBindSession(TYPE_CLIENT_BIND_SESSION_LITE, operationCode, requestId, session, callback);
InitClientChannel(callback, session);
InitClientChannel(callback, jsonParams, session);
/* The client bind session needs to receive a message indicating that the channel is open. */
session->onChannelOpened = OnLiteBindChannelOpened;
@@ -29,7 +29,7 @@ static int32_t SendLiteBindSessionData(const LiteBindSession *session, const CJs
LOGE("An error occurred when converting json to string!");
return HC_ERR_JSON_FAIL;
}
int32_t result = SendMsg(session->channelType, session->requestId,
int32_t result = HcSendMsg(session->channelType, session->requestId,
session->channelId, session->base.callback, sendDataStr);
FreeJsonString(sendDataStr);
return result;
@@ -342,7 +342,7 @@ void InitLiteBindSession(int bindType, int operationCode, int64_t requestId, Lit
session->base.type = bindType;
session->operationCode = operationCode;
session->requestId = requestId;
session->channelType = GetChannelType(callback);
session->channelType = NO_CHANNEL;
session->channelId = DEFAULT_CHANNEL_ID;
session->isWaiting = false;
session->params = NULL;
+7 -1
View File
@@ -23,6 +23,9 @@ ohos_unittest("deviceauth_llt") {
"./include",
"//third_party/json/include",
"//utils/native/base/include",
"//foundation/communication/dsoftbus/interfaces/kits/common",
"//foundation/communication/dsoftbus/interfaces/kits/transport",
"//foundation/communication/dsoftbus/interfaces/inner_kits/transport",
]
include_dirs += inc_path
include_dirs += hals_inc_path
@@ -60,5 +63,8 @@ ohos_unittest("deviceauth_llt") {
"//utils/native/base:utils",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"dsoftbus_standard:softbus_client",
]
}