wusb-cbaf 3.6 KB

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