diff -rup Cmds_sel/lib/ipmi_delloem.c patch2/lib/ipmi_delloem.c --- Cmds_sel/lib/ipmi_delloem.c 2008-02-21 02:49:53.000000000 -0600 +++ patch2/lib/ipmi_delloem.c 2008-02-21 02:32:44.000000000 -0600 @@ -20,6 +20,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -49,6 +52,11 @@ int ipmi_sel_sysinfo(struct ipmi_intf *i int ipmi_sel_print(struct ipmi_intf * intf, uint16_t count, int printOption); static uint16_t ipmi_sel_reserve(struct ipmi_intf * intf); +static int ipmi_sensor_print(SDRType* pSdr, int* pSensorIndex, struct ipmi_intf * intf); +int +ipmi_sensor_get_sensor_reading(unsigned char sensorOwner, unsigned char sensorNumber, + IPMISensorReadingType* sensorReadingData, + void* x); SDRType* ipmi_sdr_get_test(struct ipmi_intf *intf, uint16_t reserveId, uint8_t* datapt, uint16_t recordId); SDRType* ipmi_sdr_get_test2(struct ipmi_intf *intf, uint16_t reserveId, uint8_t* datapt, uint16_t recordId); SDRType* ipmi_sdr_get_test3(struct ipmi_intf *intf, uint16_t reserveId, uint8_t* datapt, uint16_t recordId); @@ -183,7 +191,7 @@ int ipmi_sel_print(struct ipmi_intf * in totalEntries = ((rsp->data[2] << 8) | rsp->data[1]); - if (printOption == SEL_PRINT_FIRST) { + if (printOption == SEL_PRINT_FIRST){ if(count > totalEntries) last = totalEntries; @@ -710,9 +718,261 @@ ipmi_sel_reserve(struct ipmi_intf * intf return (rsp->data[0] | (rsp->data[1] << 8)); } +static int ipmi_sensor_print(SDRType* pSdr, int* pSensorIndex, struct ipmi_intf * intf) +{ + CSDDUSERAPI pfnApiList; + int count; + short typeSize; + short nameSize; + short unitSize; + unsigned char readingType; + unsigned char type; + char szUnits[16]; + long sensorReading; + unsigned short sensorState; + short readSize; + short stateSize; + unsigned char thresholdMask; + SensorThrInfo thrData; + SensorThrStrType thrStrData; + char szState[SENSOR_STATE_STR_SIZE]; + short severity; + char szName[SENSOR_NAME_STR_SIZE]; + char szType[SENSOR_TYPE_STR_SIZE]; + char szReading[SENSOR_READING_STR_SIZE]; + CSDDSensorList list; + int status = COMMON_STATUS_BAD_PARAMETER; + IPMISDR* pSdrPrint; + + + /* Clear API structure */ + memset(&pfnApiList, 0, sizeof(CSDDUSERAPI)); + + pfnApiList.GetFirstSDR = sdr_get_first; + pfnApiList.GetNextSDR = sdr_get_next; + pfnApiList.GetSensorReading = ipmi_sensor_get_sensor_reading; + + CSDDAttach(&pfnApiList); + + + if (NULL != pSdr) + { + memset((void*)&list, 0, sizeof(CSDDSensorList)); + status = CSDDGetSensorsTobeMonitored(&list, pSdr, NULL, (void*)intf); + /* A failure here means no sensor present/disable for this SDR */ + if (COMMON_STATUS_SUCCESS == status) + { + for(count = 0; count < list.sensorCount; count++) + { + typeSize = SENSOR_TYPE_STR_SIZE; + nameSize = SENSOR_NAME_STR_SIZE; + unitSize = 16; + stateSize = SENSOR_STATE_STR_SIZE; + readSize = SENSOR_READING_STR_SIZE; + /* initialize string buffers */ + szState[0] = 0; + szType[0] = 0; + szReading[0] = 0; + szUnits[0] = 0; + + /* GetSensor Static Information */ + status = CSDDGetSensorStaticInformation(pSdr,0,&readingType,&type, + &nameSize, szName, &typeSize, szType, &unitSize, + szUnits, list.sensorNumber[count], (void*)intf); + + + /* Did we encounter an error? */ + if (COMMON_STATUS_SUCCESS != status) + { + printf("Error1\n"); + break; + } + memset(&sensorReading, 0, sizeof(sensorReading)); + status = CSDDGetSensorDynamicInformation(pSdr, &sensorReading, + &sensorState, &readSize, szReading, &stateSize, + szState, &severity, list.sensorNumber[count], (void*)intf); + + /* Did we encounter an error? */ + if (COMMON_STATUS_SUCCESS != status) + { + printf("Error getting dynamic information: %x\n", status); + break; + } + + /* Output common decoded data */ + + (*pSensorIndex) ++; + pSdrPrint = (IPMISDR*)pSdr; + if (pSdrPrint->type.type1.entityID != 0x22) { + + if (IPMI_READING_TYPE_THRESHOLD == readingType) + { + printf("Index : %d\n", *pSensorIndex); + printf("Sensor ID Number : %d\n", pSdrPrint->type.type1.sensorNum); + printf("Status : %s\n", g_StatusTable[severity]); + printf("Probe Name : %s\n", szName); + printf("Reading : %s %s\n", szReading, szUnits); + memset((void*)&thrData, 0, sizeof(SensorThrInfo)); + memset((void*)&thrStrData, 0, sizeof(SensorThrStrType)); + thresholdMask = 0; + + status = CSDDGetSensorThresholds(pSdr, &thresholdMask, &thrData, + &thrStrData, 0, (void*)intf); + + if (COMMON_STATUS_SUCCESS != status) + { + printf("Error3\n"); + break; + } + + printf ("Minimum Warning Threshold : %s %s\n", thrStrData.lncThr,szUnits); + printf ("Maximum Warning Threshold : %s %s\n", thrStrData.uncThr,szUnits); + printf ("Minimum Failure Threshold : %s %s\n", thrStrData.lcThr,szUnits); + printf ("Maximum Failure Threshold : %s %s\n", thrStrData.ucThr,szUnits); + + + } + else + { + printf("Index : %d\n", *pSensorIndex); + printf("Sensor ID Number : %d\n", pSdrPrint->type.type1.sensorNum); + printf("Status : %s\n", szState); + printf("Probe Name : %s\n", szName); + } + printf("\n"); + } + } + } + } + CSDDDetach(); + return status; +} + + +static int ipmi_sensor(struct ipmi_intf* intf, uint8_t sensorNumIn) +{ + int rc = 0; + int sensorIndex = 0; + int* pSensorIndex; + pSensorIndex = &sensorIndex; + IPMISDR* pRecord; + int i; + + rc = ipmi_sdr_build_table(intf); + if (rc == -1) { + /*printf("sniff1 rc = %x\n", rc);*/ + return rc; + } + + i = 0; + while (i < totalSDRCount) { + pRecord = (IPMISDR*)SDR[i].data; + if (sensorNumIn == 0xff && rc != -1) { + rc = ipmi_sensor_print((SDRType*)SDR[i].data, &sensorIndex, intf); + }else if (pRecord->type.type1.sensorNum == sensorNumIn){ + rc = ipmi_sensor_print((SDRType*)SDR[i].data, &sensorIndex, intf); + } + i++; + } + + + return rc; +} + + +static int ipmi_sensor_get(struct ipmi_intf* intf, int argc, char **argv) +{ + int rc = 0; + int sensorIndex = 0; + int* pSensorIndex; + pSensorIndex = &sensorIndex; + IPMISDR* pRecord; + int i; + int current_arg; + int currIdInt; + uint8_t currId; + + rc = ipmi_sdr_build_table(intf); + if (rc == -1) { + return rc; + } + + current_arg = 0; + while (current_arg < argc) { + make_int(argv[current_arg],&currIdInt); + currId = currIdInt; + i = 0; + while (i < totalSDRCount) { + pRecord = (IPMISDR*)SDR[i].data; + if (pRecord->type.type1.sensorNum == currId){ + rc = ipmi_sensor_print((SDRType*)SDR[i].data, &sensorIndex, intf); + } + i++; + } + current_arg++; + } + + + + + return rc; +} + +/* ipmi_sdr_get_sensor_reading - retrieve a raw sensor reading + * + * @intf: ipmi interface + * @sensor: sensor id + * + * returns ipmi response structure + */ +int +ipmi_sensor_get_sensor_reading(unsigned char sensorOwner, unsigned char sensorNumber, + IPMISensorReadingType* sensorReadingData, + void* x) +{ + struct ipmi_rq req; + struct ipmi_rs * rsp; + struct ipmi_intf * intf; + int rc = 0; + uint8_t save_addr; + + + + intf = ((struct ipmi_intf*) x); + + memset(&req, 0, sizeof (req)); + req.msg.netfn = IPMI_NETFN_SE; + req.msg.cmd = GET_SENSOR_READING; + req.msg.data = &sensorNumber; + req.msg.data_len = 1; + + rsp = intf->sendrecv(intf, &req); + if (rsp == NULL) { + return 1; + } else if (rsp->ccode > 0) { + return 1; + } + + memcpy(sensorReadingData, rsp->data, sizeof(IPMISensorReadingType)); + + /* if there is an error transmitting ipmi command, return error*/ + if (rsp->ccode != 0) { + rc = 1; + } + + /* if sensor messages are disabled, return error*/ + if ((!(rsp->data[1]& 0xC0)) || ((rsp->data[1] & 0x20))) { + rc =1; + } + + + + return rc; +} + static int ipmi_powermgmt(struct ipmi_intf* intf) { time_t now; @@ -944,6 +1204,17 @@ ipmi_sel_usage(void) lprintf(LOG_NOTICE, ""); } +static void +ipmi_sensor_usage(void) +{ + lprintf(LOG_NOTICE, ""); + lprintf(LOG_NOTICE, " sensor list"); + lprintf(LOG_NOTICE, " Lists status, reading, and thresholds for sensors"); + lprintf(LOG_NOTICE, ""); + lprintf(LOG_NOTICE, " sensor get "); + lprintf(LOG_NOTICE, " Shows information for specified sensor"); + lprintf(LOG_NOTICE, ""); +} static void ipmi_powermonitor_usage(void) @@ -987,7 +1258,7 @@ ipmi_delloem_main(struct ipmi_intf * int usage(); return 0; } - // start sel processing + /* start sel processing*/ else if (strncmp(argv[current_arg], "sel\0", 4) == 0) { current_arg++; if (argc == 1) { @@ -1043,6 +1314,28 @@ ipmi_delloem_main(struct ipmi_intf * int ipmi_sel_usage(); return -1; } + /* Sensor report processing*/ + } else if (strncmp(argv[current_arg], "sensor\0", 7) == 0) { + current_arg++; + if (argc == 1) { + rc = ipmi_sensor(intf, 0xff); + } + else if (strncmp(argv[current_arg], "list\0", 5) == 0) { + rc = ipmi_sensor(intf, 0xff); + } else if (strncmp(argv[current_arg], "get\0", 4) == 0) { + current_arg++; + if (argv[current_arg] == NULL) { + ipmi_sensor_usage(); + return -1; + } + int currIdInt; + uint8_t currId; + make_int(argv[current_arg],&currIdInt); + currId = currIdInt; + rc = ipmi_sensor_get(intf, argc - 2, &argv[2]); + } else { + ipmi_sensor_usage(); + } /* Powermanagement report processing*/ } else if (strncmp(argv[current_arg], "powermonitor\0", 13) == 0) { current_arg++;