Module: OmfRc::Util::Hostapd
- Extended by:
- ResourceProxyDSL::ClassMethods
- Includes:
- Cocaine, ResourceProxyDSL
- Included in:
- Iw
- Defined in:
- omf_rc/lib/omf_rc/util/hostapd.rb
Overview
Manage Hostapd instances
Constant Summary
Constant Summary
Constants included from ResourceProxyDSL
ResourceProxyDSL::DEFAULT_PROP_ACCESS, ResourceProxyDSL::PROXY_DIR, ResourceProxyDSL::UTIL_DIR
OMF RC Work Helper Methods (collapse)
-
- (Object) hostapd
Set up and run a hostapd instance.
-
- (Object) init_ap_conf_pid
Initialise access point conf and pid location.
- - (Object) stop_hostapd
Methods included from ResourceProxyDSL::ClassMethods
call_hook, configure, configure_all, extend_configure, extend_hook, extend_request, extend_work, hook, namespace, property, register_proxy, request, utility, work
Methods included from ResourceProxyDSL
#call_hook, #hook_defined?, included
Instance Method Details
- (Object) hostapd
Set up and run a hostapd instance
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'omf_rc/lib/omf_rc/util/hostapd.rb', line 28 work :hostapd do |device| device.init_ap_conf_pid File.open(device.property.ap_conf, "w") do |f| f << "driver=nl80211\ninterface=#{device.property.if_name}\nssid=#{device.property.essid}\nchannel=#{device.property.channel}\n" f << "hw_mode=#{device.property.hw_mode}\n" if %w(a b g).include? device.property.hw_mode if device.property.hw_mode == 'n' if device.property.channel.to_i < 15 f << "hw_mode=g\n" else device.property.channel.to_i > 15 f << "hw_mode=a\n" end f << "wmm_enabled=1\nieee80211n=1\nht_capab=[HT20-]\n" end end c=CommandLine.new("hostapd", "-B -P :ap_pid :ap_conf") c.run({ :ap_pid => device.property.ap_pid, :ap_conf => device.property.ap_conf }) end |
- (Object) init_ap_conf_pid
Initialise access point conf and pid location
20 21 22 23 |
# File 'omf_rc/lib/omf_rc/util/hostapd.rb', line 20 work :init_ap_conf_pid do |device| device.property.ap_conf = Tempfile.new(["hostapd.#{device.property.if_name}", ".conf"]).path device.property.ap_pid = Tempfile.new(["hostapd.#{device.property.if_name}", ".pid"]).path end |
- (Object) stop_hostapd
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'omf_rc/lib/omf_rc/util/hostapd.rb', line 50 work :stop_hostapd do |device| begin File.open(device.property.ap_pid,'r') do |f| logger.debug "Stopping hostapd process at PID: #{device.property.ap_pid}" c1=CommandLine.new("kill", "-9 :pid") c1.run({ :pid => f.read.chomp }) end c2=CommandLine.new("rm", "-f :ap_pid :ap_conf") c2.run({ :ap_pid => device.property.ap_pid, :ap_conf => device.property.ap_conf}) rescue => e logger.warn "Failed to clean hostapd and its related files '#{device.property.ap_pid}' and '#{device.property.ap_conf}'!" logger.warn e. end end |