wusb-cbaf 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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-CHID 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. echo $host_CHID > $dev/wusb_chid
  56. echo I: started host $(basename $dev) >&2
  57. done
  58. ;;
  59. stop)
  60. for dev in ${2:-$hdevs}
  61. do
  62. echo 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > $dev/wusb_chid
  63. echo I: stopped host $(basename $dev) >&2
  64. done
  65. ;;
  66. set-chid)
  67. shift
  68. for dev in ${2:-$devs}; do
  69. echo "${4:-$host_name}" > $dev/wusb_host_name
  70. echo "${3:-$host_band_group}" > $dev/wusb_host_band_groups
  71. echo ${2:-$host_CHID} > $dev/wusb_chid
  72. done
  73. ;;
  74. get-cdid)
  75. for dev in ${2:-$devs}
  76. do
  77. cat $dev/wusb_cdid
  78. done
  79. ;;
  80. set-cc)
  81. for dev in ${2:-$devs}; do
  82. shift
  83. CDID="$(head --bytes=16 /dev/urandom | od -tx1 -An)"
  84. CK="$(head --bytes=16 /dev/urandom | od -tx1 -An)"
  85. echo "$CDID" > $dev/wusb_cdid
  86. echo "$CK" > $dev/wusb_ck
  87. echo I: CC set >&2
  88. echo "CHID: $(cat $dev/wusb_chid)"
  89. echo "CDID:$CDID"
  90. echo "CK: $CK"
  91. done
  92. ;;
  93. help|h|--help|-h)
  94. help
  95. ;;
  96. *)
  97. echo "E: Unknown usage" 1>&2
  98. help 1>&2
  99. result=1
  100. esac
  101. exit $result