0b326280bfd694697cbbe04917fc690ba8665dd1
[10.03/packages.git] / utils / bluez-utils / files / 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         args=""
29         append_bool "$cfg" nodaemon "-n"
30         append_string "$cfg" config "-f"
31         config_get_bool enabled "$cfg" "enabled" '1'
32         [ "$enabled" -gt 0 ] && /usr/sbin/hcid $args
33 }
34
35 hciattach_config() {
36         local cfg="$1"
37         args=""
38         append_string "$cfg" initspeed "-s" "115200"
39         append_string "$cfg" tty " " "ttyS1"
40         append_string "$cfg" type " " "csr"
41         append_string "$cfg" speed " " "115200"
42         append_string "$cfg" flow " " "noflow"
43         config_get_bool enabled "$cfg" "enabled" '1'
44         [ "$enabled" -gt 0 ] && /usr/sbin/hciattach $args
45 }
46
47 rfcomm_config() {
48         local cfg="$1"
49         args=""
50         append_string "$cfg" config "-f"
51         config_get_bool enabled "$cfg" "enabled" '1'
52         [ "$enabled" -gt 0 ] && /usr/bin/rfcomm $args bind all
53 }
54
55 dund_config() {
56         local cfg="$1"
57         args=""
58         append_bool "$cfg" listen "--listen"
59         append_string "$cfg" connect "--connect"
60         append_string "$cfg" mrouter "--mrouter"
61         append_bool "$cfg" search "--search"
62         append_string "$cfg" channel "--channel"
63         append_string "$cfg" device "--device"
64         append_bool "$cfg" nosdp "--nosdp"
65         append_bool "$cfg" auth "--auth"
66         append_bool "$cfg" encrypt "--encrypt"
67         append_bool "$cfg" secure "--secure"
68         append_bool "$cfg" master "--master"
69         append_bool "$cfg" nodetach "--nodetach"
70         append_bool "$cfg" persist "--persist"
71         append_string "$cfg" pppd "--pppd"
72         append_bool "$cfg" msdun "--msdun"
73         append_bool "$cfg" activesync "--activesync"
74         append_bool "$cfg" cache "--cache"
75
76         append_string "$cfg" pppdopts ""
77         config_get ifn "$cfg" interface
78         if [ -n "$ifn" ]; then
79                 config_get unit "$cfg" unit
80                 [ -z "$unit" ] || append args "unit $unit ipparam $ifn linkname $ifn"
81         fi
82
83         config_get_bool enabled "$cfg" "enabled" '1'
84         [ "$enabled" -gt 0 ] && /usr/bin/dund $args
85 }
86
87 pand_config() {
88         local cfg="$1"
89         args=""
90         append_bool "$cfg" listen "--listen"
91         append_string "$cfg" connect "--connect"
92         append_bool "$cfg" autozap "--autozap"
93         append_bool "$cfg" search "--search"
94         append_string "$cfg" role "--role"
95         append_string "$cfg" service "--service"
96         append_string "$cfg" ethernet "--ethernet"
97         append_string "$cfg" device "--device"
98         append_bool "$cfg" nosdp "-D"
99         append_bool "$cfg" auth "-A"
100         append_bool "$cfg" encrypt "-E"
101         append_bool "$cfg" secure "-S"
102         append_bool "$cfg" master "-M"
103         append_bool "$cfg" nodetach "-n"
104         append_bool "$cfg" persist "--persist"
105         append_bool "$cfg" cache "--cache"
106         append_string "$cfg" pidfile "--pidfile"
107         config_get_bool enabled "$cfg" "enabled" '1'
108         [ "$enabled" -gt 0 ] && /usr/bin/pand $args
109 }
110
111 start() {
112         include /lib/network
113         scan_interfaces
114         config_load bluetooth
115
116         config_foreach hcid_config hcid
117         config_foreach hciattach_config hciattach
118         config_foreach rfcomm_config rfcomm
119         config_foreach dund_config dund
120         config_foreach pand_config pand
121 }
122
123 stop() {
124         killall dund
125         killall pand
126         /usr/bin/rfcomm release all
127         killall hciattach
128         killall hcid
129 }