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.

439 lines
11 KiB

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