Aspi.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. #ifndef ASPI_INCLUDED
  2. #define ASPI_INCLUDED
  3. #include <Windows.h>
  4. #include <Stdio.h>
  5. #include <Stdlib.h>
  6. // Handle to the ASPI libaray
  7. extern HINSTANCE hAspiLib;
  8. void GetAspiError(int nErrorCode,LPSTR lpszError);
  9. // 1 byte alignment or SCSI structures
  10. #pragma pack(push,1)
  11. #define MAX_SCSIDEVICES 16
  12. #define TIMEOUT 10000
  13. typedef void (*POSTPROCFUNC)();
  14. typedef struct TOC_TAG
  15. {
  16. BYTE _reserved1;
  17. BYTE bFlags;
  18. BYTE bTrack;
  19. BYTE _reserved2;
  20. DWORD dwStartSector;
  21. } TOC;
  22. // The SRB_Flags are defined below. These flags may be OR'd together to form
  23. // the final value for SRB_Flags in the SRB. Note that SRB_POSTING and
  24. // SRB_EVENT_NOTIFY are mutually exclusive, as are SRB_DIR_IN and SRB_DIR_OUT. In
  25. // addition, the directioin bits (SRB_DIR_IN and SRB_DIR_OUT) MUST be set
  26. // correctly on commands which transfer data. Using SRB_DIR_SCSI is no longer
  27. // an option as in ASPI for DOS and ASPI for Win16.
  28. #define SRB_POSTING 0x01 // Enable ASPI command completion posting. See section on posting below.
  29. #define SRB_ENABLE_RESIDUAL_COUNT 0x04 // Enables reporting of residual byte count.This flag is only significant if the host adapter reports support for residual byte count in the SC_HA_INQUIRY command. When data underrun occurs, the SRB_BufLen field is updated to reflect the remaining bytes to transfer.
  30. #define SRB_DIR_IN 0x08 // Data transfer from SCSI target to host.
  31. #define SRB_DIR_OUT 0x10 // Data transfer from host to SCSI target.
  32. #define SRB_EVENT_NOTIFY 0x40 // Enable ASPI command event notification. See section on event notification below.
  33. // Inquiry DeviceTypeCodes
  34. #define DTC_DISK 0x00 // Direct-access device
  35. #define DTC_TAPE 0x01 // Sequential-access device
  36. #define DTC_PRINTER 0x02 // Printer device
  37. #define DTC_PROCESSOR 0x03 // Processor device
  38. #define DTC_WORM 0x04 // Write-once device
  39. #define DTC_CDROM 0x05 // CD-ROM device
  40. #define DTC_SCANNER 0x06 // Scanner device
  41. #define DTC_OPTICAL 0x07 // Optical memory device
  42. #define DTC_JUKEBOX 0x08 // Medium changer device
  43. #define DTC_COMM 0x09 // Communications device
  44. #define DTC_PREPRESS1 0x0A // Pre-press device 1
  45. #define DTC_PREPRESS2 0x0B // Pre-press device 2
  46. #define DTC_UNKNOWN 0x1F // Unknown or no device type
  47. /***************************************************************************
  48. ** SRB Status
  49. ***************************************************************************/
  50. #define SS_PENDING 0x00 /* SRB being processed */
  51. #define SS_COMP 0x01 /* SRB completed without error */
  52. #define SS_ABORTED 0x02 /* SRB aborted */
  53. #define SS_ABORT_FAIL 0x03 /* Unable to abort SRB */
  54. #define SS_ERR 0x04 /* SRB completed with error */
  55. #define SS_INVALID_CMD 0x80 /* Invalid ASPI command */
  56. #define SS_INVALID_HA 0x81 /* Invalid host adapter number */
  57. #define SS_NO_DEVICE 0x82 /* SCSI device not installed */
  58. #define SS_INVALID_SRB 0xE0 /* Invalid parameter set in SRB */
  59. #define SS_OLD_MANAGER 0xE1 /* ASPI manager doesn't support */
  60. /* windows */
  61. #define SS_BUFFER_ALIGN 0xE1 /* Buffer not aligned (replaces */
  62. /* SS_OLD_MANAGER in Win32) */
  63. #define SS_ILLEGAL_MODE 0xE2 /* Unsupported Windows mode */
  64. #define SS_NO_ASPI 0xE3 /* No ASPI managers */
  65. #define SS_FAILED_INIT 0xE4 /* ASPI for windows failed init */
  66. #define SS_ASPI_IS_BUSY 0xE5 /* No resources available to */
  67. /* execute command */
  68. #define SS_BUFFER_TO_BIG 0xE6 /* Buffer size too big to handle */
  69. #define SS_BUFFER_TOO_BIG 0xE6 /* Correct spelling of 'too' */
  70. #define SS_MISMATCHED_COMPONENTS 0xE7 /* The DLLs/EXEs of ASPI don't */
  71. /* version check */
  72. #define SS_NO_ADAPTERS 0xE8 /* No host adapters to manager */
  73. #define SS_INSUFFICIENT_RESOURCES 0xE9 /* Couldn't allocate resources */
  74. /* needed to init */
  75. #define SS_ASPI_IS_SHUTDOWN 0xEA /* Call came to ASPI after */
  76. /* PROCESS_DETACH */
  77. #define SS_BAD_INSTALL 0xEB /* The DLL or other components */
  78. /* are installed wrong */
  79. // SRB defines
  80. #define SC_HA_INQUIRY 0x00 // Get information about installed host adapters,including the number of installed adapters.
  81. #define SC_GET_DEV_TYPE 0x01 // Get information about installed SCSI devices.
  82. #define SC_EXEC_SCSI_CMD 0x02 // Execute SCSI I/O.
  83. #define SC_ABORT_SRB 0x03 // Abort an outstanding I/O request.
  84. #define SC_RESET_DEV 0x04 // Reset an individual SCSI target.
  85. #define SC_GET_DISK_INFO 0x06 // Get information on disk type SCSI devices (not available under Windows NT).
  86. #define SC_GETSET_TIMEOUTS 0x08
  87. // MISC defines
  88. #define CDSAMPLEFREQ 44100
  89. #define TRACKSPERSEC 75
  90. #define CB_CDDASECTOR 2352
  91. #define CB_QSUBCHANNEL 0
  92. #define CB_CDROMSECTOR 2048
  93. #define CB_AUDIO (CB_CDDASECTOR-CB_QSUBCHANNEL)
  94. typedef struct
  95. {
  96. BYTE SRB_Cmd; // ASPI command code
  97. BYTE SRB_Status; // ASPI command status byte
  98. BYTE SRB_HaId; // ASPI host adapter number
  99. BYTE SRB_Flags; // ASPI request flags
  100. DWORD SRB_Hdr_Rsvd; // Reserved, MUST = 0
  101. } SRB_HEADER, *LPSRB;
  102. typedef struct
  103. {
  104. BYTE SRB_Cmd; // ASPI command code = SC_HA_INQUIRY
  105. BYTE SRB_Status; // ASPI command status byte
  106. BYTE SRB_HaId; // ASPI host adapter number
  107. BYTE SRB_Flags; // ASPI request flags
  108. DWORD SRB_Hdr_Rsvd; // Reserved, MUST = 0
  109. BYTE HA_Count; // Number of host adapters present
  110. BYTE HA_SCSI_ID; // SCSI ID of host adapter
  111. BYTE HA_ManagerId[16]; // String describing the manager
  112. BYTE HA_Identifier[16]; // String describing the host adapter
  113. BYTE HA_Unique[16]; // Host Adapter Unique parameters
  114. WORD HA_Rsvd1;
  115. } SRB_HAINQUIRY, *LPSRB_HAINQUIRY;
  116. typedef struct
  117. {
  118. BYTE SRB_Cmd; // ASPI command code = SC_GET_DEV_TYPE
  119. BYTE SRB_Status; // ASPI command status byte
  120. BYTE SRB_HaId; // ASPI host adapter number
  121. BYTE SRB_Flags; // Reserved
  122. DWORD SRB_Hdr_Rsvd; // Reserved
  123. BYTE SRB_Target; // Target's SCSI ID
  124. BYTE SRB_Lun; // Target's LUN number
  125. BYTE SRB_DeviceType; // Target's peripheral device type
  126. BYTE SRB_Rsvd1; // Reserved for alignment
  127. } SRB_GDEVBLOCK, *LPSRB_GDEVBLOCK;
  128. #define SENSE_LEN 14 // Maximum sense length
  129. typedef struct
  130. {
  131. BYTE SRB_Cmd; // ASPI command code = SC_EXEC_SCSI_CMD
  132. BYTE SRB_Status; // ASPI command status byte
  133. BYTE SRB_HaId; // ASPI host adapter number
  134. BYTE SRB_Flags; // ASPI request flags
  135. DWORD SRB_Hdr_Rsvd; // Reserved
  136. BYTE SRB_Target; // Target's SCSI ID
  137. BYTE SRB_Lun; // Target's LUN number
  138. WORD SRB_Rsvd1; // Reserved for Alignment
  139. DWORD SRB_BufLen; // Data Allocation Length
  140. BYTE *SRB_BufPointer; // Data Buffer Point
  141. BYTE SRB_SenseLen; // Sense Allocation Length
  142. BYTE SRB_CDBLen; // CDB Length
  143. BYTE SRB_HaStat; // Host Adapter Status
  144. BYTE SRB_TargStat; // Target Status
  145. void (*SRB_PostProc)(); // Post routine
  146. void *SRB_Rsvd2; // Reserved
  147. BYTE SRB_Rsvd3[16]; // Reserved for expansion
  148. BYTE CDBByte[16]; // SCSI CDB
  149. BYTE SenseArea[SENSE_LEN+2]; // Request Sense buffer
  150. } SRB_EXECSCSICMD, *LPSRB_EXECSCSICMD;
  151. typedef struct
  152. {
  153. BYTE SRB_Cmd; // ASPI command code = SC_EXEC_SCSI_CMD
  154. BYTE SRB_Status; // ASPI command status byte
  155. BYTE SRB_HaId; // ASPI host adapter number
  156. BYTE SRB_Flags; // Reserved
  157. DWORD SRB_Hdr_Rsvd; // Reserved
  158. BYTE SRB_Target; // Target's SCSI ID
  159. BYTE SRB_Lun; // Target's LUN number
  160. BYTE SRB_DriveFlags; // Driver flags
  161. BYTE SRB_Int13HDriveInfo;// Host Adapter Status
  162. BYTE SRB_Heads; // Preferred number of heads translation
  163. BYTE SRB_Sectors; // Preferred number of sectors translation
  164. BYTE SRB_Rsvd1[10]; // Reserved
  165. } SRB_GETDISKINFO, *LPSRB_GETDISKINFO;
  166. typedef struct
  167. {
  168. BYTE SRB_Cmd; // ASPI command code = SC_RESET_DEV
  169. BYTE SRB_Status; // ASPI command status byte
  170. BYTE SRB_HaId; // ASPI host adapter number
  171. BYTE SRB_Flags; // Reserved
  172. DWORD SRB_Hdr_Rsvd; // Reserved
  173. BYTE SRB_Target; // Target's SCSI ID
  174. BYTE SRB_Lun; // Target's LUN number
  175. BYTE SRB_Rsvd1[12]; // Reserved for Alignment
  176. BYTE SRB_HaStat; // Host Adapter Status
  177. BYTE SRB_TargStat; // Target Status
  178. void *SRB_PostProc; // Post routine
  179. void *SRB_Rsvd2; // Reserved
  180. BYTE SRB_Rsvd3[32]; // Reserved
  181. } SRB_BUSDEVICERESET, *LPSRB_BUSDEVICERESET;
  182. typedef struct
  183. {
  184. BYTE SRB_Cmd; /* 00/000 ASPI cmd code == SC_ABORT_SRB */
  185. BYTE SRB_Status; /* 01/001 ASPI command status byte */
  186. BYTE SRB_HaID; /* 02/002 ASPI host adapter number */
  187. BYTE SRB_Flags; /* 03/003 Reserved, must = 0 */
  188. DWORD SRB_Hdr_Rsvd; /* 04/004 Reserved, must = 0 */
  189. void *SRB_ToAbort; /* 08/008 Pointer to SRB to abort */
  190. } SRB_Abort, *PSRB_Abort, FAR *LPSRB_Abort;
  191. typedef unsigned char Ucbit;
  192. typedef unsigned char u_char;
  193. #define MP_P_CODE \
  194. Ucbit p_code : 6; \
  195. Ucbit p_res : 1; \
  196. Ucbit parsave : 1
  197. // CD Cap / mech status
  198. typedef struct SCSICDMODEPAGE2A_TAG
  199. {
  200. MP_P_CODE; // parsave & pagecode (0)
  201. u_char p_len; // 0x14 = 20 Bytes (1)
  202. Ucbit cd_r_read : 1; // Reads CD-R media (2)
  203. Ucbit cd_rw_read : 1; // Reads CD-RW media
  204. Ucbit method2 : 1; // Reads fixed packet method2 media
  205. Ucbit dvd_rom_read: 1; // Reads DVD ROM media
  206. Ucbit dvd_r_read : 1; // Reads DVD-R media
  207. Ucbit dvd_ram_read: 1; // Reads DVD-RAM media
  208. Ucbit res_2_67 : 2; // Reserved
  209. Ucbit cd_r_write : 1; // Supports writing CD-R media (3)
  210. Ucbit cd_rw_write : 1; // Supports writing CD-RW media
  211. Ucbit test_write : 1; // Supports emulation write
  212. Ucbit res_3_3 : 1; // Reserved
  213. Ucbit dvd_r_write : 1; // Supports writing DVD-R media
  214. Ucbit dvd_ram_write: 1; // Supports writing DVD-RAM media
  215. Ucbit res_3_67 : 2; // Reserved
  216. Ucbit audio_play : 1; // Supports Audio play operation (4)
  217. Ucbit composite : 1; // Deliveres composite A/V stream
  218. Ucbit digital_port_2: 1; // Supports digital output on port 2
  219. Ucbit digital_port_1: 1; // Supports digital output on port 1
  220. Ucbit mode_2_form_1: 1; // Reads Mode-2 form 1 media (XA)
  221. Ucbit mode_2_form_2: 1; // Reads Mode-2 form 2 media
  222. Ucbit multi_session: 1; // Reads multi-session media
  223. Ucbit res_4 : 1; // Reserved
  224. Ucbit cd_da_supported: 1; // Reads audio data with READ CD cmd
  225. Ucbit cd_da_accurate: 1; // READ CD data stream is accurate
  226. Ucbit rw_supported: 1; // Reads R-W sub channel information
  227. Ucbit rw_deint_cor: 1; // Reads de-interleved R-W sub chan
  228. Ucbit c2_pointers : 1; // Supports C2 error pointers
  229. Ucbit ISRC : 1; // Reads ISRC information
  230. Ucbit UPC : 1; // Reads media catalog number (UPC)
  231. Ucbit read_bar_code: 1; // Supports reading bar codes
  232. Ucbit lock : 1; // PREVENT/ALLOW may lock media (5)
  233. Ucbit lock_state : 1; // Lock state 0=unlocked 1=locked
  234. Ucbit prevent_jumper: 1; // State of prev/allow jumper 0=pres
  235. Ucbit eject : 1; // Ejects disc/cartr with STOP LoEj
  236. Ucbit res_6_4 : 1; // Reserved
  237. Ucbit loading_type: 3; // Loading mechanism type
  238. Ucbit sep_chan_vol: 1; // Vol controls each channel separat (6)
  239. Ucbit sep_chan_mute: 1; // Mute controls each channel separat
  240. Ucbit disk_present_rep:1; // Changer supports disk present rep
  241. Ucbit sw_slot_sel:1; // Load empty slot in changer
  242. Ucbit res_7 : 4; // Reserved
  243. BYTE ReadSpeedH; // Max. read speed in KB/s (7)
  244. BYTE ReadSpeedL; // Max. read speed in KB/s (7)
  245. u_char num_vol_levels[2]; // # of supported volume levels (9)
  246. u_char buffer_size[2]; // Buffer size for the data in KB (11)
  247. u_char cur_read_speed[2]; // Current read speed in KB/s (13)
  248. u_char res_16; // Reserved (14)
  249. Ucbit res_17_0: 1; // Reserved (15)
  250. Ucbit BCK : 1; // Data valid on falling edge of BCK
  251. Ucbit RCK : 1; // Set: HIGH high LRCK=left channel
  252. Ucbit LSBF : 1; // Set: LSB first Clear: MSB first
  253. Ucbit length : 2; // 0=32BCKs 1=16BCKs 2=24BCKs 3=24I2c
  254. Ucbit res_17 : 2; // Reserved
  255. u_char max_write_speed[2]; // Max. write speed supported in KB/s (17)
  256. u_char cur_write_speed[2]; // Current write speed in KB/s (19)
  257. } SCSICDMODEPAGE2A;
  258. char *fillbytes(void *tov, int cnt, char val);
  259. typedef struct SCISMODEHEADER_TAG {
  260. Ucbit sense_data_len : 8;
  261. u_char medium_type;
  262. Ucbit res2 : 4;
  263. Ucbit cache : 1;
  264. Ucbit res : 2;
  265. Ucbit write_prot : 1;
  266. BYTE nBlockLen;
  267. } SCISMODEHEADER;
  268. typedef struct SCSIMODEHDR_6_TAG {
  269. BYTE btModeDataLen; // 0
  270. BYTE btMediumType; // 1
  271. BYTE btDevSpecificParam; // 2
  272. BYTE btBlkDescrLen; // 3
  273. } SCSIMODEHDR_6;
  274. typedef struct SCSIMODEHDR_10_TAG {
  275. BYTE btModeDataLenH; // 0
  276. BYTE btModeDataLenL; // 1
  277. BYTE btMediumType; // 2
  278. BYTE btDevSpecificParam; // 3
  279. BYTE btReserved1; // 4
  280. BYTE btReserved2; // 5
  281. BYTE btBlkDescrLenH; // 6
  282. BYTE btBlkDescrLenL; // 7
  283. } SCSIMODEHDR_10;
  284. typedef struct SCSIBLOCKDESCRIPTOR_TAG {
  285. BYTE btDensity; // 0
  286. BYTE btNumberOfBlocksH; // 1
  287. BYTE btNumberOfBlocksM; // 2
  288. BYTE btNumberOfBlocksL; // 3
  289. BYTE btReserved; // 4
  290. BYTE btBlockLenH; // 5
  291. BYTE btBlockLenM; // 6
  292. BYTE btBlockLenL; // 7
  293. } SCSIBLOCKDESCRIPTOR;
  294. // Error recovery Parameters
  295. typedef struct SCSICDMODEPAGE1A_TAG{
  296. MP_P_CODE; // 0 parsave & pagecode
  297. u_char p_len; // 1 0x0A = 12 Bytes
  298. Ucbit disa_correction : 1; // 2 Byte 2
  299. Ucbit term_on_rec_err : 1;
  300. Ucbit report_rec_err : 1;
  301. Ucbit en_early_corr : 1;
  302. Ucbit read_continuous : 1;
  303. Ucbit tranfer_block : 1;
  304. Ucbit en_auto_reall_r : 1;
  305. Ucbit en_auto_reall_w : 1;
  306. u_char rd_retry_count; // 3 Byte 3
  307. u_char correction_span; // 4
  308. char head_offset_count; // 5
  309. char data_strobe_offset; // 6
  310. u_char res; // 7
  311. u_char wr_retry_count; // 8
  312. u_char res_tape[2]; // 9
  313. u_char recov_timelim[2]; // 11
  314. } SCSICDMODEPAGE1A;
  315. typedef struct
  316. {
  317. BYTE SRB_Cmd; // ASPI command code = SC_GETSET_TIMEOUTS
  318. BYTE SRB_Status; // ASPI command status byte
  319. BYTE SRB_HaId; // ASPI host adapter number
  320. BYTE SRB_Flags; // ASPI request flags
  321. DWORD SRB_Hdr_Rsvd; // Reserved
  322. BYTE SRB_Target; // Target's SCSI ID
  323. BYTE SRB_Lun; // Target's LUN number
  324. DWORD SRB_Timeout; // Timeout in half seconds
  325. }
  326. SRB_GetSetTimeouts, *PSRB_GetSetTimeouts;
  327. typedef struct
  328. {
  329. LPBYTE AB_BufPointer; // Pointer to the ASPI allocated buffer
  330. DWORD AB_BufLen; // Length in bytes of the buffer
  331. DWORD AB_ZeroFill; // Flag set to 1 if buffer should be zeroed
  332. DWORD AB_Reserved; // Reserved, MUST = 0
  333. }
  334. ASPI32BUFF, *PASPI32BUFF;
  335. #pragma pack(pop)
  336. #endif