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.

297 lines
6.4 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. amlload.c
  5. Abstract:
  6. This program installs an AML file into the NT registry
  7. Author:
  8. Ken Reneris
  9. Environment:
  10. Command-line.
  11. Revision History:
  12. --*/
  13. #include <windows.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. typedef struct _pm_tables {
  17. DWORD bit;
  18. UCHAR *name;
  19. } pm_tables, *ppm_tables;
  20. pm_tables pm_table_1[] = {
  21. { 0, "System Timer" },
  22. { 4, "BusMaster Request" },
  23. { 5, "Global Lock Request" },
  24. };
  25. pm_tables pm_table_2[] = {
  26. { 0, "Power Button" },
  27. { 1, "Sleep Button" },
  28. { 2, "Real Time Clock" },
  29. };
  30. UCHAR s[500]; // Registry path
  31. VOID
  32. Abort(
  33. )
  34. {
  35. exit(1);
  36. }
  37. PUCHAR
  38. get_fixed_event_name(
  39. IN ppm_tables CurTable,
  40. IN DWORD Index
  41. )
  42. {
  43. DWORD i;
  44. for (i = 0; i < 8; i++) {
  45. if (CurTable[i].bit == Index) {
  46. return CurTable[i].name;
  47. }
  48. }
  49. return NULL;
  50. }
  51. VOID
  52. display_fixed_event_info(
  53. IN UCHAR *fixedmaskdata,
  54. IN UCHAR *fixedstatusdata,
  55. IN DWORD data_length)
  56. {
  57. DWORD i;
  58. DWORD j;
  59. DWORD k;
  60. ppm_tables curTable;
  61. PUCHAR text;
  62. printf("Fixed Event Information\n");
  63. for (i = 0; i < data_length && i < 2; i++) {
  64. if (i == 0) {
  65. curTable = pm_table_1;
  66. } else {
  67. curTable = pm_table_2;
  68. }
  69. /*
  70. printf(" MaskRegister[%d]:%x StatusRegister[%d]:%x\n",
  71. i, fixedmaskdata[i], i, fixedstatusdata[i]);
  72. */
  73. for (j = 1, k = 0; k < 8; k++, j = (j << 1)) {
  74. text = get_fixed_event_name( curTable, k);
  75. if (text == NULL) {
  76. continue;
  77. }
  78. if ( (fixedmaskdata[i] & j) && (fixedstatusdata[i] & j) ) {
  79. printf(" The %s is enabled and has awoken the system.\n", text);
  80. } else if (fixedmaskdata[i] & j) {
  81. printf(" The %s is enabled to wake the system.\n", text );
  82. } else if (fixedstatusdata[i] & j) {
  83. printf(" The %s was set but not enabled to wake the system.\n", text );
  84. }
  85. }
  86. }
  87. printf("\n");
  88. }
  89. VOID
  90. display_generic_event_info(
  91. IN UCHAR *genericmaskdata,
  92. IN UCHAR *genericstatusdata,
  93. IN DWORD data_length
  94. )
  95. {
  96. DWORD i;
  97. DWORD j;
  98. DWORD k;
  99. printf("Generic Event Information\n");
  100. for (i = 0; i < data_length; i++) {
  101. /*
  102. printf(" MaskRegister[%d]:%x StatusRegister[%d]:%x\n",
  103. i, genericmaskdata[i], i, genericstatusdata[i]);
  104. */
  105. for (j = 1, k = 0; k < 8; k++, j = (j << 1) ) {
  106. if ( (genericmaskdata[i] & j) && (genericstatusdata[i] && j) ) {
  107. printf(" Event %02x is enabled and has awoken the system.\n",
  108. ( (i * 8) + k ) );
  109. } else if (genericmaskdata[i] & j) {
  110. printf(" Event %02x is enabled to wake the system.\n",
  111. ( (i * 8) + k ) );
  112. } else if (genericstatusdata[i] & j) {
  113. printf(" Event %02x was set but not enabled to wake the system.\n",
  114. ( (i * 8) + k ) );
  115. }
  116. }
  117. }
  118. printf("\n");
  119. }
  120. int
  121. __cdecl
  122. main(
  123. IN int argc,
  124. IN char *argv[]
  125. )
  126. {
  127. DWORD data_type;
  128. DWORD data_length;
  129. HKEY regKey;
  130. LONG status;
  131. UCHAR fixedmaskdata[32];
  132. UCHAR fixedstatusdata[32];
  133. UCHAR genericmaskdata[32];
  134. UCHAR genericstatusdata[32];
  135. sprintf(s, "System\\CurrentControlSet\\Services\\ACPI\\Parameters\\WakeUp");
  136. status = RegOpenKeyEx(
  137. HKEY_LOCAL_MACHINE,
  138. s,
  139. 0L,
  140. KEY_ALL_ACCESS,
  141. &regKey
  142. );
  143. if (status != ERROR_SUCCESS) {
  144. printf("Could not access the registry path: %s\n", s);
  145. Abort();
  146. }
  147. //
  148. // Read the fixed event mask
  149. //
  150. data_length = 32;
  151. status = RegQueryValueEx(
  152. regKey,
  153. "FixedEventMask", 0,
  154. &data_type,
  155. fixedmaskdata,
  156. &data_length
  157. );
  158. if (status != ERROR_SUCCESS) {
  159. printf("Could not read FixedEventMask from %s:%x\n", s, status );
  160. RegCloseKey( regKey );
  161. Abort();
  162. }
  163. if (data_type != REG_BINARY) {
  164. printf("FixedEventMask does not contain binary data\n");
  165. RegCloseKey( regKey );
  166. Abort();
  167. }
  168. //
  169. // Read the fixed event Status
  170. //
  171. data_length = 32;
  172. status = RegQueryValueEx(
  173. regKey,
  174. "FixedEventStatus", 0,
  175. &data_type,
  176. fixedstatusdata,
  177. &data_length
  178. );
  179. if (status != ERROR_SUCCESS) {
  180. printf("Could not read FixedEventStatus from %s:%x\n", s, status );
  181. RegCloseKey( regKey );
  182. Abort();
  183. }
  184. if (data_type != REG_BINARY) {
  185. printf("FixedEventStatus does not contain binary data\n");
  186. RegCloseKey( regKey );
  187. Abort();
  188. }
  189. display_fixed_event_info( fixedmaskdata, fixedstatusdata, data_length );
  190. //
  191. // Read the generic event mask
  192. //
  193. data_length = 32;
  194. status = RegQueryValueEx(
  195. regKey,
  196. "GenericEventMask", 0,
  197. &data_type,
  198. genericmaskdata,
  199. &data_length
  200. );
  201. if (status != ERROR_SUCCESS) {
  202. printf("Could not read GenericEventMask from %s:%x\n", s, status );
  203. RegCloseKey( regKey );
  204. Abort();
  205. }
  206. if (data_type != REG_BINARY) {
  207. printf("GenericEventMask does not contain binary data\n");
  208. RegCloseKey( regKey );
  209. Abort();
  210. }
  211. //
  212. // Read the generic event status
  213. //
  214. data_length = 32;
  215. status = RegQueryValueEx(
  216. regKey,
  217. "GenericEventStatus", 0,
  218. &data_type,
  219. genericstatusdata,
  220. &data_length
  221. );
  222. if (status != ERROR_SUCCESS) {
  223. printf("Could not read GenericEventStatus from %s:%x\n", s, status );
  224. RegCloseKey( regKey );
  225. Abort();
  226. }
  227. if (data_type != REG_BINARY) {
  228. printf("GenericEventStatus does not contain binary data\n");
  229. RegCloseKey( regKey );
  230. Abort();
  231. }
  232. display_generic_event_info( genericmaskdata, genericstatusdata, data_length );
  233. RegCloseKey( regKey );
  234. return 0;
  235. }