|
|
|
@ -59,7 +59,7 @@ end
|
|
|
|
|
--- Authenticates network.
|
|
|
|
|
function WpaSupplicant:authenticateNetwork(network)
|
|
|
|
|
local err, wcli, nw_id
|
|
|
|
|
--- @todo support passwordless network
|
|
|
|
|
|
|
|
|
|
wcli, err = WpaClient.new(self.wpa_supplicant.ctrl_interface)
|
|
|
|
|
if not wcli then
|
|
|
|
|
return false, T(CLIENT_INIT_ERR_MSG, err)
|
|
|
|
@ -73,14 +73,24 @@ function WpaSupplicant:authenticateNetwork(network)
|
|
|
|
|
wcli:removeNetwork(nw_id)
|
|
|
|
|
return false, _("An error occurred while selecting network.")
|
|
|
|
|
end
|
|
|
|
|
if not network.psk then
|
|
|
|
|
network.psk = calculatePsk(network.ssid, network.password)
|
|
|
|
|
self:saveNetwork(network)
|
|
|
|
|
end
|
|
|
|
|
re = wcli:setNetwork(nw_id, "psk", network.psk)
|
|
|
|
|
if re == 'FAIL' then
|
|
|
|
|
wcli:removeNetwork(nw_id)
|
|
|
|
|
return false, _("An error occurred while setting password.")
|
|
|
|
|
-- if password is empty it’s an open AP
|
|
|
|
|
if network.password and (network.password == nil or string.len(network.password) == 0) then -- Open AP
|
|
|
|
|
re = wcli:setNetwork(nw_id, "key_mgmt", "NONE")
|
|
|
|
|
if re == 'FAIL' then
|
|
|
|
|
wcli:removeNetwork(nw_id)
|
|
|
|
|
return false, _("An error occurred while setting passwordless mode.")
|
|
|
|
|
end
|
|
|
|
|
-- else it’s a WPA AP
|
|
|
|
|
else
|
|
|
|
|
if not network.psk then
|
|
|
|
|
network.psk = calculatePsk(network.ssid, network.password)
|
|
|
|
|
self:saveNetwork(network)
|
|
|
|
|
end
|
|
|
|
|
re = wcli:setNetwork(nw_id, "psk", network.psk)
|
|
|
|
|
if re == 'FAIL' then
|
|
|
|
|
wcli:removeNetwork(nw_id)
|
|
|
|
|
return false, _("An error occurred while setting password.")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
wcli:enableNetworkByID(nw_id)
|
|
|
|
|
|
|
|
|
|