Guest User

Untitled

a guest
Jul 7th, 2011
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.31 KB | None | 0 0
  1. /*-
  2.  * Copyright (c) 2009 Andriy Gapon <[email protected]>
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  *
  14.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS AS IS'' AND
  15.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  18.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  20.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  21.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  22.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  23.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  24.  * SUCH DAMAGE.
  25.  */
  26.  
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <fcntl.h>
  31. #include <unistd.h>
  32. #include <stdint.h>
  33. #include <sys/ioctl.h>
  34. #include <mei.h>
  35.  
  36. struct therm_sensor
  37. {
  38.     int8_t valid;
  39.     int32_t value;
  40. } __attribute__((packed));
  41.  
  42. struct volt_sensor
  43. {
  44.     int8_t valid;
  45.     int32_t value;
  46. } __attribute__((packed));
  47.  
  48. struct fan_sensor
  49. {
  50.     int8_t valid;
  51.     int16_t value;
  52. } __attribute__((packed));
  53.  
  54. #define THERM_SENSOR_COUNT  12
  55. struct therm_data
  56. {
  57.     int8_t status;
  58.     struct therm_sensor data[THERM_SENSOR_COUNT];
  59. } __attribute__((packed));
  60.  
  61. #define VOLT_SENSOR_COUNT   8
  62. struct volt_data
  63. {
  64.     int8_t status;
  65.     struct volt_sensor data[VOLT_SENSOR_COUNT];
  66. } __attribute__((packed));
  67.  
  68. #define FAN_SENSOR_COUNT    8
  69. struct fan_data
  70. {
  71.     int8_t status;
  72.     struct fan_sensor data[FAN_SENSOR_COUNT];
  73. } __attribute__((packed));
  74.  
  75. struct qst_cmd
  76. {
  77.     uint8_t cmd;
  78.     uint16_t in_len;
  79.     uint16_t out_len;
  80. } __attribute__((packed));
  81.  
  82. #define QST_THERMAL_CMD     0x12
  83. static const struct qst_cmd therm_cmd = { QST_THERMAL_CMD, 0, sizeof(struct therm_data) };
  84.  
  85. #define QST_VOLT_CMD        0x58
  86. static const struct qst_cmd volt_cmd = { QST_VOLT_CMD, 0, sizeof(struct volt_data) };
  87.  
  88. #define QST_FAN_CMD     0x37
  89. static const struct qst_cmd fan_cmd = { QST_FAN_CMD, 0, sizeof(struct fan_data) };
  90.  
  91. const char * const temp_names[THERM_SENSOR_COUNT] = {
  92.     "CPU",
  93.     "MB1",
  94.     NULL,
  95.     "MB2",
  96.     "ICH",
  97.     "MCH",
  98.     NULL,
  99.     NULL,
  100.     NULL,
  101.     NULL,
  102.     NULL,
  103.     NULL,
  104. };
  105.  
  106. const char * const volt_names[VOLT_SENSOR_COUNT] = {
  107.     "12P",
  108.     "50P",
  109.     "33",
  110.     "15",
  111.     "C0",
  112.     NULL,
  113.     NULL,
  114.     NULL,
  115. };
  116.  
  117. const char * const fan_names[FAN_SENSOR_COUNT] = {
  118.     "CPU",
  119.     "INL",
  120.     "OUTL",
  121.     "AUX",
  122.     NULL,
  123.     NULL,
  124.     NULL,
  125.     NULL,
  126. };
  127.  
  128.  
  129. #define SOME_UUID { \
  130.     0xB9, 0x05, 0x52, 0x6B, \
  131.     0x85, 0x81, 0x19, 0x45, \
  132.     0xB8, 0x89, 0xD9, 0x87, \
  133.     0x24, 0xB5, 0x86, 0x07  \
  134. };
  135.  
  136.  
  137. int main()
  138. {
  139.     int fd;
  140.     int rc;
  141.     int i;
  142.     struct mei_connect_client_data data=SOME_UUID;
  143.  
  144.     fd = open("/dev/mei0", O_RDWR);
  145.     if (fd < 0) {
  146.         perror("/dev/mei0\n");
  147.         return 1;
  148.     }
  149.     rc = ioctl(fd, IOCTL_MEI_CONNECT_CLIENT, &data);
  150.     if (rc < 0) {
  151.         perror("ioctl IOCTL_MEI_CONNECT_CLIENT failed\n");
  152.         return 1;
  153.     }
  154.     printf("Ver=%d, MaxLen=%ld\n",
  155.             data.out_client_properties.protocol_version,
  156.             data.out_client_properties.max_msg_length);
  157.    
  158.     /* Request temp. */
  159.     struct therm_data therm_data;
  160.     rc = write(fd, &therm_cmd, sizeof(therm_cmd));
  161.     if (rc < 0) {
  162.         perror("therm write");
  163.         return 1;
  164.     }
  165.  
  166.     rc = read(fd, &therm_data, sizeof(therm_data));
  167.     if (rc < 0) {
  168.         perror("therm read");
  169.         return 1;
  170.     }
  171.     for (i = 0; i < THERM_SENSOR_COUNT; i++) {
  172.         if (therm_data.data[i].valid) {
  173.             int32_t value = therm_data.data[i].value;
  174.             printf("TEMP");
  175.             if (temp_names[i])
  176.                 printf("%s", temp_names[i]);
  177.             else
  178.                 printf("%02d", i);
  179.             printf("\t:\t%d.%02d\n", value / 100, abs(value) % 100);
  180.         }
  181.     }
  182.  
  183.     /* Request fans */
  184.     struct fan_data fan_data;
  185.     rc = write(fd, &fan_cmd, sizeof(fan_cmd));
  186.     if (rc < 0) {
  187.         perror("fan write");
  188.         return 1;
  189.     }
  190.  
  191.     rc = read(fd, &fan_data, sizeof(fan_data));
  192.     if (rc < 0) {
  193.         perror("fan read");
  194.         return 1;
  195.     }
  196.     for (i = 0; i < FAN_SENSOR_COUNT; i++) {
  197.         if (fan_data.data[i].valid) {
  198.             int32_t value = fan_data.data[i].value;
  199.             printf("FAN");
  200.             if (fan_names[i])
  201.                 printf("%s", fan_names[i]);
  202.             else
  203.                 printf("%02d", i);
  204.             printf("\t:\t%d\n", value);
  205.         }
  206.     }
  207.  
  208.     /* Request volts. */
  209.     struct volt_data volt_data;
  210.     rc = write(fd, &volt_cmd, sizeof(volt_cmd));
  211.     if (rc < 0) {
  212.         perror("volts write");
  213.         return 1;
  214.     }
  215.  
  216.     rc = read(fd, &volt_data, sizeof(volt_data));
  217.     if (rc < 0) {
  218.         perror("volts read");
  219.         return 1;
  220.     }
  221.     for (i = 0; i < VOLT_SENSOR_COUNT; i++) {
  222.         if (volt_data.data[i].valid) {
  223.             int32_t value = volt_data.data[i].value;
  224.             printf("V");
  225.             if (volt_names[i])
  226.                 printf("%s", volt_names[i]);
  227.             else
  228.                 printf("%02d", i);
  229.             printf("\t:\t%+d.%03d\n", value / 1000, abs(value) % 1000);
  230.         }
  231.     }
  232.  
  233.     close(fd);
  234.     return 0;
  235. }
Advertisement
Add Comment
Please, Sign In to add comment