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.

519 lines
14 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. ntentry.c
  5. Abstract:
  6. NT System entry points for ATMARP.
  7. Revision History:
  8. Who When What
  9. -------- -------- ----------------------------------------------
  10. arvindm 08-08-96 Created
  11. Notes:
  12. --*/
  13. #ifdef ATMARP_WIN98
  14. #undef BINARY_COMPATIBLE
  15. #define BINARY_COMPATIBLE 0
  16. #endif // ATMARP_WIN98
  17. #include <precomp.h>
  18. #define _FILENUMBER 'NETN'
  19. //
  20. // The INIT code is discardable
  21. //
  22. #ifdef ALLOC_PRAGMA
  23. #pragma alloc_text(INIT, DriverEntry)
  24. #endif // ALLOC_PRAGMA
  25. NTSTATUS
  26. DriverEntry(
  27. IN PDRIVER_OBJECT pDriverObject,
  28. IN PUNICODE_STRING pRegistryPath
  29. )
  30. /*++
  31. Routine Description:
  32. This is the "init" routine, called by the system when the ATMARP
  33. module is loaded. We initialize all our global objects, fill in our
  34. Dispatch and Unload routine addresses in the driver object, and create
  35. a device object for receiving I/O requests on (IOCTLs).
  36. Arguments:
  37. pDriverObject - Pointer to the driver object created by the system.
  38. pRegistryPath - Pointer to our global registry path. This is ignored.
  39. Return Value:
  40. NT Status code: STATUS_SUCCESS if successful, error code otherwise.
  41. --*/
  42. {
  43. NTSTATUS Status;
  44. PDEVICE_OBJECT pDeviceObject;
  45. UNICODE_STRING DeviceName;
  46. INT i;
  47. AADEBUGP(AAD_INFO, ("DriverEntry: entered, pAtmArpGlobal 0x%x\n", pAtmArpGlobalInfo));
  48. AADEBUGP(AAD_FATAL, ("&AaDebugLevel: 0x%x, AaDebugLevel now is %d\n",
  49. &AaDebugLevel, AaDebugLevel));
  50. AADEBUGP(AAD_FATAL, ("&AaDataDebugLevel: 0x%x, AaDataDebugLevel now is %d\n",
  51. &AaDataDebugLevel, AaDataDebugLevel));
  52. #ifdef IPMCAST
  53. AAMCDEBUGP(AAD_FATAL, ("&AaMcDebugLevel: 0x%x, AaMcDebugLevel now is %d\n",
  54. &AaMcDebugLevel, AaMcDebugLevel));
  55. #endif
  56. #if DBG
  57. AADEBUGP(AAD_FATAL, ("To skip everything set AaSkipAll at 0x%x to 1\n",
  58. &AaSkipAll));
  59. if (AaSkipAll)
  60. {
  61. AADEBUGP(AAD_ERROR, ("Aborting DriverEntry\n"));
  62. return (STATUS_UNSUCCESSFUL);
  63. }
  64. #endif
  65. //
  66. // Initialize our globals.
  67. //
  68. AtmArpInitGlobals();
  69. #ifdef GPC
  70. //
  71. // Init GPC
  72. //
  73. AtmArpGpcInitialize();
  74. #endif // GPC
  75. #if !BINARY_COMPATIBLE
  76. //
  77. // Initialize the Driver Object.
  78. //
  79. pDriverObject->DriverUnload = Unload;
  80. pDriverObject->FastIoDispatch = NULL;
  81. for (i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; i++)
  82. {
  83. pDriverObject->MajorFunction[i] = Dispatch;
  84. }
  85. #ifdef ATMARP_WMI
  86. pDriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = AtmArpWmiDispatch;
  87. #endif // ATMARP_WMI
  88. pAtmArpGlobalInfo->pDriverObject = (PVOID)pDriverObject;
  89. //
  90. // Create a device object for the ATMARP module.
  91. //
  92. RtlInitUnicodeString(&DeviceName, ATMARP_DEVICE_NAME);
  93. Status = IoCreateDevice(
  94. pDriverObject,
  95. 0,
  96. &DeviceName,
  97. FILE_DEVICE_NETWORK,
  98. 0,
  99. FALSE,
  100. &pDeviceObject
  101. );
  102. if (NT_SUCCESS(Status))
  103. {
  104. //
  105. // Set up a symbolic name for interaction with the user-mode
  106. // admin application.
  107. //
  108. #define ATMARP_SYMBOLIC_NAME L"\\DosDevices\\ATMARPC"
  109. UNICODE_STRING SymbolicName;
  110. RtlInitUnicodeString(&SymbolicName, ATMARP_SYMBOLIC_NAME);
  111. IoCreateSymbolicLink(&SymbolicName, &DeviceName);
  112. //
  113. // Initialize the Device Object.
  114. //
  115. pDeviceObject->Flags |= DO_DIRECT_IO;
  116. //
  117. // Retain the device object pointer -- we'll need this
  118. // if/when we are asked to unload ourselves.
  119. //
  120. pAtmArpGlobalInfo->pDeviceObject = (PVOID)pDeviceObject;
  121. }
  122. else
  123. {
  124. pDeviceObject = NULL;
  125. }
  126. #endif // !BINARY_COMPATIBLE
  127. //
  128. // Fill in our Protocol and Client characteristics structures.
  129. //
  130. AA_SET_MEM(&AtmArpProtocolCharacteristics, 0, sizeof(AtmArpProtocolCharacteristics));
  131. AtmArpProtocolCharacteristics.MajorNdisVersion = ATMARP_NDIS_MAJOR_VERSION;
  132. AtmArpProtocolCharacteristics.MinorNdisVersion = ATMARP_NDIS_MINOR_VERSION;
  133. AtmArpProtocolCharacteristics.OpenAdapterCompleteHandler = AtmArpOpenAdapterCompleteHandler;
  134. AtmArpProtocolCharacteristics.CloseAdapterCompleteHandler = AtmArpCloseAdapterCompleteHandler;
  135. AtmArpProtocolCharacteristics.SendCompleteHandler = AtmArpSendCompleteHandler;
  136. AtmArpProtocolCharacteristics.TransferDataCompleteHandler = AtmArpTransferDataCompleteHandler;
  137. AtmArpProtocolCharacteristics.ResetCompleteHandler = AtmArpResetCompleteHandler;
  138. AtmArpProtocolCharacteristics.RequestCompleteHandler = AtmArpRequestCompleteHandler;
  139. AtmArpProtocolCharacteristics.ReceiveHandler = AtmArpReceiveHandler;
  140. AtmArpProtocolCharacteristics.ReceiveCompleteHandler = AtmArpReceiveCompleteHandler;
  141. AtmArpProtocolCharacteristics.StatusHandler = AtmArpStatusHandler;
  142. AtmArpProtocolCharacteristics.StatusCompleteHandler = AtmArpStatusCompleteHandler;
  143. NdisInitUnicodeString(
  144. &AtmArpProtocolCharacteristics.Name,
  145. ATMARP_LL_NAME
  146. );
  147. AtmArpProtocolCharacteristics.ReceivePacketHandler = AtmArpReceivePacketHandler;
  148. AtmArpProtocolCharacteristics.BindAdapterHandler = AtmArpBindAdapterHandler;
  149. AtmArpProtocolCharacteristics.UnbindAdapterHandler = AtmArpUnbindAdapterHandler;
  150. AtmArpProtocolCharacteristics.UnloadHandler = (UNLOAD_PROTOCOL_HANDLER)AtmArpUnloadProtocol;
  151. #ifdef _PNP_POWER_
  152. AtmArpProtocolCharacteristics.PnPEventHandler = AtmArpPnPEventHandler;
  153. #endif // _PNP_POWER_
  154. AtmArpProtocolCharacteristics.CoSendCompleteHandler = AtmArpCoSendCompleteHandler;
  155. AtmArpProtocolCharacteristics.CoStatusHandler = AtmArpCoStatusHandler;
  156. AtmArpProtocolCharacteristics.CoReceivePacketHandler = AtmArpCoReceivePacketHandler;
  157. AtmArpProtocolCharacteristics.CoAfRegisterNotifyHandler = AtmArpCoAfRegisterNotifyHandler;
  158. AA_SET_MEM(&AtmArpClientCharacteristics, 0, sizeof(AtmArpClientCharacteristics));
  159. AtmArpClientCharacteristics.MajorVersion = ATMARP_NDIS_MAJOR_VERSION;
  160. AtmArpClientCharacteristics.MinorVersion = ATMARP_NDIS_MINOR_VERSION;
  161. AtmArpClientCharacteristics.ClCreateVcHandler = AtmArpCreateVcHandler;
  162. AtmArpClientCharacteristics.ClDeleteVcHandler = AtmArpDeleteVcHandler;
  163. AtmArpClientCharacteristics.ClRequestHandler = AtmArpCoRequestHandler;
  164. AtmArpClientCharacteristics.ClRequestCompleteHandler = AtmArpCoRequestCompleteHandler;
  165. AtmArpClientCharacteristics.ClOpenAfCompleteHandler = AtmArpOpenAfCompleteHandler;
  166. AtmArpClientCharacteristics.ClCloseAfCompleteHandler = AtmArpCloseAfCompleteHandler;
  167. AtmArpClientCharacteristics.ClRegisterSapCompleteHandler = AtmArpRegisterSapCompleteHandler;
  168. AtmArpClientCharacteristics.ClDeregisterSapCompleteHandler = AtmArpDeregisterSapCompleteHandler;
  169. AtmArpClientCharacteristics.ClMakeCallCompleteHandler = AtmArpMakeCallCompleteHandler;
  170. AtmArpClientCharacteristics.ClModifyCallQoSCompleteHandler = AtmArpModifyQosCompleteHandler;
  171. AtmArpClientCharacteristics.ClCloseCallCompleteHandler = AtmArpCloseCallCompleteHandler;
  172. AtmArpClientCharacteristics.ClAddPartyCompleteHandler = AtmArpAddPartyCompleteHandler;
  173. AtmArpClientCharacteristics.ClDropPartyCompleteHandler = AtmArpDropPartyCompleteHandler;
  174. AtmArpClientCharacteristics.ClIncomingCallHandler = AtmArpIncomingCallHandler;
  175. AtmArpClientCharacteristics.ClIncomingCallQoSChangeHandler = (CL_INCOMING_CALL_QOS_CHANGE_HANDLER)NULL;
  176. AtmArpClientCharacteristics.ClIncomingCloseCallHandler = AtmArpIncomingCloseHandler;
  177. AtmArpClientCharacteristics.ClIncomingDropPartyHandler = AtmArpIncomingDropPartyHandler;
  178. AtmArpClientCharacteristics.ClCallConnectedHandler = AtmArpCallConnectedHandler;
  179. do
  180. {
  181. //
  182. // Register ourselves as a protocol with NDIS.
  183. //
  184. NdisRegisterProtocol(
  185. &Status,
  186. &(pAtmArpGlobalInfo->ProtocolHandle),
  187. &AtmArpProtocolCharacteristics,
  188. sizeof(AtmArpProtocolCharacteristics)
  189. );
  190. if (Status != NDIS_STATUS_SUCCESS)
  191. {
  192. AADEBUGP(AAD_FATAL,
  193. ("NdisRegisterProtocol failed: %x\n", Status));
  194. pAtmArpGlobalInfo->ProtocolHandle = NULL;
  195. break;
  196. }
  197. #ifdef NEWARP
  198. //
  199. // Register ourselves as an ARP Module with IP.
  200. //
  201. {
  202. NDIS_STRING AtmArpName;
  203. #if IFCHANGE1
  204. #ifndef ATMARP_WIN98
  205. IP_CHANGE_INDEX IpChangeIndex;
  206. IP_RESERVE_INDEX IpReserveIndex;
  207. IP_DERESERVE_INDEX IpDereserveIndex;
  208. #endif
  209. #endif // IFCHANGE1
  210. NdisInitUnicodeString(&AtmArpName, ATMARP_UL_NAME);
  211. Status = IPRegisterARP(
  212. &AtmArpName,
  213. IP_ARP_BIND_VERSION,
  214. AtmArpBindAdapterHandler,
  215. &(pAtmArpGlobalInfo->pIPAddInterfaceRtn),
  216. &(pAtmArpGlobalInfo->pIPDelInterfaceRtn),
  217. &(pAtmArpGlobalInfo->pIPBindCompleteRtn),
  218. #if P2MP
  219. &(pAtmArpGlobalInfo->pIPAddLinkRtn),
  220. &(pAtmArpGlobalInfo->pIpDeleteLinkRtn),
  221. #endif // P2MP
  222. #if IFCHANGE1
  223. #ifndef ATMARP_WIN98
  224. //
  225. // Following 3 are placeholders -- we don't use this information.
  226. // See 10/14/1998 entry in notes.txt
  227. //
  228. &IpChangeIndex,
  229. &IpReserveIndex,
  230. &IpDereserveIndex,
  231. #endif // ATMARP_WIN98
  232. #endif // IFCHANGE1
  233. &(pAtmArpGlobalInfo->ARPRegisterHandle)
  234. );
  235. if (!NT_SUCCESS(Status))
  236. {
  237. AADEBUGP(AAD_FATAL, ("DriverEntry: IPRegisterARP FAILS. Status = 0x%08lx\n", Status));
  238. pAtmArpGlobalInfo->ARPRegisterHandle = NULL;
  239. break;
  240. }
  241. }
  242. #endif // NEWARP
  243. break;
  244. }
  245. while (FALSE);
  246. if (Status != NDIS_STATUS_SUCCESS)
  247. {
  248. NDIS_STATUS CleanupStatus;
  249. //
  250. // Clean up.
  251. //
  252. #if !BINARY_COMPATIBLE
  253. if (pDeviceObject != NULL)
  254. {
  255. UNICODE_STRING SymbolicName;
  256. RtlInitUnicodeString(&SymbolicName, ATMARP_SYMBOLIC_NAME);
  257. IoDeleteSymbolicLink(&SymbolicName);
  258. IoDeleteDevice(pDeviceObject);
  259. pDeviceObject = NULL;
  260. }
  261. #endif // !BINARY_COMPATIBLE
  262. if (pAtmArpGlobalInfo->ProtocolHandle)
  263. {
  264. NdisDeregisterProtocol(
  265. &CleanupStatus,
  266. pAtmArpGlobalInfo->ProtocolHandle
  267. );
  268. pAtmArpGlobalInfo->ProtocolHandle = NULL;
  269. }
  270. if (pAtmArpGlobalInfo->ARPRegisterHandle != NULL)
  271. {
  272. CleanupStatus = IPDeregisterARP(pAtmArpGlobalInfo->ARPRegisterHandle);
  273. AA_ASSERT(CleanupStatus == NDIS_STATUS_SUCCESS);
  274. pAtmArpGlobalInfo->ARPRegisterHandle = NULL;
  275. }
  276. #ifdef GPC
  277. //
  278. // DeInit GPC
  279. //
  280. AtmArpGpcShutdown();
  281. #endif // GPC
  282. }
  283. return (Status);
  284. }
  285. #if !BINARY_COMPATIBLE
  286. NTSTATUS
  287. Dispatch(
  288. IN PDEVICE_OBJECT pDeviceObject,
  289. IN PIRP pIrp
  290. )
  291. /*++
  292. Routine Description:
  293. This routine is called by the system when there is an IRP
  294. to be processed.
  295. Arguments:
  296. pDeviceObject - Pointer to device object we created for ourselves.
  297. pIrp - Pointer to IRP to be processed.
  298. Return Value:
  299. NT Status code.
  300. --*/
  301. {
  302. NTSTATUS Status; // Return value
  303. PIO_STACK_LOCATION pIrpStack;
  304. PVOID pIoBuffer; // Values in/out
  305. ULONG InputBufferLength; // Length of input parameters
  306. ULONG OutputBufferLength; // Space for output values
  307. //
  308. // Initialize
  309. //
  310. Status = (NTSTATUS)NDIS_STATUS_SUCCESS;
  311. pIrp->IoStatus.Status = (NTSTATUS)NDIS_STATUS_SUCCESS;
  312. pIrp->IoStatus.Information = 0;
  313. //
  314. // Get all information in the IRP
  315. //
  316. pIoBuffer = pIrp->AssociatedIrp.SystemBuffer;
  317. pIrpStack = IoGetCurrentIrpStackLocation(pIrp);
  318. InputBufferLength = pIrpStack->Parameters.DeviceIoControl.InputBufferLength;
  319. OutputBufferLength = pIrpStack->Parameters.DeviceIoControl.OutputBufferLength;
  320. switch (pIrpStack->MajorFunction)
  321. {
  322. case IRP_MJ_CREATE:
  323. AADEBUGP(AAD_INFO, ("Dispatch: IRP_MJ_CREATE\n"));
  324. //
  325. // Return a pointer to the first ATMARP interface available, as the
  326. // FsContext.
  327. //
  328. pIrpStack->FileObject->FsContext = NULL; // Initialize
  329. if (pAtmArpGlobalInfo->pAdapterList != (PATMARP_ADAPTER)NULL)
  330. {
  331. pIrpStack->FileObject->FsContext =
  332. (PVOID)(pAtmArpGlobalInfo->pAdapterList->pInterfaceList);
  333. }
  334. break;
  335. case IRP_MJ_CLOSE:
  336. AADEBUGP(AAD_INFO, ("Dispatch: IRP_MJ_CLOSE\n"));
  337. break;
  338. case IRP_MJ_CLEANUP:
  339. AADEBUGP(AAD_INFO, ("Dispatch: IRP_MJ_CLEANUP\n"));
  340. break;
  341. case IRP_MJ_DEVICE_CONTROL:
  342. AADEBUGP(AAD_INFO, ("Dispatch: IRP_MJ_DEVICE_CONTROL\n"));
  343. #ifndef ATMARP_WIN98
  344. Status = AtmArpHandleIoctlRequest(pIrp, pIrpStack);
  345. #endif // ATMARP_WIN98
  346. break;
  347. default:
  348. AADEBUGP(AAD_INFO, ("Dispatch: IRP: Unknown major function 0x%x\n",
  349. pIrpStack->MajorFunction));
  350. break;
  351. }
  352. if (Status != (NTSTATUS)NDIS_STATUS_PENDING)
  353. {
  354. pIrp->IoStatus.Status = Status;
  355. IoCompleteRequest(pIrp, IO_NO_INCREMENT);
  356. }
  357. return (Status);
  358. }
  359. #endif // !BINARY_COMPATIBLE
  360. VOID
  361. Unload(
  362. IN PDRIVER_OBJECT pDriverObject
  363. )
  364. /*++
  365. Routine Description:
  366. This routine is called by the system prior to unloading us.
  367. Currently, we just undo everything we did in DriverEntry,
  368. that is, de-register ourselves as an NDIS protocol, and delete
  369. the device object we had created.
  370. Arguments:
  371. pDriverObject - Pointer to the driver object created by the system.
  372. Return Value:
  373. None
  374. --*/
  375. {
  376. NDIS_STATUS Status;
  377. #if DBG
  378. AA_IRQL EntryIrq, ExitIrq;
  379. #endif
  380. AA_GET_ENTRY_IRQL(EntryIrq);
  381. AADEBUGP(AAD_INFO, ("Unload Entered!\n"));
  382. if (pAtmArpGlobalInfo->ARPRegisterHandle != NULL)
  383. {
  384. Status = IPDeregisterARP(pAtmArpGlobalInfo->ARPRegisterHandle);
  385. AA_ASSERT(Status == NDIS_STATUS_SUCCESS);
  386. }
  387. AtmArpUnloadProtocol();
  388. //
  389. // Delay for a while.
  390. //
  391. AADEBUGP(AAD_INFO, ("Unload: will delay for a while...\n"));
  392. NdisInitializeEvent(&pAtmArpGlobalInfo->Block.Event);
  393. NdisWaitEvent(&pAtmArpGlobalInfo->Block.Event, 250);
  394. #if !BINARY_COMPATIBLE
  395. {
  396. UNICODE_STRING SymbolicName;
  397. RtlInitUnicodeString(&SymbolicName, ATMARP_SYMBOLIC_NAME);
  398. IoDeleteSymbolicLink(&SymbolicName);
  399. //
  400. // Delete our device object.
  401. //
  402. IoDeleteDevice((PDEVICE_OBJECT)pAtmArpGlobalInfo->pDeviceObject);
  403. }
  404. #endif // !BINARY_COMPATIBLE
  405. AADEBUGP(AAD_INFO, ("Unload done!\n"));
  406. AA_CHECK_EXIT_IRQL(EntryIrq, ExitIrq);
  407. return;
  408. }