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.

294 lines
8.7 KiB

  1. /*++
  2. Copyright (c) 1995-1996 Micrososfft Corporation
  3. Module Name:
  4. pxinit.c
  5. Abstract:
  6. The module contains the init code for the NDIS Proxy.
  7. Author:
  8. Richard Machin (RMachin)
  9. Revision History:
  10. Who When What
  11. -------- -------- ----------------------------------------------
  12. RMachin 10-3-96 created
  13. TonyBe 02-21-99 re-work/re-write
  14. Notes:
  15. --*/
  16. #include <precomp.h>
  17. #define MODULE_NUMBER MODULE_INIT
  18. #define _FILENUMBER 'TINI'
  19. //
  20. // Local defines...
  21. //
  22. NDIS_STATUS
  23. GetConfigDword(
  24. NDIS_HANDLE Handle,
  25. PWCHAR ParameterName,
  26. PULONG Destination,
  27. ULONG MinValue,
  28. ULONG MaxValue
  29. );
  30. BOOLEAN
  31. InitNDISProxy(
  32. VOID
  33. )
  34. /*++
  35. Routine Description
  36. The main init routine. We:
  37. read our configuration
  38. register as a protocol
  39. open the appropriate cards as a client (call ActivateBinding, which:
  40. Opens the appropriate address families
  41. Opens the cards as a Call Manager)
  42. Arguments
  43. None
  44. Calling Sequence:
  45. Called from pxntinit/DriverEntry
  46. Return Value:
  47. TRUE if initalization succeeds.
  48. --*/
  49. {
  50. NDIS_PROTOCOL_CHARACTERISTICS PxProtocolCharacteristics;
  51. NDIS_STATUS Status;
  52. NDIS_HANDLE ConfigHandle;
  53. PVOID Context;
  54. PVOID BindingList;
  55. PNDIS_STRING BindingNameString;
  56. PXDEBUGP(PXD_INFO, PXM_INIT, ("InitNdisProxy\n"));
  57. // Registering NDIS protocols.
  58. NdisZeroMemory(&PxProtocolCharacteristics,
  59. sizeof(NDIS_PROTOCOL_CHARACTERISTICS));
  60. PxProtocolCharacteristics.MajorNdisVersion = NDIS_MAJOR_VERSION;
  61. PxProtocolCharacteristics.MinorNdisVersion = NDIS_MINOR_VERSION;
  62. PxProtocolCharacteristics.Filler = (USHORT)0;
  63. PxProtocolCharacteristics.Flags = NDIS_PROTOCOL_PROXY |
  64. NDIS_PROTOCOL_BIND_ALL_CO;
  65. PxProtocolCharacteristics.OpenAdapterCompleteHandler = PxCoOpenAdaperComplete;
  66. PxProtocolCharacteristics.CloseAdapterCompleteHandler = PxCoCloseAdaperComplete;
  67. PxProtocolCharacteristics.TransferDataCompleteHandler = PxCoTransferDataComplete;
  68. PxProtocolCharacteristics.ResetCompleteHandler = PxCoResetComplete;
  69. PxProtocolCharacteristics.SendCompleteHandler = PxCoSendComplete;
  70. PxProtocolCharacteristics.RequestCompleteHandler = PxCoRequestComplete;
  71. PxProtocolCharacteristics.ReceiveHandler = NULL;
  72. PxProtocolCharacteristics.ReceiveCompleteHandler = PxCoReceiveComplete;
  73. PxProtocolCharacteristics.ReceivePacketHandler = NULL;
  74. PxProtocolCharacteristics.StatusHandler = NULL;
  75. PxProtocolCharacteristics.StatusCompleteHandler = PxCoStatusComplete;
  76. PxProtocolCharacteristics.BindAdapterHandler = PxCoBindAdapter;
  77. PxProtocolCharacteristics.UnbindAdapterHandler = PxCoUnbindAdapter;
  78. PxProtocolCharacteristics.PnPEventHandler = PxCoPnPEvent;
  79. PxProtocolCharacteristics.UnloadHandler = PxCoUnloadProtocol;
  80. PxProtocolCharacteristics.CoStatusHandler = PxCoStatus;
  81. PxProtocolCharacteristics.CoReceivePacketHandler = PxCoReceivePacket;
  82. PxProtocolCharacteristics.CoAfRegisterNotifyHandler = PxCoNotifyAfRegistration;
  83. NdisInitUnicodeString(&(PxProtocolCharacteristics.Name), PX_NAME);
  84. //
  85. // To block BindAdapter till all RegisterProtocols are done.
  86. //
  87. NdisInitializeEvent(&DeviceExtension->NdisEvent);
  88. //
  89. // Now register ourselves as a CM with NDIS.
  90. //
  91. PXDEBUGP(PXD_LOUD,PXM_INIT, ("Registering Protocol\n"));
  92. NdisRegisterProtocol(&Status,
  93. &(DeviceExtension->PxProtocolHandle),
  94. &PxProtocolCharacteristics,
  95. sizeof(PxProtocolCharacteristics));
  96. if (Status != NDIS_STATUS_SUCCESS) {
  97. PXDEBUGP(PXD_INFO, PXM_INIT, ("Protocol registration failed!\n"));
  98. return FALSE;
  99. }
  100. //
  101. // Allow BindAdapter to proceed.
  102. //
  103. NdisSetEvent(&DeviceExtension->NdisEvent);
  104. return TRUE;
  105. }
  106. VOID
  107. GetRegistryParameters(
  108. IN PUNICODE_STRING RegistryPath
  109. )
  110. /*++
  111. Routine Description:
  112. This routine stores the configuration information for this device.
  113. Arguments:
  114. RegistryPath - Pointer to the null-terminated Unicode name of the
  115. registry path for this driver.
  116. Return Value:
  117. None. As a side-effect, sets DeviceExtension->EventDataQueuLength field
  118. --*/
  119. {
  120. NDIS_STRING ProtocolName;
  121. ULONG ulDefaultData = 0;
  122. ULONG ulMaxRate = -1;
  123. NTSTATUS Status = STATUS_SUCCESS;
  124. HANDLE hHandle, hParamsKeyHandle = NULL;
  125. NDIS_STRING KeyName;
  126. USHORT DefaultMediaType[] = L"Unspecfied ADSL Media";
  127. NdisInitUnicodeString(&ProtocolName, L"NDProxy");
  128. NdisInitUnicodeString(&KeyName, L"Parameters");
  129. //
  130. // Open the Proxy's key in the registry.
  131. //
  132. NdisOpenProtocolConfiguration(&Status,
  133. &hHandle,
  134. &ProtocolName);
  135. if (Status != NDIS_STATUS_SUCCESS) {
  136. Status = STATUS_UNSUCCESSFUL;
  137. } else {
  138. NdisOpenConfigurationKeyByName(&Status,
  139. hHandle, //"HKLM/CCS/NDProxy"
  140. &KeyName, //"Parameters"
  141. &hParamsKeyHandle);
  142. if (NT_SUCCESS(Status)) {
  143. ULONG ulResult;
  144. PNDIS_CONFIGURATION_PARAMETER pNdisConfigurationParameter;
  145. //
  146. // Gather all of the "user specified" information from
  147. // the registry.
  148. //
  149. Status = GetConfigDword (hParamsKeyHandle, L"TxRate", &DeviceExtension->ADSLTxRate, ulDefaultData, ulMaxRate);
  150. if (!NT_SUCCESS(Status)) {
  151. PXDEBUGP(PXD_LOUD, PXM_INIT, (
  152. "GetRegistryParameters: NdisReadConfiguration failed, err=%x\n",
  153. Status
  154. ));
  155. } else {
  156. DeviceExtension->RegistryFlags |= ADSL_TX_RATE_FROM_REG;
  157. }
  158. //
  159. // Next
  160. //
  161. Status = GetConfigDword (hParamsKeyHandle, L"RxRate", &DeviceExtension->ADSLRxRate, ulDefaultData, ulMaxRate);
  162. if (!NT_SUCCESS(Status)) {
  163. PXDEBUGP(PXD_LOUD, PXM_INIT, (
  164. "GetRegistryParameters: NdisReadConfiguration failed, err=%x\n",
  165. Status));
  166. } else {
  167. DeviceExtension->RegistryFlags |= ADSL_RX_RATE_FROM_REG;
  168. }
  169. //
  170. // Dump values
  171. //
  172. PXDEBUGP (PXD_LOUD, PXM_INIT, (
  173. "GetRegistryParameters: ADSLTxRate = %x\n",
  174. DeviceExtension->ADSLTxRate
  175. ));
  176. PXDEBUGP (PXD_LOUD, PXM_INIT, (
  177. "GetRegistryParameters: ADSLRxRate = %x\n",
  178. DeviceExtension->ADSLRxRate
  179. ));
  180. }
  181. }
  182. }
  183. NDIS_STATUS
  184. GetConfigDword(
  185. NDIS_HANDLE Handle,
  186. PWCHAR ParameterName,
  187. PULONG Destination,
  188. ULONG MinValue,
  189. ULONG MaxValue
  190. )
  191. /*++
  192. Routine Description
  193. A routine to read a ulong from the registry. We're given a handle,
  194. the name of the key, and where to put it.
  195. Arguments
  196. Handle - Open handle to the parent key.
  197. ParameterName - Pointer to name of the parameter.
  198. Destination - Where to put the dword.
  199. MinValue - Minimum value of the dword allowed.
  200. MaxValue - Maximum allowable value.
  201. Return Value:
  202. NDIS_STATUS_SUCCESS if we read in the value, error code otherwise.
  203. --*/
  204. {
  205. NDIS_STATUS Status;
  206. ULONG Value;
  207. NDIS_STRING ParameterNameString;
  208. PNDIS_CONFIGURATION_PARAMETER pNdisConfigurationParameter;
  209. NdisInitUnicodeString(
  210. &ParameterNameString,
  211. ParameterName
  212. );
  213. NdisReadConfiguration(
  214. &Status,
  215. &pNdisConfigurationParameter,
  216. Handle,
  217. &ParameterNameString,
  218. NdisParameterInteger
  219. );
  220. if (Status == NDIS_STATUS_SUCCESS)
  221. {
  222. Value = pNdisConfigurationParameter->ParameterData.IntegerData;
  223. if ((Value >= (ULONG)MinValue) && (Value <= (ULONG)MaxValue))
  224. {
  225. *Destination = (ULONG)Value;
  226. }
  227. }
  228. return (Status);
  229. }