access point connection
This commit is contained in:
parent
e101913e5d
commit
553cd0a986
@ -19,6 +19,7 @@ end
|
||||
|
||||
|
||||
class WirelessAPSetup
|
||||
property ifname : String
|
||||
property ssid : String
|
||||
|
||||
# This is a list of parameters that should be unique to each AP
|
||||
@ -44,7 +45,7 @@ class WirelessAPSetup
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(@ssid, @security)
|
||||
def initialize(@ifname, @ssid, @security)
|
||||
@main_ip_v4 = NotSetup.new
|
||||
@main_ip_v6 = NotSetup.new
|
||||
@aliasses_v4 = Array(IPAddress).new
|
||||
@ -95,6 +96,8 @@ class WirelessAPSetup
|
||||
def execute
|
||||
puts "TODO: wireless configuration"
|
||||
|
||||
NetworkCommands.wireless_access_point_connection ifname, ssid
|
||||
|
||||
# DNS configuration
|
||||
dns.execute
|
||||
end
|
||||
@ -111,7 +114,6 @@ class InterfaceConfiguration
|
||||
property up : Bool
|
||||
property description : String?
|
||||
property mtu : Int32?
|
||||
property wireless : Bool
|
||||
property main_ip_v4 : IPAddress | DHCP | NotSetup
|
||||
property main_ip_v6 : IPAddress | Autoconfiguration | DHCP | NotSetup
|
||||
property aliasses_v4 : Array(IPAddress)
|
||||
@ -123,7 +125,7 @@ class InterfaceConfiguration
|
||||
@description,
|
||||
@mtu,
|
||||
@main_ip_v4, @main_ip_v6, aliasses,
|
||||
@wireless, @wireless_networks,
|
||||
@wireless_networks,
|
||||
@dns
|
||||
)
|
||||
|
||||
@ -258,7 +260,7 @@ class InterfaceConfiguration
|
||||
end
|
||||
|
||||
# TODO: treat differently wireless and non-wireless interfaces
|
||||
if @wireless
|
||||
if @wireless_networks.empty?
|
||||
puts "interface #{name} is wireless: connection to the access point"
|
||||
store_access_point_keys
|
||||
access_point_connection
|
||||
|
@ -89,13 +89,22 @@ class NetworkCommands
|
||||
end
|
||||
end
|
||||
|
||||
def self.connection(ssid : String, ifname : String)
|
||||
def self.connection(ifname : String, ssid : String)
|
||||
dirpath = "#{Context.root}/#{Context.keydir}"
|
||||
unless Do.run("wpa_supplicant",
|
||||
[ "-B", "-c", "#{dirpath}/#{ssid}.conf", "-i", ifname ]).success?
|
||||
raise "(wpa_supplicant) cannot connect to the wireless AP #{ssid} via the interface #{ifname}"
|
||||
end
|
||||
end
|
||||
|
||||
def self.disconnection(ifname : String, ssid : String)
|
||||
# TODO: this kills every running wpa_supplicant application
|
||||
# not only the instance for ifname
|
||||
dirpath = "#{Context.root}/#{Context.keydir}"
|
||||
unless Do.run("pkill", [ "wpa_supplicant" ]).success?
|
||||
raise "(wpa_supplicant) cannot stop the wpa_supplicant daemon"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class UDHCPCCommand
|
||||
@ -320,18 +329,16 @@ class NetworkCommands
|
||||
end
|
||||
end
|
||||
|
||||
def self.wireless_connect_wpa_psk(ifname : String, ssid : String, passwd : String)
|
||||
cmd = @@cmd_wireless_configuration
|
||||
case cmd
|
||||
when NotSetup.class
|
||||
puts "no wireless configuration program: cannot connect to ssid #{ssid}"
|
||||
else
|
||||
cmd.list_ssid ifname
|
||||
end
|
||||
end
|
||||
|
||||
def self.store_access_point_keys(ssid : String, security : WirelessAPSetup::WPA)
|
||||
# TODO: only one way to do it
|
||||
NetworkCommands::WPASupplicant.passphrase ssid, security.key
|
||||
end
|
||||
|
||||
def self.wireless_access_point_connection(ifname : String, ssid : String)
|
||||
NetworkCommands::WPASupplicant.connection ifname, ssid
|
||||
end
|
||||
|
||||
def self.wireless_access_point_disconnection(ifname : String, ssid : String)
|
||||
NetworkCommands::WPASupplicant.disconnection ifname, ssid
|
||||
end
|
||||
end
|
||||
|
@ -8,12 +8,10 @@ class NetworkConfigurationParser
|
||||
raise "The interface name is not known from the filename: '#{file_name}'"
|
||||
end
|
||||
|
||||
wireless = false
|
||||
wireless = true unless /^wl[0-9]+$/.match(ifname)
|
||||
self.parse(ifname.not_nil!, content, wireless)
|
||||
self.parse(ifname.not_nil!, content)
|
||||
end
|
||||
|
||||
def self.parse (ifname : String, data : String, wireless = false) : InterfaceConfiguration
|
||||
def self.parse (ifname : String, data : String) : InterfaceConfiguration
|
||||
up = false
|
||||
description = nil
|
||||
mtu = nil
|
||||
@ -77,7 +75,7 @@ class NetworkConfigurationParser
|
||||
next
|
||||
end
|
||||
|
||||
new_ap = WirelessAPSetup.new ssid, WirelessAPSetup::WPA.new(wpakeystr)
|
||||
new_ap = WirelessAPSetup.new ifname, ssid, WirelessAPSetup::WPA.new(wpakeystr)
|
||||
wireless_networks[ssid] = new_ap
|
||||
|
||||
when /^network (?<ssid>[^ \t]+) inet6 autoconf/
|
||||
@ -180,7 +178,7 @@ class NetworkConfigurationParser
|
||||
mtu,
|
||||
main_ip_v4, main_ip_v6,
|
||||
aliasses,
|
||||
wireless, wireless_networks,
|
||||
wireless_networks,
|
||||
dns)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user