driver/wifi: remove auto_connect attribute

This commit does away with controlling the join-intent via an attribute
but couples it to the existence of a '<network>' node. With this change
all '<network>' nodes within the configuration are always
unconditionally considered for joining.

Issue #5356.
This commit is contained in:
Josef Söntgen 2024-10-07 17:35:14 +02:00
parent e4d2a4df42
commit e0874baa8f
No known key found for this signature in database
GPG Key ID: CFCD8B5D2D93D80E
4 changed files with 41 additions and 55 deletions

View File

@ -31,15 +31,15 @@ proc wifi_verbose { } {
# You may script your tests with this function in the dynamic_rom config below.
# The syntax for the networks parameter is
#
# { ssid protection passphrase auto_connect explicit_scan }
# { ssid protection passphrase explicit_scan }
#
# Example dynamic_rom config:
#
# {<inline description="auto-connect both networks">
# } [wifi_config 5 no [list "net1 WPA2 net1_psk yes no" "net2 WPA2 net2_psk yes no"]] {
# {<inline description="connect to two networks">
# } [wifi_config 5 no [list "net1 WPA2 net1_psk no" "net2 WPA2 net2_psk no"]] {
# </inline>
# <inline description="aquto-connect both, but net2 explicitly">
# } [wifi_config 5 no [list "net1 WPA2 net1_psk yes no" "net2 WPA2 net2_psk yes yes"]] {
# <inline description="connect to two netowrks, but net2 is hidden">
# } [wifi_config 5 no [list "net1 WPA2 net1_psk no" "net2 WPA2 net2_psk yes"]] {
# </inline>}
#
@ -62,7 +62,6 @@ proc wifi_config { scan_interval update_quality_interval rfkill networks } {
append config " ssid=\"[lindex $n 0]\""
append config " protection=\"[lindex $n 1]\""
append config " passphrase=\"[lindex $n 2]\""
append config " auto_connect=\"[lindex $n 3]\""
append config "/>\n"
}
append config "</wifi_config>\n"

View File

@ -117,9 +117,10 @@ node features the following attributes.
* :verbose: allows for logging of diagnostic messages generated
by the managing portion of the driver. The default is 'false'.
Besides those attributes the '<wifi_config>' node can host one or
more '<network>' nodes. Such a node describes the parameters of
a network and has the following attributes.
Besides those attributes the '<wifi_config>' node can host '<network>'
nodes. Such a node describes the parameters of a network and its
existence implies the intent to join the network. It has the following
attributes.
* :ssid: sets the name of the network.
@ -140,17 +141,12 @@ a network and has the following attributes.
* :passphrase: sets the PSK that is required should the
network be protected.
* :auto_connect: allows for joining a network automatically. The
default value is 'true'. When more than one network is configured
with enabled 'auto_connect' the driver will try to select the best
one it gets a response from.
Note: If configured auto-connect networks overlap in locality, the
driver might switch dynamically between the networks.
Of all attributes solely the 'ssid' attribute is mandatory and all
others are optional. They should be used when needed only.
Note: If configured networks overlap in locality, the driver might
switch dynamically between these networks.
To scan for a hidden network a '<explicit_scan>' node must by added.
It contains the following mandatory attribute.
@ -165,7 +161,6 @@ while the second one is hidden but should show up in the scan results.
!<wifi_config scan_interval="10" update_quality_interval="30">
! <network ssid="Zero" protection="WPA2" passphrase="allyourbase"
! auto_connect="true"/>
! <explicit_scan ssid="Skynet"/>
!</wifi_config>

View File

@ -161,11 +161,6 @@ struct Accesspoint : Interface
Pass pass { };
unsigned quality { 0 };
/*
* Internal configuration fields
*/
bool auto_connect { false };
static Accesspoint from_xml(Xml_node const &node)
{
Accesspoint ap { };
@ -173,9 +168,8 @@ struct Accesspoint : Interface
ap.ssid = node.attribute_value("ssid", Accesspoint::Ssid());
ap.bssid = node.attribute_value("bssid", Accesspoint::Bssid());
ap.pass = node.attribute_value("passphrase", Accesspoint::Pass(""));
ap.prot = node.attribute_value("protection", Accesspoint::Prot("NONE"));
ap.auto_connect = node.attribute_value("auto_connect", true);
ap.pass = node.attribute_value("passphrase", Accesspoint::Pass(""));
ap.prot = node.attribute_value("protection", Accesspoint::Prot("NONE"));
return ap;
}
@ -216,8 +210,7 @@ struct Accesspoint : Interface
"BSSID: '", bssid, "'", " "
"protection: ", prot, " "
"id: ", id, " "
"quality: ", quality, " "
"auto_connect: ", auto_connect);
"quality: ", quality);
}
bool wpa() const { return prot != "NONE"; }
@ -228,17 +221,15 @@ struct Accesspoint : Interface
{
bool const update = ((Accesspoint::valid(other.bssid) && other.bssid != bssid)
|| pass != other.pass
|| prot != other.prot
|| auto_connect != other.auto_connect);
|| prot != other.prot);
if (!update)
return false;
if (Accesspoint::valid(other.bssid))
bssid = other.bssid;
pass = other.pass;
prot = other.prot;
auto_connect = other.auto_connect;
pass = other.pass;
prot = other.prot;
return true;
}
};
@ -488,11 +479,8 @@ struct Add_network_cmd : Action
_state = State::FILL_NETWORK_PSK;
break;
case State::FILL_NETWORK_PSK:
if (_accesspoint.auto_connect) {
ctrl_cmd(_msg, Cmd("ENABLE_NETWORK ", _accesspoint.id));
_state = State::ENABLE_NETWORK;
} else
_state = State::COMPLETE;
ctrl_cmd(_msg, Cmd("ENABLE_NETWORK ", _accesspoint.id));
_state = State::ENABLE_NETWORK;
break;
case State::ENABLE_NETWORK:
_state = State::COMPLETE;
@ -643,12 +631,12 @@ struct Remove_network_cmd : Action
/*
* Action for updating a network
*
* For now only the PSK is updated and depending on the
* auto_connect configuration the network will also be
* enabled to allow for auto-join after the alteration.
* For now only the PSK is updated.
*/
struct Update_network_cmd : Action
{
enum class Op : unsigned {
UPDATE_ALL, DISABLE_ONLY };
enum class State : unsigned {
INIT, UPDATE_NETWORK_PSK,
DISABLE_NETWORK, ENABLE_NETWORK, COMPLETE
@ -656,13 +644,17 @@ struct Update_network_cmd : Action
Ctrl_msg_buffer &_msg;
Accesspoint _accesspoint;
State _state;
Op _op;
Update_network_cmd(Ctrl_msg_buffer &msg, Accesspoint const &ap)
Update_network_cmd(Ctrl_msg_buffer &msg,
Accesspoint const &ap,
Op op = Op::UPDATE_ALL)
:
Action { Command::UPDATE },
_msg { msg },
_accesspoint { ap },
_state { State::INIT }
_state { State::INIT },
_op { op }
{ }
void print(Output &out) const override
@ -685,12 +677,11 @@ struct Update_network_cmd : Action
_state = State::DISABLE_NETWORK;
break;
case State::DISABLE_NETWORK:
if (_accesspoint.auto_connect) {
if (_op != Op::DISABLE_ONLY) {
ctrl_cmd(_msg, Cmd("ENABLE_NETWORK ", _accesspoint.id));
_state = State::ENABLE_NETWORK;
} else {
} else
_state = State::COMPLETE;
}
break;
case State::ENABLE_NETWORK:
_state = State::COMPLETE;
@ -1867,12 +1858,12 @@ struct Wifi::Manager : Wifi::Rfkill_notification_handler
Join_state _join { };
bool _single_autoconnect() const
bool _single_network() const
{
unsigned count = 0;
_network_list.for_each([&] (Network const &network) {
network.with_accesspoint([&] (Accesspoint const &ap) {
count += ap.auto_connect; }); });
++count; }); });
return count == 1;
}
@ -1929,7 +1920,7 @@ struct Wifi::Manager : Wifi::Rfkill_notification_handler
* as we do not have the available accesspoints at hand to compare
* that.
*/
if ((_join.state == Join_state::State::CONNECTING) && _single_autoconnect()) {
if ((_join.state == Join_state::State::CONNECTING) && _single_network()) {
/*
* Ignore the event for a while as it may happen that hidden
@ -1997,10 +1988,11 @@ struct Wifi::Manager : Wifi::Rfkill_notification_handler
* again. At this point intervention by the management
* component is needed.
*/
ap.auto_connect = false;
_queue_action(*new (_actions_alloc)
Update_network_cmd(_msg, ap), _config.verbose);
Update_network_cmd(_msg, ap,
Update_network_cmd::Op::DISABLE_ONLY),
_config.verbose);
});
});
} else
@ -2102,7 +2094,7 @@ struct Wifi::Manager : Wifi::Rfkill_notification_handler
Remove_network_cmd(_msg, added_ap.id), _config.verbose);
} else
if (handled && _single_autoconnect())
if (handled && _single_network())
/*
* To accomodate a management component that only deals
* with one network, e.g. the sculpt_manager, generate a

View File

@ -179,15 +179,15 @@ append config {
</inline>
<sleep milliseconds="15000"/>
<inline description="connect">
} [wifi_config 5 10 no [list "[wifi_ssid] [wifi_wpa] [wifi_psk] yes no "]] {
} [wifi_config 5 10 no [list "[wifi_ssid] [wifi_wpa] [wifi_psk] no"]] {
</inline>
<sleep milliseconds="60000"/>
<inline description="rfkill block">
} [wifi_config 5 10 yes [list "[wifi_ssid] [wifi_wpa] [wifi_psk] yes no "]] {
} [wifi_config 5 10 yes [list "[wifi_ssid] [wifi_wpa] [wifi_psk] no"]] {
</inline>
<sleep milliseconds="30000"/>
<inline description="rfkill unblock">
} [wifi_config 5 10 no [list "[wifi_ssid] [wifi_wpa] [wifi_psk] yes no "]] {
} [wifi_config 5 10 no [list "[wifi_ssid] [wifi_wpa] [wifi_psk] no"]] {
</inline>
<sleep milliseconds="30000"/>
</rom>