GCC Code Coverage Report


Directory: ./
File: libfprint/fprint-list-udev-hwdb.c
Date: 2024-09-16 14:36:32
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 = 0x047d, .pid = 0x00f2 },
33 { .vid = 0x04e8, .pid = 0x730b },
34 { .vid = 0x04f3, .pid = 0x036b },
35 { .vid = 0x04f3, .pid = 0x0c00 },
36 { .vid = 0x04f3, .pid = 0x0c4c },
37 { .vid = 0x04f3, .pid = 0x0c57 },
38 { .vid = 0x04f3, .pid = 0x0c5e },
39 { .vid = 0x04f3, .pid = 0x0c5a },
40 { .vid = 0x04f3, .pid = 0x0c6c },
41 { .vid = 0x04f3, .pid = 0x0c70 },
42 { .vid = 0x04f3, .pid = 0x0c72 },
43 { .vid = 0x04f3, .pid = 0x0c77 },
44 { .vid = 0x04f3, .pid = 0x2706 },
45 { .vid = 0x04f3, .pid = 0x3032 },
46 { .vid = 0x04f3, .pid = 0x3057 },
47 { .vid = 0x04f3, .pid = 0x3104 },
48 { .vid = 0x04f3, .pid = 0x310d },
49 { .vid = 0x04f3, .pid = 0x3128 },
50 { .vid = 0x06cb, .pid = 0x0081 },
51 { .vid = 0x06cb, .pid = 0x0088 },
52 { .vid = 0x06cb, .pid = 0x008a },
53 { .vid = 0x06cb, .pid = 0x009a },
54 { .vid = 0x06cb, .pid = 0x009b },
55 { .vid = 0x06cb, .pid = 0x00a2 },
56 { .vid = 0x06cb, .pid = 0x00a8 },
57 { .vid = 0x06cb, .pid = 0x00b7 },
58 { .vid = 0x06cb, .pid = 0x00bb },
59 { .vid = 0x06cb, .pid = 0x00be },
60 { .vid = 0x06cb, .pid = 0x00cb },
61 { .vid = 0x06cb, .pid = 0x00c9 },
62 { .vid = 0x06cb, .pid = 0x00d8 },
63 { .vid = 0x06cb, .pid = 0x00da },
64 { .vid = 0x06cb, .pid = 0x00dc },
65 { .vid = 0x06cb, .pid = 0x00e4 },
66 { .vid = 0x06cb, .pid = 0x00e7 },
67 { .vid = 0x06cb, .pid = 0x00e9 },
68 { .vid = 0x06cb, .pid = 0x00fd },
69 { .vid = 0x0a5c, .pid = 0x5801 },
70 { .vid = 0x0a5c, .pid = 0x5805 },
71 { .vid = 0x0a5c, .pid = 0x5834 },
72 { .vid = 0x0a5c, .pid = 0x5840 },
73 { .vid = 0x0a5c, .pid = 0x5841 },
74 { .vid = 0x0a5c, .pid = 0x5842 },
75 { .vid = 0x0a5c, .pid = 0x5843 },
76 { .vid = 0x0a5c, .pid = 0x5844 },
77 { .vid = 0x0a5c, .pid = 0x5845 },
78 { .vid = 0x0a5c, .pid = 0x5860 },
79 { .vid = 0x0a5c, .pid = 0x5863 },
80 { .vid = 0x0a5c, .pid = 0x5864 },
81 { .vid = 0x0a5c, .pid = 0x5865 },
82 { .vid = 0x0a5c, .pid = 0x5866 },
83 { .vid = 0x0a5c, .pid = 0x5867 },
84 { .vid = 0x0bda, .pid = 0x5812 },
85 { .vid = 0x10a5, .pid = 0x0007 },
86 { .vid = 0x10a5, .pid = 0x9200 },
87 { .vid = 0x10a5, .pid = 0x9800 },
88 { .vid = 0x10a5, .pid = 0xe340 },
89 { .vid = 0x1188, .pid = 0x9545 },
90 { .vid = 0x138a, .pid = 0x0007 },
91 { .vid = 0x138a, .pid = 0x003a },
92 { .vid = 0x138a, .pid = 0x003c },
93 { .vid = 0x138a, .pid = 0x003d },
94 { .vid = 0x138a, .pid = 0x003f },
95 { .vid = 0x138a, .pid = 0x0090 },
96 { .vid = 0x138a, .pid = 0x0092 },
97 { .vid = 0x138a, .pid = 0x0094 },
98 { .vid = 0x138a, .pid = 0x0097 },
99 { .vid = 0x138a, .pid = 0x009d },
100 { .vid = 0x138a, .pid = 0x00ab },
101 { .vid = 0x138a, .pid = 0x00a6 },
102 { .vid = 0x147e, .pid = 0x1002 },
103 { .vid = 0x1491, .pid = 0x0088 },
104 { .vid = 0x16d1, .pid = 0x1027 },
105 { .vid = 0x1c7a, .pid = 0x0300 },
106 { .vid = 0x1c7a, .pid = 0x0575 },
107 { .vid = 0x1c7a, .pid = 0x0576 },
108 { .vid = 0x1c7a, .pid = 0x0577 },
109 { .vid = 0x27c6, .pid = 0x5042 },
110 { .vid = 0x27c6, .pid = 0x5110 },
111 { .vid = 0x27c6, .pid = 0x5117 },
112 { .vid = 0x27c6, .pid = 0x5120 },
113 { .vid = 0x27c6, .pid = 0x5125 },
114 { .vid = 0x27c6, .pid = 0x5201 },
115 { .vid = 0x27c6, .pid = 0x521d },
116 { .vid = 0x27c6, .pid = 0x5301 },
117 { .vid = 0x27c6, .pid = 0x530c },
118 { .vid = 0x27c6, .pid = 0x532d },
119 { .vid = 0x27c6, .pid = 0x5335 },
120 { .vid = 0x27c6, .pid = 0x533c },
121 { .vid = 0x27c6, .pid = 0x5381 },
122 { .vid = 0x27c6, .pid = 0x5385 },
123 { .vid = 0x27c6, .pid = 0x538c },
124 { .vid = 0x27c6, .pid = 0x538d },
125 { .vid = 0x27c6, .pid = 0x5395 },
126 { .vid = 0x27c6, .pid = 0x5503 },
127 { .vid = 0x27c6, .pid = 0x550a },
128 { .vid = 0x27c6, .pid = 0x550c },
129 { .vid = 0x27c6, .pid = 0x5584 },
130 { .vid = 0x27c6, .pid = 0x55a2 },
131 { .vid = 0x27c6, .pid = 0x55a4 },
132 { .vid = 0x27c6, .pid = 0x55b4 },
133 { .vid = 0x27c6, .pid = 0x5740 },
134 { .vid = 0x27c6, .pid = 0x5e0a },
135 { .vid = 0x27c6, .pid = 0x581a },
136 { .vid = 0x27c6, .pid = 0x589a },
137 { .vid = 0x27c6, .pid = 0x6382 },
138 { .vid = 0x2808, .pid = 0x9338 },
139 { .vid = 0x2808, .pid = 0x93a9 },
140 { .vid = 0x298d, .pid = 0x2020 },
141 { .vid = 0x298d, .pid = 0x2033 },
142 { .vid = 0x3538, .pid = 0x0930 },
143 { .vid = 0 },
144 };
145
146 static const FpIdEntry denylist_id_table[] = {
147 { .vid = 0x0483, .pid = 0x2016 },
148 /* https://bugs.freedesktop.org/show_bug.cgi?id=66659 */
149 { .vid = 0x045e, .pid = 0x00bb },
150 { .vid = 0 },
151 };
152
153 static const FpDeviceClass allowlist = {
154 .type = FP_DEVICE_TYPE_USB,
155 .id_table = allowlist_id_table,
156 .id = "allowlist",
157 .full_name = "Hardcoded allowlist"
158 };
159
160 GHashTable *printed = NULL;
161
162 static void
163 30 print_driver (const FpDeviceClass *cls)
164 {
165 30 const FpIdEntry *entry;
166 30 gint num_printed = 0;
167
168
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if (cls->type != FP_DEVICE_TYPE_USB)
169 return;
170
171
2/2
✓ Branch 0 taken 321 times.
✓ Branch 1 taken 30 times.
351 for (entry = cls->id_table; entry->vid != 0; entry++)
172 {
173 const FpIdEntry *bl_entry;
174 char *key;
175
176
2/2
✓ Branch 0 taken 641 times.
✓ Branch 1 taken 319 times.
960 for (bl_entry = denylist_id_table; bl_entry->vid != 0; bl_entry++)
177
2/2
✓ Branch 0 taken 639 times.
✓ Branch 1 taken 2 times.
641 if (entry->vid == bl_entry->vid && entry->pid == bl_entry->pid)
178 break;
179
180
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 319 times.
321 if (bl_entry->vid != 0)
181 2 continue;
182
183 319 key = g_strdup_printf ("%04x:%04x", entry->vid, entry->pid);
184
185
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 318 times.
319 if (g_hash_table_lookup (printed, key) != NULL)
186 {
187
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (cls == &allowlist)
188 g_warning ("%s implemented by driver %s",
189 key, (const char *) g_hash_table_lookup (printed, key));
190 1 g_free (key);
191 1 continue;
192 }
193
194 318 g_hash_table_insert (printed, key, (void *) cls->id);
195
196
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 289 times.
318 if (num_printed == 0)
197 {
198
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 1 times.
29 if (cls != &allowlist)
199 28 g_print ("\n# Supported by libfprint driver %s\n", cls->id);
200 else
201 1 g_print ("\n# Known unsupported devices\n");
202 }
203
204 318 g_print ("usb:v%04Xp%04X*\n",
205 318 entry->vid, entry->pid);
206 318 num_printed++;
207 }
208
209
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 1 times.
30 if (num_printed > 0)
210 {
211 29 g_print (" ID_AUTOSUSPEND=1\n");
212 29 g_print (" ID_PERSIST=0\n");
213 }
214 }
215
216 static int
217 120 driver_compare (gconstpointer p1, gconstpointer p2)
218 {
219 120 g_autoptr(FpDeviceClass) cls1 = g_type_class_ref (*(GType *) p1);
220 240 g_autoptr(FpDeviceClass) cls2 = g_type_class_ref (*(GType *) p2);
221
222 120 return g_strcmp0 (cls1->id, cls2->id);
223 }
224
225 int
226 1 main (int argc, char **argv)
227 {
228 1 g_autoptr(GArray) drivers = fpi_get_driver_types ();
229 1 g_autofree char *program_name = NULL;
230 1 guint i;
231
232 1 program_name = g_path_get_basename (argv[0]);
233
234 1 g_print ("# SPDX-License-Identifier: LGPL-2.1-or-later\n");
235 1 g_print ("# This file has been generated using %s with all drivers enabled\n",
236 program_name);
237
238 1 printed = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
239 1 g_array_sort (drivers, driver_compare);
240
241
2/2
✓ Branch 1 taken 33 times.
✓ Branch 2 taken 1 times.
35 for (i = 0; i < drivers->len; i++)
242 {
243 33 GType driver = g_array_index (drivers, GType, i);
244 66 g_autoptr(FpDeviceClass) cls = g_type_class_ref (driver);
245
246
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 29 times.
33 if (cls->type != FP_DEVICE_TYPE_USB)
247 4 continue;
248
249 29 print_driver (cls);
250 }
251
252 1 print_driver (&allowlist);
253
254 1 g_hash_table_destroy (printed);
255
256 1 return 0;
257 }
258