Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame^] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <stdint.h> |
| 4 | |
| 5 | |
| 6 | extern unsigned char findSensor(char); |
| 7 | |
| 8 | struct sensorRES_t { |
| 9 | uint8_t sensor_number; |
| 10 | uint8_t operation; |
| 11 | uint8_t sensor_reading; |
| 12 | uint8_t assert_state7_0; |
| 13 | uint8_t assert_state14_8; |
| 14 | uint8_t deassert_state7_0; |
| 15 | uint8_t deassert_state14_8; |
| 16 | uint8_t event_data1; |
| 17 | uint8_t event_data2; |
| 18 | uint8_t event_data3; |
| 19 | } __attribute__ ((packed)); |
| 20 | |
| 21 | #define ISBITSET(x,y) ((x>>y)&0x01) |
| 22 | #define ASSERTINDEX 0 |
| 23 | #define DEASSERTINDEX 1 |
| 24 | |
| 25 | |
| 26 | extern int updateDbusInterface(uint8_t , const char *, const char *) ; |
| 27 | extern int set_sensor_dbus_state(uint8_t ,const char *, const char *); |
| 28 | |
| 29 | |
| 30 | |
| 31 | // Sensor Type, Offset, function handler, Dbus Method, Assert value, Deassert value |
| 32 | struct lookup_t { |
| 33 | uint8_t sensor_type; |
| 34 | uint8_t offset; |
| 35 | int (*func)(uint8_t, const char *, const char *); |
| 36 | char method[16]; |
| 37 | char assertion[16]; |
| 38 | char deassertion[16]; |
| 39 | }; |
| 40 | |
| 41 | |
| 42 | // This table lists only senors we care about telling dbus about. |
| 43 | // Offset definition cab be found in section 42.2 of the IPMI 2.0 |
| 44 | // spec. Add more if/when there are more items of interest. |
| 45 | lookup_t ipmidbuslookup[] = { |
| 46 | |
| 47 | {0x07, 0x07, set_sensor_dbus_state, "setPresent", "True", "False"}, |
| 48 | {0x07, 0x08, set_sensor_dbus_state, "setFault", "True", "False"}, |
| 49 | {0x0C, 0x06, set_sensor_dbus_state, "setPresent", "True", "False"}, |
| 50 | {0x0C, 0x04, set_sensor_dbus_state, "setFault", "True", "False"}, |
| 51 | {0xFF, 0xFF, NULL, "", "" , ""} |
| 52 | }; |
| 53 | |
| 54 | int findindex(const uint8_t sensor_type, int offset, int *index) { |
| 55 | |
| 56 | int i=0, rc=0; |
| 57 | lookup_t *pTable = ipmidbuslookup; |
| 58 | |
| 59 | do { |
| 60 | |
| 61 | if ( ((pTable+i)->sensor_type == sensor_type) && |
| 62 | ((pTable+i)->offset == offset) ) { |
| 63 | rc = 1; |
| 64 | *index = i; |
| 65 | break; |
| 66 | } |
| 67 | i++; |
| 68 | } while ((pTable+i)->sensor_type != 0xFF); |
| 69 | |
| 70 | return rc; |
| 71 | } |
| 72 | |
| 73 | int shouldReport(sensorRES_t *pRec, uint8_t sensorType, int offset, int assertState) { |
| 74 | |
| 75 | int index; |
| 76 | char *pState; |
| 77 | lookup_t *pTable = ipmidbuslookup; |
| 78 | |
| 79 | if (findindex(sensorType, offset, &index)) { |
| 80 | |
| 81 | if (assertState == ASSERTINDEX) { |
| 82 | pState = (pTable+index)->assertion; |
| 83 | } else { |
| 84 | pState = (pTable+index)->deassertion; |
| 85 | } |
| 86 | (*((pTable+index)->func))(pRec->sensor_number, (pTable+index)->method, pState); |
| 87 | } |
| 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | int updateSensorRecordFromSSRAESC(const void *record) { |
| 94 | |
| 95 | sensorRES_t *pRec = (sensorRES_t *) record; |
| 96 | unsigned char stype; |
| 97 | int index, i=0; |
| 98 | |
| 99 | stype = findSensor(pRec->sensor_number); |
| 100 | |
| 101 | // Scroll through each bit position . Determine |
| 102 | // if any bit is either asserted or Deasserted. |
| 103 | for(i=0;i<8;i++) { |
| 104 | if (ISBITSET(pRec->assert_state7_0,i)) { |
| 105 | shouldReport(pRec, stype, i, ASSERTINDEX); |
| 106 | } |
| 107 | if (ISBITSET(pRec->assert_state14_8,i)) { |
| 108 | shouldReport(pRec, stype, i+8, ASSERTINDEX); |
| 109 | } |
| 110 | if (ISBITSET(pRec->deassert_state7_0,i)) { |
| 111 | shouldReport(pRec, stype, i, DEASSERTINDEX); |
| 112 | } |
| 113 | if (ISBITSET(pRec->deassert_state14_8,i)) { |
| 114 | shouldReport(pRec, stype, i+8, DEASSERTINDEX); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | return 0; |
| 119 | } |