add usb_endpoint to HAL device tree

Kay Sievers kay.sievers at vrfy.org
Tue Jul 4 09:06:15 PDT 2006


As a working example for a class device showing up in /sys/devices,
here are the new usb_endpoint devices, which will replace the current
libusb userspace driver access some day.

Screenshot of the insane number of usb interfaces of my mobile phone
attached.

Thanks,
Kay
-------------- next part --------------
A non-text attachment was scrubbed...
Name: usb_endpoint.png
Type: image/png
Size: 174800 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/hal/attachments/20060704/daf8e70d/usb_endpoint-0001.png
-------------- next part --------------
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/classdev.c,v
retrieving revision 1.44
diff -u -p -r1.44 classdev.c
--- hald/linux2/classdev.c	25 May 2006 15:16:19 -0000	1.44
+++ hald/linux2/classdev.c	4 Jul 2006 15:57:21 -0000
@@ -518,6 +518,53 @@ usbraw_compute_udi (HalDevice *d)
 	return TRUE;
 }
 
+/*--------------------------------------------------------------------------------------------------------------*/
+
+static HalDevice *
+usb_endpoint_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *physdev, const gchar *sysfs_path_in_devices)
+{
+	HalDevice *d;
+	gchar *ep_str;
+	guint ep;
+	gchar product[256];
+
+	d = NULL;
+
+	if (physdev == NULL || sysfs_path_in_devices == NULL)
+		goto out;
+
+	d = hal_device_new ();
+	hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path);
+	hal_device_property_set_string (d, "info.parent", physdev->udi);
+	hal_device_property_set_string (d, "info.category", "usb_endpoint");
+	hal_device_add_capability (d, "usb_endpoint");
+
+	ep_str = hal_util_get_string_from_file (sysfs_path, "bEndpointAddress");
+	ep = strtoul(ep_str, NULL, 16);
+	g_snprintf(product, sizeof(product), "USB Endpoint 0x%x", ep);
+	hal_device_property_set_string (d, "info.product", product);
+
+	hal_device_property_set_int (d, "usb_endpoint.address", ep);
+	hal_device_property_set_string (d, "usb_endpoint.device", device_file);
+
+out:
+	return d;
+}
+
+static gboolean
+usb_endpoint_compute_udi (HalDevice *d)
+{
+	gchar udi[256];
+
+	hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi), "%s_usb_endpoint_0x%x",
+			      hal_device_property_get_string (d, "info.parent"),
+			      hal_device_property_get_int (d, "usb_endpoint.address"));
+	hal_device_set_udi (d, udi);
+	hal_device_property_set_string (d, "info.udi", udi);
+
+	return TRUE;
+}
+
 
 /*--------------------------------------------------------------------------------------------------------------*/
 
@@ -1142,6 +1189,16 @@ static ClassDevHandler classdev_handler_
 	.remove       = classdev_remove
 };
 
+static ClassDevHandler classdev_handler_usb_endpoint =
+{ 
+	.subsystem    = "usb_endpoint",
+	.add          = usb_endpoint_add,
+	.get_prober   = NULL,
+	.post_probing = NULL,
+	.compute_udi  = usb_endpoint_compute_udi,
+	.remove       = classdev_remove
+};
+
 static ClassDevHandler classdev_handler_video4linux =
 { 
 	.subsystem    = "video4linux",
@@ -1220,6 +1277,7 @@ static ClassDevHandler *classdev_handler
 	&classdev_handler_scsi_host,
 	&classdev_handler_usbclass,
 	&classdev_handler_usbraw,
+	&classdev_handler_usb_endpoint,
 	&classdev_handler_video4linux,
 	&classdev_handler_dvb,
 	&classdev_handler_sound,


More information about the hal mailing list