118c2aff7Sartem /***************************************************************************
218c2aff7Sartem *
318c2aff7Sartem * devinfo_misc : misc devices
418c2aff7Sartem *
5*b453864fSLin Guo - Sun Microsystems * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
618c2aff7Sartem * Use is subject to license terms.
718c2aff7Sartem *
818c2aff7Sartem * Licensed under the Academic Free License version 2.1
918c2aff7Sartem *
1018c2aff7Sartem **************************************************************************/
1118c2aff7Sartem
1200687e57Sartem #ifdef HAVE_CONFIG_H
1300687e57Sartem #include <config.h>
1400687e57Sartem #endif
1500687e57Sartem
1618c2aff7Sartem #include <stdio.h>
1718c2aff7Sartem #include <string.h>
1818c2aff7Sartem #include <sys/utsname.h>
1918c2aff7Sartem #include <libdevinfo.h>
20d2ec54f7Sphitran #include <sys/uadmin.h>
2118c2aff7Sartem
2218c2aff7Sartem #include "../osspec.h"
2318c2aff7Sartem #include "../logger.h"
2418c2aff7Sartem #include "../hald.h"
2518c2aff7Sartem #include "../hald_dbus.h"
2618c2aff7Sartem #include "../device_info.h"
2718c2aff7Sartem #include "../util.h"
2818c2aff7Sartem #include "devinfo_misc.h"
2918c2aff7Sartem
3018c2aff7Sartem static HalDevice *devinfo_computer_add(HalDevice *, di_node_t, char *, char *);
31d2ec54f7Sphitran static HalDevice *devinfo_keyboard_add(HalDevice *, di_node_t, char *, char *);
32*b453864fSLin Guo - Sun Microsystems static HalDevice *devinfo_mouse_add(HalDevice *, di_node_t, char *, char *);
3318c2aff7Sartem static HalDevice *devinfo_default_add(HalDevice *, di_node_t, char *, char *);
34*b453864fSLin Guo - Sun Microsystems const gchar *devinfo_keyboard_get_prober(HalDevice *d, int *timeout);
3518c2aff7Sartem
3618c2aff7Sartem DevinfoDevHandler devinfo_computer_handler = {
3718c2aff7Sartem devinfo_computer_add,
3818c2aff7Sartem NULL,
3918c2aff7Sartem NULL,
4018c2aff7Sartem NULL,
4118c2aff7Sartem NULL,
4218c2aff7Sartem NULL
4318c2aff7Sartem };
44a9da3307Snp146283
45d2ec54f7Sphitran DevinfoDevHandler devinfo_keyboard_handler = {
46d2ec54f7Sphitran devinfo_keyboard_add,
47d2ec54f7Sphitran NULL,
48d2ec54f7Sphitran NULL,
49d2ec54f7Sphitran NULL,
50d2ec54f7Sphitran NULL,
51*b453864fSLin Guo - Sun Microsystems devinfo_keyboard_get_prober
52*b453864fSLin Guo - Sun Microsystems };
53*b453864fSLin Guo - Sun Microsystems
54*b453864fSLin Guo - Sun Microsystems DevinfoDevHandler devinfo_mouse_handler = {
55*b453864fSLin Guo - Sun Microsystems devinfo_mouse_add,
56*b453864fSLin Guo - Sun Microsystems NULL,
57*b453864fSLin Guo - Sun Microsystems NULL,
58*b453864fSLin Guo - Sun Microsystems NULL,
59*b453864fSLin Guo - Sun Microsystems NULL,
60d2ec54f7Sphitran NULL
61d2ec54f7Sphitran };
62a9da3307Snp146283
6318c2aff7Sartem DevinfoDevHandler devinfo_default_handler = {
6418c2aff7Sartem devinfo_default_add,
6518c2aff7Sartem NULL,
6618c2aff7Sartem NULL,
6718c2aff7Sartem NULL,
6818c2aff7Sartem NULL,
6918c2aff7Sartem NULL
7018c2aff7Sartem };
7118c2aff7Sartem
7218c2aff7Sartem static HalDevice *
devinfo_computer_add(HalDevice * parent,di_node_t node,char * devfs_path,char * device_type)7318c2aff7Sartem devinfo_computer_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
7418c2aff7Sartem {
7518c2aff7Sartem HalDevice *d, *local_d;
7618c2aff7Sartem struct utsname un;
7718c2aff7Sartem
7818c2aff7Sartem if (strcmp (devfs_path, "/") != 0) {
7918c2aff7Sartem return (NULL);
8018c2aff7Sartem }
8118c2aff7Sartem
8218c2aff7Sartem d = hal_device_new ();
8318c2aff7Sartem
84112cd14aSqz150045 hal_device_property_set_string (d, "info.subsystem", "unknown");
8518c2aff7Sartem hal_device_property_set_string (d, "info.product", "Computer");
8618c2aff7Sartem hal_device_property_set_string (d, "info.udi", "/org/freedesktop/Hal/devices/computer");
8718c2aff7Sartem hal_device_set_udi (d, "/org/freedesktop/Hal/devices/computer");
8818c2aff7Sartem hal_device_property_set_string (d, "solaris.devfs_path", devfs_path);
8918c2aff7Sartem
9018c2aff7Sartem if (uname (&un) >= 0) {
9118c2aff7Sartem hal_device_property_set_string (d, "system.kernel.name", un.sysname);
9218c2aff7Sartem hal_device_property_set_string (d, "system.kernel.version", un.release);
9318c2aff7Sartem hal_device_property_set_string (d, "system.kernel.machine", un.machine);
9418c2aff7Sartem }
9518c2aff7Sartem
96d2ec54f7Sphitran hal_device_property_set_bool(d, "power_management.can_hibernate",
97d2ec54f7Sphitran (uadmin(A_FREEZE, AD_CHECK_SUSPEND_TO_DISK, 0) == 0));
98d2ec54f7Sphitran hal_device_property_set_bool(d, "power_management.can_suspend",
99d2ec54f7Sphitran (uadmin(A_FREEZE, AD_CHECK_SUSPEND_TO_RAM, 0) == 0));
100d2ec54f7Sphitran
101d2ec54f7Sphitran hal_device_add_capability(d, "button");
102d2ec54f7Sphitran
1037b840e52Sphitran /*
1047b840e52Sphitran * Let computer be in TDL while synthesizing all other events
1057b840e52Sphitran * because some may write to the object
1067b840e52Sphitran */
1077b840e52Sphitran hal_device_store_add (hald_get_tdl (), d);
1087b840e52Sphitran
10918c2aff7Sartem devinfo_add_enqueue (d, devfs_path, &devinfo_computer_handler);
11018c2aff7Sartem
11118c2aff7Sartem /* all devinfo devices belong to the 'local' branch */
11218c2aff7Sartem local_d = hal_device_new ();
11318c2aff7Sartem
11400687e57Sartem hal_device_property_set_string (local_d, "info.parent", hal_device_get_udi (d));
115112cd14aSqz150045 hal_device_property_set_string (local_d, "info.subsystem", "unknown");
11618c2aff7Sartem hal_device_property_set_string (local_d, "info.product", "Local devices");
11718c2aff7Sartem hal_device_property_set_string (local_d, "info.udi", "/org/freedesktop/Hal/devices/local");
11818c2aff7Sartem hal_device_set_udi (local_d, "/org/freedesktop/Hal/devices/local");
11918c2aff7Sartem hal_device_property_set_string (local_d, "solaris.devfs_path", "/local");
12018c2aff7Sartem
12118c2aff7Sartem devinfo_add_enqueue (local_d, "/local", &devinfo_default_handler);
12218c2aff7Sartem
12318c2aff7Sartem return (local_d);
12418c2aff7Sartem }
12518c2aff7Sartem
12618c2aff7Sartem static HalDevice *
devinfo_keyboard_add(HalDevice * parent,di_node_t node,char * devfs_path,char * device_type)127d2ec54f7Sphitran devinfo_keyboard_add(HalDevice *parent, di_node_t node, char *devfs_path,
128d2ec54f7Sphitran char *device_type)
129d2ec54f7Sphitran {
130d2ec54f7Sphitran HalDevice *d;
131*b453864fSLin Guo - Sun Microsystems char udi[HAL_PATH_MAX];
132d2ec54f7Sphitran
133d2ec54f7Sphitran if (strcmp(di_node_name(node), "keyboard") != 0) {
134d2ec54f7Sphitran return (NULL);
135d2ec54f7Sphitran }
136d2ec54f7Sphitran
137d2ec54f7Sphitran d = hal_device_new();
138d2ec54f7Sphitran
139d2ec54f7Sphitran devinfo_set_default_properties(d, parent, node, devfs_path);
140*b453864fSLin Guo - Sun Microsystems
141*b453864fSLin Guo - Sun Microsystems hal_device_add_capability(d, "input");
142d2ec54f7Sphitran hal_device_add_capability(d, "input.keyboard");
143*b453864fSLin Guo - Sun Microsystems hal_device_add_capability(d, "input.keys");
144d2ec54f7Sphitran hal_device_add_capability(d, "button");
145d2ec54f7Sphitran
146*b453864fSLin Guo - Sun Microsystems hal_device_property_set_string(d, "info.subsystem", "input");
147*b453864fSLin Guo - Sun Microsystems hal_device_property_set_string(d, "info.category", "input");
148*b453864fSLin Guo - Sun Microsystems hal_device_property_set_string(d, "input.device", "/dev/kbd");
149*b453864fSLin Guo - Sun Microsystems hal_device_property_set_string(d, "input.originating_device",
150*b453864fSLin Guo - Sun Microsystems hal_device_get_udi(d));
151*b453864fSLin Guo - Sun Microsystems
152*b453864fSLin Guo - Sun Microsystems hal_util_compute_udi(hald_get_gdl(), udi, sizeof (udi),
153*b453864fSLin Guo - Sun Microsystems "%s_logicaldev_input", hal_device_get_udi(d));
154*b453864fSLin Guo - Sun Microsystems
155*b453864fSLin Guo - Sun Microsystems hal_device_set_udi(d, udi);
156*b453864fSLin Guo - Sun Microsystems hal_device_property_set_string(d, "info.udi", udi);
157*b453864fSLin Guo - Sun Microsystems
158d2ec54f7Sphitran devinfo_add_enqueue(d, devfs_path, &devinfo_keyboard_handler);
159d2ec54f7Sphitran
160d2ec54f7Sphitran return (d);
161d2ec54f7Sphitran }
162d2ec54f7Sphitran
163d2ec54f7Sphitran static HalDevice *
devinfo_mouse_add(HalDevice * parent,di_node_t node,char * devfs_path,char * device_type)164*b453864fSLin Guo - Sun Microsystems devinfo_mouse_add(HalDevice *parent, di_node_t node, char *devfs_path,
165*b453864fSLin Guo - Sun Microsystems char *device_type)
166*b453864fSLin Guo - Sun Microsystems {
167*b453864fSLin Guo - Sun Microsystems HalDevice *d;
168*b453864fSLin Guo - Sun Microsystems char udi[HAL_PATH_MAX];
169*b453864fSLin Guo - Sun Microsystems
170*b453864fSLin Guo - Sun Microsystems if (strcmp(di_node_name(node), "mouse") != 0) {
171*b453864fSLin Guo - Sun Microsystems return (NULL);
172*b453864fSLin Guo - Sun Microsystems }
173*b453864fSLin Guo - Sun Microsystems
174*b453864fSLin Guo - Sun Microsystems d = hal_device_new();
175*b453864fSLin Guo - Sun Microsystems
176*b453864fSLin Guo - Sun Microsystems devinfo_set_default_properties(d, parent, node, devfs_path);
177*b453864fSLin Guo - Sun Microsystems
178*b453864fSLin Guo - Sun Microsystems hal_device_add_capability(d, "input");
179*b453864fSLin Guo - Sun Microsystems hal_device_add_capability(d, "input.mouse");
180*b453864fSLin Guo - Sun Microsystems
181*b453864fSLin Guo - Sun Microsystems hal_device_property_set_string(d, "info.subsystem", "input");
182*b453864fSLin Guo - Sun Microsystems hal_device_property_set_string(d, "info.category", "input");
183*b453864fSLin Guo - Sun Microsystems hal_device_property_set_string(d, "input.device", "/dev/mouse");
184*b453864fSLin Guo - Sun Microsystems hal_device_property_set_string(d, "input.originating_device",
185*b453864fSLin Guo - Sun Microsystems hal_device_get_udi(d));
186*b453864fSLin Guo - Sun Microsystems
187*b453864fSLin Guo - Sun Microsystems hal_util_compute_udi(hald_get_gdl(), udi, sizeof (udi),
188*b453864fSLin Guo - Sun Microsystems "%s_logicaldev_input", hal_device_get_udi(d));
189*b453864fSLin Guo - Sun Microsystems
190*b453864fSLin Guo - Sun Microsystems hal_device_set_udi(d, udi);
191*b453864fSLin Guo - Sun Microsystems hal_device_property_set_string(d, "info.udi", udi);
192*b453864fSLin Guo - Sun Microsystems
193*b453864fSLin Guo - Sun Microsystems devinfo_add_enqueue(d, devfs_path, &devinfo_mouse_handler);
194*b453864fSLin Guo - Sun Microsystems
195*b453864fSLin Guo - Sun Microsystems return (d);
196*b453864fSLin Guo - Sun Microsystems }
197*b453864fSLin Guo - Sun Microsystems
198*b453864fSLin Guo - Sun Microsystems static HalDevice *
devinfo_default_add(HalDevice * parent,di_node_t node,char * devfs_path,char * device_type)19918c2aff7Sartem devinfo_default_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
20018c2aff7Sartem {
20118c2aff7Sartem char *driver_name;
20218c2aff7Sartem const char *parent_path;
20318c2aff7Sartem HalDevice *d;
20418c2aff7Sartem
20518c2aff7Sartem /* ignore all children of the 'pseudo' node except lofi */
20618c2aff7Sartem if (parent != NULL) {
20718c2aff7Sartem parent_path = hal_device_property_get_string(parent, "solaris.devfs_path");
20818c2aff7Sartem if ((parent_path != NULL) &&
20918c2aff7Sartem (strcmp (parent_path, "/pseudo") == 0)) {
21018c2aff7Sartem driver_name = di_driver_name (node);
21118c2aff7Sartem if ((driver_name != NULL) &&
21218c2aff7Sartem (strcmp (driver_name, "lofi") != 0)) {
21318c2aff7Sartem return (NULL);
21418c2aff7Sartem }
21518c2aff7Sartem }
21618c2aff7Sartem }
21718c2aff7Sartem
21818c2aff7Sartem d = hal_device_new ();
21918c2aff7Sartem
22018c2aff7Sartem devinfo_set_default_properties (d, parent, node, devfs_path);
22118c2aff7Sartem
22218c2aff7Sartem devinfo_add_enqueue (d, devfs_path, &devinfo_default_handler);
22318c2aff7Sartem
22418c2aff7Sartem return (d);
22518c2aff7Sartem }
226