From 9b79f9f9537351b8ff63355f0f010b466206ecce Mon Sep 17 00:00:00 2001 From: Lukasz Mastalerz Date: Thu, 17 Nov 2022 14:18:25 +0100 Subject: [PATCH] [CP-1666] DeviceInfo request should return "SerialNumber" for Harmony Add reading serial number from emmc partition Add serial number to body response for deviceInfo endpoint for Harmony --- .../deviceInfo/DeviceInfoEndpoint.cpp | 25 ++++++++++++++++++- .../deviceInfo/DeviceInfoEndpoint.hpp | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/products/BellHybrid/services/desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp b/products/BellHybrid/services/desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp index f376ef086eda2cdbc26c14156d36c2547ad71007..d574012dd586f68bb4cf25324ceff61a21a01ede 100644 --- a/products/BellHybrid/services/desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp +++ b/products/BellHybrid/services/desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp @@ -14,12 +14,34 @@ #include #include #include +#include #include +namespace +{ + constexpr auto DEVICE_NAME = "emmc0sys1"; + constexpr auto EMMC_SN_LENGTH = 13; + constexpr auto EMMC_BUFFER_SIZE = 512; + constexpr auto SECTOR_TO_READ = 2; + constexpr auto SECTOR_COUNT = 1U; + + std::string readSerialNumberFromEmmc() + { + char buffer[EMMC_BUFFER_SIZE]; + purefs::subsystem::disk_mgr()->read(DEVICE_NAME, buffer, SECTOR_TO_READ, SECTOR_COUNT); + buffer[EMMC_SN_LENGTH] = '\0'; + return std::string(buffer); + } +} // namespace namespace sdesktop::endpoints { + auto DeviceInfoEndpoint::getSerialNumber() -> std::string + { + return readSerialNumberFromEmmc(); + } + auto DeviceInfoEndpoint::getDeviceInfo(Context &context) -> http::Code { auto [totalDeviceSpaceMiB, reservedSystemSpaceMiB, usedUserSpaceMiB] = getStorageInfo(); @@ -33,7 +55,8 @@ namespace sdesktop::endpoints {json::gitRevision, (std::string)(GIT_REV)}, {json::gitBranch, (std::string)GIT_BRANCH}, {json::currentRTCTime, std::to_string(static_cast(std::time(nullptr)))}, - {json::version, std::string(VERSION)}})); + {json::version, std::string(VERSION)}, + {json::serialNumber, getSerialNumber()}})); return http::Code::OK; } diff --git a/products/BellHybrid/services/desktop/endpoints/include/endpoints/deviceInfo/DeviceInfoEndpoint.hpp b/products/BellHybrid/services/desktop/endpoints/include/endpoints/deviceInfo/DeviceInfoEndpoint.hpp index d32aa0d8864beca61d9a81bebee6a2ea861d8294..a11e497f3ec5ea9d657a037ac71de050bdbb8671 100644 --- a/products/BellHybrid/services/desktop/endpoints/include/endpoints/deviceInfo/DeviceInfoEndpoint.hpp +++ b/products/BellHybrid/services/desktop/endpoints/include/endpoints/deviceInfo/DeviceInfoEndpoint.hpp @@ -14,6 +14,7 @@ namespace sdesktop::endpoints explicit DeviceInfoEndpoint(sys::Service *ownerServicePtr) : DeviceInfoEndpointCommon(ownerServicePtr) {} + auto getSerialNumber() -> std::string; auto getDeviceInfo(Context &context) -> http::Code override; };