From 764f8df18801814e3f13d987abbc66b82cae2d5f Mon Sep 17 00:00:00 2001
From: Omar Kallel <omar.kallel@pivasoftware.com>
Date: Thu, 5 Sep 2019 15:24:48 +0100
Subject: [PATCH] Ticket refs #921: TR-181: Device.USB. object

---
 bin/Makefile.am       |    5 +-
 dmcommon.c            |  129 +++-
 dmcommon.h            |   16 +-
 dmtree/tr181/device.c |    2 +
 dmtree/tr181/usb.c    | 1311 +++++++++++++++++++++++++++++++++++++++++
 dmtree/tr181/usb.h    |  137 +++++
 6 files changed, 1595 insertions(+), 5 deletions(-)
 create mode 100644 dmtree/tr181/usb.c
 create mode 100644 dmtree/tr181/usb.h

diff --git a/bin/Makefile.am b/bin/Makefile.am
index 70270c95a..49e973425 100644
--- a/bin/Makefile.am
+++ b/bin/Makefile.am
@@ -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
\ No newline at end of file
+libbbfdm_la_CFLAGS+=-I../dmtree/tr064
diff --git a/dmcommon.c b/dmcommon.c
index 98daf629b..ff8911cca 100644
--- a/dmcommon.c
+++ b/dmcommon.c
@@ -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);
+    }
+}
diff --git a/dmcommon.h b/dmcommon.h
index 9c82e605c..819fba095 100644
--- a/dmcommon.h
+++ b/dmcommon.h
@@ -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
diff --git a/dmtree/tr181/device.c b/dmtree/tr181/device.c
index 84adc0d98..fe399150f 100644
--- a/dmtree/tr181/device.c
+++ b/dmtree/tr181/device.c
@@ -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}
diff --git a/dmtree/tr181/usb.c b/dmtree/tr181/usb.c
new file mode 100644
index 000000000..6493c3af2
--- /dev/null
+++ b/dmtree/tr181/usb.c
@@ -0,0 +1,1311 @@
+/*
+*      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>
+*/
+
+#include "dmcwmp.h"
+#include "dmcommon.h"
+#include "usb.h"
+#include <dirent.h>
+
+/* *** Device.USB. *** */
+DMOBJ tUSBObj[] = {
+/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextobj, leaf, linker, bbfdm_type*/
+{"Interface", &DMREAD, NULL, NULL, NULL, browseUSBInterfaceInst, NULL, NULL, tUSBInterfaceObj, tUSBInterfaceParams, NULL, BBFDM_BOTH},
+{"Port", &DMREAD, NULL, NULL, NULL, browseUSBPortInst, NULL, NULL, NULL, tUSBPortParams, get_linker_usb_port, BBFDM_BOTH},
+{"USBHosts", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tUSBUSBHostsObj, tUSBUSBHostsParams, NULL, BBFDM_BOTH},
+{0}
+};
+
+DMLEAF tUSBParams[] = {
+/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
+{"InterfaceNumberOfEntries", &DMREAD, DMT_UNINT, get_USB_InterfaceNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH},
+{"PortNumberOfEntries", &DMREAD, DMT_UNINT, get_USB_PortNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH},
+{0}
+};
+
+/* *** Device.USB.Interface.{i}. *** */
+DMOBJ tUSBInterfaceObj[] = {
+/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextobj, leaf, linker, bbfdm_type*/
+{"Stats", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tUSBInterfaceStatsParams, NULL, BBFDM_BOTH},
+{0}
+};
+
+DMLEAF tUSBInterfaceParams[] = {
+/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
+{"Enable", &DMWRITE, DMT_BOOL, get_USBInterface_Enable, set_USBInterface_Enable, NULL, NULL, BBFDM_BOTH},
+{"Status", &DMREAD, DMT_STRING, get_USBInterface_Status, NULL, NULL, NULL, BBFDM_BOTH},
+{"Alias", &DMWRITE, DMT_STRING, get_USBInterface_Alias, set_USBInterface_Alias, NULL, NULL, BBFDM_BOTH},
+{"Name", &DMREAD, DMT_STRING, get_USBInterface_Name, NULL, NULL, NULL, BBFDM_BOTH},
+{"LastChange", &DMREAD, DMT_UNINT, get_USBInterface_LastChange, NULL, NULL, NULL, BBFDM_BOTH},
+{"LowerLayers", &DMWRITE, DMT_STRING, get_USBInterface_LowerLayers, set_USBInterface_LowerLayers, NULL, NULL, BBFDM_BOTH},
+{"Upstream", &DMREAD, DMT_BOOL, get_USBInterface_Upstream, NULL, NULL, NULL, BBFDM_BOTH},
+{"MACAddress", &DMREAD, DMT_STRING, get_USBInterface_MACAddress, NULL, NULL, NULL, BBFDM_BOTH},
+{"MaxBitRate", &DMREAD, DMT_UNINT, get_USBInterface_MaxBitRate, NULL, NULL, NULL, BBFDM_BOTH},
+{"Port", &DMREAD, DMT_STRING, get_USBInterface_Port, NULL, NULL, NULL, BBFDM_BOTH},
+{0}
+};
+
+/* *** Device.USB.Interface.{i}.Stats. *** */
+DMLEAF tUSBInterfaceStatsParams[] = {
+/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
+{"BytesSent", &DMREAD, DMT_UNINT, get_USBInterfaceStats_BytesSent, NULL, NULL, NULL, BBFDM_BOTH},
+{"BytesReceived", &DMREAD, DMT_UNINT, get_USBInterfaceStats_BytesReceived, NULL, NULL, NULL, BBFDM_BOTH},
+{"PacketsSent", &DMREAD, DMT_UNINT, get_USBInterfaceStats_PacketsSent, NULL, NULL, NULL, BBFDM_BOTH},
+{"PacketsReceived", &DMREAD, DMT_UNINT, get_USBInterfaceStats_PacketsReceived, NULL, NULL, NULL, BBFDM_BOTH},
+{"ErrorsSent", &DMREAD, DMT_UNINT, get_USBInterfaceStats_ErrorsSent, NULL, NULL, NULL, BBFDM_BOTH},
+{"ErrorsReceived", &DMREAD, DMT_UNINT, get_USBInterfaceStats_ErrorsReceived, NULL, NULL, NULL, BBFDM_BOTH},
+{"UnicastPacketsSent", &DMREAD, DMT_UNINT, get_USBInterfaceStats_UnicastPacketsSent, NULL, NULL, NULL, BBFDM_BOTH},
+{"UnicastPacketsReceived", &DMREAD, DMT_UNINT, get_USBInterfaceStats_UnicastPacketsReceived, NULL, NULL, NULL, BBFDM_BOTH},
+{"DiscardPacketsSent", &DMREAD, DMT_UNINT, get_USBInterfaceStats_DiscardPacketsSent, NULL, NULL, NULL, BBFDM_BOTH},
+{"DiscardPacketsReceived", &DMREAD, DMT_UNINT, get_USBInterfaceStats_DiscardPacketsReceived, NULL, NULL, NULL, BBFDM_BOTH},
+{"MulticastPacketsSent", &DMREAD, DMT_UNINT, get_USBInterfaceStats_MulticastPacketsSent, NULL, NULL, NULL, BBFDM_BOTH},
+{"MulticastPacketsReceived", &DMREAD, DMT_UNINT, get_USBInterfaceStats_MulticastPacketsReceived, NULL, NULL, NULL, BBFDM_BOTH},
+{"BroadcastPacketsSent", &DMREAD, DMT_UNINT, get_USBInterfaceStats_BroadcastPacketsSent, NULL, NULL, NULL, BBFDM_BOTH},
+{"BroadcastPacketsReceived", &DMREAD, DMT_UNINT, get_USBInterfaceStats_BroadcastPacketsReceived, NULL, NULL, NULL, BBFDM_BOTH},
+{"UnknownProtoPacketsReceived", &DMREAD, DMT_UNINT, get_USBInterfaceStats_UnknownProtoPacketsReceived, NULL, NULL, NULL, BBFDM_BOTH},
+{0}
+};
+
+/* *** Device.USB.Port.{i}. *** */
+DMLEAF tUSBPortParams[] = {
+/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
+{"Alias", &DMWRITE, DMT_STRING, get_USBPort_Alias, set_USBPort_Alias, NULL, NULL, BBFDM_BOTH},
+{"Name", &DMREAD, DMT_STRING, get_USBPort_Name, NULL, NULL, NULL, BBFDM_BOTH},
+{"Standard", &DMREAD, DMT_STRING, get_USBPort_Standard, NULL, NULL, NULL, BBFDM_BOTH},
+{"Type", &DMREAD, DMT_STRING, get_USBPort_Type, NULL, NULL, NULL, BBFDM_BOTH},
+//{"Receptacle", &DMREAD, DMT_STRING, get_USBPort_Receptacle, NULL, NULL, NULL, BBFDM_BOTH},
+{"Rate", &DMREAD, DMT_STRING, get_USBPort_Rate, NULL, NULL, NULL, BBFDM_BOTH},
+{"Power", &DMREAD, DMT_STRING, get_USBPort_Power, NULL, NULL, NULL, BBFDM_BOTH},
+{0}
+};
+
+/* *** Device.USB.USBHosts. *** */
+DMOBJ tUSBUSBHostsObj[] = {
+/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextobj, leaf, linker, bbfdm_type*/
+{"Host", &DMREAD, NULL, NULL, NULL, browseUSBUSBHostsHostInst, NULL, NULL, tUSBUSBHostsHostObj, tUSBUSBHostsHostParams, NULL, BBFDM_BOTH},
+{0}
+};
+
+DMLEAF tUSBUSBHostsParams[] = {
+/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
+{"HostNumberOfEntries", &DMREAD, DMT_UNINT, get_USBUSBHosts_HostNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH},
+{0}
+};
+
+/* *** Device.USB.USBHosts.Host.{i}. *** */
+DMOBJ tUSBUSBHostsHostObj[] = {
+/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextobj, leaf, linker, bbfdm_type*/
+{"Device", &DMREAD, NULL, NULL, NULL, browseUSBUSBHostsHostDeviceInst, NULL, NULL, tUSBUSBHostsHostDeviceObj, tUSBUSBHostsHostDeviceParams, get_linker_usb_host_device, BBFDM_BOTH},
+{0}
+};
+
+DMLEAF tUSBUSBHostsHostParams[] = {
+/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
+{"Alias", &DMWRITE, DMT_STRING, get_USBUSBHostsHost_Alias, set_USBUSBHostsHost_Alias, NULL, NULL, BBFDM_BOTH},
+{"Enable", &DMWRITE, DMT_BOOL, get_USBUSBHostsHost_Enable, set_USBUSBHostsHost_Enable, NULL, NULL, BBFDM_BOTH},
+{"Name", &DMREAD, DMT_STRING, get_USBUSBHostsHost_Name, NULL, NULL, NULL, BBFDM_BOTH},
+{"Type", &DMREAD, DMT_STRING, get_USBUSBHostsHost_Type, NULL, NULL, NULL, BBFDM_BOTH},
+{"Reset", &DMWRITE, DMT_BOOL, get_USBUSBHostsHost_Reset, set_USBUSBHostsHost_Reset, NULL, NULL, BBFDM_BOTH},
+{"PowerManagementEnable", &DMWRITE, DMT_BOOL, get_USBUSBHostsHost_PowerManagementEnable, set_USBUSBHostsHost_PowerManagementEnable, NULL, NULL, BBFDM_BOTH},
+{"USBVersion", &DMREAD, DMT_STRING, get_USBUSBHostsHost_USBVersion, NULL, NULL, NULL, BBFDM_BOTH},
+{"DeviceNumberOfEntries", &DMREAD, DMT_UNINT, get_USBUSBHostsHost_DeviceNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH},
+{0}
+};
+
+/* *** Device.USB.USBHosts.Host.{i}.Device.{i}. *** */
+DMOBJ tUSBUSBHostsHostDeviceObj[] = {
+/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextobj, leaf, linker, bbfdm_type*/
+{"Configuration", &DMREAD, NULL, NULL, NULL, browseUSBUSBHostsHostDeviceConfigurationInst, NULL, NULL, tUSBUSBHostsHostDeviceConfigurationObj, tUSBUSBHostsHostDeviceConfigurationParams, NULL, BBFDM_BOTH},
+{0}
+};
+
+DMLEAF tUSBUSBHostsHostDeviceParams[] = {
+/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
+{"DeviceNumber", &DMREAD, DMT_UNINT, get_USBUSBHostsHostDevice_DeviceNumber, NULL, NULL, NULL, BBFDM_BOTH},
+{"USBVersion", &DMREAD, DMT_STRING, get_USBUSBHostsHostDevice_USBVersion, NULL, NULL, NULL, BBFDM_BOTH},
+{"DeviceClass", &DMREAD, DMT_HEXBIN, get_USBUSBHostsHostDevice_DeviceClass, NULL, NULL, NULL, BBFDM_BOTH},
+{"DeviceSubClass", &DMREAD, DMT_HEXBIN, get_USBUSBHostsHostDevice_DeviceSubClass, NULL, NULL, NULL, BBFDM_BOTH},
+{"DeviceVersion", &DMREAD, DMT_UNINT, get_USBUSBHostsHostDevice_DeviceVersion, NULL, NULL, NULL, BBFDM_BOTH},
+{"DeviceProtocol", &DMREAD, DMT_HEXBIN, get_USBUSBHostsHostDevice_DeviceProtocol, NULL, NULL, NULL, BBFDM_BOTH},
+{"ProductID", &DMREAD, DMT_UNINT, get_USBUSBHostsHostDevice_ProductID, NULL, NULL, NULL, BBFDM_BOTH},
+{"VendorID", &DMREAD, DMT_UNINT, get_USBUSBHostsHostDevice_VendorID, NULL, NULL, NULL, BBFDM_BOTH},
+{"Manufacturer", &DMREAD, DMT_STRING, get_USBUSBHostsHostDevice_Manufacturer, NULL, NULL, NULL, BBFDM_BOTH},
+{"ProductClass", &DMREAD, DMT_STRING, get_USBUSBHostsHostDevice_ProductClass, NULL, NULL, NULL, BBFDM_BOTH},
+{"SerialNumber", &DMREAD, DMT_STRING, get_USBUSBHostsHostDevice_SerialNumber, NULL, NULL, NULL, BBFDM_BOTH},
+{"Port", &DMREAD, DMT_UNINT, get_USBUSBHostsHostDevice_Port, NULL, NULL, NULL, BBFDM_BOTH},
+{"USBPort", &DMREAD, DMT_STRING, get_USBUSBHostsHostDevice_USBPort, NULL, NULL, NULL, BBFDM_BOTH},
+{"Rate", &DMREAD, DMT_STRING, get_USBUSBHostsHostDevice_Rate, NULL, NULL, NULL, BBFDM_BOTH},
+{"Parent", &DMREAD, DMT_STRING, get_USBUSBHostsHostDevice_Parent, NULL, NULL, NULL, BBFDM_BOTH},
+{"MaxChildren", &DMREAD, DMT_UNINT, get_USBUSBHostsHostDevice_MaxChildren, NULL, NULL, NULL, BBFDM_BOTH},
+{"IsSuspended", &DMREAD, DMT_BOOL, get_USBUSBHostsHostDevice_IsSuspended, NULL, NULL, NULL, BBFDM_BOTH},
+//{"IsSelfPowered", &DMREAD, DMT_BOOL, get_USBUSBHostsHostDevice_IsSelfPowered, NULL, NULL, NULL, BBFDM_BOTH},
+{"ConfigurationNumberOfEntries", &DMREAD, DMT_UNINT, get_USBUSBHostsHostDevice_ConfigurationNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH},
+{0}
+};
+
+/* *** Device.USB.USBHosts.Host.{i}.Device.{i}.Configuration.{i}. *** */
+DMOBJ tUSBUSBHostsHostDeviceConfigurationObj[] = {
+/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextobj, leaf, linker, bbfdm_type*/
+{"Interface", &DMREAD, NULL, NULL, NULL, browseUSBUSBHostsHostDeviceConfigurationInterfaceInst, NULL, NULL, NULL, tUSBUSBHostsHostDeviceConfigurationInterfaceParams, NULL, BBFDM_BOTH},
+{0}
+};
+
+DMLEAF tUSBUSBHostsHostDeviceConfigurationParams[] = {
+/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
+{"ConfigurationNumber", &DMREAD, DMT_UNINT, get_USBUSBHostsHostDeviceConfiguration_ConfigurationNumber, NULL, NULL, NULL, BBFDM_BOTH},
+{"InterfaceNumberOfEntries", &DMREAD, DMT_UNINT, get_USBUSBHostsHostDeviceConfiguration_InterfaceNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH},
+{0}
+};
+
+/* *** Device.USB.USBHosts.Host.{i}.Device.{i}.Configuration.{i}.Interface.{i}. *** */
+DMLEAF tUSBUSBHostsHostDeviceConfigurationInterfaceParams[] = {
+/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
+{"InterfaceNumber", &DMREAD, DMT_UNINT, get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceNumber, NULL, NULL, NULL, BBFDM_BOTH},
+{"InterfaceClass", &DMREAD, DMT_HEXBIN, get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceClass, NULL, NULL, NULL, BBFDM_BOTH},
+{"InterfaceSubClass", &DMREAD, DMT_HEXBIN, get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceSubClass, NULL, NULL, NULL, BBFDM_BOTH},
+{"InterfaceProtocol", &DMREAD, DMT_HEXBIN, get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceProtocol, NULL, NULL, NULL, BBFDM_BOTH},
+{0}
+};
+
+/*************************************************************
+ * INIT
+/*************************************************************/
+void init_usb_port(struct uci_section *dm, char *folder_name, char *folder_path, struct usb_port *port){
+	port->dm_usb_port= dm;
+	port->folder_name= dmstrdup(folder_name);
+	port->folder_path= dmstrdup(folder_path);
+}
+
+void init_usb_interface(struct uci_section *dm, char *iface_name, char *iface_path, char *statistics_path, char *portlink, struct usb_interface *iface){
+	iface->dm_usb_iface= dm;
+	iface->iface_name= dmstrdup(iface_name);
+	iface->iface_path= dmstrdup(iface_path);
+	iface->portlink= dmstrdup(portlink);
+	iface->statistics_path= dmstrdup(statistics_path);
+}
+
+void add_sysfs_sectons_list_paramameter(struct list_head *dup_list, struct uci_section *dmmap_section, char *file_name, char* filepath)
+{
+	struct sysfs_dmsection *dmmap_sysfs;
+	struct list_head *ilist;
+
+	dmmap_sysfs = dmcalloc(1, sizeof(struct sysfs_dmsection));
+	list_add_tail(&dmmap_sysfs->list, dup_list);
+	dmmap_sysfs->dm = dmmap_section;
+	dmmap_sysfs->sysfs_folder_name= dmstrdup(file_name);
+	dmmap_sysfs->sysfs_folder_path= dmstrdup(filepath);
+}
+
+/*************************************************************
+ * ENTRY METHOD
+/*************************************************************/
+int browseUSBInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
+{
+	DIR *dir;
+	struct dirent *ent;
+    char *netfolderpath, *iface_name, *iface_path, *statistics_path, *port_link, *v, *instnbr, *instance;
+    size_t length;
+    char **foldersplit;
+    struct uci_section *s;
+    struct usb_interface iface= {};
+    LIST_HEAD(dup_list);
+    struct sysfs_dmsection *p;
+
+    synchronize_system_folders_with_dmmap_opt(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_interface", "port_link", "usb_iface_instance", &dup_list);
+    list_for_each_entry(p, &dup_list, list) {
+		dmasprintf(&netfolderpath, "%s/%s/net", SYSFS_USB_DEVICES_PATH, p->sysfs_folder_name);
+		if(!isfolderexist(netfolderpath)){
+			//dmuci_delete_by_section_unnamed_bbfdm(p->dm, NULL, NULL);
+			continue;
+		}
+		if(p->dm){
+			foldersplit= strsplit(p->sysfs_folder_name, ":", &length);
+			dmasprintf(&port_link, "%s", foldersplit[0]);
+			DMUCI_SET_VALUE_BY_SECTION(bbfdm, p->dm, "port_link", port_link);
+		}
+		sysfs_foreach_file(netfolderpath, dir, ent){
+			if(strcmp(ent->d_name, ".")==0 || strcmp(ent->d_name, "..")==0)
+				continue;
+			dmasprintf(&iface_name, "%s", ent->d_name);
+			break;
+		}
+		dmasprintf(&iface_path, "%s/%s", netfolderpath, iface_name);
+		dmasprintf(&statistics_path, "%s/statistics", iface_path);
+		init_usb_interface(p->dm, iface_name, iface_path, statistics_path, port_link, &iface);
+		instance =  handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, p->dm, "usb_iface_instance", "usb_iface_alias");
+		if (DM_LINK_INST_OBJ(dmctx, parent_node, &iface, instance) == DM_STOP)
+			return 0;
+    }
+    free_dmmap_config_dup_list(&dup_list);
+    return 0;
+}
+
+int browseUSBPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
+{
+	int ret1, ret2;
+	char *folderpath, *instnbr, *instance, *v;
+	struct uci_section *s;
+	struct usb_port port= {};
+	LIST_HEAD(dup_list);
+	struct sysfs_dmsection *p;
+
+    ret1= regcomp(&regex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0);
+    ret2= regcomp(&regex2, "^[0-9][0-9]*-[0-9]*[0-9]\.[0-9]*[0-9]$", 0);
+    check_create_dmmap_package("dmmap_usb");
+    synchronize_system_folders_with_dmmap_opt(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_port", "port_link", "usb_port_instance", &dup_list);
+    list_for_each_entry(p, &dup_list, list) {
+		if(regexec(&regex1, p->sysfs_folder_name, 0, NULL, 0) != 0 && regexec(&regex2, p->sysfs_folder_name, 0, NULL, 0) !=0 && strstr(p->sysfs_folder_name, "usb") != p->sysfs_folder_name){
+			dmuci_delete_by_section_unnamed_bbfdm(p->dm, NULL, NULL);
+			continue;
+		}
+		init_usb_port(p->dm, p->sysfs_folder_name, p->sysfs_folder_path, &port);
+
+		instance =  handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, p->dm, "usb_port_instance", "usb_port_alias");
+		if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, instance) == DM_STOP)
+			return 0;
+	}
+    free_dmmap_config_dup_list(&dup_list);
+    return 0;
+}
+
+int browseUSBUSBHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
+{
+	DIR *dir;
+	struct dirent *ent;
+	LIST_HEAD(dup_list);
+	struct sysfs_dmsection *p;
+	char *instance, *instnbr;
+	struct usb_port port= {};
+
+	check_create_dmmap_package("dmmap_usb");
+	synchronize_system_folders_with_dmmap_opt(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_host", "port_link", "usb_host_instance", &dup_list);
+	list_for_each_entry(p, &dup_list, list) {
+		if(strstr(p->sysfs_folder_name, "usb") != p->sysfs_folder_name){
+			dmuci_delete_by_section_unnamed_bbfdm(p->dm, NULL, NULL);
+			continue;
+		}
+		init_usb_port(p->dm, p->sysfs_folder_name, p->sysfs_folder_path, &port);
+		port.dmsect= p->dm;
+		instance =  handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, p->dm, "usb_host_instance", "usb_host_alias");
+		if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, instance) == DM_STOP)
+			return 0;
+	}
+	free_dmmap_config_dup_list(&dup_list);
+	return 0;
+}
+
+void synchronize_usb_devices_with_dmmap_opt_recursively(char *sysfsrep, char *dmmap_package, char *dmmap_section, char *opt_name, char* inst_opt, int is_root, 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;
+	int ret1, ret2;
+	char *deviceClassFile= NULL, *deviceClass= NULL, *hubpath;
+
+	ret1= regcomp(&regex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0);
+	ret2= regcomp(&regex2, "^[0-9][0-9]*-[0-9]*[0-9]\.[0-9]*[0-9]$", 0);
+
+	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;
+		if(regexec(&regex1, ent->d_name, 0, NULL, 0) == 0 || regexec(&regex2, ent->d_name, 0, NULL, 0) ==0){
+			dmasprintf(&deviceClassFile, "%s/%s/bDeviceClass", sysfsrep, ent->d_name);
+			deviceClass= readFileContent(deviceClassFile);
+			if(strncmp(deviceClass, "09", 2) == 0){
+				dmasprintf(&hubpath, "%s/%s", sysfsrep, ent->d_name);
+				synchronize_usb_devices_with_dmmap_opt_recursively(hubpath, dmmap_package, dmmap_section, opt_name, inst_opt, 0, dup_list);
+			}
+			/*
+			 * 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
+	 */
+	if(is_root){
+		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);
+			}
+		}
+	}
+}
+
+int browseUSBUSBHostsHostDeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
+{
+	DIR *dir;
+	struct dirent *ent;
+	LIST_HEAD(dup_list);
+	struct sysfs_dmsection *p;
+	char *instance, *instnbr;
+	struct usb_port port= {};
+	struct usb_port *prev_port= (struct usb_port *)prev_data;
+	check_create_dmmap_package("dmmap_usb");
+	synchronize_usb_devices_with_dmmap_opt_recursively(prev_port->folder_path, "dmmap_usb", "dmmap_host_device", "port_link", "usb_host_device_instance", 1, &dup_list);
+	list_for_each_entry(p, &dup_list, list) {
+		init_usb_port(p->dm, p->sysfs_folder_name, p->sysfs_folder_path, &port);
+		port.dmsect= prev_port->dmsect;
+		instance =  handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, p->dm, "usb_host_device_instance", "usb_host_device_alias");
+		if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, instance) == DM_STOP)
+			return 0;
+	}
+	return 0;
+}
+
+int browseUSBUSBHostsHostDeviceConfigurationInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
+{
+	struct usb_port *usb_dev= (struct usb_port*)prev_data;
+	struct usb_port port= {};
+	struct uci_section *s;
+	char *v, *instance, *instnbr = NULL, *nbre;
+	char *filepath= NULL;
+	dmasprintf(&filepath, "%s/bNumConfigurations", usb_dev->folder_path);
+	nbre= readFileContent(filepath);
+	if(nbre[0] == '0')
+		return 0;
+	check_create_dmmap_package("dmmap_usb");
+	s=is_dmmap_section_exist("dmmap_usb", "usb_device_conf");
+	if(!s)
+		dmuci_add_section_bbfdm("dmmap_usb", "usb_device_conf", &s, &v);
+
+	init_usb_port(s, usb_dev->folder_name, usb_dev->folder_path, &port);
+	instance =  handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, s, "usb_device_conf_instance", "usb_device_conf_alias");
+
+	DM_LINK_INST_OBJ(dmctx, parent_node, &port, "1");
+	return 0;
+}
+
+int browseUSBUSBHostsHostDeviceConfigurationInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
+{
+	DIR *dir;
+	struct dirent *ent;
+	struct usb_port *usb_dev= (struct usb_port*)prev_data;
+	struct usb_port port= {};
+	int ret1, ret2;
+	char *sysfs_rep_path, *v, *instance, *instnbr = NULL;
+	struct uci_section *dmmap_sect;
+	ret1= regcomp(&regex1, "^[0-9][0-9]*-[0-9]*[0-9]:[0-9][0-9]*\.[0-9]*[0-9]$", 0);
+	ret2= regcomp(&regex2, "^[0-9][0-9]*-[0-9]*[0-9]\.[0-9]*[0-9]:[0-9][0-9]*\.[0-9]*[0-9]$", 0);
+	check_create_dmmap_package("dmmap_usb");
+	sysfs_foreach_file(usb_dev->folder_path, dir, ent) {
+		if(strcmp(ent->d_name, ".")==0 || strcmp(ent->d_name, "..")==0)
+			continue;
+		if(regexec(&regex1, ent->d_name, 0, NULL, 0) == 0 || regexec(&regex2, ent->d_name, 0, NULL, 0) ==0){
+			dmasprintf(&sysfs_rep_path, "%s/%s", usb_dev->folder_path, ent->d_name);
+			if ((dmmap_sect = get_dup_section_in_dmmap_opt("dmmap_usb", "usb_device_conf_interface", "port_link", sysfs_rep_path)) == NULL) {
+				dmuci_add_section_bbfdm("dmmap_usb", "usb_device_conf_interface", &dmmap_sect, &v);
+				DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "port_link", sysfs_rep_path);
+			}
+
+			init_usb_port(dmmap_sect, ent->d_name, sysfs_rep_path, &port);
+			instance =  handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "usb_device_conf_iface_instance", "usb_device_conf_iface_alias");
+			if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, instance) == DM_STOP)
+				return 0;
+		}
+	}
+	return 0;
+}
+
+/*************************************************************
+ * GET & SET PARAM
+/*************************************************************/
+int get_USB_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	DIR *dir;
+	struct dirent *ent;
+	char filename[100];
+	char *buffer= NULL;
+	int size = 100;
+	int nbre= 0;
+
+	if ((dir = opendir ("/sys/class/net")) == NULL)
+		return 0;
+	while ((ent = readdir (dir)) != NULL) {
+		buffer= (char*)malloc(100*sizeof(char));
+		sprintf(filename, "/sys/class/net/%s", ent->d_name);
+		readlink (filename, buffer, size);
+		if(strstr(buffer, "/usb") == NULL)
+			continue;
+		nbre++;
+	}
+	dmasprintf(value, "%d", nbre);
+	return 0;
+}
+
+int get_USB_PortNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	DIR *dir;
+	struct dirent *ent;
+	int ret1, ret2, i, nbre= 0;
+
+    ret1= regcomp(&regex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0);
+    ret2= regcomp(&regex2, "^[0-9][0-9]*-[0-9]*[0-9]\.[0-9]*[0-9]$", 0);
+
+
+	sysfs_foreach_file(SYSFS_USB_DEVICES_PATH, dir, ent) {
+		if(regexec(&regex1, ent->d_name, 0, NULL, 0) == 0 || regexec(&regex2, ent->d_name, 0, NULL, 0) ==0 || strstr(ent->d_name, "usb") == ent->d_name)
+			nbre++;
+	}
+	dmasprintf(value, "%d", nbre);
+
+	return 0;
+}
+
+int get_USBInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_interface *usbiface= (struct usb_interface *)data;
+	char *filepath= NULL, *carrier;
+	dmasprintf(&filepath, "%s/carrier", usbiface->iface_path);
+	if(!isfileexist(filepath)){
+		*value= "0";
+		return 0;
+	}
+	carrier= readFileContent(filepath);
+	*value= carrier[0]=='0'?"0":"1";
+	return 0;
+}
+
+int set_USBInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
+{
+	switch (action)	{
+		case VALUECHECK:
+			break;
+		case VALUESET:
+			//TODO
+			break;
+	}
+	return 0;
+}
+
+int get_USBInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_interface *usbiface= (struct usb_interface *)data;
+	char *filepath= NULL, *carrier;
+	dmasprintf(&filepath, "%s/carrier", usbiface->iface_path);
+	carrier= readFileContent(filepath);
+	*value= carrier[0]=='0'?"Down":"Up";
+	return 0;
+}
+
+int get_USBInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_interface *usbiface= (struct usb_interface *)data;
+	dmuci_get_value_by_section_string(usbiface->dm_usb_iface, "usb_iface_alias", value);
+	return 0;
+}
+
+int set_USBInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
+{
+	struct usb_interface *usbiface= (struct usb_interface *)data;
+	switch (action)	{
+		case VALUECHECK:
+			break;
+		case VALUESET:
+			DMUCI_SET_VALUE_BY_SECTION(bbfdm, usbiface->dm_usb_iface, "usb_iface_alias", value);
+			break;
+	}
+	return 0;
+}
+
+int get_USBInterface_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_interface *usbiface= (struct usb_interface *)data;
+	dmasprintf(value, "%s", usbiface->iface_name);
+	return 0;
+}
+
+int get_USBInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	//TODO
+	return 0;
+}
+
+int get_USBInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_interface *iface= (struct usb_interface *)data;
+	adm_entry_get_linker_param(ctx, dm_print_path("%s%Ethernet%Interface%c", dmroot, dm_delim, dm_delim, dm_delim), iface->iface_name, value);
+	return 0;
+}
+
+int set_USBInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
+{
+	switch (action)	{
+		case VALUECHECK:
+			break;
+		case VALUESET:
+			//TODO
+			break;
+	}
+	return 0;
+}
+
+int get_USBInterface_Upstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	//TODO
+	return 0;
+}
+
+int get_USBInterface_MACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_interface *usbiface= (struct usb_interface *)data;
+	char *filepath= NULL;
+	dmasprintf(&filepath, "%s/address", usbiface->iface_path);
+	*value= readFileContent(filepath);
+	return 0;
+}
+
+int get_USBInterface_MaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_interface *usbiface= (struct usb_interface *)data;
+	char *filepath= NULL;
+	dmasprintf(&filepath, "%s/queues/tx-0/tx_maxrate", usbiface->iface_path);
+	*value= readFileContent(filepath);
+	return 0;
+}
+
+int get_USBInterface_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	//TODO
+	return 0;
+}
+
+int get_USBInterfaceStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_interface *usbiface= (struct usb_interface *)data;
+	char *filepath= NULL;
+	dmasprintf(&filepath, "%s/tx_bytes", usbiface->statistics_path);
+	*value= readFileContent(filepath);
+	return 0;
+}
+
+int get_USBInterfaceStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_interface *usbiface= (struct usb_interface *)data;
+	char *filepath= NULL;
+	dmasprintf(&filepath, "%s/rx_bytes", usbiface->statistics_path);
+	*value= readFileContent(filepath);
+	return 0;
+}
+
+int get_USBInterfaceStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_interface *usbiface= (struct usb_interface *)data;
+	char *filepath= NULL;
+	dmasprintf(&filepath, "%s/tx_packets", usbiface->statistics_path);
+	*value= readFileContent(filepath);
+	return 0;
+}
+
+int get_USBInterfaceStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_interface *usbiface= (struct usb_interface *)data;
+	char *filepath= NULL;
+	dmasprintf(&filepath, "%s/rx_packets", usbiface->statistics_path);
+	*value= readFileContent(filepath);
+	return 0;
+}
+
+int get_USBInterfaceStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_interface *usbiface= (struct usb_interface *)data;
+	char *filepath= NULL;
+	dmasprintf(&filepath, "%s/tx_errors", usbiface->statistics_path);
+	*value= readFileContent(filepath);
+	return 0;
+}
+
+int get_USBInterfaceStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_interface *usbiface= (struct usb_interface *)data;
+	char *filepath= NULL;
+	dmasprintf(&filepath, "%s/rx_errors", usbiface->statistics_path);
+	*value= readFileContent(filepath);
+	return 0;
+}
+
+int get_USBInterfaceStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_interface *usbiface= (struct usb_interface *)data;
+	dmasprintf(value, "%d", get_stats_from_ifconfig_command(usbiface->iface_name, "TX", "unicast"));
+	return 0;
+}
+
+int get_USBInterfaceStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_interface *usbiface= (struct usb_interface *)data;
+	dmasprintf(value, "%d", get_stats_from_ifconfig_command(usbiface->iface_name, "RX", "unicast"));
+	return 0;
+}
+
+int get_USBInterfaceStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_interface *usbiface= (struct usb_interface *)data;
+	char *filepath= NULL;
+	dmasprintf(&filepath, "%s/tx_dropped", usbiface->statistics_path);
+	*value= readFileContent(filepath);
+	return 0;
+}
+
+int get_USBInterfaceStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_interface *usbiface= (struct usb_interface *)data;
+	char *filepath= NULL;
+	dmasprintf(&filepath, "%s/rx_dropped", usbiface->statistics_path);
+	*value= readFileContent(filepath);
+	return 0;
+}
+
+int get_USBInterfaceStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_interface *usbiface= (struct usb_interface *)data;
+	dmasprintf(value, "%d", get_stats_from_ifconfig_command(usbiface->iface_name, "TX", "multicast"));
+	return 0;
+}
+
+int get_USBInterfaceStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_interface *usbiface= (struct usb_interface *)data;
+	dmasprintf(value, "%d", get_stats_from_ifconfig_command(usbiface->iface_name, "RX", "multicast"));
+	return 0;
+}
+
+int get_USBInterfaceStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_interface *usbiface= (struct usb_interface *)data;
+	dmasprintf(value, "%d", get_stats_from_ifconfig_command(usbiface->iface_name, "TX", "broadcast"));
+	return 0;
+}
+
+int get_USBInterfaceStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_interface *usbiface= (struct usb_interface *)data;
+	dmasprintf(value, "%d", get_stats_from_ifconfig_command(usbiface->iface_name, "RX", "broadcast"));
+	return 0;
+}
+
+int get_USBInterfaceStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	//TODO
+	return 0;
+}
+
+int get_USBPort_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port* port=(struct usb_port *)data;
+	dmuci_get_value_by_section_string(port->dm_usb_port, "usb_port_alias", value);
+	return 0;
+}
+
+int set_USBPort_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
+{
+	struct usb_port* port=(struct usb_port *)data;
+	switch (action)	{
+		case VALUECHECK:
+			break;
+		case VALUESET:
+			dmuci_set_value_by_section(port->dm_usb_port, "usb_port_alias", value);
+			break;
+	}
+	return 0;
+}
+
+int get_USBPort_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port* port=(struct usb_port *)data;
+	*value= dmstrdup(port->folder_name);
+	return 0;
+}
+
+int get_USBPort_Standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port* port= (struct usb_port *) data;
+	char *filepath= NULL, *bcddev, *strhex;
+
+	dmasprintf(&filepath, "%s/bcdDevice", port->folder_path);
+	bcddev= readFileContent(filepath);
+	int bcdusb = (int)strtol(bcddev, NULL, 16);
+	dmasprintf(&strhex, "%04X", bcdusb);
+	dmasprintf(value, "%c.%c", strhex[1], strhex[2]);
+	return 0;
+}
+
+int get_USBPort_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port *port= (struct usb_port *)data;
+	char *filepath= NULL, *deviceclass;
+	dmasprintf(&filepath, "%s/bDeviceClass", port->folder_path);
+	deviceclass= readFileContent(filepath);
+	if(strstr(port->folder_name,"usb") == port->folder_name)
+		*value= "Host";
+	else if(strcmp(deviceclass, "09") ==0)
+		*value= "Hub";
+	else
+		*value= "Device";
+	return 0;
+}
+
+int get_USBPort_Receptacle(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	return 0;
+}
+
+int get_USBPort_Rate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port *port= (struct usb_port *)data;
+	char *filepath= NULL, *speed;
+	dmasprintf(&filepath, "%s/speed", port->folder_path);
+	speed= readFileContent(filepath);
+	if(strcmp(speed, "1.5") == 0)
+		*value= "Low";
+	else if(strcmp(speed, "12") == 0)
+		*value= "Full";
+	else if(strcmp(speed, "480") == 0)
+		*value= "High";
+	else
+		*value= "Super";
+	return 0;
+}
+
+int get_USBPort_Power(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port *port= (struct usb_port *)data;
+	char *filepath= NULL, *folderpath= NULL, *powercontrol;
+
+	dmasprintf(&folderpath, "%s/power", port->folder_path);
+	if(!isfolderexist(folderpath))
+	{
+		*value= "";
+		return 0;
+	}
+	dmasprintf(&filepath, "%s/power/control", port->folder_path);
+	powercontrol= readFileContent(filepath);
+	if(strcmp(powercontrol, "auto") == 0)
+		*value="Self";
+	else
+		*value="Bus";
+	return 0;
+}
+
+int get_USBUSBHosts_HostNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	DIR *dir;
+	struct dirent *ent;
+
+	int ret, i, nbre= 0;
+
+	sysfs_foreach_file(SYSFS_USB_DEVICES_PATH, dir, ent) {
+		if(strstr(ent->d_name, "usb") == ent->d_name)
+			nbre++;
+	}
+	dmasprintf(value, "%d", nbre);
+	return 0;
+}
+
+int get_USBUSBHostsHost_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port* port=(struct usb_port *)data;
+	dmuci_get_value_by_section_string(port->dm_usb_port, "usb_host_alias", value);
+	return 0;
+}
+
+int set_USBUSBHostsHost_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
+{
+	struct usb_port* port=(struct usb_port *)data;
+	switch (action)	{
+		case VALUECHECK:
+			break;
+		case VALUESET:
+			dmuci_set_value_by_section(port->dm_usb_port, "usb_host_alias", value);
+			break;
+	}
+	return 0;
+}
+
+int get_USBUSBHostsHost_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port *usbhost= (struct usb_port *)data;
+	char *filepath= NULL, *up;
+	dmasprintf(&filepath, "%s/power/wakeup", usbhost->folder_path);
+	up= readFileContent(filepath);
+	*value= strcmp(up, "enabled") == 0 ?"1":"0";
+	return 0;
+}
+
+int set_USBUSBHostsHost_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
+{
+	struct usb_port *usbhost= (struct usb_port *)data;
+	bool b;
+	char *filepath;
+
+	switch (action)	{
+		case VALUECHECK:
+			break;
+		case VALUESET:
+			string_to_bool(value, &b);
+			dmasprintf(&filepath, "%s/power/wakeup", usbhost->folder_path);
+			if(b)
+				writeFileContent(usbhost->folder_path, "enabled");
+			else
+				writeFileContent(usbhost->folder_path, "disabled");
+			break;
+	}
+	return 0;
+}
+
+int get_USBUSBHostsHost_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port* port=(struct usb_port *)data;
+	dmasprintf(value, "%s", port->folder_name);
+	return 0;
+}
+
+int get_USBUSBHostsHost_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port *host= (struct usb_port *)data;
+	char *filepath= NULL, *serial;
+	dmasprintf(&filepath, "%s/serial", host->folder_path);
+	serial= readFileContent(filepath);
+	if(strcasestr(serial, "ohci")!=NULL)
+		*value= "OHCI";
+	else if(strcasestr(serial, "ehci")!=NULL)
+		*value= "EHCI";
+	else if(strcasestr(serial, "uhci")!=NULL)
+		*value= "UHCI";
+	else
+		*value= "xHCI";
+	return 0;
+}
+
+int get_USBUSBHostsHost_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	*value= "false";
+	return 0;
+}
+
+int set_USBUSBHostsHost_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
+{
+	switch (action)	{
+		case VALUECHECK:
+			break;
+		case VALUESET:
+			//TODO
+			break;
+	}
+	return 0;
+}
+
+int get_USBUSBHostsHost_PowerManagementEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port *host= (struct usb_port *)data;
+	char *filepath= NULL, *power;
+	dmasprintf(&filepath, "%s/power/level", host->folder_path);
+	if(!isfileexist(filepath)){
+		*value= "false";
+		return 0;
+	}
+	power= readFileContent(filepath);
+	if(strcmp(power, "suspend") == 0)
+		*value= "false";
+	else
+		*value= "true";
+
+	return 0;
+}
+
+int set_USBUSBHostsHost_PowerManagementEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
+{
+	struct usb_port *host= (struct usb_port *)data;
+	bool b;
+
+	switch (action)	{
+		case VALUECHECK:
+			if (string_to_bool(value, &b))
+				return FAULT_9007;
+			return 0;
+		case VALUESET:
+			string_to_bool(value, &b);
+			char *filepath;
+			dmasprintf(&filepath, "%s/power/level", host->folder_path);
+			if (!isfileexist(filepath))
+				break;
+			writeFileContent(filepath, b?"on":"suspend");
+			break;
+	}
+	return 0;
+}
+
+int get_USBUSBHostsHost_USBVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port *usbhost= (struct usb_port *)data;
+	char *strhex, *filepath= NULL;
+
+	dmasprintf(&filepath, "%s/bcdDevice", usbhost->folder_path);
+	strhex= readFileContent(filepath);
+
+	dmasprintf(value, "%c.%c", strhex[1], strhex[2]);
+	return 0;
+}
+
+void get_number_devices(char *folderpath, int *nbre){
+	DIR *dir;
+	struct dirent *ent;
+	int ret1, ret2;
+	char *deviceClassFile= NULL, *deviceClass= NULL, *hubpath;
+
+	ret1= regcomp(&regex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0);
+	ret2= regcomp(&regex2, "^[0-9][0-9]*-[0-9]*[0-9]\.[0-9]*[0-9]$", 0);
+
+	sysfs_foreach_file(folderpath, dir, ent){
+		if(regexec(&regex1, ent->d_name, 0, NULL, 0) == 0 || regexec(&regex2, ent->d_name, 0, NULL, 0) ==0){
+			dmasprintf(&deviceClassFile, "%s/%s/bDeviceClass", folderpath, ent->d_name);
+			deviceClass= readFileContent(deviceClassFile);
+			if(strncmp(deviceClass, "09", 2) == 0){
+				dmasprintf(&hubpath, "%s/%s", folderpath, ent->d_name);
+				get_number_devices(hubpath, nbre);
+			}
+			(*nbre)++;
+		}
+	}
+}
+
+int get_USBUSBHostsHost_DeviceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port* usb_host= (struct usb_port *) data;
+	int dev_nbre= 0;
+
+	get_number_devices(usb_host->folder_path, &dev_nbre);
+	dmasprintf(value, "%d", dev_nbre);
+	return 0;
+}
+
+int get_USBUSBHostsHostDevice_DeviceNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port *usbdev= (struct usb_port *)data;
+	size_t length;
+	char **filename= strsplit(usbdev->folder_name, "-", &length);
+	char **port= strsplit(filename[1], ".", &length);
+	dmasprintf(value ,"%s", port[0]);
+	return 0;
+}
+
+int get_USBUSBHostsHostDevice_USBVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port* usbdev= (struct usb_port *) data;
+	char *strhex, *filepath;
+
+	dmasprintf(&filepath,"%s/bcdDevice", usbdev->folder_path);
+	strhex= readFileContentAlphanum(filepath);
+	dmasprintf(value, "%c.%c", strhex[1], strhex[2]);
+	return 0;
+}
+
+int get_USBUSBHostsHostDevice_DeviceClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port* usbdev= (struct usb_port *) data;
+	char *bDevCls, *filepath;
+
+	dmasprintf(&filepath,"%s/bDeviceClass", usbdev->folder_path);
+	bDevCls= readFileContent(filepath);
+
+	dmasprintf(value, "%c%c", bDevCls[0], bDevCls[1]);
+	return 0;
+}
+
+int get_USBUSBHostsHostDevice_DeviceSubClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port* usbdev= (struct usb_port *) data;
+	char *bDevCls, *filepath;
+
+	dmasprintf(&filepath,"%s/bDeviceSubClass", usbdev->folder_path);
+	bDevCls= readFileContentAlphanum(filepath);
+
+	dmasprintf(value, "%c%c", bDevCls[0], bDevCls[1]);
+
+	return 0;
+}
+
+int get_USBUSBHostsHostDevice_DeviceVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	//TODO
+	return 0;
+}
+
+int get_USBUSBHostsHostDevice_DeviceProtocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port* usbdev= (struct usb_port *) data;
+	char *bDevProto, *filepath;
+
+	dmasprintf(&filepath,"%s/bDeviceProtocol", usbdev->folder_path);
+	bDevProto= readFileContentAlphanum(filepath);
+
+	dmasprintf(value, "%c%c", bDevProto[0], bDevProto[1]);
+
+	return 0;
+}
+
+int get_USBUSBHostsHostDevice_ProductID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port* usbdev= (struct usb_port *) data;
+	char *idProd, *filepath;
+
+	dmasprintf(&filepath,"%s/idProduct", usbdev->folder_path);
+	idProd= readFileContentAlphanum(filepath);
+
+	dmasprintf(value, "%c%c%c%c", idProd[0], idProd[1], idProd[2], idProd[3]);
+	return 0;
+}
+
+int get_USBUSBHostsHostDevice_VendorID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port* usbdev= (struct usb_port *) data;
+	char *idVendor, *filepath;
+
+	dmasprintf(&filepath,"%s/idVendor", usbdev->folder_path);
+	idVendor= readFileContentAlphanum(filepath);
+
+	dmasprintf(value, "%c%c%c%c", idVendor[0], idVendor[1], idVendor[2], idVendor[3]);
+	return 0;
+}
+
+int get_USBUSBHostsHostDevice_Manufacturer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port* usbdev= (struct usb_port *) data;
+	char *filepath;
+
+	dmasprintf(&filepath,"%s/manufacturer", usbdev->folder_path);
+	*value= readFileContentAlphanum(filepath);
+	return 0;
+}
+
+int get_USBUSBHostsHostDevice_ProductClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port* usbdev= (struct usb_port *) data;
+	char *filepath;
+
+	dmasprintf(&filepath,"%s/product", usbdev->folder_path);
+	*value= readFileContentAlphanum(filepath);
+	return 0;
+}
+
+int get_USBUSBHostsHostDevice_SerialNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port* usbdev= (struct usb_port *) data;
+	char *filepath;
+
+	dmasprintf(&filepath,"%s/urbnum", usbdev->folder_path);
+	*value= readFileContentAlphanum(filepath);
+	return 0;
+}
+
+int get_USBUSBHostsHostDevice_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port *port= (struct usb_port *)data;
+	int ret1, ret2, length;
+	char **busname, **portname;
+
+	ret1= regcomp(&regex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0);
+	ret2= regcomp(&regex2, "^[0-9][0-9]*-[0-9]*[0-9]\.[0-9]*[0-9]$", 0);
+	if(regexec(&regex1, port->folder_name, 0, NULL, 0) == 0 || regexec(&regex2, port->folder_name, 0, NULL, 0) ==0){
+		busname= strsplit(port->folder_name, "-", &length);
+		portname= strsplit(busname[1], ".", &length);
+		*value= strdup(portname[0]);
+		return 0;
+	}
+	*value= "0";
+	return 0;
+}
+
+int get_USBUSBHostsHostDevice_USBPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port *port= (struct usb_port *)data;
+	adm_entry_get_linker_param(ctx, dm_print_path("%s%cUSB%cPort%c", dmroot, dm_delim, dm_delim, dm_delim), port->folder_name, value);
+	return 0;
+}
+
+int get_USBUSBHostsHostDevice_Rate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port *port= (struct usb_port *)data;
+	char *filepath= NULL, *speed;
+	dmasprintf(&filepath, "%s/speed", port->folder_path);
+	speed= readFileContentAlphanum(filepath);
+	if(strcmp(speed, "1.5") == 0)
+		*value= "Low";
+	else if(strcmp(speed, "12") == 0)
+		*value= "Full";
+	else if(strcmp(speed, "480") == 0)
+		*value= "High";
+	else
+		*value= "Super";
+	return 0;
+}
+
+int get_USBUSBHostsHostDevice_Parent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port *port= (struct usb_port*)data;
+	int ret1;
+	char *v;
+	ret1= regcomp(&regex1, "^[0-9][0-9]*-[0-9]*[0-9]\.[0-9]*[0-9]$", 0);
+
+	if(regexec(&regex1, port->folder_name, 0, NULL, 0) != 0 || port->dmsect == NULL){
+		*value= "";
+		return 0;
+	}
+	dmuci_get_value_by_section_string(port->dmsect, "usb_host_instance", &v);
+	adm_entry_get_linker_param(ctx, dm_print_path("%s%cUSB%cUSBHosts%cHost%c%s%vDevice%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim, v, dm_delim, dm_delim), port->folder_name, value);
+	return 0;
+}
+
+int get_USBUSBHostsHostDevice_MaxChildren(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port *port= (struct usb_port *)data;
+	char *filepath= NULL, *maxchild;
+	dmasprintf(&filepath, "%s/maxchild", port->folder_path);
+	maxchild= readFileContentAlphanum(filepath);
+	return 0;
+}
+
+int get_USBUSBHostsHostDevice_IsSuspended(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port *port= (struct usb_port *)data;
+	char *filepath= NULL, *status;
+	dmasprintf(&filepath, "%s/power/runtime_status", port->folder_path);
+	status= readFileContentAlphanum(filepath);
+	if(strncmp(status, "suspended", 9) == 0)
+		*value= "1";
+	else
+		*value= "0";
+	return 0;
+}
+
+int get_USBUSBHostsHostDevice_IsSelfPowered(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	//TODO
+	return 0;
+}
+
+int get_USBUSBHostsHostDevice_ConfigurationNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port *port= (struct usb_port *)data;
+	char *filepath= NULL;
+	dmasprintf(&filepath, "%s/bNumConfigurations", port->folder_path);
+	*value= readFileContentAlphanum(filepath);
+	return 0;
+}
+
+int get_USBUSBHostsHostDeviceConfiguration_ConfigurationNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	*value= "";
+	struct usb_port *port= (struct usb_port *)data;
+	char *filepath= NULL;
+	dmasprintf(&filepath, "%s/bConfigurationValue", port->folder_path);
+	*value= readFileContentAlphanum(filepath);
+	return 0;
+}
+
+int get_USBUSBHostsHostDeviceConfiguration_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port *port= (struct usb_port *)data;
+	char *filepath= NULL;
+	dmasprintf(&filepath, "%s/bNumInterfaces", port->folder_path);
+	*value= readFileContent(filepath);
+	return 0;
+}
+
+int get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port *port= (struct usb_port *)data;
+	char *filepath= NULL;
+	dmasprintf(&filepath, "%s/bInterfaceNumber", port->folder_path);
+	*value= readFileContentAlphanum(filepath);
+	return 0;
+}
+
+int get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port *port= (struct usb_port *)data;
+	char *filepath= NULL;
+	dmasprintf(&filepath, "%s/bInterfaceClass", port->folder_path);
+	*value= readFileContentAlphanum(filepath);
+	return 0;
+}
+
+int get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceSubClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port *port= (struct usb_port *)data;
+	char *filepath= NULL;
+	dmasprintf(&filepath, "%s/bInterfaceSubClass", port->folder_path);
+	*value= readFileContentAlphanum(filepath);
+	return 0;
+}
+
+int get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceProtocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	struct usb_port *port= (struct usb_port *)data;
+	char *filepath= NULL;
+	dmasprintf(&filepath, "%s/bInterfaceProtocol", port->folder_path);
+	*value= readFileContentAlphanum(filepath);
+	return 0;
+}
+
+int get_linker_usb_port(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) {
+	struct usb_port *port= (struct usb_port *)data;
+	if(port && port->folder_name) {
+		*linker= dmstrdup(port->folder_name);
+		return 0;
+	} else {
+		*linker = "";
+		return 0;
+	}
+}
+
+int get_linker_usb_host_device(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker){
+	struct usb_port *port= (struct usb_port *)data;
+	if(port && port->folder_name) {
+		*linker= dmstrdup(port->folder_name);
+		return 0;
+	} else {
+		*linker = "";
+		return 0;
+	}
+}
diff --git a/dmtree/tr181/usb.h b/dmtree/tr181/usb.h
new file mode 100644
index 000000000..7a36ad640
--- /dev/null
+++ b/dmtree/tr181/usb.h
@@ -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
+
-- 
GitLab