12912Sartem /***************************************************************************
22912Sartem  *
32912Sartem  * devinfo_misc : misc devices
42912Sartem  *
56112Sqz150045  * Copyright 2008 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 
122916Sartem #pragma ident	"%Z%%M%	%I%	%E% SMI"
132912Sartem 
143121Sartem #ifdef HAVE_CONFIG_H
15*6654Snp146283 #include <config.h>
163121Sartem #endif
173121Sartem 
182912Sartem #include <stdio.h>
192912Sartem #include <string.h>
202912Sartem #include <sys/utsname.h>
212912Sartem #include <libdevinfo.h>
226573Sphitran #include <sys/uadmin.h>
232912Sartem 
242912Sartem #include "../osspec.h"
252912Sartem #include "../logger.h"
262912Sartem #include "../hald.h"
272912Sartem #include "../hald_dbus.h"
282912Sartem #include "../device_info.h"
292912Sartem #include "../util.h"
302912Sartem #include "devinfo_misc.h"
312912Sartem 
322912Sartem static HalDevice *devinfo_computer_add(HalDevice *, di_node_t, char *, char *);
336573Sphitran static HalDevice *devinfo_keyboard_add(HalDevice *, di_node_t, char *, char *);
342912Sartem static HalDevice *devinfo_default_add(HalDevice *, di_node_t, char *, char *);
352912Sartem 
362912Sartem DevinfoDevHandler devinfo_computer_handler = {
376573Sphitran 	devinfo_computer_add,
386573Sphitran 	NULL,
396573Sphitran 	NULL,
406573Sphitran 	NULL,
416573Sphitran 	NULL,
426573Sphitran 	NULL
436573Sphitran };
44*6654Snp146283 
456573Sphitran DevinfoDevHandler devinfo_keyboard_handler = {
466573Sphitran 	devinfo_keyboard_add,
472912Sartem 	NULL,
482912Sartem 	NULL,
492912Sartem 	NULL,
502912Sartem 	NULL,
516573Sphitran 	NULL
522912Sartem };
53*6654Snp146283 
542912Sartem DevinfoDevHandler devinfo_default_handler = {
556573Sphitran 	devinfo_default_add,
562912Sartem 	NULL,
572912Sartem 	NULL,
582912Sartem 	NULL,
592912Sartem 	NULL,
606573Sphitran 	NULL
612912Sartem };
622912Sartem 
632912Sartem static HalDevice *
642912Sartem devinfo_computer_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
652912Sartem {
662912Sartem 	HalDevice *d, *local_d;
672912Sartem 	struct utsname un;
682912Sartem 
692912Sartem 	if (strcmp (devfs_path, "/") != 0) {
702912Sartem 		return (NULL);
712912Sartem 	}
722912Sartem 
732912Sartem 	d = hal_device_new ();
742912Sartem 
756573Sphitran 	hal_device_property_set_string (d, "info.subsystem", "unknown");
766573Sphitran 	hal_device_property_set_string (d, "info.product", "Computer");
776573Sphitran 	hal_device_property_set_string (d, "info.udi", "/org/freedesktop/Hal/devices/computer");
786573Sphitran 	hal_device_set_udi (d, "/org/freedesktop/Hal/devices/computer");
792912Sartem 	hal_device_property_set_string (d, "solaris.devfs_path", devfs_path);
802912Sartem 
812912Sartem 	if (uname (&un) >= 0) {
822912Sartem 		hal_device_property_set_string (d, "system.kernel.name", un.sysname);
832912Sartem 		hal_device_property_set_string (d, "system.kernel.version", un.release);
842912Sartem 		hal_device_property_set_string (d, "system.kernel.machine", un.machine);
852912Sartem 	}
862912Sartem 
876573Sphitran 	hal_device_property_set_bool(d, "power_management.can_hibernate",
886573Sphitran 	    (uadmin(A_FREEZE, AD_CHECK_SUSPEND_TO_DISK, 0) == 0));
896573Sphitran 	hal_device_property_set_bool(d, "power_management.can_suspend",
906573Sphitran 	    (uadmin(A_FREEZE, AD_CHECK_SUSPEND_TO_RAM, 0) == 0));
916573Sphitran 
926573Sphitran 	hal_device_add_capability(d, "button");
936573Sphitran 
944035Sphitran 	/*
954035Sphitran 	 * Let computer be in TDL while synthesizing all other events
964035Sphitran 	 * because some may write to the object
974035Sphitran 	 */
986573Sphitran 	hal_device_store_add (hald_get_tdl (), d);
994035Sphitran 
1002912Sartem 	devinfo_add_enqueue (d, devfs_path, &devinfo_computer_handler);
1012912Sartem 
1022912Sartem 	/* all devinfo devices belong to the 'local' branch */
1032912Sartem 	local_d = hal_device_new ();
1042912Sartem 
1053121Sartem 	hal_device_property_set_string (local_d, "info.parent", hal_device_get_udi (d));
1066573Sphitran 	hal_device_property_set_string (local_d, "info.subsystem", "unknown");
1076573Sphitran 	hal_device_property_set_string (local_d, "info.product", "Local devices");
1086573Sphitran 	hal_device_property_set_string (local_d, "info.udi", "/org/freedesktop/Hal/devices/local");
1096573Sphitran 	hal_device_set_udi (local_d, "/org/freedesktop/Hal/devices/local");
1102912Sartem 	hal_device_property_set_string (local_d, "solaris.devfs_path", "/local");
1112912Sartem 
1122912Sartem 	devinfo_add_enqueue (local_d, "/local", &devinfo_default_handler);
1132912Sartem 
1142912Sartem 	return (local_d);
1152912Sartem }
1162912Sartem 
1172912Sartem static HalDevice *
1186573Sphitran devinfo_keyboard_add(HalDevice *parent, di_node_t node, char *devfs_path,
1196573Sphitran     char *device_type)
1206573Sphitran {
1216573Sphitran 	HalDevice *d;
1226573Sphitran 
1236573Sphitran 	if (strcmp(di_node_name(node), "keyboard") != 0) {
1246573Sphitran 		return (NULL);
1256573Sphitran 	}
1266573Sphitran 
1276573Sphitran 	d = hal_device_new ();
1286573Sphitran 
1296573Sphitran 	devinfo_set_default_properties (d, parent, node, devfs_path);
1306573Sphitran 	hal_device_add_capability (d, "input.keyboard");
1316573Sphitran 	hal_device_add_capability(d, "button");
1326573Sphitran 
1336573Sphitran 	devinfo_add_enqueue (d, devfs_path, &devinfo_keyboard_handler);
1346573Sphitran 
1356573Sphitran 	return (d);
1366573Sphitran }
1376573Sphitran 
1386573Sphitran static HalDevice *
1392912Sartem devinfo_default_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
1402912Sartem {
1412912Sartem 	char *driver_name;
1422912Sartem 	const char *parent_path;
1432912Sartem 	HalDevice *d;
1442912Sartem 
1452912Sartem 	/* ignore all children of the 'pseudo' node except lofi */
1462912Sartem 	if (parent != NULL) {
1472912Sartem 		parent_path = hal_device_property_get_string(parent, "solaris.devfs_path");
1482912Sartem 		if ((parent_path != NULL) &&
1492912Sartem 		    (strcmp (parent_path, "/pseudo") == 0)) {
1502912Sartem 			driver_name = di_driver_name (node);
1512912Sartem 			if ((driver_name != NULL) &&
1522912Sartem 			    (strcmp (driver_name, "lofi") != 0)) {
1532912Sartem 				return (NULL);
1542912Sartem 			}
1552912Sartem 		}
1562912Sartem 	}
1572912Sartem 
1582912Sartem 	d = hal_device_new ();
1592912Sartem 
1602912Sartem 	devinfo_set_default_properties (d, parent, node, devfs_path);
1612912Sartem 
1622912Sartem 	devinfo_add_enqueue (d, devfs_path, &devinfo_default_handler);
1632912Sartem 
1642912Sartem 	return (d);
1652912Sartem }
166