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.

313 lines
7.8 KiB

  1. /*++
  2. Copyright (c) 2000,2001 Microsoft Corporation
  3. Module Name:
  4. smbdev.c
  5. Abstract: This module contains SMBus Device related functions.
  6. Environment:
  7. User mode
  8. Author:
  9. Michael Tsang (MikeTs) 23-Jan-2001
  10. Revision History:
  11. --*/
  12. #include "pch.h"
  13. #ifdef SYSACC
  14. /*++
  15. @doc INTERNAL
  16. @func BOOL | GetSMBDevInfo | Call the SysAccess driver to get the
  17. SMBus device info.
  18. @parm IN UCHAR | bDevAddr | SMB device address.
  19. @parm IN PSMBCMD_INFO | SmbCmd | Points to the SMB device command.
  20. @parm OUT PBYTE | pbBuff | To hold the device info.
  21. @rvalue SUCCESS | Returnes TRUE.
  22. @rvalue FAILURE | Returnes FALSE.
  23. --*/
  24. BOOL
  25. GetSMBDevInfo(
  26. IN UCHAR bDevAddr,
  27. IN PSMBCMD_INFO SmbCmd,
  28. OUT PBYTE pbBuff
  29. )
  30. {
  31. TRACEPROC("GetSMBDevInfo", 3)
  32. BOOL rc;
  33. SMB_REQUEST SmbReq;
  34. DWORD dwcbReturned;
  35. TRACEENTER(("(DevAddr=%x,SmbCmd=%p,Cmd=%s,pbBuff=%p)\n",
  36. bDevAddr, SmbCmd, SmbCmd->pszLabel, pbBuff));
  37. TRACEASSERT(ghSysAcc != INVALID_HANDLE_VALUE);
  38. TRACEASSERT(SmbCmd->bProtocol <= SMB_MAXIMUM_PROTOCOL);
  39. SmbReq.Status = SMB_UNKNOWN_FAILURE;
  40. SmbReq.Address = bDevAddr;
  41. SmbReq.Protocol = SmbCmd->bProtocol;
  42. SmbReq.Command = SmbCmd->bCmd;
  43. rc = DeviceIoControl(ghSysAcc,
  44. IOCTL_SYSACC_SMBUS_REQUEST,
  45. &SmbReq,
  46. sizeof(SmbReq),
  47. &SmbReq,
  48. sizeof(SmbReq),
  49. &dwcbReturned,
  50. NULL);
  51. if (rc && (SmbReq.Status == SMB_STATUS_OK))
  52. {
  53. if (SmbReq.Protocol == SMB_READ_BLOCK)
  54. {
  55. PBLOCK_DATA Block = (PBLOCK_DATA)pbBuff;
  56. Block->bBlockLen = SmbReq.BlockLength;
  57. memset(Block->BlockData, 0, sizeof(Block->BlockData));
  58. memcpy(Block->BlockData, SmbReq.Data, SmbReq.BlockLength);
  59. }
  60. else
  61. {
  62. memcpy(pbBuff, SmbReq.Data, SmbCmd->iDataSize);
  63. }
  64. }
  65. else
  66. {
  67. ErrorMsg(IDSERR_SYSACC_DEVIOCTL, GetLastError());
  68. }
  69. TRACEEXIT(("=%x (Data=%x)\n", rc, *((PWORD)pbBuff)));
  70. return rc;
  71. } //GetSMBDevInfo
  72. /*++
  73. @doc INTERNAL
  74. @func BOOL | DisplaySMBDevInfo | Display SMBus device info.
  75. @parm IN HWND | hwndEdit | Edit window handle.
  76. @parm IN PSMBCMD_INFO | SmbCmd | Points to the SMB device command.
  77. @parm IN PBYTE | pbBuff | SMB device data to display.
  78. @rvalue SUCCESS | Returns TRUE if it handles it.
  79. @rvalue FAILURE | Returns FALSE if it doesn't handle it.
  80. --*/
  81. BOOL
  82. DisplaySMBDevInfo(
  83. IN HWND hwndEdit,
  84. IN PSMBCMD_INFO SmbCmd,
  85. IN PBYTE pbBuff
  86. )
  87. {
  88. TRACEPROC("DisplaySMBDevInfo", 3)
  89. BOOL rc = TRUE;
  90. WORD wData;
  91. BYTE bData;
  92. char *pszUnit = SmbCmd->pszUnit? SmbCmd->pszUnit: "";
  93. TRACEENTER(("(hwndEdit=%x,SmbCmd=%p,Cmd=%s,pbBuff=%p)\n",
  94. hwndEdit, SmbCmd, SmbCmd->pszLabel, pbBuff));
  95. switch (SmbCmd->bType)
  96. {
  97. case TYPEF_BYTE_HEX:
  98. bData = *pbBuff;
  99. EditPrintf(hwndEdit,
  100. " 0x%02x %s\r\n",
  101. bData,
  102. pszUnit);
  103. break;
  104. case TYPEF_BYTE_DEC:
  105. bData = *pbBuff;
  106. EditPrintf(hwndEdit,
  107. "%6d %s\r\n",
  108. bData,
  109. pszUnit);
  110. break;
  111. case TYPEF_BYTE_INT:
  112. bData = *pbBuff;
  113. EditPrintf(hwndEdit,
  114. "%6d %s\r\n",
  115. (signed char)bData,
  116. pszUnit);
  117. break;
  118. case TYPEF_WORD_HEX:
  119. wData = *((PWORD)pbBuff);
  120. EditPrintf(hwndEdit,
  121. "0x%04x %s\r\n",
  122. wData,
  123. pszUnit);
  124. break;
  125. case TYPEF_WORD_DEC:
  126. wData = *((PWORD)pbBuff);
  127. EditPrintf(hwndEdit,
  128. "%6d %s\r\n",
  129. wData,
  130. pszUnit);
  131. break;
  132. case TYPEF_WORD_INT:
  133. wData = *((PWORD)pbBuff);
  134. EditPrintf(hwndEdit,
  135. "%6d %s\r\n",
  136. (SHORT)wData,
  137. pszUnit);
  138. break;
  139. case TYPEF_BYTE_BITS:
  140. bData = *pbBuff;
  141. EditPrintf(hwndEdit, " 0x%02x", bData);
  142. DisplayDevBits(hwndEdit,
  143. SmbCmd->dwData,
  144. (PSZ *)SmbCmd->pvData,
  145. (DWORD)bData);
  146. EditPrintf(hwndEdit, "\r\n");
  147. break;
  148. case TYPEF_WORD_BITS:
  149. wData = *((PWORD)pbBuff);
  150. EditPrintf(hwndEdit, "0x%04x", wData);
  151. DisplayDevBits(hwndEdit,
  152. SmbCmd->dwData,
  153. (PSZ *)SmbCmd->pvData,
  154. (DWORD)wData);
  155. EditPrintf(hwndEdit, "\r\n");
  156. break;
  157. case TYPEF_BLOCK_STRING:
  158. EditPrintf(hwndEdit,
  159. "\"%.*s\"\r\n",
  160. ((PBLOCK_DATA)pbBuff)->bBlockLen,
  161. ((PBLOCK_DATA)pbBuff)->BlockData);
  162. break;
  163. case TYPEF_BLOCK_BUFFER:
  164. {
  165. PBLOCK_DATA BlockData = (PBLOCK_DATA)pbBuff;
  166. char szSpaces[32];
  167. int i, iLen;
  168. iLen = lstrlenA(SmbCmd->pszLabel);
  169. for (i = 0; i < iLen; ++i)
  170. {
  171. szSpaces[i] = ' ';
  172. }
  173. szSpaces[i] = '\0';
  174. for (i = 0;
  175. (i < BlockData->bBlockLen) &&
  176. (i < sizeof(BlockData->BlockData));
  177. ++i)
  178. {
  179. if ((i > 0) && ((i % 8) == 0))
  180. {
  181. EditPrintf(hwndEdit, "\r\n%s ", szSpaces);
  182. }
  183. EditPrintf(hwndEdit, " %02x", BlockData->BlockData[i]);
  184. }
  185. EditPrintf(hwndEdit, "\r\n");
  186. break;
  187. }
  188. default:
  189. rc = FALSE;
  190. }
  191. TRACEEXIT(("=%x\n", rc));
  192. return rc;
  193. } //DisplaySMBDevInfo
  194. /*++
  195. @doc INTERNAL
  196. @func VOID | DisplayDevBits | Display device bits info.
  197. @parm IN HWND | hwndEdit | Edit window handle.
  198. @parm IN DWORD | dwBitMask | Bit mask of relevant data bits.
  199. @parm IN PSZ * | apszBitNames | Points to array of bit names.
  200. @parm IN DWORD | dwData | device data.
  201. @rvalue None.
  202. --*/
  203. VOID
  204. DisplayDevBits(
  205. IN HWND hwndEdit,
  206. IN DWORD dwBitMask,
  207. IN PSZ *apszBitNames,
  208. IN DWORD dwData
  209. )
  210. {
  211. TRACEPROC("DisplayDevBits", 3)
  212. ULONG dwBit;
  213. int i;
  214. TRACEENTER(("(hwndEdit=%x,BitMask=%x,apszBitNames=%p,Data=%x)\n",
  215. hwndEdit, dwBitMask, apszBitNames, dwData));
  216. for (dwBit = 0x80000000, i = 0; dwBit != 0; dwBit >>= 1)
  217. {
  218. if (dwBitMask & dwBit)
  219. {
  220. if (dwData & dwBit)
  221. {
  222. EditPrintf(hwndEdit, ",%s", apszBitNames[i]);
  223. }
  224. i++;
  225. }
  226. }
  227. TRACEEXIT(("!\n"));
  228. return;
  229. } //DisplayDevBits
  230. /*++
  231. @doc INTERNAL
  232. @func VOID | EditPrintf | Append text to edit control.
  233. @parm IN HWND | hwndEdit | Edit window handle.
  234. @parm IN PSZ | pszFormat | Points to format string.
  235. @parm ... | Arguments
  236. @rvalue None.
  237. --*/
  238. VOID
  239. __cdecl
  240. EditPrintf(
  241. IN HWND hwndEdit,
  242. IN PSZ pszFormat,
  243. ...
  244. )
  245. {
  246. TRACEPROC("EditPrintf", 3)
  247. va_list arglist;
  248. char szText[256];
  249. TRACEENTER(("(hwndEdit=%x,Format=%s)\n", hwndEdit, pszFormat));
  250. va_start(arglist, pszFormat);
  251. vsprintf(szText, pszFormat, arglist);
  252. va_end(arglist);
  253. SendMessage(hwndEdit, EM_SETSEL, -1, -1);
  254. SendMessage(hwndEdit, EM_REPLACESEL, 0, (LPARAM)szText);
  255. TRACEEXIT(("!\n"));
  256. return;
  257. } //EditPrintf
  258. #endif //ifdef SYSACC