fp-context: Check hidraw VID/PID with udev instead of an ioctl
Previously, we checked hidraw devices against drivers by using the HIDIOCGRAWINFO ioctl. While this works, it's not ideal for doing unit tests since umockdev would have to implement hidraw ioctls. The new approach uses the HID_ID property on the parent hid device, which contains the VID/PID pair.
This commit is contained in:
parent
ba920aa41b
commit
a3f568db3d
1 changed files with 8 additions and 17 deletions
|
@ -23,16 +23,11 @@
|
||||||
#include "fpi-context.h"
|
#include "fpi-context.h"
|
||||||
#include "fpi-device.h"
|
#include "fpi-device.h"
|
||||||
#include <gusb.h>
|
#include <gusb.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#ifdef HAVE_UDEV
|
#ifdef HAVE_UDEV
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/unistd.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/fcntl.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <linux/hidraw.h>
|
|
||||||
#include <gudev/gudev.h>
|
#include <gudev/gudev.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -521,22 +516,18 @@ fp_context_enumerate (FpContext *context)
|
||||||
{
|
{
|
||||||
for (matched_hidraw = hidraw_devices; matched_hidraw; matched_hidraw = matched_hidraw->next)
|
for (matched_hidraw = hidraw_devices; matched_hidraw; matched_hidraw = matched_hidraw->next)
|
||||||
{
|
{
|
||||||
const gchar * devnode = g_udev_device_get_device_file (matched_hidraw->data);
|
/* Find the parent HID node, and check the vid/pid from its HID_ID property */
|
||||||
int temp_hid = -1, res;
|
g_autoptr(GUdevDevice) parent = g_udev_device_get_parent_with_subsystem (matched_hidraw->data, "hid", NULL);
|
||||||
struct hidraw_devinfo info;
|
const gchar * hid_id = g_udev_device_get_property (parent, "HID_ID");
|
||||||
|
guint32 vendor, product;
|
||||||
|
|
||||||
if (!devnode)
|
if (!parent || !hid_id)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
temp_hid = open (devnode, O_RDWR);
|
if (sscanf (hid_id, "%*X:%X:%X", &vendor, &product) != 2)
|
||||||
if (temp_hid < 0)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
res = ioctl (temp_hid, HIDIOCGRAWINFO, &info);
|
if (vendor == entry->hid_id.vid && product == entry->hid_id.pid)
|
||||||
close (temp_hid);
|
|
||||||
if (res < 0)
|
|
||||||
continue;
|
|
||||||
if (info.vendor == entry->hid_id.vid && info.product == entry->hid_id.pid)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* If match was not found exit */
|
/* If match was not found exit */
|
||||||
|
|
Loading…
Reference in a new issue