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.

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