Source code of Windows XP (NT5)
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.

155 lines
4.5 KiB

  1. /*** control.c - System Control Message Support
  2. *
  3. * Author: Yan Leshinsky (YanL)
  4. * Created 10/04/98
  5. *
  6. * MODIFICATION HISTORY
  7. */
  8. #include "wubiosp.h"
  9. #pragma CM_PAGEABLE_DATA
  10. #pragma CM_PAGEABLE_CODE
  11. /***EP WUBIOS_IOCtrl - Win32 Device IO Control entry point
  12. *
  13. * ENTRY
  14. * pioc -> DIOC structure
  15. *
  16. * EXIT-SUCCESS
  17. * returns ERROR_SUCCESS
  18. * EXIT-FAILURE
  19. * returns ERROR_*
  20. */
  21. CM_VXD_RESULT CM_SYSCTRL WUBIOS_IOCtrl(PDIOCPARAMETERS pdioc)
  22. {
  23. TRACENAME("WUBIOS_IOCtrl")
  24. CM_VXD_RESULT rc = ERROR_SUCCESS;
  25. ENTER(1, ("WUBIOS_IOCtrl(hVM=%lx,hDev=%lx,Code=%lx)\n",
  26. pdioc->VMHandle, pdioc->hDevice, pdioc->dwIoControlCode));
  27. switch (pdioc->dwIoControlCode)
  28. {
  29. case WUBIOCTL_GET_VERSION:
  30. if ((pdioc->cbOutBuffer < sizeof(DWORD)) || (pdioc->lpvOutBuffer == NULL))
  31. {
  32. DBG_ERR(("WUBIOS_IOCtrl: invalid parameter on GetVersion"));
  33. rc = ERROR_INVALID_PARAMETER;
  34. }
  35. else
  36. {
  37. PVMMDDB pddb = (PVMMDDB)pdioc->Internal2;
  38. *((PDWORD)pdioc->lpvOutBuffer) =
  39. (pddb->DDB_Dev_Major_Version << 8) |
  40. pddb->DDB_Dev_Minor_Version;
  41. if (pdioc->lpcbBytesReturned != NULL)
  42. *((PDWORD)pdioc->lpcbBytesReturned) = sizeof(DWORD);
  43. }
  44. break;
  45. case WUBIOCTL_GET_ACPI_TABINFO:
  46. if ((pdioc->lpvOutBuffer == NULL) ||
  47. (pdioc->cbOutBuffer != sizeof(ACPITABINFO)))
  48. {
  49. DBG_ERR(("WUBIOS_IOCtrl: invalid parameter on GetTabInfo"));
  50. rc = ERROR_INVALID_PARAMETER;
  51. }
  52. else
  53. {
  54. PACPITABINFO pTabInfo = (PACPITABINFO)pdioc->lpvOutBuffer;
  55. if ((pTabInfo->dwPhyAddr = AcpiFindTable(pTabInfo->dwTabSig, NULL)) != 0)
  56. {
  57. AcpiCopyROM(pTabInfo->dwPhyAddr, (PBYTE)&pTabInfo->dh, sizeof(pTabInfo->dh));
  58. }
  59. else
  60. {
  61. DBG_ERR(("WUBIOS_IOCtrl: failed to get table info"));
  62. rc = ERROR_GEN_FAILURE;
  63. }
  64. }
  65. break;
  66. case WUBIOCTL_GET_ACPI_TABLE:
  67. if ((pdioc->lpvInBuffer == NULL) || (pdioc->lpvOutBuffer == NULL) || (pdioc->cbOutBuffer == 0))
  68. {
  69. DBG_ERR(("WUBIOS_IOCtrl: invalid parameter on GetTable"));
  70. rc = ERROR_INVALID_PARAMETER;
  71. }
  72. else
  73. {
  74. AcpiCopyROM((DWORD)pdioc->lpvInBuffer, (PBYTE)pdioc->lpvOutBuffer, pdioc->cbOutBuffer);
  75. }
  76. break;
  77. case WUBIOCTL_GET_SMB_STRUCTSIZE:
  78. if ((pdioc->cbOutBuffer < sizeof(DWORD)) || (pdioc->lpvOutBuffer == NULL))
  79. {
  80. DBG_ERR(("WUBIOS_IOCtrl: invalid parameter on WUBIOCTL_GET_SMB_TABSIZE"));
  81. rc = ERROR_INVALID_PARAMETER;
  82. }
  83. else
  84. {
  85. *((PDWORD)(pdioc->lpvOutBuffer)) = SmbStructSize();
  86. }
  87. break;
  88. case WUBIOCTL_GET_SMB_STRUCT:
  89. if ((pdioc->lpvInBuffer == NULL) || (pdioc->lpvOutBuffer == NULL) || (pdioc->cbOutBuffer == 0))
  90. {
  91. DBG_ERR(("WUBIOS_IOCtrl: invalid parameter on GetTable"));
  92. rc = ERROR_INVALID_PARAMETER;
  93. }
  94. else
  95. {
  96. rc = SmbCopyStruct((DWORD)pdioc->lpvInBuffer, (PBYTE)pdioc->lpvOutBuffer, pdioc->cbOutBuffer);
  97. }
  98. break;
  99. case WUBIOCTL_GET_PNP_OEMID:
  100. if ((pdioc->cbOutBuffer < sizeof(DWORD)) || (pdioc->lpvOutBuffer == NULL))
  101. {
  102. DBG_ERR(("WUBIOS_IOCtrl: invalid parameter on WUBIOCTL_GET_PNP_OEMID"));
  103. rc = ERROR_INVALID_PARAMETER;
  104. }
  105. else
  106. {
  107. *((PDWORD)(pdioc->lpvOutBuffer)) = PnpOEMID();
  108. }
  109. break;
  110. default:
  111. ;
  112. }
  113. EXIT(1, ("WUBIOS_IOCtrl=%x\n", rc));
  114. return rc;
  115. } //WUBIOS_IOCtrl
  116. /***LP CheckSum - Calculate checksum of a buffer
  117. *
  118. * ENTRY
  119. * pb -> buffer
  120. * dwLen - length of buffer
  121. *
  122. * EXIT
  123. * returns checksum
  124. */
  125. BYTE CM_INTERNAL CheckSum(PBYTE pb, DWORD dwLen)
  126. {
  127. TRACENAME("CHECKSUM")
  128. BYTE bChkSum = 0;
  129. ENTER(3, ("CheckSum(pb=%x,Len=%x)\n", pb, dwLen));
  130. while (dwLen > 0)
  131. {
  132. bChkSum = (BYTE)(bChkSum + *pb);
  133. pb++;
  134. dwLen--;
  135. }
  136. EXIT(3, ("CheckSum=%x\n", bChkSum));
  137. return bChkSum;
  138. } //CheckSum