Skip to content
Browse files

usbview 0.6.0 release

 - now can handle multiple root hubs.
 - added display of bus bandwidth information for root hubs.
 - added support for device strings to describe the device.
 - made logic for device name to be smarter due to the availability
   of the string descriptors.
  • Loading branch information...
1 parent bba30cc commit 0a0a45d4db276557b8828b6d293ffc74f32584f6 @gregkh committed
Showing with 234 additions and 57 deletions.
  1. +7 −0 ChangeLog
  2. +2 −1 src/Makefile.am
  3. +10 −10 src/Makefile.in
  4. +92 −0 src/showmessage.c
  5. +1 −0 src/showmessage.h
  6. +122 −46 src/usbtree.c
View
7 ChangeLog
@@ -1,3 +1,10 @@
+version 0.6.0
+ - now can handle multiple root hubs.
+ - added display of bus bandwidth information for root hubs.
+ - added support for device strings to describe the device.
+ - made logic for device name to be smarter due to the availability
+ of the string descriptors.
+
version 0.5.0
- updated the parser to handle the fact that the interface now
dictates what driver is loaded.
View
3 src/Makefile.am
@@ -11,7 +11,8 @@ usbview_SOURCES = \
support.c support.h \
interface.c interface.h \
callbacks.c callbacks.h \
- usbtree.c usbtree.h
+ usbtree.c usbtree.h \
+ showmessage.c showmessage.h
usbview_LDADD = @GTK_LIBS@ $(INTLLIBS)
View
20 src/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated automatically by automake 1.4a from Makefile.am
+# Makefile.in generated automatically by automake 1.4 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
@@ -46,10 +46,9 @@ AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
INSTALL = @INSTALL@
-INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
-INSTALL_STRIP_FLAG =
transform = @program_transform_name@
NORMAL_INSTALL = :
@@ -92,7 +91,7 @@ INCLUDES = -I$(top_srcdir)/intl @GTK_CFLAGS@
bin_PROGRAMS = usbview
-usbview_SOURCES = main.c support.c support.h interface.c interface.h callbacks.c callbacks.h usbtree.c usbtree.h
+usbview_SOURCES = main.c support.c support.h interface.c interface.h callbacks.c callbacks.h usbtree.c usbtree.h showmessage.c showmessage.h
usbview_LDADD = @GTK_LIBS@ $(INTLLIBS)
@@ -106,7 +105,8 @@ DEFS = @DEFS@ -I. -I$(srcdir) -I..
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
-usbview_OBJECTS = main.o support.o interface.o callbacks.o usbtree.o
+usbview_OBJECTS = main.o support.o interface.o callbacks.o usbtree.o \
+showmessage.o
usbview_DEPENDENCIES =
usbview_LDFLAGS =
CFLAGS = @CFLAGS@
@@ -121,7 +121,7 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = gtar
GZIP_ENV = --best
DEP_FILES = .deps/callbacks.P .deps/interface.P .deps/main.P \
-.deps/support.P .deps/usbtree.P
+.deps/showmessage.P .deps/support.P .deps/usbtree.P
SOURCES = $(usbview_SOURCES)
OBJECTS = $(usbview_OBJECTS)
@@ -150,8 +150,8 @@ install-binPROGRAMS: $(bin_PROGRAMS)
$(mkinstalldirs) $(DESTDIR)$(bindir)
@list='$(bin_PROGRAMS)'; for p in $$list; do \
if test -f $$p; then \
- echo " $(INSTALL_PROGRAM) $(INSTALL_STRIP_FLAG) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \
- $(INSTALL_PROGRAM) $(INSTALL_STRIP_FLAG) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
+ echo " $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \
+ $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
else :; fi; \
done
@@ -223,7 +223,7 @@ distdir: $(DISTFILES)
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
- cp -pr $$d/$$file $(distdir)/$$file; \
+ cp -pr $$/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
@@ -284,7 +284,7 @@ uninstall: uninstall-am
all-am: Makefile $(PROGRAMS)
all-redirect: all-am
install-strip:
- $(MAKE) $(AM_MAKEFLAGS) INSTALL_STRIP_FLAG=-s install
+ $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs:
$(mkinstalldirs) $(DESTDIR)$(bindir)
View
92 src/showmessage.c
@@ -0,0 +1,92 @@
+/*
+ * Showmessage.c
+ *
+ * This file taken from the book "Developing Linux Applications with GTK+ and GDK"
+ * by Eric Harlow
+ *
+ */
+
+#include <gtk/gtk.h>
+#include "showmessage.h"
+
+/*
+ * CloseShowMessage
+ *
+ * Routine to close the about dialog window.
+ */
+static void CloseShowMessage (GtkWidget *widget, gpointer data)
+{
+ GtkWidget *dialogWidget = (GtkWidget *) data;
+
+ gtk_grab_remove (dialogWidget);
+
+ /* --- Close the widget --- */
+ gtk_widget_destroy (dialogWidget);
+}
+
+
+
+/*
+ * ClearShowMessage
+ *
+ * Release the window "grab"
+ * Clear out the global dialog_window since that
+ * is checked when the dialog is brought up.
+ */
+static void ClearShowMessage (GtkWidget *widget, gpointer data)
+{
+ gtk_grab_remove (widget);
+}
+
+
+/*
+ * ShowMessage
+ *
+ * Show a popup message to the user.
+ */
+void ShowMessage (gchar *title, gchar *message)
+{
+ GtkWidget *label;
+ GtkWidget *button;
+ GtkWidget *dialog_window;
+
+ /* --- Create a dialog window --- */
+ dialog_window = gtk_dialog_new ();
+
+ gtk_signal_connect (GTK_OBJECT (dialog_window), "destroy", GTK_SIGNAL_FUNC (ClearShowMessage), NULL);
+
+ /* --- Set the title and add a border --- */
+ gtk_window_set_title (GTK_WINDOW (dialog_window), title);
+ gtk_container_border_width (GTK_CONTAINER (dialog_window), 0);
+
+ /* --- Create an "Ok" button with the focus --- */
+ button = gtk_button_new_with_label ("OK");
+
+ gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (CloseShowMessage), dialog_window);
+
+ /* --- Default the "Ok" button --- */
+ GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog_window)->action_area), button, TRUE, TRUE, 0);
+ gtk_widget_grab_default (button);
+ gtk_widget_show (button);
+
+ /* --- Create a descriptive label --- */
+ label = gtk_label_new (message);
+
+ /* --- Put some room around the label text --- */
+ gtk_misc_set_padding (GTK_MISC (label), 10, 10);
+
+ /* --- Add label to designated area on dialog --- */
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog_window)->vbox),
+ label, TRUE, TRUE, 0);
+
+ /* --- Show the label --- */
+ gtk_widget_show (label);
+
+ /* --- Show the dialog --- */
+ gtk_widget_show (dialog_window);
+
+ /* --- Only this window can have actions done. --- */
+ gtk_grab_add (dialog_window);
+}
+
View
1 src/showmessage.h
@@ -0,0 +1 @@
+extern void ShowMessage (gchar *title, gchar *message);
View
168 src/usbtree.c
@@ -34,6 +34,7 @@
#include "interface.h"
#include "support.h"
#include "usbtree.h"
+#include "showmessage.h"
#define MAX_LINE_SIZE 1000
@@ -62,6 +63,7 @@
#define ENDPOINT_INTERVAL_SIZE 10
+#define TOPOLOGY_BUS_STRING "Bus="
#define TOPOLOGY_LEVEL_STRING "Lev="
#define TOPOLOGY_PARENT_STRING "Prnt="
#define TOPOLOGY_PORT_STRING "Port="
@@ -85,6 +87,10 @@
#define DEVICE_VENDOR_STRING "Vendor="
#define DEVICE_PRODUCTID_STRING "ProdID="
#define DEVICE_REVISION_STRING "Rev="
+#define DEVICE_MANUFACTURER_STRING "Manufacturer="
+#define DEVICE_PRODUCT_STRING "Product="
+#define DEVICE_SERIALNUMBER_STRING "SerialNumber="
+#define DEVICE_STRING_MAXSIZE 255
#define CONFIG_NUMINTERFACES_STRING "#Ifs="
#define CONFIG_CONFIGNUMBER_STRING "Cfg#="
@@ -107,13 +113,6 @@
-
-
-
-
-
-
-
typedef struct DeviceEndpoint {
gint address;
gboolean in; /* TRUE if in, FALSE if out */
@@ -157,6 +156,7 @@ typedef struct DeviceBandwidth {
typedef struct Device {
gchar *name;
+ gint busNumber;
gint level;
gint parentNumber;
gint portNumber;
@@ -164,7 +164,6 @@ typedef struct Device {
gint count;
gint deviceNumber;
gint speed;
-// gint interfaceNumber;
gint maxChildren;
gchar *version;
gchar *class;
@@ -175,6 +174,9 @@ typedef struct Device {
gint vendorId;
gint productId;
gchar *revisionNumber;
+ gchar *manufacturer;
+ gchar *product;
+ gchar *serialNumber;
DeviceConfig *config[MAX_CONFIGS];
struct Device *parent;
struct Device *child[MAX_CHILDREN];
@@ -186,8 +188,9 @@ typedef struct Device {
-static Device *rootDevice = NULL;
-static Device *lastDevice;
+static Device *rootDevice = NULL;
+static Device *lastDevice = NULL;
+static DeviceBandwidth *currentBandwidth = NULL;
static signed int GetInt (char *string, char *pattern, int base)
@@ -315,6 +318,9 @@ static void DestroyDevice (Device *device)
g_free (device->subClass);
g_free (device->protocol);
g_free (device->revisionNumber);
+ g_free (device->manufacturer);
+ g_free (device->product);
+ g_free (device->serialNumber);
g_free (device);
@@ -333,6 +339,12 @@ static void Init (void)
rootDevice = (Device *)g_malloc0 (sizeof(Device));
+ /* clean up any bandwidth devices */
+ if (currentBandwidth != NULL) {
+ DestroyBandwidth (currentBandwidth);
+ g_free (currentBandwidth);
+ }
+
/* blow away the tree */
gtk_tree_clear_items (GTK_TREE(treeUSB), 0, -1);
@@ -345,7 +357,7 @@ static void Init (void)
}
-static Device *FindDeviceNode (Device *device, int deviceNumber)
+static Device *FindDeviceNode (Device *device, int deviceNumber, int busNumber)
{
int i;
Device *result;
@@ -353,11 +365,12 @@ static Device *FindDeviceNode (Device *device, int deviceNumber)
if (device == NULL)
return (NULL);
- if (device->deviceNumber == deviceNumber)
+ if ((device->deviceNumber == deviceNumber) &&
+ (device->busNumber == busNumber))
return (device);
for (i = 0; i < MAX_CHILDREN; ++i) {
- result = FindDeviceNode (device->child[i], deviceNumber);
+ result = FindDeviceNode (device->child[i], deviceNumber, busNumber);
if (result != NULL)
return (result);
}
@@ -366,14 +379,14 @@ static Device *FindDeviceNode (Device *device, int deviceNumber)
}
-static Device *FindDevice (int deviceNumber)
+static Device *FindDevice (int deviceNumber, int busNumber)
{
int i;
Device *result;
/* search through the tree to try to find a device */
for (i = 0; i < MAX_CHILDREN; ++i) {
- result = FindDeviceNode (rootDevice->child[i], deviceNumber);
+ result = FindDeviceNode (rootDevice->child[i], deviceNumber, busNumber);
if (result != NULL)
return (result);
}
@@ -389,18 +402,15 @@ static Device *AddDevice (char *line)
device = (Device *)(g_malloc0 (sizeof(Device)));
/* parse the line */
+ device->busNumber = GetInt (line, TOPOLOGY_BUS_STRING, 10);
device->level = GetInt (line, TOPOLOGY_LEVEL_STRING, 10);
device->parentNumber = GetInt (line, TOPOLOGY_PARENT_STRING, 10);
device->portNumber = GetInt (line, TOPOLOGY_PORT_STRING, 10);
device->count = GetInt (line, TOPOLOGY_COUNT_STRING, 10);
device->deviceNumber = GetInt (line, TOPOLOGY_DEVICENUMBER_STRING, 10);
device->speed = GetInt (line, TOPOLOGY_SPEED_STRING, 10);
-// device->interfaceNumber = GetInt (line, TOPOLOGY_INTERFACENUMBER_STRING, 10);
device->maxChildren = GetInt (line, TOPOLOGY_MAXCHILDREN_STRING, 10);
-// device->name = (char *)g_malloc0 (TOPOLOGY_DRIVERNAME_STRING_MAXLENGTH);
-// GetString (device->name, line, TOPOLOGY_DRIVERNAME_STRING, TOPOLOGY_DRIVERNAME_STRING_MAXLENGTH);
-
if (device->deviceNumber == -1)
device->deviceNumber = 0;
@@ -408,12 +418,12 @@ static Device *AddDevice (char *line)
if (device->level == 0) {
/* this is the root, don't go looking for a parent */
device->parent = rootDevice;
- rootDevice->maxChildren = 1;
- rootDevice->child[0] = device;
+ ++rootDevice->maxChildren;
+ rootDevice->child[rootDevice->maxChildren-1] = device;
}
else {
/* need to find this device's parent */
- device->parent = FindDevice (device->parentNumber);
+ device->parent = FindDevice (device->parentNumber, device->busNumber);
if (device->parent == NULL) {
printf ("can't find parent...not good.\n");
}
@@ -472,18 +482,52 @@ static void GetMoreDeviceInformation (Device *device, char *data)
}
-static void AddBandwidth (Device *device, char *data)
+static void GetDeviceString (Device *device, char *data)
{
if (device == NULL)
return;
-
- device->bandwidth = (DeviceBandwidth *)g_malloc0 (sizeof(DeviceBandwidth));
- device->bandwidth->allocated = GetInt (data, BANDWIDTH_ALOCATED, 10);
- device->bandwidth->total = GetInt (data, BANDWIDTH_TOTAL, 10);
- device->bandwidth->percent = GetInt (data, BANDWIDTH_PERCENT, 10);
- device->bandwidth->numInterruptRequests = GetInt (data, BANDWIDTH_INTERRUPT_TOTAL, 10);
- device->bandwidth->numIsocRequests = GetInt (data, BANDWIDTH_ISOC_TOTAL, 10);
+ if (strstr (data, DEVICE_MANUFACTURER_STRING) != NULL) {
+ g_free (device->manufacturer);
+ device->manufacturer = (gchar *)g_malloc0 (DEVICE_STRING_MAXSIZE);
+ GetString (device->manufacturer, data, DEVICE_MANUFACTURER_STRING, DEVICE_STRING_MAXSIZE-1);
+ return;
+ }
+
+ if (strstr (data, DEVICE_PRODUCT_STRING) != NULL) {
+ g_free (device->product);
+ device->product = (gchar *)g_malloc0 (DEVICE_STRING_MAXSIZE);
+ GetString (device->product, data, DEVICE_PRODUCT_STRING, DEVICE_STRING_MAXSIZE-1);
+ return;
+ }
+
+ if (strstr (data, DEVICE_SERIALNUMBER_STRING) != NULL) {
+ g_free (device->serialNumber);
+ device->serialNumber = (gchar *)g_malloc0 (DEVICE_STRING_MAXSIZE);
+ GetString (device->serialNumber, data, DEVICE_SERIALNUMBER_STRING, DEVICE_STRING_MAXSIZE-1);
+ return;
+ }
+
+ return;
+}
+
+
+static void GetBandwidth (Device *device, char *data)
+{
+ DeviceBandwidth *bandwidth;
+
+ if (device == NULL)
+ return;
+
+ bandwidth = (DeviceBandwidth *)g_malloc0 (sizeof(DeviceBandwidth));
+
+ bandwidth->allocated = GetInt (data, BANDWIDTH_ALOCATED, 10);
+ bandwidth->total = GetInt (data, BANDWIDTH_TOTAL, 10);
+ bandwidth->percent = GetInt (data, BANDWIDTH_PERCENT, 10);
+ bandwidth->numInterruptRequests = GetInt (data, BANDWIDTH_INTERRUPT_TOTAL, 10);
+ bandwidth->numIsocRequests = GetInt (data, BANDWIDTH_ISOC_TOTAL, 10);
+
+ device->bandwidth = bandwidth;
return;
}
@@ -654,7 +698,7 @@ static void AddEndpoint (Device *device, char *data)
}
-static void PopulateListBox (int deviceNumber)
+static void PopulateListBox (int deviceId)
{
Device *device;
gint position = 0;
@@ -662,8 +706,10 @@ static void PopulateListBox (int deviceNumber)
int configNum;
int interfaceNum;
int endpointNum;
+ int deviceNumber = (deviceId >> 8);
+ int busNumber = (deviceId & 0x00ff);
- device = FindDevice (deviceNumber);
+ device = FindDevice (deviceNumber, busNumber);
if (device == NULL) {
printf ("Can't seem to find device info to display\n");
return;
@@ -679,6 +725,18 @@ static void PopulateListBox (int deviceNumber)
gtk_editable_insert_text (GTK_EDITABLE(textDescription), device->name, strlen(device->name), &position);
}
+ /* add the manufacturer if we have one */
+ if (device->manufacturer != NULL) {
+ sprintf (string, "\nManufacturer: %s", device->manufacturer);
+ gtk_editable_insert_text (GTK_EDITABLE(textDescription), string, strlen(string), &position);
+ }
+
+ /* add the serial number if we have one */
+ if (device->serialNumber != NULL) {
+ sprintf (string, "\nSerial Number: %s", device->serialNumber);
+ gtk_editable_insert_text (GTK_EDITABLE(textDescription), string, strlen(string), &position);
+ }
+
/* add speed */
sprintf (string, "\nSpeed: %iMb/s", device->speed);
gtk_editable_insert_text (GTK_EDITABLE(textDescription), string, strlen(string), &position);
@@ -691,7 +749,7 @@ static void PopulateListBox (int deviceNumber)
/* add the bandwidth info if available */
if (device->bandwidth != NULL) {
- sprintf (string, "\nBandwidth allocated: %i / %i (%i)", device->bandwidth->allocated, device->bandwidth->total, device->bandwidth->percent);
+ sprintf (string, "\nBandwidth allocated: %i / %i (%i%%)", device->bandwidth->allocated, device->bandwidth->total, device->bandwidth->percent);
gtk_editable_insert_text (GTK_EDITABLE(textDescription), string, strlen(string), &position);
sprintf (string, "\nTotal number of interrupt requests: %i", device->bandwidth->numInterruptRequests);
@@ -803,7 +861,8 @@ static void DisplayDevice (Device *parent, Device *device)
gtk_widget_show (device->leaf);
/* hook up our callback function to this node */
- gtk_signal_connect (GTK_OBJECT (device->leaf), "select", GTK_SIGNAL_FUNC (SelectItem), (gpointer)(device->deviceNumber));
+ gtk_signal_connect (GTK_OBJECT (device->leaf), "select", GTK_SIGNAL_FUNC (SelectItem),
+ (gpointer)((device->deviceNumber<<8) | (device->busNumber)));
/* if we have children, then make a subtree */
hasChildren = 0;
@@ -844,9 +903,16 @@ static void NameDevices (Device *device)
g_free (device->name);
device->name = (gchar *)g_malloc0 (255*sizeof (gchar));
+ /* see if this device has a product name */
+ if (device->product != NULL) {
+ strcpy (device->name, device->product);
+ goto create_children_names;
+ }
+
/* see if this device is a root hub */
if (device->level == 0) {
strcpy (device->name, "root hub");
+ goto create_children_names;
}
/* look through all of the interfaces of this device, adding them all up to form a name */
@@ -857,10 +923,12 @@ static void NameDevices (Device *device)
if (config->interface[interfaceNum]) {
DeviceInterface *interface = config->interface[interfaceNum];
if (interface->name != NULL) {
- if (strlen (device->name) > 0) {
- strcat (device->name, "/");
+ if (strstr (interface->name, "none") == NULL) {
+ if (strlen (device->name) > 0) {
+ strcat (device->name, "/");
+ }
+ strcat (device->name, interface->name);
}
- strcat (device->name, interface->name);
}
}
}
@@ -868,6 +936,8 @@ static void NameDevices (Device *device)
}
}
+create_children_names:
+
/* create all of the children's names */
for (i = 0; i < MAX_CHILDREN; ++i) {
NameDevices (device->child[i]);
@@ -889,7 +959,7 @@ static void ParseLine (char * line)
break;
case 'B': /* bandwidth */
- AddBandwidth (lastDevice, line);
+ GetBandwidth (lastDevice, line);
break;
case 'D': /* device information */
@@ -900,6 +970,10 @@ static void ParseLine (char * line)
GetMoreDeviceInformation (lastDevice, line);
break;
+ case 'S': /* device string information */
+ GetDeviceString (lastDevice, line);
+ break;
+
case 'C': /* config descriptor info */
AddConfig (lastDevice, line);
break;
@@ -922,15 +996,16 @@ static void ParseLine (char * line)
void LoadUSBTree (void)
{
- FILE *usbFile;
- char *dataLine;
- int finished;
+ FILE *usbFile;
+ char *dataLine;
+ int finished;
+ int i;
usbFile = fopen ("/proc/bus/usb/devices", "r");
if (usbFile == NULL) {
- fprintf (stderr, "Can not open /proc/bus/usb/devices\n"
- "Verify that you have this option compiled in to your kernel, and that you\n"
- "have the correct permissions to access it.\n");
+ ShowMessage ("USBView Error", "Can not open /proc/bus/usb/devices\n"
+ "Verify that you have this option compiled into your kernel,\n"
+ "and have the USB core modules loaded.");
return;
}
finished = 0;
@@ -952,8 +1027,9 @@ void LoadUSBTree (void)
NameDevices (rootDevice);
- DisplayDevice (rootDevice, rootDevice->child[0]);
-
+ for (i = 0; i < rootDevice->maxChildren; ++i) {
+ DisplayDevice (rootDevice, rootDevice->child[i]);
+ }
return;
}

0 comments on commit 0a0a45d

Please sign in to comment.
Something went wrong with that request. Please try again.