193c47394SJó Ágila Bitsch /* SPDX-License-Identifier: GPL-2.0+ */ 293c47394SJó Ágila Bitsch /* 393c47394SJó Ágila Bitsch * WebUSB descriptors and constants 493c47394SJó Ágila Bitsch * 593c47394SJó Ágila Bitsch * Copyright (C) 2023 Jó Ágila Bitsch <[email protected]> 693c47394SJó Ágila Bitsch */ 793c47394SJó Ágila Bitsch 893c47394SJó Ágila Bitsch #ifndef __LINUX_USB_WEBUSB_H 993c47394SJó Ágila Bitsch #define __LINUX_USB_WEBUSB_H 1093c47394SJó Ágila Bitsch 1193c47394SJó Ágila Bitsch #include "uapi/linux/usb/ch9.h" 1293c47394SJó Ágila Bitsch 1393c47394SJó Ágila Bitsch /* 14*2bf40502SAndy Shevchenko * Little Endian PlatformCapablityUUID for WebUSB 1593c47394SJó Ágila Bitsch * 3408b638-09a9-47a0-8bfd-a0768815b665 16*2bf40502SAndy Shevchenko * to identify Platform Device Capability descriptors as referring to WebUSB. 1793c47394SJó Ágila Bitsch */ 1893c47394SJó Ágila Bitsch #define WEBUSB_UUID \ 19*2bf40502SAndy Shevchenko GUID_INIT(0x3408b638, 0x09a9, 0x47a0, 0x8b, 0xfd, 0xa0, 0x76, 0x88, 0x15, 0xb6, 0x65) 2093c47394SJó Ágila Bitsch 2193c47394SJó Ágila Bitsch /* 2293c47394SJó Ágila Bitsch * WebUSB Platform Capability data 2393c47394SJó Ágila Bitsch * 2493c47394SJó Ágila Bitsch * A device announces support for the 2593c47394SJó Ágila Bitsch * WebUSB command set by including the following Platform Descriptor Data in its 2693c47394SJó Ágila Bitsch * Binary Object Store associated with the WebUSB_UUID above. 2793c47394SJó Ágila Bitsch * See: https://wicg.github.io/webusb/#webusb-platform-capability-descriptor 2893c47394SJó Ágila Bitsch */ 2993c47394SJó Ágila Bitsch struct usb_webusb_cap_data { 3093c47394SJó Ágila Bitsch __le16 bcdVersion; 3193c47394SJó Ágila Bitsch #define WEBUSB_VERSION_1_00 cpu_to_le16(0x0100) /* currently only version 1.00 is defined */ 3293c47394SJó Ágila Bitsch u8 bVendorCode; 3393c47394SJó Ágila Bitsch u8 iLandingPage; 3493c47394SJó Ágila Bitsch #define WEBUSB_LANDING_PAGE_NOT_PRESENT 0 3593c47394SJó Ágila Bitsch #define WEBUSB_LANDING_PAGE_PRESENT 1 /* we chose the fixed index 1 for the URL descriptor */ 3693c47394SJó Ágila Bitsch } __packed; 3793c47394SJó Ágila Bitsch 3893c47394SJó Ágila Bitsch #define USB_WEBUSB_CAP_DATA_SIZE 4 3993c47394SJó Ágila Bitsch 4093c47394SJó Ágila Bitsch /* 4193c47394SJó Ágila Bitsch * Get URL Request 4293c47394SJó Ágila Bitsch * 4393c47394SJó Ágila Bitsch * The request to fetch an URL is defined in https://wicg.github.io/webusb/#get-url as: 4493c47394SJó Ágila Bitsch * bmRequestType: (USB_DIR_IN | USB_TYPE_VENDOR) = 11000000B 4593c47394SJó Ágila Bitsch * bRequest: bVendorCode 4693c47394SJó Ágila Bitsch * wValue: iLandingPage 4793c47394SJó Ágila Bitsch * wIndex: GET_URL = 2 4893c47394SJó Ágila Bitsch * wLength: Descriptor Length (typically U8_MAX = 255) 4993c47394SJó Ágila Bitsch * Data: URL Descriptor 5093c47394SJó Ágila Bitsch */ 5193c47394SJó Ágila Bitsch #define WEBUSB_GET_URL 2 5293c47394SJó Ágila Bitsch 5393c47394SJó Ágila Bitsch /* 5493c47394SJó Ágila Bitsch * This descriptor contains a single URL and is returned by the Get URL request. 5593c47394SJó Ágila Bitsch * 5693c47394SJó Ágila Bitsch * See: https://wicg.github.io/webusb/#url-descriptor 5793c47394SJó Ágila Bitsch */ 5893c47394SJó Ágila Bitsch struct webusb_url_descriptor { 5993c47394SJó Ágila Bitsch u8 bLength; 6093c47394SJó Ágila Bitsch #define WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH 3 6193c47394SJó Ágila Bitsch u8 bDescriptorType; 6293c47394SJó Ágila Bitsch #define WEBUSB_URL_DESCRIPTOR_TYPE 3 6393c47394SJó Ágila Bitsch u8 bScheme; 6493c47394SJó Ágila Bitsch #define WEBUSB_URL_SCHEME_HTTP 0 6593c47394SJó Ágila Bitsch #define WEBUSB_URL_SCHEME_HTTPS 1 6693c47394SJó Ágila Bitsch #define WEBUSB_URL_SCHEME_NONE 255 6793c47394SJó Ágila Bitsch u8 URL[U8_MAX - WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH]; 6893c47394SJó Ágila Bitsch } __packed; 6993c47394SJó Ágila Bitsch 7093c47394SJó Ágila Bitsch /* 7193c47394SJó Ágila Bitsch * Buffer size to hold the longest URL that can be in an URL descriptor 7293c47394SJó Ágila Bitsch * 7393c47394SJó Ágila Bitsch * The descriptor can be U8_MAX bytes long. 7493c47394SJó Ágila Bitsch * WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH bytes are used for a header. 7593c47394SJó Ágila Bitsch * Since the longest prefix that might be stripped is "https://", we may accommodate an additional 7693c47394SJó Ágila Bitsch * 8 bytes. 7793c47394SJó Ágila Bitsch */ 7893c47394SJó Ágila Bitsch #define WEBUSB_URL_RAW_MAX_LENGTH (U8_MAX - WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH + 8) 7993c47394SJó Ágila Bitsch 8093c47394SJó Ágila Bitsch #endif /* __LINUX_USB_USBNET_H */ 81