Hotspot Manager tidying
This commit is contained in:
+40
-44
@@ -334,9 +334,12 @@ void HotspotManagerImpl::OnEthernetStateChanged(uint32_t state)
|
|||||||
}
|
}
|
||||||
void HotspotManagerImpl::OnWlanStateChanged(uint32_t state)
|
void HotspotManagerImpl::OnWlanStateChanged(uint32_t state)
|
||||||
{
|
{
|
||||||
this->wlanConnected = (state == 100);
|
bool value = (state == 100);
|
||||||
Lv2Log::debug(SS("HotspotMonitor: OnWlanStateChanged"));
|
if (value != this->wlanConnected)
|
||||||
MaybeStartHotspot();
|
{
|
||||||
|
this->wlanConnected = value;
|
||||||
|
MaybeStartHotspot();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HotspotManagerImpl::onStartMonitoring()
|
void HotspotManagerImpl::onStartMonitoring()
|
||||||
@@ -402,7 +405,8 @@ void HotspotManagerImpl::onStartMonitoring()
|
|||||||
this->wlanDevice->OnStateChanged.add(
|
this->wlanDevice->OnStateChanged.add(
|
||||||
[this](uint32_t, uint32_t, uint32_t)
|
[this](uint32_t, uint32_t, uint32_t)
|
||||||
{
|
{
|
||||||
OnWlanStateChanged(ethernetDevice->State());
|
// Use WLAN device state, not ethernet
|
||||||
|
OnWlanStateChanged(wlanDevice->State());
|
||||||
});
|
});
|
||||||
Lv2Log::debug("HotspotManager: state=Monitoring");
|
Lv2Log::debug("HotspotManager: state=Monitoring");
|
||||||
SetState(State::Monitoring);
|
SetState(State::Monitoring);
|
||||||
@@ -682,9 +686,9 @@ std::vector<std::vector<uint8_t>> HotspotManagerImpl::GetAllAutoConnectSsids()
|
|||||||
{
|
{
|
||||||
auto settings = connection->GetSettings();
|
auto settings = connection->GetSettings();
|
||||||
bool autoConnect = true;
|
bool autoConnect = true;
|
||||||
if (settings["connect"].count("autoconnect") > 0)
|
if (settings["connection"].count("autoconnect") > 0)
|
||||||
{
|
{
|
||||||
autoConnect = settings["connect"]["autoconnect"];
|
autoConnect = settings["connection"]["autoconnect"];
|
||||||
}
|
}
|
||||||
bool isInfrastructure =
|
bool isInfrastructure =
|
||||||
settings["802-11-wireless"].count("mode") > 0 && settings["802-11-wireless"]["mode"].get<std::string>() == "infrastructure";
|
settings["802-11-wireless"].count("mode") > 0 && settings["802-11-wireless"]["mode"].get<std::string>() == "infrastructure";
|
||||||
@@ -762,7 +766,8 @@ void HotspotManagerImpl::MaybeStartHotspot()
|
|||||||
|
|
||||||
bool wantsHotspot;
|
bool wantsHotspot;
|
||||||
|
|
||||||
if (wifiConfigSettings.NeedsScan()) {
|
if (wifiConfigSettings.NeedsScan())
|
||||||
|
{
|
||||||
|
|
||||||
std::vector<AccessPoint::ptr> allAccessPoints = GetAllAccessPoints();
|
std::vector<AccessPoint::ptr> allAccessPoints = GetAllAccessPoints();
|
||||||
std::vector<std::vector<uint8_t>> allAccessPointSsids = GetAccessPointSsids(allAccessPoints);
|
std::vector<std::vector<uint8_t>> allAccessPointSsids = GetAccessPointSsids(allAccessPoints);
|
||||||
@@ -772,13 +777,13 @@ void HotspotManagerImpl::MaybeStartHotspot()
|
|||||||
|
|
||||||
wantsHotspot = this->wifiConfigSettings.WantsHotspot(
|
wantsHotspot = this->wifiConfigSettings.WantsHotspot(
|
||||||
this->ethernetConnected, connectableSsids, allAccessPointSsids);
|
this->ethernetConnected, connectableSsids, allAccessPointSsids);
|
||||||
|
}
|
||||||
|
else
|
||||||
} else {
|
{
|
||||||
wantsHotspot = this->wifiConfigSettings.WantsHotspot(
|
wantsHotspot = this->wifiConfigSettings.WantsHotspot(
|
||||||
this->ethernetConnected);
|
this->ethernetConnected);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->state == State::Monitoring && wantsHotspot)
|
if (this->state == State::Monitoring && wantsHotspot)
|
||||||
{
|
{
|
||||||
StartHotspot();
|
StartHotspot();
|
||||||
@@ -865,53 +870,47 @@ void HotspotManagerImpl::StartHotspot()
|
|||||||
|
|
||||||
uint32_t iChannel = 0;
|
uint32_t iChannel = 0;
|
||||||
auto channel = this->wifiConfigSettings.channel_;
|
auto channel = this->wifiConfigSettings.channel_;
|
||||||
if (channel.length() != 0)
|
if (!channel.empty())
|
||||||
{
|
{
|
||||||
std::stringstream ss{channel};
|
std::stringstream ss{channel};
|
||||||
ss >> iChannel;
|
ss >> iChannel; // 0 means auto
|
||||||
}
|
}
|
||||||
if (iChannel <= 1)
|
// If a specific channel is requested, set it and derive band accordingly.
|
||||||
|
// NM "band" values: "a" (5GHz), "bg" (2.4GHz). Channels 1-14 -> 2.4GHz; >14 -> 5GHz.
|
||||||
|
if (iChannel != 0)
|
||||||
{
|
{
|
||||||
wireless["channel"] = iChannel;
|
wireless["channel"] = iChannel;
|
||||||
wireless["band"] = iChannel > 14 ? "a" : "bg";
|
wireless["band"] = (iChannel > 14) ? "a" : "bg";
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wireless["band"] = iChannel == 0 ? "bg" : "a";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, sdbus::Variant> &wirelessSecurity = settings["802-11-wireless-security"];
|
std::map<std::string, sdbus::Variant> &wirelessSecurity = settings["802-11-wireless-security"];
|
||||||
wirelessSecurity["key-mgmt"] = "wpa-psk";
|
wirelessSecurity["key-mgmt"] = "wpa-psk";
|
||||||
wirelessSecurity["psk"] = wifiConfigSettings.password_;
|
wirelessSecurity["psk"] = wifiConfigSettings.password_;
|
||||||
|
|
||||||
|
// IPv4 shared method: NM will configure NAT and DHCP; static address is fine.
|
||||||
settings["ipv4"]["method"] = "shared";
|
settings["ipv4"]["method"] = "shared";
|
||||||
settings["ipv6"]["method"] = "shared";
|
// For IPv6, use ignore to avoid advertising IPv6 if not needed; shared IPv6 is less common and can cause issues.
|
||||||
settings["ipv6"]["addr-gen-mode"] = 1; // "stable-privacy";
|
settings["ipv6"]["method"] = "ignore";
|
||||||
|
// If IPv6 were used, addr-gen-mode would be numeric enum; with method=ignore, omit it.
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Create connection
|
// Create connection
|
||||||
settings["ipv4"]["method"] = sdbus::Variant(std::string("shared"));
|
|
||||||
// settings["ipv6"]["method"] = sdbus::Variant(std::string("ignore"));
|
|
||||||
|
|
||||||
settings["ipv4"]["address-data"] = sdbus::Variant(std::vector<std::map<std::string, sdbus::Variant>>{{{"address", sdbus::Variant("192.168.60.1")},
|
settings["ipv4"]["address-data"] = sdbus::Variant(
|
||||||
{"prefix", sdbus::Variant(uint32_t(24))}}});
|
std::vector<std::map<std::string, sdbus::Variant>>{
|
||||||
// settings["ipv4"]["gateway'"] = sdbus::Variant(std::string("192.168.60.1"));
|
{{"address", sdbus::Variant("192.168.60.1")},
|
||||||
settings["ipv4"]["dhcp-send-hostname"] = sdbus::Variant(true);
|
{"prefix", sdbus::Variant(uint32_t(24))}}});
|
||||||
settings["ipv4"]["dhcp-hostname"] = sdbus::Variant("raspberrypi");
|
// For method=shared, NM provides DHCP; explicit DHCP client options on this device are not applicable.
|
||||||
// settings["ipv4"]["dhcp-options"] = sdbus::Variant(std::vector<std::string>{
|
// settings["ipv4"]["dhcp-options"] = sdbus::Variant(std::vector<std::string>{
|
||||||
// "option:classless-static-route,192.168.60.0/23,0.0.0.0,0.0.0.0/0,192.168.60.1"});
|
// "option:classless-static-route,192.168.60.0/8,0.0.0.0,0.0.0.0/0,192.168.60.1"});
|
||||||
|
|
||||||
// settings["ipv4"]["dhcp-options"] = sdbus::Variant(std::vector<std::string>{
|
// settings["ipv4"]["dhcp-options"] = sdbus::Variant(std::vector<std::string>{
|
||||||
// "option:classless-static-route,192.168.60.0/23,192.168.60.1"});
|
// "option:classless-static-route,192.168.60.0/8,192.168.60.1"});
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
settings["ipv6"]["address-data"] = sdbus::Variant(std::vector<std::map<std::string, sdbus::Variant>>{
|
// With IPv6 ignored, don't set address-data or gateway; NM may reject extraneous keys.
|
||||||
{{"address", sdbus::Variant("fdd2:e477:7b37:5b09::1")},
|
|
||||||
{"prefix", sdbus::Variant(uint32_t(64))}}});
|
|
||||||
|
|
||||||
settings["ipv6"]["gateway"] = sdbus::Variant("fdd2:e477:7b37:5b09::1");
|
|
||||||
std::map<std::string, sdbus::Variant> options;
|
std::map<std::string, sdbus::Variant> options;
|
||||||
options["persist"] = "disk";
|
options["persist"] = "disk";
|
||||||
|
|
||||||
@@ -1012,7 +1011,9 @@ void HotspotManagerImpl::ScanNow()
|
|||||||
|
|
||||||
Lv2Log::debug("Scanning");
|
Lv2Log::debug("Scanning");
|
||||||
wlanWirelessDevice->RequestScan(options);
|
wlanWirelessDevice->RequestScan(options);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1158,14 +1159,9 @@ static bool IsNetworkManagerRunning()
|
|||||||
bool HotspotManager::HasWifiDevice()
|
bool HotspotManager::HasWifiDevice()
|
||||||
{
|
{
|
||||||
// use procfs to decide this, as NetworkManager may not be available yet.
|
// use procfs to decide this, as NetworkManager may not be available yet.
|
||||||
if (!(get_wireless_interfaces_sysfs().empty()))
|
if (!get_wireless_interfaces_sysfs().empty())
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
if (!IsNetworkManagerRunning())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user