discoverd weird endianness bug in sauter's usport. fixed
[ppcskel.git] / usb / core / core.c
index b1d04743e5c77078dfb3b6b6a68e5d303ae3ccc9..10f9e5d34dcb9e4d5d8c1c1114b92f5c60846c6d 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;
@@ -113,16 +114,10 @@ usb_device *usb_add_device()
         * bRequest = GET_DESCRIPTOR
         * wValue = DEVICE (Descriptor Type)
         * wIndex = 0
-        * wLength = 8 (in Bytes!?)
+        * wLength = 64 // in fact just 8 bytes
         */
-       usb_control_msg(dev, 0x80, GET_DESCRIPTOR, DEVICE, 0, 8, buf, 8, 0);
+       usb_control_msg(dev, 0x80, GET_DESCRIPTOR, DEVICE << 8, 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));
 
@@ -262,6 +257,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)];
@@ -281,7 +277,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 */
@@ -291,6 +290,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 ***********************/
                        /**
@@ -342,12 +345,13 @@ u16 usb_submit_irp(usb_irp *irp)
                                /* wenn device descriptor von adresse 0 angefragt wird werden nur
                                 * die ersten 8 byte abgefragt
                                 */
-                               if (setup->bRequest == GET_DESCRIPTOR && (setup->wValue >> 8) == 1
+                               if (setup->bRequest == GET_DESCRIPTOR && (setup->wValue & 0xff) == 1
                                                && td->devaddress == 0) {
                                        runloop = 0;                                    /* stop loop */
                                }
 
                                        /**** send token ****/
+                               printf("togl: %d\n", togl);
                                hcdi_enqueue(td);
 
                                /* pruefe ob noch weitere Pakete vom Device abgeholt werden muessen */
@@ -373,6 +377,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);
 
@@ -417,6 +422,7 @@ u16 usb_submit_irp(usb_irp *irp)
                        else
                                togl = 0;
                                /**** send token ****/
+                       printf("togl: %d\n", togl);
                        hcdi_enqueue(td);
                        free(td);
                }