From 3d73fbfa416da10ea031574b3d1c1567caf3b77f Mon Sep 17 00:00:00 2001 From: Suvendhu Hansa <suvendhu.hansa@iopsys.eu> Date: Thu, 18 Jul 2024 20:43:30 +0530 Subject: [PATCH] Added missing Device.USB. dm params --- src/datamodel.c | 135 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 121 insertions(+), 14 deletions(-) diff --git a/src/datamodel.c b/src/datamodel.c index 2ed5775..e9782ff 100644 --- a/src/datamodel.c +++ b/src/datamodel.c @@ -163,7 +163,24 @@ static int __read_sysfs(const char *path, const char *name, char *dst, unsigned static int read_sysfs_usb_port(const struct usb_port *port, const char *name, char **value) { - return read_sysfs(port->folder_path, name, value); + char *val = NULL; + int ret = 0; + + ret = read_sysfs(port->folder_path, name, &val); + if (ret == 0 && DM_STRLEN(val)) { + /* skip leading whitespaces */ + while (*val == ' ') { + ++val; + } + + if (DM_STRLEN(val)) { + *value = dmstrdup(val); + } + + return 0; + } else { + return ret; + } } static int read_sysfs_usb_iface(const struct usb_interface *iface, const char *name, char **value) @@ -590,6 +607,12 @@ static int get_USBInterface_Name(char *refparam, struct dmctx *ctx, void *data, return 0; } +static int get_USBInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "0"; + return 0; +} + static int get_USBInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct dm_data *p = (struct dm_data *)data; @@ -599,6 +622,12 @@ static int get_USBInterface_LowerLayers(char *refparam, struct dmctx *ctx, void return 0; } +static int get_USBInterface_Upstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "0"; + return 0; +} + static int set_USBInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { @@ -624,6 +653,15 @@ static int get_USBInterface_MaxBitRate(char *refparam, struct dmctx *ctx, void * return read_sysfs_usb_iface(p->additional_data, "queues/tx-0/tx_maxrate", value); } +static int get_USBInterface_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct dm_data *p = (struct dm_data *)data; + struct usb_interface *iface = (struct usb_interface *)p->additional_data; + + _bbfdm_get_references(ctx, "Device.USB.Port.", "Name", iface->portlink, value); + return 0; +} + static int get_USBInterfaceStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct dm_data *p = (struct dm_data *)data; @@ -660,6 +698,18 @@ static int get_USBInterfaceStats_ErrorsReceived(char *refparam, struct dmctx *ct return read_sysfs_usb_net_iface(p->additional_data, "statistics/rx_errors", value); } +static int get_USBInterfaceStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "0"; + return 0; +} + +static int get_USBInterfaceStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "0"; + return 0; +} + static int get_USBInterfaceStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct dm_data *p = (struct dm_data *)data; @@ -672,12 +722,36 @@ static int get_USBInterfaceStats_DiscardPacketsReceived(char *refparam, struct d return read_sysfs_usb_net_iface(p->additional_data, "statistics/rx_dropped", value); } +static int get_USBInterfaceStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "0"; + return 0; +} + static int get_USBInterfaceStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct dm_data *p = (struct dm_data *)data; return read_sysfs_usb_net_iface(p->additional_data, "statistics/multicast", value); } +static int get_USBInterfaceStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "0"; + return 0; +} + +static int get_USBInterfaceStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "0"; + return 0; +} + +static int get_USBInterfaceStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct dm_data *p = (struct dm_data *)data; + return read_sysfs_usb_net_iface(p->additional_data, "statistics/rx_unknown_packets", value); +} + static int get_USBPort_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct dm_data *p = (struct dm_data *)data; @@ -725,6 +799,12 @@ static int get_USBPort_Type(char *refparam, struct dmctx *ctx, void *data, char return 0; } +static int get_USBPort_Receptacle(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value= "Standard-A"; + return 0; +} + static int get_USBPort_Rate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char speed[16]; @@ -912,7 +992,7 @@ static int get_USBUSBHostsHostDevice_DeviceNumber(char *refparam, struct dmctx * static int get_USBUSBHostsHostDevice_USBVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct dm_data *p = (struct dm_data *)data; - return read_sysfs_usb_port(p->additional_data, "bcdDevice", value); + return read_sysfs_usb_port(p->additional_data, "version", value); } static int get_USBUSBHostsHostDevice_DeviceClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) @@ -927,6 +1007,12 @@ static int get_USBUSBHostsHostDevice_DeviceSubClass(char *refparam, struct dmctx return read_sysfs_usb_port(p->additional_data, "bDeviceSubClass", value); } +static int get_USBUSBHostsHostDevice_DeviceVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct dm_data *p = (struct dm_data *)data; + return read_sysfs_usb_port(p->additional_data, "bcdDevice", value); +} + static int get_USBUSBHostsHostDevice_DeviceProtocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct dm_data *p = (struct dm_data *)data; @@ -1069,6 +1155,27 @@ static int get_USBUSBHostsHostDevice_IsSuspended(char *refparam, struct dmctx *c return 0; } +static int get_USBUSBHostsHostDevice_IsSelfPowered(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *attr = NULL; + struct dm_data *p = (struct dm_data *)data; + read_sysfs_usb_port(p->additional_data, "bmAttribute", &attr); + + *value = "0"; + if (DM_STRLEN(attr)) { + unsigned long val = 0; + val = strtoul(attr, NULL, 16); + + /* now extract the value at 6th bit(from 0-7) */ + unsigned long bits = (1 << 6); + + val = val & bits; + + *value = val ? "1" : "0"; + } + return 0; +} + static int get_USBUSBHostsHostDevice_ConfigurationNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct dm_data *p = (struct dm_data *)data; @@ -1143,12 +1250,12 @@ DMLEAF tUSBInterfaceParams[] = { {"Status", &DMREAD, DMT_STRING, get_USBInterface_Status, NULL, BBFDM_BOTH}, {"Alias", &DMWRITE, DMT_STRING, get_USBInterface_Alias, set_USBInterface_Alias, BBFDM_BOTH, DM_FLAG_UNIQUE}, {"Name", &DMREAD, DMT_STRING, get_USBInterface_Name, NULL, BBFDM_BOTH, DM_FLAG_UNIQUE}, -//{"LastChange", &DMREAD, DMT_UNINT, get_USBInterface_LastChange, NULL, BBFDM_BOTH}, +{"LastChange", &DMREAD, DMT_UNINT, get_USBInterface_LastChange, NULL, BBFDM_BOTH}, {"LowerLayers", &DMWRITE, DMT_STRING, get_USBInterface_LowerLayers, set_USBInterface_LowerLayers, BBFDM_BOTH, DM_FLAG_REFERENCE}, -//{"Upstream", &DMREAD, DMT_BOOL, get_USBInterface_Upstream, NULL, BBFDM_BOTH}, +{"Upstream", &DMREAD, DMT_BOOL, get_USBInterface_Upstream, NULL, BBFDM_BOTH}, {"MACAddress", &DMREAD, DMT_STRING, get_USBInterface_MACAddress, NULL, BBFDM_BOTH}, {"MaxBitRate", &DMREAD, DMT_UNINT, get_USBInterface_MaxBitRate, NULL, BBFDM_BOTH}, -//{"Port", &DMREAD, DMT_STRING, get_USBInterface_Port, NULL, BBFDM_BOTH}, +{"Port", &DMREAD, DMT_STRING, get_USBInterface_Port, NULL, BBFDM_BOTH}, {0} }; @@ -1161,15 +1268,15 @@ DMLEAF tUSBInterfaceStatsParams[] = { {"PacketsReceived", &DMREAD, DMT_UNLONG, get_USBInterfaceStats_PacketsReceived, NULL, BBFDM_BOTH}, {"ErrorsSent", &DMREAD, DMT_UNINT, get_USBInterfaceStats_ErrorsSent, NULL, BBFDM_BOTH}, {"ErrorsReceived", &DMREAD, DMT_UNINT, get_USBInterfaceStats_ErrorsReceived, NULL, BBFDM_BOTH}, -//{"UnicastPacketsSent", &DMREAD, DMT_UNLONG, get_USBInterfaceStats_UnicastPacketsSent, NULL, BBFDM_BOTH}, -//{"UnicastPacketsReceived", &DMREAD, DMT_UNLONG, get_USBInterfaceStats_UnicastPacketsReceived, NULL, BBFDM_BOTH}, +{"UnicastPacketsSent", &DMREAD, DMT_UNLONG, get_USBInterfaceStats_UnicastPacketsSent, NULL, BBFDM_BOTH}, +{"UnicastPacketsReceived", &DMREAD, DMT_UNLONG, get_USBInterfaceStats_UnicastPacketsReceived, NULL, BBFDM_BOTH}, {"DiscardPacketsSent", &DMREAD, DMT_UNINT, get_USBInterfaceStats_DiscardPacketsSent, NULL, BBFDM_BOTH}, {"DiscardPacketsReceived", &DMREAD, DMT_UNINT, get_USBInterfaceStats_DiscardPacketsReceived, NULL, BBFDM_BOTH}, -//{"MulticastPacketsSent", &DMREAD, DMT_UNLONG, get_USBInterfaceStats_MulticastPacketsSent, NULL, BBFDM_BOTH}, +{"MulticastPacketsSent", &DMREAD, DMT_UNLONG, get_USBInterfaceStats_MulticastPacketsSent, NULL, BBFDM_BOTH}, {"MulticastPacketsReceived", &DMREAD, DMT_UNLONG, get_USBInterfaceStats_MulticastPacketsReceived, NULL, BBFDM_BOTH}, -//{"BroadcastPacketsSent", &DMREAD, DMT_UNLONG, get_USBInterfaceStats_BroadcastPacketsSent, NULL, BBFDM_BOTH}, -//{"BroadcastPacketsReceived", &DMREAD, DMT_UNLONG, get_USBInterfaceStats_BroadcastPacketsReceived, NULL, BBFDM_BOTH}, -//{"UnknownProtoPacketsReceived", &DMREAD, DMT_UNINT, get_USBInterfaceStats_UnknownProtoPacketsReceived, NULL, BBFDM_BOTH}, +{"BroadcastPacketsSent", &DMREAD, DMT_UNLONG, get_USBInterfaceStats_BroadcastPacketsSent, NULL, BBFDM_BOTH}, +{"BroadcastPacketsReceived", &DMREAD, DMT_UNLONG, get_USBInterfaceStats_BroadcastPacketsReceived, NULL, BBFDM_BOTH}, +{"UnknownProtoPacketsReceived", &DMREAD, DMT_UNINT, get_USBInterfaceStats_UnknownProtoPacketsReceived, NULL, BBFDM_BOTH}, {0} }; @@ -1180,7 +1287,7 @@ DMLEAF tUSBPortParams[] = { {"Name", &DMREAD, DMT_STRING, get_USBPort_Name, NULL, BBFDM_BOTH, DM_FLAG_UNIQUE}, {"Standard", &DMREAD, DMT_STRING, get_USBPort_Standard, NULL, BBFDM_BOTH}, {"Type", &DMREAD, DMT_STRING, get_USBPort_Type, NULL, BBFDM_BOTH}, -//{"Receptacle", &DMREAD, DMT_STRING, get_USBPort_Receptacle, NULL, BBFDM_BOTH}, +{"Receptacle", &DMREAD, DMT_STRING, get_USBPort_Receptacle, NULL, BBFDM_BOTH}, {"Rate", &DMREAD, DMT_STRING, get_USBPort_Rate, NULL, BBFDM_BOTH}, {"Power", &DMREAD, DMT_STRING, get_USBPort_Power, NULL, BBFDM_BOTH}, {0} @@ -1232,7 +1339,7 @@ DMLEAF tUSBUSBHostsHostDeviceParams[] = { {"USBVersion", &DMREAD, DMT_STRING, get_USBUSBHostsHostDevice_USBVersion, NULL, BBFDM_BOTH}, {"DeviceClass", &DMREAD, DMT_HEXBIN, get_USBUSBHostsHostDevice_DeviceClass, NULL, BBFDM_BOTH}, {"DeviceSubClass", &DMREAD, DMT_HEXBIN, get_USBUSBHostsHostDevice_DeviceSubClass, NULL, BBFDM_BOTH}, -//{"DeviceVersion", &DMREAD, DMT_UNINT, get_USBUSBHostsHostDevice_DeviceVersion, NULL, BBFDM_BOTH}, +{"DeviceVersion", &DMREAD, DMT_UNINT, get_USBUSBHostsHostDevice_DeviceVersion, NULL, BBFDM_BOTH}, {"DeviceProtocol", &DMREAD, DMT_HEXBIN, get_USBUSBHostsHostDevice_DeviceProtocol, NULL, BBFDM_BOTH}, {"ProductID", &DMREAD, DMT_UNINT, get_USBUSBHostsHostDevice_ProductID, NULL, BBFDM_BOTH}, {"VendorID", &DMREAD, DMT_UNINT, get_USBUSBHostsHostDevice_VendorID, NULL, BBFDM_BOTH}, @@ -1245,7 +1352,7 @@ DMLEAF tUSBUSBHostsHostDeviceParams[] = { {"Parent", &DMREAD, DMT_STRING, get_USBUSBHostsHostDevice_Parent, NULL, BBFDM_BOTH, DM_FLAG_REFERENCE}, {"MaxChildren", &DMREAD, DMT_UNINT, get_USBUSBHostsHostDevice_MaxChildren, NULL, BBFDM_BOTH}, {"IsSuspended", &DMREAD, DMT_BOOL, get_USBUSBHostsHostDevice_IsSuspended, NULL, BBFDM_BOTH}, -//{"IsSelfPowered", &DMREAD, DMT_BOOL, get_USBUSBHostsHostDevice_IsSelfPowered, NULL, BBFDM_BOTH}, +{"IsSelfPowered", &DMREAD, DMT_BOOL, get_USBUSBHostsHostDevice_IsSelfPowered, NULL, BBFDM_BOTH}, {"ConfigurationNumberOfEntries", &DMREAD, DMT_UNINT, get_USBUSBHostsHostDevice_ConfigurationNumberOfEntries, NULL, BBFDM_BOTH}, {0} }; -- GitLab