diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 5d9f64b..979d502 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -21,6 +21,7 @@ } REQUEST(registerHID, "hid", "registerHID"); +REQUEST(registerMassStorage, "usbStorage", "setup"); UsbDescriptor *findDescriptor(UsbDescriptor *start, uint8_t descriptorType) { UsbDescriptor *result = start; @@ -47,8 +48,21 @@ free(report); } +uint8_t getEndpointIndex(UsbEndpointDescriptor *endpoint) { + uint8_t endpointNumber = endpoint->address & 0xF; // never 0 + uint8_t direction = endpoint->address >> 7; + return (endpointNumber)*2 - 1 + direction; +} + void setupMassStorage(UsbSlot *slot, UsbInterfaceDescriptor *interface) { - printf("detected a USB mass storage device \n"); + UsbEndpointDescriptor *endpoint = (void *) findDescriptor((void *) interface, 5); + uint8_t endpoint1 = getEndpointIndex(endpoint); + endpoint = (void *) findDescriptor((void *) endpoint + endpoint->size, 5); + uint8_t endpoint2 = getEndpointIndex(endpoint); + uint32_t deviceType = interface->subClass & 0xFF | interface->protocol & 0xFF << 8; + uint8_t inEndpoint = endpoint1 & 1 ? endpoint1 : endpoint2; + uint8_t outEndpoint = endpoint1 & 1 ? endpoint2 : endpoint1; + registerMassStorage(slot->id | (uint32_t) inEndpoint << 16, slot->id | (uint32_t) outEndpoint << 16); } void setupInterfaces(UsbSlot *slot, void *start, uint32_t configurationValue) { @@ -158,6 +172,7 @@ // code will be used to identify an event xhciEvent = createEvent("xhciEvent"); loadFromInitrd("hid"); + loadFromInitrd("usbStorage"); createFunction("hid_normal", (void *)hidNormal); createFunction("hid_interval", (void *)hidInterval); for (uint32_t i = 0;; i++) { diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 5d9f64b..979d502 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -21,6 +21,7 @@ } REQUEST(registerHID, "hid", "registerHID"); +REQUEST(registerMassStorage, "usbStorage", "setup"); UsbDescriptor *findDescriptor(UsbDescriptor *start, uint8_t descriptorType) { UsbDescriptor *result = start; @@ -47,8 +48,21 @@ free(report); } +uint8_t getEndpointIndex(UsbEndpointDescriptor *endpoint) { + uint8_t endpointNumber = endpoint->address & 0xF; // never 0 + uint8_t direction = endpoint->address >> 7; + return (endpointNumber)*2 - 1 + direction; +} + void setupMassStorage(UsbSlot *slot, UsbInterfaceDescriptor *interface) { - printf("detected a USB mass storage device \n"); + UsbEndpointDescriptor *endpoint = (void *) findDescriptor((void *) interface, 5); + uint8_t endpoint1 = getEndpointIndex(endpoint); + endpoint = (void *) findDescriptor((void *) endpoint + endpoint->size, 5); + uint8_t endpoint2 = getEndpointIndex(endpoint); + uint32_t deviceType = interface->subClass & 0xFF | interface->protocol & 0xFF << 8; + uint8_t inEndpoint = endpoint1 & 1 ? endpoint1 : endpoint2; + uint8_t outEndpoint = endpoint1 & 1 ? endpoint2 : endpoint1; + registerMassStorage(slot->id | (uint32_t) inEndpoint << 16, slot->id | (uint32_t) outEndpoint << 16); } void setupInterfaces(UsbSlot *slot, void *start, uint32_t configurationValue) { @@ -158,6 +172,7 @@ // code will be used to identify an event xhciEvent = createEvent("xhciEvent"); loadFromInitrd("hid"); + loadFromInitrd("usbStorage"); createFunction("hid_normal", (void *)hidNormal); createFunction("hid_interval", (void *)hidInterval); for (uint32_t i = 0;; i++) { diff --git a/src/userland/usbStorage/compile_flags.txt b/src/userland/usbStorage/compile_flags.txt new file mode 100644 index 0000000..f084bb0 --- /dev/null +++ b/src/userland/usbStorage/compile_flags.txt @@ -0,0 +1,6 @@ +clang +-Iinclude +-I../../include +-fms-extensions +-Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 5d9f64b..979d502 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -21,6 +21,7 @@ } REQUEST(registerHID, "hid", "registerHID"); +REQUEST(registerMassStorage, "usbStorage", "setup"); UsbDescriptor *findDescriptor(UsbDescriptor *start, uint8_t descriptorType) { UsbDescriptor *result = start; @@ -47,8 +48,21 @@ free(report); } +uint8_t getEndpointIndex(UsbEndpointDescriptor *endpoint) { + uint8_t endpointNumber = endpoint->address & 0xF; // never 0 + uint8_t direction = endpoint->address >> 7; + return (endpointNumber)*2 - 1 + direction; +} + void setupMassStorage(UsbSlot *slot, UsbInterfaceDescriptor *interface) { - printf("detected a USB mass storage device \n"); + UsbEndpointDescriptor *endpoint = (void *) findDescriptor((void *) interface, 5); + uint8_t endpoint1 = getEndpointIndex(endpoint); + endpoint = (void *) findDescriptor((void *) endpoint + endpoint->size, 5); + uint8_t endpoint2 = getEndpointIndex(endpoint); + uint32_t deviceType = interface->subClass & 0xFF | interface->protocol & 0xFF << 8; + uint8_t inEndpoint = endpoint1 & 1 ? endpoint1 : endpoint2; + uint8_t outEndpoint = endpoint1 & 1 ? endpoint2 : endpoint1; + registerMassStorage(slot->id | (uint32_t) inEndpoint << 16, slot->id | (uint32_t) outEndpoint << 16); } void setupInterfaces(UsbSlot *slot, void *start, uint32_t configurationValue) { @@ -158,6 +172,7 @@ // code will be used to identify an event xhciEvent = createEvent("xhciEvent"); loadFromInitrd("hid"); + loadFromInitrd("usbStorage"); createFunction("hid_normal", (void *)hidNormal); createFunction("hid_interval", (void *)hidInterval); for (uint32_t i = 0;; i++) { diff --git a/src/userland/usbStorage/compile_flags.txt b/src/userland/usbStorage/compile_flags.txt new file mode 100644 index 0000000..f084bb0 --- /dev/null +++ b/src/userland/usbStorage/compile_flags.txt @@ -0,0 +1,6 @@ +clang +-Iinclude +-I../../include +-fms-extensions +-Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/userland/usbStorage/include/storage.h b/src/userland/usbStorage/include/storage.h new file mode 100644 index 0000000..da49ead --- /dev/null +++ b/src/userland/usbStorage/include/storage.h @@ -0,0 +1,12 @@ +#ifndef STORAGE_H +#define STORAGE_H + +#include + +typedef struct { + uint32_t serviceId; + uint32_t deviceId; + uint32_t getType; +} StorageDevice; + +#endif // STORAGE_H \ No newline at end of file diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 5d9f64b..979d502 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -21,6 +21,7 @@ } REQUEST(registerHID, "hid", "registerHID"); +REQUEST(registerMassStorage, "usbStorage", "setup"); UsbDescriptor *findDescriptor(UsbDescriptor *start, uint8_t descriptorType) { UsbDescriptor *result = start; @@ -47,8 +48,21 @@ free(report); } +uint8_t getEndpointIndex(UsbEndpointDescriptor *endpoint) { + uint8_t endpointNumber = endpoint->address & 0xF; // never 0 + uint8_t direction = endpoint->address >> 7; + return (endpointNumber)*2 - 1 + direction; +} + void setupMassStorage(UsbSlot *slot, UsbInterfaceDescriptor *interface) { - printf("detected a USB mass storage device \n"); + UsbEndpointDescriptor *endpoint = (void *) findDescriptor((void *) interface, 5); + uint8_t endpoint1 = getEndpointIndex(endpoint); + endpoint = (void *) findDescriptor((void *) endpoint + endpoint->size, 5); + uint8_t endpoint2 = getEndpointIndex(endpoint); + uint32_t deviceType = interface->subClass & 0xFF | interface->protocol & 0xFF << 8; + uint8_t inEndpoint = endpoint1 & 1 ? endpoint1 : endpoint2; + uint8_t outEndpoint = endpoint1 & 1 ? endpoint2 : endpoint1; + registerMassStorage(slot->id | (uint32_t) inEndpoint << 16, slot->id | (uint32_t) outEndpoint << 16); } void setupInterfaces(UsbSlot *slot, void *start, uint32_t configurationValue) { @@ -158,6 +172,7 @@ // code will be used to identify an event xhciEvent = createEvent("xhciEvent"); loadFromInitrd("hid"); + loadFromInitrd("usbStorage"); createFunction("hid_normal", (void *)hidNormal); createFunction("hid_interval", (void *)hidInterval); for (uint32_t i = 0;; i++) { diff --git a/src/userland/usbStorage/compile_flags.txt b/src/userland/usbStorage/compile_flags.txt new file mode 100644 index 0000000..f084bb0 --- /dev/null +++ b/src/userland/usbStorage/compile_flags.txt @@ -0,0 +1,6 @@ +clang +-Iinclude +-I../../include +-fms-extensions +-Wno-microsoft-anon-tag +-Wno-incompatible-library-redeclaration diff --git a/src/userland/usbStorage/include/storage.h b/src/userland/usbStorage/include/storage.h new file mode 100644 index 0000000..da49ead --- /dev/null +++ b/src/userland/usbStorage/include/storage.h @@ -0,0 +1,12 @@ +#ifndef STORAGE_H +#define STORAGE_H + +#include + +typedef struct { + uint32_t serviceId; + uint32_t deviceId; + uint32_t getType; +} StorageDevice; + +#endif // STORAGE_H \ No newline at end of file diff --git a/src/userland/usbStorage/main.c b/src/userland/usbStorage/main.c new file mode 100644 index 0000000..5dddcbf --- /dev/null +++ b/src/userland/usbStorage/main.c @@ -0,0 +1,13 @@ +#include +#include + +void setup(uint32_t in, uint32_t out, uint32_t serviceName, uint32_t serviceId) { + StorageDevice *device = malloc(sizeof(StorageDevice)); + device->serviceId = serviceId; + device->getType = getFunction(serviceId, "type"); + printf("in: %x, out: %x\n", in, out); +} + +int32_t main() { + createFunction("setup", (void *) setup); +} \ No newline at end of file