blob: 544ac23c6e926b2e5d8fe874e357902cdb6fcbc1 [file] [log] [blame]
Sylvain Munautbc9f5c42020-09-14 10:22:29 +02001/*
2 * usb_desc_app.c
3 *
4 * Copyright (C) 2019-2020 Sylvain Munaut <tnt@246tNt.com>
5 * SPDX-License-Identifier: GPL-3.0-or-later
6 */
7
8#include <no2usb/usb_proto.h>
Sylvain Munautb9d93632021-05-31 14:03:44 +02009#include <no2usb/usb_cdc_proto.h>
Sylvain Munaut4ea7d272020-10-29 13:17:11 +010010#include <no2usb/usb_dfu_proto.h>
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020011#include <no2usb/usb.h>
12
13#define NULL ((void*)0)
14#define num_elem(a) (sizeof(a) / sizeof(a[0]))
15
16
Sylvain Munautb9d93632021-05-31 14:03:44 +020017usb_cdc_union_desc_def(1);
18
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020019static const struct {
20 /* Configuration */
21 struct usb_conf_desc conf;
22
23 /* E1 */
24 struct {
Harald Welte30fc5602020-12-14 15:56:28 +010025 /* Two altsettings are required, as isochronous
26 * interfaces must have a setting where they don't
27 * transceive any data. wMaxPacketSize is 0 for
28 * all endpoints in the 'off' altsetting */
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020029 struct {
30 struct usb_intf_desc intf;
31 struct usb_ep_desc ep_data_in;
32 struct usb_ep_desc ep_data_out;
33 struct usb_ep_desc ep_fb;
Harald Welte805f2cf2020-12-14 17:31:03 +010034 struct usb_ep_desc ep_interrupt;
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020035 } __attribute__ ((packed)) off;
36 struct {
37 struct usb_intf_desc intf;
38 struct usb_ep_desc ep_data_in;
39 struct usb_ep_desc ep_data_out;
40 struct usb_ep_desc ep_fb;
Harald Welte805f2cf2020-12-14 17:31:03 +010041 struct usb_ep_desc ep_interrupt;
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020042 } __attribute__ ((packed)) on;
43 } __attribute__ ((packed)) e1;
44
45 /* CDC */
46#if 0
47 struct {
48 struct usb_intf_desc intf_ctl;
Sylvain Munautb9d93632021-05-31 14:03:44 +020049 struct usb_cdc_hdr_desc cdc_hdr;
50 struct usb_cdc_acm_desc cdc_acm;
51 struct usb_cdc_union_desc__1 cdc_union;
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020052 struct usb_ep_desc ep_ctl;
53 struct usb_intf_desc intf_data;
54 struct usb_ep_desc ep_data_out;
55 struct usb_ep_desc ep_data_in;
56 } __attribute__ ((packed)) cdc;
57#endif
58
59 /* DFU Runtime */
60 struct {
61 struct usb_intf_desc intf;
Sylvain Munaut4ea7d272020-10-29 13:17:11 +010062 struct usb_dfu_func_desc func;
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020063 } __attribute__ ((packed)) dfu;
64} __attribute__ ((packed)) _app_conf_desc = {
65 .conf = {
66 .bLength = sizeof(struct usb_conf_desc),
67 .bDescriptorType = USB_DT_CONF,
68 .wTotalLength = sizeof(_app_conf_desc),
69#if 0
70 .bNumInterfaces = 4,
71#else
72 .bNumInterfaces = 2,
73#endif
74 .bConfigurationValue = 1,
75 .iConfiguration = 4,
76 .bmAttributes = 0x80,
77 .bMaxPower = 0x32, /* 100 mA */
78 },
79 .e1 = {
80 .off = {
81 .intf = {
82 .bLength = sizeof(struct usb_intf_desc),
83 .bDescriptorType = USB_DT_INTF,
84 .bInterfaceNumber = 0,
85 .bAlternateSetting = 0,
Harald Welte805f2cf2020-12-14 17:31:03 +010086 .bNumEndpoints = 4,
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020087 .bInterfaceClass = 0xff,
88 .bInterfaceSubClass = 0xe1,
89 .bInterfaceProtocol = 0x00,
90 .iInterface = 5,
91 },
92 .ep_data_in = {
93 .bLength = sizeof(struct usb_ep_desc),
94 .bDescriptorType = USB_DT_EP,
95 .bEndpointAddress = 0x82,
96 .bmAttributes = 0x05,
97 .wMaxPacketSize = 0,
98 .bInterval = 1,
99 },
100 .ep_data_out = {
101 .bLength = sizeof(struct usb_ep_desc),
102 .bDescriptorType = USB_DT_EP,
103 .bEndpointAddress = 0x01,
104 .bmAttributes = 0x05,
105 .wMaxPacketSize = 0,
106 .bInterval = 1,
107 },
108 .ep_fb = {
109 .bLength = sizeof(struct usb_ep_desc),
110 .bDescriptorType = USB_DT_EP,
111 .bEndpointAddress = 0x81,
112 .bmAttributes = 0x11,
113 .wMaxPacketSize = 0,
114 .bInterval = 3,
115 },
Harald Welte805f2cf2020-12-14 17:31:03 +0100116 .ep_interrupt = {
117 .bLength = sizeof(struct usb_ep_desc),
118 .bDescriptorType = USB_DT_EP,
119 .bEndpointAddress = 0x83,
120 .bmAttributes = 0x03,
121 .wMaxPacketSize = 10,
122 .bInterval = 3,
123 },
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200124 },
125 .on = {
126 .intf = {
127 .bLength = sizeof(struct usb_intf_desc),
128 .bDescriptorType = USB_DT_INTF,
129 .bInterfaceNumber = 0,
130 .bAlternateSetting = 1,
Harald Welte805f2cf2020-12-14 17:31:03 +0100131 .bNumEndpoints = 4,
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200132 .bInterfaceClass = 0xff,
133 .bInterfaceSubClass = 0xe1,
134 .bInterfaceProtocol = 0x00,
135 .iInterface = 5,
136 },
137 .ep_data_in = {
138 .bLength = sizeof(struct usb_ep_desc),
139 .bDescriptorType = USB_DT_EP,
140 .bEndpointAddress = 0x82,
141 .bmAttributes = 0x05,
142 .wMaxPacketSize = 388,
143 .bInterval = 1,
144 },
145 .ep_data_out = {
146 .bLength = sizeof(struct usb_ep_desc),
147 .bDescriptorType = USB_DT_EP,
148 .bEndpointAddress = 0x01,
149 .bmAttributes = 0x05,
150 .wMaxPacketSize = 388,
151 .bInterval = 1,
152 },
153 .ep_fb = {
154 .bLength = sizeof(struct usb_ep_desc),
155 .bDescriptorType = USB_DT_EP,
156 .bEndpointAddress = 0x81,
157 .bmAttributes = 0x11,
158 .wMaxPacketSize = 8,
159 .bInterval = 3,
160 },
Harald Welte805f2cf2020-12-14 17:31:03 +0100161 .ep_interrupt = {
162 .bLength = sizeof(struct usb_ep_desc),
163 .bDescriptorType = USB_DT_EP,
164 .bEndpointAddress = 0x83,
165 .bmAttributes = 0x03,
166 .wMaxPacketSize = 10,
167 .bInterval = 3,
168 },
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200169 },
170 },
171#if 0
172 .cdc = {
173 .intf_ctl = {
174 .bLength = sizeof(struct usb_intf_desc),
175 .bDescriptorType = USB_DT_INTF,
176 .bInterfaceNumber = 1,
177 .bAlternateSetting = 0,
178 .bNumEndpoints = 1,
Sylvain Munautb9d93632021-05-31 14:03:44 +0200179 .bInterfaceClass = USB_CLS_CDC_CONTROL,
180 .bInterfaceSubClass = USB_CDC_SCLS_ACM,
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200181 .bInterfaceProtocol = 0x00,
182 .iInterface = 6,
183 },
Sylvain Munautb9d93632021-05-31 14:03:44 +0200184 .cdc_hdr = {
185 .bLength = sizeof(struct usb_cdc_hdr_desc),
186 .bDescriptorType = USB_CS_DT_INTF,
187 .bDescriptorsubtype = USB_CDC_DST_HEADER,
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200188 .bcdCDC = 0x0110,
189 },
Sylvain Munautb9d93632021-05-31 14:03:44 +0200190 .cdc_acm = {
191 .bLength = sizeof(struct usb_cdc_acm_desc),
192 .bDescriptorType = USB_CS_DT_INTF,
193 .bDescriptorsubtype = USB_CDC_DST_ACM,
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200194 .bmCapabilities = 0x02,
195 },
Sylvain Munautb9d93632021-05-31 14:03:44 +0200196 .cdc_union = {
197 .bLength = sizeof(struct usb_cdc_union_desc) + 1,
198 .bDescriptorType = USB_CS_DT_INTF,
199 .bDescriptorsubtype = USB_CDC_DST_UNION,
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200200 .bMasterInterface = 1,
Sylvain Munautb9d93632021-05-31 14:03:44 +0200201 .bSlaveInterface = { 2 },
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200202 },
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200203 .ep_ctl = {
204 .bLength = sizeof(struct usb_ep_desc),
205 .bDescriptorType = USB_DT_EP,
206 .bEndpointAddress = 0x84,
207 .bmAttributes = 0x03,
208 .wMaxPacketSize = 64,
209 .bInterval = 0x40,
210 },
211 .intf_data = {
212 .bLength = sizeof(struct usb_intf_desc),
213 .bDescriptorType = USB_DT_INTF,
214 .bInterfaceNumber = 2,
215 .bAlternateSetting = 0,
216 .bNumEndpoints = 2,
Sylvain Munautb9d93632021-05-31 14:03:44 +0200217 .bInterfaceClass = USB_CLS_CDC_DATA,
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200218 .bInterfaceSubClass = 0x00,
219 .bInterfaceProtocol = 0x00,
220 .iInterface = 7,
221 },
222 .ep_data_out = {
223 .bLength = sizeof(struct usb_ep_desc),
224 .bDescriptorType = USB_DT_EP,
225 .bEndpointAddress = 0x05,
226 .bmAttributes = 0x02,
227 .wMaxPacketSize = 64,
228 .bInterval = 0x00,
229 },
230 .ep_data_in = {
231 .bLength = sizeof(struct usb_ep_desc),
232 .bDescriptorType = USB_DT_EP,
233 .bEndpointAddress = 0x85,
234 .bmAttributes = 0x02,
235 .wMaxPacketSize = 64,
236 .bInterval = 0x00,
237 },
238 },
239#endif
240 .dfu = {
241 .intf = {
242 .bLength = sizeof(struct usb_intf_desc),
243 .bDescriptorType = USB_DT_INTF,
244#if 0
245 .bInterfaceNumber = 3,
246#else
247 .bInterfaceNumber = 1,
248#endif
249 .bAlternateSetting = 0,
250 .bNumEndpoints = 0,
251 .bInterfaceClass = 0xfe,
252 .bInterfaceSubClass = 0x01,
253 .bInterfaceProtocol = 0x01,
254 .iInterface = 8,
255 },
256 .func = {
Sylvain Munaut4ea7d272020-10-29 13:17:11 +0100257 .bLength = sizeof(struct usb_dfu_func_desc),
258 .bDescriptorType = USB_DFU_DT_FUNC,
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200259 .bmAttributes = 0x0d,
260 .wDetachTimeOut = 1000,
261 .wTransferSize = 4096,
262 .bcdDFUVersion = 0x0101,
263 },
264 },
265};
266
267static const struct usb_conf_desc * const _conf_desc_array[] = {
268 &_app_conf_desc.conf,
269};
270
271static const struct usb_dev_desc _dev_desc = {
272 .bLength = sizeof(struct usb_dev_desc),
273 .bDescriptorType = USB_DT_DEV,
274 .bcdUSB = 0x0200,
275 .bDeviceClass = 0,
276 .bDeviceSubClass = 0,
277 .bDeviceProtocol = 0,
278 .bMaxPacketSize0 = 64,
279 .idVendor = 0x1d50,
280 .idProduct = 0x6145,
281 .bcdDevice = 0x0003, /* v0.3 */
282 .iManufacturer = 2,
283 .iProduct = 3,
284 .iSerialNumber = 1,
285 .bNumConfigurations = num_elem(_conf_desc_array),
286};
287
288#include "usb_str_app.gen.h"
289
290const struct usb_stack_descriptors app_stack_desc = {
291 .dev = &_dev_desc,
292 .conf = _conf_desc_array,
293 .n_conf = num_elem(_conf_desc_array),
294 .str = _str_desc_array,
295 .n_str = num_elem(_str_desc_array),
296};