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.

330 lines
8.6 KiB

  1. /*--Copyright (c) 1991 Microsoft Corporation
  2. Module Name:
  3. pnp.c
  4. Abstract:
  5. PnP specific code for TCP.
  6. Author:
  7. Munil Shah (munils) Mar 7, 1997
  8. Revision History:
  9. Notes:
  10. --*/
  11. #include "precomp.h"
  12. #include "addr.h"
  13. #include "tcp.h"
  14. #include "raw.h"
  15. #include "udp.h"
  16. #include "tcb.h"
  17. #include "tcpconn.h"
  18. NTSTATUS
  19. TCPQueryConnDeviceRelations(
  20. IN PIRP Irp,
  21. IN PIO_STACK_LOCATION IrpSp
  22. );
  23. NTSTATUS
  24. TCPQueryAddrDeviceRelations(
  25. IN PIRP Irp,
  26. IN PIO_STACK_LOCATION IrpSp
  27. );
  28. NTSTATUS
  29. TCPPnPReconfigRequest(
  30. IN void *ipContext,
  31. IN IPAddr ipAddr,
  32. IN NDIS_HANDLE handle,
  33. IN PIP_PNP_RECONFIG_REQUEST reconfigBuffer
  34. );
  35. NTSTATUS
  36. UDPPnPReconfigRequest(
  37. IN void *ipContext,
  38. IN IPAddr ipAddr,
  39. IN NDIS_HANDLE handle,
  40. IN PIP_PNP_RECONFIG_REQUEST reconfigBuffer
  41. );
  42. NTSTATUS
  43. RawPnPReconfigRequest(
  44. IN void *ipContext,
  45. IN IPAddr ipAddr,
  46. IN NDIS_HANDLE handle,
  47. IN PIP_PNP_RECONFIG_REQUEST reconfigBuffer
  48. );
  49. extern TDI_STATUS
  50. IPGetDeviceRelation(RouteCacheEntry * rce, PVOID * pnpDeviceContext);
  51. extern void
  52. DeleteProtocolSecurityFilter(IPAddr InterfaceAddress, ulong Protocol);
  53. extern void
  54. ControlSecurityFiltering(uint IsEnabled);
  55. extern void
  56. AddProtocolSecurityFilter(IPAddr InterfaceAddress, ulong Protocol,
  57. NDIS_HANDLE ConfigHandle);
  58. NTSTATUS
  59. TCPPnPPowerRequest(void *ipContext, IPAddr ipAddr, NDIS_HANDLE handle, PNET_PNP_EVENT netPnPEvent)
  60. {
  61. switch (netPnPEvent->NetEvent) {
  62. case NetEventReconfigure:{
  63. PIP_PNP_RECONFIG_REQUEST reconfigBuffer = (PIP_PNP_RECONFIG_REQUEST) netPnPEvent->Buffer;
  64. return TCPPnPReconfigRequest(
  65. ipContext,
  66. ipAddr,
  67. handle,
  68. reconfigBuffer
  69. );
  70. }
  71. default:
  72. break;
  73. }
  74. return STATUS_SUCCESS;
  75. }
  76. NTSTATUS
  77. UDPPnPPowerRequest(void *ipContext, IPAddr ipAddr, NDIS_HANDLE handle, PNET_PNP_EVENT netPnPEvent)
  78. {
  79. switch (netPnPEvent->NetEvent) {
  80. case NetEventReconfigure:{
  81. PIP_PNP_RECONFIG_REQUEST reconfigBuffer = (PIP_PNP_RECONFIG_REQUEST) netPnPEvent->Buffer;
  82. return UDPPnPReconfigRequest(
  83. ipContext,
  84. ipAddr,
  85. handle,
  86. reconfigBuffer
  87. );
  88. }
  89. default:
  90. break;
  91. }
  92. return STATUS_SUCCESS;
  93. }
  94. NTSTATUS
  95. RawPnPPowerRequest(void *ipContext, IPAddr ipAddr, NDIS_HANDLE handle, PNET_PNP_EVENT netPnPEvent)
  96. {
  97. switch (netPnPEvent->NetEvent) {
  98. case NetEventReconfigure:{
  99. PIP_PNP_RECONFIG_REQUEST reconfigBuffer = (PIP_PNP_RECONFIG_REQUEST) netPnPEvent->Buffer;
  100. return RawPnPReconfigRequest(
  101. ipContext,
  102. ipAddr,
  103. handle,
  104. reconfigBuffer
  105. );
  106. }
  107. default:
  108. break;
  109. }
  110. return STATUS_SUCCESS;
  111. }
  112. NTSTATUS
  113. TCPPnPReconfigRequest(void *ipContext, IPAddr ipAddr, NDIS_HANDLE handle, PIP_PNP_RECONFIG_REQUEST reconfigBuffer)
  114. {
  115. return STATUS_SUCCESS;
  116. }
  117. NTSTATUS
  118. UDPPnPReconfigRequest(void *ipContext, IPAddr ipAddr, NDIS_HANDLE handle, PIP_PNP_RECONFIG_REQUEST reconfigBuffer)
  119. {
  120. return STATUS_SUCCESS;
  121. }
  122. NTSTATUS
  123. RawPnPReconfigRequest(void *ipContext, IPAddr ipAddr, NDIS_HANDLE handle, PIP_PNP_RECONFIG_REQUEST reconfigBuffer)
  124. {
  125. return STATUS_SUCCESS;
  126. }
  127. NTSTATUS
  128. TCPDispatchPnPPower(
  129. IN PIRP irp,
  130. IN PIO_STACK_LOCATION irpSp
  131. )
  132. /*++
  133. Routine Description:
  134. Processes pnp power irps.
  135. Arguments:
  136. Irp - Pointer to I/O request packet
  137. IrpSp - Pointer to the current stack location in the Irp.
  138. Return Value:
  139. NTSTATUS -- Indicates whether the request was successful.
  140. Notes:
  141. --*/
  142. {
  143. NTSTATUS status;
  144. status = STATUS_INVALID_DEVICE_REQUEST;
  145. switch (irpSp->MinorFunction) {
  146. case IRP_MN_QUERY_DEVICE_RELATIONS:
  147. if (irpSp->Parameters.QueryDeviceRelations.Type == TargetDeviceRelation) {
  148. if (PtrToUlong(irpSp->FileObject->FsContext2) == TDI_CONNECTION_FILE) {
  149. return TCPQueryConnDeviceRelations(irp, irpSp);
  150. } else if (PtrToUlong(irpSp->FileObject->FsContext2) == TDI_TRANSPORT_ADDRESS_FILE) {
  151. return TCPQueryAddrDeviceRelations(irp, irpSp);
  152. }
  153. }
  154. break;
  155. default:
  156. break;
  157. }
  158. return status;
  159. }
  160. NTSTATUS
  161. TCPQueryConnDeviceRelations(
  162. IN PIRP Irp,
  163. IN PIO_STACK_LOCATION IrpSp
  164. )
  165. /*++
  166. Routine Description:
  167. Processes pnp power irps.
  168. Arguments:
  169. Irp - Pointer to I/O request packet
  170. IrpSp - Pointer to the current stack location in the Irp.
  171. Return Value:
  172. NTSTATUS -- Indicates whether the request was successful.
  173. Notes:
  174. --*/
  175. {
  176. PTCP_CONTEXT tcpContext;
  177. CONNECTION_CONTEXT ConnectionContext;
  178. TCB *TCB;
  179. TCPConn *Conn;
  180. PVOID pnpDeviceContext;
  181. TDI_STATUS status;
  182. PDEVICE_RELATIONS deviceRelations = NULL;
  183. CTELockHandle ConnHandle;
  184. tcpContext = (PTCP_CONTEXT) IrpSp->FileObject->FsContext;
  185. ConnectionContext = tcpContext->Handle.ConnectionContext;
  186. // find connection.
  187. Conn = GetConnFromConnID(PtrToUlong(ConnectionContext), &ConnHandle);
  188. if (Conn != NULL) {
  189. // get the tcb for this connection.
  190. TCB = Conn->tc_tcb;
  191. if (TCB) {
  192. CTEGetLockAtDPC(&TCB->tcb_lock);
  193. if (TCB->tcb_state == TCB_CLOSED || CLOSING(TCB)) {
  194. CTEFreeLockFromDPC(&TCB->tcb_lock);
  195. status = TDI_INVALID_STATE;
  196. } else {
  197. REFERENCE_TCB(TCB);
  198. CTEFreeLockFromDPC(&TCB->tcb_lock);
  199. // get device relations from IP.
  200. status = IPGetDeviceRelation(TCB->tcb_rce, &pnpDeviceContext);
  201. CTEGetLockAtDPC(&TCB->tcb_lock);
  202. DerefTCB(TCB, DISPATCH_LEVEL);
  203. if (status == TDI_SUCCESS) {
  204. deviceRelations = CTEAllocMem(sizeof(DEVICE_RELATIONS));
  205. if (deviceRelations) {
  206. //
  207. // TargetDeviceRelation allows exactly one PDO.
  208. // fill it up.
  209. //
  210. // N.B. This allocation is freed by the I/O manager
  211. // or by whichever driver issued the request.
  212. //
  213. deviceRelations->Count = 1;
  214. deviceRelations->Objects[0] = pnpDeviceContext;
  215. ObReferenceObject(pnpDeviceContext);
  216. } else {
  217. status = TDI_NO_RESOURCES;
  218. }
  219. }
  220. }
  221. } else {
  222. status = TDI_INVALID_STATE;
  223. }
  224. CTEFreeLock(&(Conn->tc_ConnBlock->cb_lock), ConnHandle);
  225. } else {
  226. status = TDI_INVALID_CONNECTION;
  227. }
  228. //
  229. // invoker of this irp will free the information buffer.
  230. //
  231. Irp->IoStatus.Status = status;
  232. Irp->IoStatus.Information = (ULONG_PTR) deviceRelations;
  233. return status;
  234. }
  235. NTSTATUS
  236. TCPQueryAddrDeviceRelations(
  237. IN PIRP Irp,
  238. IN PIO_STACK_LOCATION IrpSp
  239. )
  240. /*++
  241. Routine Description:
  242. Processes pnp power irps.
  243. Arguments:
  244. Irp - Pointer to I/O request packet
  245. IrpSp - Pointer to the current stack location in the Irp.
  246. Return Value:
  247. NTSTATUS -- Indicates whether the request was successful.
  248. Notes:
  249. --*/
  250. {
  251. return STATUS_UNSUCCESSFUL;
  252. }