Module: OmfRc::Util::Wpa

Extended by:
ResourceProxyDSL::ClassMethods
Includes:
Cocaine, ResourceProxyDSL
Included in:
Iw
Defined in:
omf_rc/lib/omf_rc/util/wpa.rb

Overview

Manage WPA 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)

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) init_wpa_conf_pid

Initialise wpa related conf and pid location



20
21
22
23
# File 'omf_rc/lib/omf_rc/util/wpa.rb', line 20

work :init_wpa_conf_pid do |device|
  device.property.wpa_conf = Tempfile.new(["wpa.#{device.property.if_name}", ".conf"]).path
  device.property.wpa_pid = Tempfile.new(["wpa.#{device.property.if_name}", ".pid"]).path
end

- (Object) stop_wpa



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'omf_rc/lib/omf_rc/util/wpa.rb', line 39

work :stop_wpa do |device|
  begin
    File.open(device.property.wpa_pid,'r') do |f|
      info "Stopping wpa supplicant at PID: #{device.property.wpa_pid}"
      c1=CommandLine.new("kill", "-9 :pid")
      c1.run({ :pid => f.read.chomp })
    end

 c2=CommandLine.new("rm", "-f :wpa_pid :wpa_conf")
    c2.run({         :wpa_pid => device.property.wpa_pid,
                    :wpa_conf => device.property.wpa_conf  })
  rescue => e
    logger.warn "Failed to clean wpa supplicant and its related files '#{device.property.wpa_pid}' and '#{device.property.wpa_conf}'!"
    logger.warn e.message
  end
end

- (Object) wpasup



26
27
28
29
30
31
32
33
34
35
36
# File 'omf_rc/lib/omf_rc/util/wpa.rb', line 26

work :wpasup do |device|
  device.init_wpa_conf_pid

  File.open(device.property.wpa_conf, "w") do |f|
    f << "network={\n  ssid=\"#{device.property.essid}\"\n  scan_ssid=1\n  key_mgmt=NONE\n}"
  end
  c=CommandLine.new("wpa_supplicant", "-B -P :wpa_pid -i:dev -c:wpa_conf")
  c.run({         :dev => device.property.if_name,
                  :wpa_conf => device.property.wpa_conf,
                  :wpa_pid => device.property.wpa_pid  })
end