GCC Code Coverage Report


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