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
153121Sartem #  include <config.h>
163121Sartem #endif
173121Sartem 
182912Sartem #include <stdio.h>
192912Sartem #include <string.h>
202912Sartem #include <sys/utsname.h>
212912Sartem #include <libdevinfo.h>
22*6573Sphitran #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 *);
33*6573Sphitran static HalDevice *devinfo_cpu_add(HalDevice *, di_node_t, char *, char *);
34*6573Sphitran static HalDevice *devinfo_keyboard_add(HalDevice *, di_node_t, char *, char *);
352912Sartem static HalDevice *devinfo_default_add(HalDevice *, di_node_t, char *, char *);
362912Sartem 
372912Sartem DevinfoDevHandler devinfo_computer_handler = {
38*6573Sphitran 	devinfo_computer_add,
39*6573Sphitran 	NULL,
40*6573Sphitran 	NULL,
41*6573Sphitran 	NULL,
42*6573Sphitran 	NULL,
43*6573Sphitran 	NULL
44*6573Sphitran };
45*6573Sphitran DevinfoDevHandler devinfo_cpu_handler = {
46*6573Sphitran 	devinfo_cpu_add,
472912Sartem 	NULL,
482912Sartem 	NULL,
492912Sartem 	NULL,
502912Sartem 	NULL,
51*6573Sphitran 	NULL
522912Sartem };
53*6573Sphitran DevinfoDevHandler devinfo_keyboard_handler = {
54*6573Sphitran 	devinfo_keyboard_add,
552912Sartem 	NULL,
562912Sartem 	NULL,
572912Sartem 	NULL,
582912Sartem 	NULL,
59*6573Sphitran 	NULL
602912Sartem };
612912Sartem DevinfoDevHandler devinfo_default_handler = {
62*6573Sphitran 	devinfo_default_add,
632912Sartem 	NULL,
642912Sartem 	NULL,
652912Sartem 	NULL,
662912Sartem 	NULL,
67*6573Sphitran 	NULL
682912Sartem };
692912Sartem 
702912Sartem static HalDevice *
712912Sartem devinfo_computer_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
722912Sartem {
732912Sartem 	HalDevice *d, *local_d;
742912Sartem 	struct utsname un;
752912Sartem 
762912Sartem 	if (strcmp (devfs_path, "/") != 0) {
772912Sartem 		return (NULL);
782912Sartem 	}
792912Sartem 
802912Sartem 	d = hal_device_new ();
812912Sartem 
82*6573Sphitran 	hal_device_property_set_string (d, "info.subsystem", "unknown");
83*6573Sphitran 	hal_device_property_set_string (d, "info.product", "Computer");
84*6573Sphitran 	hal_device_property_set_string (d, "info.udi", "/org/freedesktop/Hal/devices/computer");
85*6573Sphitran 	hal_device_set_udi (d, "/org/freedesktop/Hal/devices/computer");
862912Sartem 	hal_device_property_set_string (d, "solaris.devfs_path", devfs_path);
872912Sartem 
882912Sartem 	if (uname (&un) >= 0) {
892912Sartem 		hal_device_property_set_string (d, "system.kernel.name", un.sysname);
902912Sartem 		hal_device_property_set_string (d, "system.kernel.version", un.release);
912912Sartem 		hal_device_property_set_string (d, "system.kernel.machine", un.machine);
922912Sartem 	}
932912Sartem 
94*6573Sphitran 	hal_device_property_set_bool(d, "power_management.can_hibernate",
95*6573Sphitran 	    (uadmin(A_FREEZE, AD_CHECK_SUSPEND_TO_DISK, 0) == 0));
96*6573Sphitran 	hal_device_property_set_bool(d, "power_management.can_suspend",
97*6573Sphitran 	    (uadmin(A_FREEZE, AD_CHECK_SUSPEND_TO_RAM, 0) == 0));
98*6573Sphitran 
99*6573Sphitran 	hal_device_add_capability(d, "button");
100*6573Sphitran 
1014035Sphitran 	/*
1024035Sphitran 	 * Let computer be in TDL while synthesizing all other events
1034035Sphitran 	 * because some may write to the object
1044035Sphitran 	 */
105*6573Sphitran 	hal_device_store_add (hald_get_tdl (), d);
1064035Sphitran 
1072912Sartem 	devinfo_add_enqueue (d, devfs_path, &devinfo_computer_handler);
1082912Sartem 
1092912Sartem 	/* all devinfo devices belong to the 'local' branch */
1102912Sartem 	local_d = hal_device_new ();
1112912Sartem 
1123121Sartem 	hal_device_property_set_string (local_d, "info.parent", hal_device_get_udi (d));
113*6573Sphitran 	hal_device_property_set_string (local_d, "info.subsystem", "unknown");
114*6573Sphitran 	hal_device_property_set_string (local_d, "info.product", "Local devices");
115*6573Sphitran 	hal_device_property_set_string (local_d, "info.udi", "/org/freedesktop/Hal/devices/local");
116*6573Sphitran 	hal_device_set_udi (local_d, "/org/freedesktop/Hal/devices/local");
1172912Sartem 	hal_device_property_set_string (local_d, "solaris.devfs_path", "/local");
1182912Sartem 
1192912Sartem 	devinfo_add_enqueue (local_d, "/local", &devinfo_default_handler);
1202912Sartem 
1212912Sartem 	return (local_d);
1222912Sartem }
1232912Sartem 
1242912Sartem static HalDevice *
1252912Sartem devinfo_cpu_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
1262912Sartem {
1272912Sartem 	HalDevice *d;
1282912Sartem 
1292912Sartem 	if ((device_type == NULL) || (strcmp(device_type, "cpu") != 0)) {
1302912Sartem 		return (NULL);
1312912Sartem 	}
1322912Sartem 
1332912Sartem 	d = hal_device_new ();
1342912Sartem 
1352912Sartem 	devinfo_set_default_properties (d, parent, node, devfs_path);
1362912Sartem 	hal_device_add_capability (d, "processor");
1372912Sartem 
1382912Sartem 	devinfo_add_enqueue (d, devfs_path, &devinfo_cpu_handler);
1392912Sartem 
1402912Sartem 	return (d);
1412912Sartem }
1422912Sartem 
1432912Sartem static HalDevice *
144*6573Sphitran devinfo_keyboard_add(HalDevice *parent, di_node_t node, char *devfs_path,
145*6573Sphitran     char *device_type)
146*6573Sphitran {
147*6573Sphitran 	HalDevice *d;
148*6573Sphitran 
149*6573Sphitran 	if (strcmp(di_node_name(node), "keyboard") != 0) {
150*6573Sphitran 		return (NULL);
151*6573Sphitran 	}
152*6573Sphitran 
153*6573Sphitran 	d = hal_device_new ();
154*6573Sphitran 
155*6573Sphitran 	devinfo_set_default_properties (d, parent, node, devfs_path);
156*6573Sphitran 	hal_device_add_capability (d, "input.keyboard");
157*6573Sphitran 	hal_device_add_capability(d, "button");
158*6573Sphitran 
159*6573Sphitran 	devinfo_add_enqueue (d, devfs_path, &devinfo_keyboard_handler);
160*6573Sphitran 
161*6573Sphitran 	return (d);
162*6573Sphitran }
163*6573Sphitran 
164*6573Sphitran static HalDevice *
1652912Sartem devinfo_default_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
1662912Sartem {
1672912Sartem 	char *driver_name;
1682912Sartem 	const char *parent_path;
1692912Sartem 	HalDevice *d;
1702912Sartem 
1712912Sartem 	/* ignore all children of the 'pseudo' node except lofi */
1722912Sartem 	if (parent != NULL) {
1732912Sartem 		parent_path = hal_device_property_get_string(parent, "solaris.devfs_path");
1742912Sartem 		if ((parent_path != NULL) &&
1752912Sartem 		    (strcmp (parent_path, "/pseudo") == 0)) {
1762912Sartem 			driver_name = di_driver_name (node);
1772912Sartem 			if ((driver_name != NULL) &&
1782912Sartem 			    (strcmp (driver_name, "lofi") != 0)) {
1792912Sartem 				return (NULL);
1802912Sartem 			}
1812912Sartem 		}
1822912Sartem 	}
1832912Sartem 
1842912Sartem 	d = hal_device_new ();
1852912Sartem 
1862912Sartem 	devinfo_set_default_properties (d, parent, node, devfs_path);
1872912Sartem 
1882912Sartem 	devinfo_add_enqueue (d, devfs_path, &devinfo_default_handler);
1892912Sartem 
1902912Sartem 	return (d);
1912912Sartem }
192