Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

354 lines
10 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 2000
  3. Module Name:
  4. iscsi.h
  5. Abstract:
  6. This file contains iSCSI protocol related data structures.
  7. Revision History:
  8. --*/
  9. #ifndef _ISCSI_H_
  10. #define _ISCSI_H_
  11. #include "stdarg.h"
  12. #include "stddef.h"
  13. #include "stdio.h"
  14. #include "string.h"
  15. #include "ntddk.h"
  16. #include "scsi.h"
  17. #include "tdi.h"
  18. #include "tdikrnl.h"
  19. #include <ntddscsi.h>
  20. #include <ntdddisk.h>
  21. #include <ntddstor.h>
  22. #include <ntddtcp.h>
  23. #include "wmistr.h"
  24. #include "wdmguid.h"
  25. #include "devguid.h"
  26. //
  27. // MACRO to delay the thread execution. The parameter
  28. // gives the number of seconds to wait
  29. //
  30. #define DelayThreadExecution(x) { \
  31. \
  32. LARGE_INTEGER delayTime; \
  33. delayTime.QuadPart = -10000000L * x; \
  34. KeDelayExecutionThread( KernelMode, \
  35. FALSE, \
  36. &delayTime); \
  37. }
  38. #define IsEqual4Byte(a, b) ((*((PUCHAR) a)) == (*((PUCHAR) b)) && \
  39. (*((PUCHAR) a + 1)) == (*((PUCHAR) b + 1)) && \
  40. (*((PUCHAR) a + 2)) == (*((PUCHAR) b + 2)) && \
  41. (*((PUCHAR) a + 3)) == (*((PUCHAR) b + 3))
  42. #define IsEqual2Byte(a, b) ((*((PUCHAR) a)) == (*((PUCHAR) b)) && \
  43. (*((PUCHAR) a + 1)) == (*((PUCHAR) b + 1))
  44. #define CopyFourBytes(a, b) ((*((PUCHAR) a) = (*((PUCHAR) b)))); \
  45. ((*((PUCHAR) a + 1) = (*((PUCHAR) b + 1)))); \
  46. ((*((PUCHAR) a + 2) = (*((PUCHAR) b + 2)))); \
  47. ((*((PUCHAR) a + 3) = (*((PUCHAR) b + 3))));
  48. #define GetUlongFromArray(UCharArray, ULongValue) \
  49. ULongValue = 0; \
  50. ULongValue |= ((PUCHAR)UCharArray)[0]; \
  51. ULongValue <<= 8; \
  52. ULongValue |= ((PUCHAR)UCharArray)[1]; \
  53. ULongValue <<= 8; \
  54. ULongValue |= ((PUCHAR)UCharArray)[2]; \
  55. ULongValue <<= 8; \
  56. ULongValue |= ((PUCHAR)UCharArray)[3];
  57. #define SetUlongInArray(UCharArray, ULongValue) \
  58. ((PUCHAR) UCharArray)[0] = (UCHAR) ((ULongValue & 0xFF000000) >> 24); \
  59. ((PUCHAR) UCharArray)[1] = (UCHAR) ((ULongValue & 0x00FF0000) >> 16); \
  60. ((PUCHAR) UCharArray)[2] = (UCHAR) ((ULongValue & 0x0000FF00) >> 8); \
  61. ((PUCHAR) UCharArray)[3] = (UCHAR) (ULongValue & 0x000000FF);
  62. //
  63. // CDB Command Group Code
  64. //
  65. #define COMMAND_GROUP_0 0
  66. #define COMMAND_GROUP_1 1
  67. #define COMMAND_GROUP_2 2
  68. #define COMMAND_GROUP_5 5
  69. //
  70. // Maximum number of targets supported by the Initiator
  71. //
  72. #define MAX_TARGETS_SUPPORTED 8
  73. //
  74. // ISCSI Target Port Number
  75. //
  76. #define ISCSI_TARGET_PORT 5003L
  77. //
  78. // iSCSI Packet Operation Codes
  79. //
  80. #define ISCSIOP_NOP_OUT_MESSAGE 0x00
  81. #define ISCSIOP_SCSI_COMMAND 0x01
  82. #define ISCSIOP_SCSI_MGMT_COMMAND 0x02
  83. #define ISCSIOP_LOGIN_COMMAND 0x03
  84. #define ISCSIOP_TEXT_COMMAND 0x04
  85. #define ISCSIOP_SCSI_DATA_WRITE 0x05
  86. #define ISCSIOP_PING_COMMAND 0x09
  87. #define ISCSIOP_MAP_COMMAND 0x0A
  88. #define ISCSIOP_NOP_IN_MESSAGE 0x40
  89. #define ISCSIOP_SCSI_RESPONSE 0x41
  90. #define ISCSIOP_SCSI_MGMT_RESPONSE 0x42
  91. #define ISCSIOP_LOGIN_RESPONSE 0x43
  92. #define ISCSIOP_TEXT_RESPONSE 0x44
  93. #define ISCSIOP_SCSI_DATA_READ 0x45
  94. #define ISCSIOP_RTT 0x46
  95. #define ISCSIOP_ASYCN_EVENT 0x47
  96. #define ISCSIOP_UNKNOWN_OPCODE 0x48
  97. #define ISCSIOP_PING_RESPONSE 0x49
  98. #define ISCSIOP_MAP_RESPONSE 0x4A
  99. //
  100. // iSCSI Operation Code Mask
  101. //
  102. #define ISCSI_RETRY_COMMAND_RESPONSE 0xB7
  103. #define ISCSI_RESPONSE 0xB6
  104. //
  105. // Maximum and minimum values of iSCSI Opcode
  106. //
  107. #define ISCSI_MASK_MAX_OPCODE 0xB5
  108. #define ISCSI_MASK_MIN_OPCODE 0x00
  109. //
  110. // Task Attribute field (ATTR) in SCSI Command Packet
  111. //
  112. #define ISCSI_TASKATTR_UNTAGGED 0x00
  113. #define ISCSI_TASKATTR_SIMPLE 0x01
  114. #define ISCSI_TASKATTR_ORDERED 0x02
  115. #define ISCSI_TASKATTR_HEADOFQUEUE 0x03
  116. #define ISCSI_TASKATTR_ACA 0x04
  117. //
  118. // ISCSI Status
  119. //
  120. #define ISCSISTAT_GOOD 0x00
  121. #define ISCSISTAT_CHECK_CONDITION 0x01
  122. //
  123. // Login Type
  124. //
  125. #define ISCSI_LOGINTYPE_NONE 0x00 // No authentication
  126. #define ISCSI_LOGINTYPE_IMPLICIT 0x01
  127. #define ISCSI_LOGINTYPE_PW_ATHENTICATION 0x02 // Clear text password authentication
  128. #define ISCSI_LOGINTYPE_RSA_1_WAY 0x03
  129. #define ISCSI_LOGINTYPE_RSA_2_WAY 0x04
  130. //
  131. // Login Status
  132. //
  133. #define ISCSI_LOGINSTATUS_ACCEPT 0x00
  134. #define ISCSI_LOGINSTATUS_REJECT 0x01
  135. #define ISCSI_LOGINSTATUS_AUTH_REQ 0x02
  136. #define ISCSI_LOGINSTATUS_REJ_REC 0x03
  137. //
  138. // Forward declarations
  139. //
  140. typedef struct _ISCSI_LOGIN_COMMAND ISCSI_LOGIN_COMMAND, *PISCSI_LOGIN_COMMAND;
  141. typedef struct _ISCSI_LOGIN_RESPONSE ISCSI_LOGIN_RESPONSE, *PISCSI_LOGIN_RESPONSE;
  142. typedef struct _ISCSI_SCSI_COMMAND ISCSI_SCSI_COMMAND, *PISCSI_SCSI_COMMAND;
  143. typedef struct _ISCSI_SCSI_RESPONSE ISCSI_SCSI_RESPONSE, *PISCSI_SCSI_RESPONSE;
  144. typedef struct _ISCSI_GENERIC_HEADER ISCSI_GENERIC_HEADER, *PISCSI_GENERIC_HEADER;
  145. typedef struct _ISCSI_SCSI_DATA_READ ISCSI_SCSI_DATA_READ, *PISCSI_SCSI_DATA_READ;
  146. typedef struct _ISCSI_NOP_IN ISCSI_NOP_IN, *PISCSI_NOP_IN;
  147. typedef struct _ISCSI_NOP_OUT ISCSI_NOP_OUT, *PISCSI_NOP_OUT;
  148. //
  149. // iSCSI message\response header
  150. //
  151. typedef union _ISCSI_HEADER {
  152. //
  153. // Generic 48-Byte Header
  154. //
  155. struct _ISCSI_GENERIC_HEADER {
  156. UCHAR OpCode;
  157. UCHAR OpCodeSpecificFields1[3];
  158. UCHAR Length[4];
  159. UCHAR OpCodeSpecificFields2[8];
  160. UCHAR InitiatorTaskTag[4];
  161. UCHAR OpCodeSpecificFields3[28];
  162. } ISCSI_GENERIC_HEADER, *PISCSI_GENERIC_HEADER;
  163. //
  164. // iSCSI Login command
  165. //
  166. struct _ISCSI_LOGIN_COMMAND {
  167. UCHAR OpCode; // 0x03 - ISCSIOP_LOGIN_COMMAND
  168. UCHAR LoginType;
  169. UCHAR Reserved1[2];
  170. UCHAR Length[4];
  171. UCHAR ConnectionID[2];
  172. UCHAR RecoveredConnectionID[2];
  173. UCHAR Reserved2[4];
  174. UCHAR ISID[2];
  175. UCHAR TSID[2];
  176. UCHAR Reserved3[4];
  177. UCHAR InitCmdRN[4];
  178. UCHAR Reserved4[20];
  179. } ISCSI_LOGIN_COMMAND, *PISCSI_LOGIN_COMMAND;
  180. //
  181. // iSCSI Login response
  182. //
  183. struct _ISCSI_LOGIN_RESPONSE {
  184. UCHAR OpCode; // 0x43 - ISCSIOP_LOGIN_RESPONSE
  185. UCHAR Reserved1[3];
  186. UCHAR Length[4];
  187. UCHAR Reserved2[8];
  188. UCHAR ISID[2];
  189. UCHAR TSID[2];
  190. UCHAR Reserved3[4];
  191. UCHAR InitStatRN[4];
  192. UCHAR ExpCmdRN[4];
  193. UCHAR MaxCmdRN[4];
  194. UCHAR Status;
  195. UCHAR Reserved4[3];
  196. UCHAR Reserved5[8];
  197. } ISCSI_LOGIN_RESPONSE, *PISCSI_LOGIN_RESPONSE;
  198. //
  199. // iSCSI SCSI Command
  200. //
  201. struct _ISCSI_SCSI_COMMAND {
  202. UCHAR OpCode; // 0x01 - ISCSIOP_SCSI_COMMAND
  203. UCHAR Reserved1 : 5;
  204. UCHAR Read : 1;
  205. UCHAR ImmediateData : 2;
  206. UCHAR ATTR : 3;
  207. UCHAR Reserved2 : 4;
  208. UCHAR TurnOffAutoSense : 1;
  209. UCHAR Reserved3;
  210. UCHAR Length[4];
  211. UCHAR LogicalUnitNumber[8];
  212. UCHAR TaskTag[4];
  213. UCHAR ExpDataXferLength[4];
  214. UCHAR CmdRN[4];
  215. UCHAR ExpStatRN[4];
  216. UCHAR Cdb[16];
  217. } ISCSI_SCSI_COMMAND, *PISCSI_SCSI_COMMAND;
  218. //
  219. // iSCSI SCSI Response
  220. //
  221. struct _ISCSI_SCSI_RESPONSE {
  222. UCHAR OpCode; // 0x41 - ISCSIOP_SCSI_RESPONSE
  223. UCHAR Reserved1 : 6;
  224. UCHAR OverFlow : 1;
  225. UCHAR UnderFlow : 1;
  226. UCHAR Reserved2[2];
  227. UCHAR Length[4];
  228. UCHAR Reserved3[8];
  229. UCHAR TaskTag[4];
  230. UCHAR ResidualCount[4];
  231. UCHAR StatusRN[4];
  232. UCHAR ExpCmdRN[4];
  233. UCHAR MaxCmdRN[4];
  234. UCHAR CmdStatus;
  235. UCHAR iSCSIStatus;
  236. UCHAR Reserved4[2];
  237. UCHAR ResponseLength[2];
  238. UCHAR SenseDataLength[2];
  239. UCHAR Reserved5[4];
  240. } ISCSI_SCSI_RESPONSE, *PISCSI_SCSI_RESPONSE;
  241. //
  242. // iSCSSI SCSI Data (WRITE - Initiator to Target)
  243. //
  244. struct _ISCSI_SCSI_DATA_WRITE {
  245. UCHAR OpCode; // 0x05 - ISCSIOP_SCSI_DATA_WRITE
  246. UCHAR Reserved1[3];
  247. UCHAR Length[4];
  248. UCHAR BufferOffset[4];
  249. UCHAR TransferTag[4];
  250. UCHAR InitiatorTransferTag[4];
  251. UCHAR Reserved2[8];
  252. UCHAR CmdRN[4];
  253. UCHAR ExpStatRN[4];
  254. UCHAR Reserved[12];
  255. } ISCSI_SCSI_DATA_WRITE, *PISCSI_SCSI_DATA_WRITE;
  256. //
  257. // iSCSSI SCSI Data (READ - Target to Initiator)
  258. //
  259. struct _ISCSI_SCSI_DATA_READ {
  260. UCHAR OpCode; // 0x45 - ISCSIOP_SCSI_DATA_READ
  261. UCHAR UnderFlow : 1;
  262. UCHAR OverFlow : 1;
  263. UCHAR IsScsiStatus : 1;
  264. UCHAR Reserved1 : 5;
  265. UCHAR Reserved2[2];
  266. UCHAR Length[4];
  267. UCHAR BufferOffset[4];
  268. UCHAR TransferTag[4];
  269. UCHAR InitiatorTransferTag[4];
  270. UCHAR ResidualCount[4];
  271. UCHAR StatusRN[4];
  272. UCHAR ExpCmdRN[4];
  273. UCHAR MaxCmdRN[4];
  274. UCHAR CommandStatus;
  275. UCHAR ISCSIStatus;
  276. UCHAR Reserved3[2];
  277. UCHAR Reserved4[8];
  278. } ISCSI_SCSI_DATA_READ, *PISCSI_SCSI_DATA_READ;
  279. //
  280. // iSCSI NOP-IN
  281. //
  282. struct _ISCSI_NOP_IN {
  283. UCHAR OpCode; // 0x40 - ISCSIOP_NOP_IN_MESSAGE
  284. UCHAR Reserved1 : 7;
  285. UCHAR Poll : 1;
  286. UCHAR Reserved2[2];
  287. UCHAR Length[4];
  288. UCHAR Reserved3[20];
  289. UCHAR ExpCmdRN[4];
  290. UCHAR MaxCmdRN[4];
  291. UCHAR Reserved4[12];
  292. } ISCSI_NOP_IN, *PISCSI_NOP_IN;
  293. //
  294. // iSCSI NOP-OUT
  295. //
  296. struct _ISCSI_NOP_OUT {
  297. UCHAR OpCode; // 0x00 - ISCSIOP_NOP_OUT_MESSAGE
  298. UCHAR Reserved1 : 7;
  299. UCHAR Poll : 1;
  300. UCHAR Reserved2[2];
  301. UCHAR Length[4];
  302. UCHAR Reserved3[20];
  303. UCHAR ExpStatRN[4];
  304. UCHAR Reserved4[16];
  305. } ISCSI_NOP_OUT, *PISCSI_NOP_OUT;
  306. } ISCSI_HEADER, *PISCSI_HEADER;
  307. #endif // _ISCSI_H_