diff --git a/bin/Makefile.am b/bin/Makefile.am index 7827778..37ff615 100644 --- a/bin/Makefile.am +++ b/bin/Makefile.am @@ -239,4 +239,25 @@ icwmp_xmppd_LDADD = \ $(LIBUBOX_LIBS) \ $(LIBSTROPHE_LIBS) endif - \ No newline at end of file + +bin_PROGRAMS += icwmp_udpechoserverd + +icwmp_udpechoserverd_SOURCES = \ + ../udpechoserver/udpechoserver.c \ + ../udpechoserver/udpechoserver.h \ + ../udpechoserver/udpechoserveruci.c \ + ../udpechoserver/udpechoserveruci.h \ + ../udpechoserver/udpechoserverlog.c \ + ../udpechoserver/udpechoserverlog.h + +icwmp_udpechoserverd_CFLAGS = \ + $(AM_CFLAGS) \ + $(LIBUCI_CFLAGS) + +icwmp_udpechoserverd_LDFLAGS = \ + $(AM_LDFLAGS) \ + $(LIBUCI_LDFLAGS) + +icwmp_udpechoserverd_LDADD = \ + $(AM_LIBS) \ + $(LIBUCI_LIBS) diff --git a/config/cwmp_udpechoserver b/config/cwmp_udpechoserver new file mode 100644 index 0000000..a26deaf --- /dev/null +++ b/config/cwmp_udpechoserver @@ -0,0 +1,8 @@ +config udpechoserver 'udpechoserver' + option enable '0' + option interface '' + option address '' + option server_port '' + option plus '0' +#Log levels: Critical=0, Warning=1, Notice=2, Info=3, Debug=4 + option log_level '3' diff --git a/cwmp.c b/cwmp.c index 79f4138..cc89818 100644 --- a/cwmp.c +++ b/cwmp.c @@ -563,6 +563,24 @@ int run_session_end_func (struct session *session) cwmp_nslookup_diagnostic(); } + if (end_session_flag & END_SESSION_TRACEROUTE_DIAGNOSTIC) + { + CWMP_LOG (INFO,"Executing traceroutediagnostic: end session request"); + cwmp_traceroute_diagnostic(); + } + + if (end_session_flag & END_SESSION_UDPECHO_DIAGNOSTIC) + { + CWMP_LOG (INFO,"Executing udpechodiagnostic: end session request"); + cwmp_udp_echo_diagnostic(); + } + + if (end_session_flag & END_SESSION_SERVERSELECTION_DIAGNOSTIC) + { + CWMP_LOG (INFO,"Executing serverselectiondiagnostic: end session request"); + cwmp_serverselection_diagnostic(); + } + dm_entry_restart_services(); end_session_flag = 0; diff --git a/diagnostic.c b/diagnostic.c index 15f480e..7f4673a 100644 --- a/diagnostic.c +++ b/diagnostic.c @@ -4,8 +4,9 @@ * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * - * Copyright (C) 2013 Inteno Broadband Technology AB - * Author Imen Bhiri * + * Copyright (C) 2019 iopsys Software Solutions AB + * Author Imen Bhiri + * Author: Amin Ben Ramdhane * */ @@ -34,7 +35,6 @@ #include #include - int read_next; struct download_diag download_stats = {0}; struct upload_diagnostic_stats upload_stats = {0}; @@ -43,37 +43,34 @@ static void http_upload_per_packet(libtrace_packet_t *packet); static void libtrace_cleanup(libtrace_t *trace, libtrace_packet_t *packet); static void set_download_stats(); static void set_upload_stats(); -int init_download_stats() + +void init_download_stats(void) { memset(&download_stats, 0, sizeof(download_stats)); } -int init_upload_stats() +void init_upload_stats(void) { memset(&upload_stats, 0, sizeof(upload_stats)); } -static void ftp_download_per_packet(libtrace_packet_t *packet, int first_packet) +static void ftp_download_per_packet(libtrace_packet_t *packet) { struct tm lt; struct timeval ts; libtrace_tcp_t *tcp; char tcp_flag[16] = ""; char *nexthdr; - libtrace_ip_t *ip; char s_now[default_date_size]; uint8_t proto; uint32_t remaining; - tcp = trace_get_transport(packet, &proto, &remaining); + tcp = trace_get_transport(packet, &proto, &remaining); if (tcp == NULL) - { return; - } else - { nexthdr = trace_get_payload_from_tcp(tcp, &remaining); - } + if (tcp->ecn_ns) strcat(tcp_flag, "ECN_NS "); if (tcp->cwr) strcat(tcp_flag, "CWR "); if (tcp->ece) strcat(tcp_flag, "ECE "); @@ -83,6 +80,7 @@ static void ftp_download_per_packet(libtrace_packet_t *packet, int first_packet) if (tcp->psh) strcat(tcp_flag, "PSH "); if (tcp->ack) strcat(tcp_flag, "ACK "); if (tcp->urg) strcat(tcp_flag, "URG "); + if (strcmp(tcp_flag, "PSH ACK ") == 0 && strlen(nexthdr) > strlen(FTP_SIZE_RESPONSE) && strncmp(nexthdr, FTP_SIZE_RESPONSE, strlen(FTP_SIZE_RESPONSE)) == 0) { char *val = strstr(nexthdr,"213"); @@ -113,7 +111,6 @@ static void ftp_download_per_packet(libtrace_packet_t *packet, int first_packet) download_stats.random_seq = ntohl(tcp->ack_seq); sprintf((download_stats.tcpopenresponsetime),"%s.%06ld", s_now, (long) ts.tv_usec); } - if (strcmp(tcp_flag, "PSH ACK ") == 0 && strlen(nexthdr) > strlen(FTP_RETR_REQUEST) && strncmp(nexthdr, FTP_RETR_REQUEST, strlen(FTP_RETR_REQUEST)) == 0) { ts = trace_get_timeval(packet); @@ -123,9 +120,6 @@ static void ftp_download_per_packet(libtrace_packet_t *packet, int first_packet) } if(strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->seq) == download_stats.random_seq && download_stats.ack_seq == 0) { - ts = trace_get_timeval(packet); - (void) localtime_r(&(ts.tv_sec), <); - strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", <); download_stats.ack_seq = ntohl(tcp->seq); return; } @@ -139,9 +133,6 @@ static void ftp_download_per_packet(libtrace_packet_t *packet, int first_packet) sprintf((download_stats.bomtime),"%s.%06ld", s_now, (long) ts.tv_usec); } download_stats.first_data = 1; - ip = trace_get_ip(packet); - if (ip != NULL) - download_stats.total_bytes_received += ntohs(ip->ip_len); } if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && ntohl(tcp->ack_seq) == download_stats.ack_seq) { @@ -154,14 +145,11 @@ static void ftp_download_per_packet(libtrace_packet_t *packet, int first_packet) download_stats.first_data = 1; } sprintf((download_stats.eomtime),"%s.%06ld", s_now, (long) ts.tv_usec); - ip = trace_get_ip(packet); - if (ip != NULL) - download_stats.total_bytes_received += ntohs(ip->ip_len); } } -static void http_download_per_packet(libtrace_packet_t *packet, int first_packet) +static void http_download_per_packet(libtrace_packet_t *packet) { struct tm lt; struct timeval ts; @@ -169,21 +157,16 @@ static void http_download_per_packet(libtrace_packet_t *packet, int first_packet uint32_t seq = 0; char tcp_flag[16] = ""; char *nexthdr; - libtrace_ip_t *ip; char s_now[default_date_size]; - uint8_t proto; uint32_t remaining; - tcp = trace_get_transport(packet, &proto, &remaining); + tcp = trace_get_transport(packet, &proto, &remaining); if (tcp == NULL) - { return; - } else - { nexthdr = trace_get_payload_from_tcp(tcp, &remaining); - } + if (tcp->ecn_ns) strcat(tcp_flag, "ECN_NS "); if (tcp->cwr) strcat(tcp_flag, "CWR "); if (tcp->ece) strcat(tcp_flag, "ECE "); @@ -193,7 +176,8 @@ static void http_download_per_packet(libtrace_packet_t *packet, int first_packet if (tcp->psh) strcat(tcp_flag, "PSH "); if (tcp->ack) strcat(tcp_flag, "ACK "); if (tcp->urg) strcat(tcp_flag, "URG "); - if (strcmp(tcp_flag, "SYN ") == 0 && download_stats.random_seq == 0) + + if (strcmp(tcp_flag, "SYN ") == 0 && download_stats.random_seq == 0) { ts = trace_get_timeval(packet); (void) localtime_r(&(ts.tv_sec), <); @@ -211,7 +195,6 @@ static void http_download_per_packet(libtrace_packet_t *packet, int first_packet download_stats.random_seq = ntohl(tcp->seq); return; } - if (strcmp(tcp_flag, "PSH ACK ") == 0 && strncmp(nexthdr, "GET", 3) == 0) { ts = trace_get_timeval(packet); @@ -223,9 +206,6 @@ static void http_download_per_packet(libtrace_packet_t *packet, int first_packet } if(strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->seq) == download_stats.get_ack && download_stats.ack_seq == 0) { - ts = trace_get_timeval(packet); - (void) localtime_r(&(ts.tv_sec), <); - strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", <); download_stats.ack_seq = ntohl(tcp->ack_seq); return; } @@ -244,11 +224,6 @@ static void http_download_per_packet(libtrace_packet_t *packet, int first_packet download_stats.test_bytes_received = atoi(pch); download_stats.first_data = 1; } - ip = trace_get_ip(packet); - if (ip != NULL) - { - download_stats.total_bytes_received += ntohs(ip->ip_len); - } return; } if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && ntohl(tcp->ack_seq) == download_stats.ack_seq) @@ -266,13 +241,7 @@ static void http_download_per_packet(libtrace_packet_t *packet, int first_packet download_stats.test_bytes_received = atoi(pch); download_stats.first_data = 1; } - sprintf((download_stats.eomtime),"%s.%06ld", s_now, (long) ts.tv_usec); - ip = trace_get_ip(packet); - if (ip != NULL) - { - download_stats.total_bytes_received += ntohs(ip->ip_len); - } return; } } @@ -301,13 +270,10 @@ static void set_download_stats() uci_set_state_value(buf); sprintf(buf,"cwmp.@downloaddiagnostic[0].TestBytesReceived=%d", download_stats.test_bytes_received); uci_set_state_value(buf); - sprintf(buf,"cwmp.@downloaddiagnostic[0].TotalBytesReceived=%lu", download_stats.total_bytes_received); - uci_set_state_value(buf); } static void set_upload_stats() { - char buf[128]; sprintf(buf,"cwmp.@uploaddiagnostic[0].ROMtime=%s", upload_stats.romtime); uci_set_state_value(buf); @@ -319,8 +285,6 @@ static void set_upload_stats() uci_set_state_value(buf); sprintf(buf,"cwmp.@uploaddiagnostic[0].TCPOpenResponseTime=%s", upload_stats.tcpopenresponsetime); uci_set_state_value(buf); - sprintf(buf,"cwmp.@uploaddiagnostic[0].TotalBytesSent=%lu", upload_stats.total_bytes_sent); - uci_set_state_value(buf); } static void http_upload_per_packet(libtrace_packet_t *packet) @@ -328,23 +292,18 @@ static void http_upload_per_packet(libtrace_packet_t *packet) struct tm lt; struct timeval ts; libtrace_tcp_t *tcp; - //uint32_t remaining; char tcp_flag[16] = ""; char *nexthdr; - - libtrace_ip_t *ip; char s_now[default_date_size]; uint8_t proto; uint32_t remaining; + tcp = trace_get_transport(packet, &proto, &remaining); if (tcp == NULL) - { return; - } else - { nexthdr = trace_get_payload_from_tcp(tcp, &remaining); - } + if (tcp->ecn_ns) strcat(tcp_flag, "ECN_NS "); if (tcp->cwr) strcat(tcp_flag, "CWR "); if (tcp->ece) strcat(tcp_flag, "ECE "); @@ -354,6 +313,7 @@ static void http_upload_per_packet(libtrace_packet_t *packet) if (tcp->psh) strcat(tcp_flag, "PSH "); if (tcp->ack) strcat(tcp_flag, "ACK "); if (tcp->urg) strcat(tcp_flag, "URG "); + if (strcmp(tcp_flag, "SYN ") == 0 && download_stats.random_seq == 0) { ts = trace_get_timeval(packet); @@ -391,14 +351,12 @@ static void http_upload_per_packet(libtrace_packet_t *packet) upload_stats.ack_seq = ntohl(tcp->ack_seq); return; } - if (strcmp(tcp_flag, "ACK ") == 0 && upload_stats.tmp == 2 && ntohl(tcp->seq) == upload_stats.ack_seq) { upload_stats.tmp = 0; upload_stats.ack_seq = ntohl(tcp->ack_seq); return; } - if(strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->ack_seq) == upload_stats.ack_seq && upload_stats.tmp == 0) { ts = trace_get_timeval(packet); @@ -409,9 +367,6 @@ static void http_upload_per_packet(libtrace_packet_t *packet) sprintf((upload_stats.bomtime),"%s.%06ld", s_now, (long) ts.tv_usec); upload_stats.first_data = 1; } - ip = trace_get_ip(packet); - if (ip != NULL) - upload_stats.total_bytes_sent += ntohs(ip->ip_len); } if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && ntohl(tcp->ack_seq) == upload_stats.ack_seq && upload_stats.tmp == 0) { @@ -420,13 +375,9 @@ static void http_upload_per_packet(libtrace_packet_t *packet) strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", <); if (upload_stats.first_data == 0) { - sprintf((upload_stats.bomtime),"%s.%06ld", s_now, (long) ts.tv_usec); upload_stats.first_data = 1; } - ip = trace_get_ip(packet); - if (ip != NULL) - upload_stats.total_bytes_sent += ntohs(ip->ip_len); } if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && ntohl(tcp->seq) == upload_stats.ack_seq && upload_stats.tmp == 0) { @@ -434,7 +385,6 @@ static void http_upload_per_packet(libtrace_packet_t *packet) (void) localtime_r(&(ts.tv_sec), <); strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", <); sprintf((upload_stats.eomtime),"%s.%06ld", s_now, (long) ts.tv_usec); - ip = trace_get_ip(packet); } } @@ -447,17 +397,13 @@ struct tm lt; uint32_t remaining; char tcp_flag[16] = ""; char *nexthdr; - libtrace_ip_t *ip; char s_now[default_date_size]; + tcp = trace_get_transport(packet, &proto, &remaining); if (tcp == NULL) - { return; - } else - { nexthdr = trace_get_payload_from_tcp(tcp, &remaining); - } if (tcp->ecn_ns) strcat(tcp_flag, "ECN_NS "); if (tcp->cwr) strcat(tcp_flag, "CWR "); @@ -468,8 +414,8 @@ struct tm lt; if (tcp->psh) strcat(tcp_flag, "PSH "); if (tcp->ack) strcat(tcp_flag, "ACK "); if (tcp->urg) strcat(tcp_flag, "URG "); - if(strcmp(tcp_flag, "PSH ACK ") == 0 && strlen(nexthdr) > strlen(FTP_PASV_RESPONSE) - && strncmp(nexthdr, FTP_PASV_RESPONSE, strlen(FTP_PASV_RESPONSE)) == 0) + + if(strcmp(tcp_flag, "PSH ACK ") == 0 && strlen(nexthdr) > strlen(FTP_PASV_RESPONSE) && strncmp(nexthdr, FTP_PASV_RESPONSE, strlen(FTP_PASV_RESPONSE)) == 0) { upload_stats.ftp_syn = 1; return; @@ -490,7 +436,6 @@ struct tm lt; sprintf((upload_stats.tcpopenresponsetime),"%s.%06ld", s_now, (long) ts.tv_usec); upload_stats.random_seq = ntohl(tcp->ack_seq); } - if (strcmp(tcp_flag, "PSH ACK ") == 0 && strlen(nexthdr) > strlen(FTP_STOR_REQUEST) && strncmp(nexthdr, FTP_STOR_REQUEST, strlen(FTP_STOR_REQUEST)) == 0) { ts = trace_get_timeval(packet); @@ -500,9 +445,6 @@ struct tm lt; } if(strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->seq) == upload_stats.random_seq && upload_stats.ack_seq == 0) { - ts = trace_get_timeval(packet); - (void) localtime_r(&(ts.tv_sec), <); - strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", <); upload_stats.ack_seq = ntohl(tcp->ack_seq); return; } @@ -516,10 +458,6 @@ struct tm lt; sprintf((upload_stats.bomtime),"%s.%06ld", s_now, (long) ts.tv_usec); upload_stats.first_data = 1; } - - ip = trace_get_ip(packet); - if (ip != NULL) - upload_stats.total_bytes_sent += ntohs(ip->ip_len); } if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && ntohl(tcp->ack_seq) == upload_stats.ack_seq) //&& strlen(nexthdr) > 16 && strncmp(nexthdr, "HTTP/1.1 200 OK", 16) == 0 { @@ -531,9 +469,6 @@ struct tm lt; sprintf((upload_stats.bomtime),"%s.%06ld", s_now, (long) ts.tv_usec); upload_stats.first_data = 1; } - ip = trace_get_ip(packet); - if (ip != NULL) - upload_stats.total_bytes_sent += ntohs(ip->ip_len); } if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && strlen(nexthdr) > strlen(FTP_TRANSFERT_COMPLETE) && strncmp(nexthdr, FTP_TRANSFERT_COMPLETE, strlen(FTP_TRANSFERT_COMPLETE)) == 0) //&& strlen(nexthdr) > 16 && strncmp(nexthdr, "HTTP/1.1 200 OK", 16) == 0 { @@ -550,7 +485,6 @@ int extract_stats(char *dump_file, int proto, int diagnostic_type) libtrace_t *trace = NULL; libtrace_packet_t *packet = NULL; read_next = 1; - int first_packet = 1; packet = trace_create_packet(); if (packet == NULL) { perror("Creating libtrace packet"); @@ -574,8 +508,7 @@ int extract_stats(char *dump_file, int proto, int diagnostic_type) if (proto == DOWNLOAD_DIAGNOSTIC_HTTP && diagnostic_type == DOWNLOAD_DIAGNOSTIC) { while (trace_read_packet(trace,packet)>0 && read_next == 1) { - http_download_per_packet(packet, first_packet); - first_packet = 0; + http_download_per_packet(packet); continue; } set_download_stats(); @@ -583,8 +516,7 @@ int extract_stats(char *dump_file, int proto, int diagnostic_type) else if (proto == DOWNLOAD_DIAGNOSTIC_FTP && diagnostic_type == DOWNLOAD_DIAGNOSTIC) { while (trace_read_packet(trace,packet)>0 && read_next == 1) { - ftp_download_per_packet(packet, first_packet); - first_packet = 0; + ftp_download_per_packet(packet); continue; } set_download_stats(); @@ -593,7 +525,6 @@ int extract_stats(char *dump_file, int proto, int diagnostic_type) { while (trace_read_packet(trace,packet)>0 && read_next == 1) { http_upload_per_packet(packet); - first_packet = 0; continue; } set_upload_stats(); @@ -602,7 +533,6 @@ int extract_stats(char *dump_file, int proto, int diagnostic_type) { while (trace_read_packet(trace,packet)>0 && read_next == 1) { ftp_upload_per_packet(packet); - first_packet = 0; continue; } set_upload_stats(); @@ -614,18 +544,18 @@ int extract_stats(char *dump_file, int proto, int diagnostic_type) int get_default_gateway_device( char **gw ) { FILE *f; - char line[100] , *p , *c, *saveptr; + char line[100], *p, *c, *saveptr; f = fopen("/proc/net/route" , "r"); if (f != NULL) { while(fgets(line , 100 , f)) { - p = strtok_r(line , " \t", &saveptr); - c = strtok_r(NULL , " \t", &saveptr); + p = strtok_r(line, " \t", &saveptr); + c = strtok_r(NULL, " \t", &saveptr); if(p!=NULL && c!=NULL) { - if(strcmp(c , "00000000") == 0) + if(strcmp(c, "00000000") == 0) { asprintf(gw, "%s", p); fclose(f); @@ -638,12 +568,6 @@ int get_default_gateway_device( char **gw ) return -1; } -int cwmp_ip_ping_diagnostic() -{ - dmcmd_no_wait("/bin/sh", 2, FUNCTION_PATH, "run"); - return 0; -} - int cwmp_start_diagnostic(int diagnostic_type) { char *url = NULL; @@ -651,6 +575,7 @@ int cwmp_start_diagnostic(int diagnostic_type) char *size = NULL; int error; char *status; + if (diagnostic_type == DOWNLOAD_DIAGNOSTIC) uci_get_state_value("cwmp.@downloaddiagnostic[0].url", &url); else @@ -658,18 +583,16 @@ int cwmp_start_diagnostic(int diagnostic_type) uci_get_state_value("cwmp.@uploaddiagnostic[0].url", &url); uci_get_state_value("cwmp.@uploaddiagnostic[0].TestFileLength", &size); } - - CWMP_LOG(DEBUG,"diagnostic url %s", url); - uci_get_state_value("cwmp.@downloaddiagnostic[0].interface", &interface); if( url == NULL || ((url != NULL) && (strcmp(url,"")==0)) - || (strncmp(url,DOWNLOAD_PROTOCOL_FTP,strlen(DOWNLOAD_PROTOCOL_FTP))!=0) && - (strstr(url,"@") != NULL && strncmp(url,DOWNLOAD_PROTOCOL_HTTP,strlen(DOWNLOAD_PROTOCOL_HTTP)) == 0) + || ((strncmp(url,DOWNLOAD_PROTOCOL_FTP,strlen(DOWNLOAD_PROTOCOL_FTP))!=0) && + (strstr(url,"@") != NULL && strncmp(url,DOWNLOAD_PROTOCOL_HTTP,strlen(DOWNLOAD_PROTOCOL_HTTP)) == 0)) ) { CWMP_LOG(ERROR,"Invalid URL %s", url); free(url); return -1; } + uci_get_state_value("cwmp.@downloaddiagnostic[0].device", &interface); if ( interface == NULL || interface[0] == '\0' ) { error = get_default_gateway_device(&interface); @@ -682,12 +605,13 @@ int cwmp_start_diagnostic(int diagnostic_type) } if (diagnostic_type == DOWNLOAD_DIAGNOSTIC) { + CWMP_LOG(INFO,"Launch Download diagnostic with url %s", url); dmcmd("/bin/sh", 4, DOWNLOAD_DIAGNOSTIC_PATH, "run", url, interface); uci_get_state_value("cwmp.@downloaddiagnostic[0].DiagnosticState", &status); if (status && strcmp(status, "Completed") == 0) { init_download_stats(); - CWMP_LOG(INFO,"Extract download stats"); + CWMP_LOG(INFO,"Extract Download stats"); if(strncmp(url,DOWNLOAD_PROTOCOL_HTTP,strlen(DOWNLOAD_PROTOCOL_HTTP)) == 0) extract_stats(DOWNLOAD_DUMP_FILE, DOWNLOAD_DIAGNOSTIC_HTTP, DOWNLOAD_DIAGNOSTIC); if(strncmp(url,DOWNLOAD_PROTOCOL_FTP,strlen(DOWNLOAD_PROTOCOL_FTP)) == 0) @@ -700,12 +624,13 @@ int cwmp_start_diagnostic(int diagnostic_type) } else { + CWMP_LOG(INFO,"Launch Upload diagnostic with url %s", url); dmcmd("/bin/sh", 5, UPLOAD_DIAGNOSTIC_PATH, "run", url, interface, size); uci_get_state_value("cwmp.@uploaddiagnostic[0].DiagnosticState", &status); if (status && strcmp(status, "Completed") == 0) { init_upload_stats(); - CWMP_LOG(INFO,"Extract upload stats"); + CWMP_LOG(INFO,"Extract Upload stats"); if(strncmp(url,DOWNLOAD_PROTOCOL_HTTP,strlen(DOWNLOAD_PROTOCOL_HTTP)) == 0) extract_stats(UPLOAD_DUMP_FILE, DOWNLOAD_DIAGNOSTIC_HTTP, UPLOAD_DIAGNOSTIC); if(strncmp(url,DOWNLOAD_PROTOCOL_FTP,strlen(DOWNLOAD_PROTOCOL_FTP)) == 0) @@ -722,8 +647,32 @@ int cwmp_start_diagnostic(int diagnostic_type) return 0; } +int cwmp_ip_ping_diagnostic() +{ + dmcmd_no_wait("/bin/sh", 2, IPPING_PATH, "run"); + return 0; +} + int cwmp_nslookup_diagnostic() { dmcmd_no_wait("/bin/sh", 2, NSLOOKUP_PATH, "run"); return 0; } + +int cwmp_traceroute_diagnostic() +{ + dmcmd_no_wait("/bin/sh", 2, TRACEROUTE_PATH, "run"); + return 0; +} + +int cwmp_udp_echo_diagnostic() +{ + dmcmd_no_wait("/bin/sh", 2, UDPECHO_PATH, "run"); + return 0; +} + +int cwmp_serverselection_diagnostic() +{ + dmcmd_no_wait("/bin/sh", 2, SERVERSELECTION_PATH, "run"); + return 0; +} diff --git a/dm/dmcommon.h b/dm/dmcommon.h index 6a2681e..7f13213 100644 --- a/dm/dmcommon.h +++ b/dm/dmcommon.h @@ -57,17 +57,23 @@ do { \ if (mpp) close (mpp); \ } while (0) -#define IPPING_STOP DMCMD("/bin/sh", 2, FUNCTION_PATH, "stop"); -#define FUNCTION_PATH "/usr/share/icwmp/functions/ipping_launch" +#define IPPING_PATH "/usr/share/icwmp/functions/ipping_launch" +#define IPPING_STOP DMCMD("/bin/sh", 2, IPPING_PATH, "stop"); #define DOWNLOAD_DIAGNOSTIC_PATH "/usr/share/icwmp/functions/download_launch" #define DOWNLOAD_DUMP_FILE "/tmp/download_dump" #define DOWNLOAD_DIAGNOSTIC_STOP DMCMD("/bin/sh", 2, DOWNLOAD_DIAGNOSTIC_PATH, "stop"); #define UPLOAD_DIAGNOSTIC_PATH "/usr/share/icwmp/functions/upload_launch" #define UPLOAD_DUMP_FILE "/tmp/upload_dump" #define UPLOAD_DIAGNOSTIC_STOP DMCMD("/bin/sh", 2, UPLOAD_DIAGNOSTIC_PATH, "stop"); -#define NSLOOKUP_STOP DMCMD("/bin/sh", 2, NSLOOKUP_PATH, "stop"); #define NSLOOKUP_PATH "/usr/share/icwmp/functions/nslookup_launch" #define NSLOOKUP_LOG_FILE "/tmp/nslookup.log" +#define NSLOOKUP_STOP DMCMD("/bin/sh", 2, NSLOOKUP_PATH, "stop"); +#define TRACEROUTE_PATH "/usr/share/icwmp/functions/traceroute_launch" +#define TRACEROUTE_STOP DMCMD("/bin/sh", 2, TRACEROUTE_PATH, "stop"); +#define UDPECHO_PATH "/usr/share/icwmp/functions/udpecho_launch" +#define UDPECHO_STOP DMCMD("/bin/sh", 2, UDPECHO_PATH, "stop"); +#define SERVERSELECTION_PATH "/usr/share/icwmp/functions/serverselection_launch" +#define SERVERSELECTION_STOP DMCMD("/bin/sh", 2, SERVERSELECTION_PATH, "stop"); enum notification_enum { notification_none, diff --git a/dm/dmcwmp.h b/dm/dmcwmp.h index 7eeed8f..ca8059d 100644 --- a/dm/dmcwmp.h +++ b/dm/dmcwmp.h @@ -120,7 +120,7 @@ typedef struct dm_leaf_s { } DMLEAF; typedef struct dm_obj_s { - /* OBJ, permission, addobj, delobj, browseinstobj, forced_inform, notification, nextobj, leaf, linker(10)*/ + /* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextobj, leaf, linker(11)*/ char *obj; struct dm_permession_s *permission; int (*addobj)(char *refparam, struct dmctx *ctx, void *data, char **instance); @@ -375,7 +375,10 @@ enum end_session_enum { END_SESSION_DOWNLOAD_DIAGNOSTIC = 1<<5, END_SESSION_UPLOAD_DIAGNOSTIC = 1<<6, END_SESSION_X_FACTORY_RESET_SOFT = 1<<7, - END_SESSION_NSLOOKUP_DIAGNOSTIC = 1<<8 + END_SESSION_NSLOOKUP_DIAGNOSTIC = 1<<8, + END_SESSION_TRACEROUTE_DIAGNOSTIC = 1<<9, + END_SESSION_UDPECHO_DIAGNOSTIC = 1<<10, + END_SESSION_SERVERSELECTION_DIAGNOSTIC = 1<<11 }; enum dm_browse_enum { diff --git a/dm/dmtree/common/deviceinfo.c b/dm/dmtree/common/deviceinfo.c index 8bad4ca..636f1d3 100644 --- a/dm/dmtree/common/deviceinfo.c +++ b/dm/dmtree/common/deviceinfo.c @@ -713,6 +713,7 @@ int browsePocessEntriesInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev break; } } + return 0; } int browseVcfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) diff --git a/dm/dmtree/tr098/downloaddiagnostic.c b/dm/dmtree/tr098/downloaddiagnostic.c index 7317247..e0095ff 100644 --- a/dm/dmtree/tr098/downloaddiagnostic.c +++ b/dm/dmtree/tr098/downloaddiagnostic.c @@ -44,6 +44,7 @@ static inline char *download_diagnostic_get(char *option, char *def) else return tmp; } + int get_download_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = download_diagnostic_get("DiagnosticState", "None"); @@ -101,7 +102,6 @@ int set_download_diagnostics_interface(char *refparam, struct dmctx *ctx, void * int get_download_diagnostics_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_varstate_string("cwmp", "@downloaddiagnostic[0]", "url", value); return 0; } diff --git a/dm/dmtree/tr098/ippingdiagnostics.c b/dm/dmtree/tr098/ippingdiagnostics.c index fc3fe3b..fc80fbd 100644 --- a/dm/dmtree/tr098/ippingdiagnostics.c +++ b/dm/dmtree/tr098/ippingdiagnostics.c @@ -35,7 +35,6 @@ DMLEAF tIPPingDiagnosticsParam[] = { {0} }; - static inline char *ipping_get(char *option, char *def) { char *tmp; @@ -210,13 +209,11 @@ int set_ipping_block_size(char *refparam, struct dmctx *ctx, void *data, char *i int get_ipping_dscp(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ipping_get("DSCP", "0"); - - return 0; + return 0; } int set_ipping_dscp(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *tmp; struct uci_section *curr_section = NULL; switch (action) { @@ -255,14 +252,12 @@ int get_ipping_average_response_time(char *refparam, struct dmctx *ctx, void *da int get_ipping_min_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ipping_get("MinimumResponseTime", "0"); - return 0; } int get_ipping_max_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = ipping_get("MaximumResponseTime", "0"); - + *value = ipping_get("MaximumResponseTime", "0"); return 0; } diff --git a/dm/dmtree/tr098/uploaddiagnostic.c b/dm/dmtree/tr098/uploaddiagnostic.c index ab5270e..04a781b 100644 --- a/dm/dmtree/tr098/uploaddiagnostic.c +++ b/dm/dmtree/tr098/uploaddiagnostic.c @@ -44,6 +44,7 @@ static inline char *upload_diagnostic_get(char *option, char *def) else return tmp; } + int get_upload_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = upload_diagnostic_get("DiagnosticState", "None"); @@ -101,7 +102,6 @@ int set_upload_diagnostics_interface(char *refparam, struct dmctx *ctx, void *da int get_upload_diagnostics_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_varstate_string("cwmp", "@uploaddiagnostic[0]", "url", value); return 0; } diff --git a/dm/dmtree/tr181/dns.c b/dm/dmtree/tr181/dns.c index 8d5e8a1..e36935c 100644 --- a/dm/dmtree/tr181/dns.c +++ b/dm/dmtree/tr181/dns.c @@ -324,18 +324,6 @@ end: return 0; } -int browseServiceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - //TODO - return 0; -} - -int browseTextRecordInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - //TODO - return 0; -} - /*********************************** Add/Delet Object functions *************************/ int add_client_server(char *refparam, struct dmctx *ctx, void *data, char **instance) { diff --git a/dm/dmtree/tr181/firewall.c b/dm/dmtree/tr181/firewall.c index 414d1c4..b970bb6 100644 --- a/dm/dmtree/tr181/firewall.c +++ b/dm/dmtree/tr181/firewall.c @@ -85,8 +85,8 @@ DMLEAF tTimeSpanParams[] = { {"StopTime", &DMWRITE, DMT_STRING, get_time_span_stop_time, set_time_span_stop_time, NULL, NULL}, {0} }; -/***************************** Browse Functions ***********************************/ +/***************************** Browse Functions ***********************************/ int browseLevelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *s; @@ -223,8 +223,8 @@ int get_firewall_advanced_level(char *refparam, struct dmctx *ctx, void *data, c int get_firewall_level_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value="1"; - return 0; + *value="1"; + return 0; } int get_firewall_chain_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) @@ -235,16 +235,16 @@ int get_firewall_chain_number_of_entries(char *refparam, struct dmctx *ctx, void int get_level_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section* levels=(struct uci_section *)data; - dmuci_get_value_by_section_string(levels, "name", value); - return 0; + struct uci_section* levels=(struct uci_section *)data; + dmuci_get_value_by_section_string(levels, "name", value); + return 0; } int get_level_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section* levels=(struct uci_section *)data; dmuci_get_value_by_section_string(levels, "description", value); - return 0; + return 0; } int get_level_chain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) diff --git a/dm/dmtree/tr181/ip.c b/dm/dmtree/tr181/ip.c index 8570682..e76e586 100644 --- a/dm/dmtree/tr181/ip.c +++ b/dm/dmtree/tr181/ip.c @@ -1,13 +1,14 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * Copyright (C) 2016 Inteno Broadband Technology AB - * Author: Anis Ellouze - * - */ +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* Copyright (C) 2019 iopsys Software Solutions AB +* Author: Anis Ellouze +* Author: Amin Ben Ramdhane +* +*/ #include #include @@ -19,16 +20,15 @@ #include "ip.h" #include "diagnostic.h" #include "dmjson.h" -#include "log.h" struct dm_forced_inform_s IPv4INFRM = {0, get_ipv4_finform}; struct dm_forced_inform_s IPv6INFRM = {0, get_ipv6_finform}; /* *** Device.IP. *** */ DMOBJ tIPObj[] = { -/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextobj, leaf, linker*/ {"Interface", &DMWRITE, add_ip_interface, delete_ip_interface, NULL, browseIPIfaceInst, NULL, NULL, tInterfaceObj, tIPintParams, get_linker_ip_interface}, -{"Diagnostics", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tDiagnosticObj, NULL, NULL}, +{"Diagnostics", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tDiagnosticObj, tIPDiagnosticsParams, NULL}, {0} }; @@ -43,22 +43,16 @@ DMLEAF tIPintParams[] = { /* *** Device.IP.Interface. *** */ DMOBJ tInterfaceObj[] = { -/* OBJ, permission, addobj, delobj, browseinstobj, finform, nextobj, leaf*/ +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextobj, leaf, linker*/ {"IPv4Address", &DMWRITE, add_ipv4, delete_ipv4, NULL, browseIfaceIPv4Inst, NULL, NULL, NULL, tIPv4Params, NULL}, {"IPv6Address", &DMWRITE, add_ipv6, delete_ipv6, NULL, browseIfaceIPv6Inst, NULL, NULL, NULL, tIPv6Params, NULL}, {"Stats", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tIPInterfaceStatsParams, NULL}, {0} }; -DMOBJ tDiagnosticObj[] = { -/* OBJ, permission, addobj, delobj, browseinstobj, finform, nextobj, leaf*/ -{"IPPing", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tIpPingDiagParams, NULL}, -{0} -}; - /* *** Device.IP.Interface.{i}.IPv4Address.{i}. *** */ DMLEAF tIPv4Params[] = { -/* PARAM, permission, type, getvlue, setvalue, forced_inform*/ +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ {"Alias", &DMWRITE, DMT_STRING, get_ipv4_alias, set_ipv4_alias, &IPv4INFRM, NULL}, {"Enable", &DMWRITE, DMT_BOOL, get_ip_interface_enable, set_ip_interface_enable, &IPv4INFRM, NULL}, {CUSTOM_PREFIX"FirewallEnabled", &DMWRITE, DMT_BOOL, get_firewall_enabled, set_firewall_enabled, &IPv4INFRM, NULL}, @@ -70,7 +64,7 @@ DMLEAF tIPv4Params[] = { /* *** Device.IP.Interface.{i}.IPv6Address.{i}. *** */ DMLEAF tIPv6Params[] = { -/* PARAM, permission, type, getvlue, setvalue, forced_inform*/ +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ {"Alias", &DMWRITE, DMT_STRING, get_ipv6_alias, set_ipv6_alias, &IPv6INFRM, NULL}, {"Enable", &DMREAD, DMT_BOOL, get_ip_enable, NULL, &IPv6INFRM, NULL}, {"IPAddress", &DMWRITE, DMT_STRING, get_ipv6_address, set_ipv6_address, &IPv6INFRM, NULL}, @@ -80,7 +74,7 @@ DMLEAF tIPv6Params[] = { /* *** Device.IP.Interface.{i}.Stats. *** */ DMLEAF tIPInterfaceStatsParams[] = { -/* PARAM, permission, type, getvlue, setvalue, forced_inform, NOTIFICATION, linker*/ +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ {"BytesSent", &DMREAD, DMT_UNINT, get_ip_interface_statistics_tx_bytes, NULL, NULL, NULL}, {"BytesReceived", &DMREAD, DMT_UNINT, get_ip_interface_statistics_rx_bytes, NULL, NULL, NULL}, {"PacketsSent", &DMREAD, DMT_UNINT, get_ip_interface_statistics_tx_packets, NULL, NULL, NULL}, @@ -92,32 +86,255 @@ DMLEAF tIPInterfaceStatsParams[] = { {0} }; +/* *** Device.IP.Diagnostics. *** */ +DMOBJ tDiagnosticObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextobj, leaf, linker*/ +{"IPPing", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tIpPingDiagParams, NULL}, +{"TraceRoute", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tIPDiagnosticsTraceRouteObj, tIPDiagnosticsTraceRouteParams, NULL}, +{"DownloadDiagnostics", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tIPDiagnosticsDownloadDiagnosticsObj, tIPDiagnosticsDownloadDiagnosticsParams, NULL}, +{"UploadDiagnostics", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tIPDiagnosticsUploadDiagnosticsObj, tIPDiagnosticsUploadDiagnosticsParams, NULL}, +{"UDPEchoConfig", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tIPDiagnosticsUDPEchoConfigParams, NULL}, +{"UDPEchoDiagnostics", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tIPDiagnosticsUDPEchoDiagnosticsParams, NULL}, +{"ServerSelectionDiagnostics", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tIPDiagnosticsServerSelectionDiagnosticsParams, NULL}, +{0} +}; + +DMLEAF tIPDiagnosticsParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"IPv4PingSupported", &DMREAD, DMT_BOOL, get_diag_enable_true, NULL, NULL, NULL}, +{"IPv6PingSupported", &DMREAD, DMT_BOOL, get_diag_enable_true, NULL, NULL, NULL}, +{"IPv4TraceRouteSupported", &DMREAD, DMT_BOOL, get_diag_enable_true, NULL, NULL, NULL}, +{"IPv6TraceRouteSupported", &DMREAD, DMT_BOOL, get_diag_enable_true, NULL, NULL, NULL}, +{"IPv4DownloadDiagnosticsSupported", &DMREAD, DMT_BOOL, get_diag_enable_true, NULL, NULL, NULL}, +{"IPv6DownloadDiagnosticsSupported", &DMREAD, DMT_BOOL, get_diag_enable_true, NULL, NULL, NULL}, +{"IPv4UploadDiagnosticsSupported", &DMREAD, DMT_BOOL, get_diag_enable_true, NULL, NULL, NULL}, +{"IPv6UploadDiagnosticsSupported", &DMREAD, DMT_BOOL, get_diag_enable_true, NULL, NULL, NULL}, +{"IPv4UDPEchoDiagnosticsSupported", &DMREAD, DMT_BOOL, get_diag_enable_true, NULL, NULL, NULL}, +{"IPv6UDPEchoDiagnosticsSupported", &DMREAD, DMT_BOOL, get_diag_enable_true, NULL, NULL, NULL}, +{"IPv4ServerSelectionDiagnosticsSupported", &DMREAD, DMT_BOOL, get_diag_enable_true, NULL, NULL, NULL}, +{"IPv6ServerSelectionDiagnosticsSupported", &DMREAD, DMT_BOOL, get_diag_enable_true, NULL, NULL, NULL}, +{0} +}; + +/* *** Device.IP.Diagnostics.IPPing. *** */ DMLEAF tIpPingDiagParams[] = { -/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification , linker*/ +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ {"DiagnosticsState", &DMWRITE, DMT_STRING, get_ip_ping_diagnostics_state, set_ip_ping_diagnostics_state, NULL, NULL}, {"Interface", &DMWRITE, DMT_STRING, get_ip_ping_interface, set_ip_ping_interface, NULL, NULL}, +{"ProtocolVersion", &DMWRITE, DMT_STRING, get_ip_ping_protocolversion, set_ip_ping_protocolversion, NULL, NULL}, {"Host", &DMWRITE, DMT_STRING, get_ip_ping_host, set_ip_ping_host, NULL, NULL}, {"NumberOfRepetitions", &DMWRITE, DMT_UNINT, get_ip_ping_repetition_number, set_ip_ping_repetition_number, NULL, NULL}, {"Timeout", &DMWRITE, DMT_UNINT, get_ip_ping_timeout, set_ip_ping_timeout, NULL, NULL}, {"DataBlockSize", &DMWRITE, DMT_UNINT, get_ip_ping_block_size, set_ip_ping_block_size, NULL, NULL}, +{"DSCP", &DMWRITE, DMT_UNINT, get_ip_ping_DSCP, set_ip_ping_DSCP, NULL, NULL}, {"SuccessCount", &DMREAD, DMT_UNINT, get_ip_ping_success_count, NULL, NULL}, {"FailureCount", &DMREAD, DMT_UNINT, get_ip_ping_failure_count, NULL, NULL, NULL}, {"AverageResponseTime", &DMREAD, DMT_UNINT, get_ip_ping_average_response_time, NULL, NULL, NULL}, {"MinimumResponseTime", &DMREAD, DMT_UNINT, get_ip_ping_min_response_time, NULL, NULL, NULL}, {"MaximumResponseTime", &DMREAD, DMT_UNINT, get_ip_ping_max_response_time, NULL, NULL, NULL}, +{"AverageResponseTimeDetailed", &DMREAD, DMT_UNINT, get_ip_ping_AverageResponseTimeDetailed, NULL, NULL, NULL}, +{"MinimumResponseTimeDetailed", &DMREAD, DMT_UNINT, get_ip_ping_MinimumResponseTimeDetailed, NULL, NULL, NULL}, +{"MaximumResponseTimeDetailed", &DMREAD, DMT_UNINT, get_ip_ping_MaximumResponseTimeDetailed, NULL, NULL, NULL}, +{0} +}; + +/* *** Device.IP.Diagnostics.TraceRoute. *** */ +DMOBJ tIPDiagnosticsTraceRouteObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextobj, leaf, linker*/ +{"RouteHops", &DMREAD, NULL, NULL, NULL, browseIPDiagnosticsTraceRouteRouteHopsInst, NULL, NULL, NULL, tIPDiagnosticsTraceRouteRouteHopsParams, NULL}, +{0} +}; + +DMLEAF tIPDiagnosticsTraceRouteParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"DiagnosticsState", &DMWRITE, DMT_STRING, get_IPDiagnosticsTraceRoute_DiagnosticsState, set_IPDiagnosticsTraceRoute_DiagnosticsState, NULL, NULL}, +{"Interface", &DMWRITE, DMT_STRING, get_IPDiagnosticsTraceRoute_Interface, set_IPDiagnosticsTraceRoute_Interface, NULL, NULL}, +{"ProtocolVersion", &DMWRITE, DMT_STRING, get_IPDiagnosticsTraceRoute_ProtocolVersion, set_IPDiagnosticsTraceRoute_ProtocolVersion, NULL, NULL}, +{"Host", &DMWRITE, DMT_STRING, get_IPDiagnosticsTraceRoute_Host, set_IPDiagnosticsTraceRoute_Host, NULL, NULL}, +{"NumberOfTries", &DMWRITE, DMT_UNINT, get_IPDiagnosticsTraceRoute_NumberOfTries, set_IPDiagnosticsTraceRoute_NumberOfTries, NULL, NULL}, +{"Timeout", &DMWRITE, DMT_UNINT, get_IPDiagnosticsTraceRoute_Timeout, set_IPDiagnosticsTraceRoute_Timeout, NULL, NULL}, +{"DataBlockSize", &DMWRITE, DMT_UNINT, get_IPDiagnosticsTraceRoute_DataBlockSize, set_IPDiagnosticsTraceRoute_DataBlockSize, NULL, NULL}, +{"DSCP", &DMWRITE, DMT_UNINT, get_IPDiagnosticsTraceRoute_DSCP, set_IPDiagnosticsTraceRoute_DSCP, NULL, NULL}, +{"MaxHopCount", &DMWRITE, DMT_UNINT, get_IPDiagnosticsTraceRoute_MaxHopCount, set_IPDiagnosticsTraceRoute_MaxHopCount, NULL, NULL}, +{"ResponseTime", &DMREAD, DMT_UNINT, get_IPDiagnosticsTraceRoute_ResponseTime, NULL, NULL, NULL}, +{"RouteHopsNumberOfEntries", &DMREAD, DMT_UNINT, get_IPDiagnosticsTraceRoute_RouteHopsNumberOfEntries, NULL, NULL, NULL}, +{0} +}; + +/* *** Device.IP.Diagnostics.TraceRoute.RouteHops.{i}. *** */ +DMLEAF tIPDiagnosticsTraceRouteRouteHopsParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"Host", &DMREAD, DMT_STRING, get_IPDiagnosticsTraceRouteRouteHops_Host, NULL, NULL, NULL}, +{"HostAddress", &DMREAD, DMT_STRING, get_IPDiagnosticsTraceRouteRouteHops_HostAddress, NULL, NULL, NULL}, +{"ErrorCode", &DMREAD, DMT_UNINT, get_IPDiagnosticsTraceRouteRouteHops_ErrorCode, NULL, NULL, NULL}, +{"RTTimes", &DMREAD, DMT_STRING, get_IPDiagnosticsTraceRouteRouteHops_RTTimes, NULL, NULL, NULL}, +{0} +}; + +/* *** Device.IP.Diagnostics.DownloadDiagnostics. *** */ +DMOBJ tIPDiagnosticsDownloadDiagnosticsObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextobj, leaf, linker*/ +{"PerConnectionResult", &DMREAD, NULL, NULL, NULL, browseIPDiagnosticsDownloadDiagnosticsPerConnectionResultInst, NULL, NULL, NULL, tIPDiagnosticsDownloadDiagnosticsPerConnectionResultParams, NULL}, +{0} +}; + +DMLEAF tIPDiagnosticsDownloadDiagnosticsParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"DiagnosticsState", &DMWRITE, DMT_STRING, get_IPDiagnosticsDownloadDiagnostics_DiagnosticsState, set_IPDiagnosticsDownloadDiagnostics_DiagnosticsState, NULL, NULL}, +{"Interface", &DMWRITE, DMT_STRING, get_IPDiagnosticsDownloadDiagnostics_Interface, set_IPDiagnosticsDownloadDiagnostics_Interface, NULL, NULL}, +{"DownloadURL", &DMWRITE, DMT_STRING, get_IPDiagnosticsDownloadDiagnostics_DownloadURL, set_IPDiagnosticsDownloadDiagnostics_DownloadURL, NULL, NULL}, +{"DownloadTransports", &DMREAD, DMT_STRING, get_IPDiagnosticsDownloadDiagnostics_DownloadTransports, NULL, NULL, NULL}, +{"DownloadDiagnosticMaxConnections", &DMREAD, DMT_UNINT, get_IPDiagnosticsDownloadDiagnostics_DownloadDiagnosticMaxConnections, NULL, NULL, NULL}, +{"DSCP", &DMWRITE, DMT_UNINT, get_IPDiagnosticsDownloadDiagnostics_DSCP, set_IPDiagnosticsDownloadDiagnostics_DSCP, NULL, NULL}, +{"EthernetPriority", &DMWRITE, DMT_UNINT, get_IPDiagnosticsDownloadDiagnostics_EthernetPriority, set_IPDiagnosticsDownloadDiagnostics_EthernetPriority, NULL, NULL}, +{"ProtocolVersion", &DMWRITE, DMT_STRING, get_IPDiagnosticsDownloadDiagnostics_ProtocolVersion, set_IPDiagnosticsDownloadDiagnostics_ProtocolVersion, NULL, NULL}, +{"NumberOfConnections", &DMWRITE, DMT_UNINT, get_IPDiagnosticsDownloadDiagnostics_NumberOfConnections, set_IPDiagnosticsDownloadDiagnostics_NumberOfConnections, NULL, NULL}, +{"ROMTime", &DMREAD, DMT_TIME, get_IPDiagnosticsDownloadDiagnostics_ROMTime, NULL, NULL, NULL}, +{"BOMTime", &DMREAD, DMT_TIME, get_IPDiagnosticsDownloadDiagnostics_BOMTime, NULL, NULL, NULL}, +{"EOMTime", &DMREAD, DMT_TIME, get_IPDiagnosticsDownloadDiagnostics_EOMTime, NULL, NULL, NULL}, +{"TestBytesReceived", &DMREAD, DMT_UNINT, get_IPDiagnosticsDownloadDiagnostics_TestBytesReceived, NULL, NULL, NULL}, +{"TotalBytesReceived", &DMREAD, DMT_UNINT, get_IPDiagnosticsDownloadDiagnostics_TotalBytesReceived, NULL, NULL, NULL}, +{"TotalBytesSent", &DMREAD, DMT_UNINT, get_IPDiagnosticsDownloadDiagnostics_TotalBytesSent, NULL, NULL, NULL}, +{"TestBytesReceivedUnderFullLoading", &DMREAD, DMT_UNINT, get_IPDiagnosticsDownloadDiagnostics_TestBytesReceivedUnderFullLoading, NULL, NULL, NULL}, +{"TotalBytesReceivedUnderFullLoading", &DMREAD, DMT_UNINT, get_IPDiagnosticsDownloadDiagnostics_TotalBytesReceivedUnderFullLoading, NULL, NULL, NULL}, +{"TotalBytesSentUnderFullLoading", &DMREAD, DMT_UNINT, get_IPDiagnosticsDownloadDiagnostics_TotalBytesSentUnderFullLoading, NULL, NULL, NULL}, +{"PeriodOfFullLoading", &DMREAD, DMT_UNINT, get_IPDiagnosticsDownloadDiagnostics_PeriodOfFullLoading, NULL, NULL, NULL}, +{"TCPOpenRequestTime", &DMREAD, DMT_TIME, get_IPDiagnosticsDownloadDiagnostics_TCPOpenRequestTime, NULL, NULL, NULL}, +{"TCPOpenResponseTime", &DMREAD, DMT_TIME, get_IPDiagnosticsDownloadDiagnostics_TCPOpenResponseTime, NULL, NULL, NULL}, +{"PerConnectionResultNumberOfEntries", &DMREAD, DMT_UNINT, get_IPDiagnosticsDownloadDiagnostics_PerConnectionResultNumberOfEntries, NULL, NULL, NULL}, +{"EnablePerConnectionResults", &DMWRITE, DMT_BOOL, get_IPDiagnosticsDownloadDiagnostics_EnablePerConnectionResults, set_IPDiagnosticsDownloadDiagnostics_EnablePerConnectionResults, NULL, NULL}, +{0} +}; + +/* *** Device.IP.Diagnostics.DownloadDiagnostics.PerConnectionResult.{i}. *** */ +DMLEAF tIPDiagnosticsDownloadDiagnosticsPerConnectionResultParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"ROMTime", &DMREAD, DMT_TIME, get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_ROMTime, NULL, NULL, NULL}, +{"BOMTime", &DMREAD, DMT_TIME, get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_BOMTime, NULL, NULL, NULL}, +{"EOMTime", &DMREAD, DMT_TIME, get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_EOMTime, NULL, NULL, NULL}, +{"TestBytesReceived", &DMREAD, DMT_UNINT, get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TestBytesReceived, NULL, NULL, NULL}, +{"TotalBytesReceived", &DMREAD, DMT_UNINT, get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TotalBytesReceived, NULL, NULL, NULL}, +{"TotalBytesSent", &DMREAD, DMT_UNINT, get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TotalBytesSent, NULL, NULL, NULL}, +{"TCPOpenRequestTime", &DMREAD, DMT_TIME, get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TCPOpenRequestTime, NULL, NULL, NULL}, +{"TCPOpenResponseTime", &DMREAD, DMT_TIME, get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TCPOpenResponseTime, NULL, NULL, NULL}, +{0} +}; + +/* *** Device.IP.Diagnostics.UploadDiagnostics. *** */ +DMOBJ tIPDiagnosticsUploadDiagnosticsObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextobj, leaf, linker*/ +{"PerConnectionResult", &DMREAD, NULL, NULL, NULL, browseIPDiagnosticsUploadDiagnosticsPerConnectionResultInst, NULL, NULL, NULL, tIPDiagnosticsUploadDiagnosticsPerConnectionResultParams, NULL}, +{0} +}; + +DMLEAF tIPDiagnosticsUploadDiagnosticsParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"DiagnosticsState", &DMWRITE, DMT_STRING, get_IPDiagnosticsUploadDiagnostics_DiagnosticsState, set_IPDiagnosticsUploadDiagnostics_DiagnosticsState, NULL, NULL}, +{"Interface", &DMWRITE, DMT_STRING, get_IPDiagnosticsUploadDiagnostics_Interface, set_IPDiagnosticsUploadDiagnostics_Interface, NULL, NULL}, +{"UploadURL", &DMWRITE, DMT_STRING, get_IPDiagnosticsUploadDiagnostics_UploadURL, set_IPDiagnosticsUploadDiagnostics_UploadURL, NULL, NULL}, +{"UploadTransports", &DMREAD, DMT_STRING, get_IPDiagnosticsUploadDiagnostics_UploadTransports, NULL, NULL, NULL}, +{"DSCP", &DMWRITE, DMT_UNINT, get_IPDiagnosticsUploadDiagnostics_DSCP, set_IPDiagnosticsUploadDiagnostics_DSCP, NULL, NULL}, +{"EthernetPriority", &DMWRITE, DMT_UNINT, get_IPDiagnosticsUploadDiagnostics_EthernetPriority, set_IPDiagnosticsUploadDiagnostics_EthernetPriority, NULL, NULL}, +{"TestFileLength", &DMWRITE, DMT_UNINT, get_IPDiagnosticsUploadDiagnostics_TestFileLength, set_IPDiagnosticsUploadDiagnostics_TestFileLength, NULL, NULL}, +{"ProtocolVersion", &DMWRITE, DMT_STRING, get_IPDiagnosticsUploadDiagnostics_ProtocolVersion, set_IPDiagnosticsUploadDiagnostics_ProtocolVersion, NULL, NULL}, +{"NumberOfConnections", &DMWRITE, DMT_UNINT, get_IPDiagnosticsUploadDiagnostics_NumberOfConnections, set_IPDiagnosticsUploadDiagnostics_NumberOfConnections, NULL, NULL}, +{"ROMTime", &DMREAD, DMT_TIME, get_IPDiagnosticsUploadDiagnostics_ROMTime, NULL, NULL, NULL}, +{"BOMTime", &DMREAD, DMT_TIME, get_IPDiagnosticsUploadDiagnostics_BOMTime, NULL, NULL, NULL}, +{"EOMTime", &DMREAD, DMT_TIME, get_IPDiagnosticsUploadDiagnostics_EOMTime, NULL, NULL, NULL}, +{"TestBytesSent", &DMREAD, DMT_UNINT, get_IPDiagnosticsUploadDiagnostics_TestBytesSent, NULL, NULL, NULL}, +{"TotalBytesReceived", &DMREAD, DMT_UNINT, get_IPDiagnosticsUploadDiagnostics_TotalBytesReceived, NULL, NULL, NULL}, +{"TotalBytesSent", &DMREAD, DMT_UNINT, get_IPDiagnosticsUploadDiagnostics_TotalBytesSent, NULL, NULL, NULL}, +{"TestBytesSentUnderFullLoading", &DMREAD, DMT_UNINT, get_IPDiagnosticsUploadDiagnostics_TestBytesSentUnderFullLoading, NULL, NULL, NULL}, +{"TotalBytesReceivedUnderFullLoading", &DMREAD, DMT_UNINT, get_IPDiagnosticsUploadDiagnostics_TotalBytesReceivedUnderFullLoading, NULL, NULL, NULL}, +{"TotalBytesSentUnderFullLoading", &DMREAD, DMT_UNINT, get_IPDiagnosticsUploadDiagnostics_TotalBytesSentUnderFullLoading, NULL, NULL, NULL}, +{"PeriodOfFullLoading", &DMREAD, DMT_UNINT, get_IPDiagnosticsUploadDiagnostics_PeriodOfFullLoading, NULL, NULL, NULL}, +{"TCPOpenRequestTime", &DMREAD, DMT_TIME, get_IPDiagnosticsUploadDiagnostics_TCPOpenRequestTime, NULL, NULL, NULL}, +{"TCPOpenResponseTime", &DMREAD, DMT_TIME, get_IPDiagnosticsUploadDiagnostics_TCPOpenResponseTime, NULL, NULL, NULL}, +{"PerConnectionResultNumberOfEntries", &DMREAD, DMT_UNINT, get_IPDiagnosticsUploadDiagnostics_PerConnectionResultNumberOfEntries, NULL, NULL, NULL}, +{"EnablePerConnectionResults", &DMWRITE, DMT_BOOL, get_IPDiagnosticsUploadDiagnostics_EnablePerConnectionResults, set_IPDiagnosticsUploadDiagnostics_EnablePerConnectionResults, NULL, NULL}, +{0} +}; + +/* *** Device.IP.Diagnostics.UploadDiagnostics.PerConnectionResult.{i}. *** */ +DMLEAF tIPDiagnosticsUploadDiagnosticsPerConnectionResultParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"ROMTime", &DMREAD, DMT_TIME, get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_ROMTime, NULL, NULL, NULL}, +{"BOMTime", &DMREAD, DMT_TIME, get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_BOMTime, NULL, NULL, NULL}, +{"EOMTime", &DMREAD, DMT_TIME, get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_EOMTime, NULL, NULL, NULL}, +{"TestBytesSent", &DMREAD, DMT_UNINT, get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_TestBytesSent, NULL, NULL, NULL}, +{"TotalBytesReceived", &DMREAD, DMT_UNINT, get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_TotalBytesReceived, NULL, NULL, NULL}, +{"TotalBytesSent", &DMREAD, DMT_UNINT, get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_TotalBytesSent, NULL, NULL, NULL}, +{"TCPOpenRequestTime", &DMREAD, DMT_TIME, get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_TCPOpenRequestTime, NULL, NULL, NULL}, +{"TCPOpenResponseTime", &DMREAD, DMT_TIME, get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_TCPOpenResponseTime, NULL, NULL, NULL}, +{0} +}; + +/* *** Device.IP.Diagnostics.UDPEchoConfig. *** */ +DMLEAF tIPDiagnosticsUDPEchoConfigParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"Enable", &DMWRITE, DMT_BOOL, get_IPDiagnosticsUDPEchoConfig_Enable, set_IPDiagnosticsUDPEchoConfig_Enable, NULL, NULL}, +{"Interface", &DMWRITE, DMT_STRING, get_IPDiagnosticsUDPEchoConfig_Interface, set_IPDiagnosticsUDPEchoConfig_Interface, NULL, NULL}, +{"SourceIPAddress", &DMWRITE, DMT_STRING, get_IPDiagnosticsUDPEchoConfig_SourceIPAddress, set_IPDiagnosticsUDPEchoConfig_SourceIPAddress, NULL, NULL}, +{"UDPPort", &DMWRITE, DMT_UNINT, get_IPDiagnosticsUDPEchoConfig_UDPPort, set_IPDiagnosticsUDPEchoConfig_UDPPort, NULL, NULL}, +{"EchoPlusEnabled", &DMWRITE, DMT_BOOL, get_IPDiagnosticsUDPEchoConfig_EchoPlusEnabled, set_IPDiagnosticsUDPEchoConfig_EchoPlusEnabled, NULL, NULL}, +{"EchoPlusSupported", &DMREAD, DMT_BOOL, get_IPDiagnosticsUDPEchoConfig_EchoPlusSupported, NULL, NULL, NULL}, +{"PacketsReceived", &DMREAD, DMT_UNINT, get_IPDiagnosticsUDPEchoConfig_PacketsReceived, NULL, NULL, NULL}, +{"PacketsResponded", &DMREAD, DMT_UNINT, get_IPDiagnosticsUDPEchoConfig_PacketsResponded, NULL, NULL, NULL}, +{"BytesReceived", &DMREAD, DMT_UNINT, get_IPDiagnosticsUDPEchoConfig_BytesReceived, NULL, NULL, NULL}, +{"BytesResponded", &DMREAD, DMT_UNINT, get_IPDiagnosticsUDPEchoConfig_BytesResponded, NULL, NULL, NULL}, +{"TimeFirstPacketReceived", &DMREAD, DMT_TIME, get_IPDiagnosticsUDPEchoConfig_TimeFirstPacketReceived, NULL, NULL, NULL}, +{"TimeLastPacketReceived", &DMREAD, DMT_TIME, get_IPDiagnosticsUDPEchoConfig_TimeLastPacketReceived, NULL, NULL, NULL}, +{0} +}; + +/* *** Device.IP.Diagnostics.UDPEchoDiagnostics. *** */ +DMLEAF tIPDiagnosticsUDPEchoDiagnosticsParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"DiagnosticsState", &DMWRITE, DMT_STRING, get_IPDiagnosticsUDPEchoDiagnostics_DiagnosticsState, set_IPDiagnosticsUDPEchoDiagnostics_DiagnosticsState, NULL, NULL}, +{"Interface", &DMWRITE, DMT_STRING, get_IPDiagnosticsUDPEchoDiagnostics_Interface, set_IPDiagnosticsUDPEchoDiagnostics_Interface, NULL, NULL}, +{"Host", &DMWRITE, DMT_STRING, get_IPDiagnosticsUDPEchoDiagnostics_Host, set_IPDiagnosticsUDPEchoDiagnostics_Host, NULL, NULL}, +{"Port", &DMWRITE, DMT_UNINT, get_IPDiagnosticsUDPEchoDiagnostics_Port, set_IPDiagnosticsUDPEchoDiagnostics_Port, NULL, NULL}, +{"NumberOfRepetitions", &DMWRITE, DMT_UNINT, get_IPDiagnosticsUDPEchoDiagnostics_NumberOfRepetitions, set_IPDiagnosticsUDPEchoDiagnostics_NumberOfRepetitions, NULL, NULL}, +{"Timeout", &DMWRITE, DMT_UNINT, get_IPDiagnosticsUDPEchoDiagnostics_Timeout, set_IPDiagnosticsUDPEchoDiagnostics_Timeout, NULL, NULL}, +{"DataBlockSize", &DMWRITE, DMT_UNINT, get_IPDiagnosticsUDPEchoDiagnostics_DataBlockSize, set_IPDiagnosticsUDPEchoDiagnostics_DataBlockSize, NULL, NULL}, +{"DSCP", &DMWRITE, DMT_UNINT, get_IPDiagnosticsUDPEchoDiagnostics_DSCP, set_IPDiagnosticsUDPEchoDiagnostics_DSCP, NULL, NULL}, +{"InterTransmissionTime", &DMWRITE, DMT_UNINT, get_IPDiagnosticsUDPEchoDiagnostics_InterTransmissionTime, set_IPDiagnosticsUDPEchoDiagnostics_InterTransmissionTime, NULL, NULL}, +{"ProtocolVersion", &DMWRITE, DMT_STRING, get_IPDiagnosticsUDPEchoDiagnostics_ProtocolVersion, set_IPDiagnosticsUDPEchoDiagnostics_ProtocolVersion, NULL, NULL}, +{"SuccessCount", &DMREAD, DMT_UNINT, get_IPDiagnosticsUDPEchoDiagnostics_SuccessCount, NULL, NULL, NULL}, +{"FailureCount", &DMREAD, DMT_UNINT, get_IPDiagnosticsUDPEchoDiagnostics_FailureCount, NULL, NULL, NULL}, +{"AverageResponseTime", &DMREAD, DMT_UNINT, get_IPDiagnosticsUDPEchoDiagnostics_AverageResponseTime, NULL, NULL, NULL}, +{"MinimumResponseTime", &DMREAD, DMT_UNINT, get_IPDiagnosticsUDPEchoDiagnostics_MinimumResponseTime, NULL, NULL, NULL}, +{"MaximumResponseTime", &DMREAD, DMT_UNINT, get_IPDiagnosticsUDPEchoDiagnostics_MaximumResponseTime, NULL, NULL, NULL}, +{0} +}; + +/* *** Device.IP.Diagnostics.ServerSelectionDiagnostics. *** */ +DMLEAF tIPDiagnosticsServerSelectionDiagnosticsParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"DiagnosticsState", &DMWRITE, DMT_STRING, get_IPDiagnosticsServerSelectionDiagnostics_DiagnosticsState, set_IPDiagnosticsServerSelectionDiagnostics_DiagnosticsState, NULL, NULL}, +{"Interface", &DMWRITE, DMT_STRING, get_IPDiagnosticsServerSelectionDiagnostics_Interface, set_IPDiagnosticsServerSelectionDiagnostics_Interface, NULL, NULL}, +{"ProtocolVersion", &DMWRITE, DMT_STRING, get_IPDiagnosticsServerSelectionDiagnostics_ProtocolVersion, set_IPDiagnosticsServerSelectionDiagnostics_ProtocolVersion, NULL, NULL}, +{"Protocol", &DMWRITE, DMT_STRING, get_IPDiagnosticsServerSelectionDiagnostics_Protocol, set_IPDiagnosticsServerSelectionDiagnostics_Protocol, NULL, NULL}, +{"Port", &DMWRITE, DMT_UNINT, get_IPDiagnosticsServerSelectionDiagnostics_Port, set_IPDiagnosticsServerSelectionDiagnostics_Port, NULL, NULL}, +{"HostList", &DMWRITE, DMT_STRING, get_IPDiagnosticsServerSelectionDiagnostics_HostList, set_IPDiagnosticsServerSelectionDiagnostics_HostList, NULL, NULL}, +{"NumberOfRepetitions", &DMWRITE, DMT_UNINT, get_IPDiagnosticsServerSelectionDiagnostics_NumberOfRepetitions, set_IPDiagnosticsServerSelectionDiagnostics_NumberOfRepetitions, NULL, NULL}, +{"Timeout", &DMWRITE, DMT_UNINT, get_IPDiagnosticsServerSelectionDiagnostics_Timeout, set_IPDiagnosticsServerSelectionDiagnostics_Timeout, NULL, NULL}, +{"FastestHost", &DMREAD, DMT_STRING, get_IPDiagnosticsServerSelectionDiagnostics_FastestHost, NULL, NULL, NULL}, +{"MinimumResponseTime", &DMREAD, DMT_UNINT, get_IPDiagnosticsServerSelectionDiagnostics_MinimumResponseTime, NULL, NULL, NULL}, +{"AverageResponseTime", &DMREAD, DMT_UNINT, get_IPDiagnosticsServerSelectionDiagnostics_AverageResponseTime, NULL, NULL, NULL}, +{"MaximumResponseTime", &DMREAD, DMT_UNINT, get_IPDiagnosticsServerSelectionDiagnostics_MaximumResponseTime, NULL, NULL, NULL}, {0} }; unsigned char get_ipv4_finform(char *refparam, struct dmctx *dmctx, void *data, char *instance) { return 1; - //TODO } unsigned char get_ipv6_finform(char *refparam, struct dmctx *dmctx, void *data, char *instance) { return 1; - //TODO } + /************************************************************* * INIT /*************************************************************/ @@ -132,6 +349,22 @@ inline int init_ip_args(struct ip_args *args, struct uci_section *s, char *ip_4a /************************************************************* * GET & SET PARAM /*************************************************************/ +int get_diag_enable_true(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "1"; + return 0; +} + +int get_diag_enable_false(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "0"; + return 0; +} + +/* + * *** Device.IP.Diagnostics.IPPing. *** + */ + static inline char *ipping_get(char *option, char *def) { char *tmp; @@ -187,7 +420,7 @@ int set_ip_ping_interface(char *refparam, struct dmctx *ctx, void *data, char *i case VALUECHECK: return 0; case VALUESET: - //IPPING_STOP + IPPING_STOP curr_section = dmuci_walk_state_section("cwmp", "ippingdiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); if(!curr_section) { @@ -199,9 +432,37 @@ int set_ip_ping_interface(char *refparam, struct dmctx *ctx, void *data, char *i return 0; } +int get_ip_ping_protocolversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ipping_get("ProtocolVersion", "Any"); + return 0; +} + +int set_ip_ping_protocolversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (strcmp(value, "IPv4") == 0 || strcmp(value, "IPv6") == 0) { + IPPING_STOP + curr_section = dmuci_walk_state_section("cwmp", "ippingdiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "ippingdiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@ippingdiagnostic[0]", "ProtocolVersion", value); + } + return 0; + } + return 0; +} + int get_ip_ping_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_varstate_string("cwmp", "@ippingdiagnostic[0]", "Host", value); return 0; } @@ -242,13 +503,15 @@ int set_ip_ping_repetition_number(char *refparam, struct dmctx *ctx, void *data, case VALUECHECK: return 0; case VALUESET: - IPPING_STOP - curr_section = dmuci_walk_state_section("cwmp", "ippingdiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); - if(!curr_section) - { - dmuci_add_state_section("cwmp", "ippingdiagnostic", &curr_section, &tmp); + if (atoi(value) >= 1) { + IPPING_STOP + curr_section = dmuci_walk_state_section("cwmp", "ippingdiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "ippingdiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@ippingdiagnostic[0]", "NumberOfRepetitions", value); } - dmuci_set_varstate_value("cwmp", "@ippingdiagnostic[0]", "NumberOfRepetitions", value); return 0; } return 0; @@ -256,7 +519,6 @@ int set_ip_ping_repetition_number(char *refparam, struct dmctx *ctx, void *data, int get_ip_ping_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = ipping_get("Timeout", "1000"); return 0; } @@ -270,13 +532,15 @@ int set_ip_ping_timeout(char *refparam, struct dmctx *ctx, void *data, char *ins case VALUECHECK: return 0; case VALUESET: - IPPING_STOP - curr_section = dmuci_walk_state_section("cwmp", "ippingdiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); - if(!curr_section) - { - dmuci_add_state_section("cwmp", "ippingdiagnostic", &curr_section, &tmp); + if (atoi(value) >= 1) { + IPPING_STOP + curr_section = dmuci_walk_state_section("cwmp", "ippingdiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "ippingdiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@ippingdiagnostic[0]", "Timeout", value); } - dmuci_set_varstate_value("cwmp", "@ippingdiagnostic[0]", "Timeout", value); return 0; } return 0; @@ -298,13 +562,44 @@ int set_ip_ping_block_size(char *refparam, struct dmctx *ctx, void *data, char * case VALUECHECK: return 0; case VALUESET: - IPPING_STOP - curr_section = dmuci_walk_state_section("cwmp", "ippingdiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); - if(!curr_section) - { - dmuci_add_state_section("cwmp", "ippingdiagnostic", &curr_section, &tmp); + if ((atoi(value) >= 1) && (atoi(value) <= 65535)) { + IPPING_STOP + curr_section = dmuci_walk_state_section("cwmp", "ippingdiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "ippingdiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@ippingdiagnostic[0]", "DataBlockSize", value); + } + } + return 0; +} + +int get_ip_ping_DSCP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ipping_get("DSCP", "0"); + return 0; +} + +int set_ip_ping_DSCP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if ((atoi(value) >= 0) && (atoi(value) <= 63)) { + TRACEROUTE_STOP + curr_section = dmuci_walk_state_section("cwmp", "ippingdiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "ippingdiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@ippingdiagnostic[0]", "DSCP", value); + return 0; } - dmuci_set_varstate_value("cwmp", "@ippingdiagnostic[0]", "DataBlockSize", value); } return 0; } @@ -339,6 +634,1892 @@ int get_ip_ping_max_response_time(char *refparam, struct dmctx *ctx, void *data, return 0; } +int get_ip_ping_AverageResponseTimeDetailed(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ipping_get("AverageResponseTimeDetailed", "0"); + return 0; +} + +int get_ip_ping_MinimumResponseTimeDetailed(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ipping_get("MinimumResponseTimeDetailed", "0"); + return 0; +} + +int get_ip_ping_MaximumResponseTimeDetailed(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ipping_get("MaximumResponseTimeDetailed", "0"); + return 0; +} + +/* + * *** Device.IP.Diagnostics.TraceRoute. *** + */ + +static inline char *traceroute_get(char *option, char *def) +{ + char *tmp; + dmuci_get_varstate_string("cwmp", "@traceroutediagnostic[0]", option, &tmp); + if(tmp && tmp[0] == '\0') + return dmstrdup(def); + else + return tmp; +} + +int get_IPDiagnosticsTraceRoute_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = traceroute_get("DiagnosticState", "None"); + return 0; +} + +int set_IPDiagnosticsTraceRoute_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (strcmp(value, "Requested") == 0) { + TRACEROUTE_STOP + curr_section = dmuci_walk_state_section("cwmp", "traceroutediagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "traceroutediagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@traceroutediagnostic[0]", "DiagnosticState", value); + cwmp_set_end_session(END_SESSION_TRACEROUTE_DIAGNOSTIC); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsTraceRoute_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_varstate_string("cwmp", "@traceroutediagnostic[0]", "interface", value); + return 0; +} + +int set_IPDiagnosticsTraceRoute_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + TRACEROUTE_STOP + curr_section = dmuci_walk_state_section("cwmp", "traceroutediagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "traceroutediagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@traceroutediagnostic[0]", "interface", value); + return 0; + } + return 0; +} + +int get_IPDiagnosticsTraceRoute_ProtocolVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = traceroute_get("ProtocolVersion", "Any"); + return 0; +} + +int set_IPDiagnosticsTraceRoute_ProtocolVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (strcmp(value, "IPv4") == 0 || strcmp(value, "IPv6") == 0) { + TRACEROUTE_STOP + curr_section = dmuci_walk_state_section("cwmp", "traceroutediagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "traceroutediagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@traceroutediagnostic[0]", "ProtocolVersion", value); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsTraceRoute_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_varstate_string("cwmp", "@traceroutediagnostic[0]", "Host", value); + return 0; +} + +int set_IPDiagnosticsTraceRoute_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + TRACEROUTE_STOP + curr_section = dmuci_walk_state_section("cwmp", "traceroutediagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "traceroutediagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@traceroutediagnostic[0]", "Host", value); + return 0; + } + return 0; +} + +int get_IPDiagnosticsTraceRoute_NumberOfTries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = traceroute_get("NumberOfTries", "3"); + return 0; +} + +int set_IPDiagnosticsTraceRoute_NumberOfTries(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if ((atoi(value) >= 1) && (atoi(value) <= 3)) { + TRACEROUTE_STOP + curr_section = dmuci_walk_state_section("cwmp", "traceroutediagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "traceroutediagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@traceroutediagnostic[0]", "NumberOfTries", value); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsTraceRoute_Timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = traceroute_get("Timeout", "5000"); + return 0; +} + +int set_IPDiagnosticsTraceRoute_Timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (atoi(value) >= 1) { + TRACEROUTE_STOP + curr_section = dmuci_walk_state_section("cwmp", "traceroutediagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "traceroutediagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@traceroutediagnostic[0]", "Timeout", value); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsTraceRoute_DataBlockSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = traceroute_get("DataBlockSize", "38"); + return 0; +} + +int set_IPDiagnosticsTraceRoute_DataBlockSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if ((atoi(value) >= 1) && (atoi(value) <= 65535)) { + TRACEROUTE_STOP + curr_section = dmuci_walk_state_section("cwmp", "traceroutediagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "traceroutediagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@traceroutediagnostic[0]", "DataBlockSize", value); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsTraceRoute_DSCP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = traceroute_get("DSCP", "0"); + return 0; +} + +int set_IPDiagnosticsTraceRoute_DSCP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if ((atoi(value) >= 0) && (atoi(value) <= 63)) { + TRACEROUTE_STOP + curr_section = dmuci_walk_state_section("cwmp", "traceroutediagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "traceroutediagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@traceroutediagnostic[0]", "DSCP", value); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsTraceRoute_MaxHopCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = traceroute_get("MaxHops", "30"); + return 0; +} + +int set_IPDiagnosticsTraceRoute_MaxHopCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if ((atoi(value) >= 1) && (atoi(value) <= 64)) { + TRACEROUTE_STOP + curr_section = dmuci_walk_state_section("cwmp", "traceroutediagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "traceroutediagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@traceroutediagnostic[0]", "MaxHops", value); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsTraceRoute_ResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = traceroute_get("ResponseTime", "0"); + return 0; +} + +int get_IPDiagnosticsTraceRoute_RouteHopsNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = traceroute_get("NumberOfHops", "0"); + return 0; +} + +int get_IPDiagnosticsTraceRouteRouteHops_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "host", value); + return 0; +} + +int get_IPDiagnosticsTraceRouteRouteHops_HostAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "ip", value); + return 0; +} + +int get_IPDiagnosticsTraceRouteRouteHops_ErrorCode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "0"; + return 0; +} + +int get_IPDiagnosticsTraceRouteRouteHops_RTTimes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "time", value); + return 0; +} + +/* + * *** Device.IP.Diagnostics.DownloadDiagnostics. *** + */ + +static inline char *download_get(char *option, char *def) +{ + char *tmp; + dmuci_get_varstate_string("cwmp", "@downloaddiagnostic[0]", option, &tmp); + if(tmp && tmp[0] == '\0') + return dmstrdup(def); + else + return tmp; +} + +int get_IPDiagnosticsDownloadDiagnostics_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("DiagnosticState", "None"); + return 0; +} + +int set_IPDiagnosticsDownloadDiagnostics_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (strcmp(value, "Requested") == 0) { + DOWNLOAD_DIAGNOSTIC_STOP + curr_section = dmuci_walk_state_section("cwmp", "downloaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "downloaddiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@downloaddiagnostic[0]", "DiagnosticState", value); + cwmp_set_end_session(END_SESSION_DOWNLOAD_DIAGNOSTIC); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *linker; + dmuci_get_varstate_string("cwmp", "@downloaddiagnostic[0]", "interface", &linker); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + if (*value == NULL) + *value = ""; + return 0; +} + +int set_IPDiagnosticsDownloadDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *linker = NULL, *tmp, *device = NULL; + struct uci_section *curr_section = NULL; + json_object *res; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + adm_entry_get_linker_value(ctx, value, &linker); + if (linker) { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", linker, String}}, 1, &res); + device = dmjson_get_value(res, 1, "device"); + if (device) { + DOWNLOAD_DIAGNOSTIC_STOP + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "downloaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "downloaddiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@downloaddiagnostic[0]", "interface", linker); + dmuci_set_varstate_value("cwmp", "@downloaddiagnostic[0]", "device", device); + } + dmfree(linker); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_DownloadURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_varstate_string("cwmp", "@downloaddiagnostic[0]", "url", value); + return 0; +} + +int set_IPDiagnosticsDownloadDiagnostics_DownloadURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + DOWNLOAD_DIAGNOSTIC_STOP + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "downloaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "downloaddiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@downloaddiagnostic[0]", "url", value); + return 0; + } + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_DownloadTransports(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "HTTP,FTP"; + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_DownloadDiagnosticMaxConnections(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "1"; + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_DSCP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("DSCP", "0"); + return 0; +} + +int set_IPDiagnosticsDownloadDiagnostics_DSCP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + DOWNLOAD_DIAGNOSTIC_STOP + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "downloaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "downloaddiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@downloaddiagnostic[0]", "DSCP", value); + return 0; + } + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_EthernetPriority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("ethernetpriority", ""); + return 0; +} + +int set_IPDiagnosticsDownloadDiagnostics_EthernetPriority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + DOWNLOAD_DIAGNOSTIC_STOP + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "downloaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "downloaddiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@downloaddiagnostic[0]", "ethernetpriority", value); + return 0; + } + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_ProtocolVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("ProtocolVersion", "Any"); + return 0; +} + +int set_IPDiagnosticsDownloadDiagnostics_ProtocolVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (strcmp(value, "IPv4") == 0 || strcmp(value, "IPv6") == 0) { + DOWNLOAD_DIAGNOSTIC_STOP + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "downloaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "downloaddiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@downloaddiagnostic[0]", "ProtocolVersion", value); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_NumberOfConnections(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("NumberOfConnections", "1"); + return 0; +} + +int set_IPDiagnosticsDownloadDiagnostics_NumberOfConnections(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (strcmp(value, "1") == 0) { + DOWNLOAD_DIAGNOSTIC_STOP + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "downloaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "downloaddiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@downloaddiagnostic[0]", "NumberOfConnections", value); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_ROMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("ROMtime", "0"); + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_BOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("BOMtime", "0"); + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_EOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("EOMtime", "0"); + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_TestBytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("TestBytesReceived", "0"); + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_TotalBytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("TotalBytesReceived", "0"); + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_TotalBytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("TotalBytesSent", "0"); + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_TestBytesReceivedUnderFullLoading(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("TestBytesReceived", "0"); + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_TotalBytesReceivedUnderFullLoading(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("TotalBytesReceived", "0"); + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_TotalBytesSentUnderFullLoading(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("TotalBytesSent", "0"); + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_PeriodOfFullLoading(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("PeriodOfFullLoading", "0"); + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_TCPOpenRequestTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("TCPOpenRequestTime", "0"); + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_TCPOpenResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("TCPOpenResponseTime", "0"); + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_PerConnectionResultNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *tmp; + bool b; + dmuci_get_varstate_string("cwmp", "@downloaddiagnostic[0]", "EnablePerConnection", &tmp); + string_to_bool(tmp, &b); + *value = (b) ? "1" : "0"; + return 0; +} + +int get_IPDiagnosticsDownloadDiagnostics_EnablePerConnectionResults(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("EnablePerConnection", "0"); + return 0; +} + +int set_IPDiagnosticsDownloadDiagnostics_EnablePerConnectionResults(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + bool b; + switch (action) { + case VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + case VALUESET: + DOWNLOAD_DIAGNOSTIC_STOP + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "downloaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "downloaddiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@downloaddiagnostic[0]", "EnablePerConnection", value); + return 0; + } + return 0; +} + +int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_ROMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("ROMTime", "0"); + return 0; +} + +int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_BOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("BOMTime", "0"); + return 0; +} + +int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_EOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("EOMTime", "0"); + return 0; +} + +int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TestBytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("TestBytesReceived", "0"); + return 0; +} + +int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TotalBytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "TotalBytesReceived", value); + return 0; +} + +int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TotalBytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "TotalBytesSent", value); + return 0; +} + +int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TCPOpenRequestTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("TCPOpenRequestTime", "0"); + return 0; +} + +int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TCPOpenResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = download_get("TCPOpenResponseTime", "0"); + return 0; +} + +/* + * *** Device.IP.Diagnostics.UploadDiagnostics. *** + */ + +static inline char *upload_get(char *option, char *def) +{ + char *tmp; + dmuci_get_varstate_string("cwmp", "@uploaddiagnostic[0]", option, &tmp); + if(tmp && tmp[0] == '\0') + return dmstrdup(def); + else + return tmp; +} + +int get_IPDiagnosticsUploadDiagnostics_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("DiagnosticState", "None"); + return 0; +} + +int set_IPDiagnosticsUploadDiagnostics_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (strcmp(value, "Requested") == 0) { + UPLOAD_DIAGNOSTIC_STOP + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "uploaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "uploaddiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@uploaddiagnostic[0]", "DiagnosticState", value); + cwmp_set_end_session(END_SESSION_UPLOAD_DIAGNOSTIC); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *linker; + dmuci_get_varstate_string("cwmp", "@uploaddiagnostic[0]", "interface", &linker); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + if (*value == NULL) + *value = ""; + return 0; +} + +int set_IPDiagnosticsUploadDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *linker = NULL, *tmp, *device= NULL; + struct uci_section *curr_section = NULL; + json_object *res; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + adm_entry_get_linker_value(ctx, value, &linker); + if (linker) { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", linker, String}}, 1, &res); + device = dmjson_get_value(res, 1, "device"); + if (device) { + UPLOAD_DIAGNOSTIC_STOP + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "uploaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "uploaddiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@uploaddiagnostic[0]", "interface", linker); + dmuci_set_varstate_value("cwmp", "@uploaddiagnostic[0]", "device", device); + } + dmfree(linker); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_UploadURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_varstate_string("cwmp", "@uploaddiagnostic[0]", "url", value); + return 0; +} + +int set_IPDiagnosticsUploadDiagnostics_UploadURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + UPLOAD_DIAGNOSTIC_STOP + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "uploaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "uploaddiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@uploaddiagnostic[0]", "url", value); + return 0; + } + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_UploadTransports(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "HTTP,FTP"; + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_DSCP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("DSCP", "0"); + return 0; +} + +int set_IPDiagnosticsUploadDiagnostics_DSCP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + UPLOAD_DIAGNOSTIC_STOP + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "uploaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "uploaddiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@uploaddiagnostic[0]", "DSCP", value); + return 0; + } + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_EthernetPriority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("ethernetpriority", "0"); + return 0; +} + +int set_IPDiagnosticsUploadDiagnostics_EthernetPriority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + UPLOAD_DIAGNOSTIC_STOP + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "uploaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "uploaddiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@uploaddiagnostic[0]", "ethernetpriority", value); + return 0; + } + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_TestFileLength(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("TestFileLength", "0"); + return 0; +} + +int set_IPDiagnosticsUploadDiagnostics_TestFileLength(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + UPLOAD_DIAGNOSTIC_STOP + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "uploaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "uploaddiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@uploaddiagnostic[0]", "TestFileLength", value); + return 0; + } + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_ProtocolVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("ProtocolVersion", "Any"); + return 0; +} + +int set_IPDiagnosticsUploadDiagnostics_ProtocolVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (strcmp(value, "IPv4") == 0 || strcmp(value, "IPv6") == 0) { + UPLOAD_DIAGNOSTIC_STOP + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "uploaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "uploaddiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@uploaddiagnostic[0]", "ProtocolVersion", value); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_NumberOfConnections(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("NumberOfConnections", "1"); + return 0; +} + +int set_IPDiagnosticsUploadDiagnostics_NumberOfConnections(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (strcmp(value, "1") == 0) { + UPLOAD_DIAGNOSTIC_STOP + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "uploaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "uploaddiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@uploaddiagnostic[0]", "NumberOfConnections", value); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_ROMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("ROMtime", "0"); + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_BOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("BOMtime", "0"); + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_EOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("EOMtime", "0"); + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_TestBytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("TestBytesSent", "0"); + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_TotalBytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("TotalBytesReceived", "0"); + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_TotalBytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("TotalBytesSent", "0"); + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_TestBytesSentUnderFullLoading(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("TestBytesSent", "0"); + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_TotalBytesReceivedUnderFullLoading(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("TotalBytesReceived", "0"); + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_TotalBytesSentUnderFullLoading(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("TotalBytesSent", "0"); + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_PeriodOfFullLoading(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("PeriodOfFullLoading", "0"); + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_TCPOpenRequestTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("TCPOpenRequestTime", "0"); + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_TCPOpenResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("TCPOpenResponseTime", "0"); + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_PerConnectionResultNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *tmp; + bool b; + dmuci_get_varstate_string("cwmp", "@uploaddiagnostic[0]", "EnablePerConnection", &tmp); + string_to_bool(tmp, &b); + *value = (b) ? "1" : "0"; + return 0; +} + +int get_IPDiagnosticsUploadDiagnostics_EnablePerConnectionResults(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("EnablePerConnection", "0"); + return 0; +} + +int set_IPDiagnosticsUploadDiagnostics_EnablePerConnectionResults(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + bool b; + switch (action) { + case VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + case VALUESET: + UPLOAD_DIAGNOSTIC_STOP + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "uploaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "uploaddiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@uploaddiagnostic[0]", "EnablePerConnection", value); + return 0; + } + return 0; +} + +int get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_ROMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("ROMTime", "0"); + return 0; +} + +int get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_BOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("BOMTime", "0"); + return 0; +} + +int get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_EOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("EOMTime", "0"); + return 0; +} + +int get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_TestBytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "TestBytesSent", value); + return 0; +} + +int get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_TotalBytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "TotalBytesReceived", value); + return 0; +} + +int get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_TotalBytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "TotalBytesSent", value); + return 0; + +} + +int get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_TCPOpenRequestTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("TCPOpenRequestTime", "0"); + return 0; +} + +int get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_TCPOpenResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = upload_get("TCPOpenResponseTime", "0"); + return 0; +} + +/* + * *** Device.IP.Diagnostics.UDPEchoConfig. *** + */ + +int get_IPDiagnosticsUDPEchoConfig_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp_udpechoserver", "udpechoserver", "enable", value); + return 0; +} + +int set_IPDiagnosticsUDPEchoConfig_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + if (b) + dmuci_set_value("cwmp_udpechoserver", "udpechoserver", "enable", "1"); + else + dmuci_set_value("cwmp_udpechoserver", "udpechoserver", "enable", "0"); + return 0; + } + return 0; +} + +int get_IPDiagnosticsUDPEchoConfig_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp_udpechoserver", "udpechoserver", "interface", value); + return 0; +} + +int set_IPDiagnosticsUDPEchoConfig_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value("cwmp_udpechoserver", "udpechoserver", "interface", value); + return 0; + } + return 0; +} + +int get_IPDiagnosticsUDPEchoConfig_SourceIPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp_udpechoserver", "udpechoserver", "address", value); + return 0; +} + +int set_IPDiagnosticsUDPEchoConfig_SourceIPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value("cwmp_udpechoserver", "udpechoserver", "address", value); + return 0; + } + return 0; +} + +int get_IPDiagnosticsUDPEchoConfig_UDPPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp_udpechoserver", "udpechoserver", "server_port", value); + return 0; +} + +int set_IPDiagnosticsUDPEchoConfig_UDPPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value("cwmp_udpechoserver", "udpechoserver", "server_port", value); + return 0; + } + return 0; +} + +int get_IPDiagnosticsUDPEchoConfig_EchoPlusEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp_udpechoserver", "udpechoserver", "plus", value); + return 0; +} + +int set_IPDiagnosticsUDPEchoConfig_EchoPlusEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + if (b) + dmuci_set_value("cwmp_udpechoserver", "udpechoserver", "plus", "1"); + else + dmuci_set_value("cwmp_udpechoserver", "udpechoserver", "plus", "0"); + return 0; + } + return 0; +} + +int get_IPDiagnosticsUDPEchoConfig_EchoPlusSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "true"; + return 0; +} + +static inline char *udpechoconfig_get(char *option, char *def) +{ + char *tmp; + dmuci_get_varstate_string("cwmp_udpechoserver", "udpechoserver", option, &tmp); + if(tmp && tmp[0] == '\0') + return dmstrdup(def); + else + return tmp; +} + +int get_IPDiagnosticsUDPEchoConfig_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = udpechoconfig_get("PacketsReceived", "0"); + return 0; +} + +int get_IPDiagnosticsUDPEchoConfig_PacketsResponded(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = udpechoconfig_get("PacketsResponded", "0"); + return 0; +} + +int get_IPDiagnosticsUDPEchoConfig_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = udpechoconfig_get("BytesReceived", "0"); + return 0; +} + +int get_IPDiagnosticsUDPEchoConfig_BytesResponded(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = udpechoconfig_get("BytesResponded", "0"); + return 0; +} + +int get_IPDiagnosticsUDPEchoConfig_TimeFirstPacketReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = udpechoconfig_get("TimeFirstPacketReceived", "0"); + return 0; +} + +int get_IPDiagnosticsUDPEchoConfig_TimeLastPacketReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = udpechoconfig_get("TimeLastPacketReceived", "0"); + return 0; +} + +/* + * *** Device.IP.Diagnostics.UDPEchoDiagnostics. *** + */ + +static inline char *udpechodiagnostics_get(char *option, char *def) +{ + char *tmp; + dmuci_get_varstate_string("cwmp", "@udpechodiagnostic[0]", option, &tmp); + if(tmp && tmp[0] == '\0') + return dmstrdup(def); + else + return tmp; +} + +int get_IPDiagnosticsUDPEchoDiagnostics_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = udpechodiagnostics_get("DiagnosticState", "None"); + return 0; +} + +int set_IPDiagnosticsUDPEchoDiagnostics_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (strcmp(value, "Requested") == 0) { + UDPECHO_STOP; + curr_section = dmuci_walk_state_section("cwmp", "udpechodiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "udpechodiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@udpechodiagnostic[0]", "DiagnosticState", value); + cwmp_set_end_session(END_SESSION_UDPECHO_DIAGNOSTIC); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsUDPEchoDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_varstate_string("cwmp", "@udpechodiagnostic[0]", "Interface", value); + return 0; +} + +int set_IPDiagnosticsUDPEchoDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + UDPECHO_STOP; + curr_section = dmuci_walk_state_section("cwmp", "udpechodiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "udpechodiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@udpechodiagnostic[0]", "Interface", value); + return 0; + } + return 0; +} + +int get_IPDiagnosticsUDPEchoDiagnostics_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_varstate_string("cwmp", "@udpechodiagnostic[0]", "Host", value); + return 0; +} + +int set_IPDiagnosticsUDPEchoDiagnostics_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + UDPECHO_STOP; + curr_section = dmuci_walk_state_section("cwmp", "udpechodiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "udpechodiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@udpechodiagnostic[0]", "Host", value); + return 0; + } + return 0; +} + +int get_IPDiagnosticsUDPEchoDiagnostics_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_varstate_string("cwmp", "@udpechodiagnostic[0]", "Port", value); + return 0; +} + +int set_IPDiagnosticsUDPEchoDiagnostics_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (atoi(value) >= 1 && atoi(value) <= 65535) { + UDPECHO_STOP; + curr_section = dmuci_walk_state_section("cwmp", "udpechodiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "udpechodiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@udpechodiagnostic[0]", "port", value); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsUDPEchoDiagnostics_NumberOfRepetitions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = udpechodiagnostics_get("NumberOfRepetitions", "1"); + return 0; +} + +int set_IPDiagnosticsUDPEchoDiagnostics_NumberOfRepetitions(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + UDPECHO_STOP; + curr_section = dmuci_walk_state_section("cwmp", "udpechodiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "udpechodiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@udpechodiagnostic[0]", "NumberOfRepetitions", value); + return 0; + } + return 0; +} + +int get_IPDiagnosticsUDPEchoDiagnostics_Timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = udpechodiagnostics_get("Timeout", "5000"); + return 0; +} + +int set_IPDiagnosticsUDPEchoDiagnostics_Timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + UDPECHO_STOP; + curr_section = dmuci_walk_state_section("cwmp", "udpechodiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "udpechodiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@udpechodiagnostic[0]", "Timeout", value); + return 0; + } + return 0; +} + +int get_IPDiagnosticsUDPEchoDiagnostics_DataBlockSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = udpechodiagnostics_get("DataBlockSize", "24"); + return 0; +} + +int set_IPDiagnosticsUDPEchoDiagnostics_DataBlockSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (atoi(value) >= 1 && atoi(value) <= 65535) { + UDPECHO_STOP; + curr_section = dmuci_walk_state_section("cwmp", "udpechodiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "udpechodiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@udpechodiagnostic[0]", "DataBlockSize", value); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsUDPEchoDiagnostics_DSCP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = udpechodiagnostics_get("DSCP", "0"); + return 0; +} + +int set_IPDiagnosticsUDPEchoDiagnostics_DSCP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (atoi(value) >= 0 && atoi(value) <= 63) { + UDPECHO_STOP; + curr_section = dmuci_walk_state_section("cwmp", "udpechodiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "udpechodiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@udpechodiagnostic[0]", "DSCP", value); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsUDPEchoDiagnostics_InterTransmissionTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = udpechodiagnostics_get("InterTransmissionTime", "1000"); + return 0; +} + +int set_IPDiagnosticsUDPEchoDiagnostics_InterTransmissionTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (atoi(value) >= 1 && atoi(value) <= 65535) { + UDPECHO_STOP; + curr_section = dmuci_walk_state_section("cwmp", "udpechodiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "udpechodiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@udpechodiagnostic[0]", "InterTransmissionTime", value); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsUDPEchoDiagnostics_ProtocolVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = udpechodiagnostics_get("ProtocolVersion", "Any"); + return 0; +} + +int set_IPDiagnosticsUDPEchoDiagnostics_ProtocolVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (strcmp(value, "IPv4") == 0 || strcmp(value, "IPv6") == 0) { + UDPECHO_STOP; + curr_section = dmuci_walk_state_section("cwmp", "udpechodiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "udpechodiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@udpechodiagnostic[0]", "ProtocolVersion", value); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsUDPEchoDiagnostics_SuccessCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = udpechodiagnostics_get("SuccessCount", "0"); + return 0; +} + +int get_IPDiagnosticsUDPEchoDiagnostics_FailureCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = udpechodiagnostics_get("FailureCount", "0"); + return 0; +} + +int get_IPDiagnosticsUDPEchoDiagnostics_AverageResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = udpechodiagnostics_get("AverageResponseTime", "0"); + return 0; +} + +int get_IPDiagnosticsUDPEchoDiagnostics_MinimumResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = udpechodiagnostics_get("MinimumResponseTime", "0"); + return 0; +} + +int get_IPDiagnosticsUDPEchoDiagnostics_MaximumResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = udpechodiagnostics_get("MaximumResponseTime", "0"); + return 0; +} + +/* + * *** Device.IP.Diagnostics.ServerSelectionDiagnostics. *** + */ + +static inline char *serverselection_get(char *option, char *def) +{ + char *tmp; + dmuci_get_varstate_string("cwmp", "@serverselectiondiagnostic[0]", option, &tmp); + if(tmp && tmp[0] == '\0') + return dmstrdup(def); + else + return tmp; +} + +int get_IPDiagnosticsServerSelectionDiagnostics_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = serverselection_get("DiagnosticState", "None"); + return 0; +} + +int set_IPDiagnosticsServerSelectionDiagnostics_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (strcmp(value, "Requested") == 0) { + SERVERSELECTION_STOP + curr_section = dmuci_walk_state_section("cwmp", "serverselectiondiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "serverselectiondiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@serverselectiondiagnostic[0]", "DiagnosticState", value); + cwmp_set_end_session(END_SESSION_SERVERSELECTION_DIAGNOSTIC); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsServerSelectionDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_varstate_string("cwmp", "@serverselectiondiagnostic[0]", "interface", value); + return 0; +} + +int set_IPDiagnosticsServerSelectionDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + SERVERSELECTION_STOP + curr_section = dmuci_walk_state_section("cwmp", "serverselectiondiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "serverselectiondiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@serverselectiondiagnostic[0]", "interface", value); + return 0; + } + return 0; +} + +int get_IPDiagnosticsServerSelectionDiagnostics_ProtocolVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = serverselection_get("ProtocolVersion", "Any"); + return 0; +} + +int set_IPDiagnosticsServerSelectionDiagnostics_ProtocolVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (strcmp(value, "IPv4") == 0 || strcmp(value, "IPv6") == 0) { + SERVERSELECTION_STOP + curr_section = dmuci_walk_state_section("cwmp", "serverselectiondiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "serverselectiondiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@serverselectiondiagnostic[0]", "ProtocolVersion", value); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsServerSelectionDiagnostics_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = serverselection_get("Protocol", "ICMP"); + return 0; +} + +int set_IPDiagnosticsServerSelectionDiagnostics_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (strcmp(value, "ICMP") == 0 || strcmp(value, "UDP Echo") == 0) { + SERVERSELECTION_STOP + curr_section = dmuci_walk_state_section("cwmp", "serverselectiondiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "serverselectiondiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@serverselectiondiagnostic[0]", "Protocol", value); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsServerSelectionDiagnostics_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_varstate_string("cwmp", "@serverselectiondiagnostic[0]", "Port", value); + return 0; +} + +int set_IPDiagnosticsServerSelectionDiagnostics_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (atoi(value) >= 1 && atoi(value) <= 65535) { + SERVERSELECTION_STOP; + curr_section = dmuci_walk_state_section("cwmp", "serverselectiondiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "serverselectiondiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@serverselectiondiagnostic[0]", "port", value); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsServerSelectionDiagnostics_HostList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_varstate_string("cwmp", "@serverselectiondiagnostic[0]", "HostList", value); + return 0; +} + +int set_IPDiagnosticsServerSelectionDiagnostics_HostList(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + SERVERSELECTION_STOP + curr_section = dmuci_walk_state_section("cwmp", "serverselectiondiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "serverselectiondiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@serverselectiondiagnostic[0]", "HostList", value); + return 0; + } + return 0; +} + +int get_IPDiagnosticsServerSelectionDiagnostics_NumberOfRepetitions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = serverselection_get("NumberOfRepetitions", "3"); + return 0; +} + +int set_IPDiagnosticsServerSelectionDiagnostics_NumberOfRepetitions(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (atoi(value) >= 1) { + SERVERSELECTION_STOP + curr_section = dmuci_walk_state_section("cwmp", "serverselectiondiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "serverselectiondiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@serverselectiondiagnostic[0]", "NumberOfRepetitions", value); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsServerSelectionDiagnostics_Timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = serverselection_get("Timeout", "1000"); + return 0; +} + +int set_IPDiagnosticsServerSelectionDiagnostics_Timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *tmp; + struct uci_section *curr_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (atoi(value) >= 1) { + SERVERSELECTION_STOP + curr_section = dmuci_walk_state_section("cwmp", "serverselectiondiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + if(!curr_section) + { + dmuci_add_state_section("cwmp", "serverselectiondiagnostic", &curr_section, &tmp); + } + dmuci_set_varstate_value("cwmp", "@serverselectiondiagnostic[0]", "Timeout", value); + } + return 0; + } + return 0; +} + +int get_IPDiagnosticsServerSelectionDiagnostics_FastestHost(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = serverselection_get("FastestHost", ""); + return 0; +} + +int get_IPDiagnosticsServerSelectionDiagnostics_MinimumResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = serverselection_get("MinimumResponseTime", "0"); + return 0; +} + +int get_IPDiagnosticsServerSelectionDiagnostics_AverageResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = serverselection_get("AverageResponseTime", "0"); + return 0; +} + +int get_IPDiagnosticsServerSelectionDiagnostics_MaximumResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = serverselection_get("MaximumResponseTime", "0"); + return 0; +} + +/* + * *** Device.IP. *** + */ int get_ip_interface_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { @@ -349,8 +2530,15 @@ int get_ip_interface_enable(char *refparam, struct dmctx *ctx, void *data, char int set_ip_interface_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *lan_name = section_name(((struct ip_args *)data)->ip_sec); - set_interface_enable_ubus(lan_name, refparam, ctx, action, value); + char *lan_name; + switch (action) { + case VALUECHECK: + break; + case VALUESET: + lan_name = section_name(((struct ip_args *)data)->ip_sec); + set_interface_enable_ubus(lan_name, refparam, ctx, action, value); + break; + } return 0; } @@ -505,7 +2693,6 @@ int get_ip_int_lower_layer(char *refparam, struct dmctx *ctx, void *data, char * if (mac != NULL) { /* Expect the Ethernet.Link to be the lowerlayer*/ adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cLink%c", dmroot, dm_delim, dm_delim, dm_delim), mac, value); - CWMP_LOG(ERROR, "get_ip_int_lower_layer, lowerlay:%s", *value) return 0; } get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); @@ -1067,3 +3254,48 @@ int browseIfaceIPv6Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_dat end: return 0; } + +int browseIPDiagnosticsTraceRouteRouteHopsInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct uci_section *s = NULL; + char *instance, *idx_last = NULL; + int id = 0; + + uci_foreach_sections_state("cwmp", "RouteHops", s) + { + instance = handle_update_instance(2, dmctx, &idx_last, update_instance_alias, 3, (void *)s, "routehop_instance", "routehop_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, instance) == DM_STOP) + break; + } + return 0; +} + +int browseIPDiagnosticsDownloadDiagnosticsPerConnectionResultInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct uci_section *s = NULL; + char *instance, *idx_last = NULL; + int id = 0; + + uci_foreach_sections_state("cwmp", "DownloadPerConnection", s) + { + instance = handle_update_instance(2, dmctx, &idx_last, update_instance_alias, 3, (void *)s, "perconnection_instance", "perconnection_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, instance) == DM_STOP) + break; + } + return 0; +} + +int browseIPDiagnosticsUploadDiagnosticsPerConnectionResultInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct uci_section *s = NULL; + char *instance, *idx_last = NULL; + int id = 0; + + uci_foreach_sections_state("cwmp", "UploadPerConnection", s) + { + instance = handle_update_instance(2, dmctx, &idx_last, update_instance_alias, 3, (void *)s, "perconnection_instance", "perconnection_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, instance) == DM_STOP) + break; + } + return 0; +} diff --git a/dm/dmtree/tr181/ip.h b/dm/dmtree/tr181/ip.h index 8ae661b..7156e5f 100644 --- a/dm/dmtree/tr181/ip.h +++ b/dm/dmtree/tr181/ip.h @@ -1,17 +1,18 @@ /* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * Copyright (C) 2016 Inteno Broadband Technology AB - * Author: Anis Ellouze - * - */ +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* Copyright (C) 2019 iopsys Software Solutions AB +* Author: Anis Ellouze +* Author: Amin Ben Ramdhane +* +*/ + #ifndef __IP_H #define __IP_H -extern struct ip_ping_diagnostic ipping_diagnostic; struct ip_args { struct uci_section *ip_sec; @@ -25,13 +26,32 @@ extern DMLEAF tIPv4Params[]; extern DMLEAF tIPv6Params[]; extern DMLEAF tIPInterfaceStatsParams[]; extern DMLEAF tIPintParams[]; -extern DMLEAF tIpPingDiagParams[]; extern DMOBJ tDiagnosticObj[]; +extern DMLEAF tIPDiagnosticsParams[]; +extern DMLEAF tIpPingDiagParams[]; +extern DMOBJ tIPDiagnosticsTraceRouteObj[]; +extern DMLEAF tIPDiagnosticsTraceRouteParams[]; +extern DMLEAF tIPDiagnosticsTraceRouteRouteHopsParams[]; +extern DMOBJ tIPDiagnosticsDownloadDiagnosticsObj[]; +extern DMLEAF tIPDiagnosticsDownloadDiagnosticsParams[]; +extern DMLEAF tIPDiagnosticsDownloadDiagnosticsPerConnectionResultParams[]; +extern DMOBJ tIPDiagnosticsUploadDiagnosticsObj[]; +extern DMLEAF tIPDiagnosticsUploadDiagnosticsParams[]; +extern DMLEAF tIPDiagnosticsUploadDiagnosticsPerConnectionResultParams[]; +extern DMLEAF tIPDiagnosticsUDPEchoConfigParams[]; +extern DMLEAF tIPDiagnosticsUDPEchoDiagnosticsParams[]; +extern DMLEAF tIPDiagnosticsServerSelectionDiagnosticsParams[]; + unsigned char get_ipv4_finform(char *refparam, struct dmctx *dmctx, void *data, char *instance); unsigned char get_ipv6_finform(char *refparam, struct dmctx *dmctx, void *data, char *instance); +int get_linker_ip_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); + int browseIPIfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); int browseIfaceIPv4Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); int browseIfaceIPv6Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseIPDiagnosticsTraceRouteRouteHopsInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseIPDiagnosticsDownloadDiagnosticsPerConnectionResultInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseIPDiagnosticsUploadDiagnosticsPerConnectionResultInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); int add_ip_interface(char *refparam, struct dmctx *ctx, void *data, char **instancepara); int delete_ip_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); @@ -40,6 +60,8 @@ int delete_ipv4(char *refparam, struct dmctx *ctx, void *data, char *instance, u int add_ipv6(char *refparam, struct dmctx *ctx, void *data, char **instancepara); int delete_ipv6(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); +int get_diag_enable_true(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_diag_enable_false(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); int get_ip_interface_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); int get_ip_interface_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); int get_ip_interface_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); @@ -56,15 +78,20 @@ int get_ipv6_address(char *refparam, struct dmctx *ctx, void *data, char *instan int get_ipv6_addressing_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); int get_ip_ping_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); int get_ip_ping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ip_ping_protocolversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); int get_ip_ping_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); int get_ip_ping_repetition_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); int get_ip_ping_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); int get_ip_ping_block_size(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ip_ping_DSCP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); int get_ip_ping_success_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); int get_ip_ping_failure_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); int get_ip_ping_average_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); int get_ip_ping_min_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); int get_ip_ping_max_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ip_ping_AverageResponseTimeDetailed(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ip_ping_MinimumResponseTimeDetailed(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ip_ping_MaximumResponseTimeDetailed(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); int get_ip_interface_statistics_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); int get_ip_interface_statistics_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); int get_ip_interface_statistics_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); @@ -86,12 +113,183 @@ int set_ipv6_address(char *refparam, struct dmctx *ctx, void *data, char *instan int set_ipv6_addressing_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); int set_ip_ping_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); int set_ip_ping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ip_ping_protocolversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); int set_ip_ping_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); int set_ip_ping_repetition_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); int set_ip_ping_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); int set_ip_ping_block_size(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ip_ping_DSCP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); int set_ipv6_addressing_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); int set_ip_interface_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_linker_ip_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); +int get_IPDiagnosticsTraceRoute_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsTraceRoute_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsTraceRoute_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsTraceRoute_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsTraceRoute_ProtocolVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsTraceRoute_ProtocolVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsTraceRoute_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsTraceRoute_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsTraceRoute_NumberOfTries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsTraceRoute_NumberOfTries(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsTraceRoute_Timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsTraceRoute_Timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsTraceRoute_DataBlockSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsTraceRoute_DataBlockSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsTraceRoute_DSCP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsTraceRoute_DSCP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsTraceRoute_MaxHopCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsTraceRoute_MaxHopCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsTraceRoute_ResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsTraceRoute_RouteHopsNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsTraceRouteRouteHops_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsTraceRouteRouteHops_HostAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsTraceRouteRouteHops_ErrorCode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsTraceRouteRouteHops_RTTimes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int get_IPDiagnosticsDownloadDiagnostics_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsDownloadDiagnostics_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsDownloadDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsDownloadDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsDownloadDiagnostics_DownloadURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsDownloadDiagnostics_DownloadURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsDownloadDiagnostics_DownloadTransports(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnostics_DownloadDiagnosticMaxConnections(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnostics_DSCP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsDownloadDiagnostics_DSCP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsDownloadDiagnostics_EthernetPriority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsDownloadDiagnostics_EthernetPriority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsDownloadDiagnostics_ProtocolVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsDownloadDiagnostics_ProtocolVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsDownloadDiagnostics_NumberOfConnections(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsDownloadDiagnostics_NumberOfConnections(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsDownloadDiagnostics_ROMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnostics_BOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnostics_EOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnostics_TestBytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnostics_TotalBytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnostics_TotalBytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnostics_TestBytesReceivedUnderFullLoading(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnostics_TotalBytesReceivedUnderFullLoading(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnostics_TotalBytesSentUnderFullLoading(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnostics_PeriodOfFullLoading(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnostics_TCPOpenRequestTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnostics_TCPOpenResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnostics_PerConnectionResultNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnostics_EnablePerConnectionResults(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsDownloadDiagnostics_EnablePerConnectionResults(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_ROMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_BOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_EOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TestBytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TotalBytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TotalBytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TCPOpenRequestTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TCPOpenResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int get_IPDiagnosticsUploadDiagnostics_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUploadDiagnostics_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUploadDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUploadDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUploadDiagnostics_UploadURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUploadDiagnostics_UploadURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUploadDiagnostics_UploadTransports(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUploadDiagnostics_DSCP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUploadDiagnostics_DSCP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUploadDiagnostics_EthernetPriority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUploadDiagnostics_EthernetPriority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUploadDiagnostics_TestFileLength(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUploadDiagnostics_TestFileLength(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUploadDiagnostics_ProtocolVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUploadDiagnostics_ProtocolVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUploadDiagnostics_NumberOfConnections(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUploadDiagnostics_NumberOfConnections(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUploadDiagnostics_ROMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUploadDiagnostics_BOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUploadDiagnostics_EOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUploadDiagnostics_TestBytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUploadDiagnostics_TotalBytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUploadDiagnostics_TotalBytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUploadDiagnostics_TestBytesSentUnderFullLoading(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUploadDiagnostics_TotalBytesReceivedUnderFullLoading(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUploadDiagnostics_TotalBytesSentUnderFullLoading(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUploadDiagnostics_PeriodOfFullLoading(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUploadDiagnostics_TCPOpenRequestTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUploadDiagnostics_TCPOpenResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUploadDiagnostics_PerConnectionResultNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUploadDiagnostics_EnablePerConnectionResults(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUploadDiagnostics_EnablePerConnectionResults(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_ROMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_BOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_EOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_TestBytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_TotalBytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_TotalBytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_TCPOpenRequestTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUploadDiagnosticsPerConnectionResult_TCPOpenResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int get_IPDiagnosticsUDPEchoConfig_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUDPEchoConfig_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUDPEchoConfig_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUDPEchoConfig_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUDPEchoConfig_SourceIPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUDPEchoConfig_SourceIPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUDPEchoConfig_UDPPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUDPEchoConfig_UDPPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUDPEchoConfig_EchoPlusEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUDPEchoConfig_EchoPlusEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUDPEchoConfig_EchoPlusSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUDPEchoConfig_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUDPEchoConfig_PacketsResponded(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUDPEchoConfig_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUDPEchoConfig_BytesResponded(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUDPEchoConfig_TimeFirstPacketReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUDPEchoConfig_TimeLastPacketReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int get_IPDiagnosticsUDPEchoDiagnostics_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUDPEchoDiagnostics_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUDPEchoDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUDPEchoDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUDPEchoDiagnostics_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUDPEchoDiagnostics_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUDPEchoDiagnostics_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUDPEchoDiagnostics_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUDPEchoDiagnostics_NumberOfRepetitions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUDPEchoDiagnostics_NumberOfRepetitions(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUDPEchoDiagnostics_Timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUDPEchoDiagnostics_Timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUDPEchoDiagnostics_DataBlockSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUDPEchoDiagnostics_DataBlockSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUDPEchoDiagnostics_DSCP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUDPEchoDiagnostics_DSCP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUDPEchoDiagnostics_InterTransmissionTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUDPEchoDiagnostics_InterTransmissionTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUDPEchoDiagnostics_ProtocolVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsUDPEchoDiagnostics_ProtocolVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsUDPEchoDiagnostics_SuccessCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUDPEchoDiagnostics_FailureCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUDPEchoDiagnostics_AverageResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUDPEchoDiagnostics_MinimumResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsUDPEchoDiagnostics_MaximumResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int get_IPDiagnosticsServerSelectionDiagnostics_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsServerSelectionDiagnostics_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsServerSelectionDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsServerSelectionDiagnostics_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsServerSelectionDiagnostics_ProtocolVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsServerSelectionDiagnostics_ProtocolVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsServerSelectionDiagnostics_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsServerSelectionDiagnostics_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsServerSelectionDiagnostics_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsServerSelectionDiagnostics_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsServerSelectionDiagnostics_HostList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsServerSelectionDiagnostics_HostList(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsServerSelectionDiagnostics_NumberOfRepetitions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsServerSelectionDiagnostics_NumberOfRepetitions(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsServerSelectionDiagnostics_Timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_IPDiagnosticsServerSelectionDiagnostics_Timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_IPDiagnosticsServerSelectionDiagnostics_FastestHost(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsServerSelectionDiagnostics_MinimumResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsServerSelectionDiagnostics_AverageResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_IPDiagnosticsServerSelectionDiagnostics_MaximumResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); #endif diff --git a/dm/dmuci.h b/dm/dmuci.h index 3cc795f..93ce1dd 100644 --- a/dm/dmuci.h +++ b/dm/dmuci.h @@ -106,6 +106,11 @@ struct package_change { section != NULL; \ section = dmuci_walk_section(package, stype, arg, NULL, CMP_FILTER_FUNC, func, section, GET_NEXT_SECTION)) +#define uci_foreach_sections_state(package, stype, section) \ + for (section = dmuci_walk_state_section(package, stype, NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); \ + section != NULL; \ + section = dmuci_walk_state_section(package, stype, NULL, NULL, CMP_SECTION, NULL, section, GET_NEXT_SECTION)) + #define section_name(s) (s)->e.name static inline void uci_list_insert(struct uci_list *list, struct uci_list *ptr) diff --git a/event.c b/event.c index 8df47e8..04392a9 100644 --- a/event.c +++ b/event.c @@ -347,7 +347,7 @@ void cwmp_add_notification(void) fp = fopen(DM_ENABLED_NOTIFY, "r"); if (fp == NULL) - return 0; + return; while (fgets(buf, 512, fp) != NULL) { dm_ctx_init_sub(&dmctx, DM_CWMP, cwmp_main.conf.amd_version, cwmp_main.conf.instance_mode); diff --git a/inc/diagnostic.h b/inc/diagnostic.h index a829281..61475a3 100644 --- a/inc/diagnostic.h +++ b/inc/diagnostic.h @@ -4,9 +4,11 @@ * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * - * Copyright (C) 2012-2014 PIVA SOFTWARE (www.pivasoftware.com) + * Copyright (C) 2019 iopsys Software Solutions AB * Author: Imen Bhiri + * Author: Amin Ben Ramdhane */ + #ifndef __DIAGNOSTIC__H #define __DIAGNOSTIC__H @@ -41,7 +43,6 @@ struct upload_diagnostic_stats char romtime[default_date_size]; char bomtime[default_date_size]; char eomtime[default_date_size]; - int test_bytes_received; unsigned long total_bytes_sent; char tcpopenrequesttime[default_date_size]; char tcpopenresponsetime[default_date_size]; @@ -68,5 +69,8 @@ enum diagnostic_type { int cwmp_ip_ping_diagnostic(); int cwmp_start_diagnostic(int diagnostic_type); int cwmp_nslookup_diagnostic(); +int cwmp_traceroute_diagnostic(); +int cwmp_udp_echo_diagnostic(); +int cwmp_serverselection_diagnostic(); #endif diff --git a/init/icwmp_udpechoserverd b/init/icwmp_udpechoserverd new file mode 100644 index 0000000..d2fe587 --- /dev/null +++ b/init/icwmp_udpechoserverd @@ -0,0 +1,39 @@ +#!/bin/sh /etc/rc.common +#UDP Echo Server software +# Copyright (C) 2019 Iopsys Broadband Technology AB +#Author: Amin Ben Ramdhane + +START=99 +STOP=10 + +USE_PROCD=1 +PROG="/usr/sbin/icwmp_udpechoserverd" + +start_service() { + local enable_udpechoserver=`uci -q get cwmp_udpechoserver.udpechoserver.enable` + local port_udpechoserver=`uci -q get cwmp_udpechoserver.udpechoserver.server_port` + if [ "$port_udpechoserver" != "0" ]; then + if [ "$enable_udpechoserver" = "1" ]; then + iptables -I zone_wan_input -p udp --dport $port_udpechoserver -j ACCEPT -m comment --comment "Open UDPechoserver port" + procd_open_instance + procd_set_param command "$PROG" + procd_set_param respawn "3" "7" "0" + procd_close_instance + else + iptables -I zone_wan_input -p udp --dport $port_udpechoserver -j REJECT -m comment --comment "Close UDPechoserver port" + fi + fi +} + +boot() { + start +} + +reload_service() { + stop + start +} + +service_triggers() { + procd_add_reload_trigger cwmp_udpechoserver +} \ No newline at end of file diff --git a/scripts/functions/download_launch b/scripts/functions/download_launch index 5565a78..c6a8856 100755 --- a/scripts/functions/download_launch +++ b/scripts/functions/download_launch @@ -1,22 +1,44 @@ #!/bin/sh -# Copyright (C) 2015 PIVA Software +# Copyright (C) 2019 PIVA Software # Author: IMEN Bhiri +# Author: AMIN Ben Ramdhane UCI_CONFIG_DIR="/etc/config/" -UCI_GET_VARSTATE="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state get -q " -UCI_SET_VARSTATE="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state set -q " +UCI_GET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state get" +UCI_SET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state set" +UCI_ADD_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state add" +UCI_DELETE_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state delete" CAPTURE_FILE="/tmp/download_dump" DOWNLOAD_DIAGNOSTIC_FILE="/tmp/icwmp_download_diagnostic" +download_get() { + local val=`$UCI_GET_VARSTATE $1` + echo ${val:-$2} +} + download_launch() { - url=$1 - interface=$2 + local tx_bytes_before rx_bytes_before time1 tx_bytes_after rx_bytes_after time2 res rh ba stc periodtime + local url=$1 + local interface=$2 + [ "`$UCI_GET_VARSTATE cwmp.@downloaddiagnostic[0].DiagnosticState`" != "Requested" ] && return + [ "$url" = "" ] && { $UCI_SET_VARSTATE cwmp.@downloaddiagnostic[0].DiagnosticState=Error_InitConnectionFailed; return; } + local proto=`download_get cwmp.@downloaddiagnostic[0].ProtocolVersion Any` tcpdump -i $interface tcp -w ${CAPTURE_FILE} > /dev/null 2>&1 & PID=$! sleep 1 if [ ${url:0:7} = http:// -o ${url:0:6} = ftp:// ]; then - res=$(wget -O ${DOWNLOAD_DIAGNOSTIC_FILE} $url 2>&1) + tx_bytes_before=`ubus call network.device status "{'name':'$interface'}" | sed -n '/statistics/,$ p' | grep "tx_bytes" | awk -F ": " '{print $2}' | sed 's/.$//'` + rx_bytes_before=`ubus call network.device status "{'name':'$interface'}" | sed -n '/statistics/,$ p' | grep "rx_bytes" | awk -F ": " '{print $2}' | sed 's/.$//'` + time1=`date +%s` + [ "$proto" = "Any" ] && res=$(wget -O ${DOWNLOAD_DIAGNOSTIC_FILE} $url 2>&1) + [ "$proto" = "IPv4" ] && res=$(wget -4 -O ${DOWNLOAD_DIAGNOSTIC_FILE} $url 2>&1) + [ "$proto" = "IPv6" ] && res=$(wget -6 -O ${DOWNLOAD_DIAGNOSTIC_FILE} $url 2>&1) + time2=`date +%s` + tx_bytes_after=`ubus call network.device status "{'name':'$interface'}" | sed -n '/statistics/,$ p' | grep "tx_bytes" | awk -F ": " '{print $2}' | sed 's/.$//'` + rx_bytes_after=`ubus call network.device status "{'name':'$interface'}" | sed -n '/statistics/,$ p' | grep "rx_bytes" | awk -F ": " '{print $2}' | sed 's/.$//'` + rh=`echo "$res" | grep "resolve host"` + [ -n "$ba" ] && { $UCI_SET_VARSTATE cwmp.@downloaddiagnostic[0].DiagnosticState=Error_CannotResolveHostName; kill $PID 2> /dev/null; return; } ba=`echo "$res" | grep "bad address"` [ -n "$ba" ] && { $UCI_SET_VARSTATE cwmp.@downloaddiagnostic[0].DiagnosticState=Error_InitConnectionFailed; kill $PID 2> /dev/null; return; } stc=`echo "$res" | grep "404 Not Found"` @@ -24,7 +46,21 @@ download_launch() { stc=`echo "$res" | grep "100%"` [ -z "$stc" ] && { $UCI_SET_VARSTATE cwmp.@downloaddiagnostic[0].DiagnosticState=Error_TransferFailed; kill $PID 2> /dev/null; return; } fi + tx_bytes=$((tx_bytes_after-tx_bytes_before)) + rx_bytes=$((rx_bytes_after-rx_bytes_before)) + periodtime=$(($((time2-time1))*1000000)) $UCI_SET_VARSTATE cwmp.@downloaddiagnostic[0].DiagnosticState=Completed + $UCI_SET_VARSTATE cwmp.@downloaddiagnostic[0].TotalBytesReceived=$rx_bytes + $UCI_SET_VARSTATE cwmp.@downloaddiagnostic[0].TotalBytesSent=$tx_bytes + $UCI_SET_VARSTATE cwmp.@downloaddiagnostic[0].PeriodOfFullLoading=$periodtime + local perconnection=`$UCI_GET_VARSTATE cwmp.@downloaddiagnostic[0].EnablePerConnection` + if ([ "$perconnection" == "true" ] || [ "$perconnection" == "1" ]); then + $UCI_ADD_VARSTATE cwmp DownloadPerConnection + $UCI_SET_VARSTATE cwmp.@DownloadPerConnection[0].TotalBytesReceived=$rx_bytes + $UCI_SET_VARSTATE cwmp.@DownloadPerConnection[0].TotalBytesSent=$tx_bytes + else + $UCI_DELETE_VARSTATE cwmp.@DownloadPerConnection[0] + fi rm ${DOWNLOAD_DIAGNOSTIC_FILE} 2>/dev/null sleep 1 local pids=`ps | grep $PID` @@ -32,12 +68,13 @@ download_launch() { } download_stop_diagnostic() { + $UCI_DELETE_VARSTATE cwmp.@DownloadPerConnection[0] local pids=`ps | grep download_launch.*run | grep -v grep | awk '{print $1}'` if [ -n "$pids" ]; then kill -9 $pids &>/dev/null $UCI_SET_VARSTATE cwmp.@downloaddiagnostic[0].DiagnosticState=None fi - local pids=`ps | grep upload_launch.*run | grep -v grep | awk '{print $1}'` + local pids=`ps | grep download_launch.*run | grep -v grep | awk '{print $1}'` if [ -n "$pids" ]; then kids=$(grep -l "PPid.*$pids" /proc/*/task/*/status | grep -o "[0-9]*") for kid in $kids; do diff --git a/scripts/functions/ipping_launch b/scripts/functions/ipping_launch index ed99b4d..8107900 100755 --- a/scripts/functions/ipping_launch +++ b/scripts/functions/ipping_launch @@ -1,42 +1,46 @@ #!/bin/sh -# Copyright (C) 2015 PIVA Software +# Copyright (C) 2019 PIVA Software # Author: MOHAMED Kallel +# Author: AMIN Ben Ramdhane UCI_CONFIG_DIR="/etc/config/" -UCI_GET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state get " -UCI_SET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state set " +UCI_GET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state get" +UCI_SET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state set" ipping_get() { local val=`$UCI_GET_VARSTATE $1` echo ${val:-$2} } -ipping_set() { - $UCI_SET_VARSTATE $1=$2 - return 0 -} - ipping_launch() { - local i res ba stc times sc1 success_count failure_count min_time avg_time max_time avg_time_sum min max + local i res ba stc times sc1 success_count failure_count min_time avg_time max_time avg_time_sum min max micros avg_time_det min_time_det max_time_det avg_time_sum_det min_det max_det [ "`$UCI_GET_VARSTATE cwmp.@ippingdiagnostic[0].DiagnosticState`" != "Requested" ] && return local host=`ipping_get cwmp.@ippingdiagnostic[0].Host` local cnt=`ipping_get cwmp.@ippingdiagnostic[0].NumberOfRepetitions 3` local dsize=`ipping_get cwmp.@ippingdiagnostic[0].DataBlockSize 64` local timeout=`ipping_get cwmp.@ippingdiagnostic[0].Timeout 1000` local dscp=`ipping_get cwmp.@ippingdiagnostic[0].DSCP 0` + local proto=`ipping_get cwmp.@ippingdiagnostic[0].ProtocolVersion Any` local tos=$((dscp<<2)) [ "$host" = "" ] && return - #timeout=$((timeout/1000)) - [ "$timeout" = "0" ] && timeout="1000" + timeout=$((timeout/1000)) + [ "$timeout" = "0" ] && timeout="1" + micros=1000 success_count=0 avg_time_sum=0 + avg_time_sum_det=0 min=9999999 + min_det=999999999 max=0 + max_det=0 i=0 + while [ $i -lt $cnt ]; do let i++ - res=$(fping -o -c 1 -b $dsize -t $timeout -O $tos $host 2>&1) + [ "$proto" = "Any" ] && res=$(fping -o -c 1 -b $dsize -t $timeout -O $tos $host 2>&1) + [ "$proto" = "IPv4" ] && res=$(fping -4 -o -c 1 -b $dsize -t $timeout -O $tos $host 2>&1) + [ "$proto" = "IPv6" ] && res=$(fping -6 -o -c 1 -b $dsize -t $timeout -O $tos $host 2>&1) ba=`echo "$res" | grep "not known"` [ -n "$ba" ] && { $UCI_SET_VARSTATE cwmp.@ippingdiagnostic[0].DiagnosticState=Error_CannotResolveHostName; return; } stc=`echo "$res" | grep "loss"` @@ -53,24 +57,36 @@ ipping_launch() { min_time=${min_time:-0} avg_time=${avg_time:-0} max_time=${max_time:-0} + min_time_det=$(echo $min_time $micros | awk '{printf "%3.0f\n",$1*$2}') + avg_time_det=$(echo $avg_time $micros | awk '{printf "%3.0f\n",$1*$2}') + max_time_det=$(echo $max_time $micros | awk '{printf "%3.0f\n",$1*$2}') min_time=$(awk "BEGIN{print $min_time * 1000}") avg_time=$(awk "BEGIN{print $avg_time * 1000}") max_time=$(awk "BEGIN{print $max_time * 1000}") [ $min_time -lt $min ] && min=$min_time [ $max_time -gt $max ] && max=$max_time avg_time_sum=$((avg_time_sum+avg_time)) + [ $min_time_det -lt $min_det ] && min_det=$min_time_det + [ $max_time_det -gt $max_det ] && max_det=$max_time_det + avg_time_sum_det=$((avg_time_sum_det+avg_time_det)) done failure_count=$((cnt-success_count)) [ $success_count -gt 0 ] && avg_time=$((avg_time_sum/success_count)) || avg_time=0 + [ $success_count -gt 0 ] && avg_time_det=$((avg_time_sum_det/success_count)) || avg_time_det=0 avg_time=$(awk "BEGIN{print int($avg_time / 1000)}") min_time=$(awk "BEGIN{print int($min / 1000)}") max_time=$(awk "BEGIN{print int($max / 1000)}") + min_time_det=$min_det + max_time_det=$max_det $UCI_SET_VARSTATE cwmp.@ippingdiagnostic[0].DiagnosticState=Complete $UCI_SET_VARSTATE cwmp.@ippingdiagnostic[0].SuccessCount=$success_count $UCI_SET_VARSTATE cwmp.@ippingdiagnostic[0].FailureCount=$failure_count $UCI_SET_VARSTATE cwmp.@ippingdiagnostic[0].AverageResponseTime=$avg_time $UCI_SET_VARSTATE cwmp.@ippingdiagnostic[0].MinimumResponseTime=$min_time $UCI_SET_VARSTATE cwmp.@ippingdiagnostic[0].MaximumResponseTime=$max_time + $UCI_SET_VARSTATE cwmp.@ippingdiagnostic[0].AverageResponseTimeDetailed=$avg_time_det + $UCI_SET_VARSTATE cwmp.@ippingdiagnostic[0].MinimumResponseTimeDetailed=$min_time_det + $UCI_SET_VARSTATE cwmp.@ippingdiagnostic[0].MaximumResponseTimeDetailed=$max_time_det event_dignostic } @@ -84,6 +100,7 @@ event_dignostic() { let i++ done } + ipping_stop_diagnostic() { local pids=`ps | grep ipping_launch | grep -v grep | awk '{print $1}'` if [ -n "$pids" ]; then diff --git a/scripts/functions/nslookup_launch b/scripts/functions/nslookup_launch index 72b85d1..343228f 100644 --- a/scripts/functions/nslookup_launch +++ b/scripts/functions/nslookup_launch @@ -4,8 +4,8 @@ UCI_CONFIG_DIR="/etc/config/" -UCI_GET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state get " -UCI_SET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state set " +UCI_GET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state get" +UCI_SET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state set" LOG_FILE="/tmp/nslookup.log" nslookup_get() { @@ -13,11 +13,6 @@ nslookup_get() { echo ${val:-$2} } -nslookup_set() { - $UCI_SET_VARSTATE $1=$2 - return 0 -} - nslookup_launch() { local i time1 time2 timeresponse [ "`$UCI_GET_VARSTATE cwmp.@nslookupdiagnostic[0].DiagnosticState`" != "Requested" ] && return @@ -69,4 +64,4 @@ elif [ "$1" == "stop" ]; then nslookup_stop_diagnostic else return -fi \ No newline at end of file +fi diff --git a/scripts/functions/serverselection_launch b/scripts/functions/serverselection_launch new file mode 100644 index 0000000..2e6e906 --- /dev/null +++ b/scripts/functions/serverselection_launch @@ -0,0 +1,138 @@ +#!/bin/sh +# Copyright (C) 2019 PIVA Software +# Author: AMIN Ben Ramdhane + + +UCI_CONFIG_DIR="/etc/config/" +UCI_GET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state get" +UCI_SET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state set" + +serverselection_get() { + local val=`$UCI_GET_VARSTATE $1` + echo ${val:-$2} +} + +serverselection_launch() { + local i res ba stc times sc1 success_count min_time avg_time max_time avg_time_sum min max fasthost micros + [ "`$UCI_GET_VARSTATE cwmp.@serverselectiondiagnostic[0].DiagnosticState`" != "Requested" ] && return + local hostlist=`serverselection_get cwmp.@serverselectiondiagnostic[0].HostList` + local cnt=`serverselection_get cwmp.@serverselectiondiagnostic[0].NumberOfRepetitions 3` + local timeout=`serverselection_get cwmp.@serverselectiondiagnostic[0].Timeout 1000` + local port=`serverselection_get cwmp.@serverselectiondiagnostic[0].port` + local protoversion=`serverselection_get cwmp.@serverselectiondiagnostic[0].ProtocolVersion Any` + local proto=`serverselection_get cwmp.@serverselectiondiagnostic[0].Protocol ICMP` + [ "$hostlist" = "" ] && return + timeout=$((timeout/1000)) + [ "$timeout" = "0" ] && timeout="1" + micros=1000 + success_count=0 + avg_time_sum=0 + avg_time_host=9999999 + min=9999999 + max=0 + i=0 + + for host in $(echo $hostlist | tr "," "\n"); do + if [ "$proto" == "ICMP" ]; then + while [ $i -lt $cnt ]; do + let i++ + [ "$protoversion" = "Any" ] && res=$(ping -q -c 1 -W $timeout $host 2>&1) + [ "$protoversion" = "IPv4" ] && res=$(ping -q -4 -c 1 -W $timeout $host 2>&1) + [ "$protoversion" = "IPv6" ] && res=$(ping -q -6 -c 1 -W $timeout $host 2>&1) + ba=`echo "$res" | grep "bad address"` + [ -n "$ba" ] && { $UCI_SET_VARSTATE cwmp.@serverselectiondiagnostic[0].DiagnosticState=Error_CannotResolveHostName; break; } + ba=`echo "$res" | grep "unknown host"` + [ -n "$ba" ] && { $UCI_SET_VARSTATE cwmp.@serverselectiondiagnostic[0].DiagnosticState=Error_CannotResolveHostName; break; } + stc=`echo "$res" | grep "received"` + [ -z "$stc" ] && { $UCI_SET_VARSTATE cwmp.@serverselectiondiagnostic[0].DiagnosticState=Error_Other; break; } + times=`echo "$res" | grep "min/avg/max"` + [ -z "$times" ] && break + sc1=`echo $stc | awk '{print $4}'` + sc1=${sc1:-0} + success_count=$((success_count+sc1)) + times=`echo $times | awk -F'=' '{ print $2 }'` + min_time=`echo $times | awk -F'[=/ ]' '{ print $1 }'` + avg_time=`echo $times | awk -F'[=/ ]' '{ print $2 }'` + max_time=`echo $times | awk -F'[=/ ]' '{ print $3 }'` + min_time=${min_time:-0} + avg_time=${avg_time:-0} + max_time=${max_time:-0} + min_time=$(echo $min_time $micros | awk '{printf "%3.0f\n",$1*$2}') + avg_time=$(echo $avg_time $micros | awk '{printf "%3.0f\n",$1*$2}') + max_time=$(echo $max_time $micros | awk '{printf "%3.0f\n",$1*$2}') + [ $min_time -lt $min ] && min=$min_time + [ $max_time -gt $max ] && max=$max_time + avg_time_sum=$((avg_time_sum+avg_time)) + done + else + while [ $i -lt $cnt ]; do + [ "$port" = "" ] && return + let i++ + [ "$protoversion" = "Any" ] && res=$(nping -c 1 --udp --dest-port $port --data-length 24 $host 2>&1) + [ "$protoversion" = "IPv4" ] && res=$(nping -4 -c 1 --udp --dest-port $port --data-length 24 $host 2>&1) + [ "$protoversion" = "IPv6" ] && res=$(nping -6 -c 1 --udp --dest-port $port --data-length 24 $host 2>&1) + ba=`echo "$res" | grep "RCVD"` + [ -z "$ba" ] && { $UCI_SET_VARSTATE cwmp.@ippingdiagnostic[0].DiagnosticState=Error_CannotResolveHostName; return; } + stc=`echo "$res" | grep "RCVD" | grep "unreachable"` + [ -n "$stc" ] && { $UCI_SET_VARSTATE cwmp.@ippingdiagnostic[0].DiagnosticState=Error_Other; return; } + times=`echo "$res" | grep "rtt"` + [ -z "$times" ] && continue + sc1=`echo "$res" | grep "Rcvd" | awk -F': ' '{print $3}' | awk -F'(' '{ print $1 }'` + sc1=${sc1:-0} + success_count=$((success_count+sc1)) + max_time=`echo $times | awk -F': ' '{ print $2 }' | awk -F'ms' '{ print $1 }'` + min_time=`echo $times | awk -F': ' '{ print $3 }' | awk -F'ms' '{ print $1 }'` + avg_time=`echo $times | awk -F': ' '{ print $4 }' | awk -F'ms' '{ print $1 }'` + min_time=${min_time:-0} + avg_time=${avg_time:-0} + max_time=${max_time:-0} + min_time=$(echo $min_time $micros | awk '{printf "%3.0f\n",$1*$2}') + avg_time=$(echo $avg_time $micros | awk '{printf "%3.0f\n",$1*$2}') + max_time=$(echo $max_time $micros | awk '{printf "%3.0f\n",$1*$2}') + [ $min_time -lt $min ] && min=$min_time + [ $max_time -gt $max ] && max=$max_time + avg_time_sum=$((avg_time_sum+avg_time)) + done + fi + [ $success_count -gt 0 ] && avg_time=$((avg_time_sum/success_count)) || avg_time=0 + [[ "$avg_time" != "0" && $avg_time -lt $avg_time_host ]] && avg_time_host=$avg_time && min_time=$min && max_time=$max && fasthost=$host + success_count=0 + avg_time_sum=0 + min=9999999 + max=0 + i=0 + done + $UCI_SET_VARSTATE cwmp.@serverselectiondiagnostic[0].DiagnosticState=Complete + $UCI_SET_VARSTATE cwmp.@serverselectiondiagnostic[0].FastestHost=$fasthost + $UCI_SET_VARSTATE cwmp.@serverselectiondiagnostic[0].AverageResponseTime=$avg_time_host + $UCI_SET_VARSTATE cwmp.@serverselectiondiagnostic[0].MinimumResponseTime=$min_time + $UCI_SET_VARSTATE cwmp.@serverselectiondiagnostic[0].MaximumResponseTime=$max_time + event_dignostic +} + +event_dignostic() { + local e=1 + local i=0 + while [ "$e" != 0 -a $i -lt 200 ]; do + ubus -t 1 call tr069 inform '{"event":"8 DIAGNOSTICS COMPLETE"}' &>/dev/null + e=$? + [ "$e" != "0" ] && sleep 1; + let i++ + done +} + +serverselection_stop_diagnostic() { + local pids=`ps | grep serverselection_launch | grep -v grep | awk '{print $1}'` + if [ -n "$pids" ]; then + kill -9 $pids &>/dev/null + $UCI_SET_VARSTATE cwmp.@serverselectiondiagnostic[0].DiagnosticState=None + fi +} + +if [ "$1" == "run" ] ; then + serverselection_launch +elif [ "$1" == "stop" ]; then + serverselection_stop_diagnostic +else + return +fi diff --git a/scripts/functions/traceroute_launch b/scripts/functions/traceroute_launch new file mode 100644 index 0000000..ae385f2 --- /dev/null +++ b/scripts/functions/traceroute_launch @@ -0,0 +1,88 @@ +#!/bin/sh +# Copyright (C) 2019 PIVA Software +# Author: AMIN Ben Ramdhane + +UCI_GET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state get" +UCI_SET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state set" +UCI_ADD_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state add" +UCI_DELETE_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state delete" +UCI_SHOW_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state show" + +traceroute_get() { + local val=`$UCI_GET_VARSTATE $1` + echo ${val:-$2} +} + +traceroute_launch() { + local i res host ip time=0 + [ "`$UCI_GET_VARSTATE cwmp.@traceroutediagnostic[0].DiagnosticState`" != "Requested" ] && return + local host=`traceroute_get cwmp.@traceroutediagnostic[0].Host` + local cnt=`traceroute_get cwmp.@traceroutediagnostic[0].NumberOfTries 3` + local dsize=`traceroute_get cwmp.@traceroutediagnostic[0].DataBlockSize 38` + local timeout=`traceroute_get cwmp.@traceroutediagnostic[0].Timeout 5000` + local maxhop=`traceroute_get cwmp.@traceroutediagnostic[0].MaxHops 30` + local proto=`traceroute_get cwmp.@traceroutediagnostic[0].ProtocolVersion Any` + [ "$host" = "" ] && return + timeout=$((timeout/1000)) + [ "$timeout" = "0" ] && timeout = "1" + i=-2 + delete_all_route_hops + rm -f /tmp/traceres + [ "$proto" = "Any" ] && traceroute -m $maxhop -w $timeout -q $cnt $host $dsize 2>&1 >/tmp/traceres + [ "$proto" = "IPv4" ] && traceroute -m $maxhop -w $timeout -q $cnt -4 $host $dsize 2>&1 >/tmp/traceres + [ "$proto" = "IPv6" ] && traceroute -m $maxhop -w $timeout -q $cnt -6 $host $dsize 2>&1 >/tmp/traceres + while read _ host ip time _; do + [ "$host" = "*" -a "$ip" = "*" ] && continue + let i++ + [ "$i" = "-1" ] && continue; + ip=${ip#(}; ip=${ip%)} + time=${time%.*} + $UCI_ADD_VARSTATE cwmp RouteHops + $UCI_SET_VARSTATE cwmp.@RouteHops[$i].host=$host + $UCI_SET_VARSTATE cwmp.@RouteHops[$i].ip=$ip + $UCI_SET_VARSTATE cwmp.@RouteHops[$i].time=$time + done < /tmp/traceres + rm -f /tmp/traceres + let i++ + + $UCI_SET_VARSTATE cwmp.@traceroutediagnostic[0].DiagnosticState=Complete + $UCI_SET_VARSTATE cwmp.@traceroutediagnostic[0].NumberOfHops=$i + $UCI_SET_VARSTATE cwmp.@traceroutediagnostic[0].ResponseTime=$($UCI_GET_VARSTATE cwmp.@RouteHops[-1].time) + event_diagnostic +} + +delete_all_route_hops() { + local j + for j in $($UCI_SHOW_VARSTATE cwmp | grep "cwmp.@RouteHops.*=RouteHops"); do + $UCI_DELETE_VARSTATE cwmp.@RouteHops[-1] + done +} + +event_diagnostic() { + local e=1 + local i=0 + while [ "$e" != 0 -a $i -lt 200 ]; do + ubus -t 1 call tr069 inform '{"event":"8 DIAGNOSTICS COMPLETE"}' + e=$? + [ "$e" != "0" ] && sleep 1; + let i++ + done +} + +traceroute_stop() { + delete_all_route_hops + local pids=`ps aux | grep traceroute_launch | grep -v grep | grep -v stop | awk '{print $2}'` + [ -z "$pids" ] && pids=`ps | grep traceroute_launch | grep -v grep | grep -v stop | awk '{print $2}'` + if [ -n "$pids" ]; then + kill -9 $pids 2>/dev/null + $UCI_SET_VARSTATE cwmp.@traceroutediagnostic[0].DiagnosticState=None + fi +} + +if [ "$1" == "run" ]; then + traceroute_launch 2>/dev/null +elif [ "$1" == "stop" ]; then + traceroute_stop 2>/dev/null +else + return +fi diff --git a/scripts/functions/udpecho_launch b/scripts/functions/udpecho_launch new file mode 100644 index 0000000..a0d2475 --- /dev/null +++ b/scripts/functions/udpecho_launch @@ -0,0 +1,103 @@ +#!/bin/sh +# Copyright (C) 2019 PIVA Software +# Author: AMIN Ben Ramdhane + + +UCI_CONFIG_DIR="/etc/config/" +UCI_GET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state get" +UCI_SET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state set" + +udpecho_get() { + local val=`$UCI_GET_VARSTATE $1` + echo ${val:-$2} +} + +udpecho_launch() { + local i res ba stc times sc1 success_count failure_count min_time avg_time max_time avg_time_sum min max micros + [ "`$UCI_GET_VARSTATE cwmp.@udpechodiagnostic[0].DiagnosticState`" != "Requested" ] && return + local host=`udpecho_get cwmp.@udpechodiagnostic[0].Host` + local port=`udpecho_get cwmp.@udpechodiagnostic[0].port` + local cnt=`udpecho_get cwmp.@udpechodiagnostic[0].NumberOfRepetitions 1` + local dsize=`udpecho_get cwmp.@udpechodiagnostic[0].DataBlockSize 24` + local dscp=`udpecho_get cwmp.@udpechodiagnostic[0].DSCP 0` + local proto=`udpecho_get cwmp.@udpechodiagnostic[0].ProtocolVersion Any` + local inter_time=`udpecho_get cwmp.@udpechodiagnostic[0].InterTransmissionTime 1000` + local tos=$((dscp<<2)) + inter_time=$((inter_time/1000)) + [ "$inter_time" = "0" ] && inter_time="1" + [ "$host" = "" ] && return + [ "$port" = "" ] && return + micros=1000 + success_count=0 + avg_time_sum=0 + min=9999999 + max=0 + i=0 + + while [ $i -lt $cnt ]; do + let i++ + [ "$proto" = "Any" ] && res=$(nping -c 1 --tos $tos --udp --dest-port $port --data-length $dsize $host 2>&1) + [ "$proto" = "IPv4" ] && res=$(nping -4 -c 1 --tos $tos --udp --dest-port $port --data-length $dsize $host 2>&1) + [ "$proto" = "IPv6" ] && res=$(nping -6 -c 1 --tos $tos --udp --dest-port $port --data-length $dsize $host 2>&1) + ba=`echo "$res" | grep "RCVD"` + [ -z "$ba" ] && { $UCI_SET_VARSTATE cwmp.@ippingdiagnostic[0].DiagnosticState=Error_CannotResolveHostName; return; } + stc=`echo "$res" | grep "RCVD" | grep "unreachable"` + [ -n "$stc" ] && { $UCI_SET_VARSTATE cwmp.@ippingdiagnostic[0].DiagnosticState=Error_Other; return; } + times=`echo "$res" | grep "rtt"` + [ -z "$times" ] && continue + sc1=`echo "$res" | grep "Rcvd" | awk -F': ' '{print $3}' | awk -F'(' '{ print $1 }'` + sc1=${sc1:-0} + success_count=$((success_count+sc1)) + max_time=`echo $times | awk -F': ' '{ print $2 }' | awk -F'ms' '{ print $1 }'` + min_time=`echo $times | awk -F': ' '{ print $3 }' | awk -F'ms' '{ print $1 }'` + avg_time=`echo $times | awk -F': ' '{ print $4 }' | awk -F'ms' '{ print $1 }'` + min_time=${min_time:-0} + avg_time=${avg_time:-0} + max_time=${max_time:-0} + min_time=$(echo $min_time $micros | awk '{printf "%3.0f\n",$1*$2}') + avg_time=$(echo $avg_time $micros | awk '{printf "%3.0f\n",$1*$2}') + max_time=$(echo $max_time $micros | awk '{printf "%3.0f\n",$1*$2}') + [ $min_time -lt $min ] && min=$min_time + [ $max_time -gt $max ] && max=$max_time + avg_time_sum=$((avg_time_sum+avg_time)) + sleep $inter_time + done + failure_count=$((cnt-success_count)) + [ $success_count -gt 0 ] && avg_time=$((avg_time_sum/success_count)) || avg_time=0 + min_time=$min + max_time=$max + $UCI_SET_VARSTATE cwmp.@udpechodiagnostic[0].DiagnosticState=Complete + $UCI_SET_VARSTATE cwmp.@udpechodiagnostic[0].SuccessCount=$success_count + $UCI_SET_VARSTATE cwmp.@udpechodiagnostic[0].FailureCount=$failure_count + $UCI_SET_VARSTATE cwmp.@udpechodiagnostic[0].AverageResponseTime=$avg_time + $UCI_SET_VARSTATE cwmp.@udpechodiagnostic[0].MinimumResponseTime=$min_time + $UCI_SET_VARSTATE cwmp.@udpechodiagnostic[0].MaximumResponseTime=$max_time + event_dignostic +} + +event_dignostic() { + local e=1 + local i=0 + while [ "$e" != 0 -a $i -lt 200 ]; do + ubus -t 1 call tr069 inform '{"event":"8 DIAGNOSTICS COMPLETE"}' &>/dev/null + e=$? + [ "$e" != "0" ] && sleep 1; + let i++ + done +} + +udpecho_stop_diagnostic() { + local pids=`ps | grep udpecho_launch | grep -v grep | awk '{print $1}'` + if [ -n "$pids" ]; then + kill -9 $pids &>/dev/null + $UCI_SET_VARSTATE cwmp.@udpechodiagnostic[0].DiagnosticState=None + fi +} + +if [ "$1" == "run" ] ; then + udpecho_launch +elif [ "$1" == "stop" ]; then + udpecho_stop_diagnostic +else + return +fi diff --git a/scripts/functions/upload_launch b/scripts/functions/upload_launch index 6730285..0d51cf4 100644 --- a/scripts/functions/upload_launch +++ b/scripts/functions/upload_launch @@ -1,25 +1,45 @@ #!/bin/sh -# Copyright (C) 2015 PIVA Software +# Copyright (C) 2019 PIVA Software # Author: IMEN Bhiri +# Author: AMIN Ben Ramdhane UCI_CONFIG_DIR="/etc/config/" -UCI_GET_VARSTATE="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state get -q " -UCI_SET_VARSTATE="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state set -q " +UCI_GET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state get" +UCI_SET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state set" +UCI_ADD_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state add" +UCI_DELETE_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state delete" CAPTURE_FILE="/tmp/upload_dump" UPLOAD_DIAGNOSTIC_FILE="/tmp/icwmp_upload_diagnostic" CONNECTION_TIMEOUT=20 +upload_get() { + local val=`$UCI_GET_VARSTATE $1` + echo ${val:-$2} +} + upload_launch() { - url=$1 - interface=$2 - size=$3 + local tx_bytes_before rx_bytes_before time1 tx_bytes_after rx_bytes_after time2 res ba stc periodtime + local url=$1 + local interface=$2 + local size=$3 + [ "`$UCI_GET_VARSTATE cwmp.@uploaddiagnostic[0].DiagnosticState`" != "Requested" ] && return + [ "$url" = "" ] && { $UCI_SET_VARSTATE cwmp.@uploaddiagnostic[0].DiagnosticState=Error_InitConnectionFailed; return; } + local proto=`upload_get cwmp.@uploaddiagnostic[0].ProtocolVersion Any` tcpdump -i $interface tcp -w ${CAPTURE_FILE} > /dev/null 2>&1 & PID=$! sleep 1 dd if=/dev/zero of=${UPLOAD_DIAGNOSTIC_FILE} bs=${size} count=1 2>/dev/null if [ ${url:0:7} = http:// ]; then - res=$(curl --fail --connect-timeout ${CONNECTION_TIMEOUT} -T ${UPLOAD_DIAGNOSTIC_FILE} $url 2>&1) + tx_bytes_before=`ubus call network.device status "{'name':'$interface'}" | sed -n '/statistics/,$ p' | grep "tx_bytes" | awk -F ": " '{print $2}' | sed 's/.$//'` + rx_bytes_before=`ubus call network.device status "{'name':'$interface'}" | sed -n '/statistics/,$ p' | grep "rx_bytes" | awk -F ": " '{print $2}' | sed 's/.$//'` + time1=`date +%s` + [ "$proto" = "Any" ] && res=$(curl --fail --connect-timeout ${CONNECTION_TIMEOUT} -T ${UPLOAD_DIAGNOSTIC_FILE} $url 2>&1) + [ "$proto" = "IPv4" ] && res=$(curl -4 --fail --connect-timeout ${CONNECTION_TIMEOUT} -T ${UPLOAD_DIAGNOSTIC_FILE} $url 2>&1) + [ "$proto" = "IPv6" ] && res=$(curl -6 --fail --connect-timeout ${CONNECTION_TIMEOUT} -T ${UPLOAD_DIAGNOSTIC_FILE} $url 2>&1) + time2=`date +%s` + tx_bytes_after=`ubus call network.device status "{'name':'$interface'}" | sed -n '/statistics/,$ p' | grep "tx_bytes" | awk -F ": " '{print $2}' | sed 's/.$//'` + rx_bytes_after=`ubus call network.device status "{'name':'$interface'}" | sed -n '/statistics/,$ p' | grep "rx_bytes" | awk -F ": " '{print $2}' | sed 's/.$//'` ba=`echo "$res" | grep "bad address"` [ -n "$ba" ] && { $UCI_SET_VARSTATE cwmp.@uploaddiagnostic[0].DiagnosticState=Error_InitConnectionFailed; kill $PID &> /dev/null; return; } stc=`echo "$res" | grep "404 Not Found"` @@ -32,7 +52,15 @@ upload_launch() { if [ -z "${url##*$substr*}" ] ;then url=`echo $url |sed -e "s/ftp:\/\/\([^:]*\):\([^:]*\)@\(.*\)/-u \1:\2 ftp:\/\/\3/"` fi - res=$(curl --fail --disable-epsv --ftp-pasv --connect-timeout ${CONNECTION_TIMEOUT} -T ${UPLOAD_DIAGNOSTIC_FILE} $url 2>&1) + tx_bytes_before=`ubus call network.device status "{'name':'$interface'}" | sed -n '/statistics/,$ p' | grep "tx_bytes" | awk -F ": " '{print $2}' | sed 's/.$//'` + rx_bytes_before=`ubus call network.device status "{'name':'$interface'}" | sed -n '/statistics/,$ p' | grep "rx_bytes" | awk -F ": " '{print $2}' | sed 's/.$//'` + time1=`date +%s` + [ "$proto" = "Any" ] && res=$(curl --fail --disable-epsv --ftp-pasv --connect-timeout ${CONNECTION_TIMEOUT} -T ${UPLOAD_DIAGNOSTIC_FILE} $url 2>&1) + [ "$proto" = "IPv4" ] && res=$(curl -4 --fail --disable-epsv --ftp-pasv --connect-timeout ${CONNECTION_TIMEOUT} -T ${UPLOAD_DIAGNOSTIC_FILE} $url 2>&1) + [ "$proto" = "IPv6" ] && res=$(curl -6 --fail --disable-epsv --ftp-pasv --connect-timeout ${CONNECTION_TIMEOUT} -T ${UPLOAD_DIAGNOSTIC_FILE} $url 2>&1) + time2=`date +%s` + tx_bytes_after=`ubus call network.device status "{'name':'$interface'}" | sed -n '/statistics/,$ p' | grep "tx_bytes" | awk -F ": " '{print $2}' | sed 's/.$//'` + rx_bytes_after=`ubus call network.device status "{'name':'$interface'}" | sed -n '/statistics/,$ p' | grep "rx_bytes" | awk -F ": " '{print $2}' | sed 's/.$//'` ba=`echo "$res" | grep "Couldn't resolve host"` [ -n "$ba" ] && { $UCI_SET_VARSTATE cwmp.@uploaddiagnostic[0].DiagnosticState=Error_InitConnectionFailed; kill $PID 2> /dev/null; return; } stc=`echo "$res" | grep "Access denied"` @@ -42,7 +70,23 @@ upload_launch() { stc=`echo "$res" |tail -n 1 |awk '{print $(NF-11)}'` [ "$stc" != "100" ] && { $UCI_SET_VARSTATE cwmp.@uploaddiagnostic[0].DiagnosticState=Error_TransferFailed; kill $PID 2> /dev/null; return; } fi + tx_bytes=$((tx_bytes_after-tx_bytes_before)) + rx_bytes=$((rx_bytes_after-rx_bytes_before)) + periodtime=$(($((time2-time1))*1000000)) $UCI_SET_VARSTATE cwmp.@uploaddiagnostic[0].DiagnosticState=Completed + $UCI_SET_VARSTATE cwmp.@uploaddiagnostic[0].TestBytesSent=$size + $UCI_SET_VARSTATE cwmp.@uploaddiagnostic[0].TotalBytesReceived=$rx_bytes + $UCI_SET_VARSTATE cwmp.@uploaddiagnostic[0].TotalBytesSent=$tx_bytes + $UCI_SET_VARSTATE cwmp.@uploaddiagnostic[0].PeriodOfFullLoading=$periodtime + local perconnection=`$UCI_GET_VARSTATE cwmp.@uploaddiagnostic[0].EnablePerConnection` + if ([ "$perconnection" == "true" ] || [ "$perconnection" == "1" ]); then + $UCI_ADD_VARSTATE cwmp UploadPerConnection + $UCI_SET_VARSTATE cwmp.@UploadPerConnection[0].TestBytesSent=$size + $UCI_SET_VARSTATE cwmp.@UploadPerConnection[0].TotalBytesReceived=$rx_bytes + $UCI_SET_VARSTATE cwmp.@UploadPerConnection[0].TotalBytesSent=$tx_bytes + else + $UCI_DELETE_VARSTATE cwmp.@UploadPerConnection[0] + fi rm ${UPLOAD_DIAGNOSTIC_FILE} &>/dev/null sleep 3 local pids=`ps | grep $PID` @@ -50,6 +94,7 @@ upload_launch() { } upload_stop_diagnostic() { + $UCI_DELETE_VARSTATE cwmp.@UploadPerConnection[0] local pids=`ps | grep upload_launch.*run | grep -v grep | awk '{print $1}'` if [ -n "$pids" ]; then kill -9 $pids &>/dev/null diff --git a/udpechoserver/udpechoserver.c b/udpechoserver/udpechoserver.c new file mode 100644 index 0000000..a09d82b --- /dev/null +++ b/udpechoserver/udpechoserver.c @@ -0,0 +1,228 @@ +/* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* Copyright (C) 2019 iopsys Software Solutions AB +* Author: Amin Ben Ramdhane +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "udpechoserver.h" +#include "udpechoserverlog.h" +#include "udpechoserveruci.h" + +struct udpechoserver_config cur_udpechoserver_conf = {0}; +struct udpechoserver_result cur_udpechoserver_result={0}; + +static void set_udpechoserver_stats(void) +{ + char PacketsReceived[8], PacketsResponded[8], BytesReceived[8], BytesResponded[8]; + + sprintf(PacketsReceived, "%d", cur_udpechoserver_result.PacketsReceived); + sprintf(PacketsResponded, "%d", cur_udpechoserver_result.PacketsResponded); + sprintf(BytesReceived, "%d", cur_udpechoserver_result.BytesReceived); + sprintf(BytesResponded, "%d", cur_udpechoserver_result.BytesResponded); + + dmuci_init(); + dmuci_set_value_state("cwmp_udpechoserver", "udpechoserver", "PacketsReceived", PacketsReceived); + dmuci_set_value_state("cwmp_udpechoserver", "udpechoserver", "PacketsResponded", PacketsResponded); + dmuci_set_value_state("cwmp_udpechoserver", "udpechoserver", "BytesReceived", BytesReceived); + dmuci_set_value_state("cwmp_udpechoserver", "udpechoserver", "BytesResponded", BytesResponded); + dmuci_set_value_state("cwmp_udpechoserver", "udpechoserver", "TimeFirstPacketReceived", cur_udpechoserver_result.TimeFirstPacket); + dmuci_set_value_state("cwmp_udpechoserver", "udpechoserver", "TimeLastPacketReceived", cur_udpechoserver_result.TimeLastPacket); + dmuci_fini(); +} + +int udpechoserver_connect(void) +{ + int sock, fromlen, n, ret; + struct sockaddr_in server, from; + struct timeval tv_recv, tv_reply; + struct tm lt; + char buf[1024]; + char str[INET_ADDRSTRLEN]; + char s_now[default_date_size]; + struct udpechoserver_plus *plus; + + memset(&cur_udpechoserver_result, 0, sizeof(cur_udpechoserver_result)); + + sock = socket(AF_INET, SOCK_DGRAM, 0); + if (sock < 0) { + udpechoserver_log(SCRIT,"Socket error = %d", sock); + return -1; + } + + bzero(&server, sizeof(server)); + server.sin_family=AF_INET; + server.sin_addr.s_addr=INADDR_ANY; + server.sin_port=htons(cur_udpechoserver_conf.server_port); + + if (bind(sock, (struct sockaddr *)&server, sizeof(server)) > 0) { + udpechoserver_log(SCRIT,"Error in bind function"); + return -1; + } + + udpechoserver_log(SINFO,"CONNECT UDPECHOSERVER"); + + while(true) + { + fromlen = sizeof(struct sockaddr_in); + n = recvfrom(sock, buf, 1024, 0, (struct sockaddr *)&from, &fromlen); + if (n < 0) + udpechoserver_log(SCRIT,"Error in receive message"); + + inet_ntop(AF_INET, &(from.sin_addr.s_addr), str, INET_ADDRSTRLEN); + udpechoserver_log(SINFO,"UDPECHOSERVER receive massage from %s with data size is %d Bytes", str, n); + + if(cur_udpechoserver_conf.address && cur_udpechoserver_conf.address[0] != '\0') { + if(strcmp(cur_udpechoserver_conf.address, str) != 0) { + udpechoserver_log(SINFO,"UDPECHOSERVER can not respond to a UDP echo from this source IP address %s", str); + continue; + } + } + + gettimeofday(&tv_recv, NULL); + if(cur_udpechoserver_result.TimeFirstPacketReceived.tv_sec == 0 && cur_udpechoserver_result.TimeFirstPacketReceived.tv_usec == 0) + cur_udpechoserver_result.TimeFirstPacketReceived = tv_recv; + cur_udpechoserver_result.TimeLastPacketReceived = tv_recv; + cur_udpechoserver_result.PacketsReceived++; + cur_udpechoserver_result.BytesReceived+=n; + (void) localtime_r(&(cur_udpechoserver_result.TimeFirstPacketReceived.tv_sec), <); + strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", <); + sprintf(cur_udpechoserver_result.TimeFirstPacket,"%s.%06ld", s_now, (long) cur_udpechoserver_result.TimeFirstPacketReceived.tv_usec); + (void) localtime_r(&(cur_udpechoserver_result.TimeLastPacketReceived.tv_sec), <); + strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", <); + sprintf(cur_udpechoserver_result.TimeLastPacket,"%s.%06ld", s_now, (long) cur_udpechoserver_result.TimeLastPacketReceived.tv_usec); + + if(cur_udpechoserver_conf.plus) { + if(n >= sizeof(struct udpechoserver_plus)) { + plus = (struct udpechoserver_plus *)buf; + plus->TestRespSN = htonl(cur_udpechoserver_result.TestRespSN); + plus->TestRespRecvTimeStamp = htonl(tv_recv.tv_sec*1000000+tv_recv.tv_usec); + plus->TestRespReplyFailureCount = htonl(cur_udpechoserver_result.TestRespReplyFailureCount); + gettimeofday(&tv_reply, NULL); + plus->TestRespReplyTimeStamp = htonl(tv_reply.tv_sec*1000000+tv_reply.tv_usec); + } + } + + ret = sendto(sock, buf, n, 0, (struct sockaddr *)&from, fromlen); + if (n != ret) { + cur_udpechoserver_result.TestRespReplyFailureCount++; + udpechoserver_log(SCRIT,"Error in send massage"); + } + else { + cur_udpechoserver_result.TestRespSN++; + cur_udpechoserver_result.PacketsResponded++; + cur_udpechoserver_result.BytesResponded+=ret; + } + udpechoserver_log(SINFO,"UDPECHOSERVER sent massage to %s with data size is %d Bytes", str, ret); + + set_udpechoserver_stats(); + + udpechoserver_log(SDEBUG,"UDPECHOSERVER Stats : PacketsReceived = %d", cur_udpechoserver_result.PacketsReceived); + udpechoserver_log(SDEBUG,"UDPECHOSERVER Stats : PacketsResponded = %d", cur_udpechoserver_result.PacketsResponded); + udpechoserver_log(SDEBUG,"UDPECHOSERVER Stats : BytesReceived = %d", cur_udpechoserver_result.BytesReceived); + udpechoserver_log(SDEBUG,"UDPECHOSERVER Stats : BytesResponded = %d", cur_udpechoserver_result.BytesResponded); + udpechoserver_log(SDEBUG,"UDPECHOSERVER Stats : TestRespReplyFailureCount = %d", cur_udpechoserver_result.TestRespReplyFailureCount); + udpechoserver_log(SDEBUG,"UDPECHOSERVER Stats : TimeFirstPacketReceived = %s", cur_udpechoserver_result.TimeFirstPacket); + udpechoserver_log(SDEBUG,"UDPECHOSERVER Stats : TimeLastPacketReceived = %s", cur_udpechoserver_result.TimeLastPacket); + } +} + +int udpechoserver_init(void) +{ + char *value = NULL; + int a; + + value = dmuci_get_value("cwmp_udpechoserver", "udpechoserver", "log_level"); + if(value != NULL && *value != '\0') { + a = atoi(value); + cur_udpechoserver_conf.loglevel = a; + } + else + cur_udpechoserver_conf.loglevel = DEFAULT_LOGLEVEL; + udpechoserver_log(SDEBUG,"Log Level of UDP ECHO SERVER is :%d", cur_udpechoserver_conf.loglevel); + + value = dmuci_get_value("cwmp_udpechoserver", "udpechoserver", "enable"); + if(value != NULL && *value != '\0') { + if ((strcasecmp(value,"true")==0) || (strcmp(value,"1")==0)) { + cur_udpechoserver_conf.enable = true; + udpechoserver_log(SDEBUG,"UDP echo server is Enabled"); + } + } + + value = dmuci_get_value("cwmp_udpechoserver", "udpechoserver", "interface"); + if(value != NULL && *value != '\0') { + if (cur_udpechoserver_conf.interface != NULL) + free(cur_udpechoserver_conf.interface); + cur_udpechoserver_conf.interface = strdup(value); + udpechoserver_log(SDEBUG,"UDP echo server interface is :%s", cur_udpechoserver_conf.interface); + } + else { + cur_udpechoserver_conf.interface = strdup(""); + udpechoserver_log(SDEBUG,"UDP echo server interface is empty"); + } + + value = dmuci_get_value("cwmp_udpechoserver", "udpechoserver", "address"); + if(value != NULL && *value != '\0') { + if (cur_udpechoserver_conf.address != NULL) + free(cur_udpechoserver_conf.address); + cur_udpechoserver_conf.address = strdup(value); + udpechoserver_log(SDEBUG,"UDP echo server address is :%s", cur_udpechoserver_conf.address); + } + else { + cur_udpechoserver_conf.address = strdup(""); + udpechoserver_log(SDEBUG,"UDP echo server address is empty"); + } + + value = dmuci_get_value("cwmp_udpechoserver", "udpechoserver", "server_port"); + if(value != NULL && *value != '\0') { + a = atoi(value); + cur_udpechoserver_conf.server_port = a; + udpechoserver_log(SDEBUG,"UDP echo server port is :%d", cur_udpechoserver_conf.server_port); + } + + value = dmuci_get_value("cwmp_udpechoserver", "udpechoserver", "plus"); + if(value != NULL && *value != '\0') { + if ((strcasecmp(value,"true")==0) || (strcmp(value,"1")==0)) { + cur_udpechoserver_conf.plus = true; + udpechoserver_log(SDEBUG,"UDP echo server plus is Enabled"); + } + else { + cur_udpechoserver_conf.plus = false; + udpechoserver_log(SDEBUG,"UDP echo server plus is Disabled"); + } + } + return 0; +} + +void udpechoserver_exit(void) +{ + free(cur_udpechoserver_conf.address); + free(cur_udpechoserver_conf.interface); +} + +int main(void) +{ + dmuci_init(); + udpechoserver_init(); + dmuci_fini(); + udpechoserver_log(SINFO,"START UDPECHOSERVER"); + + udpechoserver_connect(); + + udpechoserver_exit(); + udpechoserver_log(SINFO,"EXIT UDPECHOSERVER"); + return 0; +} diff --git a/udpechoserver/udpechoserver.h b/udpechoserver/udpechoserver.h new file mode 100644 index 0000000..e119e33 --- /dev/null +++ b/udpechoserver/udpechoserver.h @@ -0,0 +1,56 @@ +/* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* Copyright (C) 2019 iopsys Software Solutions AB +* Author: Amin Ben Ramdhane +*/ + +#ifndef _UDPECHOSERVER_H__ +#define _UDPECHOSERVER_H__ + +#include +#include + +#define default_date_format "AAAA-MM-JJTHH:MM:SS.000000Z" +#define default_date_size sizeof(default_date_format) + 1 + +struct udpechoserver_config +{ + bool enable; + char *interface; + char *address; + int server_port; + bool plus; + int loglevel; +}; + +struct udpechoserver_plus +{ + unsigned int TestGenSN; + unsigned int TestRespSN; + unsigned int TestRespRecvTimeStamp; + unsigned int TestRespReplyTimeStamp; + unsigned int TestRespReplyFailureCount; +}; + +struct udpechoserver_result +{ + unsigned int TestRespSN; + unsigned int TestRespReplyFailureCount; + unsigned int PacketsReceived; + unsigned int PacketsResponded; + unsigned int BytesReceived; + unsigned int BytesResponded; + struct timeval TimeFirstPacketReceived; + struct timeval TimeLastPacketReceived; + char TimeFirstPacket[default_date_size]; + char TimeLastPacket[default_date_size]; +}; + +extern struct udpechoserver_config cur_udpechoserver_conf; +extern struct udpechoserver_result cur_udpechoserver_result; + +#endif /* _UDPECHOSERVER_H__ */ diff --git a/udpechoserver/udpechoserverlog.c b/udpechoserver/udpechoserverlog.c new file mode 100644 index 0000000..0be4e14 --- /dev/null +++ b/udpechoserver/udpechoserverlog.c @@ -0,0 +1,55 @@ +/* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* Copyright (C) 2019 iopsys Software Solutions AB +* Author: Amin Ben Ramdhane +*/ + +#include +#include +#include +#include "udpechoserverlog.h" +#include "udpechoserver.h" +#define DEBUG + +static const int log_syslogmap[] = { + [SCRIT] = LOG_CRIT, + [SWARNING] = LOG_WARNING, + [SNOTICE] = LOG_NOTICE, + [SINFO] = LOG_INFO, + [SDEBUG] = LOG_DEBUG +}; + +static const char* log_str[] = { + [SCRIT] = "CRITICAL", + [SWARNING] = "WARNING", + [SNOTICE] = "NOTICE", + [SINFO] = "INFO", + [SDEBUG] = "DEBUG" +}; + +void udpechoserver_log(int priority, const char *format, ...) +{ + va_list vl; + char *log; + + if (priority <= cur_udpechoserver_conf.loglevel) { +#ifdef DEBUG + time_t t = time(NULL); + struct tm tm = *localtime(&t); + va_start(vl, format); + printf("%d-%02d-%02d %02d:%02d:%02d [udpechoserver] %s - ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, log_str[priority]); + vprintf(format, vl); + va_end(vl); + printf("\n"); +#endif + openlog("udpechoserver", 0, LOG_DAEMON); + va_start(vl, format); + vsyslog(log_syslogmap[priority], format, vl); + va_end(vl); + closelog(); + } +} diff --git a/udpechoserver/udpechoserverlog.h b/udpechoserver/udpechoserverlog.h new file mode 100644 index 0000000..8414486 --- /dev/null +++ b/udpechoserver/udpechoserverlog.h @@ -0,0 +1,27 @@ +/* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* Copyright (C) 2019 iopsys Software Solutions AB +* Author: Amin Ben Ramdhane +*/ + +#ifndef _UDPECHOSERVERLOG_H_ +#define _UDPECHOSERVERLOG_H_ + +#define DEFAULT_LOGLEVEL SINFO + +enum udpechoserver_log_level_enum { + SCRIT, + SWARNING, + SNOTICE, + SINFO, + SDEBUG, + __MAX_SLOG +}; + +void udpechoserver_log(int priority, const char *format, ...); + +#endif /* _UDPECHOSERVERLOG_H_ */ diff --git a/udpechoserver/udpechoserveruci.c b/udpechoserver/udpechoserveruci.c new file mode 100644 index 0000000..cf2138a --- /dev/null +++ b/udpechoserver/udpechoserveruci.c @@ -0,0 +1,185 @@ +/* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* Copyright (C) 2019 iopsys Software Solutions AB +* Author: Amin Ben Ramdhane +*/ + +#include +#include "udpechoserveruci.h" + +static struct uci_context *uci_ctx = NULL; +static struct uci_context *uci_ctx_state = NULL; + +int dmuci_init(void) +{ + uci_ctx = uci_alloc_context(); + if (!uci_ctx) { + return -1; + } + uci_ctx_state = uci_alloc_context(); + if (!uci_ctx_state) { + return -1; + } + uci_add_delta_path(uci_ctx_state, uci_ctx_state->savedir); + uci_set_savedir(uci_ctx_state, VAR_STATE); + return 0; +} + +int dmuci_fini(void) +{ + if (uci_ctx) { + uci_free_context(uci_ctx); + } + if (uci_ctx_state) { + uci_free_context(uci_ctx_state); + } + uci_ctx = NULL; + uci_ctx_state = NULL; + return 0; +} + +static bool dmuci_validate_section(const char *str) +{ + if (!*str) + return false; + + for (; *str; str++) { + unsigned char c = *str; + + if (isalnum(c) || c == '_') + continue; + + return false; + } + return true; +} + +static int dmuci_init_ptr(struct uci_context *ctx, struct uci_ptr *ptr, char *package, char *section, char *option, char *value) +{ + char *last = NULL; + char *tmp; + + memset(ptr, 0, sizeof(struct uci_ptr)); + + /* value */ + if (value) { + ptr->value = value; + } + ptr->package = package; + if (!ptr->package) + goto error; + + ptr->section = section; + if (!ptr->section) { + ptr->target = UCI_TYPE_PACKAGE; + goto lastval; + } + + ptr->option = option; + if (!ptr->option) { + ptr->target = UCI_TYPE_SECTION; + goto lastval; + } else { + ptr->target = UCI_TYPE_OPTION; + } + +lastval: + if (ptr->section && !dmuci_validate_section(ptr->section)) + ptr->flags |= UCI_LOOKUP_EXTENDED; + + return 0; + +error: + return -1; +} + +void dmuci_print_list(struct uci_list *uh, char **val, char *delimiter) +{ + struct uci_element *e; + static char buffer[512]; + int dlen = strlen(delimiter); + int olen = 0; + char *buf = buffer; + *buf = '\0'; + + uci_foreach_element(uh, e) { + if (*buf) { + strcat(buf, delimiter); + strcat(buf, e->name); + } + else { + strcpy(buf, e->name); + } + } + *val = buf; +} + +char *dmuci_get_value(char *package, char *section, char *option) +{ + struct uci_ptr ptr; + char *val = ""; + + if (!section || !option) + return val; + + if (dmuci_init_ptr(uci_ctx, &ptr, package, section, option, NULL)) { + return val; + } + if (uci_lookup_ptr(uci_ctx, &ptr, NULL, true) != UCI_OK) { + return val; + } + + if (!ptr.o) + return val; + + if(ptr.o->type == UCI_TYPE_LIST) { + dmuci_print_list(&ptr.o->v.list, &val, " "); + return val; + } + + if (ptr.o->v.string) + return ptr.o->v.string; + else + return val; +} + +char *dmuci_set_value(char *package, char *section, char *option, char *value) +{ + struct uci_ptr ptr; + int ret = UCI_OK; + + if (!section) + return ""; + + if (dmuci_init_ptr(uci_ctx, &ptr, package, section, option, value)) { + return ""; + } + if (uci_lookup_ptr(uci_ctx, &ptr, NULL, true) != UCI_OK) { + return ""; + } + + uci_set(uci_ctx, &ptr); + + if (ret == UCI_OK) + ret = uci_save(uci_ctx, ptr.p); + + if (ptr.o && ptr.o->v.string) + return ptr.o->v.string; + + return ""; +} + +/************************* /var/state ***************************/ +char *dmuci_set_value_state(char *package, char *section, char *option, char *value) +{ + char *val; + struct uci_context *save_uci_ctx = uci_ctx; + uci_ctx = uci_ctx_state; + val = dmuci_set_value(package, section, option, value); + uci_ctx = save_uci_ctx; + return val; +} diff --git a/udpechoserver/udpechoserveruci.h b/udpechoserver/udpechoserveruci.h new file mode 100644 index 0000000..0f7efff --- /dev/null +++ b/udpechoserver/udpechoserveruci.h @@ -0,0 +1,23 @@ +/* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* Copyright (C) 2019 iopsys Software Solutions AB +* Author: Amin Ben Ramdhane +*/ + +#ifndef _UDPECHOSERVERUCI_H__ +#define _UDPECHOSERVERUCI_H__ + +#define VAR_STATE "/var/state" + +int dmuci_init(void); +int dmuci_fini(void); +void dmuci_print_list(struct uci_list *uh, char **val, char *delimiter); +char *dmuci_get_value(char *package, char *section, char *option); +char *dmuci_set_value(char *package, char *section, char *option, char *value); +char *dmuci_set_value_state(char *package, char *section, char *option, char *value); + +#endif /* _UDPECHOSERVERUCI_H__ */