1*d2ec54f7Sphitran /***************************************************************************
2*d2ec54f7Sphitran *
3*d2ec54f7Sphitran * hal-system-lcd-set-brightness-sunos.c : Set 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 <sys/acpi_drv.h>
26*d2ec54f7Sphitran #include "../../hald/util.h"
27*d2ec54f7Sphitran
28*d2ec54f7Sphitran int
main(int argc,char * argv[])29*d2ec54f7Sphitran main(int argc, char *argv[])
30*d2ec54f7Sphitran {
31*d2ec54f7Sphitran char arg[10];
32*d2ec54f7Sphitran int level;
33*d2ec54f7Sphitran int fd = -1;
34*d2ec54f7Sphitran char *udi;
35*d2ec54f7Sphitran char device_file[HAL_PATH_MAX] = "/devices";
36*d2ec54f7Sphitran char *devfs_path;
37*d2ec54f7Sphitran
38*d2ec54f7Sphitran if ((udi = getenv("UDI")) == NULL) {
39*d2ec54f7Sphitran return (1);
40*d2ec54f7Sphitran }
41*d2ec54f7Sphitran if ((devfs_path = getenv("HAL_PROP_SOLARIS_DEVFS_PATH")) == NULL) {
42*d2ec54f7Sphitran return (1);
43*d2ec54f7Sphitran }
44*d2ec54f7Sphitran strlcat(device_file, devfs_path, HAL_PATH_MAX);
45*d2ec54f7Sphitran fprintf(stderr, "Setting brightness on %s (udi=%s)",
46*d2ec54f7Sphitran device_file, udi);
47*d2ec54f7Sphitran
48*d2ec54f7Sphitran if ((fd = open(device_file, O_RDONLY | O_NONBLOCK)) < 0) {
49*d2ec54f7Sphitran fprintf(stderr, "Cannot open %s: %s", device_file,
50*d2ec54f7Sphitran strerror(errno));
51*d2ec54f7Sphitran return (1);
52*d2ec54f7Sphitran }
53*d2ec54f7Sphitran if (fgets(arg, sizeof (arg), stdin)) {
54*d2ec54f7Sphitran level = atoi(arg);
55*d2ec54f7Sphitran }
56*d2ec54f7Sphitran if (ioctl(fd, ACPI_DRV_IOC_SET_BRIGHTNESS, &level) < 0) {
57*d2ec54f7Sphitran close(fd);
58*d2ec54f7Sphitran return (1);
59*d2ec54f7Sphitran } else {
60*d2ec54f7Sphitran close(fd);
61*d2ec54f7Sphitran return (0);
62*d2ec54f7Sphitran }
63*d2ec54f7Sphitran }
64