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.

302 lines
8.6 KiB

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