40#include <dev/usb/template/usb_template.h> 41 42enum { 43 STRING_LANG_INDEX, 44 STRING_MAC_INDEX, 45 STRING_ETH_CONTROL_INDEX, 46 STRING_ETH_DATA_INDEX, 47 STRING_ETH_CONFIG_INDEX, 48 STRING_ETH_VENDOR_INDEX, 49 STRING_ETH_PRODUCT_INDEX, 50 STRING_ETH_SERIAL_INDEX, 51 STRING_ETH_MAX, 52}; 53 54#define STRING_LANG \ 55 0x09, 0x04, /* American English */ 56 57#define STRING_MAC \ 58 '2', 0, 'A', 0, '2', 0, '3', 0, \ 59 '4', 0, '5', 0, '6', 0, '7', 0, \ 60 '8', 0, '9', 0, 'A', 0, 'B', 0, 61 62#define STRING_ETH_CONTROL \ 63 'U', 0, 'S', 0, 'B', 0, ' ', 0, \ 64 'E', 0, 't', 0, 'h', 0, 'e', 0, \ 65 'r', 0, 'n', 0, 'e', 0, 't', 0, \ 66 ' ', 0, 'C', 0, 'o', 0, 'm', 0, \ 67 'm', 0, ' ', 0, 'i', 0, 'n', 0, \ 68 't', 0, 'e', 0, 'r', 0, 'f', 0, \ 69 'a', 0, 'c', 0, 'e', 0, 70 71#define STRING_ETH_DATA \ 72 'U', 0, 'S', 0, 'B', 0, ' ', 0, \ 73 'E', 0, 't', 0, 'h', 0, 'e', 0, \ 74 'r', 0, 'n', 0, 'e', 0, 't', 0, \ 75 ' ', 0, 'D', 0, 'a', 0, 't', 0, \ 76 'a', 0, ' ', 0, 'i', 0, 'n', 0, \ 77 't', 0, 'e', 0, 'r', 0, 'f', 0, \ 78 'a', 0, 'c', 0, 'e', 0, 79 80#define STRING_ETH_CONFIG \ 81 'D', 0, 'e', 0, 'f', 0, 'a', 0, \ 82 'u', 0, 'l', 0, 't', 0, ' ', 0, \ 83 'c', 0, 'o', 0, 'n', 0, 'f', 0, \ 84 'i', 0, 'g', 0, 85 86#define STRING_ETH_VENDOR \ 87 'F', 0, 'r', 0, 'e', 0, 'e', 0, \ 88 'B', 0, 'S', 0, 'D', 0, ' ', 0, \ 89 'f', 0, 'o', 0, 'u', 0, 'n', 0, \ 90 'd', 0, 'a', 0, 't', 0, 'i', 0, \ 91 'o', 0, 'n', 0, 92 93#define STRING_ETH_PRODUCT \ 94 'U', 0, 'S', 0, 'B', 0, ' ', 0, \ 95 'E', 0, 't', 0, 'h', 0, 'e', 0, \ 96 'r', 0, 'n', 0, 'e', 0, 't', 0, \ 97 ' ', 0, 'A', 0, 'd', 0, 'a', 0, \ 98 'p', 0, 't', 0, 'e', 0, 'r', 0, 99 100#define STRING_ETH_SERIAL \ 101 'D', 0, 'e', 0, 'c', 0, 'e', 0, \ 102 'm', 0, 'b', 0, 'e', 0, 'r', 0, \ 103 ' ', 0, '2', 0, '0', 0, '0', 0, \ 104 '7', 0, 105 106/* make the real string descriptors */ 107 108USB_MAKE_STRING_DESC(STRING_LANG, string_lang); 109USB_MAKE_STRING_DESC(STRING_MAC, string_mac); 110USB_MAKE_STRING_DESC(STRING_ETH_CONTROL, string_eth_control); 111USB_MAKE_STRING_DESC(STRING_ETH_DATA, string_eth_data); 112USB_MAKE_STRING_DESC(STRING_ETH_CONFIG, string_eth_config); 113USB_MAKE_STRING_DESC(STRING_ETH_VENDOR, string_eth_vendor); 114USB_MAKE_STRING_DESC(STRING_ETH_PRODUCT, string_eth_product); 115USB_MAKE_STRING_DESC(STRING_ETH_SERIAL, string_eth_serial); 116 117/* prototypes */ 118 119static usb_temp_get_string_desc_t eth_get_string_desc; 120 121static const struct usb_cdc_union_descriptor eth_union_desc = { 122 .bLength = sizeof(eth_union_desc), 123 .bDescriptorType = UDESC_CS_INTERFACE, 124 .bDescriptorSubtype = UDESCSUB_CDC_UNION, 125 .bMasterInterface = 0, /* this is automatically updated */ 126 .bSlaveInterface[0] = 1, /* this is automatically updated */ 127}; 128 129static const struct usb_cdc_header_descriptor eth_header_desc = { 130 .bLength = sizeof(eth_header_desc), 131 .bDescriptorType = UDESC_CS_INTERFACE, 132 .bDescriptorSubtype = UDESCSUB_CDC_HEADER, 133 .bcdCDC[0] = 0x10, 134 .bcdCDC[1] = 0x01, 135}; 136 137static const struct usb_cdc_ethernet_descriptor eth_enf_desc = { 138 .bLength = sizeof(eth_enf_desc), 139 .bDescriptorType = UDESC_CS_INTERFACE, 140 .bDescriptorSubtype = UDESCSUB_CDC_ENF, 141 .iMacAddress = STRING_MAC_INDEX, 142 .bmEthernetStatistics = {0, 0, 0, 0}, 143 .wMaxSegmentSize = {0xEA, 0x05},/* 1514 bytes */ 144 .wNumberMCFilters = {0, 0}, 145 .bNumberPowerFilters = 0, 146}; 147 148static const void *eth_control_if_desc[] = { 149 ð_union_desc, 150 ð_header_desc, 151 ð_enf_desc, 152 NULL, 153}; 154 155static const struct usb_temp_packet_size bulk_mps = { 156 .mps[USB_SPEED_FULL] = 64, 157 .mps[USB_SPEED_HIGH] = 512, 158}; 159 160static const struct usb_temp_packet_size intr_mps = { 161 .mps[USB_SPEED_FULL] = 8, 162 .mps[USB_SPEED_HIGH] = 8, 163}; 164 165static const struct usb_temp_endpoint_desc bulk_in_ep = { 166 .pPacketSize = &bulk_mps, 167#ifdef USB_HIP_IN_EP_0 168 .bEndpointAddress = USB_HIP_IN_EP_0, 169#else 170 .bEndpointAddress = UE_DIR_IN, 171#endif 172 .bmAttributes = UE_BULK, 173}; 174 175static const struct usb_temp_endpoint_desc bulk_out_ep = { 176 .pPacketSize = &bulk_mps, 177#ifdef USB_HIP_OUT_EP_0 178 .bEndpointAddress = USB_HIP_OUT_EP_0, 179#else 180 .bEndpointAddress = UE_DIR_OUT, 181#endif 182 .bmAttributes = UE_BULK, 183}; 184 185static const struct usb_temp_endpoint_desc intr_in_ep = { 186 .pPacketSize = &intr_mps, 187 .bEndpointAddress = UE_DIR_IN, 188 .bmAttributes = UE_INTERRUPT, 189}; 190 191static const struct usb_temp_endpoint_desc *eth_intr_endpoints[] = { 192 &intr_in_ep, 193 NULL, 194}; 195 196static const struct usb_temp_interface_desc eth_control_interface = { 197 .ppEndpoints = eth_intr_endpoints, 198 .ppRawDesc = eth_control_if_desc, 199 .bInterfaceClass = UICLASS_CDC, 200 .bInterfaceSubClass = UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL, 201 .bInterfaceProtocol = 0, 202 .iInterface = STRING_ETH_CONTROL_INDEX, 203}; 204 205static const struct usb_temp_endpoint_desc *eth_data_endpoints[] = { 206 &bulk_in_ep, 207 &bulk_out_ep, 208 NULL, 209}; 210 211static const struct usb_temp_interface_desc eth_data_null_interface = { 212 .ppEndpoints = NULL, /* no endpoints */ 213 .bInterfaceClass = UICLASS_CDC_DATA, 214 .bInterfaceSubClass = 0, 215 .bInterfaceProtocol = 0, 216 .iInterface = STRING_ETH_DATA_INDEX, 217}; 218 219static const struct usb_temp_interface_desc eth_data_interface = { 220 .ppEndpoints = eth_data_endpoints, 221 .bInterfaceClass = UICLASS_CDC_DATA, 222 .bInterfaceSubClass = UISUBCLASS_DATA, 223 .bInterfaceProtocol = 0, 224 .iInterface = STRING_ETH_DATA_INDEX, 225 .isAltInterface = 1, /* this is an alternate setting */ 226}; 227 228static const struct usb_temp_interface_desc *eth_interfaces[] = { 229 ð_control_interface, 230 ð_data_null_interface, 231 ð_data_interface, 232 NULL, 233}; 234 235static const struct usb_temp_config_desc eth_config_desc = { 236 .ppIfaceDesc = eth_interfaces, 237 .bmAttributes = UC_BUS_POWERED, 238 .bMaxPower = 25, /* 50 mA */ 239 .iConfiguration = STRING_ETH_CONFIG_INDEX, 240}; 241 242static const struct usb_temp_config_desc *eth_configs[] = { 243 ð_config_desc, 244 NULL, 245}; 246 247const struct usb_temp_device_desc usb_template_cdce = { 248 .getStringDesc = ð_get_string_desc, 249 .ppConfigDesc = eth_configs, 250 .idVendor = 0x0001, 251 .idProduct = 0x0001, 252 .bcdDevice = 0x0100, 253 .bDeviceClass = UDCLASS_COMM, 254 .bDeviceSubClass = 0, 255 .bDeviceProtocol = 0, 256 .iManufacturer = STRING_ETH_VENDOR_INDEX, 257 .iProduct = STRING_ETH_PRODUCT_INDEX, 258 .iSerialNumber = STRING_ETH_SERIAL_INDEX, 259}; 260 261/*------------------------------------------------------------------------* 262 * eth_get_string_desc 263 * 264 * Return values: 265 * NULL: Failure. No such string. 266 * Else: Success. Pointer to string descriptor is returned. 267 *------------------------------------------------------------------------*/ 268static const void * 269eth_get_string_desc(uint16_t lang_id, uint8_t string_index) 270{ 271 static const void *ptr[STRING_ETH_MAX] = { 272 [STRING_LANG_INDEX] = &string_lang, 273 [STRING_MAC_INDEX] = &string_mac, 274 [STRING_ETH_CONTROL_INDEX] = &string_eth_control, 275 [STRING_ETH_DATA_INDEX] = &string_eth_data, 276 [STRING_ETH_CONFIG_INDEX] = &string_eth_config, 277 [STRING_ETH_VENDOR_INDEX] = &string_eth_vendor, 278 [STRING_ETH_PRODUCT_INDEX] = &string_eth_product, 279 [STRING_ETH_SERIAL_INDEX] = &string_eth_serial, 280 }; 281 282 if (string_index == 0) { 283 return (&string_lang); 284 } 285 if (lang_id != 0x0409) { 286 return (NULL); 287 } 288 if (string_index < STRING_ETH_MAX) { 289 return (ptr[string_index]); 290 } 291 return (NULL); 292}
| 58#include <dev/usb/template/usb_template.h> 59 60enum { 61 STRING_LANG_INDEX, 62 STRING_MAC_INDEX, 63 STRING_ETH_CONTROL_INDEX, 64 STRING_ETH_DATA_INDEX, 65 STRING_ETH_CONFIG_INDEX, 66 STRING_ETH_VENDOR_INDEX, 67 STRING_ETH_PRODUCT_INDEX, 68 STRING_ETH_SERIAL_INDEX, 69 STRING_ETH_MAX, 70}; 71 72#define STRING_LANG \ 73 0x09, 0x04, /* American English */ 74 75#define STRING_MAC \ 76 '2', 0, 'A', 0, '2', 0, '3', 0, \ 77 '4', 0, '5', 0, '6', 0, '7', 0, \ 78 '8', 0, '9', 0, 'A', 0, 'B', 0, 79 80#define STRING_ETH_CONTROL \ 81 'U', 0, 'S', 0, 'B', 0, ' ', 0, \ 82 'E', 0, 't', 0, 'h', 0, 'e', 0, \ 83 'r', 0, 'n', 0, 'e', 0, 't', 0, \ 84 ' ', 0, 'C', 0, 'o', 0, 'm', 0, \ 85 'm', 0, ' ', 0, 'i', 0, 'n', 0, \ 86 't', 0, 'e', 0, 'r', 0, 'f', 0, \ 87 'a', 0, 'c', 0, 'e', 0, 88 89#define STRING_ETH_DATA \ 90 'U', 0, 'S', 0, 'B', 0, ' ', 0, \ 91 'E', 0, 't', 0, 'h', 0, 'e', 0, \ 92 'r', 0, 'n', 0, 'e', 0, 't', 0, \ 93 ' ', 0, 'D', 0, 'a', 0, 't', 0, \ 94 'a', 0, ' ', 0, 'i', 0, 'n', 0, \ 95 't', 0, 'e', 0, 'r', 0, 'f', 0, \ 96 'a', 0, 'c', 0, 'e', 0, 97 98#define STRING_ETH_CONFIG \ 99 'D', 0, 'e', 0, 'f', 0, 'a', 0, \ 100 'u', 0, 'l', 0, 't', 0, ' ', 0, \ 101 'c', 0, 'o', 0, 'n', 0, 'f', 0, \ 102 'i', 0, 'g', 0, 103 104#define STRING_ETH_VENDOR \ 105 'F', 0, 'r', 0, 'e', 0, 'e', 0, \ 106 'B', 0, 'S', 0, 'D', 0, ' ', 0, \ 107 'f', 0, 'o', 0, 'u', 0, 'n', 0, \ 108 'd', 0, 'a', 0, 't', 0, 'i', 0, \ 109 'o', 0, 'n', 0, 110 111#define STRING_ETH_PRODUCT \ 112 'U', 0, 'S', 0, 'B', 0, ' ', 0, \ 113 'E', 0, 't', 0, 'h', 0, 'e', 0, \ 114 'r', 0, 'n', 0, 'e', 0, 't', 0, \ 115 ' ', 0, 'A', 0, 'd', 0, 'a', 0, \ 116 'p', 0, 't', 0, 'e', 0, 'r', 0, 117 118#define STRING_ETH_SERIAL \ 119 'D', 0, 'e', 0, 'c', 0, 'e', 0, \ 120 'm', 0, 'b', 0, 'e', 0, 'r', 0, \ 121 ' ', 0, '2', 0, '0', 0, '0', 0, \ 122 '7', 0, 123 124/* make the real string descriptors */ 125 126USB_MAKE_STRING_DESC(STRING_LANG, string_lang); 127USB_MAKE_STRING_DESC(STRING_MAC, string_mac); 128USB_MAKE_STRING_DESC(STRING_ETH_CONTROL, string_eth_control); 129USB_MAKE_STRING_DESC(STRING_ETH_DATA, string_eth_data); 130USB_MAKE_STRING_DESC(STRING_ETH_CONFIG, string_eth_config); 131USB_MAKE_STRING_DESC(STRING_ETH_VENDOR, string_eth_vendor); 132USB_MAKE_STRING_DESC(STRING_ETH_PRODUCT, string_eth_product); 133USB_MAKE_STRING_DESC(STRING_ETH_SERIAL, string_eth_serial); 134 135/* prototypes */ 136 137static usb_temp_get_string_desc_t eth_get_string_desc; 138 139static const struct usb_cdc_union_descriptor eth_union_desc = { 140 .bLength = sizeof(eth_union_desc), 141 .bDescriptorType = UDESC_CS_INTERFACE, 142 .bDescriptorSubtype = UDESCSUB_CDC_UNION, 143 .bMasterInterface = 0, /* this is automatically updated */ 144 .bSlaveInterface[0] = 1, /* this is automatically updated */ 145}; 146 147static const struct usb_cdc_header_descriptor eth_header_desc = { 148 .bLength = sizeof(eth_header_desc), 149 .bDescriptorType = UDESC_CS_INTERFACE, 150 .bDescriptorSubtype = UDESCSUB_CDC_HEADER, 151 .bcdCDC[0] = 0x10, 152 .bcdCDC[1] = 0x01, 153}; 154 155static const struct usb_cdc_ethernet_descriptor eth_enf_desc = { 156 .bLength = sizeof(eth_enf_desc), 157 .bDescriptorType = UDESC_CS_INTERFACE, 158 .bDescriptorSubtype = UDESCSUB_CDC_ENF, 159 .iMacAddress = STRING_MAC_INDEX, 160 .bmEthernetStatistics = {0, 0, 0, 0}, 161 .wMaxSegmentSize = {0xEA, 0x05},/* 1514 bytes */ 162 .wNumberMCFilters = {0, 0}, 163 .bNumberPowerFilters = 0, 164}; 165 166static const void *eth_control_if_desc[] = { 167 ð_union_desc, 168 ð_header_desc, 169 ð_enf_desc, 170 NULL, 171}; 172 173static const struct usb_temp_packet_size bulk_mps = { 174 .mps[USB_SPEED_FULL] = 64, 175 .mps[USB_SPEED_HIGH] = 512, 176}; 177 178static const struct usb_temp_packet_size intr_mps = { 179 .mps[USB_SPEED_FULL] = 8, 180 .mps[USB_SPEED_HIGH] = 8, 181}; 182 183static const struct usb_temp_endpoint_desc bulk_in_ep = { 184 .pPacketSize = &bulk_mps, 185#ifdef USB_HIP_IN_EP_0 186 .bEndpointAddress = USB_HIP_IN_EP_0, 187#else 188 .bEndpointAddress = UE_DIR_IN, 189#endif 190 .bmAttributes = UE_BULK, 191}; 192 193static const struct usb_temp_endpoint_desc bulk_out_ep = { 194 .pPacketSize = &bulk_mps, 195#ifdef USB_HIP_OUT_EP_0 196 .bEndpointAddress = USB_HIP_OUT_EP_0, 197#else 198 .bEndpointAddress = UE_DIR_OUT, 199#endif 200 .bmAttributes = UE_BULK, 201}; 202 203static const struct usb_temp_endpoint_desc intr_in_ep = { 204 .pPacketSize = &intr_mps, 205 .bEndpointAddress = UE_DIR_IN, 206 .bmAttributes = UE_INTERRUPT, 207}; 208 209static const struct usb_temp_endpoint_desc *eth_intr_endpoints[] = { 210 &intr_in_ep, 211 NULL, 212}; 213 214static const struct usb_temp_interface_desc eth_control_interface = { 215 .ppEndpoints = eth_intr_endpoints, 216 .ppRawDesc = eth_control_if_desc, 217 .bInterfaceClass = UICLASS_CDC, 218 .bInterfaceSubClass = UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL, 219 .bInterfaceProtocol = 0, 220 .iInterface = STRING_ETH_CONTROL_INDEX, 221}; 222 223static const struct usb_temp_endpoint_desc *eth_data_endpoints[] = { 224 &bulk_in_ep, 225 &bulk_out_ep, 226 NULL, 227}; 228 229static const struct usb_temp_interface_desc eth_data_null_interface = { 230 .ppEndpoints = NULL, /* no endpoints */ 231 .bInterfaceClass = UICLASS_CDC_DATA, 232 .bInterfaceSubClass = 0, 233 .bInterfaceProtocol = 0, 234 .iInterface = STRING_ETH_DATA_INDEX, 235}; 236 237static const struct usb_temp_interface_desc eth_data_interface = { 238 .ppEndpoints = eth_data_endpoints, 239 .bInterfaceClass = UICLASS_CDC_DATA, 240 .bInterfaceSubClass = UISUBCLASS_DATA, 241 .bInterfaceProtocol = 0, 242 .iInterface = STRING_ETH_DATA_INDEX, 243 .isAltInterface = 1, /* this is an alternate setting */ 244}; 245 246static const struct usb_temp_interface_desc *eth_interfaces[] = { 247 ð_control_interface, 248 ð_data_null_interface, 249 ð_data_interface, 250 NULL, 251}; 252 253static const struct usb_temp_config_desc eth_config_desc = { 254 .ppIfaceDesc = eth_interfaces, 255 .bmAttributes = UC_BUS_POWERED, 256 .bMaxPower = 25, /* 50 mA */ 257 .iConfiguration = STRING_ETH_CONFIG_INDEX, 258}; 259 260static const struct usb_temp_config_desc *eth_configs[] = { 261 ð_config_desc, 262 NULL, 263}; 264 265const struct usb_temp_device_desc usb_template_cdce = { 266 .getStringDesc = ð_get_string_desc, 267 .ppConfigDesc = eth_configs, 268 .idVendor = 0x0001, 269 .idProduct = 0x0001, 270 .bcdDevice = 0x0100, 271 .bDeviceClass = UDCLASS_COMM, 272 .bDeviceSubClass = 0, 273 .bDeviceProtocol = 0, 274 .iManufacturer = STRING_ETH_VENDOR_INDEX, 275 .iProduct = STRING_ETH_PRODUCT_INDEX, 276 .iSerialNumber = STRING_ETH_SERIAL_INDEX, 277}; 278 279/*------------------------------------------------------------------------* 280 * eth_get_string_desc 281 * 282 * Return values: 283 * NULL: Failure. No such string. 284 * Else: Success. Pointer to string descriptor is returned. 285 *------------------------------------------------------------------------*/ 286static const void * 287eth_get_string_desc(uint16_t lang_id, uint8_t string_index) 288{ 289 static const void *ptr[STRING_ETH_MAX] = { 290 [STRING_LANG_INDEX] = &string_lang, 291 [STRING_MAC_INDEX] = &string_mac, 292 [STRING_ETH_CONTROL_INDEX] = &string_eth_control, 293 [STRING_ETH_DATA_INDEX] = &string_eth_data, 294 [STRING_ETH_CONFIG_INDEX] = &string_eth_config, 295 [STRING_ETH_VENDOR_INDEX] = &string_eth_vendor, 296 [STRING_ETH_PRODUCT_INDEX] = &string_eth_product, 297 [STRING_ETH_SERIAL_INDEX] = &string_eth_serial, 298 }; 299 300 if (string_index == 0) { 301 return (&string_lang); 302 } 303 if (lang_id != 0x0409) { 304 return (NULL); 305 } 306 if (string_index < STRING_ETH_MAX) { 307 return (ptr[string_index]); 308 } 309 return (NULL); 310}
|