mirror of
https://github.com/SerenityOS/serenity
synced 2026-05-10 17:12:55 +02:00
This fixes incorrect assumptions about the layout of descriptors and gets rid of all the pointer arithmetic. The USB spec doesn't define a strict order for all descriptors to appear in. It just says that endpoint descriptors follow its interface descriptor. We also have to skip all unknown descriptors (which also can appear anywhere), not just HID descriptors.
40 lines
1.3 KiB
C++
40 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2022, Jesse Buhagiar <jesse.buhagiar@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Badge.h>
|
|
#include <AK/Vector.h>
|
|
#include <Kernel/Bus/USB/USBDescriptors.h>
|
|
|
|
namespace Kernel::USB {
|
|
|
|
class USBConfiguration;
|
|
|
|
class USBInterface final {
|
|
public:
|
|
USBInterface() = delete;
|
|
USBInterface(USBConfiguration const& configuration, USBInterfaceDescriptor const descriptor)
|
|
: m_configuration(configuration)
|
|
, m_descriptor(descriptor)
|
|
{
|
|
}
|
|
|
|
ErrorOr<void> add_endpoint_descriptor(Badge<USBConfiguration>, USBEndpointDescriptor endpoint_descriptor) { return m_endpoint_descriptors.try_empend(endpoint_descriptor); }
|
|
|
|
Vector<USBEndpointDescriptor> const& endpoints() const { return m_endpoint_descriptors; }
|
|
|
|
USBInterfaceDescriptor const& descriptor() const { return m_descriptor; }
|
|
USBConfiguration const& configuration() const { return m_configuration; }
|
|
|
|
private:
|
|
USBConfiguration const& m_configuration; // Configuration that this interface belongs to
|
|
USBInterfaceDescriptor const m_descriptor; // Descriptor backing this interface
|
|
Vector<USBEndpointDescriptor> m_endpoint_descriptors; // Endpoint descriptors for this interface (that we can use to open an endpoint)
|
|
};
|
|
|
|
}
|