1*6573Sphitran /***************************************************************************
2*6573Sphitran  *
3*6573Sphitran  * hal-system-lcd-get-brightness-sunos.c : Get LCD brightness
4*6573Sphitran  *
5*6573Sphitran  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
6*6573Sphitran  * Use is subject to license terms.
7*6573Sphitran  *
8*6573Sphitran  * Licensed under the Academic Free License version 2.1
9*6573Sphitran  *
10*6573Sphitran  **************************************************************************/
11*6573Sphitran 
12*6573Sphitran #pragma ident	"%Z%%M%	%I%	%E% SMI"
13*6573Sphitran 
14*6573Sphitran #ifdef HAVE_CONFIG_H
15*6573Sphitran #include <config.h>
16*6573Sphitran #endif
17*6573Sphitran 
18*6573Sphitran #include <errno.h>
19*6573Sphitran #include <string.h>
20*6573Sphitran #include <strings.h>
21*6573Sphitran #include <ctype.h>
22*6573Sphitran #include <stdlib.h>
23*6573Sphitran #include <stdio.h>
24*6573Sphitran #include <sys/ioctl.h>
25*6573Sphitran #include <fcntl.h>
26*6573Sphitran #include <unistd.h>
27*6573Sphitran #include "../../hald/util.h"
28*6573Sphitran #include <sys/acpi_drv.h>
29*6573Sphitran 
30*6573Sphitran int
main(int argc,char * argv[])31*6573Sphitran main(int argc, char *argv[])
32*6573Sphitran {
33*6573Sphitran 	struct acpi_drv_output_status status;
34*6573Sphitran 	int fd = -1;
35*6573Sphitran 	char *udi;
36*6573Sphitran 	char device_file[HAL_PATH_MAX] = "/devices";
37*6573Sphitran 	char *devfs_path;
38*6573Sphitran 
39*6573Sphitran 	if ((udi = getenv("UDI")) == NULL) {
40*6573Sphitran 		return (-1);
41*6573Sphitran 	}
42*6573Sphitran 	if ((devfs_path = getenv("HAL_PROP_SOLARIS_DEVFS_PATH")) == NULL) {
43*6573Sphitran 		return (-1);
44*6573Sphitran 	}
45*6573Sphitran 
46*6573Sphitran 	strlcat(device_file, devfs_path, HAL_PATH_MAX);
47*6573Sphitran 	fprintf(stderr, "Getting brightness on %s (udi=%s)",
48*6573Sphitran 	    device_file, udi);
49*6573Sphitran 	if ((fd = open(device_file, O_RDONLY | O_NONBLOCK)) < 0) {
50*6573Sphitran 		fprintf(stderr, "Cannot open %s: %s", device_file,
51*6573Sphitran 		    strerror(errno));
52*6573Sphitran 		return (-1);
53*6573Sphitran 	}
54*6573Sphitran 
55*6573Sphitran 	bzero(&status, sizeof (status));
56*6573Sphitran 	if (ioctl(fd, ACPI_DRV_IOC_STATUS, &status) < 0) {
57*6573Sphitran 		close(fd);
58*6573Sphitran 		return (-1);
59*6573Sphitran 	} else {
60*6573Sphitran 		close(fd);
61*6573Sphitran 		return (status.cur_level_index);
62*6573Sphitran 	}
63*6573Sphitran }
64