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.

1779 lines
50 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: A L A N E O B J . C P P
  7. //
  8. // Contents: Implementation of the CALaneCfg notify object model
  9. //
  10. // Notes:
  11. //
  12. // Author: v-lcleet 01 Aug 97
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "alaneobj.h"
  18. #include "alanepsh.h"
  19. #include "ncreg.h"
  20. #include "netconp.h"
  21. #include "ncpnp.h"
  22. #include "alanehlp.h"
  23. static const WCHAR c_szAtmLane[] = L"AtmLane";
  24. static const WCHAR c_szElanList[] = L"ElanList";
  25. static const WCHAR c_szElanDevice[] = L"Device";
  26. static const WCHAR c_szElanName[] = L"ElanName";
  27. extern const WCHAR c_szDevice[];
  28. extern const WCHAR c_szInfId_MS_AtmElan[];
  29. const WCHAR c_szAtmAdapterPnpId[] = L"AtmAdapterPnpId";
  30. //
  31. // CALaneCfg
  32. //
  33. // Constructor/Destructor methods
  34. //
  35. CALaneCfg::CALaneCfg(VOID) :
  36. m_pncc(NULL),
  37. m_pnc(NULL),
  38. m_ppsp(NULL),
  39. m_pAdapterSecondary(NULL),
  40. m_pUnkContext(NULL)
  41. {
  42. m_fDirty = FALSE;
  43. m_fValid = FALSE;
  44. m_fUpgrade = FALSE;
  45. m_fNoElanInstalled = TRUE;
  46. return;
  47. }
  48. CALaneCfg::~CALaneCfg(VOID)
  49. {
  50. ClearAdapterList(&m_lstAdaptersPrimary);
  51. ClearAdapterInfo(m_pAdapterSecondary);
  52. ReleaseObj(m_pncc);
  53. ReleaseObj(m_pnc);
  54. delete m_ppsp;
  55. // Just a safty check to make sure the context is released.
  56. AssertSz((m_pUnkContext == NULL), "Why is context not released ?");
  57. ReleaseObj(m_pUnkContext) ;
  58. return;
  59. }
  60. //
  61. // CALaneCfg
  62. //
  63. // INetCfgComponentControl interface methods
  64. //
  65. STDMETHODIMP CALaneCfg::Initialize (INetCfgComponent* pncc,
  66. INetCfg* pnc,
  67. BOOL fInstalling)
  68. {
  69. HRESULT hr = S_OK;
  70. Validate_INetCfgNotify_Initialize(pncc, pnc, fInstalling);
  71. // reference and save away the component and interface.
  72. AddRefObj(m_pncc = pncc);
  73. AddRefObj(m_pnc = pnc);
  74. // if not installing then load the current config from registry
  75. if (!fInstalling)
  76. {
  77. hr = HrLoadConfiguration();
  78. }
  79. Validate_INetCfgNotify_Initialize_Return(hr);
  80. TraceError("CALaneCfg::Initialize", hr);
  81. return hr;
  82. }
  83. STDMETHODIMP CALaneCfg::Validate ()
  84. {
  85. return S_OK;
  86. }
  87. STDMETHODIMP CALaneCfg::CancelChanges ()
  88. {
  89. return S_OK;
  90. }
  91. STDMETHODIMP CALaneCfg::ApplyRegistryChanges ()
  92. {
  93. HRESULT hr = S_OK;
  94. if (m_fValid && m_fDirty)
  95. {
  96. UpdateElanDisplayNames();
  97. // flush out the registry and send reconfig notifications
  98. hr = HrFlushConfiguration();
  99. }
  100. else
  101. {
  102. // no change
  103. hr = S_FALSE;
  104. }
  105. TraceError("CALaneCfg::ApplyRegistryChanges",
  106. (hr == S_FALSE) ? S_OK : hr);
  107. return hr;
  108. }
  109. // INetCfgComponentSetup interface methods
  110. //
  111. STDMETHODIMP CALaneCfg::Install (DWORD dwSetupFlags)
  112. {
  113. // mark configuration as valid (but empty)
  114. m_fValid = TRUE;
  115. return S_OK;
  116. }
  117. STDMETHODIMP CALaneCfg::Upgrade( DWORD dwSetupFlags,
  118. DWORD dwUpgradeFomBuildNo )
  119. {
  120. // mark configuration as valid (but empty)
  121. m_fValid = TRUE;
  122. m_fUpgrade = TRUE;
  123. return S_OK;
  124. }
  125. STDMETHODIMP CALaneCfg::ReadAnswerFile (PCWSTR pszAnswerFile,
  126. PCWSTR pszAnswerSection)
  127. {
  128. return S_OK;
  129. }
  130. STDMETHODIMP CALaneCfg::Removing ()
  131. {
  132. // mark everything for deletion
  133. (VOID) HrMarkAllDeleted();
  134. return S_OK;
  135. }
  136. //
  137. // CALaneCfg
  138. //
  139. // INetCfgProperties interface methods
  140. //
  141. STDMETHODIMP CALaneCfg::QueryPropertyUi(IUnknown* pUnk)
  142. {
  143. HRESULT hr = S_FALSE;
  144. if (pUnk)
  145. {
  146. // Is this a lan connection ?
  147. INetLanConnectionUiInfo * pLanConnUiInfo;
  148. hr = pUnk->QueryInterface( IID_INetLanConnectionUiInfo,
  149. reinterpret_cast<LPVOID *>(&pLanConnUiInfo));
  150. if(FAILED(hr))
  151. {
  152. // don't show UI
  153. hr = S_FALSE;
  154. }
  155. }
  156. TraceError("CALaneCfg::QueryPropertyUi", hr);
  157. return hr;
  158. }
  159. STDMETHODIMP CALaneCfg::SetContext(IUnknown * pUnk)
  160. {
  161. HRESULT hr = S_OK;
  162. // release previous context, if any
  163. if (m_pUnkContext)
  164. ReleaseObj(m_pUnkContext);
  165. m_pUnkContext = NULL;
  166. if (pUnk) // set the new context
  167. {
  168. m_pUnkContext = pUnk;
  169. m_pUnkContext->AddRef();
  170. }
  171. TraceError("CALaneCfg::SetContext", hr);
  172. return hr;
  173. }
  174. STDMETHODIMP CALaneCfg::MergePropPages (
  175. IN OUT DWORD* pdwDefPages,
  176. OUT LPBYTE* pahpspPrivate,
  177. OUT UINT* pcPages,
  178. IN HWND hwndParent,
  179. OUT PCWSTR* pszStartPage)
  180. {
  181. Validate_INetCfgProperties_MergePropPages(pdwDefPages, pahpspPrivate,
  182. pcPages, hwndParent, pszStartPage);
  183. // Don't show any default pages
  184. *pdwDefPages = 0;
  185. *pcPages = 0;
  186. *pahpspPrivate = NULL;
  187. HPROPSHEETPAGE* ahpsp = NULL;
  188. HRESULT hr = HrALaneSetupPsh(&ahpsp);
  189. if (SUCCEEDED(hr))
  190. {
  191. *pahpspPrivate = (LPBYTE)ahpsp;
  192. *pcPages = c_cALanePages;
  193. }
  194. Validate_INetCfgProperties_MergePropPages_Return(hr);
  195. TraceError("CALaneCfg::MergePropPages", hr);
  196. return hr;
  197. }
  198. STDMETHODIMP CALaneCfg::ValidateProperties (HWND hwndSheet)
  199. {
  200. return S_OK;
  201. }
  202. STDMETHODIMP CALaneCfg::CancelProperties ()
  203. {
  204. // throw away the secondary adapter list
  205. ClearAdapterInfo(m_pAdapterSecondary);
  206. m_pAdapterSecondary = NULL;
  207. return S_OK;
  208. }
  209. STDMETHODIMP CALaneCfg::ApplyProperties ()
  210. {
  211. HRESULT hr = S_OK;
  212. ATMLANE_ADAPTER_INFO_LIST::iterator iterLstAdapters;
  213. ELAN_INFO_LIST::iterator iterLstElans;
  214. CALaneCfgElanInfo * pElanInfo;
  215. INetCfgComponent * pnccAtmElan = NULL;
  216. tstring strAtmElan;
  217. // go thru the secondary adapter info and
  218. // add miniports for elans that were added and
  219. // remove miniports for elans that were deleted.
  220. // loop thru the elan list on this adapter
  221. BOOL bCommitNow = FALSE;
  222. for (iterLstElans = m_pAdapterSecondary->m_lstElans.begin();
  223. iterLstElans != m_pAdapterSecondary->m_lstElans.end();
  224. iterLstElans++)
  225. {
  226. pElanInfo = *iterLstElans;
  227. if (pElanInfo->m_fCreateMiniportOnPropertyApply)
  228. {
  229. bCommitNow = TRUE;
  230. // create associated miniport
  231. hr = HrAddOrRemoveAdapter(m_pnc,
  232. c_szInfId_MS_AtmElan, ARA_ADD,
  233. NULL, 1, &pnccAtmElan);
  234. if (S_OK == hr)
  235. {
  236. // This is a new Elan
  237. pElanInfo->m_fNewElan = TRUE;
  238. // BindName
  239. PWSTR pszTmpBindName;
  240. hr = pnccAtmElan->GetBindName(&pszTmpBindName);
  241. if (SUCCEEDED(hr))
  242. {
  243. pElanInfo->SetElanBindName(pszTmpBindName);
  244. CoTaskMemFree(pszTmpBindName);
  245. // Device param
  246. strAtmElan = c_szDevice;
  247. strAtmElan.append(pElanInfo->SzGetElanBindName());
  248. pElanInfo->SetElanDeviceName(strAtmElan.c_str());
  249. }
  250. ReleaseObj(pnccAtmElan);
  251. }
  252. if (FAILED(hr))
  253. {
  254. TraceError("CALaneCfg::ApplyProperties, failed creating an Elan", hr);
  255. hr = S_OK;
  256. }
  257. }
  258. if (pElanInfo->m_fRemoveMiniportOnPropertyApply)
  259. {
  260. bCommitNow = TRUE;
  261. pElanInfo = *iterLstElans;
  262. hr = HrRemoveMiniportInstance(pElanInfo->SzGetElanBindName());
  263. if (FAILED(hr))
  264. {
  265. pElanInfo->m_fDeleted = FALSE;
  266. TraceError("CALaneCfg::ApplyProperties, failed removing an Elan", hr);
  267. hr = S_OK;
  268. }
  269. }
  270. }
  271. // all is well
  272. // copy secondary list to primary
  273. CopyAdapterInfoSecondaryToPrimary();
  274. m_fDirty = TRUE;
  275. ClearAdapterInfo(m_pAdapterSecondary);
  276. m_pAdapterSecondary = NULL;
  277. Validate_INetCfgProperties_ApplyProperties_Return(hr);
  278. if(bCommitNow && SUCCEEDED(hr))
  279. {
  280. hr = NETCFG_S_COMMIT_NOW;
  281. }
  282. TraceError("CALaneCfg::ApplyProperties", hr);
  283. return hr;
  284. }
  285. //
  286. // CALaneCfg
  287. //
  288. // INetCfgBindNotify interface methods
  289. //
  290. STDMETHODIMP CALaneCfg::QueryBindingPath (DWORD dwChangeFlag,
  291. INetCfgBindingPath* pncbp)
  292. {
  293. return S_OK;
  294. }
  295. STDMETHODIMP CALaneCfg::NotifyBindingPath (DWORD dwChangeFlag,
  296. INetCfgBindingPath* pncbp)
  297. {
  298. Assert(!(dwChangeFlag & NCN_ADD && dwChangeFlag & NCN_REMOVE));
  299. Assert(!(dwChangeFlag & NCN_ENABLE && dwChangeFlag & NCN_DISABLE));
  300. // If we are told to add a card, we must be told at the same time whether the
  301. // binding is enabled or disabled
  302. Assert(FImplies((dwChangeFlag & NCN_ADD),
  303. ((dwChangeFlag & NCN_ENABLE)||(dwChangeFlag & NCN_DISABLE))));
  304. INetCfgComponent * pnccLastComponent;
  305. HRESULT hr = HrGetLastComponentAndInterface(pncbp,
  306. &pnccLastComponent, NULL);
  307. if (S_OK == hr)
  308. {
  309. PWSTR pszBindName;
  310. hr = pnccLastComponent->GetBindName(&pszBindName);
  311. if (S_OK == hr)
  312. {
  313. if (dwChangeFlag & NCN_ADD)
  314. {
  315. hr = HrNotifyBindingAdd(pnccLastComponent, pszBindName);
  316. }
  317. else if (dwChangeFlag & NCN_REMOVE)
  318. {
  319. hr = HrNotifyBindingRemove(pnccLastComponent, pszBindName);
  320. }
  321. else
  322. {
  323. // simply mark the adapter as binding changed so we don't
  324. // send Elan add\remove notifications (Raid #255910)
  325. // Get the adapter component's instance name
  326. CALaneCfgAdapterInfo * pAdapterInfo;
  327. // search the in-memory list for this adapter
  328. BOOL fFound;
  329. ATMLANE_ADAPTER_INFO_LIST::iterator iterLstAdapters;
  330. for (iterLstAdapters = m_lstAdaptersPrimary.begin(), fFound = FALSE;
  331. iterLstAdapters != m_lstAdaptersPrimary.end();
  332. iterLstAdapters++)
  333. {
  334. pAdapterInfo = *iterLstAdapters;
  335. if (!lstrcmpiW(pszBindName, pAdapterInfo->SzGetAdapterBindName()))
  336. {
  337. fFound = TRUE;
  338. break;
  339. }
  340. }
  341. if (fFound)
  342. {
  343. // mark it as changed
  344. pAdapterInfo->m_fBindingChanged = TRUE;
  345. }
  346. }
  347. CoTaskMemFree (pszBindName);
  348. }
  349. ReleaseObj (pnccLastComponent);
  350. }
  351. TraceError("CALaneCfg::NotifyBindingPath", hr);
  352. return hr;
  353. }
  354. //
  355. // CALaneCfg
  356. //
  357. // Private methods
  358. //
  359. HRESULT
  360. CALaneCfg::HrNotifyBindingAdd (
  361. INetCfgComponent* pnccAdapter,
  362. PCWSTR pszBindName)
  363. {
  364. HRESULT hr = S_OK;
  365. // $REVIEW(tongl 1/25/98): Added this: we should see if this adapter is
  366. // is already in our list but marked as for deletion. If so, simply unmark
  367. // the adapter and all of it's Elans. The Binding Add could be a fake one
  368. // when it is in uprade process.
  369. BOOL fFound;
  370. CALaneCfgAdapterInfo* pAdapterInfo = NULL;
  371. // search the in-memory list for this adapter
  372. ATMLANE_ADAPTER_INFO_LIST::iterator iterLstAdapters;
  373. for (iterLstAdapters = m_lstAdaptersPrimary.begin(), fFound = FALSE;
  374. iterLstAdapters != m_lstAdaptersPrimary.end();
  375. iterLstAdapters++)
  376. {
  377. pAdapterInfo = *iterLstAdapters;
  378. if (!lstrcmpiW(pszBindName, pAdapterInfo->SzGetAdapterBindName()))
  379. {
  380. fFound = TRUE;
  381. break;
  382. }
  383. }
  384. if (fFound) // Add an old adapter back
  385. {
  386. Assert(pAdapterInfo->m_fDeleted);
  387. // mark it un-deleted
  388. pAdapterInfo->m_fDeleted = FALSE;
  389. if (m_fUpgrade)
  390. {
  391. // the Elans are not deleted, just mark them as un-deleted
  392. ELAN_INFO_LIST::iterator iterLstElans;
  393. for (iterLstElans = pAdapterInfo->m_lstElans.begin();
  394. iterLstElans!= pAdapterInfo->m_lstElans.end();
  395. iterLstElans++)
  396. {
  397. Assert((*iterLstElans)->m_fDeleted);
  398. (*iterLstElans)->m_fDeleted = FALSE;
  399. }
  400. }
  401. }
  402. else
  403. {
  404. // if this is a new atm adapter
  405. // Create a new in-memory adapter object
  406. pAdapterInfo = new CALaneCfgAdapterInfo;
  407. if (pAdapterInfo)
  408. {
  409. GUID guidAdapter;
  410. hr = pnccAdapter->GetInstanceGuid(&guidAdapter);
  411. if (S_OK == hr)
  412. {
  413. pAdapterInfo->m_guidInstanceId = guidAdapter;
  414. }
  415. // the adapter is newly added
  416. pAdapterInfo->m_fBindingChanged = TRUE;
  417. // Set the bind name of the adapter
  418. pAdapterInfo->SetAdapterBindName(pszBindName);
  419. // Set the PnpId of the adapter
  420. PWSTR pszPnpDevNodeId;
  421. hr = pnccAdapter->GetPnpDevNodeId(&pszPnpDevNodeId);
  422. if (S_OK == hr)
  423. {
  424. Assert(pszPnpDevNodeId);
  425. pAdapterInfo->SetAdapterPnpId(pszPnpDevNodeId);
  426. CoTaskMemFree(pszPnpDevNodeId);
  427. }
  428. // Create a new in-memory elan object
  429. CALaneCfgElanInfo * pElanInfo;
  430. pElanInfo = new CALaneCfgElanInfo;
  431. if (pElanInfo)
  432. {
  433. pElanInfo->m_fNewElan = TRUE;
  434. // Install a virtual miniport for a default ELAN
  435. INetCfgComponent* pnccAtmElan;
  436. hr = HrAddOrRemoveAdapter(m_pnc, c_szInfId_MS_AtmElan,
  437. ARA_ADD, NULL, 1, &pnccAtmElan);
  438. if (SUCCEEDED(hr))
  439. {
  440. Assert(pnccAtmElan);
  441. // Update the BindName
  442. PWSTR pszElanBindName;
  443. hr = pnccAtmElan->GetBindName(&pszElanBindName);
  444. if (S_OK == hr)
  445. {
  446. pElanInfo->SetElanBindName(pszElanBindName);
  447. CoTaskMemFree(pszElanBindName);
  448. }
  449. // Update the Device param
  450. tstring strAtmElan;
  451. strAtmElan = c_szDevice;
  452. strAtmElan.append(pElanInfo->SzGetElanBindName());
  453. pElanInfo->SetElanDeviceName(strAtmElan.c_str());
  454. // Push the Elan onto the the adapter's list
  455. pAdapterInfo->m_lstElans.push_back(pElanInfo);
  456. // Push the Adapter onto the adapter list
  457. m_lstAdaptersPrimary.push_back(pAdapterInfo);
  458. // Mark the in-memory configuration dirty
  459. m_fDirty = TRUE;
  460. ReleaseObj(pnccAtmElan);
  461. }
  462. }
  463. }
  464. }
  465. TraceError("CALaneCfg::HrNotifyBindingAdd", hr);
  466. return hr;
  467. }
  468. HRESULT
  469. CALaneCfg::HrNotifyBindingRemove (
  470. INetCfgComponent* pnccAdapter,
  471. PCWSTR pszBindName)
  472. {
  473. HRESULT hr = S_OK;
  474. CALaneCfgAdapterInfo * pAdapterInfo;
  475. // search the in-memory list for this adapter
  476. BOOL fFound;
  477. ATMLANE_ADAPTER_INFO_LIST::iterator iterLstAdapters;
  478. for (iterLstAdapters = m_lstAdaptersPrimary.begin(), fFound = FALSE;
  479. iterLstAdapters != m_lstAdaptersPrimary.end();
  480. iterLstAdapters++)
  481. {
  482. pAdapterInfo = *iterLstAdapters;
  483. if (!lstrcmpiW (pszBindName, pAdapterInfo->SzGetAdapterBindName()))
  484. {
  485. fFound = TRUE;
  486. break;
  487. }
  488. }
  489. if (fFound)
  490. {
  491. // mark it deleted
  492. pAdapterInfo->m_fDeleted = TRUE;
  493. // mark as binding changed
  494. pAdapterInfo->m_fBindingChanged = TRUE;
  495. // if this is upgrade, then mark all associated ELANs deleted
  496. // otherwise, delete them now
  497. HRESULT hrElan = S_OK;
  498. for (ELAN_INFO_LIST::iterator iterLstElans = pAdapterInfo->m_lstElans.begin();
  499. iterLstElans!= pAdapterInfo->m_lstElans.end();
  500. iterLstElans++)
  501. {
  502. if (!m_fUpgrade)
  503. {
  504. // Remove corresponding miniport.
  505. hrElan = HrRemoveMiniportInstance((*iterLstElans)->SzGetElanBindName());
  506. if (SUCCEEDED(hr))
  507. {
  508. (*iterLstElans)->m_fDeleted = TRUE;
  509. }
  510. else
  511. {
  512. TraceError("HrRemoveMiniportInstance failed", hrElan);
  513. hrElan = S_OK;
  514. }
  515. }
  516. }
  517. // mark the in-memory configuration dirty
  518. m_fDirty = TRUE;
  519. }
  520. TraceError("CALaneCfg::HrNotifyBindingRemove", hr);
  521. return hr;
  522. }
  523. HRESULT CALaneCfg::HrLoadConfiguration()
  524. {
  525. HRESULT hr = S_OK;
  526. // mark the memory version of the registy valid
  527. m_fValid = TRUE;
  528. // open adapter list subkey
  529. HKEY hkeyAdapterList = NULL;
  530. // Try to open an existing key first.
  531. //
  532. hr = HrRegOpenAdapterKey(c_szAtmLane, FALSE, &hkeyAdapterList);
  533. if (FAILED(hr))
  534. {
  535. // Only on failure do we try to create it
  536. //
  537. hr = HrRegOpenAdapterKey(c_szAtmLane, TRUE, &hkeyAdapterList);
  538. }
  539. if (S_OK == hr)
  540. {
  541. WCHAR szBuf[MAX_PATH+1];
  542. FILETIME time;
  543. DWORD dwSize;
  544. DWORD dwRegIndex = 0;
  545. dwSize = celems(szBuf);
  546. while (S_OK == (hr = HrRegEnumKeyEx (hkeyAdapterList, dwRegIndex,
  547. szBuf, &dwSize, NULL, NULL, &time)))
  548. {
  549. Assert(szBuf);
  550. // load this adapter's config
  551. hr = HrLoadAdapterConfiguration (hkeyAdapterList, szBuf);
  552. if (S_OK != hr)
  553. {
  554. TraceTag (ttidAtmLane, "CALaneCfg::HrLoadConfiguration failed on adapter %S", szBuf);
  555. hr = S_OK;
  556. }
  557. // increment index and reset size variable
  558. dwRegIndex++;
  559. dwSize = celems (szBuf);
  560. }
  561. if (HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS) == hr)
  562. {
  563. hr = S_OK;
  564. }
  565. RegCloseKey (hkeyAdapterList);
  566. }
  567. TraceError("CALaneCfg::HrLoadConfiguration", hr);
  568. return hr;
  569. }
  570. HRESULT CALaneCfg::HrLoadAdapterConfiguration(HKEY hkeyAdapterList,
  571. PWSTR pszAdapterName)
  572. {
  573. HRESULT hr = S_OK;
  574. // load this adapter
  575. CALaneCfgAdapterInfo* pAdapterInfo;
  576. pAdapterInfo = new CALaneCfgAdapterInfo;
  577. if (pAdapterInfo)
  578. {
  579. pAdapterInfo->SetAdapterBindName(pszAdapterName);
  580. m_lstAdaptersPrimary.push_back(pAdapterInfo);
  581. // open this adapter's subkey
  582. HKEY hkeyAdapter = NULL;
  583. DWORD dwDisposition;
  584. hr = HrRegCreateKeyEx(
  585. hkeyAdapterList,
  586. pszAdapterName,
  587. REG_OPTION_NON_VOLATILE,
  588. KEY_ALL_ACCESS,
  589. NULL,
  590. &hkeyAdapter,
  591. &dwDisposition);
  592. if (S_OK == hr)
  593. {
  594. // load the PnpId
  595. INetCfgComponent* pnccAdapter = NULL;
  596. hr = HrFindNetCardInstance(pszAdapterName, &pnccAdapter);
  597. if (S_OK == hr)
  598. {
  599. PWSTR pszPnpDevNodeId;
  600. hr = pnccAdapter->GetPnpDevNodeId(&pszPnpDevNodeId);
  601. if (S_OK == hr)
  602. {
  603. Assert(pszPnpDevNodeId);
  604. pAdapterInfo->SetAdapterPnpId(pszPnpDevNodeId);
  605. CoTaskMemFree(pszPnpDevNodeId);
  606. }
  607. GUID guidAdapter;
  608. hr = pnccAdapter->GetInstanceGuid(&guidAdapter);
  609. if (S_OK == hr)
  610. {
  611. pAdapterInfo->m_guidInstanceId = guidAdapter;
  612. }
  613. // load the ElanList
  614. hr = HrLoadElanListConfiguration(hkeyAdapter, pAdapterInfo);
  615. ReleaseObj(pnccAdapter);
  616. }
  617. else if (S_FALSE == hr)
  618. {
  619. // nromalize return
  620. hr = S_OK;
  621. }
  622. RegCloseKey(hkeyAdapter);
  623. }
  624. }
  625. TraceError("CALaneCfg::HrLoadAdapterConfiguration", hr);
  626. return hr;
  627. }
  628. HRESULT
  629. CALaneCfg::HrLoadElanListConfiguration(
  630. HKEY hkeyAdapter,
  631. CALaneCfgAdapterInfo* pAdapterInfo)
  632. {
  633. HRESULT hr;
  634. // open the ElanList subkey
  635. HKEY hkeyElanList = NULL;
  636. DWORD dwDisposition;
  637. hr = HrRegCreateKeyEx(hkeyAdapter, c_szElanList, REG_OPTION_NON_VOLATILE,
  638. KEY_ALL_ACCESS, NULL, &hkeyElanList, &dwDisposition);
  639. if (S_OK == hr)
  640. {
  641. WCHAR szBuf[MAX_PATH+1];
  642. FILETIME time;
  643. DWORD dwSize;
  644. DWORD dwRegIndex = 0;
  645. dwSize = celems(szBuf);
  646. while(SUCCEEDED(hr = HrRegEnumKeyEx(hkeyElanList, dwRegIndex, szBuf,
  647. &dwSize, NULL, NULL, &time)))
  648. {
  649. Assert(szBuf);
  650. // load this ELAN's config
  651. hr = HrLoadElanConfiguration(hkeyElanList,
  652. szBuf,
  653. pAdapterInfo);
  654. if (S_OK != hr)
  655. {
  656. TraceTag(ttidAtmLane, "CALaneCfg::HrLoadConfiguration failed on Elan %S", szBuf);
  657. hr = S_OK;
  658. }
  659. else if (m_fNoElanInstalled)
  660. {
  661. m_fNoElanInstalled = FALSE;
  662. }
  663. // increment index and reset size variable
  664. dwRegIndex ++;
  665. dwSize = celems(szBuf);
  666. }
  667. if(hr == HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS))
  668. hr = S_OK;
  669. RegCloseKey(hkeyElanList);
  670. }
  671. TraceError("CALaneCfg::HrLoadElanListConfiguration", hr);
  672. return hr;
  673. }
  674. HRESULT
  675. CALaneCfg::HrLoadElanConfiguration(
  676. HKEY hkeyElanList,
  677. PWSTR pszElan,
  678. CALaneCfgAdapterInfo* pAdapterInfo)
  679. {
  680. HRESULT hr = S_OK;
  681. do
  682. {
  683. // load this ELAN info
  684. CALaneCfgElanInfo * pElanInfo = NULL;
  685. pElanInfo = new CALaneCfgElanInfo;
  686. CALaneCfgElanInfo * pOldElanInfo = NULL;
  687. pOldElanInfo = new CALaneCfgElanInfo;
  688. if ((pElanInfo == NULL) ||
  689. (pOldElanInfo == NULL))
  690. {
  691. hr = E_OUTOFMEMORY;
  692. if (pElanInfo)
  693. {
  694. delete pElanInfo;
  695. }
  696. if (pOldElanInfo)
  697. {
  698. delete pOldElanInfo;
  699. }
  700. break;
  701. }
  702. pAdapterInfo->m_lstElans.push_back(pElanInfo);
  703. pElanInfo->SetElanBindName(pszElan);
  704. pAdapterInfo->m_lstOldElans.push_back(pOldElanInfo);
  705. pOldElanInfo->SetElanBindName(pszElan);
  706. // open the ELAN's key
  707. HKEY hkeyElan = NULL;
  708. DWORD dwDisposition;
  709. hr = HrRegCreateKeyEx (hkeyElanList, pszElan, REG_OPTION_NON_VOLATILE,
  710. KEY_ALL_ACCESS, NULL, &hkeyElan, &dwDisposition);
  711. if (S_OK == hr)
  712. {
  713. // read the Device parameter
  714. PWSTR pszElanDevice;
  715. hr = HrRegQuerySzWithAlloc (hkeyElan, c_szElanDevice, &pszElanDevice);
  716. if (S_OK == hr)
  717. {
  718. // load the Device name
  719. pElanInfo->SetElanDeviceName(pszElanDevice);
  720. pOldElanInfo->SetElanDeviceName(pszElanDevice);
  721. MemFree (pszElanDevice);
  722. // read the ELAN Name parameter
  723. PWSTR pszElanName;
  724. hr = HrRegQuerySzWithAlloc (hkeyElan, c_szElanName, &pszElanName);
  725. if (SUCCEEDED(hr))
  726. {
  727. // load the ELAN name
  728. pElanInfo->SetElanName (pszElanName);
  729. pOldElanInfo->SetElanName (pszElanName);
  730. MemFree (pszElanName);
  731. }
  732. }
  733. RegCloseKey (hkeyElan);
  734. }
  735. }
  736. while (FALSE);
  737. TraceError ("CALaneCfg::HrLoadElanConfiguration", hr);
  738. return hr;
  739. }
  740. HRESULT CALaneCfg::HrFlushConfiguration()
  741. {
  742. HRESULT hr = S_OK;
  743. HKEY hkeyAdapterList = NULL;
  744. // Open the "Adapters" list key
  745. hr = ::HrRegOpenAdapterKey(c_szAtmLane, TRUE, &hkeyAdapterList);
  746. if (S_OK == hr)
  747. {
  748. ATMLANE_ADAPTER_INFO_LIST::iterator iterLstAdapters;
  749. CALaneCfgAdapterInfo * pAdapterInfo;
  750. HRESULT hrTmp;
  751. // Iterate thru the adapters
  752. for (iterLstAdapters = m_lstAdaptersPrimary.begin();
  753. iterLstAdapters != m_lstAdaptersPrimary.end();
  754. iterLstAdapters++)
  755. {
  756. pAdapterInfo = *iterLstAdapters;
  757. // Flush this adapter's configuration
  758. hrTmp = HrFlushAdapterConfiguration(hkeyAdapterList, pAdapterInfo);
  759. if (SUCCEEDED(hrTmp))
  760. {
  761. // Raid #255910: only send Elan change notification if the
  762. // binding to the physical adapter has not changed
  763. if (!pAdapterInfo->m_fBindingChanged)
  764. {
  765. // Compare Elan list and send notifications
  766. hrTmp = HrReconfigLane(pAdapterInfo);
  767. if (FAILED(hrTmp))
  768. hrTmp = NETCFG_S_REBOOT;
  769. }
  770. }
  771. else
  772. {
  773. TraceTag(ttidAtmLane,"HrFlushAdapterConfiguration failed for adapter %S", pAdapterInfo->SzGetAdapterBindName());
  774. hrTmp = S_OK;
  775. }
  776. if (S_OK ==hr)
  777. hr = hrTmp;
  778. }
  779. RegCloseKey(hkeyAdapterList);
  780. }
  781. if (hr != NETCFG_S_REBOOT) {
  782. TraceError("CALaneCfg::HrFlushConfiguration", hr);
  783. }
  784. return hr;
  785. }
  786. HRESULT CALaneCfg::HrFlushAdapterConfiguration(HKEY hkeyAdapterList,
  787. CALaneCfgAdapterInfo *pAdapterInfo)
  788. {
  789. HRESULT hr = S_OK;
  790. HKEY hkeyAdapter = NULL;
  791. DWORD dwDisposition;
  792. if (pAdapterInfo->m_fDeleted)
  793. {
  794. // Adapter is marked for deletion
  795. // Delete this adapter's whole registry branch
  796. hr = HrRegDeleteKeyTree(hkeyAdapterList,
  797. pAdapterInfo->SzGetAdapterBindName());
  798. }
  799. else
  800. {
  801. // open this adapter's subkey
  802. hr = HrRegCreateKeyEx(
  803. hkeyAdapterList,
  804. pAdapterInfo->SzGetAdapterBindName(),
  805. REG_OPTION_NON_VOLATILE,
  806. KEY_ALL_ACCESS,
  807. NULL,
  808. &hkeyAdapter,
  809. &dwDisposition);
  810. if (S_OK == hr)
  811. {
  812. // Flush the ELAN configuration
  813. hr = HrFlushElanListConfiguration(hkeyAdapter, pAdapterInfo);
  814. RegCloseKey(hkeyAdapter);
  815. }
  816. }
  817. TraceError("CALaneCfg::HrFlushAdapterConfiguration", hr);
  818. return hr;
  819. }
  820. HRESULT CALaneCfg::HrFlushElanListConfiguration(HKEY hkeyAdapter,
  821. CALaneCfgAdapterInfo *pAdapterInfo)
  822. {
  823. HRESULT hr = S_OK;
  824. HKEY hkeyElanList = NULL;
  825. DWORD dwDisposition;
  826. // Open the Elan list subkey
  827. hr = HrRegCreateKeyEx(
  828. hkeyAdapter,
  829. c_szElanList,
  830. REG_OPTION_NON_VOLATILE,
  831. KEY_ALL_ACCESS,
  832. NULL,
  833. &hkeyElanList,
  834. &dwDisposition);
  835. if (S_OK == hr)
  836. {
  837. ELAN_INFO_LIST::iterator iterLstElans;
  838. CALaneCfgElanInfo * pElanInfo;
  839. // iterate thru the Elans
  840. for (iterLstElans = pAdapterInfo->m_lstElans.begin();
  841. iterLstElans != pAdapterInfo->m_lstElans.end();
  842. iterLstElans++)
  843. {
  844. pElanInfo = *iterLstElans;
  845. hr = HrFlushElanConfiguration(hkeyElanList, pElanInfo);
  846. if (FAILED(hr))
  847. {
  848. TraceError("HrFlushElanConfiguration failure", hr);
  849. hr = S_OK;
  850. }
  851. // $REVIEW(tongl 9/9/98): write ATM adapter's pnp id to registry (#169025)
  852. if ((!pElanInfo->m_fDeleted) && (pElanInfo->m_fNewElan))
  853. {
  854. INetCfgComponent * pnccAtmElan;
  855. hr = HrFindNetCardInstance(pElanInfo->SzGetElanBindName(),
  856. &pnccAtmElan);
  857. if (S_OK == hr)
  858. {
  859. HKEY hkeyElan = NULL;
  860. hr = pnccAtmElan->OpenParamKey(&hkeyElan);
  861. if (S_OK == hr)
  862. {
  863. Assert(hkeyElan);
  864. HrRegSetSz(hkeyElan, c_szAtmAdapterPnpId,
  865. pAdapterInfo->SzGetAdapterPnpId());
  866. }
  867. RegSafeCloseKey(hkeyElan);
  868. }
  869. ReleaseObj(pnccAtmElan);
  870. }
  871. }
  872. RegCloseKey(hkeyElanList);
  873. }
  874. TraceError("CALaneCfg::HrFlushElanListConfiguration", hr);
  875. return hr;
  876. }
  877. HRESULT CALaneCfg::HrFlushElanConfiguration(HKEY hkeyElanList,
  878. CALaneCfgElanInfo *pElanInfo)
  879. {
  880. HRESULT hr = S_OK;
  881. if (pElanInfo->m_fDeleted)
  882. {
  883. PCWSTR szBindName = pElanInfo->SzGetElanBindName();
  884. if (lstrlenW(szBindName)) // only if the bindname is not empty
  885. {
  886. // Elan is marked for deletion
  887. // Delete this Elan's whole registry branch
  888. hr = HrRegDeleteKeyTree(hkeyElanList,
  889. pElanInfo->SzGetElanBindName());
  890. }
  891. }
  892. else
  893. {
  894. HKEY hkeyElan = NULL;
  895. DWORD dwDisposition;
  896. // open/create this Elan's key
  897. hr = HrRegCreateKeyEx(
  898. hkeyElanList,
  899. pElanInfo->SzGetElanBindName(),
  900. REG_OPTION_NON_VOLATILE,
  901. KEY_ALL_ACCESS,
  902. NULL,
  903. &hkeyElan,
  904. &dwDisposition);
  905. if (S_OK == hr)
  906. {
  907. // Write the Device parameter
  908. hr = HrRegSetSz(hkeyElan, c_szElanDevice,
  909. pElanInfo->SzGetElanDeviceName());
  910. if (FAILED(hr))
  911. {
  912. TraceError("Failed save Elan device parameter", hr);
  913. hr = S_OK;
  914. }
  915. // Write the ElanName parameter
  916. hr = HrRegSetSz(hkeyElan, c_szElanName,
  917. pElanInfo->SzGetElanName());
  918. if (FAILED(hr))
  919. {
  920. TraceError("Failed save Elan name parameter", hr);
  921. hr = S_OK;
  922. }
  923. }
  924. RegSafeCloseKey(hkeyElan);
  925. }
  926. TraceError("CALaneCfg::HrFlushElanConfiguration", hr);
  927. return hr;
  928. }
  929. HRESULT CALaneCfg::HrRemoveMiniportInstance(PCWSTR pszBindNameToRemove)
  930. {
  931. // Enumerate adapters in the system.
  932. //
  933. HRESULT hr = S_OK;
  934. CIterNetCfgComponent nccIter (m_pnc, &GUID_DEVCLASS_NET);
  935. BOOL fFound = FALSE;
  936. INetCfgComponent* pnccAdapter;
  937. while ((!fFound) && SUCCEEDED(hr) &&
  938. S_OK == (hr = nccIter.HrNext (&pnccAdapter)))
  939. {
  940. if (FIsComponentId(c_szInfId_MS_AtmElan, pnccAdapter))
  941. {
  942. // Get the bindname of the miniport
  943. PWSTR pszBindName;
  944. hr = pnccAdapter->GetBindName(&pszBindName);
  945. if (S_OK == hr)
  946. {
  947. // If the right one tell it to remove itself and end
  948. BOOL fRemove = !lstrcmpiW (pszBindName, pszBindNameToRemove);
  949. if (fRemove)
  950. {
  951. fFound = TRUE;
  952. hr = HrRemoveComponent( m_pnc, pnccAdapter, NULL, NULL);
  953. }
  954. CoTaskMemFree (pszBindName);
  955. }
  956. }
  957. ReleaseObj (pnccAdapter);
  958. }
  959. TraceError("CALaneCfg::HrRemoveMiniportInstance", hr);
  960. return hr;
  961. }
  962. HRESULT
  963. CALaneCfg::HrFindNetCardInstance(
  964. PCWSTR pszBindNameToFind,
  965. INetCfgComponent** ppncc)
  966. {
  967. *ppncc = NULL;
  968. // Enumerate adapters in the system.
  969. //
  970. HRESULT hr = S_OK;
  971. CIterNetCfgComponent nccIter (m_pnc, &GUID_DEVCLASS_NET);
  972. BOOL fFound = FALSE;
  973. INetCfgComponent* pnccAdapter;
  974. while ((!fFound) && SUCCEEDED(hr) &&
  975. S_OK == (hr = nccIter.HrNext (&pnccAdapter)))
  976. {
  977. // Get the bindname of the miniport
  978. PWSTR pszBindName;
  979. hr = pnccAdapter->GetBindName(&pszBindName);
  980. if (S_OK == hr)
  981. {
  982. // If the right one tell it to remove itself and end
  983. fFound = !lstrcmpiW(pszBindName, pszBindNameToFind);
  984. CoTaskMemFree (pszBindName);
  985. if (fFound)
  986. {
  987. *ppncc = pnccAdapter;
  988. }
  989. }
  990. if (!fFound)
  991. {
  992. ReleaseObj (pnccAdapter);
  993. }
  994. }
  995. TraceHr(ttidError, FAL, hr, (S_FALSE == hr),
  996. "CALaneCfg::HrFindNetCardInstance", hr);
  997. return hr;
  998. }
  999. VOID CALaneCfg::HrMarkAllDeleted()
  1000. {
  1001. ATMLANE_ADAPTER_INFO_LIST::iterator iterLstAdapters;
  1002. ELAN_INFO_LIST::iterator iterLstElans;
  1003. // loop thru the adapter list
  1004. for (iterLstAdapters = m_lstAdaptersPrimary.begin();
  1005. iterLstAdapters != m_lstAdaptersPrimary.end();
  1006. iterLstAdapters++)
  1007. {
  1008. (*iterLstAdapters)->m_fDeleted = TRUE;
  1009. // loop thru the ELAN list
  1010. for (iterLstElans = (*iterLstAdapters)->m_lstElans.begin();
  1011. iterLstElans != (*iterLstAdapters)->m_lstElans.end();
  1012. iterLstElans++)
  1013. {
  1014. (*iterLstElans)->m_fDeleted = TRUE;
  1015. }
  1016. }
  1017. return;
  1018. }
  1019. VOID CALaneCfg::UpdateElanDisplayNames()
  1020. {
  1021. HRESULT hr = S_OK;
  1022. // loop thru the adapter list
  1023. ATMLANE_ADAPTER_INFO_LIST::iterator iterLstAdapters;
  1024. for (iterLstAdapters = m_lstAdaptersPrimary.begin();
  1025. iterLstAdapters != m_lstAdaptersPrimary.end();
  1026. iterLstAdapters++)
  1027. {
  1028. // loop thru the ELAN list
  1029. ELAN_INFO_LIST::iterator iterLstElans;
  1030. CALaneCfgElanInfo * pElanInfo;
  1031. for (iterLstElans = (*iterLstAdapters)->m_lstElans.begin();
  1032. iterLstElans != (*iterLstAdapters)->m_lstElans.end();
  1033. iterLstElans++)
  1034. {
  1035. pElanInfo = *iterLstElans;
  1036. // Update the miniport's display name with
  1037. // the ELAN name appended.
  1038. INetCfgComponent* pnccAtmElan = NULL;
  1039. hr = HrFindNetCardInstance(pElanInfo->SzGetElanBindName(),
  1040. &pnccAtmElan);
  1041. if (S_OK == hr)
  1042. {
  1043. PWSTR pszDisplayName;
  1044. hr = pnccAtmElan->GetDisplayName(&pszDisplayName);
  1045. if (S_OK == hr)
  1046. {
  1047. tstring strNewDisplayName;
  1048. int pos;
  1049. strNewDisplayName = pszDisplayName;
  1050. pos = strNewDisplayName.find_last_of(L"(");
  1051. if (pos != strNewDisplayName.npos)
  1052. strNewDisplayName.resize(pos);
  1053. strNewDisplayName.append(L"(");
  1054. if (lstrlenW(pElanInfo->SzGetElanName()) > 0)
  1055. {
  1056. strNewDisplayName.append(pElanInfo->SzGetElanName());
  1057. }
  1058. else
  1059. {
  1060. strNewDisplayName.append(SzLoadIds(IDS_ALANECFG_UNSPECIFIEDNAME));
  1061. }
  1062. strNewDisplayName.append(L")");
  1063. (VOID)pnccAtmElan->SetDisplayName(strNewDisplayName.c_str());
  1064. CoTaskMemFree(pszDisplayName);
  1065. }
  1066. ReleaseObj(pnccAtmElan);
  1067. }
  1068. }
  1069. }
  1070. }
  1071. HRESULT CALaneCfg::HrALaneSetupPsh(HPROPSHEETPAGE** pahpsp)
  1072. {
  1073. HRESULT hr = S_OK;
  1074. HPROPSHEETPAGE* ahpsp = NULL;
  1075. AssertSz(pahpsp, "We must have a place to put prop sheets");
  1076. // set connections context
  1077. hr = HrSetConnectionContext();
  1078. if SUCCEEDED(hr)
  1079. {
  1080. // copy the primary adapter list to the secondary adapters list
  1081. CopyAdapterInfoPrimaryToSecondary();
  1082. *pahpsp = NULL;
  1083. // Allocate a buffer large enough to hold the handles to all of our
  1084. // property pages.
  1085. ahpsp = (HPROPSHEETPAGE*)CoTaskMemAlloc(sizeof(HPROPSHEETPAGE));
  1086. if (ahpsp)
  1087. {
  1088. if (!m_ppsp)
  1089. delete m_ppsp;
  1090. // Allocate each of the CPropSheetPage objects
  1091. m_ppsp = new CALanePsh(this, m_pAdapterSecondary, g_aHelpIDs_IDD_MAIN);
  1092. // Create the actual PROPSHEETPAGE for each object.
  1093. // This needs to be done regardless of whether the classes existed before.
  1094. ahpsp[0] = m_ppsp->CreatePage(IDD_MAIN, PSP_DEFAULT);
  1095. *pahpsp = ahpsp;
  1096. }
  1097. else
  1098. {
  1099. hr = E_OUTOFMEMORY;
  1100. }
  1101. }
  1102. TraceError("CALaneCfg::HrALaneSetupPsh", hr);
  1103. return hr;
  1104. }
  1105. // Added by tongl at 12\11\97
  1106. HRESULT CALaneCfg::HrSetConnectionContext()
  1107. {
  1108. AssertSz(m_pUnkContext, "Invalid IUnknown pointer passed to CALaneCfg::SetContext?");
  1109. if (!m_pUnkContext)
  1110. return E_FAIL;
  1111. HRESULT hr = S_OK;
  1112. GUID guidConn;
  1113. // Is this a lan connection ?
  1114. INetLanConnectionUiInfo * pLanConnUiInfo;
  1115. hr = m_pUnkContext->QueryInterface( IID_INetLanConnectionUiInfo,
  1116. reinterpret_cast<LPVOID *>(&pLanConnUiInfo));
  1117. if (S_OK == hr)
  1118. {
  1119. // yes, lan connection
  1120. pLanConnUiInfo->GetDeviceGuid(&guidConn);
  1121. WCHAR szGuid[c_cchGuidWithTerm];
  1122. INT cch = StringFromGUID2(guidConn, szGuid, c_cchGuidWithTerm);
  1123. Assert(cch);
  1124. m_strGuidConn = szGuid;
  1125. }
  1126. ReleaseObj(pLanConnUiInfo);
  1127. TraceError("CALaneCfg::HrSetConnectionContext", hr);
  1128. return hr;
  1129. }
  1130. VOID CALaneCfg::CopyAdapterInfoPrimaryToSecondary()
  1131. {
  1132. ATMLANE_ADAPTER_INFO_LIST::iterator iterLstAdapters;
  1133. CALaneCfgAdapterInfo * pAdapterInfo;
  1134. ELAN_INFO_LIST::iterator iterLstElans;
  1135. CALaneCfgElanInfo * pElanInfo;
  1136. CALaneCfgElanInfo * pElanInfoNew;
  1137. // free any existing secondary data
  1138. ClearAdapterInfo(m_pAdapterSecondary);
  1139. m_pAdapterSecondary = NULL;
  1140. // loop thru the primary adapter list
  1141. for (iterLstAdapters = m_lstAdaptersPrimary.begin();
  1142. iterLstAdapters != m_lstAdaptersPrimary.end();
  1143. iterLstAdapters++)
  1144. {
  1145. pAdapterInfo = *iterLstAdapters;
  1146. // create new and copy from primary
  1147. if (FIsSubstr(m_strGuidConn.c_str(), pAdapterInfo->SzGetAdapterBindName()))
  1148. {
  1149. // we found a match
  1150. m_pAdapterSecondary = new CALaneCfgAdapterInfo;
  1151. m_pAdapterSecondary->m_guidInstanceId = pAdapterInfo-> m_guidInstanceId;
  1152. m_pAdapterSecondary->m_fDeleted = pAdapterInfo->m_fDeleted;
  1153. m_pAdapterSecondary->SetAdapterBindName(pAdapterInfo->SzGetAdapterBindName());
  1154. m_pAdapterSecondary->SetAdapterPnpId(pAdapterInfo->SzGetAdapterPnpId());
  1155. // loop thru the elan list on this adapter
  1156. for (iterLstElans = pAdapterInfo->m_lstElans.begin();
  1157. iterLstElans != pAdapterInfo->m_lstElans.end();
  1158. iterLstElans++)
  1159. {
  1160. pElanInfo = *iterLstElans;
  1161. // create new and copy from primary
  1162. pElanInfoNew = new CALaneCfgElanInfo;
  1163. pElanInfoNew->SetElanBindName(pElanInfo->SzGetElanBindName());
  1164. pElanInfoNew->SetElanDeviceName(pElanInfo->SzGetElanDeviceName());
  1165. pElanInfoNew->SetElanName(pElanInfo->SzGetElanName());
  1166. pElanInfoNew->m_fDeleted = pElanInfo->m_fDeleted;
  1167. pElanInfoNew->m_fNewElan = pElanInfo->m_fNewElan;
  1168. pElanInfoNew->m_fRemoveMiniportOnPropertyApply = FALSE;
  1169. pElanInfoNew->m_fCreateMiniportOnPropertyApply = FALSE;
  1170. // push onto new secondary adapter's elan list
  1171. m_pAdapterSecondary->m_lstElans.push_back(pElanInfoNew);
  1172. }
  1173. break;
  1174. }
  1175. }
  1176. Assert(m_pAdapterSecondary != NULL);
  1177. return;
  1178. }
  1179. VOID CALaneCfg::CopyAdapterInfoSecondaryToPrimary()
  1180. {
  1181. ATMLANE_ADAPTER_INFO_LIST::iterator iterLstAdapters;
  1182. CALaneCfgAdapterInfo * pAdapterInfo;
  1183. CALaneCfgAdapterInfo * pAdapterInfoNew;
  1184. ELAN_INFO_LIST::iterator iterLstElans;
  1185. CALaneCfgElanInfo * pElanInfo;
  1186. CALaneCfgElanInfo * pElanInfoNew;
  1187. // loop thru the primary adapter list
  1188. for (iterLstAdapters = m_lstAdaptersPrimary.begin();
  1189. iterLstAdapters != m_lstAdaptersPrimary.end();
  1190. iterLstAdapters++)
  1191. {
  1192. pAdapterInfo = *iterLstAdapters;
  1193. if (FIsSubstr(m_strGuidConn.c_str(), pAdapterInfo->SzGetAdapterBindName()))
  1194. {
  1195. pAdapterInfo->m_fDeleted = m_pAdapterSecondary->m_fDeleted;
  1196. pAdapterInfo->SetAdapterBindName(m_pAdapterSecondary->SzGetAdapterBindName());
  1197. pAdapterInfo->SetAdapterPnpId(m_pAdapterSecondary->SzGetAdapterPnpId());
  1198. // rebuild Elan list
  1199. ClearElanList(&pAdapterInfo->m_lstElans);
  1200. // loop thru the elan list on this adapter
  1201. for (iterLstElans = m_pAdapterSecondary->m_lstElans.begin();
  1202. iterLstElans != m_pAdapterSecondary->m_lstElans.end();
  1203. iterLstElans++)
  1204. {
  1205. pElanInfo = *iterLstElans;
  1206. // create new and copy from secondary
  1207. pElanInfoNew = new CALaneCfgElanInfo;
  1208. pElanInfoNew->SetElanBindName(pElanInfo->SzGetElanBindName());
  1209. pElanInfoNew->SetElanDeviceName(pElanInfo->SzGetElanDeviceName());
  1210. pElanInfoNew->SetElanName(pElanInfo->SzGetElanName());
  1211. pElanInfoNew->m_fDeleted = pElanInfo->m_fDeleted;
  1212. pElanInfoNew->m_fNewElan = pElanInfo->m_fNewElan;
  1213. pElanInfoNew->m_fRemoveMiniportOnPropertyApply = FALSE;
  1214. pElanInfoNew->m_fCreateMiniportOnPropertyApply = FALSE;
  1215. // add to adapter's elan list
  1216. pAdapterInfo->m_lstElans.push_back(pElanInfoNew);
  1217. }
  1218. break;
  1219. }
  1220. }
  1221. return;
  1222. }
  1223. HRESULT CALaneCfg::HrReconfigLane(CALaneCfgAdapterInfo * pAdapterInfo)
  1224. {
  1225. HRESULT hr = S_OK;
  1226. // Note: if atm physical adapter is deleted, no notification of removing elan
  1227. // is necessary. Lane protocol driver will know to delete all the elans
  1228. // (confirmed above with ArvindM 3/12).
  1229. // Raid #371343, don't send notification if ATM card not connected
  1230. if ((!pAdapterInfo->m_fDeleted) &&
  1231. FIsAdapterEnabled(&(pAdapterInfo->m_guidInstanceId)))
  1232. {
  1233. ElanChangeType elanChangeType;
  1234. // loop thru the elan list on this adapter
  1235. ELAN_INFO_LIST::iterator iterLstElans;
  1236. for (iterLstElans = pAdapterInfo->m_lstElans.begin();
  1237. iterLstElans != pAdapterInfo->m_lstElans.end();
  1238. iterLstElans++)
  1239. {
  1240. CALaneCfgElanInfo * pElanInfo = *iterLstElans;
  1241. // if this Elan is marked as for delete
  1242. if (pElanInfo->m_fDeleted)
  1243. {
  1244. PCWSTR szBindName = pElanInfo->SzGetElanBindName();
  1245. if (lstrlenW(szBindName)) // only if the bindname is not empty
  1246. {
  1247. // notify deletion
  1248. elanChangeType = DEL_ELAN;
  1249. hr = HrNotifyElanChange(pAdapterInfo, pElanInfo,
  1250. elanChangeType);
  1251. }
  1252. }
  1253. else
  1254. {
  1255. BOOL fFound = FALSE;
  1256. ELAN_INFO_LIST::iterator iterLstOldElans;
  1257. // loop through the old elan list, see if we can find a match
  1258. for (iterLstOldElans = pAdapterInfo->m_lstOldElans.begin();
  1259. iterLstOldElans != pAdapterInfo->m_lstOldElans.end();
  1260. iterLstOldElans++)
  1261. {
  1262. CALaneCfgElanInfo * pOldElanInfo = * iterLstOldElans;
  1263. if (0 == lstrcmpiW(pElanInfo->SzGetElanBindName(),
  1264. pOldElanInfo->SzGetElanBindName()))
  1265. {
  1266. // we found a match
  1267. fFound = TRUE;
  1268. // has the elan name changed ?
  1269. if (lstrcmpiW(pElanInfo->SzGetElanName(),
  1270. pOldElanInfo->SzGetElanName()) != 0)
  1271. {
  1272. elanChangeType = MOD_ELAN;
  1273. hr = HrNotifyElanChange(pAdapterInfo, pElanInfo,
  1274. elanChangeType);
  1275. }
  1276. }
  1277. }
  1278. if (!fFound)
  1279. {
  1280. elanChangeType = ADD_ELAN;
  1281. hr = HrNotifyElanChange(pAdapterInfo, pElanInfo,
  1282. elanChangeType);
  1283. // Raid #384380: If no ELAN was installed, ignore the error
  1284. if ((S_OK != hr) &&(m_fNoElanInstalled))
  1285. {
  1286. TraceError("Adding ELAN failed but error ignored since there was no ELAN installed so LANE driver is not started, reset hr to S_OK", hr);
  1287. hr = S_OK;
  1288. }
  1289. }
  1290. }
  1291. }
  1292. }
  1293. TraceError("CALaneCfg::HrReconfigLane", hr);
  1294. return hr;
  1295. }
  1296. HRESULT CALaneCfg::HrNotifyElanChange(CALaneCfgAdapterInfo * pAdapterInfo,
  1297. CALaneCfgElanInfo * pElanInfo,
  1298. ElanChangeType elanChangeType)
  1299. {
  1300. // ATMLANE_PNP_RECONFIG_REQUEST is defined in \nt\private\inc\laneinfo.h
  1301. const DWORD dwBytes = sizeof(ATMLANE_PNP_RECONFIG_REQUEST) +
  1302. CbOfSzAndTerm (pElanInfo->SzGetElanBindName());
  1303. ATMLANE_PNP_RECONFIG_REQUEST* pLaneReconfig;
  1304. HRESULT hr = HrMalloc (dwBytes, (PVOID*)&pLaneReconfig);
  1305. if (SUCCEEDED(hr))
  1306. {
  1307. pLaneReconfig->Version =1;
  1308. pLaneReconfig->OpType = elanChangeType;
  1309. pLaneReconfig->ElanKeyLength = lstrlenW(pElanInfo->SzGetElanBindName())+1;
  1310. lstrcpyW(pLaneReconfig->ElanKey, pElanInfo->SzGetElanBindName());
  1311. hr = HrSendNdisPnpReconfig( NDIS, c_szAtmLane,
  1312. pAdapterInfo->SzGetAdapterBindName(),
  1313. pLaneReconfig,
  1314. dwBytes);
  1315. if ( S_OK != hr)
  1316. {
  1317. TraceError("Notifying LANE of ELAN change returns failure, prompt for reboot ...", hr);
  1318. hr = NETCFG_S_REBOOT;
  1319. }
  1320. MemFree (pLaneReconfig);
  1321. }
  1322. TraceError("CALaneCfg::HrNotifyElanChange", hr);
  1323. return hr;
  1324. }
  1325. BOOL CALaneCfg::FIsAdapterEnabled(const GUID* pguidId)
  1326. {
  1327. FARPROC pfnHrGetPnpDeviceStatus;
  1328. HMODULE hNetman;
  1329. HRESULT hr = S_OK;
  1330. NETCON_STATUS ncStatus = NCS_CONNECTED;
  1331. hr = HrLoadLibAndGetProc(L"netman.dll", "HrGetPnpDeviceStatus",
  1332. &hNetman, &pfnHrGetPnpDeviceStatus);
  1333. if (SUCCEEDED(hr))
  1334. {
  1335. hr = (*(PHRGETPNPDEVICESTATUS)pfnHrGetPnpDeviceStatus)(
  1336. pguidId, &ncStatus);
  1337. FreeLibrary(hNetman);
  1338. }
  1339. return (NCS_CONNECTED == ncStatus);
  1340. }
  1341. //
  1342. // CALaneCfgAdapterInfo
  1343. //
  1344. CALaneCfgAdapterInfo::CALaneCfgAdapterInfo(VOID)
  1345. {
  1346. m_fDeleted = FALSE;
  1347. m_fBindingChanged = FALSE;
  1348. return;
  1349. }
  1350. CALaneCfgAdapterInfo::~CALaneCfgAdapterInfo(VOID)
  1351. {
  1352. ClearElanList(&m_lstElans);
  1353. ClearElanList(&m_lstOldElans);
  1354. return;
  1355. }
  1356. VOID CALaneCfgAdapterInfo::SetAdapterBindName(PCWSTR pszAdapterBindName)
  1357. {
  1358. m_strAdapterBindName = pszAdapterBindName;
  1359. return;
  1360. }
  1361. PCWSTR CALaneCfgAdapterInfo::SzGetAdapterBindName(VOID)
  1362. {
  1363. return m_strAdapterBindName.c_str();
  1364. }
  1365. VOID CALaneCfgAdapterInfo::SetAdapterPnpId(PCWSTR pszAdapterPnpId)
  1366. {
  1367. m_strAdapterPnpId = pszAdapterPnpId;
  1368. return;
  1369. }
  1370. PCWSTR CALaneCfgAdapterInfo::SzGetAdapterPnpId(VOID)
  1371. {
  1372. return m_strAdapterPnpId.c_str();
  1373. }
  1374. //
  1375. // CALaneCfgElanInfo
  1376. //
  1377. CALaneCfgElanInfo::CALaneCfgElanInfo(VOID)
  1378. {
  1379. m_fDeleted = FALSE;
  1380. m_fNewElan = FALSE;
  1381. m_fCreateMiniportOnPropertyApply = FALSE;
  1382. m_fRemoveMiniportOnPropertyApply = FALSE;
  1383. return;
  1384. }
  1385. VOID CALaneCfgElanInfo::SetElanBindName(PCWSTR pszElanBindName)
  1386. {
  1387. m_strElanBindName = pszElanBindName;
  1388. return;
  1389. }
  1390. PCWSTR CALaneCfgElanInfo::SzGetElanBindName(VOID)
  1391. {
  1392. return m_strElanBindName.c_str();
  1393. }
  1394. VOID CALaneCfgElanInfo::SetElanDeviceName(PCWSTR pszElanDeviceName)
  1395. {
  1396. m_strElanDeviceName = pszElanDeviceName;
  1397. return;
  1398. }
  1399. PCWSTR CALaneCfgElanInfo::SzGetElanDeviceName(VOID)
  1400. {
  1401. return m_strElanDeviceName.c_str();
  1402. }
  1403. VOID CALaneCfgElanInfo::SetElanName(PCWSTR pszElanName)
  1404. {
  1405. m_strElanName = pszElanName;
  1406. return;
  1407. }
  1408. VOID CALaneCfgElanInfo::SetElanName(PWSTR pszElanName)
  1409. {
  1410. m_strElanName = pszElanName;
  1411. return;
  1412. }
  1413. PCWSTR CALaneCfgElanInfo::SzGetElanName(VOID)
  1414. {
  1415. return m_strElanName.c_str();
  1416. }
  1417. // utility functions
  1418. void ClearElanList(ELAN_INFO_LIST *plstElans)
  1419. {
  1420. ELAN_INFO_LIST::iterator iterLstElans;
  1421. CALaneCfgElanInfo * pElanInfo;
  1422. for (iterLstElans = plstElans->begin();
  1423. iterLstElans != plstElans->end();
  1424. iterLstElans++)
  1425. {
  1426. pElanInfo = *iterLstElans;
  1427. delete pElanInfo;
  1428. }
  1429. plstElans->clear();
  1430. return;
  1431. }
  1432. void ClearAdapterList(ATMLANE_ADAPTER_INFO_LIST *plstAdapters)
  1433. {
  1434. ATMLANE_ADAPTER_INFO_LIST::iterator iterLstAdapters;
  1435. CALaneCfgAdapterInfo * pAdapterInfo;
  1436. ELAN_INFO_LIST::iterator iterLstElans;
  1437. for (iterLstAdapters = plstAdapters->begin();
  1438. iterLstAdapters != plstAdapters->end();
  1439. iterLstAdapters++)
  1440. {
  1441. pAdapterInfo = *iterLstAdapters;
  1442. ClearElanList(&pAdapterInfo->m_lstElans);
  1443. delete pAdapterInfo;
  1444. }
  1445. plstAdapters->clear();
  1446. return;
  1447. }
  1448. void ClearAdapterInfo(CALaneCfgAdapterInfo * pAdapterInfo)
  1449. {
  1450. ELAN_INFO_LIST::iterator iterLstElans;
  1451. if (pAdapterInfo)
  1452. {
  1453. ClearElanList(&pAdapterInfo->m_lstElans);
  1454. delete pAdapterInfo;
  1455. }
  1456. return;
  1457. }