make diagnostics independent of libbbf

This commit is contained in:
Omar Kallel 2020-12-30 10:55:29 +01:00
parent 5c92271ba5
commit 43e73fb4ee
14 changed files with 107 additions and 54 deletions

View file

@ -10,6 +10,8 @@
* *
*/ */
#include <unistd.h>
#include <fcntl.h>
#include "backupSession.h" #include "backupSession.h"
#include "xml.h" #include "xml.h"
#include "log.h" #include "log.h"

View file

@ -55,8 +55,7 @@ icwmpd_LDADD = \
$(LIBJSON_LIBS) \ $(LIBJSON_LIBS) \
$(LBLOBMSG_LIBS) \ $(LBLOBMSG_LIBS) \
$(LIBZ_LIBS) \ $(LIBZ_LIBS) \
$(LIBM_LIBS) \ $(LIBM_LIBS)
-lbbfdm
icwmpd_CFLAGS+=-DCWMP_VERSION=\"$(CWMP_VERSION)\" icwmpd_CFLAGS+=-DCWMP_VERSION=\"$(CWMP_VERSION)\"
icwmpd_LDFLAGS+=-DCWMP_VERSION=\"$(CWMP_VERSION)\" icwmpd_LDFLAGS+=-DCWMP_VERSION=\"$(CWMP_VERSION)\"

View file

@ -7,6 +7,7 @@
* Copyright (C) 2013-2020 iopsys Software Solutions AB * Copyright (C) 2013-2020 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
*/ */
#include <ctype.h>
#include "common.h" #include "common.h"
#include "log.h" #include "log.h"
#include "cwmp_uci.h" #include "cwmp_uci.h"

View file

@ -9,7 +9,8 @@
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com> * Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
* *
*/ */
#include <stdarg.h>
#include <unistd.h>
#include "common.h" #include "common.h"
#include "diagnostic.h" #include "diagnostic.h"
#include "config.h" #include "config.h"
@ -21,13 +22,9 @@
struct diagnostic_input struct diagnostic_input
{ {
char *input_name; char *input_name;
char *package; char *parameter_name;
char *section;
char *option;
int (*get_input_value)(char *package, char* section, char* option, char **value);
}; };
int get_diagnostic_value_by_uci(char *package, char* section, char* option, char **value); int get_diagnostic_value_by_uci(char *package, char* section, char* option, char **value);
int get_dm_ip_iface_object_by_uci_iface(char *package, char* section, char* option, char **dmiface); int get_dm_ip_iface_object_by_uci_iface(char *package, char* section, char* option, char **dmiface);
@ -38,24 +35,24 @@ int get_dm_ip_iface_object_by_uci_iface(char *package, char* section, char* opti
#define UPLOAD_DIAG_OP_NAME "UploadDiagnostics" #define UPLOAD_DIAG_OP_NAME "UploadDiagnostics"
struct diagnostic_input download_diagnostics_array[DOWNLOAD_NUMBER_INPUTS]={ struct diagnostic_input download_diagnostics_array[DOWNLOAD_NUMBER_INPUTS]={
{"Interface","dmmap_diagnostics","download","interface",get_dm_ip_iface_object_by_uci_iface}, {"Interface","Device.IP.Diagnostics.DownloadDiagnostics.Interface"},
{"DownloadURL","dmmap_diagnostics","download","url",get_diagnostic_value_by_uci}, {"DownloadURL","Device.IP.Diagnostics.DownloadDiagnostics.DownloadURL"},
{"DSCP","dmmap_diagnostics","download","DSCP",get_diagnostic_value_by_uci}, {"DSCP","Device.IP.Diagnostics.DownloadDiagnostics.DSCP"},
{"EthernetPriority","dmmap_diagnostics","download","ethernetpriority",get_diagnostic_value_by_uci}, {"EthernetPriority","Device.IP.Diagnostics.DownloadDiagnostics.EthernetPriority"},
{"ProtocolVersion","dmmap_diagnostics","download","ProtocolVersion",get_diagnostic_value_by_uci}, {"ProtocolVersion","Device.IP.Diagnostics.DownloadDiagnostics.ProtocolVersion"},
{"NumberOfConnections","dmmap_diagnostics","download","NumberOfConnections",get_diagnostic_value_by_uci}, {"NumberOfConnections","Device.IP.Diagnostics.DownloadDiagnostics.NumberOfConnections"},
{"EnablePerConnectionResults","dmmap_diagnostics","download","EnablePerConnection",get_diagnostic_value_by_uci} {"EnablePerConnectionResults","Device.IP.Diagnostics.DownloadDiagnostics.EnablePerConnection"}
}; };
struct diagnostic_input upload_diagnostics_array[UPLOAD_NUMBER_INPUTS]={ struct diagnostic_input upload_diagnostics_array[UPLOAD_NUMBER_INPUTS]={
{"Interface","dmmap_diagnostics","upload","interface",get_dm_ip_iface_object_by_uci_iface}, {"Interface","Device.IP.Diagnostics.UploadDiagnostics.Interface"},
{"UploadURL","dmmap_diagnostics","upload","url",get_diagnostic_value_by_uci}, {"UploadURL","Device.IP.Diagnostics.UploadDiagnostics.UploadURL"},
{"TestFileLength","dmmap_diagnostics","upload","TestFileLength",get_diagnostic_value_by_uci}, {"TestFileLength","Device.IP.Diagnostics.UploadDiagnostics.TestFileLength"},
{"DSCP","dmmap_diagnostics","upload","DSCP",get_diagnostic_value_by_uci}, {"DSCP","Device.IP.Diagnostics.UploadDiagnostics.DSCP"},
{"EthernetPriority","dmmap_diagnostics","upload","ethernetpriority",get_diagnostic_value_by_uci}, {"EthernetPriority","Device.IP.Diagnostics.UploadDiagnostics.EthernetPriority"},
{"ProtocolVersion","dmmap_diagnostics","upload","ProtocolVersion",get_diagnostic_value_by_uci}, {"ProtocolVersion","Device.IP.Diagnostics.UploadDiagnostics.ProtocolVersion"},
{"NumberOfConnections","dmmap_diagnostics","upload","NumberOfConnections",get_diagnostic_value_by_uci}, {"NumberOfConnections","Device.IP.Diagnostics.UploadDiagnostics.NumberOfConnections"},
{"EnablePerConnectionResults","dmmap_diagnostics","upload","EnablePerConnection",get_diagnostic_value_by_uci} {"EnablePerConnectionResults","Device.IP.Diagnostics.UploadDiagnostics.EnablePerConnection"}
}; };
static int icwmpd_cmd_no_wait(char *cmd, int n, ...) static int icwmpd_cmd_no_wait(char *cmd, int n, ...)
@ -116,7 +113,8 @@ int get_dm_ip_iface_object_by_uci_iface(char *package, char* section, char* opti
int cwmp_start_diagnostic(int diagnostic_type) int cwmp_start_diagnostic(int diagnostic_type)
{ {
int e, i, number_inputs; int e, i, number_inputs;
char *value = NULL, *operate_name = NULL; char *operate_name = NULL;
json_object *parameters = NULL, *param_obj = NULL, *value_obj = NULL;
struct diagnostic_input *diagnostics_array; struct diagnostic_input *diagnostics_array;
if (diagnostic_type == DOWNLOAD_DIAGNOSTIC) { if (diagnostic_type == DOWNLOAD_DIAGNOSTIC) {
@ -130,10 +128,13 @@ int cwmp_start_diagnostic(int diagnostic_type)
} }
LIST_HEAD(diagnostics_param_value_list); LIST_HEAD(diagnostics_param_value_list);
for (i=0; i<number_inputs; i++) { for (i=0; i<number_inputs; i++) {
if (diagnostics_array[i].get_input_value(diagnostics_array[i].package, diagnostics_array[i].section, diagnostics_array[i].option, &value) != 0) if (cwmp_get_parameter_values(diagnostics_array[i].parameter_name, &parameters) != NULL)
continue; continue;
cwmp_add_list_param_value(diagnostics_array[i].input_name, value, &diagnostics_param_value_list); param_obj = json_object_array_get_idx(parameters, 0);
FREE(value); json_object_object_get_ex(param_obj, "value", &value_obj);
cwmp_add_list_param_value(diagnostics_array[i].input_name, (char*)json_object_get_string(value_obj), &diagnostics_param_value_list);
FREE_JSON(value_obj);
FREE_JSON(param_obj);
} }
e = cwmp_ubus_call("usp.raw", "operate", CWMP_UBUS_ARGS{{"path", {.str_val="Device.IP.Diagnostics."}, UBUS_String},{"action", {.str_val=operate_name}, UBUS_String},{"input", {.param_value_list=&diagnostics_param_value_list}, UBUS_Obj_Obj}}, 3, &old_global_json_obj); e = cwmp_ubus_call("usp.raw", "operate", CWMP_UBUS_ARGS{{"path", {.str_val="Device.IP.Diagnostics."}, UBUS_String},{"action", {.str_val=operate_name}, UBUS_String},{"input", {.param_value_list=&diagnostics_param_value_list}, UBUS_Obj_Obj}}, 3, &old_global_json_obj);

View file

@ -12,6 +12,9 @@
#include <poll.h> #include <poll.h>
#include <json-c/json.h> #include <json-c/json.h>
#include <unistd.h>
#include <sys/wait.h>
#include <signal.h>
#include "external.h" #include "external.h"
#include "xml.h" #include "xml.h"

23
http.c
View file

@ -13,9 +13,13 @@
#include <curl/curl.h> #include <curl/curl.h>
#include <pthread.h> #include <pthread.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include "external.h" #include "external.h"
#include "log.h" #include "log.h"
/*#include "xml.h"*/
#include "config.h" #include "config.h"
#include "event.h" #include "event.h"
#include "http.h" #include "http.h"
@ -172,22 +176,7 @@ http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len,char **msg_i
} }
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, http_c.header_list); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, http_c.header_list);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, msg_out); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, msg_out);
if (msg_out)/*#include <stdint.h> if (msg_out)
#include <libubox/uloop.h>
*/
/*#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <uci.h>
#include <libubox/uloop.h>
#include <libubox/usock.h>*/
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) msg_out_len); curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) msg_out_len);
else else
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 0); curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 0);

View file

@ -10,13 +10,14 @@
*/ */
#ifndef __CCOMMON_H #ifndef __CCOMMON_H
#define __CCOMMON_H #define __CCOMMON_H
#include <libbbfdm/dmdiagnostics.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include <libubox/list.h> #include <libubox/list.h>
#include <sys/time.h>
#include <pthread.h>
#ifndef CWMP_VERSION #ifndef CWMP_VERSION
#define CWMP_VERSION "3.0.0" #define CWMP_VERSION "3.0.0"
@ -189,7 +190,7 @@ struct cwmp_dm_parameter {
char *type; char *type;
}; };
/*enum amd_version_enum { enum amd_version_enum {
AMD_1 = 1, AMD_1 = 1,
AMD_2, AMD_2,
AMD_3, AMD_3,
@ -200,7 +201,7 @@ struct cwmp_dm_parameter {
enum instance_mode { enum instance_mode {
INSTANCE_MODE_NUMBER, INSTANCE_MODE_NUMBER,
INSTANCE_MODE_ALIAS INSTANCE_MODE_ALIAS
};*/ };
struct cwmp_namespaces struct cwmp_namespaces
{ {

View file

@ -16,6 +16,9 @@
#include <pthread.h> #include <pthread.h>
#include <libubox/uloop.h> #include <libubox/uloop.h>
#include <sys/file.h> #include <sys/file.h>
#include <math.h>
#include <unistd.h>
#include <fcntl.h>
#include "common.h" #include "common.h"
#include "session.h" #include "session.h"
#include "xml.h" #include "xml.h"

View file

@ -12,6 +12,17 @@
#ifndef __DIAGNOSTIC__H #ifndef __DIAGNOSTIC__H
#define __DIAGNOSTIC__H #define __DIAGNOSTIC__H
#define IPPING_PATH "/usr/share/bbfdm/functions/ipping_launch"
#define NSLOOKUP_PATH "/usr/share/bbfdm/functions/nslookup_launch"
#define TRACEROUTE_PATH "/usr/share/bbfdm/functions/traceroute_launch"
#define UDPECHO_PATH "/usr/share/bbfdm/functions/udpecho_launch"
#define SERVERSELECTION_PATH "/usr/share/bbfdm/functions/serverselection_launch"
enum diagnostic_type {
DOWNLOAD_DIAGNOSTIC = 1,
UPLOAD_DIAGNOSTIC
};
int cwmp_ip_ping_diagnostic(); int cwmp_ip_ping_diagnostic();
int cwmp_start_diagnostic(int diagnostic_type); int cwmp_start_diagnostic(int diagnostic_type);
int cwmp_nslookup_diagnostic(); int cwmp_nslookup_diagnostic();

View file

@ -11,6 +11,7 @@
*/ */
#ifndef _FREECWMP_UBUS_H__ #ifndef _FREECWMP_UBUS_H__
#define _FREECWMP_UBUS_H__ #define _FREECWMP_UBUS_H__
#include <json-c/json.h>
#include "common.h" #include "common.h"
#define ARRAY_MAX 8 #define ARRAY_MAX 8

View file

@ -37,6 +37,43 @@ extern int count_download_queue;
extern const struct rpc_cpe_method rpc_cpe_methods[__RPC_CPE_MAX]; extern const struct rpc_cpe_method rpc_cpe_methods[__RPC_CPE_MAX];
extern const struct rpc_acs_method rpc_acs_methods[__RPC_ACS_MAX]; extern const struct rpc_acs_method rpc_acs_methods[__RPC_ACS_MAX];
enum fault_code_enum {
FAULT_9000 = 9000,// Method not supported
FAULT_9001,// Request denied
FAULT_9002,// Internal error
FAULT_9003,// Invalid arguments
FAULT_9004,// Resources exceeded
FAULT_9005,// Invalid parameter name
FAULT_9006,// Invalid parameter type
FAULT_9007,// Invalid parameter value
FAULT_9008,// Attempt to set a non-writable parameter
FAULT_9009,// Notification request rejected
FAULT_9010,// Download failure
FAULT_9011,// Upload failure
FAULT_9012,// File transfer server authentication failure
FAULT_9013,// Unsupported protocol for file transfer
FAULT_9014,// Download failure: unable to join multicast group
FAULT_9015,// Download failure: unable to contact file server
FAULT_9016,// Download failure: unable to access file
FAULT_9017,// Download failure: unable to complete download
FAULT_9018,// Download failure: file corrupted
FAULT_9019,// Download failure: file authentication failure
FAULT_9020,// Download failure: unable to complete download
FAULT_9021,// Cancelation of file transfer not permitted
FAULT_9022,// Invalid UUID format
FAULT_9023,// Unknown Execution Environment
FAULT_9024,// Disabled Execution Environment
FAULT_9025,// Diployment Unit to Execution environment mismatch
FAULT_9026,// Duplicate Deployment Unit
FAULT_9027,// System Ressources Exceeded
FAULT_9028,// Unknown Deployment Unit
FAULT_9029,// Invalid Deployment Unit State
FAULT_9030,// Invalid Deployment Unit Update: Downgrade not permitted
FAULT_9031,// Invalid Deployment Unit Update: Version not specified
FAULT_9032,// Invalid Deployment Unit Update: Version already exist
__FAULT_MAX
};
void xml_exit(void); void xml_exit(void);
int cwmp_handle_rpc_cpe_get_rpc_methods(struct session *session, struct rpc *rpc); int cwmp_handle_rpc_cpe_get_rpc_methods(struct session *session, struct rpc *rpc);

3
log.c
View file

@ -10,7 +10,8 @@
* *
*/ */
#include <pthread.h> #include <sys/stat.h>
#include <stdarg.h>
#include "common.h" #include "common.h"
#include "log.h" #include "log.h"

View file

@ -8,8 +8,11 @@
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
* *
*/ */
#include <unistd.h>
#include <openssl/hmac.h> #include <openssl/hmac.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#include <netdb.h>
#include <libubox/list.h>
#include "notifications.h" #include "notifications.h"
LIST_HEAD(list_value_change); LIST_HEAD(list_value_change);
@ -278,7 +281,7 @@ static void send_udp_message(struct addrinfo *servaddr, char *msg)
} }
} }
void del_list_lw_notify(struct dm_parameter *dm_parameter) void del_list_lw_notify(struct cwmp_dm_parameter *dm_parameter)
{ {
list_del(&dm_parameter->list); list_del(&dm_parameter->list);
@ -288,9 +291,9 @@ void del_list_lw_notify(struct dm_parameter *dm_parameter)
static void free_all_list_lw_notify() static void free_all_list_lw_notify()
{ {
struct dm_parameter *dm_parameter; struct cwmp_dm_parameter *dm_parameter;
while (list_lw_value_change.next != &list_lw_value_change) { while (list_lw_value_change.next != &list_lw_value_change) {
dm_parameter = list_entry(list_lw_value_change.next, struct dm_parameter, list); dm_parameter = list_entry(list_lw_value_change.next, struct cwmp_dm_parameter, list);
del_list_lw_notify(dm_parameter); del_list_lw_notify(dm_parameter);
} }
} }

3
ubus.c
View file

@ -16,7 +16,8 @@
#include <sys/file.h> #include <sys/file.h>
#include <pthread.h> #include <pthread.h>
#include <libubus.h> #include <libubus.h>
#include <json-c/json.h> #include <libubox/blobmsg_json.h>
#include "ubus.h" #include "ubus.h"
#include "session.h" #include "session.h"
#include "xml.h" #include "xml.h"