Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 0 additions & 58 deletions .gitignore

This file was deleted.

5 changes: 2 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ AM_CFLAGS = \
-I$(PKG_CONFIG_SYSROOT_DIR)${includedir}/rdk/iarmmgrs/rdmmgr \
-I$(PKG_CONFIG_SYSROOT_DIR)${includedir}/rdk/iarmmgrs/receiver \
-I$(PKG_CONFIG_SYSROOT_DIR)${includedir}/rdk/iarmmgrs/sysmgr \
-I$(PKG_CONFIG_SYSROOT_DIR)${includedir}/WPEFramework/powercontroller \
-L$(PKG_CONFIG_SYSROOT_DIR)/usr/lib/


Expand All @@ -42,10 +41,10 @@ mfr_util_SOURCES = mfr-utils/sys_mfr_utils.c
mfr_util_LDADD = -lIARMBus

QueryPowerState_SOURCES=iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c
QueryPowerState_LDADD = $(DIRECT_LIBS) $(FUSION_LIBS) $(GLIB_LIBS) $(DBUS_LIBS) -lWPEFrameworkPowerController
QueryPowerState_LDADD = $(DIRECT_LIBS) $(FUSION_LIBS) $(GLIB_LIBS) -lIARMBus $(DBUS_LIBS)

SetPowerState_SOURCES=iarm_set_powerstate/IARM_BUS_SetPowerStatus.c
SetPowerState_LDADD = -ldbus-1 -lstdc++ -lpthread -lWPEFrameworkPowerController
SetPowerState_LDADD = -ldbus-1 -lstdc++ -lIARMBus -lpthread

keySimulator_SOURCES=key_simulator/IARM_BUS_UIEventSimulator.c key_simulator/uinput.c
keySimulator_LDADD = $(GLIB_LIBS) -lIARMBus $(DBUS_LIBS)
Expand Down
173 changes: 87 additions & 86 deletions iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,133 +15,134 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
*/
#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.
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

// This include is still required for data types to read cached power status residing in /opt/uimgr_settings.bin
// TODO: after IARM PwrMgr logic is moved to PowerManager plugin refactor this code and remove this header file too.
#include <string.h>
#include <stdlib.h>
#include "libIBus.h"
#include "pwrMgr.h"

#include "power_controller.h"

#define PADDING_SIZE 32

/*LED settings*/
typedef struct _PWRMgr_LED_Settings_t {
typedef struct _PWRMgr_LED_Settings_t{
unsigned int brightness;
unsigned int color;
} PWRMgr_LED_Settings_t;
}PWRMgr_LED_Settings_t;

typedef struct _PWRMgr_Settings_t {
uint32_t magic;
uint32_t version;
uint32_t length;
IARM_Bus_PWRMgr_PowerState_t powerState;
PWRMgr_LED_Settings_t ledSettings;
uint32_t deep_sleep_timeout;
PWRMgr_LED_Settings_t ledSettings;
uint32_t deep_sleep_timeout;
char padding[PADDING_SIZE];
} PWRMgr_Settings_t;

void usage()
void usage ()
{
printf("\nUsage: 'QueryPowerState [CMD]'\n");
printf("\tCMDs are,\n");
printf("\t\t -h -> Help\n");
printf("\t\t -c -> Box state from PowerManager plugin\n");
printf("\t\t No CMD will read the iARM state from '/opt'\n");

printf("\n\tOutput will be,\n");
printf("\t\t\t ON -> Box is in Active Mode\n");
printf("\t\t\t STANDBY -> Box is in Standby Mode\n");
printf("\t\t\t LIGHTSLEEP -> Box is in Light Sleep Standby Mode\n");
printf("\t\t\t DEEPSLEEP -> Box is in Deep Sleep Standby Mode\n");
printf("\t\t\t OFF -> Box id OFF\n");
printf ("\nUsage: 'QueryPowerState [CMD]'\n");
printf ("\tCMDs are,\n");
printf ("\t\t -h -> Help\n");
printf ("\t\t -c -> Box state from iARM Cache\n");
printf ("\t\t No CMD will read the iARM state from '/opt'\n");

printf ("\n\tOutput will be,\n");
printf ("\t\t\t ON -> Box is in Active Mode\n");
printf ("\t\t\t STANDBY -> Box is in Standby Mode\n");
printf ("\t\t\t LIGHTSLEEP -> Box is in Light Sleep Standby Mode\n");
printf ("\t\t\t DEEPSLEEP -> Box is in Deep Sleep Standby Mode\n");
printf ("\t\t\t OFF -> Box id OFF\n");
}

/**
* Test application to check whether the box is in standby or not.
* This has been developed to resolve, XONE-4598
*/
int main(int argc, char* argv[])
int main(int argc, char *argv[])
{
PWRMgr_Settings_t pwrSettings;
int ret = 0;

if (argc > 1) {
if (argv[1][1] == 'c') {
uint32_t res = 0;
PowerController_PowerState_t curState = POWER_STATE_UNKNOWN, previousState = POWER_STATE_UNKNOWN;

PowerController_Init();

const char *settingsFile = "/opt/uimgr_settings.bin";

memset(&pwrSettings,0,sizeof(PWRMgr_Settings_t));

if (argc > 1)
{
if (argv[1][1] == 'c')
{
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)))
Comment on lines +80 to +89
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.
{

if (param.curState == IARM_BUS_PWRMGR_POWERSTATE_OFF)
printf ("OFF");
else if (param.curState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY)
printf ("STANDBY");
else if (param.curState == IARM_BUS_PWRMGR_POWERSTATE_ON)
printf ("ON");
else if (param.curState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_LIGHT_SLEEP)
printf ("LIGHTSLEEP");
else if (param.curState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP)
printf ("DEEPSLEEP");
else
printf ("Unknown");
}

/* Dispose closes RPC conn, do not make any power manager calls after this */
PowerController_Term();

} else if (argv[1][1] == 'h') {
else
printf ("Unknown");

IARM_Bus_Disconnect();
IARM_Bus_Term();
}
else if (argv[1][1] == 'h')
{
usage();
}
} else {
PWRMgr_Settings_t pwrSettings;
const char* settingsFile = "/opt/uimgr_settings.bin";

}
else
{
int fd = open(settingsFile, O_RDONLY);

memset(&pwrSettings, 0, sizeof(PWRMgr_Settings_t));

if (fd > 0) {
lseek(fd, 0, SEEK_SET);
ret = read(fd, &pwrSettings, (sizeof(PWRMgr_Settings_t) - PADDING_SIZE));

ret = read(fd, &pwrSettings, (sizeof(PWRMgr_Settings_t) - PADDING_SIZE) );

close(fd);
close (fd);
}

if (ret > 0) {
if (IARM_BUS_PWRMGR_POWERSTATE_OFF == pwrSettings.powerState) {
printf("OFF");
} else if (IARM_BUS_PWRMGR_POWERSTATE_STANDBY == pwrSettings.powerState) {
printf("STANDBY");
} else if (IARM_BUS_PWRMGR_POWERSTATE_ON == pwrSettings.powerState) {
printf("ON");
} else if (IARM_BUS_PWRMGR_POWERSTATE_STANDBY_LIGHT_SLEEP == pwrSettings.powerState) {
printf("LIGHTSLEEP");
} else if (IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP == pwrSettings.powerState) {
printf("DEEPSLEEP");
} else {
printf("Unknown Power state");
}
} else {
printf("Error in reading PWRMgr settings File");
if (ret > 0)
{
if (pwrSettings.powerState == IARM_BUS_PWRMGR_POWERSTATE_OFF)
printf ("OFF");
else if (pwrSettings.powerState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY)
printf ("STANDBY");
else if (pwrSettings.powerState == IARM_BUS_PWRMGR_POWERSTATE_ON)
printf ("ON");
else if (pwrSettings.powerState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_LIGHT_SLEEP)
printf ("LIGHTSLEEP");
else if (pwrSettings.powerState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP)
printf ("DEEPSLEEP");
else
printf ("Unknown Power state");
}

printf("\n");
else
printf ("Error in reading PWRMgr settings File");
}
printf ("\n");
return 0;
}
Loading
Loading