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.

498 lines
13 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992-2001.
  5. //
  6. // File: V I R T U A L . C P P
  7. //
  8. // Contents: Virtual miniport class definition.
  9. //
  10. // Notes:
  11. //
  12. // Author: Alok Sinha
  13. //----------------------------------------------------------------------------
  14. #include "virtual.h"
  15. #include "common.h"
  16. //+---------------------------------------------------------------------------
  17. //
  18. // Function: CMuxVirtualMiniport::CMuxVirtualMiniport
  19. //
  20. // Purpose: Constructor for class CMuxVirtualMiniport
  21. //
  22. // Arguments: None
  23. //
  24. // Returns:
  25. //
  26. // Notes:
  27. //
  28. CMuxVirtualMiniport::CMuxVirtualMiniport(INetCfg *pnc,
  29. GUID *pguidMiniport,
  30. GUID *pguidAdapter)
  31. {
  32. TraceMsg( L"-->CMuxVirtualMiniport::CMuxVirtualMiniport(Constructor).\n" );
  33. m_pnc = pnc;
  34. m_pnc->AddRef();
  35. CopyMemory( &m_guidAdapter,
  36. pguidAdapter,
  37. sizeof(GUID) );
  38. if ( pguidMiniport ) {
  39. CopyMemory( &m_guidMiniport,
  40. pguidMiniport,
  41. sizeof(GUID) );
  42. }
  43. else {
  44. ZeroMemory( &m_guidMiniport,
  45. sizeof(GUID) );
  46. }
  47. TraceMsg( L"<--CMuxVirtualMiniport::CMuxVirtualMiniport(Constructor).\n" );
  48. }
  49. //+---------------------------------------------------------------------------
  50. //
  51. // Function: CMuxVirtualMiniport::~CMuxVirtualMiniport
  52. //
  53. // Purpose: Destructor for class CMuxVirtualMiniport
  54. //
  55. // Arguments: None
  56. //
  57. // Returns:
  58. //
  59. // Notes:
  60. //
  61. CMuxVirtualMiniport::~CMuxVirtualMiniport(VOID)
  62. {
  63. TraceMsg( L"-->CMuxVirtualMiniport::~CMuxVirtualMiniport(Destructor).\n" );
  64. ReleaseObj( m_pnc );
  65. TraceMsg( L"<--CMuxVirtualMiniport::~CMuxVirtualMiniport(Destructor).\n" );
  66. }
  67. //+---------------------------------------------------------------------------
  68. //
  69. // Function: CMuxVirtualMiniport::LoadConfiguration
  70. //
  71. // Purpose: Load miniport configuration from the registry.
  72. //
  73. // Arguments: None
  74. //
  75. // Returns: S_OK on success, otherwise an error code.
  76. //
  77. // Notes:
  78. //
  79. HRESULT CMuxVirtualMiniport::LoadConfiguration(VOID)
  80. {
  81. TraceMsg( L"-->CMuxVirtualMiniport::LoadConfiguration.\n" );
  82. TraceMsg( L"<--CMuxVirtualMiniport::LoadConfiguration(HRESULT = %x).\n",
  83. S_OK );
  84. return S_OK;
  85. }
  86. //+---------------------------------------------------------------------------
  87. //
  88. // Function: CMuxVirtualMiniport::GetAdapterGUID
  89. //
  90. // Purpose: Returns the adapter GUID.
  91. //
  92. // Arguments:
  93. // OUT pguidAdapter: GUID of the adapter returned.
  94. //
  95. // Returns: None.
  96. //
  97. // Notes:
  98. //
  99. VOID CMuxVirtualMiniport::GetAdapterGUID (GUID *pguidAdapter)
  100. {
  101. TraceMsg( L"-->CMuxVirtualMiniport::GetAdapterGUID.\n" );
  102. CopyMemory( pguidAdapter,
  103. &m_guidAdapter,
  104. sizeof(GUID) );
  105. TraceMsg( L"<--CMuxVirtualMiniport::GetAdapterGUID.\n" );
  106. }
  107. //+---------------------------------------------------------------------------
  108. //
  109. // Function: CMuxVirtualMiniport::GetMiniportGUID
  110. //
  111. // Purpose: Returns the miniport GUID.
  112. //
  113. // Arguments:
  114. // OUT pguidMiniport: GUID of the miniport returned.
  115. //
  116. // Returns: None.
  117. //
  118. // Notes:
  119. //
  120. VOID CMuxVirtualMiniport::GetMiniportGUID (GUID *pguidMiniport)
  121. {
  122. TraceMsg( L"-->CMuxVirtualMiniport::GetMiniportGUID.\n" );
  123. CopyMemory( pguidMiniport,
  124. &m_guidMiniport,
  125. sizeof(GUID) );
  126. TraceMsg( L"<--CMuxVirtualMiniport::GetMiniportGUID.\n" );
  127. }
  128. //+---------------------------------------------------------------------------
  129. //
  130. // Function: CMuxVirtualMiniport::Install
  131. //
  132. // Purpose: Installs a virtual miniport.
  133. //
  134. // Arguments: None
  135. //
  136. // Returns: S_OK on success, otherwise an error code.
  137. //
  138. // Notes:
  139. //
  140. HRESULT CMuxVirtualMiniport::Install (VOID)
  141. {
  142. INetCfgClass *pncClass;
  143. INetCfgClassSetup *pncClassSetup;
  144. INetCfgComponent *pnccMiniport;
  145. HRESULT hr;
  146. TraceMsg( L"-->CMuxVirtualMiniport::Install.\n" );
  147. hr = m_pnc->QueryNetCfgClass( &GUID_DEVCLASS_NET,
  148. IID_INetCfgClass,
  149. (void **)&pncClass );
  150. if ( hr == S_OK ) {
  151. hr = pncClass->QueryInterface( IID_INetCfgClassSetup,
  152. (void **)&pncClassSetup );
  153. if ( hr == S_OK ) {
  154. hr = pncClassSetup->Install( c_szMuxMiniport,
  155. NULL,
  156. 0,
  157. 0,
  158. NULL,
  159. NULL,
  160. &pnccMiniport );
  161. if ( hr == S_OK ) {
  162. hr = pnccMiniport->GetInstanceGuid( &m_guidMiniport );
  163. if ( hr != S_OK ) {
  164. TraceMsg( L" Failed to get the instance guid, uninstalling "
  165. L" the miniport.\n" );
  166. pncClassSetup->DeInstall( pnccMiniport,
  167. NULL,
  168. NULL );
  169. }
  170. ReleaseObj( pnccMiniport );
  171. }
  172. else {
  173. TraceMsg( L" Failed to install the miniport.\n" );
  174. }
  175. ReleaseObj( pncClassSetup );
  176. }
  177. else {
  178. TraceMsg( L" QueryInterface failed.\n" );
  179. }
  180. ReleaseObj( pncClass );
  181. }
  182. else {
  183. TraceMsg( L" QueryNetCfgClass failed.\n" );
  184. }
  185. TraceMsg( L"<--CMuxVirtualMiniport::Install(HRESULT = %x).\n",
  186. hr );
  187. return hr;
  188. }
  189. //+---------------------------------------------------------------------------
  190. //
  191. // Function: CMuxVirtualMiniport::DeInstall
  192. //
  193. // Purpose: Uninstalls the virtual miniport.
  194. //
  195. // Arguments: None
  196. //
  197. // Returns: S_OK on success, otherwise an error code.
  198. //
  199. // Notes:
  200. //
  201. HRESULT CMuxVirtualMiniport::DeInstall (VOID)
  202. {
  203. INetCfgClass *pncClass;
  204. INetCfgClassSetup *pncClassSetup;
  205. INetCfgComponent *pnccMiniport;
  206. HRESULT hr;
  207. TraceMsg( L"-->CMuxVirtualMiniport::DeInstall.\n" );
  208. hr = m_pnc->QueryNetCfgClass( &GUID_DEVCLASS_NET,
  209. IID_INetCfgClass,
  210. (void **)&pncClass );
  211. if ( hr == S_OK ) {
  212. hr = pncClass->QueryInterface( IID_INetCfgClassSetup,
  213. (void **)&pncClassSetup );
  214. if ( hr == S_OK ) {
  215. hr = HrFindInstance( m_pnc,
  216. m_guidMiniport,
  217. &pnccMiniport );
  218. if ( hr == S_OK ) {
  219. TraceMsg( L" Found the miniport instance to uninstall.\n" );
  220. hr = pncClassSetup->DeInstall( pnccMiniport,
  221. NULL,
  222. NULL );
  223. ReleaseObj( pnccMiniport );
  224. }
  225. else {
  226. TraceMsg( L" Didn't find the miniport instance to uninstall.\n" );
  227. }
  228. ReleaseObj( pncClassSetup );
  229. }
  230. else {
  231. TraceMsg( L" QueryInterface failed.\n" );
  232. }
  233. ReleaseObj( pncClass );
  234. }
  235. else {
  236. TraceMsg( L" QueryNetCfgClass failed.\n" );
  237. }
  238. TraceMsg( L"<--CMuxVirtualMiniport::DeInstall(HRESULT = %x).\n",
  239. hr );
  240. return hr;
  241. }
  242. //+---------------------------------------------------------------------------
  243. //
  244. // Function: CMuxVirtualMiniport::ApplyRegistryChanges
  245. //
  246. // Purpose: Store the changes in the registry.
  247. //
  248. // Arguments:
  249. // IN eApplyAction: Action performed.
  250. //
  251. // Returns: S_OK on success, otherwise an error code.
  252. //
  253. // Notes:
  254. //
  255. HRESULT CMuxVirtualMiniport::ApplyRegistryChanges(ConfigAction eApplyAction)
  256. {
  257. HKEY hkeyAdapterGuid;
  258. WCHAR szAdapterGuid[MAX_PATH+1];
  259. WCHAR szAdapterGuidKey[MAX_PATH+1];
  260. WCHAR szMiniportGuid[MAX_PATH+1];
  261. LPWSTR lpDevice;
  262. LONG lResult = 0;
  263. TraceMsg( L"-->CMuxVirtualMiniport::ApplyRegistryChanges.\n" );
  264. switch( eApplyAction ) {
  265. case eActAdd: // Virtual miniport added.
  266. StringFromGUID2( m_guidAdapter,
  267. szAdapterGuid,
  268. MAX_PATH+1 );
  269. swprintf( szAdapterGuidKey,
  270. L"%s\\%s",
  271. c_szAdapterList,
  272. szAdapterGuid );
  273. lResult = RegCreateKeyExW( HKEY_LOCAL_MACHINE,
  274. szAdapterGuidKey,
  275. 0,
  276. NULL,
  277. REG_OPTION_NON_VOLATILE,
  278. KEY_ALL_ACCESS,
  279. NULL,
  280. &hkeyAdapterGuid,
  281. NULL);
  282. if ( lResult == ERROR_SUCCESS ) {
  283. StringFromGUID2( m_guidMiniport,
  284. szMiniportGuid,
  285. MAX_PATH+1 );
  286. lpDevice = AddDevicePrefix( szMiniportGuid );
  287. if ( lpDevice ) {
  288. #ifndef PASSTHRU_NOTIFY
  289. lResult = AddToMultiSzValue( hkeyAdapterGuid,
  290. lpDevice );
  291. #else
  292. lResult = RegSetValueExW( hkeyAdapterGuid,
  293. c_szUpperBindings,
  294. 0,
  295. REG_SZ,
  296. (LPBYTE)lpDevice,
  297. (wcslen(lpDevice) + 1) *
  298. sizeof(WCHAR) );
  299. #endif
  300. if ( lResult != ERROR_SUCCESS ) {
  301. TraceMsg( L" Failed to save %s at %s\\%s.\n",
  302. lpDevice,
  303. szAdapterGuidKey,
  304. c_szUpperBindings );
  305. }
  306. free( lpDevice );
  307. }
  308. else {
  309. lResult = ERROR_NOT_ENOUGH_MEMORY;
  310. }
  311. RegCloseKey( hkeyAdapterGuid );
  312. }
  313. else {
  314. TraceMsg( L" Failed to open the registry key: %s.\n",
  315. szAdapterGuidKey );
  316. }
  317. break;
  318. case eActRemove: // Virtual miniport removed.
  319. StringFromGUID2( m_guidAdapter,
  320. szAdapterGuid,
  321. MAX_PATH+1 );
  322. swprintf( szAdapterGuidKey,
  323. L"%s\\%s",
  324. c_szAdapterList,
  325. szAdapterGuid );
  326. lResult = RegCreateKeyExW( HKEY_LOCAL_MACHINE,
  327. szAdapterGuidKey,
  328. 0,
  329. NULL,
  330. REG_OPTION_NON_VOLATILE,
  331. KEY_ALL_ACCESS,
  332. NULL,
  333. &hkeyAdapterGuid,
  334. NULL);
  335. if ( lResult == ERROR_SUCCESS ) {
  336. StringFromGUID2( m_guidMiniport,
  337. szMiniportGuid,
  338. MAX_PATH+1 );
  339. lpDevice = AddDevicePrefix( szMiniportGuid );
  340. TraceMsg( L" Deleting %s at %s.\n",
  341. lpDevice,
  342. szAdapterGuidKey );
  343. if ( lpDevice ) {
  344. #ifndef PASSTHRU_NOTIFY
  345. lResult = DeleteFromMultiSzValue( hkeyAdapterGuid,
  346. lpDevice );
  347. #else
  348. lResult = RegDeleteValueW( hkeyAdapterGuid,
  349. c_szUpperBindings );
  350. #endif
  351. if ( lResult != ERROR_SUCCESS ) {
  352. TraceMsg( L" Failed to delete %s at %s\\%s.\n",
  353. lpDevice,
  354. szAdapterGuidKey,
  355. c_szUpperBindings );
  356. }
  357. free( lpDevice );
  358. }
  359. RegCloseKey( hkeyAdapterGuid );
  360. }
  361. else {
  362. TraceMsg( L" Failed to open the registry key: %s.\n",
  363. szAdapterGuidKey );
  364. }
  365. }
  366. TraceMsg( L"<--CMuxVirtualMiniport::ApplyRegistryChanges(HRESULT = %x).\n",
  367. HRESULT_FROM_WIN32(lResult) );
  368. return HRESULT_FROM_WIN32(lResult);
  369. }
  370. //+---------------------------------------------------------------------------
  371. //
  372. // Function: CMuxVirtualMiniport::ApplyPnpChanges
  373. //
  374. // Purpose:
  375. //
  376. // Arguments:
  377. // IN eApplyAction: Action performed.
  378. //
  379. // Returns: S_OK on success, otherwise an error code.
  380. //
  381. // Notes:
  382. //
  383. HRESULT CMuxVirtualMiniport::ApplyPnpChanges
  384. (INetCfgPnpReconfigCallback *pfCallback,
  385. ConfigAction eApplyAction)
  386. {
  387. TraceMsg( L"-->CMuxVirtualMiniport::ApplyPnpChanges.\n" );
  388. TraceMsg( L"<--CMuxVirtualMiniport::ApplyPnpChanges(HRESULT = %x).\n",
  389. S_OK );
  390. return S_OK;
  391. }