wusb-cbaf 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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="Linux-WUSB"
  48. devs="$(echo /sys/bus/usb/drivers/wusb-cbaf/[0-9]*)"
  49. hdevs="$(find /sys -name wusb_chid -printf "%h\n")"
  50. result=0
  51. case $1 in
  52. start)
  53. for dev in ${2:-$hdevs}
  54. do
  55. uwb_rc=$(find $(dirname $(dirname $dev)) -iname uwb_rc:uwb*)
  56. if cat $uwb_rc/uwb_rc/beacon | grep -q "channel: -1"
  57. then
  58. echo 13 0 | cat > $uwb_rc/uwb_rc/beacon
  59. echo I: started beaconing on ch 13 in host $(basename $uwb_rc)
  60. fi
  61. echo $host_CHID | cat > $dev/wusb_chid
  62. echo I: started host $(basename $dev)
  63. done
  64. ;;
  65. set-chid)
  66. shift
  67. for dev in ${2:-$devs}
  68. do
  69. echo "${2:-$host_CHID}" "${3:-$host_band_group}" "${4:-$host_name}" \
  70. | cat > $dev/wusb_host_info
  71. done
  72. ;;
  73. get-cdid)
  74. for dev in ${2:-$devs}
  75. do
  76. cat $dev/wusb_cdid
  77. done
  78. ;;
  79. set-cc)
  80. for dev in ${2:-$devs}
  81. do
  82. shift
  83. CDID="$(head --bytes=16 /dev/urandom | od -tx1 -An)"
  84. CK="$(head --bytes=16 /dev/urandom | od -tx1 -An)"
  85. cat > $dev/wusb_cc <<EOF
  86. CDID:$CDID
  87. CK:$CK
  88. EOF
  89. cat <<EOF
  90. I: CC set
  91. CHID: $host_CHID
  92. CDID:$CDID
  93. CK: $CK
  94. EOF
  95. done
  96. ;;
  97. help|h|--help|-h)
  98. help
  99. ;;
  100. *)
  101. echo "E: Unknown usage" 1>&2
  102. help 1>&2
  103. result=1
  104. esac
  105. exit $result