#ifndef _WIN_PASS_IOCTL_H_
#define _WIN_PASS_IOCTL_H_

#include "commdef.h"
#include "interface.h"

#include <iostream>
#include <tchar.h>
#include <wtypes.h>
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <winioctl.h>

#define FILE_DEVICE_CONTROLLER         						 0x00000004

#define IOCTL_SCSI_BASE                						 FILE_DEVICE_CONTROLLER
#define IOCTL_SCSI_MINIPORT                                  CTL_CODE(IOCTL_SCSI_BASE, 0x0402, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)   //0x0004D008  see NTDDSCSI.H for definition
#define IOCTL_SCSI_RESCAN_BUS                                CTL_CODE(IOCTL_SCSI_BASE, 0x0407, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_SCSI_PASS_THROUGH                              CTL_CODE(IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
#define IOCTL_SCSI_PASS_THROUGH_DIRECT                       CTL_CODE(IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)

#define ARCMSR_IOCTL_READ_RQBUFFER           0x90002004
#define ARCMSR_IOCTL_WRITE_WQBUFFER          0x90002008
#define ARCMSR_IOCTL_CLEAR_RQBUFFER          0x9000200C
#define ARCMSR_IOCTL_CLEAR_WQBUFFER          0x90002010
#define ARCMSR_IOCTL_CLEAR_ALLQBUFFER        0x90002014
#define ARCMSR_IOCTL_RETURN_CODE_3F          0x90002018
#define ARCMSR_IOCTL_SAY_HELLO               0x9000201C


// return code
#define	SRB_STATUS_SUCCESS			0x01
#define SRB_STATUS_INVALID_REQUEST	0x06


class ARCLIB_API WinPassIoctlInterface : public ArcInterface
{
	friend class CArclib;

public:     
	WinPassIoctlInterface();    
	~WinPassIoctlInterface();
	bool init(const int nScsiPort);
	int send(sIF_CMD_BLOCK *ifData);   
	int recv(sIF_CMD_BLOCK *ifData);       
	int syncSend(sIF_CMD_BLOCK *ifData);
	int	getMTU();
	void *getDeviceHandle();
	void requirelock();
	void releaselock();

private:
	BOOL ClearReadBuffer();
	BOOL ClearWriteBuffer();
	BOOL ClearReadWriteBuffer();
	HANDLE  m_hScsi;
	HANDLE  m_hSyncIm;
	PSECURITY_DESCRIPTOR    pSD;    
};

//
// SCSI CDB operation codes
//

#define SCSIOP_TEST_UNIT_READY     0x00
#define SCSIOP_REZERO_UNIT         0x01
#define SCSIOP_REWIND              0x01
#define SCSIOP_REQUEST_BLOCK_ADDR  0x02
#define SCSIOP_REQUEST_SENSE       0x03
#define SCSIOP_FORMAT_UNIT         0x04
#define SCSIOP_READ_BLOCK_LIMITS   0x05
#define SCSIOP_REASSIGN_BLOCKS     0x07
#define SCSIOP_READ6               0x08
#define SCSIOP_RECEIVE             0x08
#define SCSIOP_WRITE6              0x0A
#define SCSIOP_PRINT               0x0A
#define SCSIOP_SEND                0x0A
#define SCSIOP_SEEK6               0x0B
#define SCSIOP_TRACK_SELECT        0x0B
#define SCSIOP_SLEW_PRINT          0x0B
#define SCSIOP_SEEK_BLOCK          0x0C
#define SCSIOP_PARTITION           0x0D
#define SCSIOP_READ_REVERSE        0x0F
#define SCSIOP_WRITE_FILEMARKS     0x10
#define SCSIOP_FLUSH_BUFFER        0x10
#define SCSIOP_SPACE               0x11
#define SCSIOP_INQUIRY             0x12
#define SCSIOP_VERIFY6             0x13
#define SCSIOP_RECOVER_BUF_DATA    0x14
#define SCSIOP_MODE_SELECT         0x15
#define SCSIOP_RESERVE_UNIT        0x16
#define SCSIOP_RELEASE_UNIT        0x17
#define SCSIOP_COPY                0x18
#define SCSIOP_ERASE               0x19
#define SCSIOP_MODE_SENSE          0x1A
#define SCSIOP_START_STOP_UNIT     0x1B
#define SCSIOP_STOP_PRINT          0x1B
#define SCSIOP_LOAD_UNLOAD         0x1B
#define SCSIOP_RECEIVE_DIAGNOSTIC  0x1C
#define SCSIOP_SEND_DIAGNOSTIC     0x1D
#define SCSIOP_MEDIUM_REMOVAL      0x1E
#define SCSIOP_READ_CAPACITY       0x25
#define SCSIOP_READ                0x28
#define SCSIOP_WRITE               0x2A
#define SCSIOP_SEEK                0x2B
#define SCSIOP_LOCATE              0x2B
#define SCSIOP_WRITE_VERIFY        0x2E
#define SCSIOP_VERIFY              0x2F
#define SCSIOP_SEARCH_DATA_HIGH    0x30
#define SCSIOP_SEARCH_DATA_EQUAL   0x31
#define SCSIOP_SEARCH_DATA_LOW     0x32
#define SCSIOP_SET_LIMITS          0x33
#define SCSIOP_READ_POSITION       0x34
#define SCSIOP_SYNCHRONIZE_CACHE   0x35
#define SCSIOP_COMPARE             0x39
#define SCSIOP_COPY_COMPARE        0x3A
#define SCSIOP_WRITE_DATA_BUFF     0x3B
#define SCSIOP_READ_DATA_BUFF      0x3C
#define SCSIOP_CHANGE_DEFINITION   0x40
#define SCSIOP_READ_SUB_CHANNEL    0x42
#define SCSIOP_READ_TOC            0x43
#define SCSIOP_READ_HEADER         0x44
#define SCSIOP_PLAY_AUDIO          0x45
#define SCSIOP_PLAY_AUDIO_MSF      0x47
#define SCSIOP_PLAY_TRACK_INDEX    0x48
#define SCSIOP_PLAY_TRACK_RELATIVE 0x49
#define SCSIOP_PAUSE_RESUME        0x4B
#define SCSIOP_LOG_SELECT          0x4C
#define SCSIOP_LOG_SENSE           0x4D

#endif 