Skip to content

RDKEMW-14517: Use IARM for PowerManager clients#49

Open
yuvaramachandran-gurusamy wants to merge 7 commits intotopic/support_2.16.9_Testfrom
feature/RDKEMW-14517_pwrmgr_revert
Open

RDKEMW-14517: Use IARM for PowerManager clients#49
yuvaramachandran-gurusamy wants to merge 7 commits intotopic/support_2.16.9_Testfrom
feature/RDKEMW-14517_pwrmgr_revert

Conversation

@yuvaramachandran-gurusamy
Copy link
Contributor

RDKEMW-14517: Use IARM based PowerManager

Signed-off-by: Yuvaramachandran Gurusamy [yuvaramachandran_gurusamy@comcast.com]

@yuvaramachandran-gurusamy yuvaramachandran-gurusamy requested a review from a team as a code owner February 25, 2026 11:03
Copilot AI review requested due to automatic review settings February 25, 2026 11:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the power-state helper tools to use the IARM PowerManager APIs instead of the WPEFramework PowerController/Thunder dependency, aligning clients with the IARM-based PowerManager for RDKEMW-14517.

Changes:

  • Reworked SetPowerState tool to call IARM_BUS_PWRMGR_API_SetPowerState via IARM.
  • Reworked QueryPowerState tool to query power state via IARM_BUS_PWRMGR_API_GetPowerState (and still supports reading /opt/uimgr_settings.bin).
  • Updated build/link flags to remove -lWPEFrameworkPowerController usage and link against -lIARMBus; removed .gitignore.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 8 comments.

File Description
iarm_set_powerstate/IARM_BUS_SetPowerStatus.c Switches power-state setting implementation to IARM bus calls.
iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c Switches power-state query implementation to IARM bus calls and retains file-based fallback.
Makefile.am Removes WPEFramework PowerController include/link usage and links tools against IARMBus.
.gitignore Removed from the repository.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +50 to 55
param.newState = IARM_BUS_PWRMGR_POWERSTATE_ON;

if (optind < argc) {
strncpy(argstate, argv[optind], sizeof(argstate) - 1);
} else {
fprintf(stderr, "Error: POWER_STATE is mandatory.\n");
if (argc < 2)
{
usage();
return EXIT_FAILURE;
}
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When no power state argument is provided (argc < 2), the tool prints usage but continues and will still call SetPowerState with the default ON value. This makes SetPowerState change power unexpectedly; return a non-zero exit code (or skip the IARM call) after printing usage.

Copilot uses AI. Check for mistakes.
Comment on lines +81 to 84
else
{
usage();
return EXIT_FAILURE;
}
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On an unrecognized argument, the code prints usage but does not exit, so param.newState remains whatever was previously set (currently defaults to ON) and the IARM call still runs. Treat invalid input as an error and return without calling IARM_Bus_Call.

Copilot uses AI. Check for mistakes.

Controller controller = { .clientName = "", .ack = -1, .delaySize = 0, .clientId = 0, .transactionId = 0 };
IARM_Bus_PWRMgr_SetPowerState_Param_t param;

Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

param is a stack variable and only newState is set. Any additional fields and even padding bytes may be uninitialized and get sent over IARM, which can lead to unpredictable behavior or a stack info leak. Zero-initialize the struct (e.g., memset) before setting newState.

Suggested change
memset(&param, 0, sizeof(param));

Copilot uses AI. Check for mistakes.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strncasecmp is used but the file does not include the standard header that declares it (<strings.h> on POSIX). Depending on compiler flags this can produce an implicit-declaration build failure; include the correct header (or avoid strncasecmp).

Suggested change
#include <string.h>
#include <string.h>
#include <strings.h>

Copilot uses AI. Check for mistakes.
printf ("\t\t OFF -> Set to OFF\n");
}

void setPowerMode();
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a global prototype void setPowerMode(); that is neither defined nor used in this file. Please remove it (or provide the implementation) to avoid dead declarations confusing future maintenance.

Suggested change
void setPowerMode();

Copilot uses AI. Check for mistakes.
}
}
}
printf ("\nUsage: 'iARM_SetPowerStatus [ON | STANDBY | LIGHTSLEEP | DEEPSLEEP | OFF ]'\n");
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usage banner prints iARM_SetPowerStatus, but the installed binary name in this repo is SetPowerState (see Makefile.am). This makes CLI help misleading; update the usage text to match the actual program name.

Suggested change
printf ("\nUsage: 'iARM_SetPowerStatus [ON | STANDBY | LIGHTSLEEP | DEEPSLEEP | OFF ]'\n");
printf ("\nUsage: 'SetPowerState [ON | STANDBY | LIGHTSLEEP | DEEPSLEEP | OFF ]'\n");

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +89
IARM_Bus_PWRMgr_GetPowerState_Param_t param;

IARM_Bus_Init("iARMQueryPower_1tool");
IARM_Bus_Connect();

/** Query current Power state */
res = PowerController_GetPowerState(&curState, &previousState);

if (POWER_CONTROLLER_ERROR_NONE == res) {

if (POWER_STATE_OFF == curState) {
printf("OFF\n");
} else if (POWER_STATE_STANDBY == curState) {
printf("STANDBY\n");
} else if (POWER_STATE_ON == curState) {
printf("ON\n");
} else if (POWER_STATE_STANDBY_LIGHT_SLEEP == curState) {
printf("LIGHTSLEEP\n");
} else if (POWER_STATE_STANDBY_DEEP_SLEEP == curState) {
printf("DEEPSLEEP\n");
} else {
printf("Unknown\n");
}
} else if (POWER_CONTROLLER_ERROR_UNAVAILABLE == res) {
printf("Error :: PowerManager plugin unavailable\n");
} else {
printf("Error :: Unknown\n");
if (IARM_RESULT_SUCCESS == IARM_Bus_Call(IARM_BUS_PWRMGR_NAME,
IARM_BUS_PWRMGR_API_GetPowerState,
(void *)&param,
sizeof(param)))
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IARM_Bus_PWRMgr_GetPowerState_Param_t param is never initialized before being passed to IARM_Bus_Call. This sends uninitialized stack bytes over IPC (potential info leak) and can cause undefined behavior if the callee expects any input fields. Zero-initialize param before the call.

Copilot uses AI. Check for mistakes.
*/
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include <errno.h> is unused in this file. Please remove it to keep includes minimal and avoid suggesting errno-based error handling that isn’t implemented.

Suggested change
#include <errno.h>

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants