allow dund to grab ppp options gathered from the network scripts
[openwrt/svn-archive/archive.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 _val
21 config_get _val "$section" "$option"
22 [ -n "$_val" ] && append args "$3 $_val"
23 }
24
25 hcid_config() {
26 local cfg="$1"
27 args=""
28 append_bool "$cfg" nodaemon "-n"
29 append_string "$cfg" config "-f"
30 config_get_bool enabled "$cfg" "enabled" '1'
31 [ "$enabled" -gt 0 ] && /usr/sbin/hcid $args
32 }
33
34 rfcomm_config() {
35 local cfg="$1"
36 args=""
37 append_string "$cfg" config "-f"
38 config_get_bool enabled "$cfg" "enabled" '1'
39 [ "$enabled" -gt 0 ] && /usr/bin/rfcomm $args bind all
40 }
41
42 dund_config() {
43 local cfg="$1"
44 args=""
45 append_bool "$cfg" listen "--listen"
46 append_string "$cfg" connect "--connect"
47 append_string "$cfg" mrouter "--mrouter"
48 append_bool "$cfg" search "--search"
49 append_string "$cfg" channel "--channel"
50 append_string "$cfg" device "--device"
51 append_bool "$cfg" nosdp "--nosdp"
52 append_bool "$cfg" auth "--auth"
53 append_bool "$cfg" encrypt "--encrypt"
54 append_bool "$cfg" secure "--secure"
55 append_bool "$cfg" master "--master"
56 append_bool "$cfg" nodetach "--nodetach"
57 append_bool "$cfg" persist "--persist"
58 append_string "$cfg" pppd "--pppd"
59 append_bool "$cfg" msdun "--msdun"
60 append_bool "$cfg" activesync "--activesync"
61 append_bool "$cfg" cache "--cache"
62
63 append_string "$cfg" pppdopts ""
64 config_get ifn "$cfg" interface
65 if [ -n "$ifn" ]; then
66 config_get unit "$ifn" unit
67 [ -z "$unit" ] || append args "unit $unit ipparam $ifn linkname $ifn"
68 fi
69
70 config_get_bool enabled "$cfg" "enabled" '1'
71 [ "$enabled" -gt 0 ] && /usr/bin/dund $args
72 }
73
74 pand_config() {
75 local cfg="$1"
76 args=""
77 append_bool "$cfg" listen "--listen"
78 append_string "$cfg" connect "--connect"
79 append_bool "$cfg" autozap "--autozap"
80 append_bool "$cfg" search "--search"
81 append_string "$cfg" role "--role"
82 append_string "$cfg" service "--service"
83 append_string "$cfg" ethernet "--ethernet"
84 append_string "$cfg" device "--device"
85 append_bool "$cfg" nosdp "-D"
86 append_bool "$cfg" auth "-A"
87 append_bool "$cfg" encrypt "-E"
88 append_bool "$cfg" secure "-S"
89 append_bool "$cfg" master "-M"
90 append_bool "$cfg" nodetach "-n"
91 append_bool "$cfg" persist "--persist"
92 append_bool "$cfg" cache "--cache"
93 append_string "$cfg" pidfile "--pidfile"
94 config_get_bool enabled "$cfg" "enabled" '1'
95 [ "$enabled" -gt 0 ] && /usr/bin/pand $args
96 }
97
98 start() {
99 include /lib/network
100 scan_interfaces
101 config_load bluetooth
102
103 config_foreach hcid_config hcid
104 config_foreach rfcomm_config rfcomm
105 config_foreach dund_config dund
106 config_foreach pand_config pand
107 }
108
109 stop() {
110 killall dund
111 killall pand
112 /usr/bin/rfcomm release all
113 killall hcid
114 }