mirror of
https://gitee.com/openharmony/security_device_security_level
synced 2024-11-23 06:41:06 +00:00
!66 hidumper输出显示内容增强。
Merge pull request !66 from Zen知仁/20220408-hidumper-enhance
This commit is contained in:
commit
e50fac9d1b
@ -198,6 +198,9 @@ bool InitSelfDeviceSecureLevel(void)
|
||||
|
||||
info->deviceType = devType;
|
||||
info->onlineStatus = ONLINE_STATUS_ONLINE;
|
||||
if (info->lastOnlineTime == 0) {
|
||||
info->lastOnlineTime = GetMillisecondSinceBoot();
|
||||
}
|
||||
|
||||
if (info->credInfo.credLevel > 0) {
|
||||
info->result = SUCCESS;
|
||||
@ -205,6 +208,8 @@ bool InitSelfDeviceSecureLevel(void)
|
||||
}
|
||||
int32_t ret = DefaultInitDslmCred(&info->credInfo);
|
||||
if (ret == SUCCESS && info->credInfo.credLevel > 0) {
|
||||
info->machine.currState = STATE_SUCCESS;
|
||||
info->result = SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "utils_hexstring.h"
|
||||
#include "utils_log.h"
|
||||
#include "utils_mem.h"
|
||||
#include "utils_mutex.h"
|
||||
#include "utils_state_machine.h"
|
||||
#include "utils_timer.h"
|
||||
|
||||
@ -325,4 +326,14 @@ uint32_t GetCurrentMachineState(const DslmDeviceInfo *info)
|
||||
return STATE_FAILED;
|
||||
}
|
||||
return info->machine.currState;
|
||||
}
|
||||
|
||||
void LockDslmStateMachine(DslmDeviceInfo *info)
|
||||
{
|
||||
LockMutex(&info->machine.mutex);
|
||||
}
|
||||
|
||||
void UnLockDslmStateMachine(DslmDeviceInfo *info)
|
||||
{
|
||||
UnlockMutex(&info->machine.mutex);
|
||||
}
|
@ -47,6 +47,9 @@ enum {
|
||||
void InitDslmStateMachine(DslmDeviceInfo *info);
|
||||
void ScheduleDslmStateMachine(DslmDeviceInfo *info, uint32_t event, const void *para);
|
||||
uint32_t GetCurrentMachineState(const DslmDeviceInfo *info);
|
||||
void LockDslmStateMachine(DslmDeviceInfo *info);
|
||||
void UnLockDslmStateMachine(DslmDeviceInfo *info);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -16,12 +16,79 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "securec.h"
|
||||
|
||||
#include "utils_datetime.h"
|
||||
#include "utils_log.h"
|
||||
|
||||
#include "dslm_device_list.h"
|
||||
#include "dslm_fsm_process.h"
|
||||
#include "dslm_hidumper.h"
|
||||
|
||||
#define SPLIT_LINE "------------------------------------------------------"
|
||||
#define END_LINE "\n"
|
||||
|
||||
#define TIME_STRING_LEN 256
|
||||
|
||||
static const char *GetTimeStringFromTimeStamp(uint64_t timeStamp)
|
||||
{
|
||||
static char timeBuff[TIME_STRING_LEN] = {0};
|
||||
DateTime dateTime = {0};
|
||||
bool success = false;
|
||||
do {
|
||||
(void)memset_s(timeBuff, TIME_STRING_LEN, 0, TIME_STRING_LEN);
|
||||
if (timeStamp == 0) {
|
||||
break;
|
||||
}
|
||||
if (!GetDateTimeByMillisecondSinceBoot(timeStamp, &dateTime)) {
|
||||
SECURITY_LOG_ERROR("GetTimeStringFromTimeStamp GetDateTimeByMillisecondSinceBoot error");
|
||||
break;
|
||||
}
|
||||
int ret = snprintf_s(timeBuff, TIME_STRING_LEN, TIME_STRING_LEN - 1, "%04d-%02d-%02d %02d:%02d:%02d.%03d",
|
||||
dateTime.year, dateTime.mon, dateTime.day, dateTime.hour, dateTime.min, dateTime.sec, dateTime.msec);
|
||||
if (ret < 0) {
|
||||
break;
|
||||
}
|
||||
success = true;
|
||||
} while (0);
|
||||
|
||||
if (!success) {
|
||||
if (snprintf_s(timeBuff, TIME_STRING_LEN, TIME_STRING_LEN - 1, "-") < 0) {
|
||||
SECURITY_LOG_ERROR("GetTimeStringFromTimeStamp snprintf_s error");
|
||||
}
|
||||
}
|
||||
return timeBuff;
|
||||
}
|
||||
|
||||
static const char *GetMachineState(const DslmDeviceInfo *info)
|
||||
{
|
||||
uint32_t state = GetCurrentMachineState(info);
|
||||
switch (state) {
|
||||
case STATE_INIT:
|
||||
return "STATE_INIT";
|
||||
case STATE_WAITING_CRED_RSP:
|
||||
return "STATE_WAITING_CRED_RSP";
|
||||
case STATE_SUCCESS:
|
||||
return "STATE_SUCCESS";
|
||||
case STATE_FAILED:
|
||||
return "STATE_FAILED";
|
||||
default:
|
||||
return "STATE_UNKOWN";
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t GetPendingNotifyNodeCnt(const DslmDeviceInfo *info)
|
||||
{
|
||||
int result = 0;
|
||||
LockDslmStateMachine((DslmDeviceInfo *)info);
|
||||
ListNode *node = NULL;
|
||||
FOREACH_LIST_NODE (node, &info->notifyList) {
|
||||
result++;
|
||||
}
|
||||
UnLockDslmStateMachine((DslmDeviceInfo *)info);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void PrintBanner(int fd)
|
||||
{
|
||||
dprintf(fd, " ___ ___ _ __ __ ___ _ _ __ __ ___ ___ ___ " END_LINE);
|
||||
@ -35,13 +102,25 @@ static void DumpOneDevice(const DslmDeviceInfo *info, int32_t fd)
|
||||
if (info == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
dprintf(fd, SPLIT_LINE END_LINE);
|
||||
dprintf(fd, "DEVICE_ID : %x" END_LINE, info->machine.machineId);
|
||||
dprintf(fd, "DEVICE_TYPE : %d" END_LINE, info->deviceType);
|
||||
dprintf(fd, END_LINE);
|
||||
|
||||
dprintf(fd, "DEVICE_ONLINE_STATUS : %s" END_LINE, info->onlineStatus ? "online" : "offline");
|
||||
dprintf(fd, "DEVICE_MACHINE_STATUS : %d" END_LINE, info->machine.currState);
|
||||
dprintf(fd, "DEVICE_ONLINE_TIME : %s" END_LINE, GetTimeStringFromTimeStamp(info->lastOnlineTime));
|
||||
dprintf(fd, "DEVICE_OFFLINE_TIME : %s" END_LINE, GetTimeStringFromTimeStamp(info->lastOfflineTime));
|
||||
dprintf(fd, "DEVICE_REQUEST_TIME : %s" END_LINE, GetTimeStringFromTimeStamp(info->lastRequestTime));
|
||||
dprintf(fd, "DEVICE_RESPONE_TIME : %s" END_LINE, GetTimeStringFromTimeStamp(info->lastResponseTime));
|
||||
dprintf(fd, END_LINE);
|
||||
|
||||
dprintf(fd, "DEVICE_PENDING_NODE : %d" END_LINE, GetPendingNotifyNodeCnt(info));
|
||||
dprintf(fd, "DEVICE_MACHINE_STATUS : %s" END_LINE, GetMachineState(info));
|
||||
dprintf(fd, "DEVICE_VERIFIED_LEVEL : %d" END_LINE, info->credInfo.credLevel);
|
||||
dprintf(fd, "DEVICE_VERIFIED_RESULT : %d" END_LINE, info->result);
|
||||
dprintf(fd, "DEVICE_VERIFIED_RESULT : %s" END_LINE, info->result == 0 ? "success" : "failed");
|
||||
dprintf(fd, END_LINE);
|
||||
|
||||
dprintf(fd, "CRED_TYPE : %d" END_LINE, info->credInfo.credType);
|
||||
dprintf(fd, "CRED_SIGNTIME : %s" END_LINE, info->credInfo.signTime);
|
||||
dprintf(fd, "CRED_MANUFACTURE : %s" END_LINE, info->credInfo.manufacture);
|
||||
|
Loading…
Reference in New Issue
Block a user