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