- usb_device *dev = (usb_device *) malloc(sizeof(usb_device));
- dev->address = 0;
- dev->bMaxPacketSize0 = 8; /* send at first time only 8 bytes */
-
- dev->epSize[0] = 64;
- dev->epSize[1] = 64;
- dev->epSize[2] = 64;
-
- dev->epTogl[0] = 0;
- dev->epTogl[1] = 0;
- dev->epTogl[2] = 0;
-
- char buf[64];
- u8 devdescr_size;
- u8 address = usb_next_address();
-
- /* 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);
-
- dev->bMaxPacketSize0 = (u8) buf[7]; /* setup real ep0 fifo size */
- devdescr_size = (u8) buf[0]; /* save real length of device descriptor */
-
- /* define new adress */
- usb_control_msg(dev, 0x00, SET_ADDRESS, address << 8, 0, 0, buf, 8, 0);
- dev->address = address;
-
- /* get complete device descriptor */
- usb_control_msg(dev, 0x80, GET_DESCRIPTOR, 1, 0, devdescr_size, buf, 8,
- 0);
-
- /* save only really neccessary values for this small usbstack */
- dev->bDeviceClass = (u8) buf[4];
- dev->bDeviceSubClass = (u8) buf[5];
- dev->bDeviceProtocoll = (u8) buf[6];
- dev->idVendor = (u16) (buf[9] << 8) | (buf[8]);
- dev->idProduct = (u16) (buf[11] << 8) | (buf[10]);
- dev->bcdDevice = (u16) (buf[13] << 8) | (buf[12]);
-
- // string descriptoren werden nicht im arbeitsspeicher gehalten -> on demand mit
- // entprechenden funktionen
- // hier muss man noch mehr abholen, konfigurationene, interfaces und endpunkte
-
- /* add device to device list */
- element *tmp = (element *) malloc(sizeof(element));
- tmp->data = (void *) dev;
- list_add_tail(core.devices, tmp);
-
- usb_probe_driver();
-
- return dev;
+ usb_device *dev = (usb_device *) malloc(sizeof(usb_device));
+ dev->address = 0;
+ /* send at first time only 8 bytes */
+ dev->bMaxPacketSize0 = 8;
+
+ dev->epSize[0] = 64;
+ dev->epSize[1] = 64;
+ dev->epSize[2] = 64;
+
+ dev->epTogl[0] = 0;
+ dev->epTogl[1] = 0;
+ dev->epTogl[2] = 0;
+
+ char buf[64];
+ memset(buf, 0, sizeof(buf));
+
+ /* ask first 8 bytes of device descriptor with this special
+ * GET Descriptor Request, when device address = 0
+ */
+
+ /*
+ * see page 253 in usb_20.pdf
+ *
+ * bmRequestType = 0x80 = 10000000B
+ * bRequest = GET_DESCRIPTOR
+ * wValue = DEVICE (Descriptor Type)
+ * wIndex = 0
+ * wLength = 64 // in fact just 8 bytes
+ */
+ usb_control_msg(dev, 0x80, GET_DESCRIPTOR, DEVICE << 8, 0, 64, buf, 8, 0);
+
+ printf("=============\nbuf: 0x%08X\nafter usb control msg:\n", buf);
+ hexdump(buf, sizeof(buf));
+
+ u8 devdescr_size;
+ u8 address = usb_next_address();
+
+ /* 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, 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, 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];
+ dev->bDeviceSubClass = (u8) buf[5];
+ dev->bDeviceProtocoll = (u8) buf[6];
+ dev->idVendor = (u16) (buf[9] << 8) | (buf[8]);
+ dev->idProduct = (u16) (buf[11] << 8) | (buf[10]);
+ dev->bcdDevice = (u16) (buf[13] << 8) | (buf[12]);
+
+ printf( "bDeviceClass 0x%02X\n"
+ "bDeviceSubClass 0x%02X\n"
+ "bDeviceProtocoll 0x%02X\n"
+ "idVendor 0x%04X\n"
+ "idProduct 0x%04X\n"
+ "bcdDevice 0x%04X\n", dev->bDeviceClass,
+ dev->bDeviceSubClass, dev->bDeviceProtocoll,
+ dev->idVendor, dev->idProduct, dev->bcdDevice);
+
+#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;
+ list_add_tail(core.devices, tmp);
+
+ usb_probe_driver();
+#endif
+
+ return dev;