- 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;
+ struct usb_device *dev = (struct usb_device *) malloc(sizeof(struct 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;
+
+#define LEN 128
+ u8 buf[LEN];
+ memset(buf, 0, sizeof(buf));
+
+ s8 ret;
+ memset(buf, 0, sizeof(buf));
+ ret = usb_get_dev_desc_simple(dev, buf, sizeof(buf));
+#ifdef _DU_CORE_ADD
+ printf("=============\nbuf: 0x%08X\nafter usb_get_dev_desc_simple(ret: %d):\n", buf, ret);
+ hexdump(buf, sizeof(buf));
+#endif
+ if(ret < 0) {
+ return (void*) -1;
+ }
+
+ /* set MaxPacketSize */
+
+ u8 address = usb_next_address();
+ ret = usb_set_address(dev, address);
+ dev->address = address;
+#ifdef _DU_CORE_ADD
+ printf("set address to %d\n", dev->address);
+#endif
+
+ memset(buf, 0, sizeof(buf));
+ ret = usb_get_dev_desc(dev, buf, sizeof(buf));
+#ifdef _DU_CORE_ADD
+ printf("=============\nbuf: 0x%08X\nafter usb_get_dev_desc(ret: %d):\n", buf, ret);
+ hexdump(buf, sizeof(buf));
+#endif
+
+ char *man, *prod, *serial;
+ if(dev->iManufacturer) {
+ memset(buf, 0, sizeof(buf));
+ man = usb_get_string_simple(dev, dev->iManufacturer, buf, sizeof(buf));
+ printf("iManufacturer:\n");
+ hexdump(buf, sizeof(buf));
+ } else {
+ man = (char*) malloc(11);
+ memset(man, '\0', sizeof(man));
+ strlcpy(man, "no String", 10);
+ }
+ if(dev->iProduct) {
+ memset(buf, 0, sizeof(buf));
+ prod = usb_get_string_simple(dev, dev->iProduct, buf, sizeof(buf));
+ } else {
+ prod = (char*) malloc(11);
+ memset(prod, '\0', sizeof(prod));
+ strlcpy(prod, "no String", 10);
+ }
+ if(dev->iSerialNumber) {
+ memset(buf, 0, sizeof(buf));
+ serial = usb_get_string_simple(dev, dev->iSerialNumber, buf, sizeof(buf));
+ } else {
+ serial = (char*) malloc(11);
+ memset(serial, '\0', sizeof(serial));
+ strlcpy(serial, "no String", 10);
+ }
+
+
+ printf( "bLength 0x%02X\n"
+ "bDescriptorType 0x%02X\n"
+ "bcdUSB 0x%02X\n"
+ "bDeviceClass 0x%02X\n"
+ "bDeviceSubClass 0x%02X\n"
+ "bDeviceProtocoll 0x%02X\n"
+ "idVendor 0x%04X\n"
+ "idProduct 0x%04X\n"
+ "bcdDevice 0x%04X\n"
+ "iManufacturer(0x%02X): \"%s\"\n"
+ "iProduct(0x%02X): \"%s\"\n"
+ "iSerialNumber(0x%02X): \"%s\"\n"
+ "bNumConfigurations 0x%02X\n", dev->bLength, dev->bDeviceClass,
+ dev->bcdUSB, dev->bDescriptorType, dev->bDeviceSubClass,
+ dev->bDeviceProtocoll, dev->idVendor, dev->idProduct, dev->bcdDevice,
+ dev->iManufacturer, man,
+ dev->iProduct, prod,
+ dev->iSerialNumber, serial,
+ dev->bNumConfigurations);
+
+ memset(buf, 0, sizeof(buf));
+ /* in the most cases usb devices have just one configuration descriptor */
+ ret = usb_get_configuration(dev, 0, buf, sizeof(buf));
+ printf("=============\nbuf: 0x%08X\nafter usb_get_configuration(ret: %d):\n", buf, ret);
+ hexdump(buf, sizeof(buf));
+
+
+ /*
+ usb_get_descriptor(dev, DEVICE, 0, buf, 8);
+ memset(buf, 0, 8);
+ usb_get_descriptor(dev, DEVICE, 0, buf, size >= buf[0] ? buf[0] : size);
+ */
+#if 0
+ memset(buf, 0, sizeof(buf));
+ usb_control_msg(dev, 0x80, GET_DESCRIPTOR, (DEVICE << 8) | 0, 0, 8, buf, 0);
+ printf("=============\nbuf: 0x%08X\nafter usb control msg:\n", buf);
+ hexdump(buf, sizeof(buf));
+
+ memset(buf, 0, sizeof(buf));
+ usb_control_msg(dev, 0x80, GET_DESCRIPTOR, (DEVICE << 8) | 0, 0, buf[0], buf, 0);
+ printf("=============\nbuf: 0x%08X\nafter usb control msg:\n", buf);
+ hexdump(buf, sizeof(buf));
+
+ memset(buf, 0, sizeof(buf));
+ usb_get_string_simple(dev, 1, buf);
+ printf("=============\nbuf: 0x%08X\nafter usb control msg:\n", buf);
+ hexdump(buf, sizeof(buf));
+#endif
+
+#if 0
+ u8 devdescr_size;
+
+ /* 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 */
+ memset(buf, 0, sizeof(buf));
+ 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, sizeof(buf));
+ 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 */
+#endif
+
+#if 0
+ memset(buf, 0, sizeof(buf));
+ 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;