12db0303fSimker/**
22db0303fSimker *
32db0303fSimker * TODO: description
406437987SMatt Madia *
506437987SMatt Madia * This file is a part of USB SCSI CAM for Haiku.
62db0303fSimker * May be used under terms of the MIT License
72db0303fSimker *
82db0303fSimker * Author(s):
92db0303fSimker * 	Siarzhuk Zharski <imker@gmx.li>
1006437987SMatt Madia *
1106437987SMatt Madia *
12b3d94504SStephan Aßmus */
1306437987SMatt Madia#include "usb_scsi.h"
14b3d94504SStephan Aßmus
15b3d94504SStephan Aßmus#include <strings.h>
1606437987SMatt Madia#include "device_info.h"
1706437987SMatt Madia#include "tracing.h"
18b3d94504SStephan Aßmus
19b3d94504SStephan Aßmus#include "fake_device.h"
20b3d94504SStephan Aßmus
21b3d94504SStephan Aßmus/* duplication! Hope this fake file will be not required in Haiku version*/
222db0303fSimker#define INQ_VENDOR_LEN		0x08
232db0303fSimker#define INQ_PRODUCT_LEN		0x10
242db0303fSimker#define INQ_REVISION_LEN	0x04
25b3d94504SStephan Aßmus
26b3d94504SStephan Aßmusvoid fake_inquiry_request(usb_device_info *udi, CCB_SCSIIO *ccbio)
27b3d94504SStephan Aßmus{
282db0303fSimker	uint8 *data = ccbio->cam_data_ptr;
292db0303fSimker	if(ccbio->cam_ch.cam_flags & CAM_SCATTER_VALID){
302db0303fSimker		TRACE_ALWAYS("fake_inquiry: problems!!! scatter gatter ....=-(\n");
312db0303fSimker	} else {
322db0303fSimker		memset(data, 0, ccbio->cam_dxfer_len);
332db0303fSimker		/* data[0] = 0x1F;*/ /* we can play here with type of device */
342db0303fSimker		data[1] = 0x80;
352db0303fSimker		data[2] = 0x02;
362db0303fSimker		data[3] = 0x02;
372db0303fSimker		data[4] = (0 != udi) ? 5 : 31; /* udi != 0 - mean FIX_NO_INQUIRY */
382db0303fSimker		if(ccbio->cam_dxfer_len >= 0x24){
392db0303fSimker			strncpy(&data[8],  "USB SCSI", INQ_VENDOR_LEN);
402db0303fSimker			strncpy(&data[16], "Reserved", INQ_PRODUCT_LEN);
4106437987SMatt Madia			strncpy(&data[32], "N/A",      INQ_REVISION_LEN);
422db0303fSimker		}
432db0303fSimker	}
44b3d94504SStephan Aßmus}
45b3d94504SStephan Aßmus
46b3d94504SStephan Aßmusvoid fake_test_unit_ready_request(CCB_SCSIIO *ccbio)
47b3d94504SStephan Aßmus{
482db0303fSimker	if(ccbio->cam_sense_ptr != NULL){
492db0303fSimker		scsi_sense_data *sense_data = (scsi_sense_data *)ccbio->cam_sense_ptr;
502db0303fSimker		memset(sense_data, 0, ccbio->cam_sense_len);
512db0303fSimker		sense_data->error_code 	 = SSD_CURRENT_ERROR;
522db0303fSimker		sense_data->flags		 = SSD_KEY_NOT_READY;
532db0303fSimker		ccbio->cam_ch.cam_status = CAM_REQ_CMP_ERR | CAM_AUTOSNS_VALID;
542db0303fSimker		ccbio->cam_scsi_status	 = SCSI_STATUS_CHECK_CONDITION;
552db0303fSimker	} else {
562db0303fSimker		ccbio->cam_ch.cam_status = CAM_REQ_CMP_ERR;
572db0303fSimker		ccbio->cam_scsi_status	 = SCSI_STATUS_OK;
582db0303fSimker	}
59b3d94504SStephan Aßmus}
60b3d94504SStephan Aßmus
61b3d94504SStephan Aßmus/**
622db0303fSimker	\fn:fake_scsi_io
632db0303fSimker	\param ccbio: ????
642db0303fSimker	\return: ???
6506437987SMatt Madia
6606437987SMatt Madia	xpt_scsi_io - handle XPT_SCSI_IO sim action
67b3d94504SStephan Aßmus*/
68b3d94504SStephan Aßmusstatus_t fake_scsi_io(CCB_SCSIIO *ccbio)
69b3d94504SStephan Aßmus{
702db0303fSimker	status_t status = B_BAD_VALUE;
712db0303fSimker	uint8 *cmd;
722db0303fSimker	scsi_cmd_generic *command;
732db0303fSimker	if(ccbio->cam_ch.cam_flags & CAM_CDB_POINTER){
742db0303fSimker		cmd = ccbio->cam_cdb_io.cam_cdb_ptr;
752db0303fSimker	}else{
762db0303fSimker		cmd = ccbio->cam_cdb_io.cam_cdb_bytes;
772db0303fSimker	}
782db0303fSimker	command = (scsi_cmd_generic *)cmd;
792db0303fSimker	switch(command->opcode){
802db0303fSimker		case TEST_UNIT_READY:{
812db0303fSimker			fake_test_unit_ready_request(ccbio);
822db0303fSimker			status = B_OK;
832db0303fSimker		}break;
842db0303fSimker		case INQUIRY:{
852db0303fSimker			fake_inquiry_request(NULL, ccbio);
862db0303fSimker			ccbio->cam_ch.cam_status = CAM_REQ_CMP;
872db0303fSimker			status = B_OK;
882db0303fSimker		}break;
892db0303fSimker		default:
902db0303fSimker			ccbio->cam_ch.cam_status = CAM_REQ_INVALID;
912db0303fSimker		break;
922db0303fSimker	}
932db0303fSimker	return status;
94b3d94504SStephan Aßmus}
952db0303fSimker
96