00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #include "config.h"
00054
00055 #include "usb_drv.h"
00056 #include "usb_descriptors.h"
00057 #include "usb_specific_request.h"
00058 #include "rndis/rndis_task.h"
00059
00060
00061
00062
00063
00064 #define USB_ETH_NET_FUNC_DESC(MACAddrString,etherStat,maxSegmentSize,nMCFilters,nPowerFilters) \
00065 { sizeof(S_usb_ethernet_networking_functional_descriptor) \
00066 , 0x24, 0x0F \
00067 , MACAddrString \
00068 , etherStat \
00069 , Usb_write_word_enum_struc(maxSegmentSize) \
00070 , Usb_write_word_enum_struc(nMCFilters) \
00071 , nPowerFilters \
00072 }
00073
00074
00075
00076 #define USB_CONFIG_DESC(totalsize,interfaceCount,value,stringIndex,attr,power) \
00077 { sizeof(S_usb_configuration_descriptor) \
00078 , CONFIGURATION_DESCRIPTOR \
00079 , Usb_write_word_enum_struc(totalsize) \
00080 , interfaceCount \
00081 , value \
00082 , stringIndex \
00083 , attr \
00084 , power \
00085 }
00086
00087 #define USB_ENDPOINT(nb,attr,maxpktsize,interval) \
00088 { sizeof(S_usb_endpoint_descriptor) \
00089 , ENDPOINT_DESCRIPTOR \
00090 , nb \
00091 , attr \
00092 , Usb_write_word_enum_struc(maxpktsize) \
00093 , interval \
00094 }
00095
00096 #define USB_IAD(firstinterface,interfacecount,funcClass,funcSubClass,funcProto,stringIndex) \
00097 { \
00098 sizeof(S_usb_interface_association_descriptor), \
00099 DSC_TYPE_IAD, \
00100 firstinterface, \
00101 interfacecount, \
00102 funcClass, \
00103 funcSubClass, \
00104 funcProto, \
00105 stringIndex \
00106 }
00107
00108 #define USB_INTERFACEDESC(nb,altsetting,endpointCount,interfaceClass,interfaceSubClass,interfaceProto,stringIndex) \
00109 { sizeof(S_usb_interface_descriptor) \
00110 , INTERFACE_DESCRIPTOR \
00111 , nb \
00112 , altsetting \
00113 , endpointCount \
00114 , interfaceClass \
00115 , interfaceSubClass \
00116 , interfaceProto \
00117 , stringIndex \
00118 }
00119
00120
00121 #define FUNC_DESC_HEADER \
00122 0x05, \
00123 0x24, \
00124 0x00, \
00125 0x10,0x01
00126
00127 #define FUNC_DESC_CALL_MANAGEMENT(caps,dataInterface) \
00128 0x05, \
00129 0x24, \
00130 0x01, \
00131 caps, \
00132 dataInterface
00133
00134
00135 #define FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT(caps) \
00136 0x04, \
00137 0x24, \
00138 0x02, \
00139 caps
00140
00141 \
00142 #define FUNC_DESC_UNION(masterInterface,slaveInterface) \
00143 0x05, \
00144 0x24, \
00145 0x06, \
00146 masterInterface, \
00147 slaveInterface \
00148
00149 #define RNDIS_INTERFACES \
00150 USB_INTERFACEDESC( \
00151 INTERFACE0_NB, \
00152 ALTERNATE0, \
00153 NB_ENDPOINT0, \
00154 INTERFACE0_CLASS, \
00155 INTERFACE0_SUB_CLASS, \
00156 INTERFACE0_PROTOCOL, \
00157 USB_STRING_INTERFACE_RNDIS \
00158 ), \
00159 { \
00160 FUNC_DESC_HEADER, \
00161 FUNC_DESC_CALL_MANAGEMENT(0x00,0x00), \
00162 FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT(0x00), \
00163 FUNC_DESC_UNION(0x00,0x01), \
00164 }, \
00165 USB_ENDPOINT(ENDPOINT_NB_1,EP_ATTRIBUTES_1,EP_SIZE_1,EP_INTERVAL_1), \
00166 \
00167 USB_INTERFACEDESC( \
00168 INTERFACE1_NB, \
00169 ALTERNATE1, \
00170 NB_ENDPOINT1, \
00171 INTERFACE1_CLASS, \
00172 INTERFACE1_SUB_CLASS, \
00173 INTERFACE1_PROTOCOL, \
00174 USB_STRING_NONE \
00175 ), \
00176 USB_ENDPOINT(ENDPOINT_NB_2,EP_ATTRIBUTES_2,EP_SIZE_2,EP_INTERVAL_2), \
00177 USB_ENDPOINT(ENDPOINT_NB_3,EP_ATTRIBUTES_3,EP_SIZE_3,EP_INTERVAL_3)
00178
00179 #define CDC_SERIAL_INTERFACES \
00180 USB_INTERFACEDESC( \
00181 INTERFACE2_NB, \
00182 ALTERNATE2, \
00183 NB_ENDPOINT2, \
00184 INTERFACE2_CLASS, \
00185 INTERFACE2_SUB_CLASS, \
00186 INTERFACE2_PROTOCOL, \
00187 USB_STRING_INTERFACE_SERIAL \
00188 ), \
00189 { \
00190 FUNC_DESC_HEADER, \
00191 FUNC_DESC_CALL_MANAGEMENT(0x03,0x03), \
00192 FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT(0x02), \
00193 FUNC_DESC_UNION(0x02,0x03), \
00194 }, \
00195 USB_ENDPOINT(ENDPOINT_NB_4,EP_ATTRIBUTES_4,EP_SIZE_4,EP_INTERVAL_4), \
00196 USB_INTERFACEDESC( \
00197 INTERFACE3_NB, \
00198 ALTERNATE3, \
00199 NB_ENDPOINT3, \
00200 INTERFACE3_CLASS, \
00201 INTERFACE3_SUB_CLASS, \
00202 INTERFACE3_PROTOCOL, \
00203 USB_STRING_NONE \
00204 ), \
00205 USB_ENDPOINT(ENDPOINT_NB_5,EP_ATTRIBUTES_5,EP_SIZE_5,EP_INTERVAL_5), \
00206 USB_ENDPOINT(ENDPOINT_NB_6,EP_ATTRIBUTES_6,EP_SIZE_6,EP_INTERVAL_6)
00207
00208 #define CDC_EEM_INTERFACES \
00209 USB_INTERFACEDESC( \
00210 EEM_INTERFACE0_NB, \
00211 EEM_ALTERNATE0, \
00212 EEM_NB_ENDPOINT0, \
00213 EEM_INTERFACE0_CLASS, \
00214 EEM_INTERFACE0_SUB_CLASS, \
00215 EEM_INTERFACE0_PROTOCOL, \
00216 USB_STRING_INTERFACE_EEM \
00217 ), \
00218 USB_ENDPOINT(ENDPOINT_NB_1,EP_ATTRIBUTES_1,EP_SIZE_1,EP_INTERVAL_1), \
00219 USB_ENDPOINT(ENDPOINT_NB_2,EP_ATTRIBUTES_2,EP_SIZE_2,EP_INTERVAL_2)
00220
00221
00222
00223
00224 #if CDC_ECM_USES_INTERRUPT_ENDPOINT
00225 #define CDC_ECM_CONTROL_ENDPOINT_COUNT 1
00226 #define CDC_ECM_CONTROL_ENDPOINT USB_ENDPOINT(ENDPOINT_NB_1,EP_ATTRIBUTES_1,EP_SIZE_1,EP_INTERVAL_1),
00227 #else
00228 #define CDC_ECM_CONTROL_ENDPOINT_COUNT 0
00229 #define CDC_ECM_CONTROL_ENDPOINT
00230 #endif
00231
00232
00233 #define CDC_ECM_INTERFACES \
00234 USB_INTERFACEDESC( \
00235 ECM_INTERFACE0_NB, \
00236 ECM_ALTERNATE0, \
00237 CDC_ECM_CONTROL_ENDPOINT_COUNT, \
00238 ECM_INTERFACE0_CLASS, \
00239 ECM_INTERFACE0_SUB_CLASS, \
00240 ECM_INTERFACE0_PROTOCOL, \
00241 USB_STRING_INTERFACE_ECM \
00242 ), \
00243 { \
00244 FUNC_DESC_HEADER, \
00245 FUNC_DESC_UNION(0x00,0x01), \
00246 }, \
00247 USB_ETH_NET_FUNC_DESC( \
00248 USB_STRING_MAC_ADDRESS, \
00249 0, \
00250 USB_ETH_MTU, \
00251 0, \
00252 0 \
00253 ), \
00254 CDC_ECM_CONTROL_ENDPOINT \
00255 USB_INTERFACEDESC( \
00256 ECM_INTERFACE0_NB+1, \
00257 0, \
00258 2, \
00259 10, \
00260 0, \
00261 0, \
00262 USB_STRING_NONE \
00263 ), \
00264 USB_ENDPOINT(ENDPOINT_NB_2,EP_ATTRIBUTES_2,EP_SIZE_2,EP_INTERVAL_2), \
00265 USB_ENDPOINT(ENDPOINT_NB_3,EP_ATTRIBUTES_3,EP_SIZE_3,EP_INTERVAL_3)
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290 #if USB_CONF_MACINTOSH
00291
00292 FLASH uint8_t usb_dev_config_order[] = {
00293 USB_CONFIG_RNDIS,
00294 #if USB_CONF_SERIAL
00295 USB_CONFIG_ECM_DEBUG,
00296 #endif
00297 USB_CONFIG_ECM,
00298 #if USB_CONF_SERIAL
00299 USB_CONFIG_RNDIS_DEBUG,
00300 #endif
00301
00302 USB_CONFIG_EEM,
00303 #if USB_CONF_STORAGE
00304 USB_CONFIG_MS,
00305 #endif
00306 };
00307 #else
00308
00309 FLASH uint8_t usb_dev_config_order[] = {
00310
00311
00312 #if USB_CONF_SERIAL
00313 USB_CONFIG_RNDIS_DEBUG,
00314 #else
00315 USB_CONFIG_RNDIS,
00316 #endif
00317 #if 0 //XP may have a problem with these extra configurations
00318 USB_CONFIG_RNDIS,
00319 #if USB_CONF_SERIAL
00320 USB_CONFIG_ECM_DEBUG,
00321 #endif
00322 USB_CONFIG_ECM,
00323 USB_CONFIG_EEM,
00324 #if USB_CONF_STORAGE
00325 USB_CONFIG_MS,
00326 #endif
00327 #endif
00328 };
00329 #endif
00330
00331
00332 FLASH S_usb_device_descriptor usb_dev_desc_composite =
00333 {
00334 sizeof(usb_dev_desc_composite)
00335 , DEVICE_DESCRIPTOR
00336 , Usb_write_word_enum_struc(USB_SPECIFICATION)
00337 , COMPOSITE_DEVICE_CLASS
00338 , COMPOSITE_DEVICE_SUB_CLASS
00339 , COMPOSITE_DEVICE_PROTOCOL
00340 , EP_CONTROL_LENGTH
00341 , Usb_write_word_enum_struc(VENDOR_ID)
00342 , Usb_write_word_enum_struc(COMPOSITE_PRODUCT_ID)
00343 , Usb_write_word_enum_struc(RELEASE_NUMBER)
00344 , USB_STRING_MAN
00345 , USB_STRING_PRODUCT
00346 , USB_STRING_SERIAL
00347 , (sizeof(usb_dev_config_order)/sizeof(*usb_dev_config_order))
00348 };
00349
00350
00351
00352 FLASH S_usb_user_configuration_descriptor_composite usb_conf_desc_composite = {
00353 USB_CONFIG_DESC(
00354 sizeof(usb_conf_desc_composite),
00355 COMPOSITE_NB_INTERFACE,
00356 USB_CONFIG_RNDIS_DEBUG,
00357 USB_STRING_CONFIG_COMPOSITE,
00358 CONF_ATTRIBUTES,
00359 MAX_POWER
00360 ),
00361
00362 USB_IAD(
00363 0x00,
00364 0x02,
00365 0x02,
00366 0x02,
00367 0xFF,
00368 USB_STRING_INTERFACE_RNDIS
00369 ),RNDIS_INTERFACES,
00370
00371 USB_IAD(
00372 0x02,
00373 0x02,
00374 0x02,
00375 0x02,
00376 0x01,
00377 USB_STRING_INTERFACE_SERIAL
00378 ),CDC_SERIAL_INTERFACES
00379 };
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404 FLASH S_usb_user_configuration_descriptor_network usb_conf_desc_network = {
00405 USB_CONFIG_DESC(
00406 sizeof(usb_conf_desc_network),
00407 NETWORK_NB_INTERFACE,
00408 CONF_NB,
00409 USB_STRING_CONFIG_RNDIS,
00410 CONF_ATTRIBUTES,
00411 MAX_POWER
00412 ),
00413 RNDIS_INTERFACES
00414 };
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443 FLASH S_usb_user_configuration_descriptor_eem usb_conf_desc_eem = {
00444 USB_CONFIG_DESC(
00445 sizeof(usb_conf_desc_eem),
00446 EEM_NB_INTERFACE,
00447 USB_CONFIG_EEM,
00448 USB_STRING_CONFIG_EEM,
00449 CONF_ATTRIBUTES,
00450 MAX_POWER
00451 ),
00452 CDC_EEM_INTERFACES
00453 };
00454
00455
00456 FLASH S_usb_user_configuration_descriptor_ecm usb_conf_desc_ecm = {
00457 USB_CONFIG_DESC(
00458 sizeof(usb_conf_desc_ecm),
00459 2,
00460 USB_CONFIG_ECM,
00461 USB_STRING_CONFIG_ECM,
00462 CONF_ATTRIBUTES,
00463 MAX_POWER
00464 ),
00465 CDC_ECM_INTERFACES
00466 };
00467
00468 FLASH S_usb_user_configuration_descriptor_ecm_debug usb_conf_desc_ecm_debug = {
00469 USB_CONFIG_DESC(
00470 sizeof(usb_conf_desc_ecm_debug),
00471 4,
00472 USB_CONFIG_ECM_DEBUG,
00473 USB_STRING_CONFIG_ECM_DEBUG,
00474 CONF_ATTRIBUTES,
00475 MAX_POWER
00476 ),
00477
00478 USB_IAD(
00479 0x00,
00480 0x02,
00481 0x02,
00482 0x06,
00483 0x00,
00484 USB_STRING_INTERFACE_ECM
00485 ),CDC_ECM_INTERFACES,
00486
00487 USB_IAD(
00488 0x02,
00489 0x02,
00490 0x02,
00491 0x02,
00492 0x01,
00493 USB_STRING_INTERFACE_SERIAL
00494 ),CDC_SERIAL_INTERFACES
00495
00496
00497
00498 };
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523 #if USB_CONF_STORAGE
00524
00525
00526 FLASH S_usb_user_configuration_descriptor_mass usb_conf_desc_mass = {
00527 { sizeof(S_usb_configuration_descriptor)
00528 , CONFIGURATION_DESCRIPTOR
00529 , Usb_write_word_enum_struc(sizeof(S_usb_user_configuration_descriptor_mass))
00530 , MASS_NB_INTERFACE
00531 , CONF_NB
00532 , USB_STRING_CONFIG_MS
00533 , CONF_ATTRIBUTES
00534 , MAX_POWER
00535 },
00536
00537
00538 { sizeof(S_usb_interface_descriptor)
00539 , INTERFACE_DESCRIPTOR
00540 , MS_INTERFACE_NB
00541 , MS_ALTERNATE
00542 , MS_NB_ENDPOINT
00543 , MS_INTERFACE_CLASS
00544 , MS_INTERFACE_SUB_CLASS
00545 , MS_INTERFACE_PROTOCOL
00546 , USB_STRING_INTERFACE_MS
00547 }
00548 ,
00549 { sizeof(S_usb_endpoint_descriptor)
00550 , ENDPOINT_DESCRIPTOR
00551 , MS_ENDPOINT_NB_1
00552 , MS_EP_ATTRIBUTES_1
00553 , Usb_write_word_enum_struc(MS_EP_SIZE_1)
00554 , MS_EP_INTERVAL_1
00555 }
00556 ,
00557 { sizeof(S_usb_endpoint_descriptor)
00558 , ENDPOINT_DESCRIPTOR
00559 , MS_ENDPOINT_NB_2
00560 , MS_EP_ATTRIBUTES_2
00561 , Usb_write_word_enum_struc(MS_EP_SIZE_2)
00562 , MS_EP_INTERVAL_2
00563 }
00564 };
00565
00566 #endif
00567
00568
00569
00570
00571
00572
00573
00574 FLASH S_usb_language_id usb_user_language_id = {
00575 sizeof(usb_user_language_id)
00576 , STRING_DESCRIPTOR
00577 , Usb_write_word_enum_struc(LANGUAGE_ID)
00578 };
00579
00580
00581
00582
00583
00584 PGM_VOID_P Usb_get_dev_desc_pointer(void)
00585 {
00586 #if 1
00587 return &(usb_dev_desc_composite.bLength);
00588 #else //these are all the same length
00589 if (usb_mode == rndis_only)
00590 return &(usb_dev_desc_network.bLength);
00591
00592 if (usb_mode == rndis_debug)
00593 return &(usb_dev_desc_composite.bLength);
00594
00595 if (usb_mode == eem)
00596 return &(usb_dev_desc_eem.bLength);
00597
00598 return &(usb_dev_desc_mass.bLength);
00599 #endif
00600 }
00601
00602
00603 U8 Usb_get_dev_desc_length(void)
00604 {
00605 #if 1
00606 return sizeof(usb_dev_desc_composite);
00607 #else //these are all the same size
00608 if (usb_mode == rndis_only)
00609 return sizeof(usb_dev_desc_network);
00610
00611 if (usb_mode == rndis_debug)
00612 return sizeof(usb_dev_desc_composite);
00613
00614 if (usb_mode == eem)
00615 return sizeof(usb_dev_desc_eem);
00616
00617 return sizeof(usb_dev_desc_mass);
00618 #endif
00619 }
00620
00621
00622 PGM_VOID_P Usb_get_conf_desc_pointer(U8 index)
00623 {
00624
00625 switch(pgm_read_byte_near(&usb_dev_config_order[index])) {
00626 case USB_CONFIG_ECM:
00627 return &(usb_conf_desc_ecm.cfg.bLength);
00628 case USB_CONFIG_ECM_DEBUG:
00629 return &(usb_conf_desc_ecm_debug.cfg.bLength);
00630 case USB_CONFIG_RNDIS_DEBUG:
00631 return &(usb_conf_desc_composite.cfg.bLength);
00632 case USB_CONFIG_RNDIS:
00633 return &(usb_conf_desc_network.cfg.bLength);
00634 case USB_CONFIG_EEM:
00635 return &(usb_conf_desc_eem.cfg.bLength);
00636 #if USB_CONF_STORAGE
00637 case USB_CONFIG_MS:
00638 return &(usb_conf_desc_mass.cfg.bLength);
00639 #endif
00640 default:
00641 return 0;
00642 }
00643 }
00644
00645
00646 U8 Usb_get_conf_desc_length(U8 index)
00647 {
00648 switch(pgm_read_byte_near(&usb_dev_config_order[index])) {
00649 case USB_CONFIG_ECM:
00650 return sizeof(usb_conf_desc_ecm);
00651 case USB_CONFIG_ECM_DEBUG:
00652 return sizeof(usb_conf_desc_ecm_debug);
00653 case USB_CONFIG_RNDIS_DEBUG:
00654 return sizeof(usb_conf_desc_composite);
00655 case USB_CONFIG_RNDIS:
00656 return sizeof (usb_conf_desc_network);
00657 case USB_CONFIG_EEM:
00658 return sizeof(usb_conf_desc_eem);
00659 #if USB_CONF_STORAGE
00660 case USB_CONFIG_MS:
00661 return sizeof(usb_conf_desc_mass);
00662 #endif
00663 default:
00664 return 0;
00665 }
00666 }
00667
00668