Convert diagnostics to async operation

This commit is contained in:
Suvendhu Hansa 2024-10-07 19:14:56 +05:30 committed by Vivek Kumar Dutta
parent 153f4bfce3
commit b671efa938
5 changed files with 59 additions and 21 deletions

View file

@ -197,7 +197,6 @@ typedef struct cwmp {
bool prev_periodic_enable; bool prev_periodic_enable;
bool prev_heartbeat_enable; bool prev_heartbeat_enable;
bool heart_session; bool heart_session;
bool diag_session;
bool throttle_session; bool throttle_session;
int prev_periodic_interval; int prev_periodic_interval;
int prev_heartbeat_interval; int prev_heartbeat_interval;

View file

@ -255,6 +255,16 @@ bool set_diagnostic_parameter_structure_value(char *parameter_name, char *value)
} }
static void diagnostics_complete_cb(struct ubus_request *req, int ret)
{
struct session_timer_event *periodic_inform_event = calloc(1, sizeof(struct session_timer_event));
periodic_inform_event->session_timer_evt.cb = cwmp_schedule_session_with_event;
periodic_inform_event->event = EVENT_IDX_8DIAGNOSTICS_COMPLETE;
trigger_cwmp_session_timer_with_event(&periodic_inform_event->session_timer_evt);
FREE(req);
}
static int cwmp_diagnostics_operate(const char *command, const char *command_key, struct diagnostic_input diagnostics[], int number_inputs) static int cwmp_diagnostics_operate(const char *command, const char *command_key, struct diagnostic_input diagnostics[], int number_inputs)
{ {
struct blob_buf b = {0}; struct blob_buf b = {0};
@ -279,7 +289,7 @@ static int cwmp_diagnostics_operate(const char *command, const char *command_key
blobmsg_close_table(&b, tbl); blobmsg_close_table(&b, tbl);
} }
int e = icwmp_ubus_invoke(BBFDM_OBJECT_NAME, "operate", b.head, NULL, NULL); int e = icwmp_ubus_invoke_async(BBFDM_OBJECT_NAME, "operate", b.head, NULL, diagnostics_complete_cb);
blob_buf_free(&b); blob_buf_free(&b);
return e; return e;
@ -291,7 +301,6 @@ int cwmp_wifi_neighboring__diagnostics(void)
return -1; return -1;
CWMP_LOG(INFO, "WiFi neighboring diagnostic is successfully executed"); CWMP_LOG(INFO, "WiFi neighboring diagnostic is successfully executed");
cwmp_ctx.diag_session = true;
return 0; return 0;
} }
@ -301,7 +310,6 @@ int cwmp_packet_capture_diagnostics(void)
return -1; return -1;
CWMP_LOG(INFO, "packet capture diagnostic is successfully executed"); CWMP_LOG(INFO, "packet capture diagnostic is successfully executed");
cwmp_ctx.diag_session = true;
return 0; return 0;
} }
@ -311,7 +319,6 @@ int cwmp_selftest_diagnostics(void)
return -1; return -1;
CWMP_LOG(INFO, "self test diagnostic is successfully executed"); CWMP_LOG(INFO, "self test diagnostic is successfully executed");
cwmp_ctx.diag_session = true;
return 0; return 0;
} }
@ -321,7 +328,6 @@ int cwmp_ip_layer_capacity_diagnostics(void)
return -1; return -1;
CWMP_LOG(INFO, "IP layer capacity diagnostic is successfully executed"); CWMP_LOG(INFO, "IP layer capacity diagnostic is successfully executed");
cwmp_ctx.diag_session = true;
return 0; return 0;
} }
@ -331,7 +337,6 @@ int cwmp_download_diagnostics(void)
return -1; return -1;
CWMP_LOG(INFO, "Download diagnostic is successfully executed"); CWMP_LOG(INFO, "Download diagnostic is successfully executed");
cwmp_ctx.diag_session = true;
return 0; return 0;
} }
@ -341,7 +346,6 @@ int cwmp_upload_diagnostics(void)
return -1; return -1;
CWMP_LOG(INFO, "Upload diagnostic is successfully executed"); CWMP_LOG(INFO, "Upload diagnostic is successfully executed");
cwmp_ctx.diag_session = true;
return 0; return 0;
} }
@ -351,7 +355,6 @@ int cwmp_ip_ping_diagnostics(void)
return -1; return -1;
CWMP_LOG(INFO, "IPPing diagnostic is successfully executed"); CWMP_LOG(INFO, "IPPing diagnostic is successfully executed");
cwmp_ctx.diag_session = true;
return 0; return 0;
} }
@ -361,7 +364,6 @@ int cwmp_nslookup_diagnostics(void)
return -1; return -1;
CWMP_LOG(INFO, "Nslookup diagnostic is successfully executed"); CWMP_LOG(INFO, "Nslookup diagnostic is successfully executed");
cwmp_ctx.diag_session = true;
return 0; return 0;
} }
@ -371,7 +373,6 @@ int cwmp_traceroute_diagnostics(void)
return -1; return -1;
CWMP_LOG(INFO, "Trace Route diagnostic is successfully executed"); CWMP_LOG(INFO, "Trace Route diagnostic is successfully executed");
cwmp_ctx.diag_session = true;
return 0; return 0;
} }
@ -381,7 +382,6 @@ int cwmp_udp_echo_diagnostics(void)
return -1; return -1;
CWMP_LOG(INFO, "UDPEcho diagnostic is successfully executed"); CWMP_LOG(INFO, "UDPEcho diagnostic is successfully executed");
cwmp_ctx.diag_session = true;
return 0; return 0;
} }
@ -391,6 +391,5 @@ int cwmp_serverselection_diagnostics(void)
return -1; return -1;
CWMP_LOG(INFO, "Server Selection diagnostic is successfully executed"); CWMP_LOG(INFO, "Server Selection diagnostic is successfully executed");
cwmp_ctx.diag_session = true;
return 0; return 0;
} }

View file

@ -724,14 +724,6 @@ int run_session_end_func(void)
cwmp_selftest_diagnostics(); cwmp_selftest_diagnostics();
} }
if (cwmp_ctx.diag_session) {
struct session_timer_event *periodic_inform_event = calloc(1, sizeof(struct session_timer_event));
periodic_inform_event->session_timer_evt.cb = cwmp_schedule_session_with_event;
periodic_inform_event->event = EVENT_IDX_8DIAGNOSTICS_COMPLETE;
trigger_cwmp_session_timer_with_event(&periodic_inform_event->session_timer_evt);
cwmp_ctx.diag_session = false;
}
if (end_session_flag & END_SESSION_DOWNLOAD) { if (end_session_flag & END_SESSION_DOWNLOAD) {
CWMP_LOG(INFO, "Apply Downaload Calls"); CWMP_LOG(INFO, "Apply Downaload Calls");
apply_downloads(); apply_downloads();

View file

@ -470,6 +470,51 @@ int icwmp_ubus_invoke(const char *obj, const char *method, struct blob_attr *msg
return rc; return rc;
} }
int icwmp_ubus_invoke_async(const char *obj, const char *method, struct blob_attr *msg,
icwmp_ubus_cb data_callback, icwmp_ubus_async_cb complete_callback)
{
uint32_t id;
int fault = UBUS_STATUS_OK;
struct ubus_request *req;
if (ubus_ctx == NULL) {
CWMP_LOG(ERROR, "Failed to connect with ubus err: %d", errno);
return -1;
}
fault = ubus_lookup_id(ubus_ctx, obj, &id);
if (fault) {
CWMP_LOG(ERROR, "failed to lookup object: %s", obj);
return -1;
}
req = (struct ubus_request *)malloc(sizeof(struct ubus_request));
if (req == NULL) {
CWMP_LOG(ERROR, "failed to allocate memory for ubus request");
return -1;
}
memset(req, 0, sizeof(struct ubus_request));
fault = ubus_invoke_async(ubus_ctx, id, method, msg, req);
if (fault) {
CWMP_LOG(ERROR, "ubus async call failed");
FREE(req);
return -1;
}
if (data_callback) {
req->data_cb = data_callback;
}
if (complete_callback) {
req->complete_cb = complete_callback;
}
ubus_complete_request_async(ubus_ctx, req);
return 0;
}
int initiate_autonomous_complpolicy(void) int initiate_autonomous_complpolicy(void)
{ {
cwmp_ctx.ev = (struct ubus_event_handler *)malloc(sizeof(struct ubus_event_handler)); cwmp_ctx.ev = (struct ubus_event_handler *)malloc(sizeof(struct ubus_event_handler));

View file

@ -15,9 +15,12 @@
#include "common.h" #include "common.h"
typedef void (*icwmp_ubus_cb)(struct ubus_request *req, int type, struct blob_attr *msg); typedef void (*icwmp_ubus_cb)(struct ubus_request *req, int type, struct blob_attr *msg);
typedef void (*icwmp_ubus_async_cb)(struct ubus_request *req, int ret);
void bb_add_string(struct blob_buf *bb, const char *name, const char *value); void bb_add_string(struct blob_buf *bb, const char *name, const char *value);
int icwmp_ubus_invoke(const char *obj, const char *method, struct blob_attr *msg, int icwmp_ubus_invoke(const char *obj, const char *method, struct blob_attr *msg,
icwmp_ubus_cb icwmp_callback, void *callback_arg); icwmp_ubus_cb icwmp_callback, void *callback_arg);
int icwmp_ubus_invoke_async(const char *obj, const char *method, struct blob_attr *msg,
icwmp_ubus_cb data_callback, icwmp_ubus_async_cb complete_callback);
int icwmp_uloop_ubus_register(void); int icwmp_uloop_ubus_register(void);
void icwmp_uloop_ubus_exit(void); void icwmp_uloop_ubus_exit(void);
int initiate_autonomous_complpolicy(void); int initiate_autonomous_complpolicy(void);