static int _find_sensor_sdr_callback (ipmi_sdr_ctx_t sdr_ctx, uint8_t record_type, const void *sdr_record, unsigned int sdr_record_len, void *arg) { struct ipmi_oem_ibm_find_sensor_sdr_callback *sdr_callback_arg; ipmi_oem_state_data_t *state_data; uint8_t sdr_sensor_number; assert (sdr_ctx); assert (sdr_record); assert (sdr_record_len); assert (arg); sdr_callback_arg = (struct ipmi_oem_ibm_find_sensor_sdr_callback *)arg; state_data = sdr_callback_arg->state_data; /* achu: xCAT only checks for Full records, I'll check compact too though */ if (record_type != IPMI_SDR_FORMAT_FULL_SENSOR_RECORD && record_type != IPMI_SDR_FORMAT_COMPACT_SENSOR_RECORD) return (0); if (ipmi_sdr_parse_sensor_number (state_data->sdr_ctx, sdr_record, sdr_record_len, &sdr_sensor_number) < 0) { pstdout_fprintf (state_data->pstate, stderr, "ipmi_sdr_parse_sensor_number: %s\n", ipmi_sdr_ctx_errormsg (state_data->sdr_ctx)); return (-1); } if (sdr_callback_arg->sensor_number == sdr_sensor_number) { if (ipmi_sdr_parse_id_string (state_data->sdr_ctx, sdr_record, sdr_record_len, sdr_callback_arg->id_string, sdr_callback_arg->id_string_len) < 0) return (-1); sdr_callback_arg->found = 1; return (1); } return (0); }
static int _get_shared_sensor_name (ipmi_sdr_ctx_t ctx, const void *sdr_record, unsigned int sdr_record_len, uint8_t sensor_number, const char *id_string, char *buf, unsigned int buflen) { uint8_t share_count; uint8_t id_string_instance_modifier_type; uint8_t id_string_instance_modifier_offset; assert (ctx); assert (ctx->magic == IPMI_SDR_CTX_MAGIC); assert (id_string); if (ipmi_sdr_parse_sensor_record_sharing (ctx, sdr_record, sdr_record_len, &share_count, &id_string_instance_modifier_type, &id_string_instance_modifier_offset, NULL) < 0) return (-1); if (share_count > 1) { uint8_t sensor_number_base; uint8_t sensor_number_offset; if (ipmi_sdr_parse_sensor_number (ctx, sdr_record, sdr_record_len, &sensor_number_base) < 0) return (-1); /* I guess it's a bug if the sensor number passed in is bad */ if (sensor_number >= sensor_number_base) sensor_number_offset = sensor_number - sensor_number_base; else goto fallthrough; if (id_string_instance_modifier_type == IPMI_SDR_ID_STRING_INSTANCE_MODIFIER_TYPE_ALPHA) { char modifierbuf[IPMI_SDR_MODIFIER_BUFLEN]; memset (modifierbuf, '\0', IPMI_SDR_MODIFIER_BUFLEN); /* IPMI spec example is: * * "If the modifier = alpha, offset=0 * corresponds to 'A', offset=25 corresponses to * 'Z', and offset = 26 corresponds to 'AA', for * offset=26 the sensors could be identified as: * Temp AA, Temp AB, Temp AC." * * achu note: id_string_instance_modifier_type * is a 7 bit field, so we cannot reach a * situation of 'AAA' or 'AAB'. The max is * 'EX': * * 'A' + (127/26) = 4 => 'E' * 'A' + (127 % 26) = 23 => 'X' */ if ((id_string_instance_modifier_type + sensor_number_offset) < IPMI_SDR_CHARS_IN_ALPHABET) snprintf (buf, buflen, "%s %c", id_string, 'A' + ((id_string_instance_modifier_type + sensor_number_offset)/IPMI_SDR_CHARS_IN_ALPHABET)); else snprintf (buf, buflen, "%s %c%c", id_string, 'A' + ((id_string_instance_modifier_type + sensor_number_offset)/IPMI_SDR_CHARS_IN_ALPHABET), 'A' + (id_string_instance_modifier_type % IPMI_SDR_CHARS_IN_ALPHABET)); } else { /* IPMI spec example is: * * "Suppose sensor ID is 'Temp' for 'Temperature * Sensor', share count = 3, ID string instance * modifier = numeric, instance modifier offset * = 5 - then the sensors oculd be identified * as: Temp 5, Temp 6, Temp 7" */ snprintf (buf, buflen, "%s %u", id_string, id_string_instance_modifier_offset + sensor_number_offset); } return (0); } fallthrough: snprintf (buf, buflen, "%s", id_string); return (0); }
int ipmi_sdr_parse_entity_sensor_name (ipmi_sdr_ctx_t ctx, const void *sdr_record, unsigned int sdr_record_len, uint8_t sensor_number, unsigned int flags, char *buf, unsigned int buflen) { char id_string[IPMI_SDR_MAX_ID_STRING_LENGTH + 1]; char device_id_string[IPMI_SDR_MAX_DEVICE_ID_STRING_LENGTH + 1]; char entity_name_buf[IPMI_SDR_ENTITY_NAME_BUFLEN + 1]; char *id_string_ptr = NULL; uint8_t entity_id, entity_instance, entity_instance_type; const char *entity_id_str; uint8_t record_type; unsigned int flags_mask = (IPMI_SDR_SENSOR_NAME_FLAGS_IGNORE_SHARED_SENSORS | IPMI_SDR_SENSOR_NAME_FLAGS_ALWAYS_OUTPUT_INSTANCE_NUMBER); if (!ctx || ctx->magic != IPMI_SDR_CTX_MAGIC) { ERR_TRACE (ipmi_sdr_ctx_errormsg (ctx), ipmi_sdr_ctx_errnum (ctx)); return (-1); } if (ctx->operation != IPMI_SDR_OPERATION_READ_CACHE) { SDR_SET_ERRNUM (ctx, IPMI_SDR_ERR_CACHE_READ_INITIALIZATION); return (-1); } if (((sdr_record_len && !sdr_record_len) || (!sdr_record && sdr_record_len)) || (flags & ~flags_mask) || !buf || !buflen) { SDR_SET_ERRNUM (ctx, IPMI_SDR_ERR_PARAMETERS); return (-1); } memset (buf, '\0', buflen); memset (entity_name_buf, '\0', IPMI_SDR_ENTITY_NAME_BUFLEN + 1); if (ipmi_sdr_parse_record_id_and_type (ctx, sdr_record, sdr_record_len, NULL, &record_type) < 0) return (-1); if (record_type == IPMI_SDR_FORMAT_FULL_SENSOR_RECORD || record_type == IPMI_SDR_FORMAT_COMPACT_SENSOR_RECORD || record_type == IPMI_SDR_FORMAT_EVENT_ONLY_RECORD) { memset (id_string, '\0', IPMI_SDR_MAX_ID_STRING_LENGTH + 1); if (ipmi_sdr_parse_id_string (ctx, sdr_record, sdr_record_len, id_string, IPMI_SDR_MAX_ID_STRING_LENGTH) < 0) return (-1); id_string_ptr = id_string; } else if (record_type == IPMI_SDR_FORMAT_GENERIC_DEVICE_LOCATOR_RECORD || record_type == IPMI_SDR_FORMAT_MANAGEMENT_CONTROLLER_DEVICE_LOCATOR_RECORD) { memset (device_id_string, '\0', IPMI_SDR_MAX_DEVICE_ID_STRING_LENGTH + 1); if (ipmi_sdr_parse_device_id_string (ctx, sdr_record, sdr_record_len, device_id_string, IPMI_SDR_MAX_DEVICE_ID_STRING_LENGTH) < 0) return (-1); id_string_ptr = device_id_string; } else { SDR_SET_ERRNUM (ctx, IPMI_SDR_ERR_PARSE_INVALID_SDR_RECORD); return (-1); } if (ipmi_sdr_parse_entity_id_instance_type (ctx, sdr_record, sdr_record_len, &entity_id, &entity_instance, &entity_instance_type) < 0) return (-1); /* Table 39-1 * * "It is recommended that console software subtract 60h when * presenting device-relative Entity Instance values, and present * the Entity Instance number along with an ID for the device * providing the interface to the entity." * * achu: For the time being we do not output the device providing * the interface, only the right instance number. Adjust later if * necessary. */ if (IPMI_ENTITY_INSTANCE_DEVICE_RELATIVE (entity_instance)) entity_instance -= IPMI_ENTITY_INSTANCE_DEVICE_RELATIVE_MIN; entity_id_str = ipmi_get_entity_id_string (entity_id); /* a few special cases, for entity_ids are special, the vendor has * specifically stated there is no "entity" associated with this sdr * record */ if (entity_id == IPMI_ENTITY_ID_UNSPECIFIED || entity_id == IPMI_ENTITY_ID_OTHER || entity_id == IPMI_ENTITY_ID_UNKNOWN) snprintf (buf, buflen, "%s", id_string_ptr); else { if (ipmi_sdr_stats_compile (ctx) < 0) return (-1); if (ipmi_sdr_stats_entity_instance_unique (ctx, entity_id) > 1) { /* special case if sensor sharing is involved */ if ((record_type == IPMI_SDR_FORMAT_COMPACT_SENSOR_RECORD || record_type == IPMI_SDR_FORMAT_EVENT_ONLY_RECORD) && !(flags & IPMI_SDR_SENSOR_NAME_FLAGS_IGNORE_SHARED_SENSORS)) { uint8_t share_count; uint8_t entity_instance_sharing; char sensor_name_buf[IPMI_SDR_MAX_SENSOR_NAME_LENGTH + 1]; if (ipmi_sdr_parse_sensor_record_sharing (ctx, sdr_record, sdr_record_len, &share_count, NULL, NULL, &entity_instance_sharing) < 0) return (-1); if (share_count > 1 && entity_instance_sharing == IPMI_SDR_ENTITY_INSTANCE_INCREMENTS_FOR_EACH_SHARED_RECORD) { uint8_t sensor_number_base; if (ipmi_sdr_parse_sensor_number (ctx, sdr_record, sdr_record_len, &sensor_number_base) < 0) return (-1); /* I guess it's a bug if the sensor number passed in is bad */ if (sensor_number >= sensor_number_base) entity_instance += (sensor_number - sensor_number_base); else goto fallthrough; } memset (sensor_name_buf, '\0', IPMI_SDR_MAX_SENSOR_NAME_LENGTH + 1); if (_get_shared_sensor_name (ctx, sdr_record, sdr_record_len, sensor_number, id_string_ptr, sensor_name_buf, IPMI_SDR_MAX_SENSOR_NAME_LENGTH) < 0) return (-1); snprintf (entity_name_buf, IPMI_SDR_ENTITY_NAME_BUFLEN, "%s %u", entity_id_str, entity_instance); /* In odd chance the strings end up identical */ if (!strcasecmp (entity_name_buf, sensor_name_buf)) snprintf (buf, buflen, "%s", sensor_name_buf); else snprintf (buf, buflen, "%s %s", entity_name_buf, sensor_name_buf); } else { fallthrough: snprintf (entity_name_buf, IPMI_SDR_ENTITY_NAME_BUFLEN, "%s %u", entity_id_str, entity_instance); /* In odd chance the strings end up identical */ if (!strcasecmp (entity_name_buf, id_string_ptr)) snprintf (buf, buflen, "%s", id_string_ptr); else snprintf (buf, buflen, "%s %s", entity_name_buf, id_string_ptr); } } else { if (flags & IPMI_SDR_SENSOR_NAME_FLAGS_ALWAYS_OUTPUT_INSTANCE_NUMBER) { snprintf (entity_name_buf, IPMI_SDR_ENTITY_NAME_BUFLEN, "%s %u", entity_id_str, entity_instance); /* In odd chance the strings end up identical */ if (!strcasecmp (entity_name_buf, id_string_ptr)) snprintf (buf, buflen, "%s", id_string_ptr); else snprintf (buf, buflen, "%s %s", entity_name_buf, id_string_ptr); } else { /* In odd chance the strings end up identical */ if (!strcasecmp (entity_id_str, id_string_ptr)) snprintf (buf, buflen, "%s", id_string_ptr); else snprintf (buf, buflen, "%s %s", entity_id_str, id_string_ptr); } } } return (0); }
int ipmi_sensor_read (ipmi_sensor_read_ctx_t ctx, const void *sdr_record, unsigned int sdr_record_len, uint8_t shared_sensor_number_offset, uint8_t *sensor_reading_raw, double **sensor_reading, uint16_t *sensor_event_bitmask) { double *tmp_sensor_reading = NULL; uint64_t val; int rv = -1; fiid_obj_t obj_cmd_rs = NULL; uint8_t sensor_event_bitmask1 = 0; uint8_t sensor_event_bitmask2 = 0; int sensor_event_bitmask1_flag = 0; int sensor_event_bitmask2_flag = 0; uint16_t record_id = 0; uint8_t record_type = 0; uint8_t sensor_number = 0; uint8_t event_reading_type_code = 0; uint8_t sensor_owner_id_type = 0; uint8_t sensor_owner_id = 0; uint8_t sensor_owner_lun = 0; uint8_t channel_number = 0; uint8_t slave_address = 0; uint8_t reading_state, sensor_scanning; uint8_t local_sensor_reading_raw; unsigned int ctx_flags_orig; int event_reading_type_code_class = 0; if (!ctx || ctx->magic != IPMI_SENSOR_READ_CTX_MAGIC) { ERR_TRACE (ipmi_sensor_read_ctx_errormsg (ctx), ipmi_sensor_read_ctx_errnum (ctx)); return (-1); } if (!sdr_record || !sdr_record_len || !sensor_reading || !sensor_event_bitmask) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_PARAMETERS); return (-1); } *sensor_reading = NULL; *sensor_event_bitmask = 0; if (ipmi_sdr_parse_record_id_and_type (ctx->sdr_ctx, sdr_record, sdr_record_len, &record_id, &record_type) < 0) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_SDR_ENTRY_ERROR); goto cleanup; } if (record_type != IPMI_SDR_FORMAT_FULL_SENSOR_RECORD && record_type != IPMI_SDR_FORMAT_COMPACT_SENSOR_RECORD) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_INVALID_SDR_RECORD_TYPE); goto cleanup; } if (ipmi_sdr_parse_sensor_owner_id (ctx->sdr_ctx, sdr_record, sdr_record_len, &sensor_owner_id_type, &sensor_owner_id) < 0) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_SDR_ENTRY_ERROR); goto cleanup; } if (ipmi_sdr_parse_sensor_owner_lun (ctx->sdr_ctx, sdr_record, sdr_record_len, &sensor_owner_lun, &channel_number) < 0) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_SDR_ENTRY_ERROR); goto cleanup; } if (ipmi_sdr_parse_sensor_number (ctx->sdr_ctx, sdr_record, sdr_record_len, &sensor_number) < 0) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_SDR_ENTRY_ERROR); goto cleanup; } if (shared_sensor_number_offset) { uint8_t share_count; if (record_type != IPMI_SDR_FORMAT_COMPACT_SENSOR_RECORD) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_INVALID_SDR_RECORD_TYPE); goto cleanup; } if (ipmi_sdr_parse_sensor_record_sharing (ctx->sdr_ctx, sdr_record, sdr_record_len, &share_count, NULL, NULL, NULL) < 0) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_SDR_ENTRY_ERROR); goto cleanup; } if (share_count <= 1) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_INVALID_SDR_RECORD_TYPE); goto cleanup; } if ((sensor_number + share_count) < (sensor_number + shared_sensor_number_offset)) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_PARAMETERS); goto cleanup; } sensor_number += shared_sensor_number_offset; } if (ipmi_sdr_parse_event_reading_type_code (ctx->sdr_ctx, sdr_record, sdr_record_len, &event_reading_type_code) < 0) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_SDR_ENTRY_ERROR); goto cleanup; } if (sensor_owner_id_type == IPMI_SDR_SENSOR_OWNER_ID_TYPE_SYSTEM_SOFTWARE_ID) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_SENSOR_IS_SYSTEM_SOFTWARE); goto cleanup; } slave_address = (sensor_owner_id << 1) | sensor_owner_id_type; if (!(obj_cmd_rs = fiid_obj_create (tmpl_cmd_get_sensor_reading_rs))) { SENSOR_READ_ERRNO_TO_SENSOR_READ_ERRNUM (ctx, errno); goto cleanup; } /* * IPMI Workaround (achu) * * See comments below concerning sensor_event_bitmask. */ if (ipmi_ctx_get_flags (ctx->ipmi_ctx, &ctx_flags_orig) < 0) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_INTERNAL_ERROR); goto cleanup; } if (ipmi_ctx_set_flags (ctx->ipmi_ctx, ctx_flags_orig | IPMI_FLAGS_NO_VALID_CHECK) < 0) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_INTERNAL_ERROR); goto cleanup; } /* IPMI Workaround * * Discovered on Fujitsu RX300 * Discovered on Fujitsu RX300S2 * * On some motherboards, the sensor owner is invalid. The sensor * owner as atually the BMC. */ if (!(ctx->flags & IPMI_SENSOR_READ_FLAGS_ASSUME_BMC_OWNER)) { if (slave_address == IPMI_SLAVE_ADDRESS_BMC) { if (_get_sensor_reading (ctx, sensor_number, obj_cmd_rs) < 0) goto cleanup; } else { if (_get_sensor_reading_ipmb (ctx, slave_address, sensor_owner_lun, channel_number, sensor_number, obj_cmd_rs) < 0) goto cleanup; } } else { if (_get_sensor_reading (ctx, sensor_number, obj_cmd_rs) < 0) goto cleanup; } /* * IPMI Workaround (achu) * * See comments below concerning sensor_event_bitmask. */ if (ipmi_ctx_set_flags (ctx->ipmi_ctx, ctx_flags_orig) < 0) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_INTERNAL_ERROR); goto cleanup; } if (FIID_OBJ_GET (obj_cmd_rs, "reading_state", &val) < 0) { SENSOR_READ_FIID_OBJECT_ERROR_TO_SENSOR_READ_ERRNUM (ctx, obj_cmd_rs); goto cleanup; } reading_state = val; if (reading_state == IPMI_SENSOR_READING_STATE_UNAVAILABLE) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_SENSOR_READING_UNAVAILABLE); goto cleanup; } /* IPMI Workaround * * Discovered on Dell Poweredge 2900 * Discovered on Dell Poweredge 2950 * Discovered on Dell Poweredge R410 * Discovered on Dell Poweredge R610 * * On some motherboards, the sensor scanning bit is invalid for sensors. */ if (!(ctx->flags & IPMI_SENSOR_READ_FLAGS_IGNORE_SCANNING_DISABLED)) { if (FIID_OBJ_GET (obj_cmd_rs, "sensor_scanning", &val) < 0) { SENSOR_READ_FIID_OBJECT_ERROR_TO_SENSOR_READ_ERRNUM (ctx, obj_cmd_rs); goto cleanup; } sensor_scanning = val; if (sensor_scanning == IPMI_SENSOR_SCANNING_ON_THIS_SENSOR_DISABLE) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_SENSOR_SCANNING_DISABLED); goto cleanup; } } /* achu: * * Note: I don't bother checking the "all_event_messages" flag from * the get_sensor_reading response. If that stuff is turned off, * the bitmasks should be zeroed out. * * Hopefully this doesn't bite me later on. * * Call the normal fiid_obj_get instead of the wrapper, if the field * isn't set, we want to know and not error out. */ if ((sensor_event_bitmask1_flag = fiid_obj_get (obj_cmd_rs, "sensor_event_bitmask1", &val)) < 0) { SENSOR_READ_FIID_OBJECT_ERROR_TO_SENSOR_READ_ERRNUM (ctx, obj_cmd_rs); goto cleanup; } sensor_event_bitmask1 = val; if ((sensor_event_bitmask2_flag = fiid_obj_get (obj_cmd_rs, "sensor_event_bitmask2", &val)) < 0) { SENSOR_READ_FIID_OBJECT_ERROR_TO_SENSOR_READ_ERRNUM (ctx, obj_cmd_rs); goto cleanup; } sensor_event_bitmask2 = val; /* * IPMI Workaround (achu) * * Discovered on Dell 2950. * * It seems the sensor_event_bitmask (16 bits) may not be returned * by the server at all for some sensors, despite a minimum of 8 * bits being required. Under this situation, there's not much that * can be done. Since there is no sensor_event_bitmask, we just * assume that no states have been asserted and the * sensor_event_bitmask = 0; */ if (!sensor_event_bitmask1_flag && !sensor_event_bitmask2_flag) (*sensor_event_bitmask) = 0; else if (sensor_event_bitmask1_flag && sensor_event_bitmask2_flag) (*sensor_event_bitmask) = sensor_event_bitmask1 | (sensor_event_bitmask2 << 8); else if (sensor_event_bitmask1_flag && !sensor_event_bitmask2_flag) (*sensor_event_bitmask) = sensor_event_bitmask1; else { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_IPMI_ERROR); goto cleanup; } if (FIID_OBJ_GET (obj_cmd_rs, "sensor_reading", &val) < 0) { SENSOR_READ_FIID_OBJECT_ERROR_TO_SENSOR_READ_ERRNUM (ctx, obj_cmd_rs); goto cleanup; } local_sensor_reading_raw = val; if (sensor_reading_raw) (*sensor_reading_raw) = local_sensor_reading_raw; event_reading_type_code_class = ipmi_event_reading_type_code_class (event_reading_type_code); if (event_reading_type_code_class == IPMI_EVENT_READING_TYPE_CODE_CLASS_THRESHOLD) { if (record_type == IPMI_SDR_FORMAT_FULL_SENSOR_RECORD) { int8_t r_exponent, b_exponent; int16_t m, b; uint8_t linearization, analog_data_format; if (ipmi_sdr_parse_sensor_decoding_data (ctx->sdr_ctx, sdr_record, sdr_record_len, &r_exponent, &b_exponent, &m, &b, &linearization, &analog_data_format) < 0) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_SDR_ENTRY_ERROR); goto cleanup; } /* if the sensor is not analog, this is most likely a bug in the * SDR, since we shouldn't be decoding a non-threshold sensor. */ if (!IPMI_SDR_ANALOG_DATA_FORMAT_VALID (analog_data_format)) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_SENSOR_NON_ANALOG); rv = 0; goto cleanup; } /* if the sensor is non-linear, I just don't know what to do, * let the tool figure out what to output. */ if (!IPMI_SDR_LINEARIZATION_IS_LINEAR (linearization)) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_SENSOR_NON_LINEAR); rv = 0; goto cleanup; } if (!(tmp_sensor_reading = (double *)malloc (sizeof (double)))) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_OUT_OF_MEMORY); goto cleanup; } if (ipmi_sensor_decode_value (r_exponent, b_exponent, m, b, linearization, analog_data_format, local_sensor_reading_raw, tmp_sensor_reading) < 0) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_INTERNAL_ERROR); goto cleanup; } *sensor_reading = tmp_sensor_reading; } rv = 1; } else if (event_reading_type_code_class == IPMI_EVENT_READING_TYPE_CODE_CLASS_GENERIC_DISCRETE || event_reading_type_code_class == IPMI_EVENT_READING_TYPE_CODE_CLASS_SENSOR_SPECIFIC_DISCRETE) { /* * IPMI Workaround (achu) * * Discovered on HP Proliant DL380 G7 * Discovered on HP ProLiant ML310 G5 * * SDR records for some sensors give conflicting information. A * threshold based sensor lists an event/reading type code for a * discrete sensor. The analog data format indicates an * analog/threshold based sensor, however no threshold limits * for the sensor are listed in the SDR. * * To deal with this, if the analog data format and units * strongly suggest that a reading should occur with this * sensor, get the reading and return it. * * Note that this can only occur for full records, since * decoding data does not exist in compact records. */ if (ctx->flags & IPMI_SENSOR_READ_FLAGS_DISCRETE_READING && record_type == IPMI_SDR_FORMAT_FULL_SENSOR_RECORD) { int8_t r_exponent, b_exponent; int16_t m, b; uint8_t linearization, analog_data_format; uint8_t sensor_units_percentage; uint8_t sensor_units_modifier; uint8_t sensor_units_rate; uint8_t sensor_base_unit_type; uint8_t sensor_modifier_unit_type; if (ipmi_sdr_parse_sensor_decoding_data (ctx->sdr_ctx, sdr_record, sdr_record_len, &r_exponent, &b_exponent, &m, &b, &linearization, &analog_data_format) < 0) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_SDR_ENTRY_ERROR); goto cleanup; } if (ipmi_sdr_parse_sensor_units (ctx->sdr_ctx, sdr_record, sdr_record_len, &sensor_units_percentage, &sensor_units_modifier, &sensor_units_rate, &sensor_base_unit_type, &sensor_modifier_unit_type) < 0) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_SDR_ENTRY_ERROR); goto cleanup; } /* if the sensor is not analog, this is normal expected * case, fallthrough to normal expectations */ if (!IPMI_SDR_ANALOG_DATA_FORMAT_VALID (analog_data_format)) { rv = 1; goto cleanup; } /* if the sensor units are not specified, this is the normal expected * case, fallthrough to normal expectations */ if (sensor_units_percentage != IPMI_SDR_PERCENTAGE_YES && sensor_base_unit_type == IPMI_SENSOR_UNIT_UNSPECIFIED) { rv = 1; goto cleanup; } /* if the sensor is non-linear, I just don't know what to do, * let the tool figure out what to output. */ if (!IPMI_SDR_LINEARIZATION_IS_LINEAR (linearization)) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_SENSOR_NON_LINEAR); rv = 0; goto cleanup; } if (!(tmp_sensor_reading = (double *)malloc (sizeof (double)))) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_OUT_OF_MEMORY); goto cleanup; } if (ipmi_sensor_decode_value (r_exponent, b_exponent, m, b, linearization, analog_data_format, local_sensor_reading_raw, tmp_sensor_reading) < 0) { SENSOR_READ_SET_ERRNUM (ctx, IPMI_SENSOR_READ_ERR_INTERNAL_ERROR); goto cleanup; } *sensor_reading = tmp_sensor_reading; } rv = 1; } else if (event_reading_type_code_class == IPMI_EVENT_READING_TYPE_CODE_CLASS_OEM) /* nothing to do, sensor_event_bitmask already set */ rv = 1; else rv = 0; cleanup: fiid_obj_destroy (obj_cmd_rs); if (rv <= 0) free (tmp_sensor_reading); return (rv); }
/* achu: * * The range of potential inputs is limited by the sensor decoding * values and the "range" of values it can convert the threshold-raw * value into. Also, the threshold raw data is a 1 byte field, which * may be signed or unsigned. * * Outside of some math I currently don't want to think about, there * is really no way to determine if the raw data that is calculated by * ipmi_sensor_decode_raw_value() is within range at the end. So the * way that we'll check for a valid input range is to get the raw * value, then convert is back to a calculated value. If we get a * value that is reasonably close to what the user input, we'll * consider the input from the user legit. */ static config_validate_t _floating_point_in_range (const char *section_name, const char *key_name, const char *value, double value_input, void *arg) { ipmi_sensors_config_state_data_t *state_data; config_validate_t rv = CONFIG_VALIDATE_FATAL_ERROR; config_err_t ret; uint8_t threshold_raw; uint8_t sensor_number; double threshold_calc; double threshold_range_min, threshold_range_max; assert (section_name); assert (key_name); assert (value); assert (arg); state_data = (ipmi_sensors_config_state_data_t *)arg; if ((ret = seek_to_sdr_record (state_data, section_name)) != CONFIG_ERR_SUCCESS) { if (ret == CONFIG_ERR_NON_FATAL_ERROR) rv = CONFIG_VALIDATE_NON_FATAL_ERROR; goto cleanup; } if (ipmi_sdr_parse_sensor_number (state_data->sdr_ctx, NULL, 0, &sensor_number) < 0) { pstdout_fprintf (state_data->pstate, stderr, "ipmi_sdr_parse_sensor_number: %s\n", ipmi_sdr_ctx_errormsg (state_data->sdr_ctx)); goto cleanup; } if ((ret = _decode_value_raw (state_data, value, &threshold_raw)) != CONFIG_ERR_SUCCESS) { if (ret == CONFIG_ERR_NON_FATAL_ERROR) rv = CONFIG_VALIDATE_NON_FATAL_ERROR; goto cleanup; } if ((ret = _decode_value (state_data, threshold_raw, &threshold_calc)) != CONFIG_ERR_SUCCESS) { if (ret == CONFIG_ERR_NON_FATAL_ERROR) rv = CONFIG_VALIDATE_NON_FATAL_ERROR; goto cleanup; } threshold_range_min = threshold_calc * THRESHOLD_RANGE_MIN_MULTIPLIER; threshold_range_max = threshold_calc * THRESHOLD_RANGE_MAX_MULTIPLIER; /* achu: technically shouldn't compare doubles to constants, but I * think its ok here. */ if ((value_input >= 0.0 && (value_input < threshold_range_min || value_input > threshold_range_max)) || (value_input < 0.0 && (value_input > threshold_range_min || value_input < threshold_range_max))) rv = CONFIG_VALIDATE_OUT_OF_RANGE_VALUE; else rv = CONFIG_VALIDATE_VALID_VALUE; cleanup: return (rv); }
static config_err_t hysteresis_threshold_commit (const char *section_name, const struct config_keyvalue *kv, void *arg) { ipmi_sensors_config_state_data_t *state_data; fiid_obj_t obj_cmd_rs = NULL; config_err_t rv = CONFIG_ERR_FATAL_ERROR; config_err_t ret; uint8_t positive_going_threshold_hysteresis_value; uint8_t negative_going_threshold_hysteresis_value; uint8_t value_raw; uint8_t hysteresis_support; uint8_t sensor_number; assert (section_name); assert (kv); assert (arg); state_data = (ipmi_sensors_config_state_data_t *)arg; if ((ret = seek_to_sdr_record (state_data, section_name)) != CONFIG_ERR_SUCCESS) { rv = ret; goto cleanup; } if (ipmi_sdr_parse_sensor_capabilities (state_data->sdr_ctx, NULL, 0, NULL, NULL, &hysteresis_support, NULL, NULL) < 0) { pstdout_fprintf (state_data->pstate, stderr, "ipmi_sdr_parse_sensor_capabilities: %s\n", ipmi_sdr_ctx_errormsg (state_data->sdr_ctx)); goto cleanup; } /* achu: shouldn't hit this, was calculated during section setup. */ if (hysteresis_support != IPMI_SDR_READABLE_SETTABLE_HYSTERESIS_SUPPORT) { rv = CONFIG_ERR_NON_FATAL_ERROR; goto cleanup; } if (ipmi_sdr_parse_sensor_number (state_data->sdr_ctx, NULL, 0, &sensor_number) < 0) { pstdout_fprintf (state_data->pstate, stderr, "ipmi_sdr_parse_sensor_number: %s\n", ipmi_sdr_ctx_errormsg (state_data->sdr_ctx)); goto cleanup; } if ((ret = _get_hysteresis (state_data, sensor_number, &positive_going_threshold_hysteresis_value, &negative_going_threshold_hysteresis_value)) != CONFIG_ERR_SUCCESS) { rv = ret; goto cleanup; } /* "None" means hysteresis is not used, so don't decode */ if (!strcasecmp (kv->value_input, "None")) value_raw = 0; else { if ((ret = _decode_value_raw (state_data, kv->value_input, &value_raw)) != CONFIG_ERR_SUCCESS) { rv = ret; goto cleanup; } } if (!strcasecmp (kv->key->key_name, "Positive_Going_Threshold_Hysteresis")) positive_going_threshold_hysteresis_value = value_raw; else if (!strcasecmp (kv->key->key_name, "Negative_Going_Threshold_Hysteresis" )) negative_going_threshold_hysteresis_value = value_raw; else /* unknown key_name - fatal error */ goto cleanup; if (!(obj_cmd_rs = fiid_obj_create (tmpl_cmd_set_sensor_hysteresis_rs))) { pstdout_fprintf (state_data->pstate, stderr, "fiid_obj_create: %s\n", strerror (errno)); goto cleanup; } if (ipmi_cmd_set_sensor_hysteresis (state_data->ipmi_ctx, sensor_number, IPMI_SENSOR_HYSTERESIS_MASK, positive_going_threshold_hysteresis_value, negative_going_threshold_hysteresis_value, obj_cmd_rs) < 0) { if (state_data->prog_data->args->config_args.common_args.debug) pstdout_fprintf (state_data->pstate, stderr, "ipmi_cmd_set_sensor_hysteresis: %s\n", ipmi_ctx_errormsg (state_data->ipmi_ctx)); if (config_is_non_fatal_error (state_data->ipmi_ctx, obj_cmd_rs, &ret)) rv = ret; goto cleanup; } rv = CONFIG_ERR_SUCCESS; cleanup: fiid_obj_destroy (obj_cmd_rs); return (rv); }
static config_err_t hysteresis_threshold_checkout (const char *section_name, struct config_keyvalue *kv, void *arg) { ipmi_sensors_config_state_data_t *state_data; config_err_t rv = CONFIG_ERR_FATAL_ERROR; config_err_t ret; uint8_t positive_going_threshold_hysteresis_value; uint8_t negative_going_threshold_hysteresis_value; uint8_t value_raw; double value_calc; uint8_t hysteresis_support; uint8_t sensor_number; assert (section_name); assert (kv); assert (arg); state_data = (ipmi_sensors_config_state_data_t *)arg; if ((ret = seek_to_sdr_record (state_data, section_name)) != CONFIG_ERR_SUCCESS) { rv = ret; goto cleanup; } if (ipmi_sdr_parse_sensor_capabilities (state_data->sdr_ctx, NULL, 0, NULL, NULL, &hysteresis_support, NULL, NULL) < 0) { pstdout_fprintf (state_data->pstate, stderr, "ipmi_sdr_parse_sensor_capabilities: %s\n", ipmi_sdr_ctx_errormsg (state_data->sdr_ctx)); goto cleanup; } /* achu: shouldn't hit this, was calculated during section setup. * verbose mode should hit 'undefined' checkout */ if (hysteresis_support != IPMI_SDR_READABLE_HYSTERESIS_SUPPORT && hysteresis_support != IPMI_SDR_READABLE_SETTABLE_HYSTERESIS_SUPPORT) { rv = CONFIG_ERR_NON_FATAL_ERROR; goto cleanup; } if (ipmi_sdr_parse_sensor_number (state_data->sdr_ctx, NULL, 0, &sensor_number) < 0) { pstdout_fprintf (state_data->pstate, stderr, "ipmi_sdr_parse_sensor_number: %s\n", ipmi_sdr_ctx_errormsg (state_data->sdr_ctx)); goto cleanup; } if ((ret = _get_hysteresis (state_data, sensor_number, &positive_going_threshold_hysteresis_value, &negative_going_threshold_hysteresis_value)) != CONFIG_ERR_SUCCESS) { rv = ret; goto cleanup; } if (!strcasecmp (kv->key->key_name, "Positive_Going_Threshold_Hysteresis")) value_raw = positive_going_threshold_hysteresis_value; else if (!strcasecmp (kv->key->key_name, "Negative_Going_Threshold_Hysteresis")) value_raw = negative_going_threshold_hysteresis_value; else /* unknown key_name - fatal error */ goto cleanup; /* 0 means hysteresis is not used, so don't decode */ if (value_raw == 0) { if (config_section_update_keyvalue_output (state_data->pstate, kv, "None") < 0) goto cleanup; } else { if ((ret = _decode_value (state_data, value_raw, &value_calc)) != CONFIG_ERR_SUCCESS) { rv = ret; goto cleanup; } if (config_section_update_keyvalue_output_double (state_data->pstate, kv, value_calc) < 0) goto cleanup; } rv = CONFIG_ERR_SUCCESS; cleanup: return (rv); }
static config_err_t threshold_commit (const char *section_name, const struct config_keyvalue *kv, void *arg) { ipmi_sensors_config_state_data_t *state_data; fiid_obj_t obj_cmd_rs = NULL; config_err_t rv = CONFIG_ERR_FATAL_ERROR; config_err_t ret; uint8_t *lower_non_critical_threshold_ptr = NULL; uint8_t *lower_critical_threshold_ptr = NULL; uint8_t *lower_non_recoverable_threshold_ptr = NULL; uint8_t *upper_non_critical_threshold_ptr = NULL; uint8_t *upper_critical_threshold_ptr = NULL; uint8_t *upper_non_recoverable_threshold_ptr = NULL; uint8_t threshold_raw; uint8_t sensor_number; assert (section_name); assert (kv); assert (arg); state_data = (ipmi_sensors_config_state_data_t *)arg; if ((ret = seek_to_sdr_record (state_data, section_name)) != CONFIG_ERR_SUCCESS) { rv = ret; goto cleanup; } if (ipmi_sdr_parse_sensor_number (state_data->sdr_ctx, NULL, 0, &sensor_number) < 0) { pstdout_fprintf (state_data->pstate, stderr, "ipmi_sdr_parse_sensor_number: %s\n", ipmi_sdr_ctx_errormsg (state_data->sdr_ctx)); goto cleanup; } if ((ret = _decode_value_raw (state_data, kv->value_input, &threshold_raw)) != CONFIG_ERR_SUCCESS) { rv = ret; goto cleanup; } if (!strcasecmp (kv->key->key_name, "Lower_Non_Critical_Threshold")) lower_non_critical_threshold_ptr = &threshold_raw; else if (!strcasecmp (kv->key->key_name, "Lower_Critical_Threshold")) lower_critical_threshold_ptr = &threshold_raw; else if (!strcasecmp (kv->key->key_name, "Lower_Non_Recoverable_Threshold")) lower_non_recoverable_threshold_ptr = &threshold_raw; else if (!strcasecmp (kv->key->key_name, "Upper_Non_Critical_Threshold")) upper_non_critical_threshold_ptr = &threshold_raw; else if (!strcasecmp (kv->key->key_name, "Upper_Critical_Threshold")) upper_critical_threshold_ptr = &threshold_raw; else if (!strcasecmp (kv->key->key_name, "Upper_Non_Recoverable_Threshold")) upper_non_recoverable_threshold_ptr = &threshold_raw; else /* unknown key_name - fatal error */ goto cleanup; if (!(obj_cmd_rs = fiid_obj_create (tmpl_cmd_set_sensor_thresholds_rs))) { pstdout_fprintf (state_data->pstate, stderr, "fiid_obj_create: %s\n", strerror (errno)); goto cleanup; } if (ipmi_cmd_set_sensor_thresholds (state_data->ipmi_ctx, sensor_number, lower_non_critical_threshold_ptr, lower_critical_threshold_ptr, lower_non_recoverable_threshold_ptr, upper_non_critical_threshold_ptr, upper_critical_threshold_ptr, upper_non_recoverable_threshold_ptr, obj_cmd_rs) < 0) { if (state_data->prog_data->args->config_args.common_args.debug) pstdout_fprintf (state_data->pstate, stderr, "ipmi_cmd_set_sensor_thresholds: %s\n", ipmi_ctx_errormsg (state_data->ipmi_ctx)); if (config_is_non_fatal_error (state_data->ipmi_ctx, obj_cmd_rs, &ret)) rv = ret; goto cleanup; } rv = CONFIG_ERR_SUCCESS; cleanup: fiid_obj_destroy (obj_cmd_rs); return (rv); }
static config_err_t threshold_checkout (const char *section_name, struct config_keyvalue *kv, void *arg) { ipmi_sensors_config_state_data_t *state_data; fiid_obj_t obj_cmd_rs = NULL; config_err_t rv = CONFIG_ERR_FATAL_ERROR; config_err_t ret; char *readable_str; char *threshold_str; uint8_t readable; uint8_t threshold_raw; uint64_t val; double threshold_calc; uint8_t sensor_number; assert (section_name); assert (kv); assert (arg); state_data = (ipmi_sensors_config_state_data_t *)arg; if ((ret = seek_to_sdr_record (state_data, section_name)) != CONFIG_ERR_SUCCESS) { rv = ret; goto cleanup; } if (ipmi_sdr_parse_sensor_number (state_data->sdr_ctx, NULL, 0, &sensor_number) < 0) { pstdout_fprintf (state_data->pstate, stderr, "ipmi_sdr_parse_sensor_number: %s\n", ipmi_sdr_ctx_errormsg (state_data->sdr_ctx)); goto cleanup; } if (!(obj_cmd_rs = fiid_obj_create (tmpl_cmd_get_sensor_thresholds_rs))) { pstdout_fprintf (state_data->pstate, stderr, "fiid_obj_create: %s\n", strerror (errno)); goto cleanup; } if (ipmi_cmd_get_sensor_thresholds (state_data->ipmi_ctx, sensor_number, obj_cmd_rs) < 0) { if (state_data->prog_data->args->config_args.common_args.debug) pstdout_fprintf (state_data->pstate, stderr, "ipmi_cmd_get_sensor_thresholds: %s\n", ipmi_ctx_errormsg (state_data->ipmi_ctx)); if (config_is_non_fatal_error (state_data->ipmi_ctx, obj_cmd_rs, &ret)) rv = ret; /* * IPMI Workaround (achu) * * Discovered on HP DL585 * * Seems that the HP machine doesn't support the "Get Sensor * Thresholds" command. 99% of the time if a command is invalid * on a remote machine, that's a fatal error and we should exit. * I suppose this is an exception though. We can continue on * even if this command isn't supported. The user just doesn't * get to configure these thresholds. */ if (ipmi_ctx_errnum (state_data->ipmi_ctx) == IPMI_ERR_BAD_COMPLETION_CODE && ipmi_check_completion_code (obj_cmd_rs, IPMI_COMP_CODE_INVALID_COMMAND) == 1) rv = CONFIG_ERR_NON_FATAL_ERROR; goto cleanup; } if (!strcasecmp (kv->key->key_name, "Lower_Non_Critical_Threshold")) { readable_str = "readable_thresholds.lower_non_critical_threshold"; threshold_str = "lower_non_critical_threshold"; } else if (!strcasecmp (kv->key->key_name, "Lower_Critical_Threshold")) { readable_str = "readable_thresholds.lower_critical_threshold"; threshold_str = "lower_critical_threshold"; } else if (!strcasecmp (kv->key->key_name, "Lower_Non_Recoverable_Threshold")) { readable_str = "readable_thresholds.lower_non_recoverable_threshold"; threshold_str = "lower_non_recoverable_threshold"; } else if (!strcasecmp (kv->key->key_name, "Upper_Non_Critical_Threshold")) { readable_str = "readable_thresholds.upper_non_critical_threshold"; threshold_str = "upper_non_critical_threshold"; } else if (!strcasecmp (kv->key->key_name, "Upper_Critical_Threshold")) { readable_str = "readable_thresholds.upper_critical_threshold"; threshold_str = "upper_critical_threshold"; } else if (!strcasecmp (kv->key->key_name, "Upper_Non_Recoverable_Threshold")) { readable_str = "readable_thresholds.upper_non_recoverable_threshold"; threshold_str = "upper_non_recoverable_threshold"; } else /* unknown key_name - fatal error */ goto cleanup; if (FIID_OBJ_GET (obj_cmd_rs, readable_str, &val) < 0) { pstdout_fprintf (state_data->pstate, stderr, "fiid_obj_get: '%s': %s\n", readable_str, fiid_obj_errormsg (obj_cmd_rs)); goto cleanup; } readable = val; if (!readable) { /* Inconsistency w/ the SDR, should be readable */ if (state_data->prog_data->args->config_args.common_args.debug) pstdout_fprintf (state_data->pstate, stderr, "%s:%s - threshold not readable\n", section_name, kv->key->key_name); rv = CONFIG_ERR_NON_FATAL_ERROR; goto cleanup; } if (FIID_OBJ_GET (obj_cmd_rs, threshold_str, &val) < 0) { pstdout_fprintf (state_data->pstate, stderr, "fiid_obj_get: '%s': %s\n", threshold_str, fiid_obj_errormsg (obj_cmd_rs)); goto cleanup; } threshold_raw = val; if ((ret = _decode_value (state_data, threshold_raw, &threshold_calc)) != CONFIG_ERR_SUCCESS) { rv = ret; goto cleanup; } if (config_section_update_keyvalue_output_double (state_data->pstate, kv, threshold_calc) < 0) goto cleanup; rv = CONFIG_ERR_SUCCESS; cleanup: fiid_obj_destroy (obj_cmd_rs); return (rv); }