xref: /titanic_50/usr/src/cmd/hal/hald/solaris/devinfo_misc.c (revision 1dd08564e4a3aafe66b00aee6f222b0885346fe8)
1 /***************************************************************************
2  *
3  * devinfo_misc : misc devices
4  *
5  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
6  * Use is subject to license terms.
7  *
8  * Licensed under the Academic Free License version 2.1
9  *
10  **************************************************************************/
11 
12 #pragma ident	"%Z%%M%	%I%	%E% SMI"
13 
14 #ifdef HAVE_CONFIG_H
15 #include <config.h>
16 #endif
17 
18 #include <stdio.h>
19 #include <string.h>
20 #include <sys/utsname.h>
21 #include <libdevinfo.h>
22 #include <sys/uadmin.h>
23 
24 #include "../osspec.h"
25 #include "../logger.h"
26 #include "../hald.h"
27 #include "../hald_dbus.h"
28 #include "../device_info.h"
29 #include "../util.h"
30 #include "devinfo_misc.h"
31 
32 static HalDevice *devinfo_computer_add(HalDevice *, di_node_t, char *, char *);
33 static HalDevice *devinfo_keyboard_add(HalDevice *, di_node_t, char *, char *);
34 static HalDevice *devinfo_default_add(HalDevice *, di_node_t, char *, char *);
35 
36 DevinfoDevHandler devinfo_computer_handler = {
37 	devinfo_computer_add,
38 	NULL,
39 	NULL,
40 	NULL,
41 	NULL,
42 	NULL
43 };
44 
45 DevinfoDevHandler devinfo_keyboard_handler = {
46 	devinfo_keyboard_add,
47 	NULL,
48 	NULL,
49 	NULL,
50 	NULL,
51 	NULL
52 };
53 
54 DevinfoDevHandler devinfo_default_handler = {
55 	devinfo_default_add,
56 	NULL,
57 	NULL,
58 	NULL,
59 	NULL,
60 	NULL
61 };
62 
63 static HalDevice *
64 devinfo_computer_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
65 {
66 	HalDevice *d, *local_d;
67 	struct utsname un;
68 
69 	if (strcmp (devfs_path, "/") != 0) {
70 		return (NULL);
71 	}
72 
73 	d = hal_device_new ();
74 
75 	hal_device_property_set_string (d, "info.subsystem", "unknown");
76 	hal_device_property_set_string (d, "info.product", "Computer");
77 	hal_device_property_set_string (d, "info.udi", "/org/freedesktop/Hal/devices/computer");
78 	hal_device_set_udi (d, "/org/freedesktop/Hal/devices/computer");
79 	hal_device_property_set_string (d, "solaris.devfs_path", devfs_path);
80 
81 	if (uname (&un) >= 0) {
82 		hal_device_property_set_string (d, "system.kernel.name", un.sysname);
83 		hal_device_property_set_string (d, "system.kernel.version", un.release);
84 		hal_device_property_set_string (d, "system.kernel.machine", un.machine);
85 	}
86 
87 	hal_device_property_set_bool(d, "power_management.can_hibernate",
88 	    (uadmin(A_FREEZE, AD_CHECK_SUSPEND_TO_DISK, 0) == 0));
89 	hal_device_property_set_bool(d, "power_management.can_suspend",
90 	    (uadmin(A_FREEZE, AD_CHECK_SUSPEND_TO_RAM, 0) == 0));
91 
92 	hal_device_add_capability(d, "button");
93 
94 	/*
95 	 * Let computer be in TDL while synthesizing all other events
96 	 * because some may write to the object
97 	 */
98 	hal_device_store_add (hald_get_tdl (), d);
99 
100 	devinfo_add_enqueue (d, devfs_path, &devinfo_computer_handler);
101 
102 	/* all devinfo devices belong to the 'local' branch */
103 	local_d = hal_device_new ();
104 
105 	hal_device_property_set_string (local_d, "info.parent", hal_device_get_udi (d));
106 	hal_device_property_set_string (local_d, "info.subsystem", "unknown");
107 	hal_device_property_set_string (local_d, "info.product", "Local devices");
108 	hal_device_property_set_string (local_d, "info.udi", "/org/freedesktop/Hal/devices/local");
109 	hal_device_set_udi (local_d, "/org/freedesktop/Hal/devices/local");
110 	hal_device_property_set_string (local_d, "solaris.devfs_path", "/local");
111 
112 	devinfo_add_enqueue (local_d, "/local", &devinfo_default_handler);
113 
114 	return (local_d);
115 }
116 
117 static HalDevice *
118 devinfo_keyboard_add(HalDevice *parent, di_node_t node, char *devfs_path,
119     char *device_type)
120 {
121 	HalDevice *d;
122 
123 	if (strcmp(di_node_name(node), "keyboard") != 0) {
124 		return (NULL);
125 	}
126 
127 	d = hal_device_new ();
128 
129 	devinfo_set_default_properties (d, parent, node, devfs_path);
130 	hal_device_add_capability (d, "input.keyboard");
131 	hal_device_add_capability(d, "button");
132 
133 	devinfo_add_enqueue (d, devfs_path, &devinfo_keyboard_handler);
134 
135 	return (d);
136 }
137 
138 static HalDevice *
139 devinfo_default_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
140 {
141 	char *driver_name;
142 	const char *parent_path;
143 	HalDevice *d;
144 
145 	/* ignore all children of the 'pseudo' node except lofi */
146 	if (parent != NULL) {
147 		parent_path = hal_device_property_get_string(parent, "solaris.devfs_path");
148 		if ((parent_path != NULL) &&
149 		    (strcmp (parent_path, "/pseudo") == 0)) {
150 			driver_name = di_driver_name (node);
151 			if ((driver_name != NULL) &&
152 			    (strcmp (driver_name, "lofi") != 0)) {
153 				return (NULL);
154 			}
155 		}
156 	}
157 
158 	d = hal_device_new ();
159 
160 	devinfo_set_default_properties (d, parent, node, devfs_path);
161 
162 	devinfo_add_enqueue (d, devfs_path, &devinfo_default_handler);
163 
164 	return (d);
165 }
166