bluetooth 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin bluetooth
  4. #
  5. # Description : BlueZ Boot Script
  6. #
  7. # Authors : Armin K. <krejzi@email.com>
  8. #
  9. # Version : BLFS SVN
  10. #
  11. # Notes : Configurable through /etc/sysconfig/bluetooth
  12. # : Rewritten May 29, 2014 for bluez-5 by
  13. # Bruce Dubbs <bdubbs@linuxfromscratch.org>
  14. #
  15. ########################################################################
  16. ### BEGIN INIT INFO
  17. # Provides: bluetooth
  18. # Required-Start: $local_fs $syslog dbus
  19. # Required-Stop: $local_fs $syslog
  20. # Default-Start: 2 3 4 5
  21. # Default-Stop: 0 1 6
  22. # Short-Description: Starts bluetooth daemons
  23. # X-LFS-Provided-By: BLFS
  24. ### END INIT INFO
  25. . /lib/lsb/init-functions
  26. if [ -f "/etc/sysconfig/bluetooth" ]; then
  27. . /etc/sysconfig/bluetooth
  28. fi
  29. BLUETOOTH=/usr/bin/bluetoothd
  30. SDPTOOL=/usr/bin/sdptool
  31. HCIATTACH=/usr/bin/hciattach
  32. RFCOMM=/usr/bin/rfcomm
  33. UART_CONF=/etc/bluetooth/uart.conf
  34. RFCOMM_CONF=/etc/bluetooth/rfcomm.conf
  35. start_hci_dev()
  36. {
  37. for dev in ${ACTIVE_HCI_DEVICES_ON_BOOT} ; do
  38. hciconfig $dev up > /dev/null 2>&1
  39. done
  40. }
  41. run_sdptool()
  42. {
  43. # Declaring IFS local in this function, removes the need to
  44. # save/restore it
  45. local IFS option
  46. test -x $SDPTOOL || return 1
  47. IFS=";"
  48. for option in ${SDPTOOL_OPTIONS}; do
  49. IFS=" "
  50. $SDPTOOL $option > /dev/null 2>&1
  51. done
  52. }
  53. start_uarts()
  54. {
  55. [ -x $HCIATTACH ] && [ -f $UART_CONF ] || return
  56. grep -v '^[[:space:]]*(#|$)' $UART_CONF | while read i; do
  57. $HCIATTACH $i > /dev/null 2>&1
  58. done
  59. }
  60. stop_uarts()
  61. {
  62. [ -x $HCIATTACH ] || return
  63. killall $HCIATTACH > /dev/null 2>&1
  64. }
  65. start_rfcomm()
  66. {
  67. [ -x $RFCOMM ] && [ -f $RFCOMM_CONF ] || return
  68. $RFCOMM -f $RFCOMM_CONF bind all > /dev/null 2>&1 || :
  69. }
  70. stop_rfcomm()
  71. {
  72. [ -x $RFCOMM ] || return
  73. $RFCOMM unbind all > /dev/null 2>&1
  74. }
  75. case "${1}" in
  76. start)
  77. log_info_msg "Starting Bluetooth daemon bluetoothd..."
  78. pidlist=`pidofproc $BLUETOOTH`
  79. if [ "${?}" = "0" ]; then
  80. log_info_msg2 " Already running"
  81. log_success_msg2
  82. exit 0;
  83. fi
  84. # Start as background process and assume OK
  85. $BLUETOOTH &
  86. log_success_msg2
  87. start_hci_dev
  88. run_sdptool
  89. start_uarts
  90. start_rfcomm
  91. ;;
  92. stop)
  93. stop_rfcomm
  94. stop_uarts
  95. log_info_msg "Stopping Bluetooth daemon bluetoothd..."
  96. killproc $BLUETOOTH
  97. evaluate_retval
  98. ;;
  99. restart)
  100. ${0} stop
  101. sleep 1
  102. ${0} start
  103. ;;
  104. status)
  105. statusproc $BLUETOOTH
  106. ;;
  107. *)
  108. echo "Usage: ${0} {start|stop|restart|status}"
  109. exit 1
  110. ;;
  111. esac
  112. exit 0
  113. # End bluetooth