GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 97.9% 47 / 0 / 48
Functions: 100.0% 3 / 0 / 3
Branches: 92.3% 24 / 0 / 26

libfprint/fprint-list-udev-hwdb.c
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 = 0x00a1 },
68 { .vid = 0x06cb, .pid = 0x00a2 },
69 { .vid = 0x06cb, .pid = 0x00a8 },
70 { .vid = 0x06cb, .pid = 0x00b7 },
71 { .vid = 0x06cb, .pid = 0x00bb },
72 { .vid = 0x06cb, .pid = 0x00bc },
73 { .vid = 0x06cb, .pid = 0x00be },
74 { .vid = 0x06cb, .pid = 0x00cb },
75 { .vid = 0x06cb, .pid = 0x00c9 },
76 { .vid = 0x06cb, .pid = 0x00d8 },
77 { .vid = 0x06cb, .pid = 0x00da },
78 { .vid = 0x06cb, .pid = 0x00dc },
79 { .vid = 0x06cb, .pid = 0x00e4 },
80 { .vid = 0x06cb, .pid = 0x00e7 },
81 { .vid = 0x06cb, .pid = 0x00fd },
82 { .vid = 0x06cb, .pid = 0x00ff },
83 { .vid = 0x0a5c, .pid = 0x5801 },
84 { .vid = 0x0a5c, .pid = 0x5805 },
85 { .vid = 0x0a5c, .pid = 0x5834 },
86 { .vid = 0x0a5c, .pid = 0x5840 },
87 { .vid = 0x0a5c, .pid = 0x5841 },
88 { .vid = 0x0a5c, .pid = 0x5842 },
89 { .vid = 0x0a5c, .pid = 0x5843 },
90 { .vid = 0x0a5c, .pid = 0x5844 },
91 { .vid = 0x0a5c, .pid = 0x5845 },
92 { .vid = 0x0a5c, .pid = 0x5860 },
93 { .vid = 0x0a5c, .pid = 0x5863 },
94 { .vid = 0x0a5c, .pid = 0x5864 },
95 { .vid = 0x0a5c, .pid = 0x5865 },
96 { .vid = 0x0a5c, .pid = 0x5866 },
97 { .vid = 0x0a5c, .pid = 0x5867 },
98 { .vid = 0x0bda, .pid = 0x5812 },
99 { .vid = 0x10a5, .pid = 0x0007 },
100 { .vid = 0x10a5, .pid = 0x9200 },
101 { .vid = 0x10a5, .pid = 0x9201 },
102 { .vid = 0x10a5, .pid = 0x9800 },
103 { .vid = 0x10a5, .pid = 0xa120 },
104 { .vid = 0x10a5, .pid = 0xa900 },
105 { .vid = 0x10a5, .pid = 0xa921 },
106 { .vid = 0x10a5, .pid = 0xe340 },
107 { .vid = 0x1188, .pid = 0x9545 },
108 { .vid = 0x138a, .pid = 0x0007 },
109 { .vid = 0x138a, .pid = 0x003a },
110 { .vid = 0x138a, .pid = 0x003c },
111 { .vid = 0x138a, .pid = 0x003d },
112 { .vid = 0x138a, .pid = 0x003f },
113 { .vid = 0x138a, .pid = 0x0090 },
114 { .vid = 0x138a, .pid = 0x0092 },
115 { .vid = 0x138a, .pid = 0x0094 },
116 { .vid = 0x138a, .pid = 0x0097 },
117 { .vid = 0x138a, .pid = 0x009d },
118 { .vid = 0x138a, .pid = 0x00ab },
119 { .vid = 0x138a, .pid = 0x00a6 },
120 { .vid = 0x147e, .pid = 0x1002 },
121 { .vid = 0x1491, .pid = 0x0088 },
122 { .vid = 0x16d1, .pid = 0x1027 },
123 { .vid = 0x1c7a, .pid = 0x0300 },
124 { .vid = 0x1c7a, .pid = 0x0575 },
125 { .vid = 0x1c7a, .pid = 0x0576 },
126 { .vid = 0x1c7a, .pid = 0x0577 },
127 { .vid = 0x1c7a, .pid = 0x057e },
128 { .vid = 0x2541, .pid = 0x0236 },
129 { .vid = 0x2541, .pid = 0x9711 },
130 { .vid = 0x27c6, .pid = 0x5042 },
131 { .vid = 0x27c6, .pid = 0x5110 },
132 { .vid = 0x27c6, .pid = 0x5117 },
133 { .vid = 0x27c6, .pid = 0x5120 },
134 { .vid = 0x27c6, .pid = 0x5125 },
135 { .vid = 0x27c6, .pid = 0x5201 },
136 { .vid = 0x27c6, .pid = 0x521d },
137 { .vid = 0x27c6, .pid = 0x5301 },
138 { .vid = 0x27c6, .pid = 0x530c },
139 { .vid = 0x27c6, .pid = 0x532d },
140 { .vid = 0x27c6, .pid = 0x5335 },
141 { .vid = 0x27c6, .pid = 0x533c },
142 { .vid = 0x27c6, .pid = 0x5381 },
143 { .vid = 0x27c6, .pid = 0x5385 },
144 { .vid = 0x27c6, .pid = 0x538c },
145 { .vid = 0x27c6, .pid = 0x538d },
146 { .vid = 0x27c6, .pid = 0x5395 },
147 { .vid = 0x27c6, .pid = 0x5503 },
148 { .vid = 0x27c6, .pid = 0x550a },
149 { .vid = 0x27c6, .pid = 0x550c },
150 { .vid = 0x27c6, .pid = 0x5584 },
151 { .vid = 0x27c6, .pid = 0x55a2 },
152 { .vid = 0x27c6, .pid = 0x55a4 },
153 { .vid = 0x27c6, .pid = 0x55b4 },
154 { .vid = 0x27c6, .pid = 0x5740 },
155 { .vid = 0x27c6, .pid = 0x5e0a },
156 { .vid = 0x27c6, .pid = 0x581a },
157 { .vid = 0x27c6, .pid = 0x589a },
158 { .vid = 0x27c6, .pid = 0x5f10 },
159 { .vid = 0x27c6, .pid = 0x5f91 },
160 { .vid = 0x2808, .pid = 0x9338 },
161 { .vid = 0x2808, .pid = 0x9348 },
162 { .vid = 0x2808, .pid = 0x93a9 },
163 { .vid = 0x2808, .pid = 0xa658 },
164 { .vid = 0x2808, .pid = 0xc652 },
165 { .vid = 0x2808, .pid = 0xa553 },
166 { .vid = 0x298d, .pid = 0x2033 },
167 { .vid = 0x2df0, .pid = 0x0003 },
168 { .vid = 0x3538, .pid = 0x0930 },
169 { .vid = 0 },
170 };
171
172 static const FpIdEntry denylist_id_table[] = {
173 { .vid = 0x0483, .pid = 0x2016 },
174 /* https://bugs.freedesktop.org/show_bug.cgi?id=66659 */
175 { .vid = 0x045e, .pid = 0x00bb },
176 { .vid = 0 },
177 };
178
179 static const FpDeviceClass allowlist = {
180 .type = FP_DEVICE_TYPE_USB,
181 .id_table = allowlist_id_table,
182 .id = "allowlist",
183 .full_name = "Hardcoded allowlist"
184 };
185
186 GHashTable *printed = NULL;
187
188 static void
189 33 print_driver (const FpDeviceClass *cls)
190 {
191 33 const FpIdEntry *entry;
192 33 gint num_printed = 0;
193
194
1/2
✓ Branch 2 → 3 taken 33 times.
✗ Branch 2 → 30 not taken.
33 if (cls->type != FP_DEVICE_TYPE_USB)
195 return;
196
197
2/2
✓ Branch 26 → 7 taken 394 times.
✓ Branch 26 → 27 taken 33 times.
427 for (entry = cls->id_table; entry->vid != 0; entry++)
198 {
199 const FpIdEntry *bl_entry;
200 char *key;
201
202
2/2
✓ Branch 7 → 4 taken 787 times.
✓ Branch 7 → 8 taken 392 times.
1179 for (bl_entry = denylist_id_table; bl_entry->vid != 0; bl_entry++)
203
4/4
✓ Branch 4 → 5 taken 7 times.
✓ Branch 4 → 6 taken 780 times.
✓ Branch 5 → 6 taken 5 times.
✓ Branch 5 → 8 taken 2 times.
787 if (entry->vid == bl_entry->vid && entry->pid == bl_entry->pid)
204 break;
205
206
2/2
✓ Branch 8 → 9 taken 2 times.
✓ Branch 8 → 10 taken 392 times.
394 if (bl_entry->vid != 0)
207 2 continue;
208
209 392 key = g_strdup_printf ("%04x:%04x", entry->vid, entry->pid);
210
211
2/2
✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 18 taken 391 times.
392 if (g_hash_table_lookup (printed, key) != NULL)
212 {
213
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 16 taken 1 time.
1 if (cls == &allowlist)
214 g_warning ("%s implemented by driver %s",
215 key, (const char *) g_hash_table_lookup (printed, key));
216 1 g_free (key);
217 1 continue;
218 }
219
220 391 g_hash_table_insert (printed, key, (void *) cls->id);
221
222
2/2
✓ Branch 19 → 20 taken 32 times.
✓ Branch 19 → 23 taken 359 times.
391 if (num_printed == 0)
223 {
224
2/2
✓ Branch 20 → 21 taken 31 times.
✓ Branch 20 → 22 taken 1 time.
32 if (cls != &allowlist)
225 31 g_print ("\n# Supported by libfprint driver %s\n", cls->id);
226 else
227 1 g_print ("\n# Known unsupported devices\n");
228 }
229
230 391 g_print ("usb:v%04Xp%04X*\n",
231 391 entry->vid, entry->pid);
232 391 num_printed++;
233 }
234
235
2/2
✓ Branch 27 → 28 taken 32 times.
✓ Branch 27 → 30 taken 1 time.
33 if (num_printed > 0)
236 {
237 32 g_print (" ID_AUTOSUSPEND=1\n");
238 32 g_print (" ID_PERSIST=0\n");
239 }
240 }
241
242 static int
243 138 driver_compare (gconstpointer p1, gconstpointer p2)
244 {
245 138 g_autoptr(FpDeviceClass) cls1 = g_type_class_ref (*(GType *) p1);
246 276 g_autoptr(FpDeviceClass) cls2 = g_type_class_ref (*(GType *) p2);
247
248 138 return g_strcmp0 (cls1->id, cls2->id);
249 }
250
251 int
252 1 main (int argc, char **argv)
253 {
254 1 g_autoptr(GArray) drivers = fpi_get_driver_types ();
255 1 g_autofree char *program_name = NULL;
256 1 guint i;
257
258 1 program_name = g_path_get_basename (argv[0]);
259
260 1 g_print ("# SPDX-License-Identifier: LGPL-2.1-or-later\n");
261 1 g_print ("# This file has been generated using %s with all drivers enabled\n",
262 program_name);
263
264 1 printed = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
265 1 g_array_sort (drivers, driver_compare);
266
267
2/2
✓ Branch 15 → 9 taken 36 times.
✓ Branch 15 → 16 taken 1 time.
38 for (i = 0; i < drivers->len; i++)
268 {
269 36 GType driver = g_array_index (drivers, GType, i);
270 72 g_autoptr(FpDeviceClass) cls = g_type_class_ref (driver);
271
272
2/2
✓ Branch 10 → 11 taken 4 times.
✓ Branch 10 → 12 taken 32 times.
36 if (cls->type != FP_DEVICE_TYPE_USB)
273 4 continue;
274
275 32 print_driver (cls);
276 }
277
278 1 print_driver (&allowlist);
279
280 1 g_hash_table_destroy (printed);
281
282 1 return 0;
283 }
284