@get_descriptor|String: disable control quirk *sigh* and keep in mind to do not reque...
[ppcskel.git] / usb / core / core.c
index 628e999602d555b4bb2fecf9635b9b8011845a4b..d54b515e868bfc5f4bdb4deedf5c0f374b1733fc 100644 (file)
@@ -90,7 +90,8 @@ usb_device *usb_add_device()
 {
        usb_device *dev = (usb_device *) malloc(sizeof(usb_device));
        dev->address = 0;
-       dev->bMaxPacketSize0 = 8;       /* send at first time only 8 bytes */
+       /* send at first time only 8 bytes */
+       dev->bMaxPacketSize0 = 8;
 
        dev->epSize[0] = 64;
        dev->epSize[1] = 64;
@@ -116,26 +117,38 @@ usb_device *usb_add_device()
         * wIndex = 0
         * wLength = 64 // in fact just 8 bytes
         */
-       //usb_control_msg(dev, 0x80, GET_DESCRIPTOR, DEVICE << 8, 0, 64, buf, 8, 0);
-       // length == 8 => no STALL?! :O
        usb_control_msg(dev, 0x80, GET_DESCRIPTOR, DEVICE << 8, 0, 64, buf, 8, 0);
 
-       printf("===========\nafter usb control msg:\n");
+       printf("=============\nbuf: 0x%08X\nafter usb control msg:\n", buf);
        hexdump(buf, sizeof(buf));
 
-#if 0
        u8 devdescr_size;
        u8 address = usb_next_address();
-       dev->bMaxPacketSize0 = (u8) buf[7] ? (u8) buf[7] : 1; //dirty?  /* setup real ep0 fifo size */
-       devdescr_size = (u8) buf[0];    /* save real length of device descriptor */
+
+       /* 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 */
-       usb_control_msg(dev, 0x00, SET_ADDRESS, address << 8, 0, 0, buf, 8, 0);
+       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 */
-       usb_control_msg(dev, 0x80, GET_DESCRIPTOR, 1, 0, devdescr_size, buf, 8,
-                                                                       0);
+       memset(buf, 0, 64);
+       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 */
        dev->bDeviceClass = (u8) buf[4];
@@ -153,20 +166,31 @@ usb_device *usb_add_device()
                        "bcdDevice 0x%04X\n", dev->bDeviceClass, 
                        dev->bDeviceSubClass, dev->bDeviceProtocoll,
                        dev->idVendor, dev->idProduct, dev->bcdDevice);
-       /* for lewurms keyboard it should be:
-        * bDeviceClass                 0
-        * bDeviceSubClass              0
-        * bDeviceClass                 0
-        * idVendor                                             0x049f
-        * idProduct                                    0x000e
-        * bcdDevice                                            1.00
-        */
 
+#if 1
+       memset(buf, 0, 64);
+       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
 
+#if 0
        /* add device to device list */
        element *tmp = (element *) malloc(sizeof(element));
        tmp->data = (void *) dev;
@@ -279,7 +303,6 @@ u16 usb_submit_irp(usb_irp *irp)
 
                /* control message are always 8 bytes */
                td->actlen = 8;
-               memcpy(mybuf, td->buffer, td->actlen);
 
                togl = 0;
                /* start with data0 */
@@ -318,18 +341,19 @@ u16 usb_submit_irp(usb_irp *irp)
                /* check bit 7 of bmRequestType */
                if (bmRequestType & 0x80) { 
                        /* schleife die die tds generiert */
-                       while (runloop) {
+                       while (runloop && (restlength > 0)) {
+                               printf("restlength: %d\t irp->epsize: %d\n", restlength, irp->epsize);
                                td = usb_create_transfer_descriptor(irp);
                                td->actlen = irp->epsize;
                                /* stop loop if all bytes are send */
-                               if (restlength <= irp->epsize) {
+                               if (restlength < irp->epsize) {
                                        runloop = 0;
                                        td->actlen = restlength;
                                }
 
                                td->buffer = td_buf_ptr;
                                /* move pointer for next packet */
-                               td_buf_ptr = td_buf_ptr + irp->epsize;
+                               td_buf_ptr += irp->epsize;
 
                                td->pid = USB_PID_IN;
                                td->togl = togl;