class Bandshell::WirelessConnection

802.11* unencrypted wireless connections. These are managed by wpa_supplicant on Debian so we need to create its configuration file and link it to the interfaces file.

Attributes

interface_name[RW]
ssid[RW]

Public Class Methods

description() click to toggle source
# File lib/bandshell/netconfig.rb, line 298
def self.description
  "Wireless connection (no encryption)"
end
interfaces() click to toggle source
# File lib/bandshell/netconfig.rb, line 302
def self.interfaces
  # Again this is not guaranteed to be a catch all.
  devices = Dir.glob('/sys/class/net/{ath,wlan}*')
  devices.map { |d| Interface.new(File.basename(d)) }
end
new(args={}) click to toggle source
# File lib/bandshell/netconfig.rb, line 243
def initialize(args={})
  @ssid = args['ssid'] || ''
  @interface_name = args['interface_name'] if args['interface_name']
  @wpa_config_file = '/tmp/wpa_supplicant.concerto.conf'
end

Public Instance Methods

args() click to toggle source
# File lib/bandshell/netconfig.rb, line 291
def args
  {
    'interface_name' => @interface_name,
    'ssid' => @ssid
  }
end
config_interface_name() click to toggle source
# File lib/bandshell/netconfig.rb, line 251
def config_interface_name
  # If the user has requested a specific interface, use it.
  # Otherwise, just pick the first wlan interface, assuming
  # it works and all wlan interfaces have approximately equal
  # reception. When this assumption is wrong the user must force.
  if @interface_name && @interface_name != ''
    @interface_name
  else
    self.class.interfaces[0].name
  end
end
interfaces_lines() click to toggle source
# File lib/bandshell/netconfig.rb, line 286
def interfaces_lines
  # This links the wpa config to the interfaces file.
  ["wpa-conf #{@wpa_config_file}"]
end
safe_assign() click to toggle source
# File lib/bandshell/netconfig.rb, line 269
def safe_assign
  [ :ssid, :interface_name ]
end
validate() click to toggle source
# File lib/bandshell/netconfig.rb, line 263
def validate
  if @ssid == ''
    fail "Need SSID for wireless connection"
  end
end
write_configs() click to toggle source
# File lib/bandshell/netconfig.rb, line 273
def write_configs
  # Write a wpa_supplicant.conf file for an unsecured network.
  File.open(@wpa_config_file, 'w') do |wpaconf|
    # long lines, sorry!
    wpaconf.puts "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev"
    wpaconf.puts "network={"
    wpaconf.puts "ssid=\"#{@ssid}\""
    wpaconf.puts "scan_ssid=1"
    wpaconf.puts "key_mgmt=NONE"
    wpaconf.puts "}"
  end
end