Skip to content

Commit 85195a3

Browse files
jo-bitschLDVG
authored andcommitted
hidraw: fallback to HID_NAME
If we can't get the vendor/product string of the USB attributes, fallback to the HID_NAME string collected from the uevent.
1 parent f03f4c4 commit 85195a3

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/hid_linux.c

+16-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ is_fido(const char *path)
7777

7878
static int
7979
parse_uevent(const char *uevent, int *bus, int16_t *vendor_id,
80-
int16_t *product_id)
80+
int16_t *product_id, char **hid_name)
8181
{
8282
char *cp;
8383
char *p;
@@ -97,8 +97,12 @@ parse_uevent(const char *uevent, int *bus, int16_t *vendor_id,
9797
*vendor_id = (int16_t)y;
9898
*product_id = (int16_t)z;
9999
ok = 0;
100-
break;
101100
}
101+
continue;
102+
}
103+
if (strncmp(p, "HID_NAME=", 9) == 0 && hid_name != NULL && *hid_name == NULL) {
104+
*hid_name = strdup(p + 9);
105+
continue;
102106
}
103107
}
104108

@@ -137,6 +141,7 @@ copy_info(fido_dev_info_t *di, struct udev *udev,
137141
char *uevent = NULL;
138142
struct udev_device *dev = NULL;
139143
int bus = 0;
144+
char *hid_name = NULL;
140145
int ok = -1;
141146

142147
memset(di, 0, sizeof(*di));
@@ -148,7 +153,7 @@ copy_info(fido_dev_info_t *di, struct udev *udev,
148153
goto fail;
149154

150155
if ((uevent = get_parent_attr(dev, "hid", NULL, "uevent")) == NULL ||
151-
parse_uevent(uevent, &bus, &di->vendor_id, &di->product_id) < 0) {
156+
parse_uevent(uevent, &bus, &di->vendor_id, &di->product_id, &hid_name) < 0) {
152157
fido_log_debug("%s: uevent", __func__);
153158
goto fail;
154159
}
@@ -165,6 +170,13 @@ copy_info(fido_dev_info_t *di, struct udev *udev,
165170
di->manufacturer = strdup("");
166171
if ((di->product = get_usb_attr(dev, "product")) == NULL)
167172
di->product = strdup("");
173+
if ( di->manufacturer != NULL && *di->manufacturer == '\0' &&
174+
di->product != NULL && *di->product == '\0' &&
175+
hid_name != NULL ) {
176+
177+
free(di->product);
178+
di->product = strdup(hid_name);
179+
}
168180
if (di->path == NULL || di->manufacturer == NULL || di->product == NULL)
169181
goto fail;
170182

@@ -174,6 +186,7 @@ copy_info(fido_dev_info_t *di, struct udev *udev,
174186
udev_device_unref(dev);
175187

176188
free(uevent);
189+
free(hid_name);
177190

178191
if (ok < 0) {
179192
free(di->path);

0 commit comments

Comments
 (0)