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.

1122 lines
24 KiB

  1. /*++
  2. Copyright (c) 1990-1998 Microsoft Corporation, All Rights Reserved.
  3. Module Name:
  4. adapter.c
  5. Abstract:
  6. This contains routines related to the adapter (Initialize,
  7. Deinitialize, bind, unbind, open, close etc.)
  8. Author:
  9. Anil Francis Thomas (10/98)
  10. Environment:
  11. Kernel
  12. Revision History:
  13. --*/
  14. #include "precomp.h"
  15. #pragma hdrstop
  16. #define MODULE_ID MODULE_ADAPTER
  17. NDIS_STATUS
  18. AtmSmAllocateAdapter(
  19. PATMSM_ADAPTER *ppAdapter
  20. );
  21. VOID
  22. AtmSmDeallocateAdapter(
  23. PATMSM_ADAPTER pAdapt
  24. );
  25. VOID
  26. AtmSmOpenAdapterComplete(
  27. IN NDIS_HANDLE ProtocolBindingContext,
  28. IN NDIS_STATUS Status,
  29. IN NDIS_STATUS OpenStatus
  30. );
  31. VOID
  32. AtmSmCloseAdapterComplete(
  33. IN NDIS_HANDLE ProtocolBindingContext,
  34. IN NDIS_STATUS Status
  35. );
  36. VOID
  37. AtmSmBindAdapter(
  38. OUT PNDIS_STATUS pStatus,
  39. IN NDIS_HANDLE BindContext,
  40. IN PNDIS_STRING pDeviceName,
  41. IN PVOID SystemSpecific1,
  42. IN PVOID SystemSpecific2
  43. )
  44. /*++
  45. Routine Description:
  46. This is called by NDIS when it has an adapter for which there is a
  47. binding to the AtmSm client.
  48. We first allocate an Adapter structure. Then we open our configuration
  49. section for this adapter and save the handle in the Adapter structure.
  50. Finally, we open the adapter.
  51. We don't do anything more for this adapter until NDIS notifies us of
  52. the presence of a Call manager (via our AfRegisterNotify handler).
  53. Arguments:
  54. pStatus - Place to return status of this call
  55. BindContext - Not used, because we don't pend this call
  56. pDeviceName - The name of the adapter we are requested to bind to
  57. SystemSpecific1 - Opaque to us; to be used to access configuration info
  58. SystemSpecific2 - Opaque to us; not used.
  59. Return Value:
  60. None. We set *pStatus to an error code if something goes wrong before we
  61. call NdisOpenAdapter, otherwise NDIS_STATUS_PENDING.
  62. --*/
  63. {
  64. PATMSM_ADAPTER pAdapt = NULL; // Pointer to new adapter structure
  65. NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
  66. NDIS_STATUS OpenStatus;
  67. UINT MediumIndex;
  68. NDIS_MEDIUM MediumArray[] = {NdisMediumAtm};
  69. ULONG Length;
  70. TraceIn(AtmSmBindAdapter);
  71. DbgLoud(("BindAdapter: Context 0x%x, pDevName 0x%x, SS1 0x%x, SS2 0x%x\n",
  72. BindContext, pDeviceName, SystemSpecific1, SystemSpecific2));
  73. do {
  74. //
  75. // Allocate and initialize the Adapter structure.
  76. //
  77. Status = AtmSmAllocateAdapter(&pAdapt);
  78. if(NDIS_STATUS_SUCCESS != Status)
  79. break;
  80. pAdapt->NdisBindContext = BindContext;
  81. // Status = AtmSmReadAdapterConfiguration(pAdapt);
  82. if(NDIS_STATUS_SUCCESS != Status)
  83. break;
  84. //
  85. // Now open the adapter below and complete the initialization
  86. //
  87. NdisOpenAdapter(&Status,
  88. &OpenStatus,
  89. &pAdapt->NdisBindingHandle,
  90. &MediumIndex,
  91. MediumArray,
  92. 1,
  93. AtmSmGlobal.ProtHandle,
  94. pAdapt,
  95. pDeviceName,
  96. 0,
  97. NULL);
  98. if(NDIS_STATUS_PENDING != Status){
  99. AtmSmOpenAdapterComplete((NDIS_HANDLE)pAdapt,
  100. Status,
  101. OpenStatus);
  102. }
  103. //
  104. // Return pending since we are bound to call (or have already
  105. // called) NdisCompleteBindAdapter.
  106. //
  107. Status = NDIS_STATUS_PENDING;
  108. pAdapt->Medium = MediumArray[MediumIndex];
  109. } while (FALSE);
  110. if ((NDIS_STATUS_SUCCESS != Status) &&
  111. (NDIS_STATUS_PENDING != Status)) {
  112. DbgErr(("Failed to Open Adapter. Error - 0x%X \n", Status));
  113. if (NULL != pAdapt){
  114. AtmSmDereferenceAdapter(pAdapt);
  115. }
  116. }
  117. TraceOut(AtmSmBindAdapter);
  118. *pStatus = Status;
  119. }
  120. VOID
  121. AtmSmOpenAdapterComplete(
  122. IN NDIS_HANDLE ProtocolBindingContext,
  123. IN NDIS_STATUS Status,
  124. IN NDIS_STATUS OpenStatus
  125. )
  126. /*++
  127. Routine Description:
  128. Upcall from NDIS to signal completion of a NdisOpenAdapter() call.
  129. Or we called it from BindAdapter to complete the call.
  130. Arguments:
  131. ProtocolBindingContext Pointer to the pAdapt
  132. Status Status of NdisOpenAdapter
  133. OpenStatus OpenAdapter's code
  134. Return Value:
  135. --*/
  136. {
  137. PATMSM_ADAPTER pAdapt = (PATMSM_ADAPTER)ProtocolBindingContext;
  138. TraceIn(AtmSmOpenAdapterComplete);
  139. // First complete the pending bind call.
  140. NdisCompleteBindAdapter(pAdapt->NdisBindContext,
  141. Status,
  142. OpenStatus);
  143. pAdapt->NdisBindContext = NULL; // we don't need the context anymore
  144. if (NDIS_STATUS_SUCCESS != Status)
  145. {
  146. //
  147. // NdisOpenAdapter() failed - log an error and exit
  148. //
  149. DbgErr(("Failed to open adapter. Status - 0x%X \n", Status));
  150. AtmSmCloseAdapterComplete(pAdapt, Status);
  151. }
  152. else
  153. {
  154. pAdapt->ulFlags |= ADAPT_OPENED;
  155. AtmSmQueryAdapter(pAdapt);
  156. NdisQueryAdapterInstanceName(
  157. &pAdapt->BoundToAdapterName,
  158. pAdapt->NdisBindingHandle);
  159. }
  160. TraceOut(AtmSmOpenAdapterComplete);
  161. }
  162. VOID
  163. AtmSmUnbindAdapter(
  164. OUT PNDIS_STATUS pStatus,
  165. IN NDIS_HANDLE ProtocolBindingContext,
  166. IN NDIS_HANDLE UnbindContext
  167. )
  168. /*++
  169. Routine Description:
  170. This routine is called by NDIS when it wants us to unbind
  171. from an adapter. Or, this may be called from within our Unload
  172. handler. We undo the sequence of operations we performed
  173. in our BindAdapter handler.
  174. Arguments:
  175. pStatus - Place to return status of this operation
  176. ProtocolBindingContext - Our context for this adapter binding, which
  177. is a pointer to an ATMSM Adapter structure.
  178. UnbindContext - This is NULL if this routine is called from
  179. within our Unload handler. Otherwise (i.e.
  180. NDIS called us), we retain this for later use
  181. when calling NdisCompleteUnbindAdapter.
  182. Return Value:
  183. NDIS_STATUS_PENDING or NDIS_STATUS_SUCCESS.
  184. --*/
  185. {
  186. PATMSM_ADAPTER pAdapt = (PATMSM_ADAPTER)ProtocolBindingContext;
  187. NDIS_EVENT CleanupEvent; // Used to wait for Close Adapter
  188. #if DBG
  189. KIRQL EntryIrql, ExitIrql;
  190. #endif
  191. TraceIn(AtmSmUnBindAdapter);
  192. ATMSM_GET_ENTRY_IRQL(EntryIrql);
  193. DbgInfo(("UnbindAdapter: pAdapter 0x%x, UnbindContext 0x%X\n",
  194. pAdapt, UnbindContext));
  195. NdisInitializeEvent(&CleanupEvent);
  196. pAdapt->pCleanupEvent = &CleanupEvent;
  197. //
  198. // Save the unbind context for a later call to
  199. // NdisCompleteUnbindAdapter.
  200. pAdapt->UnbindContext = UnbindContext;
  201. // ask the adapter to shutdown
  202. AtmSmShutdownAdapter(pAdapt);
  203. //
  204. // Wait for the cleanup to complete
  205. //
  206. NdisWaitEvent(&CleanupEvent, 0);
  207. //
  208. // Return pending since we always call NdisCompleteUnbindAdapter.
  209. //
  210. *pStatus = NDIS_STATUS_PENDING;
  211. ATMSM_CHECK_EXIT_IRQL(EntryIrql, ExitIrql);
  212. TraceOut(AtmSmUnBindAdapter);
  213. return;
  214. }
  215. NDIS_STATUS
  216. AtmSmShutdownAdapter(
  217. PATMSM_ADAPTER pAdapt
  218. )
  219. /*++
  220. Routine Description:
  221. This routine is called to Shutdown an adapter.
  222. Arguments:
  223. pAdapt - Pointer to the adapter
  224. Return Value:
  225. NDIS_STATUS_PENDING or NDIS_STATUS_SUCCESS
  226. --*/
  227. {
  228. NDIS_STATUS Status;
  229. #if DBG
  230. KIRQL EntryIrql, ExitIrql;
  231. #endif
  232. TraceIn(AtmSmShutdownAdapter);
  233. ATMSM_GET_ENTRY_IRQL(EntryIrql);
  234. ACQUIRE_ADAPTER_GEN_LOCK(pAdapt);
  235. pAdapt->ulFlags |= ADAPT_SHUTTING_DOWN;
  236. //
  237. // Degister SAP
  238. //
  239. if(pAdapt->ulFlags & ADAPT_SAP_REGISTERED){
  240. pAdapt->ulFlags &= ~ADAPT_SAP_REGISTERED;
  241. RELEASE_ADAPTER_GEN_LOCK(pAdapt);
  242. Status = NdisClDeregisterSap(pAdapt->NdisSapHandle);
  243. if (NDIS_STATUS_PENDING != Status) {
  244. AtmSmDeregisterSapComplete(Status, pAdapt);
  245. }
  246. ACQUIRE_ADAPTER_GEN_LOCK(pAdapt);
  247. }
  248. //
  249. // Remove all VC's.
  250. //
  251. while (!IsListEmpty(&pAdapt->ActiveVcHead)) {
  252. PATMSM_VC pVc;
  253. pVc = CONTAINING_RECORD(pAdapt->ActiveVcHead.Flink, ATMSM_VC, List);
  254. RemoveEntryList(&pVc->List);
  255. InsertHeadList(&pAdapt->InactiveVcHead, &pVc->List);
  256. RELEASE_ADAPTER_GEN_LOCK(pAdapt);
  257. // this will result in it getting removed
  258. AtmSmDisconnectVc(pVc);
  259. ACQUIRE_ADAPTER_GEN_LOCK(pAdapt);
  260. }
  261. //
  262. // Close Address Family
  263. //
  264. if(pAdapt->ulFlags & ADAPT_AF_OPENED){
  265. pAdapt->ulFlags &= ~ADAPT_AF_OPENED;
  266. RELEASE_ADAPTER_GEN_LOCK(pAdapt);
  267. Status = NdisClCloseAddressFamily(pAdapt->NdisAfHandle);
  268. if (NDIS_STATUS_PENDING != Status){
  269. AtmSmCloseAfComplete(Status, pAdapt);
  270. }
  271. ACQUIRE_ADAPTER_GEN_LOCK(pAdapt);
  272. }
  273. if(pAdapt->pRecvIrp){
  274. PIRP pRecvIrp = pAdapt->pRecvIrp;
  275. // there is an Irp pending, complete it
  276. pRecvIrp->IoStatus.Status = STATUS_CANCELLED;
  277. pRecvIrp->Cancel = TRUE;
  278. pRecvIrp->IoStatus.Information = 0;
  279. IoCompleteRequest(pRecvIrp, IO_NETWORK_INCREMENT);
  280. pAdapt->pRecvIrp = NULL;
  281. }
  282. pAdapt->fAdapterOpenedForRecv = FALSE;
  283. //
  284. // Set the interface to closing
  285. //
  286. ASSERT ((pAdapt->ulFlags & ADAPT_CLOSING) == 0);
  287. pAdapt->ulFlags |= ADAPT_CLOSING;
  288. RELEASE_ADAPTER_GEN_LOCK(pAdapt);
  289. //
  290. // Close the adapter
  291. //
  292. NdisCloseAdapter(
  293. &Status,
  294. pAdapt->NdisBindingHandle
  295. );
  296. if (Status != NDIS_STATUS_PENDING) {
  297. AtmSmCloseAdapterComplete(
  298. (NDIS_HANDLE) pAdapt,
  299. Status
  300. );
  301. }
  302. ATMSM_CHECK_EXIT_IRQL(EntryIrql, ExitIrql);
  303. TraceOut(AtmSmShutdownAdapter);
  304. return Status;
  305. }
  306. VOID
  307. AtmSmCloseAdapterComplete(
  308. IN NDIS_HANDLE ProtocolBindingContext,
  309. IN NDIS_STATUS Status
  310. )
  311. /*++
  312. Routine Description:
  313. Called by NDIS or us to complete CloseAdapter call.
  314. Arguments:
  315. ProtocolBindingContext - Pointer to the adapter
  316. Status - Status of our close adapter
  317. Return Value:
  318. --*/
  319. {
  320. PATMSM_ADAPTER pAdapt = (PATMSM_ADAPTER)ProtocolBindingContext;
  321. NDIS_HANDLE UnbindContext = pAdapt->UnbindContext;
  322. #if DBG
  323. KIRQL EntryIrql, ExitIrql;
  324. #endif
  325. TraceIn(AtmSmCloseAdapterComplete);
  326. ATMSM_GET_ENTRY_IRQL(EntryIrql);
  327. pAdapt->NdisBindingHandle = NULL;
  328. //
  329. // Finally dereference it
  330. //
  331. AtmSmDereferenceAdapter(pAdapt);
  332. if (UnbindContext != (NDIS_HANDLE)NULL) {
  333. NdisCompleteUnbindAdapter(
  334. UnbindContext,
  335. NDIS_STATUS_SUCCESS
  336. );
  337. }
  338. ATMSM_CHECK_EXIT_IRQL(EntryIrql, ExitIrql);
  339. TraceOut(AtmSmCloseAdapterComplete);
  340. }
  341. NDIS_STATUS
  342. AtmSmAllocateAdapter(
  343. PATMSM_ADAPTER *ppAdapter
  344. )
  345. /*++
  346. Routine Description:
  347. Called for initializing an Adapter structure.
  348. Arguments:
  349. ppAdapter - newly allocated adapter
  350. Return Value:
  351. NDIS_STATUS_SUCCESS - If successful
  352. Others - failure
  353. --*/
  354. {
  355. PATMSM_ADAPTER pAdapt;
  356. NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
  357. TraceIn(AtmSmAllocateAdapter);
  358. do {
  359. AtmSmAllocMem(&pAdapt, PATMSM_ADAPTER, sizeof(ATMSM_ADAPTER));
  360. if (NULL == pAdapt){
  361. Status = NDIS_STATUS_RESOURCES;
  362. break;
  363. }
  364. //
  365. // Initialize the adapter structure
  366. //
  367. NdisZeroMemory(pAdapt, sizeof(ATMSM_ADAPTER));
  368. pAdapt->ulSignature = atmsm_adapter_signature;
  369. //
  370. // Put a reference on the adapter
  371. //
  372. AtmSmReferenceAdapter(pAdapt);
  373. // the address is invalid now
  374. pAdapt->ulFlags |= ADAPT_ADDRESS_INVALID;
  375. // Hard-code the selector Byte
  376. pAdapt->SelByte = (UCHAR) 0x5;
  377. INIT_BLOCK_STRUCT(&pAdapt->RequestBlock);
  378. InitializeListHead(&pAdapt->InactiveVcHead);
  379. InitializeListHead(&pAdapt->ActiveVcHead);
  380. NdisAllocateSpinLock(&pAdapt->AdapterLock);
  381. NdisInitializeTimer(
  382. &pAdapt->RecvTimerOb,
  383. AtmSmRecvReturnTimerFunction,
  384. pAdapt
  385. );
  386. //
  387. // Fill in some defaults.
  388. //
  389. pAdapt->MaxPacketSize = DEFAULT_MAX_PACKET_SIZE;
  390. pAdapt->LinkSpeed.Inbound = pAdapt->LinkSpeed.Outbound
  391. = DEFAULT_SEND_BANDWIDTH;
  392. pAdapt->VCFlowSpec = AtmSmDefaultVCFlowSpec;
  393. //
  394. // Allocate a Buffer Pool
  395. //
  396. NdisAllocateBufferPool(&Status,
  397. &pAdapt->BufferPoolHandle,
  398. 0xFFFFFFFF);
  399. if (NDIS_STATUS_SUCCESS != Status)
  400. break;
  401. //
  402. // Allocate a packet pool. We need this to pass sends down. We cannot
  403. // use the same packet descriptor that came down to our send handler
  404. //
  405. NdisAllocatePacketPoolEx(&Status,
  406. &pAdapt->PacketPoolHandle,
  407. DEFAULT_NUM_PKTS_IN_POOL,
  408. (0xFFFF - DEFAULT_NUM_PKTS_IN_POOL),
  409. sizeof(PROTO_RSVD));
  410. if (NDIS_STATUS_SUCCESS != Status)
  411. break;
  412. }while(FALSE);
  413. if(Status == NDIS_STATUS_SUCCESS){
  414. pAdapt->ulFlags |= ADAPT_CREATED;
  415. // queue it in the Global list of adapters
  416. ACQUIRE_GLOBAL_LOCK();
  417. pAdapt->pAdapterNext = AtmSmGlobal.pAdapterList;
  418. AtmSmGlobal.pAdapterList = pAdapt;
  419. AtmSmGlobal.ulAdapterCount++;
  420. RELEASE_GLOBAL_LOCK();
  421. } else {
  422. // Failed, so cleanup
  423. LONG lRet = AtmSmDereferenceAdapter(pAdapt);
  424. ASSERT(0 == lRet);
  425. if(0 == lRet)
  426. pAdapt = NULL;
  427. }
  428. *ppAdapter = pAdapt;
  429. TraceOut(AtmSmAllocateAdapter);
  430. return Status;
  431. }
  432. VOID
  433. AtmSmDeallocateAdapter(
  434. PATMSM_ADAPTER pAdapt
  435. )
  436. /*++
  437. Routine Description:
  438. Called for cleaning up an Adapter structure, when it is not needed anymore.
  439. We don't get here unless the reference count drops to zero, that means all
  440. VC's, SAP etc are removed by now.
  441. Arguments:
  442. pAdapt - newly allocated adapter
  443. Return Value:
  444. None
  445. --*/
  446. {
  447. PPROTO_RSVD pPRsvd;
  448. PNDIS_PACKET pPkt;
  449. PATMSM_ADAPTER pTmpAdapt, pPrevAdapt;
  450. BOOLEAN fTimerCancelled;
  451. TraceIn(AtmSmDeallocateAdapter);
  452. if(!pAdapt)
  453. return;
  454. ASSERT(0 == pAdapt->ulRefCount);
  455. // remove the adapter from the Global list of adapters
  456. ACQUIRE_GLOBAL_LOCK();
  457. pPrevAdapt = NULL;
  458. pTmpAdapt = AtmSmGlobal.pAdapterList;
  459. while(pTmpAdapt &&
  460. pTmpAdapt != pAdapt){
  461. pPrevAdapt = pTmpAdapt;
  462. pTmpAdapt = pTmpAdapt->pAdapterNext;
  463. }
  464. ASSERT(pTmpAdapt);
  465. if(pPrevAdapt)
  466. pPrevAdapt->pAdapterNext = pAdapt->pAdapterNext;
  467. else
  468. AtmSmGlobal.pAdapterList = pAdapt->pAdapterNext;
  469. AtmSmGlobal.ulAdapterCount--;
  470. RELEASE_GLOBAL_LOCK();
  471. ACQUIRE_ADAPTER_GEN_LOCK(pAdapt);
  472. // cancel any recv timer on the adapter
  473. if(pAdapt->fRecvTimerQueued)
  474. CANCEL_ADAPTER_RECV_TIMER(pAdapt, &fTimerCancelled);
  475. //
  476. // Remove any packets still in the recv queue
  477. //
  478. while(pAdapt->pRecvPktNext){
  479. pPkt = pAdapt->pRecvPktNext;
  480. pPRsvd = GET_PROTO_RSVD(pPkt);
  481. pAdapt->pRecvPktNext = pPRsvd->pPktNext;
  482. pAdapt->ulRecvPktsCount--;
  483. RELEASE_ADAPTER_GEN_LOCK(pAdapt);
  484. NdisReturnPackets(&pPkt, 1);
  485. ACQUIRE_ADAPTER_GEN_LOCK(pAdapt);
  486. }
  487. pAdapt->pRecvLastPkt = NULL;
  488. // free the buffer pool
  489. if(pAdapt->BufferPoolHandle)
  490. NdisFreeBufferPool(pAdapt->BufferPoolHandle);
  491. // free the pool handle
  492. if(pAdapt->PacketPoolHandle)
  493. NdisFreePacketPool(pAdapt->PacketPoolHandle);
  494. RELEASE_ADAPTER_GEN_LOCK(pAdapt);
  495. // Free the bound to Adapter Name
  496. if(pAdapt->BoundToAdapterName.Buffer)
  497. NdisFreeString(pAdapt->BoundToAdapterName);
  498. // Free all spinlocks
  499. NdisFreeSpinLock(&pAdapt->AdapterLock);
  500. //
  501. // Signal anyone waiting for this to happen
  502. //
  503. if (pAdapt->pCleanupEvent) {
  504. NdisSetEvent(pAdapt->pCleanupEvent);
  505. }
  506. // since memory is not cleared
  507. pAdapt->ulSignature = atmsm_dead_adapter_signature;
  508. // free the adapter itself
  509. AtmSmFreeMem(pAdapt);
  510. TraceOut(AtmSmDeallocateAdapter);
  511. }
  512. BOOLEAN
  513. AtmSmReferenceAdapter(
  514. PATMSM_ADAPTER pAdapt
  515. )
  516. /*++
  517. Routine Description:
  518. To keep a refcount on the adapter.
  519. Arguments:
  520. pAdapt - adapter
  521. Return Value:
  522. TRUE - if the adapter is valid and not closing
  523. FALSE - adapter is closing
  524. --*/
  525. {
  526. BOOLEAN rc = FALSE;
  527. ASSERT(pAdapt);
  528. DbgInfo(("AtmSmReferenceAdapter - pAdapt - 0x%X\n", pAdapt));
  529. if(!pAdapt)
  530. return FALSE;
  531. ACQUIRE_ADAPTER_GEN_LOCK(pAdapt);
  532. if(0 == (pAdapt->ulFlags & ADAPT_CLOSING)){
  533. pAdapt->ulRefCount++;
  534. rc = TRUE;
  535. }
  536. RELEASE_ADAPTER_GEN_LOCK(pAdapt);
  537. return rc;
  538. }
  539. LONG
  540. AtmSmDereferenceAdapter(
  541. PATMSM_ADAPTER pAdapt
  542. )
  543. /*++
  544. Routine Description:
  545. To keep a refcount on the adapter. If the reference drops to 0
  546. we free the adapter.
  547. Arguments:
  548. pAdapt - adapter
  549. Return Value:
  550. The new Refcount
  551. --*/
  552. {
  553. ULONG ulRet;
  554. TraceIn(AtmSmDereferenceAdapter);
  555. DbgInfo(("AtmSmDereferenceAdapter - pAdapt - 0x%X\n", pAdapt));
  556. ASSERT(pAdapt);
  557. if(pAdapt){
  558. ACQUIRE_ADAPTER_GEN_LOCK(pAdapt);
  559. ulRet = --pAdapt->ulRefCount;
  560. RELEASE_ADAPTER_GEN_LOCK(pAdapt);
  561. // There are no more references on this adapter
  562. // hence free it
  563. if(0 == ulRet)
  564. AtmSmDeallocateAdapter(pAdapt);
  565. } else
  566. ulRet = 0;
  567. TraceOut(AtmSmDereferenceAdapter);
  568. return ulRet;
  569. }
  570. NDIS_STATUS
  571. AtmSmQueryAdapterATMAddresses(
  572. PATMSM_ADAPTER pAdapt
  573. )
  574. /*++
  575. Routine Description:
  576. Send a request to the Call Manager to retrieve the ATM address
  577. registered with the switch on the given interface.
  578. Arguments:
  579. pAdapt - adapter
  580. Return Value:
  581. --*/
  582. {
  583. PNDIS_REQUEST pNdisRequest;
  584. PCO_ADDRESS pCoAddr;
  585. NDIS_STATUS Status;
  586. UINT Size;
  587. TraceIn(AtmSmQueryAdapterATMAddresses);
  588. //
  589. // Allocate a request to query the configured address
  590. //
  591. Size = sizeof(NDIS_REQUEST) + sizeof(CO_ADDRESS_LIST) + sizeof(CO_ADDRESS)
  592. + sizeof(ATM_ADDRESS);
  593. AtmSmAllocMem(&pNdisRequest, PNDIS_REQUEST, Size);
  594. if (NULL == pNdisRequest){
  595. DbgErr(("Failed to get Adapter ATM Address - STATUS_RESOURCES\n"));
  596. return NDIS_STATUS_RESOURCES;
  597. }
  598. NdisZeroMemory(pNdisRequest, Size);
  599. pNdisRequest->RequestType = NdisRequestQueryInformation;
  600. pNdisRequest->DATA.QUERY_INFORMATION.Oid = OID_CO_GET_ADDRESSES;
  601. pNdisRequest->DATA.QUERY_INFORMATION.InformationBuffer =
  602. ((PUCHAR)pNdisRequest + sizeof(NDIS_REQUEST));
  603. pNdisRequest->DATA.QUERY_INFORMATION.InformationBufferLength =
  604. Size - sizeof(NDIS_REQUEST);
  605. Status = NdisCoRequest(pAdapt->NdisBindingHandle,
  606. pAdapt->NdisAfHandle,
  607. NULL,
  608. NULL,
  609. pNdisRequest);
  610. if (NDIS_STATUS_PENDING != Status) {
  611. AtmSmCoRequestComplete(Status, pAdapt, NULL, NULL, pNdisRequest);
  612. }
  613. TraceOut(AtmSmQueryAdapterATMAddresses);
  614. return Status;
  615. }
  616. VOID
  617. AtmSmQueryAdapter(
  618. IN PATMSM_ADAPTER pAdapt
  619. )
  620. /*++
  621. Routine Description:
  622. Query the miniport we are bound to for the following info:
  623. 1. Line rate
  624. 2. Max packet size
  625. These will overwrite the defaults we set up when creating the
  626. adapter.
  627. Arguments:
  628. pAdapt Pointer to the adapter
  629. Return Value:
  630. None
  631. --*/
  632. {
  633. TraceIn(AtmSmQueryAdapter);
  634. AtmSmSendAdapterNdisRequest(
  635. pAdapt,
  636. OID_GEN_CO_LINK_SPEED,
  637. (PVOID)&(pAdapt->LinkSpeed),
  638. sizeof(NDIS_CO_LINK_SPEED));
  639. AtmSmSendAdapterNdisRequest(
  640. pAdapt,
  641. OID_ATM_MAX_AAL5_PACKET_SIZE,
  642. (PVOID)&(pAdapt->MaxPacketSize),
  643. sizeof(ULONG));
  644. TraceOut(AtmSmQueryAdapter);
  645. }
  646. NDIS_STATUS
  647. AtmSmPnPEvent(
  648. IN NDIS_HANDLE ProtocolBindingContext,
  649. IN PNET_PNP_EVENT pNetPnPEvent
  650. )
  651. /*++
  652. Routine Description:
  653. This is the NDIS entry point called when NDIS wants to inform
  654. us about a PNP/PM event happening on an adapter.
  655. Arguments:
  656. ProtocolBindingContext - Our context for this adapter binding, which
  657. is a pointer to an ATMSM Adapter structure.
  658. pNetPnPEvent - Pointer to the event.
  659. Return Value:
  660. None
  661. --*/
  662. {
  663. PATMSM_ADAPTER pAdapt =
  664. (PATMSM_ADAPTER)ProtocolBindingContext;
  665. PNET_DEVICE_POWER_STATE pPowerState =
  666. (PNET_DEVICE_POWER_STATE)pNetPnPEvent->Buffer;
  667. NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
  668. TraceIn(AtmSmPnPEvent);
  669. do {
  670. switch (pNetPnPEvent->NetEvent) {
  671. case NetEventSetPower:
  672. switch (*pPowerState) {
  673. case NetDeviceStateD0:
  674. Status = NDIS_STATUS_SUCCESS;
  675. break;
  676. default:
  677. //
  678. // We can't suspend, so we ask NDIS to Unbind us by
  679. // returning this status:
  680. //
  681. Status = NDIS_STATUS_NOT_SUPPORTED;
  682. break;
  683. }
  684. break;
  685. case NetEventQueryPower: // FALLTHRU
  686. case NetEventQueryRemoveDevice: // FALLTHRU
  687. case NetEventCancelRemoveDevice:
  688. Status = NDIS_STATUS_SUCCESS;
  689. break;
  690. case NetEventReconfigure:
  691. if (pAdapt) {
  692. // Status = AtmSmReadAdapterConfiguration(pAdapt);
  693. } else {
  694. //
  695. // Global changes
  696. //
  697. Status = NDIS_STATUS_SUCCESS;
  698. }
  699. break;
  700. case NetEventBindList:
  701. default:
  702. Status = NDIS_STATUS_NOT_SUPPORTED;
  703. break;
  704. }
  705. break;
  706. }
  707. while (FALSE);
  708. TraceOut(AtmSmPnPEvent);
  709. return (Status);
  710. }
  711. VOID
  712. AtmSmStatus(
  713. IN NDIS_HANDLE ProtocolBindingContext,
  714. IN NDIS_STATUS GeneralStatus,
  715. IN PVOID StatusBuffer,
  716. IN UINT StatusBufferSize
  717. )
  718. /*++
  719. Routine Description:
  720. Arguments:
  721. Return Value:
  722. --*/
  723. {
  724. DbgWarn(("StatusIndication: Ignored\n"));
  725. }
  726. VOID
  727. AtmSmReceiveComplete(
  728. IN NDIS_HANDLE ProtocolBindingContext
  729. )
  730. /*++
  731. Routine Description:
  732. Arguments:
  733. Return Value:
  734. --*/
  735. {
  736. return;
  737. }
  738. VOID
  739. AtmSmStatusComplete(
  740. IN NDIS_HANDLE ProtocolBindingContext
  741. )
  742. /*++
  743. Routine Description:
  744. Arguments:
  745. Return Value:
  746. --*/
  747. {
  748. DbgWarn(("StatusComplete: Ignored\n"));
  749. }
  750. VOID
  751. AtmSmCoStatus(
  752. IN NDIS_HANDLE ProtocolBindingContext,
  753. IN NDIS_HANDLE ProtocolVcContext OPTIONAL,
  754. IN NDIS_STATUS GeneralStatus,
  755. IN PVOID StatusBuffer,
  756. IN UINT StatusBufferSize
  757. )
  758. /*++
  759. Routine Description:
  760. Arguments:
  761. Return Value:
  762. --*/
  763. {
  764. DbgWarn(("CoStatus: Ignored\n"));
  765. }