You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.4 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2007 OpenWrt.org
  3. #start after dbus (60)
  4. START=62
  5. append_bool() {
  6. local section="$1"
  7. local option="$2"
  8. local value="$3"
  9. local _val
  10. config_get_bool _val "$section" "$option" '0'
  11. [ $_val -gt 0 ] && append args "$3"
  12. }
  13. append_string() {
  14. local section="$1"
  15. local option="$2"
  16. local value="$3"
  17. local default="$4"
  18. local _val
  19. config_get _val "$section" "$option" "$default"
  20. [ -n "$_val" ] && append args "$3 $_val"
  21. }
  22. hcid_config() {
  23. local cfg="$1"
  24. config_get_bool enabled "$cfg" "enabled" '1'
  25. [ $enabled -gt 0 ] || return 1
  26. args=""
  27. append_bool "$cfg" nodaemon "-n"
  28. append_string "$cfg" config "-f"
  29. service_start /usr/sbin/hcid $args
  30. }
  31. hciattach_config() {
  32. local cfg="$1"
  33. config_get_bool enabled "$cfg" "enabled" '1'
  34. [ $enabled -gt 0 ] || return 1
  35. args=""
  36. append_string "$cfg" initspeed "-s" "115200"
  37. append_string "$cfg" tty " " "ttyS1"
  38. append_string "$cfg" type " " "csr"
  39. append_string "$cfg" speed " " "115200"
  40. append_string "$cfg" flow " " "noflow"
  41. service_start /usr/sbin/hciattach $args
  42. }
  43. rfcomm_config() {
  44. local cfg="$1"
  45. config_get_bool enabled "$cfg" "enabled" '1'
  46. [ $enabled -gt 0 ] || return 1
  47. args=""
  48. append_string "$cfg" config "-f"
  49. /usr/bin/rfcomm $args bind all
  50. }
  51. dund_config() {
  52. local cfg="$1"
  53. config_get_bool enabled "$cfg" "enabled" '1'
  54. [ $enabled -gt 0 ] || return 1
  55. args=""
  56. append_bool "$cfg" listen "--listen"
  57. append_string "$cfg" connect "--connect"
  58. append_string "$cfg" mrouter "--mrouter"
  59. append_bool "$cfg" search "--search"
  60. append_string "$cfg" channel "--channel"
  61. append_string "$cfg" device "--device"
  62. append_bool "$cfg" nosdp "--nosdp"
  63. append_bool "$cfg" auth "--auth"
  64. append_bool "$cfg" encrypt "--encrypt"
  65. append_bool "$cfg" secure "--secure"
  66. append_bool "$cfg" master "--master"
  67. append_bool "$cfg" nodetach "--nodetach"
  68. append_bool "$cfg" persist "--persist"
  69. append_string "$cfg" pppd "--pppd"
  70. append_bool "$cfg" msdun "--msdun"
  71. append_bool "$cfg" activesync "--activesync"
  72. append_bool "$cfg" cache "--cache"
  73. append_string "$cfg" pppdopts ""
  74. config_get ifn "$cfg" interface
  75. if [ -n "$ifn" ]; then
  76. config_get unit "$cfg" unit
  77. [ -z "$unit" ] || append args "unit $unit ipparam $ifn linkname $ifn"
  78. fi
  79. service_start /usr/bin/dund $args
  80. }
  81. pand_config() {
  82. local cfg="$1"
  83. config_get_bool enabled "$cfg" "enabled" '1'
  84. [ $enabled -gt 0 ] || return 1
  85. args=""
  86. append_bool "$cfg" listen "--listen"
  87. append_string "$cfg" connect "--connect"
  88. append_bool "$cfg" autozap "--autozap"
  89. append_bool "$cfg" search "--search"
  90. append_string "$cfg" role "--role"
  91. append_string "$cfg" service "--service"
  92. append_string "$cfg" ethernet "--ethernet"
  93. append_string "$cfg" device "--device"
  94. append_bool "$cfg" nosdp "-D"
  95. append_bool "$cfg" auth "-A"
  96. append_bool "$cfg" encrypt "-E"
  97. append_bool "$cfg" secure "-S"
  98. append_bool "$cfg" master "-M"
  99. append_bool "$cfg" nodetach "-n"
  100. append_bool "$cfg" persist "--persist"
  101. append_bool "$cfg" cache "--cache"
  102. append_string "$cfg" pidfile "--pidfile"
  103. service_start /usr/bin/pand $args
  104. }
  105. start() {
  106. config_load bluetooth
  107. config_foreach hcid_config hcid
  108. config_foreach hciattach_config hciattach
  109. config_foreach rfcomm_config rfcomm
  110. config_foreach dund_config dund
  111. config_foreach pand_config pand
  112. }
  113. stop() {
  114. service_stop /usr/bin/dund
  115. service_stop /usr/bin/pand
  116. /usr/bin/rfcomm release all
  117. service_stop /usr/sbin/hciattach
  118. service_stop /usr/sbin/hcid
  119. }