summaryrefslogtreecommitdiff
path: root/Kernel/Bus/USB/USBDescriptors.h
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2021-06-25 09:51:22 +0300
committerAndreas Kling <kling@serenityos.org>2021-07-02 13:16:12 +0200
commit5073bf8e75a1e71be8bbcdc96c10c3711e8ae22c (patch)
tree218a5a824a781bc1dd7f32c09ec135b1bbab0f0e /Kernel/Bus/USB/USBDescriptors.h
parent6568bb47cb6b3ad7ca0c15948ce1a279792d92de (diff)
downloadserenity-5073bf8e75a1e71be8bbcdc96c10c3711e8ae22c.zip
Kernel/USB: Move the USB components as a subfolder to the Bus directory
Diffstat (limited to 'Kernel/Bus/USB/USBDescriptors.h')
-rw-r--r--Kernel/Bus/USB/USBDescriptors.h104
1 files changed, 104 insertions, 0 deletions
diff --git a/Kernel/Bus/USB/USBDescriptors.h b/Kernel/Bus/USB/USBDescriptors.h
new file mode 100644
index 0000000000..0e8486bd8a
--- /dev/null
+++ b/Kernel/Bus/USB/USBDescriptors.h
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Types.h>
+
+namespace Kernel::USB {
+
+struct [[gnu::packed]] USBDescriptorCommon {
+ u8 length;
+ u8 descriptor_type;
+};
+
+//
+// Device Descriptor
+// =================
+//
+// This descriptor type (stored on the device), represents the device, and gives
+// information related to it, such as the USB specification it complies to,
+// as well as the vendor and product ID of the device.
+//
+// https://beyondlogic.org/usbnutshell/usb5.shtml#DeviceDescriptors
+struct [[gnu::packed]] USBDeviceDescriptor {
+ USBDescriptorCommon descriptor_header;
+ u16 usb_spec_compliance_bcd;
+ u8 device_class;
+ u8 device_sub_class;
+ u8 device_protocol;
+ u8 max_packet_size;
+ u16 vendor_id;
+ u16 product_id;
+ u16 device_release_bcd;
+ u8 manufacturer_id_descriptor_index;
+ u8 product_string_descriptor_index;
+ u8 serial_number_descriptor_index;
+ u8 num_configurations;
+};
+
+//
+// Configuration Descriptor
+// ========================
+//
+// A USB device can have multiple configurations, which tells us about how the
+// device is physically configured (e.g how it's powered, max power consumption etc).
+//
+struct [[gnu::packed]] USBConfigurationDescriptor {
+ USBDescriptorCommon descriptor_header;
+ u16 total_length;
+ u8 number_of_interfaces;
+ u8 configuration_value;
+ u8 configuration_string_descriptor_index;
+ u8 attributes_bitmap;
+ u8 max_power_in_ma;
+};
+
+//
+// Interface Descriptor
+// ====================
+//
+// An interface descriptor describes to us one or more endpoints, grouped
+// together to define a singular function of a device.
+// As an example, a USB webcam might have two interface descriptors; one
+// for the camera, and one for the microphone.
+//
+struct [[gnu::packed]] USBInterfaceDescriptor {
+ USBDescriptorCommon descriptor_header;
+ u8 interface_id;
+ u8 alternate_setting;
+ u8 number_of_endpoints;
+ u8 interface_class_code;
+ u8 interface_sub_class_code;
+ u8 interface_protocol;
+ u8 interface_string_descriptor_index;
+};
+
+//
+// Endpoint Descriptor
+// ===================
+//
+// The lowest leaf in the configuration tree. And endpoint descriptor describes
+// the physical transfer properties of the endpoint (that isn't endpoint0).
+// The description given by this structure is used by a pipe to create a
+// "connection" from the host to the device.
+// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/usb-endpoints-and-their-pipes
+struct [[gnu::packed]] USBEndpointDescriptor {
+ USBDescriptorCommon descriptor_header;
+ u8 endpoint_address;
+ u8 endpoint_attributes_bitmap;
+ u16 max_packet_size;
+ u8 poll_interval_in_frames;
+};
+
+static constexpr u8 DESCRIPTOR_TYPE_DEVICE = 0x01;
+static constexpr u8 DESCRIPTOR_TYPE_CONFIGURATION = 0x02;
+static constexpr u8 DESCRIPTOR_TYPE_STRING = 0x03;
+static constexpr u8 DESCRIPTOR_TYPE_INTERFACE = 0x04;
+static constexpr u8 DESCRIPTOR_TYPE_ENDPOINT = 0x05;
+static constexpr u8 DESCRIPTOR_TYPE_DEVICE_QUALIFIER = 0x06;
+
+}