bluez-utils: Added startup script and configuration file. Set bluetooth identifier...
[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=60
5
6 append_bool() {
7 local section="$1"
8 local option="$2"
9 local value="$3"
10 local _val
11 config_get_bool _val "$section" "$option" '0'
12 [ "$_val" -gt 0 ] && append args "$3"
13 }
14
15 append_string() {
16 local section="$1"
17 local option="$2"
18 local value="$3"
19 local _val
20 config_get _val "$section" "$option"
21 [ -n "$_val" ] && append args "$3 $_val"
22 }
23
24 hcid_config() {
25 local cfg="$1"
26 args=""
27 append_bool "$cfg" nodaemon "-n"
28 append_string "$cfg" config "-f"
29 config_get_bool enabled "$cfg" "enabled" '1'
30 [ "$enabled" -gt 0 ] && /usr/sbin/hcid $args
31 }
32
33 sdpd_config() {
34 local cfg="$1"
35 args=""
36 append_bool "$cfg" nodaemon "-n"
37 append_bool "$cfg" something "-m"
38 config_get_bool enabled "$cfg" "enabled" '1'
39 [ "$enabled" -gt 0 ] && /usr/sbin/sdpd $args
40 }
41
42 rfcomm_config() {
43 local cfg="$1"
44 args=""
45 append_string "$cfg" config "-f"
46 config_get_bool enabled "$cfg" "enabled" '1'
47 [ "$enabled" -gt 0 ] && /usr/bin/rfcomm $args bind all
48 }
49
50 dund_config() {
51 local cfg="$1"
52 args=""
53 append_bool "$cfg" listen "--listen"
54 append_string "$cfg" connect "--connect"
55 append_string "$cfg" mrouter "--mrouter"
56 append_bool "$cfg" search "--search"
57 append_string "$cfg" channel "--channel"
58 append_string "$cfg" device "--device"
59 append_bool "$cfg" nosdp "--nosdp"
60 append_bool "$cfg" auth "--auth"
61 append_bool "$cfg" encrypt "--encrypt"
62 append_bool "$cfg" secure "--secure"
63 append_bool "$cfg" master "--master"
64 append_bool "$cfg" nodetach "--nodetach"
65 append_bool "$cfg" persist "--persist"
66 append_string "$cfg" pppd "--pppd"
67 append_bool "$cfg" msdun "--msdun"
68 append_bool "$cfg" activesync "--activesync"
69 append_bool "$cfg" cache "--cache"
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 sdpd_config sdpd
105 config_foreach rfcomm_config rfcomm
106 config_foreach dund_config dund
107 config_foreach pand_config pand
108 }
109
110 stop() {
111 killall dund
112 killall pand
113 /usr/bin/rfcomm release all
114 killall sdpd
115 killall hcid
116 }