Exemplo n.º 1
0
/*
 * return the first compatible value
 */
static int
montoya_get_first_compatible_value(picl_nodehdl_t nodeh, char **outbuf)
{
    int		err;
    picl_prophdl_t	proph;
    picl_propinfo_t	pinfo;
    picl_prophdl_t	tblh;
    picl_prophdl_t	rowproph;
    char		*pval;

    err = picl_get_propinfo_by_name(nodeh, OBP_PROP_COMPATIBLE,
                                    &pinfo, &proph);
    if (err != PICL_SUCCESS)
        return (err);

    if (pinfo.type == PICL_PTYPE_CHARSTRING) {
        pval = malloc(pinfo.size);
        if (pval == NULL)
            return (PICL_FAILURE);
        err = picl_get_propval(proph, pval, pinfo.size);
        if (err != PICL_SUCCESS) {
            free(pval);
            return (err);
        }
        *outbuf = pval;
        return (PICL_SUCCESS);
    }

    if (pinfo.type != PICL_PTYPE_TABLE)
        return (PICL_FAILURE);

    /* get first string from table */
    err = picl_get_propval(proph, &tblh, pinfo.size);
    if (err != PICL_SUCCESS)
        return (err);

    err = picl_get_next_by_row(tblh, &rowproph);
    if (err != PICL_SUCCESS)
        return (err);

    err = picl_get_propinfo(rowproph, &pinfo);
    if (err != PICL_SUCCESS)
        return (err);

    pval = malloc(pinfo.size);
    if (pval == NULL)
        return (PICL_FAILURE);

    err = picl_get_propval(rowproph, pval, pinfo.size);
    if (err != PICL_SUCCESS) {
        free(pval);
        return (err);
    }

    *outbuf = pval;
    return (PICL_SUCCESS);
}
Exemplo n.º 2
0
static int64_t
montoya_get_int_propval(picl_nodehdl_t modh, char *prop_name, int *ret)
{
    int		err;
    picl_prophdl_t	proph;
    picl_propinfo_t	pinfo;
    int8_t		int8v;
    int16_t		int16v;
    int32_t		int32v;
    int64_t		int64v;

    err = picl_get_propinfo_by_name(modh, prop_name, &pinfo, &proph);
    if (err != PICL_SUCCESS) {
        *ret = err;
        return (0);
    }

    /*
     * If it is not an int, uint or byte array prop, return failure
     */
    if ((pinfo.type != PICL_PTYPE_INT) &&
            (pinfo.type != PICL_PTYPE_UNSIGNED_INT) &&
            (pinfo.type != PICL_PTYPE_BYTEARRAY)) {
        *ret = PICL_FAILURE;
        return (0);
    }

    switch (pinfo.size) {
    case sizeof (int8_t):
        err = picl_get_propval(proph, &int8v, sizeof (int8v));
        *ret = err;
        return (int8v);
    case sizeof (int16_t):
        err = picl_get_propval(proph, &int16v, sizeof (int16v));
        *ret = err;
        return (int16v);
    case sizeof (int32_t):
        err = picl_get_propval(proph, &int32v, sizeof (int32v));
        *ret = err;
        return (int32v);
    case sizeof (int64_t):
        err = picl_get_propval(proph, &int64v, sizeof (int64v));
        *ret = err;
        return (int64v);
    default:	/* not supported size */
        *ret = PICL_FAILURE;
        return (0);
    }
}
Exemplo n.º 3
0
/*****************************************************************************
Gets called by probe_cpu.  Cycles through the table values until we find
what we are looking for.
*****************************************************************************/
static void search_table(int index, picl_prophdl_t table_hdl) {

  picl_prophdl_t  col_hdl;
  picl_prophdl_t  row_hdl;
  picl_propinfo_t p_info;
  int             val;
  char            string_val[PICL_PROPNAMELEN_MAX];

  for (val = picl_get_next_by_col(table_hdl, &row_hdl); val != PICL_ENDOFLIST;
       val = picl_get_next_by_col(row_hdl, &row_hdl)) {
    if (val == PICL_SUCCESS) {
      for (col_hdl = row_hdl; val != PICL_ENDOFLIST;
           val = picl_get_next_by_row(col_hdl, &col_hdl)) {
        if (val == PICL_SUCCESS) {
          val = picl_get_propinfo(col_hdl, &p_info);
          if (val == PICL_SUCCESS) {
            if (p_info.type == PICL_PTYPE_CHARSTRING) {
              val = picl_get_propval(col_hdl, &string_val, sizeof(string_val));
              if (val == PICL_SUCCESS) {
                assign_string_value(index, string_val);
              }
            }
          }
        }
      }
    }
  }
}
Exemplo n.º 4
0
static int
process_switch(picl_nodehdl_t childh,
                   char propname[PICL_PROPNAMELEN_MAX])
{
    picl_nodehdl_t  sensorh;
    picl_propinfo_t sensor_info;

    char state[32];
    int st_cnt;
    char *switch_settings[]={"OFF","ON","NORMAL","LOCKED","UNKNOWN",
                                    "DIAG","SECURE"};
    u_int value;
    u_int found = 0;
    int max_key_posns = 7;
    int typ = 3; /*other*/

    if (sensor_array[typ].n >= MAX_SENSORS){
        DEBUGMSG(("ucd-snmp/lmSensors",
            "There are too many sensors of type %d\n",typ));
        }
    else{
        picl_errno_t    error_code,ec2;

        error_code = (picl_get_propinfo_by_name(childh,
                         "State",&sensor_info,&sensorh));
        if (error_code == PICL_SUCCESS) {
             ec2 = picl_get_propval(sensorh,&state,sensor_info.size);
             if (ec2 == PICL_SUCCESS){
                 for (st_cnt=0;st_cnt < max_key_posns;st_cnt++){
                     if (strncmp(state,switch_settings[st_cnt],
                           strlen(switch_settings[st_cnt])) == 0){
                         value = st_cnt;
                         found = 1;
                         break;
                         } /* end if */
                     } /* end for */
                 if (found==0)
                     value = 99;
                 sensor_array[typ].sensor[sensor_array[typ].n].value = value;
                 snprintf(sensor_array[typ].sensor[sensor_array[typ].n].name,
                     (PICL_PROPNAMELEN_MAX - 1),"%s",propname);
                 sensor_array[typ].sensor[sensor_array[typ].n].
                     name[PICL_PROPNAMELEN_MAX - 1] = '\0';
                 sensor_array[typ].n++;
                 } /*end if ec2*/
             else
                 DEBUGMSG(("ucd-snmp/lmSensors",
                     "sensor value read error code->%d\n",ec2));
            } /* end if */
        else
            DEBUGMSG(("ucd-snmp/lmSensors",
                "sensor lookup failed  error code->%d\n",error_code));
        }
} /*process switch*/
Exemplo n.º 5
0
static int
process_i2c(picl_nodehdl_t childh,
                   char propname[PICL_PROPNAMELEN_MAX])
{
    picl_nodehdl_t  sensorh;
    picl_propinfo_t sensor_info;

    char state[32];
    int st_cnt;
    char *i2c_settings[]={"OK"};
    u_int value;
    u_int found = 0;
    int max_i2c_posns = 1;
    int typ = 3; 

    picl_errno_t    error_code,ec2;

    if (sensor_array[typ].n >= MAX_SENSORS){
        DEBUGMSG(("ucd-snmp/lmSensors",
            "There are too many sensors of type %d\n",typ));
        }
    else{
        error_code = (picl_get_propinfo_by_name(childh,
                         "State",&sensor_info,&sensorh));
        if (error_code == PICL_SUCCESS) {
             ec2 = picl_get_propval(sensorh,&state,sensor_info.size);
             if (ec2 == PICL_SUCCESS){
                 for (st_cnt=0;st_cnt < max_i2c_posns;st_cnt++){
                     if (strncmp(state,i2c_settings[st_cnt],
                           strlen(i2c_settings[st_cnt])) == 0){
                         value=st_cnt;
                         found = 1;
                         break;
                         } 
                     } 
                 if (found==0)
                     value = 99;
                 sensor_array[typ].sensor[sensor_array[typ].n].value = value;
                 snprintf(sensor_array[typ].sensor[sensor_array[typ].n].name,
                     (PICL_PROPNAMELEN_MAX - 1),"%s",propname);
                 sensor_array[typ].sensor[sensor_array[typ].n].
                     name[PICL_PROPNAMELEN_MAX - 1] = '\0';
                 sensor_array[typ].n++;
                 } 
             else
                 DEBUGMSG(("ucd-snmp/lmSensors",
                     "sensor value read error code->%d\n",ec2));
            }
        else
            DEBUGMSG(("ucd-snmp/lmSensors",
                "sensor lookup failed  error code->%d\n",error_code));
        }
}
Exemplo n.º 6
0
static int
change_locator_state(picl_nodehdl_t locator_node, locator_info_t *locator_info)
{
	picl_prophdl_t	state_prop;
	char		state[PICL_PROPNAMELEN_MAX];
	int		err;
	char		*new_state;

	err = picl_get_prop_by_name(locator_node, "State", &state_prop);
	if (err != PICL_SUCCESS) {
		(void) fprintf(stderr,
			gettext("picl_get_prop_by_name failed: %s\n"),
			picl_strerror(err));
		return (err);
	}

	err = picl_get_propval(state_prop, state, sizeof (state));
	if (err != PICL_SUCCESS) {
		(void) fprintf(stderr,
			gettext("picl_get_propval failed: %s\n"),
			picl_strerror(err));
		return (err);
	}

	new_state = (locator_info->new_state) ? locator_info->on :
	    locator_info->off;

	if (strcmp(state, new_state) != 0) {
		picl_propinfo_t prop_info;
		err = picl_get_propinfo(state_prop, &prop_info);
		if (err != PICL_SUCCESS) {
			(void) fprintf(stderr,
				gettext("picl_get_propinfo failed: %s\n"),
				picl_strerror(err));
			return (err);
		}
		err = picl_set_propval(state_prop, new_state, prop_info.size);
		if (err != PICL_SUCCESS) {
			(void) fprintf(stderr,
				gettext("picl_set_propval failed: %s\n"),
				picl_strerror(err));
			return (err);
		}
	}
	return (err);
}
Exemplo n.º 7
0
int32_t
fill_device_from_id(picl_nodehdl_t device_id, char *assoc_id,
		picl_nodehdl_t *device)
{
	int32_t		err;
	picl_prophdl_t	tbl_hdl;
	picl_prophdl_t	reference_property;

	err = picl_get_propval_by_name(device_id, assoc_id, &tbl_hdl,
		sizeof (picl_prophdl_t));
	if (err != PICL_SUCCESS) {
#ifdef WORKFILE_DEBUG
		if (err != PICL_INVALIDHANDLE) {
			log_printf(dgettext(TEXT_DOMAIN,
			"fill_device_from_id failure in "
			"picl_get_propval_by_name err is %s\n"),
			    picl_strerror(err));
		}
#endif
		return (err);
	}

	err = picl_get_next_by_row(tbl_hdl, &reference_property);
	if (err != PICL_SUCCESS) {
#ifdef WORKFILE_DEBUG
		log_printf(dgettext(TEXT_DOMAIN,
		    "fill_device_from_id failure in picl_get_next_by_row"
		    " err is %s\n"), picl_strerror(err));
#endif
		return (err);
	}

	/* get node associated with reference property */
	err = picl_get_propval(reference_property, &(*device),
		sizeof (picl_nodehdl_t));

#ifdef WORKFILE_DEBUG
	if (err != 0) {
		log_printf(dgettext(TEXT_DOMAIN,
		"fill_device_from_id failure in picl_get_propval"
		" err is %s\n"), picl_strerror(err));
	}
#endif

	return (err);
}
Exemplo n.º 8
0
static int
read_enum_sensor( picl_nodehdl_t childh, float *value, const char **options )
{
    picl_nodehdl_t  sensorh;
    picl_propinfo_t sensor_info;
    picl_errno_t    error_code;
    char            state[PICL_PROPSIZE_MAX];
    int             i;

    /*
     *  Retrieve the specified sensor information and value
     */
    error_code = picl_get_propinfo_by_name(childh, "State", &sensor_info, &sensorh);
    if ( error_code != PICL_SUCCESS ) {
        DEBUGMSGTL(("sensors:arch:detail", "sensor info lookup failed (%d)\n",
                                            error_code));
        return( error_code );
    }

    error_code = picl_get_propval(sensorh, state, sensor_info.size);
    if ( error_code != PICL_SUCCESS ) {
        DEBUGMSGTL(("sensors:arch:detail", "sensor value lookup failed (%d)\n",
                                            error_code));
        return( error_code );
    }

    /*
     * Try to find a matching entry in the list of options.
     * Note that some platforms may use upper or lower case
     *   versions of these enumeration values
     *  (so the checks are case insensitive)
     */
    *value = 99;    /* Dummy value */
    for ( i=0;  options[i] != NULL; i++ ) {
        if (strncasecmp(state, options[i], strlen(options[i])) == 0) {
            *value = i;
            return 0;
        }
    }
    
    DEBUGMSGTL(("sensors:arch:detail", "Enumeration state %s not matched\n",
                                        state));
    return 0;  /* Or an error ? */
}
Exemplo n.º 9
0
static int
read_enum_sensor(picl_nodehdl_t childh, const char **options, u_int *value)
{
  picl_nodehdl_t  sensorh;
  picl_propinfo_t sensor_info;
  picl_errno_t    error_code;
  char            state[PICL_PROPSIZE_MAX];
  int             i;

  error_code = (picl_get_propinfo_by_name(childh, "State",
                                         &sensor_info, &sensorh));

  if (error_code != PICL_SUCCESS) {
     DEBUGMSGTL(("ucd-snmp/lmSensors",
                "sensor info lookup failed in read_enum_sensor - error code->%d\n", error_code));
     return(error_code);
  }

  error_code = picl_get_propval(sensorh, state, sensor_info.size);

  if (error_code != PICL_SUCCESS) {
    DEBUGMSGTL(("ucd-snmp/lmSensors",
               "sensor value lookup failed in read_enum_sensor - error code->%d\n", error_code));
    return(error_code);
  }

  /* Start with error value, then try to fill in something better.
     Use case-insensitive match to find the right value since platforms
     may return either case. 
  */

  *value = 99;

  for (i = 0; options[i] != NULL; i++){
    if (strncasecmp(state, options[i], strlen(options[i])) == 0){
      *value = i;
      break;
    } 
  }

  DEBUGMSGTL(("ucd-snmp/lmSensors", "read_enum_sensor value is %d\n", *value));
  return(error_code);
} /* end of read_enum_sensor() */
Exemplo n.º 10
0
static int
process_digital_sensor(picl_nodehdl_t childh,
                   char propname[PICL_PROPNAMELEN_MAX])
{
    picl_nodehdl_t  sensorh;
    picl_propinfo_t sensor_info;

    int temp; /*volts?*/
    int typ = 2; /*volts*/

    picl_errno_t    error_code,ec2;

    if (sensor_array[typ].n >= MAX_SENSORS){
        DEBUGMSG(("ucd-snmp/lmSensors",
            "There are too many sensors of type %d\n",typ));
        }
    else{
        error_code = (picl_get_propinfo_by_name(childh,
                          "AtoDSensorValue",&sensor_info,&sensorh));
        if (error_code == PICL_SUCCESS) {
             ec2 = picl_get_propval(sensorh,&temp,sizeof(temp));
             if (ec2 == PICL_SUCCESS){
                 sensor_array[typ].sensor[sensor_array[typ].n].value = temp;
                 snprintf(sensor_array[typ].sensor[sensor_array[typ].n].name,
                    (PICL_PROPNAMELEN_MAX - 1),"%s",propname);
                 sensor_array[typ].sensor[sensor_array[typ].n].
                      name[PICL_PROPNAMELEN_MAX - 1] = '\0';
                 sensor_array[typ].n++;
                 }
             else
                 DEBUGMSG(("ucd-snmp/lmSensors", 
                   "sensor value read error code->%d\n",ec2));
            } /* end if */
        else
            DEBUGMSG(("ucd-snmp/lmSensors", 
              "sensor lookup failed  error code->%d\n",error_code));
        }
}  /* process digital sensor */
Exemplo n.º 11
0
static int
walk_callback(picl_nodehdl_t nodeh, void *args)
{
        char vga[10];
        picl_propinfo_t pinfo;
        picl_prophdl_t ph;
        /*int i;*/

        if (picl_get_propval_by_name(nodeh, "driver-name", vga, 10) != 0) {
                return (PICL_WALK_CONTINUE);
        }
         
        if (strcmp(vga, "vgatext") != 0) {
                return (PICL_WALK_CONTINUE);
        }
         
        if (picl_get_propinfo_by_name(nodeh, "display-edif-block",
                                &pinfo, &ph) != 0) {
                return (PICL_WALK_TERMINATE);
        }      
               
        mem = (unsigned char *)malloc(pinfo.size);
	if (mem == NULL) {
		return (PICL_WALK_TERMINATE);
	}

        if (picl_get_propval(ph, mem, pinfo.size)) {
                (void) printf("Unable to get block\n");
                return (PICL_WALK_TERMINATE);
        }      
               
        /*(void) printf("display-edif-block = ");
        for (i = 0; i < pinfo.size; i++)
                (void) printf("%02x.", mem[i]);
        (void) putchar('\n');*/
               
        return (PICL_WALK_TERMINATE);
}       
Exemplo n.º 12
0
int
prt_mem_bank_size(picl_nodehdl_t nodeh, void *args)
{
	int		ret;
	void 		*data;
	u_longlong_t	value;
	unsigned long	size;
	picl_prophdl_t	proph;
	picl_propinfo_t	pinfo;
	char		c;

	ret = picl_get_propinfo_by_name(nodeh, mem_prop[1],
						&pinfo, &proph);

	if (ret) {
		return (PICL_WALK_CONTINUE);
	}

	if (!(pinfo.accessmode & PICL_READ)) {
		return (PICL_WALK_CONTINUE);
	}

	if (pinfo.size == 0) {
		return (PICL_WALK_CONTINUE);
	}

	data = malloc(pinfo.size);

	if (data == NULL) {
		return (PICL_WALK_CONTINUE);
	}

	ret = picl_get_propval(proph, data, pinfo.size);

	if (ret) {
		(void) free(data);
		return (PICL_WALK_CONTINUE);
	}

	if ((pinfo.type == PICL_PTYPE_INT) ||
	(pinfo.type == PICL_PTYPE_UNSIGNED_INT)) {
		switch (pinfo.size) {
			case sizeof (char):
				value = *(unsigned char *)data;
				break;
			case sizeof (short):
				value = *(unsigned short *)data;
				break;
			case sizeof (int):
				value =	*(unsigned int *)data;
				break;
			case sizeof (long long):
				value =	*(unsigned long long *)data;
				break;
			default:
				break;
		}
	}

	if (value == 0) {
		(void) free(data);
		return (PICL_WALK_CONTINUE);
	}

	if (*(int *)args == 0) {
		PRINTF("(");
	} else {
		PRINTF(" + ");
	}

	value = value >> 10;

	if (value >= 1024) {
		value = value >> 10;

		if (value >= 1024) {
			size = (unsigned long) (value & 0x3ff);
			value = value >> 10;
			c = 'G';
		} else {
Exemplo n.º 13
0
void
prt_prop_val(picl_prophdl_t proph, picl_propinfo_t *pinfo)
{
	int	ret;
	void 	*data;
	char 	*str;

	if (!(pinfo->accessmode & PICL_READ)) {
		return;
	}

	if (pinfo->size == 0) {
		return;
	}

	data = malloc(pinfo->size);

	if (data == NULL) {
		return;
	}

	ret = picl_get_propval(proph, data, pinfo->size);

	if (ret) {
		(void) free(data);
		return;
	}

	switch (pinfo->type) {
		case PICL_PTYPE_CHARSTRING:
			PRINTF("%s", (char *)data);
			break;

		case PICL_PTYPE_INT:
			switch (pinfo->size) {
				case sizeof (char):
					PRINTF("%d",
					*(char *)data / granu);
					break;
				case sizeof (short):
					PRINTF("%hd",
					*(short *)data / granu);
					break;
				case sizeof (int):
					PRINTF("%d",
					*(int *)data / granu);
					break;
				case sizeof (long long):
					PRINTF("%lld",
						*(long long *)data / granu);
					break;
				default:
					PRINTF("err");
			}
			break;

		case PICL_PTYPE_UNSIGNED_INT:
			switch (pinfo->size) {
				case sizeof (unsigned char):
					PRINTF("%x",
					*(unsigned char *)data / granu);
					break;
				case sizeof (unsigned short):
					PRINTF("%hx",
					*(unsigned short *)data / granu);
					break;
				case sizeof (unsigned int):
					PRINTF("%u",
					*(unsigned int *)data / granu);
					break;
				case sizeof (unsigned long long):
					PRINTF("%llu",
					*(unsigned long long *)data / granu);
					break;
				default:
					PRINTF("err");
			}
			break;

		case PICL_PTYPE_FLOAT:
			switch (pinfo->size) {
				case sizeof (float):
					PRINTF("%f", *(float *)data);
					break;
				case sizeof (double):
					PRINTF("%f", *(double *)data);
					break;
				default:
					PRINTF("err");
			}
			break;

		case PICL_PTYPE_TIMESTAMP:
			str = ctime((time_t *)data);

			if (str) {
				str[strlen(str) - 1] = '\0';
				PRINTF("%s", str);
			}
			break;

		case PICL_PTYPE_TABLE:
			PRINTF("TBL");
			break;
		case PICL_PTYPE_REFERENCE:
			PRINTF("REF");
			break;
		case PICL_PTYPE_BYTEARRAY:
			PRINTF("BIN");
			break;
		default:
			PRINTF("unknown");
	}

	(void) free(data);
}
Exemplo n.º 14
0
static int
read_num_sensor(picl_nodehdl_t childh, const char *prop, int scale, int *value)
 {
  picl_nodehdl_t  sensorh;
  picl_propinfo_t sensor_info;
  picl_errno_t    error_code;
  int             valid = 1;

  union valu {
    char buf[PICL_PROPSIZE_MAX];
    uint32_t us4;
    uint16_t us2;
    int32_t is4;
    int16_t is2;
    float f;
  } val;

  error_code = (picl_get_propinfo_by_name(childh, prop,
                                         &sensor_info, &sensorh));

  if (error_code != PICL_SUCCESS) {
     DEBUGMSGTL(("ucd-snmp/lmSensors",
                "sensor info lookup failed in read_num_sensor - error code->%d\n", error_code));
     return(error_code);
  }

  error_code = picl_get_propval(sensorh, &val.buf, sensor_info.size);

  if (error_code != PICL_SUCCESS) {
    DEBUGMSGTL(("ucd-snmp/lmSensors",
               "sensor value lookup failed in read_num_sensor - error code->%d\n", error_code));
    return(error_code);
  }
    
  /* Can't make assumptions about the type or size of the value we get... */

  if  (sensor_info.type == PICL_PTYPE_FLOAT) {
    *value = (int)(val.f*scale);
  } else if (sensor_info.type == PICL_PTYPE_UNSIGNED_INT) {
    if (sensor_info.size == 2) {
      *value = (int)(val.us2 * scale);
    } else if (sensor_info.size == 4) {
      *value = (int)(val.us4 * scale);
    } else
      valid = 0;
  } else if (sensor_info.type == PICL_PTYPE_INT) {
    if (sensor_info.size == 2) {
      *value = (int)(val.is2 * scale);
    } else if (sensor_info.size == 4) {
      *value = (int)(val.is4 * scale);
    } else 
      valid = 0;
  } else
    valid = 0;

  if (valid == 0) {
    DEBUGMSGTL(("ucd-snmp/lmSensors",
               "Don't know how to handle data type %d with length %d\n", 
               sensor_info.type, sensor_info.size));
    error_code = PICL_FAILURE;
  } else 
    DEBUGMSGTL(("ucd-snmp/lmSensors", "read_num_sensor value is %d\n", *value));

  return(error_code);
} /* end of read_num_sensor() */
Exemplo n.º 15
0
int32_t
fill_device_array_from_id(picl_nodehdl_t device_id, char *assoc_id,
	int32_t *number_of_devices, picl_nodehdl_t *device_array[])
{
	int32_t		err;
	int		i;
	picl_prophdl_t	tbl_hdl;
	picl_prophdl_t	entry;
	int		devs = 0;

	err = picl_get_propval_by_name(device_id, assoc_id, &tbl_hdl,
		sizeof (picl_prophdl_t));
	if ((err != PICL_SUCCESS) && (err != PICL_INVALIDHANDLE)) {
#ifdef WORKFILE_DEBUG
	    log_printf(dgettext(TEXT_DOMAIN,
	    "fill_device_array_from_id failure in "
	    "picl_get_propval_by_name err is %s\n"), picl_strerror(err));
#endif
	    return (err);
	}

	entry = tbl_hdl;
	while (picl_get_next_by_row(entry, &entry) == 0)
		++devs;

	*device_array = calloc((devs), sizeof (picl_nodehdl_t));
	if (*device_array == NULL) {

#ifdef WORFILE_DEBUG
		log_printf(dgettext(TEXT_DOMAIN,
		"fill_device_array_from_id failure getting memory"
		" for array\n"));
#endif
		return (PICL_FAILURE);
	}

	entry = tbl_hdl;
	for (i = 0; i < devs; i++) {
		err = picl_get_next_by_row(entry, &entry);
		if (err != 0) {
#ifdef WORKFILE_DEBUG
			log_printf(dgettext(TEXT_DOMAIN,
			"fill_device_array_from_id failure in "
			"picl_get_next_by_row err is %s\n"),
			    picl_strerror(err));
#endif
			return (err);
		}

		/* get node associated with reference property */
		err = picl_get_propval(entry, &((*device_array)[i]),
			sizeof (picl_nodehdl_t));
		if (err != 0) {
#ifdef WORKFILE_DEBUG
			log_printf(dgettext(TEXT_DOMAIN,
			"fill_device_array_from_id failure in "
			"picl_get_propval err is %s\n"), picl_strerror(err));
#endif

			return (err);
		}
	}
	*number_of_devices = devs;
	return (err);
}
Exemplo n.º 16
0
/*
 * Handle a numeric-valued sensor
 */
static int
read_num_sensor( picl_nodehdl_t childh, const char *propval, float *value )
{
    picl_nodehdl_t  sensorh;
    picl_propinfo_t sensor_info;
    picl_errno_t    error_code;

    union valu {
        char buf[PICL_PROPSIZE_MAX];
        uint32_t us4;
        uint16_t us2;
        int32_t is4;
        int16_t is2;
        float f;
    } val;

    /*
     *  Retrieve the specified sensor information and value
     */
    error_code = picl_get_propinfo_by_name(childh, propval, &sensor_info, &sensorh);
    if ( error_code != PICL_SUCCESS ) {
        DEBUGMSGTL(("sensors:arch:detail", "sensor info lookup failed (%d)\n",
                                            error_code));
        return( error_code );
    }

    error_code = picl_get_propval(sensorh, &val.buf, sensor_info.size);
    if ( error_code != PICL_SUCCESS ) {
        DEBUGMSGTL(("sensors:arch:detail", "sensor value lookup failed (%d)\n",
                                            error_code));
        return( error_code );
    }

    /*
     *  Check the validity (type and size) of this value
     */
    if ( sensor_info.type == PICL_PTYPE_FLOAT ) {
        *value = val.f;
    } else if ( sensor_info.type == PICL_PTYPE_UNSIGNED_INT ) {
        /* 16-bit or 32-bit unsigned integers */
        if ( sensor_info.size == 2 ) {
            *value = val.us2;
        } else if ( sensor_info.size == 4 ) { 
            *value = val.us4;
        } else {
            DEBUGMSGTL(("sensors:arch:detail", "unsigned integer (%d bit)\n",
                                                sensor_info.size * 8));
            return PICL_FAILURE;
        }
    } else if ( sensor_info.type == PICL_PTYPE_INT ) {
        /* 16-bit or 32-bit signed integers */
        if ( sensor_info.size == 2 ) {
            *value = val.is2;
        } else if ( sensor_info.size == 4 ) { 
            *value = val.is4;
        } else {
            DEBUGMSGTL(("sensors:arch:detail", "signed integer (%d bit)\n",
                                                sensor_info.size * 8));
            return PICL_FAILURE;
        }
    } else {
        DEBUGMSGTL(("sensors:arch:detail", "unrecognised type (%d)\n",
                                            sensor_info.type));
        return PICL_FAILURE;
    }

    return error_code;
}
/*****************************************************************************
Gets called by picl_walk_tree_by_class.  Then it cycles through the properties
until we find what we are looking for.  Once we are done, we return
PICL_WALK_TERMINATE to stop picl_walk_tree_by_class from traversing the tree.

Note that PICL_PTYPE_UNSIGNED_INT and PICL_PTYPE_INT can either be 4-bytes
or 8-bytes.
*****************************************************************************/
static int probe_cpu(picl_nodehdl_t node_hdl, void* dummy_arg) {

  picl_prophdl_t  p_hdl;
  picl_prophdl_t  table_hdl;
  picl_propinfo_t p_info;
  long long       long_long_val;
  unsigned int    uint_val;
  int             index;
  int             int_val;
  int             val;
  char            string_val[PICL_PROPNAMELEN_MAX];

  val = picl_get_first_prop(node_hdl, &p_hdl);
  while (val == PICL_SUCCESS) {
    called_cpu_probe = 1;
    val = picl_get_propinfo(p_hdl, &p_info);
    if (val == PICL_SUCCESS) {
      for (index = 0; index < NUM_ITEMS; index++) {
        if (strcasecmp(p_info.name, items[index]) == 0) {
          if (p_info.type == PICL_PTYPE_UNSIGNED_INT) {
            if (p_info.size == sizeof(uint_val)) {
              val = picl_get_propval(p_hdl, &uint_val, sizeof(uint_val));
              if (val == PICL_SUCCESS) {
                long_long_val = uint_val;
                assign_value(index, long_long_val);
              }
            }
            else if (p_info.size == sizeof(long_long_val)) {
              val = picl_get_propval(p_hdl, &long_long_val,
                                     sizeof(long_long_val));
              if (val == PICL_SUCCESS) {
                assign_value(index, long_long_val);
              }
            }
          }
          else if (p_info.type == PICL_PTYPE_INT) {
            if (p_info.size == sizeof(int_val)) {
              val = picl_get_propval(p_hdl, &int_val, sizeof(int_val));
              if (val == PICL_SUCCESS) {
                long_long_val = int_val;
                assign_value(index, long_long_val);
              }
            }
            else if (p_info.size == sizeof(long_long_val)) {
              val = picl_get_propval(p_hdl, &long_long_val,
                                     sizeof(long_long_val));
              if (val == PICL_SUCCESS) {
                assign_value(index, long_long_val);
              }
            }
          }
          else if (p_info.type == PICL_PTYPE_CHARSTRING) {
            val = picl_get_propval(p_hdl, &string_val, sizeof(string_val));
            if (val == PICL_SUCCESS) {
              assign_string_value(index, string_val);
            }
          }
          else if (p_info.type == PICL_PTYPE_TABLE) {
            val = picl_get_propval(p_hdl, &table_hdl, p_info.size);
            if (val == PICL_SUCCESS) {
              search_table(index, table_hdl);
            }
          }
          break;
        } else if (index == NUM_ITEMS-1) {
	  if (p_info.type == PICL_PTYPE_CHARSTRING) {
            val = picl_get_propval(p_hdl, &string_val, sizeof(string_val));
            if (val == PICL_SUCCESS) {
            }	  
	  }
	} 
      }
    }

    val = picl_get_next_prop(p_hdl, &p_hdl);
  }
  return PICL_WALK_TERMINATE;
}