1 /***************************************************************************
2  *
3  * devinfo_misc : misc devices
4  *
5  * Copyright 2006 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 #include <stdio.h>
15 #include <string.h>
16 #include <sys/utsname.h>
17 #include <libdevinfo.h>
18 
19 #include "../osspec.h"
20 #include "../logger.h"
21 #include "../hald.h"
22 #include "../hald_dbus.h"
23 #include "../device_info.h"
24 #include "../util.h"
25 #include "devinfo_misc.h"
26 
27 static HalDevice *devinfo_computer_add(HalDevice *, di_node_t, char *, char *);
28 static HalDevice *devinfo_cpu_add(HalDevice *, di_node_t, char *,char *);
29 static HalDevice *devinfo_default_add(HalDevice *, di_node_t, char *, char *);
30 
31 DevinfoDevHandler devinfo_computer_handler = {
32         devinfo_computer_add,
33 	NULL,
34 	NULL,
35 	NULL,
36 	NULL,
37         NULL
38 };
39 DevinfoDevHandler devinfo_cpu_handler = {
40         devinfo_cpu_add,
41 	NULL,
42 	NULL,
43 	NULL,
44 	NULL,
45         NULL
46 };
47 DevinfoDevHandler devinfo_default_handler = {
48         devinfo_default_add,
49 	NULL,
50 	NULL,
51 	NULL,
52 	NULL,
53         NULL
54 };
55 
56 static HalDevice *
57 devinfo_computer_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
58 {
59 	HalDevice *d, *local_d;
60 	struct utsname un;
61 
62 	if (strcmp (devfs_path, "/") != 0) {
63 		return (NULL);
64 	}
65 
66 	d = hal_device_new ();
67 
68         hal_device_property_set_string (d, "info.bus", "unknown");
69         hal_device_property_set_string (d, "info.product", "Computer");
70         hal_device_property_set_string (d, "info.udi", "/org/freedesktop/Hal/devices/computer");
71         hal_device_set_udi (d, "/org/freedesktop/Hal/devices/computer");
72 	hal_device_property_set_string (d, "solaris.devfs_path", devfs_path);
73 
74 	if (uname (&un) >= 0) {
75 		hal_device_property_set_string (d, "system.kernel.name", un.sysname);
76 		hal_device_property_set_string (d, "system.kernel.version", un.release);
77 		hal_device_property_set_string (d, "system.kernel.machine", un.machine);
78 	}
79 
80 	devinfo_add_enqueue (d, devfs_path, &devinfo_computer_handler);
81 
82 	/* all devinfo devices belong to the 'local' branch */
83 	local_d = hal_device_new ();
84 
85 	hal_device_property_set_string (local_d, "info.parent", d->udi);
86         hal_device_property_set_string (local_d, "info.bus", "unknown");
87         hal_device_property_set_string (local_d, "info.product", "Local devices");
88         hal_device_property_set_string (local_d, "info.udi", "/org/freedesktop/Hal/devices/local");
89         hal_device_set_udi (local_d, "/org/freedesktop/Hal/devices/local");
90 	hal_device_property_set_string (local_d, "solaris.devfs_path", "/local");
91 
92 	devinfo_add_enqueue (local_d, "/local", &devinfo_default_handler);
93 
94 	return (local_d);
95 }
96 
97 static HalDevice *
98 devinfo_cpu_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
99 {
100 	HalDevice *d;
101 
102 	if ((device_type == NULL) || (strcmp(device_type, "cpu") != 0)) {
103 		return (NULL);
104 	}
105 
106 	d = hal_device_new ();
107 
108 	devinfo_set_default_properties (d, parent, node, devfs_path);
109 	hal_device_add_capability (d, "processor");
110 
111 	devinfo_add_enqueue (d, devfs_path, &devinfo_cpu_handler);
112 
113 	return (d);
114 }
115 
116 static HalDevice *
117 devinfo_default_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
118 {
119 	char *driver_name;
120 	const char *parent_path;
121 	HalDevice *d;
122 
123 	/* ignore all children of the 'pseudo' node except lofi */
124 	if (parent != NULL) {
125 		parent_path = hal_device_property_get_string(parent, "solaris.devfs_path");
126 		if ((parent_path != NULL) &&
127 		    (strcmp (parent_path, "/pseudo") == 0)) {
128 			driver_name = di_driver_name (node);
129 			if ((driver_name != NULL) &&
130 			    (strcmp (driver_name, "lofi") != 0)) {
131 				return (NULL);
132 			}
133 		}
134 	}
135 
136 	d = hal_device_new ();
137 
138 	devinfo_set_default_properties (d, parent, node, devfs_path);
139 
140 	devinfo_add_enqueue (d, devfs_path, &devinfo_default_handler);
141 
142 	return (d);
143 }
144