1 /***************************************************************************
3 * devinfo_misc : misc devices
5 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
6 * Use is subject to license terms.
8 * Licensed under the Academic Free License version 2.1
10 **************************************************************************/
18 #include <sys/utsname.h>
19 #include <libdevinfo.h>
20 #include <sys/uadmin.h>
22 #include "../osspec.h"
23 #include "../logger.h"
25 #include "../hald_dbus.h"
26 #include "../device_info.h"
28 #include "devinfo_misc.h"
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
);
36 DevinfoDevHandler devinfo_computer_handler
= {
45 DevinfoDevHandler devinfo_keyboard_handler
= {
51 devinfo_keyboard_get_prober
54 DevinfoDevHandler devinfo_mouse_handler
= {
63 DevinfoDevHandler devinfo_default_handler
= {
73 devinfo_computer_add(HalDevice
*parent
, di_node_t node
, char *devfs_path
, char *device_type
)
75 HalDevice
*d
, *local_d
;
78 if (strcmp (devfs_path
, "/") != 0) {
82 d
= hal_device_new ();
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
);
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
);
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));
101 hal_device_add_capability(d
, "button");
104 * Let computer be in TDL while synthesizing all other events
105 * because some may write to the object
107 hal_device_store_add (hald_get_tdl (), d
);
109 devinfo_add_enqueue (d
, devfs_path
, &devinfo_computer_handler
);
111 /* all devinfo devices belong to the 'local' branch */
112 local_d
= hal_device_new ();
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");
121 devinfo_add_enqueue (local_d
, "/local", &devinfo_default_handler
);
127 devinfo_keyboard_add(HalDevice
*parent
, di_node_t node
, char *devfs_path
,
131 char udi
[HAL_PATH_MAX
];
133 if (strcmp(di_node_name(node
), "keyboard") != 0) {
137 d
= hal_device_new();
139 devinfo_set_default_properties(d
, parent
, node
, devfs_path
);
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");
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
));
152 hal_util_compute_udi(hald_get_gdl(), udi
, sizeof (udi
),
153 "%s_logicaldev_input", hal_device_get_udi(d
));
155 hal_device_set_udi(d
, udi
);
156 hal_device_property_set_string(d
, "info.udi", udi
);
158 devinfo_add_enqueue(d
, devfs_path
, &devinfo_keyboard_handler
);
164 devinfo_mouse_add(HalDevice
*parent
, di_node_t node
, char *devfs_path
,
168 char udi
[HAL_PATH_MAX
];
170 if (strcmp(di_node_name(node
), "mouse") != 0) {
174 d
= hal_device_new();
176 devinfo_set_default_properties(d
, parent
, node
, devfs_path
);
178 hal_device_add_capability(d
, "input");
179 hal_device_add_capability(d
, "input.mouse");
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
));
187 hal_util_compute_udi(hald_get_gdl(), udi
, sizeof (udi
),
188 "%s_logicaldev_input", hal_device_get_udi(d
));
190 hal_device_set_udi(d
, udi
);
191 hal_device_property_set_string(d
, "info.udi", udi
);
193 devinfo_add_enqueue(d
, devfs_path
, &devinfo_mouse_handler
);
199 devinfo_default_add(HalDevice
*parent
, di_node_t node
, char *devfs_path
, char *device_type
)
202 const char *parent_path
;
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)) {
218 d
= hal_device_new ();
220 devinfo_set_default_properties (d
, parent
, node
, devfs_path
);
222 devinfo_add_enqueue (d
, devfs_path
, &devinfo_default_handler
);