/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* libpower routines that interface with the power management driver and
* the kernel
*/
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <strings.h>
#include <libnvpair.h>
#include <libpower.h>
#include <libpower_impl.h>
{
int fd;
char *authname;
char **vals;
char *tok;
char *propname;
void *propval;
if (fd == -1) {
return (PM_ERROR_SYSTEM);
}
/* Ask the kernel what size buffer is required to get the properties */
errno = 0;
/* Allocate a buffer of the size indicated by the kernel */
}
/* The kernel did not return a buffer size. */
"%s kernel did not return a buffer size\n",
break;
} else {
/* Could not allocate memory */
"%s could not allocate %d bytes: %d (%s)\n",
break;
}
}
/*
* Memory has been allocated. Zero the buffer, clear the
* errno, and try to get the properties again.
*/
errno = 0;
}
if (errno != 0) {
return (PM_ERROR_SYSTEM);
}
/*
* Unpack the list of properties returned by the kernel into an nvlist.
*/
return (PM_ERROR_NVLIST);
}
/*
* Scan the list of properties returned by the kernel and build a
* result list to return based on the data type of each property.
*/
err = PM_SUCCESS;
/*
* The kernel returns a list with nvpair names in the form:
* authority_name / property_name
*
* extract both the property name and authority name.
*/
if (authority == PM_AUTHORITY_INVALID) {
/*
* Any property received from the kernel without a
* valid authority prefix is by definition a current
* value.
*/
}
/*
* Add the property value to the result list based on the
* data type of the property.
*/
switch (proptype) {
case DATA_TYPE_BOOLEAN_VALUE:
if (errno == 0) {
}
break;
case DATA_TYPE_UINT64:
if (errno == 0) {
}
break;
case DATA_TYPE_STRING:
if (errno == 0) {
}
}
break;
default:
break;
}
/* Parse the next pair */
}
if (err == PM_SUCCESS) {
/* Add property group names to each property */
}
return (err);
}
/*
* Update the kernel using the values in the specified nvlist. The input
* nvlist has the same form as that output by the listprop routine, above.
*/
{
int serrno;
int fd;
char *valsp;
const char *propname;
return (PM_ERROR_NVLIST);
}
err = PM_SUCCESS;
errno = 0;
/* Get the name of the current property */
/* Get the value list for this property */
if (errno != 0) {
/* Badly formed list */
break;
}
/*
* Find the SMF value for this property in its value list.
* This is the value to synchronize with the kernel.
*/
&smf);
/*
* This pair does not have an SMF value and should not
* be sent to the kernel
*/
"%s property %s does not have an SMF value\n",
continue;
} else if (errno != 0) {
"%s encountered a fatal nvlist error %d (%s)\n",
break;
}
errno = 0;
switch (nvpair_type(smf)) {
case DATA_TYPE_BOOLEAN_VALUE:
if (errno == 0) {
}
if (errno == 0) {
err = PM_SUCCESS;
"%s added %s = %d to kernel update list\n",
} else {
"%s encountered a fatal nvlist error %d "
}
break;
case DATA_TYPE_STRING:
if (errno == 0) {
valsp);
}
if (errno == 0) {
err = PM_SUCCESS;
"%s added %s = %s to kernel update list\n",
} else {
"%s encountered a fatal nvlist error %d "
}
break;
case DATA_TYPE_UINT64:
valu = 0;
if (errno == 0) {
}
if (errno == 0) {
err = PM_SUCCESS;
"%s added %s = %llu to kernel update "
} else {
"%s encountered a fatal nvlist error %d "
}
break;
default:
"%s unhandled SMF value type %d property %s\n",
break;
}
}
if (err != PM_SUCCESS) {
/* Failed to build a list to send to the kernel */
return (err);
}
/* Pack the nvlist into a buffer for transmission to the kernel */
if (errno != 0) {
}
return (PM_ERROR_NVLIST);
}
if (fd == -1) {
"%s open(%s) failed with %d (%s)\n", __FUNCTION__,
return (PM_ERROR_SYSTEM);
}
/* Synchronize the SMF values with the kernel */
errno = 0;
/* Interrupted system call. Try again. */
errno = 0;
}
/* Clean up memory, preserving any error created by the ioctl */
}
/* Restore the ioctl's errno and return */
if (errno == 0)
return (PM_SUCCESS);
return (PM_ERROR_NOT_SUPPORTED);
return (PM_ERROR_SYSTEM);
}