1 /* 2 * Copyright (c) 2003-2005 by Siarzhuk Zharski <imker@gmx.li> 3 * Distributed under the terms of the BSD License. 4 * 5 */ 6 #include "usb_scsi.h" 7 8 #include <strings.h> 9 #include "device_info.h" 10 #include "tracing.h" 11 12 #include "fake_device.h" 13 14 /* duplication! Hope this fake file will be not required in Haiku version*/ 15 #define INQ_VENDOR_LEN 0x08 16 #define INQ_PRODUCT_LEN 0x10 17 #define INQ_REVISION_LEN 0x04 18 19 20 void fake_inquiry_request(usb_device_info *udi, CCB_SCSIIO *ccbio) 21 { 22 uint8 *data = ccbio->cam_data_ptr; 23 if(ccbio->cam_ch.cam_flags & CAM_SCATTER_VALID){ 24 TRACE_ALWAYS("fake_inquiry: problems!!! scatter gatter ....=-(\n"); 25 } else { 26 memset(data, 0, ccbio->cam_dxfer_len); 27 /* data[0] = 0x1F;*/ /* we can play here with type of device */ 28 data[1] = 0x80; 29 data[2] = 0x02; 30 data[3] = 0x02; 31 data[4] = (0 != udi) ? 5 : 31; /* udi != 0 - mean FIX_NO_INQUIRY */ 32 if(ccbio->cam_dxfer_len >= 0x24){ 33 strncpy(&data[8], "USB SCSI", INQ_VENDOR_LEN); 34 strncpy(&data[16], "Reserved", INQ_PRODUCT_LEN); 35 strncpy(&data[32], "N/A", INQ_REVISION_LEN); 36 } 37 } 38 } 39 40 void fake_test_unit_ready_request(CCB_SCSIIO *ccbio) 41 { 42 if(ccbio->cam_sense_ptr != NULL){ 43 scsi_sense_data *sense_data = (scsi_sense_data *)ccbio->cam_sense_ptr; 44 memset(sense_data, 0, ccbio->cam_sense_len); 45 sense_data->error_code = SSD_CURRENT_ERROR; 46 sense_data->flags = SSD_KEY_NOT_READY; 47 ccbio->cam_ch.cam_status = CAM_REQ_CMP_ERR | CAM_AUTOSNS_VALID; 48 ccbio->cam_scsi_status = SCSI_STATUS_CHECK_CONDITION; 49 } else { 50 ccbio->cam_ch.cam_status = CAM_REQ_CMP_ERR; 51 ccbio->cam_scsi_status = SCSI_STATUS_OK; 52 } 53 } 54 55 /** 56 \fn:fake_scsi_io 57 \param ccbio: ???? 58 \return: ??? 59 60 xpt_scsi_io - handle XPT_SCSI_IO sim action 61 */ 62 status_t fake_scsi_io(CCB_SCSIIO *ccbio) 63 { 64 status_t status = B_BAD_VALUE; 65 uint8 *cmd; 66 scsi_cmd_generic *command; 67 if(ccbio->cam_ch.cam_flags & CAM_CDB_POINTER){ 68 cmd = ccbio->cam_cdb_io.cam_cdb_ptr; 69 }else{ 70 cmd = ccbio->cam_cdb_io.cam_cdb_bytes; 71 } 72 command = (scsi_cmd_generic *)cmd; 73 switch(command->opcode){ 74 case TEST_UNIT_READY:{ 75 fake_test_unit_ready_request(ccbio); 76 status = B_OK; 77 }break; 78 case INQUIRY:{ 79 fake_inquiry_request(NULL, ccbio); 80 ccbio->cam_ch.cam_status = CAM_REQ_CMP; 81 status = B_OK; 82 }break; 83 default: 84 ccbio->cam_ch.cam_status = CAM_REQ_INVALID; 85 break; 86 } 87 return status; 88 } 89