added lsusb and some more config stuff. except of some (simple) setter
authorBernhard Urban <lewurm@gmx.net>
Tue, 22 Sep 2009 12:18:18 +0000 (14:18 +0200)
committerBernhard Urban <lewurm@gmx.net>
Tue, 22 Sep 2009 12:30:51 +0000 (14:30 +0200)
functions it should be fine now for some interrupt transfer hax :)

usb/Makefile
usb/core/core.c
usb/core/core.h
usb/core/usb.c
usb/core/usb.h

index ddd11fbdb39d559f016235b9ba95c7defc273aef..0171494c0ec1ba7fa4568b31c8e0b9d800f99892 100644 (file)
@@ -3,7 +3,7 @@ CFLAGS += -Wno-unused-parameter
 
 #debug flags; DU = Debug USB
 #CFLAGS += -D _DU_OHCI_F #fire @ u/h/ohci.c
 
 #debug flags; DU = Debug USB
 #CFLAGS += -D _DU_OHCI_F #fire @ u/h/ohci.c
-CFLAGS += -D _DU_OHCI_F_HALT #halted @ u/h/ohci.c
+#CFLAGS += -D _DU_OHCI_F_HALT #halted @ u/h/ohci.c
 #CFLAGS += -D _DU_OHCI_Q #enqueue @ u/h/ohci.c
 #CFLAGS += -D _DU_OHCI_RH #roothub @ u/h/ohci.c
 CFLAGS += -D _DU_CORE #@ u/c/core.c
 #CFLAGS += -D _DU_OHCI_Q #enqueue @ u/h/ohci.c
 #CFLAGS += -D _DU_OHCI_RH #roothub @ u/h/ohci.c
 CFLAGS += -D _DU_CORE #@ u/c/core.c
index 88e6f18e6063b228c01a5ac97fc013ef9cf09cb6..c3574283e0610562cfc13bf7b26d61aad61e8d0a 100644 (file)
@@ -113,153 +113,15 @@ struct usb_device *usb_add_device()
        u8 address = usb_next_address();
        ret = usb_set_address(dev, address);
        dev->address = address;
        u8 address = usb_next_address();
        ret = usb_set_address(dev, address);
        dev->address = address;
-#ifdef _DU_CORE_ADD
        printf("set address to %d\n", dev->address);
        printf("set address to %d\n", dev->address);
-#endif
 
        ret = usb_get_desc_dev(dev);
 
 
        ret = usb_get_desc_dev(dev);
 
-       char *man, *prod, *serial;
-       if(dev->iManufacturer) {
-               man = usb_get_string_simple(dev, dev->iManufacturer);
-       } else {
-               man = (char*) malloc(11);
-               memset(man, '\0', sizeof(man));
-               strlcpy(man, "no String", 10);
-       }
-       if(dev->iProduct) {
-               prod = usb_get_string_simple(dev, dev->iProduct);
-       } else {
-               prod = (char*) malloc(11);
-               memset(prod, '\0', sizeof(prod));
-               strlcpy(prod, "no String", 10);
-       }
-       if(dev->iSerialNumber) {
-               serial = usb_get_string_simple(dev, dev->iSerialNumber);
-       } else {
-               serial = (char*) malloc(11);
-               memset(serial, '\0', sizeof(serial));
-               strlcpy(serial, "no String", 10);
-       }
-
-       printf( "bLength 0x%02X\n"
-                       "bDescriptorType 0x%02X\n"
-                       "bcdUSB 0x%02X\n"
-                       "bDeviceClass 0x%02X\n"
-                       "bDeviceSubClass 0x%02X\n"
-                       "bDeviceProtocoll 0x%02X\n"
-                       "idVendor 0x%04X\n"
-                       "idProduct 0x%04X\n"
-                       "bcdDevice 0x%04X\n"
-                       "iManufacturer(0x%02X): \"%s\"\n"
-                       "iProduct(0x%02X): \"%s\"\n"
-                       "iSerialNumber(0x%02X): \"%s\"\n"
-                       "bNumConfigurations 0x%02X\n", dev->bLength, dev->bDeviceClass,
-                       dev->bcdUSB, dev->bDescriptorType, dev->bDeviceSubClass, 
-                       dev->bDeviceProtocoll, dev->idVendor, dev->idProduct, dev->bcdDevice, 
-                       dev->iManufacturer, man,
-                       dev->iProduct, prod,
-                       dev->iSerialNumber, serial,
-                       dev->bNumConfigurations);
-
-       /* in the most cases usb devices have just one configuration descriptor */
-       ret = usb_get_desc_config_ext(dev, 0);
-
        /* select configuration */
        ret = usb_set_configuration(dev, dev->conf->bConfigurationValue);
        printf("=============\nusb_set_configuration(ret: %d) %d\n", ret, dev->conf->bConfigurationValue);
 
        /* select configuration */
        ret = usb_set_configuration(dev, dev->conf->bConfigurationValue);
        printf("=============\nusb_set_configuration(ret: %d) %d\n", ret, dev->conf->bConfigurationValue);
 
-       /*
-       udelay(600000);
-
-       printf("=============\ninterfaces: %d\n", dev->conf->bNumInterfaces);
-       u8 i;
-       for(i = 1; i <= dev->conf->bNumInterfaces; i++) {
-               memset(buf, 0, sizeof(buf));
-               ret = usb_get_desc_interface(dev, 1, buf, sizeof(buf));
-               printf("=============\nafter usb_get_desc_interface_%d(ret: %d):\n", i, ret);
-               hexdump(buf, sizeof(buf));
-       }
-       */
-
-
-
-       /*
-       usb_get_descriptor(dev, DEVICE, 0, buf, 8);
-       memset(buf, 0, 8);
-       usb_get_descriptor(dev, DEVICE, 0, buf, size >= buf[0] ? buf[0] : size);
-       */
-#if 0
-       memset(buf, 0, sizeof(buf));
-       usb_control_msg(dev, 0x80, GET_DESCRIPTOR, (DEVICE << 8) | 0, 0, 8, buf, 0);
-       printf("=============\nbuf: 0x%08X\nafter usb control msg:\n", buf);
-       hexdump(buf, sizeof(buf));
-
-       memset(buf, 0, sizeof(buf));
-       usb_control_msg(dev, 0x80, GET_DESCRIPTOR, (DEVICE << 8) | 0, 0, buf[0], buf, 0);
-       printf("=============\nbuf: 0x%08X\nafter usb control msg:\n", buf);
-       hexdump(buf, sizeof(buf));
-
-       memset(buf, 0, sizeof(buf));
-       usb_get_string_simple(dev, 1, buf);
-       printf("=============\nbuf: 0x%08X\nafter usb control msg:\n", buf);
-       hexdump(buf, sizeof(buf));
-#endif
-
-#if 0
-       u8 devdescr_size;
-
-       /* setup real ep0 fifo size */
-       dev->bMaxPacketSize0 = (u8) buf[7];
-       if(!(u8)buf[7]) {
-               printf("FU\n");
-               return (void*)1;
-       }
-
-       /* save real length of device descriptor */
-       devdescr_size = (u8) buf[0];
-
-       /* define new adress */
-       memset(buf, 0, sizeof(buf));
-       usb_control_msg(dev, 0x00, SET_ADDRESS, address, 0, 0, buf, 8, 0);
-       dev->address = address;
-       printf("=============\nbuf: 0x%08X\nafter usb control msg:\n", buf);
-       hexdump(buf, sizeof(buf));
-       printf("address: %d\n", address);
-
-
-       /* get complete device descriptor */
-       memset(buf, 0, sizeof(buf));
-       usb_control_msg(dev, 0x80, GET_DESCRIPTOR, DEVICE<<8, 0, devdescr_size, buf, 8, 0);
-
-       printf("=============\nbuf: 0x%08X\nafter usb control msg:\n", buf);
-       hexdump(buf, sizeof(buf));
-
-       /* save only really neccessary values for this small usbstack */
-#endif
-
-#if 0
-       memset(buf, 0, sizeof(buf));
-       usb_control_msg(dev, 0x80, GET_DESCRIPTOR, (STRING<<8)|2, 0, 0x1a, buf, 8, 0);
-       hexdump(buf, sizeof(buf));
-       printf("String Descriptor [1]: ");
-       u8 i;
-       for (i=2; i<buf[0]; i+=2)
-               printf("%c", buf[i]);
-       printf("\n");
-#endif
-
-       /*
-       usb_control_msg(dev, 0x80, GET_DESCRIPTOR, (STRING<<8) | 2, 0, 0x20, buf, 8, 0);
-       printf("String Descriptor [2]: ");
-       for (i=2; i<buf[0]; i+=2)
-               printf("%c", buf[i]);
-       printf("\n");
-       */
-
-       // string descriptoren werden nicht im arbeitsspeicher gehalten -> on demand mit 
-       // entprechenden funktionen
-       // hier muss man noch mehr abholen, konfigurationene, interfaces und endpunkte
+       lsusb(dev);
 
 #if 0
        /* add device to device list */
 
 #if 0
        /* add device to device list */
@@ -273,6 +135,69 @@ struct usb_device *usb_add_device()
        return dev;
 }
 
        return dev;
 }
 
+void lsusb(struct usb_device *dev)
+{
+       printf("=== Device Descriptor === \n");
+       printf("bLength 0x%02X\n", dev->bLength);
+       printf("bDescriptorType 0x%02X\n", dev->bDeviceClass);
+       printf("bcdUSB 0x%02X\n", dev->bcdUSB);
+       printf("bDeviceClass 0x%02X\n", dev->bDeviceClass);
+       printf("bDeviceSubClass 0x%02X\n", dev->bDeviceSubClass);
+       printf("bDeviceProtocoll 0x%02X\n", dev->bDeviceProtocoll);
+       printf("idVendor 0x%04X\n", dev->idVendor);
+       printf("idProduct 0x%04X\n", dev->idProduct);
+       printf("bcdDevice 0x%04X\n", dev->bcdDevice);
+       printf("iManufacturer(0x%02X): \"%s\"\n", dev->iManufacturer, dev->iManufacturer ? usb_get_string_simple(dev, dev->iManufacturer) : "no String");
+       printf("iProduct(0x%02X): \"%s\"\n", dev->iProduct, dev->iProduct ? usb_get_string_simple(dev, dev->iProduct) : "no String");
+       printf("iSerialNumber(0x%02X): \"%s\"\n", dev->iSerialNumber, dev->iSerialNumber ? usb_get_string_simple(dev, dev->iSerialNumber) : "no String");
+       printf("bNumConfigurations 0x%02X\n", dev->bNumConfigurations);
+       
+       u8 c, i, e;
+       struct usb_conf *conf = dev->conf;
+       for(c=0; c <= dev->bNumConfigurations; c++) {
+               printf("  === Configuration Descriptor %d ===\n", c+1);
+               printf("  bLength 0x%02X\n", conf->bLength);
+               printf("  bDescriptorType 0x%02X\n", conf->bDescriptorType);
+               printf("  wTotalLength 0x%04X\n", conf->wTotalLength);
+               printf("  bNumInterfaces 0x%02X\n", conf->bNumInterfaces);
+               printf("  bConfigurationValue 0x%02X\n", conf->bConfigurationValue);
+               printf("  iConfiguration (0x%02X): \"%s\"\n", conf->iConfiguration, conf->iConfiguration ? usb_get_string_simple(dev, conf->iConfiguration) : "no String");
+               printf("  bmAttributes 0x%02X\n", conf->bmAttributes);
+               printf("  bMaxPower 0x%02X\n", conf->bMaxPower);
+
+               struct usb_intf *ifs = conf->intf;
+               for(i=1; i <= conf->bNumInterfaces; i++) {
+                       printf("    === Interface Descriptor %d ===\n", i);
+                       printf("    bLength 0x%02X\n", ifs->bLength);
+                       printf("    bDescriptorType 0x%02X\n", ifs->bDescriptorType);
+                       printf("    bInterfaceNumber 0x%02X\n", ifs->bInterfaceNumber);
+                       printf("    bAlternateSetting 0x%02X\n", ifs->bAlternateSetting);
+                       printf("    bNumEndpoints 0x%02X\n", ifs->bNumEndpoints);
+                       printf("    bInterfaceClass 0x%02X\n", ifs->bInterfaceClass);
+                       printf("    bInterfaceSubClass 0x%02X\n", ifs->bInterfaceSubClass);
+                       printf("    bInterfaceProtocol 0x%02X\n", ifs->bInterfaceProtocol);
+                       printf("    iInterface (0x%02X): \"%s\"\n", ifs->iInterface, ifs->iInterface ? usb_get_string_simple(dev, ifs->iInterface) : "no String");
+
+                       struct usb_endp *ed = ifs->endp;
+                       for(e=1; e <= ifs->bNumEndpoints; e++) {
+                               printf("      === Endpoint Descriptor %d ===\n", e);
+                               printf("      bLength 0x%02X\n", ed->bLength);
+                               printf("      bDescriptorType 0x%02X\n", ed->bDescriptorType);
+                               printf("      bEndpointAddress 0x%02X\n", ed->bEndpointAddress);
+                               printf("      bmAttributes 0x%02X\n", ed->bmAttributes);
+                               printf("      wMaxPacketSize 0x%02X\n", ed->wMaxPacketSize);
+                               printf("      bInterval 0x%02X\n", ed->bInterval);
+
+                               ed = ed->next;
+                       } //endpoint
+                       
+                       ifs = ifs->next;
+               } //interface
+
+               conf = conf->next;
+       } //configuration
+}
+
 /**
  * Find currently detached device and remove
  * data structures
 /**
  * Find currently detached device and remove
  * data structures
index f541306ad5204dee855b429d25b9c4be0f5c9397..b8149d3aef08230afb11d4918c0c1d92b7979883 100644 (file)
@@ -82,6 +82,9 @@ struct usb_conf {
        u8 iConfiguration;
        u8 bmAttributes;
        u8 bMaxPower;
        u8 iConfiguration;
        u8 bmAttributes;
        u8 bMaxPower;
+
+       struct usb_conf *next;
+       struct usb_intf *intf;
 };
 
 struct usb_intf {
 };
 
 struct usb_intf {
@@ -96,6 +99,7 @@ struct usb_intf {
        u8 iInterface;
 
        struct usb_intf *next;
        u8 iInterface;
 
        struct usb_intf *next;
+       struct usb_endp *endp;
 };
 
 struct usb_endp {
 };
 
 struct usb_endp {
@@ -193,7 +197,7 @@ u8 usb_remove_device(struct usb_device *dev);
 u8 usb_register_driver(struct usb_driver *driver);
 void usb_probe_driver();
 
 u8 usb_register_driver(struct usb_driver *driver);
 void usb_probe_driver();
 
-
+void lsusb(struct usb_device *dev);
 
 struct usb_irp *usb_get_irp();
 u8 usb_remove_irp(struct usb_irp *irp);
 
 struct usb_irp *usb_get_irp();
 u8 usb_remove_irp(struct usb_irp *irp);
index fd47cdc538b74703314388dc9cf845c440229394..6a7562e60a90afdbe84b46ffc3331e59dfed2586 100644 (file)
 #include "../../malloc.h"
 #include "../../string.h"
 
 #include "../../malloc.h"
 #include "../../string.h"
 
-#define cleargbuf() memset(gbuf, 0, 0xff)
+#define cleargbuf() memset(gbuf, 0, 0xffff)
 /* internal global buffer */
 /* internal global buffer */
-static u8 gbuf[0xff];
-
+static u8 gbuf[0xffff];
 
 /******************* Device Operations **********************/
 
 /******************* Device Operations **********************/
-
 /**
  * Open a device with verndor- and product-id for a communication.
  */
 /**
  * Open a device with verndor- and product-id for a communication.
  */
@@ -160,9 +158,7 @@ char *usb_get_string_simple(struct usb_device *dev, u8 index)
        u16 i;
        for(i=0; i<(gbuf[0]/2)-1; i++) {
                str[i] = gbuf[2+(i*2)];
        u16 i;
        for(i=0; i<(gbuf[0]/2)-1; i++) {
                str[i] = gbuf[2+(i*2)];
-               printf("%c", str[i]);
        }
        }
-       printf("\n");
 
        return str;
 }
 
        return str;
 }
@@ -205,23 +201,33 @@ s8 usb_get_desc_dev(struct usb_device *dev)
        dev->iSerialNumber = gbuf[16];
        dev->bNumConfigurations = gbuf[17];
 
        dev->iSerialNumber = gbuf[16];
        dev->bNumConfigurations = gbuf[17];
 
+       u8 i;
+       struct usb_conf *conf = dev->conf = (struct usb_conf*) malloc(sizeof(struct usb_conf));
+       for(i=0; i <= dev->bNumConfigurations; i++) {
+               if(i!=0) {
+                       conf = (struct usb_conf*) malloc(sizeof(struct usb_conf));
+               }
+               usb_get_desc_config_ext(dev, i, conf);
+       }
+
        return 0;
 }
 
        return 0;
 }
 
-s8 usb_get_desc_configuration(struct usb_device *dev, u8 index)
+s8 usb_get_desc_configuration(struct usb_device *dev, u8 index, struct usb_conf *conf)
 {
        cleargbuf();
        usb_get_descriptor(dev, CONFIGURATION, index, gbuf, 8);
        usb_get_descriptor(dev, CONFIGURATION, index, gbuf, gbuf[0]);
 
 {
        cleargbuf();
        usb_get_descriptor(dev, CONFIGURATION, index, gbuf, 8);
        usb_get_descriptor(dev, CONFIGURATION, index, gbuf, gbuf[0]);
 
-       dev->conf->bLength = gbuf[0];
-       dev->conf->bDescriptorType = gbuf[1];
-       dev->conf->wTotalLength = (u16) (gbuf[3] << 8 | gbuf[2]);
-       dev->conf->bNumInterfaces = gbuf[4];
-       dev->conf->bConfigurationValue = gbuf[5];
-       dev->conf->iConfiguration = gbuf[6];
-       dev->conf->bmAttributes = gbuf[7];
-       dev->conf->bMaxPower = gbuf[8];
+       conf->bLength = gbuf[0];
+       conf->bDescriptorType = gbuf[1];
+       conf->wTotalLength = (u16) (gbuf[3] << 8 | gbuf[2]);
+       conf->bNumInterfaces = gbuf[4];
+       conf->bConfigurationValue = gbuf[5];
+       conf->iConfiguration = gbuf[6];
+       conf->bmAttributes = gbuf[7];
+       conf->bMaxPower = gbuf[8];
+       conf->intf = NULL;
 
        return 0;
 }
 
        return 0;
 }
@@ -230,12 +236,56 @@ s8 usb_get_desc_configuration(struct usb_device *dev, u8 index)
  * INTERFACE(s) and ENDPOINT(s)
  * usb_get_desc_configuration() must be called for this device before
  */
  * INTERFACE(s) and ENDPOINT(s)
  * usb_get_desc_configuration() must be called for this device before
  */
-s8 usb_get_desc_config_ext(struct usb_device *dev, u8 index) {
+s8 usb_get_desc_config_ext(struct usb_device *dev, u8 index, struct usb_conf *conf)
+{
        cleargbuf();
 
        cleargbuf();
 
-       usb_get_desc_configuration(dev, index);
+       usb_get_desc_configuration(dev, index, conf);
        usb_get_descriptor(dev, CONFIGURATION, index, gbuf, dev->conf->wTotalLength);
 
        usb_get_descriptor(dev, CONFIGURATION, index, gbuf, dev->conf->wTotalLength);
 
+       u8 i,j,off=9;
+       struct usb_intf *ifs = dev->conf->intf = (struct usb_intf*) malloc(sizeof(struct usb_intf));
+       for(i=1; i <= dev->conf->bNumInterfaces; i++) {
+               if(i!=1) {
+                       ifs->next = (struct usb_intf*) malloc(sizeof(struct usb_intf));
+                       ifs = ifs->next;
+               }
+               ifs->bLength = gbuf[off+0];
+               ifs->bDescriptorType = gbuf[off+1];
+               ifs->bInterfaceNumber = gbuf[off+2];
+               ifs->bAlternateSetting = gbuf[off+3];
+               ifs->bNumEndpoints = gbuf[off+4];
+               ifs->bInterfaceClass = gbuf[off+5];
+               ifs->bInterfaceSubClass = gbuf[off+6];
+               ifs->bInterfaceProtocol = gbuf[off+7];
+               ifs->iInterface = gbuf[off+8];
+
+               off += 9;
+
+               struct usb_endp *ep = ifs->endp = (struct usb_endp*) malloc(sizeof(struct usb_endp));
+               for(j=1; j <= ifs->bNumEndpoints; j++) {
+                       /* skip HID Device Descriptor (see lsusb) */
+                       if(gbuf[off+1] == 33) {
+                               j--;
+                               off += 9;
+                               continue;
+                       }
+
+                       if(j!=1) {
+                               ep->next = (struct usb_endp*) malloc(sizeof(struct usb_endp));
+                               ep = ep->next;
+                       }
+
+                       ep->bLength = gbuf[off+0];
+                       ep->bDescriptorType = gbuf[off+1];
+                       ep->bEndpointAddress = gbuf[off+2];
+                       ep->bmAttributes = gbuf[off+3];
+                       ep->wMaxPacketSize = (u16) ((gbuf[off+5] << 8) | (gbuf[off+4]));
+                       ep->bInterval = gbuf[off+6];
+
+                       off += 7;
+               }
+       }
 
        printf("=============\nafter usb_get_desc_config_ext:\n");
        hexdump((void*) gbuf, dev->conf->wTotalLength);
 
        printf("=============\nafter usb_get_desc_config_ext:\n");
        hexdump((void*) gbuf, dev->conf->wTotalLength);
index b4c2db10334e0fb915a6ec0ce099ead96ff3e6fb..cf7dc315fbfdbf3eae9f6b829f89116e8cae2155 100644 (file)
@@ -63,8 +63,8 @@ s8 usb_control_msg(struct usb_device *dev, u8 requesttype, u8 request, u16 value
 s8 usb_get_descriptor(struct usb_device *dev, u8 type, u8 index, u8 *buf, u8 size);
 s8 usb_get_desc_dev_simple(struct usb_device *dev);
 s8 usb_get_desc_dev(struct usb_device *dev);
 s8 usb_get_descriptor(struct usb_device *dev, u8 type, u8 index, u8 *buf, u8 size);
 s8 usb_get_desc_dev_simple(struct usb_device *dev);
 s8 usb_get_desc_dev(struct usb_device *dev);
-s8 usb_get_desc_configuration(struct usb_device *dev, u8 index);
-s8 usb_get_desc_config_ext(struct usb_device *dev, u8 index);
+s8 usb_get_desc_configuration(struct usb_device *dev, u8 index, struct usb_conf *conf);
+s8 usb_get_desc_config_ext(struct usb_device *dev, u8 index, struct usb_conf *conf);
 
 char *usb_get_string_simple(struct usb_device *dev, u8 index);
 s8 usb_get_string(struct usb_device *dev, u8 index, u8 langid);
 
 char *usb_get_string_simple(struct usb_device *dev, u8 index);
 s8 usb_get_string(struct usb_device *dev, u8 index, u8 langid);