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.

741 lines
14 KiB

  1. /*++
  2. Copyright(c) 1992 Microsoft Corporation
  3. Module Name:
  4. wrapper.c
  5. Abstract:
  6. This file contains wrapper for all function calls that call outside atmepvc.sys.
  7. Author:
  8. ADube , 03/31/00
  9. Environment:
  10. Revision History:
  11. --*/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. VOID
  15. epvcOpenProtocolConfiguration(
  16. OUT PNDIS_STATUS Status,
  17. OUT PNDIS_HANDLE ConfigurationHandle,
  18. IN PNDIS_STRING ProtocolSection,
  19. PRM_STACK_RECORD pSR
  20. )
  21. {
  22. TRACE (TL_T, TM_Pt, (" == NdisOpenProtocolConfiguration") );
  23. ASSERT (KeGetCurrentIrql() == PASSIVE_LEVEL);
  24. NdisOpenProtocolConfiguration(Status,
  25. ConfigurationHandle,
  26. ProtocolSection);
  27. }
  28. VOID
  29. epvcOpenConfigurationKeyByName(
  30. OUT PNDIS_STATUS Status,
  31. IN NDIS_HANDLE ConfigurationHandle,
  32. IN PNDIS_STRING SubKeyName,
  33. OUT PNDIS_HANDLE SubKeyHandle,
  34. PRM_STACK_RECORD pSR
  35. )
  36. {
  37. TRACE (TL_T, TM_Pt, (" == NdisOpenConfigurationKeyByName") );
  38. ASSERT (KeGetCurrentIrql() == PASSIVE_LEVEL);
  39. NdisOpenConfigurationKeyByName(
  40. Status,
  41. ConfigurationHandle,
  42. SubKeyName,
  43. SubKeyHandle
  44. );
  45. }
  46. VOID
  47. epvcOpenConfigurationKeyByIndex(
  48. OUT PNDIS_STATUS Status,
  49. IN NDIS_HANDLE ConfigurationHandle,
  50. IN ULONG Index,
  51. OUT PNDIS_STRING KeyName,
  52. OUT PNDIS_HANDLE KeyHandle,
  53. PRM_STACK_RECORD pSR
  54. )
  55. {
  56. TRACE (TL_T, TM_Pt, (" == NdisOpenConfigurationKeyByIndex") );
  57. ASSERT (KeGetCurrentIrql() == PASSIVE_LEVEL);
  58. NdisOpenConfigurationKeyByIndex(
  59. Status,
  60. ConfigurationHandle,
  61. Index,
  62. KeyName,
  63. KeyHandle);
  64. }
  65. VOID
  66. epvcOpenAdapter(
  67. OUT PNDIS_STATUS Status,
  68. OUT PNDIS_STATUS OpenErrorStatus,
  69. OUT PNDIS_HANDLE NdisBindingHandle,
  70. OUT PUINT SelectedMediumIndex,
  71. IN PNDIS_MEDIUM MediumArray,
  72. IN UINT MediumArraySize,
  73. IN NDIS_HANDLE NdisProtocolHandle,
  74. IN NDIS_HANDLE ProtocolBindingContext,
  75. IN PNDIS_STRING AdapterName,
  76. IN UINT OpenOptions,
  77. IN PSTRING AddressingInformation OPTIONAL,
  78. PRM_STACK_RECORD pSR
  79. )
  80. {
  81. TRACE (TL_T, TM_Pt, (" == epvcOpenAdapter") );
  82. ASSERT (KeGetCurrentIrql() == PASSIVE_LEVEL);
  83. NdisOpenAdapter(
  84. Status,
  85. OpenErrorStatus,
  86. NdisBindingHandle,
  87. SelectedMediumIndex,
  88. MediumArray,
  89. MediumArraySize,
  90. NdisProtocolHandle,
  91. ProtocolBindingContext,
  92. AdapterName,
  93. OpenOptions,
  94. AddressingInformation OPTIONAL
  95. );
  96. }
  97. VOID
  98. epvcCloseAdapter(
  99. OUT PNDIS_STATUS Status,
  100. IN NDIS_HANDLE NdisBindingHandle,
  101. PRM_STACK_RECORD pSR
  102. )
  103. {
  104. ASSERT (KeGetCurrentIrql() == PASSIVE_LEVEL);
  105. TRACE (TL_T, TM_Pt, (" == epvcCloseAdapter") );
  106. NdisCloseAdapter(
  107. Status,
  108. NdisBindingHandle
  109. );
  110. }
  111. NDIS_STATUS
  112. epvcClOpenAddressFamily(
  113. IN NDIS_HANDLE NdisBindingHandle,
  114. IN PCO_ADDRESS_FAMILY AddressFamily,
  115. IN NDIS_HANDLE ProtocolAfContext,
  116. IN PNDIS_CLIENT_CHARACTERISTICS ClCharacteristics,
  117. IN UINT SizeOfClCharacteristics,
  118. OUT PNDIS_HANDLE NdisAfHandle
  119. )
  120. {
  121. TRACE (TL_T, TM_Pt, (" == epvcClOpenAddressFamily") );
  122. ASSERT (KeGetCurrentIrql() == PASSIVE_LEVEL);
  123. return NdisClOpenAddressFamily(
  124. NdisBindingHandle,
  125. AddressFamily,
  126. ProtocolAfContext,
  127. ClCharacteristics,
  128. SizeOfClCharacteristics,
  129. NdisAfHandle
  130. );
  131. }
  132. NDIS_STATUS
  133. epvcCoCreateVc(
  134. IN NDIS_HANDLE NdisBindingHandle,
  135. IN NDIS_HANDLE NdisAfHandle OPTIONAL, // For CM signalling VCs
  136. IN NDIS_HANDLE ProtocolVcContext,
  137. IN OUT PNDIS_HANDLE NdisVcHandle
  138. )
  139. {
  140. TRACE (TL_T, TM_Pt, (" == epvcCoCreateVc") );
  141. //ASSERT (KeGetCurrentIrql() == PASSIVE_LEVEL);
  142. return NdisCoCreateVc(NdisBindingHandle,
  143. NdisAfHandle OPTIONAL, // For CM signalling VCs
  144. ProtocolVcContext,
  145. NdisVcHandle
  146. );
  147. }
  148. NDIS_STATUS
  149. epvcClCloseCall(
  150. IN NDIS_HANDLE NdisVcHandle
  151. )
  152. {
  153. TRACE (TL_T, TM_Pt, (" == EpvcClCloseCall") );
  154. ASSERT (KeGetCurrentIrql() == PASSIVE_LEVEL);
  155. return NdisClCloseCall( NdisVcHandle,
  156. NULL,
  157. NULL,
  158. 0);
  159. }
  160. NDIS_STATUS
  161. epvcClMakeCall(
  162. IN NDIS_HANDLE NdisVcHandle,
  163. IN OUT PCO_CALL_PARAMETERS CallParameters,
  164. IN NDIS_HANDLE ProtocolPartyContext OPTIONAL,
  165. OUT PNDIS_HANDLE NdisPartyHandle OPTIONAL
  166. )
  167. {
  168. TRACE (TL_T, TM_Pt, (" == EpvcClMakeCall") );
  169. ASSERT (NdisVcHandle != NULL);
  170. //ASSERT (KeGetCurrentIrql() == PASSIVE_LEVEL);
  171. return NdisClMakeCall( NdisVcHandle,
  172. CallParameters,
  173. ProtocolPartyContext OPTIONAL,
  174. NdisPartyHandle OPTIONAL
  175. );
  176. }
  177. NDIS_STATUS
  178. epvcCoDeleteVc(
  179. IN NDIS_HANDLE NdisVcHandle
  180. )
  181. {
  182. TRACE (TL_T, TM_Pt, (" == epvcCoDeleteVc") );
  183. ASSERT (NdisVcHandle!= NULL);
  184. ASSERT (KeGetCurrentIrql() == PASSIVE_LEVEL);
  185. return NdisCoDeleteVc(NdisVcHandle);
  186. }
  187. NDIS_STATUS
  188. epvcAllocateMemoryWithTag(
  189. OUT PVOID * VirtualAddress,
  190. IN UINT Length,
  191. IN ULONG Tag
  192. )
  193. {
  194. return NdisAllocateMemoryWithTag(
  195. VirtualAddress,
  196. Length,
  197. Tag
  198. );
  199. }
  200. VOID
  201. epvcFreeMemory(
  202. IN PVOID VirtualAddress,
  203. IN UINT Length,
  204. IN UINT MemoryFlags
  205. )
  206. {
  207. NdisFreeMemory( VirtualAddress,
  208. Length,
  209. MemoryFlags
  210. );
  211. }
  212. VOID
  213. epvcInitializeEvent(
  214. IN PNDIS_EVENT Event
  215. )
  216. {
  217. ASSERT (KeGetCurrentIrql() == PASSIVE_LEVEL);
  218. NdisInitializeEvent(Event);
  219. }
  220. BOOLEAN
  221. epvcWaitEvent(
  222. IN PNDIS_EVENT Event,
  223. IN UINT msToWait
  224. )
  225. {
  226. return (NdisWaitEvent(Event,msToWait));
  227. }
  228. VOID
  229. epvcSetEvent(
  230. IN PNDIS_EVENT Event
  231. )
  232. {
  233. NdisSetEvent(Event);
  234. }
  235. VOID
  236. epvcResetEvent(
  237. IN PNDIS_EVENT Event
  238. )
  239. {
  240. NdisResetEvent(Event);
  241. }
  242. VOID
  243. epvcCoRequestComplete(
  244. IN NDIS_STATUS Status,
  245. IN NDIS_HANDLE NdisAfHandle,
  246. IN NDIS_HANDLE NdisVcHandle OPTIONAL,
  247. IN NDIS_HANDLE NdisPartyHandle OPTIONAL,
  248. IN PNDIS_REQUEST NdisRequest
  249. )
  250. {
  251. TRACE (TL_T, TM_Cl, ("-- epvcCoRequestComplete"));
  252. NdisCoRequestComplete(Status,
  253. NdisAfHandle,
  254. NdisVcHandle OPTIONAL,
  255. NdisPartyHandle OPTIONAL,
  256. NdisRequest
  257. );
  258. }
  259. VOID
  260. epvcEnumerateObjectsInGroup (
  261. PRM_GROUP pGroup,
  262. PFN_RM_GROUP_ENUMERATOR pfnEnumerator,
  263. PVOID pvContext,
  264. PRM_STACK_RECORD pSR
  265. )
  266. {
  267. RmWeakEnumerateObjectsInGroup(pGroup,
  268. pfnEnumerator,
  269. pvContext,
  270. pSR
  271. );
  272. return;
  273. }
  274. VOID
  275. epvcAllocatePacketPool(
  276. OUT PNDIS_STATUS Status,
  277. OUT PEPVC_PACKET_POOL pPktPool,
  278. IN UINT NumberOfDescriptors,
  279. IN UINT NumberOfOverflowDescriptors,
  280. IN UINT ProtocolReservedLength
  281. )
  282. {
  283. EPVC_ZEROSTRUCT(pPktPool);
  284. NdisAllocatePacketPoolEx(
  285. Status,
  286. &pPktPool->Handle,
  287. NumberOfDescriptors,
  288. NumberOfOverflowDescriptors,
  289. ProtocolReservedLength
  290. );
  291. }
  292. VOID
  293. epvcFreePacketPool(
  294. IN PEPVC_PACKET_POOL pPktPool
  295. )
  296. {
  297. //
  298. // Callable at PASSIVE ONLY
  299. //
  300. UINT i = 0;
  301. ASSERT (pPktPool->Handle != NULL);
  302. while (NdisPacketPoolUsage(pPktPool->Handle) != 0)
  303. {
  304. if (i >0)
  305. {
  306. TRACE (TL_I, TM_Mp, ("Looping in epvcFreePacketPool"));
  307. }
  308. NdisMSleep (10000); // 10 ms
  309. i++;
  310. }
  311. NdisFreePacketPool(pPktPool->Handle );
  312. //
  313. // Zero out the Handle,
  314. //
  315. EPVC_ZEROSTRUCT (pPktPool);
  316. }
  317. VOID
  318. epvcAllocatePacket(
  319. OUT PNDIS_STATUS Status,
  320. OUT PNDIS_PACKET * Packet,
  321. IN PEPVC_PACKET_POOL pPktPool
  322. )
  323. {
  324. NdisAllocatePacket(Status,Packet,pPktPool->Handle);
  325. if (*Status == NDIS_STATUS_SUCCESS)
  326. {
  327. NdisInterlockedIncrement (&pPktPool->AllocatedPackets);
  328. }
  329. else
  330. {
  331. Packet = NULL;
  332. }
  333. }
  334. VOID
  335. epvcFreePacket (
  336. IN PNDIS_PACKET pPkt,
  337. IN PEPVC_PACKET_POOL pPool
  338. )
  339. {
  340. NdisInterlockedDecrement (&pPool->AllocatedPackets);
  341. NdisFreePacket(pPkt);
  342. }
  343. VOID
  344. epvcDprFreePacket(
  345. IN PNDIS_PACKET Packet,
  346. IN PEPVC_PACKET_POOL pPool
  347. )
  348. {
  349. NdisInterlockedDecrement (&pPool->AllocatedPackets);
  350. NdisDprFreePacket(Packet);
  351. }
  352. VOID
  353. epvcDprAllocatePacket(
  354. OUT PNDIS_STATUS Status,
  355. OUT PNDIS_PACKET * Packet,
  356. IN PEPVC_PACKET_POOL pPktPool
  357. )
  358. {
  359. NdisDprAllocatePacket( Status,
  360. Packet,
  361. pPktPool->Handle );
  362. if (*Status == NDIS_STATUS_SUCCESS)
  363. {
  364. NdisInterlockedIncrement (&pPktPool->AllocatedPackets);
  365. }
  366. else
  367. {
  368. Packet = NULL;
  369. }
  370. }
  371. NDIS_STATUS
  372. epvcClCloseAddressFamily(
  373. IN NDIS_HANDLE NdisAfHandle
  374. )
  375. {
  376. TRACE (TL_V, TM_Pt, ("epvcClCloseAddressFamily "));
  377. return NdisClCloseAddressFamily(NdisAfHandle);
  378. }
  379. VOID
  380. epvcMIndicateStatus(
  381. IN PEPVC_I_MINIPORT pMiniport ,
  382. IN NDIS_STATUS GeneralStatus,
  383. IN PVOID StatusBuffer,
  384. IN UINT StatusBufferSize
  385. )
  386. {
  387. if (CanMiniportIndicate(pMiniport) == FALSE)
  388. {
  389. return;
  390. }
  391. NdisMIndicateStatus(pMiniport->ndis.MiniportAdapterHandle,
  392. GeneralStatus,
  393. StatusBuffer,
  394. StatusBufferSize
  395. );
  396. }
  397. VOID
  398. epvcMIndicateReceivePacket(
  399. IN PEPVC_I_MINIPORT pMiniport,
  400. IN PPNDIS_PACKET ReceivedPackets,
  401. IN UINT NumberOfPackets
  402. )
  403. {
  404. NdisMIndicateReceivePacket(pMiniport->ndis.MiniportAdapterHandle,
  405. ReceivedPackets,
  406. NumberOfPackets );
  407. }
  408. VOID
  409. epvcFreeBuffer(
  410. IN PNDIS_BUFFER Buffer
  411. )
  412. {
  413. NdisFreeBuffer(Buffer);
  414. }
  415. VOID
  416. epvcAllocateBuffer(
  417. OUT PNDIS_STATUS Status,
  418. OUT PNDIS_BUFFER * Buffer,
  419. IN NDIS_HANDLE PoolHandle,
  420. IN PVOID VirtualAddress,
  421. IN UINT Length
  422. )
  423. {
  424. NdisAllocateBuffer(Status,
  425. Buffer,
  426. PoolHandle,
  427. VirtualAddress,
  428. Length
  429. );
  430. }
  431. VOID
  432. epvcMSendComplete(
  433. IN PEPVC_I_MINIPORT pMiniport,
  434. IN PNDIS_PACKET pPkt,
  435. IN NDIS_STATUS Status
  436. )
  437. {
  438. epvcValidatePacket (pPkt);
  439. NdisMSendComplete(pMiniport->ndis.MiniportAdapterHandle,
  440. pPkt,
  441. Status);
  442. }
  443. VOID
  444. epvcReturnPacketToNdis(
  445. IN PEPVC_I_MINIPORT pMiniport,
  446. IN PNDIS_PACKET pPacket,
  447. IN PRM_STACK_RECORD pSR
  448. )
  449. {
  450. epvcValidatePacket (pPacket);
  451. NdisReturnPackets(&pPacket, 1 );
  452. }
  453. VOID
  454. epvcInitializeWorkItem(
  455. IN PRM_OBJECT_HEADER pObj,
  456. IN PNDIS_WORK_ITEM WorkItem,
  457. IN NDIS_PROC Routine,
  458. IN PVOID Context,
  459. IN PRM_STACK_RECORD pSR
  460. )
  461. {
  462. NdisInitializeWorkItem(WorkItem,
  463. Routine,
  464. Context);
  465. NdisScheduleWorkItem(WorkItem);
  466. }
  467. VOID
  468. epvcCoSendPackets(
  469. IN NDIS_HANDLE NdisVcHandle,
  470. IN PPNDIS_PACKET PacketArray,
  471. IN UINT NumberOfPackets
  472. )
  473. {
  474. ASSERT (NumberOfPackets == 1);
  475. epvcValidatePacket (*PacketArray);
  476. NdisCoSendPackets(NdisVcHandle,PacketArray,NumberOfPackets);
  477. }
  478. VOID
  479. epvcQueryPacket(
  480. IN PNDIS_PACKET _Packet,
  481. OUT PUINT _PhysicalBufferCount OPTIONAL,
  482. OUT PUINT _BufferCount OPTIONAL,
  483. OUT PNDIS_BUFFER * _FirstBuffer OPTIONAL,
  484. OUT PUINT _TotalPacketLength OPTIONAL
  485. )
  486. {
  487. NdisQueryPacket(
  488. _Packet,
  489. _PhysicalBufferCount OPTIONAL,
  490. _BufferCount OPTIONAL,
  491. _FirstBuffer OPTIONAL,
  492. _TotalPacketLength OPTIONAL
  493. );
  494. }
  495. VOID
  496. epvcIMDeInitializeDeviceInstance (
  497. IN PEPVC_I_MINIPORT pMiniport
  498. )
  499. {
  500. TRACE (TL_I, TM_Pt, (" NdisIMDeInitializeDeviceInstance pMiniport %p", pMiniport) );
  501. NdisIMDeInitializeDeviceInstance(pMiniport->ndis.MiniportAdapterHandle);
  502. }
  503. NDIS_STATUS
  504. epvcIMCancelInitializeDeviceInstance (
  505. IN PEPVC_I_MINIPORT pMiniport
  506. )
  507. {
  508. NDIS_STATUS Status;
  509. TRACE (TL_I, TM_Pt, (" NdisIMCancelInitializeDeviceInstance pMiniport %p", pMiniport) );
  510. Status = NdisIMCancelInitializeDeviceInstance (EpvcGlobals.driver.DriverHandle,&pMiniport->ndis.DeviceName);
  511. TRACE (TL_I, TM_Pt, (" Status %x\n", Status) );
  512. return Status;
  513. }