diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index 0b26f5f..e8ef161 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -7,7 +7,7 @@ extern uint32_t serviceId; -typedef volatile struct { +typedef struct { uint8_t size; uint8_t descriptorType; uint16_t usbVersion; @@ -25,6 +25,29 @@ } __attribute__((packed)) UsbDeviceDescriptor; typedef struct { + uint8_t size; + uint8_t descriptorType; + uint16_t totalLength; + uint8_t interfaceCount; + uint8_t configurationValue; + uint8_t configurationString; + uint8_t attributes; + uint8_t maxPower; +} __attribute__((packed)) UsbConfigurationDescriptor; + +typedef struct { + uint8_t size; + uint8_t descriptorType; + uint8_t interfaceNumber; + uint8_t alternateSetting; + uint8_t endpointCount; + uint8_t interfaceClass; + uint8_t subClass; + uint8_t protocol; + uint8_t stringIndex; +} __attribute__((packed)) UsbInterfaceDescriptor; + +typedef struct { uint32_t pciClass; void *(*initialize)(uint32_t, uint32_t, uint32_t); void (*getDeviceDescriptor)(void *, uint32_t, uint32_t, void *); diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index 0b26f5f..e8ef161 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -7,7 +7,7 @@ extern uint32_t serviceId; -typedef volatile struct { +typedef struct { uint8_t size; uint8_t descriptorType; uint16_t usbVersion; @@ -25,6 +25,29 @@ } __attribute__((packed)) UsbDeviceDescriptor; typedef struct { + uint8_t size; + uint8_t descriptorType; + uint16_t totalLength; + uint8_t interfaceCount; + uint8_t configurationValue; + uint8_t configurationString; + uint8_t attributes; + uint8_t maxPower; +} __attribute__((packed)) UsbConfigurationDescriptor; + +typedef struct { + uint8_t size; + uint8_t descriptorType; + uint8_t interfaceNumber; + uint8_t alternateSetting; + uint8_t endpointCount; + uint8_t interfaceClass; + uint8_t subClass; + uint8_t protocol; + uint8_t stringIndex; +} __attribute__((packed)) UsbInterfaceDescriptor; + +typedef struct { uint32_t pciClass; void *(*initialize)(uint32_t, uint32_t, uint32_t); void (*getDeviceDescriptor)(void *, uint32_t, uint32_t, void *); diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 0285a06..57c7f11 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -30,11 +30,9 @@ UsbDeviceDescriptor *descriptor = malloc(sizeof(UsbDeviceDescriptor)); slot->interface->getDeviceDescriptor(slot->data, 1 << 8, 0, buffer); memcpy(buffer, (void *)descriptor, sizeof(UsbDeviceDescriptor)); - printf("port %i: usb version %x.%x\n", slot->portIndex, - descriptor->usbVersion >> 8, descriptor->usbVersion & 0xFF); - printf("port %i: class: %i, subclass: %i, protocol %i, maxPacketSize: %i\n", - slot->portIndex, descriptor->deviceClass, descriptor->deviceSubclass, - descriptor->deviceProtocol, descriptor->maxPacketSize); + printf("port %i: usb version %x.%x, %i supported configuration(s)\n", + slot->portIndex, descriptor->usbVersion >> 8, + descriptor->usbVersion & 0xFF, descriptor->configurationCount); // slot->inputContext->deviceContext.endpoints[0].maxPacketSize = // descriptor->maxPacketSize == 9 ? 512 : descriptor->maxPacketSize; slot->interface->getDeviceDescriptor(slot->data, 3 << 8, 0, buffer); @@ -45,8 +43,29 @@ descriptor->deviceStringDescriptor, buffer); char *serial = usbReadString( slot, language, descriptor->serialNumberStringDescriptor, buffer); - printf("port %i: manufacturer: %s, device: %s, serial: %s\n", - slot->portIndex, manufacturer, device, serial); + printf("port %i: manufacturer:%s, device:%s, serial:%s\n", slot->portIndex, + manufacturer, device, serial); + + slot->interface->getDeviceDescriptor(slot->data, 2 << 8, 0, buffer); + UsbConfigurationDescriptor *configuration = malloc(((uint16_t *)buffer)[1]); + memcpy(buffer, configuration, ((uint16_t *)buffer)[1]); + char *configurationString = usbReadString( + slot, language, configuration->configurationString, buffer); + printf("port %i: %i interfaces, configuration %s, %i bytes\n", + slot->portIndex, configuration->interfaceCount, configurationString, + configuration->totalLength); + + UsbInterfaceDescriptor *interface = + (void *)configuration + configuration->size; + // only doing blank interface descriptors for now, there are + // also interface assosciations... + while (interface->descriptorType == 4) { + printf("port %i: interface %i, %i endpoints, class %i, subclass %i\n", + slot->portIndex, interface->interfaceNumber, + interface->endpointCount, interface->interfaceClass, + interface->subClass); + interface = (void *)interface + interface->size; + } } extern UsbHostControllerInterface xhci;