//! This function reads the SETUP request sent to the default control endpoint //! and calls the appropriate function. When exiting of the usb_read_request //! function, the device is ready to manage the next request. //! //! If the received request is not supported or a non-standard USB request, the function //! will call the custom decoding function in usb_specific_request module. //! //! @note List of supported requests: //! GET_DESCRIPTOR //! GET_CONFIGURATION //! SET_ADDRESS //! SET_CONFIGURATION //! CLEAR_FEATURE //! SET_FEATURE //! GET_STATUS //! void usb_process_request(void) { U8 bRequest; Usb_reset_endpoint_fifo_access(EP_CONTROL); bmRequestType = Usb_read_endpoint_data(EP_CONTROL, 8); bRequest = Usb_read_endpoint_data(EP_CONTROL, 8); switch (bRequest) { case GET_DESCRIPTOR: if (bmRequestType == 0x80) usb_get_descriptor(); else goto unsupported_request; break; case GET_CONFIGURATION: if (bmRequestType == 0x80) usb_get_configuration(); else goto unsupported_request; break; case SET_ADDRESS: if (bmRequestType == 0x00) usb_set_address(); else goto unsupported_request; break; case SET_CONFIGURATION: if (bmRequestType == 0x00) usb_set_configuration(); else goto unsupported_request; break; case CLEAR_FEATURE: if (bmRequestType <= 0x02) usb_clear_feature(); else goto unsupported_request; break; case SET_FEATURE: if (bmRequestType <= 0x02) usb_set_feature(); else goto unsupported_request; break; case GET_STATUS: if (0x7F < bmRequestType && bmRequestType <= 0x82) usb_get_status(); else goto unsupported_request; break; case GET_INTERFACE: if (bmRequestType == 0x81) { if(!usb_get_interface()) { Usb_enable_stall_handshake(EP_CONTROL); Usb_ack_setup_received_free(); } } else goto unsupported_request; break; case SET_INTERFACE: if (bmRequestType == 0x01) usb_set_interface(); else goto unsupported_request; break; case SET_DESCRIPTOR: case SYNCH_FRAME: default: //!< unsupported request => call to user read request unsupported_request: if (!usb_user_read_request(bmRequestType, bRequest)) { Usb_enable_stall_handshake(EP_CONTROL); Usb_ack_setup_received_free(); } break; } }
//! usb_process_request. //! //! @brief This function reads the SETUP request sent to the default control endpoint //! and calls the appropriate function. When exiting of the usb_read_request //! function, the device is ready to manage the next request. //! //! @param none //! //! @return none //! @note list of supported requests: //! GET_DESCRIPTOR //! GET_CONFIGURATION //! SET_ADDRESS //! SET_CONFIGURATION //! CLEAR_FEATURE //! SET_FEATURE //! GET_STATUS //! void usb_process_request(void) { U8 bmRequest; bmRequestType = Usb_read_byte(); bmRequest = Usb_read_byte(); switch (bmRequest) { case GET_DESCRIPTOR: if (0x80 == bmRequestType) { usb_get_descriptor(); } else { usb_user_read_request(bmRequestType, bmRequest); } break; case GET_CONFIGURATION: if (0x80 == bmRequestType) { usb_get_configuration(); } else { usb_user_read_request(bmRequestType, bmRequest); } break; case SET_ADDRESS: if (0x00 == bmRequestType) { usb_set_address(); } else { usb_user_read_request(bmRequestType, bmRequest); } break; case SET_CONFIGURATION: if (0x00 == bmRequestType) { usb_set_configuration(); } else { usb_user_read_request(bmRequestType, bmRequest); } break; case CLEAR_FEATURE: if (0x02 >= bmRequestType) { usb_clear_feature(); } else { usb_user_read_request(bmRequestType, bmRequest); } break; case SET_FEATURE: if (0x02 >= bmRequestType) { usb_set_feature(); } else { usb_user_read_request(bmRequestType, bmRequest); } break; case GET_STATUS: if ((0x7F < bmRequestType) & (0x82 >= bmRequestType)) { usb_get_status(); } else { usb_user_read_request(bmRequestType, bmRequest); } break; case GET_INTERFACE: if (bmRequestType == 0x81) { usb_get_interface(); } else { usb_user_read_request(bmRequestType, bmRequest); } break; case SET_INTERFACE: if (bmRequestType == 0x01) {usb_set_interface();} break; case SET_DESCRIPTOR: case SYNCH_FRAME: default: //!< un-supported request => call to user read request if(usb_user_read_request(bmRequestType, bmRequest) == FALSE) { Usb_enable_stall_handshake(); Usb_ack_receive_setup(); return; } break; } }
//! usb_process_request. //! //! @brief This function reads the SETUP request sent to the default control endpoint //! and calls the appropriate function. When exiting of the usb_read_request //! function, the device is ready to manage the next request. //! //! @note list of supported requests: //! GET_DESCRIPTOR //! GET_CONFIGURATION //! SET_ADDRESS //! SET_CONFIGURATION //! CLEAR_FEATURE //! SET_FEATURE //! GET_STATUS //! void usb_process_request(void) { U8 bmRequest; bmRequestType = Usb_read_byte(); bmRequest = Usb_read_byte(); switch (bmRequest) { case GET_DESCRIPTOR: if (0x80 == bmRequestType) { usb_get_descriptor(); } else goto user_read; break; case GET_CONFIGURATION: if (0x80 == bmRequestType) { usb_get_configuration(); } else goto user_read; break; case SET_ADDRESS: if (0x00 == bmRequestType) { usb_set_address(); } else goto user_read; break; case SET_CONFIGURATION: if (0x00 == bmRequestType) { usb_set_configuration(); } else goto user_read; break; case CLEAR_FEATURE: if (0x02 >= bmRequestType) { usb_clear_feature(); } else goto user_read; break; case SET_FEATURE: if (0x02 >= bmRequestType) { usb_set_feature(); } else goto user_read; break; case GET_STATUS: if ((0x7F < bmRequestType) & (0x82 >= bmRequestType)) { usb_get_status(); } else goto user_read; break; case GET_INTERFACE: if (bmRequestType == 0x81) { usb_get_interface(); } else goto user_read; break; case SET_INTERFACE: if (bmRequestType == 0x01) {usb_set_interface();} break; case SET_DESCRIPTOR: case SYNCH_FRAME: default: //!< un-supported request => call to user read request user_read: usb_user_read_request(bmRequestType, bmRequest); break; } Usb_select_endpoint(EP_CONTROL); // If the receive setup flag hasn't been cleared // by this point then we can assume that we didn't // support this request and should stall. if(Is_usb_receive_setup()) Usb_enable_stall_handshake(); // Clear some flags. Usb_ack_receive_setup(); Usb_ack_receive_out(); Usb_ack_in_ready(); }
/* * Read the SETUP request sent to the default control endpoint * and call the appropriate function. When exiting this * function, the device is ready to manage the next request. * * Supported requests: * GET_DESCRIPTOR * GET_CONFIGURATION * SET_ADDRESS * SET_CONFIGURATION * CLEAR_FEATURE * SET_FEATURE * GET_STATUS */ void OSUsbDeviceImpl::standardProcessRequest(void) { unsigned char bmRequest; bmRequestType = OSUsbDeviceImpl::readByte(); bmRequest = OSUsbDeviceImpl::readByte(); #if defined(DEBUG) && defined(OS_DEBUG_OSUSBDEVICE_REQUEST) OSDeviceDebug::putString("type/req="); OSDeviceDebug::putHex(bmRequestType); OSDeviceDebug::putString("/"); OSDeviceDebug::putHex(bmRequest); OSDeviceDebug::putString(" "); //OSDeviceDebug::putNewLine(); #endif switch (bmRequest) { case GET_DESCRIPTOR: if (0x80 == bmRequestType) { OSUsbDeviceImpl::usb_get_descriptor(); return; } break; case GET_CONFIGURATION: if (0x80 == bmRequestType) { usb_get_configuration(); return; } break; case SET_ADDRESS: if (0x00 == bmRequestType) { usb_set_address(); return; } break; case SET_CONFIGURATION: if (0x00 == bmRequestType) { usb_set_configuration(); return; } break; case CLEAR_FEATURE: if (0x02 >= bmRequestType) { usb_clear_feature(); return; } break; case SET_FEATURE: if (0x02 >= bmRequestType) { usb_set_feature(); return; } break; case GET_STATUS: if ((0x7F < bmRequestType) & (0x82 >= bmRequestType)) { usb_get_status(); return; } break; case GET_INTERFACE: if (bmRequestType == 0x81) { usb_get_interface(); return; } break; case SET_INTERFACE: if (bmRequestType == 0x01) { usb_set_interface(); return; } break; case SET_DESCRIPTOR: case SYNCH_FRAME: default: break; } // for un-supported requests call the specific read request if (OSUsbDeviceImpl::specificProcessReadRequest(bmRequestType, bmRequest)) return; // if nothing worked, reply with stall OSUsbDeviceImpl::Usb_enable_stall_handshake(); OSUsbDeviceImpl::Usb_ack_receive_setup(); }
RES_CODE usb_remote_hid_t::scan_hid(uint32_t port_indx, USBSubClassCode subcls, USBProtocolCode proto) { RES_CODE res; // select EPT_0 and device address ep0_hnd->mode.as_bytes[0] = EPT_0; // RX pipe ep0_hnd->mode.as_bytes[1] = EPT_0; // TX pipe res = hdc_init(port_indx); if(res == RES_OK) { epi_hnd->mode0 = ep0_hnd->mode0; // device hub port // TRACE Device descriptor TRACELN("HID: dev found %x:%x", dev_descriptor.idVendor, dev_descriptor.idProduct); trace_usb_descriptor(&dev_descriptor.as_generic); if(dev_descriptor.bDeviceClass == INTERFACE_DEFINED_CLASS) { //loop the configurations for(uint32_t cfg_indx=0; cfg_indx<dev_descriptor.bNumConfigurations; cfg_indx++) { res = get_config_descriptor(cfg_indx); if(res != RES_OK) break; // TRACE Configuration descriptor(s) trace_usb_descriptor(&config_descriptor->as_generic); //loop the interfaces for(uint32_t iface_indx=0; iface_indx<config_descriptor->bNumInterfaces; iface_indx++) { pid = usb_get_interface(config_descriptor, iface_indx); if(pid && pid->bDeviceClass == HID_DEVICE_CLASS && pid->bDeviceSubClass == subcls && pid->bDeviceProtocol == proto) { // set the configuration // set_configuration(0); res = set_configuration(config_descriptor->bConfigurationValue); if(res == RES_OK) { epi_hnd->mode.as_bytes[0] = EPT_0; epi_hnd->mode.as_bytes[1] = EPT_0; for(int i=0; i<pid->bNumEndpoints && i<2; i++) { USBEndpointDescriptor* ped; ped = usb_get_enpoint(config_descriptor, i); if(ped && ped->bmAttributes == ENDPOINT_TYPE_INTERRUPT) { if( ped->bEndpointAddress & 0x80 ) { if(epi_hnd->mode.as_bytes[0] == EPT_0) { epi_hnd->mode.as_bytes[0] = ped->bEndpointAddress & 0x7F; epi_hnd->mode.as_ushort[1] = ep0_hnd->mode.as_ushort[1]; //drv_state_cnt usb_svc_configendpoint(epi_hnd, &ped->as_generic); } } else { if(epi_hnd->mode.as_bytes[1] == EPT_0) { epi_hnd->mode.as_bytes[1] = ped->bEndpointAddress ; epi_hnd->mode.as_ushort[1] = ep0_hnd->mode.as_ushort[1]; //drv_state_cnt usb_svc_configendpoint(epi_hnd, &ped->as_generic); } } } } hid_idle = 255; get_idle(HID_REPORT_ALL); return RES_OK; } } } } } } if(res == RES_OK) res = RES_ERROR; return res; }
//! @brief This function reads the SETUP request sent to the default control endpoint //! and calls the appropriate function. When exiting of the usb_read_request //! function, the device is ready to manage the next request. //! void usb_process_request(void) { U8 bmRequestType; U8 bmRequest; Usb_ack_control_out(); bmRequestType = Usb_read_byte(); bmRequest = Usb_read_byte(); switch (bmRequest) { case SETUP_GET_DESCRIPTOR: if (USB_SETUP_GET_STAND_DEVICE == bmRequestType) { if( usb_get_descriptor() ) return; } break; case SETUP_GET_CONFIGURATION: if (USB_SETUP_GET_STAND_DEVICE == bmRequestType) { usb_get_configuration(); return; } break; case SETUP_SET_ADDRESS: if (USB_SETUP_SET_STAND_DEVICE == bmRequestType) { usb_set_address(); return; } break; case SETUP_SET_CONFIGURATION: if (USB_SETUP_SET_STAND_DEVICE == bmRequestType) { if( usb_set_configuration() ) return; } break; case SETUP_CLEAR_FEATURE: if (usb_clear_feature(bmRequestType)) return; break; case SETUP_SET_FEATURE: if (usb_set_feature(bmRequestType)) return; break; case SETUP_GET_STATUS: if (usb_get_status(bmRequestType)) return; break; case SETUP_GET_INTERFACE: if (USB_SETUP_GET_STAND_INTERFACE == bmRequestType) { if( usb_get_interface() ) return; } break; case SETUP_SET_INTERFACE: if (bmRequestType == USB_SETUP_SET_STAND_INTERFACE) { if( usb_set_interface() ) return; } break; default: break; } // un-supported like standard request => call to user read request if( !usb_user_read_request(bmRequestType, bmRequest) ) { // Request unknow in the specific request list from interface // keep that order (set StallRq/clear RxSetup) or a // OUT request following the SETUP may be acknowledged Usb_enable_stall_handshake(); Usb_ack_receive_setup(); endpoint_status[(EP_CONTROL & MSK_EP_DIR)] = 0x01; } }