- Removed generics, built with gcj. - Added super_root so that all controllers are shown, not just the first one. - Prevent traceback with converting 0x80 into a byte. - Make it so that data is shown for all URBs, both input and output. - Reader helpers are made to stop and start reading. This is still a little iffy, but is at least a step in the right direction. diff -urp -X dontdiffjava USBMon-0.3/README.txt USBMon-0.4/README.txt --- USBMon-0.3/README.txt 2005-03-27 15:38:58.000000000 -0800 +++ USBMon-0.4/README.txt 2005-05-12 18:27:52.000000000 -0700 @@ -1,11 +1,11 @@ -README for USBMon 0.3 -2005/03/27 +README for USBMon 0.4 +2005/05/12 Introduction: The USBMon is a graphical tool to capture traffic on USB bus (in theory). -In practice, release 0.3 is practically useless. It is intended to keep -the useful source code. +In practice, release 0.4 is largely useless. It is intended to serve as +a base for development. Included files: @@ -56,3 +56,5 @@ Away you go... This document was originated by Dave Harding (as dave.harding@ed.ac.uk: the e-mail address is no longer functional). + +Current maintainer is Pete Zaitcev diff -urp -X dontdiffjava USBMon-0.3/USBMon/Bus.java USBMon-0.4/USBMon/Bus.java --- USBMon-0.3/USBMon/Bus.java 2005-03-14 22:50:36.000000000 -0800 +++ USBMon-0.4/USBMon/Bus.java 2005-05-12 17:48:11.000000000 -0700 @@ -43,7 +43,7 @@ public class Bus * tree-like fashion. */ public Device root_hub; - + /** * The amount of bandwidth allocated to this Bus * @@ -74,7 +74,9 @@ public class Bus * placeholder to keep a link to the thread that reads the * /sys/kernel/debug/usbmon/0t. */ - public Mfilereader mfilereader; + private Mfilereader mfilereader; + + private int mon_level; // Per-bus monitoring level /** * Search for a particular device and return it. @@ -123,7 +125,29 @@ public class Bus number=bus_no; } + /* This only starts the helper task, but not reading */ public void readStart(Bus bus) { mfilereader = new Mfilereader(bus); } + + public void changeMonLevel(int delta) + { + mon_level += delta; +System.out.println("Bus " + number + " level " + mon_level); // P3 + if (mon_level > 0) { + /* + * Start the reading in the helper. + */ + mfilereader.wakeUp(); + } else { + /* + * Stop the reading in the helper. + * + * We do not want to interrupt read(2), so we just leave + * the reader task alone to finish when it reads the next event. + */ + } + } + + public int getMonLevel() { return mon_level; } } diff -urp -X dontdiffjava USBMon-0.3/USBMon/Device.java USBMon-0.4/USBMon/Device.java --- USBMon-0.3/USBMon/Device.java 2005-03-14 17:42:01.000000000 -0800 +++ USBMon-0.4/USBMon/Device.java 2005-05-02 00:36:09.000000000 -0700 @@ -124,11 +124,6 @@ public class Device implements TreeModel */ public int num_configs; - /** - * Number of endpointd (** INTERNAL **) - */ - public int num_endpoints; - /** * The Manufacturer number. */ @@ -196,6 +191,11 @@ public class Device implements TreeModel * This holds the tabbed pane for this device. */ public JTabbedPane tabbed_pane; + + /** + * This is needed for the TreeModel interface. + */ + private Device super_root; /** * The search method searches for devices with a particular device @@ -265,7 +265,9 @@ public class Device implements TreeModel */ public Object getRoot() { - return(bus.root_hub); + if (super_root == null) + return this; + return super_root; } /** @@ -275,7 +277,6 @@ public class Device implements TreeModel */ public Object getChild(Object parent, int index) { - Device rc; /*StringBuffer rep=new StringBuffer(); rep.append("getChild called with dev,num "); @@ -283,18 +284,7 @@ public class Device implements TreeModel rep.append(" , "); rep.append(index); System.out.println(rep.toString());*/ - if(this == (Device)parent){ - return(children.get(index)); - }else{ - try{ - rc=search(((Device)parent).num); - }catch(Exception e){ - System.out.println("WARNING - exception caught in getChild"); - return(null); - } - - return(rc.children.get(index)); - } + return ((Device)parent).children.get(index); } /** @@ -304,18 +294,7 @@ public class Device implements TreeModel */ public int getChildCount(Object parent) { - Device rc; - if(this == (Device)parent){ - return(children.size()); - }else{ - try{ - rc=search(((Device)parent).num); - }catch(Exception e){ - return(0); - } - - return(rc.children.size()); - } + return ((Device)parent).children.size(); } /** @@ -325,18 +304,7 @@ public class Device implements TreeModel */ public int getIndexOfChild(Object parent, Object child) { - Device rc; - if(this == (Device)parent){ - return(children.indexOf(child)); - }else{ - try{ - rc=search(((Device)parent).num); - }catch(Exception e){ - return(0); - } - - return(rc.children.indexOf(child)); - } + return ((Device)parent).children.indexOf(child); } /** @@ -348,35 +316,7 @@ public class Device implements TreeModel */ public boolean isLeaf(Object dev) { - Device rc; - - if(this == (Device)dev){ - if(children.size()==0){ - - return(true); - }else{ - - return(false); - } - }else{ - try{ - rc=search(((Device)dev).num); - }catch(Exception e){ - if(children.size()==0){ - - return(true); - }else{ - - return(false); - } - } - - if(rc.children.size()==0){ - return(true); - }else{ - return(false); - } - } + return ((Device)dev).children.size() == 0; } /** @@ -490,10 +430,13 @@ public class Device implements TreeModel ep=(endpoint) temp_if.endpoint_list.get(c); - System.out.println("ep "+c); - e.append("Endpoint "); e.append(ep.address); + if (ep.input) { + e.append("(I)"); + } else { + e.append("(O)"); + } temp_pane.add( new JLabel(e.toString())); @@ -625,8 +568,17 @@ public class Device implements TreeModel { StringBuffer s = new StringBuffer(); - s.append("USB Device "); - s.append(num); + if (super_root == null) { + s.append("All USB Devices"); + return s.toString(); + } + if (bus.root_hub == this) { + s.append("USB Bus "); + s.append(bus.number); + } else { + s.append("USB Device "); + s.append(num); + } s.append(" ("); s.append(product_string); s.append(") "); @@ -639,6 +591,8 @@ public class Device implements TreeModel */ public String details() { + if (bus == null) + return "Super-root\n"; return( "Device Number:"+'\t'+num+'\n'+ "Bus:"+'\t'+'\t'+bus.number+'\n'+ "Level:"+'\t'+'\t'+level+'\n'+ @@ -662,12 +616,13 @@ public class Device implements TreeModel } - public Device(Bus bus0){ + public Device(Device super_root, Bus bus){ cfg_list = new Vector(); children = new Vector(); URB_list = new Vector(); - num_endpoints=1; - bus = bus0; + this.bus = bus; + this.num = 0; + this.super_root = super_root; } } diff -urp -X dontdiffjava USBMon-0.3/USBMon/endpoint.java USBMon-0.4/USBMon/endpoint.java --- USBMon-0.3/USBMon/endpoint.java 2005-03-08 18:20:06.000000000 -0800 +++ USBMon-0.4/USBMon/endpoint.java 2005-05-12 18:25:05.000000000 -0700 @@ -41,11 +41,6 @@ public class endpoint extends AbstractTa */ public int address; - /** - * The endpoint number - */ - public int number; - /** * The endpoint is an input. */ @@ -91,7 +86,7 @@ public class endpoint extends AbstractTa /** * The level at which this endpoint is currently monitored. */ - public int monitoring_level; + private int monitoring_level; /** * Create an address for printouts @@ -112,13 +107,14 @@ public class endpoint extends AbstractTa public void set_monitoring_level(int val) throws java.io.FileNotFoundException { - - System.out.println("e m level " + val); // P3 + dev.bus.changeMonLevel(val - monitoring_level); monitoring_level=val; - /* XXX Implement this ...... */ - System.out.println("e m level done"); // P3 } + public int get_monitoring_level() + { + return monitoring_level; + } /** * In Order to Extend AbstractTableModel so that the table of endpoints @@ -347,7 +343,6 @@ public class endpoint extends AbstractTa public endpoint(Device d){ monitoring_level = 0; - number=0; dev=d; URB_list=new Vector(); } diff -urp -X dontdiffjava USBMon-0.3/USBMon/i_f.java USBMon-0.4/USBMon/i_f.java --- USBMon-0.3/USBMon/i_f.java 2001-06-01 09:03:27.000000000 -0700 +++ USBMon-0.4/USBMon/i_f.java 2005-05-12 11:55:59.000000000 -0700 @@ -156,7 +156,7 @@ public class i_f extends AbstractTableMo return(new String(temp_Integer.toString())); //break; case 5: - switch(temp_ep.monitoring_level){ + switch(temp_ep.get_monitoring_level()){ case 0: return("No Monitoring"); case 1: diff -urp -X dontdiffjava USBMon-0.3/USBMon/Makefile USBMon-0.4/USBMon/Makefile --- USBMon-0.3/USBMon/Makefile 2005-01-28 16:31:29.000000000 -0800 +++ USBMon-0.4/USBMon/Makefile 2005-05-12 11:25:57.000000000 -0700 @@ -3,9 +3,9 @@ JAVA = java JAR = jar -#JAVAC = gcj -C -JAVAC = /usr/java/jdk1.5.0_01/bin/javac +#JAVAC = gcj -Wall -C #DEBUG = -g -deprecation +JAVAC = /usr/java/jdk1.5.0_01/bin/javac DEBUG = -O # JFLAGS = -classpath $(CLASSPATH):jar/cryptix.jar:. JFLAGS = diff -urp -X dontdiffjava USBMon-0.3/USBMon/Mfilereader.java USBMon-0.4/USBMon/Mfilereader.java --- USBMon-0.3/USBMon/Mfilereader.java 2005-03-23 19:25:24.000000000 -0800 +++ USBMon-0.4/USBMon/Mfilereader.java 2005-05-12 18:17:18.000000000 -0700 @@ -86,22 +86,14 @@ import java.util.*; public class Mfilereader { FileInputStream mreader; // This has .close() method ReaderTask rtask; - TreeMap active; + TreeMap active; - /** - * Generator Method - */ - public Mfilereader(Bus bus) { - /* - * We cannot pass the bus pointer because our constructor - * is called from the Bus constructor. So we look it up later. - */ - mreader = null; - rtask = null; - - active = new TreeMap(); + /* + * XXX Side effect: result in mreader. + */ + private void openStream(int bus_no) { - String fname = "/sys/kernel/debug/usbmon/" + bus.number + "t"; + String fname = "/sys/kernel/debug/usbmon/" + bus_no + "t"; File mfile = null; try { @@ -129,17 +121,37 @@ public class Mfilereader { mreader = null; } } + } - if (mreader != null) { - try { - rtask = new ReaderTask(bus); - rtask.start(); - } catch (Exception e) { - System.err.println("Mfilereader new ReaderTask " + fname); - System.err.println(e.toString()); - rtask = null; - } - } + /** + * Generator Method + */ + public Mfilereader(Bus bus) { + mreader = null; + rtask = null; + + active = new TreeMap(); + + try { + rtask = new ReaderTask(bus); + rtask.start(); + } catch (Exception e) { + System.err.println("Mfilereader new ReaderTask(" + + bus.number + ")"); + System.err.println(e.toString()); + rtask = null; + } + } + + /* + * Bus calls this when its monitoring level increases. + */ + public void wakeUp() { + if (rtask != null) { + synchronized(rtask) { + rtask.notify(); + } + } } /* @@ -169,6 +181,8 @@ public class Mfilereader { // d07a29a0 2372620219 C Ci:001:00 0 4 = 00010100 public ParsedLine(String line) { tag = new Long(0); + stamp = new Long(0); + type = "?"; /* * Constructor is ended at this point. Initiator starts. */ @@ -180,7 +194,7 @@ public class Mfilereader { } String tag_str = st.nextToken(); try { - tag = Long.parseLong(tag_str, 16); + tag = new Long(Long.parseLong(tag_str, 16)); } catch (NumberFormatException e) { return; } @@ -196,7 +210,7 @@ public class Mfilereader { * a) they are unsigned * b) it can return more in the future */ - stamp = Long.parseLong(stamp_str); + stamp = new Long(Long.parseLong(stamp_str)); } catch (NumberFormatException e) { stamp = new Long(-1); } @@ -218,16 +232,23 @@ public class Mfilereader { devnum = Integer.parseInt(pipe_str.substring(3, 6)); epnum = Integer.parseInt(pipe_str.substring(7, 9)); + /* + * Some controls can be submitted to "device 0". + * Substitute root hub for now... + */ + if (devnum == 0) { + devnum = 1; + } + if (!st.hasMoreTokens()) { System.err.println("No status token"); // P3 return; } String status_str = st.nextToken(); try { - status = Integer.valueOf(Integer.parseInt( - status_str)); + status = Integer.parseInt(status_str); } catch (NumberFormatException e) { - status = new Integer(-1); + status = -1; } if (!st.hasMoreTokens()) { @@ -236,10 +257,9 @@ public class Mfilereader { } String length_str = st.nextToken(); try { - xfer_len = Integer.valueOf(Integer.parseInt( - length_str)); + xfer_len = Integer.parseInt(length_str); } catch (NumberFormatException e) { - xfer_len = new Integer(0); + xfer_len = 0; } if (!st.hasMoreTokens()) { @@ -281,10 +301,17 @@ public class Mfilereader { String data_str = st.nextToken(); int len = data_str.length() / 2; int i; + int b; // byte is signed, apparently?! XXX for (i = 0; i < len; i++) { - data[data_len] = Byte.parseByte( - data_str.substring(i*2, i*2 + 2), - 16); + // data[data_len] = Byte.parseByte( + // data_str.substring(i*2, i*2 + 2), + // 16); + b = Integer.parseInt( + data_str.substring(i*2, i*2 + 2), + 16); + if (b >= 128) + b *= -1; + data[data_len] = (byte) b; data_len++; } } @@ -299,14 +326,41 @@ public class Mfilereader { } public void run() { + for (;;) { + if (bus.getMonLevel() > 0) { + if (mreader == null) { + openStream(bus.number); + } + if (mreader != null) { +System.out.println("Mfilereader:" + bus.number + " run read"); // P3 + readEvents(); + } else { +System.out.println("Mfilereader:" + bus.number + " wait (nofile)"); // P3 + waitMon(); + } + } else { + // if (mreader != null) + // { close the mreader } +System.out.println("Mfilereader:" + bus.number + " wait (level)"); // P3 + waitMon(); + } + } + } + + private synchronized void waitMon() { + try { + this.wait(); + } catch (InterruptedException e) { } + } + + public void readEvents() { try{ String c_str; int rc; byte line[] = new byte[500]; ParsedLine pline; - rc=0; - while(rc != -1){ + while (bus.getMonLevel() > 0) { URB urb; rc = mreader.read(line); @@ -319,7 +373,7 @@ public class Mfilereader { * and throw away the terminating newline. */ c_str = new String(line, 0, rc-1, "US-ASCII"); - System.out.println(c_str); + // System.out.println(c_str); pline = new ParsedLine(c_str); urb = getURB(pline, bus); @@ -330,7 +384,6 @@ public class Mfilereader { try{ //urb.dev.URB_list.add(urb); - System.out.println("hmmmm"); urb.ep.URB_list.add( urb); urb.ep.fireTableRowsInserted( @@ -343,8 +396,7 @@ public class Mfilereader { c_str); System.out.println( e.toString()); - throw - new NullPointerException(); + // throw new NullPointerException(); } urb.shown = true; } @@ -358,15 +410,14 @@ public class Mfilereader { if(Dev.tabbed_pane !=null){ Dev.tabbed_pane.repaint(); } - System.out.println("repainting details pane"); } // while }catch(Exception e){ - System.out.println("Mfilereader:"); - System.out.println(e.toString()); - System.out.println(e.getMessage()); - e.printStackTrace(System.out); + System.err.println("Mfilereader:"); + System.err.println(e.toString()); + System.err.println(e.getMessage()); + e.printStackTrace(System.err); } } @@ -430,7 +481,7 @@ public class Mfilereader { * Retire it if needed. * XXX Might as well just drop regardless. */ - if ((urb = active.get(pline.tag)) != null) { + if ((urb = (URB) active.get(pline.tag)) != null) { active.remove(pline.tag); urb = null; } @@ -445,17 +496,24 @@ public class Mfilereader { * Check if we knew about this. Sometimes URBs are * submitted before we start capture. */ - if ((urb = active.get(pline.tag)) == null) { + if ((urb = (URB) active.get(pline.tag)) == null) { urb = new URB(bus, pline.devnum, pline.epnum, pline.xfer_len, pline.xfer_len, pline.data_len, pline.data); } else { + /* + * XXX This has to be in a method like "URB.update()" + */ // urb.setStatus(pline.status); // urb.setLength(pline.xfer_len); urb.status = pline.status; urb.actual_length = pline.xfer_len; - urb.millisecond = pline.stamp / 1000; + urb.millisecond = pline.stamp.longValue() / 1000; + if (pline.data_len != 0) { // Check direction? + urb.data = pline.data; + urb.data_present = true; + } } /* XXX Figure out if we're likely to receive more callbacks */ active.remove(pline.tag); diff -urp -X dontdiffjava USBMon-0.3/USBMon/procfilehandler.java USBMon-0.4/USBMon/procfilehandler.java --- USBMon-0.3/USBMon/procfilehandler.java 2005-03-14 22:49:00.000000000 -0800 +++ USBMon-0.4/USBMon/procfilehandler.java 2005-05-02 00:38:32.000000000 -0700 @@ -48,7 +48,7 @@ public class procfilehandler * This refreshes the model of the USB. * */ - public void refresh() throws IOException, usb_search_exception { + public void refresh(Device super_root) throws IOException, usb_search_exception { File inputFile = new File(device_procfile); FileReader in = new FileReader(inputFile); @@ -115,12 +115,12 @@ public class procfilehandler bus_list.set(bus_no.intValue() - 1, current_bus); } - current_device = new Device(current_bus); + current_device = new Device(super_root, current_bus); current_device.Control_Pipe = new endpoint(current_device); - current_device.Control_Pipe.number=0; + current_device.Control_Pipe.address=0; tmp5i= tmp2.indexOf("Dev#="); @@ -164,6 +164,8 @@ public class procfilehandler current_device.level==0){ current_bus.root_hub= current_device; + super_root.children.add( + current_device); }else{ parent=current_bus.search( current_device.parent); @@ -261,15 +263,11 @@ public class procfilehandler tmp5i= tmp2.indexOf("Vendor="); - temp_Integer= new Integer(1); - - current_device.vendor = temp_Integer.parseInt((tmp2.substring(tmp5i+7,tmp5i+11).trim()),16); + current_device.vendor = Integer.parseInt((tmp2.substring(tmp5i+7,tmp5i+11).trim()),16); tmp5i= tmp2.indexOf("ProdID="); - temp_Integer= new Integer(1); - - current_device.product = temp_Integer.parseInt(tmp2.substring(tmp5i+7,tmp5i+11).trim(),16); + current_device.product = Integer.parseInt(tmp2.substring(tmp5i+7,tmp5i+11).trim(),16); tmp5i= tmp2.indexOf("Rev="); @@ -284,7 +282,6 @@ public class procfilehandler case 'S': { int tmp5i; - Integer temp_Integer; //System.out.println("S -line"); if (current_device == null) continue; @@ -333,9 +330,7 @@ public class procfilehandler tmp5i= tmp2.indexOf("Atr="); - temp_Integer= new Integer(1); - - current_cfg.attr = temp_Integer.parseInt(tmp2.substring(tmp5i+4,tmp5i+7).trim(), 16); + current_cfg.attr = Integer.parseInt(tmp2.substring(tmp5i+4,tmp5i+7).trim(), 16); tmp5i= tmp2.indexOf("MxPwr="); temp_Integer= new Integer(tmp2.substring(tmp5i+7,tmp5i+9).trim()); @@ -370,22 +365,18 @@ public class procfilehandler tmp5i= tmp2.indexOf("Cls="); - temp_Integer= new Integer(1); current_if.alt_cls= - temp_Integer.parseInt(tmp2.substring(tmp5i+4,tmp5i+6).trim(),16); + Integer.parseInt(tmp2.substring(tmp5i+4,tmp5i+6).trim(),16); current_if.alt_cls_string = tmp2.substring(tmp5i+7,tmp5i+12); tmp5i= tmp2.indexOf("Sub="); - temp_Integer= new Integer(1); - - current_if.alt_subclass = temp_Integer.parseInt(tmp2.substring(tmp5i+4,tmp5i+6).trim(),16); + current_if.alt_subclass = Integer.parseInt(tmp2.substring(tmp5i+4,tmp5i+6).trim(),16); tmp5i= tmp2.indexOf("Prot="); - temp_Integer= new Integer(1); - current_if.alt_protocol = temp_Integer.parseInt(tmp2.substring(tmp5i+5,tmp5i+7).trim(),16); + current_if.alt_protocol = Integer.parseInt(tmp2.substring(tmp5i+5,tmp5i+7).trim(),16); tmp5i= tmp2.indexOf("Driver="); @@ -404,18 +395,15 @@ public class procfilehandler current_endpoint = new endpoint( current_device); - current_endpoint.number = - current_device.num_endpoints; - current_device.num_endpoints++; - current_if.endpoint_list.add( current_endpoint); tmp5i=tmp2.indexOf("Ad="); - - temp_Integer= new Integer(tmp2.substring(tmp5i+3,tmp5i+5).trim()); current_endpoint.address = - temp_Integer.intValue(); + Integer.parseInt(tmp2.substring(tmp5i+3,tmp5i+5).trim(), 16); + if (current_endpoint.address >= 128) { + current_endpoint.address -= 128; + } if(tmp2.charAt(tmp5i+6)=='I'){ current_endpoint.input=true; current_endpoint.output=false; @@ -533,11 +521,11 @@ public class procfilehandler return ret; } - public procfilehandler() throws IOException, usb_search_exception + public procfilehandler(Device super_root) throws IOException, usb_search_exception { bus_list = new Vector(); device_procfile="/proc/bus/usb/devices"; //device_procfile="dummy_proc_file"; - refresh(); + refresh(super_root); } } diff -urp -X dontdiffjava USBMon-0.3/USBMon/URB.java USBMon-0.4/USBMon/URB.java --- USBMon-0.3/USBMon/URB.java 2005-03-23 19:13:04.000000000 -0800 +++ USBMon-0.4/USBMon/URB.java 2005-05-02 00:22:37.000000000 -0700 @@ -130,8 +130,6 @@ public class URB public URB(Bus bus, int devnum, int ep_num, int size0, int len, int data_len, byte[] rec_data) { - System.out.println("Creating URB"); - /** * ...and use it to search in the Bus for the device object. */ @@ -148,7 +146,7 @@ public class URB /** * Search for Endpoint Number... */ - epnum = ep_num; // +128 if input? XXX + epnum = ep_num; @@ -176,8 +174,6 @@ public class URB } } - System.out.println("Cfg " + cfg.num + " selected."); - for(a=0;a