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.

1108 lines
30 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. nt.c
  5. Abstract:
  6. NT System entry points for ARP1394.
  7. Revision History:
  8. Who When What
  9. -------- -------- ----------------------------------------------
  10. josephj 11-05-98 Created
  11. Notes:
  12. --*/
  13. #include <precomp.h>
  14. // File-specific debugging defaults.
  15. //
  16. #define TM_CURRENT TM_NT
  17. // Global variables for this module.
  18. //
  19. ARP1394_GLOBALS ArpGlobals;
  20. // List of fixed resources used by ArpGlobals
  21. //
  22. enum
  23. {
  24. RTYPE_GLOBAL_BACKUP_TASKS,
  25. RTYPE_GLOBAL_DEVICE_OBJECT,
  26. RTYPE_GLOBAL_NDIS_BINDING,
  27. RTYPE_GLOBAL_ADAPTER_LIST,
  28. RTYPE_GLOBAL_IP_BINDING
  29. }; // ARP_GLOBAL_RESOURCES;
  30. //=========================================================================
  31. // L O C A L P R O T O T Y P E S
  32. //=========================================================================
  33. NTSTATUS
  34. DriverEntry(
  35. IN PDRIVER_OBJECT pDriverObject,
  36. IN PUNICODE_STRING pRegistryPath
  37. );
  38. VOID
  39. ArpUnload(
  40. IN PDRIVER_OBJECT pDriverObject
  41. );
  42. NTSTATUS
  43. ArpDispatch(
  44. IN PDEVICE_OBJECT pDeviceObject,
  45. IN PIRP pIrp
  46. );
  47. RM_STATUS
  48. arpResHandleGlobalDeviceObject(
  49. PRM_OBJECT_HEADER pObj,
  50. RM_RESOURCE_OPERATION Op,
  51. PVOID pvUserParams,
  52. PRM_STACK_RECORD psr
  53. );
  54. RM_STATUS
  55. arpResHandleGlobalNdisBinding(
  56. PRM_OBJECT_HEADER pObj,
  57. RM_RESOURCE_OPERATION Op,
  58. PVOID pvUserParams,
  59. PRM_STACK_RECORD psr
  60. );
  61. RM_STATUS
  62. arpResHandleGlobalIpBinding(
  63. PRM_OBJECT_HEADER pObj,
  64. RM_RESOURCE_OPERATION Op,
  65. PVOID pvUserParams,
  66. PRM_STACK_RECORD psr
  67. );
  68. RM_STATUS
  69. arpResHandleGlobalAdapterList(
  70. PRM_OBJECT_HEADER pObj,
  71. RM_RESOURCE_OPERATION Op,
  72. PVOID pvUserParams,
  73. PRM_STACK_RECORD psr
  74. );
  75. RM_STATUS
  76. arpResHandleGlobalBackupTasks(
  77. PRM_OBJECT_HEADER pObj,
  78. RM_RESOURCE_OPERATION Op,
  79. PVOID pvUserParams,
  80. PRM_STACK_RECORD psr
  81. );
  82. //
  83. // Identifies information pertaining to the use of the above resources.
  84. // Following table MUST be in strict increasing order of the RTYPE_GLOBAL
  85. // enum.
  86. //
  87. RM_RESOURCE_TABLE_ENTRY
  88. ArpGlobals_ResourceTable[] =
  89. {
  90. {RTYPE_GLOBAL_BACKUP_TASKS, arpResHandleGlobalBackupTasks},
  91. {RTYPE_GLOBAL_DEVICE_OBJECT, arpResHandleGlobalDeviceObject},
  92. {RTYPE_GLOBAL_NDIS_BINDING, arpResHandleGlobalNdisBinding},
  93. {RTYPE_GLOBAL_ADAPTER_LIST, arpResHandleGlobalAdapterList},
  94. {RTYPE_GLOBAL_IP_BINDING, arpResHandleGlobalIpBinding}
  95. };
  96. // Static informatiou about ArpGlobals.
  97. //
  98. RM_STATIC_OBJECT_INFO
  99. ArpGlobals_StaticInfo =
  100. {
  101. 0, // TypeUID
  102. 0, // TypeFlags
  103. "ArpGlobals", // TypeName
  104. 0, // Timeout
  105. NULL, // pfnCreate
  106. NULL, // pfnDelete
  107. NULL, // pfnVerifyLock
  108. sizeof(ArpGlobals_ResourceTable)/sizeof(ArpGlobals_ResourceTable[1]),
  109. ArpGlobals_ResourceTable
  110. };
  111. BOOLEAN
  112. arpAdapterCompareKey(
  113. PVOID pKey,
  114. PRM_HASH_LINK pItem
  115. )
  116. /*++
  117. Routine Description:
  118. Hash comparison function for ARP1394_ADAPTER.
  119. Arguments:
  120. pKey - Points to an NDIS_STRING containing an adapter name.
  121. pItem - Points to ARP1394_ADAPTER.Hdr.HashLink.
  122. Return Value:
  123. TRUE IFF the key (adapter name) exactly matches the key of the specified
  124. adapter object.
  125. --*/
  126. {
  127. ARP1394_ADAPTER *pA = CONTAINING_RECORD(pItem, ARP1394_ADAPTER, Hdr.HashLink);
  128. PNDIS_STRING pName = (PNDIS_STRING) pKey;
  129. //
  130. // TODO: maybe case-insensitive compare?
  131. //
  132. if ( (pA->bind.DeviceName.Length == pName->Length)
  133. && NdisEqualMemory(pA->bind.DeviceName.Buffer, pName->Buffer, pName->Length))
  134. {
  135. return TRUE;
  136. }
  137. else
  138. {
  139. return FALSE;
  140. }
  141. }
  142. ULONG
  143. arpAdapterHash(
  144. PVOID pKey
  145. )
  146. /*++
  147. Routine Description:
  148. Hash function responsible for returning a hash of pKey, which
  149. we expect to be a pointer to an NDIS_STRING.
  150. Return Value:
  151. ULONG-sized hash of the string.
  152. --*/
  153. {
  154. PNDIS_STRING pName = (PNDIS_STRING) pKey;
  155. WCHAR *pwch = pName->Buffer;
  156. WCHAR *pwchEnd = pName->Buffer + pName->Length/sizeof(*pwch);
  157. ULONG Hash = 0;
  158. for (;pwch < pwchEnd; pwch++)
  159. {
  160. Hash ^= (Hash<<1) ^ *pwch;
  161. }
  162. return Hash;
  163. }
  164. // arpAdapter_HashInfo contains information required maintain a hashtable
  165. // of ARP1394_ADAPTER objects.
  166. //
  167. RM_HASH_INFO
  168. arpAdapter_HashInfo =
  169. {
  170. NULL, // pfnTableAllocator
  171. NULL, // pfnTableDeallocator
  172. arpAdapterCompareKey, // fnCompare
  173. // Function to generate a ULONG-sized hash.
  174. //
  175. arpAdapterHash // pfnHash
  176. };
  177. // ArpGlobals_AdapterStaticInfo contains static information about
  178. // objects of type ARP1394_ADAPTER.
  179. //
  180. RM_STATIC_OBJECT_INFO
  181. ArpGlobals_AdapterStaticInfo =
  182. {
  183. 0, // TypeUID
  184. 0, // TypeFlags
  185. "Adapter", // TypeName
  186. 0, // Timeout
  187. arpAdapterCreate, // pfnCreate
  188. arpAdapterDelete, // pfnDelete
  189. NULL, // pfnVerifyLock
  190. 0, // Size of resource table
  191. NULL, // ResourceTable
  192. &arpAdapter_HashInfo
  193. };
  194. NTSTATUS
  195. DriverEntry(
  196. IN PDRIVER_OBJECT pDriverObject,
  197. IN PUNICODE_STRING pRegistryPath
  198. )
  199. /*++
  200. Routine Description:
  201. This is the "init" routine, called by the system when the ARP
  202. module is loaded. We initialize all our global objects, fill in our
  203. Dispatch and Unload routine addresses in the driver object, and create
  204. a device object for receiving I/O requests on (IOCTLs).
  205. Arguments:
  206. pDriverObject - Pointer to the driver object created by the system.
  207. pRegistryPath - Pointer to our global registry path. This is ignored.
  208. Return Value:
  209. NT Status code: STATUS_SUCCESS if successful, error code otherwise.
  210. --*/
  211. {
  212. NTSTATUS Status;
  213. BOOLEAN AllocatedGlobals = FALSE;
  214. ENTER("DriverEntry", 0xbfcb7eb1)
  215. RM_DECLARE_STACK_RECORD(sr)
  216. TIMESTAMPX("==>DriverEntry");
  217. do
  218. {
  219. // Must be done before any RM apis are used.
  220. //
  221. RmInitializeRm();
  222. RmInitializeLock(
  223. &ArpGlobals.Lock,
  224. LOCKLEVEL_GLOBAL
  225. );
  226. RmInitializeHeader(
  227. NULL, // pParentObject,
  228. &ArpGlobals.Hdr,
  229. ARP1394_GLOBALS_SIG,
  230. &ArpGlobals.Lock,
  231. &ArpGlobals_StaticInfo,
  232. NULL, // szDescription
  233. &sr
  234. );
  235. AllocatedGlobals = TRUE;
  236. //
  237. // Initialize the Driver Object.
  238. //
  239. {
  240. INT i;
  241. pDriverObject->DriverUnload = ArpUnload;
  242. pDriverObject->FastIoDispatch = NULL;
  243. for (i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; i++)
  244. {
  245. pDriverObject->MajorFunction[i] = ArpDispatch;
  246. }
  247. pDriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = ArpWmiDispatch;
  248. ArpGlobals.driver.pDriverObject = pDriverObject;
  249. }
  250. #if 0 // MILLEN
  251. TR_WARN((
  252. "&g_SkipAll =0x%p; &g_ulTracelevel=0x%p; &g_DiscardNonUnicastPackets=0x%p\n",
  253. &g_SkipAll,
  254. &g_ulTraceLevel,
  255. &g_DiscardNonUnicastPackets));
  256. #if DBG
  257. DbgBreakPoint();
  258. #endif // DBG
  259. #endif // 0
  260. Status = RmLoadGenericResource(
  261. &ArpGlobals.Hdr,
  262. RTYPE_GLOBAL_BACKUP_TASKS,
  263. &sr
  264. );
  265. if (FAIL(Status)) break;
  266. //
  267. // Create a device object for the driver.
  268. //
  269. Status = RmLoadGenericResource(
  270. &ArpGlobals.Hdr,
  271. RTYPE_GLOBAL_DEVICE_OBJECT,
  272. &sr
  273. );
  274. if (FAIL(Status)) break;
  275. //
  276. // Register ourselves with NDIS.
  277. //
  278. Status = RmLoadGenericResource(
  279. &ArpGlobals.Hdr,
  280. RTYPE_GLOBAL_NDIS_BINDING,
  281. &sr
  282. );
  283. if (FAIL(Status)) break;
  284. //
  285. // Create the Adapter List
  286. //
  287. Status = RmLoadGenericResource(
  288. &ArpGlobals.Hdr,
  289. RTYPE_GLOBAL_ADAPTER_LIST,
  290. &sr);
  291. if (FAIL(Status)) break;
  292. //
  293. // Register ourselves with IP.
  294. //
  295. Status = RmLoadGenericResource(
  296. &ArpGlobals.Hdr,
  297. RTYPE_GLOBAL_IP_BINDING,
  298. &sr
  299. );
  300. } while (FALSE);
  301. if (FAIL(Status))
  302. {
  303. if (AllocatedGlobals)
  304. {
  305. RmUnloadAllGenericResources(
  306. &ArpGlobals.Hdr,
  307. &sr
  308. );
  309. RmDeallocateObject(
  310. &ArpGlobals.Hdr,
  311. &sr
  312. );
  313. }
  314. // Must be done after any RM apis are used and async activity complete.
  315. //
  316. RmDeinitializeRm();
  317. }
  318. RM_ASSERT_CLEAR(&sr)
  319. EXIT()
  320. TIMESTAMP("<==DriverEntry");
  321. return Status;
  322. }
  323. VOID
  324. ArpUnload(
  325. IN PDRIVER_OBJECT pDriverObject
  326. )
  327. /*++
  328. Routine Description:
  329. This routine is called by the system prior to unloading us.
  330. Currently, we just undo everything we did in DriverEntry,
  331. that is, de-register ourselves as an NDIS protocol, and delete
  332. the device object we had created.
  333. Arguments:
  334. pDriverObject - Pointer to the driver object created by the system.
  335. Return Value:
  336. None
  337. --*/
  338. {
  339. ENTER("Unload", 0xc8482549)
  340. RM_DECLARE_STACK_RECORD(sr)
  341. TIMESTAMP("==>Unload");
  342. RmUnloadAllGenericResources(&ArpGlobals.Hdr, &sr);
  343. RmDeallocateObject(&ArpGlobals.Hdr, &sr);
  344. // Must be done after any RM apis are used and async activity complete.
  345. //
  346. RmDeinitializeRm();
  347. // TODO? Block(250);
  348. RM_ASSERT_CLEAR(&sr)
  349. EXIT()
  350. TIMESTAMP("<==Unload");
  351. return;
  352. }
  353. NTSTATUS
  354. ArpDispatch(
  355. IN PDEVICE_OBJECT pDeviceObject,
  356. IN PIRP pIrp
  357. )
  358. /*++
  359. Routine Description:
  360. This routine is called by the system when there is an IRP
  361. to be processed.
  362. Arguments:
  363. pDeviceObject - Pointer to device object we created for ourselves.
  364. pIrp - Pointer to IRP to be processed.
  365. Return Value:
  366. NT Status code.
  367. --*/
  368. {
  369. NTSTATUS NtStatus; // Return value
  370. PIO_STACK_LOCATION pIrpStack;
  371. PVOID pIoBuffer; // Values in/out
  372. ULONG InputBufferLength; // Length of input parameters
  373. ULONG OutputBufferLength; // Space for output values
  374. ENTER("Dispatch", 0x1dcf2679)
  375. //
  376. // Initialize
  377. //
  378. NtStatus = STATUS_SUCCESS;
  379. pIrp->IoStatus.Status = STATUS_SUCCESS;
  380. pIrp->IoStatus.Information = 0;
  381. //
  382. // Get all information in the IRP
  383. //
  384. pIoBuffer = pIrp->AssociatedIrp.SystemBuffer;
  385. pIrpStack = IoGetCurrentIrpStackLocation(pIrp);
  386. InputBufferLength = pIrpStack->Parameters.DeviceIoControl.InputBufferLength;
  387. OutputBufferLength = pIrpStack->Parameters.DeviceIoControl.OutputBufferLength;
  388. switch (pIrpStack->MajorFunction)
  389. {
  390. case IRP_MJ_CREATE:
  391. TR_INFO(("IRP_MJ_CREATE\n"));
  392. break;
  393. case IRP_MJ_CLOSE:
  394. TR_INFO(("IRP_MJ_CLOSE\n"));
  395. break;
  396. case IRP_MJ_CLEANUP:
  397. TR_INFO(("IRP_MJ_CLEANUP\n"));
  398. break;
  399. case IRP_MJ_DEVICE_CONTROL:
  400. TR_INFO(("IRP_MJ_DEVICE_CONTROL\n"));
  401. //
  402. // Handle the Ioctl.
  403. // This will fill in the Information field in the Irp
  404. //
  405. NtStatus = ArpHandleIoctlRequest(pIrp, pIrpStack);
  406. break;
  407. default:
  408. TR_WARN(("IRP: Unknown major function 0x%p\n",
  409. pIrpStack->MajorFunction));
  410. break;
  411. }
  412. if (NtStatus != STATUS_PENDING)
  413. {
  414. pIrp->IoStatus.Status = NtStatus;
  415. IoMarkIrpPending(pIrp);
  416. IoCompleteRequest(pIrp, IO_NO_INCREMENT);
  417. }
  418. EXIT()
  419. return STATUS_PENDING;
  420. }
  421. RM_STATUS
  422. arpResHandleGlobalDeviceObject(
  423. PRM_OBJECT_HEADER pObj,
  424. RM_RESOURCE_OPERATION Op,
  425. PVOID pvUserParams,
  426. PRM_STACK_RECORD pSR
  427. )
  428. /*++
  429. Routine Description:
  430. Responsible for loading and unloading of the RTYPE_GLOBAL_DEVICE_OBJECT resource.
  431. Arguments:
  432. pObj - Actually a pointer to an object of type ARP1394_GLOBALS.
  433. Op - Operation (load/unload)
  434. pvUserParams - (unused)
  435. Return Value:
  436. NDIS_STATUS_SUCCESS on success
  437. NDIS failure code otherwise.
  438. --*/
  439. {
  440. NDIS_STATUS Status = NDIS_STATUS_FAILURE;
  441. ARP1394_GLOBALS *pGlobals = CONTAINING_RECORD(pObj, ARP1394_GLOBALS, Hdr);
  442. BOOLEAN fCreatedSymbolicLink = FALSE;
  443. PDRIVER_OBJECT pDriverObject = (PDRIVER_OBJECT) pGlobals->driver.pDriverObject;
  444. UNICODE_STRING SymbolicName;
  445. ENTER("GlobalDeviceObject", 0x335f5f57)
  446. RtlInitUnicodeString(&SymbolicName, ARP1394_SYMBOLIC_NAME);
  447. if (Op == RM_RESOURCE_OP_LOAD)
  448. {
  449. TR_WARN(("LOADING"));
  450. do
  451. {
  452. PDEVICE_OBJECT pDeviceObject;
  453. UNICODE_STRING DeviceName;
  454. RtlInitUnicodeString(&DeviceName, ARP1394_DEVICE_NAME);
  455. pGlobals->driver.pDeviceObject = NULL;
  456. //
  457. // Create a device object for the ARP1394 module.
  458. //
  459. Status = IoCreateDevice(
  460. pDriverObject,
  461. 0,
  462. &DeviceName,
  463. FILE_DEVICE_NETWORK,
  464. FILE_DEVICE_SECURE_OPEN,
  465. FALSE,
  466. &pDeviceObject
  467. );
  468. if (FAIL(Status)) break;
  469. //
  470. // Retain the device object pointer -- we'll need this
  471. // if/when we are asked to unload ourselves.
  472. //
  473. pGlobals->driver.pDeviceObject = pDeviceObject;
  474. //
  475. // Set up a symbolic name for interaction with the user-mode
  476. // admin application.
  477. //
  478. {
  479. Status = IoCreateSymbolicLink(&SymbolicName, &DeviceName);
  480. if (FAIL(Status)) break;
  481. fCreatedSymbolicLink = TRUE;
  482. }
  483. //
  484. // Initialize the Device Object.
  485. //
  486. pDeviceObject->Flags |= DO_BUFFERED_IO;
  487. } while (FALSE);
  488. }
  489. else if (Op == RM_RESOURCE_OP_UNLOAD)
  490. {
  491. TR_WARN(("UNLOADING"));
  492. //
  493. // Were unloading this "resource" -- we expect
  494. // that pGlobals->driver.pDeviceObject contains a valid
  495. // device object and that we have created a symbolic
  496. // link which we need to tear down.
  497. //
  498. ASSERTEX(pGlobals->driver.pDeviceObject != NULL, pGlobals);
  499. fCreatedSymbolicLink = TRUE;
  500. // Always return success on unload.
  501. //
  502. Status = NDIS_STATUS_SUCCESS;
  503. }
  504. else
  505. {
  506. // Unexpected op code.
  507. //
  508. ASSERTEX(FALSE, pObj);
  509. }
  510. //
  511. // Release all resources either on unload or on failed load.
  512. //
  513. if (Op == RM_RESOURCE_OP_UNLOAD || FAIL(Status))
  514. {
  515. // If we've created a symbolic link, delete it.
  516. if (fCreatedSymbolicLink)
  517. {
  518. IoDeleteSymbolicLink(&SymbolicName);
  519. }
  520. // If we've created a device object, free it.
  521. if (pGlobals->driver.pDeviceObject)
  522. {
  523. IoDeleteDevice(pGlobals->driver.pDeviceObject);
  524. pGlobals->driver.pDeviceObject = NULL;
  525. }
  526. }
  527. EXIT()
  528. return Status;
  529. }
  530. RM_STATUS
  531. arpResHandleGlobalNdisBinding(
  532. PRM_OBJECT_HEADER pObj,
  533. RM_RESOURCE_OPERATION Op,
  534. PVOID pvUserParams,
  535. PRM_STACK_RECORD pSR
  536. )
  537. /*++
  538. Routine Description:
  539. Responsible for loading and unloading of the RTYPE_GLOBAL_NDIS_BINDING resource.
  540. Arguments:
  541. pObj - Actually a pointer to an object of type ARP1394_GLOBALS.
  542. Op - Operation (load/unload)
  543. pvUserParams - (unused)
  544. Return Value:
  545. NDIS_STATUS_SUCCESS on success
  546. NDIS failure code otherwise.
  547. --*/
  548. {
  549. NDIS_STATUS Status = NDIS_STATUS_FAILURE;
  550. ARP1394_GLOBALS *pGlobals = CONTAINING_RECORD(
  551. pObj,
  552. ARP1394_GLOBALS,
  553. Hdr);
  554. PNDIS_PROTOCOL_CHARACTERISTICS pNdisPC = &(pGlobals->ndis.PC);
  555. PNDIS_CLIENT_CHARACTERISTICS pNdisCC = &(pGlobals->ndis.CC);
  556. ENTER("GlobalNdisBinding", 0x62b1181e)
  557. if (Op == RM_RESOURCE_OP_LOAD)
  558. {
  559. TR_WARN(("LOADING"));
  560. //
  561. // Fill in our Protocol and Client characteristics structures.
  562. //
  563. NdisZeroMemory(pNdisPC, sizeof(*pNdisPC));
  564. pNdisPC->MajorNdisVersion = ARP1394_NDIS_MAJOR_VERSION;
  565. pNdisPC->MinorNdisVersion = ARP1394_NDIS_MINOR_VERSION;
  566. pNdisPC->OpenAdapterCompleteHandler = ArpNdOpenAdapterComplete;
  567. pNdisPC->CloseAdapterCompleteHandler = ArpNdCloseAdapterComplete;
  568. pNdisPC->ResetCompleteHandler = ArpNdResetComplete;
  569. pNdisPC->RequestCompleteHandler = ArpNdRequestComplete;
  570. pNdisPC->StatusHandler = ArpNdStatus;
  571. pNdisPC->StatusCompleteHandler = ArpNdStatusComplete;
  572. pNdisPC->SendCompleteHandler = ArpNdSendComplete;
  573. NdisInitUnicodeString(
  574. &pNdisPC->Name,
  575. ARP1394_LL_NAME
  576. );
  577. //
  578. // Following protocol context handlers are unused and set to NULL.
  579. //
  580. // pNdisPC->TransferDataCompleteHandler
  581. // pNdisPC->ReceiveHandler
  582. // pNdisPC->ReceiveCompleteHandler
  583. // pNdisPC->ReceivePacketHandler
  584. //
  585. pNdisPC->ReceiveCompleteHandler = ArpNdReceiveComplete;
  586. pNdisPC->BindAdapterHandler = ArpNdBindAdapter;
  587. pNdisPC->UnbindAdapterHandler = ArpNdUnbindAdapter;
  588. pNdisPC->UnloadHandler = (UNLOAD_PROTOCOL_HANDLER)
  589. ArpNdUnloadProtocol;
  590. pNdisPC->PnPEventHandler = ArpNdPnPEvent;
  591. pNdisPC->CoSendCompleteHandler = ArpCoSendComplete;
  592. pNdisPC->CoStatusHandler = ArpCoStatus;
  593. pNdisPC->CoReceivePacketHandler = ArpCoReceivePacket;
  594. pNdisPC->CoAfRegisterNotifyHandler = ArpCoAfRegisterNotify;
  595. NdisZeroMemory(pNdisCC, sizeof(*pNdisCC));
  596. pNdisCC->MajorVersion = ARP1394_NDIS_MAJOR_VERSION;
  597. pNdisCC->MinorVersion = ARP1394_NDIS_MINOR_VERSION;
  598. pNdisCC->ClCreateVcHandler = ArpCoCreateVc;
  599. pNdisCC->ClDeleteVcHandler = ArpCoDeleteVc;
  600. pNdisCC->ClRequestHandler = ArpCoRequest;
  601. pNdisCC->ClRequestCompleteHandler = ArpCoRequestComplete;
  602. pNdisCC->ClOpenAfCompleteHandler = ArpCoOpenAfComplete;
  603. pNdisCC->ClCloseAfCompleteHandler = ArpCoCloseAfComplete;
  604. pNdisCC->ClMakeCallCompleteHandler = ArpCoMakeCallComplete;
  605. pNdisCC->ClModifyCallQoSCompleteHandler = ArpCoModifyQosComplete;
  606. pNdisCC->ClIncomingCloseCallHandler = ArpCoIncomingClose;
  607. pNdisCC->ClCallConnectedHandler = ArpCoCallConnected;
  608. pNdisCC->ClCloseCallCompleteHandler = ArpCoCloseCallComplete;
  609. //
  610. // Following client context handlers are unused and set to NULL.
  611. //
  612. // pNdisCC->ClRegisterSapCompleteHandler
  613. // pNdisCC->ClDeregisterSapCompleteHandler
  614. // pNdisCC->ClAddPartyCompleteHandler
  615. // pNdisCC->ClDropPartyCompleteHandler
  616. // pNdisCC->ClIncomingCallHandler
  617. // pNdisCC->ClIncomingCallQoSChangeHandler
  618. // pNdisCC->ClIncomingDropPartyHandler
  619. //
  620. //
  621. // Register ourselves as a protocol with NDIS.
  622. //
  623. NdisRegisterProtocol(
  624. &Status,
  625. &(pGlobals->ndis.ProtocolHandle),
  626. pNdisPC,
  627. sizeof(*pNdisPC)
  628. );
  629. if (FAIL(Status))
  630. {
  631. NdisZeroMemory(&(pGlobals->ndis), sizeof(pGlobals->ndis));
  632. }
  633. }
  634. else if (Op == RM_RESOURCE_OP_UNLOAD)
  635. {
  636. //
  637. // Were unloading this "resource", i.e., cleaning up and
  638. // unregistering with NDIS.
  639. //
  640. TR_WARN(("UNLOADING"));
  641. ASSERTEX(pGlobals->ndis.ProtocolHandle != NULL, pGlobals);
  642. // Unregister ourselves from ndis
  643. //
  644. NdisDeregisterProtocol(
  645. &Status,
  646. pGlobals->ndis.ProtocolHandle
  647. );
  648. NdisZeroMemory(&(pGlobals->ndis), sizeof(pGlobals->ndis));
  649. }
  650. else
  651. {
  652. // Unexpected op code.
  653. //
  654. ASSERT(FALSE);
  655. }
  656. EXIT()
  657. return Status;
  658. }
  659. RM_STATUS
  660. arpResHandleGlobalIpBinding(
  661. PRM_OBJECT_HEADER pObj,
  662. RM_RESOURCE_OPERATION Op,
  663. PVOID pvUserParams,
  664. PRM_STACK_RECORD pSR
  665. )
  666. /*++
  667. Routine Description:
  668. Responsible for loading and unloading of the RTYPE_GLOBAL_IP_BINDING resource.
  669. Arguments:
  670. pObj - Actually a pointer to an object of type ARP1394_GLOBALS.
  671. Op - Operation (load/unload)
  672. pvUserParams - (unused)
  673. Return Value:
  674. NDIS_STATUS_SUCCESS on success
  675. NDIS failure code otherwise.
  676. --*/
  677. {
  678. NDIS_STATUS Status = NDIS_STATUS_FAILURE;
  679. ARP1394_GLOBALS *pGlobals = CONTAINING_RECORD(
  680. pObj,
  681. ARP1394_GLOBALS,
  682. Hdr);
  683. ENTER("GlobalIpBinding", 0xf9d36d49)
  684. if (Op == RM_RESOURCE_OP_LOAD)
  685. {
  686. //
  687. // Register ourselves as an ARP Module with IP.
  688. //
  689. NDIS_STRING ArpName;
  690. IP_CHANGE_INDEX IpChangeIndex;
  691. IP_RESERVE_INDEX IpReserveIndex;
  692. IP_DERESERVE_INDEX IpDereserveIndex;
  693. TR_WARN(("LOADING"));
  694. NdisInitUnicodeString(&ArpName, ARP1394_UL_NAME);
  695. Status = IPRegisterARP(
  696. &ArpName,
  697. IP_ARP_BIND_VERSION,
  698. ArpNdBindAdapter,
  699. &(pGlobals->ip.pAddInterfaceRtn),
  700. &(pGlobals->ip.pDelInterfaceRtn),
  701. &(pGlobals->ip.pBindCompleteRtn),
  702. &(pGlobals->ip.pAddLinkRtn),
  703. &(pGlobals->ip.pDeleteLinkRtn),
  704. //
  705. // Following 3 are placeholders -- we don't use this information.
  706. // See 10/14/1998 entry in ipatmc\notes.txt
  707. //
  708. &IpChangeIndex,
  709. &IpReserveIndex,
  710. &IpDereserveIndex,
  711. &(pGlobals->ip.ARPRegisterHandle)
  712. );
  713. if (FAIL(Status))
  714. {
  715. TR_WARN(("IPRegisterARP FAILS. Status = 0x%p", Status));
  716. NdisZeroMemory(&(pGlobals->ip), sizeof(pGlobals->ip));
  717. }
  718. else
  719. {
  720. TR_WARN(("IPRegisterARP Succeeds"));
  721. }
  722. }
  723. else if (Op == RM_RESOURCE_OP_UNLOAD)
  724. {
  725. //
  726. // Were unloading this "resource", i.e., unregistering with IP.
  727. //
  728. TR_WARN(("UNLOADING"));
  729. ASSERTEX(pGlobals->ip.ARPRegisterHandle != NULL, pGlobals);
  730. //
  731. // Unload all adapters (and disallow new adapter from being added)
  732. // *before calling IPDerigesterARP.
  733. //
  734. RmUnloadAllObjectsInGroup(
  735. &pGlobals->adapters.Group,
  736. arpAllocateTask,
  737. arpTaskShutdownAdapter,
  738. NULL, // userParam
  739. NULL, // pTask
  740. 0, // uTaskPendCode
  741. pSR
  742. );
  743. Status = IPDeregisterARP(pGlobals->ip.ARPRegisterHandle);
  744. ASSERTEX(!FAIL(Status), pGlobals);
  745. NdisZeroMemory(&(pGlobals->ip), sizeof(pGlobals->ip));
  746. }
  747. else
  748. {
  749. // Unexpected op code.
  750. //
  751. ASSERT(FALSE);
  752. }
  753. EXIT()
  754. return Status;
  755. }
  756. RM_STATUS
  757. arpResHandleGlobalAdapterList(
  758. PRM_OBJECT_HEADER pObj,
  759. RM_RESOURCE_OPERATION Op,
  760. PVOID pvUserParams,
  761. PRM_STACK_RECORD pSR
  762. )
  763. /*++
  764. Routine Description:
  765. Responsible for loading and unloading of the RTYPE_GLOBAL_ADAPTER_LIST resource.
  766. Arguments:
  767. pObj - Actually a pointer to an object of type ARP1394_GLOBALS.
  768. Op - Operation (load/unload)
  769. pvUserParams - (unused)
  770. Return Value:
  771. NDIS_STATUS_SUCCESS on success
  772. NDIS failure code otherwise.
  773. --*/
  774. {
  775. ARP1394_GLOBALS *pGlobals = CONTAINING_RECORD(
  776. pObj,
  777. ARP1394_GLOBALS,
  778. Hdr);
  779. ENTER("GlobalAdapterList", 0xb407e79e)
  780. if (Op == RM_RESOURCE_OP_LOAD)
  781. {
  782. //
  783. // Allocate adapter list.
  784. //
  785. TR_WARN(("LOADING"));
  786. RmInitializeGroup(
  787. pObj, // pParentObject
  788. &ArpGlobals_AdapterStaticInfo, // pStaticInfo
  789. &(pGlobals->adapters.Group), // pGroup
  790. "Adapter group", // szDescription
  791. pSR // pStackRecord
  792. );
  793. }
  794. else if (Op == RM_RESOURCE_OP_UNLOAD)
  795. {
  796. //
  797. // We're unloading this "resource", i.e., unloading and deallocating the
  798. // global adapter list. We first unload and free all the adapters
  799. // in the list, and then free the list itself.
  800. //
  801. TR_WARN(("UNLOADING"));
  802. //
  803. // We expect there to be no adapter objects at this point.
  804. //
  805. ASSERT(pGlobals->adapters.Group.HashTable.NumItems == 0);
  806. RmDeinitializeGroup(&pGlobals->adapters.Group, pSR);
  807. NdisZeroMemory(&(pGlobals->adapters), sizeof(pGlobals->adapters));
  808. }
  809. else
  810. {
  811. // Unexpected op code.
  812. //
  813. ASSERT(FALSE);
  814. }
  815. EXIT()
  816. return NDIS_STATUS_SUCCESS;
  817. }
  818. RM_STATUS
  819. arpResHandleGlobalBackupTasks(
  820. PRM_OBJECT_HEADER pObj,
  821. RM_RESOURCE_OPERATION Op,
  822. PVOID pvUserParams,
  823. PRM_STACK_RECORD pSR
  824. )
  825. /*++
  826. Routine Description:
  827. Allocates 4 Tasks for each adapter to be used as a backup in case of a low mem
  828. condition.
  829. Arguments:
  830. pObj - Actually a pointer to an object of type ARP1394_GLOBALS.
  831. Op - Operation (load/unload)
  832. pvUserParams - (unused)
  833. Return Value:
  834. NDIS_STATUS_SUCCESS on success
  835. NDIS failure code otherwise.
  836. --*/
  837. {
  838. ARP1394_GLOBALS *pGlobals = CONTAINING_RECORD(
  839. pObj,
  840. ARP1394_GLOBALS,
  841. Hdr);
  842. ENTER("GlobalBackupTasks", 0xb64e5007)
  843. if (Op == RM_RESOURCE_OP_LOAD)
  844. {
  845. //
  846. // Allocate adapter list.
  847. //
  848. TR_WARN(("LOADING"));
  849. arpAllocateBackupTasks(pGlobals);
  850. }
  851. else if (Op == RM_RESOURCE_OP_UNLOAD)
  852. {
  853. //
  854. // We're unloading this "resource", i.e., unloading and deallocating the
  855. // global adapter list. We first unload and free all the adapters
  856. // in the list, and then free the list itself.
  857. //
  858. TR_WARN(("UNLOADING"));
  859. //
  860. // We expect there to be no adapter objects at this point.
  861. //
  862. arpFreeBackupTasks(pGlobals);
  863. }
  864. else
  865. {
  866. // Unexpected op code.
  867. //
  868. ASSERT(FALSE);
  869. }
  870. EXIT()
  871. return NDIS_STATUS_SUCCESS;
  872. }