diff --git a/ion/src/device/usb/Makefile b/ion/src/device/usb/Makefile index c04812786..6fa7682eb 100644 --- a/ion/src/device/usb/Makefile +++ b/ion/src/device/usb/Makefile @@ -9,14 +9,17 @@ usb_objs += $(addprefix ion/src/device/usb/, \ ) usb_objs += $(addprefix ion/src/device/usb/stack/, \ + bos_descriptor.o\ configuration_descriptor.o \ descriptor.o\ device_descriptor.o\ + device_capability_descriptor.o\ dfu_functional_descriptor.o\ interface_descriptor.o\ language_id_string_descriptor.o \ streamable.o\ string_descriptor.o\ + webusb_platform_descriptor.o\ ) USB_DFU_XIP_FLASH := 0 diff --git a/ion/src/device/usb/stack/bos_descriptor.cpp b/ion/src/device/usb/stack/bos_descriptor.cpp new file mode 100644 index 000000000..069e6d56e --- /dev/null +++ b/ion/src/device/usb/stack/bos_descriptor.cpp @@ -0,0 +1,22 @@ +#include "bos_descriptor.h" + +namespace Ion { +namespace USB { +namespace Device { + +void BOSDescriptor::push(Channel * c) const { + Descriptor::push(c); + c->push(m_wTotalLength); + c->push(m_bNumDeviceCaps); + for (uint8_t i = 0; i < m_bNumDeviceCaps; i++) { + m_deviceCapabilities[i].push(c); + } +} + +uint8_t BOSDescriptor::bLength() const { + return Descriptor::bLength() + sizeof(uint16_t) + sizeof(uint8_t); +} + +} +} +} diff --git a/ion/src/device/usb/stack/bos_descriptor.h b/ion/src/device/usb/stack/bos_descriptor.h index b4c2d7244..ce2626099 100644 --- a/ion/src/device/usb/stack/bos_descriptor.h +++ b/ion/src/device/usb/stack/bos_descriptor.h @@ -1,21 +1,36 @@ +#ifndef ION_DEVICE_USB_STACK_BOS_DESCRIPTOR_H +#define ION_DEVICE_USB_STACK_BOS_DESCRIPTOR_H + +#include "descriptor.h" +#include "device_capability_descriptor.h" + +namespace Ion { +namespace USB { +namespace Device { + class BOSDescriptor : public Descriptor { public: - BOSDescriptor(const CapabilityDescriptor * capabilityDescriptors, int number) : - Descriptor(...) - m_wTotalLength(somme des size des capDesc), - bNumDeviceCaps(number) - { - } - uint16_t copy(void * target) override { - super::copy(); - for (capability in m_deviceCapabilities) { - capability->copy(target+machinchose,...); - } + constexpr BOSDescriptor( + uint16_t wTotalLength, + uint8_t bNumDeviceCapabilities, + const DeviceCapabilityDescriptor * deviceCapabilities) : + Descriptor(0x0F), + m_wTotalLength(wTotalLength), + m_bNumDeviceCaps(bNumDeviceCapabilities), + m_deviceCapabilities(deviceCapabilities) + { + } +protected: + void push(Channel * c) const override; + virtual uint8_t bLength() const override; private: - uint16_t wTotalLength; // Length of this descriptor and all of its sub descriptors - uint8_t bNumDeviceCaps; // The number of separate device capability descriptors in the BOS + uint16_t m_wTotalLength; + uint8_t m_bNumDeviceCaps; + const DeviceCapabilityDescriptor * m_deviceCapabilities; +}; - DeviceCapabilityDescriptor * m_deviceCapabilities; -} __attribute__((packed)); +} +} +} -static_assert(sizeof(DeviceDescriptor) == 12); +#endif diff --git a/ion/src/device/usb/stack/device_capability_descriptor.cpp b/ion/src/device/usb/stack/device_capability_descriptor.cpp new file mode 100644 index 000000000..e3ab162d4 --- /dev/null +++ b/ion/src/device/usb/stack/device_capability_descriptor.cpp @@ -0,0 +1,18 @@ +#include "device_capability_descriptor.h" + +namespace Ion { +namespace USB { +namespace Device { + +void DeviceCapabilityDescriptor::push(Channel * c) const { + Descriptor::push(c); + c->push(m_bDeviceCapabilityType); +} + +uint8_t DeviceCapabilityDescriptor::bLength() const { + return Descriptor::bLength() + sizeof(uint8_t); +} + +} +} +} diff --git a/ion/src/device/usb/stack/device_capability_descriptor.h b/ion/src/device/usb/stack/device_capability_descriptor.h new file mode 100644 index 000000000..cf600c9f1 --- /dev/null +++ b/ion/src/device/usb/stack/device_capability_descriptor.h @@ -0,0 +1,31 @@ +#ifndef ION_DEVICE_USB_STACK_DEVICE_CAPABLITY_DESCRIPTOR_H +#define ION_DEVICE_USB_STACK_DEVICE_CAPABLITY_DESCRIPTOR_H + +#include "descriptor.h" + +namespace Ion { +namespace USB { +namespace Device { + +class BOSDescriptor; + +class DeviceCapabilityDescriptor : public Descriptor { + friend class BOSDescriptor; +public: + constexpr DeviceCapabilityDescriptor(uint8_t bDeviceCapabilityType) : + Descriptor(0x10), + m_bDeviceCapabilityType(bDeviceCapabilityType) + { + } +protected: + void push(Channel * c) const override; + virtual uint8_t bLength() const override; +private: + uint8_t m_bDeviceCapabilityType; +}; + +} +} +} + +#endif diff --git a/ion/src/device/usb/stack/webusb_platform_descriptor.cpp b/ion/src/device/usb/stack/webusb_platform_descriptor.cpp new file mode 100644 index 000000000..76994cee1 --- /dev/null +++ b/ion/src/device/usb/stack/webusb_platform_descriptor.cpp @@ -0,0 +1,24 @@ +#include "webusb_platform_descriptor.h" + +namespace Ion { +namespace USB { +namespace Device { + +void WebUSBPlatformDescriptor::push(Channel * c) const { + DeviceCapabilityDescriptor::push(c); + c->push(m_bReserved); + for (int i = 0; i < k_platformCapabilityUUIDSize; i++) { + c->push(m_platformCapabilityUUID[i]); + } + c->push(m_bcdVersion); + c->push(m_bVendorCode); + c->push(m_iLandingPage); +} + +uint8_t WebUSBPlatformDescriptor::bLength() const { + return DeviceCapabilityDescriptor::bLength() + sizeof(uint8_t) + k_platformCapabilityUUIDSize*sizeof(uint8_t) + sizeof(uint16_t) + 2*sizeof(uint8_t); +} + +} +} +} diff --git a/ion/src/device/usb/stack/webusb_platform_descriptor.h b/ion/src/device/usb/stack/webusb_platform_descriptor.h new file mode 100644 index 000000000..d9764a0b0 --- /dev/null +++ b/ion/src/device/usb/stack/webusb_platform_descriptor.h @@ -0,0 +1,41 @@ +#ifndef ION_DEVICE_USB_STACK_WEBUSB_PLATFORM_DESCRIPTOR_H +#define ION_DEVICE_USB_STACK_WEBUSB_PLATFORM_DESCRIPTOR_H + +#include "device_capability_descriptor.h" + +namespace Ion { +namespace USB { +namespace Device { + +class WebUSBPlatformDescriptor : public DeviceCapabilityDescriptor { +public: + constexpr WebUSBPlatformDescriptor(uint8_t bVendorCode, uint8_t iLandingPage) : + DeviceCapabilityDescriptor(0x05), + m_bReserved(0), + m_platformCapabilityUUID{ + /* Little-endian encoding of {3408b638-09a9-47a0-8bfd-a0768815b665}. + * See https://wicg.github.io/webusb/#webusb-platform-capability-descriptor */ + 0x38, 0xB6, 0x08, 0x34, 0xA9, 0x09, 0xA0, 0x47, + 0x8B, 0xFD, 0xA0, 0x76, 0x88, 0x15, 0xB6, 0x65}, + m_bcdVersion(0x0100), + m_bVendorCode(bVendorCode), + m_iLandingPage(iLandingPage) + { + } +protected: + void push(Channel * c) const override; + virtual uint8_t bLength() const override; +private: + constexpr static uint8_t k_platformCapabilityUUIDSize = 16; + uint8_t m_bReserved; + uint8_t m_platformCapabilityUUID[k_platformCapabilityUUIDSize]; + uint16_t m_bcdVersion; + uint8_t m_bVendorCode; + uint8_t m_iLandingPage; +}; + +} +} +} + +#endif