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.

993 lines
22 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <windows.h>
  5. #include <winioctl.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include "saio.h"
  9. #include "..\driver\ioctl.h"
  10. void
  11. PrintACPITable(
  12. PVOID AcpiTable
  13. );
  14. PWSTR SaDeviceName[] =
  15. {
  16. { NULL }, // SA_DEVICE_UNKNOWN
  17. { L"\\\\?\\GLOBALROOT\\Device\\ServerApplianceLocalDisplay" }, // SA_DEVICE_DISPLAY
  18. { L"\\\\?\\GLOBALROOT\\Device\\ServerApplianceKeypad" }, // SA_DEVICE_KEYPAD
  19. { L"\\\\?\\GLOBALROOT\\Device\\ServerApplianceNvram" }, // SA_DEVICE_NVRAM
  20. { L"\\\\?\\GLOBALROOT\\Device\\ServerApplianceWatchdog" } // SA_DEVICE_WATCHDOG
  21. };
  22. ULONG NvramData[32];
  23. UCHAR KeyBuffer[32];
  24. PVOID WdTable;
  25. HANDLE
  26. OpenSaDevice(
  27. ULONG DeviceType
  28. )
  29. {
  30. HANDLE hDevice;
  31. WCHAR buf[128];
  32. wcscpy( buf, L"\\\\?\\GLOBALROOT" );
  33. switch (DeviceType) {
  34. case SA_DEVICE_DISPLAY:
  35. wcscat( buf, SA_DEVICE_DISPLAY_NAME_STRING );
  36. break;
  37. case SA_DEVICE_KEYPAD:
  38. wcscat( buf, SA_DEVICE_KEYPAD_NAME_STRING );
  39. break;
  40. case SA_DEVICE_NVRAM:
  41. wcscat( buf, SA_DEVICE_NVRAM_NAME_STRING );
  42. break;
  43. case SA_DEVICE_WATCHDOG:
  44. wcscat( buf, SA_DEVICE_WATCHDOG_NAME_STRING );
  45. break;
  46. }
  47. hDevice = CreateFile(
  48. buf,
  49. GENERIC_READ | GENERIC_WRITE,
  50. FILE_SHARE_READ | FILE_SHARE_WRITE,
  51. NULL,
  52. OPEN_EXISTING,
  53. 0,
  54. NULL
  55. );
  56. return hDevice;
  57. }
  58. HANDLE
  59. OpenSaTestDriver(
  60. void
  61. )
  62. {
  63. HANDLE hDevice;
  64. hDevice = CreateFile(
  65. L"\\\\.\\SaTest",
  66. GENERIC_READ | GENERIC_WRITE,
  67. FILE_SHARE_READ | FILE_SHARE_WRITE,
  68. NULL,
  69. OPEN_EXISTING,
  70. 0,
  71. NULL
  72. );
  73. return hDevice;
  74. }
  75. int
  76. WriteBitmap(
  77. PUCHAR Bitmap,
  78. ULONG Width,
  79. ULONG Height,
  80. ULONG BitmapSize
  81. )
  82. {
  83. HANDLE hFile;
  84. SA_DISPLAY_SHOW_MESSAGE SaDisplay;
  85. ULONG Count;
  86. hFile = OpenSaDevice( SA_DEVICE_DISPLAY );
  87. if (hFile == INVALID_HANDLE_VALUE) {
  88. return -1;
  89. }
  90. SaDisplay.SizeOfStruct = sizeof(SA_DISPLAY_SHOW_MESSAGE);
  91. SaDisplay.MsgCode = SA_DISPLAY_READY;
  92. SaDisplay.Width = (USHORT)Width;
  93. SaDisplay.Height = (USHORT)Height;
  94. memcpy( SaDisplay.Bits, Bitmap, BitmapSize );
  95. WriteFile( hFile, &SaDisplay, sizeof(SA_DISPLAY_SHOW_MESSAGE), &Count, NULL );
  96. CloseHandle( hFile );
  97. return 0;
  98. }
  99. void
  100. ConvertBottomLeft2TopLeft(
  101. PUCHAR Bits,
  102. ULONG Width,
  103. ULONG Height
  104. )
  105. {
  106. ULONG Row;
  107. ULONG Col;
  108. UCHAR Temp;
  109. Width = Width >> 3;
  110. for (Row = 0; Row < (Height / 2); Row++) {
  111. for (Col = 0; Col < Width; Col++) {
  112. Temp = Bits[Row * Width + Col];
  113. Bits[Row * Width + Col] = Bits[(Height - Row - 1) * Width + Col];
  114. Bits[(Height - Row - 1) * Width + Col] = Temp;
  115. }
  116. }
  117. }
  118. int
  119. DisplayBitmap(
  120. PWSTR BitmapName
  121. )
  122. {
  123. HANDLE hFile;
  124. ULONG FileSize;
  125. PUCHAR BitmapData;
  126. PBITMAPFILEHEADER bmf;
  127. PBITMAPINFOHEADER bmi;
  128. ULONG Bytes;
  129. PUCHAR Bits;
  130. hFile = CreateFile(
  131. BitmapName,
  132. GENERIC_READ,
  133. FILE_SHARE_READ | FILE_SHARE_WRITE,
  134. NULL,
  135. OPEN_EXISTING,
  136. 0,
  137. NULL
  138. );
  139. if (hFile == INVALID_HANDLE_VALUE) {
  140. return -1;
  141. }
  142. FileSize = GetFileSize( hFile, NULL );
  143. BitmapData = (PUCHAR) malloc( FileSize );
  144. if (BitmapData == NULL) {
  145. return -1;
  146. }
  147. memset( BitmapData, 0, FileSize );
  148. if (!ReadFile( hFile, BitmapData, FileSize, &Bytes, NULL )) {
  149. return -1;
  150. }
  151. bmf = (PBITMAPFILEHEADER) BitmapData;
  152. bmi = (PBITMAPINFOHEADER) (BitmapData + sizeof(BITMAPFILEHEADER));
  153. if (bmf->bfType != 0x4d42) {
  154. return -1;
  155. }
  156. if (bmi->biBitCount != 1 && bmi->biCompression != 0) {
  157. return -1;
  158. }
  159. Bits = (PUCHAR) BitmapData + bmf->bfOffBits;
  160. ConvertBottomLeft2TopLeft( Bits, bmi->biWidth, bmi->biHeight );
  161. WriteBitmap(
  162. Bits,
  163. bmi->biWidth,
  164. bmi->biHeight,
  165. (bmi->biWidth >> 3) * bmi->biHeight //NewSize
  166. );
  167. free( BitmapData );
  168. CloseHandle( hFile );
  169. return 0;
  170. }
  171. int
  172. ClearDisplay(
  173. int val
  174. )
  175. {
  176. PUCHAR BitmapData;
  177. ULONG Width = 128;
  178. ULONG Height = 64;
  179. ULONG Size = (Width * Height) / 8;
  180. BitmapData = (PUCHAR) malloc( Size );
  181. if (BitmapData == NULL) {
  182. return -1;
  183. }
  184. memset( BitmapData, val, Size );
  185. return WriteBitmap( BitmapData, Width, Height, Size );
  186. }
  187. int
  188. DoKeypadTest(
  189. void
  190. )
  191. {
  192. HANDLE hFile;
  193. ULONG Count;
  194. UCHAR Keypress;
  195. hFile = OpenSaDevice( SA_DEVICE_KEYPAD );
  196. if (hFile == INVALID_HANDLE_VALUE) {
  197. return -1;
  198. }
  199. while (1) {
  200. wprintf( L">>> " );
  201. if (ReadFile( hFile, KeyBuffer, sizeof(UCHAR), &Count, NULL )) {
  202. Keypress = KeyBuffer[0];
  203. if (Keypress & SA_KEYPAD_UP) {
  204. wprintf( L"Up Arrow\n" );
  205. } else
  206. if (Keypress & SA_KEYPAD_DOWN) {
  207. wprintf( L"Down Arrow\n" );
  208. } else
  209. if (Keypress & SA_KEYPAD_LEFT) {
  210. wprintf( L"Left Arrow\n" );
  211. } else
  212. if (Keypress & SA_KEYPAD_RIGHT) {
  213. wprintf( L"Right Arrow\n" );
  214. } else
  215. if (Keypress & SA_KEYPAD_CANCEL) {
  216. wprintf( L"Escape\n" );
  217. } else
  218. if (Keypress & SA_KEYPAD_SELECT) {
  219. wprintf( L"Enter\n" );
  220. } else {
  221. wprintf( L"**-> Unknown key [%x] <-**\n", Keypress );
  222. }
  223. }
  224. }
  225. CloseHandle( hFile );
  226. return 0;
  227. }
  228. int
  229. NvramWrite(
  230. ULONG Slot,
  231. ULONG Val
  232. )
  233. {
  234. HANDLE hFile;
  235. ULONG Count;
  236. hFile = OpenSaDevice( SA_DEVICE_NVRAM );
  237. if (hFile == INVALID_HANDLE_VALUE) {
  238. return -1;
  239. }
  240. SetFilePointer( hFile, sizeof(ULONG)*Slot, NULL, FILE_BEGIN );
  241. WriteFile( hFile, &Val, sizeof(ULONG), &Count, NULL );
  242. CloseHandle( hFile );
  243. return 0;
  244. }
  245. ULONG
  246. NvramRead(
  247. ULONG Slot
  248. )
  249. {
  250. HANDLE hFile;
  251. ULONG Count;
  252. ULONG Val;
  253. hFile = OpenSaDevice( SA_DEVICE_NVRAM );
  254. if (hFile == INVALID_HANDLE_VALUE) {
  255. return -1;
  256. }
  257. SetFilePointer( hFile, sizeof(ULONG)*Slot, NULL, FILE_BEGIN );
  258. ReadFile( hFile, &Val, sizeof(ULONG), &Count, NULL );
  259. CloseHandle( hFile );
  260. return Val;
  261. }
  262. BOOL
  263. BootCounterRead(
  264. ULONG Slot,
  265. PULONG Val
  266. )
  267. {
  268. HANDLE hFile;
  269. BOOL b;
  270. ULONG Bytes;
  271. SA_NVRAM_BOOT_COUNTER BootCounter;
  272. hFile = OpenSaDevice( SA_DEVICE_NVRAM );
  273. if (hFile == INVALID_HANDLE_VALUE) {
  274. return -1;
  275. }
  276. BootCounter.SizeOfStruct = sizeof(SA_NVRAM_BOOT_COUNTER);
  277. BootCounter.Number = Slot;
  278. BootCounter.Value = 0;
  279. b = DeviceIoControl(
  280. hFile,
  281. IOCTL_NVRAM_READ_BOOT_COUNTER,
  282. NULL,
  283. 0,
  284. &BootCounter,
  285. sizeof(SA_NVRAM_BOOT_COUNTER),
  286. &Bytes,
  287. NULL
  288. );
  289. if (!b) {
  290. *Val = 0;
  291. } else {
  292. *Val = BootCounter.Value;
  293. }
  294. CloseHandle( hFile );
  295. return b;
  296. }
  297. BOOL
  298. BootCounterWrite(
  299. ULONG Slot,
  300. ULONG Val
  301. )
  302. {
  303. HANDLE hFile;
  304. BOOL b;
  305. ULONG Bytes;
  306. SA_NVRAM_BOOT_COUNTER BootCounter;
  307. hFile = OpenSaDevice( SA_DEVICE_NVRAM );
  308. if (hFile == INVALID_HANDLE_VALUE) {
  309. return -1;
  310. }
  311. BootCounter.SizeOfStruct = sizeof(SA_NVRAM_BOOT_COUNTER);
  312. BootCounter.Number = Slot;
  313. BootCounter.Value = Val;
  314. b = DeviceIoControl(
  315. hFile,
  316. IOCTL_NVRAM_WRITE_BOOT_COUNTER,
  317. &BootCounter,
  318. sizeof(SA_NVRAM_BOOT_COUNTER),
  319. NULL,
  320. 0,
  321. &Bytes,
  322. NULL
  323. );
  324. CloseHandle( hFile );
  325. return b;
  326. }
  327. int
  328. DoWatchdogTest(
  329. void
  330. )
  331. {
  332. HANDLE hFileWd;
  333. HANDLE hFileNvram;
  334. ULONG Count;
  335. ULONG WatchdogState;
  336. ULONG i;
  337. hFileNvram = OpenSaDevice( SA_DEVICE_NVRAM );
  338. if (hFileNvram == INVALID_HANDLE_VALUE) {
  339. return -1;
  340. }
  341. ReadFile( hFileNvram, NvramData, sizeof(NvramData), &Count, NULL );
  342. for (i=0; i<32; i++) {
  343. wprintf( L"[%08x]\n", NvramData[i] );
  344. }
  345. NvramData[28] = 10;
  346. NvramData[29] = 10;
  347. NvramData[30] = 10;
  348. NvramData[31] = 10;
  349. WriteFile( hFileNvram, &NvramData, sizeof(NvramData), &Count, NULL );
  350. CloseHandle( hFileNvram );
  351. hFileWd = OpenSaDevice( SA_DEVICE_WATCHDOG );
  352. if (hFileWd == INVALID_HANDLE_VALUE) {
  353. return -1;
  354. }
  355. WatchdogState = 1;
  356. Count = DeviceIoControl(
  357. hFileWd,
  358. IOCTL_SAWD_DISABLE,
  359. &WatchdogState,
  360. sizeof(ULONG),
  361. &WatchdogState,
  362. sizeof(ULONG),
  363. &Count,
  364. NULL
  365. );
  366. CloseHandle( hFileWd );
  367. return 0;
  368. }
  369. int
  370. DoWatchdogPingLoop(
  371. void
  372. )
  373. {
  374. HANDLE hFile;
  375. ULONG Count;
  376. hFile = OpenSaDevice( SA_DEVICE_WATCHDOG );
  377. if (hFile == INVALID_HANDLE_VALUE) {
  378. return -1;
  379. }
  380. while (1) {
  381. DeviceIoControl(
  382. hFile,
  383. IOCTL_SAWD_PING,
  384. NULL,
  385. 0,
  386. NULL,
  387. 0,
  388. &Count,
  389. NULL
  390. );
  391. wprintf( L"ping...\n" );
  392. Sleep( 90 * 1000 );
  393. }
  394. CloseHandle( hFile );
  395. return 0;
  396. }
  397. int
  398. InstallTestDriver(
  399. void
  400. )
  401. {
  402. SC_HANDLE ScmHandle;
  403. SC_HANDLE ServiceHandle;
  404. WCHAR DriverBinaryPath[MAX_PATH];
  405. PWSTR s;
  406. if (GetModuleFileName( NULL, DriverBinaryPath, sizeof(DriverBinaryPath)/sizeof(WCHAR) ) == 0) {
  407. return GetLastError();
  408. }
  409. s = wcsrchr( DriverBinaryPath, L'\\' );
  410. if (s == NULL) {
  411. return -1;
  412. }
  413. s += 1;
  414. wcscpy( s, L"satest.sys" );
  415. ScmHandle = OpenSCManager(
  416. NULL,
  417. NULL,
  418. SC_MANAGER_ALL_ACCESS
  419. );
  420. if (ScmHandle == NULL) {
  421. return GetLastError();
  422. }
  423. ServiceHandle = CreateService(
  424. ScmHandle,
  425. L"satest",
  426. L"satest",
  427. SERVICE_ALL_ACCESS,
  428. SERVICE_KERNEL_DRIVER,
  429. SERVICE_DEMAND_START,
  430. SERVICE_ERROR_NORMAL,
  431. DriverBinaryPath,
  432. NULL,
  433. NULL,
  434. NULL,
  435. NULL,
  436. NULL
  437. );
  438. if (ServiceHandle == NULL) {
  439. CloseServiceHandle( ScmHandle );
  440. return GetLastError();
  441. }
  442. if (!StartService( ServiceHandle, NULL, NULL )) {
  443. CloseServiceHandle( ServiceHandle );
  444. CloseServiceHandle( ScmHandle );
  445. return GetLastError();
  446. }
  447. CloseServiceHandle( ServiceHandle );
  448. CloseServiceHandle( ScmHandle );
  449. return 0;
  450. }
  451. int
  452. UnInstallTestDriver(
  453. void
  454. )
  455. {
  456. SC_HANDLE ScmHandle;
  457. SC_HANDLE ServiceHandle;
  458. SERVICE_STATUS Status;
  459. ScmHandle = OpenSCManager(
  460. NULL,
  461. NULL,
  462. SC_MANAGER_ALL_ACCESS
  463. );
  464. if (ScmHandle == NULL) {
  465. return GetLastError();
  466. }
  467. ServiceHandle = OpenService(
  468. ScmHandle,
  469. L"satest",
  470. SERVICE_ALL_ACCESS
  471. );
  472. if (ServiceHandle == NULL) {
  473. CloseServiceHandle( ScmHandle );
  474. return GetLastError();
  475. }
  476. if (!ControlService( ServiceHandle, SERVICE_CONTROL_STOP, &Status )) {
  477. CloseServiceHandle( ServiceHandle );
  478. CloseServiceHandle( ScmHandle );
  479. return GetLastError();
  480. }
  481. if (!DeleteService( ServiceHandle )) {
  482. CloseServiceHandle( ServiceHandle );
  483. CloseServiceHandle( ScmHandle );
  484. return GetLastError();
  485. }
  486. CloseServiceHandle( ServiceHandle );
  487. CloseServiceHandle( ScmHandle );
  488. return 0;
  489. }
  490. int
  491. GetAcpiTable(
  492. void
  493. )
  494. {
  495. HANDLE SatestDevice;
  496. BOOL b;
  497. ULONG Bytes;
  498. WdTable = (PVOID) malloc( 4096 );
  499. if (WdTable == NULL) {
  500. wprintf( L"could not allocate memory for ACPI table\n" );
  501. return -1;
  502. }
  503. SatestDevice = OpenSaTestDriver();
  504. if (SatestDevice == INVALID_HANDLE_VALUE) {
  505. wprintf( L"could not open satest driver, ec=[%d]\n", GetLastError() );
  506. return -1;
  507. }
  508. b = DeviceIoControl(
  509. SatestDevice,
  510. IOCTL_SATEST_GET_ACPI_TABLE,
  511. NULL,
  512. 0,
  513. WdTable,
  514. 4096,
  515. &Bytes,
  516. NULL
  517. );
  518. if (!b) {
  519. wprintf( L"could not get the WDRT ACPI table data, ec=[%d]", GetLastError() );
  520. CloseHandle( SatestDevice );
  521. return -1;
  522. }
  523. CloseHandle( SatestDevice );
  524. return 0;
  525. }
  526. int
  527. QueryWdTimerInfo(
  528. WCHAR option
  529. )
  530. {
  531. HANDLE SatestDevice;
  532. BOOL b;
  533. ULONG Bytes;
  534. SYSTEM_WATCHDOG_TIMER_INFORMATION WdTimerInfo;
  535. switch (option) {
  536. case L'x':
  537. WdTimerInfo.WdInfoClass = WdInfoTimeoutValue;
  538. break;
  539. case L't':
  540. WdTimerInfo.WdInfoClass = WdInfoTriggerAction;
  541. break;
  542. case L's':
  543. WdTimerInfo.WdInfoClass = WdInfoState;
  544. break;
  545. default:
  546. wprintf( L"missing option\n" );
  547. return -1;
  548. }
  549. SatestDevice = OpenSaTestDriver();
  550. if (SatestDevice == INVALID_HANDLE_VALUE) {
  551. wprintf( L"could not open satest driver, ec=[%d]\n", GetLastError() );
  552. return -1;
  553. }
  554. b = DeviceIoControl(
  555. SatestDevice,
  556. IOCTL_SATEST_QUERY_WATCHDOG_TIMER_INFORMATION,
  557. NULL,
  558. 0,
  559. &WdTimerInfo,
  560. sizeof(WdTimerInfo),
  561. &Bytes,
  562. NULL
  563. );
  564. if (!b) {
  565. wprintf( L"could not query the WD timer info, ec=[%d]", GetLastError() );
  566. CloseHandle( SatestDevice );
  567. return -1;
  568. }
  569. switch (option) {
  570. case L'x':
  571. wprintf( L"Watchdog timeout value = [%x]\n", WdTimerInfo.DataValue );
  572. break;
  573. case L't':
  574. wprintf( L"Watchdog trigger action = [%x]\n", WdTimerInfo.DataValue );
  575. break;
  576. case L's':
  577. wprintf( L"Watchdog state = [%x]\n", WdTimerInfo.DataValue );
  578. break;
  579. }
  580. CloseHandle( SatestDevice );
  581. return 0;
  582. }
  583. int
  584. SetWdTimerInfo(
  585. PWSTR option
  586. )
  587. {
  588. HANDLE SatestDevice;
  589. BOOL b;
  590. ULONG Bytes;
  591. SYSTEM_WATCHDOG_TIMER_INFORMATION WdTimerInfo;
  592. switch (option[0]) {
  593. case L'x':
  594. if (option[1] != '=') {
  595. wprintf( L"missing timeout value\n" );
  596. return -1;
  597. }
  598. WdTimerInfo.WdInfoClass = WdInfoTimeoutValue;
  599. WdTimerInfo.DataValue = wcstoul( &option[2], NULL, 0 );
  600. break;
  601. case L't':
  602. if (option[1] != '=') {
  603. wprintf( L"missing trigger action value\n" );
  604. return -1;
  605. }
  606. WdTimerInfo.WdInfoClass = WdInfoTriggerAction;
  607. WdTimerInfo.DataValue = wcstoul( &option[2], NULL, 0 );
  608. break;
  609. case L'r':
  610. WdTimerInfo.WdInfoClass = WdInfoResetTimer;
  611. WdTimerInfo.DataValue = 0;
  612. break;
  613. case L'p':
  614. WdTimerInfo.WdInfoClass = WdInfoStopTimer;
  615. WdTimerInfo.DataValue = 0;
  616. break;
  617. case L's':
  618. WdTimerInfo.WdInfoClass = WdInfoStartTimer;
  619. WdTimerInfo.DataValue = 0;
  620. break;
  621. default:
  622. wprintf( L"missing option\n" );
  623. return -1;
  624. }
  625. SatestDevice = OpenSaTestDriver();
  626. if (SatestDevice == INVALID_HANDLE_VALUE) {
  627. wprintf( L"could not open satest driver, ec=[%d]\n", GetLastError() );
  628. return -1;
  629. }
  630. b = DeviceIoControl(
  631. SatestDevice,
  632. IOCTL_SATEST_SET_WATCHDOG_TIMER_INFORMATION,
  633. &WdTimerInfo,
  634. sizeof(WdTimerInfo),
  635. NULL,
  636. 0,
  637. &Bytes,
  638. NULL
  639. );
  640. if (!b) {
  641. wprintf( L"could not set the WD timer info, ec=[%d]", GetLastError() );
  642. CloseHandle( SatestDevice );
  643. return -1;
  644. }
  645. CloseHandle( SatestDevice );
  646. return 0;
  647. }
  648. int
  649. StopWatchdogPing(
  650. void
  651. )
  652. {
  653. return SetWdTimerInfo( L"t=0xbadbadff" );
  654. }
  655. int Usage( void )
  656. {
  657. wprintf( L"\nServer Availaibility Command Line Test Tool\n" );
  658. wprintf( L"Copyright Microsoft Corporation\n" );
  659. wprintf( L"\n" );
  660. wprintf( L"SATEST\n" );
  661. wprintf( L"\n" );
  662. wprintf( L" c - Clear the local display\n" );
  663. wprintf( L" w <bitmap file name> - Display a bitmap on the local display\n" );
  664. wprintf( L" n<r|w>:<slot number> [data value] - Read or write to nvram data slot\n" );
  665. wprintf( L" b<r|w>:<slot number> [data value] - Read or write to boot counter\n" );
  666. wprintf( L" k - Keypad test\n" );
  667. wprintf( L" a - Dump ACPI table\n" );
  668. wprintf( L" t - Stop pinging watchdog hardware timer\n" );
  669. wprintf( L" q:<x|t|s> - Query watchdog timer information\n" );
  670. wprintf( L" x = Timeout value\n" );
  671. wprintf( L" t = Trigger action\n" );
  672. wprintf( L" s = State\n" );
  673. wprintf( L" s:<x|t|s>=<value> - Set watchdog timer information\n" );
  674. wprintf( L" x = Timeout value\n" );
  675. wprintf( L" t = Trigger action\n" );
  676. wprintf( L" r = Reset timer\n" );
  677. wprintf( L" p = Stop timer\n" );
  678. wprintf( L" s = Start timer\n" );
  679. return 0;
  680. }
  681. int _cdecl
  682. wmain(
  683. int argc,
  684. WCHAR *argv[]
  685. )
  686. {
  687. if (argc == 1) {
  688. Usage();
  689. return -1;
  690. }
  691. switch (argv[1][0]) {
  692. case L'?':
  693. Usage();
  694. break;
  695. case L'c':
  696. if (argc == 3) {
  697. int val = wcstoul( argv[2], NULL, 0 );
  698. ClearDisplay( val );
  699. } else {
  700. ClearDisplay( 0 );
  701. }
  702. break;
  703. case L'w':
  704. DisplayBitmap( argv[2] );
  705. break;
  706. case L'n':
  707. {
  708. int slot = 0;
  709. ULONG val = 0;
  710. BOOL Read = TRUE;
  711. if (argv[1][1] == 'r') {
  712. Read = TRUE;
  713. } else if (argv[1][1] == 'w') {
  714. Read = FALSE;
  715. } else {
  716. wprintf( L"test n[r|w]:<slot> <value>\n" );
  717. return -1;
  718. }
  719. if (argv[1][2] != ':') {
  720. wprintf( L"test n[r|w]:<slot> <value>\n" );
  721. return -1;
  722. }
  723. slot = argv[1][3] - L'0';
  724. if (Read) {
  725. val = NvramRead( slot );
  726. wprintf( L"Slot #%x [%08x]\n", slot, val );
  727. } else {
  728. val = wcstoul( argv[2], NULL, 0 );
  729. NvramWrite( slot, val );
  730. }
  731. }
  732. break;
  733. case L'b':
  734. {
  735. int slot = 0;
  736. ULONG val = 0;
  737. BOOL Read = TRUE;
  738. if (argv[1][1] == 'r') {
  739. Read = TRUE;
  740. } else if (argv[1][1] == 'w') {
  741. Read = FALSE;
  742. } else {
  743. wprintf( L"test b[r|w]:<slot> <value>\n" );
  744. return -1;
  745. }
  746. if (argv[1][2] != ':') {
  747. wprintf( L"test b[r|w]:<slot> <value>\n" );
  748. return -1;
  749. }
  750. slot = argv[1][3] - L'0';
  751. if (Read) {
  752. if (BootCounterRead( slot, &val )) {
  753. wprintf( L"Boot counter #%x [%08x]\n", slot, val );
  754. } else {
  755. wprintf( L"Could not read boot counter #%d, ec=%d\n", slot, GetLastError() );
  756. }
  757. } else {
  758. val = wcstoul( argv[2], NULL, 0 );
  759. if (!BootCounterWrite( slot, val )) {
  760. wprintf( L"Could not write boot counter #%d, ec=%d\n", slot, GetLastError() );
  761. }
  762. }
  763. }
  764. break;
  765. case L'k':
  766. DoKeypadTest();
  767. break;
  768. case L'd':
  769. DoWatchdogPingLoop();
  770. break;
  771. case L'a':
  772. if (InstallTestDriver() == ERROR_SUCCESS) {
  773. if (GetAcpiTable() == 0) {
  774. PrintACPITable( WdTable );
  775. }
  776. UnInstallTestDriver();
  777. }
  778. break;
  779. case L'q':
  780. if (argv[1][1] != ':') {
  781. return -1;
  782. }
  783. if (InstallTestDriver() == ERROR_SUCCESS) {
  784. QueryWdTimerInfo( argv[1][2] );
  785. UnInstallTestDriver();
  786. }
  787. break;
  788. case L's':
  789. if (argv[1][1] != ':') {
  790. return -1;
  791. }
  792. if (InstallTestDriver() == ERROR_SUCCESS) {
  793. SetWdTimerInfo( &argv[1][2] );
  794. UnInstallTestDriver();
  795. }
  796. break;
  797. case L't':
  798. if (InstallTestDriver() == ERROR_SUCCESS) {
  799. StopWatchdogPing();
  800. UnInstallTestDriver();
  801. }
  802. break;
  803. default:
  804. Usage();
  805. break;
  806. }
  807. return 0;
  808. }