Ticket refs #921: TR-181: Device.USB. object

This commit is contained in:
Omar Kallel 2019-09-05 15:24:48 +01:00
parent f236c73ef2
commit 764f8df188
6 changed files with 1595 additions and 5 deletions

View file

@ -53,7 +53,8 @@ libbbfdm_la_SOURCES += \
../dmtree/tr181/dhcpv6.c \
../dmtree/tr181/dsl.c \
../dmtree/tr181/interfacestack.c \
../dmtree/tr181/qos.c
../dmtree/tr181/qos.c \
../dmtree/tr181/usb.c
endif
if BBF_TR104
@ -106,4 +107,4 @@ libbbfdm_la_CFLAGS+=-I../dmtree/
libbbfdm_la_CFLAGS+=-I../dmtree/tr181
libbbfdm_la_CFLAGS+=-I../dmtree/tr104
libbbfdm_la_CFLAGS+=-I../dmtree/tr143
libbbfdm_la_CFLAGS+=-I../dmtree/tr064
libbbfdm_la_CFLAGS+=-I../dmtree/tr064

View file

@ -1021,9 +1021,20 @@ struct uci_section *get_dup_section_in_dmmap(char *dmmap_package, char *section_
return NULL;
}
struct uci_section *get_dup_section_in_dmmap_eq(char *dmmap_package, char* section_type, char*sect_name, char *opt_name, char* opt_value)
struct uci_section *get_dup_section_in_dmmap_opt(char *dmmap_package, char *section_type, char *opt_name, char *opt_value)
{
struct uci_section *s;
uci_path_foreach_option_eq(bbfdm, dmmap_package, section_type, opt_name, opt_value, s)
{
return s;
}
return NULL;
}
struct uci_section *get_dup_section_in_dmmap_eq(char *dmmap_package, char* section_type, char*sect_name, char *opt_name, char* opt_value){
struct uci_section *s;
char *v;
uci_path_foreach_option_eq(bbfdm, dmmap_package, section_type, "section_name", sect_name, s) {
@ -1293,8 +1304,67 @@ bool synchronize_multi_config_sections_with_dmmap_eq_diff(char *package, char *s
return found;
}
void get_dmmap_section_of_config_section(char* dmmap_package, char* section_type, char *section_name, struct uci_section **dmmap_section)
void synchronize_system_folders_with_dmmap_opt(char *sysfsrep, char *dmmap_package, char *dmmap_section, char *opt_name, char* inst_opt, struct list_head *dup_list)
{
struct uci_section *s, *stmp, *dmmap_sect;
FILE *fp;
DIR *dir;
struct dirent *ent;
char *v, *dmmap_file_path, *sysfs_rep_path, *instance= NULL;
struct sysfs_dmsection *p;
LIST_HEAD(dup_list_no_inst);
dmasprintf(&dmmap_file_path, "/etc/bbfdm/%s", dmmap_package);
if (access(dmmap_file_path, F_OK)) {
/*
*File does not exist
**/
fp = fopen(dmmap_file_path, "w"); // new empty file
fclose(fp);
}
sysfs_foreach_file(sysfsrep, dir, ent) {
if(strcmp(ent->d_name, ".")==0 || strcmp(ent->d_name, "..")==0)
continue;
/*
* create/update corresponding dmmap section that have same config_section link and using param_value_array
*/
dmasprintf(&sysfs_rep_path, "%s/%s", sysfsrep, ent->d_name);
if ((dmmap_sect = get_dup_section_in_dmmap_opt(dmmap_package, dmmap_section, opt_name, sysfs_rep_path)) == NULL) {
dmuci_add_section_bbfdm(dmmap_package, dmmap_section, &dmmap_sect, &v);
DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, opt_name, sysfs_rep_path);
}
dmuci_get_value_by_section_string(dmmap_sect, inst_opt, &instance);
/*
* Add system and dmmap sections to the list
*/
if(instance == NULL || strlen(instance) <= 0)
add_sysfs_sectons_list_paramameter(&dup_list_no_inst, dmmap_sect, ent->d_name, sysfs_rep_path);
else
add_sysfs_sectons_list_paramameter(dup_list, dmmap_sect, ent->d_name, sysfs_rep_path);
}
/*
* fusion two lists
*/
list_for_each_entry(p, &dup_list_no_inst, list) {
add_sysfs_sectons_list_paramameter(dup_list, p->dm, p->sysfs_folder_name, p->sysfs_folder_path);
}
/*
* Delete unused dmmap sections
*/
uci_path_foreach_sections_safe(bbfdm, dmmap_package, dmmap_section, stmp, s) {
dmuci_get_value_by_section_string(s, opt_name, &v);
if(isfolderexist(v) == 0){
dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL);
}
}
}
void get_dmmap_section_of_config_section(char* dmmap_package, char* section_type, char *section_name, struct uci_section **dmmap_section){
struct uci_section* s;
uci_path_foreach_option_eq(bbfdm, dmmap_package, section_type, "section_name", section_name, s){
@ -1689,6 +1759,21 @@ char* int_period_to_date_time_format(int time)
return datetime;
}
int isfileexist(char *filepath){
if( access( filepath, F_OK ) != -1 )
return 1;
else
return 0;
}
int isfolderexist(char *folderpath){
DIR* dir = opendir(folderpath);
if (dir) {
closedir(dir);
return 1;
} else
return 0;
}
int copy_temporary_file_to_original_file(char *f1, char *f2)
{
@ -1713,3 +1798,43 @@ int copy_temporary_file_to_original_file(char *f1, char *f2)
fclose(fp);
return 1;
}
char* readFileContent(char *filepath){
char *str=NULL, *tmp= NULL, *res= NULL;
FILE *f = fopen(filepath, "rb");
int i;
if(f==NULL)
return "";
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
fseek(f, 0, SEEK_SET); //same as rewind(f);
char *filecontent = malloc(fsize + 1);
fread(filecontent, 1, fsize, f);
fclose(f);
filecontent[fsize] = 0;
return filecontent;
}
char* readFileContentAlphanum(char *filepath){
char *filecontent;
char rv = 0;
FILE *fp;
fp = fopen(filepath, "r");
if(fp==NULL)
return "";
rv = fscanf(fp, "%m[A-Za-z0-9]", &filecontent);
return filecontent;
}
void writeFileContent(const char *filepath, const char *data)
{
FILE *fp = fopen(filepath, "ab");
if (fp != NULL)
{
fputs(data, fp);
fclose(fp);
}
}

View file

@ -75,6 +75,11 @@ do { \
#define SERVERSELECTION_PATH "/usr/share/bbfdm/functions/serverselection_launch"
#define SERVERSELECTION_STOP DMCMD("/bin/sh", 2, SERVERSELECTION_PATH, "stop");
#define sysfs_foreach_file(path,dir,ent) \
if ((dir = opendir(path)) == NULL) return 0; \
while ((ent = readdir (dir)) != NULL) \
enum notification_enum {
notification_none,
notification_passive,
@ -135,6 +140,13 @@ struct dm_args
char *name;
};
struct sysfs_dmsection {
struct list_head list;
char *sysfs_folder_path;
char *sysfs_folder_name;
struct uci_section *dm;
};
void compress_spaces(char *str);
char *cut_fx(char *str, char *delimiter, int occurence);
pid_t get_pid(char *pname);
@ -184,6 +196,7 @@ void synchronize_specific_config_sections_with_dmmap_eq_no_delete(char *package,
void synchronize_specific_config_sections_with_dmmap_cont(char *package, char *section_type, char *dmmap_package,char* option_name, char* option_value, struct list_head *dup_list);
bool synchronize_multi_config_sections_with_dmmap_eq(char *package, char *section_type, char *dmmap_package, char* dmmap_section, char* option_name, char* option_value, void* additional_attribute, struct list_head *dup_list);
bool synchronize_multi_config_sections_with_dmmap_eq_diff(char *package, char *section_type, char *dmmap_package, char* dmmap_section, char* option_name, char* option_value, char* opt_diff_name, char* opt_diff_value, void* additional_attribute, struct list_head *dup_list);
void synchronize_system_folders_with_dmmap_opt(char *sysfsrep, char *dmmap_package, char *dmmap_section, char *opt_name, char* inst_opt, struct list_head *dup_list);
void get_dmmap_section_of_config_section(char* dmmap_package, char* section_type, char *section_name, struct uci_section **dmmap_section);
void get_dmmap_section_of_config_section_eq(char* dmmap_package, char* section_type, char *opt, char* value, struct uci_section **dmmap_section);
void get_config_section_of_dmmap_section(char* package, char* section_type, char *section_name, struct uci_section **config_section);
@ -209,5 +222,6 @@ char* int_period_to_date_time_format(int time);
int copy_temporary_file_to_original_file(char *f1, char *f2);
struct uci_section *is_dmmap_section_exist(char* package, char* section);
struct uci_section *is_dmmap_section_exist_eq(char* package, char* section, char* opt, char* value);
int isfileexist(char *filepath);
char* readFileContent(char *filepath);
#endif

View file

@ -48,6 +48,7 @@
#include "dhcpv6.h"
#include "interfacestack.h"
#include "qos.h"
#include "usb.h"
#ifdef BBF_TR104
#include "voice_services.h"
#endif
@ -103,6 +104,7 @@ DMOBJ tRoot_181_Obj[] = {
{"DNS", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tDNSObj, tDNSParams, NULL, BBFDM_BOTH},
{"Users", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tUsersObj, tUsersParams, NULL, BBFDM_BOTH},
{"InterfaceStack", &DMREAD, NULL, NULL, NULL, browseInterfaceStackInst, NULL, NULL, NULL, tInterfaceStackParams, NULL, BBFDM_BOTH},
{"USB", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tUSBObj, tUSBParams, NULL, BBFDM_BOTH},
//{"QoS", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tQoSObj, tQoSParams, NULL, BBFDM_BOTH},
{"XMPP", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL,tXMPPObj, tXMPPParams, NULL, BBFDM_BOTH},
{0}

1311
dmtree/tr181/usb.c Normal file

File diff suppressed because it is too large Load diff

137
dmtree/tr181/usb.h Normal file
View file

@ -0,0 +1,137 @@
/*
* 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: Omar Kallel <omar.kallel@pivasoftware.com>
*/
#ifndef __USB_H
#define __USB_H
#include <regex.h>
extern DMOBJ tUSBObj[];
extern DMLEAF tUSBParams[];
extern DMOBJ tUSBInterfaceObj[];
extern DMLEAF tUSBInterfaceParams[];
extern DMLEAF tUSBInterfaceStatsParams[];
extern DMLEAF tUSBPortParams[];
extern DMOBJ tUSBUSBHostsObj[];
extern DMLEAF tUSBUSBHostsParams[];
extern DMOBJ tUSBUSBHostsHostObj[];
extern DMLEAF tUSBUSBHostsHostParams[];
extern DMOBJ tUSBUSBHostsHostDeviceObj[];
extern DMLEAF tUSBUSBHostsHostDeviceParams[];
extern DMOBJ tUSBUSBHostsHostDeviceConfigurationObj[];
extern DMLEAF tUSBUSBHostsHostDeviceConfigurationParams[];
extern DMLEAF tUSBUSBHostsHostDeviceConfigurationInterfaceParams[];
#define SYSFS_USB_DEVICES_PATH "/sys/bus/usb/devices"
regex_t regex1, regex2;
struct usb_port {
struct uci_section *dm_usb_port;
char *folder_name;
char *folder_path;
struct uci_section *dmsect;
};
struct usb_interface {
struct uci_section *dm_usb_iface;
char *iface_name;
char *iface_path;
char *statistics_path;
char *portlink;
};
int browseUSBInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
int browseUSBPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
int browseUSBUSBHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
int browseUSBUSBHostsHostDeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
int browseUSBUSBHostsHostDeviceConfigurationInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
int browseUSBUSBHostsHostDeviceConfigurationInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
int get_USB_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USB_PortNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int set_USBInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int get_USBInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int set_USBInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int get_USBInterface_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int set_USBInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int get_USBInterface_Upstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterface_MACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterface_MaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterface_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterfaceStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterfaceStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterfaceStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterfaceStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterfaceStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterfaceStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterfaceStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterfaceStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterfaceStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterfaceStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterfaceStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterfaceStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterfaceStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterfaceStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBInterfaceStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBPort_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int set_USBPort_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int get_USBPort_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBPort_Standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBPort_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBPort_Receptacle(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBPort_Rate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBPort_Power(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHosts_HostNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHost_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int set_USBUSBHostsHost_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int get_USBUSBHostsHost_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int set_USBUSBHostsHost_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int get_USBUSBHostsHost_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHost_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHost_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int set_USBUSBHostsHost_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int get_USBUSBHostsHost_PowerManagementEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int set_USBUSBHostsHost_PowerManagementEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int get_USBUSBHostsHost_USBVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHost_DeviceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDevice_DeviceNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDevice_USBVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDevice_DeviceClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDevice_DeviceSubClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDevice_DeviceVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDevice_DeviceProtocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDevice_ProductID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDevice_VendorID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDevice_Manufacturer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDevice_ProductClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDevice_SerialNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDevice_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDevice_USBPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDevice_Rate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDevice_Parent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDevice_MaxChildren(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDevice_IsSuspended(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDevice_IsSelfPowered(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDevice_ConfigurationNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDeviceConfiguration_ConfigurationNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDeviceConfiguration_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceSubClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceProtocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_linker_usb_port(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker);
int get_linker_usb_host_device(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker);
#endif //__USB_H