pthsem: moved to github
[openwrt.org/packages.git] / utils / bluez-utils.init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/sh /etc/rc.common
# Copyright (C) 2007 OpenWrt.org

#start after dbus (60)
START=62

append_bool() {
	local section="$1"
	local option="$2"
	local value="$3"
	local _val
	config_get_bool _val "$section" "$option" '0'
	[ $_val -gt 0 ] && append args "$3"
}

append_string() {
	local section="$1"
	local option="$2"
	local value="$3"
	local default="$4"
	local _val
	config_get _val "$section" "$option" "$default"
	[ -n "$_val" ] && append args "$3 $_val"
}

hcid_config() {
	local cfg="$1"
	config_get_bool enabled "$cfg" "enabled" '1'
	[ $enabled -gt 0 ] || return 1
	args=""
	append_bool "$cfg" nodaemon "-n"
	append_string "$cfg" config "-f"
	service_start /usr/sbin/hcid $args
}

hciattach_config() {
	local cfg="$1"
	config_get_bool enabled "$cfg" "enabled" '1'
	[ $enabled -gt 0 ] || return 1
	args=""
	append_string "$cfg" initspeed "-s" "115200"
	append_string "$cfg" tty " " "ttyS1"
	append_string "$cfg" type " " "csr"
	append_string "$cfg" speed " " "115200"
	append_string "$cfg" flow " " "noflow"
	service_start /usr/sbin/hciattach $args
}

rfcomm_config() {
	local cfg="$1"
	config_get_bool enabled "$cfg" "enabled" '1'
	[ $enabled -gt 0 ] || return 1
	args=""
	append_string "$cfg" config "-f"
	/usr/bin/rfcomm $args bind all
}

dund_config() {
	local cfg="$1"
	config_get_bool enabled "$cfg" "enabled" '1'
	[ $enabled -gt 0 ] || return 1
	args=""
	append_bool "$cfg" listen "--listen"
	append_string "$cfg" connect "--connect"
	append_string "$cfg" mrouter "--mrouter"
	append_bool "$cfg" search "--search"
	append_string "$cfg" channel "--channel"
	append_string "$cfg" device "--device"
	append_bool "$cfg" nosdp "--nosdp"
	append_bool "$cfg" auth "--auth"
	append_bool "$cfg" encrypt "--encrypt"
	append_bool "$cfg" secure "--secure"
	append_bool "$cfg" master "--master"
	append_bool "$cfg" nodetach "--nodetach"
	append_bool "$cfg" persist "--persist"
	append_string "$cfg" pppd "--pppd"
	append_bool "$cfg" msdun "--msdun"
	append_bool "$cfg" activesync "--activesync"
	append_bool "$cfg" cache "--cache"

	append_string "$cfg" pppdopts ""
	config_get ifn "$cfg" interface
	if [ -n "$ifn" ]; then
		config_get unit "$cfg" unit
		[ -z "$unit" ] || append args "unit $unit ipparam $ifn linkname $ifn"
	fi

	service_start /usr/bin/dund $args
}

pand_config() {
	local cfg="$1"
	config_get_bool enabled "$cfg" "enabled" '1'
	[ $enabled -gt 0 ] || return 1
	args=""
	append_bool "$cfg" listen "--listen"
	append_string "$cfg" connect "--connect"
	append_bool "$cfg" autozap "--autozap"
	append_bool "$cfg" search "--search"
	append_string "$cfg" role "--role"
	append_string "$cfg" service "--service"
	append_string "$cfg" ethernet "--ethernet"
	append_string "$cfg" device "--device"
	append_bool "$cfg" nosdp "-D"
	append_bool "$cfg" auth "-A"
	append_bool "$cfg" encrypt "-E"
	append_bool "$cfg" secure "-S"
	append_bool "$cfg" master "-M"
	append_bool "$cfg" nodetach "-n"
	append_bool "$cfg" persist "--persist"
	append_bool "$cfg" cache "--cache"
	append_string "$cfg" pidfile "--pidfile"
	service_start /usr/bin/pand $args
}

start() {
	config_load bluetooth
	config_foreach hcid_config hcid
	config_foreach hciattach_config hciattach
	config_foreach rfcomm_config rfcomm
	config_foreach dund_config dund
	config_foreach pand_config pand
}

stop() {
	service_stop /usr/bin/dund
	service_stop /usr/bin/pand
	/usr/bin/rfcomm release all
	service_stop /usr/sbin/hciattach
	service_stop /usr/sbin/hcid
}

comments