GCC Code Coverage Report


Directory: ./
File: libfprint/fprint-list-udev-hwdb.c
Date: 2025-03-01 04:11:53
Exec Total Coverage
Lines: 47 48 97.9%
Functions: 3 3 100.0%
Branches: 22 24 91.7%

Line Branch Exec Source
1 /*
2 * Copyright (C) 2009 Red Hat <mjg@redhat.com>
3 * Copyright (C) 2008 Bastien Nocera <hadess@hadess.net>
4 * Copyright (C) 2008 Timo Hoenig <thoenig@suse.de>, <thoenig@nouse.net>
5 * Copyright (C) 2019 Benjamin Berg <bberg@redhat.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <config.h>
23
24 #include "fpi-context.h"
25 #include "fpi-device.h"
26
27 static const FpIdEntry allowlist_id_table[] = {
28 /* Currently known and unsupported devices.
29 * You can generate this list from the wiki page using e.g.:
30 * gio cat https://gitlab.freedesktop.org/libfprint/wiki/-/wikis/Unsupported-Devices.md | sed -n 's!|.*\([0-9a-fA-F]\{4\}\):\([0-9a-fA-F]\{4\}\).*|.*! { .vid = 0x\1, .pid = 0x\2 },!p'
31 */
32 { .vid = 0x0a5c, .pid = 0x5802 },
33 { .vid = 0x047d, .pid = 0x00f2 },
34 { .vid = 0x047d, .pid = 0x8054 },
35 { .vid = 0x047d, .pid = 0x8055 },
36 { .vid = 0x04e8, .pid = 0x730b },
37 { .vid = 0x04f3, .pid = 0x036b },
38 { .vid = 0x04f3, .pid = 0x0c00 },
39 { .vid = 0x04f3, .pid = 0x0c4c },
40 { .vid = 0x04f3, .pid = 0x0c57 },
41 { .vid = 0x04f3, .pid = 0x0c5e },
42 { .vid = 0x04f3, .pid = 0x0c5a },
43 { .vid = 0x04f3, .pid = 0x0c60 },
44 { .vid = 0x04f3, .pid = 0x0c6c },
45 { .vid = 0x04f3, .pid = 0x0c70 },
46 { .vid = 0x04f3, .pid = 0x0c72 },
47 { .vid = 0x04f3, .pid = 0x0c77 },
48 { .vid = 0x04f3, .pid = 0x0c7c },
49 { .vid = 0x04f3, .pid = 0x0c7f },
50 { .vid = 0x04f3, .pid = 0x0c80 },
51 { .vid = 0x04f3, .pid = 0x0c85 },
52 { .vid = 0x04f3, .pid = 0x0c90 },
53 { .vid = 0x04f3, .pid = 0x2706 },
54 { .vid = 0x04f3, .pid = 0x3032 },
55 { .vid = 0x04f3, .pid = 0x3057 },
56 { .vid = 0x04f3, .pid = 0x3104 },
57 { .vid = 0x04f3, .pid = 0x310d },
58 { .vid = 0x04f3, .pid = 0x3128 },
59 { .vid = 0x04f3, .pid = 0x0c8a },
60 { .vid = 0x05ba, .pid = 0x000e },
61 { .vid = 0x06cb, .pid = 0x0051 },
62 { .vid = 0x06cb, .pid = 0x0081 },
63 { .vid = 0x06cb, .pid = 0x0088 },
64 { .vid = 0x06cb, .pid = 0x008a },
65 { .vid = 0x06cb, .pid = 0x009a },
66 { .vid = 0x06cb, .pid = 0x009b },
67 { .vid = 0x06cb, .pid = 0x00a2 },
68 { .vid = 0x06cb, .pid = 0x00a8 },
69 { .vid = 0x06cb, .pid = 0x00b7 },
70 { .vid = 0x06cb, .pid = 0x00bb },
71 { .vid = 0x06cb, .pid = 0x00be },
72 { .vid = 0x06cb, .pid = 0x00cb },
73 { .vid = 0x06cb, .pid = 0x00c9 },
74 { .vid = 0x06cb, .pid = 0x00d8 },
75 { .vid = 0x06cb, .pid = 0x00da },
76 { .vid = 0x06cb, .pid = 0x00dc },
77 { .vid = 0x06cb, .pid = 0x00e4 },
78 { .vid = 0x06cb, .pid = 0x00e7 },
79 { .vid = 0x06cb, .pid = 0x00e9 },
80 { .vid = 0x06cb, .pid = 0x00fd },
81 { .vid = 0x06cb, .pid = 0x00ff },
82 { .vid = 0x0a5c, .pid = 0x5801 },
83 { .vid = 0x0a5c, .pid = 0x5805 },
84 { .vid = 0x0a5c, .pid = 0x5834 },
85 { .vid = 0x0a5c, .pid = 0x5840 },
86 { .vid = 0x0a5c, .pid = 0x5841 },
87 { .vid = 0x0a5c, .pid = 0x5842 },
88 { .vid = 0x0a5c, .pid = 0x5843 },
89 { .vid = 0x0a5c, .pid = 0x5844 },
90 { .vid = 0x0a5c, .pid = 0x5845 },
91 { .vid = 0x0a5c, .pid = 0x5860 },
92 { .vid = 0x0a5c, .pid = 0x5863 },
93 { .vid = 0x0a5c, .pid = 0x5864 },
94 { .vid = 0x0a5c, .pid = 0x5865 },
95 { .vid = 0x0a5c, .pid = 0x5866 },
96 { .vid = 0x0a5c, .pid = 0x5867 },
97 { .vid = 0x0bda, .pid = 0x5812 },
98 { .vid = 0x10a5, .pid = 0x0007 },
99 { .vid = 0x10a5, .pid = 0x9200 },
100 { .vid = 0x10a5, .pid = 0x9800 },
101 { .vid = 0x10a5, .pid = 0xa120 },
102 { .vid = 0x10a5, .pid = 0xa900 },
103 { .vid = 0x10a5, .pid = 0xe340 },
104 { .vid = 0x1188, .pid = 0x9545 },
105 { .vid = 0x138a, .pid = 0x0007 },
106 { .vid = 0x138a, .pid = 0x003a },
107 { .vid = 0x138a, .pid = 0x003c },
108 { .vid = 0x138a, .pid = 0x003d },
109 { .vid = 0x138a, .pid = 0x003f },
110 { .vid = 0x138a, .pid = 0x0090 },
111 { .vid = 0x138a, .pid = 0x0092 },
112 { .vid = 0x138a, .pid = 0x0094 },
113 { .vid = 0x138a, .pid = 0x0097 },
114 { .vid = 0x138a, .pid = 0x009d },
115 { .vid = 0x138a, .pid = 0x00ab },
116 { .vid = 0x138a, .pid = 0x00a6 },
117 { .vid = 0x147e, .pid = 0x1002 },
118 { .vid = 0x1491, .pid = 0x0088 },
119 { .vid = 0x16d1, .pid = 0x1027 },
120 { .vid = 0x1c7a, .pid = 0x0300 },
121 { .vid = 0x1c7a, .pid = 0x0575 },
122 { .vid = 0x1c7a, .pid = 0x0576 },
123 { .vid = 0x1c7a, .pid = 0x0584 },
124 { .vid = 0x1c7a, .pid = 0x0577 },
125 { .vid = 0x1c7a, .pid = 0x057e },
126 { .vid = 0x2541, .pid = 0x0236 },
127 { .vid = 0x2541, .pid = 0x9711 },
128 { .vid = 0x27c6, .pid = 0x5042 },
129 { .vid = 0x27c6, .pid = 0x5110 },
130 { .vid = 0x27c6, .pid = 0x5117 },
131 { .vid = 0x27c6, .pid = 0x5120 },
132 { .vid = 0x27c6, .pid = 0x5125 },
133 { .vid = 0x27c6, .pid = 0x5201 },
134 { .vid = 0x27c6, .pid = 0x521d },
135 { .vid = 0x27c6, .pid = 0x5301 },
136 { .vid = 0x27c6, .pid = 0x530c },
137 { .vid = 0x27c6, .pid = 0x532d },
138 { .vid = 0x27c6, .pid = 0x5335 },
139 { .vid = 0x27c6, .pid = 0x533c },
140 { .vid = 0x27c6, .pid = 0x5381 },
141 { .vid = 0x27c6, .pid = 0x5385 },
142 { .vid = 0x27c6, .pid = 0x538c },
143 { .vid = 0x27c6, .pid = 0x538d },
144 { .vid = 0x27c6, .pid = 0x5395 },
145 { .vid = 0x27c6, .pid = 0x5503 },
146 { .vid = 0x27c6, .pid = 0x550a },
147 { .vid = 0x27c6, .pid = 0x550c },
148 { .vid = 0x27c6, .pid = 0x5584 },
149 { .vid = 0x27c6, .pid = 0x55a2 },
150 { .vid = 0x27c6, .pid = 0x55a4 },
151 { .vid = 0x27c6, .pid = 0x55b4 },
152 { .vid = 0x27c6, .pid = 0x5740 },
153 { .vid = 0x27c6, .pid = 0x5e0a },
154 { .vid = 0x27c6, .pid = 0x581a },
155 { .vid = 0x27c6, .pid = 0x589a },
156 { .vid = 0x27c6, .pid = 0x5f10 },
157 { .vid = 0x27c6, .pid = 0x6382 },
158 { .vid = 0x2808, .pid = 0x9338 },
159 { .vid = 0x2808, .pid = 0x9348 },
160 { .vid = 0x2808, .pid = 0x93a9 },
161 { .vid = 0x2808, .pid = 0xa658 },
162 { .vid = 0x2808, .pid = 0xc652 },
163 { .vid = 0x298d, .pid = 0x2020 },
164 { .vid = 0x298d, .pid = 0x2033 },
165 { .vid = 0x2df0, .pid = 0x0003 },
166 { .vid = 0x3274, .pid = 0x8012 },
167 { .vid = 0x3538, .pid = 0x0930 },
168 { .vid = 0 },
169 };
170
171 static const FpIdEntry denylist_id_table[] = {
172 { .vid = 0x0483, .pid = 0x2016 },
173 /* https://bugs.freedesktop.org/show_bug.cgi?id=66659 */
174 { .vid = 0x045e, .pid = 0x00bb },
175 { .vid = 0 },
176 };
177
178 static const FpDeviceClass allowlist = {
179 .type = FP_DEVICE_TYPE_USB,
180 .id_table = allowlist_id_table,
181 .id = "allowlist",
182 .full_name = "Hardcoded allowlist"
183 };
184
185 GHashTable *printed = NULL;
186
187 static void
188 30 print_driver (const FpDeviceClass *cls)
189 {
190 30 const FpIdEntry *entry;
191 30 gint num_printed = 0;
192
193
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if (cls->type != FP_DEVICE_TYPE_USB)
194 return;
195
196
2/2
✓ Branch 0 taken 358 times.
✓ Branch 1 taken 30 times.
388 for (entry = cls->id_table; entry->vid != 0; entry++)
197 {
198 const FpIdEntry *bl_entry;
199 char *key;
200
201
2/2
✓ Branch 0 taken 715 times.
✓ Branch 1 taken 356 times.
1071 for (bl_entry = denylist_id_table; bl_entry->vid != 0; bl_entry++)
202
2/2
✓ Branch 0 taken 713 times.
✓ Branch 1 taken 2 times.
715 if (entry->vid == bl_entry->vid && entry->pid == bl_entry->pid)
203 break;
204
205
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 356 times.
358 if (bl_entry->vid != 0)
206 2 continue;
207
208 356 key = g_strdup_printf ("%04x:%04x", entry->vid, entry->pid);
209
210
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 355 times.
356 if (g_hash_table_lookup (printed, key) != NULL)
211 {
212
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (cls == &allowlist)
213 g_warning ("%s implemented by driver %s",
214 key, (const char *) g_hash_table_lookup (printed, key));
215 1 g_free (key);
216 1 continue;
217 }
218
219 355 g_hash_table_insert (printed, key, (void *) cls->id);
220
221
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 326 times.
355 if (num_printed == 0)
222 {
223
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 1 times.
29 if (cls != &allowlist)
224 28 g_print ("\n# Supported by libfprint driver %s\n", cls->id);
225 else
226 1 g_print ("\n# Known unsupported devices\n");
227 }
228
229 355 g_print ("usb:v%04Xp%04X*\n",
230 355 entry->vid, entry->pid);
231 355 num_printed++;
232 }
233
234
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 1 times.
30 if (num_printed > 0)
235 {
236 29 g_print (" ID_AUTOSUSPEND=1\n");
237 29 g_print (" ID_PERSIST=0\n");
238 }
239 }
240
241 static int
242 120 driver_compare (gconstpointer p1, gconstpointer p2)
243 {
244 120 g_autoptr(FpDeviceClass) cls1 = g_type_class_ref (*(GType *) p1);
245 240 g_autoptr(FpDeviceClass) cls2 = g_type_class_ref (*(GType *) p2);
246
247 120 return g_strcmp0 (cls1->id, cls2->id);
248 }
249
250 int
251 1 main (int argc, char **argv)
252 {
253 1 g_autoptr(GArray) drivers = fpi_get_driver_types ();
254 1 g_autofree char *program_name = NULL;
255 1 guint i;
256
257 1 program_name = g_path_get_basename (argv[0]);
258
259 1 g_print ("# SPDX-License-Identifier: LGPL-2.1-or-later\n");
260 1 g_print ("# This file has been generated using %s with all drivers enabled\n",
261 program_name);
262
263 1 printed = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
264 1 g_array_sort (drivers, driver_compare);
265
266
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 1 times.
35 for (i = 0; i < drivers->len; i++)
267 {
268 33 GType driver = g_array_index (drivers, GType, i);
269 66 g_autoptr(FpDeviceClass) cls = g_type_class_ref (driver);
270
271
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 29 times.
33 if (cls->type != FP_DEVICE_TYPE_USB)
272 4 continue;
273
274 29 print_driver (cls);
275 }
276
277 1 print_driver (&allowlist);
278
279 1 g_hash_table_destroy (printed);
280
281 1 return 0;
282 }
283