?? usbtargrbccmd.c
字號(hào):
/* If not an RBC device, return just the header with no page info */ g_deviceHdr.dataLen = sizeof(MODE_PARAMETER_HEADER)-1; *ppData = (UINT8 *)&g_deviceHdr; *pSize = sizeof(MODE_PARAMETER_HEADER); } /* return only what was requested */ if (allocLgth < *pSize) *pSize = allocLgth; /* set sense data */ usbTargRbcSenseDataSet (SCSI_SENSE_NO_SENSE, SCSI_ADSENSE_NO_SENSE, 0); return(OK); }/********************************************************************************* usbTargRbcTestUnitReady - test if the RBC device is ready** This routine tests whether the RBC block I/O device is ready.** RETURNS: OK or ERROR* * ERRNO:* none.*/STATUS usbTargRbcTestUnitReady ( UINT8 arg[6] /* the RBC command */ ) { /* * set sense key to NO SENSE (0x0) and set additional sense code * to NO ADDITIONAL SENSE INFORMATION */ usbTargRbcSenseDataSet(SCSI_SENSE_NO_SENSE,SCSI_ADSENSE_NO_SENSE,0); return(OK); }/******************************************************************************** usbTargRbcBufferWrite - write micro-code to the RBC device** This routine writes micro-code to the RBC block I/O device.** RETURNS: OK or ERROR* * ERRNO:* none.*/STATUS usbTargRbcBufferWrite ( UINT8 arg[10], /* the RBC command */ UINT8 ** ppData, /* micro-code location on device */ UINT32 * pSize /* size of micro-code location on device */ ) { UINT32 offset; /* offset */ UINT32 paramListLgth; /* paramter list length */ UINT8 mode; /* mode */ mode = arg[1] & 0x7; offset = (arg[3] << 16) | (arg[4] << 8) | arg[5]; paramListLgth = (arg[6] << 16) | (arg[7] << 8) | arg[8]; switch(mode) { case 5: /* * vendor-specific Microcode or control information is * transferred to the device and saved saved to * non-volatile memory */ break; case 7: /* * vendor-specific microcode or control information is * transferred to the device with two or more WRITE BUFFER commands. */ break; default: /* other modes optional for RBC devices and not implemented */ /* * set sense key to ILLEGAL REQUEST (05h) and an ASC of COMMAND * SEQUENCE ERROR (2Ch) */ usbTargRbcSenseDataSet (SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ADSENSE_CMDSEQ_ERROR, 0x0); return(ERROR); } /* * The PARAMETER LIST LENGTH field specifies the maximum number of bytes * that sent by the host to be stored in the specified buffer beginning * at the buffer offset. If the BUFFER OFFSET and PARAMETER LIST LENGTH * fields specify a transfer in excess of the buffer capacity, return * ERROR and set the sense key to ILLEGAL REQUEST with an additional * sense code of INVALID FIELD IN CDB. */ if (paramListLgth + offset > DATA_BUFFER_LEN) { usbTargRbcSenseDataSet (SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ADSENSE_INVALID_CDB, 0x0); return(ERROR); } usbTargRbcSenseDataSet(SCSI_SENSE_NO_SENSE, SCSI_ADSENSE_NO_SENSE, 0x0); *ppData = &g_dataOutBfr[0]; *pSize = DATA_BUFFER_LEN; return(OK); }/* optional routines *//********************************************************************************* usbTargRbcFormat - format the RBC device** This routine formats the RBC block I/O device.** RETURNS: OK or ERROR* * ERRNO:* none*/STATUS usbTargRbcFormat ( UINT8 arg[6] /* the RBC command */ ) { /* * This routine should not be called because the mode sense data indicates * the unit cannot be formatted. If this routine is called, return a status * of ERROR, a sense key of MEDIA ERROR (03h), an ASC/ASCQ * of FORMAT COMMAND FAILED (31h /01h). */ usbTargRbcSenseDataSet (SCSI_SENSE_MEDIUM_ERROR, SCSI_ADSENSE_FORMAT_ERROR, 0x1); return(ERROR); }/********************************************************************************* usbTargRbcPersistentReserveIn - send reserve data to the host** This routine requests reserve data to be sent to the initiator.** RETURNS: OK or ERROR* * ERRNO:* none*/STATUS usbTargRbcPersistentReserveIn ( UINT8 arg[10], /* the RBC command */ UINT8 ** ppData, /* location of reserve data on device */ UINT32 *pSize /* size of reserve data */ ) { *ppData = NULL; *pSize = 0; /* * This routine is optional and is not implemented. If this routine is called, * return a status of ERROR, a sense key of ILLEGAL REQUEST (05h), * and an ASC/ASCQ of INVALID COMMAND OPERATION CODE (20h). */ usbTargRbcSenseDataSet (SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ADSENSE_ILLEGAL_COMMAND, 0x0); return(ERROR); }/********************************************************************************* usbTargRbcPersistentReserveOut - reserve resources on the RBC device** This routine reserves resources on the RBC block I/O device.** RETURNS: OK or ERROR* * ERRNO:* none*/STATUS usbTargRbcPersistentReserveOut ( UINT8 arg[10], /* the RBC command */ UINT8 ** ppData, /* location of reserve data on device */ UINT32 *pSize /* size of reserve data */ ) { *ppData = NULL; *pSize = 0; /* * This routine is optional and is not implemented. If this routine is * called, return a status of ERROR, a sense key of ILLEGAL REQUEST (05h), * and an ASC/ASCQ of INVALID COMMAND OPERATION CODE (20h). */ usbTargRbcSenseDataSet (SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ADSENSE_ILLEGAL_COMMAND, 0x0); return(ERROR); }/********************************************************************************* usbTargRbcRelease - release a resource on the RBC device** This routine releases a resource on the RBC block I/O device.** RETURNS: OK or ERROR** ERRNO:* none.*/STATUS usbTargRbcRelease ( UINT8 arg[6] /* the RBC command */ ) { /* * This routine is optional and is not implemented. If this routine is * called, return a status of ERROR, a sense key of ILLEGAL REQUEST (05h), * and an ASC/ASCQ of INVALID COMMAND OPERATION CODE (20h). */ usbTargRbcSenseDataSet (SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ADSENSE_ILLEGAL_COMMAND, 0x0); return(ERROR); }/********************************************************************************* usbTargRbcRequestSense - request sense data from the RBC device** This routine requests sense data from the RBC block I/O device.** RETURNS: OK or ERROR** ERRNO: N/A*/STATUS usbTargRbcRequestSense ( UINT8 arg[6], /* the RBC command */ UINT8 ** ppData, /* location of sense data on device */ UINT32 *pSize /* size of sense data */ ) { UINT8 allocLgth = arg[4]; /* allocation length */ *ppData = (UINT8 *)&g_senseData; *pSize = sizeof(SENSE_DATA); if (allocLgth < *pSize) *pSize = allocLgth; return(OK); }/********************************************************************************* usbTargRbcReserve - reserve a resource on the RBC device** This routine reserves a resource on the RBC block I/O device.** RETURNS: OK or ERROR* * ERRNO:* none*/STATUS usbTargRbcReserve ( UINT8 arg[6] /* the RBC command */ ) { /* * set sense key to ILLEGAL REQUEST 0x5 and * set additional sense code to INVALID COMMAND OPERATION CODE 0x20 */ usbTargRbcSenseDataSet (SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ADSENSE_ILLEGAL_COMMAND, 0); return(ERROR); }/******************************************************************************** usbTargRbcCacheSync - synchronize the cache of the RBC device** This routine synchronizes the cache of the RBC block I/O device.** RETURNS: OK or ERROR* * ERRNO:* none*/STATUS usbTargRbcCacheSync ( UINT8 arg[10] /* the RBC command */ ) { usbTargRbcSenseDataSet (SCSI_SENSE_NO_SENSE, SCSI_ADSENSE_NO_SENSE, 0); return(OK); }/********************************************************************************* usbTargRbcBlockDevGet - return opaque pointer to the RBC BLK I/O DEV device * structure.** This routine returns an opaque pointer to the RBC BLK I/O DEV device * structure.** RETURNS: Pointer to the RBC BLK I/O DEV structure* * ERRNO:* none*/pVOID usbTargRbcBlockDevGet (void) { /* return current instance of the RBC BLK_DEV structure */ return(g_rbcBlkDev); }/********************************************************************************* usbTargRbcBlockDevSet - set the pointer to the RBC BLK I/O DEV device structure.** This routine sets the RBC BLK_DEV pointer that is accessed by the * usbTargRbcBlockDevGet() routine.** RETURNS: OK or ERROR* * ERRNO:* none*/STATUS usbTargRbcBlockDevSet ( pVOID *blkDev /* pointer to the BLK_DEV device */ ) { /* set the RBC BLK_DEV pointer to the value of the argument */ g_rbcBlkDev = blkDev; return(OK); }/******************************************************************************** usbTargRbcBlockDevCreate - create an RBC BLK_DEV device.** This routine creates an RBC BLK I/O device. The RAM driver will be used for* the actual implementation.** RETURNS: Pointer to BLK_DEV structure* * ERRNO:* none.*/STATUS usbTargRbcBlockDevCreate (void) { CBIO_DEV_ID cbio; /* CBIO_DEV_ID */ if (g_rbcBlkDev != NULL) return(OK);#if (USB_MS_BLK_DRV == USB_MS_CBIO_DRV) /* create a RAM disk cache block I/O device (CBIO) */ cbio = (CBIO_DEV_ID)ramDiskDevCreate ( NULL, /* where it is in memory (0 = malloc) */ BYTES_PER_BLOCK, /* number of bytes per block */ BLKS_PER_TRACK, /* number of blocks per track */ NUM_BLOCKS, /* number of blocks on this device */ BLK_OFFSET /* no. of blks to skip at start of device */ ); if (cbio == NULL) { usbDbgPrint("usbTargRbcBlockDevCreate: ramDiskDevCreate returned \ NULL\n"); return(ERROR); } /* create the DOS file system */ if (dosFsDevCreate (BLK_DEV_NAME, cbio, 0x20, NONE) == ERROR) { usbDbgPrint ("usbTargRbcFileSystemCreate: dosFsDevCreate \ returned ERROR\n"); return ERROR; } /* Format the first partition */ if(dosFsVolFormat (BLK_DEV_NAME, 2,0) == ERROR) { usbDbgPrint ("usbTargRbcBlockDevCreate: dosFsVolFormat returned \ ERROR\n"); return ERROR; }#elif (USB_MS_BLK_DRV == USB_MS_RAM_DRV) /* create a RAM driver and use CBIO wrapper routines */ cbio = cbioWrapBlkDev (ramDevCreate (NULL, BYTES_PER_BLOCK, BLKS_PER_TRACK, NUM_BLOCKS, BLK_OFFSET)); if (cbio == NULL) { usbDbgPrint("usbTargRbcBlockDevCreate: ramDevCreate returned NULL\n"); return(ERROR); } if(cbioIoctl(cbio,CBIO_RESET,NULL) != OK) { usbDbgPrint ("usbTargRbcBlockDevCreate: CBIO_RESET returned ERROR\n"); return ERROR; }#else#error usbTargRbcBlockDevCreate: USB_MS_BLK_DRV is an unknown device#endif /* reset the device */ if(cbioIoctl(cbio,CBIO_RESET,NULL) != OK) { usbDbgPrint ("usbTargRbcBlockDevCreate: CBIO_RESET returned ERROR\n"); return ERROR; } /* save the pointer */ g_rbcBlkDev = (pVOID)cbio; return(OK); }/******************************************************************************** usbTargRbcVendorSpecific - vendor specific call** This routine is a vendor specific call.** RETURNS: OK* * ERRNO:* none*/STATUS usbTargRbcVendorSpecific ( UINT8 arg[10], /* the RBC command */ UINT8 ** ppData, /* location of sense data on device */ UINT32 * pSize /* size of sense data */ ) { *ppData = g_VendorSpecificData; *pSize = VENDOR_SPECIFIC_23_LENGTH; return(OK); }
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -