1a3227a693514a3f54d90a71d0b972479816254b
[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 sdpd_config() {
35 local cfg="$1"
36 args=""
37 append_bool "$cfg" nodaemon "-n"
38 append_bool "$cfg" something "-m"
39 config_get_bool enabled "$cfg" "enabled" '1'
40 [ "$enabled" -gt 0 ] && /usr/sbin/sdpd $args
41 }
42
43 rfcomm_config() {
44 local cfg="$1"
45 args=""
46 append_string "$cfg" config "-f"
47 config_get_bool enabled "$cfg" "enabled" '1'
48 [ "$enabled" -gt 0 ] && /usr/bin/rfcomm $args bind all
49 }
50
51 dund_config() {
52 local cfg="$1"
53 args=""
54 append_bool "$cfg" listen "--listen"
55 append_string "$cfg" connect "--connect"
56 append_string "$cfg" mrouter "--mrouter"
57 append_bool "$cfg" search "--search"
58 append_string "$cfg" channel "--channel"
59 append_string "$cfg" device "--device"
60 append_bool "$cfg" nosdp "--nosdp"
61 append_bool "$cfg" auth "--auth"
62 append_bool "$cfg" encrypt "--encrypt"
63 append_bool "$cfg" secure "--secure"
64 append_bool "$cfg" master "--master"
65 append_bool "$cfg" nodetach "--nodetach"
66 append_bool "$cfg" persist "--persist"
67 append_string "$cfg" pppd "--pppd"
68 append_bool "$cfg" msdun "--msdun"
69 append_bool "$cfg" activesync "--activesync"
70 append_bool "$cfg" cache "--cache"
71
72 append_string "$cfg" pppdopts ""
73 config_get_bool enabled "$cfg" "enabled" '1'
74 [ "$enabled" -gt 0 ] && /usr/bin/dund $args
75 }
76
77 pand_config() {
78 local cfg="$1"
79 args=""
80 append_bool "$cfg" listen "--listen"
81 append_string "$cfg" connect "--connect"
82 append_bool "$cfg" autozap "--autozap"
83 append_bool "$cfg" search "--search"
84 append_string "$cfg" role "--role"
85 append_string "$cfg" service "--service"
86 append_string "$cfg" ethernet "--ethernet"
87 append_string "$cfg" device "--device"
88 append_bool "$cfg" nosdp "-D"
89 append_bool "$cfg" auth "-A"
90 append_bool "$cfg" encrypt "-E"
91 append_bool "$cfg" secure "-S"
92 append_bool "$cfg" master "-M"
93 append_bool "$cfg" nodetach "-n"
94 append_bool "$cfg" persist "--persist"
95 append_bool "$cfg" cache "--cache"
96 append_string "$cfg" pidfile "--pidfile"
97 config_get_bool enabled "$cfg" "enabled" '1'
98 [ "$enabled" -gt 0 ] && /usr/bin/pand $args
99 }
100
101 start() {
102 include /lib/network
103 scan_interfaces
104 config_load bluetooth
105
106 config_foreach hcid_config hcid
107 config_foreach sdpd_config sdpd
108 config_foreach rfcomm_config rfcomm
109 config_foreach dund_config dund
110 config_foreach pand_config pand
111 }
112
113 stop() {
114 killall dund
115 killall pand
116 /usr/bin/rfcomm release all
117 killall sdpd
118 killall hcid
119 }