Skip to content

Commit

Permalink
Merge pull request rdkcentral#4087 from PaviP98/main
Browse files Browse the repository at this point in the history
RDK-41544: Startup service configuration changes to support Flex 2.0 activation
  • Loading branch information
anand-ky authored Jun 1, 2023
2 parents 56633ac + 8147488 commit 12ca7cc
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 2 deletions.
4 changes: 4 additions & 0 deletions MaintenanceManager/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ All notable changes to this RDK Service will be documented in this file.

* For more details, refer to [versioning](https://github.com/rdkcentral/rdkservices#versioning) section under Main README.

## [1.0.20] - 2023-06-01
### Added
- Implementation to get the partner provisioning context from whoAmI

## [1.0.19] - 2023-05-30
### Fixed
- Updated unsolicited_maintenance completed status as true in stopMaintenance()
Expand Down
171 changes: 169 additions & 2 deletions MaintenanceManager/MaintenanceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,18 @@ using namespace std;

#define API_VERSION_NUMBER_MAJOR 1
#define API_VERSION_NUMBER_MINOR 0
#define API_VERSION_NUMBER_PATCH 19
#define API_VERSION_NUMBER_PATCH 20
#define SERVER_DETAILS "127.0.0.1:9998"


#define PROC_DIR "/proc"
#define MAINTENANCE_MANAGER_RFC_CALLER_ID "MaintenanceManager"
#define TR181_AUTOREBOOT_ENABLE "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.AutoReboot.Enable"
#define TR181_STOP_MAINTENANCE "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.StopMaintenance.Enable"
#define TR181_RDKVFWUPGRADER "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKFirmwareUpgrader.Enable"
#define TR181_PARTNER_ID "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.PartnerName"
#define TR181_TARGET_PROPOSITION "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.TargetProposition"
#define TR181_XCONFURL "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.XconfUrl"

string notifyStatusToString(Maint_notify_status_t &status)
{
Expand Down Expand Up @@ -228,6 +232,12 @@ namespace WPEFramework {
"uploadSTBLogs.sh"
};

string deviceInitializationContext[] = {
"partnerId",
"targetProposition",
"regionalConfigService"
};

/**
* Register MaintenanceManager module as wpeframework plugin
*/
Expand Down Expand Up @@ -255,7 +265,13 @@ namespace WPEFramework {
MaintenanceManager::m_task_map[task_names_foreground[2].c_str()]=false;
MaintenanceManager::m_task_map[task_names_foreground[3].c_str()]=false;

MaintenanceManager::m_param_map[deviceInitializationContext[0].c_str()] = TR181_PARTNER_ID;
MaintenanceManager::m_param_map[deviceInitializationContext[1].c_str()] = TR181_TARGET_PROPOSITION;
MaintenanceManager::m_param_map[deviceInitializationContext[2].c_str()] = TR181_XCONFURL;

MaintenanceManager::m_paramType_map[deviceInitializationContext[0].c_str()] = DATA_TYPE::WDMP_STRING;
MaintenanceManager::m_paramType_map[deviceInitializationContext[1].c_str()] = DATA_TYPE::WDMP_STRING;
MaintenanceManager::m_paramType_map[deviceInitializationContext[2].c_str()] = DATA_TYPE::WDMP_STRING;
}

void MaintenanceManager::task_execution_thread(){
Expand Down Expand Up @@ -292,6 +308,16 @@ namespace WPEFramework {
internetConnectStatus = isDeviceOnline();
#endif

#if defined(ENABLE_WHOAMI)
if (UNSOLICITED_MAINTENANCE == g_maintenance_type) {
/* WhoAmI check*/
bool whoAmIStatus = knowWhoAmI();
if (whoAmIStatus) {
LOGINFO("knowWhoAmI() returned successfully");
}
}
#endif

if ( false == internetConnectStatus ) {
m_statusMutex.lock();
MaintenanceManager::_instance->onMaintenanceStatusChange(MAINTENANCE_ERROR);
Expand All @@ -307,13 +333,26 @@ namespace WPEFramework {

if (UNSOLICITED_MAINTENANCE == g_maintenance_type){
LOGINFO("---------------UNSOLICITED_MAINTENANCE--------------");
#ifndef ENABLE_WHOAMI
tasks.push_back(task_names_foreground[0].c_str());
#endif
}
else if( SOLICITED_MAINTENANCE == g_maintenance_type){
LOGINFO("=============SOLICITED_MAINTENANCE===============");
}

#if defined(SUPPRESS_MAINTENANCE)
#if defined(ENABLE_WHOAMI)
if (UNSOLICITED_MAINTENANCE == g_maintenance_type) {
tasks.push_back(task_names_foreground[1].c_str());
tasks.push_back(task_names_foreground[2].c_str());
tasks.push_back(task_names_foreground[0].c_str());
tasks.push_back(task_names_foreground[3].c_str());
} else {
tasks.push_back(task_names_foreground[1].c_str());
tasks.push_back(task_names_foreground[2].c_str());
tasks.push_back(task_names_foreground[3].c_str());
}
#elif defined(SUPPRESS_MAINTENANCE)
/* decide which all tasks are needed based on the activation status */
if (activationStatus){
if(skipFirmwareCheck){
Expand Down Expand Up @@ -356,6 +395,134 @@ namespace WPEFramework {
LOGINFO("Worker Thread Completed");
}

bool MaintenanceManager::knowWhoAmI()
{
bool success = false;
int retryDelay = 10;
int retryCount = 0;
const char* secMgr_callsign = "org.rdk.SecManager";
const char* secMgr_callsign_ver = "org.rdk.SecManager.1";
PluginHost::IShell::state state;
WPEFramework::JSONRPC::LinkType<WPEFramework::Core::JSON::IElement>* thunder_client = nullptr;

do {

if ((getServiceState(m_service, secMgr_callsign, state) == Core::ERROR_NONE) && (state == PluginHost::IShell::state::ACTIVATED)) {
LOGINFO("%s is active", secMgr_callsign);

thunder_client=getThunderPluginHandle(secMgr_callsign_ver);
if (thunder_client == nullptr) {
LOGINFO("Failed to get plugin handle");
} else {
JsonObject params;
JsonObject joGetResult;

thunder_client->Invoke<JsonObject, JsonObject>(5000, "getDeviceInitializationContext", params, joGetResult);
if (joGetResult.HasLabel("success") && joGetResult["success"].Boolean()) {
if (joGetResult.HasLabel("partnerProvisioningContext")) {
JsonObject getProvisioningContext = joGetResult["partnerProvisioningContext"].Object();
int size = (int)(sizeof(deviceInitializationContext)/sizeof(deviceInitializationContext[0]));
for (int idx=0; idx < size; idx++) {
const char* key = deviceInitializationContext[idx].c_str();

// Retrive partnerProvisioningContext Value
string paramValue = getProvisioningContext[key].String();

if (!paramValue.empty()) {
if (strcmp(key, "regionalConfigService") == 0) {
paramValue = "https://" + paramValue;
}
LOGINFO("[partnerProvisioningContext] %s : %s", key, paramValue.c_str());

// Retrieve tr181 parameter from m_param_map
string rfc_parameter = m_param_map[key];

// Retrieve parameter data type from m_paramType_map
DATA_TYPE rfc_dataType = m_paramType_map[key];

// Set the RFC values for partnerProvisioningContext parameters
setRFC(rfc_parameter.c_str(), paramValue.c_str(), rfc_dataType);
} else {
LOGINFO("Not able to fetch %s value from partnerProvisioningContext", key);
}
}
success = true;
} else {
LOGINFO("partnerProvisioningContext is not available in the response");
}
} else {
// Get retryDelay value and sleep for that much seconds
if (joGetResult.HasLabel("retryDelay")) {
retryDelay = joGetResult["retryDelay"].Number();
}
LOGINFO("getDeviceInitializationContext failed");
}
}
} else {
LOGINFO("%s is not active", secMgr_callsign);
}

retryCount++;
if (retryCount == 4 && !success) {
if (checkActivatedStatus() == "activated") {
LOGINFO("Device is already activated. Exiting from knowWhoAmI()");
success = true;
}
}

if (!success) {
LOGINFO("Retrying in %d seconds", retryDelay);
sleep(retryDelay);
}

} while (!success);
return success;
}

// Thunder plugin communication
WPEFramework::JSONRPC::LinkType<WPEFramework::Core::JSON::IElement>* MaintenanceManager::getThunderPluginHandle(const char* callsign)
{
string token;
WPEFramework::JSONRPC::LinkType<WPEFramework::Core::JSON::IElement>* thunder_client = nullptr;

auto security = m_service->QueryInterfaceByCallsign<PluginHost::IAuthenticate>("SecurityAgent");
if (security != nullptr) {
string payload = "http://localhost";
if (security->CreateToken(
static_cast<uint16_t>(payload.length()),
reinterpret_cast<const uint8_t*>(payload.c_str()),
token)
== Core::ERROR_NONE) {
std::cout << "MaintenanceManager got security token" << std::endl;
} else {
std::cout << "MaintenanceManager failed to get security token" << std::endl;
}
security->Release();
} else {
std::cout << "No security agent" << std::endl;
}

string query = "token=" + token;
Core::SystemInfo::SetEnvironment(_T("THUNDER_ACCESS"), _T(SERVER_DETAILS));
thunder_client = new WPEFramework::JSONRPC::LinkType<Core::JSON::IElement>(callsign, "", false, query);
return thunder_client;
}

bool MaintenanceManager::setRFC(const char* rfc, const char* value, DATA_TYPE dataType)
{
bool result = false;
WDMP_STATUS status;
status = setRFCParameter((char *)MAINTENANCE_MANAGER_RFC_CALLER_ID, rfc, value, dataType);

if ( WDMP_SUCCESS == status ){
LOGINFO("Successfuly set the tr181 parameter %s with value %s", rfc, value);
result = true;
} else {
LOGINFO("Failed setting %s parameter", rfc);
}
return result;
}

const string MaintenanceManager::checkActivatedStatus()
{
JsonObject joGetParams;
Expand Down
5 changes: 5 additions & 0 deletions MaintenanceManager/MaintenanceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ namespace WPEFramework {
std::thread m_thread;

std::map<string, bool> m_task_map;
std::map<string, string> m_param_map;
std::map<string, DATA_TYPE> m_paramType_map;
PluginHost::IShell* m_service;

bool isDeviceOnline();
Expand All @@ -146,6 +148,9 @@ namespace WPEFramework {
void maintenanceManagerOnBootup();
bool checkAutoRebootFlag();
bool readRFC(const char *);
bool setRFC(const char*, const char*, DATA_TYPE);
WPEFramework::JSONRPC::LinkType<WPEFramework::Core::JSON::IElement>* getThunderPluginHandle(const char*);
bool knowWhoAmI();
bool stopMaintenanceTasks();
bool checkNetwork();
bool getActivatedStatus(bool &skipFirmwareCheck);
Expand Down
5 changes: 5 additions & 0 deletions broadcom.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ if (BUILD_DONT_SET_POWER_BRIGHTNESS)
add_definitions (-DDONT_SET_POWER_BRIGHTNESS)
endif()

if (ENABLE_WHOAMI)
message("Enable WHOAMI")
add_definitions (-DENABLE_WHOAMI=ON)
endif()

if (BUILD_ENABLE_HDCP)
message("Building with hdcp profile")
add_definitions (-DBUILD_ENABLE_HDCP)
Expand Down

0 comments on commit 12ca7cc

Please sign in to comment.