Align with new uci config name: 'deviceinfo' -> 'reboots'

This commit is contained in:
Amin Ben Romdhane 2024-11-06 11:07:27 +01:00
parent 99e62413e1
commit aaca7af64e
3 changed files with 23 additions and 23 deletions

View file

@ -4,18 +4,18 @@ In TR-181 version 2.18, a new object, Device.DeviceInfo.Reboots, was introduced
Currently, there is no standard configuration mapping to this object. However, we propose introducing a custom config called `sysmngr` to manage this information effectively. Currently, there is no standard configuration mapping to this object. However, we propose introducing a custom config called `sysmngr` to manage this information effectively.
The idea is to maintain a 1-to-1 mapping between the parameters and UCI config. To achieve this, we need to create an `init.d` service script that generates a UCI section each time the start_service() function is called. Essentially, when the start_service() function is executed, it will check the `/tmp/reset_reason` file for specific markers, such as (reset reason) and (reset triggered), to identify the cause of the last boot. And based on these markers, it will calculate the required counter for data model parameters and commit the changes in `sysmngr.deviceinfo` section. Furthermore, if necessary, it will create a UCI reboot section by checking `sysmngr.deviceinfo.max_reboot_entries` and adjusting the config accordingly. The idea is to maintain a 1-to-1 mapping between the parameters and UCI config. To achieve this, we need to create an `init.d` service script that generates a UCI section each time the start_service() function is called. Essentially, when the start_service() function is executed, it will check the `/tmp/reset_reason` file for specific markers, such as (reset reason) and (reset triggered), to identify the cause of the last boot. And based on these markers, it will calculate the required counter for data model parameters and commit the changes in `sysmngr.reboots` section. Furthermore, if necessary, it will create a UCI reboot section by checking `sysmngr.reboots.max_reboot_entries` and adjusting the config accordingly.
This approach ensures that the data model maps directly to UCI config as closely as possible, eliminating the need for any adjustments at the data model layer. This approach ensures that the data model maps directly to UCI config as closely as possible, eliminating the need for any adjustments at the data model layer.
## Parameter Mapping Details ## Parameter Mapping Details
- Device.DeviceInfo.Reboots.BootCount: Maps to sysmngr.deviceinfo.boot_count. This value is determined based on the marker (reset triggered: defaultreset) defined in `/tmp/reset_reason` file. - Device.DeviceInfo.Reboots.BootCount: Maps to sysmngr.reboots.boot_count. This value is determined based on the marker (reset triggered: defaultreset) defined in `/tmp/reset_reason` file.
- Device.DeviceInfo.Reboots.CurrentVersionBootCount: Maps to sysmngr.deviceinfo.curr_version_boot_count. This value is determined based on the marker (reset triggered: upgrade) defined in `/tmp/reset_reason` file. - Device.DeviceInfo.Reboots.CurrentVersionBootCount: Maps to sysmngr.reboots.curr_version_boot_count. This value is determined based on the marker (reset triggered: upgrade) defined in `/tmp/reset_reason` file.
- Device.DeviceInfo.Reboots.WatchdogBootCount: Maps to sysmngr.deviceinfo.watchdog_boot_count. This value is determined based on the marker (reset reason: WATCHDOG) defined in `/tmp/reset_reason` file. - Device.DeviceInfo.Reboots.WatchdogBootCount: Maps to sysmngr.reboots.watchdog_boot_count. This value is determined based on the marker (reset reason: WATCHDOG) defined in `/tmp/reset_reason` file.
- Device.DeviceInfo.Reboots.ColdBootCount: Maps to sysmngr.deviceinfo.cold_boot_count. This value is determined based on the marker (reset reason: POR_RESET) defined in `/tmp/reset_reason` file. - Device.DeviceInfo.Reboots.ColdBootCount: Maps to sysmngr.reboots.cold_boot_count. This value is determined based on the marker (reset reason: POR_RESET) defined in `/tmp/reset_reason` file.
- Device.DeviceInfo.Reboots.WarmBootCount: Maps to sysmngr.deviceinfo.warm_boot_count. This value is determined based on the marker (reset reason: POR_RESET) defined in `/tmp/reset_reason` file. - Device.DeviceInfo.Reboots.WarmBootCount: Maps to sysmngr.reboots.warm_boot_count. This value is determined based on the marker (reset reason: POR_RESET) defined in `/tmp/reset_reason` file.
- Device.DeviceInfo.Reboots.MaxRebootEntries: Maps to sysmngr.deviceinfo.max_reboot_entries. Possible values include {-1, 0, etc..}. Each case will be handled internally by bbfdm and default value is 3 and maximum reboot entry supported is 255. - Device.DeviceInfo.Reboots.MaxRebootEntries: Maps to sysmngr.reboots.max_reboot_entries. Possible values include {-1, 0, etc..}. Each case will be handled internally by bbfdm and default value is 3 and maximum reboot entry supported is 255.
- Device.DeviceInfo.Reboots.RebootNumberOfEntries: This is an internal bbfdm mechanism used to count the number of reboot entries. - Device.DeviceInfo.Reboots.RebootNumberOfEntries: This is an internal bbfdm mechanism used to count the number of reboot entries.
- Device.DeviceInfo.Reboots.RemoveAllReboots(): An internal bbfdm API to remove all reboot sections. - Device.DeviceInfo.Reboots.RemoveAllReboots(): An internal bbfdm API to remove all reboot sections.
- Device.DeviceInfo.Reboots.Reboot.{i}.: Each reboot entry is stored in a 'reboot' section. - Device.DeviceInfo.Reboots.Reboot.{i}.: Each reboot entry is stored in a 'reboot' section.
@ -34,7 +34,7 @@ Below is an example of the configuration file:
```bash ```bash
cat /etc/config/sysmngr cat /etc/config/sysmngr
config device-info 'deviceinfo' config reboots 'reboots'
option boot_count '2' option boot_count '2'
option curr_version_boot_count '4' option curr_version_boot_count '4'
option watchdog_boot_count '3' option watchdog_boot_count '3'

View file

@ -28,7 +28,7 @@ static void _exec_reboot(const void *arg1, void *arg2)
snprintf(config_name, sizeof(config_name), "%s", "sysmngr"); snprintf(config_name, sizeof(config_name), "%s", "sysmngr");
// Set last_reboot_cause to 'RemoteReboot' because the upcoming reboot will be initiated by USP Operate // Set last_reboot_cause to 'RemoteReboot' because the upcoming reboot will be initiated by USP Operate
dmuci_set_value(config_name, "deviceinfo", "last_reboot_cause", "RemoteReboot"); dmuci_set_value(config_name, "reboots", "last_reboot_cause", "RemoteReboot");
dmuci_commit_package(config_name); dmuci_commit_package(config_name);
sleep(3); sleep(3);
@ -40,7 +40,7 @@ static void _exec_reboot(const void *arg1, void *arg2)
BBF_ERR("Reboot call failed!!!"); BBF_ERR("Reboot call failed!!!");
// Set last_reboot_cause to empty because there is a problem in the system reboot // Set last_reboot_cause to empty because there is a problem in the system reboot
dmuci_set_value(config_name, "deviceinfo", "last_reboot_cause", ""); dmuci_set_value(config_name, "reboots", "last_reboot_cause", "");
dmuci_commit_package(config_name); dmuci_commit_package(config_name);
} }

View file

@ -29,19 +29,19 @@ static int g_retry_count = 0;
static void reset_option_counter(const char *option_name, const char *option_value) static void reset_option_counter(const char *option_name, const char *option_value)
{ {
sysmngr_uci_set("sysmngr", "deviceinfo", option_name, option_value); sysmngr_uci_set("sysmngr", "reboots", option_name, option_value);
} }
static void increment_option_counter(const char *option_name) static void increment_option_counter(const char *option_name)
{ {
char buf[16] = {0}; char buf[16] = {0};
sysmngr_uci_get("sysmngr", "deviceinfo", option_name, "0", buf, sizeof(buf)); sysmngr_uci_get("sysmngr", "reboots", option_name, "0", buf, sizeof(buf));
int counter = (int)strtol(buf, NULL, 10) + 1; int counter = (int)strtol(buf, NULL, 10) + 1;
snprintf(buf, sizeof(buf), "%d", counter); snprintf(buf, sizeof(buf), "%d", counter);
sysmngr_uci_set("sysmngr", "deviceinfo", option_name, buf); sysmngr_uci_set("sysmngr", "reboots", option_name, buf);
} }
static void get_boot_option_value(const char *option_name, char *buffer, size_t buffer_size) static void get_boot_option_value(const char *option_name, char *buffer, size_t buffer_size)
@ -185,9 +185,9 @@ static void create_reboot_section(const char *trigger, const char *reason)
sysmngr_uci_set("sysmngr", sec_name, "cause", "FactoryReset"); sysmngr_uci_set("sysmngr", sec_name, "cause", "FactoryReset");
} else { } else {
char last_reboot_cause[32] = {0}; char last_reboot_cause[32] = {0};
sysmngr_uci_get("sysmngr", "deviceinfo", "last_reboot_cause", "LocalReboot", last_reboot_cause, sizeof(last_reboot_cause)); sysmngr_uci_get("sysmngr", "reboots", "last_reboot_cause", "LocalReboot", last_reboot_cause, sizeof(last_reboot_cause));
sysmngr_uci_set("sysmngr", sec_name, "cause", last_reboot_cause); sysmngr_uci_set("sysmngr", sec_name, "cause", last_reboot_cause);
sysmngr_uci_set("sysmngr", "deviceinfo", "last_reboot_cause", ""); sysmngr_uci_set("sysmngr", "reboots", "last_reboot_cause", "");
} }
sysmngr_uci_set("sysmngr", sec_name, "reason", boot_reason_message(trigger, reason)); sysmngr_uci_set("sysmngr", sec_name, "reason", boot_reason_message(trigger, reason));
@ -224,7 +224,7 @@ static void sysmngr_register_boot_action(void)
increment_option_counter("warm_boot_count"); increment_option_counter("warm_boot_count");
} }
sysmngr_uci_get("sysmngr", "deviceinfo", "max_reboot_entries", "3", max_entries, sizeof(max_entries)); sysmngr_uci_get("sysmngr", "reboots", "max_reboot_entries", "3", max_entries, sizeof(max_entries));
int max_reboot_entries = (int)strtol(max_entries, NULL, 10); int max_reboot_entries = (int)strtol(max_entries, NULL, 10);
if (max_reboot_entries != 0) { if (max_reboot_entries != 0) {
@ -293,37 +293,37 @@ static int browseDeviceInfoRebootsRebootInst(struct dmctx *dmctx, DMNODE *parent
**************************************************************/ **************************************************************/
static int get_DeviceInfoReboots_BootCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_DeviceInfoReboots_BootCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
dmuci_get_option_value_string("sysmngr", "deviceinfo", "boot_count", value); dmuci_get_option_value_string("sysmngr", "reboots", "boot_count", value);
return 0; return 0;
} }
static int get_DeviceInfoReboots_CurrentVersionBootCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_DeviceInfoReboots_CurrentVersionBootCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
dmuci_get_option_value_string("sysmngr", "deviceinfo", "curr_version_boot_count", value); dmuci_get_option_value_string("sysmngr", "reboots", "curr_version_boot_count", value);
return 0; return 0;
} }
static int get_DeviceInfoReboots_WatchdogBootCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_DeviceInfoReboots_WatchdogBootCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
dmuci_get_option_value_string("sysmngr", "deviceinfo", "watchdog_boot_count", value); dmuci_get_option_value_string("sysmngr", "reboots", "watchdog_boot_count", value);
return 0; return 0;
} }
static int get_DeviceInfoReboots_ColdBootCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_DeviceInfoReboots_ColdBootCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
dmuci_get_option_value_string("sysmngr", "deviceinfo", "cold_boot_count", value); dmuci_get_option_value_string("sysmngr", "reboots", "cold_boot_count", value);
return 0; return 0;
} }
static int get_DeviceInfoReboots_WarmBootCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_DeviceInfoReboots_WarmBootCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
dmuci_get_option_value_string("sysmngr", "deviceinfo", "warm_boot_count", value); dmuci_get_option_value_string("sysmngr", "reboots", "warm_boot_count", value);
return 0; return 0;
} }
static int get_DeviceInfoReboots_MaxRebootEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_DeviceInfoReboots_MaxRebootEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
*value = dmuci_get_option_value_fallback_def("sysmngr", "deviceinfo", "max_reboot_entries", "3"); *value = dmuci_get_option_value_fallback_def("sysmngr", "reboots", "max_reboot_entries", "3");
return 0; return 0;
} }
@ -365,7 +365,7 @@ static int set_DeviceInfoReboots_MaxRebootEntries(char *refparam, struct dmctx *
} }
} }
dmuci_set_value("sysmngr", "deviceinfo", "max_reboot_entries", value); dmuci_set_value("sysmngr", "reboots", "max_reboot_entries", value);
break; break;
} }
return 0; return 0;