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.

419 lines
11 KiB

  1. //-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: A U N I O B J . C P P
  7. //
  8. // Contents: CAtmUniCfg interface method function implementation
  9. //
  10. // Notes:
  11. //
  12. // Author: tongl 21 Mar 1997
  13. //
  14. //-----------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "arpsobj.h"
  18. #include "auniobj.h"
  19. #include "atmutil.h"
  20. #include "ncstl.h"
  21. #include "aunidlg.h"
  22. #include "netconp.h"
  23. #include "ncpnp.h"
  24. static const WCHAR c_szAtmuni[] = L"Atmuni";
  25. extern const WCHAR c_szInfId_MS_RawWan[];
  26. /////////////////////////////////////////////////////////////////////////////
  27. //
  28. CAtmUniCfg::CAtmUniCfg()
  29. : m_pnc(NULL),
  30. m_pnccUni(NULL),
  31. m_pnccRwan(NULL),
  32. m_fSaveRegistry(FALSE),
  33. m_fUIParamChanged(FALSE),
  34. m_fSecondMemoryModified(FALSE),
  35. m_fPVCInfoLoaded(FALSE),
  36. m_strGuidConn(c_szEmpty),
  37. m_pUnkContext(NULL),
  38. m_pSecondMemoryAdapterInfo(NULL),
  39. m_uniPage(NULL)
  40. {
  41. }
  42. CAtmUniCfg::~CAtmUniCfg()
  43. {
  44. ReleaseObj(m_pnc);
  45. ReleaseObj(m_pnccUni);
  46. ReleaseObj(m_pnccRwan);
  47. FreeCollectionAndItem(m_listAdapters);
  48. // Just a safty check to make sure the context is released.
  49. AssertSz((m_pUnkContext == NULL), "Why is context not released ? Not a bug in ATM UNI config.");
  50. if (m_pUnkContext)
  51. ReleaseObj(m_pUnkContext) ;
  52. delete m_uniPage;
  53. }
  54. // INetCfgComponentControl
  55. STDMETHODIMP CAtmUniCfg::Initialize (INetCfgComponent* pncc,
  56. INetCfg* pNetCfg,
  57. BOOL fInstalling )
  58. {
  59. HRESULT hr = S_OK;
  60. Validate_INetCfgNotify_Initialize(pncc, pNetCfg, fInstalling);
  61. AssertSz(pNetCfg, "NetCfg pointer is NULL!");
  62. m_pnc = pNetCfg;
  63. AddRefObj(m_pnc);
  64. AssertSz(pncc, "Component pointer is NULL!");
  65. m_pnccUni = pncc;
  66. AddRefObj(m_pnccUni);
  67. // Get a copy of the ATMRwan and store in our object
  68. hr = m_pnc->FindComponent(c_szInfId_MS_RawWan, &m_pnccRwan);
  69. if (S_FALSE == hr) // RWan not found
  70. {
  71. if (!fInstalling) // Trace the error, RWan should be installed
  72. {
  73. TraceError("CAtmUniCfg::Initialize - ATMRwan has not been installed yet", hr);
  74. }
  75. else // We are ok since ATMUNI will install ATMRwan
  76. {
  77. hr = S_OK;
  78. }
  79. }
  80. // Construct the in memory structure (m_listAdapters) by
  81. // iterating through the binding path
  82. if (!fInstalling)
  83. {
  84. hr = HrLoadSettings();
  85. }
  86. Validate_INetCfgNotify_Initialize_Return(hr);
  87. TraceError("CAtmUniCfg::Initialize", hr);
  88. return hr;
  89. }
  90. STDMETHODIMP CAtmUniCfg::Validate ()
  91. {
  92. return S_OK;
  93. }
  94. STDMETHODIMP CAtmUniCfg::CancelChanges ()
  95. {
  96. return S_OK;
  97. }
  98. STDMETHODIMP CAtmUniCfg::ApplyRegistryChanges ()
  99. {
  100. HRESULT hr = S_OK;
  101. if (m_fSaveRegistry)
  102. {
  103. hr = HrSaveSettings();
  104. if (SUCCEEDED(hr) && m_fUIParamChanged)
  105. {
  106. // send reconfig notification if parameter has changed
  107. for (UNI_ADAPTER_LIST::iterator iterAdapter = m_listAdapters.begin();
  108. iterAdapter != m_listAdapters.end();
  109. iterAdapter ++)
  110. {
  111. if ((*iterAdapter)->m_fDeleted)
  112. continue;
  113. if (FIsSubstr(m_strGuidConn.c_str(), (*iterAdapter)->m_strBindName.c_str()))
  114. {
  115. HRESULT hrReconfig;
  116. hrReconfig = HrSendNdisPnpReconfig(NDIS, c_szAtmuni,
  117. (*iterAdapter)->m_strBindName.c_str(),
  118. NULL, 0);
  119. if (FAILED(hrReconfig))
  120. {
  121. TraceTag(ttidAtmUni,"Notifying Atm UNI Call manager of parameter change returns failure, prompt for reboot ...");
  122. hr = NETCFG_S_REBOOT;
  123. }
  124. break;
  125. }
  126. }
  127. }
  128. }
  129. else
  130. {
  131. // no change
  132. hr = S_FALSE;
  133. }
  134. Validate_INetCfgNotify_Apply_Return(hr);
  135. TraceError("CAtmUniCfg::ApplyRegistryChanges", (S_FALSE == hr)? S_OK : hr);
  136. return hr;
  137. }
  138. // INetCfgComponentSetup
  139. STDMETHODIMP CAtmUniCfg::Install (DWORD dwSetupFlags)
  140. {
  141. m_fSaveRegistry = TRUE;
  142. // Just in case it was installed already, we need to release
  143. // m_pnccRwan before we overwrite it.
  144. //
  145. ReleaseObj (m_pnccRwan);
  146. // Install the ATM Rawwan protocol on behalf of ATMUNI
  147. HRESULT hr = HrInstallComponentOboComponent( m_pnc, NULL,
  148. GUID_DEVCLASS_NETTRANS,
  149. c_szInfId_MS_RawWan,
  150. m_pnccUni,
  151. &m_pnccRwan);
  152. TraceError("CAtmUniCfg::Install", hr);
  153. return hr;
  154. }
  155. STDMETHODIMP CAtmUniCfg::Upgrade(DWORD dwSetupFlags,
  156. DWORD dwUpgradeFomBuildNo )
  157. {
  158. return S_FALSE;
  159. }
  160. STDMETHODIMP CAtmUniCfg::ReadAnswerFile(PCWSTR pszAnswerFile,
  161. PCWSTR pszAnswerSection)
  162. {
  163. return S_OK;
  164. }
  165. STDMETHODIMP CAtmUniCfg::Removing ()
  166. {
  167. // Remove ATMRwan protocol
  168. HRESULT hr = HrRemoveComponentOboComponent(m_pnc,
  169. GUID_DEVCLASS_NETTRANS,
  170. c_szInfId_MS_RawWan,
  171. m_pnccUni);
  172. TraceError("CAtmUniCfg::Removing", hr);
  173. return hr;
  174. }
  175. // INetCfgBindNotify
  176. STDMETHODIMP CAtmUniCfg::QueryBindingPath (DWORD dwChangeFlag,
  177. INetCfgBindingPath* pncbpItem )
  178. {
  179. return S_OK;
  180. }
  181. STDMETHODIMP CAtmUniCfg::NotifyBindingPath (DWORD dwChangeFlag,
  182. INetCfgBindingPath* pncbp )
  183. {
  184. Assert(!(dwChangeFlag & NCN_ADD && dwChangeFlag & NCN_REMOVE));
  185. Assert(!(dwChangeFlag & NCN_ENABLE && dwChangeFlag & NCN_DISABLE));
  186. // If we are told to add a card, we must be told at the same time whether the
  187. // binding is enabled or disabled
  188. Assert(FImplies((dwChangeFlag & NCN_ADD),
  189. ((dwChangeFlag & NCN_ENABLE)||(dwChangeFlag & NCN_DISABLE))));
  190. // We handle NCN_ADD and NCN_REMOVE only (for Beta1):
  191. // NCN_ADD: if item not on list, add a new item
  192. // NCN_REMOVE: if item already on list, remove the item
  193. HRESULT hr = S_OK;
  194. Validate_INetCfgBindNotify_NotifyBindingPath (dwChangeFlag,pncbp);
  195. INetCfgComponent * pnccLastComponent;
  196. hr = HrGetLastComponentAndInterface(pncbp,
  197. &pnccLastComponent, NULL);
  198. if SUCCEEDED(hr)
  199. {
  200. GUID guidNetClass;
  201. hr = pnccLastComponent->GetClassGuid (&guidNetClass);
  202. AssertSz(IsEqualGUID(guidNetClass, GUID_DEVCLASS_NET),
  203. "Why the last component on the path is not an adapter?");
  204. // Is this a net card ?
  205. if (SUCCEEDED(hr) && IsEqualGUID(guidNetClass, GUID_DEVCLASS_NET))
  206. {
  207. // If we are adding/removing cards, set m_fSaveRegistry
  208. // so we apply the changes to registry
  209. if (dwChangeFlag & NCN_ADD)
  210. {
  211. hr = HrAddAdapter(pnccLastComponent);
  212. }
  213. if(dwChangeFlag & NCN_ENABLE)
  214. {
  215. hr = HrBindAdapter(pnccLastComponent);
  216. }
  217. if(dwChangeFlag & NCN_DISABLE)
  218. {
  219. hr = HrUnBindAdapter(pnccLastComponent);
  220. }
  221. if (dwChangeFlag & NCN_REMOVE)
  222. {
  223. hr = HrRemoveAdapter(pnccLastComponent);
  224. }
  225. }
  226. ReleaseObj (pnccLastComponent);
  227. }
  228. Validate_INetCfgBindNotify_NotifyBindingPath_Return(hr);
  229. TraceError("CAtmUniCfg::NotifyBindingPath", hr);
  230. return hr;
  231. }
  232. // INetCfgProperties
  233. STDMETHODIMP CAtmUniCfg::QueryPropertyUi (IUnknown* pUnk)
  234. {
  235. HRESULT hr = S_FALSE;
  236. if (pUnk)
  237. {
  238. // Is this a lan connection ?
  239. INetLanConnectionUiInfo * pLanConnUiInfo;
  240. hr = pUnk->QueryInterface( IID_INetLanConnectionUiInfo,
  241. reinterpret_cast<LPVOID *>(&pLanConnUiInfo));
  242. if(FAILED(hr))
  243. {
  244. hr = S_FALSE;
  245. }
  246. }
  247. TraceError("CAtmUniCfg::SetContext", hr);
  248. return hr;
  249. }
  250. STDMETHODIMP CAtmUniCfg::SetContext(IUnknown * pUnk)
  251. {
  252. HRESULT hr = S_OK;
  253. // release previous context, if any
  254. if (m_pUnkContext)
  255. ReleaseObj(m_pUnkContext);
  256. m_pUnkContext = NULL;
  257. if (pUnk) // set the new context
  258. {
  259. m_pUnkContext = pUnk;
  260. m_pUnkContext->AddRef();
  261. }
  262. TraceError("CArpsCfg::SetContext", hr);
  263. return hr;
  264. }
  265. STDMETHODIMP CAtmUniCfg::MergePropPages (
  266. IN OUT DWORD* pdwDefPages,
  267. OUT LPBYTE* pahpspPrivate,
  268. OUT UINT* pcPages,
  269. IN HWND hwndParent,
  270. OUT PCWSTR* pszStartPage)
  271. {
  272. HRESULT hr = S_OK;
  273. // Initialize output parameter
  274. HPROPSHEETPAGE *ahpsp = NULL;
  275. int cPages = 0;
  276. Validate_INetCfgProperties_MergePropPages (
  277. pdwDefPages, pahpspPrivate, pcPages, hwndParent, pszStartPage);
  278. // We don't want any default pages to be shown
  279. *pdwDefPages = 0;
  280. *pcPages = NULL;
  281. *pahpspPrivate = NULL;
  282. // get the connection context in which we are bringing up the UI
  283. hr = HrSetConnectionContext();
  284. if SUCCEEDED(hr)
  285. {
  286. // Initialize the common controls library
  287. INITCOMMONCONTROLSEX icc;
  288. icc.dwSize = sizeof(icc);
  289. icc.dwICC = ICC_INTERNET_CLASSES;
  290. SideAssert(InitCommonControlsEx(&icc));
  291. hr = HrSetupPropSheets(&ahpsp, &cPages);
  292. if (SUCCEEDED(hr))
  293. {
  294. *pahpspPrivate = (LPBYTE)ahpsp;
  295. *pcPages = cPages;
  296. }
  297. else
  298. {
  299. *pcPages = 0;
  300. CoTaskMemFree(ahpsp);
  301. }
  302. }
  303. Validate_INetCfgProperties_MergePropPages_Return(hr);
  304. TraceError("CAtmUniCfg::MergePropPages", hr);
  305. return hr;
  306. }
  307. STDMETHODIMP CAtmUniCfg::ValidateProperties (HWND hwndSheet)
  308. {
  309. // all error checking are done in the UI
  310. return S_OK;
  311. }
  312. STDMETHODIMP CAtmUniCfg::CancelProperties ()
  313. {
  314. // Release second memory info
  315. delete m_pSecondMemoryAdapterInfo;
  316. m_pSecondMemoryAdapterInfo = NULL;
  317. return S_OK;
  318. }
  319. STDMETHODIMP CAtmUniCfg::ApplyProperties ()
  320. {
  321. HRESULT hr = S_OK;
  322. if(!m_fSaveRegistry)
  323. m_fSaveRegistry = m_fSecondMemoryModified;
  324. if(!m_fUIParamChanged)
  325. m_fUIParamChanged = m_fSecondMemoryModified;
  326. // Copy info from second memory state to first memory state
  327. if (m_fSecondMemoryModified)
  328. {
  329. hr = HrSaveAdapterPVCInfo();
  330. }
  331. // Release second memory info
  332. delete m_pSecondMemoryAdapterInfo;
  333. m_pSecondMemoryAdapterInfo = NULL;
  334. Validate_INetCfgProperties_ApplyProperties_Return(hr);
  335. TraceError("CAtmUniCfg::ApplyProperties", hr);
  336. return hr;
  337. }