csl_mscAux.h
Go to the documentation of this file.
00001 /*  ============================================================================
00002  *   Copyright (c) Texas Instruments Inc 2002, 2003, 2004, 2005, 2008
00003  *
00004  *   Use of this software is controlled by the terms and conditions found in the
00005  *   license agreement under which this software has been supplied.
00006  *  ============================================================================
00007  */
00008 
00016 /* ============================================================================
00017  * Revision History
00018  * ================
00019  * 25-Oct-2008 Created
00020  * 08-May-2009 Modified to fix the string desc ASCII to UNICODE conversion issue
00021  * 28-May-2009 Modified as per the review comments
00022  * ============================================================================
00023  */
00024 
00025 #ifndef _CSL_MSCAUX_H_
00026 #define _CSL_MSCAUX_H_
00027 
00028 #ifdef __cplusplus
00029 extern "C" {
00030 #endif
00031 
00032 #include "csl_usbAux.h"
00033 #include "csl_msc.h"
00034 
00035 #include <stdio.h>
00036 
00087 static inline
00088 void MSC_SetSenseKeys(Uint16    *senseData,
00089                       Uint16    senseKey,
00090                       Uint16    addSenseKey)
00091 {
00092    senseData[CSL_MSC_SSD_2] = senseKey;
00093    senseData[CSL_MSC_SSD_7] = addSenseKey;
00094 }
00095 
00139 static inline
00140 CSL_Status MSC_HandleStateReset(CSL_MscObject    *pMscHandle,
00141                                 pUsbEpHandle     hUsbOutEp)
00142 {
00143     CSL_Status    status;
00144 
00145     status = USB_abortTransaction(hUsbOutEp);
00146     status = USB_postTransaction(hUsbOutEp, CSL_MSC_STATE_RESET_DATA_SIZE,
00147                                  &pMscHandle->cbw[0], CSL_USB_IOFLAG_NONE);
00148     pMscHandle->storageState = CSL_MSC_STORAGE_STATE_WAIT_FOR_CBW;
00149 
00150     return(status);
00151 }
00152 
00198 static inline
00199 CSL_Status MSC_HandleStartStopUnit(CSL_MscObject    *pMscHandle,
00200                                    pUsbEpHandle     hUsbInEp,
00201                                    Uint16           lunNum)
00202 {
00203     CSL_MscMediaStatus    mediaEjectStat;
00204     CSL_Status            status;
00205     Uint16                loadEject;
00206 
00207     if (pMscHandle->cbwDataTransferLength != 0)
00208     {
00209         /* Stall the end point */
00210         pMscHandle->storageState = CSL_MSC_STORAGE_STATE_SENDING_STALL;
00211         status = USB_stallEndpt(&pMscHandle->bulkOutEpObj);
00212         status = USB_stallEndpt(&pMscHandle->bulkInEpObj);
00213 
00214 
00215         /* Dummy data transfer to intimate MSC_bulk function */
00216         status |= USB_postTransaction(&pMscHandle->bulkInEpObj,
00217                                      0,
00218                                      pMscHandle->lbaBuffer,
00219                                      CSL_USB_IOFLAG_NOT);
00220 
00221         return(status);
00222     }
00223 
00224     loadEject = pMscHandle->cbw[CSL_MSC_CBW_9] >> CSL_MSC_8BIT_SHIFT;
00225     pMscHandle->csw[CSL_MSC_CSW_6] = CSL_MSC_CSW_STATUS_COMMAND_PASSED;
00226 
00227     pMscHandle->storageState = CSL_MSC_STORAGE_STATE_SENDING_CSW;
00228 
00229     if(loadEject == 0x02) /* If the Eject Command */
00230     {
00231         if (pMscHandle->lun[lunNum].mediaState & CSL_MSC_MEDIA_LOCKED)
00232         {
00233             MSC_SetSenseKeys(pMscHandle->senseData,
00234                 CSL_MSC_SCSI_SENSEKEY_UNIT_ATTENTION,
00235                 CSL_MSC_SCSI_ASC_MEDIA_REMOVAL_PREVENTED);
00236             pMscHandle->csw[CSL_MSC_CSW_6] = CSL_MSC_CSW_STATUS_COMMAND_FAILED;
00237         }
00238         else
00239         {
00240             mediaEjectStat = pMscHandle->mediaEject(lunNum);
00241             if (mediaEjectStat == CSL_MSC_MEDIACCESS_SUCCESS)
00242             {
00243                 /* Change the media state to not present or not bad */
00244                 pMscHandle->lun[lunNum].mediaState &=~(CSL_MSC_MEDIA_PRESENT | CSL_MSC_MEDIA_BAD);
00245                 MSC_SetSenseKeys(pMscHandle->senseData,
00246                     CSL_MSC_SCSI_SENSEKEY_NO_SENSE,
00247                     CSL_MSC_SCSI_ASC_NO_ADDITIONAL_SENSE_INFORMATION);
00248             }
00249             else
00250             {
00251                 pMscHandle->csw[CSL_MSC_CSW_6] = CSL_MSC_CSW_STATUS_COMMAND_FAILED;
00252                 MSC_SetSenseKeys(pMscHandle->senseData,
00253                     CSL_MSC_SCSI_SENSEKEY_ILLEGAL_REQUEST,
00254                     CSL_MSC_SCSI_ASC_INVALID_COMMAND_OPERATION_CODE);
00255             }
00256         }
00257     }
00258     else
00259     {
00260         MSC_SetSenseKeys(pMscHandle->senseData,
00261             CSL_MSC_SCSI_SENSEKEY_NO_SENSE,
00262             CSL_MSC_SCSI_ASC_NO_ADDITIONAL_SENSE_INFORMATION);
00263         /* Change the media state to not present or not bad .. PRASAD*/
00264         pMscHandle->lun[lunNum].mediaState &=~(CSL_MSC_MEDIA_PRESENT | CSL_MSC_MEDIA_BAD);
00265     }
00266 
00267     status = USB_postTransaction(hUsbInEp,13,&pMscHandle->csw[0],CSL_USB_IOFLAG_NONE);
00268 
00269     return(status);
00270 }
00271 
00317 static inline
00318 CSL_Status MSC_HandleStateSendCSW(CSL_MscObject    *pMscHandle,
00319                                   pUsbEpHandle     hUsbOutEp,
00320                                   pUsbEpHandle     hUsbInEp)
00321 {
00322     CSL_Status    status;
00323 
00324     if(USB_isTransactionDone(hUsbInEp, &status))
00325     {
00326         pMscHandle->activityPresentFlag = FALSE;
00327         pMscHandle->storageState = CSL_MSC_STORAGE_STATE_WAIT_FOR_CBW;
00328         status |= USB_postTransaction(hUsbOutEp, CSL_MSC_CBW_DATA_SIZE,
00329                                   &pMscHandle->cbw[0], CSL_USB_IOFLAG_NONE);
00330     }
00331 
00332     return(status);
00333 }
00334 
00379 static inline
00380 CSL_Status MSC_HandleStateSendData(CSL_MscObject    *pMscHandle,
00381                                    pUsbEpHandle     hUsbInEp)
00382 {
00383     CSL_Status    status;
00384 
00385     if(USB_isTransactionDone(hUsbInEp, &status))
00386     {
00387         status |= USB_postTransaction(hUsbInEp, CSL_MSC_CSW_DATA_SIZE,
00388                                     &pMscHandle->csw[0], CSL_USB_IOFLAG_NONE);
00389         pMscHandle->storageState = CSL_MSC_STORAGE_STATE_SENDING_CSW;
00390     }
00391 
00392     return(status);
00393 }
00394 
00439 static inline
00440 CSL_Status MSC_HandleStateSendStall(CSL_MscObject    *pMscHandle,
00441                                     pUsbEpHandle     hUsbInEp)
00442 {
00443     CSL_Status    status;
00444 
00445     if(USB_isTransactionDone(hUsbInEp, &status))
00446     {
00447         status |= USB_postTransaction(hUsbInEp, CSL_MSC_CSW_DATA_SIZE,
00448                                      &pMscHandle->csw[0], CSL_USB_IOFLAG_NONE);
00449         pMscHandle->storageState = CSL_MSC_STORAGE_STATE_SENDING_CSW;
00450     }
00451 
00452     return(status);
00453 }
00454 
00499 static inline
00500 CSL_Status MSC_HandleStateSendingShortPkt(CSL_MscObject    *pMscHandle,
00501                                           pUsbEpHandle     hUsbInEp)
00502 {
00503     CSL_Status    status;
00504 
00505     pMscHandle->storageState = CSL_MSC_STORAGE_STATE_SENDING_STALL;
00506 
00507     status = USB_stallEndpt(hUsbInEp);
00508 
00509     /* Dummy data transfer to intimate MSC_bulk function */
00510     status |= USB_postTransaction(hUsbInEp, 0,
00511                                   &pMscHandle->csw[0],
00512                                   CSL_USB_IOFLAG_NOT);
00513 
00514     return (status);
00515 }
00516 
00562 static inline
00563 CSL_Status MSC_HandleModeSense6(CSL_MscObject    *pMscHandle,
00564                                 pUsbEpHandle     hUsbInEp,
00565                                 Uint16           logicalUnit)
00566 {
00567     CSL_Status    status;
00568     Uint16        modeSenseLen;
00569     Uint16        smallerLen;
00570 
00571     /* Check whether the data direction is proper or not */
00572     if(((pMscHandle->cbw[CSL_MSC_CBW_6] &
00573          CSL_MSC_CBW_DIRBIT_MASK) != CSL_MSC_CBW_DATADIR_IN) &&
00574         (pMscHandle->cbwDataTransferLength != 0))
00575     {
00576         pMscHandle->csw[CSL_MSC_CSW_6] = CSL_MSC_CSW_STATUS_PHASE_ERROR;
00577 
00578         /* Stall the end point */
00579         pMscHandle->storageState = CSL_MSC_STORAGE_STATE_SENDING_STALL;
00580         status = USB_stallEndpt(&pMscHandle->bulkInEpObj);
00581         status = USB_stallEndpt(&pMscHandle->bulkOutEpObj);
00582 
00583         /* Dummy data transfer to intimate MSC_bulk function */
00584         status = USB_postTransaction(&pMscHandle->bulkInEpObj,
00585                                      0,
00586                                      pMscHandle->lbaBuffer,
00587                                      CSL_USB_IOFLAG_NOT);
00588         return(status);
00589     }
00590 
00591     if (pMscHandle->cbwDataTransferLength > 0)
00592     {
00593         modeSenseLen = pMscHandle->modeSenseData[0];
00594 
00595         /* Getting smaller of the two values */
00596         if(modeSenseLen < pMscHandle->cbwDataTransferLength)
00597         {
00598             smallerLen = modeSenseLen;
00599         }
00600         else
00601         {
00602             smallerLen = (Uint16)(pMscHandle->cbwDataTransferLength &
00603                                   CSL_MSC_16BIT_MASK);
00604         }
00605 
00606         /* Setting the Data Residue :- Transfer Length - Data transferred */
00607         pMscHandle->cbwDataTransferLength -= (Uint32)smallerLen;
00608         pMscHandle->csw[CSL_MSC_CSW_4] =
00609               (Uint16)(pMscHandle->cbwDataTransferLength & CSL_MSC_16BIT_MASK);
00610         pMscHandle->csw[CSL_MSC_CSW_5] =
00611               (Uint16)(pMscHandle->cbwDataTransferLength >> CSL_MSC_16BIT_SHIFT);
00612         pMscHandle->csw[CSL_MSC_CSW_6] = CSL_MSC_CSW_STATUS_COMMAND_PASSED;
00613         status = USB_postTransaction(hUsbInEp, smallerLen,
00614                                     &pMscHandle->modeSenseData[1],
00615                                     CSL_USB_IOFLAG_NOSHORT);
00616 
00617         pMscHandle->storageState = CSL_MSC_STORAGE_STATE_SENDING_DATA;
00618     }
00619     else
00620     {
00621         status = MSC_sendCswWithPhaseError(pMscHandle, hUsbInEp);
00622     }
00623 
00624     return(status);
00625 }
00626 
00672 static inline
00673 CSL_Status MSC_HandleModeSense10(CSL_MscObject    *pMscHandle,
00674                                  pUsbEpHandle     hUsbInEp,
00675                                  Uint16           logicalUnit)
00676 {
00677     CSL_Status    status;
00678     Uint16        modeSenseLen;
00679     Uint16        smallerLen;
00680 
00681     /* Check whether the data direction is proper or not */
00682     if(((pMscHandle->cbw[CSL_MSC_CBW_6] &
00683          CSL_MSC_CBW_DIRBIT_MASK) != CSL_MSC_CBW_DATADIR_IN) &&
00684         (pMscHandle->cbwDataTransferLength != 0))
00685     {
00686         pMscHandle->csw[CSL_MSC_CSW_6] = CSL_MSC_CSW_STATUS_PHASE_ERROR;
00687 
00688         /* Stall the end point */
00689         pMscHandle->storageState = CSL_MSC_STORAGE_STATE_SENDING_STALL;
00690         status = USB_stallEndpt(&pMscHandle->bulkInEpObj);
00691         status = USB_stallEndpt(&pMscHandle->bulkOutEpObj);
00692 
00693         /* Dummy data transfer to intimate MSC_bulk function */
00694         status = USB_postTransaction(&pMscHandle->bulkInEpObj,
00695                                      0,
00696                                      pMscHandle->lbaBuffer,
00697                                      CSL_USB_IOFLAG_NOT);
00698         return(status);
00699     }
00700 
00701     if (pMscHandle->cbwDataTransferLength > 0)
00702     {
00703         modeSenseLen = pMscHandle->modeSenseData[0];
00704 
00705         /* Getting smaller of the two values */
00706         if(modeSenseLen < pMscHandle->cbwDataTransferLength)
00707         {
00708             smallerLen = modeSenseLen;
00709         }
00710         else
00711         {
00712             smallerLen = (Uint16)(pMscHandle->cbwDataTransferLength &
00713                                   CSL_MSC_16BIT_MASK);
00714         }
00715 
00716         /* Setting the Data Residue :- Transfer Length - Data transferred */
00717         pMscHandle->cbwDataTransferLength -= (Uint32)smallerLen;
00718         pMscHandle->csw[CSL_MSC_CSW_4] =
00719               (Uint16)(pMscHandle->cbwDataTransferLength & CSL_MSC_16BIT_MASK);
00720         pMscHandle->csw[CSL_MSC_CSW_5] =
00721               (Uint16)(pMscHandle->cbwDataTransferLength >> CSL_MSC_16BIT_SHIFT);
00722         pMscHandle->csw[CSL_MSC_CSW_6] = CSL_MSC_CSW_STATUS_COMMAND_PASSED;
00723         status = USB_postTransaction(hUsbInEp, smallerLen,
00724                                     &pMscHandle->modeSenseData[1],
00725                                     CSL_USB_IOFLAG_NOSHORT);
00726 
00727         pMscHandle->storageState = CSL_MSC_STORAGE_STATE_SENDING_DATA;
00728     }
00729     else
00730     {
00731         status = MSC_sendCswWithPhaseError(pMscHandle, hUsbInEp);
00732     }
00733 
00734     return(status);
00735 }
00736 
00782 static inline
00783 CSL_Status MSC_HandleInquiry(CSL_MscObject    *pMscHandle,
00784                              pUsbEpHandle     hUsbInEp,
00785                              Uint16           logicalUnit)
00786 {
00787     CSL_Status    status;
00788     Uint16        cbwRespLen;
00789     Uint16        smallerLen;
00790 
00791     /* Check whether the data direction is proper or not */
00792     if(((pMscHandle->cbw[CSL_MSC_CBW_6] &
00793          CSL_MSC_CBW_DIRBIT_MASK) != CSL_MSC_CBW_DATADIR_IN) &&
00794         (pMscHandle->cbwDataTransferLength != 0))
00795     {
00796         status = MSC_handleDataDirMisMatch(pMscHandle, CSL_MSC_CBW_DATADIR_IN);
00797 
00798         return(status);
00799     }
00800 
00801     if (pMscHandle->cbwDataTransferLength > 0)
00802     {
00803         cbwRespLen = pMscHandle->lun[logicalUnit].scsiInquiryData[0];
00804         /* Getting smaller of the two values */
00805         if(cbwRespLen < pMscHandle->cbwDataTransferLength)
00806         {
00807             smallerLen = cbwRespLen;
00808             pMscHandle->storageState = CSL_MSC_STORAGE_STATE_SENDING_SHORT_PKT;
00809         }
00810         else
00811         {
00812             smallerLen = (Uint16)(pMscHandle->cbwDataTransferLength &
00813                                   CSL_MSC_16BIT_MASK);
00814             pMscHandle->storageState = CSL_MSC_STORAGE_STATE_SENDING_DATA;
00815         }
00816 
00817         /* Setting the Data Residue :- Transfer Length - Data transferred */
00818         pMscHandle->cbwDataTransferLength -= (Uint32)smallerLen;
00819         pMscHandle->csw[CSL_MSC_CSW_4] =
00820              (Uint16)(pMscHandle->cbwDataTransferLength & CSL_MSC_16BIT_MASK);
00821         pMscHandle->csw[CSL_MSC_CSW_5] =
00822              (Uint16)(pMscHandle->cbwDataTransferLength >> CSL_MSC_16BIT_SHIFT);
00823         pMscHandle->csw[CSL_MSC_CSW_6] = CSL_MSC_CSW_STATUS_COMMAND_PASSED;
00824 
00825         status = USB_postTransaction(hUsbInEp, smallerLen,
00826                                  &pMscHandle->lun[logicalUnit].scsiInquiryData[1],
00827                                  CSL_USB_IOFLAG_NOSHORT);
00828     }
00829     else
00830     {
00831         status = MSC_sendCswWithPhaseError(pMscHandle, hUsbInEp);
00832     }
00833 
00834     return(status);
00835 }
00836 
00881 static inline
00882 CSL_Status MSC_HandleRequestSense(CSL_MscObject    *pMscHandle,
00883                                   pUsbEpHandle     hUsbInEp)
00884 {
00885     CSL_Status    status;
00886     Uint16        cbwRespLen;
00887     Uint16        smallerLen;
00888 
00889     /* Check whether the data direction is proper or not */
00890     if(((pMscHandle->cbw[CSL_MSC_CBW_6] &
00891          CSL_MSC_CBW_DIRBIT_MASK) != CSL_MSC_CBW_DATADIR_IN) &&
00892         (pMscHandle->cbwDataTransferLength != 0))
00893     {
00894         status = MSC_handleDataDirMisMatch(pMscHandle, CSL_MSC_CBW_DATADIR_IN);
00895 
00896         return(status);
00897     }
00898 
00899     if (pMscHandle->cbwDataTransferLength > 0)
00900     {
00901         cbwRespLen = pMscHandle->senseData[0];
00902 
00903         /* Getting smaller of the two values */
00904         if(cbwRespLen < pMscHandle->cbwDataTransferLength)
00905         {
00906             pMscHandle->storageState = CSL_MSC_STORAGE_STATE_SENDING_SHORT_PKT;
00907             smallerLen = cbwRespLen;
00908         }
00909         else
00910         {
00911             pMscHandle->storageState = CSL_MSC_STORAGE_STATE_SENDING_DATA;
00912 
00913             smallerLen= (Uint16)(pMscHandle->cbwDataTransferLength &
00914                                  CSL_MSC_16BIT_MASK);
00915         }
00916 
00917         /* Setting the Data Residue :- Transfer Length - Data transferred */
00918         pMscHandle->cbwDataTransferLength -= (Uint32)smallerLen;
00919         pMscHandle->csw[CSL_MSC_CSW_4] =
00920                (Uint16)(pMscHandle->cbwDataTransferLength & CSL_MSC_16BIT_SHIFT);
00921         pMscHandle->csw[CSL_MSC_CSW_5] =
00922                (Uint16)(pMscHandle->cbwDataTransferLength >> CSL_MSC_16BIT_SHIFT);
00923         pMscHandle->csw[CSL_MSC_CSW_6] = CSL_MSC_CSW_STATUS_COMMAND_PASSED;
00924         status = USB_postTransaction(hUsbInEp, smallerLen,
00925                                      &pMscHandle->senseData[1],
00926                                      CSL_USB_IOFLAG_NOSHORT);
00927     }
00928     else
00929     {
00930         status = MSC_sendCswWithPhaseError(pMscHandle, hUsbInEp);
00931     }
00932 
00933     return(status);
00934 }
00935 
00981 static inline
00982 CSL_Status MSC_HandleVerify10(CSL_MscObject    *pMscHandle,
00983                               pUsbEpHandle     hUsbInEp,
00984                               Uint16           logicalUnit)
00985 {
00986     CSL_Status    status;
00987     Uint16        verifyLen;
00988 
00989     if (pMscHandle->cbwDataTransferLength != 0)
00990     {
00991         /* Stall the end point */
00992         pMscHandle->storageState = CSL_MSC_STORAGE_STATE_SENDING_STALL;
00993         status = USB_stallEndpt(&pMscHandle->bulkOutEpObj);
00994         status = USB_stallEndpt(&pMscHandle->bulkInEpObj);
00995 
00996 
00997         /* Dummy data transfer to intimate MSC_bulk function */
00998         status |= USB_postTransaction(&pMscHandle->bulkInEpObj,
00999                                      0,
01000                                      pMscHandle->lbaBuffer,
01001                                      CSL_USB_IOFLAG_NOT);
01002 
01003         return(status);
01004     }
01005 
01006     verifyLen = ((pMscHandle->cbw[CSL_MSC_CBW_11] & CSL_MSC_8BIT_MASK) <<
01007                  CSL_MSC_8BIT_SHIFT)|((pMscHandle->cbw[CSL_MSC_CBW_11] &
01008                  CSL_MSC_8BIT_HIGH_MASK) >> CSL_MSC_8BIT_SHIFT);
01009 
01010     if((pMscHandle->lun[logicalUnit].verifyFlag == CSL_MSC_VERIFY_PASSED) ||
01011        (verifyLen == 0))
01012     {
01013         pMscHandle->csw[CSL_MSC_CSW_6] = CSL_MSC_CSW_STATUS_COMMAND_PASSED;
01014     }
01015     else
01016     {
01017         pMscHandle->csw[CSL_MSC_CSW_6] = CSL_MSC_CSW_STATUS_COMMAND_FAILED;
01018         MSC_SetSenseKeys(pMscHandle->senseData,
01019             CSL_MSC_SCSI_SENSEKEY_MISCOMPARE,
01020             CSL_MSC_SCSI_ASC_MISCOMPARE_VERIFY);
01021     }
01022 
01023     pMscHandle->storageState = CSL_MSC_STORAGE_STATE_SENDING_CSW;
01024     status = USB_postTransaction(hUsbInEp, CSL_MSC_CSW_DATA_SIZE,
01025                                  &pMscHandle->csw[0], CSL_USB_IOFLAG_NOSHORT);
01026 
01027     return(status);
01028 }
01029 
01084 static inline
01085 CSL_MscRequestRet MSC_reqUnknown(CSL_UsbDevNum         devNum,
01086                                  CSL_UsbSetupStruct    *usbSetup,
01087                                  pUsbEpHandle          hInEp,
01088                                  pUsbEpHandle          hOutEp,
01089                                  void                  *pMsc)
01090 {
01091     CSL_MscRequestRet    retStat;
01092 
01093     /* STALL the endpoint - the request is either not known or not supported */
01094     retStat = CSL_MSC_REQUEST_STALL;
01095 
01096     return(retStat);
01097 }
01098 
01149 static inline
01150 fpMSC_REQ_HANDLER MSC_lookupReqHandler(Uint16                  request,
01151                                        CSL_MscRequestStruct    *pUSB_ReqTable)
01152 {
01153     Uint16    index;
01154 
01155     /* parse thru the end of request handler table */
01156     for(index = 0; pUSB_ReqTable[index].fpRequestHandler != NULL; index++)
01157     {
01158         /* if request handler exists return a pointer to the request handler routine */
01159         if(pUSB_ReqTable[index].request == request)
01160         {
01161             return(pUSB_ReqTable[index].fpRequestHandler);
01162         }
01163     }
01164 
01165     /* if request handler does not exist return a pointer to the USB_reqUnknown
01166     routine */
01167     return(MSC_reqUnknown);
01168 }
01169 
01223 static inline
01224 CSL_MscRequestRet MSC_reqSetAddress(CSL_UsbDevNum         devNum,
01225                                     CSL_UsbSetupStruct    *usbSetup,
01226                                     pUsbEpHandle          hInEp,
01227                                     pUsbEpHandle          hOutEp,
01228                                     void                  *pMsc)
01229 {
01230     USB_setDevAddr(devNum, (Uint16)(usbSetup->wValue));
01231 
01232     return(CSL_MSC_REQUEST_DONE);
01233 }
01234 
01289 static inline
01290 CSL_MscRequestRet MSC_reqSetConfiguration(CSL_UsbDevNum         devNum,
01291                                           CSL_UsbSetupStruct    *usbSetup,
01292                                           pUsbEpHandle          hInEp,
01293                                           pUsbEpHandle          hOutEp,
01294                                           void                  *pMsc)
01295 {
01296     CSL_MscRequestRet    retStat;
01297 
01298     pMscClassHandle      pMscClassHdl;
01299     CSL_MscCtrlObject    *pCtrlHandle;
01300 
01301     pMscClassHdl = (pMscClassHandle)(pMsc);
01302     pCtrlHandle  = &pMscClassHdl->ctrlHandle;
01303 
01304     if((usbSetup->wValue == FALSE) || (usbSetup->wValue == TRUE))
01305     {
01306         pCtrlHandle->curConfigStat = usbSetup->wValue;
01307 
01308         USB_setConfiguration(devNum,usbSetup->wValue);
01309 
01310         retStat   = CSL_MSC_REQUEST_SEND_ACK;
01311     }
01312     else
01313     {
01314         /* configuration not supported, STALL the endpoint */
01315         retStat = CSL_MSC_REQUEST_STALL;
01316     }
01317 
01318     return(retStat);
01319 }
01320 
01375 static inline
01376 CSL_MscRequestRet MSC_reqClearFeature(CSL_UsbDevNum         devNum,
01377                                       CSL_UsbSetupStruct    *usbSetup,
01378                                       pUsbEpHandle          hInEp,
01379                                       pUsbEpHandle          hOutEp,
01380                                       void                  *pMsc)
01381 {
01382     CSL_MscRequestRet    retStat;
01383     pUsbEpHandle         hEPx;
01384     Uint16               endpt;  /* this is USB logical endpoint */
01385 
01386     retStat = CSL_MSC_REQUEST_SEND_ACK;
01387 
01388     switch(usbSetup->wValue)
01389     {
01390         case CSL_USB_FEATURE_ENDPOINT_STALL:
01391             endpt = (usbSetup->wIndex) & CSL_MSC_8BIT_MASK;
01392             hEPx = USB_epNumToHandle(devNum, endpt);
01393             USB_clearEndptStall(hEPx);
01394             break;
01395 
01396         case CSL_USB_FEATURE_REMOTE_WAKEUP:
01397             USB_setRemoteWakeup(devNum, (CSL_UsbBoolean)FALSE);
01398             break;
01399 
01400         default:
01401             /* Unsupported Feature. STALL the endpoint */
01402             retStat = CSL_MSC_REQUEST_STALL;
01403             break;
01404     }
01405 
01406     return(retStat);
01407 }
01408 
01463 static inline
01464 CSL_MscRequestRet MSC_reqGetStatus(CSL_UsbDevNum         devNum,
01465                                    CSL_UsbSetupStruct    *usbSetup,
01466                                    pUsbEpHandle          hInEp,
01467                                    pUsbEpHandle          hOutEp,
01468                                    void                  *pMsc)
01469 {
01470     CSL_MscRequestRet     retStat;
01471     pMscClassHandle       pMscClassHdl;
01472     CSL_MscCtrlObject     *pCtrlHandle;
01473     pUsbEpHandle          hEPx;
01474     CSL_Status            status;
01475     Uint16                endpt;   /* this is USB logical endpoint */
01476 
01477     pMscClassHdl = (pMscClassHandle)(pMsc);
01478     pCtrlHandle  = &pMscClassHdl->ctrlHandle;
01479     retStat      = CSL_MSC_REQUEST_GET_ACK;
01480 
01481     switch(usbSetup->bmRequestType - CSL_MSC_REQUEST_TYPE_BASE)
01482     {
01483         /* Device Status to be returned */
01484         case CSL_MSC_REQUEST_TYPE_DEVICE_STATUS:
01485             pCtrlHandle->ctrlBuffer[1] =
01486             (((Uint16)USB_getRemoteWakeupStat(devNum))<<1) |
01487              CSL_MSC_CURRDEV_STAT;
01488             USB_postTransaction(hInEp, 2, &pCtrlHandle->ctrlBuffer,
01489                                 CSL_USB_IOFLAG_NONE);
01490             break;
01491 
01492         /* Interface status is to be returned */
01493         case CSL_MSC_REQUEST_TYPE_INTERFACE_STATUS:
01494             pCtrlHandle->ctrlBuffer[1] = CSL_MSC_CURRDEV_STAT;
01495             USB_postTransaction(hInEp, 2, &pCtrlHandle->ctrlBuffer,
01496                                 CSL_USB_IOFLAG_NONE);
01497             break;
01498 
01499         /* Endpoint status to be returned */
01500         case CSL_MSC_REQUEST_TYPE_EP_STATUS:
01501 
01502             endpt  =  usbSetup->wIndex & 0xFF;
01503             hEPx   =  USB_epNumToHandle(devNum, endpt);
01504             pCtrlHandle->ctrlBuffer[1] = (Uint16)USB_getEndptStall(hEPx,
01505                                                                    &status);
01506             USB_postTransaction(hInEp, 2, &pCtrlHandle->ctrlBuffer,
01507                                 CSL_USB_IOFLAG_NONE);
01508             break;
01509 
01510         default:
01511             /* STALL the endpoint */
01512             retStat = CSL_MSC_REQUEST_STALL;
01513             break;
01514     }
01515 
01516     return(retStat);
01517 }
01518 
01573 static inline
01574 CSL_MscRequestRet MSC_reqSetFeature(CSL_UsbDevNum         devNum,
01575                                     CSL_UsbSetupStruct    *usbSetup,
01576                                     pUsbEpHandle          hInEp,
01577                                     pUsbEpHandle          hOutEp,
01578                                     void                  *pMsc)
01579 {
01580     CSL_MscRequestRet    retStat;
01581     pUsbEpHandle         hEPx;
01582     Uint16               endpt;        /* this is USB logical endpoint */
01583 
01584     retStat = CSL_MSC_REQUEST_SEND_ACK;
01585 
01586     switch(usbSetup->wValue)
01587     {
01588         case CSL_USB_FEATURE_ENDPOINT_STALL:
01589             /* updated set and clear endpoint stall to work with logical endpoint num */
01590             endpt = (usbSetup->wIndex) & CSL_MSC_8BIT_MASK;
01591             hEPx = USB_epNumToHandle(devNum, endpt);
01592             USB_stallEndpt(hEPx);
01593             break;
01594 
01595         case CSL_USB_FEATURE_REMOTE_WAKEUP:
01596             USB_setRemoteWakeup(devNum, (CSL_UsbBoolean)TRUE);
01597             break;
01598 
01599         default:
01600             /* Feature not supported, STALL the endpoint */
01601             retStat = CSL_MSC_REQUEST_STALL;
01602             break;
01603     }
01604 
01605   return(retStat);
01606 }
01607 
01661 static inline
01662 CSL_MscRequestRet MSC_reqGetConfiguration(CSL_UsbDevNum         devNum,
01663                                           CSL_UsbSetupStruct    *usbSetup,
01664                                           pUsbEpHandle          hInEp,
01665                                           pUsbEpHandle          hOutEp,
01666                                           void                  *pMsc)
01667 {
01668     pMscClassHandle       pMscClassHdl;
01669     CSL_MscCtrlObject*    pCtrlHandle;
01670 
01671     pMscClassHdl = (pMscClassHandle)(pMsc);
01672     pCtrlHandle  = &pMscClassHdl->ctrlHandle;
01673 
01674     /* Send the current Configuration Value */
01675     pCtrlHandle->ctrlBuffer[1] = pCtrlHandle->curConfigStat;
01676     USB_postTransaction(hInEp, 1, (void*)&pCtrlHandle->ctrlBuffer,
01677                         CSL_USB_IOFLAG_NONE | CSL_USB_IOFLAG_NOSHORT);
01678 
01679     return(CSL_MSC_REQUEST_GET_ACK);
01680 }
01681 
01737 static inline
01738 CSL_MscRequestRet MSC_reqGetMaxLUN(CSL_UsbDevNum         devNum,
01739                                    CSL_UsbSetupStruct    *usbSetup,
01740                                    pUsbEpHandle          hInEp,
01741                                    pUsbEpHandle          hOutEp,
01742                                    void                  *pMsc)
01743 {
01744     pMscClassHandle       pMscClassHdl;
01745     CSL_MscCtrlObject*    pCtrlHandle;
01746     CSL_MscRequestRet     retStat;
01747 
01748     pMscClassHdl = (pMscClassHandle)(pMsc);
01749     pCtrlHandle  = &pMscClassHdl->ctrlHandle;
01750     pCtrlHandle->ctrlBuffer[1] = pMscClassHdl->mscHandle.noOfLun;
01751 
01752     /*
01753      * Verify the setup packet fields
01754      * wValue - 0
01755      * wIndex - interface number, set 0
01756      * wLength - 1
01757      */
01758     if ((usbSetup->wIndex == 0) &&
01759         (usbSetup->wLength == 1) &&
01760         (usbSetup->wValue == 0))
01761     {
01762         USB_postTransaction(hInEp, 1, &pCtrlHandle->ctrlBuffer[0],
01763                             CSL_USB_IOFLAG_NONE);
01764 
01765         /* Receive a 0 length packet for acknowledgement */
01766         retStat = CSL_MSC_REQUEST_GET_ACK;
01767     }
01768     else
01769     {
01770         retStat = CSL_MSC_REQUEST_STALL;
01771     }
01772 
01773     return (retStat);
01774 }
01775 
01831 static inline
01832 CSL_MscRequestRet MSC_reqGetInterface(CSL_UsbDevNum         devNum,
01833                                       CSL_UsbSetupStruct    *usbSetup,
01834                                       pUsbEpHandle          hInEp,
01835                                       pUsbEpHandle          hOutEp,
01836                                       void                  *pMsc)
01837 {
01838     pMscClassHandle       pMscClassHdl;
01839     CSL_MscCtrlObject     *pCtrlHandle;
01840     CSL_MscRequestRet     retStat;
01841 
01842     pMscClassHdl = (pMscClassHandle)(pMsc);
01843     pCtrlHandle  = &pMscClassHdl->ctrlHandle;
01844     retStat      = CSL_MSC_REQUEST_GET_ACK;
01845 
01846     /* Compare the Interface with the bNumInterfaces byte of Configuration Descriptor */
01847     if(usbSetup->wIndex == 0)
01848     {
01849         /* Send the current Interface Value */
01850         pCtrlHandle->ctrlBuffer[1] = 0;
01851         USB_postTransaction(hInEp, 1, &pCtrlHandle->ctrlBuffer[0],
01852                             CSL_USB_IOFLAG_NONE);
01853     }
01854     else
01855     {
01856         /*  Interface specified doesn't exist, STALL the endpoint */
01857         retStat = CSL_MSC_REQUEST_STALL;
01858     }
01859 
01860     return retStat;
01861 }
01862 
01918 static inline
01919 CSL_MscRequestRet MSC_reqSetInterface(CSL_UsbDevNum         devNum,
01920                                       CSL_UsbSetupStruct    *usbSetup,
01921                                       pUsbEpHandle          hInEp,
01922                                       pUsbEpHandle          hOutEp,
01923                                       void                  *pMsc)
01924 {
01925     CSL_MscRequestRet    retStat;
01926 
01927     if(usbSetup->wIndex == 0)
01928     {
01929         if (usbSetup->wValue == 0)
01930         {
01931             USB_setConfiguration(devNum,usbSetup->wValue);
01932             retStat = CSL_MSC_REQUEST_SEND_ACK;
01933         }
01934     }
01935     else
01936     {
01937         /* configuration not supported, STALL the endpoint */
01938         retStat = CSL_MSC_REQUEST_STALL;
01939     }
01940 
01941     return(retStat);
01942 }
01943 
01993 static inline
01994 CSL_Status  MSC_verifyCBW(CSL_MscObject    *pMscHandle,
01995                           pUsbEpHandle     hUsbOutEp,
01996                           pUsbEpHandle     hUsbInEp)
01997 {
01998     Uint32        cbwSignature;
01999     CSL_Status    status;
02000     Uint16        cbwSize;
02001     Uint16        logicalUnit;
02002 
02003     cbwSignature = 0;
02004     status       = CSL_SOK;
02005     cbwSize      = 0;
02006     logicalUnit  = 0;
02007 
02008     if ((pMscHandle != NULL) && (hUsbOutEp != NULL) && (hUsbInEp != NULL))
02009     {
02010         cbwSignature =  ((Uint32)(pMscHandle->cbw[CSL_MSC_CBW_1]) <<
02011                                   CSL_MSC_16BIT_SHIFT) |
02012                                   (Uint32)pMscHandle->cbw[CSL_MSC_CBW_0];
02013 
02014         if (cbwSignature != CSL_MSC_CBW_SIGNATURE)
02015         {
02016             status = CSL_ESYS_FAIL;
02017         }
02018         else
02019         {
02020             cbwSize = USB_getDataCountReadFromFifo(hUsbOutEp);
02021             if (cbwSize != CSL_MSC_CBW_DATA_SIZE)
02022             {
02023                 status = CSL_ESYS_FAIL;
02024             }
02025             else
02026             {
02027                 /* Getting the logical Unit ready */
02028                 logicalUnit = pMscHandle->cbw[CSL_MSC_CBW_6] >> CSL_MSC_8BIT_SHIFT;
02029 
02030                 if (logicalUnit > pMscHandle->noOfLun)
02031                 {
02032                     status = CSL_ESYS_FAIL;
02033                 }
02034             }
02035         }
02036     }
02037     else
02038     {
02039         status = CSL_ESYS_FAIL;
02040     }
02041 
02042     return (status);
02043 }
02044 
02048 #ifdef __cplusplus
02049 }
02050 #endif
02051 
02052 #endif    // _CSL_MSCAUX_H_
02053