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.

1304 lines
42 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1997
  4. *
  5. * TITLE: PARSE.C
  6. *
  7. * VERSION: 2.0
  8. *
  9. * AUTHOR: ReedB
  10. *
  11. * DATE: 1 Jan, 1997
  12. *
  13. * DESCRIPTION:
  14. * Helper parsing code for the default power schemes generator, MAKEINI.EXE.
  15. *
  16. *******************************************************************************/
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <windows.h>
  24. #include <ntpoapi.h>
  25. #include "parse.h"
  26. /*******************************************************************************
  27. *
  28. * G L O B A L D A T A
  29. *
  30. *******************************************************************************/
  31. char *g_pszSrc[MAX_SKUS];
  32. char *g_pszLines[MAX_SKUS][MAX_LINES];
  33. UINT g_uiLineCount;
  34. UINT g_uiPoliciesCount[MAX_SKUS];
  35. PMACHINE_POWER_POLICY g_pmpp[MAX_SKUS][MAX_PROFILES];
  36. PUSER_POWER_POLICY g_pupp[MAX_SKUS][MAX_PROFILES];
  37. PMACHINE_PROCESSOR_POWER_POLICY g_ppmpp[MAX_SKUS][MAX_PROFILES];
  38. GLOBAL_USER_POWER_POLICY g_gupp[MAX_SKUS];
  39. GLOBAL_MACHINE_POWER_POLICY g_gmpp[MAX_SKUS];
  40. char *g_pszSkuNames[MAX_SKUS] = {
  41. "..\\DEFAULTS.CSV",
  42. "..\\PER.CSV",
  43. "..\\PRO.CSV",
  44. "..\\SRV.CSV",
  45. "..\\ADS.CSV",
  46. "..\\DTC.CSV"
  47. };
  48. char g_pszSkuDecoration[MAX_SKUS];
  49. /*******************************************************************************
  50. *
  51. * StrTrimTrailingBlanks
  52. *
  53. * DESCRIPTION:
  54. *
  55. * PARAMETERS:
  56. *
  57. *******************************************************************************/
  58. void StrTrimTrailingBlanks(char *psz)
  59. {
  60. UINT i = 0;
  61. if (psz) {
  62. while (*psz) {
  63. psz++;
  64. }
  65. while (*--psz == ' ') {
  66. *psz = '\0';
  67. }
  68. }
  69. }
  70. /*******************************************************************************
  71. *
  72. * StrToUpper
  73. *
  74. * DESCRIPTION:
  75. *
  76. * PARAMETERS:
  77. *
  78. *******************************************************************************/
  79. void StrToUpper(char *pszDest, char *pszSrc)
  80. {
  81. UINT i = 0;
  82. while (*pszSrc) {
  83. *pszDest = (char)toupper(*pszSrc);
  84. pszSrc++;
  85. pszDest++;
  86. if (++i == MAX_STR) {
  87. DefFatalExit(FALSE, "StrToUpper failure, source too large: %s\n", pszSrc);
  88. }
  89. }
  90. *pszDest = '\0';
  91. }
  92. /*******************************************************************************
  93. *
  94. * GetTokens
  95. *
  96. * DESCRIPTION:
  97. * Fill an array with tokens.
  98. *
  99. * PARAMETERS:
  100. *
  101. *******************************************************************************/
  102. UINT GetTokens(
  103. char *pszSrc,
  104. UINT uiMaxTokenSize,
  105. char **pszTokens,
  106. UINT uiMaxTokens,
  107. char *pszDelimiters
  108. )
  109. {
  110. char *psz;
  111. DWORD dwSize;
  112. UINT i = 0;
  113. psz = strtok(pszSrc, pszDelimiters);
  114. StrTrimTrailingBlanks(psz);
  115. while (psz) {
  116. if (i % 2) {
  117. printf(".");
  118. }
  119. dwSize = strlen(psz) + 1;
  120. if (dwSize > uiMaxTokenSize) {
  121. printf("GetTokens, Token to large: %s\n", psz);
  122. return 0;
  123. }
  124. if ((pszTokens[i] = (char *) malloc(dwSize)) != NULL) {
  125. strcpy(pszTokens[i], psz);
  126. }
  127. else {
  128. printf("GetTokens, Unable to allocate token buffer: %s\n", psz);
  129. return 0;
  130. }
  131. i++;
  132. if (i == uiMaxTokens) {
  133. printf("GetTokens, Too many tokens: %d\n", i);
  134. return 0;
  135. }
  136. psz = strtok(NULL, pszDelimiters);
  137. StrTrimTrailingBlanks(psz);
  138. }
  139. return i;
  140. }
  141. /*******************************************************************************
  142. *
  143. * GetCheckLabelToken
  144. *
  145. * DESCRIPTION:
  146. * Consume a label token. Check to be sure it matches the passed parameter.
  147. * Call fatal exit if it doesn't. Labels are always comma delimited. Sets up
  148. * strtok for subsequent calls.
  149. *
  150. * PARAMETERS:
  151. * uiLine - One based line index.
  152. *
  153. *******************************************************************************/
  154. VOID GetCheckLabelToken(UINT uiLine, char *pszCheck, UINT uiSku)
  155. {
  156. char szUpperCheck[MAX_STR];
  157. static char szUpperTok[MAX_STR] = "No last token";
  158. char *pszTok;
  159. pszTok = strtok(g_pszLines[uiSku][uiLine - 1], DELIMITERS);
  160. StrTrimTrailingBlanks(pszTok);
  161. if (!pszTok) {
  162. DefFatalExit(FALSE, "GetStringTokens failure, out of tokens. Last token: %s\n", szUpperTok);
  163. }
  164. StrToUpper(szUpperTok, pszTok);
  165. StrToUpper(szUpperCheck, pszCheck);
  166. if (strcmp(szUpperCheck, szUpperTok)) {
  167. DefFatalExit(FALSE, "GetStringTokens failure, check: %s doesn't match: %s\n",szUpperCheck, szUpperTok);
  168. }
  169. }
  170. /*******************************************************************************
  171. *
  172. * GetPowerActionToken
  173. *
  174. * DESCRIPTION:
  175. * Consume a token and return a power action.
  176. *
  177. * PARAMETERS:
  178. *
  179. *******************************************************************************/
  180. POWER_ACTION GetPowerActionToken(VOID)
  181. {
  182. static char szUpperTok[MAX_STR] = "No last token";
  183. char *pszTok;
  184. pszTok = strtok(NULL, DELIMITERS);
  185. StrTrimTrailingBlanks(pszTok);
  186. if (!pszTok) {
  187. DefFatalExit(FALSE,"GetPowerActionToken failure, out of tokens. Last token: %s\n", szUpperTok);
  188. }
  189. StrToUpper(szUpperTok, pszTok);
  190. if (!strcmp(szUpperTok, "NONE")) {
  191. return PowerActionNone;
  192. }
  193. if (!strcmp(szUpperTok, "DOZE")) {
  194. return PowerActionReserved;
  195. }
  196. if (!strcmp(szUpperTok, "SLEEP")) {
  197. return PowerActionSleep;
  198. }
  199. if (!strcmp(szUpperTok, "HIBERNATE")) {
  200. return PowerActionHibernate;
  201. }
  202. if (!strcmp(szUpperTok, "SHUTDOWN")) {
  203. return PowerActionShutdown;
  204. }
  205. if (!strcmp(szUpperTok, "SHUTDOWNRESET")) {
  206. return PowerActionShutdownReset;
  207. }
  208. if (!strcmp(szUpperTok, "SHUTDOWNOFF")) {
  209. return PowerActionShutdownOff;
  210. }
  211. DefFatalExit(FALSE,"GetPowerActionToken failure, check: %s doesn't match: \nNONE, DOZE, SLEEP, SHUTDOWN, SHUTDOWNRESET or SHUTDOWNOFF\n", szUpperTok);
  212. return 0;
  213. }
  214. /*******************************************************************************
  215. *
  216. * GetFlagToken
  217. *
  218. * DESCRIPTION:
  219. * Consume a token and return a flag value.
  220. *
  221. * PARAMETERS:
  222. *
  223. *******************************************************************************/
  224. UINT GetFlagToken(UINT uiFlag)
  225. {
  226. static char szUpperTok[MAX_STR] = "No last token";
  227. char *pszTok;
  228. pszTok = strtok(NULL, DELIMITERS);
  229. StrTrimTrailingBlanks(pszTok);
  230. if (!pszTok) {
  231. DefFatalExit(FALSE, "GetFlagToken failure, out of tokens. Last token: %s\n", szUpperTok);
  232. }
  233. StrToUpper(szUpperTok, pszTok);
  234. if (!strcmp(szUpperTok, "YES")) {
  235. return uiFlag;
  236. }
  237. if (!strcmp(szUpperTok, "TRUE")) {
  238. return uiFlag;
  239. }
  240. if (!strcmp(szUpperTok, "FALSE")) {
  241. return 0;
  242. }
  243. if (!strcmp(szUpperTok, "NO")) {
  244. return 0;
  245. }
  246. if (!strcmp(szUpperTok, "N/A")) {
  247. return 0;
  248. }
  249. DefFatalExit(FALSE, "GetFlagToken failure, check: %s doesn't match: YES, NO or N/A\n", szUpperTok);
  250. return 0;
  251. }
  252. /*******************************************************************************
  253. *
  254. * GetPowerStateToken
  255. *
  256. * DESCRIPTION:
  257. * Consume a token and return a power state.
  258. *
  259. * PARAMETERS:
  260. *
  261. *******************************************************************************/
  262. UINT GetPowerStateToken(VOID)
  263. {
  264. static char szUpperTok[MAX_STR] = "No last token";
  265. char *pszTok;
  266. pszTok = strtok(NULL, DELIMITERS);
  267. StrTrimTrailingBlanks(pszTok);
  268. if (!pszTok) {
  269. DefFatalExit(FALSE,"GetPowerStateToken failure, out of tokens. Last token: %s\n", szUpperTok);
  270. }
  271. StrToUpper(szUpperTok, pszTok);
  272. if (!strcmp(szUpperTok, "S0")) {
  273. return PowerSystemWorking;
  274. }
  275. if (!strcmp(szUpperTok, "S1")) {
  276. return PowerSystemSleeping1;
  277. }
  278. if (!strcmp(szUpperTok, "S2")) {
  279. return PowerSystemSleeping2;
  280. }
  281. if (!strcmp(szUpperTok, "S3")) {
  282. return PowerSystemSleeping3;
  283. }
  284. if (!strcmp(szUpperTok, "S4")) {
  285. return PowerSystemHibernate;
  286. }
  287. if (!strcmp(szUpperTok, "S5")) {
  288. return PowerSystemShutdown;
  289. }
  290. if (!strcmp(szUpperTok, "N/A")) {
  291. return PowerSystemUnspecified;
  292. }
  293. DefFatalExit(FALSE,"GetPowerStateToken failure, check: %s doesn't match: S0, S1, S2, S3, S4 or S5\n", szUpperTok);
  294. return PowerSystemUnspecified;
  295. }
  296. /*******************************************************************************
  297. *
  298. * GetINFTypeToken
  299. *
  300. * DESCRIPTION:
  301. * Consume a token and return an INF type.
  302. *
  303. * PARAMETERS:
  304. *
  305. *******************************************************************************/
  306. UINT GetINFTypeToken(VOID)
  307. {
  308. static char szUpperTok[MAX_STR] = "No last token";
  309. char *pszTok;
  310. UINT uiRet = 0;
  311. pszTok = strtok(NULL, DELIMITERS);
  312. StrTrimTrailingBlanks(pszTok);
  313. if (!pszTok) {
  314. DefFatalExit(FALSE,"GetINFTypeToken failure, out of tokens. Last token: %s\n", szUpperTok);
  315. }
  316. StrToUpper(szUpperTok, pszTok);
  317. if (strstr(szUpperTok, "TYPICALINSTALL")) {
  318. uiRet |= TYPICAL;
  319. }
  320. if (strstr(szUpperTok, "COMPACTINSTALL")) {
  321. uiRet |= COMPACT;
  322. }
  323. if (strstr(szUpperTok, "CUSTOMINSTALL")) {
  324. uiRet |= CUSTOM;
  325. }
  326. if (strstr(szUpperTok, "PORTABLEINSTALL")) {
  327. uiRet |= PORTABLE;
  328. }
  329. if (strstr(szUpperTok, "SERVERINSTALL")) {
  330. uiRet |= SERVER;
  331. }
  332. if (!uiRet) {
  333. DefFatalExit(FALSE,"GetINFTypeToken failure, check: %s doesn't match install file type\n", szUpperTok);
  334. }
  335. return uiRet;
  336. }
  337. /*******************************************************************************
  338. *
  339. * GetOSTypeToken
  340. *
  341. * DESCRIPTION:
  342. * Consume a token and return an OS type.
  343. *
  344. * PARAMETERS:
  345. *
  346. *******************************************************************************/
  347. UINT GetOSTypeToken(VOID)
  348. {
  349. static char szUpperTok[MAX_STR] = "No last token";
  350. char *pszTok;
  351. UINT uiRet = 0;
  352. pszTok = strtok(NULL, DELIMITERS);
  353. StrTrimTrailingBlanks(pszTok);
  354. if (!pszTok) {
  355. DefFatalExit(FALSE,"GetOSTypeToken failure, out of tokens. Last token: %s\n", szUpperTok);
  356. }
  357. StrToUpper(szUpperTok, pszTok);
  358. if (strstr(szUpperTok, "WIN95")) {
  359. uiRet |= WIN_95;
  360. }
  361. if (strstr(szUpperTok, "NT")) {
  362. uiRet |= WIN_NT;
  363. }
  364. if (!uiRet) {
  365. DefFatalExit(FALSE,"GetOSTypeToken failure, check: %s doesn't match: WINNT, WIN95\n", szUpperTok);
  366. }
  367. return uiRet;
  368. }
  369. /*******************************************************************************
  370. *
  371. * GetIntToken
  372. *
  373. * DESCRIPTION:
  374. * Consume a token and return an integer. Verify the units if passed.
  375. *
  376. * PARAMETERS:
  377. *
  378. *******************************************************************************/
  379. UINT GetIntToken(char *pszUnits)
  380. {
  381. char szUpperUnits[MAX_STR];
  382. static char szUpperTok[MAX_STR] = "No last token";
  383. char *pszTok;
  384. UINT i, uiMult = 1;
  385. pszTok = strtok(NULL, DELIMITERS);
  386. StrTrimTrailingBlanks(pszTok);
  387. if (!pszTok) {
  388. DefFatalExit(FALSE,"GetIntToken failure, out of tokens. Last token: %s\n", szUpperTok);
  389. }
  390. StrToUpper(szUpperTok, pszTok);
  391. if (!strcmp(szUpperTok, "N/A")) {
  392. return 0;
  393. }
  394. if (!strcmp(szUpperTok, "DISABLED")) {
  395. return 0;
  396. }
  397. if (pszUnits) {
  398. StrToUpper(szUpperUnits, pszUnits);
  399. if (!strcmp(szUpperUnits, "%")) {
  400. // Percentages are a special case. Excel sometimes saves
  401. // 50% as 0.5.
  402. if ((pszUnits = strstr(szUpperTok, szUpperUnits)) != NULL) {
  403. // Strip off units.
  404. *pszUnits = '\0';
  405. if (sscanf(szUpperTok, "%d", &i) == 1) {
  406. return i;
  407. }
  408. }
  409. if (*szUpperTok == '1') {
  410. return 100;
  411. }
  412. while ((*pszTok == '0') &&
  413. (*(pszTok + 1) == '.')) {
  414. pszTok += 2;
  415. }
  416. // Get the first digit after the decimal.
  417. i = *pszTok++ - '0';
  418. i *= 10;
  419. // if there is a second digit, get that, too.
  420. if ((*pszTok >= '0') && (*pszTok <= '9')) {
  421. i = i + (*pszTok - '0');
  422. }
  423. return i;
  424. } else {
  425. if ((pszUnits = strstr(szUpperTok, szUpperUnits)) == NULL) {
  426. DefFatalExit(FALSE, "GetIntToken failure, units: %s doesn't match: %s\n", szUpperTok, szUpperUnits);
  427. }
  428. if (!strcmp(szUpperUnits, "MIN")) {
  429. uiMult = 60;
  430. } else if (!strcmp(szUpperUnits, "US")) {
  431. uiMult = 1;
  432. } else {
  433. DefFatalExit(FALSE, "GetIntToken failure, unknown units: %s\n", szUpperUnits);
  434. }
  435. // Strip off units.
  436. *pszUnits = '\0';
  437. if (sscanf(szUpperTok, "%d", &i) == 1) {
  438. return i * uiMult;
  439. }
  440. }
  441. }
  442. DefFatalExit(FALSE,"GetIntToken failure, error converting: %s to integer\n", szUpperTok);
  443. return 0;
  444. }
  445. /*******************************************************************************
  446. *
  447. * GetNAToken
  448. *
  449. * DESCRIPTION:
  450. * Consume a N/A token.
  451. *
  452. * PARAMETERS:
  453. *
  454. *******************************************************************************/
  455. VOID GetNAToken(VOID)
  456. {
  457. static char szUpperTok[MAX_STR] = "No last token";
  458. char *pszTok;
  459. pszTok = strtok(NULL, DELIMITERS);
  460. StrTrimTrailingBlanks(pszTok);
  461. if (!pszTok) {
  462. DefFatalExit(FALSE, "GetNAToken failure, out of tokens. Last token: %s\n", szUpperTok);
  463. }
  464. StrToUpper(szUpperTok, pszTok);
  465. if (!strcmp(szUpperTok, "N/A")) {
  466. return;
  467. }
  468. DefFatalExit(FALSE, "GetNAToken failure, check: %s doesn't match: N/A\n", szUpperTok);
  469. }
  470. /*******************************************************************************
  471. *
  472. * GetThrottleToken
  473. *
  474. * DESCRIPTION:
  475. * Consume a N/A token.
  476. *
  477. * PARAMETERS:
  478. *
  479. *******************************************************************************/
  480. UINT GetThrottleToken(VOID)
  481. {
  482. static char szUpperTok[MAX_STR] = "No last token";
  483. char *pszTok;
  484. pszTok = strtok(NULL, DELIMITERS);
  485. StrTrimTrailingBlanks(pszTok);
  486. if (!pszTok) {
  487. DefFatalExit(FALSE, "GetNAToken failure, out of tokens. Last token: %s\n", szUpperTok);
  488. }
  489. StrToUpper(szUpperTok, pszTok);
  490. if (!strcmp(szUpperTok, "NONE")) {
  491. return PO_THROTTLE_NONE;
  492. }
  493. if (!strcmp(szUpperTok, "CONSTANT")) {
  494. return PO_THROTTLE_CONSTANT;
  495. }
  496. if (!strcmp(szUpperTok, "DEGRADE")) {
  497. return PO_THROTTLE_DEGRADE;
  498. }
  499. if (!strcmp(szUpperTok, "ADAPTIVE")) {
  500. return PO_THROTTLE_ADAPTIVE;
  501. }
  502. DefFatalExit(FALSE, "GetThrottleToken failure, check: %s doesn't match.\n", szUpperTok);
  503. return PO_THROTTLE_NONE;
  504. }
  505. /*******************************************************************************
  506. *
  507. * DefFatalExit
  508. *
  509. * DESCRIPTION:
  510. * Print error and exit.
  511. *
  512. * PARAMETERS:
  513. *
  514. *******************************************************************************/
  515. VOID CDECL DefFatalExit(BOOLEAN bGetLastError, char *pszFormat, ... )
  516. {
  517. va_list Marker;
  518. va_start(Marker, pszFormat);
  519. printf("\n\n");
  520. vprintf(pszFormat, Marker);
  521. if (bGetLastError) {
  522. printf("Last error: %d\n", GetLastError());
  523. }
  524. printf("\n\nDefault Processing Failure. Output files are invalid.\n");
  525. exit(1);
  526. }
  527. /*******************************************************************************
  528. *
  529. * ReadSource
  530. *
  531. * DESCRIPTION:
  532. *
  533. * PARAMETERS:
  534. *
  535. *******************************************************************************/
  536. BOOLEAN ReadSource(void)
  537. {
  538. HANDLE fh;
  539. DWORD dwSize, dwRead, sku;
  540. BOOLEAN bRet;
  541. for (sku = 0; sku < MAX_SKUS; sku++) {
  542. bRet = FALSE;
  543. fh = CreateFile(g_pszSkuNames[sku], GENERIC_READ,
  544. FILE_SHARE_READ|FILE_SHARE_WRITE,
  545. NULL, OPEN_EXISTING, 0, NULL);
  546. if (fh != INVALID_HANDLE_VALUE) {
  547. // Allocate the source buffer.
  548. if ((dwSize = GetFileSize(fh, NULL)) != INVALID_FILE_SIZE) {
  549. if ((g_pszSrc[sku] = (char *) malloc(dwSize + 1)) != NULL) {
  550. // Read in the file buffer.
  551. SetFilePointer(fh, 0, NULL, FILE_BEGIN);
  552. if (ReadFile(fh, g_pszSrc[sku], dwSize, &dwRead, NULL)) {
  553. printf("ReadSource successful.\n");
  554. g_pszSrc[sku][dwSize] = 0;
  555. bRet = TRUE;
  556. }
  557. }
  558. }
  559. CloseHandle(fh);
  560. }
  561. if (!bRet) {
  562. DefFatalExit(TRUE, "ReadSource failed reading: %s\n", g_pszSkuNames[sku]);
  563. }
  564. }
  565. return bRet;
  566. }
  567. /*******************************************************************************
  568. *
  569. * BuildLineArray
  570. *
  571. * DESCRIPTION:
  572. *
  573. * PARAMETERS:
  574. *
  575. *******************************************************************************/
  576. UINT BuildLineArray(void)
  577. {
  578. char *psz;
  579. UINT sku, lineCount;
  580. for (sku = 0; sku < MAX_SKUS; sku++) {
  581. printf("\nBuilding the line array.");
  582. lineCount = GetTokens(g_pszSrc[sku], MAX_LINE_SIZE,
  583. g_pszLines[sku], MAX_LINES, LINE_DELIMITERS);
  584. printf("\nFound %d lines in file %s.\n\n", lineCount, g_pszSrc[sku]);
  585. }
  586. return lineCount;
  587. }
  588. /*******************************************************************************
  589. *
  590. * GetSleepActionFlags
  591. *
  592. * DESCRIPTION:
  593. *
  594. * PARAMETERS:
  595. *
  596. *******************************************************************************/
  597. VOID GetSleepActionFlags(
  598. UINT uiStartLine,
  599. UINT uiFlagsAC[],
  600. UINT uiFlagsDC[],
  601. PUINT puiCount,
  602. UINT sku
  603. )
  604. {
  605. UINT i;
  606. for (i = 0; i < *puiCount; i++) {
  607. uiFlagsAC[i] = 0;
  608. uiFlagsDC[i] = 0;
  609. }
  610. GetCheckLabelToken(uiStartLine, "Sleep action flags", sku);
  611. GetCheckLabelToken(uiStartLine+QUERY_APPS, "Query apps", sku);
  612. for (i = 0; i < *puiCount; i++) {
  613. uiFlagsAC[i] += GetFlagToken(POWER_ACTION_QUERY_ALLOWED);
  614. uiFlagsDC[i] += GetFlagToken(POWER_ACTION_QUERY_ALLOWED);
  615. }
  616. GetCheckLabelToken(uiStartLine+ALLOW_UI, "Allow UI", sku);
  617. for (i = 0; i < *puiCount; i++) {
  618. uiFlagsAC[i] += GetFlagToken(POWER_ACTION_UI_ALLOWED);
  619. uiFlagsDC[i] += GetFlagToken(POWER_ACTION_UI_ALLOWED);
  620. }
  621. GetCheckLabelToken(uiStartLine+IGNORE_NON_RESP, "Ignore non-responsive apps", sku);
  622. for (i = 0; i < *puiCount; i++) {
  623. uiFlagsAC[i] += GetFlagToken(POWER_ACTION_OVERRIDE_APPS);
  624. uiFlagsDC[i] += GetFlagToken(POWER_ACTION_OVERRIDE_APPS);
  625. }
  626. GetCheckLabelToken(uiStartLine+IGNORE_WAKE, "Ignore wakeup events", sku);
  627. for (i = 0; i < *puiCount; i++) {
  628. uiFlagsAC[i] += GetFlagToken(POWER_ACTION_DISABLE_WAKES);
  629. uiFlagsDC[i] += GetFlagToken(POWER_ACTION_DISABLE_WAKES);
  630. }
  631. GetCheckLabelToken(uiStartLine+IGNORE_CRITICAL, "Critical (go to sleep immediately)", sku);
  632. for (i = 0; i < *puiCount; i++) {
  633. uiFlagsAC[i] += GetFlagToken(POWER_ACTION_CRITICAL);
  634. uiFlagsDC[i] += GetFlagToken(POWER_ACTION_CRITICAL);
  635. }
  636. }
  637. /*******************************************************************************
  638. *
  639. * GetSleepActionFlagsGlobal
  640. *
  641. * DESCRIPTION:
  642. *
  643. * PARAMETERS:
  644. *
  645. *******************************************************************************/
  646. VOID GetSleepActionFlagsGlobal(
  647. UINT uiStartLine,
  648. PPOWER_ACTION_POLICY ppapAC,
  649. PPOWER_ACTION_POLICY ppapDC,
  650. UINT sku
  651. )
  652. {
  653. UINT uiOne = 1;
  654. UINT uiFlagsAC[MAX_PROFILES];
  655. UINT uiFlagsDC[MAX_PROFILES];
  656. GetSleepActionFlags(uiStartLine, uiFlagsAC, uiFlagsDC, &uiOne, sku);
  657. if (ppapAC) {
  658. ppapAC->Flags = uiFlagsAC[0];
  659. }
  660. ppapDC->Flags = uiFlagsDC[0];
  661. }
  662. /*******************************************************************************
  663. *
  664. * GetSleepActionFlagsPolicy
  665. *
  666. * DESCRIPTION:
  667. *
  668. * PARAMETERS:
  669. *
  670. *******************************************************************************/
  671. VOID GetSleepActionFlagsUserPolicy(
  672. UINT uiStartLine,
  673. ULONG ulAcPowerPolicyOffset,
  674. ULONG ulDcPowerPolicyOffset,
  675. PUINT puiCount,
  676. UINT sku
  677. )
  678. {
  679. UINT i;
  680. UINT uiFlagsAC[MAX_PROFILES];
  681. UINT uiFlagsDC[MAX_PROFILES];
  682. PPOWER_ACTION_POLICY ppap;
  683. GetSleepActionFlags(uiStartLine, uiFlagsAC, uiFlagsDC, puiCount, sku);
  684. for (i = 0; i < *puiCount; i++) {
  685. ppap = (PPOWER_ACTION_POLICY)((BYTE*)(g_pupp[sku][i]) + ulAcPowerPolicyOffset);
  686. ppap->Flags = uiFlagsAC[i];
  687. ppap = (PPOWER_ACTION_POLICY)((BYTE*)(g_pupp[sku][i]) + ulDcPowerPolicyOffset);
  688. ppap->Flags = uiFlagsDC[i];
  689. }
  690. }
  691. /*******************************************************************************
  692. *
  693. * GetSleepActionFlagsMachinePolicy
  694. *
  695. * DESCRIPTION:
  696. *
  697. * PARAMETERS:
  698. *
  699. *******************************************************************************/
  700. VOID GetSleepActionFlagsMachinePolicy(
  701. UINT uiStartLine,
  702. ULONG ulAcPowerPolicyOffset,
  703. ULONG ulDcPowerPolicyOffset,
  704. PUINT puiCount,
  705. UINT sku
  706. )
  707. {
  708. UINT i;
  709. UINT uiFlagsAC[MAX_PROFILES];
  710. UINT uiFlagsDC[MAX_PROFILES];
  711. PPOWER_ACTION_POLICY ppap;
  712. GetSleepActionFlags(uiStartLine, uiFlagsAC, uiFlagsDC, puiCount, sku);
  713. for (i = 0; i < *puiCount; i++) {
  714. ppap = (PPOWER_ACTION_POLICY)((BYTE*)(g_pmpp[sku][i]) + ulAcPowerPolicyOffset);
  715. ppap->Flags = uiFlagsAC[i];
  716. ppap = (PPOWER_ACTION_POLICY)((BYTE*)(g_pmpp[sku][i]) + ulDcPowerPolicyOffset);
  717. ppap->Flags = uiFlagsDC[i];
  718. }
  719. }
  720. VOID GetEventCodes(
  721. UINT uiStartLine,
  722. PPOWER_ACTION_POLICY ppapAC,
  723. PPOWER_ACTION_POLICY ppapDC,
  724. UINT flagToken,
  725. UINT sku
  726. )
  727. {
  728. UINT i;
  729. GetCheckLabelToken(uiStartLine, "Event Code", sku);
  730. GetCheckLabelToken(uiStartLine+NOTIFY_USER_CODE, "Notify User", sku);
  731. ppapAC->EventCode += GetFlagToken(flagToken);
  732. ppapDC->EventCode += GetFlagToken(flagToken);
  733. }
  734. /*******************************************************************************
  735. *
  736. * GetCStateThresholds
  737. *
  738. * DESCRIPTION:
  739. *
  740. * PARAMETERS:
  741. *
  742. *******************************************************************************/
  743. VOID GetCStateThresholds(
  744. UINT uiStartLine,
  745. UINT uiCState,
  746. PUINT puiCount,
  747. UINT sku
  748. )
  749. {
  750. UINT i;
  751. uiCState -= 1;
  752. for (i = 0; i < *puiCount; i++) {
  753. g_ppmpp[sku][i]->ProcessorPolicyAc.PolicyCount = 3;
  754. g_ppmpp[sku][i]->ProcessorPolicyDc.PolicyCount = 3;
  755. }
  756. GetCheckLabelToken(uiStartLine+C_TIME_CHECK, "Time Check", sku);
  757. for (i = 0; i < *puiCount; i++) {
  758. g_ppmpp[sku][i]->ProcessorPolicyAc.Policy[uiCState].TimeCheck = GetIntToken("us");
  759. g_ppmpp[sku][i]->ProcessorPolicyDc.Policy[uiCState].TimeCheck = GetIntToken("us");
  760. }
  761. GetCheckLabelToken(uiStartLine+C_PROMOTE_LIMIT, "Promote Limit", sku);
  762. for (i = 0; i < *puiCount; i++) {
  763. g_ppmpp[sku][i]->ProcessorPolicyAc.Policy[uiCState].PromoteLimit = GetIntToken("us");
  764. g_ppmpp[sku][i]->ProcessorPolicyDc.Policy[uiCState].PromoteLimit = GetIntToken("us");
  765. }
  766. GetCheckLabelToken(uiStartLine+C_DEMOTE_LIMIT, "Demote Limit", sku);
  767. for (i = 0; i < *puiCount; i++) {
  768. g_ppmpp[sku][i]->ProcessorPolicyAc.Policy[uiCState].DemoteLimit = GetIntToken("us");
  769. g_ppmpp[sku][i]->ProcessorPolicyDc.Policy[uiCState].DemoteLimit = GetIntToken("us");
  770. }
  771. GetCheckLabelToken(uiStartLine+C_PROMOTE_PERCENT, "Promote Percent", sku);
  772. for (i = 0; i < *puiCount; i++) {
  773. g_ppmpp[sku][i]->ProcessorPolicyAc.Policy[uiCState].PromotePercent = (UCHAR)GetIntToken("%");
  774. g_ppmpp[sku][i]->ProcessorPolicyDc.Policy[uiCState].PromotePercent = (UCHAR)GetIntToken("%");
  775. }
  776. GetCheckLabelToken(uiStartLine+C_DEMOTE_PERCENT, "Demote Percent", sku);
  777. for (i = 0; i < *puiCount; i++) {
  778. g_ppmpp[sku][i]->ProcessorPolicyAc.Policy[uiCState].DemotePercent = (UCHAR)GetIntToken("%");
  779. g_ppmpp[sku][i]->ProcessorPolicyDc.Policy[uiCState].DemotePercent = (UCHAR)GetIntToken("%");
  780. }
  781. GetCheckLabelToken(uiStartLine+C_ALLOW_PROMOTION, "Allow Promotion", sku);
  782. for (i = 0; i < *puiCount; i++) {
  783. g_ppmpp[sku][i]->ProcessorPolicyAc.Policy[uiCState].Reserved = 0;
  784. g_ppmpp[sku][i]->ProcessorPolicyAc.Policy[uiCState].AllowPromotion = GetFlagToken(TRUE);
  785. g_ppmpp[sku][i]->ProcessorPolicyDc.Policy[uiCState].AllowPromotion = GetFlagToken(TRUE);
  786. }
  787. GetCheckLabelToken(uiStartLine+C_ALLOW_DEMOTION, "Allow Demotion", sku);
  788. for (i = 0; i < *puiCount; i++) {
  789. g_ppmpp[sku][i]->ProcessorPolicyAc.Policy[uiCState].AllowDemotion = GetFlagToken(TRUE);
  790. g_ppmpp[sku][i]->ProcessorPolicyDc.Policy[uiCState].AllowDemotion = GetFlagToken(TRUE);
  791. }
  792. }
  793. /*******************************************************************************
  794. *
  795. * GetDischargePolicies
  796. *
  797. * DESCRIPTION:
  798. *
  799. * PARAMETERS:
  800. *
  801. *******************************************************************************/
  802. VOID GetDischargePolicies(
  803. UINT uiLine,
  804. UINT uiNum,
  805. UINT uiIndex,
  806. UINT sku
  807. )
  808. {
  809. UINT i, uiOne = 1;
  810. char szLabel[] = "Discharge Policy 1";
  811. sprintf(szLabel, "Discharge Policy %d", uiNum);
  812. GetCheckLabelToken(uiLine, szLabel, sku);
  813. GetCheckLabelToken(uiLine+DP_ENABLE, "Enable", sku);
  814. GetNAToken();
  815. g_gupp[sku].DischargePolicy[uiIndex].Enable = (BOOLEAN)GetFlagToken(TRUE);
  816. GetCheckLabelToken(uiLine+DP_BAT_LEVEL, "Battery Level", sku);
  817. GetNAToken();
  818. g_gupp[sku].DischargePolicy[uiIndex].BatteryLevel = GetIntToken("%");
  819. GetCheckLabelToken(uiLine + DP_POWER_POLICY, "Power Policy", sku);
  820. GetNAToken();
  821. g_gupp[sku].DischargePolicy[uiIndex].PowerPolicy.Action = GetPowerActionToken();
  822. GetCheckLabelToken(uiLine + DP_MIN_SLEEP_STATE, "Min system sleep state", sku);
  823. GetNAToken();
  824. g_gupp[sku].DischargePolicy[uiIndex].MinSystemState = GetPowerStateToken();
  825. GetCheckLabelToken(uiLine + DP_TEXT_NOTIFY, "Text Notify", sku);
  826. GetNAToken();
  827. g_gupp[sku].DischargePolicy[uiIndex].PowerPolicy.EventCode =
  828. GetFlagToken(POWER_LEVEL_USER_NOTIFY_TEXT);
  829. GetCheckLabelToken(uiLine+DP_SOUND_NOTIFY, "Sound Notify", sku);
  830. GetNAToken();
  831. g_gupp[sku].DischargePolicy[uiIndex].PowerPolicy.EventCode |=
  832. GetFlagToken(POWER_LEVEL_USER_NOTIFY_SOUND);
  833. GetSleepActionFlagsGlobal(uiLine + DP_SLEEP_ACT_FLAGS, NULL,
  834. &(g_gupp[sku].DischargePolicy[uiIndex].PowerPolicy), sku);
  835. printf(" Parsed %s\n", szLabel);
  836. }
  837. /*******************************************************************************
  838. *
  839. * GetGlobalPolicies
  840. *
  841. * DESCRIPTION:
  842. * Parse the global policies into the USER: and HKEY_LOCAL_MACHINE global
  843. * power policies structures.
  844. *
  845. * PARAMETERS:
  846. *
  847. *******************************************************************************/
  848. BOOLEAN GetGlobalPolicies(void)
  849. {
  850. UINT i, uiOne = 1, sku;
  851. for (sku = 0; sku < MAX_SKUS; sku++) {
  852. printf("Parsing global power policies\n");
  853. // Set both User and Local Machine revision levels
  854. g_gupp[sku].Revision = DATA_REV;
  855. g_gmpp[sku].Revision = DATA_REV;
  856. //**********************************************************************
  857. // Advanced
  858. //**********************************************************************
  859. GetCheckLabelToken(ADVANCED_LINE, "Advanced", sku);
  860. GetCheckLabelToken(LOCK_ON_SLEEP_LINE, "Lock Workstation", sku);
  861. g_gupp[sku].GlobalFlags = GetFlagToken(EnablePasswordLogon);
  862. if (g_gupp[sku].GlobalFlags != GetFlagToken(EnablePasswordLogon)) {
  863. DefFatalExit(FALSE,"AC and DC Lock Workstation entries don't match");
  864. }
  865. GetCheckLabelToken(WAKE_ON_RING_LINE, "Wake on Ring", sku);
  866. g_gupp[sku].GlobalFlags |= GetFlagToken(EnableWakeOnRing);
  867. if ((g_gupp[sku].GlobalFlags & EnableWakeOnRing) !=
  868. GetFlagToken(EnableWakeOnRing)) {
  869. DefFatalExit(FALSE,"AC and DC Wake on Ring entries don't match");
  870. }
  871. GetCheckLabelToken(VIDEO_DIM_DISPLAY_LINE, "Video Dim Display on DC", sku);
  872. GetFlagToken(0);
  873. g_gupp[sku].GlobalFlags |= GetFlagToken(EnableVideoDimDisplay);
  874. //**********************************************************************
  875. // Power button
  876. //**********************************************************************
  877. GetCheckLabelToken(POWER_BUTTON_LINE, "Power button", sku);
  878. g_gupp[sku].PowerButtonAc.Action = GetPowerActionToken();
  879. g_gupp[sku].PowerButtonDc.Action = GetPowerActionToken();
  880. GetSleepActionFlagsGlobal(POWER_BUTTON_SLEEP_ACTION_FLAGS_LINE,
  881. &(g_gupp[sku].PowerButtonAc),
  882. &(g_gupp[sku].PowerButtonDc),
  883. sku);
  884. GetEventCodes(POWER_BUTTON_SLEEP_EVENT_CODE_LINE,
  885. &(g_gupp[sku].PowerButtonAc),
  886. &(g_gupp[sku].PowerButtonDc),
  887. POWER_USER_NOTIFY_BUTTON,
  888. sku);
  889. printf(" Parsed Power Button Policies\n");
  890. //**********************************************************************
  891. // Sleep button
  892. //**********************************************************************
  893. GetCheckLabelToken(SLEEP_BUTTON_LINE, "Sleep button", sku);
  894. g_gupp[sku].SleepButtonAc.Action = GetPowerActionToken();
  895. g_gupp[sku].SleepButtonDc.Action = GetPowerActionToken();
  896. GetSleepActionFlagsGlobal(SLEEP_BUTTON_SLEEP_ACTION_FLAGS_LINE,
  897. &(g_gupp[sku].SleepButtonAc),
  898. &(g_gupp[sku].SleepButtonDc),
  899. sku);
  900. GetEventCodes(SLEEP_BUTTON_SLEEP_EVENT_CODE_LINE,
  901. &(g_gupp[sku].PowerButtonAc),
  902. &(g_gupp[sku].PowerButtonDc),
  903. POWER_USER_NOTIFY_BUTTON,
  904. sku);
  905. printf(" Parsed Sleep Button Policies\n");
  906. //**********************************************************************
  907. // Lid Closed
  908. //**********************************************************************
  909. GetCheckLabelToken(LID_CLOSE_LINE, "Lid close", sku);
  910. g_gupp[sku].LidCloseAc.Action = GetPowerActionToken();
  911. g_gupp[sku].LidCloseDc.Action = GetPowerActionToken();
  912. GetSleepActionFlagsGlobal(LID_CLOSE_SLEEP_ACTION_FLAGS_LINE,
  913. &(g_gupp[sku].LidCloseAc),
  914. &(g_gupp[sku].LidCloseDc),
  915. sku);
  916. printf(" Parsed Lid Close Policies\n");
  917. //**********************************************************************
  918. // Lid Open Wake
  919. //**********************************************************************
  920. GetCheckLabelToken(LID_OPEN_WAKE_LINE, "Lid Open Wake", sku);
  921. g_gmpp[sku].LidOpenWakeAc = GetPowerStateToken();
  922. g_gmpp[sku].LidOpenWakeDc = GetPowerStateToken();
  923. printf(" Parsed Lid Open Wake Policies\n");
  924. //**********************************************************************
  925. // Battery Policies
  926. //**********************************************************************
  927. GetCheckLabelToken(BROADCAST_CAP_RES_LINE, "Broadcast capacity resolution", sku);
  928. GetIntToken(NULL);
  929. g_gmpp[sku].BroadcastCapacityResolution = GetIntToken("%");
  930. GetCheckLabelToken(BATMETER_ENABLE_SYSTRAY_FLAG_LINE, "Force Systray Battery Meter", sku);
  931. g_gupp[sku].GlobalFlags |= GetFlagToken(EnableSysTrayBatteryMeter);
  932. GetFlagToken(0);
  933. GetCheckLabelToken(BATMETER_ENABLE_MULTI_FLAG_LINE, "Enable Multi-Battery Display", sku);
  934. GetFlagToken(0);
  935. g_gupp[sku].GlobalFlags |= GetFlagToken(EnableMultiBatteryDisplay);
  936. printf(" Parsed Battery Policies\n");
  937. //**********************************************************************
  938. // Discharge Policies 1, Low Battery
  939. //**********************************************************************
  940. GetDischargePolicies(DISCHARGE_POLICY_1_LINE, 1, DISCHARGE_POLICY_LOW, sku);
  941. //**********************************************************************
  942. // Discharge Policies 2, Critical Battery
  943. //**********************************************************************
  944. GetDischargePolicies(DISCHARGE_POLICY_2_LINE, 2, DISCHARGE_POLICY_CRITICAL, sku);
  945. }
  946. return TRUE;
  947. }
  948. /*******************************************************************************
  949. *
  950. * GetPolicies
  951. *
  952. * DESCRIPTION:
  953. * Parse the power policies into the USER: and HKEY_LOCAL_MACHINE global
  954. * power policies structures arrays.
  955. *
  956. * PARAMETERS:
  957. *
  958. *******************************************************************************/
  959. BOOLEAN GetPolicies(void)
  960. {
  961. UINT i, sku;
  962. BOOLEAN bRet = FALSE;
  963. for (sku = 0; sku < MAX_SKUS; sku++) {
  964. printf("Processing SKU# %d\n\n", sku);
  965. printf("Parsing power policies\n");
  966. // First get a place to put the data.
  967. for (i = 0; i < g_uiPoliciesCount[sku]; i++) {
  968. g_pupp[sku][i] = (PUSER_POWER_POLICY)malloc(sizeof(USER_POWER_POLICY));
  969. g_pmpp[sku][i] = (PMACHINE_POWER_POLICY)malloc(sizeof(MACHINE_POWER_POLICY));
  970. g_ppmpp[sku][i] = (PMACHINE_PROCESSOR_POWER_POLICY)malloc(sizeof(MACHINE_PROCESSOR_POWER_POLICY));
  971. if (!g_pupp[sku][i] || !g_pmpp[sku][i] || !g_ppmpp[sku][i]) {
  972. goto gp_leave;
  973. }
  974. FillMemory(g_pupp[sku][i], sizeof(USER_POWER_POLICY), 0);
  975. FillMemory(g_pmpp[sku][i], sizeof(MACHINE_POWER_POLICY), 0);
  976. FillMemory(g_ppmpp[sku][i], sizeof(MACHINE_PROCESSOR_POWER_POLICY), 0);
  977. }
  978. // Initialize revision data.
  979. for (i = 0; i < g_uiPoliciesCount[sku]; i++) {
  980. g_pupp[sku][i]->Revision = DATA_REV;
  981. g_pmpp[sku][i]->Revision = DATA_REV;
  982. g_ppmpp[sku][i]->Revision = DATA_REV;
  983. }
  984. printf(" Allocated policies\n");
  985. //**********************************************************************
  986. // System Idle
  987. //**********************************************************************
  988. GetCheckLabelToken(SYSTEM_IDLE_LINE, "Idle action", sku);
  989. for (i = 0; i < g_uiPoliciesCount[sku]; i++) {
  990. g_pupp[sku][i]->IdleAc.Action = GetPowerActionToken();
  991. g_pupp[sku][i]->IdleDc.Action = GetPowerActionToken();
  992. }
  993. GetCheckLabelToken(SYSTEM_IDLE_TIMEOUT_LINE, "Idle timeout", sku);
  994. for (i = 0; i < g_uiPoliciesCount[sku]; i++) {
  995. g_pupp[sku][i]->IdleTimeoutAc = GetIntToken("MIN");
  996. g_pupp[sku][i]->IdleTimeoutDc = GetIntToken("MIN");
  997. }
  998. GetSleepActionFlagsUserPolicy(SYSTEM_IDLE_SLEEP_ACTION_FLAGS_LINE,
  999. FIELD_OFFSET(USER_POWER_POLICY, IdleAc),
  1000. FIELD_OFFSET(USER_POWER_POLICY, IdleDc),
  1001. &g_uiPoliciesCount[sku],
  1002. sku);
  1003. GetCheckLabelToken(SYSTEM_IDLE_SENSITIVITY_LINE, "Idle sensitivity", sku);
  1004. for (i = 0; i < g_uiPoliciesCount[sku]; i++) {
  1005. g_pupp[sku][i]->IdleSensitivityAc = (UCHAR)GetIntToken("%");
  1006. g_pupp[sku][i]->IdleSensitivityDc = (UCHAR)GetIntToken("%");
  1007. }
  1008. printf(" Parsed System Idle Policies\n");
  1009. //**********************************************************************
  1010. // Sleep Policies
  1011. //**********************************************************************
  1012. GetCheckLabelToken(MIN_SLEEP_LINE, "Minimum sleep", sku);
  1013. for (i = 0; i < g_uiPoliciesCount[sku]; i++) {
  1014. g_pmpp[sku][i]->MinSleepAc = GetPowerStateToken();
  1015. g_pmpp[sku][i]->MinSleepDc = GetPowerStateToken();
  1016. }
  1017. GetCheckLabelToken(MAX_SLEEP_LINE, "Max sleep", sku);
  1018. for (i = 0; i < g_uiPoliciesCount[sku]; i++) {
  1019. g_pupp[sku][i]->MaxSleepAc = GetPowerStateToken();
  1020. g_pupp[sku][i]->MaxSleepDc = GetPowerStateToken();
  1021. }
  1022. GetCheckLabelToken(REDUCED_LATENCY_SLEEP_LINE, "Reduced latency sleep", sku);
  1023. for (i = 0; i < g_uiPoliciesCount[sku]; i++) {
  1024. g_pmpp[sku][i]->ReducedLatencySleepAc = GetPowerStateToken();
  1025. g_pmpp[sku][i]->ReducedLatencySleepDc = GetPowerStateToken();
  1026. }
  1027. GetCheckLabelToken(DOZE_TIMEOUT_LINE, "Doze timeout", sku);
  1028. for (i = 0; i < g_uiPoliciesCount[sku]; i++) {
  1029. g_pmpp[sku][i]->DozeTimeoutAc = GetIntToken("MIN");
  1030. g_pmpp[sku][i]->DozeTimeoutDc = GetIntToken("MIN");
  1031. }
  1032. GetCheckLabelToken(DOZE_S4_TIMEOUT_LINE, "DozeS4Timeout", sku);
  1033. for (i = 0; i < g_uiPoliciesCount[sku]; i++) {
  1034. g_pmpp[sku][i]->DozeS4TimeoutAc = GetIntToken("MIN");
  1035. g_pmpp[sku][i]->DozeS4TimeoutDc = GetIntToken("MIN");
  1036. }
  1037. printf(" Parsed Sleep Policies\n");
  1038. //**********************************************************************
  1039. // Device Power Management
  1040. //**********************************************************************
  1041. GetCheckLabelToken(VIDEO_TIMEOUT_LINE, "Video timeout", sku);
  1042. for (i = 0; i < g_uiPoliciesCount[sku]; i++) {
  1043. g_pupp[sku][i]->VideoTimeoutAc = GetIntToken("MIN");
  1044. g_pupp[sku][i]->VideoTimeoutDc = GetIntToken("MIN");
  1045. }
  1046. GetCheckLabelToken(SPINDOWN_TIMEOUT_LINE, "Spindown timeout", sku);
  1047. for (i = 0; i < g_uiPoliciesCount[sku]; i++) {
  1048. g_pupp[sku][i]->SpindownTimeoutAc = GetIntToken("MIN");
  1049. g_pupp[sku][i]->SpindownTimeoutDc = GetIntToken("MIN");
  1050. }
  1051. printf(" Parsed Device Power Management Policies\n");
  1052. //**********************************************************************
  1053. // CPU Policies
  1054. //**********************************************************************
  1055. GetCheckLabelToken(OPTIMIZE_FOR_POWER_LINE, "Optimize for power", sku);
  1056. for (i = 0; i < g_uiPoliciesCount[sku]; i++) {
  1057. g_pupp[sku][i]->OptimizeForPowerAc = (BOOLEAN)GetFlagToken(TRUE);
  1058. g_pupp[sku][i]->OptimizeForPowerDc = (BOOLEAN)GetFlagToken(TRUE);
  1059. }
  1060. GetCheckLabelToken(FAN_THROTTLE_TOL_LINE, "Fan throttle Tolerance", sku);
  1061. for (i = 0; i < g_uiPoliciesCount[sku]; i++) {
  1062. g_pupp[sku][i]->FanThrottleToleranceAc = (UCHAR)GetIntToken("%");
  1063. g_pupp[sku][i]->FanThrottleToleranceDc = (UCHAR)GetIntToken("%");
  1064. }
  1065. GetCheckLabelToken(FORCED_THROTTLE_LINE, "Forced throttle", sku);
  1066. for (i = 0; i < g_uiPoliciesCount[sku]; i++) {
  1067. g_pupp[sku][i]->ForcedThrottleAc = (UCHAR)GetIntToken("%");
  1068. g_pupp[sku][i]->ForcedThrottleDc = (UCHAR)GetIntToken("%");
  1069. }
  1070. GetCheckLabelToken(MIN_THROTTLE_LINE, "Min throttle", sku);
  1071. for (i = 0; i < g_uiPoliciesCount[sku]; i++) {
  1072. g_pmpp[sku][i]->MinThrottleAc = (UCHAR)GetIntToken("%");
  1073. g_pmpp[sku][i]->MinThrottleDc = (UCHAR)GetIntToken("%");
  1074. }
  1075. GetCheckLabelToken(OVERTHROTTLED_LINE, "Overthrottled", sku);
  1076. for (i = 0; i < g_uiPoliciesCount[sku]; i++) {
  1077. g_pmpp[sku][i]->OverThrottledAc.Action = GetPowerActionToken();
  1078. g_pmpp[sku][i]->OverThrottledDc.Action = GetPowerActionToken();
  1079. }
  1080. GetSleepActionFlagsMachinePolicy(OVERTHROTTLED_SLEEP_ACTION_FLAGS_LINE,
  1081. FIELD_OFFSET(MACHINE_POWER_POLICY, OverThrottledAc),
  1082. FIELD_OFFSET(MACHINE_POWER_POLICY, OverThrottledDc),
  1083. &g_uiPoliciesCount[sku],
  1084. sku);
  1085. //
  1086. // Processor Policies
  1087. //
  1088. GetCheckLabelToken(DYNAMIC_THROTTLE_LINE, "Dynamic Throttle", sku);
  1089. for (i = 0; i < g_uiPoliciesCount[sku]; i++) {
  1090. g_ppmpp[sku][i]->ProcessorPolicyAc.Revision = 1;
  1091. g_ppmpp[sku][i]->ProcessorPolicyDc.Revision = 1;
  1092. g_ppmpp[sku][i]->ProcessorPolicyAc.DynamicThrottle = g_pupp[sku][i]->ThrottlePolicyAc = (UCHAR)GetThrottleToken();
  1093. g_ppmpp[sku][i]->ProcessorPolicyDc.DynamicThrottle = g_pupp[sku][i]->ThrottlePolicyDc = (UCHAR)GetThrottleToken();
  1094. }
  1095. GetCStateThresholds(C1_THRESHOLDS_LINE, 1, &g_uiPoliciesCount[sku], sku);
  1096. GetCStateThresholds(C2_THRESHOLDS_LINE, 2, &g_uiPoliciesCount[sku], sku);
  1097. GetCStateThresholds(C3_THRESHOLDS_LINE, 3, &g_uiPoliciesCount[sku], sku);
  1098. printf(" Parsed CPU Policies\n");
  1099. }
  1100. bRet = TRUE;
  1101. printf("Parsing power policies success!\n\n");
  1102. gp_leave:
  1103. if (!bRet) {
  1104. printf("GetPolicies failed, Last Error: %d\n", GetLastError());
  1105. }
  1106. return bRet;
  1107. }