Leaked source code of windows server 2003
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.

1341 lines
54 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. Afd.h
  5. Abstract:
  6. Contains structures and declarations for AFD. AFD stands for the
  7. Ancillary Function Driver. This driver enhances the functionality
  8. of TDI so that it is a sufficiently rich interface to support
  9. user-mode sockets and XTI DLLs.
  10. Author:
  11. David Treadwell (davidtr) 20-Feb-1992
  12. Revision History:
  13. --*/
  14. #ifndef _AFD_
  15. #define _AFD_
  16. //
  17. // If WINSOCK2.H has not been included, then just embed the definition
  18. // of the WSABUF and QOS structures here. This makes building AFD.SYS
  19. // much easier.
  20. //
  21. #ifndef _WINSOCK2API_
  22. typedef struct _WSABUF {
  23. ULONG len;
  24. PCHAR buf;
  25. } WSABUF, *LPWSABUF;
  26. #include <qos.h>
  27. typedef struct _QualityOfService
  28. {
  29. FLOWSPEC SendingFlowspec; /* the flow spec for data sending */
  30. FLOWSPEC ReceivingFlowspec; /* the flow spec for data receiving */
  31. WSABUF ProviderSpecific; /* additional provider specific stuff */
  32. } QOS, *LPQOS;
  33. #define MSG_TRUNC 0x0100
  34. #define MSG_CTRUNC 0x0200
  35. #define MSG_BCAST 0x0400
  36. #define MSG_MCAST 0x0800
  37. #endif
  38. #define AFD_DEVICE_NAME L"\\Device\\Afd"
  39. //
  40. // Endpoint flags computed based on Winsock2 provider flags
  41. // and socket type
  42. //
  43. typedef struct _AFD_ENDPOINT_FLAGS {
  44. union {
  45. struct {
  46. BOOLEAN ConnectionLess :1;
  47. BOOLEAN :3; // This spacing makes strcutures
  48. // much more readable (hex) in the
  49. // debugger and has no effect
  50. // on the generated code as long
  51. // as number of flags is less than
  52. // 8 (we still take up full 32 bits
  53. // because of aligment requiremens
  54. // of most other fields)
  55. BOOLEAN MessageMode :1;
  56. BOOLEAN :3;
  57. BOOLEAN Raw :1;
  58. BOOLEAN :3;
  59. BOOLEAN Multipoint :1;
  60. BOOLEAN :3;
  61. BOOLEAN C_Root :1;
  62. BOOLEAN :3;
  63. BOOLEAN D_Root :1;
  64. BOOLEAN :3;
  65. };
  66. ULONG EndpointFlags; // Flags are as fine as bit fields,
  67. // but create problems when we need
  68. // to cast them to boolean.
  69. };
  70. #define AFD_ENDPOINT_FLAG_CONNECTIONLESS 0x00000001
  71. #define AFD_ENDPOINT_FLAG_MESSAGEMODE 0x00000010
  72. #define AFD_ENDPOINT_FLAG_RAW 0x00000100
  73. //
  74. // Old AFD_ENDPOINT_TYPE mappings. Flags make things clearer at
  75. // at the TDI level and after all Winsock2 switched to provider flags
  76. // instead of socket type anyway (ATM for example needs connection oriented
  77. // raw sockets, which can only be reflected by SOCK_RAW+SOCK_STREAM combination
  78. // which does not exists).
  79. //
  80. #define AfdEndpointTypeStream 0
  81. #define AfdEndpointTypeDatagram (AFD_ENDPOINT_FLAG_CONNECTIONLESS|\
  82. AFD_ENDPOINT_FLAG_MESSAGEMODE)
  83. #define AfdEndpointTypeRaw (AFD_ENDPOINT_FLAG_CONNECTIONLESS|\
  84. AFD_ENDPOINT_FLAG_MESSAGEMODE|\
  85. AFD_ENDPOINT_FLAG_RAW)
  86. #define AfdEndpointTypeSequencedPacket (AFD_ENDPOINT_FLAG_MESSAGEMODE)
  87. #define AfdEndpointTypeReliableMessage (AFD_ENDPOINT_FLAG_MESSAGEMODE)
  88. //
  89. // New multipoint semantics
  90. //
  91. #define AFD_ENDPOINT_FLAG_MULTIPOINT 0x00001000
  92. #define AFD_ENDPOINT_FLAG_CROOT 0x00010000
  93. #define AFD_ENDPOINT_FLAG_DROOT 0x00100000
  94. #define AFD_ENDPOINT_VALID_FLAGS 0x00111111
  95. } AFD_ENDPOINT_FLAGS;
  96. //
  97. // Structures used on NtCreateFile() for AFD.
  98. //
  99. typedef struct _AFD_OPEN_PACKET {
  100. AFD_ENDPOINT_FLAGS __f;
  101. #define afdConnectionLess __f.ConnectionLess
  102. #define afdMessageMode __f.MessageMode
  103. #define afdRaw __f.Raw
  104. #define afdMultipoint __f.Multipoint
  105. #define afdC_Root __f.C_Root
  106. #define afdD_Root __f.D_Root
  107. #define afdEndpointFlags __f.EndpointFlags
  108. LONG GroupID;
  109. ULONG TransportDeviceNameLength;
  110. WCHAR TransportDeviceName[1];
  111. } AFD_OPEN_PACKET, *PAFD_OPEN_PACKET;
  112. // *** the XX is to ensure natural alignment of the open packet part
  113. // of the EA buffer
  114. #define AfdOpenPacket "AfdOpenPacketXX"
  115. #define AFD_OPEN_PACKET_NAME_LENGTH (sizeof(AfdOpenPacket) - 1)
  116. //
  117. // The input structure for IOCTL_AFD_BIND
  118. //
  119. typedef struct _AFD_BIND_INFO {
  120. ULONG ShareAccess;
  121. #define AFD_NORMALADDRUSE 0 // Do not reuse address if
  122. // already in use but allow
  123. // subsequent reuse by others
  124. // (this is a default)
  125. #define AFD_REUSEADDRESS 1 // Reuse address if necessary
  126. #define AFD_WILDCARDADDRESS 2 // Address is a wildcard, no checking
  127. // can be performed by winsock layer.
  128. #define AFD_EXCLUSIVEADDRUSE 3 // Do not allow reuse of this
  129. // address (admin only).
  130. TRANSPORT_ADDRESS Address;
  131. } AFD_BIND_INFO, *PAFD_BIND_INFO;
  132. //
  133. // The output strucuture is TDI_ADDRESS_INFO
  134. // The address handle is returned via IoStatus->Information
  135. //
  136. //
  137. // The input structure for IOCTL_AFD_START_LISTEN.
  138. //
  139. typedef struct _AFD_LISTEN_INFO {
  140. BOOLEAN SanActive;
  141. ULONG MaximumConnectionQueue;
  142. BOOLEAN UseDelayedAcceptance;
  143. } AFD_LISTEN_INFO, *PAFD_LISTEN_INFO;
  144. //
  145. // The output structure for IOCTL_AFD_WAIT_FOR_LISTEN.
  146. //
  147. typedef struct _AFD_LISTEN_RESPONSE_INFO {
  148. LONG Sequence;
  149. TRANSPORT_ADDRESS RemoteAddress;
  150. } AFD_LISTEN_RESPONSE_INFO, *PAFD_LISTEN_RESPONSE_INFO;
  151. //
  152. // The input structure for IOCTL_AFD_ACCEPT.
  153. //
  154. typedef struct _AFD_ACCEPT_INFO {
  155. BOOLEAN SanActive;
  156. LONG Sequence;
  157. HANDLE AcceptHandle;
  158. } AFD_ACCEPT_INFO, *PAFD_ACCEPT_INFO;
  159. typedef struct _AFD_SUPER_ACCEPT_INFO {
  160. BOOLEAN SanActive;
  161. BOOLEAN FixAddressAlignment;
  162. HANDLE AcceptHandle;
  163. ULONG ReceiveDataLength;
  164. ULONG LocalAddressLength;
  165. ULONG RemoteAddressLength;
  166. } AFD_SUPER_ACCEPT_INFO, *PAFD_SUPER_ACCEPT_INFO;
  167. //
  168. // The input structure for IOCTL_AFD_DEFER_ACCEPT.
  169. //
  170. typedef struct _AFD_DEFER_ACCEPT_INFO {
  171. LONG Sequence;
  172. BOOLEAN Reject;
  173. } AFD_DEFER_ACCEPT_INFO, *PAFD_DEFER_ACCEPT_INFO;
  174. //
  175. // Flags and input structure for IOCTL_AFD_PARTIAL_DISCONNECT.
  176. //
  177. #define AFD_PARTIAL_DISCONNECT_SEND 0x01
  178. #define AFD_PARTIAL_DISCONNECT_RECEIVE 0x02
  179. #define AFD_ABORTIVE_DISCONNECT 0x4
  180. #define AFD_UNCONNECT_DATAGRAM 0x08
  181. typedef struct _AFD_PARTIAL_DISCONNECT_INFO {
  182. ULONG DisconnectMode;
  183. LARGE_INTEGER Timeout;
  184. } AFD_PARTIAL_DISCONNECT_INFO, *PAFD_PARTIAL_DISCONNECT_INFO;
  185. typedef struct _AFD_SUPER_DISCONNECT_INFO {
  186. ULONG Flags; // Same as TransmitFile
  187. } AFD_SUPER_DISCONNECT_INFO, *PAFD_SUPER_DISCONNECT_INFO;
  188. //
  189. // Structures for IOCTL_AFD_POLL.
  190. //
  191. typedef struct _AFD_POLL_HANDLE_INFO {
  192. HANDLE Handle;
  193. ULONG PollEvents;
  194. NTSTATUS Status;
  195. } AFD_POLL_HANDLE_INFO, *PAFD_POLL_HANDLE_INFO;
  196. typedef struct _AFD_POLL_INFO {
  197. LARGE_INTEGER Timeout;
  198. ULONG NumberOfHandles;
  199. BOOLEAN Unique;
  200. AFD_POLL_HANDLE_INFO Handles[1];
  201. } AFD_POLL_INFO, *PAFD_POLL_INFO;
  202. #define AFD_POLL_RECEIVE_BIT 0 //0001
  203. #define AFD_POLL_RECEIVE (1 << AFD_POLL_RECEIVE_BIT)
  204. #define AFD_POLL_RECEIVE_EXPEDITED_BIT 1 //0002
  205. #define AFD_POLL_RECEIVE_EXPEDITED (1 << AFD_POLL_RECEIVE_EXPEDITED_BIT)
  206. #define AFD_POLL_SEND_BIT 2 //0004
  207. #define AFD_POLL_SEND (1 << AFD_POLL_SEND_BIT)
  208. #define AFD_POLL_DISCONNECT_BIT 3 //0008
  209. #define AFD_POLL_DISCONNECT (1 << AFD_POLL_DISCONNECT_BIT)
  210. #define AFD_POLL_ABORT_BIT 4 //0010
  211. #define AFD_POLL_ABORT (1 << AFD_POLL_ABORT_BIT)
  212. #define AFD_POLL_LOCAL_CLOSE_BIT 5 //0020
  213. #define AFD_POLL_LOCAL_CLOSE (1 << AFD_POLL_LOCAL_CLOSE_BIT)
  214. #define AFD_POLL_CONNECT_BIT 6 //0040
  215. #define AFD_POLL_CONNECT (1 << AFD_POLL_CONNECT_BIT)
  216. #define AFD_POLL_ACCEPT_BIT 7 //0080
  217. #define AFD_POLL_ACCEPT (1 << AFD_POLL_ACCEPT_BIT)
  218. #define AFD_POLL_CONNECT_FAIL_BIT 8 //0100
  219. #define AFD_POLL_CONNECT_FAIL (1 << AFD_POLL_CONNECT_FAIL_BIT)
  220. #define AFD_POLL_QOS_BIT 9 //0200
  221. #define AFD_POLL_QOS (1 << AFD_POLL_QOS_BIT)
  222. #define AFD_POLL_GROUP_QOS_BIT 10 //0400
  223. #define AFD_POLL_GROUP_QOS (1 << AFD_POLL_GROUP_QOS_BIT)
  224. #define AFD_POLL_ROUTING_IF_CHANGE_BIT 11 //0800
  225. #define AFD_POLL_ROUTING_IF_CHANGE (1 << AFD_POLL_ROUTING_IF_CHANGE_BIT)
  226. #define AFD_POLL_ADDRESS_LIST_CHANGE_BIT 12 //1000
  227. #define AFD_POLL_ADDRESS_LIST_CHANGE (1 << AFD_POLL_ADDRESS_LIST_CHANGE_BIT)
  228. #define AFD_NUM_POLL_EVENTS 13
  229. #define AFD_POLL_ALL ((1 << AFD_NUM_POLL_EVENTS) - 1)
  230. #define AFD_POLL_SANCOUNTS_UPDATED 0x80000000
  231. //
  232. // Structure for querying receive information.
  233. //
  234. typedef struct _AFD_RECEIVE_INFORMATION {
  235. ULONG BytesAvailable;
  236. ULONG ExpeditedBytesAvailable;
  237. } AFD_RECEIVE_INFORMATION, *PAFD_RECEIVE_INFORMATION;
  238. //
  239. // Structure for quering the TDI handles for an AFD endpoint.
  240. //
  241. #define AFD_QUERY_ADDRESS_HANDLE 1
  242. #define AFD_QUERY_CONNECTION_HANDLE 2
  243. typedef struct _AFD_HANDLE_INFO {
  244. HANDLE TdiAddressHandle;
  245. HANDLE TdiConnectionHandle;
  246. } AFD_HANDLE_INFO, *PAFD_HANDLE_INFO;
  247. //
  248. // Structure and manifests for setting information in AFD.
  249. //
  250. typedef struct _AFD_INFORMATION {
  251. ULONG InformationType;
  252. union {
  253. BOOLEAN Boolean;
  254. ULONG Ulong;
  255. LARGE_INTEGER LargeInteger;
  256. } Information;
  257. } AFD_INFORMATION, *PAFD_INFORMATION;
  258. #define AFD_INLINE_MODE 0x01
  259. #define AFD_NONBLOCKING_MODE 0x02
  260. #define AFD_MAX_SEND_SIZE 0x03
  261. #define AFD_SENDS_PENDING 0x04
  262. #define AFD_MAX_PATH_SEND_SIZE 0x05
  263. #define AFD_RECEIVE_WINDOW_SIZE 0x06
  264. #define AFD_SEND_WINDOW_SIZE 0x07
  265. #define AFD_CONNECT_TIME 0x08
  266. #define AFD_CIRCULAR_QUEUEING 0x09
  267. #define AFD_GROUP_ID_AND_TYPE 0x0A
  268. #define AFD_GROUP_ID_AND_TYPE 0x0A
  269. #define AFD_REPORT_PORT_UNREACHABLE 0x0B
  270. //
  271. // Structure for the transmit file IOCTL.
  272. //
  273. typedef struct _AFD_TRANSMIT_FILE_INFO {
  274. LARGE_INTEGER Offset;
  275. LARGE_INTEGER WriteLength;
  276. ULONG SendPacketLength;
  277. HANDLE FileHandle;
  278. PVOID Head;
  279. ULONG HeadLength;
  280. PVOID Tail;
  281. ULONG TailLength;
  282. ULONG Flags;
  283. } AFD_TRANSMIT_FILE_INFO, *PAFD_TRANSMIT_FILE_INFO;
  284. //
  285. // Flags for the TransmitFile API.
  286. //
  287. #define AFD_TF_DISCONNECT 0x01
  288. #define AFD_TF_REUSE_SOCKET 0x02
  289. #define AFD_TF_WRITE_BEHIND 0x04
  290. #define AFD_TF_USE_DEFAULT_WORKER 0x00
  291. #define AFD_TF_USE_SYSTEM_THREAD 0x10
  292. #define AFD_TF_USE_KERNEL_APC 0x20
  293. #define AFD_TF_WORKER_KIND_MASK 0x30
  294. //
  295. // Flag definitions for the AfdFlags field in the AFD_SEND_INFO,
  296. // AFD_SEND_DATAGRAM_INFO, AFD_RECV_INFO, and AFD_RECV_DATAGRAM_INFO
  297. // structures.
  298. //
  299. #define AFD_NO_FAST_IO 0x0001 // Always fail Fast IO on this request.
  300. #define AFD_OVERLAPPED 0x0002 // Overlapped operation.
  301. //
  302. // Structure for connected sends.
  303. //
  304. typedef struct _AFD_SEND_INFO {
  305. LPWSABUF BufferArray;
  306. ULONG BufferCount;
  307. ULONG AfdFlags;
  308. ULONG TdiFlags;
  309. } AFD_SEND_INFO, *PAFD_SEND_INFO;
  310. //
  311. // Structure for unconnected datagram sends.
  312. //
  313. typedef struct _AFD_SEND_DATAGRAM_INFO {
  314. LPWSABUF BufferArray;
  315. ULONG BufferCount;
  316. ULONG AfdFlags;
  317. TDI_REQUEST_SEND_DATAGRAM TdiRequest;
  318. TDI_CONNECTION_INFORMATION TdiConnInfo;
  319. } AFD_SEND_DATAGRAM_INFO, *PAFD_SEND_DATAGRAM_INFO;
  320. //
  321. // Structure for connected recvs.
  322. //
  323. typedef struct _AFD_RECV_INFO {
  324. LPWSABUF BufferArray;
  325. ULONG BufferCount;
  326. ULONG AfdFlags;
  327. ULONG TdiFlags;
  328. } AFD_RECV_INFO, *PAFD_RECV_INFO;
  329. //
  330. // Structure for receiving datagrams on unconnected sockets.
  331. //
  332. typedef struct _AFD_RECV_DATAGRAM_INFO {
  333. LPWSABUF BufferArray;
  334. ULONG BufferCount;
  335. ULONG AfdFlags;
  336. ULONG TdiFlags;
  337. PVOID Address;
  338. PULONG AddressLength;
  339. } AFD_RECV_DATAGRAM_INFO, *PAFD_RECV_DATAGRAM_INFO;
  340. //
  341. // Structure for receiving datagram messages.
  342. //
  343. typedef struct _AFD_RECV_MESSAGE_INFO {
  344. AFD_RECV_DATAGRAM_INFO dgi;
  345. PVOID ControlBuffer;
  346. PULONG ControlLength;
  347. PULONG MsgFlags;
  348. } AFD_RECV_MESSAGE_INFO, *PAFD_RECV_MESSAGE_INFO;
  349. #define AFD_MAX_TDI_FAST_ADDRESS 32
  350. //
  351. // Structure for event select.
  352. //
  353. typedef struct _AFD_EVENT_SELECT_INFO {
  354. HANDLE Event;
  355. ULONG PollEvents;
  356. } AFD_EVENT_SELECT_INFO, *PAFD_EVENT_SELECT_INFO;
  357. //
  358. // Output structure for enum network events.
  359. //
  360. typedef struct _AFD_ENUM_NETWORK_EVENTS_INFO {
  361. ULONG PollEvents;
  362. NTSTATUS EventStatus[AFD_NUM_POLL_EVENTS];
  363. } AFD_ENUM_NETWORK_EVENTS_INFO, *PAFD_ENUM_NETWORK_EVENTS_INFO;
  364. //
  365. // Structures for QOS and grouping.
  366. //
  367. typedef struct _AFD_QOS_INFO {
  368. QOS Qos;
  369. BOOLEAN GroupQos;
  370. } AFD_QOS_INFO, *PAFD_QOS_INFO;
  371. //
  372. // Group membership type.
  373. //
  374. typedef enum _AFD_GROUP_TYPE {
  375. GroupTypeNeither = 0,
  376. GroupTypeConstrained = SG_CONSTRAINED_GROUP,
  377. GroupTypeUnconstrained = SG_UNCONSTRAINED_GROUP
  378. } AFD_GROUP_TYPE, *PAFD_GROUP_TYPE;
  379. //
  380. // Note that, for totally slimy reasons, the following
  381. // structure must be exactly eight bytes long (the size
  382. // of a LARGE_INTEGER). See msafd\socket.c and afd\misc.c
  383. // for the gory details.
  384. //
  385. typedef struct _AFD_GROUP_INFO {
  386. LONG GroupID;
  387. AFD_GROUP_TYPE GroupType;
  388. } AFD_GROUP_INFO, *PAFD_GROUP_INFO;
  389. //
  390. // Structure for validating group membership.
  391. //
  392. typedef struct _AFD_VALIDATE_GROUP_INFO {
  393. LONG GroupID;
  394. TRANSPORT_ADDRESS RemoteAddress;
  395. } AFD_VALIDATE_GROUP_INFO, *PAFD_VALIDATE_GROUP_INFO;
  396. //
  397. // Structure for querying connect data on an unaccepted connection.
  398. //
  399. typedef struct _AFD_UNACCEPTED_CONNECT_DATA_INFO {
  400. LONG Sequence;
  401. ULONG ConnectDataLength;
  402. BOOLEAN LengthOnly;
  403. } AFD_UNACCEPTED_CONNECT_DATA_INFO, *PAFD_UNACCEPTED_CONNECT_DATA_INFO;
  404. typedef struct _AFD_TRANSPORT_IOCTL_INFO {
  405. HANDLE Handle;
  406. PVOID InputBuffer;
  407. ULONG InputBufferLength;
  408. ULONG IoControlCode;
  409. ULONG AfdFlags;
  410. ULONG PollEvent;
  411. } AFD_TRANSPORT_IOCTL_INFO, *PAFD_TRANSPORT_IOCTL_INFO;
  412. typedef struct _AFD_CONNECT_JOIN_INFO {
  413. BOOLEAN SanActive;
  414. HANDLE RootEndpoint; // Root endpoint for joins
  415. HANDLE ConnectEndpoint; // Connect/leaf endpoint for async connects
  416. TRANSPORT_ADDRESS RemoteAddress; // Remote address
  417. } AFD_CONNECT_JOIN_INFO, *PAFD_CONNECT_JOIN_INFO;
  418. typedef struct _AFD_SUPER_CONNECT_INFO {
  419. BOOLEAN SanActive;
  420. TRANSPORT_ADDRESS RemoteAddress; // Remote address
  421. } AFD_SUPER_CONNECT_INFO, *PAFD_SUPER_CONNECT_INFO;
  422. #ifndef _WINSOCK2API_
  423. typedef struct _TRANSMIT_PACKETS_ELEMENT {
  424. ULONG dwElFlags;
  425. #define TP_MEMORY 1
  426. #define TP_FILE 2
  427. #define TP_EOP 4
  428. ULONG cLength;
  429. union {
  430. struct {
  431. LARGE_INTEGER nFileOffset;
  432. HANDLE hFile;
  433. };
  434. PVOID pBuffer;
  435. };
  436. } TRANSMIT_PACKETS_ELEMENT, *LPTRANSMIT_PACKETS_ELEMENT;
  437. #else
  438. typedef struct _TRANSMIT_PACKETS_ELEMENT TRANSMIT_PACKETS_ELEMENT, *LPTRANSMIT_PACKETS_ELEMENT;
  439. #endif
  440. typedef struct _AFD_TPACKETS_INFO {
  441. LPTRANSMIT_PACKETS_ELEMENT ElementArray;
  442. ULONG ElementCount;
  443. ULONG SendSize;
  444. ULONG Flags;
  445. } AFD_TPACKETS_INFO, *PAFD_TPACKETS_INFO;
  446. //
  447. // AFD IOCTL code definitions.
  448. //
  449. // N.B. To ensure the efficient of the code generated by AFD's
  450. // IOCTL dispatcher, these IOCTL codes should be contiguous
  451. // (no gaps).
  452. //
  453. // N.B. If new IOCTLs are added here, update the lookup table in
  454. // ntos\afd\dispatch.c!
  455. //
  456. #define FSCTL_AFD_BASE FILE_DEVICE_NETWORK
  457. #define _AFD_CONTROL_CODE(request,method) \
  458. ((FSCTL_AFD_BASE)<<12 | (request<<2) | method)
  459. #define _AFD_REQUEST(ioctl) \
  460. ((((ULONG)(ioctl)) >> 2) & 0x03FF)
  461. #define _AFD_BASE(ioctl) \
  462. ((((ULONG)(ioctl)) >> 12) & 0xFFFFF)
  463. #define AFD_BIND 0
  464. #define AFD_CONNECT 1
  465. #define AFD_START_LISTEN 2
  466. #define AFD_WAIT_FOR_LISTEN 3
  467. #define AFD_ACCEPT 4
  468. #define AFD_RECEIVE 5
  469. #define AFD_RECEIVE_DATAGRAM 6
  470. #define AFD_SEND 7
  471. #define AFD_SEND_DATAGRAM 8
  472. #define AFD_POLL 9
  473. #define AFD_PARTIAL_DISCONNECT 10
  474. #define AFD_GET_ADDRESS 11
  475. #define AFD_QUERY_RECEIVE_INFO 12
  476. #define AFD_QUERY_HANDLES 13
  477. #define AFD_SET_INFORMATION 14
  478. #define AFD_GET_REMOTE_ADDRESS 15
  479. #define AFD_GET_CONTEXT 16
  480. #define AFD_SET_CONTEXT 17
  481. #define AFD_SET_CONNECT_DATA 18
  482. #define AFD_SET_CONNECT_OPTIONS 19
  483. #define AFD_SET_DISCONNECT_DATA 20
  484. #define AFD_SET_DISCONNECT_OPTIONS 21
  485. #define AFD_GET_CONNECT_DATA 22
  486. #define AFD_GET_CONNECT_OPTIONS 23
  487. #define AFD_GET_DISCONNECT_DATA 24
  488. #define AFD_GET_DISCONNECT_OPTIONS 25
  489. #define AFD_SIZE_CONNECT_DATA 26
  490. #define AFD_SIZE_CONNECT_OPTIONS 27
  491. #define AFD_SIZE_DISCONNECT_DATA 28
  492. #define AFD_SIZE_DISCONNECT_OPTIONS 29
  493. #define AFD_GET_INFORMATION 30
  494. #define AFD_TRANSMIT_FILE 31
  495. #define AFD_SUPER_ACCEPT 32
  496. #define AFD_EVENT_SELECT 33
  497. #define AFD_ENUM_NETWORK_EVENTS 34
  498. #define AFD_DEFER_ACCEPT 35
  499. #define AFD_WAIT_FOR_LISTEN_LIFO 36
  500. #define AFD_SET_QOS 37
  501. #define AFD_GET_QOS 38
  502. #define AFD_NO_OPERATION 39
  503. #define AFD_VALIDATE_GROUP 40
  504. #define AFD_GET_UNACCEPTED_CONNECT_DATA 41
  505. #define AFD_ROUTING_INTERFACE_QUERY 42
  506. #define AFD_ROUTING_INTERFACE_CHANGE 43
  507. #define AFD_ADDRESS_LIST_QUERY 44
  508. #define AFD_ADDRESS_LIST_CHANGE 45
  509. #define AFD_JOIN_LEAF 46
  510. #define AFD_TRANSPORT_IOCTL 47
  511. #define AFD_TRANSMIT_PACKETS 48
  512. #define AFD_SUPER_CONNECT 49
  513. #define AFD_SUPER_DISCONNECT 50
  514. #define AFD_RECEIVE_MESSAGE 51
  515. //
  516. // SAN switch specific AFD function numbers
  517. //
  518. #define AFD_SWITCH_CEMENT_SAN 52
  519. #define AFD_SWITCH_SET_EVENTS 53
  520. #define AFD_SWITCH_RESET_EVENTS 54
  521. #define AFD_SWITCH_CONNECT_IND 55
  522. #define AFD_SWITCH_CMPL_ACCEPT 56
  523. #define AFD_SWITCH_CMPL_REQUEST 57
  524. #define AFD_SWITCH_CMPL_IO 58
  525. #define AFD_SWITCH_REFRESH_ENDP 59
  526. #define AFD_SWITCH_GET_PHYSICAL_ADDR 60
  527. #define AFD_SWITCH_ACQUIRE_CTX 61
  528. #define AFD_SWITCH_TRANSFER_CTX 62
  529. #define AFD_SWITCH_GET_SERVICE_PID 63
  530. #define AFD_SWITCH_SET_SERVICE_PROCESS 64
  531. #define AFD_SWITCH_PROVIDER_CHANGE 65
  532. #define AFD_SWITCH_ADDRLIST_CHANGE 66
  533. #define AFD_NUM_IOCTLS 67
  534. #define IOCTL_AFD_BIND _AFD_CONTROL_CODE( AFD_BIND, METHOD_NEITHER )
  535. #define IOCTL_AFD_CONNECT _AFD_CONTROL_CODE( AFD_CONNECT, METHOD_NEITHER )
  536. #define IOCTL_AFD_START_LISTEN _AFD_CONTROL_CODE( AFD_START_LISTEN, METHOD_NEITHER )
  537. #define IOCTL_AFD_WAIT_FOR_LISTEN _AFD_CONTROL_CODE( AFD_WAIT_FOR_LISTEN, METHOD_BUFFERED )
  538. #define IOCTL_AFD_ACCEPT _AFD_CONTROL_CODE( AFD_ACCEPT, METHOD_BUFFERED )
  539. #define IOCTL_AFD_RECEIVE _AFD_CONTROL_CODE( AFD_RECEIVE, METHOD_NEITHER )
  540. #define IOCTL_AFD_RECEIVE_DATAGRAM _AFD_CONTROL_CODE( AFD_RECEIVE_DATAGRAM, METHOD_NEITHER )
  541. #define IOCTL_AFD_SEND _AFD_CONTROL_CODE( AFD_SEND, METHOD_NEITHER )
  542. #define IOCTL_AFD_SEND_DATAGRAM _AFD_CONTROL_CODE( AFD_SEND_DATAGRAM, METHOD_NEITHER )
  543. #define IOCTL_AFD_POLL _AFD_CONTROL_CODE( AFD_POLL, METHOD_BUFFERED )
  544. #define IOCTL_AFD_PARTIAL_DISCONNECT _AFD_CONTROL_CODE( AFD_PARTIAL_DISCONNECT, METHOD_NEITHER )
  545. #define IOCTL_AFD_GET_ADDRESS _AFD_CONTROL_CODE( AFD_GET_ADDRESS, METHOD_NEITHER )
  546. #define IOCTL_AFD_QUERY_RECEIVE_INFO _AFD_CONTROL_CODE( AFD_QUERY_RECEIVE_INFO, METHOD_NEITHER )
  547. #define IOCTL_AFD_QUERY_HANDLES _AFD_CONTROL_CODE( AFD_QUERY_HANDLES, METHOD_NEITHER )
  548. #define IOCTL_AFD_SET_INFORMATION _AFD_CONTROL_CODE( AFD_SET_INFORMATION, METHOD_NEITHER )
  549. #define IOCTL_AFD_GET_REMOTE_ADDRESS _AFD_CONTROL_CODE( AFD_GET_REMOTE_ADDRESS, METHOD_NEITHER )
  550. #define IOCTL_AFD_GET_CONTEXT _AFD_CONTROL_CODE( AFD_GET_CONTEXT, METHOD_NEITHER )
  551. #define IOCTL_AFD_SET_CONTEXT _AFD_CONTROL_CODE( AFD_SET_CONTEXT, METHOD_NEITHER )
  552. #define IOCTL_AFD_SET_CONNECT_DATA _AFD_CONTROL_CODE( AFD_SET_CONNECT_DATA, METHOD_NEITHER )
  553. #define IOCTL_AFD_SET_CONNECT_OPTIONS _AFD_CONTROL_CODE( AFD_SET_CONNECT_OPTIONS, METHOD_NEITHER )
  554. #define IOCTL_AFD_SET_DISCONNECT_DATA _AFD_CONTROL_CODE( AFD_SET_DISCONNECT_DATA, METHOD_NEITHER )
  555. #define IOCTL_AFD_SET_DISCONNECT_OPTIONS _AFD_CONTROL_CODE( AFD_SET_DISCONNECT_OPTIONS, METHOD_NEITHER )
  556. #define IOCTL_AFD_GET_CONNECT_DATA _AFD_CONTROL_CODE( AFD_GET_CONNECT_DATA, METHOD_NEITHER )
  557. #define IOCTL_AFD_GET_CONNECT_OPTIONS _AFD_CONTROL_CODE( AFD_GET_CONNECT_OPTIONS, METHOD_NEITHER )
  558. #define IOCTL_AFD_GET_DISCONNECT_DATA _AFD_CONTROL_CODE( AFD_GET_DISCONNECT_DATA, METHOD_NEITHER )
  559. #define IOCTL_AFD_GET_DISCONNECT_OPTIONS _AFD_CONTROL_CODE( AFD_GET_DISCONNECT_OPTIONS, METHOD_NEITHER )
  560. #define IOCTL_AFD_SIZE_CONNECT_DATA _AFD_CONTROL_CODE( AFD_SIZE_CONNECT_DATA, METHOD_NEITHER )
  561. #define IOCTL_AFD_SIZE_CONNECT_OPTIONS _AFD_CONTROL_CODE( AFD_SIZE_CONNECT_OPTIONS, METHOD_NEITHER )
  562. #define IOCTL_AFD_SIZE_DISCONNECT_DATA _AFD_CONTROL_CODE( AFD_SIZE_DISCONNECT_DATA, METHOD_NEITHER )
  563. #define IOCTL_AFD_SIZE_DISCONNECT_OPTIONS _AFD_CONTROL_CODE( AFD_SIZE_DISCONNECT_OPTIONS, METHOD_NEITHER )
  564. #define IOCTL_AFD_GET_INFORMATION _AFD_CONTROL_CODE( AFD_GET_INFORMATION, METHOD_NEITHER )
  565. #define IOCTL_AFD_TRANSMIT_FILE _AFD_CONTROL_CODE( AFD_TRANSMIT_FILE, METHOD_NEITHER )
  566. #define IOCTL_AFD_SUPER_ACCEPT _AFD_CONTROL_CODE( AFD_SUPER_ACCEPT, METHOD_NEITHER )
  567. #define IOCTL_AFD_EVENT_SELECT _AFD_CONTROL_CODE( AFD_EVENT_SELECT, METHOD_NEITHER )
  568. #define IOCTL_AFD_ENUM_NETWORK_EVENTS _AFD_CONTROL_CODE( AFD_ENUM_NETWORK_EVENTS, METHOD_NEITHER )
  569. #define IOCTL_AFD_DEFER_ACCEPT _AFD_CONTROL_CODE( AFD_DEFER_ACCEPT, METHOD_BUFFERED )
  570. #define IOCTL_AFD_WAIT_FOR_LISTEN_LIFO _AFD_CONTROL_CODE( AFD_WAIT_FOR_LISTEN_LIFO, METHOD_BUFFERED )
  571. #define IOCTL_AFD_SET_QOS _AFD_CONTROL_CODE( AFD_SET_QOS, METHOD_BUFFERED )
  572. #define IOCTL_AFD_GET_QOS _AFD_CONTROL_CODE( AFD_GET_QOS, METHOD_BUFFERED )
  573. #define IOCTL_AFD_NO_OPERATION _AFD_CONTROL_CODE( AFD_NO_OPERATION, METHOD_NEITHER )
  574. #define IOCTL_AFD_VALIDATE_GROUP _AFD_CONTROL_CODE( AFD_VALIDATE_GROUP, METHOD_BUFFERED )
  575. #define IOCTL_AFD_GET_UNACCEPTED_CONNECT_DATA _AFD_CONTROL_CODE( AFD_GET_UNACCEPTED_CONNECT_DATA, METHOD_NEITHER )
  576. #define IOCTL_AFD_ROUTING_INTERFACE_QUERY _AFD_CONTROL_CODE( AFD_ROUTING_INTERFACE_QUERY, METHOD_NEITHER )
  577. #define IOCTL_AFD_ROUTING_INTERFACE_CHANGE _AFD_CONTROL_CODE( AFD_ROUTING_INTERFACE_CHANGE, METHOD_BUFFERED )
  578. #define IOCTL_AFD_ADDRESS_LIST_QUERY _AFD_CONTROL_CODE( AFD_ADDRESS_LIST_QUERY, METHOD_NEITHER )
  579. #define IOCTL_AFD_ADDRESS_LIST_CHANGE _AFD_CONTROL_CODE( AFD_ADDRESS_LIST_CHANGE, METHOD_BUFFERED )
  580. #define IOCTL_AFD_JOIN_LEAF _AFD_CONTROL_CODE( AFD_JOIN_LEAF, METHOD_NEITHER )
  581. #define IOCTL_AFD_TRANSPORT_IOCTL _AFD_CONTROL_CODE( AFD_TRANSPORT_IOCTL, METHOD_NEITHER )
  582. #define IOCTL_AFD_TRANSMIT_PACKETS _AFD_CONTROL_CODE( AFD_TRANSMIT_PACKETS, METHOD_NEITHER )
  583. #define IOCTL_AFD_SUPER_CONNECT _AFD_CONTROL_CODE( AFD_SUPER_CONNECT, METHOD_NEITHER )
  584. #define IOCTL_AFD_SUPER_DISCONNECT _AFD_CONTROL_CODE( AFD_SUPER_DISCONNECT, METHOD_NEITHER )
  585. #define IOCTL_AFD_RECEIVE_MESSAGE _AFD_CONTROL_CODE( AFD_RECEIVE_MESSAGE, METHOD_NEITHER )
  586. //
  587. // SAN support
  588. //
  589. //
  590. //
  591. // SAN IOCTL control codes.
  592. //
  593. #define IOCTL_AFD_SWITCH_CEMENT_SAN _AFD_CONTROL_CODE( AFD_SWITCH_CEMENT_SAN, METHOD_NEITHER )
  594. /*++
  595. Ioctl Description:
  596. Changes the AFD endpoint type to SAN to indicate that
  597. it is used for support of user mode SAN providers
  598. Associates switch context with the endpoint.
  599. Arguments:
  600. Handle - helper endpoint handle for the process.
  601. InputBuffer - input parameters for the operation (AFD_SWITCH_CONTEXT_INFO)
  602. SocketHandle - handle of the endpoint being changed to SAN
  603. SwitchContext - switch context associated with the endpoint
  604. InputBufferLength - sizeof(AFD_SWITCH_CONTEXT_INFO)
  605. OutputBuffer - NULL (ingored)
  606. OutputBufferLength - 0 (ignored)
  607. Return Value:
  608. IoStatus.Status:
  609. STATUS_SUCCESS - operation succeeded.
  610. STATUS_OBJECT_TYPE_MISMATCH - helper handle or switch socket handle are not
  611. AFD file object handles
  612. STATUS_INVALID_HANDLE - helper handle or switch socket handle correspond to AFD
  613. endpoint of incorrect type/state.
  614. STATUS_INVALID_PARAMETER - input buffer is of incorrect size.
  615. other - failed when attempting to access switch socket, input buffer, or switch context.
  616. IoStatus.Information - 0 (ignored)
  617. --*/
  618. #define IOCTL_AFD_SWITCH_SET_EVENTS _AFD_CONTROL_CODE( AFD_SWITCH_SET_EVENTS, METHOD_NEITHER )
  619. /*++
  620. Ioctl Description:
  621. Sets the poll event on the san endpoint to report
  622. to the application via various forms of the select.
  623. Arguments:
  624. Handle - helper endpoint handle for the process.
  625. InputBuffer - input parameters for the operation (AFD_SWITCH_EVENT_INFO)
  626. SocketHandle - handle of the SAN endpoint (except
  627. AFD_POLL_EVENT_CONNECT_FAIL which
  628. just needs a bound endpoint).
  629. SwitchContext - switch context associated with endpoint (NULL
  630. for AFD_POLL_EVENT_CONNECT_FAIL) to validate
  631. the handle-endpoint association
  632. EventBit - event bit to set
  633. Status - associated status (for AFD_POLL_EVENT_CONNECT_FAIL)
  634. InputBufferLength - sizeof(AFD_SWITCH_EVENT_INFO)
  635. OutputBuffer - NULL (ignored)
  636. OutputBufferLength - 0 (ignored)
  637. Return Value:
  638. IoStatus.Status:
  639. STATUS_SUCCESS - operation succeeded.
  640. STATUS_OBJECT_TYPE_MISMATCH - helper handle or switch socket handle are not
  641. AFD file object handles
  642. STATUS_INVALID_HANDLE - helper handle or switch socket handle+context correspond
  643. to AFD endpoint of incorrect type/state.
  644. STATUS_INVALID_PARAMETER - input buffer is of incorrect size.
  645. other - failed when attempting to access switch socket, input buffer, or switch context.
  646. IoStatus.Information - 0 (ignored)
  647. --*/
  648. #define IOCTL_AFD_SWITCH_RESET_EVENTS _AFD_CONTROL_CODE( AFD_SWITCH_RESET_EVENTS, METHOD_NEITHER )
  649. /*++
  650. Ioctl Description:
  651. Resets the poll event on the san endpoint so that it is no
  652. longer reported to the application via various forms of the select
  653. Arguments:
  654. Handle - helper endpoint handle for the process.
  655. InputBuffer - input parameters for the operation (AFD_SWITCH_EVENT_INFO)
  656. SocketHandle - handle of the SAN endpoint
  657. SwitchContext - switch context associated with endpoint
  658. to validate the handle-endpoint association
  659. EventBit - event bit to reset
  660. Status - associated status (ignored)
  661. InputBufferLength - sizeof(AFD_SWITCH_EVENT_INFO)
  662. OutputBuffer - NULL (ignored)
  663. OutputBufferLength - 0 (ignored)
  664. Return Value:
  665. IoStatus.Status:
  666. STATUS_SUCCESS - operation succeeded.
  667. STATUS_OBJECT_TYPE_MISMATCH - helper handle or switch socket handle are not
  668. AFD file object handles
  669. STATUS_INVALID_HANDLE - helper handle or switch socket handle+context correspond
  670. to AFD endpoint of incorrect type/state.
  671. STATUS_INVALID_PARAMETER - input buffer is of incorrect size.
  672. other - failed when attempting to access switch socket, input buffer, or switch context.
  673. IoStatus.Information - 0 (ignored)
  674. --*/
  675. #define IOCTL_AFD_SWITCH_CONNECT_IND _AFD_CONTROL_CODE( AFD_SWITCH_CONNECT_IND, METHOD_OUT_DIRECT )
  676. /*++
  677. Ioctl Description:
  678. Implements connect indication from SAN provider.
  679. Picks up the accept from the listening endpoint queue
  680. or queues the indication an signals the application to come
  681. down with an accept.
  682. Arguments:
  683. Handle - helper endpoint handle for the process.
  684. InputBuffer - input parameters for the operation (AFD_SWITCH_CONNECT_INFO):
  685. ListenHandle - handle of the listening endpoint
  686. RemoteAddress - remote and local addresses associated
  687. with indication incoming connection
  688. InputBufferLength - sizeof(AFD_SWITCH_CONNECT_INFO)+addresses
  689. OutputBuffer - output parameters for the operation (AFD_SWITCH_ACCEPT_INFO):
  690. AcceptHandle - handle of the accepting endpoint
  691. ReceiveLength - length of the receive buffer supplied by
  692. the application in AcceptEx
  693. OutputBufferLength - sizeof (AFD_SWITCH_ACCEPT_INFO)
  694. Return Value:
  695. STATUS_PENDING - request was queued waiting for corresponding transfer request
  696. from the current socket context owner process.
  697. IoStatus.Status:
  698. STATUS_SUCCESS - operation succeeded.
  699. STATUS_OBJECT_TYPE_MISMATCH - helper handle or listen socket handle are not
  700. AFD file object handles
  701. STATUS_INVALID_HANDLE - helper handle or listen socket handle correspond
  702. to AFD endpoint of incorrect type/state.
  703. STATUS_INVALID_PARAMETER - input or output buffers are of incorrect size.
  704. STATUS_CANCELLED - connection indication was cancelled (thread exited or
  705. accepting and/or listening socket closed)
  706. other - failed when attempting to access listening socket, input or output buffers
  707. IoStatus.Information - sizeof (AFD_SWITCH_ACCEPT_INFO) in case of success.
  708. --*/
  709. #define IOCTL_AFD_SWITCH_CMPL_ACCEPT _AFD_CONTROL_CODE( AFD_SWITCH_CMPL_ACCEPT, METHOD_NEITHER )
  710. /*++
  711. Ioctl Description:
  712. Completes the acceptance of SAN connection
  713. Arguments:
  714. Handle - helper endpoint handle for the process.
  715. InputBuffer - input parameters for the operation (AFD_SWITCH_CONTEXT_INFO)
  716. SocketHandle - handle of the accepting endpoint
  717. SwitchContext - switch context associated with the endpoint
  718. InputBufferLength - sizeof(AFD_SWITCH_CONTEXT_INFO)
  719. OutputBuffer - data to copy into the AcceptEx receive buffer
  720. OutputBufferLength - size of received data
  721. Return Value:
  722. IoStatus.Status:
  723. STATUS_SUCCESS - operation succeeded.
  724. STATUS_OBJECT_TYPE_MISMATCH - helper handle or switch socket handle are not
  725. AFD file object handles
  726. STATUS_INVALID_HANDLE - helper handle or switch socket handle+context correspond
  727. to AFD endpoint of incorrect type/state.
  728. STATUS_INVALID_PARAMETER - input buffer is of incorrect size.
  729. STATUS_LOCAL_DISCONNECT - accept was aborted by the application.
  730. other - failed when attempting to access accepte socket, input/output buffers,
  731. or switch context.
  732. IoStatus.Information - Number of bytes copied into application's receive buffer.
  733. --*/
  734. #define IOCTL_AFD_SWITCH_CMPL_REQUEST _AFD_CONTROL_CODE( AFD_SWITCH_CMPL_REQUEST, METHOD_NEITHER )
  735. /*++
  736. Ioctl Description:
  737. Completes the redirected read/write request processed by SAN provider
  738. Arguments:
  739. Handle - helper endpoint handle for the process.
  740. InputBuffer - input parameters for the operation (AFD_SWITCH_REQUEST_INFO)
  741. SocketHandle - SAN endpoint on which to complete the request
  742. SwitchContext - switch context associated with endpoint
  743. to validate the handle-endpoint association
  744. RequestContext - value that identifies the request to complete
  745. RequestStatus - status with which to complete the request (
  746. STATUS_PENDING has special meaning, request
  747. is not completed - merely data is copied)
  748. DataOffset - offset in the request buffer to read/write the data
  749. InputBufferLength - sizeof (AFD_SWITCH_REQUEST_INFO)
  750. OutputBuffer - switch buffer to read/write data
  751. OutputBufferLength - length of the buffer
  752. Return Value:
  753. IoStatus.Status:
  754. STATUS_SUCCESS - operation succeeded.
  755. STATUS_OBJECT_TYPE_MISMATCH - helper handle or switch socket handle are not
  756. AFD file object handles
  757. STATUS_INVALID_HANDLE - helper handle or switch socket handle+context correspond
  758. to AFD endpoint of incorrect type/state.
  759. STATUS_INVALID_PARAMETER - input buffer is of incorrect size.
  760. STATUS_CANCELLED - request to be completed has already been cancelled
  761. other - failed when attempting to access SAN endpoint,
  762. input buffer or output buffers.
  763. IoStatus.Information - number of bytes copied from/to switch buffer.
  764. --*/
  765. #define IOCTL_AFD_SWITCH_CMPL_IO _AFD_CONTROL_CODE( AFD_SWITCH_CMPL_IO, METHOD_NEITHER )
  766. /*++
  767. Ioctl Description:
  768. Simulates async IO completion for the switch.
  769. Arguments:
  770. Handle - SAN socket handle on which to complete the IO.
  771. InputBuffer - input parameters for the operation (IO_STATUS_BLOCK)
  772. Status - final operation status
  773. Information - associated information (number of bytes
  774. transferred to/from request buffer(s))
  775. InputBufferLength - sizeof (IO_STATUS_BLOCK)
  776. OutputBuffer - NULL (ignored)
  777. OutputBufferLength - 0 (ignored)
  778. Return Value:
  779. IoStatus.Status:
  780. STATUS_INVALID_PARAMETER - input buffer is of invalid size.
  781. other - status of the IO operation or failure code when attempting to
  782. access input buffer.
  783. IoStatus.Information - information from the input buffer
  784. --*/
  785. #define IOCTL_AFD_SWITCH_REFRESH_ENDP _AFD_CONTROL_CODE( AFD_SWITCH_REFRESH_ENDP, METHOD_NEITHER )
  786. /*++
  787. Ioctl Description:
  788. Refreshes endpoint so it can be used again in AcceptEx
  789. Arguments:
  790. Handle - helper endpoint handle for the process.
  791. InputBuffer - input parameters for the operation (AFD_SWITCH_CONTEXT_INFO)
  792. SocketHandle - Socket to refresh
  793. SwitchContext - switch context associated with endpoint
  794. to validate the handle-endpoint association
  795. InputBufferLength - sizeof (AFD_SWITCH_CONTEXT_INFO)
  796. OutputBuffer - NULL (ignored)
  797. OutputBufferLength - 0 (ignored)
  798. Return Value:
  799. IoStatus.Status:
  800. STATUS_SUCCESS - operation succeeded.
  801. STATUS_OBJECT_TYPE_MISMATCH - helper handle or switch socket handle are not
  802. AFD file object handles
  803. STATUS_INVALID_HANDLE - helper handle or switch socket handle+context correspond
  804. to AFD endpoint of incorrect type/state.
  805. STATUS_INVALID_PARAMETER - input buffer is of incorrect size.
  806. other - failed when attempting to access SAN endpoint,
  807. input buffer buffer.
  808. IoStatus.Information - 0 (ignored)
  809. --*/
  810. #define IOCTL_AFD_SWITCH_GET_PHYSICAL_ADDR _AFD_CONTROL_CODE( AFD_SWITCH_GET_PHYSICAL_ADDR, METHOD_NEITHER )
  811. /*++
  812. Ioctl Description:
  813. Returns physical address corresponding to provided virtual address.
  814. Arguments:
  815. Handle - helper endpoint handle for the process.
  816. InputBuffer - user mode virtual address
  817. InputBufferLength - access mode
  818. OutputBuffer - Buffer to place physical address into.
  819. OutputBufferLength - sizeof (PHYSICAL_ADDRESS)
  820. Return Value:
  821. IoStatus.Status:
  822. STATUS_SUCCESS - operation succeeded.
  823. STATUS_OBJECT_TYPE_MISMATCH - helper handle is not AFD file object handle
  824. STATUS_INVALID_HANDLE - helper handle corresponds to AFD endpoint of incorrect
  825. type.
  826. STATUS_BUFFER_TOO_SMALL - output buffer is of incorrect size.
  827. STATUS_INVALID_PARAMETER - invalid access mode.
  828. other - failed when attempting to access SAN endpoint,
  829. input buffer buffer.
  830. IoStatus.Information - sizeof(PHYSICAL_ADDRESS).
  831. --*/
  832. #define IOCTL_AFD_SWITCH_ACQUIRE_CTX _AFD_CONTROL_CODE( AFD_SWITCH_ACQUIRE_CTX, METHOD_NEITHER )
  833. /*++
  834. Ioctl Description:
  835. Requests transfer of the socket context to the current process.
  836. Arguments:
  837. Handle - helper endpoint handle for the process.
  838. InputBuffer - input parameters for the operation (AFD_SWITCH_ACQUIRE_CTX_INFO)
  839. SocketHandle - SAN endpoint on which to complete the request
  840. SwitchContext - switch context to be associated with endpoint
  841. when context transfered to the current process.
  842. SocketCtxBuf - buffer to receive current socket context from
  843. another process
  844. SocketCtxBufSize - size of the buffer
  845. InputBufferLength - sizeof (AFD_SWITCH_ACQUIRE_CTX_INFO)
  846. OutputBuffer - buffer to receive data buffered on the socket in another process
  847. and not yet delivered to the applicaiton
  848. OutputBufferLength - length of the receive buffer
  849. Return Value:
  850. STATUS_PENDING - request was queued waiting for corresponding transfer request
  851. from the current socket context owner process.
  852. IoStatus.Status:
  853. STATUS_SUCCESS - operation succeeded.
  854. STATUS_OBJECT_TYPE_MISMATCH - helper handle or switch socket handle are not
  855. AFD file object handles
  856. STATUS_INVALID_HANDLE - helper handle or switch socket handle correspond
  857. to AFD endpoint of incorrect type/state.
  858. STATUS_INVALID_PARAMETER - input buffer is of incorrect size.
  859. other - failed when attempting to access SAN endpoint,
  860. input buffer or output buffers.
  861. IoStatus.Information - number of bytes copied to receive buffer.
  862. --*/
  863. #define IOCTL_AFD_SWITCH_TRANSFER_CTX _AFD_CONTROL_CODE( AFD_SWITCH_TRANSFER_CTX, METHOD_NEITHER )
  864. /*++
  865. Ioctl Description:
  866. Requests AFD to transfer endpoint into another process context
  867. Arguments:
  868. InputBuffer - input parameters for the operation (AFD_SWITCH_TRANSFER_CTX_INFO)
  869. SocketHandle - Socket to transfer
  870. SwitchContext - switch context associated with endpoint
  871. to validate the handle-endpoint association
  872. RequestContext - value that identifies corresponding acquire request,
  873. NULL if this is unsolicited request to transfer to
  874. the service process.
  875. SocketCtxBuf - socket context to copy destination process
  876. acquire request context buffer
  877. SocketCtxSize - size of the context buffer to copy
  878. RcvBufferArray - array of buffered data to transfer to
  879. destination process acquire request
  880. RcvBufferCount - number of elements in the array.
  881. InputBufferLength - sizeof (AFD_SWITCH_TRANSFER_CTX_INFO)
  882. OutputBuffer - NULL (ignored)
  883. OutputBufferLength - 0 (ignored)
  884. Return Value:
  885. IoStatus.Status:
  886. STATUS_SUCCESS - operation succeeded.
  887. STATUS_OBJECT_TYPE_MISMATCH - helper handle or switch socket handle are not
  888. AFD file object handles
  889. STATUS_INVALID_HANDLE - helper handle or switch socket handle+context correspond
  890. to AFD endpoint of incorrect type/state.
  891. STATUS_INVALID_PARAMETER - input buffer is of incorrect size.
  892. other - failed when attempting to access SAN endpoint,
  893. input buffer buffer.
  894. IoStatus.Information - number of bytes copied from RcvBufferArray.
  895. --*/
  896. #define IOCTL_AFD_SWITCH_GET_SERVICE_PID _AFD_CONTROL_CODE( AFD_SWITCH_GET_SERVICE_PID, METHOD_NEITHER )
  897. /*++
  898. Ioctl Description:
  899. Returns PID of the service process used for intermediate socket duplication.
  900. Arguments:
  901. Handle - helper endpoint handle for the process.
  902. InputBuffer - NULL, ignored
  903. InputBufferLength - 0, ignored
  904. OutputBuffer - NULL, ignored
  905. OutputBufferLength - 0, ignored
  906. Return Value:
  907. IoStatus.Status:
  908. STATUS_SUCCESS - operation succeeded.
  909. STATUS_OBJECT_TYPE_MISMATCH - helper handle is not AFD file object handle
  910. STATUS_INVALID_HANDLE - helper handle corresponds to AFD endpoint of incorrect
  911. type.
  912. IoStatus.Information - pid of the service process.
  913. --*/
  914. #define IOCTL_AFD_SWITCH_SET_SERVICE_PROCESS _AFD_CONTROL_CODE( AFD_SWITCH_SET_SERVICE_PROCESS, METHOD_NEITHER )
  915. /*++
  916. Ioctl Description:
  917. Notifies AFD that this process will be used for handle duplication services
  918. Arguments:
  919. Handle - helper endpoint handle for the service process.
  920. InputBuffer - NULL, ignored
  921. InputBufferLength - 0, ignored
  922. OutputBuffer - NULL, ignored
  923. OutputBufferLength - 0, ignored
  924. Return Value:
  925. IoStatus.Status:
  926. STATUS_SUCCESS - operation succeeded.
  927. STATUS_OBJECT_TYPE_MISMATCH - helper handle is not AFD file object handle
  928. STATUS_INVALID_HANDLE - helper handle corresponds to AFD endpoint of incorrect
  929. type.
  930. STATUS_ACCESS_DENIED - helper endpoint is not for the service process.
  931. IoStatus.Information - 0, ignored.
  932. --*/
  933. #define IOCTL_AFD_SWITCH_PROVIDER_CHANGE _AFD_CONTROL_CODE( AFD_SWITCH_PROVIDER_CHANGE, METHOD_NEITHER )
  934. /*++
  935. Ioctl Description:
  936. Notifies interested processes of SAN provider addition/deletion/change.
  937. Arguments:
  938. Handle - helper endpoint handle for the service process.
  939. InputBuffer - NULL, ignored
  940. InputBufferLength - 0, ignored
  941. OutputBuffer - NULL, ignored
  942. OutputBufferLength - 0, ignored
  943. Return Value:
  944. IoStatus.Status:
  945. STATUS_SUCCESS - operation succeeded.
  946. STATUS_OBJECT_TYPE_MISMATCH - helper handle is not AFD file object handle
  947. STATUS_INVALID_HANDLE - helper handle corresponds to AFD endpoint of incorrect
  948. type.
  949. STATUS_ACCESS_DENIED - helper endpoint is not for the service process.
  950. IoStatus.Information - 0, ignored.
  951. --*/
  952. #define IOCTL_AFD_SWITCH_ADDRLIST_CHANGE _AFD_CONTROL_CODE( AFD_SWITCH_ADDRLIST_CHANGE, METHOD_BUFFERED )
  953. /*++
  954. Ioctl Description:
  955. SAN specific version of address list change notifications.
  956. Capture provider installation/removal in addition to plain
  957. address list changes.
  958. Arguments:
  959. Handle - helper endpoint handle for the service process.
  960. InputBuffer - Input parameters for the operation (AFD_TRANSPORT_IOCTL_INFO):
  961. AfdFlags - operation flags (e.g. AFD_OVERLAPPED)
  962. Handle - unused
  963. PollEvent - unused
  964. IoControlCode - IOCTL_AFD_ADDRESS_LIST_CHANGE
  965. InputBuffer - pointer to address family (AF_INET)
  966. InputBufferLength - sizeof (USHORT)
  967. InputBufferLength - sizeof (AFD_TRANSPORT_IOCTL_INFO)
  968. OutputBuffer - NULL, ignored
  969. OutputBufferLength - 0, ignored
  970. Return Value:
  971. IoStatus.Status:
  972. STATUS_SUCCESS - operation succeeded.
  973. STATUS_OBJECT_TYPE_MISMATCH - helper handle is not AFD file object handle
  974. STATUS_INVALID_HANDLE - helper handle corresponds to AFD endpoint of incorrect
  975. type.
  976. IoStatus.Information - 0 - regular address list change
  977. otherwise, seq number of provider list change.
  978. --*/
  979. // Open packet that identifies SAN helper endpoint used
  980. // for communication between SAN switch and AFD.
  981. // This is EA name
  982. //
  983. #define AfdSwitchOpenPacket "AfdSwOpenPacket"
  984. #define AFD_SWITCH_OPEN_PACKET_NAME_LENGTH (sizeof(AfdSwitchOpenPacket)-1)
  985. //
  986. // Data passed in the open packet
  987. // This is EA value
  988. //
  989. typedef struct _AFD_SWITCH_OPEN_PACKET {
  990. HANDLE CompletionPort; // Completion port notify SAN switch
  991. // of SAN io completions
  992. HANDLE CompletionEvent;// Completion event to distinguish IO issued
  993. // by SAN switch from application IO.
  994. } AFD_SWITCH_OPEN_PACKET, *PAFD_SWITCH_OPEN_PACKET;
  995. typedef struct _AFD_SWITCH_CONTEXT {
  996. LONG EventsActive; // Poll events activated by switch
  997. LONG RcvCount; // Count of polls for receive
  998. LONG ExpCount; // Count of polls for expedited
  999. LONG SndCount; // Count of polls for send
  1000. BOOLEAN SelectFlag; // TRUE if app has done any form of select
  1001. } AFD_SWITCH_CONTEXT, *PAFD_SWITCH_CONTEXT;
  1002. //
  1003. // Information for associating AFD endpoint with SAN provider
  1004. //
  1005. typedef struct _AFD_SWITCH_CONTEXT_INFO {
  1006. HANDLE SocketHandle; // Handle to associate with SAN provider
  1007. PAFD_SWITCH_CONTEXT SwitchContext; // Opaque context value maintained for the switch
  1008. } AFD_SWITCH_CONTEXT_INFO, *PAFD_SWITCH_CONTEXT_INFO;
  1009. //
  1010. // Information for connection indication from SAN provider to AFD
  1011. //
  1012. typedef struct _AFD_SWITCH_CONNECT_INFO {
  1013. HANDLE ListenHandle; // Listening socket handle
  1014. PAFD_SWITCH_CONTEXT SwitchContext;
  1015. TRANSPORT_ADDRESS RemoteAddress; // Address of the remote peer wishing
  1016. // to connect
  1017. } AFD_SWITCH_CONNECT_INFO, *PAFD_SWITCH_CONNECT_INFO;
  1018. //
  1019. // Information returned by the AFD to switch in response
  1020. // to connection indication
  1021. //
  1022. typedef struct _AFD_SWITCH_ACCEPT_INFO {
  1023. HANDLE AcceptHandle; // Socket handle to use to accept connection
  1024. ULONG ReceiveLength; // Length of the initial receive buffer (for AcceptEx)
  1025. } AFD_SWITCH_ACCEPT_INFO, *PAFD_SWITCH_ACCEPT_INFO;
  1026. //
  1027. // Information passed by the switch to signal network events on the
  1028. // endpoint (socket)
  1029. //
  1030. typedef struct _AFD_SWITCH_EVENT_INFO {
  1031. HANDLE SocketHandle; // Socket handle on which to signal
  1032. PAFD_SWITCH_CONTEXT SwitchContext; // Switch context associated with the socket
  1033. ULONG EventBit; // Event bit to set/reset (AFD_POLL_xxx_BIT constants)
  1034. NTSTATUS Status; // Status code associated with the event (this
  1035. // is used for AFD_POLL_CONNECT_FAIL_BIT)
  1036. } AFD_SWITCH_EVENT_INFO, *PAFD_SWITCH_EVENT_INFO;
  1037. //
  1038. // Information passed by the switch to retreive parameters/complete
  1039. // redirected read/write request
  1040. //
  1041. typedef struct _AFD_SWITCH_REQUEST_INFO {
  1042. HANDLE SocketHandle; // Socket handle on which request us active
  1043. PAFD_SWITCH_CONTEXT SwitchContext; // Switch context associated with the socket
  1044. PVOID RequestContext; // Request context that identifies it
  1045. NTSTATUS RequestStatus; // Completion status of the request (STATUS_PENDING
  1046. // indicates that request should NOT be completed yet)
  1047. ULONG DataOffset; // Offset from which to start copying data from/to
  1048. // application's buffer
  1049. } AFD_SWITCH_REQUEST_INFO, *PAFD_SWITCH_REQUEST_INFO;
  1050. //
  1051. // Access type (read access or write access) that's needed for an app buffer
  1052. // whose physical address is requested thru AfdSanFastGetPhysicalAddr
  1053. //
  1054. #define MEM_READ_ACCESS 1
  1055. #define MEM_WRITE_ACCESS 2
  1056. //
  1057. // Information passed between processes when socket is duplicated.
  1058. //
  1059. typedef struct _AFD_SWITCH_ACQUIRE_CTX_INFO {
  1060. HANDLE SocketHandle; // Socket handle which needs to be transferred
  1061. PAFD_SWITCH_CONTEXT SwitchContext; // Switch context to be associated with the socket
  1062. PVOID SocketCtxBuf; // Socket context buffer
  1063. ULONG SocketCtxBufSize; // Socket context buffer size
  1064. } AFD_SWITCH_ACQUIRE_CTX_INFO, *PAFD_SWITCH_ACQUIRE_CTX_INFO;
  1065. typedef struct _AFD_SWITCH_TRANSFER_CTX_INFO {
  1066. HANDLE SocketHandle; // Socket handle which needs to be transferred
  1067. PAFD_SWITCH_CONTEXT SwitchContext; // Switch context associated with the socket
  1068. PVOID RequestContext; // Value that identifies corresponding acquire request
  1069. PVOID SocketCtxBuf; // Socket context buffer
  1070. ULONG SocketCtxBufSize; // Socket context buffer size
  1071. LPWSABUF RcvBufferArray; // Receive buffers to copy to destination process
  1072. ULONG RcvBufferCount; // Number of receive buffers
  1073. NTSTATUS Status; // Status of transfer opertaion.
  1074. } AFD_SWITCH_TRANSFER_CTX_INFO, *PAFD_SWITCH_TRANSFER_CTX_INFO;
  1075. //
  1076. // Request from AFD to switch (passed via completion port)
  1077. //
  1078. #define AFD_SWITCH_REQUEST_CLOSE 0
  1079. /*++
  1080. Request Description:
  1081. All references to the socket have been closed in all processes, safe
  1082. to destroy the SAN provider socket and connection
  1083. Arguments (NtRemoveIoCompletion return parameters):
  1084. Key - switch context associated with the socket
  1085. ApcContext - AFD_SWITCH_MAKE_REQUEST_CONTEXT(0, AFD_SWITCH_REQUEST_CLOSE)
  1086. IoStatus.Status - STATUS_SUCCESS (ignored)
  1087. IoStatus.Information - 0 (ignored)
  1088. --*/
  1089. #define AFD_SWITCH_REQUEST_READ 1
  1090. /*++
  1091. Request Description:
  1092. Read request arrived from the application via IO subsystem interface.
  1093. Arguments (NtRemoveIoCompletion return parameters):
  1094. Key - switch context associated with the socket
  1095. ApcContext - AFD_SWITCH_MAKE_REQUEST_CONTEXT(RequestId, AFD_SWITCH_REQUEST_READ)
  1096. IoStatus.Status - STATUS_SUCCESS (ignored)
  1097. IoStatus.Information - size of the receive buffer supplied by the application
  1098. --*/
  1099. #define AFD_SWITCH_REQUEST_WRITE 2
  1100. /*++
  1101. Request Description:
  1102. Write request arrived from the application via IO subsystem interface.
  1103. Arguments (NtRemoveIoCompletion return parameters):
  1104. Key - switch context associated with the socket
  1105. ApcContext - AFD_SWITCH_MAKE_REQUEST_CONTEXT(RequestId, AFD_SWITCH_REQUEST_WRITE)
  1106. IoStatus.Status - STATUS_SUCCESS (ignored)
  1107. IoStatus.Information - size of the send data supplied by the application
  1108. --*/
  1109. #define AFD_SWITCH_REQUEST_TFCTX 3
  1110. /*++
  1111. Request Description:
  1112. Another process requests ownership of the socket.
  1113. Arguments (NtRemoveIoCompletion return parameters):
  1114. Key - switch context associated with the socket
  1115. ApcContext - AFD_SWITCH_MAKE_REQUEST_CONTEXT(RequestId, AFD_SWITCH_REQUEST_TFCTX)
  1116. IoStatus.Status - STATUS_SUCCESS (ignored)
  1117. IoStatus.Information - PID of the process requesting ownership.
  1118. --*/
  1119. #define AFD_SWITCH_REQUEST_CHCTX 4
  1120. /*++
  1121. Request Description:
  1122. Relationship between socket handle and switch context has become invalid
  1123. (application must have closed the original socket and using duplicated handle)
  1124. Arguments (NtRemoveIoCompletion return parameters):
  1125. Key - switch context associated with the socket
  1126. ApcContext - AFD_SWITCH_MAKE_REQUEST_CONTEXT(0, AFD_SWITCH_REQUEST_CHCTX)
  1127. IoStatus.Status - STATUS_SUCCESS (ignored)
  1128. IoStatus.Information - Handle currently used by the application.
  1129. --*/
  1130. #define AFD_SWITCH_REQUEST_AQCTX 5
  1131. /*++
  1132. Request Description:
  1133. Request to service process to acquire ownership of the socket
  1134. Arguments (NtRemoveIoCompletion return parameters):
  1135. Key - NULL
  1136. ApcContext - AFD_SWITCH_MAKE_REQUEST_CONTEXT(0, AFD_SWITCH_REQUEST_AQCTX)
  1137. IoStatus.Status - STATUS_SUCCESS (ignored)
  1138. IoStatus.Information - Handle of the socket to be acquired.
  1139. --*/
  1140. #define AFD_SWITCH_REQUEST_CLSOC 6
  1141. /*++
  1142. Request Description:
  1143. Request to service process to close the socket
  1144. Arguments (NtRemoveIoCompletion return parameters):
  1145. Key - switch context associated with the socket
  1146. ApcContext - AFD_SWITCH_MAKE_REQUEST_CONTEXT(0, AFD_SWITCH_REQUEST_CLSOC)
  1147. IoStatus.Status - STATUS_SUCCESS (ignored)
  1148. IoStatus.Information - 0.
  1149. --*/
  1150. #define AFD_SWITCH_REQUEST_ID_SHIFT 3
  1151. #define AFD_SWITCH_REQUEST_TYPE_MASK \
  1152. ((1<<AFD_SWITCH_REQUEST_ID_SHIFT)-1)
  1153. #define AFD_SWITCH_MAKE_REQUEST_CONTEXT(_id,_type) \
  1154. UlongToPtr(((_id)<<AFD_SWITCH_REQUEST_ID_SHIFT)+(_type))
  1155. //
  1156. // Retrives request type from the request context
  1157. //
  1158. #define AFD_SWITCH_REQUEST_TYPE(_RequestContext) \
  1159. (((ULONG_PTR)(_RequestContext))&AFD_SWITCH_REQUEST_TYPE_MASK)
  1160. #endif // ndef _AFD_