xref: /titanic_41/usr/src/cmd/hal/hald/solaris/devinfo_misc.c (revision 9a0e82381c494d655823a54fc713a8c2a571131c)
1 /***************************************************************************
2  *
3  * devinfo_misc : misc devices
4  *
5  * Copyright 2009 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 #ifdef HAVE_CONFIG_H
13 #include <config.h>
14 #endif
15 
16 #include <stdio.h>
17 #include <string.h>
18 #include <sys/utsname.h>
19 #include <libdevinfo.h>
20 #include <sys/uadmin.h>
21 
22 #include "../osspec.h"
23 #include "../logger.h"
24 #include "../hald.h"
25 #include "../hald_dbus.h"
26 #include "../device_info.h"
27 #include "../util.h"
28 #include "devinfo_misc.h"
29 
30 static HalDevice *devinfo_computer_add(HalDevice *, di_node_t, char *, char *);
31 static HalDevice *devinfo_keyboard_add(HalDevice *, di_node_t, char *, char *);
32 static HalDevice *devinfo_mouse_add(HalDevice *, di_node_t, char *, char *);
33 static HalDevice *devinfo_default_add(HalDevice *, di_node_t, char *, char *);
34 const gchar *devinfo_keyboard_get_prober(HalDevice *d, int *timeout);
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 	devinfo_keyboard_get_prober
52 };
53 
54 DevinfoDevHandler devinfo_mouse_handler = {
55 	devinfo_mouse_add,
56 	NULL,
57 	NULL,
58 	NULL,
59 	NULL,
60 	NULL
61 };
62 
63 DevinfoDevHandler devinfo_default_handler = {
64 	devinfo_default_add,
65 	NULL,
66 	NULL,
67 	NULL,
68 	NULL,
69 	NULL
70 };
71 
72 static HalDevice *
73 devinfo_computer_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
74 {
75 	HalDevice *d, *local_d;
76 	struct utsname un;
77 
78 	if (strcmp (devfs_path, "/") != 0) {
79 		return (NULL);
80 	}
81 
82 	d = hal_device_new ();
83 
84 	hal_device_property_set_string (d, "info.subsystem", "unknown");
85 	hal_device_property_set_string (d, "info.product", "Computer");
86 	hal_device_property_set_string (d, "info.udi", "/org/freedesktop/Hal/devices/computer");
87 	hal_device_set_udi (d, "/org/freedesktop/Hal/devices/computer");
88 	hal_device_property_set_string (d, "solaris.devfs_path", devfs_path);
89 
90 	if (uname (&un) >= 0) {
91 		hal_device_property_set_string (d, "system.kernel.name", un.sysname);
92 		hal_device_property_set_string (d, "system.kernel.version", un.release);
93 		hal_device_property_set_string (d, "system.kernel.machine", un.machine);
94 	}
95 
96 	hal_device_property_set_bool(d, "power_management.can_hibernate",
97 	    (uadmin(A_FREEZE, AD_CHECK_SUSPEND_TO_DISK, 0) == 0));
98 	hal_device_property_set_bool(d, "power_management.can_suspend",
99 	    (uadmin(A_FREEZE, AD_CHECK_SUSPEND_TO_RAM, 0) == 0));
100 
101 	hal_device_add_capability(d, "button");
102 
103 	/*
104 	 * Let computer be in TDL while synthesizing all other events
105 	 * because some may write to the object
106 	 */
107 	hal_device_store_add (hald_get_tdl (), d);
108 
109 	devinfo_add_enqueue (d, devfs_path, &devinfo_computer_handler);
110 
111 	/* all devinfo devices belong to the 'local' branch */
112 	local_d = hal_device_new ();
113 
114 	hal_device_property_set_string (local_d, "info.parent", hal_device_get_udi (d));
115 	hal_device_property_set_string (local_d, "info.subsystem", "unknown");
116 	hal_device_property_set_string (local_d, "info.product", "Local devices");
117 	hal_device_property_set_string (local_d, "info.udi", "/org/freedesktop/Hal/devices/local");
118 	hal_device_set_udi (local_d, "/org/freedesktop/Hal/devices/local");
119 	hal_device_property_set_string (local_d, "solaris.devfs_path", "/local");
120 
121 	devinfo_add_enqueue (local_d, "/local", &devinfo_default_handler);
122 
123 	return (local_d);
124 }
125 
126 static HalDevice *
127 devinfo_keyboard_add(HalDevice *parent, di_node_t node, char *devfs_path,
128     char *device_type)
129 {
130 	HalDevice *d;
131 	char	udi[HAL_PATH_MAX];
132 
133 	if (strcmp(di_node_name(node), "keyboard") != 0) {
134 		return (NULL);
135 	}
136 
137 	d = hal_device_new();
138 
139 	devinfo_set_default_properties(d, parent, node, devfs_path);
140 
141 	hal_device_add_capability(d, "input");
142 	hal_device_add_capability(d, "input.keyboard");
143 	hal_device_add_capability(d, "input.keys");
144 	hal_device_add_capability(d, "button");
145 
146 	hal_device_property_set_string(d, "info.subsystem", "input");
147 	hal_device_property_set_string(d, "info.category", "input");
148 	hal_device_property_set_string(d, "input.device", "/dev/kbd");
149 	hal_device_property_set_string(d, "input.originating_device",
150 	    hal_device_get_udi(d));
151 
152 	hal_util_compute_udi(hald_get_gdl(), udi, sizeof (udi),
153 	    "%s_logicaldev_input", hal_device_get_udi(d));
154 
155 	hal_device_set_udi(d, udi);
156 	hal_device_property_set_string(d, "info.udi", udi);
157 
158 	devinfo_add_enqueue(d, devfs_path, &devinfo_keyboard_handler);
159 
160 	return (d);
161 }
162 
163 static HalDevice *
164 devinfo_mouse_add(HalDevice *parent, di_node_t node, char *devfs_path,
165     char *device_type)
166 {
167 	HalDevice *d;
168 	char	udi[HAL_PATH_MAX];
169 
170 	if (strcmp(di_node_name(node), "mouse") != 0) {
171 		return (NULL);
172 	}
173 
174 	d = hal_device_new();
175 
176 	devinfo_set_default_properties(d, parent, node, devfs_path);
177 
178 	hal_device_add_capability(d, "input");
179 	hal_device_add_capability(d, "input.mouse");
180 
181 	hal_device_property_set_string(d, "info.subsystem", "input");
182 	hal_device_property_set_string(d, "info.category", "input");
183 	hal_device_property_set_string(d, "input.device", "/dev/mouse");
184 	hal_device_property_set_string(d, "input.originating_device",
185 	    hal_device_get_udi(d));
186 
187 	hal_util_compute_udi(hald_get_gdl(), udi, sizeof (udi),
188 	    "%s_logicaldev_input", hal_device_get_udi(d));
189 
190 	hal_device_set_udi(d, udi);
191 	hal_device_property_set_string(d, "info.udi", udi);
192 
193 	devinfo_add_enqueue(d, devfs_path, &devinfo_mouse_handler);
194 
195 	return (d);
196 }
197 
198 static HalDevice *
199 devinfo_default_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
200 {
201 	char *driver_name;
202 	const char *parent_path;
203 	HalDevice *d;
204 
205 	/* ignore all children of the 'pseudo' node except lofi */
206 	if (parent != NULL) {
207 		parent_path = hal_device_property_get_string(parent, "solaris.devfs_path");
208 		if ((parent_path != NULL) &&
209 		    (strcmp (parent_path, "/pseudo") == 0)) {
210 			driver_name = di_driver_name (node);
211 			if ((driver_name != NULL) &&
212 			    (strcmp (driver_name, "lofi") != 0)) {
213 				return (NULL);
214 			}
215 		}
216 	}
217 
218 	d = hal_device_new ();
219 
220 	devinfo_set_default_properties (d, parent, node, devfs_path);
221 
222 	devinfo_add_enqueue (d, devfs_path, &devinfo_default_handler);
223 
224 	return (d);
225 }
226