xref: /freebsd/contrib/libfido2/udev/genrules.awk (revision 2ccfa855b2fc331819953e3de1b1c15ce5b95a7e)
10afa8e06SEd Maste#!/usr/bin/awk -f
20afa8e06SEd Maste
30afa8e06SEd Maste# Copyright (c) 2020 Yubico AB. All rights reserved.
40afa8e06SEd Maste# Use of this source code is governed by a BSD-style
50afa8e06SEd Maste# license that can be found in the LICENSE file.
6*2ccfa855SEd Maste# SPDX-License-Identifier: BSD-2-Clause
70afa8e06SEd Maste
80afa8e06SEd MasteNR == 1 {
90afa8e06SEd Maste	print "# Copyright (c) 2020 Yubico AB. All rights reserved."
10*2ccfa855SEd Maste	print "#"
11*2ccfa855SEd Maste	print "# Redistribution and use in source and binary forms, with or without"
12*2ccfa855SEd Maste	print "# modification, are permitted provided that the following conditions are"
13*2ccfa855SEd Maste	print "# met:"
14*2ccfa855SEd Maste	print "# "
15*2ccfa855SEd Maste	print "#    1. Redistributions of source code must retain the above copyright"
16*2ccfa855SEd Maste	print "#       notice, this list of conditions and the following disclaimer."
17*2ccfa855SEd Maste	print "#    2. Redistributions in binary form must reproduce the above copyright"
18*2ccfa855SEd Maste	print "#       notice, this list of conditions and the following disclaimer in"
19*2ccfa855SEd Maste	print "#       the documentation and/or other materials provided with the"
20*2ccfa855SEd Maste	print "#       distribution."
21*2ccfa855SEd Maste	print "# "
22*2ccfa855SEd Maste	print "# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS"
23*2ccfa855SEd Maste	print "# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT"
24*2ccfa855SEd Maste	print "# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR"
25*2ccfa855SEd Maste	print "# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT"
26*2ccfa855SEd Maste	print "# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,"
27*2ccfa855SEd Maste	print "# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT"
28*2ccfa855SEd Maste	print "# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,"
29*2ccfa855SEd Maste	print "# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY"
30*2ccfa855SEd Maste	print "# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT"
31*2ccfa855SEd Maste	print "# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE"
32*2ccfa855SEd Maste	print "# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
33*2ccfa855SEd Maste	print "#"
34*2ccfa855SEd Maste	print "# SPDX-License-Identifier: BSD-2-Clause"
350afa8e06SEd Maste	print ""
36*2ccfa855SEd Maste	print "# This file is automatically generated, and should be used with udev 188"
37*2ccfa855SEd Maste	print "# or newer."
380afa8e06SEd Maste	print ""
390afa8e06SEd Maste	print "ACTION!=\"add|change\", GOTO=\"fido_end\""
400afa8e06SEd Maste
410afa8e06SEd Maste	next
420afa8e06SEd Maste}
430afa8e06SEd Maste
440afa8e06SEd Maste$1 == "vendor" {
450afa8e06SEd Maste	sub("0x", "", $3)
460afa8e06SEd Maste	vendors[$2, "id"] = $3
470afa8e06SEd Maste
480afa8e06SEd Maste	f = 4
490afa8e06SEd Maste	while (f <= NF) {
500afa8e06SEd Maste		vendors[$2, "name"] = vendors[$2, "name"] " " $f
510afa8e06SEd Maste		f++
520afa8e06SEd Maste	}
530afa8e06SEd Maste}
540afa8e06SEd Maste
550afa8e06SEd Maste$1 == "product" {
560afa8e06SEd Maste	sub("0x", "", $3)
570afa8e06SEd Maste	name = ""
580afa8e06SEd Maste
590afa8e06SEd Maste	f = 4
600afa8e06SEd Maste	while (f <= NF) {
610afa8e06SEd Maste		name = name " " $f
620afa8e06SEd Maste		f++
630afa8e06SEd Maste	}
640afa8e06SEd Maste
650afa8e06SEd Maste	line = "\n#" name " by" vendors[$2, "name"]"\n"
660afa8e06SEd Maste	line = line"KERNEL==\"hidraw*\""
670afa8e06SEd Maste	line = line", SUBSYSTEM==\"hidraw\""
680afa8e06SEd Maste	line = line", ATTRS{idVendor}==\""vendors[$2, "id"]"\""
690afa8e06SEd Maste	line = line", ATTRS{idProduct}==\""$3"\""
700afa8e06SEd Maste	line = line", TAG+=\"uaccess\""
710afa8e06SEd Maste	line = line", GROUP=\"plugdev\""
720afa8e06SEd Maste	line = line", MODE=\"0660\""
730afa8e06SEd Maste
740afa8e06SEd Maste	print line
750afa8e06SEd Maste}
760afa8e06SEd Maste
770afa8e06SEd MasteEND {
780afa8e06SEd Maste	print "\nLABEL=\"fido_end\""
790afa8e06SEd Maste}
80