Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 1 | #include "sensorhandler.h" |
| 2 | #include "ipmid-api.h" |
| 3 | #include <stdio.h> |
| 4 | #include <string.h> |
| 5 | #include <stdint.h> |
| 6 | |
| 7 | |
| 8 | void register_netfn_sen_functions() __attribute__((constructor)); |
| 9 | |
| 10 | |
| 11 | struct sensor_data_t { |
| 12 | uint8_t sennum; |
| 13 | } __attribute__ ((packed)) ; |
| 14 | |
| 15 | unsigned char g_sensortype [][2] = { |
| 16 | {0xc7, 58}, |
| 17 | {0x01, 113}, |
| 18 | {0xc7, 56}, |
| 19 | {0x01, 114}, |
| 20 | {0xc6, 54}, |
| 21 | {0x07, 40}, |
| 22 | {0xC1, 121}, |
| 23 | {0xC2, 137}, |
| 24 | {0x07, 36}, |
| 25 | {0x07, 43}, |
| 26 | {0xC1, 122}, |
| 27 | {0xC1, 119}, |
| 28 | {0x01, 12}, |
| 29 | {0x01, 111}, |
| 30 | {0x01, 116}, |
| 31 | {0xC1, 127}, |
| 32 | {0xC2, 134}, |
| 33 | {0xC2, 130}, |
| 34 | {0xc, 33}, |
| 35 | {0xC1, 125}, |
| 36 | {0x01, 115}, |
| 37 | {0x22, 4}, |
| 38 | {0xC2, 138}, |
| 39 | {0x01, 108}, |
| 40 | {0x01, 102}, |
| 41 | {0xc, 46}, |
| 42 | {0x7, 11}, |
| 43 | {0xC1, 120}, |
| 44 | {0x07, 39}, |
| 45 | {0x07, 42}, |
| 46 | {0x5, 21}, |
| 47 | {0xC2, 131}, |
| 48 | {0xc1, 48}, |
| 49 | {0x12, 53}, |
| 50 | {0xC1, 124}, |
| 51 | {0x01, 117}, |
| 52 | {0xC1, 126}, |
| 53 | {0xf, 5}, |
| 54 | {0x23, 0}, |
| 55 | {0xC2, 139}, |
| 56 | {0x07, 34}, |
| 57 | {0x09, 146}, |
| 58 | {0x02, 178}, |
| 59 | {0xC2, 140}, |
| 60 | {0xC1, 118}, |
| 61 | {0xC2, 133}, |
| 62 | {0x07, 38}, |
| 63 | {0xC2, 143}, |
| 64 | {0x01, 101}, |
| 65 | {0xc3, 9}, |
| 66 | {0x7, 10}, |
| 67 | {0xc2, 51}, |
| 68 | {0x01, 109}, |
| 69 | {0xc, 32}, |
| 70 | {0x7, 8}, |
| 71 | {0xC1, 129}, |
| 72 | {0x01, 112}, |
| 73 | {0x01, 107}, |
| 74 | {0x07, 37}, |
| 75 | {0x07, 44}, |
| 76 | {0x1f, 50}, |
| 77 | {0xC2, 144}, |
| 78 | {0xc7, 52}, |
| 79 | {0xC2, 141}, |
| 80 | {0x01, 106}, |
| 81 | {0x01, 110}, |
| 82 | {0x01, 103}, |
| 83 | {0x9, 28}, |
| 84 | {0x07, 35}, |
| 85 | {0xc7, 55}, |
| 86 | {0x03, 179}, |
| 87 | {0x07, 41}, |
| 88 | {0xc, 30}, |
| 89 | {0x01, 100}, |
| 90 | {0xC1, 128}, |
| 91 | {0xC2, 135}, |
| 92 | {0x01, 105}, |
| 93 | {0x7, 47}, |
| 94 | {0xC2, 145}, |
| 95 | {0xc7, 57}, |
| 96 | {0x01, 104}, |
| 97 | {0x07, 45}, |
| 98 | {0xC2, 132}, |
| 99 | {0xc4, 49}, |
| 100 | {0xC1, 123}, |
| 101 | {0xC2, 142}, |
| 102 | {0x01, 13}, |
| 103 | {0xC2, 136}, |
| 104 | {0xc, 31}, |
| 105 | {0xff,0xff} |
| 106 | }; |
| 107 | |
| 108 | |
| 109 | unsigned char findSensor(char sensor_number) { |
| 110 | |
| 111 | int i=0; |
| 112 | |
| 113 | // TODO : This function should actually call |
| 114 | // a dbus object and have it return the data |
| 115 | // it is not ready yet so use a Palmetto |
| 116 | // based lookup table for now. The g_sensortype |
| 117 | // can be removed once the dbus method exists |
| 118 | while (g_sensortype[i][0] != 0xff) { |
| 119 | if (g_sensortype[i][1] == sensor_number) { |
| 120 | break; |
| 121 | } else { |
| 122 | i++; |
| 123 | } |
| 124 | |
| 125 | } |
| 126 | |
| 127 | return g_sensortype[i][0]; |
| 128 | |
| 129 | } |
| 130 | |
| 131 | ipmi_ret_t ipmi_sen_get_sensor_type(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 132 | ipmi_request_t request, ipmi_response_t response, |
| 133 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 134 | { |
| 135 | sensor_data_t *reqptr = (sensor_data_t*)request; |
| 136 | ipmi_ret_t rc = IPMI_CC_OK; |
| 137 | |
| 138 | printf("IPMI GET_SENSOR_TYPE [0x%02X]\n",reqptr->sennum); |
| 139 | |
| 140 | // TODO Not sure what the System-event-sensor is suppose to return |
| 141 | // need to ask Hostboot team |
| 142 | unsigned char buf[] = {0x00,0x6F}; |
| 143 | |
| 144 | buf[0] = findSensor(reqptr->sennum); |
| 145 | |
| 146 | *data_len = sizeof(buf); |
| 147 | memcpy(response, &buf, *data_len); |
| 148 | |
| 149 | |
| 150 | |
| 151 | return rc; |
| 152 | } |
| 153 | |
| 154 | |
| 155 | |
| 156 | // TODO: Saves the sensor information to a file in /tmp. This |
| 157 | // will need to change to calling the correct method |
| 158 | // once it exists in the stack. |
| 159 | ipmi_ret_t ipmi_sen_set_sensor(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 160 | ipmi_request_t request, ipmi_response_t response, |
| 161 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 162 | { |
| 163 | FILE *fp; |
| 164 | char string[16]; |
| 165 | sensor_data_t *reqptr = (sensor_data_t*)request; |
| 166 | ipmi_ret_t rc = IPMI_CC_OK; |
| 167 | unsigned short rlen; |
| 168 | |
| 169 | rlen = (unsigned short) *data_len - 1; |
| 170 | |
| 171 | sprintf(string, "%s%02x", "/tmp/sen", reqptr->sennum); |
| 172 | |
| 173 | printf("IPMI SET_SENSOR [%s]\n",string); |
| 174 | |
| 175 | if ((fp = fopen(string, "wb")) != NULL) { |
| 176 | fwrite(reqptr+1,rlen,1,fp); |
| 177 | fclose(fp); |
| 178 | } else { |
| 179 | fprintf(stderr, "Error trying to write to sensor file %s\n",string); |
| 180 | ipmi_ret_t rc = IPMI_CC_INVALID; |
| 181 | } |
| 182 | |
| 183 | *data_len=0; |
| 184 | |
| 185 | |
| 186 | return rc; |
| 187 | } |
| 188 | |
| 189 | ipmi_ret_t ipmi_sen_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 190 | ipmi_request_t request, ipmi_response_t response, |
| 191 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 192 | { |
| 193 | ipmi_ret_t rc = IPMI_CC_OK; |
| 194 | |
| 195 | printf("IPMI S/E Wildcard Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd); |
| 196 | *data_len = 0; |
| 197 | |
| 198 | return rc; |
| 199 | } |
| 200 | |
| 201 | |
| 202 | void register_netfn_sen_functions() |
| 203 | { |
| 204 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_WILDCARD); |
| 205 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_WILDCARD, NULL, ipmi_sen_wildcard); |
| 206 | |
| 207 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE); |
| 208 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE, NULL, ipmi_sen_get_sensor_type); |
| 209 | |
| 210 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_SET_SENSOR); |
| 211 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_SET_SENSOR, NULL, ipmi_sen_set_sensor); |
| 212 | return; |
| 213 | } |