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.

1336 lines
53 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. #ifndef _WINSOCK2API_
  419. typedef struct _TRANSMIT_PACKETS_ELEMENT {
  420. ULONG dwElFlags;
  421. #define TP_MEMORY 1
  422. #define TP_FILE 2
  423. #define TP_EOP 4
  424. ULONG cLength;
  425. union {
  426. struct {
  427. LARGE_INTEGER nFileOffset;
  428. HANDLE hFile;
  429. };
  430. PVOID pBuffer;
  431. };
  432. } TRANSMIT_PACKETS_ELEMENT, *LPTRANSMIT_PACKETS_ELEMENT;
  433. #else
  434. typedef struct _TRANSMIT_PACKETS_ELEMENT TRANSMIT_PACKETS_ELEMENT, *LPTRANSMIT_PACKETS_ELEMENT;
  435. #endif
  436. typedef struct _AFD_TPACKETS_INFO {
  437. LPTRANSMIT_PACKETS_ELEMENT ElementArray;
  438. ULONG ElementCount;
  439. ULONG SendSize;
  440. ULONG Flags;
  441. } AFD_TPACKETS_INFO, *PAFD_TPACKETS_INFO;
  442. //
  443. // AFD IOCTL code definitions.
  444. //
  445. // N.B. To ensure the efficient of the code generated by AFD's
  446. // IOCTL dispatcher, these IOCTL codes should be contiguous
  447. // (no gaps).
  448. //
  449. // N.B. If new IOCTLs are added here, update the lookup table in
  450. // ntos\afd\dispatch.c!
  451. //
  452. #define FSCTL_AFD_BASE FILE_DEVICE_NETWORK
  453. #define _AFD_CONTROL_CODE(request,method) \
  454. ((FSCTL_AFD_BASE)<<12 | (request<<2) | method)
  455. #define _AFD_REQUEST(ioctl) \
  456. ((((ULONG)(ioctl)) >> 2) & 0x03FF)
  457. #define _AFD_BASE(ioctl) \
  458. ((((ULONG)(ioctl)) >> 12) & 0xFFFFF)
  459. #define AFD_BIND 0
  460. #define AFD_CONNECT 1
  461. #define AFD_START_LISTEN 2
  462. #define AFD_WAIT_FOR_LISTEN 3
  463. #define AFD_ACCEPT 4
  464. #define AFD_RECEIVE 5
  465. #define AFD_RECEIVE_DATAGRAM 6
  466. #define AFD_SEND 7
  467. #define AFD_SEND_DATAGRAM 8
  468. #define AFD_POLL 9
  469. #define AFD_PARTIAL_DISCONNECT 10
  470. #define AFD_GET_ADDRESS 11
  471. #define AFD_QUERY_RECEIVE_INFO 12
  472. #define AFD_QUERY_HANDLES 13
  473. #define AFD_SET_INFORMATION 14
  474. #define AFD_GET_REMOTE_ADDRESS 15
  475. #define AFD_GET_CONTEXT 16
  476. #define AFD_SET_CONTEXT 17
  477. #define AFD_SET_CONNECT_DATA 18
  478. #define AFD_SET_CONNECT_OPTIONS 19
  479. #define AFD_SET_DISCONNECT_DATA 20
  480. #define AFD_SET_DISCONNECT_OPTIONS 21
  481. #define AFD_GET_CONNECT_DATA 22
  482. #define AFD_GET_CONNECT_OPTIONS 23
  483. #define AFD_GET_DISCONNECT_DATA 24
  484. #define AFD_GET_DISCONNECT_OPTIONS 25
  485. #define AFD_SIZE_CONNECT_DATA 26
  486. #define AFD_SIZE_CONNECT_OPTIONS 27
  487. #define AFD_SIZE_DISCONNECT_DATA 28
  488. #define AFD_SIZE_DISCONNECT_OPTIONS 29
  489. #define AFD_GET_INFORMATION 30
  490. #define AFD_TRANSMIT_FILE 31
  491. #define AFD_SUPER_ACCEPT 32
  492. #define AFD_EVENT_SELECT 33
  493. #define AFD_ENUM_NETWORK_EVENTS 34
  494. #define AFD_DEFER_ACCEPT 35
  495. #define AFD_WAIT_FOR_LISTEN_LIFO 36
  496. #define AFD_SET_QOS 37
  497. #define AFD_GET_QOS 38
  498. #define AFD_NO_OPERATION 39
  499. #define AFD_VALIDATE_GROUP 40
  500. #define AFD_GET_UNACCEPTED_CONNECT_DATA 41
  501. #define AFD_ROUTING_INTERFACE_QUERY 42
  502. #define AFD_ROUTING_INTERFACE_CHANGE 43
  503. #define AFD_ADDRESS_LIST_QUERY 44
  504. #define AFD_ADDRESS_LIST_CHANGE 45
  505. #define AFD_JOIN_LEAF 46
  506. #define AFD_TRANSPORT_IOCTL 47
  507. #define AFD_TRANSMIT_PACKETS 48
  508. #define AFD_SUPER_CONNECT 49
  509. #define AFD_SUPER_DISCONNECT 50
  510. #define AFD_RECEIVE_MESSAGE 51
  511. //
  512. // SAN switch specific AFD function numbers
  513. //
  514. #define AFD_SWITCH_CEMENT_SAN 52
  515. #define AFD_SWITCH_SET_EVENTS 53
  516. #define AFD_SWITCH_RESET_EVENTS 54
  517. #define AFD_SWITCH_CONNECT_IND 55
  518. #define AFD_SWITCH_CMPL_ACCEPT 56
  519. #define AFD_SWITCH_CMPL_REQUEST 57
  520. #define AFD_SWITCH_CMPL_IO 58
  521. #define AFD_SWITCH_REFRESH_ENDP 59
  522. #define AFD_SWITCH_GET_PHYSICAL_ADDR 60
  523. #define AFD_SWITCH_ACQUIRE_CTX 61
  524. #define AFD_SWITCH_TRANSFER_CTX 62
  525. #define AFD_SWITCH_GET_SERVICE_PID 63
  526. #define AFD_SWITCH_SET_SERVICE_PROCESS 64
  527. #define AFD_SWITCH_PROVIDER_CHANGE 65
  528. #define AFD_SWITCH_ADDRLIST_CHANGE 66
  529. #define AFD_NUM_IOCTLS 67
  530. #define IOCTL_AFD_BIND _AFD_CONTROL_CODE( AFD_BIND, METHOD_NEITHER )
  531. #define IOCTL_AFD_CONNECT _AFD_CONTROL_CODE( AFD_CONNECT, METHOD_NEITHER )
  532. #define IOCTL_AFD_START_LISTEN _AFD_CONTROL_CODE( AFD_START_LISTEN, METHOD_NEITHER )
  533. #define IOCTL_AFD_WAIT_FOR_LISTEN _AFD_CONTROL_CODE( AFD_WAIT_FOR_LISTEN, METHOD_BUFFERED )
  534. #define IOCTL_AFD_ACCEPT _AFD_CONTROL_CODE( AFD_ACCEPT, METHOD_BUFFERED )
  535. #define IOCTL_AFD_RECEIVE _AFD_CONTROL_CODE( AFD_RECEIVE, METHOD_NEITHER )
  536. #define IOCTL_AFD_RECEIVE_DATAGRAM _AFD_CONTROL_CODE( AFD_RECEIVE_DATAGRAM, METHOD_NEITHER )
  537. #define IOCTL_AFD_SEND _AFD_CONTROL_CODE( AFD_SEND, METHOD_NEITHER )
  538. #define IOCTL_AFD_SEND_DATAGRAM _AFD_CONTROL_CODE( AFD_SEND_DATAGRAM, METHOD_NEITHER )
  539. #define IOCTL_AFD_POLL _AFD_CONTROL_CODE( AFD_POLL, METHOD_BUFFERED )
  540. #define IOCTL_AFD_PARTIAL_DISCONNECT _AFD_CONTROL_CODE( AFD_PARTIAL_DISCONNECT, METHOD_NEITHER )
  541. #define IOCTL_AFD_GET_ADDRESS _AFD_CONTROL_CODE( AFD_GET_ADDRESS, METHOD_NEITHER )
  542. #define IOCTL_AFD_QUERY_RECEIVE_INFO _AFD_CONTROL_CODE( AFD_QUERY_RECEIVE_INFO, METHOD_NEITHER )
  543. #define IOCTL_AFD_QUERY_HANDLES _AFD_CONTROL_CODE( AFD_QUERY_HANDLES, METHOD_NEITHER )
  544. #define IOCTL_AFD_SET_INFORMATION _AFD_CONTROL_CODE( AFD_SET_INFORMATION, METHOD_NEITHER )
  545. #define IOCTL_AFD_GET_REMOTE_ADDRESS _AFD_CONTROL_CODE( AFD_GET_REMOTE_ADDRESS, METHOD_NEITHER )
  546. #define IOCTL_AFD_GET_CONTEXT _AFD_CONTROL_CODE( AFD_GET_CONTEXT, METHOD_NEITHER )
  547. #define IOCTL_AFD_SET_CONTEXT _AFD_CONTROL_CODE( AFD_SET_CONTEXT, METHOD_NEITHER )
  548. #define IOCTL_AFD_SET_CONNECT_DATA _AFD_CONTROL_CODE( AFD_SET_CONNECT_DATA, METHOD_NEITHER )
  549. #define IOCTL_AFD_SET_CONNECT_OPTIONS _AFD_CONTROL_CODE( AFD_SET_CONNECT_OPTIONS, METHOD_NEITHER )
  550. #define IOCTL_AFD_SET_DISCONNECT_DATA _AFD_CONTROL_CODE( AFD_SET_DISCONNECT_DATA, METHOD_NEITHER )
  551. #define IOCTL_AFD_SET_DISCONNECT_OPTIONS _AFD_CONTROL_CODE( AFD_SET_DISCONNECT_OPTIONS, METHOD_NEITHER )
  552. #define IOCTL_AFD_GET_CONNECT_DATA _AFD_CONTROL_CODE( AFD_GET_CONNECT_DATA, METHOD_NEITHER )
  553. #define IOCTL_AFD_GET_CONNECT_OPTIONS _AFD_CONTROL_CODE( AFD_GET_CONNECT_OPTIONS, METHOD_NEITHER )
  554. #define IOCTL_AFD_GET_DISCONNECT_DATA _AFD_CONTROL_CODE( AFD_GET_DISCONNECT_DATA, METHOD_NEITHER )
  555. #define IOCTL_AFD_GET_DISCONNECT_OPTIONS _AFD_CONTROL_CODE( AFD_GET_DISCONNECT_OPTIONS, METHOD_NEITHER )
  556. #define IOCTL_AFD_SIZE_CONNECT_DATA _AFD_CONTROL_CODE( AFD_SIZE_CONNECT_DATA, METHOD_NEITHER )
  557. #define IOCTL_AFD_SIZE_CONNECT_OPTIONS _AFD_CONTROL_CODE( AFD_SIZE_CONNECT_OPTIONS, METHOD_NEITHER )
  558. #define IOCTL_AFD_SIZE_DISCONNECT_DATA _AFD_CONTROL_CODE( AFD_SIZE_DISCONNECT_DATA, METHOD_NEITHER )
  559. #define IOCTL_AFD_SIZE_DISCONNECT_OPTIONS _AFD_CONTROL_CODE( AFD_SIZE_DISCONNECT_OPTIONS, METHOD_NEITHER )
  560. #define IOCTL_AFD_GET_INFORMATION _AFD_CONTROL_CODE( AFD_GET_INFORMATION, METHOD_NEITHER )
  561. #define IOCTL_AFD_TRANSMIT_FILE _AFD_CONTROL_CODE( AFD_TRANSMIT_FILE, METHOD_NEITHER )
  562. #define IOCTL_AFD_SUPER_ACCEPT _AFD_CONTROL_CODE( AFD_SUPER_ACCEPT, METHOD_NEITHER )
  563. #define IOCTL_AFD_EVENT_SELECT _AFD_CONTROL_CODE( AFD_EVENT_SELECT, METHOD_NEITHER )
  564. #define IOCTL_AFD_ENUM_NETWORK_EVENTS _AFD_CONTROL_CODE( AFD_ENUM_NETWORK_EVENTS, METHOD_NEITHER )
  565. #define IOCTL_AFD_DEFER_ACCEPT _AFD_CONTROL_CODE( AFD_DEFER_ACCEPT, METHOD_BUFFERED )
  566. #define IOCTL_AFD_WAIT_FOR_LISTEN_LIFO _AFD_CONTROL_CODE( AFD_WAIT_FOR_LISTEN_LIFO, METHOD_BUFFERED )
  567. #define IOCTL_AFD_SET_QOS _AFD_CONTROL_CODE( AFD_SET_QOS, METHOD_BUFFERED )
  568. #define IOCTL_AFD_GET_QOS _AFD_CONTROL_CODE( AFD_GET_QOS, METHOD_BUFFERED )
  569. #define IOCTL_AFD_NO_OPERATION _AFD_CONTROL_CODE( AFD_NO_OPERATION, METHOD_NEITHER )
  570. #define IOCTL_AFD_VALIDATE_GROUP _AFD_CONTROL_CODE( AFD_VALIDATE_GROUP, METHOD_BUFFERED )
  571. #define IOCTL_AFD_GET_UNACCEPTED_CONNECT_DATA _AFD_CONTROL_CODE( AFD_GET_UNACCEPTED_CONNECT_DATA, METHOD_NEITHER )
  572. #define IOCTL_AFD_ROUTING_INTERFACE_QUERY _AFD_CONTROL_CODE( AFD_ROUTING_INTERFACE_QUERY, METHOD_NEITHER )
  573. #define IOCTL_AFD_ROUTING_INTERFACE_CHANGE _AFD_CONTROL_CODE( AFD_ROUTING_INTERFACE_CHANGE, METHOD_BUFFERED )
  574. #define IOCTL_AFD_ADDRESS_LIST_QUERY _AFD_CONTROL_CODE( AFD_ADDRESS_LIST_QUERY, METHOD_NEITHER )
  575. #define IOCTL_AFD_ADDRESS_LIST_CHANGE _AFD_CONTROL_CODE( AFD_ADDRESS_LIST_CHANGE, METHOD_BUFFERED )
  576. #define IOCTL_AFD_JOIN_LEAF _AFD_CONTROL_CODE( AFD_JOIN_LEAF, METHOD_NEITHER )
  577. #define IOCTL_AFD_TRANSPORT_IOCTL _AFD_CONTROL_CODE( AFD_TRANSPORT_IOCTL, METHOD_NEITHER )
  578. #define IOCTL_AFD_TRANSMIT_PACKETS _AFD_CONTROL_CODE( AFD_TRANSMIT_PACKETS, METHOD_NEITHER )
  579. #define IOCTL_AFD_SUPER_CONNECT _AFD_CONTROL_CODE( AFD_SUPER_CONNECT, METHOD_NEITHER )
  580. #define IOCTL_AFD_SUPER_DISCONNECT _AFD_CONTROL_CODE( AFD_SUPER_DISCONNECT, METHOD_NEITHER )
  581. #define IOCTL_AFD_RECEIVE_MESSAGE _AFD_CONTROL_CODE( AFD_RECEIVE_MESSAGE, METHOD_NEITHER )
  582. //
  583. // SAN support
  584. //
  585. //
  586. //
  587. // SAN IOCTL control codes.
  588. //
  589. #define IOCTL_AFD_SWITCH_CEMENT_SAN _AFD_CONTROL_CODE( AFD_SWITCH_CEMENT_SAN, METHOD_NEITHER )
  590. /*++
  591. Ioctl Description:
  592. Changes the AFD endpoint type to SAN to indicate that
  593. it is used for support of user mode SAN providers
  594. Associates switch context with the endpoint.
  595. Arguments:
  596. Handle - helper endpoint handle for the process.
  597. InputBuffer - input parameters for the operation (AFD_SWITCH_CONTEXT_INFO)
  598. SocketHandle - handle of the endpoint being changed to SAN
  599. SwitchContext - switch context associated with the endpoint
  600. InputBufferLength - sizeof(AFD_SWITCH_CONTEXT_INFO)
  601. OutputBuffer - NULL (ingored)
  602. OutputBufferLength - 0 (ignored)
  603. Return Value:
  604. IoStatus.Status:
  605. STATUS_SUCCESS - operation succeeded.
  606. STATUS_OBJECT_TYPE_MISMATCH - helper handle or switch socket handle are not
  607. AFD file object handles
  608. STATUS_INVALID_HANDLE - helper handle or switch socket handle correspond to AFD
  609. endpoint of incorrect type/state.
  610. STATUS_INVALID_PARAMETER - input buffer is of incorrect size.
  611. other - failed when attempting to access switch socket, input buffer, or switch context.
  612. IoStatus.Information - 0 (ignored)
  613. --*/
  614. #define IOCTL_AFD_SWITCH_SET_EVENTS _AFD_CONTROL_CODE( AFD_SWITCH_SET_EVENTS, METHOD_NEITHER )
  615. /*++
  616. Ioctl Description:
  617. Sets the poll event on the san endpoint to report
  618. to the application via various forms of the select.
  619. Arguments:
  620. Handle - helper endpoint handle for the process.
  621. InputBuffer - input parameters for the operation (AFD_SWITCH_EVENT_INFO)
  622. SocketHandle - handle of the SAN endpoint (except
  623. AFD_POLL_EVENT_CONNECT_FAIL which
  624. just needs a bound endpoint).
  625. SwitchContext - switch context associated with endpoint (NULL
  626. for AFD_POLL_EVENT_CONNECT_FAIL) to validate
  627. the handle-endpoint association
  628. EventBit - event bit to set
  629. Status - associated status (for AFD_POLL_EVENT_CONNECT_FAIL)
  630. InputBufferLength - sizeof(AFD_SWITCH_EVENT_INFO)
  631. OutputBuffer - NULL (ignored)
  632. OutputBufferLength - 0 (ignored)
  633. Return Value:
  634. IoStatus.Status:
  635. STATUS_SUCCESS - operation succeeded.
  636. STATUS_OBJECT_TYPE_MISMATCH - helper handle or switch socket handle are not
  637. AFD file object handles
  638. STATUS_INVALID_HANDLE - helper handle or switch socket handle+context correspond
  639. to AFD endpoint of incorrect type/state.
  640. STATUS_INVALID_PARAMETER - input buffer is of incorrect size.
  641. other - failed when attempting to access switch socket, input buffer, or switch context.
  642. IoStatus.Information - 0 (ignored)
  643. --*/
  644. #define IOCTL_AFD_SWITCH_RESET_EVENTS _AFD_CONTROL_CODE( AFD_SWITCH_RESET_EVENTS, METHOD_NEITHER )
  645. /*++
  646. Ioctl Description:
  647. Resets the poll event on the san endpoint so that it is no
  648. longer reported to the application via various forms of the select
  649. Arguments:
  650. Handle - helper endpoint handle for the process.
  651. InputBuffer - input parameters for the operation (AFD_SWITCH_EVENT_INFO)
  652. SocketHandle - handle of the SAN endpoint
  653. SwitchContext - switch context associated with endpoint
  654. to validate the handle-endpoint association
  655. EventBit - event bit to reset
  656. Status - associated status (ignored)
  657. InputBufferLength - sizeof(AFD_SWITCH_EVENT_INFO)
  658. OutputBuffer - NULL (ignored)
  659. OutputBufferLength - 0 (ignored)
  660. Return Value:
  661. IoStatus.Status:
  662. STATUS_SUCCESS - operation succeeded.
  663. STATUS_OBJECT_TYPE_MISMATCH - helper handle or switch socket handle are not
  664. AFD file object handles
  665. STATUS_INVALID_HANDLE - helper handle or switch socket handle+context correspond
  666. to AFD endpoint of incorrect type/state.
  667. STATUS_INVALID_PARAMETER - input buffer is of incorrect size.
  668. other - failed when attempting to access switch socket, input buffer, or switch context.
  669. IoStatus.Information - 0 (ignored)
  670. --*/
  671. #define IOCTL_AFD_SWITCH_CONNECT_IND _AFD_CONTROL_CODE( AFD_SWITCH_CONNECT_IND, METHOD_OUT_DIRECT )
  672. /*++
  673. Ioctl Description:
  674. Implements connect indication from SAN provider.
  675. Picks up the accept from the listening endpoint queue
  676. or queues the indication an signals the application to come
  677. down with an accept.
  678. Arguments:
  679. Handle - helper endpoint handle for the process.
  680. InputBuffer - input parameters for the operation (AFD_SWITCH_CONNECT_INFO):
  681. ListenHandle - handle of the listening endpoint
  682. RemoteAddress - remote and local addresses associated
  683. with indication incoming connection
  684. InputBufferLength - sizeof(AFD_SWITCH_CONNECT_INFO)+addresses
  685. OutputBuffer - output parameters for the operation (AFD_SWITCH_ACCEPT_INFO):
  686. AcceptHandle - handle of the accepting endpoint
  687. ReceiveLength - length of the receive buffer supplied by
  688. the application in AcceptEx
  689. OutputBufferLength - sizeof (AFD_SWITCH_ACCEPT_INFO)
  690. Return Value:
  691. STATUS_PENDING - request was queued waiting for corresponding transfer request
  692. from the current socket context owner process.
  693. IoStatus.Status:
  694. STATUS_SUCCESS - operation succeeded.
  695. STATUS_OBJECT_TYPE_MISMATCH - helper handle or listen socket handle are not
  696. AFD file object handles
  697. STATUS_INVALID_HANDLE - helper handle or listen socket handle correspond
  698. to AFD endpoint of incorrect type/state.
  699. STATUS_INVALID_PARAMETER - input or output buffers are of incorrect size.
  700. STATUS_CANCELLED - connection indication was cancelled (thread exited or
  701. accepting and/or listening socket closed)
  702. other - failed when attempting to access listening socket, input or output buffers
  703. IoStatus.Information - sizeof (AFD_SWITCH_ACCEPT_INFO) in case of success.
  704. --*/
  705. #define IOCTL_AFD_SWITCH_CMPL_ACCEPT _AFD_CONTROL_CODE( AFD_SWITCH_CMPL_ACCEPT, METHOD_NEITHER )
  706. /*++
  707. Ioctl Description:
  708. Completes the acceptance of SAN connection
  709. Arguments:
  710. Handle - helper endpoint handle for the process.
  711. InputBuffer - input parameters for the operation (AFD_SWITCH_CONTEXT_INFO)
  712. SocketHandle - handle of the accepting endpoint
  713. SwitchContext - switch context associated with the endpoint
  714. InputBufferLength - sizeof(AFD_SWITCH_CONTEXT_INFO)
  715. OutputBuffer - data to copy into the AcceptEx receive buffer
  716. OutputBufferLength - size of received data
  717. Return Value:
  718. IoStatus.Status:
  719. STATUS_SUCCESS - operation succeeded.
  720. STATUS_OBJECT_TYPE_MISMATCH - helper handle or switch socket handle are not
  721. AFD file object handles
  722. STATUS_INVALID_HANDLE - helper handle or switch socket handle+context correspond
  723. to AFD endpoint of incorrect type/state.
  724. STATUS_INVALID_PARAMETER - input buffer is of incorrect size.
  725. STATUS_LOCAL_DISCONNECT - accept was aborted by the application.
  726. other - failed when attempting to access accepte socket, input/output buffers,
  727. or switch context.
  728. IoStatus.Information - Number of bytes copied into application's receive buffer.
  729. --*/
  730. #define IOCTL_AFD_SWITCH_CMPL_REQUEST _AFD_CONTROL_CODE( AFD_SWITCH_CMPL_REQUEST, METHOD_NEITHER )
  731. /*++
  732. Ioctl Description:
  733. Completes the redirected read/write request processed by SAN provider
  734. Arguments:
  735. Handle - helper endpoint handle for the process.
  736. InputBuffer - input parameters for the operation (AFD_SWITCH_REQUEST_INFO)
  737. SocketHandle - SAN endpoint on which to complete the request
  738. SwitchContext - switch context associated with endpoint
  739. to validate the handle-endpoint association
  740. RequestContext - value that identifies the request to complete
  741. RequestStatus - status with which to complete the request (
  742. STATUS_PENDING has special meaning, request
  743. is not completed - merely data is copied)
  744. DataOffset - offset in the request buffer to read/write the data
  745. InputBufferLength - sizeof (AFD_SWITCH_REQUEST_INFO)
  746. OutputBuffer - switch buffer to read/write data
  747. OutputBufferLength - length of the buffer
  748. Return Value:
  749. IoStatus.Status:
  750. STATUS_SUCCESS - operation succeeded.
  751. STATUS_OBJECT_TYPE_MISMATCH - helper handle or switch socket handle are not
  752. AFD file object handles
  753. STATUS_INVALID_HANDLE - helper handle or switch socket handle+context correspond
  754. to AFD endpoint of incorrect type/state.
  755. STATUS_INVALID_PARAMETER - input buffer is of incorrect size.
  756. STATUS_CANCELLED - request to be completed has already been cancelled
  757. other - failed when attempting to access SAN endpoint,
  758. input buffer or output buffers.
  759. IoStatus.Information - number of bytes copied from/to switch buffer.
  760. --*/
  761. #define IOCTL_AFD_SWITCH_CMPL_IO _AFD_CONTROL_CODE( AFD_SWITCH_CMPL_IO, METHOD_NEITHER )
  762. /*++
  763. Ioctl Description:
  764. Simulates async IO completion for the switch.
  765. Arguments:
  766. Handle - SAN socket handle on which to complete the IO.
  767. InputBuffer - input parameters for the operation (IO_STATUS_BLOCK)
  768. Status - final operation status
  769. Information - associated information (number of bytes
  770. transferred to/from request buffer(s))
  771. InputBufferLength - sizeof (IO_STATUS_BLOCK)
  772. OutputBuffer - NULL (ignored)
  773. OutputBufferLength - 0 (ignored)
  774. Return Value:
  775. IoStatus.Status:
  776. STATUS_INVALID_PARAMETER - input buffer is of invalid size.
  777. other - status of the IO operation or failure code when attempting to
  778. access input buffer.
  779. IoStatus.Information - information from the input buffer
  780. --*/
  781. #define IOCTL_AFD_SWITCH_REFRESH_ENDP _AFD_CONTROL_CODE( AFD_SWITCH_REFRESH_ENDP, METHOD_NEITHER )
  782. /*++
  783. Ioctl Description:
  784. Refreshes endpoint so it can be used again in AcceptEx
  785. Arguments:
  786. Handle - helper endpoint handle for the process.
  787. InputBuffer - input parameters for the operation (AFD_SWITCH_CONTEXT_INFO)
  788. SocketHandle - Socket to refresh
  789. SwitchContext - switch context associated with endpoint
  790. to validate the handle-endpoint association
  791. InputBufferLength - sizeof (AFD_SWITCH_CONTEXT_INFO)
  792. OutputBuffer - NULL (ignored)
  793. OutputBufferLength - 0 (ignored)
  794. Return Value:
  795. IoStatus.Status:
  796. STATUS_SUCCESS - operation succeeded.
  797. STATUS_OBJECT_TYPE_MISMATCH - helper handle or switch socket handle are not
  798. AFD file object handles
  799. STATUS_INVALID_HANDLE - helper handle or switch socket handle+context correspond
  800. to AFD endpoint of incorrect type/state.
  801. STATUS_INVALID_PARAMETER - input buffer is of incorrect size.
  802. other - failed when attempting to access SAN endpoint,
  803. input buffer buffer.
  804. IoStatus.Information - 0 (ignored)
  805. --*/
  806. #define IOCTL_AFD_SWITCH_GET_PHYSICAL_ADDR _AFD_CONTROL_CODE( AFD_SWITCH_GET_PHYSICAL_ADDR, METHOD_NEITHER )
  807. /*++
  808. Ioctl Description:
  809. Returns physical address corresponding to provided virtual address.
  810. Arguments:
  811. Handle - helper endpoint handle for the process.
  812. InputBuffer - user mode virtual address
  813. InputBufferLength - access mode
  814. OutputBuffer - Buffer to place physical address into.
  815. OutputBufferLength - sizeof (PHYSICAL_ADDRESS)
  816. Return Value:
  817. IoStatus.Status:
  818. STATUS_SUCCESS - operation succeeded.
  819. STATUS_OBJECT_TYPE_MISMATCH - helper handle is not AFD file object handle
  820. STATUS_INVALID_HANDLE - helper handle corresponds to AFD endpoint of incorrect
  821. type.
  822. STATUS_BUFFER_TOO_SMALL - output buffer is of incorrect size.
  823. STATUS_INVALID_PARAMETER - invalid access mode.
  824. other - failed when attempting to access SAN endpoint,
  825. input buffer buffer.
  826. IoStatus.Information - sizeof(PHYSICAL_ADDRESS).
  827. --*/
  828. #define IOCTL_AFD_SWITCH_ACQUIRE_CTX _AFD_CONTROL_CODE( AFD_SWITCH_ACQUIRE_CTX, METHOD_NEITHER )
  829. /*++
  830. Ioctl Description:
  831. Requests transfer of the socket context to the current process.
  832. Arguments:
  833. Handle - helper endpoint handle for the process.
  834. InputBuffer - input parameters for the operation (AFD_SWITCH_ACQUIRE_CTX_INFO)
  835. SocketHandle - SAN endpoint on which to complete the request
  836. SwitchContext - switch context to be associated with endpoint
  837. when context transfered to the current process.
  838. SocketCtxBuf - buffer to receive current socket context from
  839. another process
  840. SocketCtxBufSize - size of the buffer
  841. InputBufferLength - sizeof (AFD_SWITCH_ACQUIRE_CTX_INFO)
  842. OutputBuffer - buffer to receive data buffered on the socket in another process
  843. and not yet delivered to the applicaiton
  844. OutputBufferLength - length of the receive buffer
  845. Return Value:
  846. STATUS_PENDING - request was queued waiting for corresponding transfer request
  847. from the current socket context owner process.
  848. IoStatus.Status:
  849. STATUS_SUCCESS - operation succeeded.
  850. STATUS_OBJECT_TYPE_MISMATCH - helper handle or switch socket handle are not
  851. AFD file object handles
  852. STATUS_INVALID_HANDLE - helper handle or switch socket handle correspond
  853. to AFD endpoint of incorrect type/state.
  854. STATUS_INVALID_PARAMETER - input buffer is of incorrect size.
  855. other - failed when attempting to access SAN endpoint,
  856. input buffer or output buffers.
  857. IoStatus.Information - number of bytes copied to receive buffer.
  858. --*/
  859. #define IOCTL_AFD_SWITCH_TRANSFER_CTX _AFD_CONTROL_CODE( AFD_SWITCH_TRANSFER_CTX, METHOD_NEITHER )
  860. /*++
  861. Ioctl Description:
  862. Requests AFD to transfer endpoint into another process context
  863. Arguments:
  864. InputBuffer - input parameters for the operation (AFD_SWITCH_TRANSFER_CTX_INFO)
  865. SocketHandle - Socket to transfer
  866. SwitchContext - switch context associated with endpoint
  867. to validate the handle-endpoint association
  868. RequestContext - value that identifies corresponding acquire request,
  869. NULL if this is unsolicited request to transfer to
  870. the service process.
  871. SocketCtxBuf - socket context to copy destination process
  872. acquire request context buffer
  873. SocketCtxSize - size of the context buffer to copy
  874. RcvBufferArray - array of buffered data to transfer to
  875. destination process acquire request
  876. RcvBufferCount - number of elements in the array.
  877. InputBufferLength - sizeof (AFD_SWITCH_TRANSFER_CTX_INFO)
  878. OutputBuffer - NULL (ignored)
  879. OutputBufferLength - 0 (ignored)
  880. Return Value:
  881. IoStatus.Status:
  882. STATUS_SUCCESS - operation succeeded.
  883. STATUS_OBJECT_TYPE_MISMATCH - helper handle or switch socket handle are not
  884. AFD file object handles
  885. STATUS_INVALID_HANDLE - helper handle or switch socket handle+context correspond
  886. to AFD endpoint of incorrect type/state.
  887. STATUS_INVALID_PARAMETER - input buffer is of incorrect size.
  888. other - failed when attempting to access SAN endpoint,
  889. input buffer buffer.
  890. IoStatus.Information - number of bytes copied from RcvBufferArray.
  891. --*/
  892. #define IOCTL_AFD_SWITCH_GET_SERVICE_PID _AFD_CONTROL_CODE( AFD_SWITCH_GET_SERVICE_PID, METHOD_NEITHER )
  893. /*++
  894. Ioctl Description:
  895. Returns PID of the service process used for intermediate socket duplication.
  896. Arguments:
  897. Handle - helper endpoint handle for the process.
  898. InputBuffer - NULL, ignored
  899. InputBufferLength - 0, ignored
  900. OutputBuffer - NULL, ignored
  901. OutputBufferLength - 0, ignored
  902. Return Value:
  903. IoStatus.Status:
  904. STATUS_SUCCESS - operation succeeded.
  905. STATUS_OBJECT_TYPE_MISMATCH - helper handle is not AFD file object handle
  906. STATUS_INVALID_HANDLE - helper handle corresponds to AFD endpoint of incorrect
  907. type.
  908. IoStatus.Information - pid of the service process.
  909. --*/
  910. #define IOCTL_AFD_SWITCH_SET_SERVICE_PROCESS _AFD_CONTROL_CODE( AFD_SWITCH_SET_SERVICE_PROCESS, METHOD_NEITHER )
  911. /*++
  912. Ioctl Description:
  913. Notifies AFD that this process will be used for handle duplication services
  914. Arguments:
  915. Handle - helper endpoint handle for the service process.
  916. InputBuffer - NULL, ignored
  917. InputBufferLength - 0, ignored
  918. OutputBuffer - NULL, ignored
  919. OutputBufferLength - 0, ignored
  920. Return Value:
  921. IoStatus.Status:
  922. STATUS_SUCCESS - operation succeeded.
  923. STATUS_OBJECT_TYPE_MISMATCH - helper handle is not AFD file object handle
  924. STATUS_INVALID_HANDLE - helper handle corresponds to AFD endpoint of incorrect
  925. type.
  926. STATUS_ACCESS_DENIED - helper endpoint is not for the service process.
  927. IoStatus.Information - 0, ignored.
  928. --*/
  929. #define IOCTL_AFD_SWITCH_PROVIDER_CHANGE _AFD_CONTROL_CODE( AFD_SWITCH_PROVIDER_CHANGE, METHOD_NEITHER )
  930. /*++
  931. Ioctl Description:
  932. Notifies interested processes of SAN provider addition/deletion/change.
  933. Arguments:
  934. Handle - helper endpoint handle for the service process.
  935. InputBuffer - NULL, ignored
  936. InputBufferLength - 0, ignored
  937. OutputBuffer - NULL, ignored
  938. OutputBufferLength - 0, ignored
  939. Return Value:
  940. IoStatus.Status:
  941. STATUS_SUCCESS - operation succeeded.
  942. STATUS_OBJECT_TYPE_MISMATCH - helper handle is not AFD file object handle
  943. STATUS_INVALID_HANDLE - helper handle corresponds to AFD endpoint of incorrect
  944. type.
  945. STATUS_ACCESS_DENIED - helper endpoint is not for the service process.
  946. IoStatus.Information - 0, ignored.
  947. --*/
  948. #define IOCTL_AFD_SWITCH_ADDRLIST_CHANGE _AFD_CONTROL_CODE( AFD_SWITCH_ADDRLIST_CHANGE, METHOD_BUFFERED )
  949. /*++
  950. Ioctl Description:
  951. SAN specific version of address list change notifications.
  952. Capture provider installation/removal in addition to plain
  953. address list changes.
  954. Arguments:
  955. Handle - helper endpoint handle for the service process.
  956. InputBuffer - Input parameters for the operation (AFD_TRANSPORT_IOCTL_INFO):
  957. AfdFlags - operation flags (e.g. AFD_OVERLAPPED)
  958. Handle - unused
  959. PollEvent - unused
  960. IoControlCode - IOCTL_AFD_ADDRESS_LIST_CHANGE
  961. InputBuffer - pointer to address family (AF_INET)
  962. InputBufferLength - sizeof (USHORT)
  963. InputBufferLength - sizeof (AFD_TRANSPORT_IOCTL_INFO)
  964. OutputBuffer - NULL, ignored
  965. OutputBufferLength - 0, ignored
  966. Return Value:
  967. IoStatus.Status:
  968. STATUS_SUCCESS - operation succeeded.
  969. STATUS_OBJECT_TYPE_MISMATCH - helper handle is not AFD file object handle
  970. STATUS_INVALID_HANDLE - helper handle corresponds to AFD endpoint of incorrect
  971. type.
  972. IoStatus.Information - 0 - regular address list change
  973. otherwise, seq number of provider list change.
  974. --*/
  975. // Open packet that identifies SAN helper endpoint used
  976. // for communication between SAN switch and AFD.
  977. // This is EA name
  978. //
  979. #define AfdSwitchOpenPacket "AfdSwOpenPacket"
  980. #define AFD_SWITCH_OPEN_PACKET_NAME_LENGTH (sizeof(AfdSwitchOpenPacket)-1)
  981. //
  982. // Data passed in the open packet
  983. // This is EA value
  984. //
  985. typedef struct _AFD_SWITCH_OPEN_PACKET {
  986. HANDLE CompletionPort; // Completion port notify SAN switch
  987. // of SAN io completions
  988. HANDLE CompletionEvent;// Completion event to distinguish IO issued
  989. // by SAN switch from application IO.
  990. } AFD_SWITCH_OPEN_PACKET, *PAFD_SWITCH_OPEN_PACKET;
  991. typedef struct _AFD_SWITCH_CONTEXT {
  992. LONG EventsActive; // Poll events activated by switch
  993. LONG RcvCount; // Count of polls for receive
  994. LONG ExpCount; // Count of polls for expedited
  995. LONG SndCount; // Count of polls for send
  996. BOOLEAN SelectFlag; // TRUE if app has done any form of select
  997. } AFD_SWITCH_CONTEXT, *PAFD_SWITCH_CONTEXT;
  998. //
  999. // Information for associating AFD endpoint with SAN provider
  1000. //
  1001. typedef struct _AFD_SWITCH_CONTEXT_INFO {
  1002. HANDLE SocketHandle; // Handle to associate with SAN provider
  1003. PAFD_SWITCH_CONTEXT SwitchContext; // Opaque context value maintained for the switch
  1004. } AFD_SWITCH_CONTEXT_INFO, *PAFD_SWITCH_CONTEXT_INFO;
  1005. //
  1006. // Information for connection indication from SAN provider to AFD
  1007. //
  1008. typedef struct _AFD_SWITCH_CONNECT_INFO {
  1009. HANDLE ListenHandle; // Listening socket handle
  1010. PAFD_SWITCH_CONTEXT SwitchContext;
  1011. TRANSPORT_ADDRESS RemoteAddress; // Address of the remote peer wishing
  1012. // to connect
  1013. } AFD_SWITCH_CONNECT_INFO, *PAFD_SWITCH_CONNECT_INFO;
  1014. //
  1015. // Information returned by the AFD to switch in response
  1016. // to connection indication
  1017. //
  1018. typedef struct _AFD_SWITCH_ACCEPT_INFO {
  1019. HANDLE AcceptHandle; // Socket handle to use to accept connection
  1020. ULONG ReceiveLength; // Length of the initial receive buffer (for AcceptEx)
  1021. } AFD_SWITCH_ACCEPT_INFO, *PAFD_SWITCH_ACCEPT_INFO;
  1022. //
  1023. // Information passed by the switch to signal network events on the
  1024. // endpoint (socket)
  1025. //
  1026. typedef struct _AFD_SWITCH_EVENT_INFO {
  1027. HANDLE SocketHandle; // Socket handle on which to signal
  1028. PAFD_SWITCH_CONTEXT SwitchContext; // Switch context associated with the socket
  1029. ULONG EventBit; // Event bit to set/reset (AFD_POLL_xxx_BIT constants)
  1030. NTSTATUS Status; // Status code associated with the event (this
  1031. // is used for AFD_POLL_CONNECT_FAIL_BIT)
  1032. } AFD_SWITCH_EVENT_INFO, *PAFD_SWITCH_EVENT_INFO;
  1033. //
  1034. // Information passed by the switch to retreive parameters/complete
  1035. // redirected read/write request
  1036. //
  1037. typedef struct _AFD_SWITCH_REQUEST_INFO {
  1038. HANDLE SocketHandle; // Socket handle on which request us active
  1039. PAFD_SWITCH_CONTEXT SwitchContext; // Switch context associated with the socket
  1040. PVOID RequestContext; // Request context that identifies it
  1041. NTSTATUS RequestStatus; // Completion status of the request (STATUS_PENDING
  1042. // indicates that request should NOT be completed yet)
  1043. ULONG DataOffset; // Offset from which to start copying data from/to
  1044. // application's buffer
  1045. } AFD_SWITCH_REQUEST_INFO, *PAFD_SWITCH_REQUEST_INFO;
  1046. //
  1047. // Access type (read access or write access) that's needed for an app buffer
  1048. // whose physical address is requested thru AfdSanFastGetPhysicalAddr
  1049. //
  1050. #define MEM_READ_ACCESS 1
  1051. #define MEM_WRITE_ACCESS 2
  1052. //
  1053. // Information passed between processes when socket is duplicated.
  1054. //
  1055. typedef struct _AFD_SWITCH_ACQUIRE_CTX_INFO {
  1056. HANDLE SocketHandle; // Socket handle which needs to be transferred
  1057. PAFD_SWITCH_CONTEXT SwitchContext; // Switch context to be associated with the socket
  1058. PVOID SocketCtxBuf; // Socket context buffer
  1059. ULONG SocketCtxBufSize; // Socket context buffer size
  1060. } AFD_SWITCH_ACQUIRE_CTX_INFO, *PAFD_SWITCH_ACQUIRE_CTX_INFO;
  1061. typedef struct _AFD_SWITCH_TRANSFER_CTX_INFO {
  1062. HANDLE SocketHandle; // Socket handle which needs to be transferred
  1063. PAFD_SWITCH_CONTEXT SwitchContext; // Switch context associated with the socket
  1064. PVOID RequestContext; // Value that identifies corresponding acquire request
  1065. PVOID SocketCtxBuf; // Socket context buffer
  1066. ULONG SocketCtxBufSize; // Socket context buffer size
  1067. LPWSABUF RcvBufferArray; // Receive buffers to copy to destination process
  1068. ULONG RcvBufferCount; // Number of receive buffers
  1069. NTSTATUS Status; // Status of transfer opertaion.
  1070. } AFD_SWITCH_TRANSFER_CTX_INFO, *PAFD_SWITCH_TRANSFER_CTX_INFO;
  1071. //
  1072. // Request from AFD to switch (passed via completion port)
  1073. //
  1074. #define AFD_SWITCH_REQUEST_CLOSE 0
  1075. /*++
  1076. Request Description:
  1077. All references to the socket have been closed in all processes, safe
  1078. to destroy the SAN provider socket and connection
  1079. Arguments (NtRemoveIoCompletion return parameters):
  1080. Key - switch context associated with the socket
  1081. ApcContext - AFD_SWITCH_MAKE_REQUEST_CONTEXT(0, AFD_SWITCH_REQUEST_CLOSE)
  1082. IoStatus.Status - STATUS_SUCCESS (ignored)
  1083. IoStatus.Information - 0 (ignored)
  1084. --*/
  1085. #define AFD_SWITCH_REQUEST_READ 1
  1086. /*++
  1087. Request Description:
  1088. Read request arrived from the application via IO subsystem interface.
  1089. Arguments (NtRemoveIoCompletion return parameters):
  1090. Key - switch context associated with the socket
  1091. ApcContext - AFD_SWITCH_MAKE_REQUEST_CONTEXT(RequestId, AFD_SWITCH_REQUEST_READ)
  1092. IoStatus.Status - STATUS_SUCCESS (ignored)
  1093. IoStatus.Information - size of the receive buffer supplied by the application
  1094. --*/
  1095. #define AFD_SWITCH_REQUEST_WRITE 2
  1096. /*++
  1097. Request Description:
  1098. Write request arrived from the application via IO subsystem interface.
  1099. Arguments (NtRemoveIoCompletion return parameters):
  1100. Key - switch context associated with the socket
  1101. ApcContext - AFD_SWITCH_MAKE_REQUEST_CONTEXT(RequestId, AFD_SWITCH_REQUEST_WRITE)
  1102. IoStatus.Status - STATUS_SUCCESS (ignored)
  1103. IoStatus.Information - size of the send data supplied by the application
  1104. --*/
  1105. #define AFD_SWITCH_REQUEST_TFCTX 3
  1106. /*++
  1107. Request Description:
  1108. Another process requests ownership of the socket.
  1109. Arguments (NtRemoveIoCompletion return parameters):
  1110. Key - switch context associated with the socket
  1111. ApcContext - AFD_SWITCH_MAKE_REQUEST_CONTEXT(RequestId, AFD_SWITCH_REQUEST_TFCTX)
  1112. IoStatus.Status - STATUS_SUCCESS (ignored)
  1113. IoStatus.Information - PID of the process requesting ownership.
  1114. --*/
  1115. #define AFD_SWITCH_REQUEST_CHCTX 4
  1116. /*++
  1117. Request Description:
  1118. Relationship between socket handle and switch context has become invalid
  1119. (application must have closed the original socket and using duplicated handle)
  1120. Arguments (NtRemoveIoCompletion return parameters):
  1121. Key - switch context associated with the socket
  1122. ApcContext - AFD_SWITCH_MAKE_REQUEST_CONTEXT(0, AFD_SWITCH_REQUEST_CHCTX)
  1123. IoStatus.Status - STATUS_SUCCESS (ignored)
  1124. IoStatus.Information - Handle currently used by the application.
  1125. --*/
  1126. #define AFD_SWITCH_REQUEST_AQCTX 5
  1127. /*++
  1128. Request Description:
  1129. Request to service process to acquire ownership of the socket
  1130. Arguments (NtRemoveIoCompletion return parameters):
  1131. Key - NULL
  1132. ApcContext - AFD_SWITCH_MAKE_REQUEST_CONTEXT(0, AFD_SWITCH_REQUEST_AQCTX)
  1133. IoStatus.Status - STATUS_SUCCESS (ignored)
  1134. IoStatus.Information - Handle of the socket to be acquired.
  1135. --*/
  1136. #define AFD_SWITCH_REQUEST_CLSOC 6
  1137. /*++
  1138. Request Description:
  1139. Request to service process to close the socket
  1140. Arguments (NtRemoveIoCompletion return parameters):
  1141. Key - switch context associated with the socket
  1142. ApcContext - AFD_SWITCH_MAKE_REQUEST_CONTEXT(0, AFD_SWITCH_REQUEST_CLSOC)
  1143. IoStatus.Status - STATUS_SUCCESS (ignored)
  1144. IoStatus.Information - 0.
  1145. --*/
  1146. #define AFD_SWITCH_REQUEST_ID_SHIFT 3
  1147. #define AFD_SWITCH_REQUEST_TYPE_MASK \
  1148. ((1<<AFD_SWITCH_REQUEST_ID_SHIFT)-1)
  1149. #define AFD_SWITCH_MAKE_REQUEST_CONTEXT(_id,_type) \
  1150. UlongToPtr(((_id)<<AFD_SWITCH_REQUEST_ID_SHIFT)+(_type))
  1151. //
  1152. // Retrives request type from the request context
  1153. //
  1154. #define AFD_SWITCH_REQUEST_TYPE(_RequestContext) \
  1155. (((ULONG_PTR)(_RequestContext))&AFD_SWITCH_REQUEST_TYPE_MASK)
  1156. #endif // ndef _AFD_