Sylvain Munaut | f5d7bf2 | 2020-09-14 10:23:50 +0200 | [diff] [blame] | 1 | /* |
| 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 Munaut | 4ea7d27 | 2020-10-29 13:17:11 +0100 | [diff] [blame] | 9 | #include <no2usb/usb_dfu_proto.h> |
Sylvain Munaut | f5d7bf2 | 2020-09-14 10:23:50 +0200 | [diff] [blame] | 10 | #include <no2usb/usb.h> |
| 11 | |
| 12 | #define NULL ((void*)0) |
| 13 | #define num_elem(a) (sizeof(a) / sizeof(a[0])) |
| 14 | |
| 15 | |
Harald Welte | f9280b0 | 2022-11-01 21:58:34 +0100 | [diff] [blame^] | 16 | /* Legacy Configuration */ |
Sylvain Munaut | f5d7bf2 | 2020-09-14 10:23:50 +0200 | [diff] [blame] | 17 | static const struct { |
Sylvain Munaut | f5d7bf2 | 2020-09-14 10:23:50 +0200 | [diff] [blame] | 18 | struct usb_conf_desc conf; |
Sylvain Munaut | f5d7bf2 | 2020-09-14 10:23:50 +0200 | [diff] [blame] | 19 | /* E1 */ |
| 20 | struct { |
| 21 | struct { |
| 22 | struct usb_intf_desc intf; |
| 23 | struct usb_ep_desc ep_data_in0; |
| 24 | struct usb_ep_desc ep_data_in1; |
| 25 | } __attribute__ ((packed)) off; |
| 26 | struct { |
| 27 | struct usb_intf_desc intf; |
| 28 | struct usb_ep_desc ep_data_in0; |
| 29 | struct usb_ep_desc ep_data_in1; |
| 30 | } __attribute__ ((packed)) on; |
| 31 | } __attribute__ ((packed)) e1; |
Sylvain Munaut | f5d7bf2 | 2020-09-14 10:23:50 +0200 | [diff] [blame] | 32 | /* DFU Runtime */ |
| 33 | struct { |
| 34 | struct usb_intf_desc intf; |
Sylvain Munaut | 4ea7d27 | 2020-10-29 13:17:11 +0100 | [diff] [blame] | 35 | struct usb_dfu_func_desc func; |
Sylvain Munaut | f5d7bf2 | 2020-09-14 10:23:50 +0200 | [diff] [blame] | 36 | } __attribute__ ((packed)) dfu; |
| 37 | } __attribute__ ((packed)) _app_conf_desc = { |
| 38 | .conf = { |
| 39 | .bLength = sizeof(struct usb_conf_desc), |
| 40 | .bDescriptorType = USB_DT_CONF, |
| 41 | .wTotalLength = sizeof(_app_conf_desc), |
Sylvain Munaut | f5d7bf2 | 2020-09-14 10:23:50 +0200 | [diff] [blame] | 42 | .bNumInterfaces = 2, |
Sylvain Munaut | f5d7bf2 | 2020-09-14 10:23:50 +0200 | [diff] [blame] | 43 | .bConfigurationValue = 1, |
| 44 | .iConfiguration = 4, |
| 45 | .bmAttributes = 0x80, |
| 46 | .bMaxPower = 0x32, /* 100 mA */ |
| 47 | }, |
| 48 | .e1 = { |
| 49 | .off = { |
| 50 | .intf = { |
| 51 | .bLength = sizeof(struct usb_intf_desc), |
| 52 | .bDescriptorType = USB_DT_INTF, |
| 53 | .bInterfaceNumber = 0, |
| 54 | .bAlternateSetting = 0, |
| 55 | .bNumEndpoints = 2, |
| 56 | .bInterfaceClass = 0xff, |
| 57 | .bInterfaceSubClass = 0xe1, |
| 58 | .bInterfaceProtocol = 0x00, |
| 59 | .iInterface = 5, |
| 60 | }, |
| 61 | .ep_data_in0 = { |
| 62 | .bLength = sizeof(struct usb_ep_desc), |
| 63 | .bDescriptorType = USB_DT_EP, |
| 64 | .bEndpointAddress = 0x81, |
| 65 | .bmAttributes = 0x05, |
| 66 | .wMaxPacketSize = 0, |
| 67 | .bInterval = 1, |
| 68 | }, |
| 69 | .ep_data_in1 = { |
| 70 | .bLength = sizeof(struct usb_ep_desc), |
| 71 | .bDescriptorType = USB_DT_EP, |
| 72 | .bEndpointAddress = 0x82, |
| 73 | .bmAttributes = 0x05, |
| 74 | .wMaxPacketSize = 0, |
| 75 | .bInterval = 1, |
| 76 | }, |
| 77 | }, |
| 78 | .on = { |
| 79 | .intf = { |
| 80 | .bLength = sizeof(struct usb_intf_desc), |
| 81 | .bDescriptorType = USB_DT_INTF, |
| 82 | .bInterfaceNumber = 0, |
| 83 | .bAlternateSetting = 1, |
| 84 | .bNumEndpoints = 2, |
| 85 | .bInterfaceClass = 0xff, |
| 86 | .bInterfaceSubClass = 0xe1, |
| 87 | .bInterfaceProtocol = 0x00, |
| 88 | .iInterface = 5, |
| 89 | }, |
| 90 | .ep_data_in0 = { |
| 91 | .bLength = sizeof(struct usb_ep_desc), |
| 92 | .bDescriptorType = USB_DT_EP, |
| 93 | .bEndpointAddress = 0x81, |
| 94 | .bmAttributes = 0x05, |
| 95 | .wMaxPacketSize = 388, |
| 96 | .bInterval = 1, |
| 97 | }, |
| 98 | .ep_data_in1 = { |
| 99 | .bLength = sizeof(struct usb_ep_desc), |
| 100 | .bDescriptorType = USB_DT_EP, |
| 101 | .bEndpointAddress = 0x82, |
| 102 | .bmAttributes = 0x05, |
| 103 | .wMaxPacketSize = 388, |
| 104 | .bInterval = 1, |
| 105 | }, |
| 106 | }, |
| 107 | }, |
Sylvain Munaut | f5d7bf2 | 2020-09-14 10:23:50 +0200 | [diff] [blame] | 108 | .dfu = { |
| 109 | .intf = { |
| 110 | .bLength = sizeof(struct usb_intf_desc), |
| 111 | .bDescriptorType = USB_DT_INTF, |
Sylvain Munaut | f5d7bf2 | 2020-09-14 10:23:50 +0200 | [diff] [blame] | 112 | .bInterfaceNumber = 1, |
Sylvain Munaut | f5d7bf2 | 2020-09-14 10:23:50 +0200 | [diff] [blame] | 113 | .bAlternateSetting = 0, |
| 114 | .bNumEndpoints = 0, |
| 115 | .bInterfaceClass = 0xfe, |
| 116 | .bInterfaceSubClass = 0x01, |
| 117 | .bInterfaceProtocol = 0x01, |
Sylvain Munaut | c704c07 | 2020-10-29 13:22:55 +0100 | [diff] [blame] | 118 | .iInterface = 6, |
Sylvain Munaut | f5d7bf2 | 2020-09-14 10:23:50 +0200 | [diff] [blame] | 119 | }, |
| 120 | .func = { |
Sylvain Munaut | 4ea7d27 | 2020-10-29 13:17:11 +0100 | [diff] [blame] | 121 | .bLength = sizeof(struct usb_dfu_func_desc), |
| 122 | .bDescriptorType = USB_DFU_DT_FUNC, |
Sylvain Munaut | f5d7bf2 | 2020-09-14 10:23:50 +0200 | [diff] [blame] | 123 | .bmAttributes = 0x0d, |
| 124 | .wDetachTimeOut = 1000, |
| 125 | .wTransferSize = 4096, |
| 126 | .bcdDFUVersion = 0x0101, |
| 127 | }, |
| 128 | }, |
| 129 | }; |
| 130 | |
Harald Welte | f9280b0 | 2022-11-01 21:58:34 +0100 | [diff] [blame^] | 131 | /* "icE1usb" compatible Configuration */ |
| 132 | static const struct { |
| 133 | struct usb_conf_desc conf; |
| 134 | /* Interface / Direction A */ |
| 135 | struct { |
| 136 | struct { |
| 137 | struct usb_intf_desc intf; |
| 138 | } __attribute__ ((packed)) off; |
| 139 | struct { |
| 140 | struct usb_intf_desc intf; |
| 141 | struct usb_ep_desc ep_data_in0; |
| 142 | } __attribute__ ((packed)) on; |
| 143 | } __attribute__ ((packed)) a; |
| 144 | /* Interface / Direction B */ |
| 145 | struct { |
| 146 | struct { |
| 147 | struct usb_intf_desc intf; |
| 148 | } __attribute__ ((packed)) off; |
| 149 | struct { |
| 150 | struct usb_intf_desc intf; |
| 151 | struct usb_ep_desc ep_data_in1; |
| 152 | } __attribute__ ((packed)) on; |
| 153 | } __attribute__ ((packed)) b; |
| 154 | } __attribute__ ((packed)) _app_conf_desc_e1d = { |
| 155 | .conf = { |
| 156 | .bLength = sizeof(struct usb_conf_desc), |
| 157 | .bDescriptorType = USB_DT_CONF, |
| 158 | .wTotalLength = sizeof(_app_conf_desc_e1d), |
| 159 | .bNumInterfaces = 3, |
| 160 | .bConfigurationValue = 2, |
| 161 | .iConfiguration = 7, |
| 162 | .bmAttributes = 0x80, |
| 163 | .bMaxPower = 0x32, /* 100 mA */ |
| 164 | }, |
| 165 | .a = { |
| 166 | .off = { |
| 167 | .intf = { |
| 168 | .bLength = sizeof(struct usb_intf_desc), |
| 169 | .bDescriptorType = USB_DT_INTF, |
| 170 | .bInterfaceNumber = 0, |
| 171 | .bAlternateSetting = 0, |
| 172 | .bNumEndpoints = 0, |
| 173 | .bInterfaceClass = 0xff, |
| 174 | .bInterfaceSubClass = 0xe1, |
| 175 | .bInterfaceProtocol = 0x00, |
| 176 | .iInterface = 8, |
| 177 | }, |
| 178 | }, |
| 179 | .on = { |
| 180 | .intf = { |
| 181 | .bLength = sizeof(struct usb_intf_desc), |
| 182 | .bDescriptorType = USB_DT_INTF, |
| 183 | .bInterfaceNumber = 0, |
| 184 | .bAlternateSetting = 1, |
| 185 | .bNumEndpoints = 1, |
| 186 | .bInterfaceClass = 0xff, |
| 187 | .bInterfaceSubClass = 0xe1, |
| 188 | .bInterfaceProtocol = 0x00, |
| 189 | .iInterface = 8, |
| 190 | }, |
| 191 | .ep_data_in0 = { |
| 192 | .bLength = sizeof(struct usb_ep_desc), |
| 193 | .bDescriptorType = USB_DT_EP, |
| 194 | .bEndpointAddress = 0x81, |
| 195 | .bmAttributes = 0x05, |
| 196 | .wMaxPacketSize = 388, |
| 197 | .bInterval = 1, |
| 198 | }, |
| 199 | }, |
| 200 | }, |
| 201 | .b = { |
| 202 | .off = { |
| 203 | .intf = { |
| 204 | .bLength = sizeof(struct usb_intf_desc), |
| 205 | .bDescriptorType = USB_DT_INTF, |
| 206 | .bInterfaceNumber = 1, |
| 207 | .bAlternateSetting = 0, |
| 208 | .bNumEndpoints = 0, |
| 209 | .bInterfaceClass = 0xff, |
| 210 | .bInterfaceSubClass = 0xe1, |
| 211 | .bInterfaceProtocol = 0x00, |
| 212 | .iInterface = 9, |
| 213 | }, |
| 214 | }, |
| 215 | .on = { |
| 216 | .intf = { |
| 217 | .bLength = sizeof(struct usb_intf_desc), |
| 218 | .bDescriptorType = USB_DT_INTF, |
| 219 | .bInterfaceNumber = 1, |
| 220 | .bAlternateSetting = 1, |
| 221 | .bNumEndpoints = 1, |
| 222 | .bInterfaceClass = 0xff, |
| 223 | .bInterfaceSubClass = 0xe1, |
| 224 | .bInterfaceProtocol = 0x00, |
| 225 | .iInterface = 9, |
| 226 | }, |
| 227 | .ep_data_in1 = { |
| 228 | .bLength = sizeof(struct usb_ep_desc), |
| 229 | .bDescriptorType = USB_DT_EP, |
| 230 | .bEndpointAddress = 0x82, |
| 231 | .bmAttributes = 0x05, |
| 232 | .wMaxPacketSize = 388, |
| 233 | .bInterval = 1, |
| 234 | }, |
| 235 | }, |
| 236 | }, |
| 237 | }; |
| 238 | |
Sylvain Munaut | f5d7bf2 | 2020-09-14 10:23:50 +0200 | [diff] [blame] | 239 | static const struct usb_conf_desc * const _conf_desc_array[] = { |
| 240 | &_app_conf_desc.conf, |
Harald Welte | f9280b0 | 2022-11-01 21:58:34 +0100 | [diff] [blame^] | 241 | &_app_conf_desc_e1d.conf, |
Sylvain Munaut | f5d7bf2 | 2020-09-14 10:23:50 +0200 | [diff] [blame] | 242 | }; |
| 243 | |
| 244 | static 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 = 0x6151, |
| 254 | .bcdDevice = 2, |
| 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 | |
| 263 | const 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 | }; |