xref: /freebsd/contrib/libfido2/udev/genrules.awk (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1#!/usr/bin/awk -f
2
3# Copyright (c) 2020 Yubico AB. All rights reserved.
4# Use of this source code is governed by a BSD-style
5# license that can be found in the LICENSE file.
6# SPDX-License-Identifier: BSD-2-Clause
7
8NR == 1 {
9	print "# Copyright (c) 2020 Yubico AB. All rights reserved."
10	print "#"
11	print "# Redistribution and use in source and binary forms, with or without"
12	print "# modification, are permitted provided that the following conditions are"
13	print "# met:"
14	print "# "
15	print "#    1. Redistributions of source code must retain the above copyright"
16	print "#       notice, this list of conditions and the following disclaimer."
17	print "#    2. Redistributions in binary form must reproduce the above copyright"
18	print "#       notice, this list of conditions and the following disclaimer in"
19	print "#       the documentation and/or other materials provided with the"
20	print "#       distribution."
21	print "# "
22	print "# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS"
23	print "# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT"
24	print "# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR"
25	print "# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT"
26	print "# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,"
27	print "# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT"
28	print "# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,"
29	print "# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY"
30	print "# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT"
31	print "# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE"
32	print "# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
33	print "#"
34	print "# SPDX-License-Identifier: BSD-2-Clause"
35	print ""
36	print "# This file is automatically generated, and should be used with udev 188"
37	print "# or newer."
38	print ""
39	print "ACTION!=\"add|change\", GOTO=\"fido_end\""
40
41	next
42}
43
44$1 == "vendor" {
45	sub("0x", "", $3)
46	vendors[$2, "id"] = $3
47
48	f = 4
49	while (f <= NF) {
50		vendors[$2, "name"] = vendors[$2, "name"] " " $f
51		f++
52	}
53}
54
55$1 == "product" {
56	sub("0x", "", $3)
57	name = ""
58
59	f = 4
60	while (f <= NF) {
61		name = name " " $f
62		f++
63	}
64
65	line = "\n#" name " by" vendors[$2, "name"]"\n"
66	line = line"KERNEL==\"hidraw*\""
67	line = line", SUBSYSTEM==\"hidraw\""
68	line = line", ATTRS{idVendor}==\""vendors[$2, "id"]"\""
69	line = line", ATTRS{idProduct}==\""$3"\""
70	line = line", TAG+=\"uaccess\""
71	line = line", GROUP=\"plugdev\""
72	line = line", MODE=\"0660\""
73
74	print line
75}
76
77END {
78	print "\nLABEL=\"fido_end\""
79}
80