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.

1041 lines
27 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. hwprof.c
  5. Abstract:
  6. This module contains the API routines that operate directly on hardware
  7. profile configurations.
  8. CM_Is_Dock_Station_Present
  9. CM_Request_Eject_PC
  10. CM_Get_HW_Prof_Flags
  11. CM_Set_HW_Prof_Flags
  12. CM_Get_Hardware_Profile_Info
  13. CM_Set_HW_Prof
  14. Author:
  15. Paula Tomlinson (paulat) 7-18-1995
  16. Environment:
  17. User mode only.
  18. Revision History:
  19. 18-July-1995 paulat
  20. Creation and initial implementation.
  21. --*/
  22. //
  23. // includes
  24. //
  25. #include "precomp.h"
  26. #pragma hdrstop
  27. #include "cfgi.h"
  28. CMAPI
  29. CONFIGRET
  30. WINAPI
  31. CM_Is_Dock_Station_Present_Ex(
  32. OUT PBOOL pbPresent,
  33. IN HMACHINE hMachine
  34. )
  35. /*++
  36. Routine Description:
  37. This routine determines whether a docking station is currently present.
  38. Parameters:
  39. pbPresent Supplies the address of a boolean variable that is set
  40. upon successful return to indicate whether or not a
  41. docking station is currently present.
  42. Return Value:
  43. If the function succeeds, the return value is CR_SUCCESS.
  44. If the function fails, the return value is a CR failure code.
  45. --*/
  46. {
  47. CONFIGRET status = CR_SUCCESS;
  48. handle_t hBinding = NULL;
  49. try {
  50. //
  51. // validate input parameters
  52. //
  53. if (!ARGUMENT_PRESENT(pbPresent)) {
  54. status = CR_INVALID_POINTER;
  55. goto Clean0;
  56. }
  57. //
  58. // Initialize output parameter
  59. //
  60. *pbPresent = FALSE;
  61. //
  62. // setup rpc binding handle
  63. //
  64. if (!PnPGetGlobalHandles(hMachine, NULL, &hBinding)) {
  65. status = CR_FAILURE;
  66. goto Clean0;
  67. }
  68. //
  69. // No special privileges are required by the server
  70. //
  71. RpcTryExcept {
  72. //
  73. // call rpc service entry point
  74. //
  75. status = PNP_IsDockStationPresent(
  76. hBinding,
  77. pbPresent);
  78. }
  79. RpcExcept (I_RpcExceptionFilter(RpcExceptionCode())) {
  80. KdPrintEx((DPFLTR_PNPMGR_ID,
  81. DBGF_ERRORS,
  82. "PNP_IsDockStationPresent caused an exception (%d)\n",
  83. RpcExceptionCode()));
  84. status = MapRpcExceptionToCR(RpcExceptionCode());
  85. goto Clean0;
  86. }
  87. RpcEndExcept
  88. Clean0:
  89. NOTHING;
  90. } except(EXCEPTION_EXECUTE_HANDLER) {
  91. status = CR_FAILURE;
  92. }
  93. return status;
  94. } // CM_Is_Dock_Station_Present_Ex
  95. CMAPI
  96. CONFIGRET
  97. WINAPI
  98. CM_Request_Eject_PC_Ex(
  99. IN HMACHINE hMachine
  100. )
  101. /*++
  102. Routine Description:
  103. This routine requests that the PC be ejected (i.e., undocked).
  104. Parameters:
  105. none.
  106. Return Value:
  107. If the function succeeds, the return value is CR_SUCCESS.
  108. If the function fails, the return value is a CR failure code.
  109. --*/
  110. {
  111. CONFIGRET status = CR_SUCCESS;
  112. handle_t hBinding = NULL;
  113. HANDLE hToken;
  114. ULONG ulPrivilege;
  115. try {
  116. //
  117. // No input Parameters to validate.
  118. //
  119. //
  120. // setup rpc binding handle
  121. //
  122. if (!PnPGetGlobalHandles(hMachine, NULL, &hBinding)) {
  123. status = CR_FAILURE;
  124. goto Clean0;
  125. }
  126. //
  127. // Enable privileges required by the server
  128. //
  129. ulPrivilege = SE_UNDOCK_PRIVILEGE;
  130. hToken = PnPEnablePrivileges(&ulPrivilege, 1);
  131. RpcTryExcept {
  132. //
  133. // call rpc service entry point
  134. //
  135. status = PNP_RequestEjectPC(
  136. hBinding); // rpc binding handle
  137. }
  138. RpcExcept (I_RpcExceptionFilter(RpcExceptionCode())) {
  139. KdPrintEx((DPFLTR_PNPMGR_ID,
  140. DBGF_ERRORS,
  141. "PNP_RequestEjectPC caused an exception (%d)\n",
  142. RpcExceptionCode()));
  143. status = MapRpcExceptionToCR(RpcExceptionCode());
  144. }
  145. RpcEndExcept
  146. //
  147. // Restore previous privileges
  148. //
  149. PnPRestorePrivileges(hToken);
  150. Clean0:
  151. NOTHING;
  152. } except(EXCEPTION_EXECUTE_HANDLER) {
  153. status = CR_FAILURE;
  154. }
  155. return status;
  156. } // CM_Request_Eject_PC_Ex
  157. CONFIGRET
  158. CM_Get_HW_Prof_Flags_ExW(
  159. IN DEVINSTID_W pDeviceID,
  160. IN ULONG ulHardwareProfile,
  161. OUT PULONG pulValue,
  162. IN ULONG ulFlags,
  163. IN HMACHINE hMachine
  164. )
  165. /*++
  166. Routine Description:
  167. This routine retrieves the configuration-specific configuration flags
  168. for a device instance and hardware profile combination.
  169. Parameters:
  170. pDeviceID Supplies the address of a NULL-terminated string
  171. specifying the name of the device instance to query.
  172. ulHardwareProfile Supplies the handle of the hardware profile to query.
  173. If 0, the API queries the current hardware profile.
  174. pulValue Supplies the address of the variable that receives the
  175. configuration-specific configuration (CSCONFIGFLAG_)
  176. flags.
  177. ulFlags Must be zero.
  178. hMachine Machine handle returned from CM_Connect_Machine or NULL.
  179. Return Value:
  180. If the function succeeds, the return value is CR_SUCCESS.
  181. If the function fails, the return value is one of the following:
  182. CR_INVALID_FLAG,
  183. CR_INVALID_POINTER,
  184. CR_REGISTRY_ERROR,
  185. CR_REMOTE_COMM_FAILURE,
  186. CR_MACHINE_UNAVAILABLE,
  187. CR_FAILURE.
  188. --*/
  189. {
  190. CONFIGRET Status = CR_SUCCESS;
  191. WCHAR szFixedUpDeviceID[MAX_DEVICE_ID_LEN];
  192. handle_t hBinding = NULL;
  193. size_t DeviceIDLen = 0;
  194. try {
  195. //
  196. // validate input parameters
  197. //
  198. if ((!ARGUMENT_PRESENT(pDeviceID)) ||
  199. (!ARGUMENT_PRESENT(pulValue))) {
  200. Status = CR_INVALID_POINTER;
  201. goto Clean0;
  202. }
  203. if (INVALID_FLAGS(ulFlags, 0)) {
  204. Status = CR_INVALID_FLAG;
  205. goto Clean0;
  206. }
  207. //
  208. // make sure the device instance path isn't too long
  209. //
  210. if (FAILED(StringCchLength(pDeviceID,
  211. MAX_DEVICE_ID_LEN,
  212. &DeviceIDLen))) {
  213. Status = CR_INVALID_DEVICE_ID;
  214. goto Clean0;
  215. }
  216. ASSERT(DeviceIDLen < MAX_DEVICE_ID_LEN);
  217. //
  218. // device instance path is not optional
  219. //
  220. if (DeviceIDLen == 0) {
  221. Status = CR_INVALID_DEVICE_ID;
  222. goto Clean0;
  223. }
  224. //
  225. // check the format of the device id string
  226. //
  227. if (!IsLegalDeviceId(pDeviceID)) {
  228. Status = CR_INVALID_DEVICE_ID;
  229. goto Clean0;
  230. }
  231. //
  232. // fix up the device ID string for consistency (uppercase, etc)
  233. //
  234. CopyFixedUpDeviceId(szFixedUpDeviceID,
  235. pDeviceID,
  236. (DWORD)DeviceIDLen);
  237. //
  238. // setup rpc binding handle
  239. //
  240. if (!PnPGetGlobalHandles(hMachine, NULL, &hBinding)) {
  241. Status = CR_FAILURE;
  242. goto Clean0;
  243. }
  244. //
  245. // No special privileges are required by the server
  246. //
  247. RpcTryExcept {
  248. //
  249. // call rpc service entry point
  250. //
  251. Status = PNP_HwProfFlags(
  252. hBinding, // rpc binding handle
  253. PNP_GET_HWPROFFLAGS, // HW Prof Action flag
  254. szFixedUpDeviceID, // device id string
  255. ulHardwareProfile, // hw config id
  256. pulValue, // config flags returned here
  257. NULL, // Buffer that receives VetoType
  258. NULL, // Buffer that receives VetoName
  259. 0, // Size of VetoName buffer
  260. ulFlags); // currently unused
  261. }
  262. RpcExcept (I_RpcExceptionFilter(RpcExceptionCode())) {
  263. KdPrintEx((DPFLTR_PNPMGR_ID,
  264. DBGF_ERRORS,
  265. "PNP_HwProfFlags caused an exception (%d)\n",
  266. RpcExceptionCode()));
  267. Status = MapRpcExceptionToCR(RpcExceptionCode());
  268. }
  269. RpcEndExcept
  270. Clean0:
  271. NOTHING;
  272. } except(EXCEPTION_EXECUTE_HANDLER) {
  273. Status = CR_FAILURE;
  274. }
  275. return Status;
  276. } // CM_Get_HW_Prof_Flags_ExW
  277. CONFIGRET
  278. CM_Set_HW_Prof_Flags_ExW(
  279. IN DEVINSTID_W pDeviceID,
  280. IN ULONG ulConfig,
  281. IN ULONG ulValue,
  282. IN ULONG ulFlags,
  283. IN HMACHINE hMachine
  284. )
  285. /*++
  286. Routine Description:
  287. This routine sets the configuration-specific configuration flags for a
  288. device instance and hardware profile combination. If the
  289. CSCONFIGFLAG_DO_NOT_CREATE bit is set for an existing device instance
  290. in the current hardware profile, it will be removed. If the
  291. CSCONFIGFLAG_DO_NOT_CREATE bit is cleared in the current hardware profile,
  292. the entire hardware tree will be reenumerated, so that the parent of the
  293. device instance has the chance to create the device instance if necessary.
  294. Parameters:
  295. pDeviceID Supplies the address of a null-terminated string that
  296. specifies the name of a device instance to modify.
  297. ulConfig Supplies the number of the hardware profile to modify.
  298. If 0, the API modifies the current hardware profile.
  299. ulValue Supplies the configuration flags value. Can be a
  300. combination of these values:
  301. CSCONFIGFLAG_DISABLE Disable the device instance in this
  302. hardware profile.
  303. CSCONFIGFLAG_DO_NOT_CREATE Do not allow this device
  304. instance to be created in this hardware profile.
  305. ulFlags CM_SET_HW_PROF_FLAGS_UI_NOT_OK
  306. If this flag is specified then the OS will not display the
  307. reason that the device failed to be disabled or removed.
  308. hMachine Machine handle returned from CM_Connect_Machine or NULL.
  309. Return Value:
  310. If the function succeeds, the return value is CR_SUCCESS.
  311. If the function fails, the return value is one of the following:
  312. CR_INVALID_FLAG,
  313. CR_INVALID_POINTER,
  314. CR_REGISTRY_ERROR,
  315. CR_REMOTE_COMM_FAILURE,
  316. CR_MACHINE_UNAVAILABLE,
  317. CR_FAILURE.
  318. --*/
  319. {
  320. CONFIGRET Status = CR_SUCCESS;
  321. WCHAR szFixedUpDeviceID[MAX_DEVICE_ID_LEN];
  322. ULONG ulTempValue = 0;
  323. handle_t hBinding = NULL;
  324. PNP_VETO_TYPE vetoType, *pVetoType;
  325. WCHAR vetoName[MAX_DEVICE_ID_LEN], *pszVetoName;
  326. ULONG ulNameLength;
  327. size_t DeviceIDLen = 0;
  328. HANDLE hToken;
  329. ULONG ulPrivilege;
  330. try {
  331. //
  332. // validate parameters
  333. //
  334. if (!ARGUMENT_PRESENT(pDeviceID)) {
  335. Status = CR_INVALID_POINTER;
  336. goto Clean0;
  337. }
  338. if (INVALID_FLAGS(ulFlags, CM_SET_HW_PROF_FLAGS_BITS)) {
  339. Status = CR_INVALID_FLAG;
  340. goto Clean0;
  341. }
  342. if (INVALID_FLAGS(ulValue, CSCONFIGFLAG_BITS)) {
  343. Status = CR_INVALID_DATA;
  344. goto Clean0;
  345. }
  346. //
  347. // make sure the device instance path isn't too long
  348. //
  349. if (FAILED(StringCchLength(pDeviceID,
  350. MAX_DEVICE_ID_LEN,
  351. &DeviceIDLen))) {
  352. Status = CR_INVALID_DEVICE_ID;
  353. goto Clean0;
  354. }
  355. ASSERT(DeviceIDLen < MAX_DEVICE_ID_LEN);
  356. //
  357. // device instance path is not optional
  358. //
  359. if (DeviceIDLen == 0) {
  360. Status = CR_INVALID_DEVICE_ID;
  361. goto Clean0;
  362. }
  363. //
  364. // check the format of the device id string
  365. //
  366. if (!IsLegalDeviceId(pDeviceID)) {
  367. Status = CR_INVALID_DEVICE_ID;
  368. goto Clean0;
  369. }
  370. //
  371. // fix up the device ID string for consistency (uppercase, etc)
  372. //
  373. CopyFixedUpDeviceId(szFixedUpDeviceID,
  374. pDeviceID,
  375. (DWORD)DeviceIDLen);
  376. //
  377. // setup rpc binding handle
  378. //
  379. if (!PnPGetGlobalHandles(hMachine, NULL, &hBinding)) {
  380. Status = CR_FAILURE;
  381. goto Clean0;
  382. }
  383. if (ulFlags & CM_SET_HW_PROF_FLAGS_UI_NOT_OK) {
  384. vetoType = PNP_VetoTypeUnknown;
  385. pVetoType = &vetoType;
  386. vetoName[0] = L'\0';
  387. pszVetoName = &vetoName[0];
  388. ulNameLength = MAX_DEVICE_ID_LEN;
  389. } else {
  390. pVetoType = NULL;
  391. pszVetoName = NULL;
  392. ulNameLength = 0;
  393. }
  394. ulTempValue = ulValue;
  395. //
  396. // Enable privileges required by the server
  397. //
  398. // Note that setting hardware profile flags may require
  399. // SE_LOAD_DRIVER_PRIVILEGE when the change affects the current state of
  400. // a device in the current hardware profile. Otherwise, only the access
  401. // to change persistent state is required.
  402. //
  403. ulPrivilege = SE_LOAD_DRIVER_PRIVILEGE;
  404. hToken = PnPEnablePrivileges(&ulPrivilege, 1);
  405. RpcTryExcept {
  406. //
  407. // call rpc service entry point
  408. //
  409. Status = PNP_HwProfFlags(
  410. hBinding, // rpc machine name
  411. PNP_SET_HWPROFFLAGS, // HW Prof Action flag
  412. szFixedUpDeviceID, // device id string
  413. ulConfig, // hw config id
  414. &ulTempValue, // specifies config flags
  415. pVetoType, // Buffer that receives the VetoType
  416. pszVetoName, // Buffer that receives the VetoName
  417. ulNameLength, // size of the pszVetoName buffer
  418. ulFlags); // specifies hwprof set flags
  419. }
  420. RpcExcept (I_RpcExceptionFilter(RpcExceptionCode())) {
  421. KdPrintEx((DPFLTR_PNPMGR_ID,
  422. DBGF_ERRORS,
  423. "PNP_HwProfFlags caused an exception (%d)\n",
  424. RpcExceptionCode()));
  425. Status = MapRpcExceptionToCR(RpcExceptionCode());
  426. }
  427. RpcEndExcept
  428. //
  429. // Restore previous privileges
  430. //
  431. PnPRestorePrivileges(hToken);
  432. Clean0:
  433. NOTHING;
  434. } except(EXCEPTION_EXECUTE_HANDLER) {
  435. Status = CR_FAILURE;
  436. }
  437. return Status;
  438. } // CM_Set_HW_Prof_Flags_ExW
  439. CONFIGRET
  440. CM_Get_Hardware_Profile_Info_ExW(
  441. IN ULONG ulIndex,
  442. OUT PHWPROFILEINFO_W pHWProfileInfo,
  443. IN ULONG ulFlags,
  444. IN HMACHINE hMachine
  445. )
  446. /*++
  447. Routine Description:
  448. This routine returns information about a hardware profile.
  449. Parameters:
  450. ulIndex Supplies the index of the hardware profile to retrieve
  451. information for. Specifying 0xFFFFFFFF references the
  452. currently active hardware profile.
  453. pHWProfileInfo Supplies the address of a HWPROFILEINFO structure that
  454. will receive information about the specified hardware
  455. profile.
  456. ulFlags Must be zero.
  457. hMachine Machine handle returned from CM_Connect_Machine or NULL.
  458. Return Value:
  459. If the function succeeds, the return value is CR_SUCCESS.
  460. If the function fails, the return value is one of the following:
  461. CR_INVALID_FLAG,
  462. CR_INVALID_POINTER,
  463. CR_INVALID_DATA,
  464. CR_NO_SUCH_VALUE,
  465. CR_REGISTRY_ERROR,
  466. CR_REMOTE_COMM_FAILURE,
  467. CR_MACHINE_UNAVAILABLE,
  468. CR_FAILURE.
  469. --*/
  470. {
  471. CONFIGRET Status = CR_SUCCESS;
  472. ULONG ulSize = sizeof(HWPROFILEINFO);
  473. handle_t hBinding = NULL;
  474. try {
  475. //
  476. // validate parameters
  477. //
  478. if (!ARGUMENT_PRESENT(pHWProfileInfo)) {
  479. Status = CR_INVALID_POINTER;
  480. goto Clean0;
  481. }
  482. if (INVALID_FLAGS(ulFlags, 0)) {
  483. Status = CR_INVALID_FLAG;
  484. goto Clean0;
  485. }
  486. //
  487. // setup rpc binding handle
  488. //
  489. if (!PnPGetGlobalHandles(hMachine, NULL, &hBinding)) {
  490. Status = CR_FAILURE;
  491. goto Clean0;
  492. }
  493. //
  494. // No special privileges are required by the server
  495. //
  496. RpcTryExcept {
  497. //
  498. // call rpc service entry point
  499. //
  500. Status = PNP_GetHwProfInfo(
  501. hBinding, // rpc machine name
  502. ulIndex, // hw profile index
  503. pHWProfileInfo, // returns profile info
  504. ulSize, // sizeof of profile info struct
  505. ulFlags); // currently unused
  506. }
  507. RpcExcept (I_RpcExceptionFilter(RpcExceptionCode())) {
  508. KdPrintEx((DPFLTR_PNPMGR_ID,
  509. DBGF_ERRORS,
  510. "PNP_GetHwProfInfo caused an exception (%d)\n",
  511. RpcExceptionCode()));
  512. Status = MapRpcExceptionToCR(RpcExceptionCode());
  513. }
  514. RpcEndExcept
  515. Clean0:
  516. NOTHING;
  517. } except(EXCEPTION_EXECUTE_HANDLER) {
  518. Status = CR_FAILURE;
  519. }
  520. return Status;
  521. } // CM_Get_Hardware_Profile_Info_ExW
  522. CONFIGRET
  523. CM_Set_HW_Prof_Ex(
  524. IN ULONG ulHardwareProfile,
  525. IN ULONG ulFlags,
  526. IN HMACHINE hMachine
  527. )
  528. /*++
  529. Routine Description:
  530. This routine sets the current hardware profile. This API updates the
  531. HKEY_CURRENT_CONFIG predefined key in the registry, broadcasts a
  532. DBT_CONFIGCHANGED message, and reenumerates the root device instance.
  533. It should only be called by the Configuration Manager and the control
  534. panel.
  535. Parameters:
  536. ulHardwareProfile Supplies the current hardware profile handle.
  537. ulFlags Must be zero.
  538. Return Value:
  539. If the function succeeds, the return value is CR_SUCCESS.
  540. If the function fails, the return value is one of the following:
  541. CR_INVALID_FLAG or
  542. CR_REGISTRY_ERROR. (Windows 95 may also return CR_NOT_AT_APPY_TIME.)
  543. --*/
  544. {
  545. CONFIGRET Status = CR_SUCCESS;
  546. handle_t hBinding = NULL;
  547. HANDLE hToken;
  548. ULONG ulPrivilege;
  549. try {
  550. //
  551. // validate parameters
  552. //
  553. if (INVALID_FLAGS(ulFlags, 0)) {
  554. Status = CR_INVALID_FLAG;
  555. goto Clean0;
  556. }
  557. //
  558. // setup rpc binding handle
  559. //
  560. if (!PnPGetGlobalHandles(hMachine, NULL, &hBinding)) {
  561. Status = CR_FAILURE;
  562. goto Clean0;
  563. }
  564. //
  565. // Enable privileges required by the server
  566. //
  567. ulPrivilege = SE_LOAD_DRIVER_PRIVILEGE;
  568. hToken = PnPEnablePrivileges(&ulPrivilege, 1);
  569. RpcTryExcept {
  570. //
  571. // call rpc service entry point
  572. //
  573. Status = PNP_SetHwProf(
  574. hBinding, // rpc machine name
  575. ulHardwareProfile, // hw config id
  576. ulFlags); // currently unused
  577. }
  578. RpcExcept (I_RpcExceptionFilter(RpcExceptionCode())) {
  579. KdPrintEx((DPFLTR_PNPMGR_ID,
  580. DBGF_ERRORS,
  581. "PNP_SetHwProf caused an exception (%d)\n",
  582. RpcExceptionCode()));
  583. Status = MapRpcExceptionToCR(RpcExceptionCode());
  584. }
  585. RpcEndExcept
  586. //
  587. // Restore previous privileges
  588. //
  589. PnPRestorePrivileges(hToken);
  590. Clean0:
  591. NOTHING;
  592. } except(EXCEPTION_EXECUTE_HANDLER) {
  593. Status = CR_FAILURE;
  594. }
  595. return Status;
  596. } // CM_Set_HW_Prof_Ex
  597. //-------------------------------------------------------------------
  598. // ANSI Stubs
  599. //-------------------------------------------------------------------
  600. CONFIGRET
  601. CM_Get_HW_Prof_Flags_ExA(
  602. IN DEVINSTID_A szDevInstName,
  603. IN ULONG ulHardwareProfile,
  604. OUT PULONG pulValue,
  605. IN ULONG ulFlags,
  606. IN HMACHINE hMachine
  607. )
  608. {
  609. CONFIGRET Status = CR_SUCCESS;
  610. PWSTR pUniDeviceID = NULL;
  611. //
  612. // convert devinst string to UNICODE and pass to wide version
  613. //
  614. if (pSetupCaptureAndConvertAnsiArg(szDevInstName, &pUniDeviceID) == NO_ERROR) {
  615. Status = CM_Get_HW_Prof_Flags_ExW(pUniDeviceID,
  616. ulHardwareProfile,
  617. pulValue,
  618. ulFlags,
  619. hMachine);
  620. pSetupFree(pUniDeviceID);
  621. } else {
  622. Status = CR_INVALID_POINTER;
  623. }
  624. return Status;
  625. } // CM_Get_HW_Prof_Flags_ExA
  626. CONFIGRET
  627. CM_Set_HW_Prof_Flags_ExA(
  628. IN DEVINSTID_A szDevInstName,
  629. IN ULONG ulConfig,
  630. IN ULONG ulValue,
  631. IN ULONG ulFlags,
  632. IN HMACHINE hMachine
  633. )
  634. {
  635. CONFIGRET Status = CR_SUCCESS;
  636. PWSTR pUniDeviceID = NULL;
  637. //
  638. // convert devinst string to UNICODE and pass to wide version
  639. //
  640. if (pSetupCaptureAndConvertAnsiArg(szDevInstName, &pUniDeviceID) == NO_ERROR) {
  641. Status = CM_Set_HW_Prof_Flags_ExW(pUniDeviceID,
  642. ulConfig,
  643. ulValue,
  644. ulFlags,
  645. hMachine);
  646. pSetupFree(pUniDeviceID);
  647. } else {
  648. Status = CR_INVALID_POINTER;
  649. }
  650. return Status;
  651. } // CM_Set_HW_Prof_Flags_ExA
  652. CONFIGRET
  653. CM_Get_Hardware_Profile_Info_ExA(
  654. IN ULONG ulIndex,
  655. OUT PHWPROFILEINFO_A pHWProfileInfo,
  656. IN ULONG ulFlags,
  657. IN HMACHINE hMachine
  658. )
  659. {
  660. CONFIGRET Status = CR_SUCCESS;
  661. HWPROFILEINFO_W UniHwProfInfo;
  662. ULONG ulLength;
  663. size_t FriendlyNameLen = 0;
  664. //
  665. // validate essential parameters only
  666. //
  667. if (!ARGUMENT_PRESENT(pHWProfileInfo)) {
  668. return CR_INVALID_POINTER;
  669. }
  670. //
  671. // call the wide version, passing a unicode struct as a parameter
  672. //
  673. Status = CM_Get_Hardware_Profile_Info_ExW(ulIndex,
  674. &UniHwProfInfo,
  675. ulFlags,
  676. hMachine);
  677. //
  678. // a HWPROFILEINFO_W structure should always be large enough.
  679. //
  680. ASSERT(Status != CR_BUFFER_SMALL);
  681. //
  682. // copy the info from the unicode structure to the ansi structure passed in
  683. // by the caller (converting the embedded strings to ansi in the process)
  684. //
  685. if (Status == CR_SUCCESS) {
  686. pHWProfileInfo->HWPI_ulHWProfile = UniHwProfInfo.HWPI_ulHWProfile;
  687. pHWProfileInfo->HWPI_dwFlags = UniHwProfInfo.HWPI_dwFlags;
  688. //
  689. // convert the hardware profile friendly name string to ANSI.
  690. //
  691. if (FAILED(StringCchLength(
  692. (PWSTR)UniHwProfInfo.HWPI_szFriendlyName,
  693. MAX_PROFILE_LEN,
  694. &FriendlyNameLen))) {
  695. return CR_FAILURE;
  696. }
  697. ulLength = MAX_PROFILE_LEN;
  698. Status =
  699. PnPUnicodeToMultiByte(
  700. (PWSTR)UniHwProfInfo.HWPI_szFriendlyName,
  701. (ULONG)((FriendlyNameLen+1)*sizeof(WCHAR)),
  702. pHWProfileInfo->HWPI_szFriendlyName,
  703. &ulLength);
  704. //
  705. // the ANSI representation of a hardware profile friendly name string
  706. // should not be longer than MAX_PROFILE_LEN bytes, because that's the
  707. // max size of the buffer in the structure.
  708. //
  709. ASSERT(Status != CR_BUFFER_SMALL);
  710. }
  711. return Status;
  712. } // CM_Get_Hardware_Profile_Info_ExA
  713. //-------------------------------------------------------------------
  714. // Local Stubs
  715. //-------------------------------------------------------------------
  716. CMAPI
  717. CONFIGRET
  718. WINAPI
  719. CM_Request_Eject_PC (
  720. VOID
  721. )
  722. {
  723. return CM_Request_Eject_PC_Ex (NULL);
  724. }
  725. CMAPI
  726. CONFIGRET
  727. WINAPI
  728. CM_Is_Dock_Station_Present (
  729. OUT PBOOL pbPresent
  730. )
  731. {
  732. return CM_Is_Dock_Station_Present_Ex (pbPresent, NULL);
  733. }
  734. CONFIGRET
  735. CM_Get_HW_Prof_FlagsW(
  736. IN DEVINSTID_W pDeviceID,
  737. IN ULONG ulHardwareProfile,
  738. OUT PULONG pulValue,
  739. IN ULONG ulFlags
  740. )
  741. {
  742. return CM_Get_HW_Prof_Flags_ExW(pDeviceID, ulHardwareProfile,
  743. pulValue, ulFlags, NULL);
  744. }
  745. CONFIGRET
  746. CM_Get_HW_Prof_FlagsA(
  747. IN DEVINSTID_A pDeviceID,
  748. IN ULONG ulHardwareProfile,
  749. OUT PULONG pulValue,
  750. IN ULONG ulFlags
  751. )
  752. {
  753. return CM_Get_HW_Prof_Flags_ExA(pDeviceID, ulHardwareProfile,
  754. pulValue, ulFlags, NULL);
  755. }
  756. CONFIGRET
  757. CM_Set_HW_Prof_FlagsW(
  758. IN DEVINSTID_W pDeviceID,
  759. IN ULONG ulConfig,
  760. IN ULONG ulValue,
  761. IN ULONG ulFlags
  762. )
  763. {
  764. return CM_Set_HW_Prof_Flags_ExW(pDeviceID, ulConfig, ulValue,
  765. ulFlags, NULL);
  766. }
  767. CONFIGRET
  768. CM_Set_HW_Prof_FlagsA(
  769. IN DEVINSTID_A pDeviceID,
  770. IN ULONG ulConfig,
  771. IN ULONG ulValue,
  772. IN ULONG ulFlags
  773. )
  774. {
  775. return CM_Set_HW_Prof_Flags_ExA(pDeviceID, ulConfig, ulValue,
  776. ulFlags, NULL);
  777. }
  778. CONFIGRET
  779. CM_Get_Hardware_Profile_InfoW(
  780. IN ULONG ulIndex,
  781. OUT PHWPROFILEINFO_W pHWProfileInfo,
  782. IN ULONG ulFlags
  783. )
  784. {
  785. return CM_Get_Hardware_Profile_Info_ExW(ulIndex, pHWProfileInfo,
  786. ulFlags, NULL);
  787. }
  788. CONFIGRET
  789. CM_Get_Hardware_Profile_InfoA(
  790. IN ULONG ulIndex,
  791. OUT PHWPROFILEINFO_A pHWProfileInfo,
  792. IN ULONG ulFlags
  793. )
  794. {
  795. return CM_Get_Hardware_Profile_Info_ExA(ulIndex, pHWProfileInfo,
  796. ulFlags, NULL);
  797. }
  798. CONFIGRET
  799. CM_Set_HW_Prof(
  800. IN ULONG ulHardwareProfile,
  801. IN ULONG ulFlags
  802. )
  803. {
  804. return CM_Set_HW_Prof_Ex(ulHardwareProfile, ulFlags, NULL);
  805. }