control_quirk seems to be evil and our buf must be "80 06 00 01 00 00 40 00" for...
[ppcskel.git] / usb / core / core.c
index 94abe688b5dceb4fa172c8b3846f85c1b8d6b5e1..95b8091e4a175849857bd6dd7118530c60c6d08e 100644 (file)
@@ -40,6 +40,7 @@
 #include "../lib/list.h"
 #include "../../malloc.h"
 #include "../../bootmii_ppc.h" //printf
+#include "../../string.h" //memset
 
 /**
  * Initialize USB stack.
@@ -89,7 +90,7 @@ 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 */
+       dev->bMaxPacketSize0 = 8;       /* send at first time only 8 bytes */
 
        dev->epSize[0] = 64;
        dev->epSize[1] = 64;
@@ -100,17 +101,36 @@ usb_device *usb_add_device()
        dev->epTogl[2] = 0;
 
        char buf[64];
-       u8 devdescr_size;
-       u8 address = usb_next_address();
+       memset(buf, 0, sizeof(buf));
 
        /* ask first 8 bytes of device descriptor with this special 
         * GET Descriptor Request, when device address = 0
         */
-       usb_control_msg(dev, 0x80, GET_DESCRIPTOR, 1, 0, 64, buf, 8, 0);
+
+       /*
+        * see page 253 in usb_20.pdf
+        * 
+        * bmRequestType = 0x80 = 10000000B
+        * bRequest = GET_DESCRIPTOR
+        * wValue = DEVICE (Descriptor Type)
+        * wIndex = 0
+        * wLength = 8 (in Bytes!?)
+        */
+       usb_control_msg(dev, 0x80, GET_DESCRIPTOR, DEVICE << 8, 0, 64, buf, 8, 0);
+       //usb_control_msg(dev, 0x80, GET_DESCRIPTOR, DEVICE, 0, 64, buf, 8, 0);
+
+       /* 
+        * length (here =64) should be "number of byte to transfer", not 
+        * (as here) "number of bits to transfer.
+        * ?
+        */
+       //usb_control_msg(dev, 0x80, GET_DESCRIPTOR, 1, 0, 64, buf, 8, 0);
        printf("===========\nafter usb control msg:\n");
        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 */
 
@@ -244,6 +264,7 @@ u16 usb_submit_irp(usb_irp *irp)
        u8 runloop = 1;
        u16 restlength = irp->len;
        char *td_buf_ptr = irp->buffer;
+       char mybuf[64];
 
        //u8 togl=irp->dev->epTogl[(irp->endpoint & 0x7F)];
        u8 togl = irp->dev->epTogl[(irp->endpoint & 0x7F)];
@@ -263,7 +284,10 @@ u16 usb_submit_irp(usb_irp *irp)
                td = usb_create_transfer_descriptor(irp);
                td->pid = USB_PID_SETUP;
                td->buffer = irp->buffer;
-               td->actlen = 8;                                                 /* control message are always 8 bytes */
+
+               /* control message are always 8 bytes */
+               td->actlen = 8;
+               memcpy(mybuf, td->buffer, td->actlen);
 
                togl = 0;
                td->togl = togl;                                                /* start with data0 */
@@ -272,7 +296,12 @@ u16 usb_submit_irp(usb_irp *irp)
                else
                        togl = 0;
                        /**** send token ****/
+               printf("togl: %d\n", togl);
                hcdi_enqueue(td);
+#if 0
+               break;
+               memcpy(td->buffer, mybuf, td->actlen);
+#endif
 
                        /***************** Data Stage ***********************/
                        /**
@@ -330,6 +359,7 @@ u16 usb_submit_irp(usb_irp *irp)
                                }
 
                                        /**** send token ****/
+                               printf("togl: %d\n", togl);
                                hcdi_enqueue(td);
 
                                /* pruefe ob noch weitere Pakete vom Device abgeholt werden muessen */
@@ -355,6 +385,7 @@ u16 usb_submit_irp(usb_irp *irp)
                        td->pid = USB_PID_IN;
                }
                        /**** send token ****/
+               printf("togl: %d\n", togl);
                hcdi_enqueue(td);
                free(td);
 
@@ -399,6 +430,7 @@ u16 usb_submit_irp(usb_irp *irp)
                        else
                                togl = 0;
                                /**** send token ****/
+                       printf("togl: %d\n", togl);
                        hcdi_enqueue(td);
                        free(td);
                }
@@ -428,6 +460,7 @@ usb_transfer_descriptor *usb_create_transfer_descriptor(usb_irp * irp)
        td->endpoint = irp->endpoint;
        td->iso = 0;
        td->state = USB_TRANSFER_DESCR_NONE;
+       td->maxp = irp->epsize;
 
        return td;
 }