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.

309 lines
9.1 KiB

  1. //depot/Lab03_N/Net/rras/ndis/raspptp/common/raspptp.c#4 - edit change 19457 (text)
  2. /*****************************************************************************
  3. *
  4. * Copyright (c) 1998-1999 Microsoft Corporation
  5. *
  6. * RASPPTP.C - RASPPTP driver main module (DriverEntry, etc.)
  7. *
  8. * Author: Stan Adermann (stana)
  9. *
  10. * Created: 7/28/1998
  11. *
  12. *****************************************************************************/
  13. #include "raspptp.h"
  14. #include "raspptp.tmh"
  15. NTSTATUS
  16. DriverEntry(
  17. IN PDRIVER_OBJECT pDriverObject,
  18. IN PUNICODE_STRING pRegistryPath
  19. );
  20. #pragma NDIS_INIT_FUNCTION(DriverEntry)
  21. NDIS_HANDLE ghNdisWrapper;
  22. PDRIVER_OBJECT gDriverObject;
  23. COUNTERS gCounters;
  24. #if DBG
  25. ULONG PptpTraceMask = 0xffffffff;
  26. #else
  27. ULONG PptpTraceMask = 0;
  28. #endif
  29. VOID MiniportUnload(PVOID DriverObject)
  30. {
  31. if(gDriverObject != NULL)
  32. {
  33. WPP_CLEANUP(gDriverObject);
  34. }
  35. }
  36. NTSTATUS
  37. DriverEntry(
  38. IN PDRIVER_OBJECT pDriverObject,
  39. IN PUNICODE_STRING pRegistryPath
  40. )
  41. {
  42. NDIS_MINIPORT_CHARACTERISTICS Characteristics;
  43. NDIS_STATUS Status;
  44. DEFAULT_DEBUG_OPTIONS(
  45. DBG_ERROR |
  46. DBG_WARN |
  47. //DBG_FUNC |
  48. DBG_INIT |
  49. //DBG_TX |
  50. //DBG_RX |
  51. DBG_TDI |
  52. DBG_TUNNEL |
  53. DBG_CALL |
  54. DBG_NDIS |
  55. DBG_TAPI |
  56. //DBG_THREAD |
  57. //DBG_POOL |
  58. //DBG_REF |
  59. //DBG_LOG |
  60. 0
  61. );
  62. DEBUGMSG(DBG_INIT|DBG_FUNC, (DTEXT("+DriverEntry\n")));
  63. // Standard NDIS initiailization:
  64. // InitializeWrapper
  65. // Fill in the characteristics
  66. // Register the miniport
  67. NdisMInitializeWrapper(&ghNdisWrapper,
  68. pDriverObject,
  69. pRegistryPath,
  70. NULL
  71. );
  72. NdisZeroMemory(&Characteristics, sizeof(NDIS_MINIPORT_CHARACTERISTICS));
  73. Characteristics.MajorNdisVersion = NDIS_MAJOR_VERSION;
  74. Characteristics.MinorNdisVersion = NDIS_MINOR_VERSION;
  75. Characteristics.Reserved = NDIS_USE_WAN_WRAPPER;
  76. Characteristics.InitializeHandler = MiniportInitialize;
  77. Characteristics.HaltHandler = MiniportHalt;
  78. Characteristics.ResetHandler = MiniportReset;
  79. Characteristics.QueryInformationHandler = MiniportQueryInformation;
  80. Characteristics.SetInformationHandler = MiniportSetInformation;
  81. Characteristics.WanSendHandler = MiniportWanSend;
  82. // ToDo: Characteristics.ReturnPacketHandler = MpReturnPacket;
  83. Status = NdisMRegisterMiniport(ghNdisWrapper,
  84. &Characteristics,
  85. sizeof(Characteristics));
  86. if (Status!=NDIS_STATUS_SUCCESS)
  87. {
  88. DEBUGMSG(DBG_ERROR, (DTEXT("PPTP: NdisMRegisterMiniport failed %x\n"), Status));
  89. NdisTerminateWrapper(ghNdisWrapper, NULL);
  90. return STATUS_UNSUCCESSFUL;
  91. }
  92. // WPP tracing support
  93. NdisMRegisterUnloadHandler(ghNdisWrapper, MiniportUnload);
  94. gDriverObject = pDriverObject;
  95. WPP_INIT_TRACING(pDriverObject, pRegistryPath);
  96. DEBUGMSG(DBG_INIT|DBG_FUNC, (DTEXT("-DriverEntry\n")));
  97. return STATUS_SUCCESS;
  98. }
  99. VOID
  100. AdapterCleanup(
  101. IN PVOID SystemSpecific1,
  102. IN PVOID pContext,
  103. IN PVOID SystemSpecific2,
  104. IN PVOID SystemSpecific3
  105. )
  106. {
  107. PPPTP_ADAPTER pAdapter = pContext;
  108. extern VOID CtlpCleanupLooseEnds(PPPTP_ADAPTER pAdapter);
  109. extern VOID CallpCleanupLooseEnds(PPPTP_ADAPTER pAdapter);
  110. extern VOID CtdiCleanupLooseEnds(VOID);
  111. DEBUGMSG(DBG_FUNC, (DTEXT("+AdapterCleanup\n")));
  112. CtdiCleanupLooseEnds();
  113. CtlpCleanupLooseEnds(pAdapter);
  114. CallpCleanupLooseEnds(pAdapter);
  115. DEBUGMSG(DBG_FUNC, (DTEXT("-AdapterCleanup\n")));
  116. }
  117. PPPTP_ADAPTER
  118. AdapterAlloc(NDIS_HANDLE NdisAdapterHandle)
  119. {
  120. PPPTP_ADAPTER pAdapter;
  121. NDIS_PHYSICAL_ADDRESS HighestAcceptableAddress = NDIS_PHYSICAL_ADDRESS_CONST(-1,-1);
  122. UINT i;
  123. DEBUGMSG(DBG_FUNC, (DTEXT("+AdapterAlloc\n")));
  124. pAdapter = MyMemAlloc(sizeof(PPTP_ADAPTER), TAG_PPTP_ADAPTER);
  125. if (!pAdapter)
  126. {
  127. DEBUGMSG(DBG_FUNC|DBG_ERROR, (DTEXT("-AdapterAlloc NULL\n")));
  128. return NULL;
  129. }
  130. NdisZeroMemory(pAdapter, sizeof(PPTP_ADAPTER));
  131. pAdapter->hMiniportAdapter = NdisAdapterHandle;
  132. NdisAllocateSpinLock(&pAdapter->Lock);
  133. // Fill the NDIS_WAN_INFO structure.
  134. pAdapter->Info.MaxFrameSize = 1400;
  135. pAdapter->Info.MaxTransmit = PptpMaxTransmit;
  136. pAdapter->Info.HeaderPadding = sizeof(GRE_HEADER) + sizeof(ULONG)*2 + sizeof(IP4_HEADER);
  137. pAdapter->Info.TailPadding = 0;
  138. pAdapter->Info.Endpoints = PptpWanEndpoints;
  139. pAdapter->Info.MemoryFlags = 0;
  140. pAdapter->Info.HighestAcceptableAddress = HighestAcceptableAddress;
  141. pAdapter->Info.FramingBits = PPP_FRAMING |
  142. PPP_COMPRESS_ADDRESS_CONTROL |
  143. PPP_COMPRESS_PROTOCOL_FIELD |
  144. TAPI_PROVIDER;
  145. pAdapter->Info.DesiredACCM = 0;
  146. pAdapter->pCallArray = MyMemAlloc(sizeof(PCALL_SESSION)*pAdapter->Info.Endpoints, TAG_PPTP_CALL_LIST);
  147. if (!pAdapter->pCallArray)
  148. {
  149. AdapterFree(pAdapter);
  150. DEBUGMSG(DBG_FUNC|DBG_ERROR, (DTEXT("-AdapterAlloc Call NULL\n")));
  151. return NULL;
  152. }
  153. NdisZeroMemory(pAdapter->pCallArray, sizeof(PCALL_SESSION)*pAdapter->Info.Endpoints);
  154. for (i=0; i<pAdapter->Info.Endpoints; i++)
  155. {
  156. // Allocate the call on TapiOpen
  157. //pAdapter->pCallArray[i] = CallAlloc(pAdapter);
  158. pAdapter->pCallArray[i] = NULL;
  159. }
  160. NdisInitializeListHead(&pAdapter->ControlTunnelList);
  161. NdisMInitializeTimer(&pAdapter->CleanupTimer,
  162. pAdapter->hMiniportAdapter,
  163. AdapterCleanup,
  164. pAdapter);
  165. NdisMSetPeriodicTimer(&pAdapter->CleanupTimer, 60000); // 60 second intervals
  166. DEBUGMSG(DBG_FUNC, (DTEXT("-AdapterAlloc %08x\n"), pAdapter));
  167. return pAdapter;
  168. }
  169. VOID
  170. AdapterFree(PPPTP_ADAPTER pAdapter)
  171. {
  172. ULONG i;
  173. BOOLEAN NotUsed;
  174. if (!pAdapter)
  175. {
  176. return;
  177. }
  178. DEBUGMSG(DBG_FUNC, (DTEXT("+AdapterFree\n")));
  179. ASSERT(IsListEmpty(&pAdapter->ControlTunnelList));
  180. if (pAdapter->pCallArray)
  181. {
  182. for (i=0; i<pAdapter->Info.Endpoints; i++)
  183. {
  184. CallFree(pAdapter->pCallArray[i]);
  185. }
  186. MyMemFree(pAdapter->pCallArray, sizeof(PCALL_SESSION)*pAdapter->Info.Endpoints);
  187. // We init and start Cleanup timer after we alloc pCallArray hence use this as a flag.
  188. NdisMCancelTimer(&pAdapter->CleanupTimer, &NotUsed);
  189. }
  190. NdisFreeSpinLock(&pAdapter->Lock);
  191. MyMemFree(pAdapter, sizeof(PPTP_ADAPTER));
  192. DEBUGMSG(DBG_FUNC, (DTEXT("-AdapterFree\n")));
  193. }
  194. PLIST_ENTRY FASTCALL
  195. EnumListEntry(
  196. IN PLIST_ENTRY pHead,
  197. IN PENUM_CONTEXT pEnum,
  198. IN PNDIS_SPIN_LOCK pLock
  199. )
  200. {
  201. PLIST_ENTRY pEntry = NULL;
  202. DEBUGMSG(DBG_FUNC, (DTEXT("+EnumListEntry\n")));
  203. ASSERT(pEnum->Signature==ENUM_SIGNATURE);
  204. if (pLock)
  205. {
  206. NdisAcquireSpinLock(pLock);
  207. }
  208. do
  209. {
  210. if (pEnum->ListEntry.Flink==NULL)
  211. {
  212. // First call
  213. if (!IsListEmpty(pHead))
  214. {
  215. pEntry = pHead->Flink;
  216. InsertHeadList(pEntry, &pEnum->ListEntry);
  217. }
  218. }
  219. else
  220. {
  221. if (pEnum->ListEntry.Flink!=pHead)
  222. {
  223. pEntry = pEnum->ListEntry.Flink;
  224. RemoveEntryList(&pEnum->ListEntry);
  225. InsertHeadList(pEntry, &pEnum->ListEntry);
  226. }
  227. else
  228. {
  229. RemoveEntryList(&pEnum->ListEntry);
  230. pEnum->ListEntry.Flink = pEnum->ListEntry.Blink = NULL;
  231. pEntry = NULL;
  232. }
  233. }
  234. } while ( pEntry &&
  235. ((PENUM_CONTEXT)pEntry)->Signature==ENUM_SIGNATURE );
  236. if (pLock)
  237. {
  238. NdisReleaseSpinLock(pLock);
  239. }
  240. DEBUGMSG(DBG_FUNC, (DTEXT("-EnumListEntry %08x\n"), pEntry));
  241. return pEntry;
  242. }
  243. VOID
  244. EnumComplete(
  245. IN PENUM_CONTEXT pEnum,
  246. IN PNDIS_SPIN_LOCK pLock
  247. )
  248. {
  249. DEBUGMSG(DBG_FUNC, (DTEXT("+EnumComplete\n")));
  250. if (pEnum->ListEntry.Flink)
  251. {
  252. if (pLock)
  253. {
  254. NdisAcquireSpinLock(pLock);
  255. }
  256. RemoveEntryList(&pEnum->ListEntry);
  257. pEnum->ListEntry.Flink = pEnum->ListEntry.Blink = NULL;
  258. if (pLock)
  259. {
  260. NdisReleaseSpinLock(pLock);
  261. }
  262. }
  263. DEBUGMSG(DBG_FUNC, (DTEXT("-EnumComplete\n")));
  264. }