data{0,1} now decided by endpoint (for PID_IN) (see p22/23 @ ohci specs
[ppcskel.git] / usb / core / core.c
index 1f7baf40dab1632a3907cdd6117caae3070c6e93..789e36e96b2f443bd7c89e7b90af4ec8ebc82b58 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,30 @@ 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, 8, buf, 8, 0);
+       //usb_control_msg(dev, 0x80, GET_DESCRIPTOR, DEVICE, 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 +258,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 +278,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 */
@@ -273,6 +291,10 @@ u16 usb_submit_irp(usb_irp *irp)
                        togl = 0;
                        /**** send token ****/
                hcdi_enqueue(td);
+#if 0
+               break;
+               memcpy(td->buffer, mybuf, td->actlen);
+#endif
 
                        /***************** Data Stage ***********************/
                        /**
@@ -330,6 +352,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 +378,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 +423,7 @@ u16 usb_submit_irp(usb_irp *irp)
                        else
                                togl = 0;
                                /**** send token ****/
+                       printf("togl: %d\n", togl);
                        hcdi_enqueue(td);
                        free(td);
                }