Ticker refs #8912: icwmp: Add support for default active notifications

This commit is contained in:
Omar Kallel 2022-10-04 14:08:50 +01:00
parent 7f24daa02f
commit 1b7b0e2918
5 changed files with 46 additions and 16 deletions

View file

@ -247,6 +247,7 @@ static int cwmp_init()
CWMP_LOG(DEBUG, "Successfully load icwmpd configuration");
cwmp_get_deviceid();
load_custom_notify_json();
set_default_forced_active_parameters_notifications();
init_list_param_notify();
create_cwmp_session_structure();
get_nonce_key();

View file

@ -19,6 +19,8 @@
#include "log.h"
#include "session.h"
#include "cwmp_event.h"
#include "notifications.h"
//#include <libubox/list.h>
const struct EVENT_CONST_STRUCT EVENT_CONST[] = {[EVENT_IDX_0BOOTSTRAP] = { "0 BOOTSTRAP", EVENT_RETRY_AFTER_TRANSMIT_FAIL | EVENT_RETRY_AFTER_REBOOT },

View file

@ -29,10 +29,18 @@ struct uloop_timeout check_notify_timer = { .cb = periodic_check_notifiy };
char *notifications[7] = {"disabled" , "passive", "active", "passive_lw", "passive_passive_lw", "active_lw", "passive_active_lw"};
struct cwmp_dm_parameter forced_notifications_parameters[] = {
{.name = "Device.DeviceInfo.SoftwareVersion", .notification = 2, .forced_notification_param = true},
{.name = "Device.DeviceInfo.ProvisioningCode", .notification = 2, .forced_notification_param = true},
{.name = "Device.ManagementServer.ConnectionRequestURL", .notification = 2, .forced_notification_param = true}
char *default_active_notifications_parameters[] = {
"Device.ManagementServer.ConnectionRequestURL",
"Device.ManagementServer.ConnReqJabberID",
"Device.GatewayInfo.ManufacturerOUI",
"Device.GatewayInfo.ProductClass",
"Device.GatewayInfo.SerialNumber",
"Device.SoftwareModules.ExecutionUnit.*.Status",
};
char *forced_notifications_parameters[] = {
"Device.DeviceInfo.SoftwareVersion",
"Device.DeviceInfo.ProvisioningCode"
};
/*
@ -64,8 +72,8 @@ int check_parameter_forced_notification(const char *parameter)
}
for (i = 0; i < (int)ARRAY_SIZE(forced_notifications_parameters); i++) {
if (strcmp(forced_notifications_parameters[i].name, parameter) == 0)
return forced_notifications_parameters[i].notification;
if (strcmp(forced_notifications_parameters[i], parameter) == 0)
return 2;
}
return 0;
@ -336,19 +344,19 @@ void create_list_param_obj_notify()
}
}
char* update_list_param_leaf_notify_with_sub_parameter_list(struct list_head *list_param_leaf_notify, struct cwmp_dm_parameter parent_parameter, void (*update_notify_file_line_arg)(FILE *notify_file, char *param_name, char *param_type, char *param_value, int notification), FILE* notify_file_arg)
char* update_list_param_leaf_notify_with_sub_parameter_list(struct list_head *list_param_leaf_notify, char* parent_parameter, int parent_notification, bool parent_forced_notif, void (*update_notify_file_line_arg)(FILE *notify_file, char *param_name, char *param_type, char *param_value, int notification), FILE* notify_file_arg)
{
struct cwmp_dm_parameter *param_iter = NULL;
LIST_HEAD(params_list);
char *err = cwmp_get_parameter_values(parent_parameter.name, &params_list);
char *err = cwmp_get_parameter_values(parent_parameter, &params_list);
if (err)
return err;
list_for_each_entry (param_iter, &params_list, list) {
if (parent_parameter.forced_notification_param || (!parameter_is_other_notif_object_child(parent_parameter.name, param_iter->name) && !check_parameter_forced_notification(param_iter->name))) {
if (parent_forced_notif || (!parameter_is_other_notif_object_child(parent_parameter, param_iter->name) && !check_parameter_forced_notification(param_iter->name))) {
if (list_param_leaf_notify != NULL)
add_dm_parameter_to_list(list_param_leaf_notify, param_iter->name, param_iter->value, "", parent_parameter.notification, false);
add_dm_parameter_to_list(list_param_leaf_notify, param_iter->name, param_iter->value, "", parent_notification, false);
if (notify_file_arg != NULL && update_notify_file_line_arg != NULL)
update_notify_file_line_arg(notify_file_arg, param_iter->name, param_iter->type, param_iter->value, parent_parameter.notification);
update_notify_file_line_arg(notify_file_arg, param_iter->name, param_iter->type, param_iter->value, parent_notification);
}
}
cwmp_free_all_dm_parameter_list(&params_list);
@ -361,13 +369,12 @@ void create_list_param_leaf_notify(struct list_head *list_param_leaf_notify, voi
int i;
for (i = 0; i < (int)ARRAY_SIZE(forced_notifications_parameters); i++)
update_list_param_leaf_notify_with_sub_parameter_list(list_param_leaf_notify, forced_notifications_parameters[i], update_notify_file_line_arg, notify_file_arg);
update_list_param_leaf_notify_with_sub_parameter_list(list_param_leaf_notify, forced_notifications_parameters[i], 2, true, update_notify_file_line_arg, notify_file_arg);
list_for_each_entry (param_iter, &list_param_obj_notify, list) {
if (param_iter->notification == 0)
continue;
param_iter->forced_notification_param = false;
update_list_param_leaf_notify_with_sub_parameter_list(list_param_leaf_notify, *param_iter, update_notify_file_line_arg, notify_file_arg);
update_list_param_leaf_notify_with_sub_parameter_list(list_param_leaf_notify, param_iter->name, param_iter->notification, false, update_notify_file_line_arg, notify_file_arg);
}
}
@ -490,6 +497,25 @@ void load_custom_notify_json()
cwmp_main->custom_notify_active = true;
}
void set_default_forced_active_parameters_notifications()
{
int i;
int nbre_default_active_parameters = (int)ARRAY_SIZE(default_active_notifications_parameters);
for (i = 0; i < nbre_default_active_parameters; i++) {
char *fault = cwmp_set_parameter_attributes(default_active_notifications_parameters[i], 2);
if (fault == NULL)
continue;
if (strcmp(fault, "9005") == 0) {
CWMP_LOG(WARNING, "The parameter %s is wrong path", default_active_notifications_parameters[i]);
continue;
}
if (strcmp(fault, "9009") == 0) {
CWMP_LOG(WARNING, "This parameter %s is forced notification parameter, can't be changed", default_active_notifications_parameters[i]);
continue;
}
}
}
/*
* Check value change
*/

View file

@ -27,7 +27,7 @@ enum NOTIFICATION_STATUS
NOTIF_LW_ACTIVE = 1 << 4
};
extern struct cwmp_dm_parameter forced_notifications_parameters[];
extern char *forced_notifications_parameters[];
extern struct list_head list_lw_value_change;
extern struct list_head list_value_change;
extern struct list_head list_param_obj_notify;
@ -61,6 +61,7 @@ void clean_list_value_change();
char *cwmp_set_parameter_attributes(char *parameter_name, int notification);
char *cwmp_get_parameter_attributes(char *parameter_name, struct list_head *parameters_list);
void load_custom_notify_json();
void set_default_forced_active_parameters_notifications();
void add_lw_list_value_change(char *param_name, char *param_data, char *param_type);
char *calculate_lwnotification_cnonce();
void cwmp_lwnotification();

View file

@ -143,7 +143,7 @@ static void cwmp_update_notify_file_unit_test_default(void **state)
cwmp_update_enabled_notify_file();
int notification = 0, nbre_iter = 0;
nbre_iter = check_notify_file("Device.DeviceInfo.ProvisioningCode", &notification);
assert_int_equal(nbre_iter, 3);
assert_int_equal(nbre_iter, 2);
assert_int_equal(notification, 2);
}