Leaked source code of windows server 2003
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.

383 lines
12 KiB

  1. /////////////////////////////////////////////////////////////////////////
  2. //
  3. // cfgmgrdevice.h
  4. //
  5. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  6. //
  7. // History: 10/15/97 Sanj Created by Sanj
  8. // 10/17/97 jennymc Moved things a tiny bit
  9. //
  10. /////////////////////////////////////////////////////////////////////////
  11. #ifndef __CFGMGRDEVICE_H__
  12. #define __CFGMGRDEVICE_H__
  13. /////////////////////////////////////////////////////////////////////////
  14. // registry keys
  15. /////////////////////////////////////////////////////////////////////////
  16. #define CONFIGMGR_ENUM_KEY L"Config Manager\\Enum\\"
  17. #define LOCALMACHINE_ENUM_KEY L"Enum\\"
  18. #define CONFIGMGR_DEVICE_HARDWAREKEY_VALUE _T("HardwareKey")
  19. #define CONFIGMGR_DEVICE_ALLOCATION_VALUE _T("Allocation")
  20. #define CONFIGMGR_DEVICEDESC_VALUE _T("DeviceDesc")
  21. #define CONFIGMGR_DEVICE_PROBLEM_VALUE _T("Problem")
  22. #define CONFIGMGR_DEVICE_STATUS_VALUE L"Status"
  23. #define CONFIGMGR_DEVICE_STATUS_VALUET _T("Status")
  24. #include "iodesc.h"
  25. #include "chwres.h"
  26. #include "sms95lanexp.h"
  27. #include "refptrlite.h"
  28. class CIRQCollection;
  29. class CDMACollection;
  30. class CDeviceMemoryCollection;
  31. class CNT4ServiceToResourceMap;
  32. BOOL WINAPI FindDosDeviceName ( const TCHAR *a_DosDeviceNameList , const CHString a_SymbolicName , CHString &a_DosDevice , BOOL a_MappedDevice = FALSE ) ;
  33. BOOL WINAPI QueryDosDeviceNames ( TCHAR *&a_DosDeviceNameList ) ;
  34. class __declspec(uuid("CB0E0536-D375-11d2-B35E-00104BC97924")) CConfigMgrDevice;
  35. _COM_SMARTPTR_TYPEDEF(CConfigMgrDevice, __uuidof(CConfigMgrDevice));
  36. /////////////////////////////////////////////////////////////////////////
  37. class
  38. __declspec(uuid("CB0E0536-D375-11d2-B35E-00104BC97924"))
  39. CConfigMgrDevice : public CRefPtrLite
  40. {
  41. public:
  42. // Construction/Destruction
  43. CConfigMgrDevice( LPCWSTR pszConfigMgrName,DWORD dwTypeToGet );
  44. //CConfigMgrDevice( LPCWSTR pszDevice );
  45. CConfigMgrDevice( DEVNODE dn = NULL, DWORD dwResType = ResType_All );
  46. ~CConfigMgrDevice();
  47. //////////////////////////////////////////////////
  48. // AVOID THESE FUNCTIONS, THESE ARE LEGACY //
  49. //////////////////////////////////////////////////
  50. LPCWSTR GetName( void );
  51. LPCWSTR GetHardwareKey( void );
  52. LPCWSTR GetDeviceDesc( void );
  53. // Status and problem functions
  54. DWORD GetStatus( void );
  55. BOOL GetStatus( CHString& str );
  56. void GetProblem( CHString& str );
  57. DWORD GetProblem( void );
  58. BOOL IsOK( void );
  59. BOOL MapKeyToConfigMgrDeviceName();
  60. //////////////////////////////////
  61. // END LEGACY FUNCTIONS //
  62. //////////////////////////////////
  63. //////////////////////////////////////////////////////
  64. // USE THESE FUNCTIONS, THESE ARE THE REAL THING! //
  65. //////////////////////////////////////////////////////
  66. // New functions that use config manager APIs directly
  67. // Resource retrieval
  68. void GetResourceList( CResourceCollection& resourceList, CNT4ServiceToResourceMap* pResourceMap = NULL );
  69. BOOL GetIRQResources( CIRQCollection& irqList, CNT4ServiceToResourceMap* pResourceMap = NULL );
  70. BOOL GetIOResources( CIOCollection& ioList, CNT4ServiceToResourceMap* pResourceMap = NULL );
  71. BOOL GetDMAResources( CDMACollection& dmaList, CNT4ServiceToResourceMap* pResourceMap = NULL );
  72. BOOL GetDeviceMemoryResources( CDeviceMemoryCollection& DeviceMemoryList, CNT4ServiceToResourceMap* pResourceMap = NULL );
  73. // String Values
  74. BOOL GetDeviceDesc( CHString& strVal );
  75. BOOL GetService( CHString& strVal );
  76. BOOL GetClass( CHString& strVal );
  77. BOOL GetClassGUID( CHString& strVal );
  78. BOOL GetDriver( CHString& strVal );
  79. BOOL GetMfg( CHString& strVal );
  80. BOOL GetFriendlyName( CHString& strVal );
  81. BOOL GetLocationInformation( CHString& strVal );
  82. BOOL GetPhysicalDeviceObjectName( CHString& strVal );
  83. BOOL GetEnumeratorName( CHString& strVal );
  84. // DWORD Values
  85. BOOL GetConfigFlags( DWORD& dwVal );
  86. BOOL GetCapabilities( DWORD& dwVal );
  87. BOOL GetUINumber( DWORD& dwVal );
  88. // MULTI_SZ Values
  89. BOOL GetHardwareID( CHStringArray& strArray );
  90. BOOL GetCompatibleIDS( CHStringArray& strArray );
  91. BOOL GetUpperFilters( CHStringArray& strArray );
  92. BOOL GetLowerFilters( CHStringArray& strArray );
  93. // Use Config Manager APIs directly
  94. BOOL GetStringProperty( ULONG ulProperty, CHString& strValue );
  95. BOOL GetDWORDProperty( ULONG ulProperty, DWORD* pdwVal );
  96. BOOL GetMULTISZProperty( ULONG ulProperty, CHStringArray& strArray );
  97. // Device Relationship functions
  98. BOOL GetParent( CConfigMgrDevicePtr & pParentDevice );
  99. BOOL GetChild( CConfigMgrDevicePtr & pChildDevice );
  100. BOOL GetSibling( CConfigMgrDevicePtr & pSiblingDevice );
  101. // Miscelaneous Device functions
  102. BOOL GetBusInfo( INTERFACE_TYPE* pitBusType, LPDWORD pdwBusNumber, CNT4ServiceToResourceMap* pResourceMap = NULL );
  103. BOOL GetDeviceID( CHString& strID );
  104. BOOL GetStatus( LPDWORD pdwStatus, LPDWORD pdwProblem );
  105. BOOL IsUsingForcedConfig();
  106. BOOL IsClass(LPCWSTR pwszClassName);
  107. // Direct registry access helpers
  108. BOOL GetRegistryKeyName( CHString &strName);
  109. BOOL GetRegStringProperty(LPCWSTR szProperty, CHString &strValue);
  110. BOOL operator == ( const CConfigMgrDevice& device );
  111. private:
  112. // Registry traversal helpers
  113. // LEGACY FUNCTIONS BEGIN
  114. BOOL GetConfigMgrInfo( void );
  115. BOOL GetDeviceInfo( void );
  116. BOOL GetHardwareKey( HKEY hKey );
  117. BOOL GetResourceAllocation( HKEY hKey );
  118. BOOL GetStatusInfo( HKEY hKey );
  119. BOOL GetDeviceDesc( HKEY hKey );
  120. // LEGACY FUNCTIONS END
  121. #if NTONLY > 4
  122. // NT 5 Helpers
  123. BOOL GetBusInfoNT5( INTERFACE_TYPE* pitBusType, LPDWORD pdwBusNumber );
  124. static BOOL WINAPI IsIsaReallyEisa();
  125. static INTERFACE_TYPE WINAPI ConvertBadIsaBusType(INTERFACE_TYPE type);
  126. #endif
  127. // Resource Allocation Data Helpers
  128. // Resource allocation registry walkthroughs
  129. void TraverseAllocationData( CResourceCollection& resourceList );
  130. void TraverseData( const BYTE *& pbTraverseData, DWORD& dwSizeRemainingData, DWORD dwSizeTraverse );
  131. BOOL GetNextResource( const BYTE * pbTraverseData, DWORD dwSizeRemainingData, DWORD& dwResourceType, DWORD& dwResourceSize );
  132. // Resource functions
  133. BOOL WalkAllocatedResources( CResourceCollection& resourceList, CNT4ServiceToResourceMap* pResourceMap, RESOURCEID resType );
  134. BOOL AddResourceToList( RESOURCEID resourceID, LPVOID pResource, DWORD dwResourceLength, CResourceCollection& resourceList );
  135. #ifdef NTONLY
  136. // NT4 Resource functions
  137. BOOL WalkAllocatedResourcesNT4( CResourceCollection& resourceList, CNT4ServiceToResourceMap* pResourceMap, CM_RESOURCE_TYPE resType );
  138. BOOL GetServiceResourcesNT4( LPCWSTR pszServiceName, CNT4ServiceToResourceMap& resourceMap, CResourceCollection& resourceList, CM_RESOURCE_TYPE cmrtFilter = CmResourceTypeNull );
  139. #if NTONLY == 4
  140. BOOL GetBusInfoNT4( INTERFACE_TYPE* pitBusType, LPDWORD pdwBusNumber, CNT4ServiceToResourceMap* pResourceMap );
  141. #endif
  142. // NT 4 resource datatype coercsion functions
  143. CM_RESOURCE_TYPE RESOURCEIDToCM_RESOURCE_TYPE( RESOURCEID resType );
  144. void NT4IRQToIRQ_DES( LPRESOURCE_DESCRIPTOR pResourceDescriptor, PIRQ_DES pirqDes32 );
  145. void NT4IOToIOWBEM_DES( LPRESOURCE_DESCRIPTOR pResourceDescriptor, PIOWBEM_DES pioDes32 );
  146. void NT4MEMToMEM_DES( LPRESOURCE_DESCRIPTOR pResourceDescriptor, PMEM_DES pmemDes32 );
  147. void NT4DMAToDMA_DES( LPRESOURCE_DESCRIPTOR pResourceDescriptor, PDMA_DES pdmaDes32 );
  148. #endif
  149. // 16 to 32-bit coercsion functions
  150. void IRQDes16To32( PIRQ_DES16 pirqDes16, PIRQ_DES pirqDes32 );
  151. void IODes16To32( PIO_DES16 pioDes16, PIOWBEM_DES pioDes32 );
  152. void DMADes16To32( PDMA_DES16 pdmaDes16, PDMA_DES pdmaDes32 );
  153. void MEMDes16To32( PMEM_DES16 pmemDes16, PMEM_DES pmemDes32 );
  154. BOOL BusType16ToInterfaceType( CMBUSTYPE cmBusType16, INTERFACE_TYPE* pinterfaceType );
  155. // LEGACY VARIABLES BEGIN
  156. CHString m_strConfigMgrName;
  157. CHString m_strHardwareKey;
  158. CHString m_strDeviceDesc;
  159. DWORD m_dwTypeToGet;
  160. // If we get allocation information, we store it in here.
  161. BYTE* m_pbAllocationData;
  162. DWORD m_dwSizeAllocationData;
  163. // Device status info
  164. DWORD m_dwStatus;
  165. DWORD m_dwProblem;
  166. #ifdef WIN9XONLY
  167. DWORD GetStatusFromConfigManagerDirectly(void);
  168. #endif
  169. // LEGACY VARIABLES END
  170. // Use the devnode to query values directly from config manager
  171. DEVNODE m_dn;
  172. };
  173. inline LPCWSTR CConfigMgrDevice::GetName( void )
  174. {
  175. return m_strConfigMgrName;
  176. }
  177. inline LPCWSTR CConfigMgrDevice::GetHardwareKey( void )
  178. {
  179. return m_strHardwareKey;
  180. }
  181. inline LPCWSTR CConfigMgrDevice::GetDeviceDesc( void )
  182. {
  183. return m_strDeviceDesc;
  184. }
  185. inline void CConfigMgrDevice::GetResourceList( CResourceCollection& resourceList, CNT4ServiceToResourceMap* pResourceMap/*=NULL*/ )
  186. {
  187. WalkAllocatedResources( resourceList, pResourceMap, m_dwTypeToGet );
  188. }
  189. inline DWORD CConfigMgrDevice::GetStatus( void )
  190. {
  191. return m_dwStatus;
  192. }
  193. inline DWORD CConfigMgrDevice::GetProblem( void )
  194. {
  195. return m_dwProblem;
  196. }
  197. inline BOOL CConfigMgrDevice::IsOK( void )
  198. {
  199. return ( 0 == m_dwProblem );
  200. }
  201. // New Config manager functions that query Config Manager (16 & 32 bit)
  202. // directly for info.
  203. // REG_SZ Properties
  204. inline BOOL CConfigMgrDevice::GetDeviceDesc( CHString& strVal )
  205. {
  206. return GetStringProperty( CM_DRP_DEVICEDESC, strVal );
  207. }
  208. inline BOOL CConfigMgrDevice::GetService( CHString& strVal )
  209. {
  210. return GetStringProperty( CM_DRP_SERVICE, strVal );
  211. }
  212. inline BOOL CConfigMgrDevice::GetClass( CHString& strVal )
  213. {
  214. return GetStringProperty( CM_DRP_CLASS, strVal );
  215. }
  216. inline BOOL CConfigMgrDevice::GetClassGUID( CHString& strVal )
  217. {
  218. return GetStringProperty( CM_DRP_CLASSGUID, strVal );
  219. }
  220. inline BOOL CConfigMgrDevice::GetDriver( CHString& strVal )
  221. {
  222. return GetStringProperty( CM_DRP_DRIVER, strVal );
  223. }
  224. inline BOOL CConfigMgrDevice::GetMfg( CHString& strVal )
  225. {
  226. return GetStringProperty( CM_DRP_MFG, strVal );
  227. }
  228. inline BOOL CConfigMgrDevice::GetFriendlyName( CHString& strVal )
  229. {
  230. return GetStringProperty( CM_DRP_FRIENDLYNAME, strVal );
  231. }
  232. inline BOOL CConfigMgrDevice::GetLocationInformation( CHString& strVal )
  233. {
  234. return GetStringProperty( CM_DRP_LOCATION_INFORMATION, strVal );
  235. }
  236. inline BOOL CConfigMgrDevice::GetPhysicalDeviceObjectName( CHString& strVal )
  237. {
  238. return GetStringProperty( CM_DRP_PHYSICAL_DEVICE_OBJECT_NAME, strVal );
  239. }
  240. inline BOOL CConfigMgrDevice::GetEnumeratorName( CHString& strVal )
  241. {
  242. return GetStringProperty( CM_DRP_ENUMERATOR_NAME, strVal );
  243. }
  244. // DWORD functions
  245. inline BOOL CConfigMgrDevice::GetConfigFlags( DWORD& dwVal )
  246. {
  247. return GetDWORDProperty( CM_DRP_CONFIGFLAGS, &dwVal );
  248. }
  249. inline BOOL CConfigMgrDevice::GetCapabilities( DWORD& dwVal )
  250. {
  251. return GetDWORDProperty( CM_DRP_CAPABILITIES, &dwVal );
  252. }
  253. inline BOOL CConfigMgrDevice::GetUINumber( DWORD& dwVal )
  254. {
  255. return GetDWORDProperty( CM_DRP_UI_NUMBER, &dwVal );
  256. }
  257. // MULTI_SZ properties
  258. inline BOOL CConfigMgrDevice::GetHardwareID( CHStringArray& strArray )
  259. {
  260. return GetMULTISZProperty( CM_DRP_HARDWAREID, strArray );
  261. }
  262. inline BOOL CConfigMgrDevice::GetCompatibleIDS( CHStringArray& strArray )
  263. {
  264. return GetMULTISZProperty( CM_DRP_COMPATIBLEIDS, strArray );
  265. }
  266. inline BOOL CConfigMgrDevice::GetUpperFilters( CHStringArray& strArray )
  267. {
  268. return GetMULTISZProperty( CM_DRP_UPPERFILTERS, strArray );
  269. }
  270. inline BOOL CConfigMgrDevice::GetLowerFilters( CHStringArray& strArray )
  271. {
  272. return GetMULTISZProperty( CM_DRP_LOWERFILTERS, strArray );
  273. }
  274. // Overloaded == operator. Checks if DEVNODEs are the same.
  275. inline BOOL CConfigMgrDevice::operator == ( const CConfigMgrDevice& device )
  276. {
  277. return ( m_dn == device.m_dn );
  278. }
  279. // A collection of Devices
  280. class CDeviceCollection : public TRefPtr<CConfigMgrDevice>
  281. {
  282. public:
  283. // Construction/Destruction
  284. CDeviceCollection();
  285. ~CDeviceCollection();
  286. // Get the resources for this list of devices.
  287. BOOL GetResourceList( CResourceCollection& resourceList );
  288. BOOL GetIRQResources( CIRQCollection& IRQList );
  289. BOOL GetDMAResources( CDMACollection& DMAList );
  290. BOOL GetIOResources( CIOCollection& IOList );
  291. BOOL GetDeviceMemoryResources( CDeviceMemoryCollection& DeviceMemoryList );
  292. private:
  293. // Because we're inheriting, we need to declare this here
  294. // (= operator is not inherited).
  295. const CDeviceCollection& operator = ( const CDeviceCollection& srcCollection );
  296. };
  297. #endif