bluetooth 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/bin/sh
  2. . /etc/rc.d/functions
  3. if [ -f "/etc/sysconfig/bluetooth" ]; then
  4. . /etc/sysconfig/bluetooth
  5. fi
  6. BLUETOOTH=/usr/bin/bluetoothd
  7. SDPTOOL=/usr/bin/sdptool
  8. HCIATTACH=/usr/bin/hciattach
  9. RFCOMM=/usr/bin/rfcomm
  10. UART_CONF=/etc/bluetooth/uart.conf
  11. RFCOMM_CONF=/etc/bluetooth/rfcomm.conf
  12. start_hci_dev()
  13. {
  14. for dev in ${ACTIVE_HCI_DEVICES_ON_BOOT} ; do
  15. hciconfig $dev up > /dev/null 2>&1
  16. done
  17. }
  18. run_sdptool()
  19. {
  20. # Declaring IFS local in this function, removes the need to
  21. # save/restore it
  22. local IFS option
  23. test -x $SDPTOOL || return 1
  24. IFS=";"
  25. for option in ${SDPTOOL_OPTIONS}; do
  26. IFS=" "
  27. $SDPTOOL $option > /dev/null 2>&1
  28. done
  29. }
  30. start_uarts()
  31. {
  32. [ -x $HCIATTACH ] && [ -f $UART_CONF ] || return
  33. grep -v '^[[:space:]]*(#|$)' $UART_CONF | while read i; do
  34. $HCIATTACH $i > /dev/null 2>&1
  35. done
  36. }
  37. stop_uarts()
  38. {
  39. [ -x $HCIATTACH ] || return
  40. killall $HCIATTACH > /dev/null 2>&1
  41. }
  42. start_rfcomm()
  43. {
  44. [ -x $RFCOMM ] && [ -f $RFCOMM_CONF ] || return
  45. $RFCOMM -f $RFCOMM_CONF bind all > /dev/null 2>&1 || :
  46. }
  47. stop_rfcomm()
  48. {
  49. [ -x $RFCOMM ] || return
  50. $RFCOMM unbind all > /dev/null 2>&1
  51. }
  52. case "${1}" in
  53. start)
  54. log_info_msg "Starting Bluetooth daemon bluetoothd..."
  55. pidlist=`pidofproc $BLUETOOTH`
  56. if [ "${?}" = "0" ]; then
  57. log_info_msg2 " Already running"
  58. log_success_msg2
  59. exit 0;
  60. fi
  61. # Start as background process and assume OK
  62. $BLUETOOTH &
  63. log_success_msg2
  64. start_hci_dev
  65. run_sdptool
  66. start_uarts
  67. start_rfcomm
  68. ;;
  69. stop)
  70. stop_rfcomm
  71. stop_uarts
  72. log_info_msg "Stopping Bluetooth daemon bluetoothd..."
  73. killproc $BLUETOOTH
  74. evaluate_retval
  75. ;;
  76. restart)
  77. ${0} stop
  78. sleep 1
  79. ${0} start
  80. ;;
  81. status)
  82. statusproc $BLUETOOTH
  83. ;;
  84. *)
  85. echo "Usage: ${0} {start|stop|restart|status}"
  86. exit 1
  87. ;;
  88. esac
  89. exit 0
  90. # End bluetooth