From 42b8f64baa16a829f4e9630bf5ab76c518e16997 Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Sun, 25 Jan 2026 14:25:06 +0530 Subject: [PATCH 01/28] stackmode code --- configure.ac | 17 ++ source/scripts/init/Makefile.am | 4 + source/scripts/init/stackmode/Makefile.am | 27 +++ source/scripts/init/stackmode/stackmode.c | 193 ++++++++++++++++++ source/scripts/init/stackmode/stackmode.h | 28 +++ source/scripts/init/stackmode/stackmode_log.c | 46 +++++ source/scripts/init/stackmode/stackmode_log.h | 50 +++++ 7 files changed, 365 insertions(+) create mode 100644 source/scripts/init/stackmode/Makefile.am create mode 100644 source/scripts/init/stackmode/stackmode.c create mode 100644 source/scripts/init/stackmode/stackmode.h create mode 100644 source/scripts/init/stackmode/stackmode_log.c create mode 100644 source/scripts/init/stackmode/stackmode_log.h diff --git a/configure.ac b/configure.ac index 2b2e6e00..50be4bb5 100644 --- a/configure.ac +++ b/configure.ac @@ -226,6 +226,23 @@ AC_ARG_ENABLE([hotspot], [enable_hotspot=true]) AM_CONDITIONAL([ENABLE_HOTSPOT_SERVICE], [test x$enable_hotspot = xtrue]) +AC_ARG_ENABLE([stackmode], + AS_HELP_STRING([--enable-stackmode],[Enable StackMode support]), + [ + case "${enableval}" in + yes) enable_stackmode=true ;; + no) enable_stackmode=false ;; + *) AC_MSG_ERROR([bad value ${enableval} for --enable-stackmode]) ;; + esac + ], + [enable_stackmode=false]) +AM_CONDITIONAL([ENABLE_STACKMODE_SERVICE], [test x$enable_stackmode = xtrue]) + +AM_COND_IF( [ENABLE_STACKMODE_SERVICE], [ +AC_CONFIG_FILES([ + source/scripts/init/stackmode/Makefile +])] ) + AC_CONFIG_FILES( Makefile source/Makefile diff --git a/source/scripts/init/Makefile.am b/source/scripts/init/Makefile.am index 7aa4259f..65e68cc2 100644 --- a/source/scripts/init/Makefile.am +++ b/source/scripts/init/Makefile.am @@ -18,3 +18,7 @@ ########################################################################## #SUBDIRS = c_registration src service.d syslog_conf SUBDIRS = c_registration src + +if ENABLE_STACKMODE_SERVICE +SUBDIRS += stackmode +endif diff --git a/source/scripts/init/stackmode/Makefile.am b/source/scripts/init/stackmode/Makefile.am new file mode 100644 index 00000000..4d359a78 --- /dev/null +++ b/source/scripts/init/stackmode/Makefile.am @@ -0,0 +1,27 @@ +########################################################################## +# If not stated otherwise in this file or this component's Licenses.txt +# file the following copyright and licenses apply: +# +# Copyright 2026 RDK Management +# +# 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. +########################################################################## +AM_CFLAGS = -Wall -Werror + +bin_PROGRAMS = stackmode + +stackmode_SOURCES = stackmode.c stackmode_log.c + +stackmode_CPPFLAGS = -I$(top_srcdir)/source/stackmode + +stackmode_LDADD = -lsyscfg -lrdkloggers -lhal_platform diff --git a/source/scripts/init/stackmode/stackmode.c b/source/scripts/init/stackmode/stackmode.c new file mode 100644 index 00000000..c63408ea --- /dev/null +++ b/source/scripts/init/stackmode/stackmode.c @@ -0,0 +1,193 @@ +#include +#include +#include +#include +#include "stackmode.h" +#include "stackmode_log.h" +#include "syscfg/syscfg.h" +#include "platform_hal.h" + +#if defined(_STACKMODE_PRODUCT_REQ_) +#define BUFLEN_32 32 +#define BUFLEN_256 256 +#define MAX_RETRY 3 +#define RETRY_DELAY_SEC 1 +#define PARTNER_ID_FILE "/nvram/.partner_ID" +#define SETSTACKMODE_FILE "/nvram/setstackmode" +#define STACKMODE_BUSINESS "business-commercial-mode" +#define STACKMODE_RESIDENTIAL "residential-mode" + +/** + * @brief Trim trailing newline from string + * @param str String to trim + */ +static inline void trim_newline(char *str) +{ + size_t len = strlen(str); + if (len > 0 && str[len - 1] == '\n') + { + str[len - 1] = '\0'; + } +} + +/** + * @brief Get partner ID with fallback mechanism + * @param pValue Buffer to store the partner ID + * @param size Size of the buffer + * @return 0 on success, -1 on failure + */ +int get_setstackmode(char *pValue, int size) +{ + FILE *fp = NULL; + char buffer[BUFLEN_256] = {0}; + int retry; + + if (!pValue || size <= 0) + { + STACKMODE_ERROR("%s: Invalid parameters (pValue=%p, size=%d)\n", __FUNCTION__, pValue, size); + return -1; + } + + STACKMODE_DEBUG("%s: Starting partner ID retrieval\n", __FUNCTION__); + + // 1. Try reading from file first + if (access(PARTNER_ID_FILE, R_OK) == 0) + { + STACKMODE_DEBUG("%s: Attempting to read from file: %s\n", __FUNCTION__, PARTNER_ID_FILE); + fp = fopen(PARTNER_ID_FILE, "r"); + if (fp) + { + if (fgets(buffer, sizeof(buffer), fp)) + { + trim_newline(buffer); + + if (buffer[0] != '\0') + { + strncpy(pValue, buffer, size - 1); + pValue[size - 1] = '\0'; + fclose(fp); + STACKMODE_INFO("%s: Partner ID retrieved from file: %s\n", __FUNCTION__, pValue); + return 0; + } + } + fclose(fp); + } + else + { + STACKMODE_WARN("%s: Failed to open file: %s\n", __FUNCTION__, PARTNER_ID_FILE); + } + } + else + { + STACKMODE_DEBUG("%s: File not accessible: %s, trying HAL API\n", __FUNCTION__, PARTNER_ID_FILE); + } + + // 2. Try HAL API with retries + for (retry = 0; retry < MAX_RETRY; retry++) + { + STACKMODE_DEBUG("%s: Attempting HAL API call (attempt %d/%d)\n", __FUNCTION__, retry + 1, MAX_RETRY); + if (platform_hal_getFactoryPartnerId(pValue) == 0 && pValue[0] != '\0') + { + STACKMODE_INFO("%s: Partner ID retrieved from HAL API: %s (attempt %d)\n", __FUNCTION__, pValue, retry + 1); + return 0; + } + if (retry < MAX_RETRY - 1) + { + sleep(RETRY_DELAY_SEC); + } + } + STACKMODE_WARN("%s: HAL API failed after %d retries, trying syscfg\n", __FUNCTION__, MAX_RETRY); + + // 3. Fallback to syscfg + STACKMODE_DEBUG("%s: Attempting syscfg_get for PartnerID\n", __FUNCTION__); + if (syscfg_get(NULL, "PartnerID", pValue, size) == 0 && pValue[0] != '\0') + { + STACKMODE_INFO("%s: Partner ID retrieved from syscfg: %s\n", __FUNCTION__, pValue); + return 0; + } + + STACKMODE_ERROR("%s: Failed to retrieve partner ID from all sources (File/HAL/Syscfg)\n", __FUNCTION__); + return -1; +} + +int main(int argc, char *argv[]) +{ + char partnerId[BUFLEN_256] = {0}; + bool isBci = false; + FILE *fp = NULL; + int ret; + + // Initialize RDK logger + if (!stackmode_log_init()) + { + fprintf(stderr, "WARN: stackmode_log_init() failed, continuing without RDK logging\n"); + } + + STACKMODE_INFO("StackMode SetStackMode Utility started\n"); + + if (get_setstackmode(partnerId, sizeof(partnerId)) == 0) + { + isBci = (strcmp(partnerId, "comcast-business") == 0); + + STACKMODE_INFO("Partner ID: %s | Is BCI: %s\n", partnerId, isBci ? "Yes" : "No"); + + if (isBci) + { + // Create marker file for business-commercial mode + fp = fopen(SETSTACKMODE_FILE, "w"); + if (fp) + { + fclose(fp); + STACKMODE_INFO("Created marker file: %s\n", SETSTACKMODE_FILE); + } + else + { + STACKMODE_WARN("Failed to create marker file: %s\n", SETSTACKMODE_FILE); + } + + // Set stackmode to business-commercial-mode + ret = syscfg_set(NULL, "stackmode", STACKMODE_BUSINESS); + if (ret == 0) + { + syscfg_commit(); + STACKMODE_INFO("Set stackmode to: %s\n", STACKMODE_BUSINESS); + } + else + { + STACKMODE_ERROR("Failed to set stackmode to: %s\n", STACKMODE_BUSINESS); + } + } + else + { + // Set stackmode to residential-mode + ret = syscfg_set(NULL, "stackmode", STACKMODE_RESIDENTIAL); + if (ret == 0) + { + syscfg_commit(); + STACKMODE_INFO("Set stackmode to: %s\n", STACKMODE_RESIDENTIAL); + } + else + { + STACKMODE_ERROR("Failed to set stackmode to: %s\n", STACKMODE_RESIDENTIAL); + } + } + + stackmode_log_deinit(); + return 0; + } + + STACKMODE_ERROR("Failed to retrieve Partner ID\n"); + + stackmode_log_deinit(); + return 1; +} + +#else + +int main(int argc, char *argv[]) +{ + fprintf(stderr, "ERROR: StackMode utility is not enabled (_STACKMODE_PRODUCT_REQ_ not defined)\n"); + return 1; +} + +#endif diff --git a/source/scripts/init/stackmode/stackmode.h b/source/scripts/init/stackmode/stackmode.h new file mode 100644 index 00000000..b26db971 --- /dev/null +++ b/source/scripts/init/stackmode/stackmode.h @@ -0,0 +1,28 @@ +#ifndef _COMMON_STACKMODE_H_ +#define _COMMON_STACKMODE_H_ + +#include + +#ifdef _STACKMODE_PRODUCT_REQ_ + +/** + * @brief Get partner ID and set stack mode with fallback mechanism + * + * This function attempts to retrieve the partner ID using the following priority: + * 1. Read from /nvram/.partner_ID file + * 2. HAL API (platform_hal_getFactoryPartnerId) with 3 retries + * 3. Read from syscfg (PartnerID) + * + * Based on the partner ID, sets the stack mode: + * - "comcast-business" -> business-commercial-mode (creates /nvram/setstackmode marker) + * - Other -> residential-mode + * + * @param pValue Buffer to store the partner ID + * @param size Size of the buffer + * @return 0 on success, -1 on failure + */ +int get_setstackmode(char *pValue, int size); + +#endif + +#endif /* _COMMON_STACKMODE_H_ */ diff --git a/source/scripts/init/stackmode/stackmode_log.c b/source/scripts/init/stackmode/stackmode_log.c new file mode 100644 index 00000000..a2b9d6a3 --- /dev/null +++ b/source/scripts/init/stackmode/stackmode_log.c @@ -0,0 +1,46 @@ +/* + * If not stated otherwise in this file or this component's Licenses.txt file the + * following copyright and licenses apply: + * + * Copyright 2026 RDK Management + * + * 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. +*/ + +#include +#include "stackmode_log.h" + +bool stackmode_log_init(void) +{ + if (rdk_logger_init(DEBUG_INI_PATH) != 0) + { + fprintf(stderr, "Warning: RDK logger initialization failed for %s\n", DEBUG_INI_PATH); + return false; + } + + STACKMODE_INFO("%s: Logging initialized successfully\n", __FUNCTION__); + return true; +} + +bool stackmode_log_deinit(void) +{ + STACKMODE_DEBUG("%s: Deinitializing logging\n", __FUNCTION__); + + if (rdk_logger_deinit() != 0) + { + fprintf(stderr, "Warning: RDK logger deinitialization failed\n"); + return false; + } + + return true; +} diff --git a/source/scripts/init/stackmode/stackmode_log.h b/source/scripts/init/stackmode/stackmode_log.h new file mode 100644 index 00000000..0a237ba1 --- /dev/null +++ b/source/scripts/init/stackmode/stackmode_log.h @@ -0,0 +1,50 @@ +/* + * If not stated otherwise in this file or this component's Licenses.txt file the + * following copyright and licenses apply: + * + * Copyright 2026 RDK Management + * + * 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. +*/ + +#ifndef _STACKMODE_LOG_H_ +#define _STACKMODE_LOG_H_ + +#include +#include "rdk_debug.h" + +#define LOG_MODULE "LOG.RDK.STACKMODE" +#define DEBUG_INI_PATH "/etc/debug.ini" + +// Logging macros +#define STACKMODE_LOG(level, ...) \ + RDK_LOG(level, LOG_MODULE, __VA_ARGS__) + +#define STACKMODE_ERROR(...) STACKMODE_LOG(RDK_LOG_ERROR, __VA_ARGS__) +#define STACKMODE_WARN(...) STACKMODE_LOG(RDK_LOG_WARN, __VA_ARGS__) +#define STACKMODE_INFO(...) STACKMODE_LOG(RDK_LOG_INFO, __VA_ARGS__) +#define STACKMODE_DEBUG(...) STACKMODE_LOG(RDK_LOG_DEBUG, __VA_ARGS__) + +/** + * @brief Initialize StackMode logging + * @return true on success, false on failure + */ +bool stackmode_log_init(void); + +/** + * @brief Deinitialize StackMode logging + * @return true on success, false on failure + */ +bool stackmode_log_deinit(void); + +#endif /* _STACKMODE_LOG_H_ */ From a6cc5c5786e0f7520eaa02c16c1aabd76728fb52 Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Sun, 25 Jan 2026 14:35:27 +0530 Subject: [PATCH 02/28] stackmode code --- source/scripts/init/stackmode/stackmode.c | 4 ++-- source/scripts/init/stackmode/stackmode.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/scripts/init/stackmode/stackmode.c b/source/scripts/init/stackmode/stackmode.c index c63408ea..a029ba10 100644 --- a/source/scripts/init/stackmode/stackmode.c +++ b/source/scripts/init/stackmode/stackmode.c @@ -7,7 +7,7 @@ #include "syscfg/syscfg.h" #include "platform_hal.h" -#if defined(_STACKMODE_PRODUCT_REQ_) +#if defined(_ONESTACK_PRODUCT_REQ_) #define BUFLEN_32 32 #define BUFLEN_256 256 #define MAX_RETRY 3 @@ -186,7 +186,7 @@ int main(int argc, char *argv[]) int main(int argc, char *argv[]) { - fprintf(stderr, "ERROR: StackMode utility is not enabled (_STACKMODE_PRODUCT_REQ_ not defined)\n"); + fprintf(stderr, "ERROR: StackMode utility is not enabled (_ONESTACK_PRODUCT_REQ_ not defined)\n"); return 1; } diff --git a/source/scripts/init/stackmode/stackmode.h b/source/scripts/init/stackmode/stackmode.h index b26db971..0f7b75b7 100644 --- a/source/scripts/init/stackmode/stackmode.h +++ b/source/scripts/init/stackmode/stackmode.h @@ -3,7 +3,7 @@ #include -#ifdef _STACKMODE_PRODUCT_REQ_ +#ifdef _ONESTACK_PRODUCT_REQ_ /** * @brief Get partner ID and set stack mode with fallback mechanism From 0278668c0d58df8247eeada847b4179c6733fe4a Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Tue, 27 Jan 2026 20:49:30 +0530 Subject: [PATCH 03/28] Updating code --- configure.ac | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/configure.ac b/configure.ac index 50be4bb5..e3601391 100644 --- a/configure.ac +++ b/configure.ac @@ -46,6 +46,27 @@ AC_ARG_ENABLE([unitTestDockerSupport], AM_CONDITIONAL([UNIT_TEST_DOCKER_SUPPORT], [test x$UNIT_TEST_DOCKER_SUPPORT = xtrue]) +AC_ARG_ENABLE([stackmode], + AS_HELP_STRING([--enable-stackmode],[enable StackMode support (default is no)]), + [ + case "${enableval}" in + yes) + ENABLE_STACKMODE_SERVICE=true + m4_if(m4_sysval,[0],[AC_CONFIG_FILES([source/scripts/init/stackmode/Makefile])]) + ;; + no) + ENABLE_STACKMODE_SERVICE=false + AC_MSG_WARN([StackMode support is disabled]) + ;; + *) + AC_MSG_ERROR([bad value ${enableval} for --enable-stackmode]) + ;; + esac + ], + [AC_MSG_WARN([StackMode support is disabled])]) + +AM_CONDITIONAL([ENABLE_STACKMODE_SERVICE], [test x$ENABLE_STACKMODE_SERVICE = xtrue]) + AC_PREFIX_DEFAULT(`pwd`) AC_ENABLE_SHARED AC_DISABLE_STATIC @@ -226,23 +247,6 @@ AC_ARG_ENABLE([hotspot], [enable_hotspot=true]) AM_CONDITIONAL([ENABLE_HOTSPOT_SERVICE], [test x$enable_hotspot = xtrue]) -AC_ARG_ENABLE([stackmode], - AS_HELP_STRING([--enable-stackmode],[Enable StackMode support]), - [ - case "${enableval}" in - yes) enable_stackmode=true ;; - no) enable_stackmode=false ;; - *) AC_MSG_ERROR([bad value ${enableval} for --enable-stackmode]) ;; - esac - ], - [enable_stackmode=false]) -AM_CONDITIONAL([ENABLE_STACKMODE_SERVICE], [test x$enable_stackmode = xtrue]) - -AM_COND_IF( [ENABLE_STACKMODE_SERVICE], [ -AC_CONFIG_FILES([ - source/scripts/init/stackmode/Makefile -])] ) - AC_CONFIG_FILES( Makefile source/Makefile From 69d38e48f4f858f01b98249ae142725eeb7e0497 Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Wed, 28 Jan 2026 06:03:51 +0530 Subject: [PATCH 04/28] Updating code --- configure.ac | 2 +- source/scripts/init/{ => src}/stackmode/Makefile.am | 0 source/scripts/init/{ => src}/stackmode/stackmode.c | 0 source/scripts/init/{ => src}/stackmode/stackmode.h | 0 source/scripts/init/{ => src}/stackmode/stackmode_log.c | 0 source/scripts/init/{ => src}/stackmode/stackmode_log.h | 0 6 files changed, 1 insertion(+), 1 deletion(-) rename source/scripts/init/{ => src}/stackmode/Makefile.am (100%) rename source/scripts/init/{ => src}/stackmode/stackmode.c (100%) rename source/scripts/init/{ => src}/stackmode/stackmode.h (100%) rename source/scripts/init/{ => src}/stackmode/stackmode_log.c (100%) rename source/scripts/init/{ => src}/stackmode/stackmode_log.h (100%) diff --git a/configure.ac b/configure.ac index e3601391..58710009 100644 --- a/configure.ac +++ b/configure.ac @@ -52,7 +52,7 @@ AC_ARG_ENABLE([stackmode], case "${enableval}" in yes) ENABLE_STACKMODE_SERVICE=true - m4_if(m4_sysval,[0],[AC_CONFIG_FILES([source/scripts/init/stackmode/Makefile])]) + m4_if(m4_sysval,[0],[AC_CONFIG_FILES([source/scripts/init/src/stackmode/Makefile])]) ;; no) ENABLE_STACKMODE_SERVICE=false diff --git a/source/scripts/init/stackmode/Makefile.am b/source/scripts/init/src/stackmode/Makefile.am similarity index 100% rename from source/scripts/init/stackmode/Makefile.am rename to source/scripts/init/src/stackmode/Makefile.am diff --git a/source/scripts/init/stackmode/stackmode.c b/source/scripts/init/src/stackmode/stackmode.c similarity index 100% rename from source/scripts/init/stackmode/stackmode.c rename to source/scripts/init/src/stackmode/stackmode.c diff --git a/source/scripts/init/stackmode/stackmode.h b/source/scripts/init/src/stackmode/stackmode.h similarity index 100% rename from source/scripts/init/stackmode/stackmode.h rename to source/scripts/init/src/stackmode/stackmode.h diff --git a/source/scripts/init/stackmode/stackmode_log.c b/source/scripts/init/src/stackmode/stackmode_log.c similarity index 100% rename from source/scripts/init/stackmode/stackmode_log.c rename to source/scripts/init/src/stackmode/stackmode_log.c diff --git a/source/scripts/init/stackmode/stackmode_log.h b/source/scripts/init/src/stackmode/stackmode_log.h similarity index 100% rename from source/scripts/init/stackmode/stackmode_log.h rename to source/scripts/init/src/stackmode/stackmode_log.h From 7e422545e72e708d46ee069bd130ac741c371d3e Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Wed, 28 Jan 2026 11:40:25 +0530 Subject: [PATCH 05/28] updating code --- source/scripts/init/Makefile.am | 3 --- 1 file changed, 3 deletions(-) diff --git a/source/scripts/init/Makefile.am b/source/scripts/init/Makefile.am index 65e68cc2..4ec750a7 100644 --- a/source/scripts/init/Makefile.am +++ b/source/scripts/init/Makefile.am @@ -19,6 +19,3 @@ #SUBDIRS = c_registration src service.d syslog_conf SUBDIRS = c_registration src -if ENABLE_STACKMODE_SERVICE -SUBDIRS += stackmode -endif From e57f2f84d77a85588762a5377f4456f28602cac3 Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Wed, 28 Jan 2026 15:14:28 +0530 Subject: [PATCH 06/28] Updating code --- .../apply_system_defaults.c | 30 ++++++++++++++ source/scripts/init/src/stackmode/stackmode.c | 41 ++++++------------- source/scripts/init/system/utopia_init_arm.sh | 6 +++ 3 files changed, 49 insertions(+), 28 deletions(-) diff --git a/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c b/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c index 0a589550..fa926516 100644 --- a/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c +++ b/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c @@ -3529,6 +3529,36 @@ static void getPartnerIdWithRetry(char* buf, char* PartnerID) APPLY_PRINT("%s - Failed to apply_value_to_sysevent block into sysevent for '%s'\n", __FUNCTION__, PartnerID); } +#if defined(_ONESTACK_PRODUCT_REQ_) + // Set stackmode based on /nvram/setstackmode marker file + if (access("/nvram/setstackmode", F_OK) == 0) + { + // File exists, set to business-commercial-mode + if (syscfg_set(NULL, "stackmode", "business-commercial-mode") == 0) + { + syscfg_commit(); + APPLY_PRINT("%s - Set stackmode to business-commercial-mode\n", __FUNCTION__); + } + else + { + APPLY_PRINT("%s - Failed to set stackmode to business-commercial-mode\n", __FUNCTION__); + } + } + else + { + // File does not exist, set to residential-mode + if (syscfg_set(NULL, "stackmode", "residential-mode") == 0) + { + syscfg_commit(); + APPLY_PRINT("%s - Set stackmode to residential-mode\n", __FUNCTION__); + } + else + { + APPLY_PRINT("%s - Failed to set stackmode to residential-mode\n", __FUNCTION__); + } + } +#endif + sysevent_close(global_fd, global_id); return(0); diff --git a/source/scripts/init/src/stackmode/stackmode.c b/source/scripts/init/src/stackmode/stackmode.c index a029ba10..5e72ac0a 100644 --- a/source/scripts/init/src/stackmode/stackmode.c +++ b/source/scripts/init/src/stackmode/stackmode.c @@ -10,7 +10,7 @@ #if defined(_ONESTACK_PRODUCT_REQ_) #define BUFLEN_32 32 #define BUFLEN_256 256 -#define MAX_RETRY 3 +#define MAX_RETRY 2 #define RETRY_DELAY_SEC 1 #define PARTNER_ID_FILE "/nvram/.partner_ID" #define SETSTACKMODE_FILE "/nvram/setstackmode" @@ -66,6 +66,16 @@ int get_setstackmode(char *pValue, int size) strncpy(pValue, buffer, size - 1); pValue[size - 1] = '\0'; fclose(fp); + + // Copy content to /tmp/ for record keeping + FILE *record_fp = fopen("/tmp/.partner_ID_record", "w"); + if (record_fp) + { + fprintf(record_fp, "%s\n", pValue); + fclose(record_fp); + STACKMODE_DEBUG("%s: Partner ID copied to /tmp/.partner_ID_record\n", __FUNCTION__); + } + STACKMODE_INFO("%s: Partner ID retrieved from file: %s\n", __FUNCTION__, pValue); return 0; } @@ -115,7 +125,6 @@ int main(int argc, char *argv[]) char partnerId[BUFLEN_256] = {0}; bool isBci = false; FILE *fp = NULL; - int ret; // Initialize RDK logger if (!stackmode_log_init()) @@ -144,34 +153,10 @@ int main(int argc, char *argv[]) { STACKMODE_WARN("Failed to create marker file: %s\n", SETSTACKMODE_FILE); } - - // Set stackmode to business-commercial-mode - ret = syscfg_set(NULL, "stackmode", STACKMODE_BUSINESS); - if (ret == 0) - { - syscfg_commit(); - STACKMODE_INFO("Set stackmode to: %s\n", STACKMODE_BUSINESS); - } - else - { - STACKMODE_ERROR("Failed to set stackmode to: %s\n", STACKMODE_BUSINESS); - } - } - else - { - // Set stackmode to residential-mode - ret = syscfg_set(NULL, "stackmode", STACKMODE_RESIDENTIAL); - if (ret == 0) - { - syscfg_commit(); - STACKMODE_INFO("Set stackmode to: %s\n", STACKMODE_RESIDENTIAL); - } - else - { - STACKMODE_ERROR("Failed to set stackmode to: %s\n", STACKMODE_RESIDENTIAL); - } } + STACKMODE_INFO("Stackmode configuration will be handled by apply_system_defaults\n"); + stackmode_log_deinit(); return 0; } diff --git a/source/scripts/init/system/utopia_init_arm.sh b/source/scripts/init/system/utopia_init_arm.sh index 65f76e52..001cf92e 100755 --- a/source/scripts/init/system/utopia_init_arm.sh +++ b/source/scripts/init/system/utopia_init_arm.sh @@ -233,6 +233,12 @@ if [ -f $SYSCFG_BKUP_FILE ]; then CheckAndReCreateDB fi else + # Call stackmode binary to set stackmode marker + if [ -x /usr/bin/stackmode ]; then + echo "[utopia][init] Calling stackmode binary to configure stack mode" + /usr/bin/stackmode + fi + echo -n > $SYSCFG_FILE syscfg_create -f $SYSCFG_FILE if [ $? != 0 ]; then From 7dad4055945bbd480cd0ceb70a3e02197eadb5f2 Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Thu, 29 Jan 2026 08:07:46 +0530 Subject: [PATCH 07/28] Updating code --- source/scripts/init/system/utopia_init_arm.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/scripts/init/system/utopia_init_arm.sh b/source/scripts/init/system/utopia_init_arm.sh index 001cf92e..7204d597 100755 --- a/source/scripts/init/system/utopia_init_arm.sh +++ b/source/scripts/init/system/utopia_init_arm.sh @@ -237,6 +237,8 @@ else if [ -x /usr/bin/stackmode ]; then echo "[utopia][init] Calling stackmode binary to configure stack mode" /usr/bin/stackmode + else + echo "[utopia][init] stackmode binary not found, skipping stack mode configuration" fi echo -n > $SYSCFG_FILE From d59b5a2a6b253637a5ce42ac4ba15a185dc23de3 Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Thu, 29 Jan 2026 08:14:42 +0530 Subject: [PATCH 08/28] Updating code --- configure.ac | 8 ++++++-- source/scripts/init/src/stackmode/Makefile.am | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 58710009..57bb8282 100644 --- a/configure.ac +++ b/configure.ac @@ -52,7 +52,6 @@ AC_ARG_ENABLE([stackmode], case "${enableval}" in yes) ENABLE_STACKMODE_SERVICE=true - m4_if(m4_sysval,[0],[AC_CONFIG_FILES([source/scripts/init/src/stackmode/Makefile])]) ;; no) ENABLE_STACKMODE_SERVICE=false @@ -63,7 +62,7 @@ AC_ARG_ENABLE([stackmode], ;; esac ], - [AC_MSG_WARN([StackMode support is disabled])]) + [ENABLE_STACKMODE_SERVICE=false]) AM_CONDITIONAL([ENABLE_STACKMODE_SERVICE], [test x$ENABLE_STACKMODE_SERVICE = xtrue]) @@ -247,6 +246,11 @@ AC_ARG_ENABLE([hotspot], [enable_hotspot=true]) AM_CONDITIONAL([ENABLE_HOTSPOT_SERVICE], [test x$enable_hotspot = xtrue]) +AM_COND_IF( [ENABLE_STACKMODE_SERVICE], [ +AC_CONFIG_FILES([ + source/scripts/init/src/stackmode/Makefile +])] ) + AC_CONFIG_FILES( Makefile source/Makefile diff --git a/source/scripts/init/src/stackmode/Makefile.am b/source/scripts/init/src/stackmode/Makefile.am index 4d359a78..021ecbd6 100644 --- a/source/scripts/init/src/stackmode/Makefile.am +++ b/source/scripts/init/src/stackmode/Makefile.am @@ -22,6 +22,8 @@ bin_PROGRAMS = stackmode stackmode_SOURCES = stackmode.c stackmode_log.c -stackmode_CPPFLAGS = -I$(top_srcdir)/source/stackmode +stackmode_CPPFLAGS = -I$(top_srcdir)/source/scripts/init/src/stackmode \ + -I$(top_srcdir)/source/syscfg \ + -I$(top_srcdir)/source/include -stackmode_LDADD = -lsyscfg -lrdkloggers -lhal_platform +stackmode_LDADD = -lsyscfg -lrdkloggers -lhal_platform -lpthread From 4a7d46dd12d6eff4110a0b573a2d26126e6833be Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Thu, 29 Jan 2026 20:33:46 +0530 Subject: [PATCH 09/28] Updating Code --- configure.ac | 26 +------------------------- source/scripts/init/Makefile.am | 1 - source/scripts/init/src/Makefile.am | 6 +++--- 3 files changed, 4 insertions(+), 29 deletions(-) diff --git a/configure.ac b/configure.ac index 57bb8282..825fa18e 100644 --- a/configure.ac +++ b/configure.ac @@ -46,26 +46,6 @@ AC_ARG_ENABLE([unitTestDockerSupport], AM_CONDITIONAL([UNIT_TEST_DOCKER_SUPPORT], [test x$UNIT_TEST_DOCKER_SUPPORT = xtrue]) -AC_ARG_ENABLE([stackmode], - AS_HELP_STRING([--enable-stackmode],[enable StackMode support (default is no)]), - [ - case "${enableval}" in - yes) - ENABLE_STACKMODE_SERVICE=true - ;; - no) - ENABLE_STACKMODE_SERVICE=false - AC_MSG_WARN([StackMode support is disabled]) - ;; - *) - AC_MSG_ERROR([bad value ${enableval} for --enable-stackmode]) - ;; - esac - ], - [ENABLE_STACKMODE_SERVICE=false]) - -AM_CONDITIONAL([ENABLE_STACKMODE_SERVICE], [test x$ENABLE_STACKMODE_SERVICE = xtrue]) - AC_PREFIX_DEFAULT(`pwd`) AC_ENABLE_SHARED AC_DISABLE_STATIC @@ -246,11 +226,6 @@ AC_ARG_ENABLE([hotspot], [enable_hotspot=true]) AM_CONDITIONAL([ENABLE_HOTSPOT_SERVICE], [test x$enable_hotspot = xtrue]) -AM_COND_IF( [ENABLE_STACKMODE_SERVICE], [ -AC_CONFIG_FILES([ - source/scripts/init/src/stackmode/Makefile -])] ) - AC_CONFIG_FILES( Makefile source/Makefile @@ -270,6 +245,7 @@ AC_CONFIG_FILES( source/scripts/init/src/apply_system_defaults/Makefile source/scripts/init/src/apply_system_defaults_psm/Makefile source/scripts/init/src/execute_dir/Makefile + source/scripts/init/src/stackmode/Makefile source/services/Makefile source/services/lib/Makefile source/service_ipv6/Makefile diff --git a/source/scripts/init/Makefile.am b/source/scripts/init/Makefile.am index 4ec750a7..7aa4259f 100644 --- a/source/scripts/init/Makefile.am +++ b/source/scripts/init/Makefile.am @@ -18,4 +18,3 @@ ########################################################################## #SUBDIRS = c_registration src service.d syslog_conf SUBDIRS = c_registration src - diff --git a/source/scripts/init/src/Makefile.am b/source/scripts/init/src/Makefile.am index ebac695a..e0dc6802 100644 --- a/source/scripts/init/src/Makefile.am +++ b/source/scripts/init/src/Makefile.am @@ -17,7 +17,7 @@ # limitations under the License. ########################################################################## if PARTNER_DEFAULT_EXT -SUBDIRS = execute_dir apply_system_defaults apply_system_defaults_psm +SUBDIRS = execute_dir apply_system_defaults apply_system_defaults_psm stackmode else -SUBDIRS = execute_dir apply_system_defaults -endif +SUBDIRS = execute_dir apply_system_defaults stackmode +endif \ No newline at end of file From 3eb2621e2b4967271bd0a3809d352c5168fbdcec Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Thu, 29 Jan 2026 21:49:27 +0530 Subject: [PATCH 10/28] Updating Code --- source/scripts/init/src/stackmode/Makefile.am | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/scripts/init/src/stackmode/Makefile.am b/source/scripts/init/src/stackmode/Makefile.am index 021ecbd6..93a19cae 100644 --- a/source/scripts/init/src/stackmode/Makefile.am +++ b/source/scripts/init/src/stackmode/Makefile.am @@ -26,4 +26,7 @@ stackmode_CPPFLAGS = -I$(top_srcdir)/source/scripts/init/src/stackmode \ -I$(top_srcdir)/source/syscfg \ -I$(top_srcdir)/source/include -stackmode_LDADD = -lsyscfg -lrdkloggers -lhal_platform -lpthread +stackmode_LDADD = $(top_builddir)/source/syscfg/lib/libsyscfg.la \ + -lrdkloggers \ + -lhal_platform \ + -lpthread From bc95e695df1f6bc2565e91519bb70a4e461bcb1c Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Fri, 30 Jan 2026 12:46:57 +0530 Subject: [PATCH 11/28] Updating Code --- source/scripts/init/src/stackmode/Makefile.am | 1 - .../init/src/stackmode/stackmode_log.c | 55 ++++++++++++++++--- .../init/src/stackmode/stackmode_log.h | 18 +++--- 3 files changed, 55 insertions(+), 19 deletions(-) diff --git a/source/scripts/init/src/stackmode/Makefile.am b/source/scripts/init/src/stackmode/Makefile.am index 93a19cae..68a2cd28 100644 --- a/source/scripts/init/src/stackmode/Makefile.am +++ b/source/scripts/init/src/stackmode/Makefile.am @@ -27,6 +27,5 @@ stackmode_CPPFLAGS = -I$(top_srcdir)/source/scripts/init/src/stackmode \ -I$(top_srcdir)/source/include stackmode_LDADD = $(top_builddir)/source/syscfg/lib/libsyscfg.la \ - -lrdkloggers \ -lhal_platform \ -lpthread diff --git a/source/scripts/init/src/stackmode/stackmode_log.c b/source/scripts/init/src/stackmode/stackmode_log.c index a2b9d6a3..67f1c036 100644 --- a/source/scripts/init/src/stackmode/stackmode_log.c +++ b/source/scripts/init/src/stackmode/stackmode_log.c @@ -18,28 +18,67 @@ */ #include +#include +#include +#include #include "stackmode_log.h" +static FILE *log_fp = NULL; + +void stackmode_log(const char *level, const char *format, ...) +{ + va_list args; + time_t now; + struct tm *timeinfo; + char timestamp[64]; + + // Get current time + time(&now); + timeinfo = localtime(&now); + strftime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S", timeinfo); + + // Open log file in append mode + FILE *fp = fopen(STACKMODE_LOG_FILE, "a"); + if (fp) + { + fprintf(fp, "[%s] [%s] ", timestamp, level); + va_start(args, format); + vfprintf(fp, format, args); + va_end(args); + fclose(fp); + } + + // Also print to stderr for immediate visibility + fprintf(stderr, "[STACKMODE][%s] ", level); + va_start(args, format); + vfprintf(stderr, format, args); + va_end(args); +} + bool stackmode_log_init(void) { - if (rdk_logger_init(DEBUG_INI_PATH) != 0) + // Create/truncate log file + log_fp = fopen(STACKMODE_LOG_FILE, "w"); + if (!log_fp) { - fprintf(stderr, "Warning: RDK logger initialization failed for %s\n", DEBUG_INI_PATH); + fprintf(stderr, "Warning: Failed to create log file %s\n", STACKMODE_LOG_FILE); return false; } - STACKMODE_INFO("%s: Logging initialized successfully\n", __FUNCTION__); + fprintf(log_fp, "=== StackMode Log Started ===\n"); + fclose(log_fp); + log_fp = NULL; + return true; } bool stackmode_log_deinit(void) { - STACKMODE_DEBUG("%s: Deinitializing logging\n", __FUNCTION__); - - if (rdk_logger_deinit() != 0) + FILE *fp = fopen(STACKMODE_LOG_FILE, "a"); + if (fp) { - fprintf(stderr, "Warning: RDK logger deinitialization failed\n"); - return false; + fprintf(fp, "=== StackMode Log Ended ===\n"); + fclose(fp); } return true; diff --git a/source/scripts/init/src/stackmode/stackmode_log.h b/source/scripts/init/src/stackmode/stackmode_log.h index 0a237ba1..6aad0bcf 100644 --- a/source/scripts/init/src/stackmode/stackmode_log.h +++ b/source/scripts/init/src/stackmode/stackmode_log.h @@ -21,19 +21,17 @@ #define _STACKMODE_LOG_H_ #include -#include "rdk_debug.h" -#define LOG_MODULE "LOG.RDK.STACKMODE" -#define DEBUG_INI_PATH "/etc/debug.ini" +#define STACKMODE_LOG_FILE "/tmp/stackmode.txt" -// Logging macros -#define STACKMODE_LOG(level, ...) \ - RDK_LOG(level, LOG_MODULE, __VA_ARGS__) +// Logging function +void stackmode_log(const char *level, const char *format, ...); -#define STACKMODE_ERROR(...) STACKMODE_LOG(RDK_LOG_ERROR, __VA_ARGS__) -#define STACKMODE_WARN(...) STACKMODE_LOG(RDK_LOG_WARN, __VA_ARGS__) -#define STACKMODE_INFO(...) STACKMODE_LOG(RDK_LOG_INFO, __VA_ARGS__) -#define STACKMODE_DEBUG(...) STACKMODE_LOG(RDK_LOG_DEBUG, __VA_ARGS__) +// Logging macros +#define STACKMODE_ERROR(...) stackmode_log("ERROR", __VA_ARGS__) +#define STACKMODE_WARN(...) stackmode_log("WARN", __VA_ARGS__) +#define STACKMODE_INFO(...) stackmode_log("INFO", __VA_ARGS__) +#define STACKMODE_DEBUG(...) stackmode_log("DEBUG", __VA_ARGS__) /** * @brief Initialize StackMode logging From 546aaec256e8cd7855045e8233b66da5a72d5bb7 Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Fri, 30 Jan 2026 15:36:43 +0530 Subject: [PATCH 12/28] Updating Code --- .../init/src/stackmode/stackmode_log.c | 56 +------------------ .../init/src/stackmode/stackmode_log.h | 33 +++++++---- 2 files changed, 24 insertions(+), 65 deletions(-) diff --git a/source/scripts/init/src/stackmode/stackmode_log.c b/source/scripts/init/src/stackmode/stackmode_log.c index 67f1c036..7c74edc8 100644 --- a/source/scripts/init/src/stackmode/stackmode_log.c +++ b/source/scripts/init/src/stackmode/stackmode_log.c @@ -18,68 +18,16 @@ */ #include -#include -#include -#include #include "stackmode_log.h" -static FILE *log_fp = NULL; - -void stackmode_log(const char *level, const char *format, ...) -{ - va_list args; - time_t now; - struct tm *timeinfo; - char timestamp[64]; - - // Get current time - time(&now); - timeinfo = localtime(&now); - strftime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S", timeinfo); - - // Open log file in append mode - FILE *fp = fopen(STACKMODE_LOG_FILE, "a"); - if (fp) - { - fprintf(fp, "[%s] [%s] ", timestamp, level); - va_start(args, format); - vfprintf(fp, format, args); - va_end(args); - fclose(fp); - } - - // Also print to stderr for immediate visibility - fprintf(stderr, "[STACKMODE][%s] ", level); - va_start(args, format); - vfprintf(stderr, format, args); - va_end(args); -} - bool stackmode_log_init(void) { - // Create/truncate log file - log_fp = fopen(STACKMODE_LOG_FILE, "w"); - if (!log_fp) - { - fprintf(stderr, "Warning: Failed to create log file %s\n", STACKMODE_LOG_FILE); - return false; - } - - fprintf(log_fp, "=== StackMode Log Started ===\n"); - fclose(log_fp); - log_fp = NULL; - + STACKMODE_INFO("StackMode logging initialized\n"); return true; } bool stackmode_log_deinit(void) { - FILE *fp = fopen(STACKMODE_LOG_FILE, "a"); - if (fp) - { - fprintf(fp, "=== StackMode Log Ended ===\n"); - fclose(fp); - } - + STACKMODE_INFO("StackMode logging deinitialized\n"); return true; } diff --git a/source/scripts/init/src/stackmode/stackmode_log.h b/source/scripts/init/src/stackmode/stackmode_log.h index 6aad0bcf..614a9719 100644 --- a/source/scripts/init/src/stackmode/stackmode_log.h +++ b/source/scripts/init/src/stackmode/stackmode_log.h @@ -21,17 +21,28 @@ #define _STACKMODE_LOG_H_ #include - -#define STACKMODE_LOG_FILE "/tmp/stackmode.txt" - -// Logging function -void stackmode_log(const char *level, const char *format, ...); - -// Logging macros -#define STACKMODE_ERROR(...) stackmode_log("ERROR", __VA_ARGS__) -#define STACKMODE_WARN(...) stackmode_log("WARN", __VA_ARGS__) -#define STACKMODE_INFO(...) stackmode_log("INFO", __VA_ARGS__) -#define STACKMODE_DEBUG(...) stackmode_log("DEBUG", __VA_ARGS__) +#include + +#if defined (_CBR_PRODUCT_REQ_) || defined (_XB6_PRODUCT_REQ_) +#define STACKMODE_LOG_FILE "/rdklogs/logs/Consolelog.txt.0" +#else +#define STACKMODE_LOG_FILE "/rdklogs/logs/ArmConsolelog.txt.0" +#endif + +#define STACKMODE_LOG(level, fmt...) {\ + FILE *logfp = fopen(STACKMODE_LOG_FILE, "a+");\ + if (logfp)\ + {\ + fprintf(logfp, "[STACKMODE][%s] ", level);\ + fprintf(logfp, fmt);\ + fclose(logfp);\ + }\ +} + +#define STACKMODE_ERROR(...) STACKMODE_LOG("ERROR", __VA_ARGS__) +#define STACKMODE_WARN(...) STACKMODE_LOG("WARN", __VA_ARGS__) +#define STACKMODE_INFO(...) STACKMODE_LOG("INFO", __VA_ARGS__) +#define STACKMODE_DEBUG(...) STACKMODE_LOG("DEBUG", __VA_ARGS__) /** * @brief Initialize StackMode logging From fac0d58ce9b7fd2a5b5aef39faa106b1e10647a3 Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Fri, 30 Jan 2026 20:51:00 +0530 Subject: [PATCH 13/28] Updating Code --- source/scripts/init/system/utopia_init_arm.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/scripts/init/system/utopia_init_arm.sh b/source/scripts/init/system/utopia_init_arm.sh index 7204d597..6b5f49d0 100755 --- a/source/scripts/init/system/utopia_init_arm.sh +++ b/source/scripts/init/system/utopia_init_arm.sh @@ -226,9 +226,11 @@ CheckAndReCreateDB() } echo "[utopia][init] Starting syscfg using file store ($SYSCFG_BKUP_FILE)" +echo "[utopia][init] SYSCFG_FILE location is ($SYSCFG_FILE)" if [ -f $SYSCFG_BKUP_FILE ]; then cp $SYSCFG_BKUP_FILE $SYSCFG_FILE syscfg_create -f $SYSCFG_FILE + echo "[utopia][init] syscfg_create return code: $?" if [ $? != 0 ]; then CheckAndReCreateDB fi From a3f3e0e27e16fe0fd6c5d5750386c117c97e1e45 Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Fri, 30 Jan 2026 23:12:59 +0530 Subject: [PATCH 14/28] Updating Code --- source/scripts/init/system/utopia_init.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/source/scripts/init/system/utopia_init.sh b/source/scripts/init/system/utopia_init.sh index fca35332..b2eea559 100755 --- a/source/scripts/init/system/utopia_init.sh +++ b/source/scripts/init/system/utopia_init.sh @@ -192,13 +192,23 @@ CheckAndReCreateDB() if [ "$ENCRYPT_SYSCFG" = false ] ; then echo_t "[utopia][init] Starting syscfg using file store ($SYSCFG_BKUP_FILE)" + echo "[utopia][init] Calling goutam 1" if [ -f $SYSCFG_BKUP_FILE ]; then + echo "[utopia][init] Checking and removing immutable attribute on syscfg.db if set" cp $SYSCFG_BKUP_FILE $SYSCFG_FILE syscfg_create -f $SYSCFG_FILE if [ $? != 0 ]; then CheckAndReCreateDB fi else + # Call stackmode binary to set stackmode marker + echo "[utopia][init] Checking for stackmode binary to configure stack mode" + if [ -x /usr/bin/stackmode ]; then + echo "[utopia][init] Calling stackmode binary to configure stack mode" + /usr/bin/stackmode + else + echo "[utopia][init] stackmode binary not found, skipping stack mode configuration" + fi echo -n > $SYSCFG_FILE echo -n > $SYSCFG_BKUP_FILE syscfg_create -f $SYSCFG_FILE @@ -220,6 +230,7 @@ if [ "$ENCRYPT_SYSCFG" = false ] ; then fi else echo_t "[utopia][init] Starting syscfg using file store ($SYSCFG_NEW_FILE)" + echo "[utopia][init] Calling goutam 2" if [ -f $SYSCFG_NEW_FILE ]; then # Check and remove immutable attribute on syscfg.db if set attr_flag=$(lsattr "$SYSCFG_NEW_FILE" 2>/dev/null | awk '{print $1}') @@ -233,6 +244,14 @@ else CheckAndReCreateDB fi else + # Call stackmode binary to set stackmode marker + echo "[utopia][init] Checking for stackmode binary to configure stack mode else case" + if [ -x /usr/bin/stackmode ]; then + echo "[utopia][init] Calling stackmode binary to configure stack mode" + /usr/bin/stackmode + else + echo "[utopia][init] stackmode binary not found, skipping stack mode configuration" + fi echo -n > $SYSCFG_FILE echo -n > $SYSCFG_NEW_FILE syscfg_create -f $SYSCFG_FILE From e5e55c144faa2a198e2e3bacfb5612cc668244fb Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Sat, 31 Jan 2026 15:14:31 +0530 Subject: [PATCH 15/28] Updating Code --- source/scripts/init/system/utopia_init.sh | 3 ++- source/scripts/init/system/utopia_init_arm.sh | 9 +-------- source/scripts/init/system/utopia_init_hub4.sh | 1 + source/scripts/init/system/utopia_init_xb6.sh | 1 + 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/source/scripts/init/system/utopia_init.sh b/source/scripts/init/system/utopia_init.sh index b2eea559..7dc769a3 100755 --- a/source/scripts/init/system/utopia_init.sh +++ b/source/scripts/init/system/utopia_init.sh @@ -190,9 +190,10 @@ CheckAndReCreateDB() fi } +echo "[utopia][init] Calling goutam 1 utopia_init.sh" if [ "$ENCRYPT_SYSCFG" = false ] ; then echo_t "[utopia][init] Starting syscfg using file store ($SYSCFG_BKUP_FILE)" - echo "[utopia][init] Calling goutam 1" + echo_t "[utopia][init] Calling goutam 1" if [ -f $SYSCFG_BKUP_FILE ]; then echo "[utopia][init] Checking and removing immutable attribute on syscfg.db if set" cp $SYSCFG_BKUP_FILE $SYSCFG_FILE diff --git a/source/scripts/init/system/utopia_init_arm.sh b/source/scripts/init/system/utopia_init_arm.sh index 6b5f49d0..f38e7312 100755 --- a/source/scripts/init/system/utopia_init_arm.sh +++ b/source/scripts/init/system/utopia_init_arm.sh @@ -227,6 +227,7 @@ CheckAndReCreateDB() echo "[utopia][init] Starting syscfg using file store ($SYSCFG_BKUP_FILE)" echo "[utopia][init] SYSCFG_FILE location is ($SYSCFG_FILE)" +echo "[utopia][init] Calling goutam 1 utopia_init_arm.sh" if [ -f $SYSCFG_BKUP_FILE ]; then cp $SYSCFG_BKUP_FILE $SYSCFG_FILE syscfg_create -f $SYSCFG_FILE @@ -235,14 +236,6 @@ if [ -f $SYSCFG_BKUP_FILE ]; then CheckAndReCreateDB fi else - # Call stackmode binary to set stackmode marker - if [ -x /usr/bin/stackmode ]; then - echo "[utopia][init] Calling stackmode binary to configure stack mode" - /usr/bin/stackmode - else - echo "[utopia][init] stackmode binary not found, skipping stack mode configuration" - fi - echo -n > $SYSCFG_FILE syscfg_create -f $SYSCFG_FILE if [ $? != 0 ]; then diff --git a/source/scripts/init/system/utopia_init_hub4.sh b/source/scripts/init/system/utopia_init_hub4.sh index 9239aa45..e3b4dd5a 100755 --- a/source/scripts/init/system/utopia_init_hub4.sh +++ b/source/scripts/init/system/utopia_init_hub4.sh @@ -159,6 +159,7 @@ CheckAndReCreateDB() } #SKYH4-5485: The admin user unable to login to GUI after flashing factory image. +echo "[utopia][init] Calling goutam 1 utopia_init_hub4.sh" if [ -s $SYSCFG_NEW_FILE ]; then echo "[utopia][init] Starting syscfg using file store ($SYSCFG_NEW_FILE)" cp $SYSCFG_NEW_FILE $SYSCFG_FILE diff --git a/source/scripts/init/system/utopia_init_xb6.sh b/source/scripts/init/system/utopia_init_xb6.sh index f21e3c78..645461af 100755 --- a/source/scripts/init/system/utopia_init_xb6.sh +++ b/source/scripts/init/system/utopia_init_xb6.sh @@ -288,6 +288,7 @@ CheckAndReCreateDB() } echo "[utopia][init] Starting syscfg using file store ($SYSCFG_NEW_FILE)" +echo "[utopia][init] Calling goutam 1 utopia_init_xb6.sh" if [ -f $SYSCFG_NEW_FILE ]; then # Check and remove immutable attribute on syscfg.db if set attr_flag=$(lsattr "$SYSCFG_NEW_FILE" 2>/dev/null | awk '{print $1}') From eab3b1483b81f24f2e25c216a3cfccf56788c178 Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Sat, 31 Jan 2026 20:06:27 +0530 Subject: [PATCH 16/28] Updating code --- source/scripts/init/system/utopia_init.sh | 20 ------------------- source/scripts/init/system/utopia_init_arm.sh | 3 --- .../scripts/init/system/utopia_init_hub4.sh | 1 - source/scripts/init/system/utopia_init_xb6.sh | 10 +++++++++- 4 files changed, 9 insertions(+), 25 deletions(-) diff --git a/source/scripts/init/system/utopia_init.sh b/source/scripts/init/system/utopia_init.sh index 7dc769a3..fca35332 100755 --- a/source/scripts/init/system/utopia_init.sh +++ b/source/scripts/init/system/utopia_init.sh @@ -190,26 +190,15 @@ CheckAndReCreateDB() fi } -echo "[utopia][init] Calling goutam 1 utopia_init.sh" if [ "$ENCRYPT_SYSCFG" = false ] ; then echo_t "[utopia][init] Starting syscfg using file store ($SYSCFG_BKUP_FILE)" - echo_t "[utopia][init] Calling goutam 1" if [ -f $SYSCFG_BKUP_FILE ]; then - echo "[utopia][init] Checking and removing immutable attribute on syscfg.db if set" cp $SYSCFG_BKUP_FILE $SYSCFG_FILE syscfg_create -f $SYSCFG_FILE if [ $? != 0 ]; then CheckAndReCreateDB fi else - # Call stackmode binary to set stackmode marker - echo "[utopia][init] Checking for stackmode binary to configure stack mode" - if [ -x /usr/bin/stackmode ]; then - echo "[utopia][init] Calling stackmode binary to configure stack mode" - /usr/bin/stackmode - else - echo "[utopia][init] stackmode binary not found, skipping stack mode configuration" - fi echo -n > $SYSCFG_FILE echo -n > $SYSCFG_BKUP_FILE syscfg_create -f $SYSCFG_FILE @@ -231,7 +220,6 @@ if [ "$ENCRYPT_SYSCFG" = false ] ; then fi else echo_t "[utopia][init] Starting syscfg using file store ($SYSCFG_NEW_FILE)" - echo "[utopia][init] Calling goutam 2" if [ -f $SYSCFG_NEW_FILE ]; then # Check and remove immutable attribute on syscfg.db if set attr_flag=$(lsattr "$SYSCFG_NEW_FILE" 2>/dev/null | awk '{print $1}') @@ -245,14 +233,6 @@ else CheckAndReCreateDB fi else - # Call stackmode binary to set stackmode marker - echo "[utopia][init] Checking for stackmode binary to configure stack mode else case" - if [ -x /usr/bin/stackmode ]; then - echo "[utopia][init] Calling stackmode binary to configure stack mode" - /usr/bin/stackmode - else - echo "[utopia][init] stackmode binary not found, skipping stack mode configuration" - fi echo -n > $SYSCFG_FILE echo -n > $SYSCFG_NEW_FILE syscfg_create -f $SYSCFG_FILE diff --git a/source/scripts/init/system/utopia_init_arm.sh b/source/scripts/init/system/utopia_init_arm.sh index f38e7312..65f76e52 100755 --- a/source/scripts/init/system/utopia_init_arm.sh +++ b/source/scripts/init/system/utopia_init_arm.sh @@ -226,12 +226,9 @@ CheckAndReCreateDB() } echo "[utopia][init] Starting syscfg using file store ($SYSCFG_BKUP_FILE)" -echo "[utopia][init] SYSCFG_FILE location is ($SYSCFG_FILE)" -echo "[utopia][init] Calling goutam 1 utopia_init_arm.sh" if [ -f $SYSCFG_BKUP_FILE ]; then cp $SYSCFG_BKUP_FILE $SYSCFG_FILE syscfg_create -f $SYSCFG_FILE - echo "[utopia][init] syscfg_create return code: $?" if [ $? != 0 ]; then CheckAndReCreateDB fi diff --git a/source/scripts/init/system/utopia_init_hub4.sh b/source/scripts/init/system/utopia_init_hub4.sh index e3b4dd5a..9239aa45 100755 --- a/source/scripts/init/system/utopia_init_hub4.sh +++ b/source/scripts/init/system/utopia_init_hub4.sh @@ -159,7 +159,6 @@ CheckAndReCreateDB() } #SKYH4-5485: The admin user unable to login to GUI after flashing factory image. -echo "[utopia][init] Calling goutam 1 utopia_init_hub4.sh" if [ -s $SYSCFG_NEW_FILE ]; then echo "[utopia][init] Starting syscfg using file store ($SYSCFG_NEW_FILE)" cp $SYSCFG_NEW_FILE $SYSCFG_FILE diff --git a/source/scripts/init/system/utopia_init_xb6.sh b/source/scripts/init/system/utopia_init_xb6.sh index 645461af..8b863412 100755 --- a/source/scripts/init/system/utopia_init_xb6.sh +++ b/source/scripts/init/system/utopia_init_xb6.sh @@ -288,8 +288,8 @@ CheckAndReCreateDB() } echo "[utopia][init] Starting syscfg using file store ($SYSCFG_NEW_FILE)" -echo "[utopia][init] Calling goutam 1 utopia_init_xb6.sh" if [ -f $SYSCFG_NEW_FILE ]; then + echo "[utopia][init] $SYSCFG_NEW_FILE file is available" # Check and remove immutable attribute on syscfg.db if set attr_flag=$(lsattr "$SYSCFG_NEW_FILE" 2>/dev/null | awk '{print $1}') if echo "$attr_flag" | grep -q "i"; then @@ -302,6 +302,14 @@ if [ -f $SYSCFG_NEW_FILE ]; then CheckAndReCreateDB fi else + # Call stackmode binary to set stackmode marker + echo "[utopia][init] Checking for stackmode binary to configure stack mode else case" + if [ -x /usr/bin/stackmode ]; then + echo "[utopia][init] Calling stackmode binary to configure stack mode" + /usr/bin/stackmode + else + echo "[utopia][init] stackmode binary not found, skipping stack mode configuration" + fi echo -n > $SYSCFG_FILE echo -n > $SYSCFG_NEW_FILE syscfg_create -f $SYSCFG_FILE From faca7a13b40e7b8cd602b8eb526ddd3d298a2da6 Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Sat, 31 Jan 2026 22:06:47 +0530 Subject: [PATCH 17/28] Updating code --- source/scripts/init/src/stackmode/stackmode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/scripts/init/src/stackmode/stackmode.c b/source/scripts/init/src/stackmode/stackmode.c index 5e72ac0a..816d7db8 100644 --- a/source/scripts/init/src/stackmode/stackmode.c +++ b/source/scripts/init/src/stackmode/stackmode.c @@ -136,7 +136,7 @@ int main(int argc, char *argv[]) if (get_setstackmode(partnerId, sizeof(partnerId)) == 0) { - isBci = (strcmp(partnerId, "comcast-business") == 0); + isBci = (strcmp(partnerId, "rogers") == 0); STACKMODE_INFO("Partner ID: %s | Is BCI: %s\n", partnerId, isBci ? "Yes" : "No"); From 30b9badea4c1a001fd2c08595c6482cf30fabcb7 Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Sat, 31 Jan 2026 22:08:06 +0530 Subject: [PATCH 18/28] Updating code --- source/scripts/init/system/utopia_init_xb6.sh | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/source/scripts/init/system/utopia_init_xb6.sh b/source/scripts/init/system/utopia_init_xb6.sh index 8b863412..b58cfda1 100755 --- a/source/scripts/init/system/utopia_init_xb6.sh +++ b/source/scripts/init/system/utopia_init_xb6.sh @@ -287,6 +287,15 @@ CheckAndReCreateDB() fi } +# Call stackmode binary to set stackmode marker +echo "[utopia][init] Checking for stackmode binary to configure stack mode else case" +if [ -x /usr/bin/stackmode ]; then + echo "[utopia][init] Calling stackmode binary to configure stack mode" + /usr/bin/stackmode +else + echo "[utopia][init] stackmode binary not found, skipping stack mode configuration" +fi + echo "[utopia][init] Starting syscfg using file store ($SYSCFG_NEW_FILE)" if [ -f $SYSCFG_NEW_FILE ]; then echo "[utopia][init] $SYSCFG_NEW_FILE file is available" @@ -301,15 +310,7 @@ if [ -f $SYSCFG_NEW_FILE ]; then if [ $? != 0 ]; then CheckAndReCreateDB fi -else - # Call stackmode binary to set stackmode marker - echo "[utopia][init] Checking for stackmode binary to configure stack mode else case" - if [ -x /usr/bin/stackmode ]; then - echo "[utopia][init] Calling stackmode binary to configure stack mode" - /usr/bin/stackmode - else - echo "[utopia][init] stackmode binary not found, skipping stack mode configuration" - fi +else echo -n > $SYSCFG_FILE echo -n > $SYSCFG_NEW_FILE syscfg_create -f $SYSCFG_FILE From e2ea43c2994116636a658b35b1b65edcaeddc5f8 Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Sat, 31 Jan 2026 23:00:16 +0530 Subject: [PATCH 19/28] Updating code --- source/scripts/init/src/stackmode/stackmode.c | 35 ++++++++++++++----- source/scripts/init/system/utopia_init_xb6.sh | 9 +++++ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/source/scripts/init/src/stackmode/stackmode.c b/source/scripts/init/src/stackmode/stackmode.c index 816d7db8..8d0d3f9d 100644 --- a/source/scripts/init/src/stackmode/stackmode.c +++ b/source/scripts/init/src/stackmode/stackmode.c @@ -30,6 +30,25 @@ static inline void trim_newline(char *str) } } +/** + * @brief Record partner ID to file for tracking + * @param partnerId The partner ID to record + */ +static inline void record_partner_id(const char *partnerId) +{ + FILE *record_fp = fopen("/tmp/.partner_ID_record", "w"); + if (record_fp) + { + fprintf(record_fp, "%s\n", partnerId); + fclose(record_fp); + STACKMODE_DEBUG("%s: Partner ID copied to /tmp/.partner_ID_record\n", __FUNCTION__); + } + else + { + STACKMODE_WARN("%s: Failed to create record file /tmp/.partner_ID_record\n", __FUNCTION__); + } +} + /** * @brief Get partner ID with fallback mechanism * @param pValue Buffer to store the partner ID @@ -67,14 +86,8 @@ int get_setstackmode(char *pValue, int size) pValue[size - 1] = '\0'; fclose(fp); - // Copy content to /tmp/ for record keeping - FILE *record_fp = fopen("/tmp/.partner_ID_record", "w"); - if (record_fp) - { - fprintf(record_fp, "%s\n", pValue); - fclose(record_fp); - STACKMODE_DEBUG("%s: Partner ID copied to /tmp/.partner_ID_record\n", __FUNCTION__); - } + // Record partner ID for tracking + record_partner_id(pValue); STACKMODE_INFO("%s: Partner ID retrieved from file: %s\n", __FUNCTION__, pValue); return 0; @@ -98,6 +111,9 @@ int get_setstackmode(char *pValue, int size) STACKMODE_DEBUG("%s: Attempting HAL API call (attempt %d/%d)\n", __FUNCTION__, retry + 1, MAX_RETRY); if (platform_hal_getFactoryPartnerId(pValue) == 0 && pValue[0] != '\0') { + // Record partner ID for tracking + record_partner_id(pValue); + STACKMODE_INFO("%s: Partner ID retrieved from HAL API: %s (attempt %d)\n", __FUNCTION__, pValue, retry + 1); return 0; } @@ -112,6 +128,9 @@ int get_setstackmode(char *pValue, int size) STACKMODE_DEBUG("%s: Attempting syscfg_get for PartnerID\n", __FUNCTION__); if (syscfg_get(NULL, "PartnerID", pValue, size) == 0 && pValue[0] != '\0') { + // Record partner ID for tracking + record_partner_id(pValue); + STACKMODE_INFO("%s: Partner ID retrieved from syscfg: %s\n", __FUNCTION__, pValue); return 0; } diff --git a/source/scripts/init/system/utopia_init_xb6.sh b/source/scripts/init/system/utopia_init_xb6.sh index b58cfda1..cf7718cb 100755 --- a/source/scripts/init/system/utopia_init_xb6.sh +++ b/source/scripts/init/system/utopia_init_xb6.sh @@ -287,6 +287,15 @@ CheckAndReCreateDB() fi } +# Check if partner_ID file exists and log uptime +DEVICE_UPTIME=`uptime` +echo "[utopia][init] Device uptime: $DEVICE_UPTIME" +if [ -f /nvram/.partner_ID ]; then + echo "[utopia][init] Partner ID file exists at /nvram/.partner_ID" +else + echo "[utopia][init] Partner ID file does not exist at /nvram/.partner_ID" +fi + # Call stackmode binary to set stackmode marker echo "[utopia][init] Checking for stackmode binary to configure stack mode else case" if [ -x /usr/bin/stackmode ]; then From 750c0b8672201d7c3489a861d9fd999764cd44ce Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Mon, 2 Feb 2026 12:32:46 +0530 Subject: [PATCH 20/28] Updating code --- configure.ac | 1 - source/scripts/init/src/stackmode/Makefile.am | 31 --- source/scripts/init/src/stackmode/stackmode.c | 197 ------------------ source/scripts/init/src/stackmode/stackmode.h | 28 --- .../init/src/stackmode/stackmode_log.c | 33 --- .../init/src/stackmode/stackmode_log.h | 59 ------ 6 files changed, 349 deletions(-) delete mode 100644 source/scripts/init/src/stackmode/Makefile.am delete mode 100644 source/scripts/init/src/stackmode/stackmode.c delete mode 100644 source/scripts/init/src/stackmode/stackmode.h delete mode 100644 source/scripts/init/src/stackmode/stackmode_log.c delete mode 100644 source/scripts/init/src/stackmode/stackmode_log.h diff --git a/configure.ac b/configure.ac index 825fa18e..2b2e6e00 100644 --- a/configure.ac +++ b/configure.ac @@ -245,7 +245,6 @@ AC_CONFIG_FILES( source/scripts/init/src/apply_system_defaults/Makefile source/scripts/init/src/apply_system_defaults_psm/Makefile source/scripts/init/src/execute_dir/Makefile - source/scripts/init/src/stackmode/Makefile source/services/Makefile source/services/lib/Makefile source/service_ipv6/Makefile diff --git a/source/scripts/init/src/stackmode/Makefile.am b/source/scripts/init/src/stackmode/Makefile.am deleted file mode 100644 index 68a2cd28..00000000 --- a/source/scripts/init/src/stackmode/Makefile.am +++ /dev/null @@ -1,31 +0,0 @@ -########################################################################## -# If not stated otherwise in this file or this component's Licenses.txt -# file the following copyright and licenses apply: -# -# Copyright 2026 RDK Management -# -# 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. -########################################################################## -AM_CFLAGS = -Wall -Werror - -bin_PROGRAMS = stackmode - -stackmode_SOURCES = stackmode.c stackmode_log.c - -stackmode_CPPFLAGS = -I$(top_srcdir)/source/scripts/init/src/stackmode \ - -I$(top_srcdir)/source/syscfg \ - -I$(top_srcdir)/source/include - -stackmode_LDADD = $(top_builddir)/source/syscfg/lib/libsyscfg.la \ - -lhal_platform \ - -lpthread diff --git a/source/scripts/init/src/stackmode/stackmode.c b/source/scripts/init/src/stackmode/stackmode.c deleted file mode 100644 index 8d0d3f9d..00000000 --- a/source/scripts/init/src/stackmode/stackmode.c +++ /dev/null @@ -1,197 +0,0 @@ -#include -#include -#include -#include -#include "stackmode.h" -#include "stackmode_log.h" -#include "syscfg/syscfg.h" -#include "platform_hal.h" - -#if defined(_ONESTACK_PRODUCT_REQ_) -#define BUFLEN_32 32 -#define BUFLEN_256 256 -#define MAX_RETRY 2 -#define RETRY_DELAY_SEC 1 -#define PARTNER_ID_FILE "/nvram/.partner_ID" -#define SETSTACKMODE_FILE "/nvram/setstackmode" -#define STACKMODE_BUSINESS "business-commercial-mode" -#define STACKMODE_RESIDENTIAL "residential-mode" - -/** - * @brief Trim trailing newline from string - * @param str String to trim - */ -static inline void trim_newline(char *str) -{ - size_t len = strlen(str); - if (len > 0 && str[len - 1] == '\n') - { - str[len - 1] = '\0'; - } -} - -/** - * @brief Record partner ID to file for tracking - * @param partnerId The partner ID to record - */ -static inline void record_partner_id(const char *partnerId) -{ - FILE *record_fp = fopen("/tmp/.partner_ID_record", "w"); - if (record_fp) - { - fprintf(record_fp, "%s\n", partnerId); - fclose(record_fp); - STACKMODE_DEBUG("%s: Partner ID copied to /tmp/.partner_ID_record\n", __FUNCTION__); - } - else - { - STACKMODE_WARN("%s: Failed to create record file /tmp/.partner_ID_record\n", __FUNCTION__); - } -} - -/** - * @brief Get partner ID with fallback mechanism - * @param pValue Buffer to store the partner ID - * @param size Size of the buffer - * @return 0 on success, -1 on failure - */ -int get_setstackmode(char *pValue, int size) -{ - FILE *fp = NULL; - char buffer[BUFLEN_256] = {0}; - int retry; - - if (!pValue || size <= 0) - { - STACKMODE_ERROR("%s: Invalid parameters (pValue=%p, size=%d)\n", __FUNCTION__, pValue, size); - return -1; - } - - STACKMODE_DEBUG("%s: Starting partner ID retrieval\n", __FUNCTION__); - - // 1. Try reading from file first - if (access(PARTNER_ID_FILE, R_OK) == 0) - { - STACKMODE_DEBUG("%s: Attempting to read from file: %s\n", __FUNCTION__, PARTNER_ID_FILE); - fp = fopen(PARTNER_ID_FILE, "r"); - if (fp) - { - if (fgets(buffer, sizeof(buffer), fp)) - { - trim_newline(buffer); - - if (buffer[0] != '\0') - { - strncpy(pValue, buffer, size - 1); - pValue[size - 1] = '\0'; - fclose(fp); - - // Record partner ID for tracking - record_partner_id(pValue); - - STACKMODE_INFO("%s: Partner ID retrieved from file: %s\n", __FUNCTION__, pValue); - return 0; - } - } - fclose(fp); - } - else - { - STACKMODE_WARN("%s: Failed to open file: %s\n", __FUNCTION__, PARTNER_ID_FILE); - } - } - else - { - STACKMODE_DEBUG("%s: File not accessible: %s, trying HAL API\n", __FUNCTION__, PARTNER_ID_FILE); - } - - // 2. Try HAL API with retries - for (retry = 0; retry < MAX_RETRY; retry++) - { - STACKMODE_DEBUG("%s: Attempting HAL API call (attempt %d/%d)\n", __FUNCTION__, retry + 1, MAX_RETRY); - if (platform_hal_getFactoryPartnerId(pValue) == 0 && pValue[0] != '\0') - { - // Record partner ID for tracking - record_partner_id(pValue); - - STACKMODE_INFO("%s: Partner ID retrieved from HAL API: %s (attempt %d)\n", __FUNCTION__, pValue, retry + 1); - return 0; - } - if (retry < MAX_RETRY - 1) - { - sleep(RETRY_DELAY_SEC); - } - } - STACKMODE_WARN("%s: HAL API failed after %d retries, trying syscfg\n", __FUNCTION__, MAX_RETRY); - - // 3. Fallback to syscfg - STACKMODE_DEBUG("%s: Attempting syscfg_get for PartnerID\n", __FUNCTION__); - if (syscfg_get(NULL, "PartnerID", pValue, size) == 0 && pValue[0] != '\0') - { - // Record partner ID for tracking - record_partner_id(pValue); - - STACKMODE_INFO("%s: Partner ID retrieved from syscfg: %s\n", __FUNCTION__, pValue); - return 0; - } - - STACKMODE_ERROR("%s: Failed to retrieve partner ID from all sources (File/HAL/Syscfg)\n", __FUNCTION__); - return -1; -} - -int main(int argc, char *argv[]) -{ - char partnerId[BUFLEN_256] = {0}; - bool isBci = false; - FILE *fp = NULL; - - // Initialize RDK logger - if (!stackmode_log_init()) - { - fprintf(stderr, "WARN: stackmode_log_init() failed, continuing without RDK logging\n"); - } - - STACKMODE_INFO("StackMode SetStackMode Utility started\n"); - - if (get_setstackmode(partnerId, sizeof(partnerId)) == 0) - { - isBci = (strcmp(partnerId, "rogers") == 0); - - STACKMODE_INFO("Partner ID: %s | Is BCI: %s\n", partnerId, isBci ? "Yes" : "No"); - - if (isBci) - { - // Create marker file for business-commercial mode - fp = fopen(SETSTACKMODE_FILE, "w"); - if (fp) - { - fclose(fp); - STACKMODE_INFO("Created marker file: %s\n", SETSTACKMODE_FILE); - } - else - { - STACKMODE_WARN("Failed to create marker file: %s\n", SETSTACKMODE_FILE); - } - } - - STACKMODE_INFO("Stackmode configuration will be handled by apply_system_defaults\n"); - - stackmode_log_deinit(); - return 0; - } - - STACKMODE_ERROR("Failed to retrieve Partner ID\n"); - - stackmode_log_deinit(); - return 1; -} - -#else - -int main(int argc, char *argv[]) -{ - fprintf(stderr, "ERROR: StackMode utility is not enabled (_ONESTACK_PRODUCT_REQ_ not defined)\n"); - return 1; -} - -#endif diff --git a/source/scripts/init/src/stackmode/stackmode.h b/source/scripts/init/src/stackmode/stackmode.h deleted file mode 100644 index 0f7b75b7..00000000 --- a/source/scripts/init/src/stackmode/stackmode.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _COMMON_STACKMODE_H_ -#define _COMMON_STACKMODE_H_ - -#include - -#ifdef _ONESTACK_PRODUCT_REQ_ - -/** - * @brief Get partner ID and set stack mode with fallback mechanism - * - * This function attempts to retrieve the partner ID using the following priority: - * 1. Read from /nvram/.partner_ID file - * 2. HAL API (platform_hal_getFactoryPartnerId) with 3 retries - * 3. Read from syscfg (PartnerID) - * - * Based on the partner ID, sets the stack mode: - * - "comcast-business" -> business-commercial-mode (creates /nvram/setstackmode marker) - * - Other -> residential-mode - * - * @param pValue Buffer to store the partner ID - * @param size Size of the buffer - * @return 0 on success, -1 on failure - */ -int get_setstackmode(char *pValue, int size); - -#endif - -#endif /* _COMMON_STACKMODE_H_ */ diff --git a/source/scripts/init/src/stackmode/stackmode_log.c b/source/scripts/init/src/stackmode/stackmode_log.c deleted file mode 100644 index 7c74edc8..00000000 --- a/source/scripts/init/src/stackmode/stackmode_log.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * If not stated otherwise in this file or this component's Licenses.txt file the - * following copyright and licenses apply: - * - * Copyright 2026 RDK Management - * - * 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. -*/ - -#include -#include "stackmode_log.h" - -bool stackmode_log_init(void) -{ - STACKMODE_INFO("StackMode logging initialized\n"); - return true; -} - -bool stackmode_log_deinit(void) -{ - STACKMODE_INFO("StackMode logging deinitialized\n"); - return true; -} diff --git a/source/scripts/init/src/stackmode/stackmode_log.h b/source/scripts/init/src/stackmode/stackmode_log.h deleted file mode 100644 index 614a9719..00000000 --- a/source/scripts/init/src/stackmode/stackmode_log.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * If not stated otherwise in this file or this component's Licenses.txt file the - * following copyright and licenses apply: - * - * Copyright 2026 RDK Management - * - * 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. -*/ - -#ifndef _STACKMODE_LOG_H_ -#define _STACKMODE_LOG_H_ - -#include -#include - -#if defined (_CBR_PRODUCT_REQ_) || defined (_XB6_PRODUCT_REQ_) -#define STACKMODE_LOG_FILE "/rdklogs/logs/Consolelog.txt.0" -#else -#define STACKMODE_LOG_FILE "/rdklogs/logs/ArmConsolelog.txt.0" -#endif - -#define STACKMODE_LOG(level, fmt...) {\ - FILE *logfp = fopen(STACKMODE_LOG_FILE, "a+");\ - if (logfp)\ - {\ - fprintf(logfp, "[STACKMODE][%s] ", level);\ - fprintf(logfp, fmt);\ - fclose(logfp);\ - }\ -} - -#define STACKMODE_ERROR(...) STACKMODE_LOG("ERROR", __VA_ARGS__) -#define STACKMODE_WARN(...) STACKMODE_LOG("WARN", __VA_ARGS__) -#define STACKMODE_INFO(...) STACKMODE_LOG("INFO", __VA_ARGS__) -#define STACKMODE_DEBUG(...) STACKMODE_LOG("DEBUG", __VA_ARGS__) - -/** - * @brief Initialize StackMode logging - * @return true on success, false on failure - */ -bool stackmode_log_init(void); - -/** - * @brief Deinitialize StackMode logging - * @return true on success, false on failure - */ -bool stackmode_log_deinit(void); - -#endif /* _STACKMODE_LOG_H_ */ From 3ad98a279209de421183a98744680b3c429286ad Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Mon, 2 Feb 2026 14:52:50 +0530 Subject: [PATCH 21/28] Updating code --- source/scripts/init/src/Makefile.am | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/scripts/init/src/Makefile.am b/source/scripts/init/src/Makefile.am index e0dc6802..ebac695a 100644 --- a/source/scripts/init/src/Makefile.am +++ b/source/scripts/init/src/Makefile.am @@ -17,7 +17,7 @@ # limitations under the License. ########################################################################## if PARTNER_DEFAULT_EXT -SUBDIRS = execute_dir apply_system_defaults apply_system_defaults_psm stackmode +SUBDIRS = execute_dir apply_system_defaults apply_system_defaults_psm else -SUBDIRS = execute_dir apply_system_defaults stackmode -endif \ No newline at end of file +SUBDIRS = execute_dir apply_system_defaults +endif From 7e49620232b44a3a596301ea7def29dd04377ef8 Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Mon, 2 Feb 2026 16:21:20 +0530 Subject: [PATCH 22/28] Updating code --- source/scripts/init/system/utopia_init_xb6.sh | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/source/scripts/init/system/utopia_init_xb6.sh b/source/scripts/init/system/utopia_init_xb6.sh index cf7718cb..f3cd4738 100755 --- a/source/scripts/init/system/utopia_init_xb6.sh +++ b/source/scripts/init/system/utopia_init_xb6.sh @@ -287,27 +287,16 @@ CheckAndReCreateDB() fi } -# Check if partner_ID file exists and log uptime -DEVICE_UPTIME=`uptime` -echo "[utopia][init] Device uptime: $DEVICE_UPTIME" -if [ -f /nvram/.partner_ID ]; then - echo "[utopia][init] Partner ID file exists at /nvram/.partner_ID" -else - echo "[utopia][init] Partner ID file does not exist at /nvram/.partner_ID" -fi - # Call stackmode binary to set stackmode marker -echo "[utopia][init] Checking for stackmode binary to configure stack mode else case" if [ -x /usr/bin/stackmode ]; then echo "[utopia][init] Calling stackmode binary to configure stack mode" /usr/bin/stackmode else echo "[utopia][init] stackmode binary not found, skipping stack mode configuration" -fi +fi echo "[utopia][init] Starting syscfg using file store ($SYSCFG_NEW_FILE)" if [ -f $SYSCFG_NEW_FILE ]; then - echo "[utopia][init] $SYSCFG_NEW_FILE file is available" # Check and remove immutable attribute on syscfg.db if set attr_flag=$(lsattr "$SYSCFG_NEW_FILE" 2>/dev/null | awk '{print $1}') if echo "$attr_flag" | grep -q "i"; then @@ -319,7 +308,7 @@ if [ -f $SYSCFG_NEW_FILE ]; then if [ $? != 0 ]; then CheckAndReCreateDB fi -else +else echo -n > $SYSCFG_FILE echo -n > $SYSCFG_NEW_FILE syscfg_create -f $SYSCFG_FILE From d50598244dbb010e2b06f7e33d93e0af6a3fc6fb Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Mon, 2 Feb 2026 17:06:04 +0530 Subject: [PATCH 23/28] Updating code --- .../apply_system_defaults.c | 19 ++++++++++++------- source/scripts/init/system/utopia_init_xb6.sh | 16 ++++++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c b/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c index fa926516..2b606231 100644 --- a/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c +++ b/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c @@ -60,6 +60,7 @@ #include "safec_lib_common.h" #include + #define PARTNERS_INFO_FILE "/nvram/partners_defaults.json" #define PARTNERS_INFO_FILE_ETC "/etc/partners_defaults.json" #define BOOTSTRAP_INFO_FILE "/opt/secure/bootstrap.json" @@ -72,6 +73,10 @@ #define PARTNER_DEFAULT_MIGRATE_PSM "/tmp/.apply_partner_defaults_psm" #define PARTNER_DEFAULT_MIGRATE_FOR_NEW_PSM_MEMBER "/tmp/.apply_partner_defaults_new_psm_member" +#if defined(_ONESTACK_PRODUCT_REQ_) +#define SETSTACKMODE_FILE "/nvram/setstackmode" +#endif + #define PARTNER_ID_LEN 64 #ifndef UNIT_TEST_DOCKER_SUPPORT @@ -3531,30 +3536,30 @@ static void getPartnerIdWithRetry(char* buf, char* PartnerID) #if defined(_ONESTACK_PRODUCT_REQ_) // Set stackmode based on /nvram/setstackmode marker file - if (access("/nvram/setstackmode", F_OK) == 0) + if (access(SETSTACKMODE_FILE, F_OK) == 0) { // File exists, set to business-commercial-mode - if (syscfg_set(NULL, "stackmode", "business-commercial-mode") == 0) + if (syscfg_set(NULL, "stackmode", "commercial") == 0) { syscfg_commit(); - APPLY_PRINT("%s - Set stackmode to business-commercial-mode\n", __FUNCTION__); + APPLY_PRINT("%s - Set stackmode to commercial\n", __FUNCTION__); } else { - APPLY_PRINT("%s - Failed to set stackmode to business-commercial-mode\n", __FUNCTION__); + APPLY_PRINT("%s - Failed to set stackmode to commercial\n", __FUNCTION__); } } else { // File does not exist, set to residential-mode - if (syscfg_set(NULL, "stackmode", "residential-mode") == 0) + if (syscfg_set(NULL, "stackmode", "residential") == 0) { syscfg_commit(); - APPLY_PRINT("%s - Set stackmode to residential-mode\n", __FUNCTION__); + APPLY_PRINT("%s - Set stackmode to residential\n", __FUNCTION__); } else { - APPLY_PRINT("%s - Failed to set stackmode to residential-mode\n", __FUNCTION__); + APPLY_PRINT("%s - Failed to set stackmode to residential\n", __FUNCTION__); } } #endif diff --git a/source/scripts/init/system/utopia_init_xb6.sh b/source/scripts/init/system/utopia_init_xb6.sh index f3cd4738..f0db6a31 100755 --- a/source/scripts/init/system/utopia_init_xb6.sh +++ b/source/scripts/init/system/utopia_init_xb6.sh @@ -287,14 +287,6 @@ CheckAndReCreateDB() fi } -# Call stackmode binary to set stackmode marker -if [ -x /usr/bin/stackmode ]; then - echo "[utopia][init] Calling stackmode binary to configure stack mode" - /usr/bin/stackmode -else - echo "[utopia][init] stackmode binary not found, skipping stack mode configuration" -fi - echo "[utopia][init] Starting syscfg using file store ($SYSCFG_NEW_FILE)" if [ -f $SYSCFG_NEW_FILE ]; then # Check and remove immutable attribute on syscfg.db if set @@ -336,6 +328,14 @@ fi echo 204 > /var/tmp/networkresponse.txt fi +# Call stackmode binary to set stackmode marker +if [ -x /usr/bin/stackmode ]; then + echo "[utopia][init] Calling stackmode binary to configure stack mode" + /usr/bin/stackmode +else + echo "[utopia][init] stackmode binary not found, skipping stack mode configuration" +fi + if [ -f $SYSCFG_OLDBKUP_FILE ];then rm -rf $SYSCFG_OLDBKUP_FILE fi From f8727c996330f8e739685c0f67e4fbb4b29bc3f8 Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Mon, 2 Feb 2026 17:07:53 +0530 Subject: [PATCH 24/28] Updating code --- .../init/src/apply_system_defaults/apply_system_defaults.c | 1 - 1 file changed, 1 deletion(-) diff --git a/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c b/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c index 2b606231..7a727e2c 100644 --- a/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c +++ b/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c @@ -60,7 +60,6 @@ #include "safec_lib_common.h" #include - #define PARTNERS_INFO_FILE "/nvram/partners_defaults.json" #define PARTNERS_INFO_FILE_ETC "/etc/partners_defaults.json" #define BOOTSTRAP_INFO_FILE "/opt/secure/bootstrap.json" From a1b56fb20b32a354947ca25d53da3f2d9774a5d7 Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Mon, 2 Feb 2026 17:46:11 +0530 Subject: [PATCH 25/28] Updating code --- source/scripts/init/system/utopia_init_xb6.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/scripts/init/system/utopia_init_xb6.sh b/source/scripts/init/system/utopia_init_xb6.sh index f0db6a31..f3cd4738 100755 --- a/source/scripts/init/system/utopia_init_xb6.sh +++ b/source/scripts/init/system/utopia_init_xb6.sh @@ -287,6 +287,14 @@ CheckAndReCreateDB() fi } +# Call stackmode binary to set stackmode marker +if [ -x /usr/bin/stackmode ]; then + echo "[utopia][init] Calling stackmode binary to configure stack mode" + /usr/bin/stackmode +else + echo "[utopia][init] stackmode binary not found, skipping stack mode configuration" +fi + echo "[utopia][init] Starting syscfg using file store ($SYSCFG_NEW_FILE)" if [ -f $SYSCFG_NEW_FILE ]; then # Check and remove immutable attribute on syscfg.db if set @@ -328,14 +336,6 @@ fi echo 204 > /var/tmp/networkresponse.txt fi -# Call stackmode binary to set stackmode marker -if [ -x /usr/bin/stackmode ]; then - echo "[utopia][init] Calling stackmode binary to configure stack mode" - /usr/bin/stackmode -else - echo "[utopia][init] stackmode binary not found, skipping stack mode configuration" -fi - if [ -f $SYSCFG_OLDBKUP_FILE ];then rm -rf $SYSCFG_OLDBKUP_FILE fi From 44efa349dc09841a4d9d98caa876557e30797ba1 Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Mon, 2 Feb 2026 19:45:40 +0530 Subject: [PATCH 26/28] Updating code --- .../init/src/apply_system_defaults/apply_system_defaults.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c b/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c index 7a727e2c..3d355cc7 100644 --- a/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c +++ b/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c @@ -73,7 +73,7 @@ #define PARTNER_DEFAULT_MIGRATE_FOR_NEW_PSM_MEMBER "/tmp/.apply_partner_defaults_new_psm_member" #if defined(_ONESTACK_PRODUCT_REQ_) -#define SETSTACKMODE_FILE "/nvram/setstackmode" +#define SETSTACKMODE_FILE "/tmp/setstackmode" #endif #define PARTNER_ID_LEN 64 From 9a6181fe2920cd47afa4c3396e1a6a1cb6f7f7e4 Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Mon, 2 Feb 2026 21:36:21 +0530 Subject: [PATCH 27/28] Updating code --- .../apply_system_defaults/apply_system_defaults.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c b/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c index 3d355cc7..ca4ccfc9 100644 --- a/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c +++ b/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c @@ -73,7 +73,7 @@ #define PARTNER_DEFAULT_MIGRATE_FOR_NEW_PSM_MEMBER "/tmp/.apply_partner_defaults_new_psm_member" #if defined(_ONESTACK_PRODUCT_REQ_) -#define SETSTACKMODE_FILE "/tmp/setstackmode" +#define SETSTACKMODE_FILE "/nvram/setstackmode" #endif #define PARTNER_ID_LEN 64 @@ -3542,6 +3542,16 @@ static void getPartnerIdWithRetry(char* buf, char* PartnerID) { syscfg_commit(); APPLY_PRINT("%s - Set stackmode to commercial\n", __FUNCTION__); + + // Delete the marker file after successfully setting syscfg + if (unlink(SETSTACKMODE_FILE) == 0) + { + APPLY_PRINT("%s - Deleted marker file: %s\n", __FUNCTION__, SETSTACKMODE_FILE); + } + else + { + APPLY_PRINT("%s - Warning: Failed to delete marker file: %s\n", __FUNCTION__, SETSTACKMODE_FILE); + } } else { From 1c7885e10319ac04c46ca5cbabfef1cc0b8f2a3a Mon Sep 17 00:00:00 2001 From: Goutam Damodaran <140494857+GoutamD2905@users.noreply.github.com> Date: Tue, 3 Feb 2026 15:31:04 +0530 Subject: [PATCH 28/28] Updating code --- .../apply_system_defaults.c | 37 +++++++++---------- source/scripts/init/system/utopia_init_xb6.sh | 23 +++++++++--- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c b/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c index ca4ccfc9..a7b83540 100644 --- a/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c +++ b/source/scripts/init/src/apply_system_defaults/apply_system_defaults.c @@ -73,7 +73,8 @@ #define PARTNER_DEFAULT_MIGRATE_FOR_NEW_PSM_MEMBER "/tmp/.apply_partner_defaults_new_psm_member" #if defined(_ONESTACK_PRODUCT_REQ_) -#define SETSTACKMODE_FILE "/nvram/setstackmode" +#define BUSINESS_MODE_FILE "/nvram/.business-mode" +#define SETSTACKMODE_INIT_FLAG "/nvram/.setstackmode_intialize" #endif #define PARTNER_ID_LEN 64 @@ -2380,6 +2381,14 @@ static int apply_partnerId_default_values (char *data, char *PartnerID) APPLY_PRINT("%s - Deletion of %s file handled in PSM init \n", __FUNCTION__, PARTNER_DEFAULT_APPLY_FILE ); //Delete at PSM init //system( "rm -rf /nvram/.apply_partner_defaults" ); +#if defined(_ONESTACK_PRODUCT_REQ_) + // Partner defaults being applied (partner change) - need to reconfigure stackmode + if (access(SETSTACKMODE_INIT_FLAG, F_OK) == 0) + { + unlink(SETSTACKMODE_INIT_FLAG); + APPLY_PRINT("%s - Deleted %s to force stackmode reconfiguration\n", __FUNCTION__, SETSTACKMODE_INIT_FLAG); + } +#endif } if ( access( PARTNER_DEFAULT_MIGRATE_PSM , F_OK ) == 0 ) @@ -3534,37 +3543,27 @@ static void getPartnerIdWithRetry(char* buf, char* PartnerID) } #if defined(_ONESTACK_PRODUCT_REQ_) - // Set stackmode based on /nvram/setstackmode marker file - if (access(SETSTACKMODE_FILE, F_OK) == 0) + // Set stackmode based on business-mode marker file + if (access(BUSINESS_MODE_FILE, F_OK) == 0) { - // File exists, set to business-commercial-mode - if (syscfg_set(NULL, "stackmode", "commercial") == 0) + // Business mode marker file exists, set to business mode + if (syscfg_set(NULL, "stackmode", "business") == 0) { syscfg_commit(); - APPLY_PRINT("%s - Set stackmode to commercial\n", __FUNCTION__); - - // Delete the marker file after successfully setting syscfg - if (unlink(SETSTACKMODE_FILE) == 0) - { - APPLY_PRINT("%s - Deleted marker file: %s\n", __FUNCTION__, SETSTACKMODE_FILE); - } - else - { - APPLY_PRINT("%s - Warning: Failed to delete marker file: %s\n", __FUNCTION__, SETSTACKMODE_FILE); - } + APPLY_PRINT("%s - Set stackmode to business (marker file present)\n", __FUNCTION__); } else { - APPLY_PRINT("%s - Failed to set stackmode to commercial\n", __FUNCTION__); + APPLY_PRINT("%s - Failed to set stackmode to business\n", __FUNCTION__); } } else { - // File does not exist, set to residential-mode + // No business mode marker file, set to residential mode if (syscfg_set(NULL, "stackmode", "residential") == 0) { syscfg_commit(); - APPLY_PRINT("%s - Set stackmode to residential\n", __FUNCTION__); + APPLY_PRINT("%s - Set stackmode to residential (no marker file)\n", __FUNCTION__); } else { diff --git a/source/scripts/init/system/utopia_init_xb6.sh b/source/scripts/init/system/utopia_init_xb6.sh index f3cd4738..2d75ea65 100755 --- a/source/scripts/init/system/utopia_init_xb6.sh +++ b/source/scripts/init/system/utopia_init_xb6.sh @@ -287,12 +287,25 @@ CheckAndReCreateDB() fi } -# Call stackmode binary to set stackmode marker -if [ -x /usr/bin/stackmode ]; then - echo "[utopia][init] Calling stackmode binary to configure stack mode" - /usr/bin/stackmode +# Call setstackmode binary to set stackmode marker (with optimization) +if [ -x /usr/bin/setstackmode ]; then + SETSTACKMODE_INIT_FLAG="/nvram/.setstackmode_intialize" + + # Optimization: Check if initialization flag exists + if [ -f "$SETSTACKMODE_INIT_FLAG" ]; then + echo "[utopia][init] setstackmode already initialized, skipping binary execution" + else + echo "[utopia][init] Calling setstackmode binary to configure stack mode" + /usr/bin/setstackmode + ret=$? + if [ $ret -eq 0 ]; then + echo "[utopia][init] setstackmode binary executed successfully (return code: $ret)" + else + echo "[utopia][init] setstackmode binary failed with return code: $ret" + fi + fi else - echo "[utopia][init] stackmode binary not found, skipping stack mode configuration" + echo "[utopia][init] setstackmode binary not found, skipping stack mode configuration" fi echo "[utopia][init] Starting syscfg using file store ($SYSCFG_NEW_FILE)"