4 PHY_DIR
="/sys/class/ieee80211"
9 echo "${PHY_DIR}/${phy}"
12 function phy_exists
() {
15 [ -d "$(phy_dir ${phy})" ]
20 for phy
in $
(phy_dir
)/*; do
21 phy
=$
(basename ${phy})
31 if listmatch
${info} $
(phy_list
); then
33 elif device_exists
${info}; then
34 info
=$
(device_get_address
${info})
37 if [ -z "${phy}" ] && mac_is_valid
${info}; then
39 for i
in $
(phy_list
); do
40 if [ "${info}" = "$(phy_get_address ${i})" ]; then
47 if [ -z "${phy}" ]; then
55 function phy_get_address
() {
60 cat $
(phy_dir
${phy})/macaddress
2>/dev
/null
63 function wireless_create
() {
65 local phy
=$
(phy_get
${2})
73 isset mac || mac
=$
(mac_generate
)
75 assert phy_exists
${phy}
76 assert isoneof
type managed __ap
78 iw phy
${phy} interface add ${device} type ${type}
80 if device_exists
${device}; then
81 device_set_address
${device} ${mac}
84 device_set_up
${device}
87 function wireless_remove
() {
90 assert device_exists
${device}
92 device_set_down
${device}
97 function wireless_set_channel
() {
102 assert device_exists
${device}
105 iw dev
${device} set channel
${channel} $@
108 function hostapd_init
() {
109 mkdir
-p $
(hostapd_config_dir
)
112 init_register hostapd_init
114 function hostapd_config_dir
() {
117 echo "${RUN_DIR}/hostapd/${device}"
120 function hostapd_config_write
() {
124 assert device_exists
${device}
132 while [ $# -gt 0 ]; do
135 broadcast_ssid
=${1#--broadcast-ssid=}
138 channel
=${1#--channel=}
141 country_code
=${1#--country-code=}
150 warning_log
"Ignoring unknown argument '${1}'."
156 assert isset broadcast_ssid
157 assert isbool broadcast_ssid
160 assert isinteger channel
162 assert isset country_code
166 local ignore_broadcast_ssid
167 if enabled broadcast_ssid
; then
168 ignore_broadcast_ssid
="0"
170 ignore_broadcast_ssid
="1"
174 ### Hostapd configuration for ${device}
176 # Interface configuration
180 # Wireless configuration
182 country_code=${country_code}
184 ignore_broadcast_ssid=${ignore_broadcast_ssid}
189 logger_syslog_level=2
191 logger_stdout_level=2
194 dump_file=$(hostapd_config_dir ${device}/dump
196 ctrl_interface=/var/run/hostapd
197 ctrl_interface_group=0
203 function hostapd_start
() {
209 local config_dir
=$
(hostapd_config_dir
${device})
210 mkdir
-p ${config_dir}
212 local config_file
=${config_dir}/config
213 hostapd_config_write
${device} $@
> ${config_file}
215 hostapd
-dd -B -P ${config_dir}/pid
${config_file}
220 log DEBUG
"Hostapd was successfully started for '${device}'."
224 error_log
"Could not start hostapd properly for '${device}'."
226 error_log
"Configuration file dump:"
230 done < ${config_file}
237 function hostapd_stop
() {
242 local pid
=$
(hostapd_get_pid
${device})
247 warning_log
"Could not find pid file for hostapd process running for ${device}."
250 rm -rf $
(hostapd_config_dir
${device})
253 function hostapd_get_pid
() {
258 local pid_file
="$(hostapd_config_dir ${device})/pid"
260 [ -e "${pid_file}" ] ||
return ${EXIT_ERROR}
262 cat ${pid_file} 2>/dev
/null
266 function hostapd_is_running
() {
271 local pid
=$
(hostapd_get_pid
${device})
273 if isset pid
&& [ -d "/proc/${pid}" ]; then