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.

5558 lines
124 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. callmgr.c - Call Manager Interface routines.
  5. Abstract:
  6. Call Manager Interface routines for the ATMARP Client, including
  7. NDIS entry points for that interface.
  8. Revision History:
  9. Who When What
  10. -------- -------- ----------------------------------------------
  11. arvindm 02-15-96 Created
  12. Notes:
  13. --*/
  14. #include <precomp.h>
  15. #define _FILENUMBER 'RGMC'
  16. VOID
  17. AtmArpCoAfRegisterNotifyHandler(
  18. IN NDIS_HANDLE ProtocolBindingContext,
  19. IN PCO_ADDRESS_FAMILY pAddressFamily
  20. )
  21. /*++
  22. Routine Description:
  23. This routine is called by NDIS when a Call manager registers its support
  24. for an Address Family over an adapter. If this is the Address Family we
  25. are interested in (UNI 3.1), then we start up all LIS' configured on
  26. this adapter.
  27. Arguments:
  28. ProtocolBindingContext - our context passed in NdisOpenAdapter, which is
  29. a pointer to our Adapter structure.
  30. pAddressFamily - points to a structure describing the Address Family
  31. being registered by a Call Manager.
  32. Return Value:
  33. None
  34. --*/
  35. {
  36. PATMARP_ADAPTER pAdapter;
  37. PATMARP_INTERFACE pInterface; // Pointer to new ATMARP Interface
  38. ULONG NumIFConfigured; // # of LIS' over this adapter
  39. ULONG NumIFActivated; // # activated successfully here
  40. NDIS_STATUS Status;
  41. NDIS_HANDLE LISConfigHandle; // Handle to per-LIS config
  42. struct LLIPBindInfo BindInfo;
  43. BOOLEAN bProcessingAf;
  44. //
  45. // Initialize.
  46. //
  47. Status = NDIS_STATUS_SUCCESS;
  48. pAdapter = NULL_PATMARP_ADAPTER;
  49. LISConfigHandle = NULL;
  50. NumIFActivated = 0;
  51. bProcessingAf = FALSE;
  52. do
  53. {
  54. //
  55. // Check if this AF is interesting to us.
  56. //
  57. if ((pAddressFamily->AddressFamily != CO_ADDRESS_FAMILY_Q2931) ||
  58. (pAddressFamily->MajorVersion != 3) ||
  59. (pAddressFamily->MinorVersion != 1))
  60. {
  61. AADEBUGP(AAD_LOUD,
  62. ("CoAfRegisterNotifyHandler: uninteresting AF %d or MajVer %d or MinVer %d\n",
  63. pAddressFamily->AddressFamily,
  64. pAddressFamily->MajorVersion,
  65. pAddressFamily->MinorVersion));
  66. Status = NDIS_STATUS_NOT_RECOGNIZED;
  67. break;
  68. }
  69. pAdapter = (PATMARP_ADAPTER)ProtocolBindingContext;
  70. AA_STRUCT_ASSERT(pAdapter, aaa);
  71. AA_ACQUIRE_GLOBAL_LOCK(pAtmArpGlobalInfo);
  72. if (pAdapter->Flags & AA_ADAPTER_FLAGS_UNBINDING)
  73. {
  74. AADEBUGP(AAD_INFO,
  75. ("CoAfRegisterNotify: Adapter %x is unbinding, bailing out\n", pAdapter));
  76. AA_RELEASE_GLOBAL_LOCK(pAtmArpGlobalInfo);
  77. Status = NDIS_STATUS_FAILURE;
  78. break;
  79. }
  80. //
  81. // If we have already created LIS' on this adapter, we don't want
  82. // to open this Call Manager (multiple Call Managers supporting the
  83. // same AF on the same adapter?)
  84. //
  85. if (pAdapter->pInterfaceList != NULL_PATMARP_INTERFACE)
  86. {
  87. AADEBUGP(AAD_WARNING,
  88. ("CoAfRegisterNotifyHandler: pAdapter 0x%x, IFs (%x) already created!\n",
  89. pAdapter, pAdapter->pInterfaceList));
  90. AA_RELEASE_GLOBAL_LOCK(pAtmArpGlobalInfo);
  91. Status = NDIS_STATUS_FAILURE;
  92. break;
  93. }
  94. if (pAdapter->Flags & AA_ADAPTER_FLAGS_PROCESSING_AF)
  95. {
  96. AADEBUGP(AAD_WARNING,
  97. ("CoAfRegisterNotifyHandler: pAdapter 0x%x, Already processing AF!\n",
  98. pAdapter));
  99. AA_RELEASE_GLOBAL_LOCK(pAtmArpGlobalInfo);
  100. Status = NDIS_STATUS_FAILURE;
  101. break;
  102. }
  103. //
  104. // Make sure that we don't let an UnbindAdapter thread preempt us.
  105. //
  106. AA_INIT_BLOCK_STRUCT(&pAdapter->UnbindBlock);
  107. pAdapter->Flags |= AA_ADAPTER_FLAGS_PROCESSING_AF;
  108. bProcessingAf = TRUE;
  109. if (pAdapter->Flags & AA_ADAPTER_FLAGS_AF_NOTIFIED)
  110. {
  111. //
  112. // This can happen when resuming from suspend/hibernate, since
  113. // we do not get unbound from the adapter. All IFs go away,
  114. // but the adapter remains.
  115. //
  116. // So we skip the one-time init stuff (see below), but go ahead
  117. // and process the AF and create IFs now.
  118. //
  119. AADEBUGP(AAD_WARNING,
  120. ("CoAfRegisterNotify: Adapter %x seen AF notify already, Flags %x\n",
  121. pAdapter, pAdapter->Flags));
  122. AA_RELEASE_GLOBAL_LOCK(pAtmArpGlobalInfo);
  123. }
  124. else
  125. {
  126. //
  127. // Do one-time init stuff for this adapter.
  128. //
  129. pAdapter->Flags |= AA_ADAPTER_FLAGS_AF_NOTIFIED;
  130. AA_RELEASE_GLOBAL_LOCK(pAtmArpGlobalInfo);
  131. //
  132. // Query the adapter (miniport) for information about the adapter
  133. // we are bound to.
  134. //
  135. Status = AtmArpGetAdapterInfo(pAdapter);
  136. if (Status != NDIS_STATUS_SUCCESS)
  137. {
  138. AADEBUGP(AAD_WARNING,
  139. ("CoAfRegisterNotifyHandler: Failed to get adapter info.\n"));
  140. break;
  141. }
  142. //
  143. // Read the adapter's configuration information from the registry.
  144. //
  145. Status = AtmArpCfgReadAdapterConfiguration(pAdapter);
  146. if (Status != NDIS_STATUS_SUCCESS)
  147. {
  148. AADEBUGP(AAD_WARNING,
  149. ("CoAfRegisterNotifyHandler: Failed to open adapter configuration\n"));
  150. break;
  151. }
  152. }
  153. AADEBUGP(AAD_WARNING,
  154. ("CoAfRegisterNotify: Adapter %x/%x, starting up\n", pAdapter, pAdapter->Flags));
  155. //
  156. // Initialize some variables so that we know if we failed
  157. // somewhere in the following loop.
  158. //
  159. LISConfigHandle = NULL;
  160. pInterface = NULL_PATMARP_INTERFACE;
  161. //
  162. // Set up IP and NDIS interfaces for each LIS configured
  163. // for this adapter. Loop while there are more LIS'.
  164. //
  165. for (NumIFConfigured = 0;
  166. ; // Stop only on error or no more LIS
  167. NumIFConfigured++)
  168. {
  169. #ifdef NEWARP
  170. //
  171. // TCP/IP's Configuration section for this interface.
  172. //
  173. NDIS_STRING IPConfigString;
  174. #endif // NEWARP
  175. //
  176. // Process LIS # NumIFConfigured.
  177. //
  178. // Open the configuration section for this LIS. We use
  179. // "NumIFConfigured" as the index of the LIS to be opened.
  180. //
  181. LISConfigHandle = AtmArpCfgOpenLISConfiguration(
  182. pAdapter,
  183. NumIFConfigured
  184. #ifdef NEWARP
  185. ,
  186. &IPConfigString
  187. #endif // NEWARP
  188. );
  189. if (LISConfigHandle == NULL)
  190. {
  191. //
  192. // This is the normal termination condition, i.e.
  193. // we reached the end of the LIS list for this
  194. // adapter.
  195. //
  196. AADEBUGP(AAD_INFO, ("NotifyRegAfHandler: cannot open LIS %d\n",
  197. NumIFConfigured));
  198. Status = NDIS_STATUS_SUCCESS;
  199. break; // out of for loop
  200. }
  201. pInterface = AtmArpAddInterfaceToAdapter (
  202. pAdapter,
  203. LISConfigHandle,
  204. &IPConfigString
  205. );
  206. //
  207. // Close the configuration section for this LIS.
  208. //
  209. AtmArpCfgCloseLISConfiguration(LISConfigHandle);
  210. LISConfigHandle = NULL;
  211. if (pInterface == NULL_PATMARP_INTERFACE)
  212. {
  213. Status = NDIS_STATUS_FAILURE;
  214. break;
  215. }
  216. } // for
  217. }
  218. while (FALSE);
  219. if (NumIFActivated > 0)
  220. {
  221. //
  222. // We managed to activate atleast one Logical IP Subnet
  223. // on this adapter.
  224. //
  225. pAdapter->InterfaceCount = NumIFActivated;
  226. }
  227. if (bProcessingAf)
  228. {
  229. AA_ACQUIRE_GLOBAL_LOCK(pAtmArpGlobalInfo);
  230. pAdapter->Flags &= ~AA_ADAPTER_FLAGS_PROCESSING_AF;
  231. AA_SIGNAL_BLOCK_STRUCT(&pAdapter->UnbindBlock, NDIS_STATUS_SUCCESS);
  232. AA_RELEASE_GLOBAL_LOCK(pAtmArpGlobalInfo);
  233. }
  234. return;
  235. }
  236. NDIS_STATUS
  237. AtmArpOpenCallMgr(
  238. IN PATMARP_INTERFACE pInterface
  239. )
  240. /*++
  241. Routine Description:
  242. Start access to the Call Manager on the specified Interface,
  243. by doing the following:
  244. - Open Address Family
  245. For all of these, we wait for completion in case they pend.
  246. It is assumed that the Interface structure is locked.
  247. Arguments:
  248. pInterface - pointer to the ATMARP interface
  249. Return Value:
  250. NDIS status.
  251. --*/
  252. {
  253. PCO_ADDRESS_FAMILY pAddressFamily;
  254. NDIS_STATUS Status;
  255. ULONG RequestSize;
  256. pAddressFamily = (PCO_ADDRESS_FAMILY)NULL;
  257. Status = NDIS_STATUS_SUCCESS;
  258. do {
  259. //
  260. // Allocate everything we need
  261. //
  262. RequestSize = sizeof(CO_ADDRESS_FAMILY)+
  263. sizeof(CO_SAP)+
  264. sizeof(ATM_SAP)+
  265. sizeof(ATM_ADDRESS);
  266. AA_ALLOC_MEM(
  267. pAddressFamily,
  268. CO_ADDRESS_FAMILY,
  269. RequestSize
  270. );
  271. if (pAddressFamily == (PCO_ADDRESS_FAMILY)NULL)
  272. {
  273. AADEBUGP(AAD_ERROR, ("OpenCallMgr: alloc failed!\n"));
  274. Status = NDIS_STATUS_RESOURCES;
  275. break;
  276. }
  277. //
  278. // DONT remove the following
  279. //
  280. AA_SET_MEM((PUCHAR)pAddressFamily, 0, RequestSize);
  281. //
  282. // The Address Family we are interested in is Q.2931 (UNI 3.1)
  283. //
  284. pAddressFamily->AddressFamily = CO_ADDRESS_FAMILY_Q2931;
  285. pAddressFamily->MajorVersion = 3;
  286. pAddressFamily->MinorVersion = 1;
  287. AA_INIT_BLOCK_STRUCT(&(pInterface->Block));
  288. Status = NdisClOpenAddressFamily(
  289. pInterface->NdisAdapterHandle,
  290. pAddressFamily,
  291. (NDIS_HANDLE)pInterface,
  292. &AtmArpClientCharacteristics,
  293. sizeof(AtmArpClientCharacteristics),
  294. &(pInterface->NdisAfHandle)
  295. );
  296. if (Status == NDIS_STATUS_PENDING)
  297. {
  298. //
  299. // Wait for completion
  300. //
  301. Status = AA_WAIT_ON_BLOCK_STRUCT(&(pInterface->Block));
  302. }
  303. if (Status != NDIS_STATUS_SUCCESS)
  304. {
  305. AADEBUGP(AAD_ERROR, ("Open Af returned error: 0x%x\n", Status));
  306. break;
  307. }
  308. AADEBUGP(AAD_INFO, ("Interface: 0x%x, Got NdisAfHandle: 0x%x\n",
  309. pInterface, pInterface->NdisAfHandle));
  310. break;
  311. }
  312. while (FALSE);
  313. if (pAddressFamily != (PCO_ADDRESS_FAMILY)NULL)
  314. {
  315. AA_FREE_MEM(pAddressFamily);
  316. }
  317. AADEBUGP(AAD_LOUD, ("Open Call Mgr returning 0x%x\n", Status));
  318. return (Status);
  319. }
  320. VOID
  321. AtmArpCloseCallMgr(
  322. IN PATMARP_INTERFACE pInterface
  323. )
  324. /*++
  325. Routine Description:
  326. Halt access to the Call Manager on the specified interface. It is
  327. assumed that all VCs and SAPs pertaining to the "Address Family Open"
  328. have been released.
  329. Arguments:
  330. pInterface - pointer to the ATMARP interface
  331. Return Value:
  332. None
  333. --*/
  334. {
  335. NDIS_STATUS Status;
  336. NDIS_HANDLE NdisAfHandle;
  337. NdisAfHandle = pInterface->NdisAfHandle;
  338. pInterface->NdisAfHandle = NULL;
  339. AADEBUGP(AAD_INFO,
  340. ("Closing Call Mgr on Interface: 0x%x, AfH: 0x%x\n",
  341. pInterface, NdisAfHandle));
  342. if (NdisAfHandle != (NDIS_HANDLE)NULL)
  343. {
  344. Status = NdisClCloseAddressFamily(NdisAfHandle);
  345. AADEBUGP(AAD_INFO, ("NdisClCloseAF on IF 0x%x returned 0x%x\n",
  346. pInterface, Status));
  347. if (Status != NDIS_STATUS_PENDING)
  348. {
  349. AtmArpCloseAfCompleteHandler(
  350. Status,
  351. (NDIS_HANDLE)pInterface
  352. );
  353. }
  354. }
  355. }
  356. VOID
  357. AtmArpRegisterSaps(
  358. IN PATMARP_INTERFACE pInterface
  359. )
  360. /*++
  361. Routine Description:
  362. Register all SAPs configured on the given ATMARP interface.
  363. Atleast one SAP must be present in the list of SAPs on the
  364. interface.
  365. We just issue the NdisClRegisterSap requests for all SAPs.
  366. We don't wait for completion.
  367. Arguments:
  368. pInterface - Pointer to ATMARP Interface
  369. Return Value:
  370. None
  371. --*/
  372. {
  373. PATMARP_SAP pAtmArpSap;
  374. PATMARP_SAP pNextSap;
  375. PCO_SAP pSapInfo;
  376. NDIS_STATUS Status;
  377. NDIS_HANDLE NdisAfHandle;
  378. ULONG rc; // Ref count on Interface
  379. AA_ACQUIRE_IF_LOCK(pInterface);
  380. AA_ASSERT(pInterface->NumberOfSaps > 0);
  381. //
  382. // Initialize
  383. //
  384. pAtmArpSap = &(pInterface->SapList);
  385. NdisAfHandle = pInterface->NdisAfHandle;
  386. //
  387. // Make sure that the Interface doesn't go away.
  388. //
  389. AtmArpReferenceInterface(pInterface);
  390. AA_RELEASE_IF_LOCK(pInterface);
  391. do
  392. {
  393. pSapInfo = pAtmArpSap->pInfo;
  394. pAtmArpSap->NdisSapHandle = NULL;
  395. AA_SET_FLAG(pAtmArpSap->Flags,
  396. AA_SAP_REG_STATE_MASK,
  397. AA_SAP_REG_STATE_REGISTERING);
  398. pNextSap = pAtmArpSap->pNextSap;
  399. //
  400. // The ATMARP SAP structure itself won't go away as long as
  401. // the Interface structure lives.
  402. //
  403. Status = NdisClRegisterSap(
  404. NdisAfHandle,
  405. (NDIS_HANDLE)pAtmArpSap, // ProtocolSapContext
  406. pSapInfo,
  407. &(pAtmArpSap->NdisSapHandle)
  408. );
  409. if (Status != NDIS_STATUS_PENDING)
  410. {
  411. AtmArpRegisterSapCompleteHandler(
  412. Status,
  413. (NDIS_HANDLE)pAtmArpSap,
  414. pSapInfo,
  415. pAtmArpSap->NdisSapHandle
  416. );
  417. }
  418. pAtmArpSap = pNextSap;
  419. }
  420. while (pAtmArpSap != NULL_PATMARP_SAP);
  421. //
  422. // Remove the reference we added earlier to the Interface.
  423. //
  424. AA_ACQUIRE_IF_LOCK(pInterface);
  425. rc = AtmArpDereferenceInterface(pInterface);
  426. if (rc > 0)
  427. {
  428. AA_RELEASE_IF_LOCK(pInterface);
  429. }
  430. //
  431. // else the Interface is gone!
  432. }
  433. VOID
  434. AtmArpDeregisterSaps(
  435. IN PATMARP_INTERFACE pInterface
  436. )
  437. /*++
  438. Routine Description:
  439. Deregister all SAPs on an ATMARP Interface. We issue NdisClDeregisterSap
  440. calls on all SAPs we have currently registered.
  441. Arguments:
  442. pInterface - Pointer to ATMARP Interface
  443. Return Value:
  444. None
  445. --*/
  446. {
  447. NDIS_HANDLE NdisSapHandle;
  448. ULONG rc; // Reference count on Interface
  449. PATMARP_SAP pAtmArpSap;
  450. PATMARP_SAP pNextSap;
  451. NDIS_STATUS Status;
  452. AA_ACQUIRE_IF_LOCK(pInterface);
  453. //
  454. // Initialize
  455. //
  456. pAtmArpSap = &(pInterface->SapList);
  457. //
  458. // Make sure the Interface structure doesn't go away.
  459. //
  460. AtmArpReferenceInterface(pInterface);
  461. AA_RELEASE_IF_LOCK(pInterface);
  462. do
  463. {
  464. NdisSapHandle = pAtmArpSap->NdisSapHandle;
  465. pNextSap = pAtmArpSap->pNextSap;
  466. if (NdisSapHandle != NULL)
  467. {
  468. Status = NdisClDeregisterSap(NdisSapHandle);
  469. if (Status != NDIS_STATUS_PENDING)
  470. {
  471. AtmArpDeregisterSapCompleteHandler(
  472. Status,
  473. (NDIS_HANDLE)pAtmArpSap
  474. );
  475. }
  476. }
  477. pAtmArpSap = pNextSap;
  478. }
  479. while (pAtmArpSap != NULL_PATMARP_SAP);
  480. //
  481. // Remove the reference we added earlier to the Interface.
  482. //
  483. AA_ACQUIRE_IF_LOCK(pInterface);
  484. rc = AtmArpDereferenceInterface(pInterface);
  485. if (rc > 0)
  486. {
  487. AA_RELEASE_IF_LOCK(pInterface);
  488. }
  489. //
  490. // else the interface is gone
  491. //
  492. }
  493. NDIS_STATUS
  494. AtmArpMakeCall(
  495. IN PATMARP_INTERFACE pInterface,
  496. IN PATMARP_ATM_ENTRY pAtmEntry LOCKIN NOLOCKOUT,
  497. IN PATMARP_FLOW_SPEC pFlowSpec,
  498. IN PNDIS_PACKET pPacketToBeQueued OPTIONAL
  499. )
  500. /*++
  501. Routine Description:
  502. Place a call to the given destination. Map the specified flow
  503. specs to ATM QoS/Traffic parameters.
  504. NOTE: The caller is assumed to hold a lock for the ATM Entry,
  505. which will be released here. The reason we do it this way is so that
  506. nobody else can come in and try to make another call (of the same kind)
  507. to this ATM Entry -- once we get a new VC into the ATM Entry's list,
  508. we can release its lock.
  509. SIDE EFFECT: If the NDIS call doesn't pend, then we call our
  510. MakeCall completion handler from here, and return NDIS_STATUS_PENDING
  511. to the caller.
  512. Arguments:
  513. pInterface - the ARP Interface originating this call
  514. pAtmEntry - Pointer to ATM Address Entry corresponding to the
  515. called address.
  516. pFlowSpec - pointer to a Flow Spec structure containing parameters
  517. for the call
  518. pPacketToBeQueued - Optionally, a packet to be queued for transmission when
  519. the call is established.
  520. Return Value:
  521. If there is an immediate failure (e.g. allocation failure), we return
  522. NDIS_STATUS_XXX denoting that failure.
  523. If we made it to the call to NdisClMakeCall(), we return NDIS_STATUS_PENDING.
  524. However, if NDIS returns other than NDIS_STATUS_PENDING, we'd also
  525. call our MakeCall completion handler.
  526. --*/
  527. {
  528. //
  529. // New VC structure to be allocated for this call
  530. //
  531. PATMARP_VC pVc;
  532. NDIS_HANDLE NdisVcHandle;
  533. NDIS_HANDLE ProtocolVcContext;
  534. NDIS_HANDLE ProtocolPartyContext;
  535. PNDIS_HANDLE pNdisPartyHandle;
  536. NDIS_STATUS Status;
  537. BOOLEAN IsPMP;
  538. PATM_ADDRESS pCalledAddress;
  539. //
  540. // Set of parameters for a MakeCall
  541. //
  542. PCO_CALL_PARAMETERS pCallParameters;
  543. PCO_CALL_MANAGER_PARAMETERS pCallMgrParameters;
  544. PQ2931_CALLMGR_PARAMETERS pAtmCallMgrParameters;
  545. //
  546. // All Info Elements that we need to fill:
  547. //
  548. Q2931_IE UNALIGNED * pIe;
  549. AAL_PARAMETERS_IE UNALIGNED * pAalIe;
  550. ATM_TRAFFIC_DESCRIPTOR_IE UNALIGNED * pTrafficDescriptor;
  551. ATM_BROADBAND_BEARER_CAPABILITY_IE UNALIGNED * pBbc;
  552. ATM_BLLI_IE UNALIGNED * pBlli;
  553. ATM_QOS_CLASS_IE UNALIGNED * pQos;
  554. //
  555. // Total space requirements for the MakeCall
  556. //
  557. ULONG RequestSize;
  558. //
  559. // Did we queue the given packet?
  560. //
  561. BOOLEAN PacketWasQueued = FALSE;
  562. AA_STRUCT_ASSERT(pInterface, aai);
  563. AA_STRUCT_ASSERT(pAtmEntry, aae);
  564. AA_ASSERT(pInterface->AdminState == IF_STATUS_UP);
  565. do
  566. {
  567. if (pPacketToBeQueued != (PNDIS_PACKET)NULL)
  568. {
  569. //
  570. // Make this a list of exactly one packet.
  571. //
  572. AA_SET_NEXT_PACKET(pPacketToBeQueued, NULL);
  573. }
  574. //
  575. // Fail makecall if atmentry state is really closing.
  576. //
  577. if (AA_IS_FLAG_SET(
  578. pAtmEntry->Flags,
  579. AA_ATM_ENTRY_STATE_MASK,
  580. AA_ATM_ENTRY_CLOSING))
  581. {
  582. BOOLEAN ReallyClosing = TRUE;
  583. //
  584. // This may be a harmless close -- if the interface is not shutting
  585. // down we check if it's a harmless close, else (if the interface
  586. // is shutting down) we fail the call anyway. Note that we don't
  587. // claim the interface list lock (which is used to guard access
  588. // to AtmEntryListUp) -- we don't do this because we currently
  589. // hold the lock to pAtmEntry (and don't want to release it), so if
  590. // AtmEntryListUp is in the
  591. // process of being set to FALSE, when we read it's value here,
  592. // in the worst case we'll read it's value as TRUE and conclude that
  593. // the atm entry is not really closing and go ahead and make the call.
  594. // However in this case, the shutdown routine will invalidate the call.
  595. //
  596. if (pInterface->AtmEntryListUp)
  597. {
  598. //
  599. // WARNING: AtmArpAtmEntryIsReallyClosing may clear the
  600. // CLOSING state (if the entry is basically idle) --
  601. // see comments in that function.
  602. //
  603. ReallyClosing = AtmArpAtmEntryIsReallyClosing(pAtmEntry);
  604. }
  605. if (ReallyClosing)
  606. {
  607. AADEBUGP(AAD_FATAL,
  608. ("AtmArpMakeCall -- failing because AE 0x%lx is really closing.\n",
  609. pAtmEntry));
  610. Status = NDIS_STATUS_FAILURE;
  611. break;
  612. }
  613. }
  614. //
  615. // Some initialization.
  616. //
  617. if (AA_IS_FLAG_SET(pAtmEntry->Flags,
  618. AA_ATM_ENTRY_TYPE_MASK,
  619. AA_ATM_ENTRY_TYPE_UCAST))
  620. {
  621. IsPMP = FALSE;
  622. ProtocolPartyContext = NULL;
  623. pNdisPartyHandle = NULL;
  624. pCalledAddress = &(pAtmEntry->ATMAddress);
  625. }
  626. #ifdef IPMCAST
  627. else
  628. {
  629. IsPMP = TRUE;
  630. ProtocolPartyContext = (NDIS_HANDLE)(pAtmEntry->pMcAtmInfo->pMcAtmEntryList);
  631. pNdisPartyHandle = &(pAtmEntry->pMcAtmInfo->pMcAtmEntryList->NdisPartyHandle);
  632. pCalledAddress = &(pAtmEntry->pMcAtmInfo->pMcAtmEntryList->ATMAddress);
  633. }
  634. #else
  635. else
  636. {
  637. AA_ASSERT(FALSE);
  638. }
  639. #endif // IPMCAST
  640. //
  641. // Compute all the space needed for the MakeCall, and allocate it
  642. // in one big block.
  643. //
  644. RequestSize = sizeof(CO_CALL_PARAMETERS) +
  645. sizeof(CO_CALL_MANAGER_PARAMETERS) +
  646. sizeof(Q2931_CALLMGR_PARAMETERS) +
  647. ATMARP_MAKE_CALL_IE_SPACE +
  648. 0;
  649. AA_ALLOC_MEM(pCallParameters, CO_CALL_PARAMETERS, RequestSize);
  650. if (pCallParameters == (PCO_CALL_PARAMETERS)NULL)
  651. {
  652. AADEBUGP(AAD_WARNING, ("Make Call: alloc (%d) failed\n", RequestSize));
  653. Status = NDIS_STATUS_RESOURCES;
  654. break;
  655. }
  656. //
  657. // Allocate a VC structure for the call
  658. //
  659. pVc = AtmArpAllocateVc(pInterface);
  660. if (pVc == NULL_PATMARP_VC)
  661. {
  662. AADEBUGP(AAD_WARNING, ("Make Call: failed to allocate VC\n"));
  663. AA_FREE_MEM(pCallParameters);
  664. Status = NDIS_STATUS_RESOURCES;
  665. break;
  666. }
  667. //
  668. // For a later call to MakeCallComplete
  669. //
  670. ProtocolVcContext = (NDIS_HANDLE)pVc;
  671. //
  672. // Get an NDIS handle for this VC
  673. //
  674. NdisVcHandle = (NDIS_HANDLE)NULL;
  675. Status = NdisCoCreateVc(
  676. pInterface->NdisAdapterHandle,
  677. pInterface->NdisAfHandle,
  678. ProtocolVcContext,
  679. &NdisVcHandle
  680. );
  681. if (Status != NDIS_STATUS_SUCCESS)
  682. {
  683. AA_ASSERT(Status != NDIS_STATUS_PENDING);
  684. AADEBUGP(AAD_WARNING, ("Make Call: NdisCoCreateVc failed: 0x%x\n", Status));
  685. AA_FREE_MEM(pCallParameters);
  686. AtmArpDeallocateVc(pVc);
  687. break;
  688. }
  689. AADEBUGP(AAD_VERY_LOUD,
  690. ("Make Call: pAtmEntry 0x%x, pVc 0x%x, got NdisVcHandle 0x%x\n",
  691. pAtmEntry,
  692. pVc,
  693. NdisVcHandle));
  694. AtmArpReferenceVc(pVc); // CreateVC reference
  695. //
  696. // At this point, we are sure that we will call NdisClMakeCall.
  697. //
  698. //
  699. // Now fill in the rest of the VC structure. We don't need a lock
  700. // for the VC until it gets linked to the ATM Entry structure.
  701. //
  702. pVc->NdisVcHandle = NdisVcHandle;
  703. pVc->Flags = AA_VC_TYPE_SVC |
  704. AA_VC_OWNER_IS_ATMARP |
  705. AA_VC_CALL_STATE_OUTGOING_IN_PROGRESS;
  706. if (IsPMP)
  707. {
  708. pVc->Flags |= AA_VC_CONN_TYPE_PMP;
  709. }
  710. else
  711. {
  712. pVc->Flags |= AA_VC_CONN_TYPE_P2P;
  713. }
  714. pVc->FlowSpec = *pFlowSpec;
  715. //
  716. // Make sure that the packet sizes are within the miniport's range.
  717. //
  718. if (pVc->FlowSpec.SendMaxSize > pInterface->pAdapter->MaxPacketSize)
  719. {
  720. pVc->FlowSpec.SendMaxSize = pInterface->pAdapter->MaxPacketSize;
  721. }
  722. if (pVc->FlowSpec.ReceiveMaxSize > pInterface->pAdapter->MaxPacketSize)
  723. {
  724. pVc->FlowSpec.ReceiveMaxSize = pInterface->pAdapter->MaxPacketSize;
  725. }
  726. if (pPacketToBeQueued != (PNDIS_PACKET)NULL)
  727. {
  728. pVc->PacketList = pPacketToBeQueued;
  729. PacketWasQueued = TRUE;
  730. }
  731. #ifdef IPMCAST
  732. AtmArpFillCallParameters(
  733. pCallParameters,
  734. RequestSize,
  735. pCalledAddress,
  736. &(pInterface->LocalAtmAddress), // Calling address
  737. &(pVc->FlowSpec),
  738. IsPMP,
  739. TRUE // IsMakeCall?
  740. );
  741. #else
  742. //
  743. // Zero out everything
  744. //
  745. AA_SET_MEM((PUCHAR)pCallParameters, 0, RequestSize);
  746. //
  747. // Distribute space amongst the various structures
  748. //
  749. pCallMgrParameters = (PCO_CALL_MANAGER_PARAMETERS)
  750. ((PUCHAR)pCallParameters +
  751. sizeof(CO_CALL_PARAMETERS));
  752. //
  753. // Set pointers to link the above structures together
  754. //
  755. pCallParameters->CallMgrParameters = pCallMgrParameters;
  756. pCallParameters->MediaParameters = (PCO_MEDIA_PARAMETERS)NULL;
  757. pCallMgrParameters->CallMgrSpecific.ParamType = 0;
  758. pCallMgrParameters->CallMgrSpecific.Length =
  759. sizeof(Q2931_CALLMGR_PARAMETERS) +
  760. ATMARP_CALL_IE_SPACE;
  761. pAtmCallMgrParameters = (PQ2931_CALLMGR_PARAMETERS)
  762. pCallMgrParameters->CallMgrSpecific.Parameters;
  763. //
  764. // Call Manager generic flow parameters:
  765. //
  766. pCallMgrParameters->Transmit.TokenRate = (pFlowSpec->SendAvgBandwidth);
  767. pCallMgrParameters->Transmit.TokenBucketSize = (pFlowSpec->SendMaxSize);
  768. pCallMgrParameters->Transmit.MaxSduSize = pFlowSpec->SendMaxSize;
  769. pCallMgrParameters->Transmit.PeakBandwidth = (pFlowSpec->SendPeakBandwidth);
  770. pCallMgrParameters->Transmit.ServiceType = pFlowSpec->SendServiceType;
  771. pCallMgrParameters->Receive.TokenRate = (pFlowSpec->ReceiveAvgBandwidth);
  772. pCallMgrParameters->Receive.TokenBucketSize = pFlowSpec->ReceiveMaxSize;
  773. pCallMgrParameters->Receive.MaxSduSize = pFlowSpec->ReceiveMaxSize;
  774. pCallMgrParameters->Receive.PeakBandwidth = (pFlowSpec->ReceivePeakBandwidth);
  775. pCallMgrParameters->Receive.ServiceType = pFlowSpec->ReceiveServiceType;
  776. //
  777. // Q2931 Call Manager Parameters:
  778. //
  779. //
  780. // Called address:
  781. //
  782. // TBD: Add Called Subaddress IE in outgoing call.
  783. //
  784. AA_COPY_MEM((PUCHAR)&(pAtmCallMgrParameters->CalledParty),
  785. (PUCHAR)&(pAtmEntry->ATMAddress),
  786. sizeof(ATM_ADDRESS));
  787. //
  788. // Calling address:
  789. //
  790. AA_COPY_MEM((PUCHAR)&(pAtmCallMgrParameters->CallingParty),
  791. (PUCHAR)&(pInterface->LocalAtmAddress),
  792. sizeof(ATM_ADDRESS));
  793. //
  794. // RFC 1755 (Sec 5) says that the following IEs MUST be present in the
  795. // SETUP message, so fill them all.
  796. //
  797. // AAL Parameters
  798. // Traffic Descriptor
  799. // Broadband Bearer Capability
  800. // Broadband Low Layer Info
  801. // QoS
  802. //
  803. //
  804. // Initialize the Info Element list
  805. //
  806. pAtmCallMgrParameters->InfoElementCount = 0;
  807. pIe = (PQ2931_IE)(pAtmCallMgrParameters->InfoElements);
  808. //
  809. // AAL Parameters:
  810. //
  811. {
  812. UNALIGNED AAL5_PARAMETERS *pAal5;
  813. pIe->IEType = IE_AALParameters;
  814. pIe->IELength = SIZEOF_Q2931_IE + SIZEOF_AAL_PARAMETERS_IE;
  815. pAalIe = (PAAL_PARAMETERS_IE)pIe->IE;
  816. pAalIe->AALType = AAL_TYPE_AAL5;
  817. pAal5 = &(pAalIe->AALSpecificParameters.AAL5Parameters);
  818. pAal5->ForwardMaxCPCSSDUSize = pFlowSpec->SendMaxSize;
  819. pAal5->BackwardMaxCPCSSDUSize = pFlowSpec->ReceiveMaxSize;
  820. }
  821. pAtmCallMgrParameters->InfoElementCount++;
  822. pIe = (PQ2931_IE)((PUCHAR)pIe + pIe->IELength);
  823. //
  824. // Traffic Descriptor:
  825. //
  826. pIe->IEType = IE_TrafficDescriptor;
  827. pIe->IELength = SIZEOF_Q2931_IE + SIZEOF_ATM_TRAFFIC_DESCR_IE;
  828. pTrafficDescriptor = (PATM_TRAFFIC_DESCRIPTOR_IE)pIe->IE;
  829. if (pFlowSpec->SendServiceType == SERVICETYPE_BESTEFFORT)
  830. {
  831. pTrafficDescriptor->ForwardTD.PeakCellRateCLP01 =
  832. BYTES_TO_CELLS(pFlowSpec->SendPeakBandwidth);
  833. pTrafficDescriptor->BackwardTD.PeakCellRateCLP01 =
  834. BYTES_TO_CELLS(pFlowSpec->ReceivePeakBandwidth);
  835. pTrafficDescriptor->BestEffort = TRUE;
  836. }
  837. else
  838. {
  839. // Predictive/Guaranteed service (we map this to CBR, see BBC below)
  840. pTrafficDescriptor->ForwardTD.PeakCellRateCLP01 =
  841. BYTES_TO_CELLS(pFlowSpec->SendPeakBandwidth);
  842. pTrafficDescriptor->BackwardTD.PeakCellRateCLP01 =
  843. BYTES_TO_CELLS(pFlowSpec->ReceivePeakBandwidth);
  844. pTrafficDescriptor->BestEffort = FALSE;
  845. }
  846. pAtmCallMgrParameters->InfoElementCount++;
  847. pIe = (PQ2931_IE)((PUCHAR)pIe + pIe->IELength);
  848. //
  849. // Broadband Bearer Capability
  850. //
  851. pIe->IEType = IE_BroadbandBearerCapability;
  852. pIe->IELength = SIZEOF_Q2931_IE + SIZEOF_ATM_BBC_IE;
  853. pBbc = (PATM_BROADBAND_BEARER_CAPABILITY_IE)pIe->IE;
  854. pBbc->BearerClass = BCOB_X;
  855. pBbc->UserPlaneConnectionConfig = UP_P2P;
  856. if (pFlowSpec->SendServiceType == SERVICETYPE_BESTEFFORT)
  857. {
  858. pBbc->TrafficType = TT_NOIND;
  859. pBbc->TimingRequirements = TR_NOIND;
  860. pBbc->ClippingSusceptability = CLIP_NOT;
  861. }
  862. else
  863. {
  864. pBbc->TrafficType = TT_CBR;
  865. pBbc->TimingRequirements = TR_END_TO_END;
  866. pBbc->ClippingSusceptability = CLIP_SUS;
  867. }
  868. pAtmCallMgrParameters->InfoElementCount++;
  869. pIe = (PQ2931_IE)((PUCHAR)pIe + pIe->IELength);
  870. //
  871. // Broadband Lower Layer Information
  872. //
  873. pIe->IEType = IE_BLLI;
  874. pIe->IELength = SIZEOF_Q2931_IE + SIZEOF_ATM_BLLI_IE;
  875. pBlli = (PATM_BLLI_IE)pIe->IE;
  876. AA_COPY_MEM((PUCHAR)pBlli,
  877. (PUCHAR)&AtmArpDefaultBlli,
  878. sizeof(ATM_BLLI_IE));
  879. pAtmCallMgrParameters->InfoElementCount++;
  880. pIe = (PQ2931_IE)((PUCHAR)pIe + pIe->IELength);
  881. //
  882. // QoS
  883. //
  884. pIe->IEType = IE_QOSClass;
  885. pIe->IELength = SIZEOF_Q2931_IE + SIZEOF_ATM_QOS_IE;
  886. pQos = (PATM_QOS_CLASS_IE)pIe->IE;
  887. if (pFlowSpec->SendServiceType == SERVICETYPE_BESTEFFORT)
  888. {
  889. pQos->QOSClassForward = pQos->QOSClassBackward = 0;
  890. }
  891. else
  892. {
  893. pQos->QOSClassForward = pQos->QOSClassBackward = 1;
  894. }
  895. pAtmCallMgrParameters->InfoElementCount++;
  896. pIe = (PQ2931_IE)((PUCHAR)pIe + pIe->IELength);
  897. #endif // IPMCAST
  898. //
  899. // We add the Call reference and ATM Entry Link reference
  900. // right here
  901. //
  902. AtmArpReferenceVc(pVc); // Call reference (MakeCall coming up)
  903. AtmArpReferenceVc(pVc); // ATM Entry link reference (coming up below)
  904. #ifdef IPMCAST
  905. if (IsPMP)
  906. {
  907. pAtmEntry->pMcAtmInfo->TransientLeaves++;
  908. }
  909. #endif // IPMCAST
  910. //
  911. // We are ready to make the call. Before we do so, we need to
  912. // link the VC structure to the ATM Entry, and release the
  913. // ATM Entry lock
  914. //
  915. AtmArpLinkVcToAtmEntry(pVc, pAtmEntry);
  916. AA_RELEASE_AE_LOCK(pAtmEntry); // acquired by caller
  917. //
  918. // Make the Call now
  919. //
  920. Status = NdisClMakeCall(
  921. NdisVcHandle,
  922. pCallParameters,
  923. ProtocolPartyContext,
  924. pNdisPartyHandle
  925. );
  926. if (Status != NDIS_STATUS_PENDING)
  927. {
  928. NDIS_HANDLE NdisPartyHandle;
  929. NdisPartyHandle = ((pNdisPartyHandle != NULL)?
  930. *pNdisPartyHandle : NULL);
  931. AtmArpMakeCallCompleteHandler(
  932. Status,
  933. ProtocolVcContext,
  934. NdisPartyHandle,
  935. pCallParameters
  936. );
  937. Status = NDIS_STATUS_PENDING;
  938. }
  939. //
  940. // else the MakeCall complete handler will be called
  941. // later
  942. //
  943. } while (FALSE);
  944. if (Status != NDIS_STATUS_PENDING)
  945. {
  946. ULONG Flags;
  947. //
  948. // Something failed within this routine.
  949. // Recovery:
  950. // - Release the ATM Entry lock
  951. // - If we were given a packet for queueing, and we didn't do so,
  952. // then free it
  953. //
  954. Flags = pAtmEntry->Flags;
  955. AA_RELEASE_AE_LOCK(pAtmEntry); // acquired by caller
  956. if ((pPacketToBeQueued != (PNDIS_PACKET)NULL) && (!PacketWasQueued))
  957. {
  958. AA_HEADER_TYPE HdrType;
  959. BOOLEAN HdrPresent;
  960. if (pFlowSpec->Encapsulation == ENCAPSULATION_TYPE_LLCSNAP)
  961. {
  962. HdrPresent = TRUE;
  963. if (AA_IS_FLAG_SET(Flags,
  964. AA_ATM_ENTRY_TYPE_MASK,
  965. AA_ATM_ENTRY_TYPE_UCAST))
  966. {
  967. HdrType = AA_HEADER_TYPE_UNICAST;
  968. }
  969. else
  970. {
  971. HdrType = AA_HEADER_TYPE_NUNICAST;
  972. }
  973. }
  974. else
  975. {
  976. HdrPresent = FALSE;
  977. HdrType = AA_HEADER_TYPE_NONE;
  978. }
  979. AtmArpFreeSendPackets(
  980. pInterface,
  981. pPacketToBeQueued,
  982. HdrPresent
  983. );
  984. }
  985. }
  986. AADEBUGP(AAD_VERY_LOUD, ("Make Call: VC: 0x%x, returning status 0x%x\n",
  987. pVc, Status));
  988. return Status;
  989. }
  990. VOID
  991. AtmArpFillCallParameters(
  992. IN PCO_CALL_PARAMETERS pCallParameters,
  993. IN ULONG ParametersSize,
  994. IN PATM_ADDRESS pCalledAddress,
  995. IN PATM_ADDRESS pCallingAddress,
  996. IN PATMARP_FLOW_SPEC pFlowSpec,
  997. IN BOOLEAN IsPMP,
  998. IN BOOLEAN IsMakeCall
  999. )
  1000. /*++
  1001. Routine Description:
  1002. Fill in a Call Parameters structure with the given information,
  1003. thus making it ready for use in an NdisClMakeCall/NdisClAddParty
  1004. call.
  1005. Arguments:
  1006. pCallParameters - points to structure to be filled in.
  1007. ParametersSize - size of the above
  1008. pCalledAddress - points to called ATM address
  1009. pCallingAddress - points to calling ATM address
  1010. pFlowSpec - points to Flow spec for this connection
  1011. IsPMP - Is this a point to multipoint connection?
  1012. IsMakeCall - Is this for MakeCall (FALSE => AddParty)
  1013. Return Value:
  1014. None
  1015. --*/
  1016. {
  1017. PCO_CALL_MANAGER_PARAMETERS pCallMgrParameters;
  1018. PQ2931_CALLMGR_PARAMETERS pAtmCallMgrParameters;
  1019. //
  1020. // All Info Elements that we need to fill:
  1021. //
  1022. Q2931_IE UNALIGNED * pIe;
  1023. AAL_PARAMETERS_IE UNALIGNED * pAalIe;
  1024. ATM_TRAFFIC_DESCRIPTOR_IE UNALIGNED * pTrafficDescriptor;
  1025. ATM_BROADBAND_BEARER_CAPABILITY_IE UNALIGNED * pBbc;
  1026. ATM_BLLI_IE UNALIGNED * pBlli;
  1027. ATM_QOS_CLASS_IE UNALIGNED * pQos;
  1028. //
  1029. // Zero out everything. Don't remove this!
  1030. //
  1031. AA_SET_MEM((PUCHAR)pCallParameters, 0, ParametersSize);
  1032. //
  1033. // Distribute space amongst the various structures
  1034. //
  1035. pCallMgrParameters = (PCO_CALL_MANAGER_PARAMETERS)
  1036. ((PUCHAR)pCallParameters +
  1037. sizeof(CO_CALL_PARAMETERS));
  1038. //
  1039. // Set pointers to link the above structures together
  1040. //
  1041. pCallParameters->CallMgrParameters = pCallMgrParameters;
  1042. pCallParameters->MediaParameters = (PCO_MEDIA_PARAMETERS)NULL;
  1043. pCallMgrParameters->CallMgrSpecific.ParamType = 0;
  1044. pCallMgrParameters->CallMgrSpecific.Length =
  1045. sizeof(Q2931_CALLMGR_PARAMETERS) +
  1046. (IsMakeCall? ATMARP_MAKE_CALL_IE_SPACE: ATMARP_ADD_PARTY_IE_SPACE);
  1047. pAtmCallMgrParameters = (PQ2931_CALLMGR_PARAMETERS)
  1048. pCallMgrParameters->CallMgrSpecific.Parameters;
  1049. if (IsPMP)
  1050. {
  1051. pCallParameters->Flags |= MULTIPOINT_VC;
  1052. }
  1053. //
  1054. // Call Manager generic flow parameters:
  1055. //
  1056. pCallMgrParameters->Transmit.TokenRate = (pFlowSpec->SendAvgBandwidth);
  1057. pCallMgrParameters->Transmit.TokenBucketSize = (pFlowSpec->SendMaxSize);
  1058. pCallMgrParameters->Transmit.MaxSduSize = pFlowSpec->SendMaxSize;
  1059. pCallMgrParameters->Transmit.PeakBandwidth = (pFlowSpec->SendPeakBandwidth);
  1060. pCallMgrParameters->Transmit.ServiceType = pFlowSpec->SendServiceType;
  1061. if ((!IsPMP) && (IsMakeCall))
  1062. {
  1063. pCallMgrParameters->Receive.TokenRate = (pFlowSpec->ReceiveAvgBandwidth);
  1064. pCallMgrParameters->Receive.TokenBucketSize = pFlowSpec->ReceiveMaxSize;
  1065. pCallMgrParameters->Receive.MaxSduSize = pFlowSpec->ReceiveMaxSize;
  1066. pCallMgrParameters->Receive.PeakBandwidth = (pFlowSpec->ReceivePeakBandwidth);
  1067. pCallMgrParameters->Receive.ServiceType = pFlowSpec->ReceiveServiceType;
  1068. }
  1069. else
  1070. {
  1071. //
  1072. // else receive side values are 0's.
  1073. //
  1074. pCallMgrParameters->Receive.ServiceType = SERVICETYPE_NOTRAFFIC;
  1075. }
  1076. //
  1077. // Q2931 Call Manager Parameters:
  1078. //
  1079. //
  1080. // Called address:
  1081. //
  1082. // TBD: Add Called Subaddress IE in outgoing call.
  1083. //
  1084. AA_COPY_MEM((PUCHAR)&(pAtmCallMgrParameters->CalledParty),
  1085. (PUCHAR)pCalledAddress,
  1086. sizeof(ATM_ADDRESS));
  1087. //
  1088. // Calling address:
  1089. //
  1090. AA_COPY_MEM((PUCHAR)&(pAtmCallMgrParameters->CallingParty),
  1091. (PUCHAR)pCallingAddress,
  1092. sizeof(ATM_ADDRESS));
  1093. //
  1094. // RFC 1755 (Sec 5) says that the following IEs MUST be present in the
  1095. // SETUP message, so fill them all.
  1096. //
  1097. // AAL Parameters
  1098. // Traffic Descriptor (only for MakeCall)
  1099. // Broadband Bearer Capability (only for MakeCall)
  1100. // Broadband Low Layer Info
  1101. // QoS (only for MakeCall)
  1102. //
  1103. //
  1104. // Initialize the Info Element list
  1105. //
  1106. pAtmCallMgrParameters->InfoElementCount = 0;
  1107. pIe = (PQ2931_IE)(pAtmCallMgrParameters->InfoElements);
  1108. //
  1109. // AAL Parameters:
  1110. //
  1111. {
  1112. UNALIGNED AAL5_PARAMETERS *pAal5;
  1113. pIe->IEType = IE_AALParameters;
  1114. pIe->IELength = SIZEOF_Q2931_IE + SIZEOF_AAL_PARAMETERS_IE;
  1115. pAalIe = (PAAL_PARAMETERS_IE)pIe->IE;
  1116. pAalIe->AALType = AAL_TYPE_AAL5;
  1117. pAal5 = &(pAalIe->AALSpecificParameters.AAL5Parameters);
  1118. pAal5->ForwardMaxCPCSSDUSize = pFlowSpec->SendMaxSize;
  1119. pAal5->BackwardMaxCPCSSDUSize = pFlowSpec->ReceiveMaxSize;
  1120. }
  1121. pAtmCallMgrParameters->InfoElementCount++;
  1122. pIe = (PQ2931_IE)((PUCHAR)pIe + pIe->IELength);
  1123. #ifdef PREPARE_IES_OURSELVES
  1124. //
  1125. // Let the Call Manager convert from generic flow spec to Traffic Descr,
  1126. // Broadband Bearer Cap, and QoS.
  1127. //
  1128. //
  1129. // Traffic Descriptor:
  1130. //
  1131. if (IsMakeCall)
  1132. {
  1133. pIe->IEType = IE_TrafficDescriptor;
  1134. pIe->IELength = SIZEOF_Q2931_IE + SIZEOF_ATM_TRAFFIC_DESCR_IE;
  1135. pTrafficDescriptor = (PATM_TRAFFIC_DESCRIPTOR_IE)pIe->IE;
  1136. if (pFlowSpec->SendServiceType == SERVICETYPE_BESTEFFORT)
  1137. {
  1138. pTrafficDescriptor->ForwardTD.PeakCellRateCLP01 =
  1139. BYTES_TO_CELLS(pFlowSpec->SendPeakBandwidth);
  1140. if (!IsPMP)
  1141. {
  1142. pTrafficDescriptor->BackwardTD.PeakCellRateCLP01 =
  1143. BYTES_TO_CELLS(pFlowSpec->ReceivePeakBandwidth);
  1144. }
  1145. //
  1146. // else we have zero'ed out everything, which is what we want.
  1147. //
  1148. pTrafficDescriptor->BestEffort = TRUE;
  1149. }
  1150. else
  1151. {
  1152. // Predictive/Guaranteed service (we map this to CBR, see BBC below)
  1153. pTrafficDescriptor->ForwardTD.PeakCellRateCLP01 =
  1154. BYTES_TO_CELLS(pFlowSpec->SendPeakBandwidth);
  1155. if (!IsPMP)
  1156. {
  1157. pTrafficDescriptor->BackwardTD.PeakCellRateCLP01 =
  1158. BYTES_TO_CELLS(pFlowSpec->ReceivePeakBandwidth);
  1159. }
  1160. //
  1161. // else we have zero'ed out everything, which is what we want.
  1162. //
  1163. pTrafficDescriptor->BestEffort = FALSE;
  1164. }
  1165. pAtmCallMgrParameters->InfoElementCount++;
  1166. pIe = (PQ2931_IE)((PUCHAR)pIe + pIe->IELength);
  1167. }
  1168. //
  1169. // Broadband Bearer Capability
  1170. //
  1171. if (IsMakeCall)
  1172. {
  1173. pIe->IEType = IE_BroadbandBearerCapability;
  1174. pIe->IELength = SIZEOF_Q2931_IE + SIZEOF_ATM_BBC_IE;
  1175. pBbc = (PATM_BROADBAND_BEARER_CAPABILITY_IE)pIe->IE;
  1176. pBbc->BearerClass = BCOB_X;
  1177. pBbc->UserPlaneConnectionConfig = (IsPMP ? UP_P2MP: UP_P2P);
  1178. if (pFlowSpec->SendServiceType == SERVICETYPE_BESTEFFORT)
  1179. {
  1180. pBbc->TrafficType = TT_NOIND;
  1181. pBbc->TimingRequirements = TR_NOIND;
  1182. pBbc->ClippingSusceptability = CLIP_NOT;
  1183. }
  1184. else
  1185. {
  1186. pBbc->TrafficType = TT_CBR;
  1187. pBbc->TimingRequirements = TR_END_TO_END;
  1188. pBbc->ClippingSusceptability = CLIP_SUS;
  1189. }
  1190. pAtmCallMgrParameters->InfoElementCount++;
  1191. pIe = (PQ2931_IE)((PUCHAR)pIe + pIe->IELength);
  1192. }
  1193. #endif // PREPARE_IES_OURSELVES
  1194. //
  1195. // Broadband Lower Layer Information
  1196. //
  1197. pIe->IEType = IE_BLLI;
  1198. pIe->IELength = SIZEOF_Q2931_IE + SIZEOF_ATM_BLLI_IE;
  1199. pBlli = (PATM_BLLI_IE)pIe->IE;
  1200. AA_COPY_MEM((PUCHAR)pBlli,
  1201. (PUCHAR)&AtmArpDefaultBlli,
  1202. sizeof(ATM_BLLI_IE));
  1203. pAtmCallMgrParameters->InfoElementCount++;
  1204. pIe = (PQ2931_IE)((PUCHAR)pIe + pIe->IELength);
  1205. #ifdef PREPARE_IES_OURSELVES
  1206. //
  1207. // QoS
  1208. //
  1209. if (IsMakeCall)
  1210. {
  1211. pIe->IEType = IE_QOSClass;
  1212. pIe->IELength = SIZEOF_Q2931_IE + SIZEOF_ATM_QOS_IE;
  1213. pQos = (PATM_QOS_CLASS_IE)pIe->IE;
  1214. if (pFlowSpec->SendServiceType == SERVICETYPE_BESTEFFORT)
  1215. {
  1216. pQos->QOSClassForward = pQos->QOSClassBackward = 0;
  1217. }
  1218. else
  1219. {
  1220. pQos->QOSClassForward = pQos->QOSClassBackward = 1;
  1221. }
  1222. pAtmCallMgrParameters->InfoElementCount++;
  1223. pIe = (PQ2931_IE)((PUCHAR)pIe + pIe->IELength);
  1224. }
  1225. #endif // PREPARE_IES_OURSELVES
  1226. }
  1227. #ifdef IPMCAST
  1228. BOOLEAN
  1229. AtmArpMcPrepareAtmEntryForClose(
  1230. IN PATMARP_ATM_ENTRY pAtmEntry LOCKIN LOCKOUT
  1231. )
  1232. /*++
  1233. Routine Description:
  1234. Prepare an ATM Entry that has an outgoing PMP call on it, for Close Call.
  1235. This means that we drop all but the last leaf on this PMP call.
  1236. NOTE: The caller is assumed to hold the ATM Entry lock
  1237. Arguments:
  1238. pAtmEntry - Points to ATM Entry representing a PMP call
  1239. Return Value:
  1240. TRUE iff the connection on this ATM Entry is ready for CloseCall.
  1241. --*/
  1242. {
  1243. PATMARP_IPMC_ATM_ENTRY pMcAtmEntry;
  1244. PATMARP_IPMC_ATM_ENTRY pNextMcAtmEntry;
  1245. PATMARP_INTERFACE pInterface;
  1246. NDIS_HANDLE NdisPartyHandle;
  1247. NDIS_STATUS Status;
  1248. AA_ASSERT(pAtmEntry->pMcAtmInfo->TransientLeaves == 0);
  1249. AA_ASSERT(pAtmEntry->pVcList != NULL_PATMARP_VC);
  1250. pInterface = pAtmEntry->pInterface;
  1251. AAMCDEBUGP(AAD_EXTRA_LOUD,
  1252. ("McPrepareAtmEntryForClose: pAtmEntry 0x%x, McList 0x%x, ActiveLeaves %d\n",
  1253. pAtmEntry,
  1254. pAtmEntry->pMcAtmInfo->pMcAtmEntryList,
  1255. pAtmEntry->pMcAtmInfo->ActiveLeaves));
  1256. //
  1257. // First, prune all members that aren't connected.
  1258. //
  1259. for (pMcAtmEntry = pAtmEntry->pMcAtmInfo->pMcAtmEntryList;
  1260. pMcAtmEntry != NULL_PATMARP_IPMC_ATM_ENTRY;
  1261. pMcAtmEntry = pNextMcAtmEntry)
  1262. {
  1263. pNextMcAtmEntry = pMcAtmEntry->pNextMcAtmEntry;
  1264. //
  1265. // Stop any timer running here.
  1266. //
  1267. (VOID)AtmArpStopTimer(&(pMcAtmEntry->Timer), pInterface);
  1268. if (AA_IS_FLAG_SET(pMcAtmEntry->Flags,
  1269. AA_IPMC_AE_CONN_STATE_MASK,
  1270. AA_IPMC_AE_CONN_DISCONNECTED))
  1271. {
  1272. AtmArpMcUnlinkAtmMember(
  1273. pAtmEntry,
  1274. pMcAtmEntry
  1275. );
  1276. }
  1277. }
  1278. //
  1279. // Next, send drop party requests for all but one member.
  1280. //
  1281. while (pAtmEntry->pMcAtmInfo->ActiveLeaves > 1)
  1282. {
  1283. for (pMcAtmEntry = pAtmEntry->pMcAtmInfo->pMcAtmEntryList;
  1284. /* NONE */;
  1285. pMcAtmEntry = pMcAtmEntry->pNextMcAtmEntry)
  1286. {
  1287. AA_ASSERT(pMcAtmEntry != NULL_PATMARP_IPMC_ATM_ENTRY);
  1288. if (AA_IS_FLAG_SET(pMcAtmEntry->Flags,
  1289. AA_IPMC_AE_CONN_STATE_MASK,
  1290. AA_IPMC_AE_CONN_ACTIVE))
  1291. {
  1292. break;
  1293. }
  1294. }
  1295. NdisPartyHandle = pMcAtmEntry->NdisPartyHandle;
  1296. AAMCDEBUGP(AAD_INFO,
  1297. ("PrepareAtmEntry: pAtmEntry 0x%x, will DropPty, McAtmEnt 0x%x, PtyHnd 0x%x\n",
  1298. pAtmEntry, pMcAtmEntry, NdisPartyHandle));
  1299. AA_SET_FLAG(pMcAtmEntry->Flags,
  1300. AA_IPMC_AE_CONN_STATE_MASK,
  1301. AA_IPMC_AE_CONN_WACK_DROP_PARTY);
  1302. pAtmEntry->pMcAtmInfo->ActiveLeaves--;
  1303. AA_RELEASE_AE_LOCK(pAtmEntry);
  1304. Status = NdisClDropParty(
  1305. NdisPartyHandle,
  1306. NULL, // Buffer
  1307. (UINT)0 // Size
  1308. );
  1309. if (Status != NDIS_STATUS_PENDING)
  1310. {
  1311. AtmArpDropPartyCompleteHandler(
  1312. Status,
  1313. (NDIS_HANDLE)pMcAtmEntry
  1314. );
  1315. }
  1316. AA_ACQUIRE_AE_LOCK(pAtmEntry);
  1317. }
  1318. //
  1319. // Now, if we have exactly one ATM member in the list of
  1320. // leaves for this PMP, we can CloseCall.
  1321. //
  1322. if (pAtmEntry->pMcAtmInfo->pMcAtmEntryList->pNextMcAtmEntry ==
  1323. NULL_PATMARP_IPMC_ATM_ENTRY)
  1324. {
  1325. return (TRUE);
  1326. }
  1327. else
  1328. {
  1329. return (FALSE);
  1330. }
  1331. }
  1332. #endif // IPMCAST
  1333. VOID
  1334. AtmArpCloseCall(
  1335. IN PATMARP_VC pVc LOCKIN NOLOCKOUT
  1336. )
  1337. /*++
  1338. Routine Description:
  1339. Closes an existing call on a VC. It is assumed that a call exists
  1340. on the VC.
  1341. NOTE: The caller is assumed to hold a lock to the VC structure,
  1342. and it will be released here.
  1343. SIDE EFFECT: If the NDIS call returns other than NDIS_STATUS_PENDING,
  1344. we call our CloseCall Complete handler from here.
  1345. Arguments:
  1346. pVc - Pointer to ATMARP VC structure.
  1347. Return Value:
  1348. None
  1349. --*/
  1350. {
  1351. PATMARP_INTERFACE pInterface;
  1352. PATMARP_ATM_ENTRY pAtmEntry;
  1353. NDIS_HANDLE NdisVcHandle;
  1354. NDIS_HANDLE ProtocolVcContext;
  1355. #ifdef IPMCAST
  1356. NDIS_HANDLE NdisPartyHandle;
  1357. #endif
  1358. NDIS_STATUS Status;
  1359. PNDIS_PACKET PacketList; // Packets queued on this VC
  1360. AA_HEADER_TYPE HdrType; // for queued packets
  1361. BOOLEAN HdrPresent; // for queued packets
  1362. BOOLEAN WasRunning; // Was a timer running on this VC?
  1363. BOOLEAN IsPMP; // Is this a PMP call?
  1364. ULONG rc; // Ref Count on this VC.
  1365. AA_STRUCT_ASSERT(pVc, avc);
  1366. NdisVcHandle = pVc->NdisVcHandle;
  1367. ProtocolVcContext = (NDIS_HANDLE)pVc;
  1368. pInterface = pVc->pInterface;
  1369. IsPMP = AA_IS_FLAG_SET(pVc->Flags,
  1370. AA_VC_CONN_TYPE_MASK,
  1371. AA_VC_CONN_TYPE_PMP);
  1372. AADEBUGP(AAD_INFO,
  1373. ("Closing call on VC 0x%x, VC Flags 0x%x, Ref %d, NdisVcHandle 0x%x\n",
  1374. pVc, pVc->Flags, pVc->RefCount, NdisVcHandle));
  1375. //
  1376. // Remove the list of packets queued on this VC.
  1377. //
  1378. PacketList = pVc->PacketList;
  1379. pVc->PacketList = (PNDIS_PACKET)NULL;
  1380. if (pVc->FlowSpec.Encapsulation == ENCAPSULATION_TYPE_LLCSNAP)
  1381. {
  1382. HdrType = (IsPMP ? AA_HEADER_TYPE_NUNICAST: AA_HEADER_TYPE_UNICAST);
  1383. HdrPresent = TRUE;
  1384. }
  1385. else
  1386. {
  1387. HdrType = AA_HEADER_TYPE_NONE;
  1388. HdrPresent = FALSE;
  1389. }
  1390. //
  1391. // Stop any timer running on this VC.
  1392. //
  1393. WasRunning = AtmArpStopTimer(&(pVc->Timer), pInterface);
  1394. if (WasRunning)
  1395. {
  1396. //
  1397. // Remove the timer reference on this VC.
  1398. //
  1399. rc = AtmArpDereferenceVc(pVc);
  1400. }
  1401. else
  1402. {
  1403. rc = pVc->RefCount;
  1404. }
  1405. #ifdef GPC
  1406. //
  1407. // If this VC is associated with a Flow, unlink them.
  1408. //
  1409. if (rc != 0)
  1410. {
  1411. if (pVc->FlowHandle != NULL)
  1412. {
  1413. PATMARP_FLOW_INFO pFlowInfo = (PATMARP_FLOW_INFO)pVc->FlowHandle;
  1414. if ((PVOID)pVc == InterlockedCompareExchangePointer(
  1415. &(pFlowInfo->VcContext),
  1416. NULL,
  1417. pVc
  1418. ))
  1419. {
  1420. pVc->FlowHandle = NULL;
  1421. rc = AtmArpDereferenceVc(pVc); // Unlink from GPC Flow
  1422. }
  1423. }
  1424. }
  1425. #endif // GPC
  1426. if (rc != 0)
  1427. {
  1428. //
  1429. // Check the call state on this VC. If the call is active and
  1430. // we have no sends going on, then we close the call.
  1431. // Otherwise, simply mark the VC as closing. We will continue
  1432. // this process when the current operation on the VC completes.
  1433. //
  1434. if (AA_IS_FLAG_SET(pVc->Flags,
  1435. AA_VC_CALL_STATE_MASK,
  1436. AA_VC_CALL_STATE_ACTIVE) &&
  1437. (pVc->OutstandingSends == 0))
  1438. {
  1439. //
  1440. // Set VC call state to "Close Call in progress" so that we don't
  1441. // reenter here.
  1442. //
  1443. AA_SET_FLAG(
  1444. pVc->Flags,
  1445. AA_VC_CALL_STATE_MASK,
  1446. AA_VC_CALL_STATE_CLOSE_IN_PROGRESS);
  1447. #ifdef IPMCAST
  1448. if (IsPMP)
  1449. {
  1450. PATMARP_IPMC_ATM_ENTRY pMcAtmEntry; // last leaf
  1451. pAtmEntry = pVc->pAtmEntry;
  1452. AA_ASSERT(pAtmEntry != NULL_PATMARP_ATM_ENTRY);
  1453. AA_ASSERT(pAtmEntry->pMcAtmInfo != NULL_PATMARP_IPMC_ATM_INFO);
  1454. if (pAtmEntry->pMcAtmInfo->TransientLeaves == 0)
  1455. {
  1456. //
  1457. // No AddParty in progress.
  1458. //
  1459. AA_RELEASE_VC_LOCK(pVc);
  1460. AA_ACQUIRE_AE_LOCK(pAtmEntry);
  1461. if (AtmArpMcPrepareAtmEntryForClose(pAtmEntry))
  1462. {
  1463. //
  1464. // The entry is ready for CloseCall.
  1465. //
  1466. AAMCDEBUGP(AAD_LOUD,
  1467. ("CloseCall (MC): pAtmEntry 0x%x, ready for close\n", pAtmEntry));
  1468. //
  1469. // Get the party handle of the last leaf, and unlink
  1470. // it from the PMP structure.
  1471. //
  1472. AA_ASSERT(pAtmEntry->pMcAtmInfo->pMcAtmEntryList !=
  1473. NULL_PATMARP_IPMC_ATM_ENTRY);
  1474. pMcAtmEntry = pVc->pAtmEntry->pMcAtmInfo->pMcAtmEntryList;
  1475. NdisPartyHandle = pMcAtmEntry->NdisPartyHandle;
  1476. AA_SET_FLAG(pMcAtmEntry->Flags,
  1477. AA_IPMC_AE_CONN_STATE_MASK,
  1478. AA_IPMC_AE_CONN_WACK_DROP_PARTY);
  1479. pAtmEntry->pMcAtmInfo->ActiveLeaves--;
  1480. AA_ASSERT(pAtmEntry->pMcAtmInfo->ActiveLeaves == 0);
  1481. AA_RELEASE_AE_LOCK(pAtmEntry);
  1482. AA_ACQUIRE_VC_LOCK(pVc);
  1483. }
  1484. else
  1485. {
  1486. AA_RELEASE_AE_LOCK(pAtmEntry);
  1487. AA_ACQUIRE_VC_LOCK(pVc);
  1488. //
  1489. // There are pending DropParty calls. Mark this VC
  1490. // so that we trigger a CloseCall when all DropParty
  1491. // calls complete.
  1492. //
  1493. AA_SET_FLAG(pVc->Flags,
  1494. AA_VC_CLOSE_STATE_MASK,
  1495. AA_VC_CLOSE_STATE_CLOSING);
  1496. NdisVcHandle = NULL; // Don't close call now
  1497. }
  1498. }
  1499. else
  1500. {
  1501. //
  1502. // There are pending AddParty calls. Mark this VC
  1503. // so that we trigger a CloseCall when all AddParty
  1504. // calls complete.
  1505. //
  1506. AA_SET_FLAG(pVc->Flags,
  1507. AA_VC_CLOSE_STATE_MASK,
  1508. AA_VC_CLOSE_STATE_CLOSING);
  1509. NdisVcHandle = NULL; // Don't close call now
  1510. }
  1511. }
  1512. else
  1513. {
  1514. NdisPartyHandle = NULL;
  1515. }
  1516. if (NdisVcHandle != NULL)
  1517. {
  1518. AA_RELEASE_VC_LOCK(pVc);
  1519. Status = NdisClCloseCall(
  1520. NdisVcHandle,
  1521. NdisPartyHandle,
  1522. (PVOID)NULL, // No Buffer
  1523. (UINT)0 // Size of above
  1524. );
  1525. if (Status != NDIS_STATUS_PENDING)
  1526. {
  1527. AtmArpCloseCallCompleteHandler(
  1528. Status,
  1529. ProtocolVcContext,
  1530. (NDIS_HANDLE)NULL
  1531. );
  1532. }
  1533. }
  1534. else
  1535. {
  1536. //
  1537. // Set the call state back to what it was.
  1538. //
  1539. AA_SET_FLAG(
  1540. pVc->Flags,
  1541. AA_VC_CALL_STATE_MASK,
  1542. AA_VC_CALL_STATE_ACTIVE);
  1543. AA_RELEASE_VC_LOCK(pVc);
  1544. }
  1545. #else
  1546. AA_RELEASE_VC_LOCK(pVc);
  1547. Status = NdisClCloseCall(
  1548. NdisVcHandle,
  1549. NULL, // NdisPartyHandle
  1550. (PVOID)NULL, // No Buffer
  1551. (UINT)0 // Size of above
  1552. );
  1553. if (Status != NDIS_STATUS_PENDING)
  1554. {
  1555. AtmArpCloseCallCompleteHandler(
  1556. Status,
  1557. ProtocolVcContext,
  1558. (NDIS_HANDLE)NULL
  1559. );
  1560. }
  1561. #endif // IPMCAST
  1562. }
  1563. else
  1564. {
  1565. //
  1566. // Some operation is going on here (call setup/close/send). Mark this
  1567. // VC so that we know what to do when this operation completes.
  1568. //
  1569. AA_SET_FLAG(
  1570. pVc->Flags,
  1571. AA_VC_CLOSE_STATE_MASK,
  1572. AA_VC_CLOSE_STATE_CLOSING);
  1573. AA_RELEASE_VC_LOCK(pVc);
  1574. }
  1575. }
  1576. //
  1577. // else the VC is gone.
  1578. //
  1579. //
  1580. // Free any packets queued on this VC
  1581. //
  1582. if (PacketList != (PNDIS_PACKET)NULL)
  1583. {
  1584. AtmArpFreeSendPackets(
  1585. pInterface,
  1586. PacketList,
  1587. HdrPresent
  1588. );
  1589. }
  1590. }
  1591. NDIS_STATUS
  1592. AtmArpCreateVcHandler(
  1593. IN NDIS_HANDLE ProtocolAfContext,
  1594. IN NDIS_HANDLE NdisVcHandle,
  1595. OUT PNDIS_HANDLE pProtocolVcContext
  1596. )
  1597. /*++
  1598. Routine Description:
  1599. Entry point called by NDIS when the Call Manager wants to create
  1600. a new endpoint (VC). We allocate a new ATMARP VC structure, and
  1601. return a pointer to it as our VC context.
  1602. Arguments:
  1603. ProtocolAfContext - Actually a pointer to the ATMARP Interface structure
  1604. NdisVcHandle - Handle for this VC for all future references
  1605. pProtocolVcContext - Place where we (protocol) return our context for the VC
  1606. Return Value:
  1607. NDIS_STATUS_SUCCESS if we could create a VC
  1608. NDIS_STATUS_RESOURCES otherwise
  1609. --*/
  1610. {
  1611. PATMARP_INTERFACE pInterface;
  1612. PATMARP_VC pVc;
  1613. NDIS_STATUS Status;
  1614. pInterface = (PATMARP_INTERFACE)ProtocolAfContext;
  1615. pVc = AtmArpAllocateVc(pInterface);
  1616. if (pVc != NULL_PATMARP_VC)
  1617. {
  1618. *pProtocolVcContext = (NDIS_HANDLE)pVc;
  1619. pVc->NdisVcHandle = NdisVcHandle;
  1620. pVc->Flags = AA_VC_OWNER_IS_CALLMGR;
  1621. AtmArpReferenceVc(pVc); // Create VC ref
  1622. Status = NDIS_STATUS_SUCCESS;
  1623. }
  1624. else
  1625. {
  1626. Status = NDIS_STATUS_RESOURCES;
  1627. }
  1628. AADEBUGP(AAD_INFO, ("Create Vc Handler: pVc 0x%x, Status 0x%x\n", pVc, Status));
  1629. return (Status);
  1630. }
  1631. NDIS_STATUS
  1632. AtmArpDeleteVcHandler(
  1633. IN NDIS_HANDLE ProtocolVcContext
  1634. )
  1635. /*++
  1636. Routine Description:
  1637. Our Delete VC handler. This VC would have been allocated as a result
  1638. of a previous entry into our CreateVcHandler, and possibly used for
  1639. an incoming call.
  1640. At this time, this VC structure should be free of any calls, and we
  1641. simply free this.
  1642. Arguments:
  1643. ProtocolVcContext - pointer to our VC structure
  1644. Return Value:
  1645. NDIS_STATUS_SUCCESS always
  1646. --*/
  1647. {
  1648. PATMARP_VC pVc;
  1649. ULONG rc; // Ref count on the VC
  1650. pVc = (PATMARP_VC)ProtocolVcContext;
  1651. AA_STRUCT_ASSERT(pVc, avc);
  1652. AA_ASSERT((pVc->Flags & AA_VC_OWNER_MASK) == AA_VC_OWNER_IS_CALLMGR);
  1653. AA_ACQUIRE_VC_LOCK(pVc);
  1654. rc = AtmArpDereferenceVc(pVc);
  1655. if (rc > 0)
  1656. {
  1657. //
  1658. // This can happen if there is a timer still running
  1659. // on this VC. When the timer elapses, the VC will be
  1660. // freed.
  1661. //
  1662. AADEBUGP(AAD_WARNING, ("Delete VC handler: pVc 0x%x, Flags 0x%x, refcount %d, pAtmEntry %x\n",
  1663. pVc, pVc->Flags, rc, pVc->pAtmEntry));
  1664. AA_RELEASE_VC_LOCK(pVc);
  1665. }
  1666. //
  1667. // else the VC is gone.
  1668. //
  1669. AADEBUGP(AAD_LOUD, ("Delete Vc Handler: 0x%x: done\n", pVc));
  1670. return (NDIS_STATUS_SUCCESS);
  1671. }
  1672. NDIS_STATUS
  1673. AtmArpIncomingCallHandler(
  1674. IN NDIS_HANDLE ProtocolSapContext,
  1675. IN NDIS_HANDLE ProtocolVcContext,
  1676. IN OUT PCO_CALL_PARAMETERS pCallParameters
  1677. )
  1678. /*++
  1679. Routine Description:
  1680. This handler is called when there is an incoming call matching our
  1681. SAP. This could be either an SVC or a PVC. In either case, we store
  1682. FlowSpec information from the incoming call in the VC structure, making
  1683. sure that the MTU for the interface is not violated.
  1684. For an SVC, we expect a Calling Address to be present in the call,
  1685. otherwise we reject the call. If an ATM Entry with this address exists,
  1686. this VC is linked to that entry, otherwise a new entry with this address
  1687. is created.
  1688. In the case of a PVC, we ignore any Calling Address information, and
  1689. depend on InATMARP to resolve the ATM Address as well as the IP address
  1690. of the other end.
  1691. Arguments:
  1692. ProtocolSapContext - Pointer to ATMARP Interface structure
  1693. ProtocolVcContext - Pointer to ATMARP VC structure
  1694. pCallParameters - Call parameters
  1695. Return Value:
  1696. NDIS_STATUS_SUCCESS if we accept this call
  1697. NDIS_STATUS_FAILURE if we reject it.
  1698. --*/
  1699. {
  1700. PATMARP_VC pVc;
  1701. PATMARP_ATM_ENTRY pAtmEntry;
  1702. PATMARP_INTERFACE pInterface;
  1703. CO_CALL_MANAGER_PARAMETERS UNALIGNED * pCallMgrParameters;
  1704. Q2931_CALLMGR_PARAMETERS UNALIGNED * pAtmCallMgrParameters;
  1705. //
  1706. // To traverse the list of Info Elements
  1707. //
  1708. Q2931_IE UNALIGNED * pIe;
  1709. ULONG InfoElementCount;
  1710. //
  1711. // Info Elements in the incoming call, that are of interest to us.
  1712. // Initialize these to <not present>.
  1713. //
  1714. ATM_ADDRESS UNALIGNED * pCallingAddress = NULL;
  1715. ATM_CALLING_PARTY_SUBADDRESS_IE UNALIGNED * pCallingSubaddressIe = NULL;
  1716. ATM_ADDRESS UNALIGNED * pCallingSubaddress = NULL;
  1717. AAL_PARAMETERS_IE UNALIGNED * pAal = NULL;
  1718. ATM_TRAFFIC_DESCRIPTOR_IE UNALIGNED * pTrafficDescriptor = NULL;
  1719. ATM_BROADBAND_BEARER_CAPABILITY_IE UNALIGNED * pBbc = NULL;
  1720. ATM_BLLI_IE UNALIGNED * pBlli = NULL;
  1721. ATM_QOS_CLASS_IE UNALIGNED * pQos = NULL;
  1722. AAL5_PARAMETERS UNALIGNED * pAal5;
  1723. UCHAR AddrTypeLen;
  1724. UCHAR SubaddrTypeLen;
  1725. PUCHAR pAtmSubaddress;
  1726. NDIS_STATUS Status;
  1727. pVc = (PATMARP_VC)ProtocolVcContext;
  1728. AA_STRUCT_ASSERT(pVc, avc);
  1729. AA_ASSERT((pVc->Flags & AA_VC_TYPE_MASK) == AA_VC_TYPE_UNUSED);
  1730. AA_ASSERT((pVc->Flags & AA_VC_OWNER_MASK) == AA_VC_OWNER_IS_CALLMGR);
  1731. AA_ASSERT((pVc->Flags & AA_VC_CALL_STATE_MASK) == AA_VC_CALL_STATE_IDLE);
  1732. pInterface = pVc->pInterface;
  1733. AADEBUGP(AAD_LOUD, ("Incoming Call: IF 0x%x, VC 0x%x, pCallParams 0x%x\n",
  1734. pInterface, pVc, pCallParameters));
  1735. do
  1736. {
  1737. if (pInterface->AdminState != IF_STATUS_UP)
  1738. {
  1739. Status = NDIS_STATUS_FAILURE;
  1740. break;
  1741. }
  1742. //
  1743. // Get the following info from the Incoming call:
  1744. // Calling Address
  1745. // AAL Parameters
  1746. // Traffic Descriptor
  1747. // Broadband Bearer Capability
  1748. // QoS
  1749. //
  1750. pCallMgrParameters = pCallParameters->CallMgrParameters;
  1751. pAtmCallMgrParameters = (PQ2931_CALLMGR_PARAMETERS)
  1752. pCallParameters->CallMgrParameters->CallMgrSpecific.Parameters;
  1753. pCallingAddress = &(pAtmCallMgrParameters->CallingParty);
  1754. InfoElementCount = pAtmCallMgrParameters->InfoElementCount;
  1755. pIe = (PQ2931_IE)(pAtmCallMgrParameters->InfoElements);
  1756. while (InfoElementCount--)
  1757. {
  1758. switch (pIe->IEType)
  1759. {
  1760. case IE_AALParameters:
  1761. pAal = (PAAL_PARAMETERS_IE)(pIe->IE);
  1762. break;
  1763. case IE_TrafficDescriptor:
  1764. pTrafficDescriptor = (PATM_TRAFFIC_DESCRIPTOR_IE)(pIe->IE);
  1765. break;
  1766. case IE_BroadbandBearerCapability:
  1767. pBbc = (PATM_BROADBAND_BEARER_CAPABILITY_IE)(pIe->IE);
  1768. break;
  1769. case IE_QOSClass:
  1770. pQos = (PATM_QOS_CLASS_IE)(pIe->IE);
  1771. break;
  1772. case IE_CallingPartySubaddress:
  1773. pCallingSubaddressIe = (ATM_CALLING_PARTY_SUBADDRESS_IE *)(pIe->IE);
  1774. pCallingSubaddress = pCallingSubaddressIe;
  1775. break;
  1776. default:
  1777. break;
  1778. }
  1779. pIe = (PQ2931_IE)((PUCHAR)pIe + pIe->IELength);
  1780. }
  1781. if ((pCallParameters->Flags & PERMANENT_VC) == 0)
  1782. {
  1783. //
  1784. // This is an SVC.
  1785. //
  1786. //
  1787. // Make sure all mandatory IEs are present. If not, reject the call
  1788. //
  1789. if ((pAal == (PAAL_PARAMETERS_IE)NULL) ||
  1790. (pTrafficDescriptor == (PATM_TRAFFIC_DESCRIPTOR_IE)NULL) ||
  1791. (pBbc == (PATM_BROADBAND_BEARER_CAPABILITY_IE)NULL) ||
  1792. (pQos == (PATM_QOS_CLASS_IE)NULL))
  1793. {
  1794. AADEBUGP(AAD_WARNING,
  1795. ("In call: IE missing: AAL 0x%x, TRAF 0x%x, BBC 0x%x, QOS 0x%x",
  1796. pAal,
  1797. pTrafficDescriptor,
  1798. pBbc,
  1799. pQos));
  1800. Status = NDIS_STATUS_AAL_PARAMS_UNSUPPORTED;
  1801. break;
  1802. }
  1803. //
  1804. // We insist on the Calling Address
  1805. // being present, as well
  1806. //
  1807. if (pCallingAddress->NumberOfDigits == 0)
  1808. {
  1809. AADEBUGP(AAD_WARNING, ("In call: calling address missing for SVC\n"));
  1810. Status = NDIS_STATUS_INVALID_ADDRESS;
  1811. break;
  1812. }
  1813. }
  1814. if (pAal != NULL)
  1815. {
  1816. //
  1817. // Make sure that the requested MTU values aren't beyond our
  1818. // capabilities:
  1819. //
  1820. pAal5 = &(pAal->AALSpecificParameters.AAL5Parameters);
  1821. if (pAal5->ForwardMaxCPCSSDUSize > pInterface->pAdapter->MaxPacketSize)
  1822. {
  1823. pAal5->ForwardMaxCPCSSDUSize = pInterface->pAdapter->MaxPacketSize;
  1824. }
  1825. if (pAal5->BackwardMaxCPCSSDUSize > pInterface->pAdapter->MaxPacketSize)
  1826. {
  1827. pAal5->BackwardMaxCPCSSDUSize = pInterface->pAdapter->MaxPacketSize;
  1828. }
  1829. }
  1830. #ifdef PREPARE_IES_OURSELVES
  1831. //
  1832. // Get the Flow Specs for this VC from the ATM Info Elements
  1833. //
  1834. pVc->FlowSpec.SendPeakBandwidth =
  1835. CELLS_TO_BYTES(pTrafficDescriptor->ForwardTD.PeakCellRateCLP01);
  1836. pVc->FlowSpec.SendMaxSize = pAal5->ForwardMaxCPCSSDUSize;
  1837. pVc->FlowSpec.ReceivePeakBandwidth =
  1838. CELLS_TO_BYTES(pTrafficDescriptor->BackwardTD.PeakCellRateCLP01);
  1839. pVc->FlowSpec.ReceiveMaxSize = pAal5->BackwardMaxCPCSSDUSize;
  1840. if ((pQos->QOSClassForward == 0) || (pQos->QOSClassBackward == 0))
  1841. {
  1842. pVc->FlowSpec.SendServiceType = SERVICETYPE_BESTEFFORT;
  1843. }
  1844. else
  1845. {
  1846. pVc->FlowSpec.SendServiceType = SERVICETYPE_GUARANTEED;
  1847. }
  1848. #else
  1849. //
  1850. // Get the Flow Specs for this VC
  1851. //
  1852. pVc->FlowSpec.SendPeakBandwidth = pCallMgrParameters->Transmit.PeakBandwidth;
  1853. pVc->FlowSpec.SendAvgBandwidth = pCallMgrParameters->Transmit.TokenRate;
  1854. pVc->FlowSpec.SendMaxSize = pCallMgrParameters->Transmit.MaxSduSize;
  1855. pVc->FlowSpec.SendServiceType = pCallMgrParameters->Transmit.ServiceType;
  1856. pVc->FlowSpec.ReceivePeakBandwidth = pCallMgrParameters->Receive.PeakBandwidth;
  1857. pVc->FlowSpec.ReceiveAvgBandwidth = pCallMgrParameters->Receive.TokenRate;
  1858. pVc->FlowSpec.ReceiveMaxSize = pCallMgrParameters->Receive.MaxSduSize;
  1859. pVc->FlowSpec.ReceiveServiceType = pCallMgrParameters->Receive.ServiceType;
  1860. #endif // PREPARE_IES_OURSELVES
  1861. AADEBUGP(AAD_LOUD, ("InCall: VC 0x%x: Type %s, Calling Addr:\n",
  1862. pVc,
  1863. (((pCallParameters->Flags & PERMANENT_VC) == 0)? "SVC": "PVC")
  1864. ));
  1865. AADEBUGPDUMP(AAD_LOUD, pCallingAddress->Address, pCallingAddress->NumberOfDigits);
  1866. AADEBUGP(AAD_LOUD,
  1867. ("InCall: VC 0x%x: SendBW: %d, RcvBW: %d, SendSz %d, RcvSz %d\n",
  1868. pVc,
  1869. pVc->FlowSpec.SendPeakBandwidth,
  1870. pVc->FlowSpec.ReceivePeakBandwidth,
  1871. pVc->FlowSpec.SendMaxSize,
  1872. pVc->FlowSpec.ReceiveMaxSize));
  1873. #if DBG
  1874. if (pCallParameters->Flags & MULTIPOINT_VC)
  1875. {
  1876. AAMCDEBUGPATMADDR(AAD_EXTRA_LOUD, "Incoming PMP call from :", pCallingAddress);
  1877. }
  1878. #endif // DBG
  1879. //
  1880. // If this is a PVC, we are done. Accept the call.
  1881. //
  1882. if ((pCallParameters->Flags & PERMANENT_VC) != 0)
  1883. {
  1884. pVc->Flags |= (AA_VC_TYPE_PVC|AA_VC_CALL_STATE_INCOMING_IN_PROGRESS);
  1885. Status = NDIS_STATUS_SUCCESS;
  1886. break;
  1887. }
  1888. //
  1889. // Here if SVC. Check if an ATM Entry for this Calling address exists.
  1890. // If an entry exists, link this VC to the entry; otherwise, create a new
  1891. // ATM entry and link this VC to it.
  1892. //
  1893. AddrTypeLen = AA_PKT_ATM_ADDRESS_TO_TYPE_LEN(pCallingAddress);
  1894. if (pCallingSubaddress != (PATM_ADDRESS)NULL)
  1895. {
  1896. SubaddrTypeLen = AA_PKT_ATM_ADDRESS_TO_TYPE_LEN(pCallingSubaddress);
  1897. pAtmSubaddress = pCallingSubaddress->Address;
  1898. }
  1899. else
  1900. {
  1901. SubaddrTypeLen = 0;
  1902. pAtmSubaddress = (PUCHAR)NULL;
  1903. }
  1904. pAtmEntry = AtmArpSearchForAtmAddress(
  1905. pInterface,
  1906. AddrTypeLen,
  1907. pCallingAddress->Address,
  1908. SubaddrTypeLen,
  1909. pAtmSubaddress,
  1910. AE_REFTYPE_TMP,
  1911. TRUE // Create one if no match found
  1912. );
  1913. if (pAtmEntry == NULL_PATMARP_ATM_ENTRY)
  1914. {
  1915. Status = NDIS_STATUS_FAILURE;
  1916. break;
  1917. }
  1918. //
  1919. // Link this VC to the ATM Entry, and accept this call.
  1920. //
  1921. AA_ACQUIRE_AE_LOCK(pAtmEntry);
  1922. {
  1923. ULONG rc;
  1924. AtmArpLinkVcToAtmEntry(pVc, pAtmEntry);
  1925. //
  1926. // AtmArpSearchForAtmAddress addrefd pAtmEntry for us -- we deref it
  1927. // here (AFTER calling AtmArpLinkVcToAtmEntry).
  1928. //
  1929. rc = AA_DEREF_AE(pAtmEntry, AE_REFTYPE_TMP);
  1930. if (rc == 0)
  1931. {
  1932. //
  1933. // We shouldn't get here because AtmArpLinkVcToAtmEntry
  1934. // should have added a reference tp pAtmEntry.
  1935. //
  1936. AA_ASSERT(FALSE);
  1937. Status = NDIS_STATUS_FAILURE;
  1938. break;
  1939. }
  1940. }
  1941. AA_RELEASE_AE_LOCK(pAtmEntry);
  1942. //
  1943. // All checks for an incoming SVC are complete.
  1944. //
  1945. pVc->Flags |= (AA_VC_TYPE_SVC|AA_VC_CALL_STATE_INCOMING_IN_PROGRESS);
  1946. AtmArpReferenceVc(pVc); // ATM Entry reference
  1947. Status = NDIS_STATUS_SUCCESS;
  1948. break;
  1949. }
  1950. while (FALSE);
  1951. AADEBUGP(AAD_VERY_LOUD, ("Incoming call: VC 0x%x, Status 0x%x\n", pVc, Status));
  1952. return Status;
  1953. }
  1954. VOID
  1955. AtmArpCallConnectedHandler(
  1956. IN NDIS_HANDLE ProtocolVcContext
  1957. )
  1958. /*++
  1959. Routine Description:
  1960. This handler is called as the final step in an incoming call, to inform
  1961. us that the call is fully setup.
  1962. For a PVC, we link the ATMARP VC structure in the list of unresolved PVCs,
  1963. and use InATMARP to resolve both the IP and ATM addresses of the other
  1964. end.
  1965. For an SVC, we send off any packets queued on the VC while we were waiting
  1966. for the Call Connected.
  1967. Arguments:
  1968. ProtocolVcContext - Pointer to ATMARP VC structure
  1969. Return Value:
  1970. None
  1971. --*/
  1972. {
  1973. PATMARP_VC pVc;
  1974. PATMARP_INTERFACE pInterface;
  1975. #if DBG
  1976. AA_IRQL EntryIrq, ExitIrq;
  1977. #endif
  1978. AA_GET_ENTRY_IRQL(EntryIrq);
  1979. pVc = (PATMARP_VC)ProtocolVcContext;
  1980. AA_STRUCT_ASSERT(pVc, avc);
  1981. AA_ASSERT((pVc->Flags & AA_VC_CALL_STATE_MASK)
  1982. == AA_VC_CALL_STATE_INCOMING_IN_PROGRESS);
  1983. AA_ACQUIRE_VC_LOCK(pVc);
  1984. //
  1985. // Note down that a call is active on this VC.
  1986. //
  1987. AA_SET_FLAG(
  1988. pVc->Flags,
  1989. AA_VC_CALL_STATE_MASK,
  1990. AA_VC_CALL_STATE_ACTIVE
  1991. );
  1992. AtmArpReferenceVc(pVc); // Incoming call reference
  1993. AADEBUGP(AAD_INFO, ("Call Connected: VC: 0x%x, Flags: 0x%x, ATM Entry: 0x%x\n",
  1994. pVc, pVc->Flags, pVc->pAtmEntry));
  1995. pInterface = pVc->pInterface;
  1996. AA_STRUCT_ASSERT(pInterface, aai);
  1997. if (pInterface->AdminState == IF_STATUS_UP)
  1998. {
  1999. if ((pVc->Flags & AA_VC_TYPE_PVC) != 0)
  2000. {
  2001. //
  2002. // This is a PVC, link it to the list of unresolved PVCs, and
  2003. // send an InATMARP request on it.
  2004. //
  2005. pVc->pNextVc = pInterface->pUnresolvedVcs;
  2006. pInterface->pUnresolvedVcs = pVc;
  2007. AA_SET_FLAG(pVc->Flags,
  2008. AA_VC_ARP_STATE_MASK,
  2009. AA_VC_INARP_IN_PROGRESS);
  2010. //
  2011. // Start an InARP wait timer while we hold a lock for
  2012. // the Interface
  2013. //
  2014. AtmArpStartTimer(
  2015. pInterface,
  2016. &(pVc->Timer),
  2017. AtmArpPVCInARPWaitTimeout,
  2018. pInterface->InARPWaitTimeout,
  2019. (PVOID)pVc
  2020. );
  2021. AtmArpReferenceVc(pVc); // Timer ref
  2022. AtmArpReferenceVc(pVc); // Unresolved VCs Link reference
  2023. AADEBUGP(AAD_LOUD, ("PVC Call Connected: VC 0x%x\n", pVc));
  2024. #ifndef VC_REFS_ON_SENDS
  2025. AA_RELEASE_VC_LOCK(pVc);
  2026. #endif // VC_REFS_ON_SENDS
  2027. AtmArpSendInARPRequest(pVc);
  2028. AA_CHECK_EXIT_IRQL(EntryIrq, ExitIrq);
  2029. }
  2030. else
  2031. {
  2032. AADEBUGP(AAD_LOUD, ("SVC Call Connected: VC 0x%x\n", pVc));
  2033. AtmArpStartSendsOnVc(pVc);
  2034. //
  2035. // The VC lock is released within StartSendsOnVc()
  2036. //
  2037. AA_CHECK_EXIT_IRQL(EntryIrq, ExitIrq);
  2038. }
  2039. }
  2040. else
  2041. {
  2042. //
  2043. // The interface is marked as down. Close this call.
  2044. //
  2045. AtmArpCloseCall(pVc);
  2046. //
  2047. // The VC lock is released within the above
  2048. //
  2049. }
  2050. AA_CHECK_EXIT_IRQL(EntryIrq, ExitIrq);
  2051. return;
  2052. }
  2053. VOID
  2054. AtmArpIncomingCloseHandler(
  2055. IN NDIS_STATUS CloseStatus,
  2056. IN NDIS_HANDLE ProtocolVcContext,
  2057. IN PVOID pCloseData OPTIONAL,
  2058. IN UINT Size OPTIONAL
  2059. )
  2060. /*++
  2061. Routine Description:
  2062. This handler is called when a call is closed, either by the network
  2063. or by the remote peer.
  2064. Arguments:
  2065. CloseStatus - Reason for the call clearing
  2066. ProtocolVcContext - Actually a pointer to the ATMARP VC structure
  2067. pCloseData - Additional info about the close
  2068. Size - Length of above
  2069. Return Value:
  2070. None
  2071. --*/
  2072. {
  2073. PATMARP_VC pVc;
  2074. PATMARP_ATM_ENTRY pAtmEntry;
  2075. PATMARP_INTERFACE pInterface;
  2076. ULONG rc; // Ref Count
  2077. BOOLEAN VcAbnormalTermination;
  2078. BOOLEAN IsPVC;
  2079. BOOLEAN Found;
  2080. PATM_CAUSE_IE pCauseIe;
  2081. pVc = (PATMARP_VC)ProtocolVcContext;
  2082. AA_STRUCT_ASSERT(pVc, avc);
  2083. AADEBUGP(AAD_INFO, ("Incoming Close: pVc 0x%x, Status 0x%x\n", pVc, CloseStatus));
  2084. pCauseIe = (PATM_CAUSE_IE)pCloseData;
  2085. #if DBG
  2086. if (pCauseIe != (PATM_CAUSE_IE)NULL)
  2087. {
  2088. AADEBUGP(AAD_INFO, ("Incoming Close: pVc 0x%x, Locn 0x%x, Cause 0x%x\n",
  2089. pVc, pCauseIe->Location, pCauseIe->Cause));
  2090. }
  2091. #endif // DBG
  2092. AA_ACQUIRE_VC_LOCK(pVc);
  2093. IsPVC = AA_IS_FLAG_SET(pVc->Flags, AA_VC_TYPE_MASK, AA_VC_TYPE_PVC);
  2094. pInterface = pVc->pInterface;
  2095. //
  2096. // Stop any timer (e.g. VC aging) running on this VC
  2097. //
  2098. if (AtmArpStopTimer(&(pVc->Timer), pVc->pInterface))
  2099. {
  2100. //
  2101. // A timer WAS running
  2102. //
  2103. rc = AtmArpDereferenceVc(pVc); // Timer reference
  2104. AA_ASSERT(rc > 0);
  2105. }
  2106. if ((CloseStatus == NDIS_STATUS_DEST_OUT_OF_ORDER) || IsPVC)
  2107. {
  2108. //
  2109. // This is an abnormal close, note down the fact
  2110. //
  2111. VcAbnormalTermination = TRUE;
  2112. }
  2113. else
  2114. {
  2115. VcAbnormalTermination = FALSE;
  2116. }
  2117. if (AA_IS_FLAG_SET(pVc->Flags,
  2118. AA_VC_CALL_STATE_MASK,
  2119. AA_VC_CALL_STATE_INCOMING_IN_PROGRESS))
  2120. {
  2121. AADEBUGP(AAD_WARNING,
  2122. ("Incoming close: VC 0x%x state is INCOMING_IN_PROGRESS; changing to ACTIVE\n",
  2123. pVc));
  2124. //
  2125. // We're getting a close call for an incoming call that is not yet
  2126. // in the connected state. Since we won't get any further notifications
  2127. // for this call, this call is effectively in the active state.
  2128. // So we set the state to active, and then close the VC.
  2129. // Note: we will not go down the InvalidateAtmEntryPath even
  2130. // if CloseStatus == NDIS_STATUS_DEST_OUT_OF_ORDER;
  2131. // we instead simply close the vc. (If the client is truly out of order,
  2132. // and we want to send to it, well separately try to make an OUTGOING
  2133. // call to the destination, which should fail with "DEST_OUT_OF_ORDER",
  2134. // and we'll end up eventually invalidating the atm entry.
  2135. //
  2136. AA_SET_FLAG(pVc->Flags,
  2137. AA_VC_CALL_STATE_MASK,
  2138. AA_VC_CALL_STATE_ACTIVE);
  2139. AtmArpReferenceVc(pVc); // Incoming call reference
  2140. VcAbnormalTermination = FALSE;
  2141. }
  2142. if (VcAbnormalTermination &&
  2143. (pVc->pAtmEntry != NULL_PATMARP_ATM_ENTRY))
  2144. {
  2145. pAtmEntry = pVc->pAtmEntry;
  2146. AADEBUGP(AAD_INFO,
  2147. ("IncomingClose: will invalidate ATM entry %x/%x - IP Entry %x, VC %x/%x\n",
  2148. pAtmEntry, pAtmEntry->Flags,
  2149. pAtmEntry->pIpEntryList,
  2150. pVc, pVc->Flags));
  2151. AA_RELEASE_VC_LOCK(pVc);
  2152. AA_ACQUIRE_AE_LOCK(pAtmEntry);
  2153. AtmArpInvalidateAtmEntry(
  2154. pAtmEntry,
  2155. FALSE // Not shutting down
  2156. );
  2157. //
  2158. // AE Lock is released within the above.
  2159. //
  2160. if (IsPVC)
  2161. {
  2162. //
  2163. // Start a CloseCall right here because InvalidateAtmEntry doesn't.
  2164. //
  2165. AA_ACQUIRE_VC_LOCK(pVc);
  2166. AtmArpCloseCall(pVc);
  2167. //
  2168. // VC lock is released above
  2169. }
  2170. }
  2171. else
  2172. {
  2173. AtmArpCloseCall(pVc);
  2174. }
  2175. AADEBUGP(AAD_LOUD, ("Leaving Incoming Close handler, VC: 0x%x\n", pVc));
  2176. return;
  2177. }
  2178. #ifdef IPMCAST
  2179. VOID
  2180. AtmArpAddParty(
  2181. IN PATMARP_ATM_ENTRY pAtmEntry,
  2182. IN PATMARP_IPMC_ATM_ENTRY pMcAtmEntry
  2183. )
  2184. /*++
  2185. Routine Description:
  2186. Add a party to an existing PMP connection. The ATM Entry contains
  2187. all address information for the connection, and the Multicast ATM
  2188. Entry represents one of the leaves, the one to be added.
  2189. NOTE: The caller is assumed to hold a lock for the ATM Entry,
  2190. which is released here.
  2191. Arguments:
  2192. pAtmEntry - Pointer to ATM Entry on which to add the leaf (party).
  2193. pMcAtmEntry - Points to ATM Multicast Entry representing the leaf.
  2194. Return Value:
  2195. None
  2196. --*/
  2197. {
  2198. PATMARP_VC pVc; // The VC structure for the connection
  2199. NDIS_HANDLE NdisVcHandle;
  2200. PCO_CALL_PARAMETERS pCallParameters;
  2201. ULONG RequestSize;
  2202. NDIS_STATUS Status;
  2203. AA_ASSERT(pAtmEntry->pVcList != NULL_PATMARP_VC);
  2204. pVc = pAtmEntry->pVcList;
  2205. NdisVcHandle = pVc->NdisVcHandle;
  2206. //
  2207. // Allocate all the space we need.
  2208. //
  2209. RequestSize = sizeof(CO_CALL_PARAMETERS) +
  2210. sizeof(CO_CALL_MANAGER_PARAMETERS) +
  2211. sizeof(Q2931_CALLMGR_PARAMETERS) +
  2212. ATMARP_ADD_PARTY_IE_SPACE +
  2213. 0;
  2214. AA_ALLOC_MEM(pCallParameters, CO_CALL_PARAMETERS, RequestSize);
  2215. if (pCallParameters != (PCO_CALL_PARAMETERS)NULL)
  2216. {
  2217. //
  2218. // Fill in Call Parameters.
  2219. //
  2220. AtmArpFillCallParameters(
  2221. pCallParameters,
  2222. RequestSize,
  2223. &(pMcAtmEntry->ATMAddress), // Called address
  2224. &(pAtmEntry->pInterface->LocalAtmAddress), // Calling address
  2225. &(pVc->FlowSpec),
  2226. TRUE, // IsPMP
  2227. FALSE // IsMakeCall?
  2228. );
  2229. }
  2230. AA_SET_FLAG(pMcAtmEntry->Flags,
  2231. AA_IPMC_AE_CONN_STATE_MASK,
  2232. AA_IPMC_AE_CONN_WACK_ADD_PARTY);
  2233. pAtmEntry->pMcAtmInfo->TransientLeaves++;
  2234. AA_RELEASE_AE_LOCK(pAtmEntry);
  2235. if (pCallParameters != (PCO_CALL_PARAMETERS)NULL)
  2236. {
  2237. Status = NdisClAddParty(
  2238. NdisVcHandle,
  2239. (NDIS_HANDLE)pMcAtmEntry,
  2240. pCallParameters,
  2241. &(pMcAtmEntry->NdisPartyHandle)
  2242. );
  2243. }
  2244. else
  2245. {
  2246. Status = NDIS_STATUS_RESOURCES;
  2247. }
  2248. if (Status != NDIS_STATUS_PENDING)
  2249. {
  2250. AtmArpAddPartyCompleteHandler(
  2251. Status,
  2252. (NDIS_HANDLE)pMcAtmEntry,
  2253. pMcAtmEntry->NdisPartyHandle,
  2254. pCallParameters
  2255. );
  2256. }
  2257. }
  2258. VOID
  2259. AtmArpMcTerminateMember(
  2260. IN PATMARP_ATM_ENTRY pAtmEntry,
  2261. IN PATMARP_IPMC_ATM_ENTRY pMcAtmEntry
  2262. )
  2263. /*++
  2264. Routine Description:
  2265. Terminate the specified member of a multicast group. If it is
  2266. currently a leaf in the point-to-multipoint connection to the
  2267. group, then we drop it. If it is the LAST leaf, then we close
  2268. the entire connection.
  2269. NOTE: the caller is assumed to hold the ATM Entry lock, which
  2270. will be released here.
  2271. Arguments:
  2272. pAtmEntry - Pointer to ATM Entry
  2273. pMcAtmEntry - Points to ATM Multicast Entry representing the leaf to
  2274. be terminated.
  2275. Return Value:
  2276. None
  2277. --*/
  2278. {
  2279. PATMARP_IPMC_ATM_INFO pMcAtmInfo;
  2280. PATMARP_VC pVc;
  2281. NDIS_HANDLE NdisPartyHandle;
  2282. NDIS_STATUS Status;
  2283. pMcAtmInfo = pAtmEntry->pMcAtmInfo;
  2284. pVc = pAtmEntry->pVcList;
  2285. NdisPartyHandle = pMcAtmEntry->NdisPartyHandle;
  2286. AAMCDEBUGP(AAD_VERY_LOUD,
  2287. ("TerminateMember: pAtmEntry 0x%x, pMcAtmEntry 0x%x, pVc 0x%x, NdisPtyHnd 0x%x\n",
  2288. pAtmEntry, pMcAtmEntry, pVc, NdisPartyHandle));
  2289. #if DBG
  2290. {
  2291. PATMARP_IP_ENTRY pIpEntry = pAtmEntry->pIpEntryList;
  2292. if (pIpEntry != NULL_PATMARP_IP_ENTRY)
  2293. {
  2294. AAMCDEBUGPMAP(AAD_INFO, "Terminating ",
  2295. &pIpEntry->IPAddress,
  2296. &pMcAtmEntry->ATMAddress);
  2297. }
  2298. }
  2299. #endif // DBG
  2300. if (AA_IS_FLAG_SET(pMcAtmEntry->Flags,
  2301. AA_IPMC_AE_GEN_STATE_MASK,
  2302. AA_IPMC_AE_TERMINATING))
  2303. {
  2304. AA_RELEASE_AE_LOCK(pAtmEntry);
  2305. return;
  2306. }
  2307. AA_SET_FLAG(pMcAtmEntry->Flags,
  2308. AA_IPMC_AE_GEN_STATE_MASK,
  2309. AA_IPMC_AE_TERMINATING);
  2310. if (AA_IS_FLAG_SET(pMcAtmEntry->Flags,
  2311. AA_IPMC_AE_CONN_STATE_MASK,
  2312. AA_IPMC_AE_CONN_ACTIVE))
  2313. {
  2314. if (pMcAtmInfo->ActiveLeaves == 1)
  2315. {
  2316. //
  2317. // This is the last active leaf in this connection. Close the call.
  2318. //
  2319. AA_RELEASE_AE_LOCK(pAtmEntry);
  2320. AA_ASSERT(pVc != NULL_PATMARP_VC);
  2321. AA_ACQUIRE_VC_LOCK(pVc);
  2322. AtmArpCloseCall(pVc);
  2323. //
  2324. // VC lock is released within the above.
  2325. //
  2326. }
  2327. else
  2328. {
  2329. //
  2330. // This isn't the only leaf in this connection. Drop this party.
  2331. //
  2332. pAtmEntry->pMcAtmInfo->ActiveLeaves--;
  2333. AA_SET_FLAG(pMcAtmEntry->Flags,
  2334. AA_IPMC_AE_CONN_STATE_MASK,
  2335. AA_IPMC_AE_CONN_WACK_DROP_PARTY);
  2336. AA_RELEASE_AE_LOCK(pAtmEntry);
  2337. Status = NdisClDropParty(
  2338. NdisPartyHandle,
  2339. NULL, // Buffer
  2340. (UINT)0 // Size
  2341. );
  2342. if (Status != NDIS_STATUS_PENDING)
  2343. {
  2344. AtmArpDropPartyCompleteHandler(
  2345. Status,
  2346. (NDIS_HANDLE)pMcAtmEntry
  2347. );
  2348. }
  2349. }
  2350. }
  2351. else if (AA_IS_FLAG_SET(pMcAtmEntry->Flags,
  2352. AA_IPMC_AE_CONN_STATE_MASK,
  2353. AA_IPMC_AE_CONN_DISCONNECTED))
  2354. {
  2355. //
  2356. // Simply unlink this entry.
  2357. //
  2358. UINT rc;
  2359. AA_REF_AE(pAtmEntry, AE_REFTYPE_TMP); // temp ref
  2360. AtmArpMcUnlinkAtmMember(pAtmEntry, pMcAtmEntry);
  2361. rc = AA_DEREF_AE(pAtmEntry, AE_REFTYPE_TMP); // temp ref
  2362. if (rc!=0)
  2363. {
  2364. AA_RELEASE_AE_LOCK(pAtmEntry);
  2365. }
  2366. }
  2367. else
  2368. {
  2369. //
  2370. // This party is in a transient state. Let it finish its current
  2371. // operation.
  2372. //
  2373. AA_RELEASE_AE_LOCK(pAtmEntry);
  2374. }
  2375. }
  2376. #endif // IPMCAST
  2377. VOID
  2378. AtmArpIncomingDropPartyHandler(
  2379. IN NDIS_STATUS DropStatus,
  2380. IN NDIS_HANDLE ProtocolPartyContext,
  2381. IN PVOID pCloseData OPTIONAL,
  2382. IN UINT Size OPTIONAL
  2383. )
  2384. /*++
  2385. Routine Description:
  2386. This handler is called if the network (or remote peer) drops
  2387. a leaf node from a point-to-multipoint call rooted at us.
  2388. See Section 5.1.5.1 in RFC 2022: we delete the member from
  2389. the multicast group it belongs to. And we start a timer at
  2390. the end of which we mark the multicast group as needing
  2391. revalidation.
  2392. Arguments:
  2393. DropStatus - Leaf drop status
  2394. ProtocolPartyContext - Pointer to our Multicast ATM Entry structure
  2395. pCloseData - Optional additional info (ignored)
  2396. Size - of the above (ignored)
  2397. Return Value:
  2398. None
  2399. --*/
  2400. {
  2401. #ifdef IPMCAST
  2402. PATMARP_IPMC_ATM_ENTRY pMcAtmEntry;
  2403. PATMARP_ATM_ENTRY pAtmEntry;
  2404. PATMARP_IP_ENTRY pIpEntry;
  2405. PATMARP_INTERFACE pInterface;
  2406. NDIS_HANDLE NdisPartyHandle;
  2407. NDIS_STATUS Status;
  2408. pMcAtmEntry = (PATMARP_IPMC_ATM_ENTRY)ProtocolPartyContext;
  2409. AA_STRUCT_ASSERT(pMcAtmEntry, ame);
  2410. AA_ASSERT(pMcAtmEntry->pAtmEntry != NULL_PATMARP_ATM_ENTRY);
  2411. AA_ASSERT(pMcAtmEntry->pAtmEntry->pIpEntryList != NULL_PATMARP_IP_ENTRY);
  2412. pAtmEntry = pMcAtmEntry->pAtmEntry;
  2413. AA_ACQUIRE_AE_LOCK(pAtmEntry);
  2414. NdisPartyHandle = pMcAtmEntry->NdisPartyHandle;
  2415. pIpEntry = pAtmEntry->pIpEntryList;
  2416. pInterface = pAtmEntry->pInterface;
  2417. AADEBUGP(AAD_INFO,
  2418. ("Incoming Drop: pMcAtmEntry 0x%x, PtyHnd 0x%x, pAtmEntry 0x%x, IP Addr: %d.%d.%d.%d\n",
  2419. pMcAtmEntry,
  2420. NdisPartyHandle,
  2421. pAtmEntry,
  2422. ((PUCHAR)&(pIpEntry->IPAddress))[0],
  2423. ((PUCHAR)&(pIpEntry->IPAddress))[1],
  2424. ((PUCHAR)&(pIpEntry->IPAddress))[2],
  2425. ((PUCHAR)&(pIpEntry->IPAddress))[3]));
  2426. pAtmEntry->pMcAtmInfo->ActiveLeaves--;
  2427. AA_SET_FLAG(pMcAtmEntry->Flags,
  2428. AA_IPMC_AE_CONN_STATE_MASK,
  2429. AA_IPMC_AE_CONN_RCV_DROP_PARTY);
  2430. AA_RELEASE_AE_LOCK(pAtmEntry);
  2431. //
  2432. // We need to revalidate this multicast group after a random
  2433. // delay. Start a random delay timer.
  2434. //
  2435. AA_ACQUIRE_IE_LOCK(pIpEntry);
  2436. AA_ASSERT(AA_IE_IS_ALIVE(pIpEntry));
  2437. if (!AA_IS_TIMER_ACTIVE(&(pIpEntry->Timer)) &&
  2438. AA_IS_FLAG_SET(pIpEntry->Flags,
  2439. AA_IP_ENTRY_MC_RESOLVE_MASK,
  2440. AA_IP_ENTRY_MC_RESOLVED))
  2441. {
  2442. ULONG RandomDelay;
  2443. RandomDelay = AA_GET_RANDOM(
  2444. pInterface->MinRevalidationDelay,
  2445. pInterface->MaxRevalidationDelay);
  2446. AtmArpStartTimer(
  2447. pInterface,
  2448. &(pIpEntry->Timer),
  2449. AtmArpMcRevalidationDelayTimeout,
  2450. RandomDelay,
  2451. (PVOID)pIpEntry
  2452. );
  2453. AA_REF_IE(pIpEntry, IE_REFTYPE_TIMER); // Timer ref
  2454. }
  2455. AA_RELEASE_IE_LOCK(pIpEntry);
  2456. //
  2457. // Complete the DropParty handshake.
  2458. //
  2459. Status = NdisClDropParty(
  2460. NdisPartyHandle,
  2461. NULL,
  2462. 0
  2463. );
  2464. if (Status != NDIS_STATUS_PENDING)
  2465. {
  2466. AtmArpDropPartyCompleteHandler(
  2467. Status,
  2468. (NDIS_HANDLE)pMcAtmEntry
  2469. );
  2470. }
  2471. #endif // IPMCAST
  2472. return;
  2473. }
  2474. VOID
  2475. AtmArpQosChangeHandler(
  2476. IN NDIS_HANDLE ProtocolVcContext,
  2477. IN PCO_CALL_PARAMETERS pCallParameters
  2478. )
  2479. /*++
  2480. Routine Description:
  2481. This handler is called if the remote peer modifies call parameters
  2482. "on the fly", i.e. after the call is established and running.
  2483. This isn't supported by existing ATM signalling, and shouldn't happen,
  2484. but we'll allow this.
  2485. FUTURE: The FlowSpecs associated with the call are affected by this.
  2486. Arguments:
  2487. ProtocolVcContext - Pointer to our ATMARP VC structure
  2488. pCallParameters - updated call parameters.
  2489. Return Value:
  2490. None
  2491. --*/
  2492. {
  2493. PATMARP_VC pVc;
  2494. pVc = (PATMARP_VC)ProtocolVcContext;
  2495. AADEBUGP(AAD_WARNING, ("Ignoring Qos Change, VC: 0x%x\n", pVc));
  2496. return;
  2497. }
  2498. VOID
  2499. AtmArpOpenAfCompleteHandler(
  2500. IN NDIS_STATUS Status,
  2501. IN NDIS_HANDLE ProtocolAfContext,
  2502. IN NDIS_HANDLE NdisAfHandle
  2503. )
  2504. /*++
  2505. Routine Description:
  2506. This handler is called to indicate completion of a previous call
  2507. to NdisClOpenAddressFamily. We would have blocked the thread that
  2508. called this. Wake it up now.
  2509. By the way, if the call was successful, store the NDIS AF handle
  2510. in our Interface structure.
  2511. We don't need to acquire locks here because the thread that called
  2512. OpenAddressFamily would have blocked with a lock acquired.
  2513. Arguments:
  2514. Status - Status of the Open AF
  2515. ProtocolAfContext - Pointer to our ATMARP Interface structure
  2516. NdisAfHandle - NDIS handle to the AF association
  2517. Return Value:
  2518. None
  2519. --*/
  2520. {
  2521. PATMARP_INTERFACE pInterface;
  2522. pInterface = (PATMARP_INTERFACE)ProtocolAfContext;
  2523. AA_STRUCT_ASSERT(pInterface, aai);
  2524. AADEBUGP(AAD_INFO, ("Open AF Complete: IF 0x%x, Status 0x%x, AF Handle 0x%x\n",
  2525. pInterface, Status, NdisAfHandle));
  2526. if (Status == NDIS_STATUS_SUCCESS)
  2527. {
  2528. pInterface->NdisAfHandle = NdisAfHandle;
  2529. }
  2530. //
  2531. // Wake up the blocked thread
  2532. //
  2533. AA_SIGNAL_BLOCK_STRUCT(&(pInterface->Block), Status);
  2534. }
  2535. VOID
  2536. AtmArpSendIPDelInterface(
  2537. IN PNDIS_WORK_ITEM pWorkItem,
  2538. IN PVOID IfContext
  2539. )
  2540. {
  2541. PATMARP_INTERFACE pInterface;
  2542. PVOID IPContext;
  2543. ULONG rc;
  2544. #if DBG
  2545. AA_IRQL EntryIrq, ExitIrq;
  2546. #endif
  2547. AA_GET_ENTRY_IRQL(EntryIrq);
  2548. #if !BINARY_COMPATIBLE
  2549. AA_ASSERT(EntryIrq == PASSIVE_LEVEL);
  2550. #endif
  2551. pInterface = (PATMARP_INTERFACE)IfContext;
  2552. AA_STRUCT_ASSERT(pInterface, aai);
  2553. AA_FREE_MEM(pWorkItem);
  2554. AA_ACQUIRE_IF_LOCK(pInterface);
  2555. IPContext = pInterface->IPContext;
  2556. pInterface->IPContext = NULL;
  2557. AA_RELEASE_IF_LOCK(pInterface);
  2558. AADEBUGP(AAD_INFO, ("SendIPDelInterface: IF 0x%x, IPContext 0x%x\n",
  2559. pInterface, IPContext));
  2560. if (IPContext != NULL)
  2561. {
  2562. (*(pAtmArpGlobalInfo->pIPDelInterfaceRtn))(
  2563. IPContext
  2564. #if IFCHANGE1
  2565. #ifndef ATMARP_WIN98
  2566. ,0 // DeleteIndex (unused) -- See 10/14/1998 entry
  2567. // in notes.txt
  2568. #endif
  2569. #endif // IFCHANGE1
  2570. );
  2571. }
  2572. else
  2573. {
  2574. AADEBUGP(AAD_INFO, ("SendIPDelInterface: NO IPContext"));
  2575. }
  2576. AA_ACQUIRE_IF_LOCK(pInterface);
  2577. rc = AtmArpDereferenceInterface(pInterface); // Work Item: Del Interface
  2578. if (rc != 0)
  2579. {
  2580. AA_RELEASE_IF_LOCK(pInterface);
  2581. }
  2582. //
  2583. // else the Interface is gone.
  2584. //
  2585. }
  2586. VOID
  2587. AtmArpCloseAfCompleteHandler(
  2588. IN NDIS_STATUS Status,
  2589. IN NDIS_HANDLE ProtocolAfContext
  2590. )
  2591. /*++
  2592. Routine Description:
  2593. This routine is called to indicate completion of a call to
  2594. NdisClCloseAddressFamily. Tell IP to Delete this Interface now.
  2595. Arguments:
  2596. Status - Status of the Close AF (ignored here)
  2597. ProtocolAfContext - Pointer to ATMARP Interface structure
  2598. Return Value:
  2599. None
  2600. --*/
  2601. {
  2602. PATMARP_INTERFACE pInterface;
  2603. PNDIS_WORK_ITEM pWorkItem;
  2604. NDIS_STATUS NdisStatus;
  2605. BOOLEAN bUnloading;
  2606. #if 0
  2607. PVOID IPContext;
  2608. #endif
  2609. #if DBG
  2610. AA_IRQL EntryIrq, ExitIrq;
  2611. #endif
  2612. AA_GET_ENTRY_IRQL(EntryIrq);
  2613. #if !BINARY_COMPATIBLE
  2614. AA_ASSERT(EntryIrq == PASSIVE_LEVEL);
  2615. #endif
  2616. AA_ASSERT(Status == NDIS_STATUS_SUCCESS);
  2617. pInterface = (PATMARP_INTERFACE)ProtocolAfContext;
  2618. AADEBUGP(AAD_INFO, ("CloseAfComplete: If 0x%x, Status 0x%x\n",
  2619. pInterface, Status));
  2620. AA_STRUCT_ASSERT(pInterface, aai);
  2621. AA_ACQUIRE_IF_LOCK(pInterface);
  2622. pInterface->NdisAfHandle = NULL;
  2623. bUnloading = pAtmArpGlobalInfo->bUnloading;
  2624. if (pInterface->IPContext != NULL)
  2625. {
  2626. //
  2627. // We haven't seen an IfClose yet.
  2628. //
  2629. AA_ALLOC_MEM(pWorkItem, NDIS_WORK_ITEM, sizeof(NDIS_WORK_ITEM));
  2630. if (pWorkItem == NULL)
  2631. {
  2632. AA_ASSERT(FALSE);
  2633. AA_RELEASE_IF_LOCK(pInterface);
  2634. return;
  2635. }
  2636. #if 0
  2637. IPContext = (PVOID)pInterface->IPContext;
  2638. pInterface->IPContext = NULL;
  2639. #endif
  2640. AtmArpReferenceInterface(pInterface); // Work Item
  2641. AA_RELEASE_IF_LOCK(pInterface);
  2642. if (bUnloading)
  2643. {
  2644. AtmArpSendIPDelInterface(pWorkItem, (PVOID)pInterface);
  2645. }
  2646. else
  2647. {
  2648. //
  2649. // Queue a work item so that (a) things unravel easier,
  2650. // (b) we are at passive level when we call IPDelInterface.
  2651. //
  2652. NdisInitializeWorkItem(
  2653. pWorkItem,
  2654. AtmArpSendIPDelInterface,
  2655. (PVOID)pInterface
  2656. );
  2657. NdisStatus = NdisScheduleWorkItem(pWorkItem);
  2658. AA_ASSERT(NdisStatus == NDIS_STATUS_SUCCESS);
  2659. }
  2660. }
  2661. else
  2662. {
  2663. AADEBUGP(AAD_WARNING, ("CloseAfComplete: NO IPContext"));
  2664. AA_RELEASE_IF_LOCK(pInterface);
  2665. }
  2666. AA_CHECK_EXIT_IRQL(EntryIrq, ExitIrq);
  2667. }
  2668. VOID
  2669. AtmArpRegisterSapCompleteHandler(
  2670. IN NDIS_STATUS Status,
  2671. IN NDIS_HANDLE ProtocolSapContext,
  2672. IN PCO_SAP pSap,
  2673. IN NDIS_HANDLE NdisSapHandle
  2674. )
  2675. /*++
  2676. Routine Description:
  2677. This routine is called to indicate completion of a call to
  2678. NdisClRegisterSap. If the call was successful, save the
  2679. allocated NdisSapHandle in our SAP structure.
  2680. Arguments:
  2681. Status - Status of Register SAP
  2682. ProtocolSapContext - Pointer to our ATMARP Interface structure
  2683. pSap - SAP information we'd passed in the call
  2684. NdisSapHandle - SAP Handle
  2685. Return Value:
  2686. None
  2687. --*/
  2688. {
  2689. PATMARP_SAP pAtmArpSap;
  2690. pAtmArpSap = (PATMARP_SAP)ProtocolSapContext;
  2691. if (Status == NDIS_STATUS_SUCCESS)
  2692. {
  2693. pAtmArpSap->NdisSapHandle = NdisSapHandle;
  2694. AA_SET_FLAG(pAtmArpSap->Flags,
  2695. AA_SAP_REG_STATE_MASK,
  2696. AA_SAP_REG_STATE_REGISTERED);
  2697. }
  2698. else
  2699. {
  2700. AA_SET_FLAG(pAtmArpSap->Flags,
  2701. AA_SAP_REG_STATE_MASK,
  2702. AA_SAP_REG_STATE_IDLE);
  2703. }
  2704. }
  2705. VOID
  2706. AtmArpDeregisterSapCompleteHandler(
  2707. IN NDIS_STATUS Status,
  2708. IN NDIS_HANDLE ProtocolSapContext
  2709. )
  2710. /*++
  2711. Routine Description:
  2712. This routine is called when a previous call to NdisClDeregisterSap
  2713. has completed. If it was successful, we update the state of the ATMARP
  2714. SAP structure representing the Sap.
  2715. Arguments:
  2716. Status - Status of the Deregister SAP request
  2717. ProtocolSapContext - Pointer to our ATMARP SAP structure
  2718. Return Value:
  2719. None
  2720. --*/
  2721. {
  2722. PATMARP_INTERFACE pInterface;
  2723. PATMARP_SAP pAtmArpSap;
  2724. if (Status == NDIS_STATUS_SUCCESS)
  2725. {
  2726. pAtmArpSap = (PATMARP_SAP)ProtocolSapContext;
  2727. AA_STRUCT_ASSERT(pAtmArpSap, aas);
  2728. pInterface = pAtmArpSap->pInterface;
  2729. AA_ACQUIRE_IF_LOCK(pInterface);
  2730. pAtmArpSap->NdisSapHandle = NULL;
  2731. AA_SET_FLAG(pAtmArpSap->Flags,
  2732. AA_SAP_REG_STATE_MASK,
  2733. AA_SAP_REG_STATE_IDLE);
  2734. AA_RELEASE_IF_LOCK(pInterface);
  2735. }
  2736. return;
  2737. }
  2738. VOID
  2739. AtmArpMakeCallCompleteHandler(
  2740. IN NDIS_STATUS Status,
  2741. IN NDIS_HANDLE ProtocolVcContext,
  2742. IN NDIS_HANDLE NdisPartyHandle OPTIONAL,
  2743. IN PCO_CALL_PARAMETERS pCallParameters
  2744. )
  2745. /*++
  2746. Routine Description:
  2747. This routine is called when an outgoing call request (NdisClMakeCall)
  2748. has completed. The "Status" parameter indicates whether the call was
  2749. successful or not.
  2750. If the call was successful, we send any packets queued for transmission
  2751. on this VC.
  2752. If the call failed, we free any packets queued on this VC and unlink it
  2753. from the ATM Address Entry it was linked to. If this was an attempt to
  2754. connect to the ATMARP server, delay for a while before attempting to
  2755. connect again.
  2756. Arguments:
  2757. Status - Result of the NdisClMakeCall
  2758. ProtocolVcContext - Pointer to ATMARP VC structure
  2759. NdisPartyHandle - Not used (no point-to-multipoint calls)
  2760. pCallParameters - Pointer to call parameters
  2761. Return Value:
  2762. None
  2763. --*/
  2764. {
  2765. PATMARP_VC pVc;
  2766. PATMARP_INTERFACE pInterface;
  2767. ULONG rc; // ref count
  2768. BOOLEAN IsServerVc; // Is this the VC to the ATMARP server?
  2769. BOOLEAN IsPMP;
  2770. PNDIS_PACKET PacketList; // List of packets waiting to be sent
  2771. AA_HEADER_TYPE HdrType; // header types for the above
  2772. BOOLEAN HdrPresent;
  2773. NDIS_HANDLE NdisVcHandle;
  2774. PATMARP_ATM_ENTRY pAtmEntry; // ATM Entry to which this VC is linked
  2775. Q2931_CALLMGR_PARAMETERS UNALIGNED * pCallMgrSpecific;
  2776. Q2931_IE UNALIGNED * pIe;
  2777. ULONG InfoElementCount;
  2778. //
  2779. // Initialize
  2780. //
  2781. PacketList = (PNDIS_PACKET)NULL;
  2782. pVc = (PATMARP_VC)ProtocolVcContext;
  2783. AA_STRUCT_ASSERT(pVc, avc);
  2784. AADEBUGP(AAD_INFO, ("MakeCall Complete: Status 0x%x, VC 0x%x, pAtmEntry 0x%x\n",
  2785. Status, pVc, pVc->pAtmEntry));
  2786. AA_ACQUIRE_VC_LOCK(pVc);
  2787. IsPMP = AA_IS_FLAG_SET(pVc->Flags,
  2788. AA_VC_CONN_TYPE_MASK,
  2789. AA_VC_CONN_TYPE_PMP);
  2790. pAtmEntry = pVc->pAtmEntry;
  2791. AA_ASSERT(pAtmEntry != NULL_PATMARP_ATM_ENTRY);
  2792. if (pVc->FlowSpec.Encapsulation == ENCAPSULATION_TYPE_LLCSNAP)
  2793. {
  2794. HdrType = (IsPMP? AA_HEADER_TYPE_NUNICAST: AA_HEADER_TYPE_UNICAST);
  2795. HdrPresent = TRUE;
  2796. }
  2797. else
  2798. {
  2799. HdrType = AA_HEADER_TYPE_NONE;
  2800. HdrPresent = FALSE;
  2801. }
  2802. pInterface = pVc->pInterface;
  2803. if (pInterface->AdminState == IF_STATUS_UP)
  2804. {
  2805. if (Status == NDIS_STATUS_SUCCESS)
  2806. {
  2807. AADEBUGP(AAD_LOUD, ("Make Call Successful on VC 0x%x\n", pVc));
  2808. //
  2809. // Update the call state on this VC, and send queued packets.
  2810. // If this happens to be the VC to the ATMARP Server, we expect
  2811. // to see our initial ARP Request (to register with the server)
  2812. // in this queue.
  2813. //
  2814. AA_SET_FLAG(pVc->Flags,
  2815. AA_VC_CALL_STATE_MASK,
  2816. AA_VC_CALL_STATE_ACTIVE);
  2817. //
  2818. // Locate the AAL parameters Info Element, and get the updated
  2819. // packet sizes.
  2820. //
  2821. pCallMgrSpecific = (PQ2931_CALLMGR_PARAMETERS)&pCallParameters->CallMgrParameters->CallMgrSpecific.Parameters[0];
  2822. pIe = (PQ2931_IE)&pCallMgrSpecific->InfoElements[0];
  2823. for (InfoElementCount = 0;
  2824. InfoElementCount < pCallMgrSpecific->InfoElementCount;
  2825. InfoElementCount++)
  2826. {
  2827. if (pIe->IEType == IE_AALParameters)
  2828. {
  2829. AAL_PARAMETERS_IE UNALIGNED * pAalIe;
  2830. UNALIGNED AAL5_PARAMETERS * pAal5;
  2831. pAalIe = (PAAL_PARAMETERS_IE)&pIe->IE[0];
  2832. AA_ASSERT(pAalIe->AALType == AAL_TYPE_AAL5);
  2833. pAal5 = &pAalIe->AALSpecificParameters.AAL5Parameters;
  2834. #if DBG
  2835. if (pVc->FlowSpec.SendMaxSize != pAal5->ForwardMaxCPCSSDUSize)
  2836. {
  2837. AADEBUGP(AAD_INFO,
  2838. ("CallComplete: Send size changed (%d->%d)\n",
  2839. pVc->FlowSpec.SendMaxSize,
  2840. pAal5->ForwardMaxCPCSSDUSize));
  2841. }
  2842. if (pVc->FlowSpec.ReceiveMaxSize != pAal5->BackwardMaxCPCSSDUSize)
  2843. {
  2844. AADEBUGP(AAD_INFO,
  2845. ("CallComplete: Receive size changed (%d->%d)\n",
  2846. pVc->FlowSpec.ReceiveMaxSize,
  2847. pAal5->BackwardMaxCPCSSDUSize));
  2848. }
  2849. #endif // DBG
  2850. pVc->FlowSpec.SendMaxSize = pAal5->ForwardMaxCPCSSDUSize;
  2851. pVc->FlowSpec.ReceiveMaxSize = pAal5->BackwardMaxCPCSSDUSize;
  2852. break;
  2853. }
  2854. pIe = (PQ2931_IE)((PUCHAR)pIe + pIe->IELength);
  2855. }
  2856. AA_ASSERT(InfoElementCount != pCallMgrSpecific->InfoElementCount);
  2857. //
  2858. // Update the call type on this VC. If this is an SVC, start
  2859. // the VC aging timer.
  2860. //
  2861. if (pCallParameters->Flags & PERMANENT_VC)
  2862. {
  2863. AA_SET_FLAG(pVc->Flags,
  2864. AA_VC_TYPE_MASK,
  2865. AA_VC_TYPE_PVC);
  2866. }
  2867. else
  2868. {
  2869. ULONG AgingTime;
  2870. AA_SET_FLAG(pVc->Flags,
  2871. AA_VC_TYPE_MASK,
  2872. AA_VC_TYPE_SVC);
  2873. #ifdef IPMCAST
  2874. if (IsPMP)
  2875. {
  2876. AgingTime = pInterface->MulticastEntryAgingTimeout;
  2877. }
  2878. else
  2879. {
  2880. AgingTime = pVc->FlowSpec.AgingTime;
  2881. }
  2882. #else
  2883. AgingTime = pVc->FlowSpec.AgingTime;
  2884. #endif // IPMCAST
  2885. //
  2886. // Start VC aging timer on this SVC.
  2887. //
  2888. if (AgingTime != 0)
  2889. {
  2890. AtmArpStartTimer(
  2891. pInterface,
  2892. &(pVc->Timer),
  2893. AtmArpVcAgingTimeout,
  2894. AgingTime,
  2895. (PVOID)pVc
  2896. );
  2897. AtmArpReferenceVc(pVc); // Timer ref
  2898. }
  2899. }
  2900. AtmArpStartSendsOnVc(pVc);
  2901. //
  2902. // The VC lock is released within StartSendsOnVc()
  2903. //
  2904. #ifdef IPMCAST
  2905. if (IsPMP)
  2906. {
  2907. AtmArpMcMakeCallComplete(
  2908. pAtmEntry,
  2909. NdisPartyHandle,
  2910. Status
  2911. );
  2912. }
  2913. #endif // IPMCAST
  2914. }
  2915. else
  2916. {
  2917. //
  2918. // The call failed.
  2919. //
  2920. AA_SET_FLAG(pVc->Flags,
  2921. AA_VC_CALL_STATE_MASK,
  2922. AA_VC_CALL_STATE_IDLE);
  2923. //
  2924. // Delete the Call reference
  2925. //
  2926. rc = AtmArpDereferenceVc(pVc);
  2927. AA_ASSERT(rc > 0);
  2928. //
  2929. // Remove all packets queued on this VC
  2930. //
  2931. PacketList = pVc->PacketList;
  2932. pVc->PacketList = (PNDIS_PACKET)NULL;
  2933. //
  2934. // Was this a call to the ATMARP server?
  2935. //
  2936. if (pInterface->pCurrentServer != NULL)
  2937. {
  2938. IsServerVc = (pVc->pAtmEntry == pInterface->pCurrentServer->pAtmEntry);
  2939. }
  2940. else
  2941. {
  2942. IsServerVc = FALSE;
  2943. }
  2944. AADEBUGP(AAD_INFO,
  2945. ("Make Call FAILED on VC 0x%x IsPMP=%lu IsServer=%lu\n",
  2946. pVc,
  2947. IsPMP,
  2948. IsServerVc
  2949. ));
  2950. #ifdef GPC
  2951. //
  2952. // Unlink this VC from the flow, if linked...
  2953. //
  2954. if (pVc->FlowHandle != NULL)
  2955. {
  2956. PATMARP_FLOW_INFO pFlowInfo = (PATMARP_FLOW_INFO)pVc->FlowHandle;
  2957. if ((PVOID)pVc == InterlockedCompareExchangePointer(
  2958. &(pFlowInfo->VcContext),
  2959. NULL,
  2960. pVc
  2961. ))
  2962. {
  2963. pVc->FlowHandle = NULL;
  2964. rc = AtmArpDereferenceVc(pVc); // Unlink from GPC Flow
  2965. AA_ASSERT(rc > 0);
  2966. }
  2967. }
  2968. #endif // GPC
  2969. //
  2970. // Unlink this VC from the ATM Entry it belonged to, if any
  2971. //
  2972. AA_ASSERT(pVc->pAtmEntry != NULL_PATMARP_ATM_ENTRY);
  2973. AtmArpUnlinkVcFromAtmEntry(pVc, FALSE);
  2974. //
  2975. // Delete the ATM Entry reference
  2976. //
  2977. rc = AtmArpDereferenceVc(pVc); // ATM Entry ref
  2978. AA_ASSERT(rc > 0);
  2979. //
  2980. // Delete the CreateVc reference
  2981. //
  2982. NdisVcHandle = pVc->NdisVcHandle;
  2983. rc = AtmArpDereferenceVc(pVc); // Create Vc ref
  2984. if (rc != 0)
  2985. {
  2986. AA_RELEASE_VC_LOCK(pVc);
  2987. }
  2988. #ifndef VC_REFS_ON_SENDS
  2989. //
  2990. // Delete the NDIS association
  2991. //
  2992. (VOID)NdisCoDeleteVc(NdisVcHandle);
  2993. #endif // VC_REFS_ON_SENDS
  2994. AADEBUGP(AAD_LOUD, ("Deleted NDIS VC on pVc 0x%x: NdisVcHandle 0x%x\n",
  2995. pVc, NdisVcHandle));
  2996. AA_ACQUIRE_AE_LOCK(pAtmEntry);
  2997. rc = AA_DEREF_AE(pAtmEntry, AE_REFTYPE_VC); // Unlink Vc - make call
  2998. if (rc != 0)
  2999. {
  3000. AA_RELEASE_AE_LOCK(pAtmEntry);
  3001. #ifdef IPMCAST
  3002. if (IsPMP)
  3003. {
  3004. AtmArpMcMakeCallComplete(
  3005. pAtmEntry,
  3006. NdisPartyHandle,
  3007. Status
  3008. );
  3009. }
  3010. else
  3011. {
  3012. #endif // IPMCAST
  3013. if (!AA_IS_TRANSIENT_FAILURE(Status))
  3014. {
  3015. AA_ACQUIRE_AE_LOCK(pAtmEntry);
  3016. AtmArpInvalidateAtmEntry(pAtmEntry, FALSE); // MakeCall failure
  3017. //
  3018. // AE Lock is released within the above.
  3019. //
  3020. }
  3021. #ifdef IPMCAST
  3022. }
  3023. #endif // IPMCAST
  3024. }
  3025. //
  3026. // else the ATM Entry is gone
  3027. //
  3028. if (IsServerVc)
  3029. {
  3030. BOOLEAN WasRunning;
  3031. AA_ACQUIRE_IF_LOCK(pInterface);
  3032. //
  3033. // If we were in the process of registering (or refreshing)
  3034. // ourselves with the server, then retry after a while.
  3035. //
  3036. if (AA_IS_FLAG_SET(
  3037. pInterface->Flags,
  3038. AA_IF_SERVER_STATE_MASK,
  3039. AA_IF_SERVER_REGISTERING))
  3040. {
  3041. AA_SET_FLAG(pInterface->Flags,
  3042. AA_IF_SERVER_STATE_MASK,
  3043. AA_IF_SERVER_NO_CONTACT);
  3044. //
  3045. // The server registration timer would have been
  3046. // started -- stop it first.
  3047. //
  3048. WasRunning = AtmArpStopTimer(&(pInterface->Timer), pInterface);
  3049. if (WasRunning)
  3050. {
  3051. rc = AtmArpDereferenceInterface(pInterface);
  3052. }
  3053. else
  3054. {
  3055. rc = pInterface->RefCount;
  3056. }
  3057. if (rc > 0)
  3058. {
  3059. AtmArpRetryServerRegistration(pInterface);
  3060. //
  3061. // The IF lock is released within the above.
  3062. //
  3063. }
  3064. //
  3065. // else the IF is gone!
  3066. //
  3067. }
  3068. else
  3069. {
  3070. //
  3071. // We might have been trying to set up the server VC
  3072. // because of other reasons:
  3073. // - to resolve an unknown IP address
  3074. // - the server ATM address might be shared with other
  3075. // services (e.g. DHCP server)
  3076. //
  3077. // We don't have to retry registration in these cases.
  3078. //
  3079. AA_RELEASE_IF_LOCK(pInterface);
  3080. }
  3081. }
  3082. }
  3083. }
  3084. else
  3085. {
  3086. //
  3087. // The Interface is going down: clean up everything first.
  3088. //
  3089. if (Status == NDIS_STATUS_SUCCESS)
  3090. {
  3091. AA_SET_FLAG(pVc->Flags,
  3092. AA_VC_CALL_STATE_MASK,
  3093. AA_VC_CALL_STATE_ACTIVE);
  3094. //
  3095. // The call had been set up successfully, so close it.
  3096. // AtmArpCloseCall also frees any queued packets on the VC.
  3097. //
  3098. AtmArpCloseCall(pVc);
  3099. //
  3100. // The VC lock is released by CloseCall
  3101. //
  3102. }
  3103. else
  3104. {
  3105. // MakeCall had failed. (And the IF is going down)
  3106. AA_SET_FLAG(pVc->Flags,
  3107. AA_VC_CALL_STATE_MASK,
  3108. AA_VC_CALL_STATE_IDLE);
  3109. //
  3110. // Remove all packets queued on this VC
  3111. //
  3112. PacketList = pVc->PacketList;
  3113. pVc->PacketList = (PNDIS_PACKET)NULL;
  3114. NdisVcHandle = pVc->NdisVcHandle;
  3115. AtmArpUnlinkVcFromAtmEntry(pVc, TRUE);
  3116. //
  3117. // Delete the ATM Entry reference
  3118. //
  3119. rc = AtmArpDereferenceVc(pVc); // ATM Entry ref
  3120. //
  3121. // Delete the Call reference
  3122. //
  3123. rc = AtmArpDereferenceVc(pVc);
  3124. AA_ASSERT(rc > 0);
  3125. //
  3126. // Delete the CreateVc reference
  3127. //
  3128. rc = AtmArpDereferenceVc(pVc); // Create Vc ref
  3129. if (rc != 0)
  3130. {
  3131. AA_RELEASE_VC_LOCK(pVc);
  3132. }
  3133. #ifndef VC_REFS_ON_SENDS
  3134. //
  3135. // Delete the NDIS association
  3136. //
  3137. (VOID)NdisCoDeleteVc(NdisVcHandle);
  3138. AADEBUGP(AAD_LOUD,
  3139. ("MakeCall Fail: Deleted NDIS VC on pVc 0x%x: NdisVcHandle 0x%x\n",
  3140. pVc, NdisVcHandle));
  3141. #endif // !VC_REFS_ON_SENDS
  3142. }
  3143. }
  3144. //
  3145. // If there was a failure in making the call, or we aborted
  3146. // it for some reason, free all packets that were queued
  3147. // on the VC.
  3148. //
  3149. if (PacketList != (PNDIS_PACKET)NULL)
  3150. {
  3151. AtmArpFreeSendPackets(
  3152. pInterface,
  3153. PacketList,
  3154. HdrPresent
  3155. );
  3156. }
  3157. //
  3158. // We would have allocated the Call Parameters in MakeCall().
  3159. // We don't need it anymore.
  3160. //
  3161. AA_FREE_MEM(pCallParameters);
  3162. return;
  3163. }
  3164. #ifdef IPMCAST
  3165. VOID
  3166. AtmArpMcMakeCallComplete(
  3167. IN PATMARP_ATM_ENTRY pAtmEntry,
  3168. IN NDIS_HANDLE NdisPartyHandle OPTIONAL,
  3169. IN NDIS_STATUS Status
  3170. )
  3171. /*++
  3172. Routine Description:
  3173. Post-processing of a PMP MakeCall completion.
  3174. Arguments:
  3175. pAtmEntry - Represents the multicast group to which
  3176. the call was made.
  3177. NdisPartyHandle - Returned from the MakeCall.
  3178. Status - Result of the MakeCall
  3179. Return Value:
  3180. None
  3181. --*/
  3182. {
  3183. PATMARP_IPMC_ATM_ENTRY pMcAtmEntry;
  3184. PATMARP_IPMC_ATM_ENTRY * ppMcAtmEntry;
  3185. PATMARP_IPMC_ATM_INFO pMcAtmInfo;
  3186. PATMARP_IP_ENTRY pIpEntry;
  3187. PATMARP_INTERFACE pInterface;
  3188. //
  3189. // Do we need to update the PMP connection as a result
  3190. // of this event?
  3191. //
  3192. BOOLEAN bWantConnUpdate;
  3193. ULONG DelayBeforeRetry;
  3194. BOOLEAN bAtmEntryLockAcquired;
  3195. bAtmEntryLockAcquired = TRUE;
  3196. AA_ACQUIRE_AE_LOCK(pAtmEntry);
  3197. AA_ASSERT(pAtmEntry->pMcAtmInfo != NULL_PATMARP_IPMC_ATM_INFO);
  3198. AA_ASSERT(pAtmEntry->pIpEntryList != NULL_PATMARP_IP_ENTRY);
  3199. pIpEntry = pAtmEntry->pIpEntryList;
  3200. pMcAtmInfo = pAtmEntry->pMcAtmInfo;
  3201. pInterface = pAtmEntry->pInterface;
  3202. bWantConnUpdate = FALSE;
  3203. pMcAtmInfo->TransientLeaves--;
  3204. //
  3205. // Locate the MC ATM Entry representing the first party.
  3206. //
  3207. for (pMcAtmEntry = pMcAtmInfo->pMcAtmEntryList;
  3208. /* NONE */;
  3209. pMcAtmEntry = pMcAtmEntry->pNextMcAtmEntry)
  3210. {
  3211. AA_ASSERT(pMcAtmEntry != NULL_PATMARP_IPMC_ATM_ENTRY);
  3212. if (AA_IS_FLAG_SET(pMcAtmEntry->Flags,
  3213. AA_IPMC_AE_CONN_STATE_MASK,
  3214. AA_IPMC_AE_CONN_WACK_ADD_PARTY))
  3215. {
  3216. break;
  3217. }
  3218. }
  3219. AAMCDEBUGP(AAD_INFO,
  3220. ("McMakeCallComplete: pAtmEntry 0x%x, pMcAtmEntry 0x%x, Status 0x%x\n",
  3221. pAtmEntry, pMcAtmEntry, Status));
  3222. AAMCDEBUGPATMADDR(AAD_EXTRA_LOUD, "McMakeCall Addr: ", &pMcAtmEntry->ATMAddress);
  3223. if (Status == NDIS_STATUS_SUCCESS)
  3224. {
  3225. pMcAtmInfo->ActiveLeaves++;
  3226. //
  3227. // Update Multicast state
  3228. //
  3229. AA_SET_FLAG(pMcAtmInfo->Flags,
  3230. AA_IPMC_AI_CONN_STATE_MASK,
  3231. AA_IPMC_AI_CONN_ACTIVE);
  3232. //
  3233. // Update state of "first party"
  3234. //
  3235. pMcAtmEntry->NdisPartyHandle = NdisPartyHandle;
  3236. AA_SET_FLAG(pMcAtmEntry->Flags,
  3237. AA_IPMC_AE_CONN_STATE_MASK,
  3238. AA_IPMC_AE_CONN_ACTIVE);
  3239. bWantConnUpdate = TRUE;
  3240. //
  3241. // If we had decided to terminate this member when the
  3242. // MakeCall was going on, then we now mark this as Invalid.
  3243. // When we next update this PMP connection, this member will
  3244. // be removed.
  3245. //
  3246. if (AA_IS_FLAG_SET(pMcAtmEntry->Flags,
  3247. AA_IPMC_AE_GEN_STATE_MASK,
  3248. AA_IPMC_AE_TERMINATING))
  3249. {
  3250. AA_SET_FLAG(pMcAtmEntry->Flags,
  3251. AA_IPMC_AE_GEN_STATE_MASK,
  3252. AA_IPMC_AE_INVALID);
  3253. }
  3254. }
  3255. else
  3256. {
  3257. //
  3258. // A PMP call failed. If the failure is not "transient",
  3259. // we remove the member we were trying to connect to
  3260. // from the list. If there is atleast one more member
  3261. // that hasn't been attempted yet, try to connect to that.
  3262. //
  3263. AAMCDEBUGP(AAD_INFO, ("McMakeCall failed: pAtmEntry 0x%x, pMcAtmEntry 0x%x, Status 0x%x ",
  3264. pAtmEntry, pMcAtmEntry, Status));
  3265. AAMCDEBUGPATMADDR(AAD_INFO, " Addr: ", &pMcAtmEntry->ATMAddress);
  3266. //
  3267. // Update PMP connection state
  3268. //
  3269. AA_SET_FLAG(pAtmEntry->pMcAtmInfo->Flags,
  3270. AA_IPMC_AI_CONN_STATE_MASK,
  3271. AA_IPMC_AI_CONN_NONE);
  3272. if (AA_IS_TRANSIENT_FAILURE(Status))
  3273. {
  3274. //
  3275. // Update first party state.
  3276. //
  3277. AA_SET_FLAG(pMcAtmEntry->Flags,
  3278. AA_IPMC_AE_CONN_STATE_MASK,
  3279. AA_IPMC_AE_CONN_TEMP_FAILURE);
  3280. DelayBeforeRetry = AA_GET_TIMER_DURATION(&(pMcAtmEntry->Timer));
  3281. if (DelayBeforeRetry == 0)
  3282. {
  3283. //
  3284. // First time we're doing this.
  3285. //
  3286. DelayBeforeRetry = AA_GET_RANDOM(
  3287. pInterface->MinPartyRetryDelay,
  3288. pInterface->MaxPartyRetryDelay);
  3289. }
  3290. else
  3291. {
  3292. DelayBeforeRetry = 2*DelayBeforeRetry;
  3293. }
  3294. AtmArpStartTimer(
  3295. pInterface,
  3296. &(pMcAtmEntry->Timer),
  3297. AtmArpMcPartyRetryDelayTimeout,
  3298. DelayBeforeRetry,
  3299. (PVOID)pMcAtmEntry
  3300. );
  3301. }
  3302. else
  3303. {
  3304. AA_SET_FLAG(pMcAtmEntry->Flags,
  3305. AA_IPMC_AE_CONN_STATE_MASK,
  3306. AA_IPMC_AE_CONN_DISCONNECTED);
  3307. AtmArpMcUnlinkAtmMember(
  3308. pAtmEntry,
  3309. pMcAtmEntry
  3310. );
  3311. }
  3312. //
  3313. // Look for a member that we haven't tried to connect to.
  3314. //
  3315. for (ppMcAtmEntry = &(pMcAtmInfo->pMcAtmEntryList);
  3316. *ppMcAtmEntry != NULL_PATMARP_IPMC_ATM_ENTRY;
  3317. ppMcAtmEntry = &((*ppMcAtmEntry)->pNextMcAtmEntry))
  3318. {
  3319. if (AA_IS_FLAG_SET((*ppMcAtmEntry)->Flags,
  3320. AA_IPMC_AE_CONN_STATE_MASK,
  3321. AA_IPMC_AE_CONN_DISCONNECTED))
  3322. {
  3323. //
  3324. // Found one.
  3325. //
  3326. break;
  3327. }
  3328. }
  3329. if (*ppMcAtmEntry != NULL_PATMARP_IPMC_ATM_ENTRY)
  3330. {
  3331. pMcAtmEntry = *ppMcAtmEntry;
  3332. //
  3333. // Move this member to the top of the list.
  3334. // First, unlink from current position.
  3335. //
  3336. *ppMcAtmEntry = pMcAtmEntry->pNextMcAtmEntry;
  3337. //
  3338. // Now insert this at top of list.
  3339. //
  3340. pMcAtmEntry->pNextMcAtmEntry = pMcAtmInfo->pMcAtmEntryList;
  3341. pMcAtmInfo->pMcAtmEntryList = pMcAtmEntry;
  3342. bWantConnUpdate = TRUE;
  3343. }
  3344. else
  3345. {
  3346. //
  3347. // There is no ATM member that we haven't tried to connect to.
  3348. //
  3349. if (pMcAtmInfo->pMcAtmEntryList == NULL_PATMARP_IPMC_ATM_ENTRY)
  3350. {
  3351. //
  3352. // The list of ATM Members is empty.
  3353. //
  3354. AA_RELEASE_AE_LOCK(pAtmEntry);
  3355. AA_ACQUIRE_IE_LOCK(pIpEntry);
  3356. AA_ASSERT(AA_IE_IS_ALIVE(pIpEntry));
  3357. AtmArpAbortIPEntry(pIpEntry);
  3358. //
  3359. // IE Lock is released within the above.
  3360. //
  3361. bAtmEntryLockAcquired = FALSE;
  3362. }
  3363. }
  3364. }
  3365. if (bWantConnUpdate)
  3366. {
  3367. AA_ASSERT(bAtmEntryLockAcquired == TRUE);
  3368. AtmArpMcUpdateConnection(pAtmEntry);
  3369. //
  3370. // AE Lock is released within the above.
  3371. //
  3372. }
  3373. else
  3374. {
  3375. if (bAtmEntryLockAcquired)
  3376. {
  3377. AA_RELEASE_AE_LOCK(pAtmEntry);
  3378. }
  3379. }
  3380. }
  3381. #endif // IPMCAST
  3382. VOID
  3383. AtmArpCloseCallCompleteHandler(
  3384. IN NDIS_STATUS Status,
  3385. IN NDIS_HANDLE ProtocolVcContext,
  3386. IN NDIS_HANDLE ProtocolPartyContext OPTIONAL
  3387. )
  3388. /*++
  3389. Routine Description:
  3390. This routine handles completion of a previous NdisClCloseCall.
  3391. It is assumed that Status is always NDIS_STATUS_SUCCESS.
  3392. We delete the VC on which the call was just closed.
  3393. Special case: if we just finished closing a PMP call for a multicast
  3394. group that has been told to migrate to a (possibly) new set of
  3395. addresses, start off a new connection now.
  3396. Arguments:
  3397. Status - Status of the Close Call.
  3398. ProtocolVcContext - Pointer to ATMARP VC structure.
  3399. ProtocolPartyContext - Not used.
  3400. Return Value:
  3401. None
  3402. --*/
  3403. {
  3404. PATMARP_VC pVc;
  3405. PATMARP_VC * ppVc;
  3406. PATMARP_ATM_ENTRY pAtmEntry;
  3407. PATMARP_INTERFACE pInterface;
  3408. #ifdef IPMCAST
  3409. PATMARP_IPMC_ATM_ENTRY pMcAtmEntry; // represents the last leaf
  3410. PATMARP_IPMC_ATM_INFO pMcAtmInfo;
  3411. #endif // IPMCAST
  3412. ULONG rc; // Ref Count
  3413. NDIS_HANDLE NdisVcHandle;
  3414. BOOLEAN UpdatePMPConnection;
  3415. BOOLEAN AtmEntryIsClosing;
  3416. BOOLEAN IsMarsProblem;
  3417. BOOLEAN IsPVC;
  3418. BOOLEAN Found;
  3419. pVc = (PATMARP_VC)ProtocolVcContext;
  3420. AA_STRUCT_ASSERT(pVc, avc);
  3421. AADEBUGP(AAD_VERY_LOUD, ("CloseCallComplete: pVc 0x%x, Flags 0x%x, RefCount %d\n",
  3422. pVc, pVc->Flags, pVc->RefCount));
  3423. IsPVC = AA_IS_FLAG_SET(pVc->Flags, AA_VC_TYPE_MASK, AA_VC_TYPE_PVC);
  3424. //
  3425. // This VC may not be linked to an ATM Entry, e.g. for an unresolved
  3426. // Incoming PVC.
  3427. //
  3428. pAtmEntry = pVc->pAtmEntry;
  3429. if (pAtmEntry != NULL_PATMARP_ATM_ENTRY)
  3430. {
  3431. AtmEntryIsClosing = AA_IS_FLAG_SET(pAtmEntry->Flags,
  3432. AA_ATM_ENTRY_STATE_MASK,
  3433. AA_ATM_ENTRY_CLOSING);
  3434. }
  3435. else
  3436. {
  3437. AtmEntryIsClosing = FALSE;
  3438. }
  3439. pInterface = pVc->pInterface;
  3440. if (IsPVC)
  3441. {
  3442. //
  3443. // Take the PVC out of the unresolved VC list, if it
  3444. // exists there.
  3445. //
  3446. Found = FALSE;
  3447. AA_ACQUIRE_IF_LOCK(pInterface);
  3448. ppVc = &(pInterface->pUnresolvedVcs);
  3449. while (*ppVc != NULL_PATMARP_VC)
  3450. {
  3451. if (*ppVc == pVc)
  3452. {
  3453. *ppVc = pVc->pNextVc;
  3454. Found = TRUE;
  3455. break;
  3456. }
  3457. ppVc = &((*ppVc)->pNextVc);
  3458. }
  3459. AA_RELEASE_IF_LOCK(pInterface);
  3460. AA_ACQUIRE_VC_LOCK(pVc);
  3461. if (Found)
  3462. {
  3463. AADEBUGP(AAD_FATAL,
  3464. ("CloseCallComplete: took VC (PVC) %x out of IF %x\n",
  3465. pVc, pInterface));
  3466. rc = AtmArpDereferenceVc(pVc); // Unresolved VC list
  3467. }
  3468. else
  3469. {
  3470. rc = pVc->RefCount;
  3471. }
  3472. if (rc == 0)
  3473. {
  3474. //
  3475. // The VC is gone!
  3476. //
  3477. AADEBUGP(AAD_WARNING,
  3478. ("CloseCallComplete: VC (PVC) %x derefed away, IF %x\n",
  3479. pVc, pInterface));
  3480. return;
  3481. }
  3482. else
  3483. {
  3484. AA_RELEASE_VC_LOCK(pVc);
  3485. }
  3486. }
  3487. #ifdef IPMCAST
  3488. //
  3489. // We have lost our connection to the MARS if this was the last
  3490. // VC going to that address. We should atleast be a party on
  3491. // ClusterControlVc.
  3492. //
  3493. IsMarsProblem = FALSE;
  3494. if (pInterface->AdminState == IF_STATUS_UP)
  3495. {
  3496. if (pAtmEntry != NULL_PATMARP_ATM_ENTRY)
  3497. {
  3498. if (pAtmEntry->pVcList->pNextVc == NULL_PATMARP_VC)
  3499. {
  3500. if (pInterface->pCurrentMARS &&
  3501. (pInterface->pCurrentMARS->pAtmEntry == pAtmEntry))
  3502. {
  3503. IsMarsProblem = TRUE;
  3504. AA_ACQUIRE_IF_LOCK(pInterface);
  3505. AtmArpReferenceInterface(pInterface);
  3506. AA_RELEASE_IF_LOCK(pInterface);
  3507. }
  3508. }
  3509. }
  3510. }
  3511. UpdatePMPConnection = FALSE;
  3512. pMcAtmEntry = (PATMARP_IPMC_ATM_ENTRY)ProtocolPartyContext;
  3513. //
  3514. // If this is a point-to-multipoint connection that was closed,
  3515. // handle unlinking the last leaf.
  3516. //
  3517. if (pMcAtmEntry != NULL_PATMARP_IPMC_ATM_ENTRY)
  3518. {
  3519. //
  3520. // This is a PMP connection.
  3521. //
  3522. AAMCDEBUGP(AAD_LOUD, ("CloseCallComplete (MC): pAtmEntry 0x%x/0x%x\n",
  3523. pAtmEntry, pAtmEntry->Flags));
  3524. AA_ASSERT(pAtmEntry != NULL_PATMARP_ATM_ENTRY);
  3525. AA_ACQUIRE_AE_LOCK(pAtmEntry);
  3526. AA_SET_FLAG(pMcAtmEntry->Flags,
  3527. AA_IPMC_AE_CONN_STATE_MASK,
  3528. AA_IPMC_AE_CONN_DISCONNECTED);
  3529. AtmArpMcUnlinkAtmMember(pAtmEntry, pMcAtmEntry);
  3530. pMcAtmInfo = pAtmEntry->pMcAtmInfo;
  3531. AA_ASSERT(pMcAtmInfo != NULL_PATMARP_IPMC_ATM_INFO);
  3532. //
  3533. // Make the new list of ATM stations (the "Migrate to" list)
  3534. // the current list. This might be NULL.
  3535. //
  3536. pMcAtmInfo->pMcAtmEntryList = pMcAtmInfo->pMcAtmMigrateList;
  3537. pMcAtmInfo->pMcAtmMigrateList = NULL_PATMARP_IPMC_ATM_ENTRY;
  3538. //
  3539. // If there is a non-empty migrate list, then we have
  3540. // to make a fresh PMP connection.
  3541. //
  3542. UpdatePMPConnection =
  3543. (pMcAtmInfo->pMcAtmEntryList != NULL_PATMARP_IPMC_ATM_ENTRY);
  3544. AA_SET_FLAG(pMcAtmInfo->Flags,
  3545. AA_IPMC_AI_CONN_STATE_MASK,
  3546. AA_IPMC_AI_CONN_NONE);
  3547. AA_RELEASE_AE_LOCK(pAtmEntry);
  3548. }
  3549. #endif // IPMCAST
  3550. AA_ACQUIRE_VC_LOCK(pVc);
  3551. if (pAtmEntry != NULL_PATMARP_ATM_ENTRY)
  3552. {
  3553. AtmArpUnlinkVcFromAtmEntry(pVc, TRUE);
  3554. rc = AtmArpDereferenceVc(pVc); // ATM Entry ref
  3555. AA_ASSERT(rc != 0);
  3556. }
  3557. rc = AtmArpDereferenceVc(pVc); // Call reference
  3558. AA_ASSERT(rc != 0); // CreateVc reference remains
  3559. AA_SET_FLAG(pVc->Flags,
  3560. AA_VC_CALL_STATE_MASK,
  3561. AA_VC_CALL_STATE_IDLE);
  3562. AA_ASSERT(pVc->PacketList == NULL);
  3563. //
  3564. // If this VC belongs to us, delete it.
  3565. //
  3566. if (AA_IS_FLAG_SET(pVc->Flags,
  3567. AA_VC_OWNER_MASK,
  3568. AA_VC_OWNER_IS_ATMARP))
  3569. {
  3570. NdisVcHandle = pVc->NdisVcHandle;
  3571. rc = AtmArpDereferenceVc(pVc); // Create Vc ref
  3572. if (rc != 0)
  3573. {
  3574. // Could still be temp refs...
  3575. AA_RELEASE_VC_LOCK(pVc);
  3576. }
  3577. else
  3578. {
  3579. // The VC has been deallocated, and lock released
  3580. }
  3581. #ifndef VC_REFS_ON_SENDS
  3582. //
  3583. // Delete the NDIS association
  3584. //
  3585. (VOID)NdisCoDeleteVc(NdisVcHandle);
  3586. #endif // VC_REFS_ON_SENDS
  3587. AADEBUGP(AAD_LOUD,
  3588. ("CloseCallComplete: deleted NDIS VC on pVc 0x%x: NdisVcHandle 0x%x\n",
  3589. pVc, NdisVcHandle));
  3590. }
  3591. else
  3592. {
  3593. //
  3594. // VC belongs to the Call Manager -- take it back to the
  3595. // state it was when it was just created (via our CreateVcHandler).
  3596. // The Call Manager can either re-use it or delete it.
  3597. //
  3598. pVc->Flags = AA_VC_OWNER_IS_CALLMGR;
  3599. AA_RELEASE_VC_LOCK(pVc);
  3600. }
  3601. #ifdef IPMCAST
  3602. if (UpdatePMPConnection)
  3603. {
  3604. AAMCDEBUGP(AAD_INFO,
  3605. ("CloseCallComplete: pVc 0x%x, starting update on pAtmEntry 0x%x\n",
  3606. pVc, pAtmEntry));
  3607. AA_ACQUIRE_AE_LOCK(pAtmEntry);
  3608. AtmArpMcUpdateConnection(pAtmEntry);
  3609. //
  3610. // AE Lock is released within the above.
  3611. //
  3612. }
  3613. else
  3614. {
  3615. //
  3616. // If this was a PMP connection, handle the case
  3617. // of a remote-initiated CloseCall: we need to
  3618. // unlink the ATM Entry from the IP Entry.
  3619. //
  3620. if ((pMcAtmEntry != NULL_PATMARP_IPMC_ATM_ENTRY) &&
  3621. !AtmEntryIsClosing)
  3622. {
  3623. AA_ACQUIRE_AE_LOCK(pAtmEntry);
  3624. AtmArpInvalidateAtmEntry(pAtmEntry, FALSE); // CloseCallComplete
  3625. }
  3626. }
  3627. if (IsMarsProblem)
  3628. {
  3629. AA_ACQUIRE_IF_LOCK(pInterface);
  3630. rc = AtmArpDereferenceInterface(pInterface);
  3631. if (rc != 0)
  3632. {
  3633. AA_RELEASE_IF_LOCK(pInterface);
  3634. AtmArpMcHandleMARSFailure(pInterface, FALSE);
  3635. }
  3636. //
  3637. // else the interface is gone.
  3638. //
  3639. }
  3640. #endif
  3641. return;
  3642. }
  3643. #ifdef IPMCAST
  3644. VOID
  3645. AtmArpAddPartyCompleteHandler(
  3646. IN NDIS_STATUS Status,
  3647. IN NDIS_HANDLE ProtocolPartyContext,
  3648. IN NDIS_HANDLE NdisPartyHandle,
  3649. IN PCO_CALL_PARAMETERS pCallParameters
  3650. )
  3651. /*++
  3652. Routine Description:
  3653. This routine is called on completion of a previous call to
  3654. NdisClAddParty. Since we don't use point-to-multipoint connections,
  3655. this should never get called.
  3656. If the AddParty was successful, we just update state and exit. If it
  3657. failed, we check the failure code. If this indicates a transient
  3658. failure condition, we start a timer so that we reattempt to add this
  3659. party later. Otherwise ("hard" failure), this multicast entry is deleted.
  3660. Arguments:
  3661. Status - Status of the AddParty
  3662. ProtocolPartyContext - Pointer to an IPMC_ATM_ENTRY structure
  3663. NdisPartyHandle - NDIS' handle for this party
  3664. pCallParameters - what we had passed to NdisClAddParty
  3665. Return Value:
  3666. None
  3667. --*/
  3668. {
  3669. PATMARP_IPMC_ATM_ENTRY pMcAtmEntry;
  3670. PATMARP_ATM_ENTRY pAtmEntry;
  3671. PATMARP_IP_ENTRY pIpEntry;
  3672. PATMARP_VC pVc;
  3673. ULONG VcFlags;
  3674. PATMARP_INTERFACE pInterface;
  3675. ULONG DelayBeforeRetry;
  3676. BOOLEAN ClearToSend;
  3677. pMcAtmEntry = (PATMARP_IPMC_ATM_ENTRY)(ProtocolPartyContext);
  3678. AA_STRUCT_ASSERT(pMcAtmEntry, ame);
  3679. pAtmEntry = pMcAtmEntry->pAtmEntry;
  3680. AA_ACQUIRE_AE_LOCK(pAtmEntry);
  3681. pAtmEntry->pMcAtmInfo->TransientLeaves--;
  3682. pVc = pAtmEntry->pVcList;
  3683. VcFlags = pVc->Flags;
  3684. pInterface = pAtmEntry->pInterface;
  3685. AAMCDEBUGP(AAD_LOUD,
  3686. ("AddPartyComplete: Status 0x%x, pAtmEntry 0x%x, pMcAtmEntry 0x%x, pVc 0x%x\n",
  3687. Status, pAtmEntry, pMcAtmEntry, pVc));
  3688. AAMCDEBUGPATMADDR(AAD_EXTRA_LOUD, "AddParty Addr: ", &pMcAtmEntry->ATMAddress);
  3689. if (Status == NDIS_STATUS_SUCCESS)
  3690. {
  3691. AA_SET_FLAG(pMcAtmEntry->Flags,
  3692. AA_IPMC_AE_CONN_STATE_MASK,
  3693. AA_IPMC_AE_CONN_ACTIVE);
  3694. //
  3695. // If we had decided to terminate this member when the
  3696. // AddParty was going on, then we now mark this as Invalid.
  3697. // When we next update this PMP connection, this member will
  3698. // be removed.
  3699. //
  3700. if (AA_IS_FLAG_SET(pMcAtmEntry->Flags,
  3701. AA_IPMC_AE_GEN_STATE_MASK,
  3702. AA_IPMC_AE_TERMINATING))
  3703. {
  3704. AA_SET_FLAG(pMcAtmEntry->Flags,
  3705. AA_IPMC_AE_GEN_STATE_MASK,
  3706. AA_IPMC_AE_INVALID);
  3707. }
  3708. pMcAtmEntry->NdisPartyHandle = NdisPartyHandle;
  3709. pAtmEntry->pMcAtmInfo->ActiveLeaves++;
  3710. }
  3711. else
  3712. {
  3713. AAMCDEBUGP(AAD_INFO,
  3714. ("AddPartyComplete: Status 0x%x, pAtmEntry 0x%x, to ", Status, pAtmEntry));
  3715. AAMCDEBUGPATMADDR(AAD_INFO, "", &pMcAtmEntry->ATMAddress);
  3716. //
  3717. // Check if the failure was due to a transient
  3718. // condition.
  3719. //
  3720. if (AA_IS_TRANSIENT_FAILURE(Status))
  3721. {
  3722. //
  3723. // We'll fire a timer, so that we reattempt to
  3724. // connect to this one later. If we had already
  3725. // done this (i.e. time out on failure), then
  3726. // we include a back-off time in the delay.
  3727. //
  3728. DelayBeforeRetry = AA_GET_TIMER_DURATION(&(pMcAtmEntry->Timer));
  3729. if (DelayBeforeRetry == 0)
  3730. {
  3731. //
  3732. // First time we're doing this.
  3733. //
  3734. DelayBeforeRetry = AA_GET_RANDOM(
  3735. pInterface->MinPartyRetryDelay,
  3736. pInterface->MaxPartyRetryDelay);
  3737. }
  3738. else
  3739. {
  3740. DelayBeforeRetry = 2*DelayBeforeRetry;
  3741. }
  3742. AtmArpStartTimer(
  3743. pInterface,
  3744. &(pMcAtmEntry->Timer),
  3745. AtmArpMcPartyRetryDelayTimeout,
  3746. DelayBeforeRetry,
  3747. (PVOID)pMcAtmEntry
  3748. );
  3749. AA_SET_FLAG(pMcAtmEntry->Flags,
  3750. AA_IPMC_AE_CONN_STATE_MASK,
  3751. AA_IPMC_AE_CONN_TEMP_FAILURE);
  3752. }
  3753. else
  3754. {
  3755. //
  3756. // Not a transient failure. Delete this member.
  3757. //
  3758. AA_SET_FLAG(pMcAtmEntry->Flags,
  3759. AA_IPMC_AE_CONN_STATE_MASK,
  3760. AA_IPMC_AE_CONN_DISCONNECTED);
  3761. AtmArpMcUnlinkAtmMember(
  3762. pAtmEntry,
  3763. pMcAtmEntry
  3764. );
  3765. }
  3766. }
  3767. ClearToSend = ((pAtmEntry->pMcAtmInfo->TransientLeaves == 0) &&
  3768. (AA_IS_FLAG_SET(pAtmEntry->pMcAtmInfo->Flags,
  3769. AA_IPMC_AI_CONN_STATE_MASK,
  3770. AA_IPMC_AI_CONN_ACTIVE)));
  3771. pIpEntry = pAtmEntry->pIpEntryList;
  3772. AA_RELEASE_AE_LOCK(pAtmEntry);
  3773. if (pCallParameters != (PCO_CALL_PARAMETERS)NULL)
  3774. {
  3775. AA_FREE_MEM(pCallParameters);
  3776. }
  3777. //
  3778. // Check if the VC is closing, and we had held back because
  3779. // this AddParty was in progress. If so, try to continue the
  3780. // CloseCall process.
  3781. //
  3782. AA_ACQUIRE_VC_LOCK(pVc);
  3783. if (AA_IS_FLAG_SET(pVc->Flags,
  3784. AA_VC_CLOSE_STATE_MASK,
  3785. AA_VC_CLOSE_STATE_CLOSING))
  3786. {
  3787. AtmArpCloseCall(pVc);
  3788. //
  3789. // VC Lock is released within the above.
  3790. //
  3791. }
  3792. else
  3793. {
  3794. PNDIS_PACKET pPacketList;
  3795. AA_RELEASE_VC_LOCK(pVc);
  3796. if (ClearToSend && pIpEntry)
  3797. {
  3798. AA_ACQUIRE_IE_LOCK(pIpEntry);
  3799. AA_ASSERT(AA_IE_IS_ALIVE(pIpEntry));
  3800. pPacketList = pIpEntry->PacketList;
  3801. pIpEntry->PacketList = (PNDIS_PACKET)NULL;
  3802. AA_RELEASE_IE_LOCK(pIpEntry);
  3803. if (pPacketList != (PNDIS_PACKET)NULL)
  3804. {
  3805. AAMCDEBUGP(AAD_INFO, ("AddPtyCompl: pAtmEntry 0x%x, sending pktlist 0x%x\n",
  3806. pAtmEntry, pPacketList));
  3807. AtmArpSendPacketListOnAtmEntry(
  3808. pInterface,
  3809. pAtmEntry,
  3810. pPacketList,
  3811. TRUE // IsBroadcast
  3812. );
  3813. }
  3814. }
  3815. }
  3816. }
  3817. #else
  3818. VOID
  3819. AtmArpAddPartyCompleteHandler(
  3820. IN NDIS_STATUS Status,
  3821. IN NDIS_HANDLE ProtocolPartyContext,
  3822. IN NDIS_HANDLE NdisPartyHandle,
  3823. IN PCO_CALL_PARAMETERS pCallParameters
  3824. )
  3825. /*++
  3826. Routine Description:
  3827. This routine is called on completion of a previous call to
  3828. NdisClAddParty. Since we don't use point-to-multipoint connections,
  3829. this should never get called.
  3830. Arguments:
  3831. <Don't care>
  3832. Return Value:
  3833. None
  3834. --*/
  3835. {
  3836. AADEBUGP(AAD_ERROR, ("Add Party Complete unexpectedly called\n"));
  3837. AA_ASSERT(FALSE);
  3838. }
  3839. #endif // IPMCAST
  3840. VOID
  3841. AtmArpDropPartyCompleteHandler(
  3842. IN NDIS_STATUS Status,
  3843. IN NDIS_HANDLE ProtocolPartyContext
  3844. )
  3845. /*++
  3846. Routine Description:
  3847. This routine is called on completion of a previous call to
  3848. NdisClDropParty. We unlink our party structure and free it.
  3849. Arguments:
  3850. Status - Final result of the Drop Party
  3851. ProtocolPartyContext - Pointer to the MC ATM Entry we used
  3852. to represent the party.
  3853. Return Value:
  3854. None
  3855. --*/
  3856. {
  3857. #ifdef IPMCAST
  3858. PATMARP_IPMC_ATM_ENTRY pMcAtmEntry;
  3859. PATMARP_ATM_ENTRY pAtmEntry;
  3860. PATMARP_IP_ENTRY pIpEntry;
  3861. ULONG rc;
  3862. BOOLEAN LockReleased;
  3863. AAMCDEBUGP(AAD_LOUD, ("DropPartyComplete: Status 0x%x, Context 0x%x\n",
  3864. Status, ProtocolPartyContext));
  3865. AA_ASSERT(Status == NDIS_STATUS_SUCCESS);
  3866. pMcAtmEntry = (PATMARP_IPMC_ATM_ENTRY)ProtocolPartyContext;
  3867. AA_STRUCT_ASSERT(pMcAtmEntry, ame);
  3868. pAtmEntry = pMcAtmEntry->pAtmEntry;
  3869. AA_ASSERT(pAtmEntry != NULL_PATMARP_ATM_ENTRY);
  3870. AA_STRUCT_ASSERT(pAtmEntry, aae);
  3871. AA_ACQUIRE_AE_LOCK(pAtmEntry);
  3872. AA_REF_AE(pAtmEntry, AE_REFTYPE_TMP); // temp ref
  3873. AA_SET_FLAG(pMcAtmEntry->Flags,
  3874. AA_IPMC_AE_CONN_STATE_MASK,
  3875. AA_IPMC_AE_CONN_DISCONNECTED);
  3876. AtmArpMcUnlinkAtmMember(pAtmEntry, pMcAtmEntry);
  3877. //
  3878. // If we are in the processing of closing this PMP call,
  3879. // and this event signifies that all preliminary DropParty's
  3880. // are complete, then close the call itself.
  3881. //
  3882. LockReleased = FALSE;
  3883. rc = AA_DEREF_AE(pAtmEntry, AE_REFTYPE_TMP); // temp ref
  3884. if (rc != 0)
  3885. {
  3886. PATMARP_VC pVc;
  3887. pVc = pAtmEntry->pVcList;
  3888. if (pVc != NULL_PATMARP_VC)
  3889. {
  3890. if (AA_IS_FLAG_SET(pVc->Flags,
  3891. AA_VC_CLOSE_STATE_MASK,
  3892. AA_VC_CLOSE_STATE_CLOSING) &&
  3893. (pAtmEntry->pMcAtmInfo->NumOfEntries == 1))
  3894. {
  3895. AA_RELEASE_AE_LOCK(pAtmEntry);
  3896. AA_ACQUIRE_VC_LOCK(pVc);
  3897. AtmArpCloseCall(pVc);
  3898. //
  3899. // VC lock is released within the above.
  3900. //
  3901. LockReleased = TRUE;
  3902. }
  3903. }
  3904. }
  3905. if (!LockReleased)
  3906. {
  3907. AA_RELEASE_AE_LOCK(pAtmEntry);
  3908. }
  3909. #endif // IPMCAST
  3910. }
  3911. VOID
  3912. AtmArpModifyQosCompleteHandler(
  3913. IN NDIS_STATUS Status,
  3914. IN NDIS_HANDLE ProtocolVcContext,
  3915. IN PCO_CALL_PARAMETERS pCallParameters
  3916. )
  3917. /*++
  3918. Routine Description:
  3919. This routine is called on completion of a previous call to
  3920. NdisClModifyCallQoS. Since we don't call this, this should never
  3921. get called.
  3922. Arguments:
  3923. <Don't care>
  3924. Return Value:
  3925. None
  3926. --*/
  3927. {
  3928. AADEBUGP(AAD_ERROR, ("Modify QOS Complete unexpectedly called\n"));
  3929. AA_ASSERT(FALSE);
  3930. }
  3931. #ifndef OID_CO_AF_CLOSE
  3932. #define OID_CO_AF_CLOSE 0xFE00000A
  3933. #endif
  3934. NDIS_STATUS
  3935. AtmArpCoRequestHandler(
  3936. IN NDIS_HANDLE ProtocolAfContext,
  3937. IN NDIS_HANDLE ProtocolVcContext OPTIONAL,
  3938. IN NDIS_HANDLE ProtocolPartyContext OPTIONAL,
  3939. IN OUT PNDIS_REQUEST pNdisRequest
  3940. )
  3941. /*++
  3942. Routine Description:
  3943. This routine is called by NDIS when our Call Manager sends us an
  3944. NDIS Request. NDIS Requests that are of significance to us are:
  3945. - OID_CO_ADDRESS_CHANGE
  3946. The set of addresses registered with the switch has changed,
  3947. i.e. address registration is complete. We issue an NDIS Request
  3948. ourselves to get the list of addresses registered.
  3949. - OID_CO_SIGNALING_ENABLED
  3950. We ignore this as of now.
  3951. - OID_CO_SIGNALING_DISABLED
  3952. We ignore this for now.
  3953. - OID_CO_AF_CLOSE
  3954. The Call Manager wants us to shut down this Interface.
  3955. We ignore all other OIDs.
  3956. Arguments:
  3957. ProtocolAfContext - Our context for the Address Family binding,
  3958. which is a pointer to the ATMARP Interface.
  3959. ProtocolVcContext - Our context for a VC, which is a pointer to
  3960. an ATMARP VC structure.
  3961. ProtocolPartyContext - Our context for a Party. Since we don't do
  3962. PMP, this is ignored (must be NULL).
  3963. pNdisRequest - Pointer to the NDIS Request.
  3964. Return Value:
  3965. NDIS_STATUS_SUCCESS if we recognized the OID
  3966. NDIS_STATUS_NOT_RECOGNIZED if we didn't.
  3967. --*/
  3968. {
  3969. PATMARP_INTERFACE pInterface;
  3970. NDIS_STATUS Status;
  3971. pInterface = (PATMARP_INTERFACE)ProtocolAfContext;
  3972. AA_STRUCT_ASSERT(pInterface, aai);
  3973. //
  3974. // Initialize
  3975. //
  3976. Status = NDIS_STATUS_NOT_RECOGNIZED;
  3977. if (pNdisRequest->RequestType == NdisRequestSetInformation)
  3978. {
  3979. switch (pNdisRequest->DATA.SET_INFORMATION.Oid)
  3980. {
  3981. case OID_CO_ADDRESS_CHANGE:
  3982. //
  3983. // The Call Manager says that the list of addresses
  3984. // registered on this interface has changed. Get the
  3985. // (potentially) new ATM address for this interface.
  3986. //
  3987. AA_ACQUIRE_IF_LOCK(pInterface);
  3988. pInterface->AtmInterfaceUp = FALSE;
  3989. AA_RELEASE_IF_LOCK(pInterface);
  3990. AtmArpGetAtmAddress(pInterface);
  3991. Status = NDIS_STATUS_SUCCESS;
  3992. break;
  3993. case OID_CO_SIGNALING_ENABLED: // FALLTHRU
  3994. case OID_CO_SIGNALING_DISABLED:
  3995. // Ignored for now
  3996. Status = NDIS_STATUS_SUCCESS;
  3997. break;
  3998. case OID_CO_AF_CLOSE:
  3999. AA_ACQUIRE_IF_LOCK(pInterface);
  4000. pInterface->AdminState = pInterface->State = IF_STATUS_DOWN;
  4001. pInterface->LastChangeTime = GetTimeTicks();
  4002. AA_RELEASE_IF_LOCK(pInterface);
  4003. AtmArpShutdownInterface(pInterface);
  4004. Status = NDIS_STATUS_SUCCESS;
  4005. break;
  4006. default:
  4007. break;
  4008. }
  4009. }
  4010. return (Status);
  4011. }
  4012. VOID
  4013. AtmArpCoRequestCompleteHandler(
  4014. IN NDIS_STATUS Status,
  4015. IN NDIS_HANDLE ProtocolAfContext,
  4016. IN NDIS_HANDLE ProtocolVcContext OPTIONAL,
  4017. IN NDIS_HANDLE ProtocolPartyContext OPTIONAL,
  4018. IN PNDIS_REQUEST pNdisRequest
  4019. )
  4020. /*++
  4021. Routine Description:
  4022. This routine is called by NDIS when a previous call to NdisCoRequest
  4023. that had pended, is complete. We handle this based on the request
  4024. we had sent, which has to be one of:
  4025. - OID_CO_GET_ADDRESSES
  4026. Get all addresses registered on the specified AF binding.
  4027. Arguments:
  4028. Status - Status of the Request.
  4029. ProtocolAfContext - Our context for the Address Family binding,
  4030. which is a pointer to the ATMARP Interface.
  4031. ProtocolVcContext - Our context for a VC, which is a pointer to
  4032. an ATMARP VC structure.
  4033. ProtocolPartyContext - Our context for a Party. Since we don't do
  4034. PMP, this is ignored (must be NULL).
  4035. pNdisRequest - Pointer to the NDIS Request.
  4036. Return Value:
  4037. None
  4038. --*/
  4039. {
  4040. PATMARP_INTERFACE pInterface;
  4041. ULONG Oid;
  4042. pInterface = (PATMARP_INTERFACE)ProtocolAfContext;
  4043. AA_STRUCT_ASSERT(pInterface, aai);
  4044. if (pNdisRequest->RequestType == NdisRequestQueryInformation)
  4045. {
  4046. switch (pNdisRequest->DATA.QUERY_INFORMATION.Oid)
  4047. {
  4048. case OID_CO_GET_ADDRESSES:
  4049. AtmArpHandleGetAddressesComplete(
  4050. Status,
  4051. pInterface,
  4052. pNdisRequest
  4053. );
  4054. break;
  4055. default:
  4056. AADEBUGP(AAD_ERROR,
  4057. ("CoRequestComplete: pNdisReq 0x%x, unknown Query Oid 0x%x\n",
  4058. pNdisRequest,
  4059. pNdisRequest->DATA.QUERY_INFORMATION.Oid));
  4060. AA_ASSERT(FALSE);
  4061. break;
  4062. }
  4063. }
  4064. else
  4065. {
  4066. Oid = pNdisRequest->DATA.QUERY_INFORMATION.Oid;
  4067. switch (Oid)
  4068. {
  4069. case OID_CO_ADD_ADDRESS: // FALLTHRU
  4070. case OID_CO_DELETE_ADDRESS:
  4071. AtmArpHandleModAddressComplete(
  4072. Status,
  4073. pInterface,
  4074. pNdisRequest,
  4075. Oid
  4076. );
  4077. break;
  4078. default:
  4079. AADEBUGP(AAD_ERROR,
  4080. ("CoRequestComplete: pNdisReq 0x%x, unknown Set Oid 0x%x\n",
  4081. pNdisRequest, Oid));
  4082. AA_ASSERT(FALSE);
  4083. break;
  4084. }
  4085. }
  4086. AA_FREE_MEM(pNdisRequest);
  4087. }
  4088. VOID
  4089. AtmArpGetAtmAddress(
  4090. IN PATMARP_INTERFACE pInterface
  4091. )
  4092. /*++
  4093. Routine Description:
  4094. Send a request to the Call Manager to retrieve the ATM address
  4095. registered with the switch on the given interface.
  4096. This is called when the Call Manager tells us that there has been
  4097. a change in its list of addresses registered with the switch.
  4098. Normally, this happens when we start up our signalling stack (i.e.
  4099. initial address registration), but it might happen during runtime,
  4100. for example, if the link goes down and up, or we get physically
  4101. connected to a different switch...
  4102. In any case, we issue an NDIS Request to the Call Manager to retrieve
  4103. the first address it has registered. Action then continues in
  4104. AtmArpHandleGetAddressesComplete.
  4105. Arguments:
  4106. pInterface - Interface structure for which this event occurred.
  4107. Return Value:
  4108. None
  4109. --*/
  4110. {
  4111. PNDIS_REQUEST pNdisRequest;
  4112. NDIS_HANDLE NdisAfHandle;
  4113. NDIS_HANDLE NdisAdapterHandle;
  4114. NDIS_STATUS Status;
  4115. PCO_ADDRESS_LIST pAddressList;
  4116. ULONG RequestSize;
  4117. AADEBUGP(AAD_INFO, ("GetAtmAddress: pIf 0x%x\n", pInterface));
  4118. AA_ACQUIRE_IF_LOCK(pInterface);
  4119. NdisAfHandle = pInterface->NdisAfHandle;
  4120. NdisAdapterHandle = pInterface->NdisAdapterHandle;
  4121. AA_RELEASE_IF_LOCK(pInterface);
  4122. RequestSize = sizeof(CO_ADDRESS_LIST) + sizeof(CO_ADDRESS) + sizeof(ATM_ADDRESS);
  4123. //
  4124. // Allocate all that we need.
  4125. //
  4126. AA_ALLOC_MEM(pNdisRequest, NDIS_REQUEST, sizeof(NDIS_REQUEST)+RequestSize);
  4127. if (pNdisRequest != (PNDIS_REQUEST)NULL)
  4128. {
  4129. pAddressList = (PCO_ADDRESS_LIST)((PUCHAR)pNdisRequest + sizeof(NDIS_REQUEST));
  4130. AA_SET_MEM(pAddressList, 0, sizeof(CO_ADDRESS_LIST));
  4131. Status = AtmArpSendNdisCoRequest(
  4132. NdisAdapterHandle,
  4133. NdisAfHandle,
  4134. pNdisRequest,
  4135. NdisRequestQueryInformation,
  4136. OID_CO_GET_ADDRESSES,
  4137. (PVOID)pAddressList,
  4138. RequestSize
  4139. );
  4140. if (Status != NDIS_STATUS_PENDING)
  4141. {
  4142. AtmArpCoRequestCompleteHandler(
  4143. Status,
  4144. (NDIS_HANDLE)pInterface, // ProtocolAfContext
  4145. NULL, // Vc Context
  4146. NULL, // Party Context
  4147. pNdisRequest
  4148. );
  4149. }
  4150. }
  4151. }
  4152. VOID
  4153. AtmArpHandleGetAddressesComplete(
  4154. IN NDIS_STATUS Status,
  4155. IN PATMARP_INTERFACE pInterface,
  4156. IN PNDIS_REQUEST pNdisRequest
  4157. )
  4158. /*++
  4159. Routine Description:
  4160. This is called when we have a reply to our previous call to
  4161. NdisCoRequest(OID_CO_GET_ADDRESSES). Check if we got any addresses
  4162. back: if we did, store the address as our Local ATM Address, and
  4163. if conditions are ripe, start registering ourselves with the ARP
  4164. server.
  4165. Since we allocated the NDIS request, free it here.
  4166. Arguments:
  4167. Status - result of the request
  4168. pInterface - ATMARP interface on which the request was issued
  4169. pNdisRequest - the request itself. This will also contain the
  4170. returned address.
  4171. Return Value:
  4172. None
  4173. --*/
  4174. {
  4175. PCO_ADDRESS_LIST pAddressList;
  4176. ATM_ADDRESS UNALIGNED * pAtmAddress;
  4177. AADEBUGP(AAD_LOUD, ("GetAddr complete: pIf 0x%x, Status 0x%x\n",
  4178. pInterface, Status));
  4179. if (Status == NDIS_STATUS_SUCCESS)
  4180. {
  4181. pAddressList = (PCO_ADDRESS_LIST)
  4182. pNdisRequest->DATA.QUERY_INFORMATION.InformationBuffer;
  4183. AADEBUGP(AAD_LOUD, ("GetAddr complete: pIf 0x%x, Count %d\n",
  4184. pInterface, pAddressList->NumberOfAddresses));
  4185. if (pAddressList->NumberOfAddresses > 0)
  4186. {
  4187. //
  4188. // We have atleast one address here. Copy it in.
  4189. //
  4190. AA_ACQUIRE_IF_LOCK(pInterface);
  4191. pAtmAddress = (ATM_ADDRESS UNALIGNED *)(pAddressList->AddressList.Address);
  4192. AA_COPY_MEM((PUCHAR)&(pInterface->LocalAtmAddress),
  4193. (PUCHAR)pAtmAddress,
  4194. sizeof(ATM_ADDRESS));
  4195. //
  4196. // Patch the selector byte with whatever is configured for
  4197. // this LIS.
  4198. //
  4199. pInterface->LocalAtmAddress.Address[ATM_ADDRESS_LENGTH-1] =
  4200. (UCHAR)(pInterface->SapSelector);
  4201. pInterface->AtmInterfaceUp = TRUE;
  4202. //
  4203. // To force registration:
  4204. //
  4205. AA_SET_FLAG(
  4206. pInterface->Flags,
  4207. AA_IF_SERVER_STATE_MASK,
  4208. AA_IF_SERVER_NO_CONTACT);
  4209. AtmArpStartRegistration(pInterface);
  4210. //
  4211. // The IF lock is released within the above.
  4212. //
  4213. #ifdef IPMCAST
  4214. //
  4215. // Attempt to start our Multicast side, too.
  4216. //
  4217. AA_ACQUIRE_IF_LOCK(pInterface);
  4218. AtmArpMcStartRegistration(pInterface);
  4219. //
  4220. // IF Lock is released within the above.
  4221. //
  4222. #endif // IPMCAST
  4223. //
  4224. // Add any (additional) addresses we want to register with
  4225. // the switch now.
  4226. //
  4227. AtmArpUpdateAddresses(
  4228. pInterface,
  4229. TRUE // Add them
  4230. );
  4231. }
  4232. //
  4233. // else no address is registered currently.
  4234. //
  4235. }
  4236. //
  4237. // else our request failed! Wait for another ADDRESS_CHANGE.
  4238. //
  4239. return;
  4240. }
  4241. VOID
  4242. AtmArpUpdateAddresses(
  4243. IN PATMARP_INTERFACE pInterface,
  4244. IN BOOLEAN AddThem
  4245. )
  4246. /*++
  4247. Routine Description:
  4248. Update the list of addresses we want the Call manager to register
  4249. with the switch: either add addresses or delete them. We do this
  4250. only if we are running in an SVC environment.
  4251. Arguments:
  4252. pInterface - Pointer to ATMARP Interface
  4253. AddThem - TRUE if caller wants us to add addresses,
  4254. FALSE if caller wats us to delete them.
  4255. Return Value:
  4256. None
  4257. --*/
  4258. {
  4259. PATMARP_SAP pAtmArpSap;
  4260. PATMARP_SAP pNextSap;
  4261. PATM_SAP pAtmSap;
  4262. PATM_ADDRESS pAtmAddress;
  4263. PCO_ADDRESS pCoAddress;
  4264. PNDIS_REQUEST pNdisRequest;
  4265. NDIS_HANDLE NdisAfHandle;
  4266. NDIS_HANDLE NdisAdapterHandle;
  4267. NDIS_OID Oid;
  4268. ULONG BufferLength;
  4269. NDIS_STATUS Status;
  4270. BOOLEAN StateIsOkay; // Does the current state allow this request
  4271. ULONG rc; // Ref count
  4272. StateIsOkay = TRUE;
  4273. BufferLength = sizeof(CO_ADDRESS) + sizeof(ATM_ADDRESS);
  4274. AA_ACQUIRE_IF_LOCK(pInterface);
  4275. NdisAfHandle = pInterface->NdisAfHandle;
  4276. NdisAdapterHandle = pInterface->NdisAdapterHandle;
  4277. if (AddThem)
  4278. {
  4279. Oid = OID_CO_ADD_ADDRESS;
  4280. //
  4281. // This is allowed only if the AdminState for the interface
  4282. // is UP.
  4283. //
  4284. if (pInterface->AdminState != IF_STATUS_UP)
  4285. {
  4286. StateIsOkay = FALSE;
  4287. }
  4288. }
  4289. else
  4290. {
  4291. Oid = OID_CO_DELETE_ADDRESS;
  4292. }
  4293. //
  4294. // Check all pre-conditions before progressing.
  4295. //
  4296. if (!(pInterface->PVCOnly) &&
  4297. (StateIsOkay) &&
  4298. (pInterface->AtmInterfaceUp) &&
  4299. (pInterface->NumberOfSaps > 1))
  4300. {
  4301. AA_ASSERT(pInterface->SapList.pNextSap != NULL_PATMARP_SAP);
  4302. //
  4303. // Reference the Interface so that it doesn't go away.
  4304. //
  4305. AtmArpReferenceInterface(pInterface);
  4306. pAtmArpSap = pInterface->SapList.pNextSap;
  4307. AA_RELEASE_IF_LOCK(pInterface);
  4308. do
  4309. {
  4310. if (AA_IS_FLAG_SET(
  4311. pAtmArpSap->Flags,
  4312. AA_SAP_ADDRTYPE_MASK,
  4313. AA_SAP_ADDRTYPE_NEED_ADD))
  4314. {
  4315. //
  4316. // This SAP is of the type that needs to be added/deleted
  4317. // via ILMI
  4318. //
  4319. AA_ALLOC_MEM(
  4320. pNdisRequest,
  4321. NDIS_REQUEST,
  4322. sizeof(NDIS_REQUEST)+
  4323. sizeof(CO_ADDRESS)+
  4324. sizeof(ATM_ADDRESS)
  4325. );
  4326. if (pNdisRequest != (PNDIS_REQUEST)NULL)
  4327. {
  4328. AA_SET_MEM(pNdisRequest, 0, sizeof(NDIS_REQUEST));
  4329. //
  4330. // Stuff in our context for this request, which is a pointer
  4331. // to this ATMARP SAP, into the ProtocolReserved part of
  4332. // this request, so that we can handle completion easily.
  4333. //
  4334. *((PVOID *)(pNdisRequest->ProtocolReserved)) = (PVOID)pAtmArpSap;
  4335. pCoAddress = (PCO_ADDRESS)((PUCHAR)pNdisRequest + sizeof(NDIS_REQUEST));
  4336. pCoAddress->AddressSize = sizeof(ATM_ADDRESS);
  4337. BufferLength = sizeof(CO_ADDRESS) + sizeof(ATM_ADDRESS);
  4338. //
  4339. // Save a pointer to the next SAP
  4340. //
  4341. pNextSap = pAtmArpSap->pNextSap;
  4342. //
  4343. // Get at the ATM address in this SAP.
  4344. //
  4345. pAtmSap = (PATM_SAP)(pAtmArpSap->pInfo->Sap);
  4346. AA_ASSERT(pAtmSap->NumberOfAddresses > 0);
  4347. pAtmAddress = (PATM_ADDRESS)(pAtmSap->Addresses);
  4348. AA_COPY_MEM(pCoAddress->Address, pAtmAddress, sizeof(ATM_ADDRESS));
  4349. Status = AtmArpSendNdisCoRequest(
  4350. NdisAdapterHandle,
  4351. NdisAfHandle,
  4352. pNdisRequest,
  4353. NdisRequestSetInformation,
  4354. Oid,
  4355. (PVOID)pCoAddress,
  4356. BufferLength
  4357. );
  4358. //
  4359. // Go to the next SAP in the list.
  4360. //
  4361. pAtmArpSap = pNextSap;
  4362. }
  4363. else
  4364. {
  4365. //
  4366. // Out of resources.
  4367. //
  4368. break;
  4369. }
  4370. }
  4371. }
  4372. while (pAtmArpSap != NULL_PATMARP_SAP);
  4373. //
  4374. // Remove the reference we added earlier on.
  4375. //
  4376. AA_ACQUIRE_IF_LOCK(pInterface);
  4377. rc = AtmArpDereferenceInterface(pInterface);
  4378. if (rc > 0)
  4379. {
  4380. AA_RELEASE_IF_LOCK(pInterface);
  4381. }
  4382. //
  4383. // else the Interface is gone!
  4384. }
  4385. else
  4386. {
  4387. AA_RELEASE_IF_LOCK(pInterface);
  4388. }
  4389. }
  4390. VOID
  4391. AtmArpHandleModAddressComplete(
  4392. IN NDIS_STATUS Status,
  4393. IN PATMARP_INTERFACE pInterface,
  4394. IN PNDIS_REQUEST pNdisRequest,
  4395. IN ULONG Oid
  4396. )
  4397. /*++
  4398. Routine Description:
  4399. This is called when we have a reply to our previous call to
  4400. NdisCoRequest(OID_CO_ADD_ADDRESS or OID_CO_DELETE_ADDRESS).
  4401. All we do now is to update the state on the ATMARP SAP.
  4402. Arguments:
  4403. Status - the result of our request.
  4404. pInterface - ATMARP interface pointer.
  4405. pNdisRequest - the request we had sent.
  4406. Oid - CO_OID_ADD_ADDRESS or CO_OID_DELETE_ADDRESS
  4407. Return Value:
  4408. None
  4409. --*/
  4410. {
  4411. PATMARP_SAP pAtmArpSap;
  4412. pAtmArpSap = (PATMARP_SAP)(*((PVOID *)(pNdisRequest->ProtocolReserved)));
  4413. AA_STRUCT_ASSERT(pAtmArpSap, aas);
  4414. AA_ACQUIRE_IF_LOCK(pInterface);
  4415. //
  4416. // Update the state on this ATMARP SAP.
  4417. //
  4418. if ((Oid == OID_CO_ADD_ADDRESS) && (Status == NDIS_STATUS_SUCCESS))
  4419. {
  4420. AA_SET_FLAG(pAtmArpSap->Flags,
  4421. AA_SAP_ILMI_STATE_MASK,
  4422. AA_SAP_ILMI_STATE_ADDED);
  4423. }
  4424. else
  4425. {
  4426. AA_SET_FLAG(pAtmArpSap->Flags,
  4427. AA_SAP_ILMI_STATE_MASK,
  4428. AA_SAP_ILMI_STATE_IDLE);
  4429. }
  4430. AA_RELEASE_IF_LOCK(pInterface);
  4431. }
  4432. NDIS_STATUS
  4433. AtmArpSendNdisCoRequest(
  4434. IN NDIS_HANDLE NdisAdapterHandle,
  4435. IN NDIS_HANDLE NdisAfHandle,
  4436. IN PNDIS_REQUEST pNdisRequest,
  4437. IN NDIS_REQUEST_TYPE RequestType,
  4438. IN NDIS_OID Oid,
  4439. IN PVOID pBuffer,
  4440. IN ULONG BufferLength
  4441. )
  4442. /*++
  4443. Routine Description:
  4444. Send an NDIS Connection Oriented request to the Call Manager. We
  4445. allocate an NDIS_REQUEST structure, link the supplied buffer to it,
  4446. and send the request. If the request does not pend, we call our
  4447. completion routine from here.
  4448. Arguments:
  4449. NdisAdapterHandle - Binding Handle to be used in the request
  4450. NdisAfHandle - AF Handle value to be used in the request
  4451. pNdisRequest - Pointer to NDIS request structure
  4452. RequestType - Set/Query information
  4453. Oid - OID to be passed in the request
  4454. pBuffer - place for value(s)
  4455. BufferLength - length of above
  4456. Return Value:
  4457. Status of the NdisCoRequest.
  4458. --*/
  4459. {
  4460. NDIS_STATUS Status;
  4461. //
  4462. // Fill in the NDIS Request structure
  4463. //
  4464. pNdisRequest->RequestType = RequestType;
  4465. if (RequestType == NdisRequestQueryInformation)
  4466. {
  4467. pNdisRequest->DATA.QUERY_INFORMATION.Oid = Oid;
  4468. pNdisRequest->DATA.QUERY_INFORMATION.InformationBuffer = pBuffer;
  4469. pNdisRequest->DATA.QUERY_INFORMATION.InformationBufferLength = BufferLength;
  4470. pNdisRequest->DATA.QUERY_INFORMATION.BytesWritten = 0;
  4471. pNdisRequest->DATA.QUERY_INFORMATION.BytesNeeded = BufferLength;
  4472. }
  4473. else
  4474. {
  4475. pNdisRequest->DATA.SET_INFORMATION.Oid = Oid;
  4476. pNdisRequest->DATA.SET_INFORMATION.InformationBuffer = pBuffer;
  4477. pNdisRequest->DATA.SET_INFORMATION.InformationBufferLength = BufferLength;
  4478. pNdisRequest->DATA.SET_INFORMATION.BytesRead = 0;
  4479. pNdisRequest->DATA.SET_INFORMATION.BytesNeeded = 0;
  4480. }
  4481. Status = NdisCoRequest(
  4482. NdisAdapterHandle,
  4483. NdisAfHandle,
  4484. NULL, // No VC handle
  4485. NULL, // No Party Handle
  4486. pNdisRequest);
  4487. return (Status);
  4488. }