blob: 246e70f5ecbcc9a7b2aee482937666f369032408 [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
Sylvain Munaut96744362022-01-03 17:03:26 +010027 * transceive any data. We just remove the isochronous
28 * endpoints in the 'off' altsetting */
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020029 struct {
30 struct usb_intf_desc intf;
Harald Welte805f2cf2020-12-14 17:31:03 +010031 struct usb_ep_desc ep_interrupt;
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020032 } __attribute__ ((packed)) off;
33 struct {
34 struct usb_intf_desc intf;
35 struct usb_ep_desc ep_data_in;
36 struct usb_ep_desc ep_data_out;
37 struct usb_ep_desc ep_fb;
Harald Welte805f2cf2020-12-14 17:31:03 +010038 struct usb_ep_desc ep_interrupt;
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020039 } __attribute__ ((packed)) on;
40 } __attribute__ ((packed)) e1;
41
42 /* CDC */
43#if 0
44 struct {
45 struct usb_intf_desc intf_ctl;
Sylvain Munautb9d93632021-05-31 14:03:44 +020046 struct usb_cdc_hdr_desc cdc_hdr;
47 struct usb_cdc_acm_desc cdc_acm;
48 struct usb_cdc_union_desc__1 cdc_union;
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020049 struct usb_ep_desc ep_ctl;
50 struct usb_intf_desc intf_data;
51 struct usb_ep_desc ep_data_out;
52 struct usb_ep_desc ep_data_in;
53 } __attribute__ ((packed)) cdc;
54#endif
55
56 /* DFU Runtime */
57 struct {
58 struct usb_intf_desc intf;
Sylvain Munaut4ea7d272020-10-29 13:17:11 +010059 struct usb_dfu_func_desc func;
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020060 } __attribute__ ((packed)) dfu;
61} __attribute__ ((packed)) _app_conf_desc = {
62 .conf = {
63 .bLength = sizeof(struct usb_conf_desc),
64 .bDescriptorType = USB_DT_CONF,
65 .wTotalLength = sizeof(_app_conf_desc),
66#if 0
67 .bNumInterfaces = 4,
68#else
69 .bNumInterfaces = 2,
70#endif
71 .bConfigurationValue = 1,
72 .iConfiguration = 4,
73 .bmAttributes = 0x80,
74 .bMaxPower = 0x32, /* 100 mA */
75 },
76 .e1 = {
77 .off = {
78 .intf = {
79 .bLength = sizeof(struct usb_intf_desc),
80 .bDescriptorType = USB_DT_INTF,
81 .bInterfaceNumber = 0,
82 .bAlternateSetting = 0,
Sylvain Munaut96744362022-01-03 17:03:26 +010083 .bNumEndpoints = 1,
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020084 .bInterfaceClass = 0xff,
85 .bInterfaceSubClass = 0xe1,
86 .bInterfaceProtocol = 0x00,
87 .iInterface = 5,
88 },
Harald Welte805f2cf2020-12-14 17:31:03 +010089 .ep_interrupt = {
90 .bLength = sizeof(struct usb_ep_desc),
91 .bDescriptorType = USB_DT_EP,
92 .bEndpointAddress = 0x83,
93 .bmAttributes = 0x03,
94 .wMaxPacketSize = 10,
95 .bInterval = 3,
96 },
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020097 },
98 .on = {
99 .intf = {
100 .bLength = sizeof(struct usb_intf_desc),
101 .bDescriptorType = USB_DT_INTF,
102 .bInterfaceNumber = 0,
103 .bAlternateSetting = 1,
Harald Welte805f2cf2020-12-14 17:31:03 +0100104 .bNumEndpoints = 4,
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200105 .bInterfaceClass = 0xff,
106 .bInterfaceSubClass = 0xe1,
107 .bInterfaceProtocol = 0x00,
108 .iInterface = 5,
109 },
110 .ep_data_in = {
111 .bLength = sizeof(struct usb_ep_desc),
112 .bDescriptorType = USB_DT_EP,
113 .bEndpointAddress = 0x82,
114 .bmAttributes = 0x05,
115 .wMaxPacketSize = 388,
116 .bInterval = 1,
117 },
118 .ep_data_out = {
119 .bLength = sizeof(struct usb_ep_desc),
120 .bDescriptorType = USB_DT_EP,
121 .bEndpointAddress = 0x01,
122 .bmAttributes = 0x05,
123 .wMaxPacketSize = 388,
124 .bInterval = 1,
125 },
126 .ep_fb = {
127 .bLength = sizeof(struct usb_ep_desc),
128 .bDescriptorType = USB_DT_EP,
129 .bEndpointAddress = 0x81,
130 .bmAttributes = 0x11,
131 .wMaxPacketSize = 8,
132 .bInterval = 3,
133 },
Harald Welte805f2cf2020-12-14 17:31:03 +0100134 .ep_interrupt = {
135 .bLength = sizeof(struct usb_ep_desc),
136 .bDescriptorType = USB_DT_EP,
137 .bEndpointAddress = 0x83,
138 .bmAttributes = 0x03,
139 .wMaxPacketSize = 10,
140 .bInterval = 3,
141 },
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200142 },
143 },
144#if 0
145 .cdc = {
146 .intf_ctl = {
147 .bLength = sizeof(struct usb_intf_desc),
148 .bDescriptorType = USB_DT_INTF,
149 .bInterfaceNumber = 1,
150 .bAlternateSetting = 0,
151 .bNumEndpoints = 1,
Sylvain Munautb9d93632021-05-31 14:03:44 +0200152 .bInterfaceClass = USB_CLS_CDC_CONTROL,
153 .bInterfaceSubClass = USB_CDC_SCLS_ACM,
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200154 .bInterfaceProtocol = 0x00,
155 .iInterface = 6,
156 },
Sylvain Munautb9d93632021-05-31 14:03:44 +0200157 .cdc_hdr = {
158 .bLength = sizeof(struct usb_cdc_hdr_desc),
159 .bDescriptorType = USB_CS_DT_INTF,
160 .bDescriptorsubtype = USB_CDC_DST_HEADER,
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200161 .bcdCDC = 0x0110,
162 },
Sylvain Munautb9d93632021-05-31 14:03:44 +0200163 .cdc_acm = {
164 .bLength = sizeof(struct usb_cdc_acm_desc),
165 .bDescriptorType = USB_CS_DT_INTF,
166 .bDescriptorsubtype = USB_CDC_DST_ACM,
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200167 .bmCapabilities = 0x02,
168 },
Sylvain Munautb9d93632021-05-31 14:03:44 +0200169 .cdc_union = {
170 .bLength = sizeof(struct usb_cdc_union_desc) + 1,
171 .bDescriptorType = USB_CS_DT_INTF,
172 .bDescriptorsubtype = USB_CDC_DST_UNION,
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200173 .bMasterInterface = 1,
Sylvain Munautb9d93632021-05-31 14:03:44 +0200174 .bSlaveInterface = { 2 },
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200175 },
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200176 .ep_ctl = {
177 .bLength = sizeof(struct usb_ep_desc),
178 .bDescriptorType = USB_DT_EP,
179 .bEndpointAddress = 0x84,
180 .bmAttributes = 0x03,
181 .wMaxPacketSize = 64,
182 .bInterval = 0x40,
183 },
184 .intf_data = {
185 .bLength = sizeof(struct usb_intf_desc),
186 .bDescriptorType = USB_DT_INTF,
187 .bInterfaceNumber = 2,
188 .bAlternateSetting = 0,
189 .bNumEndpoints = 2,
Sylvain Munautb9d93632021-05-31 14:03:44 +0200190 .bInterfaceClass = USB_CLS_CDC_DATA,
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200191 .bInterfaceSubClass = 0x00,
192 .bInterfaceProtocol = 0x00,
193 .iInterface = 7,
194 },
195 .ep_data_out = {
196 .bLength = sizeof(struct usb_ep_desc),
197 .bDescriptorType = USB_DT_EP,
198 .bEndpointAddress = 0x05,
199 .bmAttributes = 0x02,
200 .wMaxPacketSize = 64,
201 .bInterval = 0x00,
202 },
203 .ep_data_in = {
204 .bLength = sizeof(struct usb_ep_desc),
205 .bDescriptorType = USB_DT_EP,
206 .bEndpointAddress = 0x85,
207 .bmAttributes = 0x02,
208 .wMaxPacketSize = 64,
209 .bInterval = 0x00,
210 },
211 },
212#endif
213 .dfu = {
214 .intf = {
215 .bLength = sizeof(struct usb_intf_desc),
216 .bDescriptorType = USB_DT_INTF,
217#if 0
218 .bInterfaceNumber = 3,
219#else
220 .bInterfaceNumber = 1,
221#endif
222 .bAlternateSetting = 0,
223 .bNumEndpoints = 0,
224 .bInterfaceClass = 0xfe,
225 .bInterfaceSubClass = 0x01,
226 .bInterfaceProtocol = 0x01,
227 .iInterface = 8,
228 },
229 .func = {
Sylvain Munaut4ea7d272020-10-29 13:17:11 +0100230 .bLength = sizeof(struct usb_dfu_func_desc),
231 .bDescriptorType = USB_DFU_DT_FUNC,
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200232 .bmAttributes = 0x0d,
Sylvain Munaut3c3ae792022-01-05 20:55:37 +0100233 .wDetachTimeOut = 0,
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200234 .wTransferSize = 4096,
235 .bcdDFUVersion = 0x0101,
236 },
237 },
238};
239
240static const struct usb_conf_desc * const _conf_desc_array[] = {
241 &_app_conf_desc.conf,
242};
243
244static const struct usb_dev_desc _dev_desc = {
245 .bLength = sizeof(struct usb_dev_desc),
246 .bDescriptorType = USB_DT_DEV,
247 .bcdUSB = 0x0200,
248 .bDeviceClass = 0,
249 .bDeviceSubClass = 0,
250 .bDeviceProtocol = 0,
251 .bMaxPacketSize0 = 64,
252 .idVendor = 0x1d50,
253 .idProduct = 0x6145,
254 .bcdDevice = 0x0003, /* v0.3 */
255 .iManufacturer = 2,
256 .iProduct = 3,
257 .iSerialNumber = 1,
258 .bNumConfigurations = num_elem(_conf_desc_array),
259};
260
261#include "usb_str_app.gen.h"
262
263const struct usb_stack_descriptors app_stack_desc = {
264 .dev = &_dev_desc,
265 .conf = _conf_desc_array,
266 .n_conf = num_elem(_conf_desc_array),
267 .str = _str_desc_array,
268 .n_str = num_elem(_str_desc_array),
269};