blob: 2e78b70f3adccf8bc5f16c13990d042ec8c2b03f [file] [log] [blame]
Inaky Perez-Gonzalez99d368b2008-09-17 16:34:04 +01001#! /bin/bash
2#
3
4set -e
5
6progname=$(basename $0)
7function help
8{
9 cat <<EOF
10Usage: $progname COMMAND DEVICEs [ARGS]
11
12Command for manipulating the pairing/authentication credentials of a
13Wireless USB device that supports wired-mode Cable-Based-Association.
14
15Works in conjunction with the wusb-cba.ko driver from http://linuxuwb.org.
16
17
18DEVICE
19
20 sysfs path to the device to authenticate; for example, both this
21 guys are the same:
22
23 /sys/devices/pci0000:00/0000:00:1d.7/usb1/1-4/1-4.4/1-4.4:1.1
24 /sys/bus/usb/drivers/wusb-cbaf/1-4.4:1.1
25
26COMMAND/ARGS are
27
28 start
29
30 Start a WUSB host controller (by setting up a CHID)
31
32 set-chid DEVICE HOST-CHID HOST-BANDGROUP HOST-NAME
33
34 Sets host information in the device; after this you can call the
35 get-cdid to see how does this device report itself to us.
36
37 get-cdid DEVICE
38
39 Get the device ID associated to the HOST-CHDI we sent with
40 'set-chid'. We might not know about it.
41
42 set-cc DEVICE
43
44 If we allow the device to connect, set a random new CDID and CK
45 (connection key). Device saves them for the next time it wants to
46 connect wireless. We save them for that next time also so we can
47 authenticate the device (when we see the CDID he uses to id
48 itself) and the CK to crypto talk to it.
49
50CHID is always 16 hex bytes in 'XX YY ZZ...' form
51BANDGROUP is almost always 0001
52
53Examples:
54
55 You can default most arguments to '' to get a sane value:
56
57 $ $progname set-chid '' '' '' "My host name"
58
59 A full sequence:
60
61 $ $progname set-chid '' '' '' "My host name"
62 $ $progname get-cdid ''
63 $ $progname set-cc ''
64
65EOF
66}
67
68
69# Defaults
70# FIXME: CHID should come from a database :), band group from the host
71host_CHID="00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff"
72host_band_group="0001"
Felipe Zimmerlef1fa0352008-09-17 16:34:42 +010073host_name=$(hostname)
Inaky Perez-Gonzalez99d368b2008-09-17 16:34:04 +010074
75devs="$(echo /sys/bus/usb/drivers/wusb-cbaf/[0-9]*)"
Felipe Zimmerlef1fa0352008-09-17 16:34:42 +010076hdevs="$(for h in /sys/class/uwb_rc/*/wusbhc; do readlink -f $h; done)"
Inaky Perez-Gonzalez99d368b2008-09-17 16:34:04 +010077
78result=0
79case $1 in
80 start)
81 for dev in ${2:-$hdevs}
82 do
Felipe Zimmerlef1fa0352008-09-17 16:34:42 +010083 uwb_rc=$(readlink -f $dev/uwb_rc)
84 if cat $uwb_rc/beacon | grep -q -- "-1"
Inaky Perez-Gonzalez99d368b2008-09-17 16:34:04 +010085 then
Felipe Zimmerlef1fa0352008-09-17 16:34:42 +010086 echo 13 0 > $uwb_rc/beacon
87 echo I: started beaconing on ch 13 on $(basename $uwb_rc) >&2
Inaky Perez-Gonzalez99d368b2008-09-17 16:34:04 +010088 fi
Felipe Zimmerlef1fa0352008-09-17 16:34:42 +010089 echo $host_CHID > $dev/wusb_chid
90 echo I: started host $(basename $dev) >&2
91 done
92 ;;
93 stop)
94 for dev in ${2:-$hdevs}
95 do
96 echo 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > $dev/wusb_chid
97 echo I: stopped host $(basename $dev) >&2
98 uwb_rc=$(readlink -f $dev/uwb_rc)
99 echo -1 | cat > $uwb_rc/beacon
100 echo I: stopped beaconing on $(basename $uwb_rc) >&2
Inaky Perez-Gonzalez99d368b2008-09-17 16:34:04 +0100101 done
102 ;;
103 set-chid)
104 shift
Felipe Zimmerlef1fa0352008-09-17 16:34:42 +0100105 for dev in ${2:-$devs}; do
106 echo "${4:-$host_name}" > $dev/wusb_host_name
107 echo "${3:-$host_band_group}" > $dev/wusb_host_band_groups
108 echo ${2:-$host_CHID} > $dev/wusb_chid
Inaky Perez-Gonzalez99d368b2008-09-17 16:34:04 +0100109 done
110 ;;
111 get-cdid)
112 for dev in ${2:-$devs}
113 do
114 cat $dev/wusb_cdid
115 done
116 ;;
117 set-cc)
Felipe Zimmerlef1fa0352008-09-17 16:34:42 +0100118 for dev in ${2:-$devs}; do
119 shift
120 CDID="$(head --bytes=16 /dev/urandom | od -tx1 -An)"
121 CK="$(head --bytes=16 /dev/urandom | od -tx1 -An)"
122 echo "$CDID" > $dev/wusb_cdid
123 echo "$CK" > $dev/wusb_ck
124
125 echo I: CC set >&2
126 echo "CHID: $(cat $dev/wusb_chid)"
127 echo "CDID:$CDID"
128 echo "CK: $CK"
Inaky Perez-Gonzalez99d368b2008-09-17 16:34:04 +0100129 done
130 ;;
131 help|h|--help|-h)
132 help
133 ;;
134 *)
135 echo "E: Unknown usage" 1>&2
136 help 1>&2
137 result=1
138esac
139exit $result