vudc_server_example.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/bin/bash
  2. ################################################################################
  3. # This is free and unencumbered software released into the public domain.
  4. #
  5. # Anyone is free to copy, modify, publish, use, compile, sell, or
  6. # distribute this software, either in source code form or as a compiled
  7. # binary, for any purpose, commercial or non-commercial, and by any
  8. # means.
  9. #
  10. # In jurisdictions that recognize copyright laws, the author or authors
  11. # of this software dedicate any and all copyright interest in the
  12. # software to the public domain. We make this dedication for the benefit
  13. # of the public at large and to the detriment of our heirs and
  14. # successors. We intend this dedication to be an overt act of
  15. # relinquishment in perpetuity of all present and future rights to this
  16. # software under copyright law.
  17. #
  18. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  21. # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  22. # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  23. # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  24. # OTHER DEALINGS IN THE SOFTWARE.
  25. #
  26. # For more information, please refer to <http://unlicense.org/>
  27. ################################################################################
  28. ################################################################################
  29. # This is a sample script which shows how to use vUDC with ConfigFS gadgets
  30. ################################################################################
  31. # Stop script on error
  32. set -e
  33. ################################################################################
  34. # Create your USB gadget
  35. # You may use bare ConfigFS interface (as below)
  36. # or libusbgx or gt toool
  37. # Instead of ConfigFS gadgets you may use any of legacy gadgets.
  38. ################################################################################
  39. CONFIGFS_MOUNT_POINT="/sys/kernel/config"
  40. GADGET_NAME="g1"
  41. ID_VENDOR="0x1d6b"
  42. ID_PRODUCT="0x0104"
  43. cd ${CONFIGFS_MOUNT_POINT}/usb_gadget
  44. # Create a new USB gadget
  45. mkdir ${GADGET_NAME}
  46. cd ${GADGET_NAME}
  47. # This gadget contains one function - ACM (serial port over USB)
  48. FUNC_DIR="functions/acm.ser0"
  49. mkdir ${FUNC_DIR}
  50. # Just one configuration
  51. mkdir configs/c.1
  52. ln -s ${FUNC_DIR} configs/c.1
  53. # Set our gadget identity
  54. echo ${ID_VENDOR} > idVendor
  55. echo ${ID_PRODUCT} > idProduct
  56. ################################################################################
  57. # Load vudc-module if vudc is not available
  58. # You may change value of num param to get more than one vUDC instance
  59. ################################################################################
  60. [[ -d /sys/class/udc/usbip-vudc.0 ]] || modprobe usbip-vudc num=1
  61. ################################################################################
  62. # Bind gadget to our vUDC
  63. # By default we bind to first one but you may change this if you would like
  64. # to use more than one instance
  65. ################################################################################
  66. echo "usbip-vudc.0" > UDC
  67. ################################################################################
  68. # Let's now run our usbip daemon in a USB device mode
  69. ################################################################################
  70. usbipd --device &
  71. ################################################################################
  72. # Now your USB gadget is available using USB/IP protocol.
  73. # To prepare your client, you should ensure that usbip-vhci module is inside
  74. # your kernel. If it's not then you can load it:
  75. #
  76. # $ modprobe usbip-vhci
  77. #
  78. # To check availability of your gadget you may try to list devices exported
  79. # on a remote server:
  80. #
  81. # $ modprobe usbip-vhci
  82. # $ usbip list -r $SERVER_IP
  83. # Exportable USB devices
  84. # ======================
  85. # usbipd: info: request 0x8005(6): complete
  86. # - 127.0.0.1
  87. # usbip-vudc.0: Linux Foundation : unknown product (1d6b:0104)
  88. # : /sys/devices/platform/usbip-vudc.0
  89. # : (Defined at Interface level) (00/00/00)
  90. #
  91. # To attach this device to your client you may use:
  92. #
  93. # $ usbip attach -r $SERVER_IP -d usbip-vudc.0
  94. #
  95. ################################################################################