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.

175 lines
4.2 KiB

  1. // Copyright (c) 2000, Microsoft Corporation, all rights reserved
  2. //
  3. // main.c
  4. // RAS PPPoE mini-port/call-manager driver
  5. // Main routine (DriverEntry) and global data definitions
  6. //
  7. // 01/26/2000 Hakan BERK
  8. //
  9. #include <ntddk.h>
  10. #include <ndis.h>
  11. #include <ndiswan.h>
  12. #include <ndistapi.h>
  13. #include "debug.h"
  14. #include "timer.h"
  15. #include "bpool.h"
  16. #include "ppool.h"
  17. #include "util.h"
  18. #include "packet.h"
  19. #include "protocol.h"
  20. #include "miniport.h"
  21. #include "packet.h"
  22. //-----------------------------------------------------------------------------
  23. // Global Variables
  24. //-----------------------------------------------------------------------------
  25. NDIS_HANDLE gl_NdisWrapperHandle = NULL;
  26. NDIS_HANDLE gl_NdisProtocolHandle = NULL;
  27. //
  28. // Lookaside list for work items
  29. //
  30. NPAGED_LOOKASIDE_LIST gl_llistWorkItems;
  31. //-----------------------------------------------------------------------------
  32. // Local prototypes
  33. //-----------------------------------------------------------------------------
  34. NTSTATUS
  35. DriverEntry(
  36. IN PDRIVER_OBJECT DriverObject,
  37. IN PUNICODE_STRING RegistryPath );
  38. //
  39. // Mark routine to be unloaded after initialization.
  40. //
  41. #pragma NDIS_INIT_FUNCTION(DriverEntry)
  42. VOID
  43. DriverUnload(
  44. IN PDRIVER_OBJECT DriverObject
  45. );
  46. //-----------------------------------------------------------------------------
  47. // Routines
  48. //-----------------------------------------------------------------------------
  49. NTSTATUS
  50. DriverEntry(
  51. IN PDRIVER_OBJECT DriverObject,
  52. IN PUNICODE_STRING RegistryPath )
  53. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  54. Functional Description:
  55. The DriverEntry routine is the main entry point for the driver.
  56. It is responsible for the initializing the Miniport wrapper and
  57. registering the driver with the Miniport wrapper.
  58. Parameters:
  59. DriverObject _ Pointer to driver object created by the system.
  60. RegistryPath _ Pointer to registery path name used to read registry
  61. parameters.
  62. Return Values:
  63. STATUS_SUCCESS
  64. STATUS_UNSUCCESSFUL
  65. ---------------------------------------------------------------------------*/
  66. {
  67. NTSTATUS ntStatus;
  68. NDIS_STATUS status;
  69. TRACE( TL_N, TM_Mn, ( "+DriverEntry" ) );
  70. do
  71. {
  72. //
  73. // Register miniport
  74. //
  75. status = MpRegisterMiniport( DriverObject, RegistryPath, &gl_NdisWrapperHandle );
  76. if (status != NDIS_STATUS_SUCCESS)
  77. {
  78. TRACE( TL_A, TM_Mn, ( "MpRegisterMiniport=$%x", status ) );
  79. break;
  80. }
  81. //
  82. // Register protocol
  83. //
  84. status = PrRegisterProtocol( DriverObject, RegistryPath, &gl_NdisProtocolHandle );
  85. if (status != NDIS_STATUS_SUCCESS)
  86. {
  87. TRACE( TL_A, TM_Mn, ( "PrRegisterProtocol=$%x", status ) );
  88. break;
  89. }
  90. //
  91. // Set driver object's unload function
  92. //
  93. NdisMRegisterUnloadHandler( gl_NdisWrapperHandle, DriverUnload );
  94. //
  95. // Initialize the lookaside list for bindings
  96. //
  97. InitializeWorkItemLookasideList( &gl_llistWorkItems,
  98. MTAG_LLIST_WORKITEMS );
  99. } while ( FALSE );
  100. if ( status == NDIS_STATUS_SUCCESS )
  101. {
  102. ntStatus = STATUS_SUCCESS;
  103. }
  104. else
  105. {
  106. if(NULL != gl_NdisWrapperHandle)
  107. {
  108. NdisTerminateWrapper(gl_NdisWrapperHandle, NULL);
  109. gl_NdisWrapperHandle = NULL;
  110. }
  111. ntStatus = STATUS_UNSUCCESSFUL;
  112. }
  113. TRACE( TL_N, TM_Mn, ( "-DriverEntry=$%x",ntStatus ) );
  114. return ntStatus;
  115. }
  116. VOID
  117. DriverUnload(
  118. IN PDRIVER_OBJECT DriverObject
  119. )
  120. {
  121. NDIS_STATUS Status;
  122. TRACE( TL_N, TM_Mn, ( "+DriverUnload" ) );
  123. //
  124. // First deregister the protocol
  125. //
  126. NdisDeregisterProtocol( &Status, gl_NdisProtocolHandle );
  127. //
  128. // Clean up the protocol resources before driver unloads
  129. //
  130. PrUnload();
  131. NdisDeleteNPagedLookasideList( &gl_llistWorkItems );
  132. TRACE( TL_N, TM_Mn, ( "-DriverUnload" ) );
  133. }