- uchar recipient = data[0] & 0x1f; /* assign arith ops to variables to enforce byte size */
- if(recipient == USBRQ_RCPT_DEVICE)
- replyData[0] = USB_CFG_IS_SELF_POWERED;
-#endif
- replyData[1] = 0;
- replyLen = 2;
- }else if(data[1] == 5){ /* SET_ADDRESS */
- usbNewDeviceId = data[2];
- }else if(data[1] == 6){ /* GET_DESCRIPTOR */
- flags = USB_FLG_MSGPTR_IS_ROM | USB_FLG_USE_DEFAULT_RW;
- if(data[3] == 1){ /* descriptor type requested */
- replyLen = sizeof(usbDescrDevice);
- replyData = (uchar *)usbDescrDevice;
- }else if(data[3] == 2){
- replyLen = sizeof(usbDescrConfig);
- replyData = (uchar *)usbDescrConfig;
- }else if(data[3] == 3){ /* string descriptor */
- if(data[2] == 0){ /* descriptor index */
- replyLen = sizeof(usbDescrString0);
- replyData = (uchar *)usbDescrString0;
-#if USB_CFG_VENDOR_NAME_LEN
- }else if(data[2] == 1){
- replyLen = sizeof(usbDescrString1);
- replyData = (uchar *)usbDescrString1;
-#endif
-#if USB_CFG_DEVICE_NAME_LEN
- }else if(data[2] == 2){
- replyLen = sizeof(usbDescrString2);
- replyData = (uchar *)usbDescrString2;
-#endif
- }
- }
- }else if(data[1] == 8){ /* GET_CONFIGURATION */
- replyLen = 1;
- replyData[0] = 1; /* config is always 1, no setConfig required */
- }else if(data[1] == 10){ /* GET_INTERFACE */
- replyLen = 1;
+ if(recipient == USBRQ_RCPT_DEVICE)
+ replyData[0] = USB_CFG_IS_SELF_POWERED;
+#endif
+#if USB_CFG_HAVE_INTRIN_ENDPOINT && USB_CFG_IMPLEMENT_HALT
+ if(recipient == USBRQ_RCPT_ENDPOINT && rq->wIndex.bytes[0] == 0x81) /* request status for endpoint 1 */
+ replyData[0] = usbTxLen1 == USBPID_STALL;
+#endif
+ replyData[1] = 0;
+ SET_REPLY_LEN(2);
+ }else if(rq->bRequest == USBRQ_SET_ADDRESS){ /* 5 */
+ usbNewDeviceAddr = rq->wValue.bytes[0];
+ }else if(rq->bRequest == USBRQ_GET_DESCRIPTOR){ /* 6 */
+ flags = USB_FLG_MSGPTR_IS_ROM | USB_FLG_USE_DEFAULT_RW;
+ if(rq->wValue.bytes[1] == USBDESCR_DEVICE){ /* 1 */
+ GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_DEVICE, usbDescriptorDevice)
+ }else if(rq->wValue.bytes[1] == USBDESCR_CONFIG){ /* 2 */
+ GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_CONFIGURATION, usbDescriptorConfiguration)
+ }else if(rq->wValue.bytes[1] == USBDESCR_STRING){ /* 3 */
+#if USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC
+ if(USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_RAM)
+ flags &= ~USB_FLG_MSGPTR_IS_ROM;
+ replyLen = usbFunctionDescriptor(rq);
+#else /* USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC */
+ if(rq->wValue.bytes[0] == 0){ /* descriptor index */
+ GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_0, usbDescriptorString0)
+ }else if(rq->wValue.bytes[0] == 1){
+ GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_VENDOR, usbDescriptorStringVendor)
+ }else if(rq->wValue.bytes[0] == 2){
+ GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_DEVICE, usbDescriptorStringDevice)
+ }else if(rq->wValue.bytes[0] == 3){
+ GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER, usbDescriptorStringSerialNumber)
+ }else if(USB_CFG_DESCR_PROPS_UNKNOWN & USB_PROP_IS_DYNAMIC){
+ replyLen = usbFunctionDescriptor(rq);
+ }
+#endif /* USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC */
+ }else if(rq->wValue.bytes[1] == USBDESCR_HID){ /* 0x21 */
+ GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_HID, usbDescriptorConfiguration + 18)
+ }else if(rq->wValue.bytes[1] == USBDESCR_HID_REPORT){ /* 0x22 */
+ GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_HID_REPORT, usbDescriptorHidReport)
+ }else if(USB_CFG_DESCR_PROPS_UNKNOWN & USB_PROP_IS_DYNAMIC){
+ replyLen = usbFunctionDescriptor(rq);
+ }
+ }else if(rq->bRequest == USBRQ_GET_CONFIGURATION){ /* 8 */
+ replyData = &usbConfiguration; /* send current configuration value */
+ SET_REPLY_LEN(1);
+ }else if(rq->bRequest == USBRQ_SET_CONFIGURATION){ /* 9 */
+ usbConfiguration = rq->wValue.bytes[0];
+#if USB_CFG_IMPLEMENT_HALT
+ usbTxLen1 = USBPID_NAK;
+#endif
+ }else if(rq->bRequest == USBRQ_GET_INTERFACE){ /* 10 */
+ SET_REPLY_LEN(1);