static int sensor_threshold_event_handler(ipmi_sensor_t *sensor, enum ipmi_event_dir_e dir, enum ipmi_thresh_e threshold, enum ipmi_event_value_dir_e high_low, enum ipmi_value_present_e value_present, unsigned int raw_value, double value, void *cb_data, ipmi_event_t *event) { ipmi_cmd_info_t *evi; char sensor_name[IPMI_SENSOR_NAME_LEN]; int rv; char *errstr; ipmi_sensor_get_name(sensor, sensor_name, sizeof(sensor_name)); evi = ipmi_cmdlang_alloc_event_info(); if (!evi) { rv = ENOMEM; errstr = "Out of memory"; goto out_err; } ipmi_cmdlang_out(evi, "Object Type", "Sensor"); ipmi_cmdlang_out(evi, "Name", sensor_name); ipmi_cmdlang_out(evi, "Operation", "Event"); ipmi_cmdlang_out(evi, "Threshold", ipmi_get_threshold_string(threshold)); ipmi_cmdlang_out(evi, "High/Low", ipmi_get_value_dir_string(high_low)); ipmi_cmdlang_out(evi, "Direction", ipmi_get_event_dir_string(dir)); switch (value_present) { case IPMI_BOTH_VALUES_PRESENT: ipmi_cmdlang_out_double(evi, "Value", value); /* FALLTHRU */ case IPMI_RAW_VALUE_PRESENT: ipmi_cmdlang_out_int(evi, "Raw Value", raw_value); break; default: break; } if (event) { ipmi_cmdlang_out(evi, "Event", NULL); ipmi_cmdlang_down(evi); ipmi_cmdlang_event_out(event, evi); ipmi_cmdlang_up(evi); } ipmi_cmdlang_cmd_info_put(evi); return IPMI_EVENT_NOT_HANDLED; out_err: ipmi_cmdlang_global_err(sensor_name, "cmd_sensor.c(sensor_threshold_event_handler)", errstr, rv); if (evi) ipmi_cmdlang_cmd_info_put(evi); return IPMI_EVENT_NOT_HANDLED; }
static void solparm_close(ipmi_solparm_t *solparm, void *cb_data) { ipmi_cmd_info_t *cmd_info = cb_data; ipmi_cmdlang_t *cmdlang = ipmi_cmdinfo_get_cmdlang(cmd_info); int rv; solparm_info_t *info; info = ipmi_mem_alloc(sizeof(*info)); if (!info) { cmdlang->errstr = "Out of memory"; cmdlang->err = ENOMEM; goto out_err; } info->cmd_info = cmd_info; ipmi_solparm_get_name(solparm, info->name, sizeof(info->name)); ipmi_cmdlang_cmd_info_get(cmd_info); rv = ipmi_solparm_destroy(solparm, solparm_close_done, info); if (rv) { ipmi_cmdlang_cmd_info_put(cmd_info); ipmi_solparm_get_name(solparm, cmdlang->objstr, cmdlang->objstr_len); cmdlang->errstr = "Error closing SOLPARM"; cmdlang->err = rv; ipmi_mem_free(info); } return; out_err: cmdlang->location = "cmd_solparm.c(solparm_close)"; }
static void sensor_set_hysteresis_done(ipmi_sensor_t *sensor, int err, void *cb_data) { ipmi_cmd_info_t *cmd_info = cb_data; ipmi_cmdlang_t *cmdlang = ipmi_cmdinfo_get_cmdlang(cmd_info); char sensor_name[IPMI_SENSOR_NAME_LEN]; ipmi_cmdlang_lock(cmd_info); if (err) { cmdlang->errstr = "Error setting sensor hysteresis"; cmdlang->err = err; ipmi_sensor_get_name(sensor, cmdlang->objstr, cmdlang->objstr_len); cmdlang->location = "cmd_sensor.c(sensor_set_hysteresis_done)"; goto out; } ipmi_sensor_get_name(sensor, sensor_name, sizeof(sensor_name)); ipmi_cmdlang_out(cmd_info, "Hysteresis set", sensor_name); out: ipmi_cmdlang_unlock(cmd_info); ipmi_cmdlang_cmd_info_put(cmd_info); }
static int sensor_discrete_event_handler(ipmi_sensor_t *sensor, enum ipmi_event_dir_e dir, int offset, int severity, int prev_severity, void *cb_data, ipmi_event_t *event) { ipmi_cmd_info_t *evi; char sensor_name[IPMI_SENSOR_NAME_LEN]; int rv; char *errstr; ipmi_sensor_get_name(sensor, sensor_name, sizeof(sensor_name)); evi = ipmi_cmdlang_alloc_event_info(); if (!evi) { rv = ENOMEM; errstr = "Out of memory"; goto out_err; } ipmi_cmdlang_out(evi, "Object Type", "Sensor"); ipmi_cmdlang_out(evi, "Name", sensor_name); ipmi_cmdlang_out(evi, "Operation", "Event"); ipmi_cmdlang_out_int(evi, "Offset", offset); ipmi_cmdlang_out(evi, "Direction", ipmi_get_event_dir_string(dir)); ipmi_cmdlang_out_int(evi, "Severity", severity); ipmi_cmdlang_out_int(evi, "Previous Severity", prev_severity); if (event) { ipmi_cmdlang_out(evi, "Event", NULL); ipmi_cmdlang_down(evi); ipmi_cmdlang_event_out(event, evi); ipmi_cmdlang_up(evi); } ipmi_cmdlang_cmd_info_put(evi); return IPMI_EVENT_NOT_HANDLED; out_err: ipmi_cmdlang_global_err(sensor_name, "cmd_sensor.c(sensor_discrete_event_handler)", errstr, rv); if (evi) ipmi_cmdlang_cmd_info_put(evi); return IPMI_EVENT_NOT_HANDLED; }
static void read_sensor_states(ipmi_sensor_t *sensor, int err, ipmi_states_t *states, void *cb_data) { ipmi_cmd_info_t *cmd_info = cb_data; ipmi_cmdlang_t *cmdlang = ipmi_cmdinfo_get_cmdlang(cmd_info); int i; char sensor_name[IPMI_SENSOR_NAME_LEN]; int rv; ipmi_cmdlang_lock(cmd_info); if (err) { cmdlang->errstr = "Error reading sensor"; cmdlang->err = err; ipmi_sensor_get_name(sensor, cmdlang->objstr, cmdlang->objstr_len); cmdlang->location = "cmd_sensor.c(read_sensor_states)"; goto out; } ipmi_sensor_get_name(sensor, sensor_name, sizeof(sensor_name)); ipmi_cmdlang_out(cmd_info, "Sensor", NULL); ipmi_cmdlang_down(cmd_info); ipmi_cmdlang_out(cmd_info, "Name", sensor_name); ipmi_cmdlang_out_bool(cmd_info, "Event Messages Enabled", ipmi_is_event_messages_enabled(states)); ipmi_cmdlang_out_bool(cmd_info, "Sensor Scanning Enabled", ipmi_is_sensor_scanning_enabled(states)); ipmi_cmdlang_out_bool(cmd_info, "Initial Update In Progress", ipmi_is_initial_update_in_progress(states)); for (i=0; i<15; i++) { int ival; const char *str; rv = ipmi_sensor_discrete_event_readable(sensor, i, &ival); if ((rv) || !ival) continue; ipmi_cmdlang_out(cmd_info, "Event", NULL); ipmi_cmdlang_down(cmd_info); ipmi_cmdlang_out_int(cmd_info, "Offset", i); str = ipmi_sensor_reading_name_string(sensor, i); if (strcmp(str, "unknown") != 0) ipmi_cmdlang_out(cmd_info, "Name", str); ipmi_cmdlang_out_bool(cmd_info, "Set", ipmi_is_state_set(states, i)); ipmi_cmdlang_up(cmd_info); } ipmi_cmdlang_up(cmd_info); out: ipmi_cmdlang_unlock(cmd_info); ipmi_cmdlang_cmd_info_put(cmd_info); }
static void sensor_get_thresholds_done(ipmi_sensor_t *sensor, int err, ipmi_thresholds_t *th, void *cb_data) { ipmi_cmd_info_t *cmd_info = cb_data; ipmi_cmdlang_t *cmdlang = ipmi_cmdinfo_get_cmdlang(cmd_info); char sensor_name[IPMI_SENSOR_NAME_LEN]; enum ipmi_thresh_e thresh; int rv; ipmi_cmdlang_lock(cmd_info); if (err) { cmdlang->errstr = "Error reading sensor thresholds"; cmdlang->err = err; ipmi_sensor_get_name(sensor, cmdlang->objstr, cmdlang->objstr_len); cmdlang->location = "cmd_sensor.c(sensor_get_thresholds_done)"; goto out; } ipmi_sensor_get_name(sensor, sensor_name, sizeof(sensor_name)); ipmi_cmdlang_out(cmd_info, "Sensor", NULL); ipmi_cmdlang_down(cmd_info); ipmi_cmdlang_out(cmd_info, "Name", sensor_name); for (thresh = IPMI_LOWER_NON_CRITICAL; thresh <= IPMI_UPPER_NON_RECOVERABLE; thresh++) { int ival; double dval; rv = ipmi_sensor_threshold_reading_supported(sensor, thresh, &ival); if ((rv) || !ival) continue; ipmi_cmdlang_out(cmd_info, "Threshold", NULL); ipmi_cmdlang_down(cmd_info); ipmi_cmdlang_out(cmd_info, "Name", ipmi_get_threshold_string(thresh)); rv = ipmi_threshold_get(th, thresh, &dval); if (rv) continue; ipmi_cmdlang_out_double(cmd_info, "Value", dval); ipmi_cmdlang_up(cmd_info); } ipmi_cmdlang_up(cmd_info); out: ipmi_cmdlang_unlock(cmd_info); ipmi_cmdlang_cmd_info_put(cmd_info); }
static void sensor_set_hysteresis(ipmi_sensor_t *sensor, void *cb_data) { ipmi_cmd_info_t *cmd_info = cb_data; ipmi_cmdlang_t *cmdlang = ipmi_cmdinfo_get_cmdlang(cmd_info); int rv; int curr_arg = ipmi_cmdlang_get_curr_arg(cmd_info); int argc = ipmi_cmdlang_get_argc(cmd_info); char **argv = ipmi_cmdlang_get_argv(cmd_info); int pos, neg; if ((argc - curr_arg) < 2) { /* Not enough parameters */ cmdlang->errstr = "Not enough parameters"; cmdlang->err = EINVAL; goto out_err; } ipmi_cmdlang_get_int(argv[curr_arg], &pos, cmd_info); if (cmdlang->err) { cmdlang->errstr = "Invalid positive hysteresis"; goto out_err; } curr_arg++; ipmi_cmdlang_get_int(argv[curr_arg], &neg, cmd_info); if (cmdlang->err) { cmdlang->errstr = "Invalid negative hysteresis"; goto out_err; } curr_arg++; ipmi_cmdlang_cmd_info_get(cmd_info); rv = ipmi_sensor_set_hysteresis(sensor, pos, neg, sensor_set_hysteresis_done, cmd_info); if (rv) { ipmi_cmdlang_cmd_info_put(cmd_info); cmdlang->err = rv; cmdlang->errstr = "Error setting hysteresis"; goto out_err; } out_err: ipmi_sensor_get_name(sensor, cmdlang->objstr, cmdlang->objstr_len); cmdlang->location = "cmd_sensor.c(sensor_set_hysteresis)"; }
static void sensor_get_hysteresis(ipmi_sensor_t *sensor, void *cb_data) { ipmi_cmd_info_t *cmd_info = cb_data; ipmi_cmdlang_t *cmdlang = ipmi_cmdinfo_get_cmdlang(cmd_info); int rv; ipmi_cmdlang_cmd_info_get(cmd_info); rv = ipmi_sensor_get_hysteresis(sensor, sensor_get_hysteresis_done, cmd_info); if (rv) { ipmi_cmdlang_cmd_info_put(cmd_info); cmdlang->err = rv; cmdlang->errstr = "Error getting hysteresis"; ipmi_sensor_get_name(sensor, cmdlang->objstr, cmdlang->objstr_len); cmdlang->location = "cmd_sensor.c(sensor_get_hysteresis)"; } }
static void sensor_get_hysteresis_done(ipmi_sensor_t *sensor, int err, unsigned int positive_hysteresis, unsigned int negative_hysteresis, void *cb_data) { ipmi_cmd_info_t *cmd_info = cb_data; ipmi_cmdlang_t *cmdlang = ipmi_cmdinfo_get_cmdlang(cmd_info); char sensor_name[IPMI_SENSOR_NAME_LEN]; ipmi_cmdlang_lock(cmd_info); if (err) { cmdlang->errstr = "Error reading sensor hysteresis"; cmdlang->err = err; ipmi_sensor_get_name(sensor, cmdlang->objstr, cmdlang->objstr_len); cmdlang->location = "cmd_sensor.c(sensor_get_hysteresis_done)"; goto out; } ipmi_sensor_get_name(sensor, sensor_name, sizeof(sensor_name)); ipmi_cmdlang_out(cmd_info, "Sensor", NULL); ipmi_cmdlang_down(cmd_info); ipmi_cmdlang_out(cmd_info, "Name", sensor_name); ipmi_cmdlang_out_int(cmd_info, "Positive Hysteresis", positive_hysteresis); ipmi_cmdlang_out_int(cmd_info, "Negative Hysteresis", negative_hysteresis); ipmi_cmdlang_up(cmd_info); out: ipmi_cmdlang_unlock(cmd_info); ipmi_cmdlang_cmd_info_put(cmd_info); }
static void sensor_get(ipmi_sensor_t *sensor, void *cb_data) { ipmi_cmd_info_t *cmd_info = cb_data; ipmi_cmdlang_t *cmdlang = ipmi_cmdinfo_get_cmdlang(cmd_info); int rv; ipmi_cmdlang_cmd_info_get(cmd_info); if (ipmi_sensor_get_event_reading_type(sensor) == IPMI_EVENT_READING_TYPE_THRESHOLD) { rv = ipmi_sensor_get_reading(sensor, read_sensor, cmd_info); } else { rv = ipmi_sensor_get_states(sensor, read_sensor_states, cmd_info); } if (rv) { ipmi_cmdlang_cmd_info_put(cmd_info); cmdlang->err = rv; cmdlang->errstr = "Error reading sensor"; ipmi_sensor_get_name(sensor, cmdlang->objstr, cmdlang->objstr_len); cmdlang->location = "cmd_sensor.c(sensor_get)"; } }
static void solparm_close_done(ipmi_solparm_t *solparm, int err, void *cb_data) { solparm_info_t *info = cb_data; ipmi_cmd_info_t *cmd_info = info->cmd_info; ipmi_cmdlang_t *cmdlang = ipmi_cmdinfo_get_cmdlang(cmd_info); ipmi_cmdlang_lock(cmd_info); if (err) { ipmi_solparm_get_name(solparm, cmdlang->objstr, cmdlang->objstr_len); cmdlang->errstr = "Error closing SOLPARM"; cmdlang->err = err; cmdlang->location = "cmd_solparm.c(solparm_close_done)"; goto out; } ipmi_cmdlang_out(cmd_info, "SOLPARM destroyed", info->name); out: ipmi_cmdlang_unlock(cmd_info); ipmi_cmdlang_cmd_info_put(cmd_info); ipmi_mem_free(info); }
static void sensor_get_event_enables_done(ipmi_sensor_t *sensor, int err, ipmi_event_state_t *states, void *cb_data) { ipmi_cmd_info_t *cmd_info = cb_data; ipmi_cmdlang_t *cmdlang = ipmi_cmdinfo_get_cmdlang(cmd_info); char sensor_name[IPMI_SENSOR_NAME_LEN]; int rv; int val; ipmi_cmdlang_lock(cmd_info); if (err) { cmdlang->errstr = "Error reading sensor event enables"; cmdlang->err = err; ipmi_sensor_get_name(sensor, cmdlang->objstr, cmdlang->objstr_len); cmdlang->location = "cmd_sensor.c(sensor_get_event_enables_done)"; goto out; } ipmi_sensor_get_name(sensor, sensor_name, sizeof(sensor_name)); ipmi_cmdlang_out(cmd_info, "Sensor", NULL); ipmi_cmdlang_down(cmd_info); ipmi_cmdlang_out(cmd_info, "Name", sensor_name); ipmi_cmdlang_out_bool(cmd_info, "Event Messages Enabled", ipmi_event_state_get_events_enabled(states)); ipmi_cmdlang_out_bool(cmd_info, "Sensor Scanning Enabled", ipmi_event_state_get_scanning_enabled(states)); ipmi_cmdlang_out_bool(cmd_info, "Busy", ipmi_event_state_get_busy(states)); if (ipmi_sensor_get_event_reading_type(sensor) == IPMI_EVENT_READING_TYPE_THRESHOLD) { enum ipmi_thresh_e thresh; enum ipmi_event_value_dir_e value_dir; enum ipmi_event_dir_e dir; for (thresh = IPMI_LOWER_NON_CRITICAL; thresh <= IPMI_UPPER_NON_RECOVERABLE; thresh++) { for (value_dir = IPMI_GOING_LOW; value_dir <= IPMI_GOING_HIGH; value_dir++) { for (dir = IPMI_ASSERTION; dir <= IPMI_DEASSERTION; dir++) { char th_name[50]; rv = ipmi_sensor_threshold_event_supported(sensor, thresh, value_dir, dir, &val); if (rv || !val) continue; ipmi_cmdlang_out(cmd_info, "Threshold", NULL); ipmi_cmdlang_down(cmd_info); snprintf(th_name, sizeof(th_name), "%s %s %s", ipmi_get_threshold_string(thresh), ipmi_get_value_dir_string(value_dir), ipmi_get_event_dir_string(dir)); ipmi_cmdlang_out(cmd_info, "Name", th_name); ipmi_cmdlang_out_bool(cmd_info, "Enabled", ipmi_is_threshold_event_set (states, thresh, value_dir, dir)); ipmi_cmdlang_up(cmd_info); } } } } else { int offset; const char *str; for (offset=0; offset<15; offset++) { rv = ipmi_sensor_discrete_event_readable(sensor, offset, &val); if (rv || !val) continue; ipmi_cmdlang_out(cmd_info, "Event", NULL); ipmi_cmdlang_down(cmd_info); ipmi_cmdlang_out_int(cmd_info, "Offset", offset); str = ipmi_sensor_reading_name_string(sensor, offset); if (strcmp(str, "unknown") != 0) ipmi_cmdlang_out(cmd_info, "Name", str); rv = ipmi_sensor_discrete_event_supported(sensor, offset, IPMI_ASSERTION, &val); if (!rv && val) { ipmi_cmdlang_out_bool(cmd_info, "Assertion Enabled", ipmi_is_discrete_event_set (states, offset, IPMI_ASSERTION)); } rv = ipmi_sensor_discrete_event_supported(sensor, offset, IPMI_DEASSERTION, &val); if (!rv && val) { ipmi_cmdlang_out_bool(cmd_info, "Deassertion Enabled", ipmi_is_discrete_event_set (states, offset, IPMI_DEASSERTION)); } ipmi_cmdlang_up(cmd_info); } } ipmi_cmdlang_up(cmd_info); out: ipmi_cmdlang_unlock(cmd_info); ipmi_cmdlang_cmd_info_put(cmd_info); }
static void mod_event_enables(ipmi_sensor_t *sensor, void *cb_data, enum ev_en_kind kind) { ipmi_cmd_info_t *cmd_info = cb_data; ipmi_cmdlang_t *cmdlang = ipmi_cmdinfo_get_cmdlang(cmd_info); int rv; int curr_arg = ipmi_cmdlang_get_curr_arg(cmd_info); int argc = ipmi_cmdlang_get_argc(cmd_info); char **argv = ipmi_cmdlang_get_argv(cmd_info); ipmi_event_state_t *s = NULL; if ((argc - curr_arg) < 2) { /* Not enough parameters */ cmdlang->errstr = "Not enough parameters"; cmdlang->err = EINVAL; goto out_err; } s = ipmi_mem_alloc(ipmi_states_size()); if (!s) { cmdlang->errstr = "Out of memory"; cmdlang->err = ENOMEM; goto out_err; } ipmi_event_state_init(s); if (strcmp(argv[curr_arg], "msg") == 0) ipmi_event_state_set_events_enabled(s, 1); else if (strcmp(argv[curr_arg], "nomsg") == 0) ipmi_event_state_set_events_enabled(s, 0); else { cmdlang->errstr = "Invalid message enable setting"; cmdlang->err = EINVAL; goto out_err; } curr_arg++; if (strcmp(argv[curr_arg], "scan") == 0) ipmi_event_state_set_scanning_enabled(s, 1); else if (strcmp(argv[curr_arg], "noscan") == 0) ipmi_event_state_set_scanning_enabled(s, 0); else { cmdlang->errstr = "Invalid scanning enable setting"; cmdlang->err = EINVAL; goto out_err; } curr_arg++; if (ipmi_sensor_get_event_reading_type(sensor) == IPMI_EVENT_READING_TYPE_THRESHOLD) { while (curr_arg < argc) { enum ipmi_thresh_e thresh; enum ipmi_event_value_dir_e value_dir; enum ipmi_event_dir_e dir; ipmi_cmdlang_get_threshold_ev(argv[curr_arg], &thresh, &value_dir, &dir, cmd_info); if (cmdlang->err) { goto out_err; } ipmi_threshold_event_set(s, thresh, value_dir, dir); curr_arg++; } } else { while (curr_arg < argc) { int offset; enum ipmi_event_dir_e dir; ipmi_cmdlang_get_discrete_ev(argv[curr_arg], &offset, &dir, cmd_info); if (cmdlang->err) { goto out_err; } ipmi_discrete_event_set(s, offset, dir); curr_arg++; } } ipmi_cmdlang_cmd_info_get(cmd_info); switch (kind) { case ev_en_set: rv = ipmi_sensor_set_event_enables(sensor, s, sensor_set_event_enables_done, cmd_info); break; case ev_en_enable: rv = ipmi_sensor_enable_events(sensor, s, sensor_set_event_enables_done, cmd_info); break; case ev_en_disable: rv = ipmi_sensor_disable_events(sensor, s, sensor_set_event_enables_done, cmd_info); break; default: rv = EINVAL; } if (rv) { ipmi_cmdlang_cmd_info_put(cmd_info); cmdlang->err = rv; cmdlang->errstr = "Error setting event enables"; goto out_err; } ipmi_mem_free(s); return; out_err: ipmi_sensor_get_name(sensor, cmdlang->objstr, cmdlang->objstr_len); cmdlang->location = "cmd_sensor.c(sensor_set_event_enables)"; if (s) ipmi_mem_free(s); }
void ipmi_cmdlang_sensor_change(enum ipmi_update_e op, ipmi_entity_t *entity, ipmi_sensor_t *sensor, void *cb_data) { char *errstr; int rv; ipmi_cmd_info_t *evi; char sensor_name[IPMI_SENSOR_NAME_LEN]; ipmi_sensor_get_name(sensor, sensor_name, sizeof(sensor_name)); evi = ipmi_cmdlang_alloc_event_info(); if (!evi) { rv = ENOMEM; errstr = "Out of memory"; goto out_err; } ipmi_cmdlang_out(evi, "Object Type", "Sensor"); ipmi_cmdlang_out(evi, "Name", sensor_name); switch (op) { case IPMI_ADDED: ipmi_cmdlang_out(evi, "Operation", "Add"); if (ipmi_cmdlang_get_evinfo()) sensor_dump(sensor, evi); if (ipmi_sensor_get_event_reading_type(sensor) == IPMI_EVENT_READING_TYPE_THRESHOLD) { rv = ipmi_sensor_add_threshold_event_handler (sensor, sensor_threshold_event_handler, NULL); } else { rv = ipmi_sensor_add_discrete_event_handler (sensor, sensor_discrete_event_handler, NULL); } if (rv) { ipmi_cmdlang_global_err(sensor_name, "cmd_sensor.c(ipmi_cmdlang_sensor_change)", "Unable to set event handler for sensor", rv); } break; case IPMI_DELETED: ipmi_cmdlang_out(evi, "Operation", "Delete"); break; case IPMI_CHANGED: ipmi_cmdlang_out(evi, "Operation", "Change"); if (ipmi_cmdlang_get_evinfo()) sensor_dump(sensor, evi); break; } ipmi_cmdlang_cmd_info_put(evi); return; out_err: ipmi_cmdlang_global_err(sensor_name, "cmd_sensor.c(ipmi_cmdlang_sensor_change)", errstr, rv); if (evi) ipmi_cmdlang_cmd_info_put(evi); }
static void read_sensor(ipmi_sensor_t *sensor, int err, enum ipmi_value_present_e value_present, unsigned int raw_val, double val, ipmi_states_t *states, void *cb_data) { ipmi_cmd_info_t *cmd_info = cb_data; ipmi_cmdlang_t *cmdlang = ipmi_cmdinfo_get_cmdlang(cmd_info); enum ipmi_thresh_e thresh; char sensor_name[IPMI_SENSOR_NAME_LEN]; int rv; ipmi_cmdlang_lock(cmd_info); if (err) { cmdlang->errstr = "Error reading sensor"; cmdlang->err = err; ipmi_sensor_get_name(sensor, cmdlang->objstr, cmdlang->objstr_len); cmdlang->location = "cmd_sensor.c(read_sensor)"; goto out; } ipmi_sensor_get_name(sensor, sensor_name, sizeof(sensor_name)); ipmi_cmdlang_out(cmd_info, "Sensor", NULL); ipmi_cmdlang_down(cmd_info); ipmi_cmdlang_out(cmd_info, "Name", sensor_name); ipmi_cmdlang_out_bool(cmd_info, "Event Messages Enabled", ipmi_is_event_messages_enabled(states)); ipmi_cmdlang_out_bool(cmd_info, "Sensor Scanning Enabled", ipmi_is_sensor_scanning_enabled(states)); ipmi_cmdlang_out_bool(cmd_info, "Initial Update In Progress", ipmi_is_initial_update_in_progress(states)); switch (value_present) { case IPMI_BOTH_VALUES_PRESENT: ipmi_cmdlang_out_double(cmd_info, "Value", val); /* FALLTHRU */ case IPMI_RAW_VALUE_PRESENT: ipmi_cmdlang_out_hex(cmd_info, "Raw Value", raw_val); default: break; } for (thresh = IPMI_LOWER_NON_CRITICAL; thresh <= IPMI_UPPER_NON_RECOVERABLE; thresh++) { int ival; rv = ipmi_sensor_threshold_reading_supported(sensor, thresh, &ival); if ((rv) || !ival) continue; ipmi_cmdlang_out(cmd_info, "Threshold", NULL); ipmi_cmdlang_down(cmd_info); ipmi_cmdlang_out(cmd_info, "Name", ipmi_get_threshold_string(thresh)); ipmi_cmdlang_out_bool(cmd_info, "Out Of Range", ipmi_is_threshold_out_of_range(states, thresh)); ipmi_cmdlang_up(cmd_info); } ipmi_cmdlang_up(cmd_info); out: ipmi_cmdlang_unlock(cmd_info); ipmi_cmdlang_cmd_info_put(cmd_info); }
static void sensor_rearm(ipmi_sensor_t *sensor, void *cb_data) { ipmi_cmd_info_t *cmd_info = cb_data; ipmi_cmdlang_t *cmdlang = ipmi_cmdinfo_get_cmdlang(cmd_info); int rv; int curr_arg = ipmi_cmdlang_get_curr_arg(cmd_info); int argc = ipmi_cmdlang_get_argc(cmd_info); char **argv = ipmi_cmdlang_get_argv(cmd_info); int global; ipmi_event_state_t *s = NULL; if ((argc - curr_arg) < 1) { cmdlang->errstr = "Not enough parameters"; cmdlang->err = EINVAL; goto out_err; } if (strcmp(argv[curr_arg], "global") == 0) { global = 1; } else { global = 0; s = ipmi_mem_alloc(ipmi_event_state_size()); if (!s) { cmdlang->errstr = "Out of memory"; cmdlang->err = ENOMEM; goto out_err; } ipmi_event_state_init(s); if (ipmi_sensor_get_event_reading_type(sensor) == IPMI_EVENT_READING_TYPE_THRESHOLD) { enum ipmi_thresh_e thresh; enum ipmi_event_value_dir_e value_dir; enum ipmi_event_dir_e dir; while (curr_arg < argc) { ipmi_cmdlang_get_threshold_ev(argv[curr_arg], &thresh, &value_dir, &dir, cmd_info); if (cmdlang->err) { goto out_err; } ipmi_threshold_event_set(s, thresh, value_dir, dir); curr_arg++; } } else { int offset; enum ipmi_event_dir_e dir; while (curr_arg < argc) { ipmi_cmdlang_get_discrete_ev(argv[curr_arg], &offset, &dir, cmd_info); if (cmdlang->err) { goto out_err; } ipmi_discrete_event_set(s, offset, dir); curr_arg++; } } } ipmi_cmdlang_cmd_info_get(cmd_info); rv = ipmi_sensor_rearm(sensor, global, s, sensor_rearm_done, cmd_info); if (rv) { ipmi_cmdlang_cmd_info_put(cmd_info); cmdlang->err = rv; cmdlang->errstr = "Error rearming sensor"; goto out_err; } if (s) ipmi_mem_free(s); return; out_err: ipmi_sensor_get_name(sensor, cmdlang->objstr, cmdlang->objstr_len); cmdlang->location = "cmd_sensor.c(sensor_rearm)"; if (s) ipmi_mem_free(s); }
static void sensor_set_thresholds(ipmi_sensor_t *sensor, void *cb_data) { ipmi_cmd_info_t *cmd_info = cb_data; ipmi_cmdlang_t *cmdlang = ipmi_cmdinfo_get_cmdlang(cmd_info); int rv; int curr_arg = ipmi_cmdlang_get_curr_arg(cmd_info); int argc = ipmi_cmdlang_get_argc(cmd_info); char **argv = ipmi_cmdlang_get_argv(cmd_info); ipmi_thresholds_t *th = NULL; enum ipmi_thresh_e thresh; double val; if ((argc - curr_arg) < 1) { /* Not enough parameters */ cmdlang->errstr = "Not enough parameters"; cmdlang->err = EINVAL; goto out_err; } th = ipmi_mem_alloc(ipmi_thresholds_size()); if (!th) { cmdlang->errstr = "Out of memory"; cmdlang->err = ENOMEM; goto out_err; } ipmi_thresholds_init(th); while (curr_arg < argc) { ipmi_cmdlang_get_threshold(argv[curr_arg], &thresh, cmd_info); if (cmdlang->err) { cmdlang->errstr = "Invalid threshold"; goto out_err; } curr_arg++; ipmi_cmdlang_get_double(argv[curr_arg], &val, cmd_info); if (cmdlang->err) { cmdlang->errstr = "Invalid threshold value"; goto out_err; } curr_arg++; rv = ipmi_threshold_set(th, sensor, thresh, val); if (rv) { cmdlang->errstr = "Error setting value"; cmdlang->err = rv; goto out_err; } } ipmi_cmdlang_cmd_info_get(cmd_info); rv = ipmi_sensor_set_thresholds(sensor, th, sensor_set_thresholds_done, cmd_info); if (rv) { ipmi_cmdlang_cmd_info_put(cmd_info); cmdlang->err = rv; cmdlang->errstr = "Error setting thresholds"; goto out_err; } ipmi_mem_free(th); return; out_err: ipmi_sensor_get_name(sensor, cmdlang->objstr, cmdlang->objstr_len); cmdlang->location = "cmd_sensor.c(sensor_set_thresholds)"; if (th) ipmi_mem_free(th); }