MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / hid_enumerate

Function hid_enumerate

lib/hidapi/linux/hid.c:844–929  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

842}
843
844struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, unsigned short product_id)
845{
846 struct udev *udev;
847 struct udev_enumerate *enumerate;
848 struct udev_list_entry *devices, *dev_list_entry;
849
850 struct hid_device_info *root = NULL; /* return object */
851 struct hid_device_info *cur_dev = NULL;
852
853 hid_init();
854 /* register_global_error: global error is reset by hid_init */
855
856 /* Create the udev object */
857 udev = udev_new();
858 if (!udev) {
859 register_global_error("Couldn't create udev context");
860 return NULL;
861 }
862
863 /* Create a list of the devices in the 'hidraw' subsystem. */
864 enumerate = udev_enumerate_new(udev);
865 udev_enumerate_add_match_subsystem(enumerate, "hidraw");
866 udev_enumerate_scan_devices(enumerate);
867 devices = udev_enumerate_get_list_entry(enumerate);
868 /* For each item, see if it matches the vid/pid, and if so
869 create a udev_device record for it */
870 udev_list_entry_foreach(dev_list_entry, devices) {
871 const char *sysfs_path;
872 unsigned short dev_vid = 0;
873 unsigned short dev_pid = 0;
874 unsigned bus_type = 0;
875 struct udev_device *raw_dev; /* The device's hidraw udev node. */
876 struct hid_device_info * tmp;
877
878 /* Get the filename of the /sys entry for the device
879 and create a udev_device object (dev) representing it */
880 sysfs_path = udev_list_entry_get_name(dev_list_entry);
881 if (!sysfs_path)
882 continue;
883
884 if (vendor_id != 0 || product_id != 0) {
885 if (!parse_hid_vid_pid_from_sysfs(sysfs_path, &bus_type, &dev_vid, &dev_pid))
886 continue;
887
888 if (vendor_id != 0 && vendor_id != dev_vid)
889 continue;
890 if (product_id != 0 && product_id != dev_pid)
891 continue;
892 }
893
894 raw_dev = udev_device_new_from_syspath(udev, sysfs_path);
895 if (!raw_dev)
896 continue;
897
898 tmp = create_device_info_for_device(raw_dev);
899 if (tmp) {
900 if (cur_dev) {
901 cur_dev->next = tmp;

Callers 1

hid_openFunction · 0.70

Calls 3

register_global_errorFunction · 0.70

Tested by

no test coverage detected