예제 #1
0
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);
}
예제 #2
0
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)";
}
예제 #3
0
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);
}
예제 #4
0
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);
}
예제 #5
0
static void
solparm_list_handler(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);
    char            solparm_name[IPMI_SOLPARM_NAME_LEN];

    if (cmdlang->err)
	return;

    ipmi_solparm_get_name(solparm, solparm_name, sizeof(solparm_name));

    ipmi_cmdlang_out(cmd_info, "Name", solparm_name);
}
예제 #6
0
static void
sensor_list_handler(ipmi_entity_t *entity, 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);
    char            sensor_name[IPMI_SENSOR_NAME_LEN];

    if (cmdlang->err)
	return;

    ipmi_sensor_get_name(sensor, sensor_name, sizeof(sensor_name));

    ipmi_cmdlang_out(cmd_info, "Name", sensor_name);
}
예제 #7
0
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)";
}
예제 #8
0
static void
solparm_new(ipmi_mc_t *mc, void *cb_data)
{
    ipmi_cmd_info_t *cmd_info = cb_data;
    ipmi_cmdlang_t  *cmdlang = ipmi_cmdinfo_get_cmdlang(cmd_info);
    int             channel;
    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_solparm_t  *solparm;
    char            solparm_name[IPMI_SOLPARM_NAME_LEN];

    if ((argc - curr_arg) < 1) {
	/* Not enough parameters */
	cmdlang->errstr = "Not enough parameters";
	cmdlang->err = EINVAL;
	goto out_err;
    }

    ipmi_cmdlang_get_int(argv[curr_arg], &channel, cmd_info);
    if (cmdlang->err) {
	cmdlang->errstr = "channel invalid";
	goto out_err;
    }
    curr_arg++;

    rv = ipmi_solparm_alloc(mc, channel, &solparm);
    if (rv) {
	cmdlang->errstr = "Error from ipmi_solparm_alloc";
	cmdlang->err = rv;
	goto out_err;
    }

    ipmi_solparm_get_name(solparm, solparm_name, sizeof(solparm_name));
    ipmi_cmdlang_out(cmd_info, "SOLPARM", solparm_name);

    return;

 out_err:
    ipmi_mc_get_name(mc, cmdlang->objstr,
		     cmdlang->objstr_len);
    cmdlang->location = "cmd_solparm.c(solparm_new)";
}
예제 #9
0
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)";
    }
}
예제 #10
0
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);
}
예제 #11
0
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);
}
예제 #12
0
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)";
    }
}
예제 #13
0
static void
sensor_dump(ipmi_sensor_t *sensor, ipmi_cmd_info_t *cmd_info)
{
    ipmi_cmdlang_t  *cmdlang = ipmi_cmdinfo_get_cmdlang(cmd_info);
    int             num, lun;
    char            *str;
    const char      *cstr;
    int             event_support;
    int             event_reading_type;
    int             len;
    int             rv;
    int             val;

    event_reading_type = ipmi_sensor_get_event_reading_type(sensor);

    ipmi_sensor_get_num(sensor, &lun, &num);
    ipmi_cmdlang_out_int(cmd_info, "LUN", lun);
    ipmi_cmdlang_out_int(cmd_info, "Number", num);
    ipmi_cmdlang_out_int(cmd_info, "Event Reading Type",
		     ipmi_sensor_get_event_reading_type(sensor));
    ipmi_cmdlang_out(cmd_info, "Event Reading Type Name",
		     ipmi_sensor_get_event_reading_type_string(sensor));
    ipmi_cmdlang_out_int(cmd_info, "Type",
			 ipmi_sensor_get_sensor_type(sensor));
    ipmi_cmdlang_out(cmd_info, "Type Name",
		     ipmi_sensor_get_sensor_type_string(sensor));
    val = ipmi_sensor_get_sensor_direction(sensor);
    if (val != IPMI_SENSOR_DIRECTION_UNSPECIFIED)
	ipmi_cmdlang_out(cmd_info, "Direction",
			 ipmi_get_sensor_direction_string(val));
    
    event_support = ipmi_sensor_get_event_support(sensor);
    switch (event_support) {
    case IPMI_EVENT_SUPPORT_PER_STATE:
	ipmi_cmdlang_out(cmd_info, "Event Support", "per state");
	break;
    case IPMI_EVENT_SUPPORT_ENTIRE_SENSOR:
	ipmi_cmdlang_out(cmd_info, "Event Support", "entire sensor");
	break;
    case IPMI_EVENT_SUPPORT_GLOBAL_ENABLE:
	ipmi_cmdlang_out(cmd_info, "Event Support", "global");
	break;
    default:
	break;
    }

    ipmi_cmdlang_out_bool(cmd_info, "Init Scanning",
			 ipmi_sensor_get_sensor_init_scanning(sensor));
    ipmi_cmdlang_out_bool(cmd_info, "Init Events",
			 ipmi_sensor_get_sensor_init_events(sensor));
    ipmi_cmdlang_out_bool(cmd_info, "Init Thresholds",
			 ipmi_sensor_get_sensor_init_thresholds(sensor));
    ipmi_cmdlang_out_bool(cmd_info, "Init Hysteresis",
			 ipmi_sensor_get_sensor_init_hysteresis(sensor));
    ipmi_cmdlang_out_bool(cmd_info, "Init Type",
			 ipmi_sensor_get_sensor_init_type(sensor));
    ipmi_cmdlang_out_bool(cmd_info, "Init Power Up Events",
			 ipmi_sensor_get_sensor_init_pu_events(sensor));
    ipmi_cmdlang_out_bool(cmd_info, "Init Power Up Scanning",
			 ipmi_sensor_get_sensor_init_pu_scanning(sensor));

    ipmi_cmdlang_out_bool(cmd_info, "Ignore If No Entity",
			 ipmi_sensor_get_ignore_if_no_entity(sensor));
    ipmi_cmdlang_out_bool(cmd_info, "Auto Rearm",
			 ipmi_sensor_get_supports_auto_rearm(sensor));
    ipmi_cmdlang_out_int(cmd_info, "OEM1",
			 ipmi_sensor_get_oem1(sensor));

    len = ipmi_sensor_get_id_length(sensor);
    if (len) {
	str = ipmi_mem_alloc(len);
	if (!str) {
	    cmdlang->err = ENOMEM;
	    cmdlang->errstr = "Out of memory";
	    goto out_err;
	}
	len = ipmi_sensor_get_id(sensor, str, len);
	ipmi_cmdlang_out_type(cmd_info, "Id",
			      ipmi_sensor_get_id_type(sensor),
			      str, len);
	ipmi_mem_free(str);
    }

    if (event_reading_type == IPMI_EVENT_READING_TYPE_THRESHOLD) {
	int access = ipmi_sensor_get_threshold_access(sensor);
	enum ipmi_thresh_e          thresh;
	enum ipmi_event_value_dir_e value_dir;
	enum ipmi_event_dir_e       dir;
	int                         rv;
	char                        th_name[50];
	double                      dval;

	ipmi_cmdlang_out(cmd_info, "Threshold Access",
			 ipmi_get_threshold_access_support_string(access));

	for (thresh = IPMI_LOWER_NON_CRITICAL;
	     thresh <= IPMI_UPPER_NON_RECOVERABLE; 
	     thresh++)
	{
	    rv = ipmi_sensor_threshold_reading_supported(sensor, thresh, &val);
	    if ((rv) || !val)
		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_sensor_threshold_readable(sensor, thresh, &val);
	    if (rv)
		val = 0;
	    ipmi_cmdlang_out_bool(cmd_info, "Readable", val);
	    rv = ipmi_sensor_threshold_settable(sensor, thresh, &val);
	    if (rv)
		val = 0;
	    ipmi_cmdlang_out_bool(cmd_info, "Settable", val);

	    for (value_dir = IPMI_GOING_LOW;
		 value_dir <= IPMI_GOING_HIGH;
		 value_dir++)
	    {
		for (dir = IPMI_ASSERTION;
		     dir <= IPMI_DEASSERTION;
		     dir++)
		{
		    rv = ipmi_sensor_threshold_event_supported(sensor,
							       thresh,
							       value_dir,
							       dir,
							       &val);
		    if (rv || !val) continue;

		    snprintf(th_name, sizeof(th_name), "%s %s",
			     ipmi_get_value_dir_string(value_dir),
			     ipmi_get_event_dir_string(dir));
		    ipmi_cmdlang_out(cmd_info, "Supports", th_name);
		}
	    }
	    ipmi_cmdlang_up(cmd_info);
	}

	val = ipmi_sensor_get_hysteresis_support(sensor);
	ipmi_cmdlang_out(cmd_info, "Hysteresis Support",
			 ipmi_get_hysteresis_support_string(val));

#if 0
	/* FIXME - no accuracy handling */
	int ipmi_sensor_get_accuracy(ipmi_sensor_t *sensor, int val,
				     double *accuracy);
#endif

	rv = ipmi_sensor_get_nominal_reading(sensor, &dval);
	if (!rv)
	    ipmi_cmdlang_out_double(cmd_info, "Nominal Reading", dval);
	rv = ipmi_sensor_get_normal_max(sensor, &dval);
	if (!rv)
	    ipmi_cmdlang_out_double(cmd_info, "Normal Max", dval);
	rv = ipmi_sensor_get_normal_min(sensor, &dval);
	if (!rv)
	    ipmi_cmdlang_out_double(cmd_info, "Normal Min", dval);
	rv = ipmi_sensor_get_sensor_max(sensor, &dval);
	if (!rv)
	    ipmi_cmdlang_out_double(cmd_info, "Sensor Max", dval);
	rv = ipmi_sensor_get_sensor_min(sensor, &dval);
	if (!rv)
	    ipmi_cmdlang_out_double(cmd_info, "Sensor Min", dval);

	ipmi_cmdlang_out_int(cmd_info, "Base Unit",
			     ipmi_sensor_get_base_unit(sensor));
	ipmi_cmdlang_out(cmd_info, "Base Unit Name",
			 ipmi_sensor_get_base_unit_string(sensor));
	cstr = ipmi_sensor_get_rate_unit_string(sensor);
	if (strlen(cstr)) {
	    ipmi_cmdlang_out_int(cmd_info, "Rate Unit",
				 ipmi_sensor_get_rate_unit(sensor));
	    ipmi_cmdlang_out(cmd_info, "Rate Unit Name", cstr);
	}
	switch (ipmi_sensor_get_modifier_unit_use(sensor)) {
	case IPMI_MODIFIER_UNIT_BASE_DIV_MOD:
	    ipmi_cmdlang_out(cmd_info, "Modifier Use", "/");
	    ipmi_cmdlang_out_int(cmd_info, "Modifier Unit",
				 ipmi_sensor_get_modifier_unit(sensor));
	    ipmi_cmdlang_out(cmd_info, "Modifier Unit Name",
			     ipmi_sensor_get_modifier_unit_string(sensor));
	    break;
		
	case IPMI_MODIFIER_UNIT_BASE_MULT_MOD:
	    ipmi_cmdlang_out(cmd_info, "Modifier Use", "*");
	    ipmi_cmdlang_out_int(cmd_info, "Modifier Unit",
				 ipmi_sensor_get_modifier_unit(sensor));
	    ipmi_cmdlang_out(cmd_info, "Modifier Unit Name",
			     ipmi_sensor_get_modifier_unit_string(sensor));
	    break;

	default:
	    break;
	}
	if (ipmi_sensor_get_percentage(sensor))
	    ipmi_cmdlang_out(cmd_info, "Percentage", "%");
    } else {
	int                   event;
	enum ipmi_event_dir_e dir;

	for (event=0; event<15; event++) {
	    rv = ipmi_sensor_discrete_event_readable(sensor, event, &val);
	    if (rv || !val)
		continue;
	    ipmi_cmdlang_out(cmd_info, "Event", NULL);
	    ipmi_cmdlang_down(cmd_info);
	    ipmi_cmdlang_out_int(cmd_info, "Offset", event);
	    cstr = ipmi_sensor_reading_name_string(sensor, event);
	    if (strcmp(cstr, "unknown") != 0)
		ipmi_cmdlang_out(cmd_info, "Name", cstr);
	    
	    for (dir = IPMI_ASSERTION;
		 dir <= IPMI_DEASSERTION;
		 dir++)
	    {
		rv = ipmi_sensor_discrete_event_supported(sensor,
							  event,
							  dir,
							  &val);
		if (rv || !val) continue;

		ipmi_cmdlang_out(cmd_info, "Supports",
				 ipmi_get_event_dir_string(dir));
	    }
	    ipmi_cmdlang_up(cmd_info);
	}
    }
    return;

 out_err:
    ipmi_sensor_get_name(sensor, cmdlang->objstr,
			 cmdlang->objstr_len);
    cmdlang->location = "cmd_sensor.c(sensor_dump)";
}
예제 #14
0
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);
}
예제 #15
0
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);
}
예제 #16
0
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);
}
예제 #17
0
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);
}
예제 #18
0
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);
}