Beispiel #1
0
int
ipmi_oem_ibm_get_led (ipmi_oem_state_data_t *state_data)
{
  struct ipmi_oem_ibm_get_led_sdr_callback sdr_callback_arg;
  struct sensor_column_width column_width;
  struct ipmi_oem_data oem_data;
  int rv = -1;
  
  assert (state_data);
  assert (!state_data->prog_data->args->oem_options_count);

  if (sdr_cache_create_and_load (state_data->sdr_ctx,
                                 state_data->pstate,
                                 state_data->ipmi_ctx,
                                 state_data->hostname,
 				 &state_data->prog_data->args->common_args) < 0)
    goto cleanup;

  if (calculate_column_widths (state_data->pstate,
                               state_data->sdr_ctx,
                               NULL,
                               0,
                               NULL,
                               0,
                               0, /* non_abbreviated_units */
                               0, /* shared_sensors */
                               0, /* count_event_only_records */
                               0, /* count_device_locator_records */
                               1, /* count_oem_records */
                               0, /* entity_sensor_names */
                               &column_width) < 0)
    goto cleanup;

  if (ipmi_get_oem_data (state_data->pstate,
                         state_data->ipmi_ctx,
                         &oem_data) < 0)
    goto cleanup;

  sdr_callback_arg.state_data = state_data;
  sdr_callback_arg.column_width = &column_width;
  sdr_callback_arg.oem_data = &oem_data;
  sdr_callback_arg.header_output_flag = 0;

  if (ipmi_sdr_cache_iterate (state_data->sdr_ctx,
			      _get_led_sdr_callback,
			      &sdr_callback_arg) < 0)
    {
      pstdout_fprintf (state_data->pstate,
		       stderr,
		       "ipmi_sdr_cache_iterate: %s\n",
		       ipmi_sdr_ctx_errormsg (state_data->sdr_ctx));
      goto cleanup;
    }
  
  rv = 0;
 cleanup:
  return (rv);
}
Beispiel #2
0
int
ipmi_oem_sun_set_led (ipmi_oem_state_data_t *state_data)
{
  uint8_t bytes_rq[IPMI_OEM_MAX_BYTES];
  uint8_t bytes_rs[IPMI_OEM_MAX_BYTES];
  int rs_len;
  uint16_t record_id;
  uint8_t led_mode;
  long value;
  char *ptr;
  uint8_t sdr_record[IPMI_SDR_MAX_RECORD_LENGTH];
  int sdr_record_len = 0;
  uint8_t record_type;
  uint8_t entity_instance_type;
  int rv = -1;

  assert (state_data);
  assert (state_data->prog_data->args->oem_options_count == 2);

  errno = 0;
  value = strtol (state_data->prog_data->args->oem_options[0], &ptr, 10);
  if (errno
      || ptr[0] != '\0'
      || value < 0
      || value < IPMI_SDR_RECORD_ID_FIRST
      || value > IPMI_SDR_RECORD_ID_LAST)
    {
      pstdout_fprintf (state_data->pstate,
                       stderr,
                       "%s:%s invalid record_id\n",
                       state_data->prog_data->args->oem_id,
                       state_data->prog_data->args->oem_command);
      goto cleanup;
    }

  record_id = value;

  if (strcasecmp (state_data->prog_data->args->oem_options[1], "off")
      && strcasecmp (state_data->prog_data->args->oem_options[1], "on")
      && strcasecmp (state_data->prog_data->args->oem_options[1], "standby")
      && strcasecmp (state_data->prog_data->args->oem_options[1], "slow")
      && strcasecmp (state_data->prog_data->args->oem_options[1], "fast"))
    {
      pstdout_fprintf (state_data->pstate,
                       stderr,
                       "%s:%s invalid OEM option argument '%s'\n",
                       state_data->prog_data->args->oem_id,
                       state_data->prog_data->args->oem_command,
                       state_data->prog_data->args->oem_options[1]);
      goto cleanup;
    }

  if (!strcasecmp (state_data->prog_data->args->oem_options[1], "off"))
    led_mode = IPMI_OEM_SUN_LED_MODE_OFF;
  else if (!strcasecmp (state_data->prog_data->args->oem_options[1], "on"))
    led_mode = IPMI_OEM_SUN_LED_MODE_ON;
  else if (!strcasecmp (state_data->prog_data->args->oem_options[1], "standby"))
    led_mode = IPMI_OEM_SUN_LED_MODE_STANDBY;
  else if (!strcasecmp (state_data->prog_data->args->oem_options[1], "slow"))
    led_mode = IPMI_OEM_SUN_LED_MODE_SLOW;
  else /* !strcasecmp (state_data->prog_data->args->oem_options[1], "fast") */
    led_mode = IPMI_OEM_SUN_LED_MODE_FAST;

  if (sdr_cache_create_and_load (state_data->sdr_ctx,
                                 state_data->pstate,
                                 state_data->ipmi_ctx,
                                 state_data->hostname,
 				 &state_data->prog_data->args->common_args) < 0)
    goto cleanup;

  /* Sun OEM
   *
   * From Ipmitool (http://ipmitool.sourceforge.net/)
   *
   * Set Led Request
   *
   * 0x2E - OEM network function (is IPMI_NET_FN_OEM_GROUP_RQ)
   * 0x22 - OEM cmd
   * 0x?? - Device Slave Address (in General Device Locator Record)
   *      - Note that the IPMI command requires the entire
   *        byte of the slave address.
   * 0x?? - LED Type (see below [1])
   *      - 0 - ok2rm
   *      - 1 - service
   *      - 2 - activity
   *      - 3 - locate 
   * 0x?? - Controller Address / Device Access Address (in General Device Locator Record)
   *      - 0x20 if the LED is local
   *      - Note that the IPMI command requires the entire
   *        byte of the access address.
   * 0x?? - HW Info (OEM field in General Device Locator Record)
   * 0x?? - LED Mode
   * 0x?? - Force
   *      - 0 - Go thru controller
   *      - 1 - Directly access device
   * 0x?? - Role
   *      - Ipmitool comments state "Used by BMC for authorization purposes"
   *      - achu: I have no idea what this is for, set to 0 like in code
   *
   * An alternate format is described in the ipmitool comments for Sun
   * Blade Moduler Systems.
   *
   * 0x2E - OEM network function (is IPMI_NET_FN_OEM_GROUP_RQ)
   * 0x22 - OEM cmd
   * 0x?? - Device Slave Address (in General Device Locator Record)
   * 0x?? - LED Type
   * 0x?? - Controller Address / Device Access Address (in General Device Locator Record)
   * 0x?? - HW Info (OEM field in General Device Locator Record)
   * 0x?? - LED Mode
   * 0x?? - Entity ID
   * 0x?? - Entity Instance
   *      - 7 bit version
   * 0x?? - Force
   *      - 0 - Go thru controller
   *      - 1 - Directly access device
   * 0x?? - Role
   *      - Ipmitool comments state "Used by BMC for authorization purposes"
   *      - achu: I have no idea what this is for, set to 0 like in code
   *
   * Set Led Response
   *
   * 0x22 - OEM cmd
   * 0x?? - Completion Code
   *
   * achu notes: 
   *
   * [1] - As far as I can tell, the LED type field is useless.  My
   * assumption is that on older Sun systems, or other motherboards I
   * don't have access to, one can specify an LED type, which allows
   * you to enable/disable a particular LED amongst many.  On my Sun
   * Fire 4140, it appears to do nothing and affect nothing.  I will
   * add in a new option later if it becomes necessary for the user to
   * specify an LED type.  In the meantime, I will copy the code use
   * in ipmitool and set this field to the OEM field.
   */
  
  if (ipmi_sdr_cache_search_record_id (state_data->sdr_ctx, record_id) < 0)
    {
      pstdout_fprintf (state_data->pstate,
                       stderr,
                       "ipmi_sdr_cache_search_record_id: %s\n",
                       ipmi_sdr_ctx_errormsg (state_data->sdr_ctx));
      goto cleanup;
    }
  
  if ((sdr_record_len = ipmi_sdr_cache_record_read (state_data->sdr_ctx,
                                                    sdr_record,
                                                    IPMI_SDR_MAX_RECORD_LENGTH)) < 0)
    {
      pstdout_fprintf (state_data->pstate,
                       stderr,
                       "ipmi_sdr_cache_record_read: %s\n",
                       ipmi_sdr_ctx_errormsg (state_data->sdr_ctx));
      goto cleanup;
    }
  
  if (ipmi_sdr_parse_record_id_and_type (state_data->sdr_ctx,
                                         sdr_record,
                                         sdr_record_len,
                                         NULL,
                                         &record_type) < 0)
    {
      pstdout_fprintf (state_data->pstate,
                       stderr,
                       "ipmi_sdr_parse_record_id_and_type: %s\n",
                       ipmi_sdr_ctx_errormsg (state_data->sdr_ctx));
      goto cleanup;
    }
  
  if (record_type != IPMI_SDR_FORMAT_GENERIC_DEVICE_LOCATOR_RECORD)
    {
      pstdout_fprintf (state_data->pstate,
                       stderr,
                       "Record ID points to invalid record type: %Xh\n",
                       record_type);
      goto cleanup;
    }
  
  if (ipmi_sdr_parse_entity_id_instance_type (state_data->sdr_ctx,
                                              sdr_record,
                                              sdr_record_len,
                                              NULL,
                                              NULL,
                                              &entity_instance_type) < 0)
    {
      pstdout_fprintf (state_data->pstate,
                       stderr,
                       "ipmi_sdr_parse_entity_id_and_instance: %s\n",
                       ipmi_sdr_ctx_errormsg (state_data->sdr_ctx));
      goto cleanup;
    }

  if (entity_instance_type != IPMI_SDR_PHYSICAL_ENTITY)
    {
      pstdout_fprintf (state_data->pstate,
                       stderr,
                       "Record ID points to non physical entity\n");
      goto cleanup;
    }
  
  /* achu: the sun oem commands want the full byte, not just the
   * sub-field, so use indexes instead of sdr-parse lib.
   */
  
  bytes_rq[0] = IPMI_CMD_OEM_SUN_SET_LED;
  bytes_rq[1] = sdr_record[IPMI_SDR_RECORD_GENERIC_DEVICE_LOCATOR_DEVICE_SLAVE_ADDRESS_INDEX];
  bytes_rq[2] = sdr_record[IPMI_SDR_RECORD_GENERIC_DEVICE_LOCATOR_OEM_INDEX];
  bytes_rq[3] = sdr_record[IPMI_SDR_RECORD_GENERIC_DEVICE_LOCATOR_DEVICE_ACCESS_ADDRESS_INDEX];
  bytes_rq[4] = sdr_record[IPMI_SDR_RECORD_GENERIC_DEVICE_LOCATOR_OEM_INDEX];
  bytes_rq[5] = led_mode;
  bytes_rq[6] = IPMI_OEM_SUN_LED_FORCE_GO_THRU_CONTROLLER;
  bytes_rq[7] = 0;              /* see comments above, just set to 0 */
  
  if ((rs_len = ipmi_cmd_raw (state_data->ipmi_ctx,
                              0, /* lun */
                              IPMI_NET_FN_OEM_GROUP_RQ, /* network function */
                              bytes_rq, /* data */
                              8, /* num bytes */
                              bytes_rs,
                              IPMI_OEM_MAX_BYTES)) < 0)
    {
      pstdout_fprintf (state_data->pstate,
                       stderr,
                       "ipmi_cmd_raw: %s\n",
                       ipmi_ctx_errormsg (state_data->ipmi_ctx));
      goto cleanup;
    }
      
  if (ipmi_oem_check_response_and_completion_code (state_data,
                                                   bytes_rs,
                                                   rs_len,
                                                   2,
                                                   IPMI_CMD_OEM_SUN_SET_LED,
                                                   IPMI_NET_FN_OEM_GROUP_RS,
                                                   NULL) < 0)
    goto cleanup;
 
  rv = 0;
 cleanup: 
  return (rv);
}
Beispiel #3
0
static int
_find_sensor (ipmi_oem_state_data_t *state_data,
              uint8_t sensor_number,
              char *id_string,
              unsigned int id_string_len)
{
  struct ipmi_oem_ibm_find_sensor_sdr_callback sdr_callback_arg;
  struct common_cmd_args common_args;
  ipmi_sdr_ctx_t tmp_sdr_ctx = NULL;
  int rv = -1;

  assert (state_data);
  assert (id_string);
  assert (id_string_len);

  /* Make temporary sdr cache to search for sensor
   *
   * Redo loading of SDR cache since this is being called from a loop
   * using the state_data sdr_ctx.
   */
  if (!(tmp_sdr_ctx = ipmi_sdr_ctx_create ()))
    {
      pstdout_perror (state_data->pstate, "ipmi_sdr_ctx_create()");
      goto cleanup;
    }

  sdr_callback_arg.state_data = state_data;
  sdr_callback_arg.sensor_number = sensor_number;
  sdr_callback_arg.id_string = id_string;
  sdr_callback_arg.id_string_len = id_string_len;
  sdr_callback_arg.found = 0;

  /* Should not cause sdr recreation, since this is the second time we're calling it */
  memcpy (&common_args, &state_data->prog_data->args->common_args, sizeof (struct common_cmd_args));
  common_args.quiet_cache = 1;
  common_args.sdr_cache_recreate = 0;

  if (sdr_cache_create_and_load (tmp_sdr_ctx,
                                 state_data->pstate,
                                 state_data->ipmi_ctx,
                                 state_data->hostname,
				 &common_args) < 0)
    goto cleanup;

  if (ipmi_sdr_cache_iterate (tmp_sdr_ctx,
			      _find_sensor_sdr_callback,
			      &sdr_callback_arg) < 0)
    {
      pstdout_fprintf (state_data->pstate,
		       stderr,
		       "ipmi_sdr_cache_iterate: %s\n",
		       ipmi_sdr_ctx_errormsg (state_data->sdr_ctx));
      goto cleanup;
    }

  if (!sdr_callback_arg.found)
    snprintf (id_string,
              id_string_len,
              "Sensor Number = %02Xh",
              sensor_number);
  rv = 0;
 cleanup:
  ipmi_sdr_ctx_destroy (tmp_sdr_ctx);
  return (rv);
}
static int
_ipmi_sensors_config (pstdout_state_t pstate,
                      const char *hostname,
                      void *arg)
{
    ipmi_sensors_config_state_data_t state_data;
    ipmi_sensors_config_prog_data_t *prog_data;
    int exit_code = EXIT_FAILURE;
    config_err_t ret = 0;
    int file_opened = 0;
    FILE *fp = NULL;              /* init NULL to remove warnings */

    assert (pstate);
    assert (arg);

    prog_data = (ipmi_sensors_config_prog_data_t *) arg;

    if (prog_data->args->config_args.common_args.flush_cache)
    {
        if (sdr_cache_flush_cache (pstate,
                                   hostname,
                                   &prog_data->args->config_args.common_args) < 0)
            return (EXIT_FAILURE);
        return (EXIT_SUCCESS);
    }

    memset (&state_data, '\0', sizeof (ipmi_sensors_config_state_data_t));
    state_data.prog_data = prog_data;
    state_data.pstate = pstate;

    if (!(state_data.ipmi_ctx = ipmi_open (prog_data->progname,
                                           hostname,
                                           &(prog_data->args->config_args.common_args),
                                           state_data.pstate)))
        goto cleanup;

    if (!(state_data.sdr_ctx = ipmi_sdr_ctx_create ()))
    {
        pstdout_perror (pstate, "ipmi_sdr_ctx_create()");
        goto cleanup;
    }

    if (sdr_cache_create_and_load (state_data.sdr_ctx,
                                   NULL,
                                   state_data.ipmi_ctx,
                                   hostname,
                                   &state_data.prog_data->args->config_args.common_args) < 0)
        goto cleanup;

    if (!(state_data.sections = ipmi_sensors_config_sections_create (&state_data)))
        goto cleanup;

    if (prog_data->args->config_args.action == CONFIG_ACTION_CHECKOUT)
    {
        if (prog_data->args->config_args.filename)
        {
            if (prog_data->hosts_count > 1)
            {
                pstdout_fprintf (pstate,
                                 stderr,
                                 "Cannot output multiple host checkout into a single file\n");
                goto cleanup;
            }

            if (!(fp = fopen (prog_data->args->config_args.filename, "w")))
            {
                pstdout_perror (pstate, "fopen");
                goto cleanup;
            }
            file_opened++;
        }
        else
            fp = stdout;
    }
    else if (prog_data->args->config_args.action == CONFIG_ACTION_COMMIT
             || prog_data->args->config_args.action == CONFIG_ACTION_DIFF)
    {
        if (prog_data->args->config_args.filename
                && strcmp (prog_data->args->config_args.filename, "-"))
        {
            if (!(fp = fopen (prog_data->args->config_args.filename, "r")))
            {
                pstdout_perror (pstate, "fopen");
                goto cleanup;
            }
            file_opened++;
        }
        else
            fp = stdin;
    }

    /* parse if there is an input file or no pairs at all */
    if ((prog_data->args->config_args.action == CONFIG_ACTION_COMMIT
            && prog_data->args->config_args.filename)
            || (prog_data->args->config_args.action == CONFIG_ACTION_COMMIT
                && !prog_data->args->config_args.filename
                && !prog_data->args->config_args.keypairs)
            || (prog_data->args->config_args.action == CONFIG_ACTION_DIFF
                && prog_data->args->config_args.filename)
            || (prog_data->args->config_args.action == CONFIG_ACTION_DIFF
                && !prog_data->args->config_args.filename
                && !prog_data->args->config_args.keypairs))
    {
        if (config_parse (pstate,
                          state_data.sections,
                          &(prog_data->args->config_args),
                          fp) < 0)
        {
            /* errors printed in function call */
            goto cleanup;
        }
    }

    /* note: argp validation catches if user specified keypair and
       filename for a diff
    */
    if ((prog_data->args->config_args.action == CONFIG_ACTION_CHECKOUT
            || prog_data->args->config_args.action == CONFIG_ACTION_COMMIT
            || prog_data->args->config_args.action == CONFIG_ACTION_DIFF)
            && prog_data->args->config_args.keypairs)
    {
        if (config_sections_insert_keyvalues (pstate,
                                              state_data.sections,
                                              prog_data->args->config_args.keypairs) < 0)
        {
            /* errors printed in function call */
            goto cleanup;
        }
    }

    if (prog_data->args->config_args.action == CONFIG_ACTION_COMMIT
            || prog_data->args->config_args.action == CONFIG_ACTION_DIFF)
    {
        int num;

        if ((num = config_sections_validate_keyvalue_inputs (pstate,
                   state_data.sections,
                   &state_data)) < 0)
            goto cleanup;

        /* some errors found */
        if (num)
            goto cleanup;
    }

    if (prog_data->args->config_args.action == CONFIG_ACTION_CHECKOUT
            && prog_data->args->config_args.section_strs)
    {
        struct config_section_str *sstr;

        sstr = prog_data->args->config_args.section_strs;
        while (sstr)
        {
            if (!config_find_section (state_data.sections,
                                      sstr->section_name))
            {
                pstdout_fprintf (pstate,
                                 stderr,
                                 "Unknown section `%s'\n",
                                 sstr->section_name);
                goto cleanup;
            }
            sstr = sstr->next;
        }
    }

    switch (prog_data->args->config_args.action)
    {
    case CONFIG_ACTION_CHECKOUT:
        if (prog_data->args->config_args.section_strs)
        {
            struct config_section_str *sstr;

            /* note: argp validation catches if user specified --section
             * and --keypair, so all_keys_if_none_specified should be '1'.
             */

            sstr = prog_data->args->config_args.section_strs;
            while (sstr)
            {
                struct config_section *s;
                config_err_t this_ret;

                if (!(s = config_find_section (state_data.sections,
                                               sstr->section_name)))
                {
                    pstdout_fprintf (pstate,
                                     stderr,
                                     "## FATAL: Cannot checkout section '%s'\n",
                                     sstr->section_name);
                    continue;
                }

                this_ret = config_checkout_section (pstate,
                                                    s,
                                                    &(prog_data->args->config_args),
                                                    1,
                                                    fp,
                                                    75,
                                                    &state_data);
                if (this_ret != CONFIG_ERR_SUCCESS)
                    ret = this_ret;
                if (ret == CONFIG_ERR_FATAL_ERROR)
                    break;

                sstr = sstr->next;
            }
        }
        else
        {
            int all_keys_if_none_specified = 0;

            if (!prog_data->args->config_args.keypairs)
                all_keys_if_none_specified++;

            ret = config_checkout (pstate,
                                   state_data.sections,
                                   &(prog_data->args->config_args),
                                   all_keys_if_none_specified,
                                   fp,
                                   75,
                                   &state_data);
        }
        break;
    case CONFIG_ACTION_COMMIT:
        ret = config_commit (pstate,
                             state_data.sections,
                             &(prog_data->args->config_args),
                             &state_data);
        break;
    case CONFIG_ACTION_DIFF:
        ret = config_diff (pstate,
                           state_data.sections,
                           &(prog_data->args->config_args),
                           &state_data);
        break;
    case CONFIG_ACTION_LIST_SECTIONS:
        ret = config_output_sections_list (pstate, state_data.sections);
        break;
    }

    if (ret == CONFIG_ERR_FATAL_ERROR)
    {
        exit_code = CONFIG_FATAL_EXIT_VALUE;
        goto cleanup;
    }

    if (ret == CONFIG_ERR_NON_FATAL_ERROR)
    {
        exit_code = CONFIG_NON_FATAL_EXIT_VALUE;
        goto cleanup;
    }

    exit_code = EXIT_SUCCESS;
cleanup:
    ipmi_sdr_ctx_destroy (state_data.sdr_ctx);
    ipmi_ctx_close (state_data.ipmi_ctx);
    ipmi_ctx_destroy (state_data.ipmi_ctx);
    config_sections_destroy (state_data.sections);
    if (file_opened)
        fclose (fp);
    return (exit_code);
}