aboutsummaryrefslogtreecommitdiffstats
path: root/fido_configfs.sh
blob: 25192616e9250d51e218746d37b5fdc0b85bb281 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
set -x

configdir=/sys/kernel/config/usb_gadget
dev=fido2
report_desc=`pwd`/fido

if [ `whoami` != "root" ]; then
    echo "Must be root to run this script"
    exit 1;
fi

if [ ! -f $report_desc ]; then
    echo "ERROR: $report_desc must exist"
    exit 1;
fi

modprobe libcomposite
# expect systemd to have mounted configfs
if [ ! -d $configdir ]; then
    echo "systemd failed to mount $configdir"
    exit 1;
fi

cd $configdir
mkdir $dev
cd $dev
##
# create bogus vendor and product
##
echo 0xabcd > idVendor
echo 0xabcd > idProduct
##
# Add identity strings
##
mkdir strings/0x409
echo jejb > strings/0x409/manufacturer
echo "fido2 ctap" > strings/0x409/product
echo 12345678 > strings/0x409/serialnumber

##
# Now make the Config
##
mkdir configs/c.1
# conventional power number
echo 120 > configs/c.1/MaxPower
mkdir configs/c.1/strings/0x409
# should set configuration but HID would override

##
# now set up the function
##
mkdir functions/hid.usb0
# we're a non boot hid
echo 0 > functions/hid.usb0/protocol
echo 0 > functions/hid.usb0/subclass
##
# All CTAP protocols require 64 byte reports
##
echo 64 > functions/hid.usb0/report_length
##
# Set the compiled report descriptor
##
$report_desc  functions/hid.usb0/report_desc || exit 1

##
# now link the config to the interface
##
ln -s functions/hid.usb0 configs/c.1/
modprobe dummy_hcd
echo "dummy_udc.0" > UDC