//----------------------------------------------------------------------------- /// Handles composite-specific USB requests sent by the host, and forwards /// standard ones to the USB device driver. /// \param request Pointer to a USBGenericRequest instance. //----------------------------------------------------------------------------- void MULTIDriver_RequestHandler(const USBGenericRequest *request) { // Check if this is a class request if (USBGenericRequest_GetType(request) == USBGenericRequest_CLASS) { unsigned char rc = 0; //rc = CCID_RequestHandler(request); if (!rc) { TRACE_WARNING( "MULTIDriver_RequestHandler: Unsupported request (%d)\n\r", USBGenericRequest_GetRequest(request)); USBD_Stall(0); } } // Check if this is a standard request else if (USBGenericRequest_GetType(request) == USBGenericRequest_STANDARD) { unsigned char rc = 0; // Forward request to the standard handler if (rc == 0) USBDDriver_RequestHandler(&(usbdDriver), request); } // Unsupported request type else { TRACE_WARNING( "MULTIDriver_RequestHandler: Unsupported request type (%d)\n\r", USBGenericRequest_GetType(request)); USBD_Stall(0); } }
/** * Handles composite-specific USB requests sent by the host, and forwards * standard ones to the USB device driver. * \param request Pointer to a USBGenericRequest instance. */ void DUALCDCDDriver_RequestHandler(const USBGenericRequest *request) { CDCDSerialPort *pCdcd = 0; USBDDriver *pUsbd = 0; uint32_t rc, i; TRACE_INFO_WP("NewReq "); for (i = 0; i < NUM_PORTS; i ++) { pCdcd = &dualcdcdDriver.cdcdSerialPort[i]; rc = CDCDSerialPort_RequestHandler(pCdcd, request); if (rc == USBRC_SUCCESS) break; } /* Not handled by CDC Serial */ if (rc != USBRC_SUCCESS) { if (USBGenericRequest_GetType(request) == USBGenericRequest_STANDARD) { pUsbd = pCdcd->pUsbd; USBDDriver_RequestHandler(pUsbd, request); } else { TRACE_WARNING( "DUALCDCDDriver_RequestHandler: Unsupported request (%d,%d)\n\r", USBGenericRequest_GetType(request), USBGenericRequest_GetRequest(request)); USBD_Stall(0); } } }
/** * Handles audio-specific USB requests sent by the host, and forwards * standard ones to the USB device driver. * \param request Pointer to a USBGenericRequest instance. */ void AUDDSpeakerDriver_RequestHandler(const USBGenericRequest *request) { AUDDSpeakerDriver *pAudd = &auddSpeakerDriver; AUDDSpeakerPhone *pAudf = &pAudd->fun; USBDDriver *pUsbd = pAudf->pUsbd; TRACE_INFO_WP("NewReq "); /* Handle Audio Class requests */ if (AUDDSpeakerPhone_RequestHandler(pAudf, request) == USBRC_SUCCESS) { return; } /* Handle STD requests */ if (USBGenericRequest_GetType(request) == USBGenericRequest_STANDARD) { USBDDriver_RequestHandler(pUsbd, request); } /* Unsupported request */ else { TRACE_WARNING( "AUDDSpeakerDriver_RequestHandler: Unsupported request (%d,%x)\n\r", USBGenericRequest_GetType(request), USBGenericRequest_GetRequest(request)); USBD_Stall(0); } }
void fastsource_req_hdlr(const USBGenericRequest *request) { unsigned char entity; unsigned char interface; switch (USBGenericRequest_GetType(request)) { case USBGenericRequest_STANDARD: USBDDriver_RequestHandler(&fast_source_driver, request); return; case USBGenericRequest_CLASS: /* continue below */ break; default: TRACE_WARNING("Unsupported request type %u\n\r", USBGenericRequest_GetType(request)); USBD_Stall(0); return; } switch (USBGenericRequest_GetRequest(request)) { case AUDGenericRequest_SETCUR: entity = AUDGenericRequest_GetEntity(request); interface = AUDGenericRequest_GetInterface(request); if (((entity == AUDDLoopRecDriverDescriptors_FEATUREUNIT) || (entity == AUDDLoopRecDriverDescriptors_FEATUREUNIT_REC)) && (interface == AUDDLoopRecDriverDescriptors_CONTROL)) { fastsource_set_feat_cur_val(entity, AUDFeatureUnitRequest_GetChannel(request), AUDFeatureUnitRequest_GetControl(request), USBGenericRequest_GetLength(request)); } else { TRACE_WARNING("Unsupported entity/interface combination 0x%04x\n\r", USBGenericRequest_GetIndex(request)); USBD_Stall(0); } break; case AUDGenericRequest_GETCUR: entity = AUDGenericRequest_GetEntity(request); interface = AUDGenericRequest_GetInterface(request); if (((entity == AUDDLoopRecDriverDescriptors_FEATUREUNIT) || (entity == AUDDLoopRecDriverDescriptors_FEATUREUNIT_REC)) && (interface == AUDDLoopRecDriverDescriptors_CONTROL)) { fastsource_get_feat_cur_val(entity, AUDFeatureUnitRequest_GetChannel(request), AUDFeatureUnitRequest_GetControl(request), USBGenericRequest_GetLength(request)); } else { TRACE_WARNING("Unsupported entity/interface combination 0x%04x\n\r", USBGenericRequest_GetIndex(request)); USBD_Stall(0); } break; default: TRACE_WARNING("Unsupported request %u\n\r", USBGenericRequest_GetIndex(request)); USBD_Stall(0); break; } }
static void handle_osmosdr_read(const USBGenericRequest* request) { int len = USBGenericRequest_GetLength(request); printf("OsmoSDR GET request: type:%d, request:%d, value:%d, index: %d, length: %d\n\r", USBGenericRequest_GetType(request), USBGenericRequest_GetRequest(request), USBGenericRequest_GetValue(request), USBGenericRequest_GetIndex(request), len); USBD_Stall(0); }
uint32_t CDCDSerialPort_RequestHandler( CDCDSerialPort *pCdcd, const USBGenericRequest *request) { if (USBGenericRequest_GetType(request) != USBGenericRequest_CLASS) return USBRC_PARAM_ERR; TRACE_INFO_WP("Cdcs "); /* Validate interface */ if (request->wIndex >= pCdcd->bInterfaceNdx && request->wIndex < pCdcd->bInterfaceNdx + pCdcd->bNumInterface) { } else { return USBRC_PARAM_ERR; } /* Handle the request */ switch (USBGenericRequest_GetRequest(request)) { case CDCGenericRequest_SETLINECODING: _SetLineCoding(pCdcd); break; case CDCGenericRequest_GETLINECODING: _GetLineCoding(pCdcd); break; case CDCGenericRequest_SETCONTROLLINESTATE: _SetControlLineState(pCdcd, request); break; default: return USBRC_PARAM_ERR; } return USBRC_SUCCESS; }
/** * Handles audio-specific USB requests sent by the host * \param pAudf Pointer to AUDDSpeakerPhone instance. * \param pRequest Pointer to a USBGenericRequest instance. * \return USBRC_PARAM_ERR if not handled. */ uint32_t AUDDSpeakerPhone_RequestHandler( AUDDSpeakerPhone *pAudf, const USBGenericRequest* pRequest) { //USBDDriver *pUsbd = pAudf->pUsbd; if (USBGenericRequest_GetType(pRequest) != USBGenericRequest_CLASS) return USBRC_PARAM_ERR; TRACE_INFO_WP("Aud "); switch (USBGenericRequest_GetRequest(pRequest)) { case AUDGenericRequest_SETCUR: AUDD_SetCUR(pAudf, pRequest); break; case AUDGenericRequest_GETCUR: AUDD_GetCUR(pAudf, pRequest); break; default: return USBRC_PARAM_ERR; } return USBRC_SUCCESS; }
/** * Handler for incoming SETUP requests on default Control endpoint 0. * * Standard requests are forwarded to the USBDDriver_RequestHandler * method. * \param pMsdDriver Pointer to MSDDriver instance. * \param request Pointer to a USBGenericRequest instance */ uint32_t MSDFunction_RequestHandler( const USBGenericRequest *request) { MSDDriver *pMsdDriver = &msdFunction; uint32_t reqCode = (USBGenericRequest_GetType(request) << 8) | (USBGenericRequest_GetRequest(request)); TRACE_INFO_WP("Msdf "); /* Handle requests */ switch (reqCode) { /*--------------------- */ case USBGenericRequest_CLEARFEATURE: /*--------------------- */ TRACE_INFO_WP("ClrFeat "); switch (USBFeatureRequest_GetFeatureSelector(request)) { /*--------------------- */ case USBFeatureRequest_ENDPOINTHALT: /*--------------------- */ TRACE_INFO_WP("Hlt "); /* Do not clear the endpoint halt status if the device is waiting */ /* for a reset recovery sequence */ if (!pMsdDriver->waitResetRecovery) { /* Forward the request to the standard handler */ USBDDriver_RequestHandler(USBD_GetDriver(), request); } else { TRACE_INFO_WP("No "); } USBD_Write(0, 0, 0, 0, 0); return USBRC_SUCCESS; /* Handled */ } break; /*------------------- */ case (USBGenericRequest_CLASS<<8)|MSD_GET_MAX_LUN: /*------------------- */ TRACE_INFO_WP("gMaxLun "); /* Check request parameters */ if ((request->wValue == 0) && (request->wIndex == pMsdDriver->interfaceNb) && (request->wLength == 1)) { USBD_Write(0, &(pMsdDriver->maxLun), 1, 0, 0); } else { TRACE_WARNING( "MSDDriver_RequestHandler: GetMaxLUN(%d,%d,%d)\n\r", request->wValue, request->wIndex, request->wLength); USBD_Stall(0); } return USBRC_SUCCESS; /* Handled */ /*----------------------- */ case (USBGenericRequest_CLASS<<8)|MSD_BULK_ONLY_RESET: /*----------------------- */ TRACE_INFO_WP("Rst "); /* Check parameters */ if ((request->wValue == 0) && (request->wIndex == pMsdDriver->interfaceNb) && (request->wLength == 0)) { /* Reset the MSD driver */ MSDFunction_Reset(); USBD_Write(0, 0, 0, 0, 0); } else { TRACE_WARNING( "MSDDriver_RequestHandler: Reset(%d,%d,%d)\n\r", request->wValue, request->wIndex, request->wLength); USBD_Stall(0); } return USBRC_SUCCESS; /* Handled */ } return USBRC_PARAM_ERR; }
//------------------------------------------------------------------------------ /// Handles the given request if it is standard, otherwise STALLs it. /// \param pDriver Pointer to a USBDDriver instance. /// \param pRequest Pointer to a USBGenericRequest instance. //------------------------------------------------------------------------------ void USBDDriver_RequestHandler( USBDDriver *pDriver, const USBGenericRequest *pRequest) { unsigned char cfgnum; unsigned char infnum; unsigned char eptnum; unsigned char setting; unsigned char type; unsigned char indexDesc; unsigned int length; unsigned int address; TRACE_INFO_WP("Std "); // Check request code switch (USBGenericRequest_GetRequest(pRequest)) { case USBGenericRequest_GETDESCRIPTOR: TRACE_INFO_WP("gDesc "); // Send the requested descriptor type = USBGetDescriptorRequest_GetDescriptorType(pRequest); indexDesc = USBGetDescriptorRequest_GetDescriptorIndex(pRequest); length = USBGenericRequest_GetLength(pRequest); GetDescriptor(pDriver, type, indexDesc, length); break; case USBGenericRequest_SETADDRESS: TRACE_INFO_WP("sAddr "); // Sends a zero-length packet and then set the device address address = USBSetAddressRequest_GetAddress(pRequest); USBD_Write(0, 0, 0, (TransferCallback) USBD_SetAddress, (void *) address); break; case USBGenericRequest_SETCONFIGURATION: TRACE_INFO_WP("sCfg "); // Set the requested configuration cfgnum = USBSetConfigurationRequest_GetConfiguration(pRequest); SetConfiguration(pDriver, cfgnum); break; case USBGenericRequest_GETCONFIGURATION: TRACE_INFO_WP("gCfg "); // Send the current configuration number GetConfiguration(pDriver); break; case USBGenericRequest_GETSTATUS: TRACE_INFO_WP("gSta "); // Check who is the recipient switch (USBGenericRequest_GetRecipient(pRequest)) { case USBGenericRequest_DEVICE: TRACE_INFO_WP("Dev "); // Send the device status GetDeviceStatus(pDriver); break; case USBGenericRequest_ENDPOINT: TRACE_INFO_WP("Ept "); // Send the endpoint status eptnum = USBGenericRequest_GetEndpointNumber(pRequest); GetEndpointStatus(eptnum); break; default: TRACE_WARNING( "USBDDriver_RequestHandler: Unknown recipient (%d)\n\r", USBGenericRequest_GetRecipient(pRequest)); USBD_Stall(0); } break; case USBGenericRequest_CLEARFEATURE: TRACE_INFO_WP("cFeat "); // Check which is the requested feature switch (USBFeatureRequest_GetFeatureSelector(pRequest)) { case USBFeatureRequest_ENDPOINTHALT: TRACE_INFO_WP("Hlt "); // Unhalt endpoint and send a zero-length packet USBD_Unhalt(USBGenericRequest_GetEndpointNumber(pRequest)); USBD_Write(0, 0, 0, 0, 0); break; case USBFeatureRequest_DEVICEREMOTEWAKEUP: TRACE_INFO_WP("RmWU "); // Disable remote wake-up and send a zero-length packet pDriver->isRemoteWakeUpEnabled = 0; USBD_Write(0, 0, 0, 0, 0); break; default: TRACE_WARNING( "USBDDriver_RequestHandler: Unknown feature selector (%d)\n\r", USBFeatureRequest_GetFeatureSelector(pRequest)); USBD_Stall(0); } break; case USBGenericRequest_SETFEATURE: TRACE_INFO_WP("sFeat "); // Check which is the selected feature switch (USBFeatureRequest_GetFeatureSelector(pRequest)) { case USBFeatureRequest_DEVICEREMOTEWAKEUP: TRACE_INFO_WP("RmWU "); // Enable remote wake-up and send a ZLP pDriver->isRemoteWakeUpEnabled = 1; USBD_Write(0, 0, 0, 0, 0); break; case USBFeatureRequest_ENDPOINTHALT: TRACE_INFO_WP("Halt "); // Halt endpoint USBD_Halt(USBGenericRequest_GetEndpointNumber(pRequest)); USBD_Write(0, 0, 0, 0, 0); break; #if defined(CHIP_USB_UDPHS) || defined(CHIP_USB_OTGHS) case USBFeatureRequest_TESTMODE: // 7.1.20 Test Mode Support if ((USBGenericRequest_GetType(pRequest) == USBGenericRequest_DEVICE) && ((USBGenericRequest_GetIndex(pRequest) & 0x000F) == 0)) { // Handle test request USBDDriver_Test(USBFeatureRequest_GetTestSelector(pRequest)); } else { USBD_Stall(0); } break; #endif #if defined(CHIP_USB_OTGHS) case USBFeatureRequest_OTG_B_HNP_ENABLE: TRACE_INFO_WP("OTG_B_HNP_ENABLE "); otg_features_supported |= 1<<USBFeatureRequest_OTG_B_HNP_ENABLE; USBD_Write(0, 0, 0, 0, 0); break; case USBFeatureRequest_OTG_A_HNP_SUPPORT: TRACE_INFO_WP("OTG_A_HNP_SUPPORT "); otg_features_supported |= 1<<USBFeatureRequest_OTG_A_HNP_SUPPORT; USBD_Write(0, 0, 0, 0, 0); break; case USBFeatureRequest_OTG_A_ALT_HNP_SUPPORT: TRACE_INFO_WP("OTG_A_ALT_HNP_SUPPORT "); otg_features_supported |= 1<<USBFeatureRequest_OTG_A_ALT_HNP_SUPPORT; USBD_Write(0, 0, 0, 0, 0); break; #endif default: TRACE_WARNING( "USBDDriver_RequestHandler: Unknown feature selector (%d)\n\r", USBFeatureRequest_GetFeatureSelector(pRequest)); USBD_Stall(0); } break; case USBGenericRequest_SETINTERFACE: TRACE_INFO_WP("sInterface "); infnum = USBInterfaceRequest_GetInterface(pRequest); setting = USBInterfaceRequest_GetAlternateSetting(pRequest); SetInterface(pDriver, infnum, setting); break; case USBGenericRequest_GETINTERFACE: TRACE_INFO_WP("gInterface "); infnum = USBInterfaceRequest_GetInterface(pRequest); GetInterface(pDriver, infnum); break; default: TRACE_WARNING( "USBDDriver_RequestHandler: Unknown request code (%d)\n\r", USBGenericRequest_GetRequest(pRequest)); USBD_Stall(0); } }
//------------------------------------------------------------------------------ /// Handles audio-specific USB requests sent by the host, and forwards /// standard ones to the USB device driver. /// \param request Pointer to a USBGenericRequest instance. //------------------------------------------------------------------------------ void AUDDSpeakerDriver_RequestHandler(const USBGenericRequest *request) { unsigned char entity; unsigned char interface; TRACE_INFO_WP("NewReq "); // Check if this is a class request if (USBGenericRequest_GetType(request) == USBGenericRequest_CLASS) { // Check if the request is supported switch (USBGenericRequest_GetRequest(request)) { case AUDGenericRequest_SETCUR: TRACE_INFO_WP( "sCur(0x%04X) ", USBGenericRequest_GetIndex(request)); // Check the target interface and entity entity = AUDGenericRequest_GetEntity(request); interface = AUDGenericRequest_GetInterface(request); if ((entity == AUDDSpeakerDriverDescriptors_FEATUREUNIT) && (interface == AUDDSpeakerDriverDescriptors_CONTROL)) { AUDDSpeakerDriver_SetFeatureCurrentValue( entity, AUDFeatureUnitRequest_GetChannel(request), AUDFeatureUnitRequest_GetControl(request), USBGenericRequest_GetLength(request)); } else { TRACE_WARNING( "AUDDSpeakerDriver_RequestHandler: Unsupported entity/interface combination (0x%04X)\n\r", USBGenericRequest_GetIndex(request)); USBD_Stall(0); } break; case AUDGenericRequest_GETCUR: TRACE_INFO_WP( "gCur(0x%04X) ", USBGenericRequest_GetIndex(request)); // Check the target interface and entity entity = AUDGenericRequest_GetEntity(request); interface = AUDGenericRequest_GetInterface(request); if ((entity == AUDDSpeakerDriverDescriptors_FEATUREUNIT) && (interface == AUDDSpeakerDriverDescriptors_CONTROL)) { AUDDSpeakerDriver_GetFeatureCurrentValue( entity, AUDFeatureUnitRequest_GetChannel(request), AUDFeatureUnitRequest_GetControl(request), USBGenericRequest_GetLength(request)); } else { TRACE_WARNING( "AUDDSpeakerDriver_RequestHandler: Unsupported entity/interface combination (0x%04X)\n\r", USBGenericRequest_GetIndex(request)); USBD_Stall(0); } break; default: TRACE_WARNING( "AUDDSpeakerDriver_RequestHandler: Unsupported request (%d)\n\r", USBGenericRequest_GetRequest(request)); USBD_Stall(0); } } // Check if this is a standard request else if (USBGenericRequest_GetType(request) == USBGenericRequest_STANDARD) { // Forward request to the standard handler USBDDriver_RequestHandler(&(auddSpeakerDriver.usbdDriver), request); } // Unsupported request type else { TRACE_WARNING( "AUDDSpeakerDriver_RequestHandler: Unsupported request type (%d)\n\r", USBGenericRequest_GetType(request)); USBD_Stall(0); } }
/** * Handles HID-specific SETUP request sent by the host. * \param request Pointer to a USBGenericRequest instance */ void HIDDTransferDriver_RequestHandler(const USBGenericRequest *request) { HIDDTransferDriver *pDrv = &hiddTransferDriver; HIDDFunction *pHidd = &pDrv->hidFunction; TRACE_INFO("NewReq "); /* Check if this is a standard request */ if (USBGenericRequest_GetType(request) == USBGenericRequest_STANDARD) { /* This is a standard request */ switch (USBGenericRequest_GetRequest(request)) { case USBGenericRequest_GETDESCRIPTOR: /* Check if this is a HID descriptor, otherwise forward it to the standard driver */ if (!HIDDTransferDriver_GetDescriptor( USBGetDescriptorRequest_GetDescriptorType(request), USBGenericRequest_GetLength(request))) { USBDDriver_RequestHandler(pHidd->pUsbd, request); } return; /* Handled, no need to do others */ case USBGenericRequest_CLEARFEATURE: /* Check which is the requested feature */ switch (USBFeatureRequest_GetFeatureSelector(request)) { case USBFeatureRequest_ENDPOINTHALT: { uint8_t ep = USBGenericRequest_GetEndpointNumber(request); if (USBD_IsHalted(ep)) { /* Unhalt endpoint restart OUT EP */ USBD_Unhalt(ep); if (ep == pHidd->bPipeOUT) { HIDDFunction_StartPollingOutputs(pHidd); } } /* and send a zero-length packet */ USBD_Write(0, 0, 0, 0, 0); return; /* Handled, no need to do others */ } } break; } } /* We use different buffer for SetReport */ else if (USBGenericRequest_GetType(request) == USBGenericRequest_CLASS) { switch (USBGenericRequest_GetRequest(request)) { case HIDGenericRequest_SETREPORT: { uint16_t length = USBGenericRequest_GetLength(request); uint8_t type = HIDReportRequest_GetReportType(request); if (type == HIDReportRequest_OUTPUT) { if (length > HIDDTransferDriver_REPORTSIZE) length = HIDDTransferDriver_REPORTSIZE; USBD_Read(0, pDrv->iReportBuf, length, HIDDTransferDriver_ReportReceived, 0); /* No argument to the callback function */ } else { USBD_Stall(0); } } return; /* Handled, no need do others */ } } /* Process HID requests */ if (USBRC_SUCCESS == HIDDFunction_RequestHandler(pHidd, request)) { return; } else USBDDriver_RequestHandler(pHidd->pUsbd, request); }