Skip to content
Browse files

usbview 0.8.0 release

        - Added ability to select where the devices file is located at.
          This allows you to view a usbdevfs devices file that comes
          from another user, for instance. It also accomidates those who
          do not mount usbdevfs at /proc/bus/usb.
        - Fixed bug with devices that have a lot of interfaces.
        - Changed the tree widget to a different style.
        - Restructured the internal code a bit nicer (a lot of work to
          go with this...)
        - Added a TODO file to the archive listing some potential changes
          that could be done.
  • Loading branch information...
1 parent 4485b13 commit df4a395964661ca121b99e2f27573ee06b9d6945 @gregkh committed Oct 22, 2007
Showing with 1,481 additions and 790 deletions.
  1. +12 −0 ChangeLog
  2. +17 −1 Makefile.in
  3. +23 −0 TODO
  4. +5 −4 po/cat-id-tbl.c
  5. +8 −4 po/usbview.pot
  6. +3 −1 src/Makefile.am
  7. +6 −5 src/Makefile.in
  8. +9 −0 src/callbacks.c
  9. +5 −0 src/callbacks.h
  10. +265 −0 src/config.c
  11. +25 −0 src/config.h
  12. +19 −4 src/interface.c
  13. +7 −6 src/main.c
  14. +677 −0 src/usbparse.c
  15. +184 −0 src/usbparse.h
  16. +109 −765 src/usbtree.c
  17. +7 −0 src/usbtree.h
  18. +100 −0 usbview.spec
View
12 ChangeLog
@@ -1,3 +1,15 @@
+version 0.8.0
+ - Added ability to select where the devices file is located at.
+ This allows you to view a usbdevfs devices file that comes
+ from another user, for instance. It also accomidates those who
+ do not mount usbdevfs at /proc/bus/usb.
+ - Fixed bug with devices that have a lot of interfaces.
+ - Changed the tree widget to a different style.
+ - Restructured the internal code a bit nicer (a lot of work to
+ go with this...)
+ - Added a TODO file to the archive listing some potential changes
+ that could be done.
+
version 0.7.0
- the logic for determining the name of the device changed to
properly display the name of a keyboard or mouse when the
View
18 Makefile.in
@@ -10,6 +10,8 @@
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
+ROOT = usbview
+VERS = 0.8.0
SHELL = @SHELL@
@@ -92,7 +94,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = config.h
CONFIG_CLEAN_FILES =
-DIST_COMMON = README ./stamp-h.in ABOUT-NLS AUTHORS COPYING ChangeLog \
+DIST_COMMON = README ./stamp-h.in ABOUT-NLS AUTHORS COPYING TODO ChangeLog \
INSTALL Makefile.am Makefile.in NEWS acconfig.h aclocal.m4 config.h.in \
configure configure.in install-sh missing mkinstalldirs
@@ -395,6 +397,20 @@ dist-hook:
done \
fi
+snapshot: $(SOURCES) $(DOCS) $(OTHERFILES)
+ @echo
+ @echo "->Note: The version for now is hacked into Makefile.in as"
+ @echo "->" $(VERS)
+ @echo
+ @echo "->copying all release files to the directory " edgeport-$(VERS)
+ @echo
+ -mkdir $(ROOT)-$(VERS)
+ cp -r * $(ROOT)-$(VERS)
+ tar -c $(ROOT)-$(VERS) | gzip -9 > $(ROOT)-$(VERS).tar.gz
+ @echo "->removing the temporary directory " $(ROOT)-$(VERS)
+ /bin/rm -rf $(ROOT)-$(VERS)
+
+
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
View
23 TODO
@@ -0,0 +1,23 @@
+List of things that I think that would be nice to have in usbview:
+
+(feel free to submit patches to implement these :)
+
+- fix the Gtk-WARNING that happens the first time you press the [Refresh]
+ button (I know the problem, just haven't fixed it yet.)
+
+- fix the potential buffer overflows (there are at least one of these, but
+ since usbview isn't running suid, the worst thing that can happen is
+ crashing the program.)
+
+- remove [Refresh] button and replace it with select(1) to track changes
+ in real time.
+
+- change layout to look something like gproc (removing the buttons and
+ right info bar, only having a tree.) The device info would be accessed
+ differently (come on, who really reads all of that stuff all the time...)
+
+- make into a Gnome applet.
+
+
+greg k-h
+greg@kroah.com
View
9 po/cat-id-tbl.c
@@ -10,9 +10,10 @@ const struct _msg_ent _msg_tbl[] = {
{"", 1},
{"USB Viewer", 2},
{"Refresh", 3},
- {"Close", 4},
- {"Couldn't find pixmap file: %s", 5},
- {"Error loading pixmap file: %s", 6},
+ {"Configure", 4},
+ {"Close", 5},
+ {"Couldn't find pixmap file: %s", 6},
+ {"Error loading pixmap file: %s", 7},
};
-int _msg_tbl_length = 6;
+int _msg_tbl_length = 7;
View
12 po/usbview.pot
@@ -6,23 +6,27 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
-"POT-Creation-Date: 1999-10-13 11:46-0700\n"
+"POT-Creation-Date: 2000-06-15 23:37-0700\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: ENCODING\n"
-#: src/interface.c:55
+#: src/interface.c:56
msgid "USB Viewer"
msgstr ""
-#: src/interface.c:109
+#: src/interface.c:111
msgid "Refresh"
msgstr ""
-#: src/interface.c:119
+#: src/interface.c:121
+msgid "Configure"
+msgstr ""
+
+#: src/interface.c:131
msgid "Close"
msgstr ""
View
4 src/Makefile.am
@@ -12,7 +12,9 @@ usbview_SOURCES = \
interface.c interface.h \
callbacks.c callbacks.h \
usbtree.c usbtree.h \
- showmessage.c showmessage.h
+ showmessage.c showmessage.h \
+ usbparse.c usbparse.h \
+ config.c config.h
usbview_LDADD = @GTK_LIBS@ $(INTLLIBS)
View
11 src/Makefile.in
@@ -91,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 showmessage.c showmessage.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 usbparse.c usbparse.h config.c config.h
usbview_LDADD = @GTK_LIBS@ $(INTLLIBS)
@@ -106,7 +106,7 @@ CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
usbview_OBJECTS = main.o support.o interface.o callbacks.o usbtree.o \
-showmessage.o
+showmessage.o usbparse.o config.o
usbview_DEPENDENCIES =
usbview_LDFLAGS =
CFLAGS = @CFLAGS@
@@ -120,8 +120,9 @@ 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/showmessage.P .deps/support.P .deps/usbtree.P
+DEP_FILES = .deps/callbacks.P .deps/config.P .deps/interface.P \
+.deps/main.P .deps/showmessage.P .deps/support.P .deps/usbparse.P \
+.deps/usbtree.P
SOURCES = $(usbview_SOURCES)
OBJECTS = $(usbview_OBJECTS)
@@ -223,7 +224,7 @@ distdir: $(DISTFILES)
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
- cp -pr $$/$$file $(distdir)/$$file; \
+ cp -pr $$d/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
View
9 src/callbacks.c
@@ -29,6 +29,7 @@
#include "interface.h"
#include "support.h"
#include "usbtree.h"
+#include "config.h"
void
@@ -57,3 +58,11 @@ on_buttonRefresh_clicked (GtkButton *button,
LoadUSBTree();
}
+
+void
+on_buttonConfigure_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ configure_dialog ();
+}
+
View
5 src/callbacks.h
@@ -34,3 +34,8 @@ on_window1_delete_event (GtkWidget *widget,
void
on_buttonRefresh_clicked (GtkButton *button,
gpointer user_data);
+
+void
+on_buttonConfigure_clicked (GtkButton *button,
+ gpointer user_data);
+
View
265 src/config.c
@@ -0,0 +1,265 @@
+/*************************************************************************
+** config.c for USBView - a USB device viewer
+** Copyright (c) 1999 by Greg Kroah-Hartman, greg@kroah.com
+**
+** 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.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** (See the included file COPYING)
+*************************************************************************/
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "callbacks.h"
+#include "interface.h"
+#include "support.h"
+#include "usbtree.h"
+#include "showmessage.h"
+#include "usbparse.h"
+#include "config.h"
+
+
+
+
+static GtkWidget *fileEntry;
+static GtkWidget *filew;
+static char *sFilename;
+
+/*
+ * Get the selected filename and print it to the console
+ */
+static void file_ok_sel (GtkWidget *w, GtkFileSelection *fs)
+{
+ char *sTempFile;
+
+ /* --- Get the name --- */
+ sTempFile = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs));
+
+ /* --- Allocate space and save it. --- */
+ sFilename = malloc (sizeof (char) * (strlen (sTempFile) + 1));
+ strcpy (sFilename, sTempFile);
+
+ /* --- Destroy the file selection --- */
+ gtk_widget_destroy (filew);
+}
+
+
+static void file_cancel_sel (GtkWidget *w, GtkFileSelection *fs)
+{
+ /* --- Destroy the file selection --- */
+ gtk_widget_destroy (filew);
+}
+
+
+/*
+ * DestroyDialog
+ *
+ * Destroy the dialog (obvious, eh?) but also remove the
+ * grab and close the modal.
+ */
+static int DestroyDialog (GtkWidget *widget, gpointer *data)
+{
+ gtk_grab_remove (widget);
+ gtk_main_quit ();
+ return (FALSE);
+}
+
+
+/*
+ * GetFilename
+ */
+static char *GetFilename (char *sTitle, char *initialFilename)
+{
+ sFilename = NULL;
+
+ /* --- Create a new file selection widget --- */
+ filew = gtk_file_selection_new (sTitle);
+
+ /* --- If it's destroyed --- */
+ gtk_signal_connect (GTK_OBJECT (filew), "destroy", (GtkSignalFunc) DestroyDialog, &filew);
+
+ /* --- Connect the ok_button to file_ok_sel function --- */
+ gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button), "clicked", (GtkSignalFunc) file_ok_sel, filew );
+
+ /* --- Connect the cancel_button to destroy the widget --- */
+ gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->cancel_button), "clicked", (GtkSignalFunc) file_cancel_sel, filew);
+
+ /* --- Lets set the filename --- */
+ gtk_file_selection_set_filename (GTK_FILE_SELECTION(filew), initialFilename);
+
+ /* --- Turn off the file operation buttons --- */
+ gtk_file_selection_hide_fileop_buttons (GTK_FILE_SELECTION(filew));
+
+ /* --- Of course, we show it --- */
+ gtk_widget_show (filew);
+
+ /* --- Make sure we keep the focus --- */
+ gtk_grab_add (filew);
+
+ gtk_main ();
+
+ return (sFilename);
+}
+
+
+static void ClearShowMessage (GtkWidget *widget, gpointer data)
+{
+ gtk_grab_remove (widget);
+}
+
+static void CancelConfigureDialog (GtkWidget *widget, gpointer data)
+{
+ GtkWidget *dialogWidget = (GtkWidget *) data;
+
+ gtk_grab_remove (dialogWidget);
+
+ /* --- Close the widget --- */
+ gtk_widget_destroy (dialogWidget);
+}
+
+static void OkConfigureDialog (GtkWidget *widget, gpointer data)
+{
+ GtkWidget *dialogWidget = (GtkWidget *) data;
+ gchar *editString;
+
+ editString = gtk_editable_get_chars (GTK_EDITABLE (fileEntry), 0, -1);
+
+ gtk_grab_remove (dialogWidget);
+
+ /* --- Close the widget --- */
+ gtk_widget_destroy (dialogWidget);
+
+ strcpy (devicesFile, editString);
+
+ g_free (editString);
+}
+
+
+static void fileSelectButtonClick (GtkWidget *widget, gpointer data)
+{
+ gchar *newFilename;
+
+ newFilename = GetFilename ("locate usbdevfs devices file", devicesFile);
+
+ if (newFilename != NULL) {
+ gtk_entry_set_text (GTK_ENTRY (fileEntry), newFilename);
+ gtk_widget_show (fileEntry);
+ g_free (newFilename);
+ }
+}
+
+
+void configure_dialog (void)
+{
+ GtkWidget *configDialog;
+ GtkWidget *dialog_vbox2;
+ GtkWidget *hbox1;
+ GtkWidget *label1;
+ GtkWidget *dialog_action_area2;
+ GtkWidget *hbuttonbox2;
+ GtkWidget *okButton;
+ GtkWidget *cancelButton;
+ GtkWidget *fileSelectButton;
+
+ configDialog = gtk_dialog_new ();
+ gtk_object_set_data (GTK_OBJECT (configDialog), "configDialog", configDialog);
+ gtk_window_set_title (GTK_WINDOW (configDialog), "USB View Configuration");
+ gtk_window_set_policy (GTK_WINDOW (configDialog), TRUE, TRUE, FALSE);
+
+ dialog_vbox2 = GTK_DIALOG (configDialog)->vbox;
+ gtk_object_set_data (GTK_OBJECT (configDialog), "dialog_vbox2", dialog_vbox2);
+ gtk_widget_show (dialog_vbox2);
+
+ hbox1 = gtk_hbox_new (FALSE, 0);
+ gtk_widget_ref (hbox1);
+ gtk_object_set_data_full (GTK_OBJECT (configDialog), "hbox1", hbox1, (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (hbox1);
+ gtk_box_pack_start (GTK_BOX (dialog_vbox2), hbox1, TRUE, TRUE, 0);
+
+ label1 = gtk_label_new ("location of usbdevfs devices file");
+ gtk_widget_ref (label1);
+ gtk_object_set_data_full (GTK_OBJECT (configDialog), "label1", label1, (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (label1);
+ gtk_box_pack_start (GTK_BOX (hbox1), label1, FALSE, FALSE, 5);
+
+ fileEntry = gtk_entry_new ();
+ gtk_widget_ref (fileEntry);
+ gtk_object_set_data_full (GTK_OBJECT (configDialog), "fileEntry", fileEntry, (GtkDestroyNotify) gtk_widget_unref);
+ gtk_entry_set_text (GTK_ENTRY (fileEntry), devicesFile);
+ gtk_widget_show (fileEntry);
+ gtk_box_pack_start (GTK_BOX (hbox1), fileEntry, TRUE, TRUE, 0);
+
+ dialog_action_area2 = GTK_DIALOG (configDialog)->action_area;
+ gtk_object_set_data (GTK_OBJECT (configDialog), "dialog_action_area2", dialog_action_area2);
+ gtk_widget_show (dialog_action_area2);
+ gtk_container_set_border_width (GTK_CONTAINER (dialog_action_area2), 1);
+
+ hbuttonbox2 = gtk_hbutton_box_new ();
+ gtk_widget_ref (hbuttonbox2);
+ gtk_object_set_data_full (GTK_OBJECT (configDialog), "hbuttonbox2", hbuttonbox2, (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (hbuttonbox2);
+ gtk_box_pack_start (GTK_BOX (dialog_action_area2), hbuttonbox2, TRUE, TRUE, 11);
+
+ okButton = gtk_button_new_with_label ("OK");
+ gtk_widget_ref (okButton);
+ gtk_object_set_data_full (GTK_OBJECT (configDialog), "okButton", okButton, (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (okButton);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox2), okButton);
+ GTK_WIDGET_SET_FLAGS (okButton, GTK_CAN_DEFAULT);
+
+ cancelButton = gtk_button_new_with_label ("Cancel");
+ gtk_widget_ref (cancelButton);
+ gtk_object_set_data_full (GTK_OBJECT (configDialog), "cancelButton", cancelButton, (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (cancelButton);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox2), cancelButton);
+ GTK_WIDGET_SET_FLAGS (cancelButton, GTK_CAN_DEFAULT);
+
+ fileSelectButton = gtk_button_new_with_label ("...");
+ gtk_widget_ref (fileSelectButton);
+ gtk_object_set_data_full (GTK_OBJECT (configDialog), "fileSelectButton", fileSelectButton, (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (fileSelectButton);
+
+ gtk_box_pack_start (GTK_BOX (hbox1), fileSelectButton, TRUE, TRUE, 1);
+// gtk_container_add (GTK_CONTAINER (hbuttonbox2), cancelButton);
+// GTK_WIDGET_SET_FLAGS (cancelButton, GTK_CAN_DEFAULT);
+
+ gtk_signal_connect (GTK_OBJECT (okButton), "clicked", GTK_SIGNAL_FUNC (OkConfigureDialog), configDialog);
+ gtk_signal_connect (GTK_OBJECT (cancelButton), "clicked", GTK_SIGNAL_FUNC (CancelConfigureDialog), configDialog);
+ gtk_signal_connect (GTK_OBJECT (fileSelectButton), "clicked", GTK_SIGNAL_FUNC (fileSelectButtonClick), configDialog);
+
+ /* --- Default the "Ok" button --- */
+ GTK_WIDGET_SET_FLAGS (okButton, GTK_CAN_DEFAULT);
+ gtk_widget_grab_default (okButton);
+
+ gtk_signal_connect (GTK_OBJECT (configDialog), "destroy", GTK_SIGNAL_FUNC (ClearShowMessage), NULL);
+
+ /* --- Show the dialog --- */
+ gtk_widget_show (configDialog);
+
+ /* --- Only this window can have actions done. --- */
+ gtk_grab_add (configDialog);
+
+ return;
+}
+
+
View
25 src/config.h
@@ -0,0 +1,25 @@
+/*************************************************************************
+** config.h for USBView - a USB device viewer
+** Copyright (c) 1999 by Greg Kroah-Hartman, greg@kroah.com
+**
+** 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.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** (See the included file COPYING)
+*************************************************************************/
+
+
+extern void configure_dialog (void);
+
+
View
23 src/interface.c
@@ -47,13 +47,14 @@ create_windowMain ()
GtkWidget *scrolledwindow1;
GtkWidget *hbuttonbox1;
GtkWidget *buttonRefresh;
+ GtkWidget *buttonConfigure;
GtkWidget *buttonClose;
windowMain = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_name (windowMain, "windowMain");
gtk_object_set_data (GTK_OBJECT (windowMain), "windowMain", windowMain);
gtk_window_set_title (GTK_WINDOW (windowMain), _("USB Viewer"));
- gtk_window_set_default_size (GTK_WINDOW (windowMain), 400, 300);
+ gtk_window_set_default_size (GTK_WINDOW (windowMain), 500, 300);
vbox1 = gtk_vbox_new (FALSE, 0);
gtk_widget_set_name (vbox1, "vbox1");
@@ -70,9 +71,10 @@ create_windowMain ()
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (hpaned1);
gtk_box_pack_start (GTK_BOX (vbox1), hpaned1, TRUE, TRUE, 0);
- gtk_paned_set_position (GTK_PANED (hpaned1), 100);
+ gtk_paned_set_position (GTK_PANED (hpaned1), 200);
- treeUSB = gtk_tree_new ();
+// treeUSB = gtk_tree_new ();
+ treeUSB = gtk_ctree_new_with_titles (1, 0, NULL);
gtk_widget_set_name (treeUSB, "treeUSB");
gtk_widget_ref (treeUSB);
gtk_object_set_data_full (GTK_OBJECT (windowMain), "treeUSB", treeUSB,
@@ -116,6 +118,16 @@ create_windowMain ()
gtk_container_set_border_width (GTK_CONTAINER (buttonRefresh), 4);
GTK_WIDGET_SET_FLAGS (buttonRefresh, GTK_CAN_DEFAULT);
+ buttonConfigure = gtk_button_new_with_label (_("Configure"));
+ gtk_widget_set_name (buttonConfigure, "buttonConfigure");
+ gtk_widget_ref (buttonConfigure);
+ gtk_object_set_data_full (GTK_OBJECT (windowMain), "buttonConfigure", buttonConfigure,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (buttonConfigure);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox1), buttonConfigure);
+ gtk_container_set_border_width (GTK_CONTAINER (buttonConfigure), 4);
+ GTK_WIDGET_SET_FLAGS (buttonConfigure, GTK_CAN_DEFAULT);
+
buttonClose = gtk_button_new_with_label (_("Close"));
gtk_widget_set_name (buttonClose, "buttonClose");
gtk_widget_ref (buttonClose);
@@ -132,10 +144,13 @@ create_windowMain ()
gtk_signal_connect (GTK_OBJECT (buttonRefresh), "clicked",
GTK_SIGNAL_FUNC (on_buttonRefresh_clicked),
NULL);
+ gtk_signal_connect (GTK_OBJECT (buttonConfigure), "clicked",
+ GTK_SIGNAL_FUNC (on_buttonConfigure_clicked),
+ NULL);
gtk_signal_connect (GTK_OBJECT (buttonClose), "clicked",
GTK_SIGNAL_FUNC (on_buttonClose_clicked),
NULL);
-
+
return windowMain;
}
View
13 src/main.c
@@ -28,19 +28,20 @@
#include "interface.h"
#include "support.h"
-int
-main (int argc, char *argv[])
+int main (int argc, char *argv[])
{
GtkWidget *window1;
- bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
- textdomain (PACKAGE);
+// bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
+// textdomain (PACKAGE);
gtk_set_locale ();
gtk_init (&argc, &argv);
- add_pixmap_directory (PACKAGE_DATA_DIR "/pixmaps");
- add_pixmap_directory (PACKAGE_SOURCE_DIR "/pixmaps");
+// add_pixmap_directory (PACKAGE_DATA_DIR "/pixmaps");
+// add_pixmap_directory (PACKAGE_SOURCE_DIR "/pixmaps");
+
+ initialize_stuff();
/*
* The following code was added by Glade to create one of each component
View
677 src/usbparse.c
@@ -0,0 +1,677 @@
+/*************************************************************************
+** usbparse.c for USBView - a USB device viewer
+** Copyright (c) 1999 by Greg Kroah-Hartman, greg@kroah.com
+**
+** 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.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** (See the included file COPYING)
+*************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "callbacks.h"
+#include "interface.h"
+#include "support.h"
+#include "usbtree.h"
+#include "showmessage.h"
+#include "usbparse.h" /* all of the usb structure definitions */
+
+#define MAX_LINE_SIZE 1000
+
+
+ Device *rootDevice = NULL;
+static Device *lastDevice = NULL;
+static DeviceBandwidth *currentBandwidth = NULL;
+
+
+static signed int GetInt (char *string, char *pattern, int base)
+{
+ char *pointer;
+
+ pointer = strstr (string, pattern);
+ if (pointer == NULL)
+ return (0);
+
+ pointer += strlen(pattern);
+ return ((int)(strtol (pointer, NULL, base)));
+}
+
+/* uncomment this if we ever need to read a float
+static double GetFloat (char *string, char *pattern)
+{
+ char *pointer;
+
+ pointer = strstr (string, pattern);
+ if (pointer == NULL)
+ return (0.0);
+
+ pointer += strlen(pattern);
+ return (strtod (pointer, NULL));
+}
+*/
+
+
+static void GetString (char *dest, char *source, char *pattern, int maxSize)
+{
+ char *pointer;
+
+ pointer = strstr (source, pattern);
+ if (pointer == NULL)
+ return;
+
+ pointer += strlen(pattern);
+ strncpy (dest, pointer, maxSize);
+ return;
+}
+
+
+static void DestroyEndpoint (DeviceEndpoint *endpoint)
+{
+ if (endpoint == NULL)
+ return;
+
+ g_free (endpoint->type);
+ g_free (endpoint->interval);
+
+ g_free (endpoint);
+
+ return;
+}
+
+
+static void DestroyInterface (DeviceInterface *interface)
+{
+ int i;
+
+ if (interface == NULL)
+ return;
+
+ for (i = 0; i < MAX_ENDPOINTS; ++i)
+ DestroyEndpoint (interface->endpoint[i]);
+
+ g_free (interface->name);
+ g_free (interface->class);
+
+ g_free (interface);
+
+ return;
+}
+
+
+static void DestroyConfig (DeviceConfig *config)
+{
+ int i;
+
+ if (config == NULL)
+ return;
+
+ for (i = 0; i < MAX_INTERFACES; ++i)
+ DestroyInterface (config->interface[i]);
+
+ g_free (config->maxPower);
+
+ g_free (config);
+
+ return;
+}
+
+
+static void DestroyBandwidth (DeviceBandwidth *bandwidth)
+{
+ /* nothing dynamic in the bandwidth structure yet. */
+ return;
+}
+
+
+static void DestroyDevice (Device *device)
+{
+ int i;
+
+ if (device == NULL)
+ return;
+
+ for (i = 0; i < MAX_CHILDREN; ++i)
+ DestroyDevice (device->child[i]);
+
+ for (i = 0; i < MAX_CONFIGS; ++i)
+ DestroyConfig (device->config[i]);
+
+ if (device->bandwidth != NULL) {
+ DestroyBandwidth (device->bandwidth);
+ g_free (device->bandwidth);
+ }
+
+ g_free (device->name);
+ g_free (device->version);
+ g_free (device->class);
+ 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);
+
+ return;
+}
+
+
+
+
+static Device *FindDeviceNode (Device *device, int deviceNumber, int busNumber)
+{
+ int i;
+ Device *result;
+
+ if (device == NULL)
+ return (NULL);
+
+ if ((device->deviceNumber == deviceNumber) &&
+ (device->busNumber == busNumber))
+ return (device);
+
+ for (i = 0; i < MAX_CHILDREN; ++i) {
+ result = FindDeviceNode (device->child[i], deviceNumber, busNumber);
+ if (result != NULL)
+ return (result);
+ }
+
+ return (NULL);
+}
+
+
+Device *usb_find_device (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, busNumber);
+ if (result != NULL)
+ return (result);
+ }
+ return (NULL);
+}
+
+
+static Device *AddDevice (char *line)
+{
+ Device *device;
+
+ /* create a new device */
+ 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->maxChildren = GetInt (line, TOPOLOGY_MAXCHILDREN_STRING, 10);
+
+ if (device->deviceNumber == -1)
+ device->deviceNumber = 0;
+
+ /* Set up the parent / child relationship */
+ if (device->level == 0) {
+ /* this is the root, don't go looking for a parent */
+ device->parent = rootDevice;
+ ++rootDevice->maxChildren;
+ rootDevice->child[rootDevice->maxChildren-1] = device;
+ }
+ else {
+ /* need to find this device's parent */
+ device->parent = usb_find_device (device->parentNumber, device->busNumber);
+ if (device->parent == NULL) {
+ printf ("can't find parent...not good.\n");
+ }
+ device->parent->child[device->portNumber] = device;
+ }
+
+ return (device);
+}
+
+
+
+
+
+static void GetDeviceInformation (Device *device, char *data)
+{
+ if (device == NULL)
+ return;
+
+ g_free (device->version);
+ g_free (device->class);
+ g_free (device->subClass);
+ g_free (device->protocol);
+
+ device->version = (char *)g_malloc0 ((DEVICE_VERSION_SIZE) * sizeof(char));
+ device->class = (char *)g_malloc0 ((DEVICE_CLASS_SIZE) * sizeof(char));
+ device->subClass = (char *)g_malloc0 ((DEVICE_SUBCLASS_SIZE) * sizeof(char));
+ device->protocol = (char *)g_malloc0 ((DEVICE_PROTOCOL_SIZE) * sizeof(char));
+
+ GetString (device->version, data, DEVICE_VERSION_STRING, DEVICE_VERSION_SIZE-1);
+ GetString (device->class, data, DEVICE_CLASS_STRING, DEVICE_CLASS_SIZE-1);
+ GetString (device->subClass, data, DEVICE_SUBCLASS_STRING, DEVICE_SUBCLASS_SIZE-1);
+ GetString (device->protocol, data, DEVICE_PROTOCOL_STRING, DEVICE_PROTOCOL_SIZE-1);
+
+ device->maxPacketSize = GetInt (data, DEVICE_MAXPACKETSIZE_STRING, 10);
+ device->numConfigs = GetInt (data, DEVICE_NUMCONFIGS_STRING, 10);
+
+ return;
+}
+
+
+
+static void GetMoreDeviceInformation (Device *device, char *data)
+{
+ if (device == NULL)
+ return;
+
+ g_free (device->revisionNumber);
+
+ device->vendorId = GetInt (data, DEVICE_VENDOR_STRING, 16);
+ device->productId = GetInt (data, DEVICE_PRODUCTID_STRING, 16);
+
+ device->revisionNumber = (char *)g_malloc0 ((DEVICE_REVISION_NUMBER_SIZE) * sizeof(char));
+ GetString (device->revisionNumber, data, DEVICE_REVISION_STRING, DEVICE_REVISION_NUMBER_SIZE);
+
+ return;
+}
+
+
+static void GetDeviceString (Device *device, char *data)
+{
+ if (device == NULL)
+ return;
+
+ 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;
+}
+
+
+static void AddConfig (Device *device, char *data)
+{
+ DeviceConfig *config;
+ int i;
+
+ if (device == NULL)
+ return;
+
+ /* Find the next available config in this device */
+ for (i = 0; i < MAX_CONFIGS; ++i) {
+ if (device->config[i] == NULL) {
+ break;
+ }
+ }
+ if (i >= MAX_CONFIGS) {
+ /* ran out of room to hold this config */
+ g_warning ("Too many configs for this device.\n");
+ return;
+ }
+
+ config = (DeviceConfig *)g_malloc0 (sizeof(DeviceConfig));
+ config->maxPower = (gchar *)g_malloc0 ((CONFIG_MAXPOWER_SIZE) * sizeof(gchar));
+
+ config->numInterfaces = GetInt (data, CONFIG_NUMINTERFACES_STRING, 10);
+ config->configNumber = GetInt (data, CONFIG_CONFIGNUMBER_STRING, 10);
+ config->attributes = GetInt (data, CONFIG_ATTRIBUTES_STRING, 16);
+
+ GetString (config->maxPower, data, CONFIG_MAXPOWER_STRING, CONFIG_MAXPOWER_SIZE);
+
+ /* have the device now point to this config */
+ device->config[i] = config;
+
+ return;
+}
+
+
+static void AddInterface (Device *device, char *data)
+{
+ DeviceConfig *config;
+ DeviceInterface *interface;
+ int i;
+ int configNum;
+
+ if (device == NULL)
+ return;
+
+ /* find the LAST config in the device */
+ configNum = -1;
+ for (i = 0; i < MAX_CONFIGS; ++i)
+ if (device->config[i])
+ configNum = i;
+ if (configNum == -1) {
+ /* no config to put this interface at, not good */
+ g_warning ("No config to put an interface at for this device.\n");
+ return;
+ }
+
+ config = device->config[configNum];
+
+ /* now find a place in this config to place the interface */
+ for (i = 0; i < MAX_INTERFACES; ++i)
+ if (config->interface[i] == NULL)
+ break;
+ if (i >= MAX_INTERFACES) {
+ /* ran out of room to hold this interface */
+ g_warning ("Too many interfaces for this device.\n");
+ return;
+ }
+
+ interface = (DeviceInterface *)g_malloc0 (sizeof(DeviceInterface));
+
+ interface->class = (gchar *)g_malloc0 ((INTERFACE_CLASS_SIZE) * sizeof(gchar));
+ interface->name = (gchar *)g_malloc0 ((INTERFACE_DRIVERNAME_STRING_MAXLENGTH) * sizeof(gchar));
+
+ interface->interfaceNumber = GetInt (data, INTERFACE_NUMBER_STRING, 10);
+ interface->alternateNumber = GetInt (data, INTERFACE_ALTERNATESETTING_STRING, 10);
+ interface->numEndpoints = GetInt (data, INTERFACE_NUMENDPOINTS_STRING, 10);
+ interface->subClass = GetInt (data, INTERFACE_SUBCLASS_STRING, 10);
+ interface->protocol = GetInt (data, INTERFACE_PROTOCOL_STRING, 10);
+
+ GetString (interface->class, data, INTERFACE_CLASS_STRING, INTERFACE_CLASS_SIZE);
+ GetString (interface->name, data, INTERFACE_DRIVERNAME_STRING, INTERFACE_DRIVERNAME_STRING_MAXLENGTH);
+
+ /* if this interface does not have a driver attached to it, save that info for later */
+ if (strncmp(interface->name, INTERFACE_DRIVERNAME_NODRIVER_STRING, INTERFACE_DRIVERNAME_STRING_MAXLENGTH) == 0) {
+ interface->driverAttached = FALSE;
+ }
+ else {
+ interface->driverAttached = TRUE;
+ }
+
+ /* now point the config to this interface */
+ config->interface[i] = interface;
+
+ return;
+}
+
+
+static void AddEndpoint (Device *device, char *data)
+{
+ DeviceConfig *config;
+ DeviceInterface *interface;
+ DeviceEndpoint *endpoint;
+ int i;
+ int configNum;
+ int interfaceNum;
+
+ if (device == NULL)
+ return;
+
+ /* find the LAST config in the device */
+ configNum = -1;
+ for (i = 0; i < MAX_CONFIGS; ++i)
+ if (device->config[i])
+ configNum = i;
+ if (configNum == -1) {
+ /* no config to put this interface at, not good */
+ g_warning ("No config to put an interface at for this device.\n");
+ return;
+ }
+
+ config = device->config[configNum];
+
+ /* find the LAST interface in the config */
+ interfaceNum = -1;
+ for (i = 0; i < MAX_INTERFACES; ++i)
+ if (config->interface[i])
+ interfaceNum = i;
+ if (interfaceNum == -1) {
+ /* no interface to put this endpoint at, not good */
+ g_warning ("No interface to put an endpoint at for this device.\n");
+ return;
+ }
+
+ interface = config->interface[interfaceNum];
+
+ /* now find a place in this interface to place the endpoint */
+ for (i = 0; i < MAX_ENDPOINTS; ++i) {
+ if (interface->endpoint[i] == NULL) {
+ break;
+ }
+ }
+ if (i >= MAX_ENDPOINTS) {
+ /* ran out of room to hold this endpoint */
+ g_warning ("Too many endpoints for this device.\n");
+ return;
+ }
+
+ endpoint = (DeviceEndpoint *)g_malloc0 (sizeof(DeviceEndpoint));
+
+ endpoint->type = (gchar *)g_malloc0 ((ENDPOINT_TYPE_SIZE) * sizeof(gchar));
+ endpoint->interval = (gchar *)g_malloc0 ((ENDPOINT_INTERVAL_SIZE) * sizeof(gchar));
+
+ endpoint->address = GetInt (data, ENDPOINT_ADDRESS_STRING, 16);
+ if (data[10] == 'I')
+ endpoint->in = TRUE;
+ else
+ endpoint->in = FALSE;
+ endpoint->attribute = GetInt (data, ENDPOINT_ATTRIBUTES_STRING, 16);
+ endpoint->maxPacketSize = GetInt (data, ENDPOINT_MAXPACKETSIZE_STRING, 10);
+
+ GetString (interface->class, data, INTERFACE_CLASS_STRING, INTERFACE_CLASS_SIZE);
+
+ memcpy (endpoint->type, &data[20], ENDPOINT_TYPE_SIZE-1);
+ GetString (endpoint->interval, data, ENDPOINT_INTERVAL_STRING, ENDPOINT_INTERVAL_SIZE);
+
+ /* point the interface to the endpoint */
+ interface->endpoint[i] = endpoint;
+}
+
+
+/* Build all of the names of the devices */
+static void NameDevice (Device *device)
+{
+ int configNum;
+ int interfaceNum;
+ int i;
+
+ if (device == NULL)
+ return;
+
+ /* build the name for this device */
+ if (device != rootDevice) {
+ if (device->name)
+ g_free (device->name);
+ device->name = (gchar *)g_malloc0 (DEVICE_STRING_MAXSIZE*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 */
+ for (configNum = 0; configNum < MAX_CONFIGS; ++configNum) {
+ if (device->config[configNum]) {
+ DeviceConfig *config = device->config[configNum];
+ for (interfaceNum = 0; interfaceNum < MAX_INTERFACES; ++interfaceNum) {
+ if (config->interface[interfaceNum]) {
+ DeviceInterface *interface = config->interface[interfaceNum];
+ if (interface->name != NULL) {
+ if (strstr (interface->name, "none") == NULL) {
+ if (strcmp (interface->name, "hid") == 0) {
+ if (interface->subClass == 1) {
+ switch (interface->protocol) {
+ case 1 :
+ strcat (device->name, "keyboard");
+ continue;
+ case 2 :
+ strcat (device->name, "mouse");
+ continue;
+ }
+ }
+ }
+ if (strlen (device->name) > 0) {
+ strcat (device->name, " / ");
+ }
+ strcat (device->name, interface->name);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (strlen (device->name) == 0) {
+ strcat (device->name, "Unknown Device");
+ }
+
+ }
+
+create_children_names:
+
+ /* create all of the children's names */
+ for (i = 0; i < MAX_CHILDREN; ++i) {
+ NameDevice (device->child[i]);
+ }
+
+ return;
+}
+
+
+void usb_initialize_list (void)
+{
+ if (rootDevice != NULL) {
+ DestroyDevice (rootDevice);
+ rootDevice = NULL;
+ }
+
+ rootDevice = (Device *)g_malloc0 (sizeof(Device));
+
+ /* clean up any bandwidth devices */
+ if (currentBandwidth != NULL) {
+ DestroyBandwidth (currentBandwidth);
+ g_free (currentBandwidth);
+ }
+
+ lastDevice = NULL;
+
+ return;
+}
+
+
+void usb_parse_line (char * line)
+{
+ /* chop off the trailing \n */
+ line[strlen(line)-1] = 0x00;
+
+ /* look at the first character to see what kind of line this is */
+ switch (line[0]) {
+ case 'T': /* topology */
+ lastDevice = AddDevice (line);
+ break;
+
+ case 'B': /* bandwidth */
+ GetBandwidth (lastDevice, line);
+ break;
+
+ case 'D': /* device information */
+ GetDeviceInformation (lastDevice, line);
+ break;
+
+ case 'P': /* more device information */
+ GetMoreDeviceInformation (lastDevice, line);
+ break;
+
+ case 'S': /* device string information */
+ GetDeviceString (lastDevice, line);
+ break;
+
+ case 'C': /* config descriptor info */
+ AddConfig (lastDevice, line);
+ break;
+
+ case 'I': /* interface descriptor info */
+ AddInterface (lastDevice, line);
+ break;
+
+ case 'E': /* endpoint descriptor info */
+ AddEndpoint (lastDevice, line);
+ break;
+
+ default:
+ break;
+ }
+
+ return;
+}
+
+
+void usb_name_devices (void)
+{
+ NameDevice (rootDevice);
+}
View
184 src/usbparse.h
@@ -0,0 +1,184 @@
+/*************************************************************************
+** usbparse.h for USBView - a USB device viewer
+** Copyright (c) 1999 by Greg Kroah-Hartman, greg@kroah.com
+**
+** 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.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** (See the included file COPYING)
+*************************************************************************/
+
+#ifndef __USB_PARSE_H
+#define __USB_PARSE_H
+
+/* should make these dynamic someday... */
+#define MAX_ENDPOINTS 32
+#define MAX_INTERFACES 32
+#define MAX_CONFIGS 32
+#define MAX_CHILDREN 32
+
+#define DEVICE_VERSION_SIZE 6
+#define DEVICE_CLASS_SIZE 10
+#define DEVICE_SUBCLASS_SIZE 3
+#define DEVICE_PROTOCOL_SIZE 3
+#define DEVICE_VENDOR_ID_SIZE 5
+#define DEVICE_PRODUCT_ID_SIZE 5
+#define DEVICE_REVISION_NUMBER_SIZE 6
+
+#define CONFIG_ATTRIBUTES_SIZE 3
+#define CONFIG_MAXPOWER_SIZE 10
+
+#define INTERFACE_CLASS_SIZE 10
+
+#define ENDPOINT_TYPE_SIZE 5
+#define ENDPOINT_MAXPACKETSIZE_SIZE 5
+#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="
+#define TOPOLOGY_COUNT_STRING "Cnt="
+#define TOPOLOGY_DEVICENUMBER_STRING "Dev#="
+#define TOPOLOGY_SPEED_STRING "Spd="
+#define TOPOLOGY_MAXCHILDREN_STRING "MxCh="
+
+#define BANDWIDTH_ALOCATED "Alloc="
+#define BANDWIDTH_TOTAL "/"
+#define BANDWIDTH_PERCENT "us ("
+#define BANDWIDTH_INTERRUPT_TOTAL "#Int="
+#define BANDWIDTH_ISOC_TOTAL "#Iso="
+
+#define DEVICE_VERSION_STRING "Ver="
+#define DEVICE_CLASS_STRING "Cls="
+#define DEVICE_SUBCLASS_STRING "Sub="
+#define DEVICE_PROTOCOL_STRING "Prot="
+#define DEVICE_MAXPACKETSIZE_STRING "MxPS="
+#define DEVICE_NUMCONFIGS_STRING "#Cfgs="
+#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#="
+#define CONFIG_ATTRIBUTES_STRING "Atr="
+#define CONFIG_MAXPOWER_STRING "MxPwr="
+
+#define INTERFACE_NUMBER_STRING "If#="
+#define INTERFACE_ALTERNATESETTING_STRING "Alt="
+#define INTERFACE_NUMENDPOINTS_STRING "#EPs="
+#define INTERFACE_CLASS_STRING "Cls="
+#define INTERFACE_SUBCLASS_STRING "Sub="
+#define INTERFACE_PROTOCOL_STRING "Prot="
+#define INTERFACE_DRIVERNAME_STRING "Driver="
+#define INTERFACE_DRIVERNAME_NODRIVER_STRING "(none)"
+#define INTERFACE_DRIVERNAME_STRING_MAXLENGTH 50
+
+#define ENDPOINT_ADDRESS_STRING "Ad="
+#define ENDPOINT_ATTRIBUTES_STRING "Atr="
+#define ENDPOINT_MAXPACKETSIZE_STRING "MxPS="
+#define ENDPOINT_INTERVAL_STRING "Ivl="
+
+
+
+typedef struct DeviceEndpoint {
+ gint address;
+ gboolean in; /* TRUE if in, FALSE if out */
+ gint attribute;
+ gchar *type;
+ gint maxPacketSize;
+ gchar *interval;
+} DeviceEndpoint;
+
+
+typedef struct DeviceInterface {
+ gchar *name;
+ gint interfaceNumber;
+ gint alternateNumber;
+ gint numEndpoints;
+ gint subClass;
+ gint protocol;
+ gchar *class;
+ DeviceEndpoint *endpoint[MAX_ENDPOINTS];
+ gboolean driverAttached; /* TRUE if driver is attached to this interface currently */
+} DeviceInterface;
+
+
+
+typedef struct DeviceConfig {
+ gint configNumber;
+ gint numInterfaces;
+ gint attributes;
+ gchar *maxPower;
+ DeviceInterface *interface[MAX_INTERFACES];
+} DeviceConfig;
+
+
+typedef struct DeviceBandwidth {
+ gint allocated;
+ gint total;
+ gint percent;
+ gint numInterruptRequests;
+ gint numIsocRequests;
+} DeviceBandwidth;
+
+
+typedef struct Device {
+ gchar *name;
+ gint busNumber;
+ gint level;
+ gint parentNumber;
+ gint portNumber;
+ gint connectorNumber;
+ gint count;
+ gint deviceNumber;
+ gint speed;
+ gint maxChildren;
+ gchar *version;
+ gchar *class;
+ gchar *subClass;
+ gchar *protocol;
+ gint maxPacketSize;
+ gint numConfigs;
+ gint vendorId;
+ gint productId;
+ gchar *revisionNumber;
+ gchar *manufacturer;
+ gchar *product;
+ gchar *serialNumber;
+ DeviceConfig *config[MAX_CONFIGS];
+ struct Device *parent;
+ struct Device *child[MAX_CHILDREN];
+ DeviceBandwidth *bandwidth;
+ GtkWidget *tree;
+ GtkCTreeNode *leaf;
+} Device;
+
+
+extern Device *rootDevice;
+
+
+extern Device *usb_find_device (int deviceNumber, int busNumber);
+extern void usb_initialize_list (void);
+extern void usb_parse_line (char *line);
+extern void usb_name_devices (void);
+
+
+#endif /* __USB_PARSE_H */
+
View
874 src/usbtree.c
@@ -35,663 +35,28 @@
#include "support.h"
#include "usbtree.h"
#include "showmessage.h"
+#include "usbparse.h"
#define MAX_LINE_SIZE 1000
-#define MAX_ENDPOINTS 32
-#define MAX_INTERFACES 8
-#define MAX_CONFIGS 8
-#define MAX_CHILDREN 8
-
-#define DEVICE_VERSION_SIZE 6
-#define DEVICE_CLASS_SIZE 10
-#define DEVICE_SUBCLASS_SIZE 3
-#define DEVICE_PROTOCOL_SIZE 3
-#define DEVICE_VENDOR_ID_SIZE 5
-#define DEVICE_PRODUCT_ID_SIZE 5
-#define DEVICE_REVISION_NUMBER_SIZE 6
-
-#define CONFIG_ATTRIBUTES_SIZE 3
-#define CONFIG_MAXPOWER_SIZE 10
-
-#define INTERFACE_CLASS_SIZE 10
-
-#define ENDPOINT_TYPE_SIZE 5
-#define ENDPOINT_MAXPACKETSIZE_SIZE 5
-#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="
-#define TOPOLOGY_COUNT_STRING "Cnt="
-#define TOPOLOGY_DEVICENUMBER_STRING "Dev#="
-#define TOPOLOGY_SPEED_STRING "Spd="
-#define TOPOLOGY_MAXCHILDREN_STRING "MxCh="
-
-#define BANDWIDTH_ALOCATED "Alloc="
-#define BANDWIDTH_TOTAL "/"
-#define BANDWIDTH_PERCENT "us ("
-#define BANDWIDTH_INTERRUPT_TOTAL "#Int="
-#define BANDWIDTH_ISOC_TOTAL "#Iso="
-
-#define DEVICE_VERSION_STRING "Ver="
-#define DEVICE_CLASS_STRING "Cls="
-#define DEVICE_SUBCLASS_STRING "Sub="
-#define DEVICE_PROTOCOL_STRING "Prot="
-#define DEVICE_MAXPACKETSIZE_STRING "MxPS="
-#define DEVICE_NUMCONFIGS_STRING "#Cfgs="
-#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#="
-#define CONFIG_ATTRIBUTES_STRING "Atr="
-#define CONFIG_MAXPOWER_STRING "MxPwr="
-
-#define INTERFACE_NUMBER_STRING "If#="
-#define INTERFACE_ALTERNATESETTING_STRING "Alt="
-#define INTERFACE_NUMENDPOINTS_STRING "#EPs="
-#define INTERFACE_CLASS_STRING "Cls="
-#define INTERFACE_SUBCLASS_STRING "Sub="
-#define INTERFACE_PROTOCOL_STRING "Prot="
-#define INTERFACE_DRIVERNAME_STRING "Driver="
-#define INTERFACE_DRIVERNAME_STRING_MAXLENGTH 50
-
-#define ENDPOINT_ADDRESS_STRING "Ad="
-#define ENDPOINT_ATTRIBUTES_STRING "Atr="
-#define ENDPOINT_MAXPACKETSIZE_STRING "MxPS="
-#define ENDPOINT_INTERVAL_STRING "Ivl="
-
-
-
-typedef struct DeviceEndpoint {
- gint address;
- gboolean in; /* TRUE if in, FALSE if out */
- gint attribute;
- gchar *type;
- gint maxPacketSize;
- gchar *interval;
-} DeviceEndpoint;
-
-
-typedef struct DeviceInterface {
- gchar *name;
- gint interfaceNumber;
- gint alternateNumber;
- gint numEndpoints;
- gint subClass;
- gint protocol;
- gchar *class;
- DeviceEndpoint *endpoint[MAX_ENDPOINTS];
-} DeviceInterface;
-
-
-
-typedef struct DeviceConfig {
- gint configNumber;
- gint numInterfaces;
- gint attributes;
- gchar *maxPower;
- DeviceInterface *interface[MAX_INTERFACES];
-} DeviceConfig;
-
-
-typedef struct DeviceBandwidth {
- gint allocated;
- gint total;
- gint percent;
- gint numInterruptRequests;
- gint numIsocRequests;
-} DeviceBandwidth;
-
-
-typedef struct Device {
- gchar *name;
- gint busNumber;
- gint level;
- gint parentNumber;
- gint portNumber;
- gint connectorNumber;
- gint count;
- gint deviceNumber;
- gint speed;
- gint maxChildren;
- gchar *version;
- gchar *class;
- gchar *subClass;
- gchar *protocol;
- gint maxPacketSize;
- gint numConfigs;
- gint vendorId;
- gint productId;
- gchar *revisionNumber;
- gchar *manufacturer;
- gchar *product;
- gchar *serialNumber;
- DeviceConfig *config[MAX_CONFIGS];
- struct Device *parent;
- struct Device *child[MAX_CHILDREN];
- DeviceBandwidth *bandwidth;
- GtkWidget *tree;
- GtkWidget *leaf;
-} Device;
-
-static Device *rootDevice = NULL;
-static Device *lastDevice = NULL;
-static DeviceBandwidth *currentBandwidth = NULL;
-
-
-static signed int GetInt (char *string, char *pattern, int base)
-{
- char *pointer;
-
- pointer = strstr (string, pattern);
- if (pointer == NULL)
- return (0);
-
- pointer += strlen(pattern);
- return ((int)(strtol (pointer, NULL, base)));
-}
-
-/*
-static double GetFloat (char *string, char *pattern)
-{
- char *pointer;
-
- pointer = strstr (string, pattern);
- if (pointer == NULL)
- return (0.0);
-
- pointer += strlen(pattern);
- return (strtod (pointer, NULL));
-}
-*/
-
-
-static void GetString (char *dest, char *source, char *pattern, int maxSize)
-{
- char *pointer;
-
- pointer = strstr (source, pattern);
- if (pointer == NULL)
- return;
-
- pointer += strlen(pattern);
- strncpy (dest, pointer, maxSize);
- return;
-}
-
-
-static void DestroyEndpoint (DeviceEndpoint *endpoint)
-{
- if (endpoint == NULL)
- return;
-
- g_free (endpoint->type);
- g_free (endpoint->interval);
-
- g_free (endpoint);
-
- return;
-}
-
-
-static void DestroyInterface (DeviceInterface *interface)
-{
- int i;
-
- if (interface == NULL)
- return;
-
- for (i = 0; i < MAX_ENDPOINTS; ++i)
- DestroyEndpoint (interface->endpoint[i]);
-
- g_free (interface->name);
- g_free (interface->class);
-
- g_free (interface);
-
- return;
-}
-
-
-static void DestroyConfig (DeviceConfig *config)
-{
- int i;
-
- if (config == NULL)
- return;
-
- for (i = 0; i < MAX_INTERFACES; ++i)
- DestroyInterface (config->interface[i]);
-
- g_free (config->maxPower);
-
- g_free (config);
-
- return;
-}
-
-
-static void DestroyBandwidth (DeviceBandwidth *bandwidth)
-{
- /* nothing dynamic in the bandwidth structure yet. */
- return;
-}
-
-
-static void DestroyDevice (Device *device)
-{
- int i;
-
- if (device == NULL)
- return;
-
- for (i = 0; i < MAX_CHILDREN; ++i)
- DestroyDevice (device->child[i]);
-
- for (i = 0; i < MAX_CONFIGS; ++i)
- DestroyConfig (device->config[i]);
-
- if (device->bandwidth != NULL) {
- DestroyBandwidth (device->bandwidth);
- g_free (device->bandwidth);
- }
-
- g_free (device->name);
- g_free (device->version);
- g_free (device->class);
- 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);
-
- return;
-}
-
-
-
static void Init (void)
{
+ /* blow away the tree if there is one */
if (rootDevice != NULL) {
- DestroyDevice (rootDevice);
- rootDevice = NULL;
- }
-
- 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);
+ gtk_ctree_remove_node (GTK_CTREE(treeUSB), GTK_CTREE_NODE(rootDevice->leaf));
+ }
/* clean out the text box */
gtk_editable_delete_text (GTK_EDITABLE(textDescription), 0, -1);
- lastDevice = NULL;
-
return;
}
-static Device *FindDeviceNode (Device *device, int deviceNumber, int busNumber)
-{
- int i;
- Device *result;
-
- if (device == NULL)
- return (NULL);
-
- if ((device->deviceNumber == deviceNumber) &&
- (device->busNumber == busNumber))
- return (device);
-
- for (i = 0; i < MAX_CHILDREN; ++i) {
- result = FindDeviceNode (device->child[i], deviceNumber, busNumber);
- if (result != NULL)
- return (result);
- }
-
- return (NULL);
-}
-
-
-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, busNumber);
- if (result != NULL)
- return (result);
- }
- return (NULL);
-}
-
-
-static Device *AddDevice (char *line)
-{
- Device *device;
-
- /* create a new device */
- 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->maxChildren = GetInt (line, TOPOLOGY_MAXCHILDREN_STRING, 10);
-
- if (device->deviceNumber == -1)
- device->deviceNumber = 0;
-
- /* Set up the parent / child relationship */
- if (device->level == 0) {
- /* this is the root, don't go looking for a parent */
- device->parent = rootDevice;
- ++rootDevice->maxChildren;
- rootDevice->child[rootDevice->maxChildren-1] = device;
- }
- else {
- /* need to find this device's parent */
- device->parent = FindDevice (device->parentNumber, device->busNumber);
- if (device->parent == NULL) {
- printf ("can't find parent...not good.\n");
- }
- device->parent->child[device->portNumber] = device;
- }
-
- return (device);
-}
-
-
-
-
-
-static void GetDeviceInformation (Device *device, char *data)
-{
- if (device == NULL)
- return;
-
- g_free (device->version);
- g_free (device->class);
- g_free (device->subClass);
- g_free (device->protocol);
-
- device->version = (char *)g_malloc0 ((DEVICE_VERSION_SIZE) * sizeof(char));
- device->class = (char *)g_malloc0 ((DEVICE_CLASS_SIZE) * sizeof(char));
- device->subClass = (char *)g_malloc0 ((DEVICE_SUBCLASS_SIZE) * sizeof(char));
- device->protocol = (char *)g_malloc0 ((DEVICE_PROTOCOL_SIZE) * sizeof(char));
-
- GetString (device->version, data, DEVICE_VERSION_STRING, DEVICE_VERSION_SIZE-1);
- GetString (device->class, data, DEVICE_CLASS_STRING, DEVICE_CLASS_SIZE-1);
- GetString (device->subClass, data, DEVICE_SUBCLASS_STRING, DEVICE_SUBCLASS_SIZE-1);
- GetString (device->protocol, data, DEVICE_PROTOCOL_STRING, DEVICE_PROTOCOL_SIZE-1);
-
- device->maxPacketSize = GetInt (data, DEVICE_MAXPACKETSIZE_STRING, 10);
- device->numConfigs = GetInt (data, DEVICE_NUMCONFIGS_STRING, 10);
-
- return;
-}
-
-
-
-static void GetMoreDeviceInformation (Device *device, char *data)
-{
- if (device == NULL)
- return;
-
- g_free (device->revisionNumber);
-
- device->vendorId = GetInt (data, DEVICE_VENDOR_STRING, 16);
- device->productId = GetInt (data, DEVICE_PRODUCTID_STRING, 16);
-
- device->revisionNumber = (char *)g_malloc0 ((DEVICE_REVISION_NUMBER_SIZE) * sizeof(char));
- GetString (device->revisionNumber, data, DEVICE_REVISION_STRING, DEVICE_REVISION_NUMBER_SIZE);
-
- return;
-}
-
-
-static void GetDeviceString (Device *device, char *data)
-{
- if (device == NULL)
- return;
-
- 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;
-}
-
-
-static void AddConfig (Device *device, char *data)
-{
- DeviceConfig *config;
- int i;
-
- if (device == NULL)
- return;
-
- /* Find the next available config in this device */
- for (i = 0; i < MAX_CONFIGS; ++i) {
- if (device->config[i] == NULL) {
- break;
- }
- }
- if (i >= MAX_CONFIGS) {
- /* ran out of room to hold this config */
- g_warning ("Too many configs for this device.\n");
- return;
- }
-
- config = (DeviceConfig *)g_malloc0 (sizeof(DeviceConfig));
- config->maxPower = (gchar *)g_malloc0 ((CONFIG_MAXPOWER_SIZE) * sizeof(gchar));
-
- config->numInterfaces = GetInt (data, CONFIG_NUMINTERFACES_STRING, 10);
- config->configNumber = GetInt (data, CONFIG_CONFIGNUMBER_STRING, 10);
- config->attributes = GetInt (data, CONFIG_ATTRIBUTES_STRING, 16);
-
- GetString (config->maxPower, data, CONFIG_MAXPOWER_STRING, CONFIG_MAXPOWER_SIZE);
-
- /* have the device now point to this config */
- device->config[i] = config;
-
- return;
-}
-
-
-static void AddInterface (Device *device, char *data)
-{
- DeviceConfig *config;
- DeviceInterface *interface;
- int i;
- int configNum;
-
- if (device == NULL)
- return;
-
- /* find the LAST config in the device */
- configNum = -1;
- for (i = 0; i < MAX_CONFIGS; ++i)
- if (device->config[i])
- configNum = i;
- if (configNum == -1) {
- /* no config to put this interface at, not good */
- g_warning ("No config to put an interface at for this device.\n");
- return;
- }
-
- config = device->config[configNum];
-
- /* now find a place in this config to place the interface */
- for (i = 0; i < MAX_INTERFACES; ++i)
- if (config->interface[i] == NULL)
- break;
- if (i >= MAX_INTERFACES) {
- /* ran out of room to hold this interface */
- g_warning ("Too many interfaces for this device.\n");
- return;
- }
-
- interface = (DeviceInterface *)g_malloc0 (sizeof(DeviceInterface));
-
- interface->class = (gchar *)g_malloc0 ((INTERFACE_CLASS_SIZE) * sizeof(gchar));
- interface->name = (gchar *)g_malloc0 ((INTERFACE_DRIVERNAME_STRING_MAXLENGTH) * sizeof(gchar));
-
- interface->interfaceNumber = GetInt (data, INTERFACE_NUMBER_STRING, 10);
- interface->alternateNumber = GetInt (data, INTERFACE_ALTERNATESETTING_STRING, 10);
- interface->numEndpoints = GetInt (data, INTERFACE_NUMENDPOINTS_STRING, 10);
- interface->subClass = GetInt (data, INTERFACE_SUBCLASS_STRING, 10);
- interface->protocol = GetInt (data, INTERFACE_PROTOCOL_STRING, 10);
-
- GetString (interface->class, data, INTERFACE_CLASS_STRING, INTERFACE_CLASS_SIZE);
- GetString (interface->name, data, INTERFACE_DRIVERNAME_STRING, INTERFACE_DRIVERNAME_STRING_MAXLENGTH);
-
- /* now point the config to this interface */
- config->interface[i] = interface;
-
- return;
-}
-
-
-static void AddEndpoint (Device *device, char *data)
-{
- DeviceConfig *config;
- DeviceInterface *interface;
- DeviceEndpoint *endpoint;
- int i;
- int configNum;
- int interfaceNum;
-
- if (device == NULL)
- return;
-
- /* find the LAST config in the device */
- configNum = -1;
- for (i = 0; i < MAX_CONFIGS; ++i)
- if (device->config[i])
- configNum = i;
- if (configNum == -1) {
- /* no config to put this interface at, not good */
- g_warning ("No config to put an interface at for this device.\n");
- return;
- }
-
- config = device->config[configNum];
-
- /* find the LAST interface in the config */
- interfaceNum = -1;
- for (i = 0; i < MAX_INTERFACES; ++i)
- if (config->interface[i])
- interfaceNum = i;
- if (interfaceNum == -1) {
- /* no interface to put this endpoint at, not good */
- g_warning ("No interface to put an endpoint at for this device.\n");
- return;
- }
-
- interface = config->interface[interfaceNum];
-
- /* now find a place in this interface to place the endpoint */
- for (i = 0; i < MAX_ENDPOINTS; ++i) {
- if (interface->endpoint[i] == NULL) {
- break;
- }
- }
- if (i >= MAX_ENDPOINTS) {
- /* ran out of room to hold this endpoint */
- g_warning ("Too many endpoints for this device.\n");
- return;
- }
-
- endpoint = (DeviceEndpoint *)g_malloc0 (sizeof(DeviceEndpoint));
-
- endpoint->type = (gchar *)g_malloc0 ((ENDPOINT_TYPE_SIZE) * sizeof(gchar));
- endpoint->interval = (gchar *)g_malloc0 ((ENDPOINT_INTERVAL_SIZE) * sizeof(gchar));
-
- endpoint->address = GetInt (data, ENDPOINT_ADDRESS_STRING, 16);
- if (data[10] == 'I')
- endpoint->in = TRUE;
- else
- endpoint->in = FALSE;
- endpoint->attribute = GetInt (data, ENDPOINT_ATTRIBUTES_STRING, 16);
- endpoint->maxPacketSize = GetInt (data, ENDPOINT_MAXPACKETSIZE_STRING, 10);
-
- GetString (interface->class, data, INTERFACE_CLASS_STRING, INTERFACE_CLASS_SIZE);
-
- memcpy (endpoint->type, &data[20], ENDPOINT_TYPE_SIZE-1);
- GetString (endpoint->interval, data, ENDPOINT_INTERVAL_STRING, ENDPOINT_INTERVAL_SIZE);
-
- /* point the interface to the endpoint */
- interface->endpoint[i] = endpoint;
-}
-
-
static void PopulateListBox (int deviceId)
{
Device *device;
@@ -703,7 +68,7 @@ static void PopulateListBox (int deviceId)
int deviceNumber = (deviceId >> 8);
int busNumber = (deviceId & 0x00ff);
- device = FindDevice (deviceNumber, busNumber);
+ device = usb_find_device (deviceNumber, busNumber);
if (device == NULL) {
printf ("Can't seem to find device info to display\n");
return;
@@ -830,8 +195,12 @@ static void PopulateListBox (int deviceId)
-void SelectItem (GtkWidget *widget, gpointer data)
+//void SelectItem (GtkWidget *widget, gpointer data)
+void SelectItem (GtkWidget *widget, GtkCTreeNode *node, gint column, gpointer userData)
{
+ int data;
+ data = (int) gtk_ctree_node_get_row_data (GTK_CTREE (widget), node);
+
PopulateListBox ((int)data);
return;
@@ -841,17 +210,73 @@ void SelectItem (GtkWidget *widget, gpointer data)
static void DisplayDevice (Device *parent, Device *device)
{
int i;
- char hasChildren;
+ gchar *text[1];
+ //GdkPixmap *pixmap;
+ //GdkBitmap *mask;
+
+ if (device == NULL)
+ return;
+
+ //pixmap = gdk_pixmap_create_from_xpm_d (NULL, &mask, NULL, mouse_xpm);
+
+ text[0] = device->name;
+ device->leaf = gtk_ctree_insert_node (GTK_CTREE(treeUSB), parent->leaf, NULL, text, 1, NULL, NULL, NULL, NULL, FALSE, FALSE);
+ gtk_ctree_node_set_row_data (GTK_CTREE(treeUSB), device->leaf, (gpointer)((device->deviceNumber<<8) | (device->busNumber)));
+
+#ifdef 0
+ int i;
+ int configNum;
+ int interfaceNum;
+ char hasChildren;
+ gboolean driverAttached = TRUE;
if (device == NULL)
return;
+ /* determine if this device has drivers attached to all interfaces */
+ for (configNum = 0; configNum < MAX_CONFIGS; ++configNum) {
+ if (device->config[configNum]) {
+ DeviceConfig *config = device->config[configNum];
+ for (interfaceNum = 0; interfaceNum < MAX_INTERFACES; ++interfaceNum) {
+ if (config->interface[interfaceNum]) {
+ DeviceInterface *interface = config->interface[interfaceNum];
+ if (interface->driverAttached == FALSE) {
+ driverAttached = FALSE;
+ break;
+ }
+ }
+ }
+ }
+ }
+
/* create the leaf for this device */
device->leaf = gtk_tree_item_new_with_label (device->name);
if (parent->tree == NULL)
gtk_tree_append (GTK_TREE (treeUSB), device->leaf);
else
gtk_tree_append (GTK_TREE (parent->tree), device->leaf);
+
+ /* change the color of this leaf if there are no drivers attached to it */
+ if (driverAttached == FALSE) {
+ GdkColor red = {0, 0xffff, 0x0000, 0x0000};
+ GtkStyle *defaultStyle;
+ GtkStyle *style;
+
+ /* get the current style */
+ defaultStyle = gtk_widget_get_default_style();
+ style = gtk_style_copy (defaultStyle);
+ for (i = 0; i < 5; ++i) {
+ style->fg[i] = red;
+ style->bg[i] = red;
+ style->text[i] = red;
+ style->base[i] = red;
+ style->light[i] = red;
+ style->dark[i] = red;
+ style->mid[i] = red;
+ }
+ gtk_widget_set_style (device->leaf, style);
+ }
+
gtk_widget_show (device->leaf);
/* hook up our callback function to this node */
@@ -871,7 +296,8 @@ static void DisplayDevice (Device *parent, Device *device)
gtk_tree_item_set_subtree (GTK_TREE_ITEM(device->leaf), device->tree);
gtk_tree_item_expand (GTK_TREE_ITEM(device->leaf)); /* make the tree expanded to start with */
}
-
+#endif
+
/* create all of the children's leafs */
for (i = 0; i < MAX_CHILDREN; ++i) {
DisplayDevice (device, device->child[i]);
@@ -881,124 +307,12 @@ static void DisplayDevice (Device *parent, Device *device)
}
-/* Build all of the names of the devices */
-static void NameDevices (Device *device)
-{
- int configNum;
- int interfaceNum;
- int i;
-
- if (device == NULL)
- return;
-
- /* build the name for this device */
- if (device != rootDevice) {
- if (device->name)
- 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 */
- for (configNum = 0; configNum < MAX_CONFIGS; ++configNum) {
- if (device->config[configNum]) {
- DeviceConfig *config = device->config[configNum];
- for (interfaceNum = 0; interfaceNum < MAX_INTERFACES; ++interfaceNum) {
- if (config->interface[interfaceNum]) {
- DeviceInterface *interface = config->interface[interfaceNum];
- if (interface->name != NULL) {
- if (strstr (interface->name, "none") == NULL) {
- if (strcmp (interface->name, "hid") == 0) {
- if (interface->subClass == 1) {
- switch (interface->protocol) {
- case 1 :
- strcat (device->name, "keyboard");
- continue;
- case 2 :
- strcat (device->name, "mouse");
- continue;
- }
- }
- }
- if (strlen (device->name) > 0) {
- strcat (device->name, " / ");
- }
- strcat (device->name, interface->name);
- }
- }
- }
- }
- }
- }
- }
-
-create_children_names:
-
- /* create all of the children's names */
- for (i = 0; i < MAX_CHILDREN; ++i) {
- NameDevices (device->child[i]);
- }
-
- return;
-}
-
-
-static void ParseLine (char * line)
-{
- /* chop off the trailing \n */
- line[strlen(line)-1] = 0x00;
- /* look at the first character to see what kind of line this is */
- switch (line[0]) {
- case 'T': /* topology */
- lastDevice = AddDevice (line);
- break;
-
- case 'B': /* bandwidth */
- GetBandwidth (lastDevice, line);
- break;
-
- case 'D': /* device information */
- GetDeviceInformation (lastDevice, line);
- break;
-
- case 'P': /* more device information */
- GetMoreDeviceInformation (lastDevice, line);
- break;
-
- case 'S': /* device string information */
- GetDeviceString (lastDevice, line);
- break;
-
- case 'C': /* config descriptor info */
- AddConfig (lastDevice, line);
- break;
-
- case 'I': /* interface descriptor info */
- AddInterface (lastDevice, line);
- break;
-
- case 'E': /* endpoint descriptor info */
- AddEndpoint (lastDevice, line);
- break;
-
- default:
- break;
- }
-
- return;
-}
+gchar devicesFile[1000];
+const char *verifyMessage = "Verify that you have USB compiled into your kernel,\n"
+ "have the USB core modules loaded, and have the\n"
+ "usbdevfs filesystem mounted.";
void LoadUSBTree (void)
{
@@ -1007,35 +321,65 @@ void LoadUSBTree (void)
int finished;
int i;
- usbFile = fopen ("/proc/bus/usb/devices", "r");
+ usbFile = fopen (devicesFile, "r");
if (usbFile == NULL) {
- 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.");
+ gchar *tempString = g_malloc0(strlen (verifyMessage) + strlen (devicesFile) + 50);
+ sprintf (tempString, "Can not open %s\n%s", devicesFile, verifyMessage);
+ ShowMessage ("USBView Error", tempString);
+ g_free (tempString);
return;
}
finished = 0;
+
Init();
+ usb_initialize_list ();
+
dataLine = (char *)g_malloc (MAX_LINE_SIZE);
while (!finished) {
/* read the line in from the file */
fgets (dataLine, MAX_LINE_SIZE, usbFile);
if (dataLine[strlen(dataLine)-1] == '\n')
- ParseLine (dataLine);
+ usb_parse_line (dataLine);
if (feof (usbFile))
finished = 1;
}
g_free (dataLine);
- NameDevices (rootDevice);
+ usb_name_devices ();
+ /* set up our tree */
+ gtk_ctree_set_line_style (GTK_CTREE(treeUSB), GTK_CTREE_LINES_DOTTED);
+ gtk_ctree_set_expander_style (GTK_CTREE(treeUSB), GTK_CTREE_EXPANDER_SQUARE);
+ gtk_ctree_set_indent (GTK_CTREE(treeUSB),10);
+ gtk_clist_column_titles_passive (GTK_CLIST(treeUSB));
+
+ /* build our tree */
for (i = 0; i < rootDevice->maxChildren; ++i) {
DisplayDevice (rootDevice, rootDevice->child[i]);
}
+ gtk_widget_show (treeUSB);
+
+ gtk_ctree_expand_recursive (GTK_CTREE(treeUSB), NULL);
+
+ /* hook up our callback function to this tree */
+ gtk_signal_disconnect_by_func (GTK_OBJECT (treeUSB), GTK_SIGNAL_FUNC (SelectItem), NULL);
+ gtk_signal_connect (GTK_OBJECT (treeUSB), "tree-select-row", GTK_SIGNAL_FUNC (SelectItem), NULL);
+
return;
}
+
+
+
+void initialize_stuff (void)
+{
+ strcpy (devicesFile, "/proc/bus/usb/devices");
+// strcpy (devicesFile, "/home/greg/uhci.proc");