|
1 | 1 | // Copyright 2019 Shift Cryptosecurity AG
|
| 2 | +// Copyright 2025 Shift Crypto AG |
2 | 3 | //
|
3 | 4 | // Licensed under the Apache License, Version 2.0 (the "License");
|
4 | 5 | // you may not use this file except in compliance with the License.
|
|
15 | 16 | #ifndef _USB_DESC_H_
|
16 | 17 | #define _USB_DESC_H_
|
17 | 18 |
|
| 19 | +#include "usb_desc_common.h" |
| 20 | +#include "usb_size.h" |
18 | 21 | #include <bootloader/bootloader_version.h>
|
19 | 22 | #include <version.h>
|
20 | 23 | #ifndef TESTING
|
21 | 24 | #include "usb_protocol.h"
|
22 | 25 | #include "usb_protocol_hid.h"
|
| 26 | +#include <usb_u2f_desc.h> |
23 | 27 | #endif
|
24 | 28 |
|
25 |
| -#define USB_DESC_LE16(a) ((uint8_t)(a)), ((uint8_t)((a) >> 8)) |
26 |
| - |
27 |
| -#define USB_DESC_IDVENDER 0x03eb |
28 |
| -#define USB_DESC_IDPRODUCT 0x2403 |
29 |
| -#define USB_DESC_HWW_EP_IN (1 | USB_EP_DIR_IN) |
30 |
| -#define USB_DESC_HWW_EP_OUT (2 | USB_EP_DIR_OUT) |
31 |
| -#if APP_U2F == 1 |
32 |
| -#define USB_DESC_U2F_EP_IN (3 | USB_EP_DIR_IN) |
33 |
| -#define USB_DESC_U2F_EP_OUT (4 | USB_EP_DIR_OUT) |
34 |
| -#define USB_DESC_IFACE_NUM_U2F 1 |
35 |
| -#define USB_DESC_NUM_IFACES 2 |
36 |
| -#else |
37 |
| -#define USB_DESC_NUM_IFACES 1 |
38 |
| -#endif |
39 |
| -#define USB_DESC_IFACE_NUM_HWW 0 |
40 |
| -#define USB_DESC_IFACE_LEN 32 |
41 |
| -#define USB_DESC_CONFIG_LEN 9 |
42 |
| -#define USB_DESC_WTOTALLEN (USB_DESC_CONFIG_LEN + USB_DESC_IFACE_LEN * USB_DESC_NUM_IFACES) |
43 |
| -#define USB_DESC_BMAXPKSZ0 0x40 |
44 |
| -#define USB_DESC_BCDUSB 0x200 // 0x0200 => USB 2.0 version; 0x0210 => USB 2.1 version |
45 |
| -#define USB_DESC_BCDDEVICE 0x100 |
46 |
| -#define USB_DESC_BNUMCONFIG 0x1 |
47 |
| -#define USB_DESC_BCONFIGVAL 0x1 |
48 |
| -#define USB_DESC_BMATTRI 0x80 // Bus power supply, no support for remote wakeup |
49 |
| -#define USB_DESC_BMAXPOWER 0x32 |
50 |
| -#define USB_DESC_HID_EP_SIZE 0x40 |
51 |
| -#define USB_REPORT_SIZE USB_DESC_HID_EP_SIZE |
52 |
| -#define USB_HID_REPORT_IN_SIZE USB_REPORT_SIZE |
53 |
| -#define USB_HID_REPORT_OUT_SIZE USB_REPORT_SIZE |
54 |
| - |
55 |
| -#define USB_DESC_LANGID 0x0409 // English - United States |
56 |
| -#define USB_DESC_LANGID_DESC \ |
57 |
| - 4, /* bLength */ \ |
58 |
| - 0x03, /* bDescriptorType */ \ |
59 |
| - USB_DESC_LE16(USB_DESC_LANGID), /* wLANGID[0] */ |
60 |
| - |
61 |
| -#define USB_DESC_IMANUFACT 1 |
62 |
| -#define USB_DESC_IMANUFACT_STR_DESC \ |
63 |
| - 26, /* bLength */ \ |
64 |
| - 0x03, /* bDescriptorType */ \ |
65 |
| - 'b', 0, 'i', 0, 't', 0, 'b', 0, 'o', 0, 'x', 0, '.', 0, 's', 0, 'w', 0, 'i', 0, 's', 0, \ |
66 |
| - 's', 0, |
67 |
| - |
68 |
| -#define USB_DESC_IPRODUCT 2 |
69 | 29 | #if defined(BOOTLOADER)
|
70 | 30 | #if PRODUCT_BITBOX_BTCONLY == 1
|
71 | 31 | #define USB_DESC_IPRODUCT_STR_DESC \
|
|
98 | 58 | 'B', 0, 'i', 0, 't', 0, 'B', 0, 'o', 0, 'x', 0, '0', 0, '2', 0,
|
99 | 59 | #endif
|
100 | 60 |
|
101 |
| -#define USB_DESC_ISERIALNUM 3 |
102 |
| - |
103 |
| -#if defined(BOOTLOADER_DEVDEVICE) && defined(BOOTLOADER_VERSION_HAS_METADATA) |
104 |
| -#define BOOTLOADER_VERSION_APPEND_LEN 4 |
105 |
| -#define BOOTLOADER_VERSION_APPEND_W16 '.', 0, 'd', 0, 'e', 0, 'v', 0, |
106 |
| -#elif defined(BOOTLOADER_DEVDEVICE) |
107 |
| -#define BOOTLOADER_VERSION_APPEND_LEN 4 |
108 |
| -#define BOOTLOADER_VERSION_APPEND_W16 '+', 0, 'd', 0, 'e', 0, 'v', 0, |
109 |
| -#else |
110 |
| -#define BOOTLOADER_VERSION_APPEND_LEN 0 |
111 |
| -#define BOOTLOADER_VERSION_APPEND_W16 |
112 |
| -#endif |
113 |
| - |
114 |
| -#ifdef BOOTLOADER |
115 |
| -#define USB_DESC_ISERIALNUM_STR_DESC \ |
116 |
| - (2 + BOOTLOADER_VERSION_LEN * 2 + BOOTLOADER_VERSION_APPEND_LEN * 2), /* bLength */ \ |
117 |
| - 0x03, /* bDescriptorType */ \ |
118 |
| - BOOTLOADER_VERSION_W16 BOOTLOADER_VERSION_APPEND_W16 |
119 |
| -#else |
120 |
| -#define USB_DESC_ISERIALNUM_STR_DESC \ |
121 |
| - (2 + DIGITAL_BITBOX_VERSION_LEN * 2), /* bLength */ \ |
122 |
| - 0x03, /* bDescriptorType */ \ |
123 |
| - DIGITAL_BITBOX_VERSION_W16 |
124 |
| -#endif |
125 |
| - |
126 | 61 | #define USB_STR_DESC \
|
127 | 62 | USB_DESC_LANGID_DESC \
|
128 | 63 | USB_DESC_IMANUFACT_STR_DESC \
|
|
148 | 83 | 0x91, 0x02, /* OUTPUT (Data,Var,Abs) */ \
|
149 | 84 | 0xc0 /* END_COLLECTION */
|
150 | 85 |
|
151 |
| -#ifndef BOOTLOADER |
152 |
| -#define USB_DESC_U2F_REPORT_LEN 34 |
153 |
| -#define USB_DESC_U2F_REPORT \ |
154 |
| - 0x06, 0xd0, 0xf1, /* USAGE_PAGE (Reserved 0xFIDO) */ \ |
155 |
| - 0x09, 0x01, /* USAGE (HID Generic Device) */ \ |
156 |
| - 0xa1, 0x01, /* COLLECTION (Application) */ /* In Report */ \ |
157 |
| - 0x09, 0x20, /* USAGE (Input Report Data) */ \ |
158 |
| - 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \ |
159 |
| - 0x26, 0xff, 0x00, /* LOGICAL_MAXIMUM (255) */ \ |
160 |
| - 0x75, 0x08, /* REPORT_SIZE (8) */ \ |
161 |
| - 0x95, 0x40, /* REPORT_COUNT (64) */ \ |
162 |
| - 0x81, 0x02, /* INPUT (Data,Var,Abs) */ /* Out Report */ \ |
163 |
| - 0x09, 0x21, /* USAGE (Output Report Data) */ \ |
164 |
| - 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \ |
165 |
| - 0x26, 0xff, 0x00, /* LOGICAL_MAXIMUM (255) */ \ |
166 |
| - 0x75, 0x08, /* REPORT_SIZE (8) */ \ |
167 |
| - 0x95, 0x40, /* REPORT_COUNT (64) */ \ |
168 |
| - 0x91, 0x02, /* OUTPUT (Data,Var,Abs) */ \ |
169 |
| - 0xc0 /* END_COLLECTION */ |
170 |
| -#endif |
171 |
| - |
172 | 86 | #define USB_DESC_IFACE_HWW \
|
173 | 87 | 9, /* iface.bLength */ \
|
174 | 88 | 0x04, /* iface.bDescriptorType: INTERFACE */ \
|
|
199 | 113 | USB_DESC_LE16(USB_DESC_HID_EP_SIZE), /* ep_out.wMaxPacketSize */ \
|
200 | 114 | 4 /* ep_out.bInterval */
|
201 | 115 |
|
202 |
| -#if APP_U2F == 1 |
203 |
| -#define USB_DESC_IFACE_U2F \ |
204 |
| - 9, /* iface.bLength */ \ |
205 |
| - 0x04, /* iface.bDescriptorType: INTERFACE */ \ |
206 |
| - USB_DESC_IFACE_NUM_U2F, /* iface.bInterfaceNumber */ \ |
207 |
| - 0x00, /* iface.bAlternateSetting */ \ |
208 |
| - 0x02, /* iface.bNumEndpoints */ \ |
209 |
| - HID_CLASS, /* iface.bInterfaceClass */ \ |
210 |
| - USB_SUBCLASS_NO, /* iface.bInterfaceSubClass */ \ |
211 |
| - USB_PROTOCOL_NO, /* iface.bInterfaceProtocol */ \ |
212 |
| - 0x00, /* iface.iInterface */ \ |
213 |
| - 9, /* hid.bLength */ \ |
214 |
| - USB_DT_HID, /* hid.bDescriptorType: HID */ \ |
215 |
| - USB_DESC_LE16(USB_HID_BDC_V1_11), /* hid.bcdHID */ \ |
216 |
| - 0x00, /* hid.bCountryCode */ \ |
217 |
| - 0x01, /* hid.bNumDescriptors */ \ |
218 |
| - 0x22, /* hid.bRDescriptorType */ \ |
219 |
| - USB_DESC_LE16(USB_DESC_U2F_REPORT_LEN), /* hid.wDescriptorLength */ \ |
220 |
| - 7, /* ep_in.bLength */ \ |
221 |
| - 0x05, /* ep_in.bDescriptorType: ENDPOINT */ \ |
222 |
| - USB_DESC_U2F_EP_IN, /* ep_in.bEndpointAddress */ \ |
223 |
| - 0x03, /* ep_in.bmAttributes */ \ |
224 |
| - USB_DESC_LE16(USB_DESC_HID_EP_SIZE), /* ep_in.wMaxPacketSize */ \ |
225 |
| - 4, /* ep_in.bInterval */ \ |
226 |
| - 7, /* ep_out.bLength */ \ |
227 |
| - 0x05, /* ep_out.bDescriptorType: ENDPOINT */ \ |
228 |
| - USB_DESC_U2F_EP_OUT, /* ep_out.bEndpointAddress */ \ |
229 |
| - 0x03, /* ep_out.bmAttributes */ \ |
230 |
| - USB_DESC_LE16(USB_DESC_HID_EP_SIZE), /* ep_out.wMaxPacketSize */ \ |
231 |
| - 4 /* ep_out.bInterval */ |
232 |
| -#endif |
233 |
| - |
234 | 116 | #define USB_DESC_CONFIG \
|
235 | 117 | USB_DESC_CONFIG_LEN, /* bLength */ \
|
236 | 118 | 0x02, /* bDescriptorType: CONFIGURATION */ \
|
|
241 | 123 | USB_DESC_BMATTRI, /* bmAttributes */ \
|
242 | 124 | USB_DESC_BMAXPOWER /* bMaxPower */
|
243 | 125 |
|
244 |
| -#define USB_DEV_DESC \ |
245 |
| - 18, /* bLength */ \ |
246 |
| - 0x01, /* bDescriptorType: DEVICE */ \ |
247 |
| - USB_DESC_LE16(USB_DESC_BCDUSB), /* bcdUSB */ \ |
248 |
| - USB_CLASS_NO, /* bDeviceClass */ \ |
249 |
| - USB_SUBCLASS_NO, /* bDeviceSubClass */ \ |
250 |
| - USB_PROTOCOL_NO, /* bDeviceProtocol */ \ |
251 |
| - USB_DESC_BMAXPKSZ0, /* bMaxPacketSize0 */ \ |
252 |
| - USB_DESC_LE16(USB_DESC_IDVENDER), /* idVendor */ \ |
253 |
| - USB_DESC_LE16(USB_DESC_IDPRODUCT), /* idProduct */ \ |
254 |
| - USB_DESC_LE16(USB_DESC_BCDDEVICE), /* bcdDevice */ \ |
255 |
| - USB_DESC_IMANUFACT, /* iManufacturer */ \ |
256 |
| - USB_DESC_IPRODUCT, /* iProduct */ \ |
257 |
| - USB_DESC_ISERIALNUM, /* iSerialNumber */ \ |
258 |
| - USB_DESC_BNUMCONFIG /* bNumConfigurations */ |
259 |
| - |
260 | 126 | // ** If add an interface, adjust USB_DESC_WTOTALLEN **
|
261 | 127 | // TODO: USB_DESC_D_MAX_EP_N doesn't exist, but there is CONF_USB_D_NUM_EP_SP
|
262 | 128 | // (= supported endpoints) - is that the one that needs to change?
|
|
0 commit comments