diff --git a/baselib/msglib/include/messenger.h b/baselib/msglib/include/messenger.h index 0b63b8f46de9e6d3c72aff389617c0c296b48cc3..b805eb32645dbdd910107199677907af96d0dd27 100644 --- a/baselib/msglib/include/messenger.h +++ b/baselib/msglib/include/messenger.h @@ -33,11 +33,11 @@ typedef struct DeviceIdentify { typedef int32_t (*DeviceMessageReceiver)(const DeviceIdentify *devId, const uint8_t *msg, uint32_t msgLen); -typedef int32_t (*DeviceStatusReceiver)(const DeviceIdentify *devId, uint32_t status, uint32_t devType); +typedef int32_t (*DeviceStatusReceiver)(const DeviceIdentify *devId, uint32_t status, int32_t level); typedef int32_t (*MessageSendResultNotifier)(const DeviceIdentify *devId, uint64_t transNo, uint32_t result); -typedef int32_t (*DeviceProcessor)(const DeviceIdentify *devId, uint32_t devType, void *para); +typedef int32_t (*DeviceProcessor)(const DeviceIdentify *devId, int32_t level, void *para); typedef struct MessengerConfig { const char *pkgName; @@ -86,9 +86,9 @@ bool IsMessengerReady(const Messenger *messenger); void SendMsgTo(const Messenger *messenger, uint64_t transNo, const DeviceIdentify *devId, const uint8_t *msg, uint32_t msgLen); -bool GetDeviceOnlineStatus(const Messenger *messenger, const DeviceIdentify *devId, uint32_t *devType); +bool GetDeviceOnlineStatus(const Messenger *messenger, const DeviceIdentify *devId, int32_t *level); -bool GetSelfDeviceIdentify(const Messenger *messenger, DeviceIdentify *devId, uint32_t *devType); +bool GetSelfDeviceIdentify(const Messenger *messenger, DeviceIdentify *devId, int32_t *level); void ForEachDeviceProcess(const Messenger *messenger, const DeviceProcessor processor, void *para); diff --git a/baselib/msglib/src/common/messenger.c b/baselib/msglib/src/common/messenger.c index b342f419599a305fae6d414643529246fb5911df..96dabb1b85e1b73811fb1f04841d3609aed49de3 100644 --- a/baselib/msglib/src/common/messenger.c +++ b/baselib/msglib/src/common/messenger.c @@ -37,14 +37,14 @@ void SendMsgTo(const Messenger *messenger, uint64_t transNo, const DeviceIdentif SendMsgToImpl(messenger, transNo, devId, msg, msgLen); } -bool GetDeviceOnlineStatus(const Messenger *messenger, const DeviceIdentify *devId, uint32_t *devType) +bool GetDeviceOnlineStatus(const Messenger *messenger, const DeviceIdentify *devId, int32_t *level) { - return GetDeviceOnlineStatusImpl(messenger, devId, devType); + return GetDeviceOnlineStatusImpl(messenger, devId, level); } -bool GetSelfDeviceIdentify(const Messenger *messenger, DeviceIdentify *devId, uint32_t *devType) +bool GetSelfDeviceIdentify(const Messenger *messenger, DeviceIdentify *devId, int32_t *level) { - return GetSelfDeviceIdentifyImpl(messenger, devId, devType); + return GetSelfDeviceIdentifyImpl(messenger, devId, level); } void ForEachDeviceProcess(const Messenger *messenger, const DeviceProcessor processor, void *para) diff --git a/baselib/msglib/src/common/messenger_device_status_manager.h b/baselib/msglib/src/common/messenger_device_status_manager.h index 1b2508d77bbc38b95a3c737408dbcf61c551d1ae..9a410a2dbbbfc773b9969b8d4399832ab1c9ce6b 100644 --- a/baselib/msglib/src/common/messenger_device_status_manager.h +++ b/baselib/msglib/src/common/messenger_device_status_manager.h @@ -35,9 +35,9 @@ bool InitDeviceStatusManager(WorkQueue *queue, const char *pkgName, DeviceStatus bool DeInitDeviceStatusManager(void); -bool MessengerGetDeviceOnlineStatus(const DeviceIdentify *devId, uint32_t *devType); +bool MessengerGetDeviceOnlineStatus(const DeviceIdentify *devId, int32_t *level); -bool MessengerGetSelfDeviceIdentify(DeviceIdentify *devId, uint32_t *devType); +bool MessengerGetSelfDeviceIdentify(DeviceIdentify *devId, int32_t *level); void MessengerForEachDeviceProcess(const DeviceProcessor processor, void *para); diff --git a/baselib/msglib/src/common/messenger_impl.h b/baselib/msglib/src/common/messenger_impl.h index e0f404815a445ad4090db4a64359d8d7fbad1b10..2a381b0d34232c50ba497b37acd34102a40fc0fe 100644 --- a/baselib/msglib/src/common/messenger_impl.h +++ b/baselib/msglib/src/common/messenger_impl.h @@ -31,9 +31,9 @@ void SendMsgToImpl(const Messenger *messenger, uint64_t transNo, const DeviceIde bool IsMessengerReadyImpl(const Messenger *messenger); -bool GetDeviceOnlineStatusImpl(const Messenger *messenger, const DeviceIdentify *devId, uint32_t *devType); +bool GetDeviceOnlineStatusImpl(const Messenger *messenger, const DeviceIdentify *devId, int32_t *level); -bool GetSelfDeviceIdentifyImpl(const Messenger *messenger, DeviceIdentify *devId, uint32_t *devType); +bool GetSelfDeviceIdentifyImpl(const Messenger *messenger, DeviceIdentify *devId, int32_t *level); void ForEachDeviceProcessImpl(const Messenger *messenger, const DeviceProcessor processor, void *para); diff --git a/baselib/msglib/src/lite/messenger_device_session_manager.c b/baselib/msglib/src/lite/messenger_device_session_manager.c index bb6a2157256298f431336d299210805ac11f599f..becb8ec7d85c16eb73c6c64bc72e4a57255abd93 100644 --- a/baselib/msglib/src/lite/messenger_device_session_manager.c +++ b/baselib/msglib/src/lite/messenger_device_session_manager.c @@ -464,8 +464,8 @@ void MessengerSendMsgTo(uint64_t transNo, const DeviceIdentify *devId, const uin } static DeviceIdentify self = {0, {0}}; - uint32_t devType; - MessengerGetSelfDeviceIdentify(&self, &devType); + int32_t level; + MessengerGetSelfDeviceIdentify(&self, &level); if (IsSameDevice(&self, devId)) { SECURITY_LOG_DEBUG("loopback msg"); diff --git a/baselib/msglib/src/lite/messenger_device_status_manager.c b/baselib/msglib/src/lite/messenger_device_status_manager.c index 5c83ec0d39a1a6a8b56df727b6df69554719041e..b5721bccc61bf3749e8908ce34a475c2745a2c43 100644 --- a/baselib/msglib/src/lite/messenger_device_status_manager.c +++ b/baselib/msglib/src/lite/messenger_device_status_manager.c @@ -28,7 +28,7 @@ static void MessengerOnNodeOnline(NodeBasicInfo *info); static void MessengerOnNodeOffline(NodeBasicInfo *info); static void MessengerOnNodeBasicInfoChanged(NodeBasicInfoType type, NodeBasicInfo *info); -static int32_t InitDeviceOnlineProcessor(const DeviceIdentify *devId, uint32_t devType, void *para); +static int32_t InitDeviceOnlineProcessor(const DeviceIdentify *devId, int32_t level, void *para); typedef struct DeviceStatusManager { const INodeStateCb nodeStateCb; @@ -40,7 +40,7 @@ typedef struct DeviceStatusManager { typedef struct QueueStatusData { DeviceIdentify srcIdentity; uint32_t status; - uint32_t devType; + int32_t level; } QueueStatusData; static DeviceStatusManager *GetDeviceManagerInstance(void) @@ -76,11 +76,11 @@ static void ProcessDeviceStatusReceived(const uint8_t *data, uint32_t len) SECURITY_LOG_ERROR("ProcessSessionMessageReceived, messageReceiver is null"); return; } - deviceStatusReceiver(&queueData->srcIdentity, queueData->status, queueData->devType); + deviceStatusReceiver(&queueData->srcIdentity, queueData->status, queueData->level); FREE(queueData); } -static void ProcessDeviceStatusReceiver(const DeviceIdentify *devId, uint32_t status, uint32_t devType) +static void ProcessDeviceStatusReceiver(const DeviceIdentify *devId, uint32_t status, int32_t level) { DeviceStatusManager *instance = GetDeviceManagerInstance(); @@ -108,7 +108,7 @@ static void ProcessDeviceStatusReceiver(const DeviceIdentify *devId, uint32_t st FREE(data); return; } - data->devType = devType; + data->level = level; data->status = status; ret = QueueWork(queue, ProcessDeviceStatusReceived, (uint8_t *)data, sizeof(QueueStatusData)); @@ -127,6 +127,7 @@ static void MessengerOnNodeStateChange(NodeBasicInfo *info, uint32_t state) } DeviceStatusManager *instance = GetDeviceManagerInstance(); + int32_t level = 0; char udid[UDID_BUF_LEN] = {0}; if (GetNodeKeyInfo(instance->pkgName, info->networkId, NODE_KEY_UDID, (uint8_t *)udid, UDID_BUF_LEN) != 0) { SECURITY_LOG_ERROR("MessengerOnNodeStateChange process get device identity error."); @@ -139,10 +140,10 @@ static void MessengerOnNodeStateChange(NodeBasicInfo *info, uint32_t state) SECURITY_LOG_ERROR("MessengerOnNodeStateChange copy device error"); } uint32_t maskId = MaskDeviceIdentity(udid, UDID_BUF_LEN); - SECURITY_LOG_INFO("MessengerOnNodeStateChange device(%{public}x*** change to %{public}s, deviceType is %{public}d)", - maskId, (state == EVENT_NODE_STATE_ONLINE) ? "online" : "offline", info->deviceTypeId); + SECURITY_LOG_INFO("MessengerOnNodeStateChange device(%{public}x*** change to %{public}s)", maskId, + (state == EVENT_NODE_STATE_ONLINE) ? "online" : "offline"); - ProcessDeviceStatusReceiver(&identity, state, info->deviceTypeId); + ProcessDeviceStatusReceiver(&identity, state, level); } static void MessengerOnNodeOnline(NodeBasicInfo *info) @@ -161,10 +162,10 @@ static void MessengerOnNodeBasicInfoChanged(NodeBasicInfoType type, NodeBasicInf (void)info; } -static int32_t InitDeviceOnlineProcessor(const DeviceIdentify *devId, uint32_t devType, void *para) +static int32_t InitDeviceOnlineProcessor(const DeviceIdentify *devId, int32_t level, void *para) { (void)para; - ProcessDeviceStatusReceiver(devId, EVENT_NODE_STATE_ONLINE, devType); + ProcessDeviceStatusReceiver(devId, EVENT_NODE_STATE_ONLINE, level); return 0; } @@ -274,15 +275,15 @@ bool MessengerGetDeviceNodeBasicInfo(const DeviceIdentify *devId, NodeBasicInfo return find; } -bool MessengerGetDeviceOnlineStatus(const DeviceIdentify *devId, uint32_t *devType) +bool MessengerGetDeviceOnlineStatus(const DeviceIdentify *devId, int32_t *level) { if (devId == NULL) { return false; } NodeBasicInfo info = {{0}, {0}, 0}; bool result = MessengerGetDeviceNodeBasicInfo(devId, &info); - if (result == true && devType != NULL) { - *devType = info.deviceTypeId; + if (result == true && level != NULL) { + *level = -1; } return result; } @@ -306,9 +307,9 @@ bool MessengerGetNetworkIdByDeviceIdentify(const DeviceIdentify *devId, char *ne return true; } -bool MessengerGetSelfDeviceIdentify(DeviceIdentify *devId, uint32_t *devType) +bool MessengerGetSelfDeviceIdentify(DeviceIdentify *devId, int32_t *level) { - if (devId == NULL || devType == NULL) { + if (devId == NULL || level == NULL) { return false; } @@ -325,11 +326,10 @@ bool MessengerGetSelfDeviceIdentify(DeviceIdentify *devId, uint32_t *devType) if (convert == false) { return false; } - *devType = info.deviceTypeId; + *level = -1; uint32_t maskId = MaskDeviceIdentity((const char *)&devId->identity[0], UDID_BUF_LEN); - SECURITY_LOG_DEBUG("MessengerGetSelfDeviceIdentify device %{public}x***, deviceType is %{public}d", maskId, - info.deviceTypeId); + SECURITY_LOG_DEBUG("MessengerGetSelfDeviceIdentify device %{public}x***", maskId); return true; } @@ -343,6 +343,7 @@ void MessengerForEachDeviceProcess(const DeviceProcessor processor, void *para) NodeBasicInfo *infoList = NULL; int infoListLen = 0; + int32_t level = -1; int32_t ret = GetAllNodeDeviceInfo(instance->pkgName, &infoList, &infoListLen); if (ret != 0) { SECURITY_LOG_ERROR("MessengerForEachDeviceProcess GetAllNodeDeviceInfo failed = %{public}d", ret); @@ -354,7 +355,7 @@ void MessengerForEachDeviceProcess(const DeviceProcessor processor, void *para) DeviceIdentify devId = {DEVICE_ID_MAX_LEN, {0}}; bool convert = MessengerConvertNodeToIdentity(node, &devId); if (convert == true) { - processor(&devId, node->deviceTypeId, para); + processor(&devId, level, para); } } diff --git a/baselib/msglib/src/lite/messenger_impl.c b/baselib/msglib/src/lite/messenger_impl.c index 010817433a63a4e99dcc6fbb96994a26af552a74..64958678accc0e40cef4a837340ebec33a709b76 100644 --- a/baselib/msglib/src/lite/messenger_impl.c +++ b/baselib/msglib/src/lite/messenger_impl.c @@ -103,24 +103,24 @@ void SendMsgToImpl(const Messenger *messenger, uint64_t transNo, const DeviceIde MessengerSendMsgTo(transNo, devId, msg, msgLen); } -bool GetDeviceOnlineStatusImpl(const Messenger *messenger, const DeviceIdentify *devId, uint32_t *devType) +bool GetDeviceOnlineStatusImpl(const Messenger *messenger, const DeviceIdentify *devId, int32_t *level) { if (messenger == NULL || messenger->magicHead != MESSENGER_MAGIC_HEAD) { SECURITY_LOG_ERROR("invalid params"); return false; } - return MessengerGetDeviceOnlineStatus(devId, devType); + return MessengerGetDeviceOnlineStatus(devId, level); } -bool GetSelfDeviceIdentifyImpl(const Messenger *messenger, DeviceIdentify *devId, uint32_t *devType) +bool GetSelfDeviceIdentifyImpl(const Messenger *messenger, DeviceIdentify *devId, int32_t *level) { if (messenger == NULL || messenger->magicHead != MESSENGER_MAGIC_HEAD) { SECURITY_LOG_ERROR("invalid params"); return false; } - return MessengerGetSelfDeviceIdentify(devId, devType); + return MessengerGetSelfDeviceIdentify(devId, level); } void ForEachDeviceProcessImpl(const Messenger *messenger, const DeviceProcessor processor, void *para) diff --git a/baselib/msglib/src/standard/messenger_device_socket_manager.c b/baselib/msglib/src/standard/messenger_device_socket_manager.c index 4af8193dbd8852c22508f1b9a099bf79a5fcbbb9..20c61c23f9c84878f756b634e4a9e0071ae316fd 100644 --- a/baselib/msglib/src/standard/messenger_device_socket_manager.c +++ b/baselib/msglib/src/standard/messenger_device_socket_manager.c @@ -712,8 +712,8 @@ void MessengerSendMsgTo(uint64_t transNo, const DeviceIdentify *devId, const uin } static DeviceIdentify self = {0, {0}}; - uint32_t devType; - MessengerGetSelfDeviceIdentify(&self, &devType); + int32_t level; + MessengerGetSelfDeviceIdentify(&self, &level); if (IsSameDevice(&self, devId)) { SECURITY_LOG_DEBUG("loopback msg"); diff --git a/baselib/msglib/src/standard/messenger_device_status_manager.cpp b/baselib/msglib/src/standard/messenger_device_status_manager.cpp index fd48cbe78eddd8f777eef68541fb127edc07fee0..ef58ef56cf726e9cc88d24399b4da80a52c68d0f 100644 --- a/baselib/msglib/src/standard/messenger_device_status_manager.cpp +++ b/baselib/msglib/src/standard/messenger_device_status_manager.cpp @@ -28,6 +28,10 @@ #include "utils_log.h" #include "utils_mem.h" +#define PKG_NAME_LEN 128 + +static void GetDeviceSecurityLevelByNetworkId(const std::string &networkId, int32_t &level); + namespace OHOS { namespace Security { namespace DeviceSecurityLevel { @@ -35,7 +39,7 @@ using namespace OHOS::DistributedHardware; class DeviceStatusControlBlock final : public Singleton { public: - using StateReceiver = std::function; + using StateReceiver = std::function; void Reset(const std::string &pkgName, WorkQueue *queue, StateReceiver deviceStatusReceiver) { std::lock_guard lock(mutex_); @@ -83,7 +87,7 @@ public: struct QueueStatusData { DeviceIdentify srcIdentity {0, {0}}; uint32_t status {0}; - uint32_t devType {0}; + uint32_t level {0}; }; DslmDeviceState() = default; @@ -114,14 +118,18 @@ public: static void MessengerOnNodeStateChange(const DmDeviceInfo &info, State state) { DeviceIdentify identity = {DEVICE_ID_MAX_LEN, {0}}; + int32_t level = 0; if (!MessengerGetDeviceIdentifyByNetworkId(info.networkId, &identity)) { SECURITY_LOG_ERROR("MessengerOnNodeStateChange copy device error"); return; } - ProcessDeviceStatusReceiver(&identity, state, info.deviceTypeId); + if (state == EVENT_NODE_STATE_ONLINE) { + GetDeviceSecurityLevelByNetworkId(info.networkId, level); + } + ProcessDeviceStatusReceiver(&identity, state, level); } - static void ProcessDeviceStatusReceiver(const DeviceIdentify *devId, uint32_t status, uint32_t devType) + static void ProcessDeviceStatusReceiver(const DeviceIdentify *devId, uint32_t status, int32_t level) { if (devId == nullptr || devId->length == 0) { SECURITY_LOG_ERROR("ProcessDeviceStatusReceiver, invalid input"); @@ -140,12 +148,12 @@ public: return; } data->srcIdentity = *devId; - data->devType = devType; + data->level = level; data->status = status; uint32_t maskId = MaskDeviceIdentity((const char *)&devId->identity[0], DEVICE_ID_MAX_LEN); - SECURITY_LOG_INFO("OnlineStateChange device %{public}x*** change to %{public}s, devType is %{public}d", maskId, - (status == EVENT_NODE_STATE_ONLINE) ? " online " : " offline ", devType); + SECURITY_LOG_INFO("OnlineStateChange device %{public}x*** change to %{public}s, level is %{public}d", maskId, + (status == EVENT_NODE_STATE_ONLINE) ? " online " : " offline ", level); auto process = [](const uint8_t *data, uint32_t len) { if (data == nullptr || len == 0) { @@ -161,7 +169,7 @@ public: SECURITY_LOG_ERROR("ProcessDeviceStatusReceiver, invalid queue"); return; } - processor(&queueData->srcIdentity, queueData->status, queueData->devType); + processor(&queueData->srcIdentity, queueData->status, queueData->level); delete queueData; }; auto input = static_cast(static_cast(data)); @@ -234,6 +242,14 @@ static bool MessengerGetDeviceNodeBasicInfo(const DeviceIdentify &devId, DmDevic extern "C" { #endif using namespace OHOS::Security::DeviceSecurityLevel; + +static void GetDeviceSecurityLevelByNetworkId(const std::string &networkId, int32_t &level) +{ + const char pkgName[PKG_NAME_LEN + 1] = "ohos.dslm"; + int32_t ret = DeviceManager::GetInstance().GetDeviceSecurityLevel(pkgName, networkId, level); + SECURITY_LOG_INFO("GetDeviceSecurityLevelByNetworkId ret = %{public}d, level = %{public}d", ret, level); +} + bool InitDeviceStatusManager(WorkQueue *queue, const char *pkgName, DeviceStatusReceiver deviceStatusReceiver) { if (queue == nullptr || pkgName == nullptr || deviceStatusReceiver == nullptr) { @@ -273,9 +289,9 @@ bool InitDeviceStatusManager(WorkQueue *queue, const char *pkgName, DeviceStatus return false; } - auto process = [](const DeviceIdentify *devId, uint32_t devType, void *para) -> int32_t { + auto process = [](const DeviceIdentify *devId, int32_t level, void *para) -> int32_t { static_cast(para); - DslmDeviceState::ProcessDeviceStatusReceiver(devId, DslmDeviceState::State::EVENT_NODE_STATE_ONLINE, devType); + DslmDeviceState::ProcessDeviceStatusReceiver(devId, DslmDeviceState::State::EVENT_NODE_STATE_ONLINE, level); return 0; }; @@ -294,7 +310,7 @@ bool DeInitDeviceStatusManager(void) return true; } -bool MessengerGetDeviceOnlineStatus(const DeviceIdentify *devId, uint32_t *devType) +bool MessengerGetDeviceOnlineStatus(const DeviceIdentify *devId, int32_t *level) { if (devId == nullptr) { return false; @@ -302,15 +318,15 @@ bool MessengerGetDeviceOnlineStatus(const DeviceIdentify *devId, uint32_t *devTy DmDeviceInfo info; bool result = MessengerGetDeviceNodeBasicInfo(*devId, info); - if (result == true && devType != nullptr) { - *devType = info.deviceTypeId; + if (result == true && level != nullptr) { + GetDeviceSecurityLevelByNetworkId(info.networkId, *level); } return result; } -bool MessengerGetSelfDeviceIdentify(DeviceIdentify *devId, uint32_t *devType) +bool MessengerGetSelfDeviceIdentify(DeviceIdentify *devId, int32_t *level) { - if (devId == nullptr || devType == nullptr) { + if (devId == nullptr || level == NULL) { return false; } @@ -327,11 +343,11 @@ bool MessengerGetSelfDeviceIdentify(DeviceIdentify *devId, uint32_t *devType) if (convert == false) { return false; } - *devType = info.deviceTypeId; + + GetDeviceSecurityLevelByNetworkId(info.networkId, *level); uint32_t maskId = MaskDeviceIdentity((const char *)&devId->identity[0], DEVICE_ID_MAX_LEN); - SECURITY_LOG_DEBUG("MessengerGetSelfDeviceIdentify device %{public}x***, deviceType is %{public}d", maskId, - info.deviceTypeId); + SECURITY_LOG_DEBUG("MessengerGetSelfDeviceIdentify device %{public}x***, level is %{public}d", maskId, *level); return true; } @@ -353,8 +369,11 @@ void MessengerForEachDeviceProcess(const DeviceProcessor processor, void *para) for (auto const &device : deviceList) { DeviceIdentify curr = {DEVICE_ID_MAX_LEN, {0}}; bool convert = MessengerConvertNodeToIdentity(device.networkId, curr); + int32_t level = 0; + GetDeviceSecurityLevelByNetworkId(device.networkId, level); + if (convert == true) { - processor(&curr, device.deviceTypeId, para); + processor(&curr, level, para); } } } diff --git a/baselib/msglib/src/standard/messenger_impl.c b/baselib/msglib/src/standard/messenger_impl.c index 17831e3b9890c31769d83f7e7780e63c9a1f0741..3d82fbdf036b9facf51055a1f5b8a49173f8f996 100644 --- a/baselib/msglib/src/standard/messenger_impl.c +++ b/baselib/msglib/src/standard/messenger_impl.c @@ -100,24 +100,24 @@ void SendMsgToImpl(const Messenger *messenger, uint64_t transNo, const DeviceIde MessengerSendMsgTo(transNo, devId, msg, msgLen); } -bool GetDeviceOnlineStatusImpl(const Messenger *messenger, const DeviceIdentify *devId, uint32_t *devType) +bool GetDeviceOnlineStatusImpl(const Messenger *messenger, const DeviceIdentify *devId, int32_t *level) { if (messenger == NULL || messenger->magicHead != MESSENGER_MAGIC_HEAD) { SECURITY_LOG_ERROR("invalid params"); return false; } - return MessengerGetDeviceOnlineStatus(devId, devType); + return MessengerGetDeviceOnlineStatus(devId, level); } -bool GetSelfDeviceIdentifyImpl(const Messenger *messenger, DeviceIdentify *devId, uint32_t *devType) +bool GetSelfDeviceIdentifyImpl(const Messenger *messenger, DeviceIdentify *devId, int32_t *level) { if (messenger == NULL || messenger->magicHead != MESSENGER_MAGIC_HEAD) { SECURITY_LOG_ERROR("invalid params"); return false; } - return MessengerGetSelfDeviceIdentify(devId, devType); + return MessengerGetSelfDeviceIdentify(devId, level); } void ForEachDeviceProcessImpl(const Messenger *messenger, const DeviceProcessor processor, void *para) diff --git a/services/dfx/dslm_hidumper.c b/services/dfx/dslm_hidumper.c index af80bc3d5b13547b4935eae6fa4eb519cbdc12cd..96611009a8f38b21ea64b07b6b60f0115fb9970f 100644 --- a/services/dfx/dslm_hidumper.c +++ b/services/dfx/dslm_hidumper.c @@ -168,7 +168,6 @@ static void PrintBanner(int fd) static void DumpDeviceDetails(const DslmDeviceInfo *info, int32_t fd) { dprintf(fd, "DEVICE_ID : %x" END_LINE, info->machine.machineId); - dprintf(fd, "DEVICE_TYPE : %u" END_LINE, info->deviceType); dprintf(fd, END_LINE); dprintf(fd, "DEVICE_ONLINE_STATUS : %s" END_LINE, (info->onlineStatus != 0) ? "online" : "offline"); diff --git a/services/dslm/dslm_core_defines.h b/services/dslm/dslm_core_defines.h index 3117d5d709df9e1fed0b3fbce4b9270640a08c8b..48b20ab77b8a7bc55c7d2c2e97faf499e51bdac9 100644 --- a/services/dslm/dslm_core_defines.h +++ b/services/dslm/dslm_core_defines.h @@ -41,7 +41,6 @@ typedef struct DslmDeviceInfo { DeviceIdentify identity; uint32_t version; uint32_t onlineStatus; - uint32_t deviceType; uint64_t nonce; uint64_t nonceTimeStamp; uint64_t lastOnlineTime; diff --git a/services/dslm/dslm_core_process.c b/services/dslm/dslm_core_process.c index d44128c92e6f566f06800021f484fdbb761b2080..c97c9080a784f685620270fc43983697575aed5c 100644 --- a/services/dslm/dslm_core_process.c +++ b/services/dslm/dslm_core_process.c @@ -179,7 +179,7 @@ int32_t OnRequestDeviceSecLevelInfo(const DeviceIdentify *deviceId, const Reques return SUCCESS; } -int32_t OnPeerStatusReceiver(const DeviceIdentify *deviceId, uint32_t status, uint32_t devType) +int32_t OnPeerStatusReceiver(const DeviceIdentify *deviceId, uint32_t status, int32_t level) { DslmDeviceInfo *info = CreatOrGetDslmDeviceInfo(deviceId); if (info == NULL) { @@ -192,14 +192,14 @@ int32_t OnPeerStatusReceiver(const DeviceIdentify *deviceId, uint32_t status, ui uint32_t event = (status == ONLINE_STATUS_ONLINE) ? EVENT_DEVICE_ONLINE : EVENT_DEVICE_OFFLINE; - ScheduleDslmStateMachine(info, event, &devType); + ScheduleDslmStateMachine(info, event, &level); return SUCCESS; } bool InitSelfDeviceSecureLevel(void) { - uint32_t devType = 0; - const DeviceIdentify *device = GetSelfDevice(&devType); + int32_t level = 0; + const DeviceIdentify *device = GetSelfDevice(&level); if (device->length == 0) { SECURITY_LOG_ERROR("GetSelfDevice failed"); ReportHiEventInitSelfFailed("GetSelfDevice failed"); @@ -213,12 +213,13 @@ bool InitSelfDeviceSecureLevel(void) return false; } - info->deviceType = devType; info->onlineStatus = ONLINE_STATUS_ONLINE; if (info->lastOnlineTime == 0) { info->lastOnlineTime = GetMillisecondSinceBoot(); } - + if (level > 0) { + info->credInfo.credLevel = level; + } if (info->credInfo.credLevel > 0) { info->result = SUCCESS; info->machine.currState = STATE_SUCCESS; @@ -233,7 +234,7 @@ bool InitSelfDeviceSecureLevel(void) return true; } - ret = OnPeerStatusReceiver(device, ONLINE_STATUS_ONLINE, devType); + ret = OnPeerStatusReceiver(device, ONLINE_STATUS_ONLINE, level); if (ret != SUCCESS) { SECURITY_LOG_ERROR("make self online failed"); } @@ -269,21 +270,21 @@ bool DeinitDslmProcess(void) static const DeviceIdentify *RefreshDeviceOnlineStatus(const DeviceIdentify *deviceId) { - uint32_t devType = 0; + int32_t level = 0; if (deviceId == NULL) { return NULL; } if (deviceId->identity[0] == 0) { SECURITY_LOG_INFO("RefreshDeviceOnlineStatus to self"); - return GetSelfDevice(&devType); + return GetSelfDevice(&level); } - if (GetPeerDeviceOnlineStatus(deviceId, &devType)) { - (void)OnPeerStatusReceiver(deviceId, ONLINE_STATUS_ONLINE, devType); + if (GetPeerDeviceOnlineStatus(deviceId, &level)) { + (void)OnPeerStatusReceiver(deviceId, ONLINE_STATUS_ONLINE, level); } - if (IsSameDevice(deviceId, GetSelfDevice((&devType)))) { + if (IsSameDevice(deviceId, GetSelfDevice(&level))) { (void)InitSelfDeviceSecureLevel(); } diff --git a/services/dslm/dslm_fsm_process.c b/services/dslm/dslm_fsm_process.c index 943119542ab1428f7fb2d023bbd99dae851b2fac..c3e6600ecaa089c70178805db0674e9ba637881a 100644 --- a/services/dslm/dslm_fsm_process.c +++ b/services/dslm/dslm_fsm_process.c @@ -173,6 +173,9 @@ static void ProcessSendDeviceInfoCallback(DslmDeviceInfo *info, DslmInfoChecker static bool CheckNeedToResend(const DslmDeviceInfo *info) { + if (info->credInfo.credLevel > 0) { + return false; + } if (info->credInfo.credLevel == 0) { return true; } @@ -188,8 +191,9 @@ static bool CheckNeedToResend(const DslmDeviceInfo *info) static bool ProcessDeviceOnline(const StateMachine *machine, uint32_t event, const void *para) { DslmDeviceInfo *info = STATE_MACHINE_ENTRY(machine, DslmDeviceInfo, machine); - if (para != NULL) { - info->deviceType = *(uint32_t *)para; + if (para != NULL && *(int32_t *)para > 0) { + info->credInfo.credLevel = *(int32_t *)para; + info->result = SUCCESS; } info->onlineStatus = ONLINE_STATUS_ONLINE; info->queryTimes = 0; diff --git a/services/include/dslm_core_process.h b/services/include/dslm_core_process.h index d69655fecf596bc37358f3b668f7127b27c846e5..a08ca929e984f66856b5f4872d59268d1570c860 100644 --- a/services/include/dslm_core_process.h +++ b/services/include/dslm_core_process.h @@ -36,7 +36,7 @@ int32_t OnRequestDeviceSecLevelInfo(const DeviceIdentify *deviceId, const Reques int32_t OnMsgSendResultNotifier(const DeviceIdentify *deviceId, uint64_t transNo, uint32_t result); -int32_t OnPeerStatusReceiver(const DeviceIdentify *deviceId, uint32_t status, uint32_t devType); +int32_t OnPeerStatusReceiver(const DeviceIdentify *deviceId, uint32_t status, int32_t level); bool InitDslmProcess(void); diff --git a/services/include/dslm_messenger_wrapper.h b/services/include/dslm_messenger_wrapper.h index 9f5535518a5f17995d1d0d859615d5537f49e4ff..ab7b242a55e16c544ca0d8c13e88fe65d94ceb2a 100644 --- a/services/include/dslm_messenger_wrapper.h +++ b/services/include/dslm_messenger_wrapper.h @@ -30,11 +30,11 @@ extern "C" { typedef int32_t (*MessageReceiver)(const DeviceIdentify *devId, const uint8_t *msg, uint32_t len); -typedef int32_t (*StatusReceiver)(const DeviceIdentify *devId, uint32_t status, uint32_t devType); +typedef int32_t (*StatusReceiver)(const DeviceIdentify *devId, uint32_t status, int32_t level); typedef int32_t (*SendResultNotifier)(const DeviceIdentify *devId, uint64_t transNo, uint32_t result); -typedef int32_t (*DeviceProcessor)(const DeviceIdentify *devId, uint32_t devType, void *para); +typedef int32_t (*DeviceProcessor)(const DeviceIdentify *devId, int32_t level, void *para); void SendMsgToDevice(uint64_t transNo, const DeviceIdentify *devId, const uint8_t *msg, uint32_t msgLen); @@ -45,9 +45,9 @@ uint32_t DeinitMessenger(void); bool GetMessengerStatus(void); -bool GetPeerDeviceOnlineStatus(const DeviceIdentify *devId, uint32_t *devType); +bool GetPeerDeviceOnlineStatus(const DeviceIdentify *devId, int32_t *level); -const DeviceIdentify *GetSelfDevice(uint32_t *devType); +const DeviceIdentify *GetSelfDevice(int32_t *level); const char *GetMessengerPackageName(void) __attribute__((weak)); const char *GetMessengerPrimarySessionName(void) __attribute__((weak)); diff --git a/services/msg/dslm_messenger_wrapper.c b/services/msg/dslm_messenger_wrapper.c index 722f780e89b755e4138933793ecfad6ca7087039..37eac79b04330a985e19efff081cb52d6f9b9f74 100644 --- a/services/msg/dslm_messenger_wrapper.c +++ b/services/msg/dslm_messenger_wrapper.c @@ -89,35 +89,31 @@ void SendMsgToDevice(uint64_t transNo, const DeviceIdentify *devId, const uint8_ return; } -bool GetPeerDeviceOnlineStatus(const DeviceIdentify *devId, uint32_t *devType) +bool GetPeerDeviceOnlineStatus(const DeviceIdentify *devId, int32_t *level) { LockMutex(&g_mutex); if (g_messenger == NULL) { UnlockMutex(&g_mutex); return false; } - if (devId == NULL || devType == NULL) { + if (devId == NULL || level == NULL) { UnlockMutex(&g_mutex); return false; } - bool ret = GetDeviceOnlineStatus(g_messenger, devId, devType); + bool ret = GetDeviceOnlineStatus(g_messenger, devId, level); UnlockMutex(&g_mutex); return ret; } -const DeviceIdentify *GetSelfDevice(uint32_t *devType) +const DeviceIdentify *GetSelfDevice(int32_t *level) { LockMutex(&g_mutex); - static uint32_t type = 0; static DeviceIdentify deviceId = {0, {0}}; if (deviceId.length == 0 || deviceId.identity[0] == 0) { if (g_messenger != NULL) { - GetSelfDeviceIdentify(g_messenger, &deviceId, &type); + GetSelfDeviceIdentify(g_messenger, &deviceId, level); } } - if (devType != NULL) { - *devType = type; - } UnlockMutex(&g_mutex); return &deviceId; } diff --git a/test/dslm_fuzz_test/dslm_fuzzer/dslm_fuzzer.cpp b/test/dslm_fuzz_test/dslm_fuzzer/dslm_fuzzer.cpp index 2401fafb8199ce3a302135e169b1218fedd8b95c..e254f28e3d7b32ac2d462e6c0163a03e5b175aef 100644 --- a/test/dslm_fuzz_test/dslm_fuzzer/dslm_fuzzer.cpp +++ b/test/dslm_fuzz_test/dslm_fuzzer/dslm_fuzzer.cpp @@ -49,7 +49,7 @@ extern "C" int32_t OnPeerMsgReceived(const DeviceIdentify *devId, const uint8_t *msg, uint32_t len); extern "C" int32_t OnSendResultNotifier(const DeviceIdentify *devId, uint64_t transNo, uint32_t result); -extern "C" bool MessengerGetDeviceOnlineStatus(const DeviceIdentify *devId, uint32_t *devType); +extern "C" bool MessengerGetDeviceOnlineStatus(const DeviceIdentify *devId, int32_t *level); namespace OHOS { namespace Security { @@ -130,12 +130,12 @@ void ServiceTest(DeviceIdentify *deviceIdentify, Parcel &parcel) )"; uint64_t transNo = 1; static DeviceIdentify self = {0, {0}}; - uint32_t devType; + int32_t level; (void)InitService(); - (void)MessengerGetDeviceOnlineStatus(deviceIdentify, &devType); - (void)MessengerGetDeviceOnlineStatus(nullptr, &devType); - (void)MessengerGetSelfDeviceIdentify(&self, &devType); - (void)MessengerGetSelfDeviceIdentify(nullptr, &devType); + (void)MessengerGetDeviceOnlineStatus(deviceIdentify, &level); + (void)MessengerGetDeviceOnlineStatus(nullptr, &level); + (void)MessengerGetSelfDeviceIdentify(&self, &level); + (void)MessengerGetSelfDeviceIdentify(nullptr, &level); MessengerSendMsgTo(transNo, deviceIdentify, jsonString, sizeof(jsonString)); g_init++; } @@ -166,8 +166,8 @@ void MessengerSendMsgToTest(DeviceIdentify *deviceIdentify, Parcel &parcel) )"; uint64_t transNo = 1; static DeviceIdentify self = {0, {0}}; - uint32_t devType; - (void)MessengerGetSelfDeviceIdentify(&self, &devType); + int32_t level; + (void)MessengerGetSelfDeviceIdentify(&self, &level); MessengerSendMsgTo(transNo, deviceIdentify, jsonString, sizeof(jsonString)); MessengerSendMsgTo(transNo, nullptr, jsonString, sizeof(jsonString)); } @@ -175,10 +175,10 @@ void MessengerSendMsgToTest(DeviceIdentify *deviceIdentify, Parcel &parcel) void OnPeerStatusReceiverTest(DeviceIdentify *deviceIdentify, Parcel &parcel) { uint32_t status = parcel.ReadUint32() % 2; - uint32_t devType = parcel.ReadUint32() % 2; - (void)MessengerGetDeviceOnlineStatus(deviceIdentify, &devType); - (void)MessengerGetDeviceOnlineStatus(nullptr, &devType); - (void)OnPeerStatusReceiver(deviceIdentify, status, devType); + int32_t level = -1; + (void)MessengerGetDeviceOnlineStatus(deviceIdentify, &level); + (void)MessengerGetDeviceOnlineStatus(nullptr, &level); + (void)OnPeerStatusReceiver(deviceIdentify, status, level); } void DslmDumperTest(DeviceIdentify *deviceIdentify, Parcel &parcel) @@ -213,8 +213,8 @@ void RequestDeviceSecurityInfoTest(DeviceIdentify *deviceIdentify, Parcel &parce void GetPeerDeviceOnlineStatusTest(DeviceIdentify *deviceIdentify, Parcel &parcel) { - uint32_t devType; - (void)GetPeerDeviceOnlineStatus(deviceIdentify, &devType); + int32_t level; + (void)GetPeerDeviceOnlineStatus(deviceIdentify, &level); (void)GetPeerDeviceOnlineStatus(nullptr, nullptr); } diff --git a/test/dslm_unit_test/dslm_msg_interface_mock.cpp b/test/dslm_unit_test/dslm_msg_interface_mock.cpp index a2308c509796491a88cd842f6e0af5127c4e8ee0..84e04d11edc576fa229e507d3da7f6c7e36cbd19 100644 --- a/test/dslm_unit_test/dslm_msg_interface_mock.cpp +++ b/test/dslm_unit_test/dslm_msg_interface_mock.cpp @@ -28,7 +28,7 @@ extern "C" { extern Messenger *g_messenger; extern int32_t OnPeerMsgReceived(const DeviceIdentify *devId, const uint8_t *msg, uint32_t len); extern int32_t OnSendResultNotifier(const DeviceIdentify *devId, uint64_t transNo, uint32_t result); -extern int32_t OnPeerStatusReceiver(const DeviceIdentify *deviceId, uint32_t status, uint32_t devType); +extern int32_t OnPeerStatusReceiver(const DeviceIdentify *deviceId, uint32_t status, int32_t level); } namespace OHOS { @@ -63,7 +63,7 @@ void DslmMsgInterfaceMock::MakeMsgLoopback() const void DslmMsgInterfaceMock::MakeSelfDeviceId(const DeviceIdentify *self) const { - auto loopback = [this, self](const Messenger *messenger, DeviceIdentify *devId, uint32_t *devType) { + auto loopback = [this, self](const Messenger *messenger, DeviceIdentify *devId, int32_t *level) { *devId = *self; return true; }; @@ -111,14 +111,14 @@ uint64_t SendMsgToImpl(const Messenger *messenger, uint64_t transNo, const Devic return GetDslmMsgInterface()->SendMsgTo(messenger, transNo, devId, msg, msgLen); } -bool GetDeviceOnlineStatusImpl(const Messenger *messenger, const DeviceIdentify *devId, uint32_t *devType) +bool GetDeviceOnlineStatusImpl(const Messenger *messenger, const DeviceIdentify *devId, int32_t *level) { - return GetDslmMsgInterface()->GetDeviceOnlineStatus(messenger, devId, devType); + return GetDslmMsgInterface()->GetDeviceOnlineStatus(messenger, devId, level); } -bool GetSelfDeviceIdentifyImpl(const Messenger *messenger, DeviceIdentify *devId, uint32_t *devType) +bool GetSelfDeviceIdentifyImpl(const Messenger *messenger, DeviceIdentify *devId, int32_t *level) { - return GetDslmMsgInterface()->GetSelfDeviceIdentify(messenger, devId, devType); + return GetDslmMsgInterface()->GetSelfDeviceIdentify(messenger, devId, level); } void ForEachDeviceProcessImpl(const Messenger *messenger, const DeviceProcessor processor, void *para) diff --git a/test/dslm_unit_test/dslm_msg_interface_mock.h b/test/dslm_unit_test/dslm_msg_interface_mock.h index 35b32f5b9e416a8352d49241a8d276e672edb28c..e4a98f2778f3497ae8808092a41170d42ae91ad0 100644 --- a/test/dslm_unit_test/dslm_msg_interface_mock.h +++ b/test/dslm_unit_test/dslm_msg_interface_mock.h @@ -36,9 +36,9 @@ public: virtual uint64_t SendMsgTo(const Messenger *messenger, uint64_t transNo, const DeviceIdentify *devId, const uint8_t *msg, uint32_t msgLen) = 0; - virtual bool GetDeviceOnlineStatus(const Messenger *messenger, const DeviceIdentify *devId, uint32_t *devType) = 0; + virtual bool GetDeviceOnlineStatus(const Messenger *messenger, const DeviceIdentify *devId, int32_t *level) = 0; - virtual bool GetSelfDeviceIdentify(const Messenger *messenger, DeviceIdentify *devId, uint32_t *devType) = 0; + virtual bool GetSelfDeviceIdentify(const Messenger *messenger, DeviceIdentify *devId, int32_t *level) = 0; virtual void ForEachDeviceProcess(const Messenger *messenger, const DeviceProcessor processor, void *para) = 0; }; @@ -51,8 +51,8 @@ public: MOCK_METHOD5(SendMsgTo, uint64_t(const Messenger *messenger, uint64_t transNo, const DeviceIdentify *devId, const uint8_t *msg, uint32_t msgLen)); MOCK_METHOD3(GetDeviceOnlineStatus, - bool(const Messenger *messenger, const DeviceIdentify *devId, uint32_t *devType)); - MOCK_METHOD3(GetSelfDeviceIdentify, bool(const Messenger *messenger, DeviceIdentify *devId, uint32_t *devType)); + bool(const Messenger *messenger, const DeviceIdentify *devId, int32_t *level)); + MOCK_METHOD3(GetSelfDeviceIdentify, bool(const Messenger *messenger, DeviceIdentify *devId, int32_t *level)); MOCK_METHOD3(ForEachDeviceProcess, void(const Messenger *messenger, const DeviceProcessor processor, void *para)); void MakeMsgLoopback() const; void MakeSelfDeviceId(const DeviceIdentify *devId) const; diff --git a/test/dslm_unit_test/dslm_test.cpp b/test/dslm_unit_test/dslm_test.cpp index 10c80b7b30eb4152ca8ad329200405c8b618ff46..1b7ed0629474058e5d6e9e0dd827d67e632bc869 100644 --- a/test/dslm_unit_test/dslm_test.cpp +++ b/test/dslm_unit_test/dslm_test.cpp @@ -1276,9 +1276,9 @@ HWTEST_F(DslmTest, OnPeerStatusReceiver_case1, TestSize.Level0) { const DeviceIdentify device = {DEVICE_ID_MAX_LEN, {'a', 'b', 'c', 'd', 'e', 'f', 'a', 'b'}}; uint32_t status = 1234; - uint32_t devType = 0; + uint32_t level = -1; - int32_t ret = OnPeerStatusReceiver(&device, status, devType); + int32_t ret = OnPeerStatusReceiver(&device, status, level); EXPECT_EQ(SUCCESS, ret); } @@ -1374,10 +1374,9 @@ HWTEST_F(DslmTest, GetPeerDeviceOnlineStatus_case2, TestSize.Level0) */ HWTEST_F(DslmTest, GetSelfDevice_case1, TestSize.Level0) { - uint32_t *type = nullptr; - const DeviceIdentify *identify = GetSelfDevice(type); + int32_t level = 0; + const DeviceIdentify *identify = GetSelfDevice(&level); EXPECT_NE(nullptr, identify); - EXPECT_EQ(nullptr, type); } /**