- 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->conf = (struct usb_conf *) malloc(sizeof(struct usb_conf));
+ 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;
+
+ s8 ret;
+ ret = usb_get_desc_dev_simple(dev);
+ if(ret < 0) {
+ return (void*) -1;
+ }
+
+ /* set MaxPacketSize */
+
+ u8 address = usb_next_address();
+ ret = usb_set_address(dev, address);
+ dev->address = address;
+ printf("set address to %d\n", dev->address);
+
+ ret = usb_get_desc_dev(dev);
+
+ /* select configuration */
+ ret = usb_set_configuration(dev, dev->conf->bConfigurationValue);
+ printf("=============\nusb_set_configuration(ret: %d) %d\n", ret, dev->conf->bConfigurationValue);
+
+ lsusb(dev);
+
+#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;
+}
+
+void lsusb(struct usb_device *dev)
+{
+ printf("=== Device Descriptor === \n");
+ printf("bLength 0x%02X\n", dev->bLength);
+ printf("bDescriptorType 0x%02X\n", dev->bDeviceClass);
+ printf("bcdUSB 0x%02X\n", dev->bcdUSB);
+ printf("bDeviceClass 0x%02X\n", dev->bDeviceClass);
+ printf("bDeviceSubClass 0x%02X\n", dev->bDeviceSubClass);
+ printf("bDeviceProtocoll 0x%02X\n", dev->bDeviceProtocoll);
+ printf("idVendor 0x%04X\n", dev->idVendor);
+ printf("idProduct 0x%04X\n", dev->idProduct);
+ printf("bcdDevice 0x%04X\n", dev->bcdDevice);
+ printf("iManufacturer(0x%02X): \"%s\"\n", dev->iManufacturer, dev->iManufacturer ? usb_get_string_simple(dev, dev->iManufacturer) : "no String");
+ printf("iProduct(0x%02X): \"%s\"\n", dev->iProduct, dev->iProduct ? usb_get_string_simple(dev, dev->iProduct) : "no String");
+ printf("iSerialNumber(0x%02X): \"%s\"\n", dev->iSerialNumber, dev->iSerialNumber ? usb_get_string_simple(dev, dev->iSerialNumber) : "no String");
+ printf("bNumConfigurations 0x%02X\n", dev->bNumConfigurations);
+
+ u8 c, i, e;
+ struct usb_conf *conf = dev->conf;
+ for(c=0; c <= dev->bNumConfigurations; c++) {
+ printf(" === Configuration Descriptor %d ===\n", c+1);
+ printf(" bLength 0x%02X\n", conf->bLength);
+ printf(" bDescriptorType 0x%02X\n", conf->bDescriptorType);
+ printf(" wTotalLength 0x%04X\n", conf->wTotalLength);
+ printf(" bNumInterfaces 0x%02X\n", conf->bNumInterfaces);
+ printf(" bConfigurationValue 0x%02X\n", conf->bConfigurationValue);
+ printf(" iConfiguration (0x%02X): \"%s\"\n", conf->iConfiguration, conf->iConfiguration ? usb_get_string_simple(dev, conf->iConfiguration) : "no String");
+ printf(" bmAttributes 0x%02X\n", conf->bmAttributes);
+ printf(" bMaxPower 0x%02X\n", conf->bMaxPower);
+
+ struct usb_intf *ifs = conf->intf;
+ for(i=1; i <= conf->bNumInterfaces; i++) {
+ printf(" === Interface Descriptor %d ===\n", i);
+ printf(" bLength 0x%02X\n", ifs->bLength);
+ printf(" bDescriptorType 0x%02X\n", ifs->bDescriptorType);
+ printf(" bInterfaceNumber 0x%02X\n", ifs->bInterfaceNumber);
+ printf(" bAlternateSetting 0x%02X\n", ifs->bAlternateSetting);
+ printf(" bNumEndpoints 0x%02X\n", ifs->bNumEndpoints);
+ printf(" bInterfaceClass 0x%02X\n", ifs->bInterfaceClass);
+ printf(" bInterfaceSubClass 0x%02X\n", ifs->bInterfaceSubClass);
+ printf(" bInterfaceProtocol 0x%02X\n", ifs->bInterfaceProtocol);
+ printf(" iInterface (0x%02X): \"%s\"\n", ifs->iInterface, ifs->iInterface ? usb_get_string_simple(dev, ifs->iInterface) : "no String");
+
+ struct usb_endp *ed = ifs->endp;
+ for(e=1; e <= ifs->bNumEndpoints; e++) {
+ printf(" === Endpoint Descriptor %d ===\n", e);
+ printf(" bLength 0x%02X\n", ed->bLength);
+ printf(" bDescriptorType 0x%02X\n", ed->bDescriptorType);
+ printf(" bEndpointAddress 0x%02X\n", ed->bEndpointAddress);
+ printf(" bmAttributes 0x%02X\n", ed->bmAttributes);
+ printf(" wMaxPacketSize 0x%02X\n", ed->wMaxPacketSize);
+ printf(" bInterval 0x%02X\n", ed->bInterval);
+
+ ed = ed->next;
+ } //endpoint
+
+ ifs = ifs->next;
+ } //interface
+
+ conf = conf->next;
+ } //configuration