mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2025-12-10 07:44:41 +01:00
Fix cwmp notification sending
This commit is contained in:
parent
9015576137
commit
2eeb099061
6 changed files with 135 additions and 35 deletions
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <json-c/json.h>
|
||||||
|
|
||||||
#include "notifications.h"
|
#include "notifications.h"
|
||||||
#include "uci_utils.h"
|
#include "uci_utils.h"
|
||||||
|
|
@ -30,6 +31,7 @@ LIST_HEAD(list_param_obj_notify);
|
||||||
|
|
||||||
static int cr_url_retry = 3;
|
static int cr_url_retry = 3;
|
||||||
|
|
||||||
|
static void update_notify_file_line(FILE *notify_file, char *param_name, char *param_type, char *param_value, int notification);
|
||||||
static void create_list_param_leaf_notify(struct list_head *, void (*fp)(FILE *, char *, char *, char *, int), FILE*);
|
static void create_list_param_leaf_notify(struct list_head *, void (*fp)(FILE *, char *, char *, char *, int), FILE*);
|
||||||
static void send_active_value_change(void);
|
static void send_active_value_change(void);
|
||||||
static void add_list_value_change(const char *param_name, const char *param_data, const char *param_type);
|
static void add_list_value_change(const char *param_name, const char *param_data, const char *param_type);
|
||||||
|
|
@ -402,6 +404,113 @@ void create_list_param_leaf_notify(struct list_head *list_param_leaf_notify, voi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void load_notify_values(struct list_head *notify_list)
|
||||||
|
{
|
||||||
|
if (notify_list == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// cppcheck-suppress cert-MSC24-C
|
||||||
|
FILE *fp = fopen(DM_ENABLED_NOTIFY, "r");
|
||||||
|
if (fp == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
char line[2048] = {0};
|
||||||
|
|
||||||
|
while (fgets(line, sizeof(line), fp)) {
|
||||||
|
const char *p_name = NULL, *p_val = NULL, *p_type = NULL;
|
||||||
|
int p_notif = 0;
|
||||||
|
|
||||||
|
json_object *jobj = json_tokener_parse(line);
|
||||||
|
if (jobj == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
json_object *p_obj = json_object_object_get(jobj, "parameter");
|
||||||
|
json_object *v_obj = json_object_object_get(jobj, "value");
|
||||||
|
json_object *n_obj = json_object_object_get(jobj, "notification");
|
||||||
|
json_object *t_obj = json_object_object_get(jobj, "type");
|
||||||
|
|
||||||
|
if (p_obj == NULL || v_obj == NULL || n_obj == NULL || t_obj == NULL) {
|
||||||
|
json_object_put(jobj);
|
||||||
|
jobj = NULL;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
p_name = json_object_get_string(p_obj);
|
||||||
|
p_val = json_object_get_string(v_obj);
|
||||||
|
p_notif = json_object_get_int(n_obj);
|
||||||
|
p_type = json_object_get_string(t_obj);
|
||||||
|
|
||||||
|
add_dm_parameter_to_list(notify_list, p_name, p_val, p_type, p_notif, 0);
|
||||||
|
|
||||||
|
json_object_put(jobj);
|
||||||
|
jobj = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void apply_notify_values(struct list_head *notify_list)
|
||||||
|
{
|
||||||
|
if (notify_list == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (list_empty(notify_list))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// cppcheck-suppress cert-MSC24-C
|
||||||
|
FILE *fp = fopen(DM_ENABLED_NOTIFY, "w");
|
||||||
|
if (fp == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
struct cwmp_dm_parameter *notif_value = NULL;
|
||||||
|
list_for_each_entry(notif_value, notify_list, list) {
|
||||||
|
update_notify_file_line(fp, notif_value->name, notif_value->type, notif_value->value, notif_value->notification);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cwmp_update_notify_values(struct list_head *parameter_values_list)
|
||||||
|
{
|
||||||
|
struct cwmp_dm_parameter *param_value = NULL, *notif_value = NULL;
|
||||||
|
bool value_changed = false;
|
||||||
|
|
||||||
|
LIST_HEAD(notify_list);
|
||||||
|
|
||||||
|
load_notify_values(¬ify_list);
|
||||||
|
|
||||||
|
if (list_empty(¬ify_list))
|
||||||
|
return;
|
||||||
|
|
||||||
|
list_for_each_entry(param_value, parameter_values_list, list) {
|
||||||
|
if (CWMP_STRLEN(param_value->name) == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
char *inst_path = NULL;
|
||||||
|
if (CWMP_OK != instantiate_param_name(param_value->name, &inst_path))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
list_for_each_entry(notif_value, ¬ify_list, list) {
|
||||||
|
if (CWMP_STRCMP(inst_path, notif_value->name) == 0) {
|
||||||
|
if (CWMP_STRCMP(param_value->value, notif_value->value) != 0) {
|
||||||
|
FREE(notif_value->value);
|
||||||
|
notif_value->value = strdup(param_value->value);
|
||||||
|
value_changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FREE(inst_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value_changed == true) {
|
||||||
|
apply_notify_values(¬ify_list);
|
||||||
|
}
|
||||||
|
|
||||||
|
cwmp_free_all_dm_parameter_list(¬ify_list);
|
||||||
|
}
|
||||||
|
|
||||||
void init_list_param_notify()
|
void init_list_param_notify()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -564,6 +673,7 @@ static void get_parameter_value_from_parameters_list(struct list_head *params_li
|
||||||
continue;
|
continue;
|
||||||
if (strcmp(parameter_name, param_value->name) != 0)
|
if (strcmp(parameter_name, param_value->name) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
*value = strdup(param_value->value ? param_value->value : "");
|
*value = strdup(param_value->value ? param_value->value : "");
|
||||||
*type = strdup(param_value->type ? param_value->type : "");
|
*type = strdup(param_value->type ? param_value->type : "");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,4 +52,5 @@ void init_list_param_notify();
|
||||||
void reinit_list_param_notify();
|
void reinit_list_param_notify();
|
||||||
void cwmp_prepare_value_change(void);
|
void cwmp_prepare_value_change(void);
|
||||||
void trigger_periodic_notify_check();
|
void trigger_periodic_notify_check();
|
||||||
|
void cwmp_update_notify_values(struct list_head *parameter_values_list);
|
||||||
#endif /* SRC_INC_NOTIFICATIONS_H_ */
|
#endif /* SRC_INC_NOTIFICATIONS_H_ */
|
||||||
|
|
|
||||||
|
|
@ -1207,7 +1207,9 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct rpc *rpc)
|
||||||
goto fault;
|
goto fault;
|
||||||
}
|
}
|
||||||
|
|
||||||
cwmp_set_end_session(END_SESSION_SET_NOTIFICATION_UPDATE | END_SESSION_RELOAD);
|
/* update values in notify file if any notify enable parameter exist in spv list */
|
||||||
|
cwmp_update_notify_values(&list_set_param_value);
|
||||||
|
|
||||||
if (status == 1) {
|
if (status == 1) {
|
||||||
cwmp_set_end_session(END_SESSION_RESTART_SERVICES);
|
cwmp_set_end_session(END_SESSION_RESTART_SERVICES);
|
||||||
}
|
}
|
||||||
|
|
@ -1284,7 +1286,8 @@ int cwmp_handle_rpc_cpe_set_parameter_attributes(struct rpc *rpc)
|
||||||
goto fault;
|
goto fault;
|
||||||
}
|
}
|
||||||
|
|
||||||
cwmp_set_end_session(END_SESSION_SET_NOTIFICATION_UPDATE | END_SESSION_RESTART_SERVICES | END_SESSION_INIT_NOTIFY);
|
reinit_list_param_notify();
|
||||||
|
cwmp_update_enabled_notify_file();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fault:
|
fault:
|
||||||
|
|
|
||||||
|
|
@ -694,16 +694,6 @@ int run_session_end_func(void)
|
||||||
reinit_cwmp_periodic_session_feature();
|
reinit_cwmp_periodic_session_feature();
|
||||||
reinit_heartbeat_procedures();
|
reinit_heartbeat_procedures();
|
||||||
|
|
||||||
if (end_session_flag & END_SESSION_INIT_NOTIFY) {
|
|
||||||
CWMP_LOG(INFO, "SetParameterAttributes end session: reinit list notify");
|
|
||||||
reinit_list_param_notify();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (end_session_flag & END_SESSION_SET_NOTIFICATION_UPDATE) {
|
|
||||||
CWMP_LOG(INFO, "SetParameterAttributes/Values end session: update enabled notify file");
|
|
||||||
cwmp_update_enabled_notify_file();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (end_session_flag & END_SESSION_NSLOOKUP_DIAGNOSTIC) {
|
if (end_session_flag & END_SESSION_NSLOOKUP_DIAGNOSTIC) {
|
||||||
CWMP_LOG(INFO, "Executing nslookupdiagnostic: end session request");
|
CWMP_LOG(INFO, "Executing nslookupdiagnostic: end session request");
|
||||||
cwmp_nslookup_diagnostics();
|
cwmp_nslookup_diagnostics();
|
||||||
|
|
|
||||||
|
|
@ -54,30 +54,27 @@ enum end_session_enum
|
||||||
{
|
{
|
||||||
END_SESSION_REBOOT = 1,
|
END_SESSION_REBOOT = 1,
|
||||||
END_SESSION_EXTERNAL_ACTION = 1 << 1,
|
END_SESSION_EXTERNAL_ACTION = 1 << 1,
|
||||||
END_SESSION_RELOAD = 1 << 2,
|
END_SESSION_FACTORY_RESET = 1 << 2,
|
||||||
END_SESSION_FACTORY_RESET = 1 << 3,
|
END_SESSION_X_FACTORY_RESET_SOFT = 1 << 3,
|
||||||
END_SESSION_X_FACTORY_RESET_SOFT = 1 << 4,
|
|
||||||
|
|
||||||
END_SESSION_IPPING_DIAGNOSTIC = 1 << 5,
|
END_SESSION_IPPING_DIAGNOSTIC = 1 << 4,
|
||||||
END_SESSION_DOWNLOAD_DIAGNOSTIC = 1 << 6,
|
END_SESSION_DOWNLOAD_DIAGNOSTIC = 1 << 5,
|
||||||
END_SESSION_UPLOAD_DIAGNOSTIC = 1 << 7,
|
END_SESSION_UPLOAD_DIAGNOSTIC = 1 << 6,
|
||||||
END_SESSION_NSLOOKUP_DIAGNOSTIC = 1 << 8,
|
END_SESSION_NSLOOKUP_DIAGNOSTIC = 1 << 7,
|
||||||
END_SESSION_TRACEROUTE_DIAGNOSTIC = 1 << 9,
|
END_SESSION_TRACEROUTE_DIAGNOSTIC = 1 << 8,
|
||||||
END_SESSION_UDPECHO_DIAGNOSTIC = 1 << 10,
|
END_SESSION_UDPECHO_DIAGNOSTIC = 1 << 9,
|
||||||
END_SESSION_SERVERSELECTION_DIAGNOSTIC = 1 << 11,
|
END_SESSION_SERVERSELECTION_DIAGNOSTIC = 1 << 10,
|
||||||
END_SESSION_NEIGBORING_WIFI_DIAGNOSTIC = 1<<12,
|
END_SESSION_NEIGBORING_WIFI_DIAGNOSTIC = 1<<11,
|
||||||
END_SESSION_IPLAYERCAPACITY_DIAGNOSTIC = 1 << 13,
|
END_SESSION_IPLAYERCAPACITY_DIAGNOSTIC = 1 << 12,
|
||||||
|
|
||||||
END_SESSION_SET_NOTIFICATION_UPDATE = 1 << 14,
|
END_SESSION_RESTART_SERVICES = 1 << 13,
|
||||||
END_SESSION_RESTART_SERVICES = 1 << 15,
|
END_SESSION_DOWNLOAD = 1 << 14,
|
||||||
END_SESSION_INIT_NOTIFY = 1 << 16,
|
END_SESSION_SCHEDULE_DOWNLOAD = 1 << 15,
|
||||||
END_SESSION_DOWNLOAD = 1 << 17,
|
END_SESSION_UPLOAD = 1 << 16,
|
||||||
END_SESSION_SCHEDULE_DOWNLOAD = 1 << 18,
|
END_SESSION_SCHEDULE_INFORM = 1 << 17,
|
||||||
END_SESSION_UPLOAD = 1 << 19,
|
END_SESSION_CDU = 1 << 18,
|
||||||
END_SESSION_SCHEDULE_INFORM = 1 << 20,
|
END_SESSION_PACKETCAPTURE_DIAGNOSTIC = 1 << 19,
|
||||||
END_SESSION_CDU = 1 << 21,
|
END_SESSION_SELFTEST_DIAGNOSTIC = 1 << 20,
|
||||||
END_SESSION_PACKETCAPTURE_DIAGNOSTIC = 1 << 22,
|
|
||||||
END_SESSION_SELFTEST_DIAGNOSTIC = 1 << 23,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum enum_session_status
|
enum enum_session_status
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,6 @@ static int reload_cmd(struct blob_buf *b)
|
||||||
{
|
{
|
||||||
CWMP_LOG(INFO, "triggered ubus reload");
|
CWMP_LOG(INFO, "triggered ubus reload");
|
||||||
if (cwmp_ctx.session->session_status.last_status == SESSION_RUNNING) {
|
if (cwmp_ctx.session->session_status.last_status == SESSION_RUNNING) {
|
||||||
cwmp_set_end_session(END_SESSION_RELOAD);
|
|
||||||
blobmsg_add_u32(b, "status", 0);
|
blobmsg_add_u32(b, "status", 0);
|
||||||
blobmsg_add_string(b, "info", "Session running, reload at the end of the session");
|
blobmsg_add_string(b, "info", "Session running, reload at the end of the session");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue