xref: /onnv-gate/usr/src/cmd/hal/hald/solaris/devinfo_misc.c (revision 9608:c0413dca22b0)
12912Sartem /***************************************************************************
22912Sartem  *
32912Sartem  * devinfo_misc : misc devices
42912Sartem  *
5*9608SLin.Guo@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
62912Sartem  * Use is subject to license terms.
72912Sartem  *
82912Sartem  * Licensed under the Academic Free License version 2.1
92912Sartem  *
102912Sartem  **************************************************************************/
112912Sartem 
123121Sartem #ifdef HAVE_CONFIG_H
136654Snp146283 #include <config.h>
143121Sartem #endif
153121Sartem 
162912Sartem #include <stdio.h>
172912Sartem #include <string.h>
182912Sartem #include <sys/utsname.h>
192912Sartem #include <libdevinfo.h>
206573Sphitran #include <sys/uadmin.h>
212912Sartem 
222912Sartem #include "../osspec.h"
232912Sartem #include "../logger.h"
242912Sartem #include "../hald.h"
252912Sartem #include "../hald_dbus.h"
262912Sartem #include "../device_info.h"
272912Sartem #include "../util.h"
282912Sartem #include "devinfo_misc.h"
292912Sartem 
302912Sartem static HalDevice *devinfo_computer_add(HalDevice *, di_node_t, char *, char *);
316573Sphitran static HalDevice *devinfo_keyboard_add(HalDevice *, di_node_t, char *, char *);
32*9608SLin.Guo@Sun.COM static HalDevice *devinfo_mouse_add(HalDevice *, di_node_t, char *, char *);
332912Sartem static HalDevice *devinfo_default_add(HalDevice *, di_node_t, char *, char *);
34*9608SLin.Guo@Sun.COM const gchar *devinfo_keyboard_get_prober(HalDevice *d, int *timeout);
352912Sartem 
362912Sartem DevinfoDevHandler devinfo_computer_handler = {
376573Sphitran 	devinfo_computer_add,
386573Sphitran 	NULL,
396573Sphitran 	NULL,
406573Sphitran 	NULL,
416573Sphitran 	NULL,
426573Sphitran 	NULL
436573Sphitran };
446654Snp146283 
456573Sphitran DevinfoDevHandler devinfo_keyboard_handler = {
466573Sphitran 	devinfo_keyboard_add,
472912Sartem 	NULL,
482912Sartem 	NULL,
492912Sartem 	NULL,
502912Sartem 	NULL,
51*9608SLin.Guo@Sun.COM 	devinfo_keyboard_get_prober
52*9608SLin.Guo@Sun.COM };
53*9608SLin.Guo@Sun.COM 
54*9608SLin.Guo@Sun.COM DevinfoDevHandler devinfo_mouse_handler = {
55*9608SLin.Guo@Sun.COM 	devinfo_mouse_add,
56*9608SLin.Guo@Sun.COM 	NULL,
57*9608SLin.Guo@Sun.COM 	NULL,
58*9608SLin.Guo@Sun.COM 	NULL,
59*9608SLin.Guo@Sun.COM 	NULL,
606573Sphitran 	NULL
612912Sartem };
626654Snp146283 
632912Sartem DevinfoDevHandler devinfo_default_handler = {
646573Sphitran 	devinfo_default_add,
652912Sartem 	NULL,
662912Sartem 	NULL,
672912Sartem 	NULL,
682912Sartem 	NULL,
696573Sphitran 	NULL
702912Sartem };
712912Sartem 
722912Sartem static HalDevice *
devinfo_computer_add(HalDevice * parent,di_node_t node,char * devfs_path,char * device_type)732912Sartem devinfo_computer_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
742912Sartem {
752912Sartem 	HalDevice *d, *local_d;
762912Sartem 	struct utsname un;
772912Sartem 
782912Sartem 	if (strcmp (devfs_path, "/") != 0) {
792912Sartem 		return (NULL);
802912Sartem 	}
812912Sartem 
822912Sartem 	d = hal_device_new ();
832912Sartem 
846573Sphitran 	hal_device_property_set_string (d, "info.subsystem", "unknown");
856573Sphitran 	hal_device_property_set_string (d, "info.product", "Computer");
866573Sphitran 	hal_device_property_set_string (d, "info.udi", "/org/freedesktop/Hal/devices/computer");
876573Sphitran 	hal_device_set_udi (d, "/org/freedesktop/Hal/devices/computer");
882912Sartem 	hal_device_property_set_string (d, "solaris.devfs_path", devfs_path);
892912Sartem 
902912Sartem 	if (uname (&un) >= 0) {
912912Sartem 		hal_device_property_set_string (d, "system.kernel.name", un.sysname);
922912Sartem 		hal_device_property_set_string (d, "system.kernel.version", un.release);
932912Sartem 		hal_device_property_set_string (d, "system.kernel.machine", un.machine);
942912Sartem 	}
952912Sartem 
966573Sphitran 	hal_device_property_set_bool(d, "power_management.can_hibernate",
976573Sphitran 	    (uadmin(A_FREEZE, AD_CHECK_SUSPEND_TO_DISK, 0) == 0));
986573Sphitran 	hal_device_property_set_bool(d, "power_management.can_suspend",
996573Sphitran 	    (uadmin(A_FREEZE, AD_CHECK_SUSPEND_TO_RAM, 0) == 0));
1006573Sphitran 
1016573Sphitran 	hal_device_add_capability(d, "button");
1026573Sphitran 
1034035Sphitran 	/*
1044035Sphitran 	 * Let computer be in TDL while synthesizing all other events
1054035Sphitran 	 * because some may write to the object
1064035Sphitran 	 */
1076573Sphitran 	hal_device_store_add (hald_get_tdl (), d);
1084035Sphitran 
1092912Sartem 	devinfo_add_enqueue (d, devfs_path, &devinfo_computer_handler);
1102912Sartem 
1112912Sartem 	/* all devinfo devices belong to the 'local' branch */
1122912Sartem 	local_d = hal_device_new ();
1132912Sartem 
1143121Sartem 	hal_device_property_set_string (local_d, "info.parent", hal_device_get_udi (d));
1156573Sphitran 	hal_device_property_set_string (local_d, "info.subsystem", "unknown");
1166573Sphitran 	hal_device_property_set_string (local_d, "info.product", "Local devices");
1176573Sphitran 	hal_device_property_set_string (local_d, "info.udi", "/org/freedesktop/Hal/devices/local");
1186573Sphitran 	hal_device_set_udi (local_d, "/org/freedesktop/Hal/devices/local");
1192912Sartem 	hal_device_property_set_string (local_d, "solaris.devfs_path", "/local");
1202912Sartem 
1212912Sartem 	devinfo_add_enqueue (local_d, "/local", &devinfo_default_handler);
1222912Sartem 
1232912Sartem 	return (local_d);
1242912Sartem }
1252912Sartem 
1262912Sartem static HalDevice *
devinfo_keyboard_add(HalDevice * parent,di_node_t node,char * devfs_path,char * device_type)1276573Sphitran devinfo_keyboard_add(HalDevice *parent, di_node_t node, char *devfs_path,
1286573Sphitran     char *device_type)
1296573Sphitran {
1306573Sphitran 	HalDevice *d;
131*9608SLin.Guo@Sun.COM 	char	udi[HAL_PATH_MAX];
1326573Sphitran 
1336573Sphitran 	if (strcmp(di_node_name(node), "keyboard") != 0) {
1346573Sphitran 		return (NULL);
1356573Sphitran 	}
1366573Sphitran 
137*9608SLin.Guo@Sun.COM 	d = hal_device_new();
138*9608SLin.Guo@Sun.COM 
139*9608SLin.Guo@Sun.COM 	devinfo_set_default_properties(d, parent, node, devfs_path);
1406573Sphitran 
141*9608SLin.Guo@Sun.COM 	hal_device_add_capability(d, "input");
142*9608SLin.Guo@Sun.COM 	hal_device_add_capability(d, "input.keyboard");
143*9608SLin.Guo@Sun.COM 	hal_device_add_capability(d, "input.keys");
1446573Sphitran 	hal_device_add_capability(d, "button");
1456573Sphitran 
146*9608SLin.Guo@Sun.COM 	hal_device_property_set_string(d, "info.subsystem", "input");
147*9608SLin.Guo@Sun.COM 	hal_device_property_set_string(d, "info.category", "input");
148*9608SLin.Guo@Sun.COM 	hal_device_property_set_string(d, "input.device", "/dev/kbd");
149*9608SLin.Guo@Sun.COM 	hal_device_property_set_string(d, "input.originating_device",
150*9608SLin.Guo@Sun.COM 	    hal_device_get_udi(d));
151*9608SLin.Guo@Sun.COM 
152*9608SLin.Guo@Sun.COM 	hal_util_compute_udi(hald_get_gdl(), udi, sizeof (udi),
153*9608SLin.Guo@Sun.COM 	    "%s_logicaldev_input", hal_device_get_udi(d));
154*9608SLin.Guo@Sun.COM 
155*9608SLin.Guo@Sun.COM 	hal_device_set_udi(d, udi);
156*9608SLin.Guo@Sun.COM 	hal_device_property_set_string(d, "info.udi", udi);
157*9608SLin.Guo@Sun.COM 
158*9608SLin.Guo@Sun.COM 	devinfo_add_enqueue(d, devfs_path, &devinfo_keyboard_handler);
159*9608SLin.Guo@Sun.COM 
160*9608SLin.Guo@Sun.COM 	return (d);
161*9608SLin.Guo@Sun.COM }
162*9608SLin.Guo@Sun.COM 
163*9608SLin.Guo@Sun.COM static HalDevice *
devinfo_mouse_add(HalDevice * parent,di_node_t node,char * devfs_path,char * device_type)164*9608SLin.Guo@Sun.COM devinfo_mouse_add(HalDevice *parent, di_node_t node, char *devfs_path,
165*9608SLin.Guo@Sun.COM     char *device_type)
166*9608SLin.Guo@Sun.COM {
167*9608SLin.Guo@Sun.COM 	HalDevice *d;
168*9608SLin.Guo@Sun.COM 	char	udi[HAL_PATH_MAX];
169*9608SLin.Guo@Sun.COM 
170*9608SLin.Guo@Sun.COM 	if (strcmp(di_node_name(node), "mouse") != 0) {
171*9608SLin.Guo@Sun.COM 		return (NULL);
172*9608SLin.Guo@Sun.COM 	}
173*9608SLin.Guo@Sun.COM 
174*9608SLin.Guo@Sun.COM 	d = hal_device_new();
175*9608SLin.Guo@Sun.COM 
176*9608SLin.Guo@Sun.COM 	devinfo_set_default_properties(d, parent, node, devfs_path);
177*9608SLin.Guo@Sun.COM 
178*9608SLin.Guo@Sun.COM 	hal_device_add_capability(d, "input");
179*9608SLin.Guo@Sun.COM 	hal_device_add_capability(d, "input.mouse");
180*9608SLin.Guo@Sun.COM 
181*9608SLin.Guo@Sun.COM 	hal_device_property_set_string(d, "info.subsystem", "input");
182*9608SLin.Guo@Sun.COM 	hal_device_property_set_string(d, "info.category", "input");
183*9608SLin.Guo@Sun.COM 	hal_device_property_set_string(d, "input.device", "/dev/mouse");
184*9608SLin.Guo@Sun.COM 	hal_device_property_set_string(d, "input.originating_device",
185*9608SLin.Guo@Sun.COM 	    hal_device_get_udi(d));
186*9608SLin.Guo@Sun.COM 
187*9608SLin.Guo@Sun.COM 	hal_util_compute_udi(hald_get_gdl(), udi, sizeof (udi),
188*9608SLin.Guo@Sun.COM 	    "%s_logicaldev_input", hal_device_get_udi(d));
189*9608SLin.Guo@Sun.COM 
190*9608SLin.Guo@Sun.COM 	hal_device_set_udi(d, udi);
191*9608SLin.Guo@Sun.COM 	hal_device_property_set_string(d, "info.udi", udi);
192*9608SLin.Guo@Sun.COM 
193*9608SLin.Guo@Sun.COM 	devinfo_add_enqueue(d, devfs_path, &devinfo_mouse_handler);
1946573Sphitran 
1956573Sphitran 	return (d);
1966573Sphitran }
1976573Sphitran 
1986573Sphitran static HalDevice *
devinfo_default_add(HalDevice * parent,di_node_t node,char * devfs_path,char * device_type)1992912Sartem devinfo_default_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
2002912Sartem {
2012912Sartem 	char *driver_name;
2022912Sartem 	const char *parent_path;
2032912Sartem 	HalDevice *d;
2042912Sartem 
2052912Sartem 	/* ignore all children of the 'pseudo' node except lofi */
2062912Sartem 	if (parent != NULL) {
2072912Sartem 		parent_path = hal_device_property_get_string(parent, "solaris.devfs_path");
2082912Sartem 		if ((parent_path != NULL) &&
2092912Sartem 		    (strcmp (parent_path, "/pseudo") == 0)) {
2102912Sartem 			driver_name = di_driver_name (node);
2112912Sartem 			if ((driver_name != NULL) &&
2122912Sartem 			    (strcmp (driver_name, "lofi") != 0)) {
2132912Sartem 				return (NULL);
2142912Sartem 			}
2152912Sartem 		}
2162912Sartem 	}
2172912Sartem 
2182912Sartem 	d = hal_device_new ();
2192912Sartem 
2202912Sartem 	devinfo_set_default_properties (d, parent, node, devfs_path);
2212912Sartem 
2222912Sartem 	devinfo_add_enqueue (d, devfs_path, &devinfo_default_handler);
2232912Sartem 
2242912Sartem 	return (d);
2252912Sartem }
226