Skip to content
Merged
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
6 changes: 4 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ AM_CFLAGS = $(TRACE_CFLAGS)

AM_CFLAGS += -Wall -Werror $(cjson_CFLAGS) $(curl_CFLAGS) $(CFLAGS)
AM_LDFLAGS = -L$(PKG_CONFIG_SYSROOT_DIR)/$(libdir)
AM_LDFLAGS += $(cjson_LIBS) $(curl_LIBS)
AM_LDFLAGS += -lrdkloggers -ldwnlutil -lfwutils -lsecure_wrapper -lparsejson -lpthread
AM_LDFLAGS += $(cjson_LIBS) $(curl_LIBS)
AM_LDFLAGS += -lrdkloggers -ldwnlutil -lfwutils -lsecure_wrapper -lparsejson -lpthread -lrbus

bin_PROGRAMS= rdkvfwupgrader

Expand All @@ -35,12 +35,14 @@ rdkvfwupgrader_SOURCES = \
${top_srcdir}/src/download_status_helper.c \
${top_srcdir}/src/iarmInterface/iarmInterface.c \
${top_srcdir}/src/rfcInterface/rfcinterface.c \
${top_srcdir}/src/rbusInterface/rbusInterface.c \
${top_srcdir}/src/deviceutils/device_api.c \
${top_srcdir}/src/deviceutils/deviceutils.c

rdkvfwupgrader_include_HEADERS = \
${top_srcdir}/src/rfcInterface/rfcinterface.h \
${top_srcdir}/src/iarmInterface/iarmInterface.h \
${top_srcdir}/src/rbusInterface/rbusInterface.h \
${top_srcdir}/src/deviceutils/device_api.h \
${top_srcdir}/src/deviceutils/deviceutils.h \
${top_srcdir}/src/include/device_status_helper.h
Expand Down
2 changes: 1 addition & 1 deletion src/device_status_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ bool checkForValidPCIUpgrade(int trigger_type, const char *myfwversion, const ch
t2ValNotify("cloudFWFile_split", (char *)cloudFWFile);
SWLOG_INFO("lastdwnlfile:%s\n", last_dwnl_img);
SWLOG_INFO("currentImg:%s\n", current_img);
if (trigger_type == 1 || trigger_type == 4) {
if (trigger_type == 1 || trigger_type == 3 || trigger_type == 4) {
if ((false == current_img_status) || (false == last_dwnl_status)) {
SWLOG_INFO("Unable to fetch current running image file name or last download file\n");
SWLOG_INFO("Error identified with image file comparison !!! Proceeding with firmware version check.\n");
Expand Down
1 change: 1 addition & 0 deletions src/deviceutils/device_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ size_t GetAdditionalFwVerInfo( char *pAdditionalFwVerInfo, size_t szBufSize )
{
len += GetRemoteInfo( (pAdditionalFwVerInfo + len), (szBufSize - len) );
}
len = stripinvalidchar(pAdditionalFwVerInfo, len); // remove newline etc.
}
else
{
Expand Down
118 changes: 115 additions & 3 deletions src/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,28 @@
*/

#include <sys/stat.h>
#include <curl/curl.h>
#include "rdkv_cdl.h"
#include "rdkv_cdl_log_wrapper.h"
#include "download_status_helper.h"
#include "device_status_helper.h"
#include "iarmInterface/iarmInterface.h"
#ifndef GTEST_ENABLE
#include "urlHelper.h"
#include "json_parse.h"
#include "rdk_fwdl_utils.h"
#include "system_utils.h"
#include "rbusInterface/rbusInterface.h"
#else
#include "rbus_mock.h"
#endif
#include "rfcInterface/rfcinterface.h"
#include <sys/wait.h>
#include "deviceutils.h"

extern int getTriggerType();
extern void t2CountNotify(char *marker, int val);

/* Description:Use for Flashing the image
* @param: server_url : server url
* @param: upgrade_file : Image file to be flash
Expand Down Expand Up @@ -138,10 +147,25 @@ int flashImage(const char *server_url, const char *upgrade_file, const char *reb
snprintf(fwdls.status, sizeof(fwdls.status), "Status|Success\n");
snprintf(fwdls.FwUpdateState, sizeof(fwdls.FwUpdateState), "FwUpdateState|Validation complete\n");
snprintf(fwdls.failureReason, sizeof(fwdls.failureReason), "FailureReason|");
if (((strncmp(maint, "true", 4)) == 0) && (0 == (strncmp(reboot_flag, "true", 4)))) {
char *pXconfCheckNow = calloc(10, sizeof(char));
FILE *canFile = fopen("/tmp/xconfchecknow_val", "r");
if (canFile != NULL) {
int fret = fscanf(canFile, "%9s", pXconfCheckNow);
if (fret <= 0) {
SWLOG_ERROR("Device_X_COMCAST_COM_Xcalibur_Client_xconfCheckNow: Error reading from file\n");
}
fclose(canFile);
}
else {
SWLOG_INFO("Device_X_COMCAST_COM_Xcalibur_Client_xconfCheckNow: File does not exist\n");
}
if (((strncmp(maint, "true", 4)) == 0) && (0 == (strncmp(reboot_flag, "true", 4))) && ((0 != strcasecmp("CANARY", pXconfCheckNow)) || (getTriggerType() != 3))) {
eventManager("MaintenanceMGR", MAINT_CRITICAL_UPDATE);
SWLOG_INFO("Posting Critical update");
}
if( pXconfCheckNow != NULL ) {
free(pXconfCheckNow);
}
if (0 == filePresentCheck(upgrade_file)) {
SWLOG_INFO("flashImage: Flashing completed. Deleting File:%s\n", upgrade_file);
unlink(upgrade_file);
Expand Down Expand Up @@ -276,6 +300,21 @@ int postFlash(const char *maint, const char *upgrade_file, int upgrade_type, con
}
sleep(5);
sync();
char* pXconfCheckNow = calloc(10, sizeof(char));
if (pXconfCheckNow == NULL) {
SWLOG_ERROR("Device_X_COMCAST_COM_Xcalibur_Client_xconfCheckNow: CALLOC failure\n");
return ret;
}
FILE *file = fopen("/tmp/xconfchecknow_val", "r");
if (file != NULL) {
if (fscanf(file, "%9s", pXconfCheckNow) == EOF) {
SWLOG_ERROR("Device_X_COMCAST_COM_Xcalibur_Client_xconfCheckNow: Error reading file\n");
}
fclose(file);
}
else {
SWLOG_INFO("Device_X_COMCAST_COM_Xcalibur_Client_xconfCheckNow: Error opening file for read\n");
}
if (0 != (filePresentCheck("/tmp/fw_preparing_to_reboot"))) {
fp = fopen("/tmp/fw_preparing_to_reboot", "w");
if (fp == NULL) {
Expand All @@ -284,7 +323,9 @@ int postFlash(const char *maint, const char *upgrade_file, int upgrade_type, con
SWLOG_INFO("Creating flag for preparing to reboot event sent to AS/EPG\n");
fclose(fp);
}
eventManager(FW_STATE_EVENT,FW_STATE_PREPARING_TO_REBOOT);
if ((0 != strcasecmp("CANARY", pXconfCheckNow)) || (getTriggerType() != 3)) {
eventManager(FW_STATE_EVENT,FW_STATE_PREPARING_TO_REBOOT);
}
}
if (upgrade_type == PDRI_UPGRADE) {
SWLOG_INFO("Reboot Not Needed after PDRI Upgrade..!\n");
Expand All @@ -295,7 +336,75 @@ int postFlash(const char *maint, const char *upgrade_file, int upgrade_type, con
fprintf(fp, "%s\n", upgrade_file);
fclose(fp);
}
if (0 == (strncmp(maint, "true", 4))) {
if ((0 == strcasecmp("CANARY", pXconfCheckNow)) && (getTriggerType() == 3)) {

char post_data[] = "{\"jsonrpc\":\"2.0\",\"id\":\"42\",\"method\": \"org.rdk.System.getPowerState\"}";
DownloadData DwnLoc = {NULL, 0, 0};
JSON *pJson = NULL;
JSON *pItem = NULL;
JSON *res_val = NULL;

if( MemDLAlloc( &DwnLoc, DEFAULT_DL_ALLOC ) == 0 ) {
if (0 != getJsonRpc(post_data, &DwnLoc)) {
SWLOG_INFO("%s :: isconnected JsonRpc call failed\n",__FUNCTION__);
free(pXconfCheckNow);
if (DwnLoc.pvOut != NULL) {
free(DwnLoc.pvOut);
}
return ret;
}
pJson = ParseJsonStr( (char *)DwnLoc.pvOut );
if( pJson != NULL ) {
pItem = GetJsonItem( pJson, "result" );
res_val = GetJsonItem( pItem, "powerState" );
}
else {
SWLOG_INFO("%s :: isconnected JsonRpc response is empty\n",__FUNCTION__);
free(pXconfCheckNow);
if (DwnLoc.pvOut != NULL) {
free(DwnLoc.pvOut);
}
return ret;
}
}

if(res_val != NULL) {
if(0 == strcasecmp("ON", res_val->valuestring)) {
SWLOG_INFO("Defer Reboot for Canary Firmware Upgrade since power state is ON\n");
t2CountNotify("SYS_INFO_DEFER_CANARY_REBOOT", 1);
}
#ifndef GTEST_ENABLE
else {
t2CountNotify("SYS_INFO_CANARY_Update", 1);
// Call rbus method - Device.X_RDKCENTRAL-COM_T2.UploadDCMReport
if( RBUS_ERROR_SUCCESS != invokeRbusDCMReport()) {
SWLOG_ERROR("Error in uploading telemetry report\n");
if( DwnLoc.pvOut != NULL ) {
free( DwnLoc.pvOut );
}
if( pJson != NULL ) {
FreeJson( pJson );
}
if ( pXconfCheckNow != NULL ) {
free(pXconfCheckNow);
}
return ret;
}
if (0 == (strncmp(reboot_flag, "true", 4))) {
SWLOG_INFO("Rebooting from RDK for Canary Firmware Upgrade\n");
v_secure_system("sh /rebootNow.sh -s '%s' -o '%s'","CANARY_Update", "Rebooting the box from RDK for Pending Canary Firmware Upgrade...");
}
}
#endif
}
if( DwnLoc.pvOut != NULL ) {
free( DwnLoc.pvOut );
}
if( pJson != NULL ) {
FreeJson( pJson );
}
}
else if (0 == (strncmp(maint, "true", 4))) {
eventManager("MaintenanceMGR", MAINT_REBOOT_REQUIRED);
if (0 == (strncmp(device_name, "PLATCO", 6)) && (0 == (strncmp(reboot_flag, "true", 4)))) {
SWLOG_INFO("Send notification to reboot in 10mins due to critical upgrade\n");
Expand Down Expand Up @@ -324,5 +433,8 @@ int postFlash(const char *maint, const char *upgrade_file, int upgrade_type, con
}
}
}
if( pXconfCheckNow != NULL ) {
free(pXconfCheckNow);
}
return 0;
}
72 changes: 72 additions & 0 deletions src/rbusInterface/rbusInterface.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2023 Comcast Cable Communications Management, LLC

Check failure on line 2 in src/rbusInterface/rbusInterface.c

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'src/rbusInterface/rbusInterface.c' (Match: lightning-js/solid/0.8.0, 14 lines, url: https://github.com/lightning-js/solid/archive/v0.8.0.tar.gz, file: src/core/node/index.ts)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef GTEST_ENABLE
#include <unistd.h>
#include "rbusInterface.h"
#else
#include "rbus_mock.h"
#include <stddef.h>
#endif
/* Description:Use for Rbus callback
* @param: handle : rbus handle
* @param: methodName : Method name
* @param: error : rbus return value type
* @param: param : rbus object
* @return void : NA
* */
static void t2EventHandler(rbusHandle_t handle, char const* methodName, rbusError_t error, rbusObject_t param)
{
SWLOG_INFO("Got %s rbus callback\n", methodName);
if (RBUS_ERROR_SUCCESS == error)
{
rbusValue_t uploadStatus = rbusObject_GetValue(param, "UPLOAD_STATUS");
if(uploadStatus)
{
SWLOG_INFO("Device.X_RDKCENTRAL-COM_T2.UploadDCMReport Upload Status = %s\n", rbusValue_GetString(uploadStatus, NULL));
}
}
}

/* Description: Trigger T2 upload
* @return rbusError_t : Return SUCCESS/FAILURE
* */
rbusError_t invokeRbusDCMReport()
{
rbusHandle_t rdkfwRbusHandle;
if (RBUS_ERROR_SUCCESS == rbus_open(&rdkfwRbusHandle, RDKFWUPGRADER_RBUS_HANDLE_NAME)) {
if (RBUS_ERROR_SUCCESS == rbusMethod_InvokeAsync(rdkfwRbusHandle, T2_UPLOAD, NULL, t2EventHandler, 0)) {
SWLOG_INFO("Waiting 60 sec to complete upload from Device.X_RDKCENTRAL-COM_T2.UploadDCMReport\n");
sleep(60);
}
else {
SWLOG_ERROR("Error in calling Device.X_RDKCENTRAL-COM_T2.UploadDCMReport\n");
return RBUS_ERROR_BUS_ERROR;
}
}
else {
SWLOG_ERROR("Error in opening rbus handle\n");
return RBUS_ERROR_BUS_ERROR;
}
if (RBUS_ERROR_SUCCESS != rbus_close(rdkfwRbusHandle)) {
SWLOG_ERROR("Rbus termination failed\n");
return RBUS_ERROR_BUS_ERROR;
}
return RBUS_ERROR_SUCCESS;
}

27 changes: 27 additions & 0 deletions src/rbusInterface/rbusInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2023 Comcast Cable Communications Management, LLC

Check failure on line 2 in src/rbusInterface/rbusInterface.h

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'src/rbusInterface/rbusInterface.h' (Match: lightning-js/solid/0.8.0, 14 lines, url: https://github.com/lightning-js/solid/archive/v0.8.0.tar.gz, file: src/core/node/index.ts)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef GTEST_ENABLE
#include "rbus/rbus.h"
#include "rdkv_cdl_log_wrapper.h"

#define RDKFWUPGRADER_RBUS_HANDLE_NAME "rdkfwRbus"
#define T2_UPLOAD "Device.X_RDKCENTRAL-COM_T2.UploadDCMReport"

rbusError_t invokeRbusDCMReport();
#endif
9 changes: 9 additions & 0 deletions src/rdkv_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ static pthread_mutex_t app_mode_status = PTHREAD_MUTEX_INITIALIZER;
static int app_mode = 1; // 1: fore ground and 0: background
int force_exit = 0; //This use when rdkvfwupgrader rcv appmode background and thottle speed is set to zero.

/* Description: Get trigger type info.
* @param: NA
* @return: int
* */
int getTriggerType()
{
return trigger_type;
}

/* Description: Set App mode.
* @param: state : set state
* @return: void
Expand Down
2 changes: 2 additions & 0 deletions src/rfcInterface/rfcinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ typedef struct rfcdetails {
#define RFC_FW_AUTO_EXCLUDE "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.FWUpdate.AutoExcluded.Enable"
#define RFC_DEBUGSRV "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Identity.DbgServices.Enable"

#define RFC_XCONF_CHECK_NOW "Device.X_COMCAST-COM_Xcalibur.Client.xconfCheckNow"

int getRFCSettings(Rfc_t *rfc_list);

int read_RFCProperty(char* type, const char* key, char *data, size_t datasize);
Expand Down
4 changes: 2 additions & 2 deletions unittest/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ AUTOMAKE_OPTIONS = subdir-objects
bin_PROGRAMS = rdkfw_device_status_gtest rdkfw_deviceutils_gtest rdkfw_main_gtest rdkfw_interface_gtest

# Define the include directories
COMMON_CPPFLAGS = -std=c++11 -I/usr/include/cjson -I../src -I../src/cedmInterface -I../src/deviceutils/ -I../src/rfcInterface/ -I../src/iarmInterface/ -I../src/include/ -I./mocks/ -I./deviceutils/ -DGTEST_ENABLE -DGTEST_BASIC -DIARM_ENABLED -DRFC_API_ENABLED -DT2_EVENT_ENABLED
COMMON_CPPFLAGS = -std=c++11 -I/usr/include/cjson -I../src -I../src/cedmInterface -I../src/deviceutils/ -I../src/rfcInterface/ -I../src/iarmInterface/ -I../src/include/ -I../src/rbusInterface/ -I./mocks/ -I./deviceutils/ -DGTEST_ENABLE -DGTEST_BASIC -DIARM_ENABLED -DRFC_API_ENABLED -DT2_EVENT_ENABLED

# Define the libraries to link against
COMMON_LDADD = -lgtest -lgtest_main -lgmock_main -lgmock -lcjson -lgcov
Expand All @@ -35,7 +35,7 @@ rdkfw_deviceutils_gtest_SOURCES = deviceutils/device_api_gtest.cpp deviceutils/d

rdkfw_main_gtest_SOURCES = basic_rdkv_main_gtest.cpp ../src/rdkv_main.c ../src/chunk.c ../src/flash.c ../src/json_process.c ../src/deviceutils/device_api.c deviceutils/json_parse.c ./mocks/deviceutils_mock.cpp ../src/deviceutils/deviceutils.c

rdkfw_interface_gtest_SOURCES = fwdl_interface_gtest.cpp ./mocks/interface_mock.cpp ../src/rfcInterface/rfcinterface.c ../src/iarmInterface/iarmInterface.c deviceutils/json_parse.c
rdkfw_interface_gtest_SOURCES = fwdl_interface_gtest.cpp ./mocks/interface_mock.cpp ../src/rfcInterface/rfcinterface.c ../src/iarmInterface/iarmInterface.c ./mocks/rbus_mock.c ../src/rbusInterface/rbusInterface.c deviceutils/json_parse.c

# Apply common properties to each program
rdkfw_device_status_gtest_CPPFLAGS = $(COMMON_CPPFLAGS)
Expand Down
6 changes: 6 additions & 0 deletions unittest/fwdl_interface_gtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
extern "C" {
#include "rfcinterface.h"
#include "iarmInterface.h"
#include "./mocks/rbus_mock.h"
void DwnlStopEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len);
}
#include "./mocks/interface_mock.h"
Expand Down Expand Up @@ -265,6 +266,11 @@ TEST_F(InterfaceTestFixture, TestName_eventManagerFail)
eventManager(IMG_DWL_EVENT, "2");
EXPECT_EQ(0, 0);
}
TEST_F(InterfaceTestFixture, TestName_invokeRbusDCMReport)
{
rbusError_t status = invokeRbusDCMReport();
EXPECT_EQ(status, RBUS_ERROR_SUCCESS);
}

GTEST_API_ int main(int argc, char *argv[]){
char testresults_fullfilepath[GTEST_REPORT_FILEPATH_SIZE];
Expand Down
Loading
Loading