fix: map hichain error

Signed-off-by: shufewhx <wanghaoxu1@huawei.com>
This commit is contained in:
shufewhx 2024-04-03 03:25:05 +00:00
parent e08b262633
commit 623f3bcd6b
5 changed files with 57 additions and 9 deletions

View File

@ -81,6 +81,11 @@ if (expression) { \
#define AUTH_REQUEST_TIMTOUR 30000
#define SHORT_HASH_LEN 8
#define SOFTBUS_SUB_SYSTEM 203
#define SOFTBUS_AUTH_MODULE 3
#define SOFTBUS_HICHAIN_MAX (-((SOFTBUS_SUB_SYSTEM << 21) | (SOFTBUS_AUTH_MODULE << 16) | 0x0001))
#define SOFTBUS_HICHAIN_MIN (-((SOFTBUS_SUB_SYSTEM << 21) | (SOFTBUS_AUTH_MODULE << 16) | 0x10FF))
#define TO_INT32(value) ((int32_t)(((uint32_t)(value)) & INT32_MASK))
#define TO_UINT32(value) ((uint32_t)(((uint32_t)(value)) & INT32_MASK))

View File

@ -34,6 +34,20 @@
#define KEY_LENGTH 16 /* Note: WinPc's special nearby only support 128 bits key */
#define ONTRANSMIT_MAX_DATA_BUFFER_LEN 5120 /* 5 × 1024 */
#define HICHAIN_DAS_ERRCODE_MIN 0xF0000001
#define HICHAIN_DAS_ERRCODE_MAX 0xF00010FF
#define HICHAIN_COMMON_ERRCODE_MIN 0x0001
#define HICHAIN_COMMON_ERRCODE_MAX 0xFFFF
#define MASK_HIGH_4BIT 0xF000
#define MASK_LOW_8BIT 0x00FF
#define MASK_LOW_16BIT 0xFFFF
#define ERRCODE_OR_BIT 0x1000
#define ERRCODE_SHIFT_21BIT 21
#define ERRCODE_SHIFT_16BIT 16
#define ERRCODE_SHIFT_12BIT 12
#define ERRCODE_SHIFT_8BIT 8
typedef struct {
char groupId[GROUPID_BUF_LEN];
GroupType groupType;
@ -128,13 +142,36 @@ static void OnFinish(int64_t authSeq, int operationCode, const char *returnData)
(void)AuthSessionHandleAuthFinish(authSeq);
}
static void GetSoftbusHichainAuthErrorCode(int32_t hichainErrCode, int32_t *softbusErrCode)
{
if (hichainErrCode >= HICHAIN_DAS_ERRCODE_MIN && hichainErrCode <= HICHAIN_DAS_ERRCODE_MAX) {
*softbusErrCode = hichainErrCode & MASK_LOW_16BIT;
*softbusErrCode = -(((SOFTBUS_SUB_SYSTEM) << ERRCODE_SHIFT_21BIT) |
((AUTH_SUB_MODULE_CODE) << ERRCODE_SHIFT_16BIT) | (*softbusErrCode | ERRCODE_OR_BIT));
} else if (hichainErrCode >= HICHAIN_COMMON_ERRCODE_MIN && hichainErrCode <= HICHAIN_COMMON_ERRCODE_MAX) {
uint32_t high4bit = 0;
int32_t tempCode = 0;
high4bit = hichainErrCode & MASK_HIGH_4BIT;
high4bit = high4bit >> ERRCODE_SHIFT_12BIT;
tempCode = hichainErrCode & MASK_LOW_8BIT;
*softbusErrCode = -(((SOFTBUS_SUB_SYSTEM) << ERRCODE_SHIFT_21BIT) |
((AUTH_SUB_MODULE_CODE) << ERRCODE_SHIFT_16BIT) | (tempCode | (high4bit << ERRCODE_SHIFT_8BIT)));
} else {
*softbusErrCode = hichainErrCode;
AUTH_LOGI(AUTH_HICHAIN, "unknow hichain errcode=%{public}d", hichainErrCode);
}
}
static void OnError(int64_t authSeq, int operationCode, int errCode, const char *errorReturn)
{
(void)operationCode;
(void)errorReturn;
DfxRecordLnnEndHichainEnd(authSeq, errCode);
AUTH_LOGE(AUTH_HICHAIN, "hichain OnError: authSeq=%{public}" PRId64 ", errCode=%{public}d", authSeq, errCode);
(void)AuthSessionHandleAuthError(authSeq, SOFTBUS_AUTH_HICHAIN_AUTH_ERROR);
int32_t authErrCode = 0;
(void)GetSoftbusHichainAuthErrorCode(errCode, &authErrCode);
AUTH_LOGE(AUTH_HICHAIN, "hichain OnError: authSeq=%{public}" PRId64 ", errCode=%{public}d authErrCode=%{public}d",
authSeq, errCode, authErrCode);
(void)AuthSessionHandleAuthError(authSeq, authErrCode);
}
static char *OnRequest(int64_t authSeq, int operationCode, const char *reqParams)

View File

@ -339,6 +339,9 @@ static void ReportAuthResultEvt(AuthFsm *authFsm, int32_t result)
uint64_t costTime = authFsm->statisticData.endAuthTime - authFsm->statisticData.startAuthTime;
DfxRecordLnnAuthEnd(authFsm, costTime, result);
AuthFailStage stage;
if (result >= SOFTBUS_HICHAIN_MIN && result <= SOFTBUS_HICHAIN_MAX) {
stage = AUTH_VERIFY_STAGE;
}
switch (result) {
case SOFTBUS_OK:
if (SoftBusRecordAuthResult(linkType, SOFTBUS_OK, costTime, AUTH_STAGE_BUTT) != SOFTBUS_OK) {
@ -355,7 +358,6 @@ static void ReportAuthResultEvt(AuthFsm *authFsm, int32_t result)
stage = AUTH_CONNECT_STAGE;
break;
case SOFTBUS_AUTH_HICHAIN_PROCESS_FAIL:
case SOFTBUS_AUTH_HICHAIN_AUTH_ERROR:
case SOFTBUS_AUTH_TIMEOUT:
case SOFTBUS_AUTH_HICHAIN_NOT_TRUSTED:
stage = AUTH_VERIFY_STAGE;
@ -786,7 +788,7 @@ static void HandleMsgAuthError(AuthFsm *authFsm, const MessagePara *para)
int32_t result = *((int32_t *)(para->data));
AUTH_LOGE(AUTH_FSM,
"auth fsm handle hichain error, authSeq=%{public}" PRId64", reason=%{public}d", authFsm->authSeq, result);
CompleteAuthSession(authFsm, SOFTBUS_AUTH_HICHAIN_AUTH_ERROR);
CompleteAuthSession(authFsm, result);
}
static void HandleMsgRecvDevInfoEarly(AuthFsm *authFsm, const MessagePara *para)

View File

@ -19,6 +19,7 @@
#include <inttypes.h>
#include "anonymizer.h"
#include "auth_common.h"
#include "auth_deviceprofile.h"
#include "auth_interface.h"
#include "auth_request.h"
@ -1867,11 +1868,10 @@ static void OnReAuthVerifyPassed(uint32_t requestId, AuthHandle authHandle, cons
static void OnReAuthVerifyFailed(uint32_t requestId, int32_t reason)
{
LNN_LOGI(LNN_BUILDER, "verify failed. requestId=%{public}u, reason=%{public}d", requestId, reason);
if (reason != SOFTBUS_AUTH_HICHAIN_AUTH_ERROR) {
return;
if (reason >= SOFTBUS_HICHAIN_MIN && reason <= SOFTBUS_HICHAIN_MAX) {
AuthHandle authHandle = { .authId = AUTH_INVALID_ID };
PostVerifyResult(requestId, reason, authHandle, NULL);
}
AuthHandle authHandle = { .authId = AUTH_INVALID_ID };
PostVerifyResult(requestId, reason, authHandle, NULL);
}
static AuthVerifyCallback g_reAuthVerifyCallback = {

View File

@ -38,6 +38,10 @@ constexpr uint8_t MSG[] = "123456BNHFCF";
constexpr int64_t AUTH_ID = 10;
constexpr uint32_t REQUEST_ID = 10;
#define SOFTBUS_SUB_SYSTEM 203
#define SOFTBUS_AUTH_MODULE 3
#define HICHAIN_ERROR_KEY_NOEXIST (-((SOFTBUS_SUB_SYSTEM << 21) | (SOFTBUS_AUTH_MODULE << 16) | 0x0101))
namespace OHOS {
using namespace testing::ext;
@ -349,7 +353,7 @@ HWTEST_F(LNNNetBuilderTest, LNN_GET_VERIFY_CALLBACK_TEST_001, TestSize.Level0)
authVerifyCallback->onVerifyPassed(REQUEST_ID, authHandle, info);
authVerifyCallback->onVerifyPassed(REQUEST_ID, authHandle, &info1);
authVerifyCallback->onVerifyFailed(REQUEST_ID, SOFTBUS_OK);
authVerifyCallback->onVerifyFailed(REQUEST_ID, SOFTBUS_AUTH_HICHAIN_AUTH_ERROR);
authVerifyCallback->onVerifyFailed(REQUEST_ID, HICHAIN_ERROR_KEY_NOEXIST);
}
/*