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