Exemple #1
0
static int
_reset_watchdog_timer_cmd (void)
{
  fiid_obj_t obj_cmd_rq = NULL;
  fiid_obj_t obj_cmd_rs = NULL;
  int rv = -1;

  if (!(obj_cmd_rq = fiid_obj_create (tmpl_cmd_reset_watchdog_timer_rq)))
    err_exit ("fiid_obj_create: %s", strerror (errno));

  if (!(obj_cmd_rs = fiid_obj_create (tmpl_cmd_reset_watchdog_timer_rs)))
    err_exit ("fiid_obj_create: %s", strerror (errno));

  if (fill_cmd_reset_watchdog_timer (obj_cmd_rq) < 0)
    err_exit ("fill_cmd_reset_watchdog_timer: %s", strerror (errno));

  if (_cmd ("Reset Cmd",
	    IPMI_NET_FN_APP_RQ,
	    IPMI_CMD_RESET_WATCHDOG_TIMER,
	    obj_cmd_rq,
	    obj_cmd_rs) < 0)
    goto cleanup;

  rv = 0;
 cleanup:
  fiid_obj_destroy (obj_cmd_rq);
  fiid_obj_destroy (obj_cmd_rs);
  return (rv);
}
Exemple #2
0
/* read weight from device */
int ads321_get_weight(int dev_no, double *weight)
{
	char cmd[128];
	char *buf;
	if (!_fd || dev_no < start_sensor_index || dev_no >= end_sensor_index || !weight) {
		dbg(1, "check args failed.");
		return -1;
	}
	snprintf(cmd, 128, "s%02d;msv?;", dev_no);
	if (!(buf = _cmd(cmd,6))) {
		dbg(1, "weight cmd failed.");
		return -2;
	}
	ads_int data;
	/* read data into bits: 31~8 */
	data.c[3] = buf[0];
	data.c[2] = buf[1];
	data.c[1] = buf[2];
	data.c[0] = 0x00;
	/* do the right shift */
	data.i = data.i >> 8;
	/* data translation */
	if (raw_data_mode)
		*weight = data.i;
	else
		*weight = _weight_compensate(data.i);
	return 0;
}
Exemple #3
0
static int
_set_watchdog_timer_cmd (uint8_t timer_use,
                         uint8_t stop_timer,
                         uint8_t log,
                         uint8_t timeout_action,
                         uint8_t pre_timeout_interrupt,
                         uint8_t pre_timeout_interval,
                         uint8_t timer_use_expiration_flag_bios_frb2,
                         uint8_t timer_use_expiration_flag_bios_post,
                         uint8_t timer_use_expiration_flag_os_load,
                         uint8_t timer_use_expiration_flag_sms_os,
                         uint8_t timer_use_expiration_flag_oem,
                         uint16_t initial_countdown_seconds)
{
  fiid_obj_t obj_cmd_rq = NULL;
  fiid_obj_t obj_cmd_rs = NULL;
  uint16_t initial_countdown_chunks;
  int rv = -1;

  /* IPMI specifies timeout in 100 millisecond chunks */
  initial_countdown_chunks = initial_countdown_seconds * 10;

  if (!(obj_cmd_rq = fiid_obj_create (tmpl_cmd_set_watchdog_timer_rq)))
    err_exit ("fiid_obj_create: %s", strerror (errno));

  if (!(obj_cmd_rs = fiid_obj_create (tmpl_cmd_set_watchdog_timer_rs)))
    err_exit ("fiid_obj_create: %s", strerror (errno));

  if (fill_cmd_set_watchdog_timer (timer_use,
                                   stop_timer,
                                   log,
                                   timeout_action,
                                   pre_timeout_interrupt,
                                   pre_timeout_interval,
                                   timer_use_expiration_flag_bios_frb2,
                                   timer_use_expiration_flag_bios_post,
                                   timer_use_expiration_flag_os_load,
                                   timer_use_expiration_flag_sms_os,
                                   timer_use_expiration_flag_oem,
                                   initial_countdown_chunks,
                                   obj_cmd_rq) < 0)
    err_exit ("fill_cmd_set_watchdog_timer: %s", strerror (errno));

  if (_cmd ("Set Cmd",
	    IPMI_NET_FN_APP_RQ,
	    IPMI_CMD_SET_WATCHDOG_TIMER,
	    obj_cmd_rq,
	    obj_cmd_rs) < 0)
    goto cleanup;

  rv = 0;
 cleanup:
  fiid_obj_destroy (obj_cmd_rq);
  fiid_obj_destroy (obj_cmd_rs);
  return (rv);
}
Exemple #4
0
int
unix_system (string cmd, string& result) {
  url temp= url_temp ();
  string temp_s= escape_sh (concretize (temp));
  c_string _cmd (cmd * " > " * temp_s * " 2>&1");
  int ret= system (_cmd);
  bool flag= load_string (temp, result, false);
  remove (temp);
  if (flag) result= "";
  return ret;
}
Exemple #5
0
/* check if the sensor with address=dev_no is alive */
int _check_alive(int dev_no)
{
	char *recv_buf, buf[256];
	int n;

	snprintf(buf, 256, "s%02d;adr?;", dev_no);
	recv_buf = _cmd(buf, 4);
	if (recv_buf == NULL)
		return -1;
	if (!sscanf(recv_buf, "%d", &n))
		return -2;
	if (n != dev_no)
		return -3;

	return 0;
}
Exemple #6
0
/* returns -1 on error, 0 can't configure, 1 on configured */
static int
_suspend_bmc_arps_cmd (uint8_t gratuitous_arp,
                       uint8_t arp_response)
{
  fiid_obj_t obj_cmd_rq = NULL;
  fiid_obj_t obj_cmd_rs = NULL;
  uint8_t channel_number = 0;
  int ret, rv = -1;

  if (!(obj_cmd_rq = fiid_obj_create (tmpl_cmd_suspend_bmc_arps_rq)))
    err_exit ("fiid_obj_create: %s", strerror (errno));

  if (!(obj_cmd_rs = fiid_obj_create (tmpl_cmd_suspend_bmc_arps_rs)))
    err_exit ("fiid_obj_create: %s", strerror (errno));

  if ((ret = _get_channel_number (&channel_number)) < 0)
    goto cleanup;

  if (!ret)
    {
      rv = 0;
      goto cleanup;
    }

  if (fill_cmd_suspend_bmc_arps (channel_number,
                                 gratuitous_arp,
                                 arp_response,
                                 obj_cmd_rq) < 0)
    err_exit ("fill_cmd_suspend_bmc_arps: %s", strerror (errno));

  if (_cmd ("Suspend Cmd",
	    IPMI_NET_FN_TRANSPORT_RQ,
	    IPMI_CMD_SUSPEND_BMC_ARPS,
	    obj_cmd_rq,
	    obj_cmd_rs) < 0)
    goto cleanup;

  rv = 1;
 cleanup:
  fiid_obj_destroy (obj_cmd_rq);
  fiid_obj_destroy (obj_cmd_rs);
  return (rv);
}
Exemple #7
0
int ads321_get_temp(int dev_no, double *temp)
{
	char cmd[128];
	char *buf;
	if (!_fd || dev_no < start_sensor_index || dev_no >= end_sensor_index || !temp) {
		dbg(1, "check args failed.");
		return -1;
	}
	snprintf(cmd, 128, "s%02d;tep?;", dev_no);
	if (!(buf = _cmd(cmd,10))) {
		dbg(1, "weight cmd failed.");
		return -2;
	}
	if (!sscanf(buf, "%lf", temp)) {
		dbg(1, "cannot convert to double.");
		return -3;
	}
	if (!raw_data_mode)
		*temp = _temp_compensate(*temp);
	return 0;
}
Exemple #8
0
tree
sql_exec (url db_name, string cmd) {
  if (!sqlite3_initialized)
    tm_sqlite3_initialize ();
  if (sqlite3_error) {
    cout << "TeXmacs] ERROR: SQLite support not properly configured.\n";
    return tree (TUPLE);
  }
  string name= concretize (db_name);
  if (!sqlite3_connections->contains (name)) {
    c_string _name (name);
    sqlite3* db= NULL;
    //cout << "Opening " << _name << "\n";
    int status= SQLITE3_open (_name, &db);
    if (status == SQLITE_OK)
      sqlite3_connections (name) = (void*) db;
  }
  if (!sqlite3_connections->contains (name)) {
    cout << "TeXmacs] SQL error: database " << name << " could not be opened\n";
    return tree (TUPLE);
  }
  tree ret (TUPLE);
  sqlite3* db= (sqlite3*) sqlite3_connections [name];
  c_string _cmd (sql_escape (cmd));
  char** tab;
  int rows, cols;
  char* err;
  //cout << "Executing " << _cmd << "\n";
  int status= SQLITE3_get_table (db, _cmd, &tab, &rows, &cols, &err);

  int attempt= 0;
  while (status != SQLITE_OK &&
         string (err) == string ("database is locked") &&
         attempt < 100) {
    usleep (100000);
    attempt++;
    status= SQLITE3_get_table (db, _cmd, &tab, &rows, &cols, &err);
  }

  if (status != SQLITE_OK) {
    // TODO: improve error handling
    cout << "TeXmacs] SQL error\n";
    if (err != NULL) cout << "TeXmacs] " << err << "\n";
  }

  for (int r=0; r<=rows; r++) {
    tree row (TUPLE);
    //cout << "  Row " << r << LF;
    for (int c=0; c<cols; c++) {
      int i= r*cols + c;
      if (tab[i] == NULL) row << tree (TUPLE);
      else {
        row << tree (scm_quote (sql_unescape (tab[i])));
        //cout << "    Column " << c << ": " << tab[i] << LF;
      }
    }
    ret << row;
  }

  SQLITE3_free_table (tab);
  //cout << "Return " << ret << "\n";
  return ret;
}
Exemple #9
0
/* returns -1 on error, 0 on not found, 1 on found */
static int
_get_channel_number (uint8_t *channel_number)
{
  fiid_obj_t dev_id_obj_cmd_rq = NULL;
  fiid_obj_t dev_id_obj_cmd_rs = NULL;
  fiid_obj_t channel_info_obj_cmd_rq = NULL;
  fiid_obj_t channel_info_obj_cmd_rs = NULL;
  uint32_t manufacturer_id;
  uint16_t product_id;
  unsigned int i;
  uint64_t val;
  int rv = -1;

  assert (channel_number);

  if (!(dev_id_obj_cmd_rq = fiid_obj_create (tmpl_cmd_get_device_id_rq)))
    err_exit ("fiid_obj_create: %s", strerror (errno));

  if (!(dev_id_obj_cmd_rs = fiid_obj_create (tmpl_cmd_get_device_id_rs)))
    err_exit ("fiid_obj_create: %s", strerror (errno));

  if (fill_cmd_get_device_id (dev_id_obj_cmd_rq) < 0)
    err_exit ("fill_cmd_get_device_id: %s", strerror (errno));

  if (_cmd ("Get Device Id Cmd",
	    IPMI_NET_FN_APP_RQ,
	    IPMI_CMD_GET_DEVICE_ID,
	    dev_id_obj_cmd_rq,
	    dev_id_obj_cmd_rs) < 0)
    _ipmi_err_exit ("Get Device Id Error");
  
  _fiid_obj_get (dev_id_obj_cmd_rs, "manufacturer_id.id", &val);
  manufacturer_id = val;
  
  _fiid_obj_get (dev_id_obj_cmd_rs, "product_id", &val);
  product_id = val;

  switch (manufacturer_id)
    {
    case IPMI_IANA_ENTERPRISE_ID_INTEL:
    case 0xB000157: /* Intel */
      switch (product_id)
        {
        case 0x1B:
	  (*channel_number) = 7;
	  rv = 1;
          goto cleanup;
        }
    }

  if (!(channel_info_obj_cmd_rq = fiid_obj_create (tmpl_cmd_get_channel_info_rq)))
    err_exit ("fiid_obj_create: %s", strerror (errno));

  if (!(channel_info_obj_cmd_rs = fiid_obj_create (tmpl_cmd_get_channel_info_rs)))
    err_exit ("fiid_obj_create: %s", strerror (errno));

  /* Channel numbers range from 0 - 7 */
  for (i = 0; i < 8; i++)
    {
      uint8_t channel_medium_type;

      if (fill_cmd_get_channel_info (i, channel_info_obj_cmd_rq) < 0)
	err_exit ("fill_cmd_get_channel_info: %s", strerror (errno));

      if (_cmd ("Get Channel Info Cmd",
                IPMI_NET_FN_APP_RQ,
                IPMI_CMD_GET_CHANNEL_INFO_COMMAND,
                channel_info_obj_cmd_rq,
                channel_info_obj_cmd_rs) < 0)
        continue;

      _fiid_obj_get (channel_info_obj_cmd_rs, "channel_medium_type", &val);
      channel_medium_type = val;

      if (channel_medium_type == IPMI_CHANNEL_MEDIUM_TYPE_LAN_802_3)
        {
          _fiid_obj_get (channel_info_obj_cmd_rs, "actual_channel_number", &val);
          (*channel_number) = val;
          rv = 1;
          goto cleanup;
        }
    }

  rv = 0;
 cleanup:
  fiid_obj_destroy (dev_id_obj_cmd_rq);
  fiid_obj_destroy (dev_id_obj_cmd_rs);
  fiid_obj_destroy (channel_info_obj_cmd_rq);
  fiid_obj_destroy (channel_info_obj_cmd_rs);
  return (rv);
}
Exemple #10
0
static int
_get_watchdog_timer_cmd (uint8_t *timer_use,
                         uint8_t *timer_state,
                         uint8_t *log,
                         uint8_t *timeout_action,
                         uint8_t *pre_timeout_interrupt,
                         uint8_t *pre_timeout_interval,
                         uint8_t *timer_use_expiration_flag_bios_frb2,
                         uint8_t *timer_use_expiration_flag_bios_post,
                         uint8_t *timer_use_expiration_flag_os_load,
                         uint8_t *timer_use_expiration_flag_sms_os,
                         uint8_t *timer_use_expiration_flag_oem,
                         uint16_t *initial_countdown_seconds,
                         uint16_t *present_countdown_seconds)
{
  fiid_obj_t obj_cmd_rq = NULL;
  fiid_obj_t obj_cmd_rs = NULL;
  uint64_t val;
  int rv = -1;

  if (!(obj_cmd_rq = fiid_obj_create (tmpl_cmd_get_watchdog_timer_rq)))
    err_exit ("fiid_obj_create: %s", strerror (errno));

  if (!(obj_cmd_rs = fiid_obj_create (tmpl_cmd_get_watchdog_timer_rs)))
    err_exit ("fiid_obj_create: %s", strerror (errno));

  if (fill_cmd_get_watchdog_timer (obj_cmd_rq) < 0)
    err_exit ("fill_cmd_get_watchdog_timer: %s", strerror (errno));

  if (_cmd ("Get Cmd",
	    IPMI_NET_FN_APP_RQ,
	    IPMI_CMD_GET_WATCHDOG_TIMER,
	    obj_cmd_rq,
	    obj_cmd_rs) < 0)
    goto cleanup;

  if (timer_use)
    {
      _fiid_obj_get (obj_cmd_rs, "timer_use", &val);
      (*timer_use) = val;
    }

  if (timer_state)
    {
      _fiid_obj_get (obj_cmd_rs, "timer_state", &val);
      (*timer_state) = val;
    }

  if (log)
    {
      _fiid_obj_get (obj_cmd_rs, "log", &val);
      (*log) = val;
    }

  if (timeout_action)
    {
      _fiid_obj_get (obj_cmd_rs, "timeout_action", &val);
      (*timeout_action) = val;
    }

  if (pre_timeout_interrupt)
    {
      _fiid_obj_get (obj_cmd_rs, "pre_timeout_interrupt", &val);
      (*pre_timeout_interrupt) = val;
    }

  if (pre_timeout_interval)
    {
      _fiid_obj_get (obj_cmd_rs, "pre_timeout_interval", &val);
      (*pre_timeout_interval) = val;
    }

  if (timer_use_expiration_flag_bios_frb2)
    {
      _fiid_obj_get (obj_cmd_rs, "timer_use_expiration_flag.bios_frb2", &val);
      (*timer_use_expiration_flag_bios_frb2) = val;
    }

  if (timer_use_expiration_flag_bios_post)
    {
      _fiid_obj_get (obj_cmd_rs, "timer_use_expiration_flag.bios_post", &val);
      (*timer_use_expiration_flag_bios_post) = val;
    }

  if (timer_use_expiration_flag_os_load)
    {
      _fiid_obj_get (obj_cmd_rs, "timer_use_expiration_flag.os_load", &val);
      (*timer_use_expiration_flag_os_load) = val;
    }

  if (timer_use_expiration_flag_sms_os)
    {
      _fiid_obj_get (obj_cmd_rs, "timer_use_expiration_flag.sms_os", &val);
      (*timer_use_expiration_flag_sms_os) = val;
    }

  if (timer_use_expiration_flag_oem)
    {
      _fiid_obj_get (obj_cmd_rs, "timer_use_expiration_flag.oem", &val);
      (*timer_use_expiration_flag_oem) = val;
    }

  if (initial_countdown_seconds)
    {
      _fiid_obj_get (obj_cmd_rs, "initial_countdown_value", &val);
      (*initial_countdown_seconds) = val / 10;
    }

  if (present_countdown_seconds)
    {
      _fiid_obj_get (obj_cmd_rs, "present_countdown_value", &val);
      (*present_countdown_seconds) = val / 10;
    }

  rv = 0;
 cleanup:
  fiid_obj_destroy (obj_cmd_rq);
  fiid_obj_destroy (obj_cmd_rs);
  return (rv);
}