Auto hotspot implementation

This commit is contained in:
Robin Davies
2024-09-11 00:06:52 -04:00
parent bbfd0a07fd
commit 448979e7fe
61 changed files with 5234 additions and 178 deletions
+51 -6
View File
@@ -76,16 +76,19 @@ bool pipedal::UsingNetworkManager()
return std::filesystem::exists(NETWORK_MANAGER_SERVICE_PATH);
}
static bool IsApdInstalled()
{
return std::filesystem::exists(DNSMASQ_APD_PATH);
}
static bool IsP2pInstalled()
{
return std::filesystem::exists(DNSMASQ_P2P_PATH) | std::filesystem::exists(NETWORK_MANAGER_DNSMASQ_P2P_PATH);
}
static bool IsApdInstalled()
{
return std::filesystem::exists(DNSMASQ_APD_PATH);
}
#if !NEW_WIFI_CONFIG
static void restoreApdDhcpdConfFile()
{
// remove the interface wlan0 section.
@@ -123,6 +126,7 @@ static void restoreApdDhcpdConfFile()
dhcpcd.Save(dhcpcdConfig);
}
}
#endif
static void restoreP2pDhcpdConfFile()
{
@@ -170,6 +174,7 @@ static void restoreP2pDhcpdConfFile()
}
}
#if !NEW_WIFI_CONFIG
static void restoreApdDnsmasqConfFile()
{
std::filesystem::path path(DNSMASQ_APD_PATH);
@@ -178,6 +183,7 @@ static void restoreApdDnsmasqConfFile()
std::filesystem::remove(path);
}
}
#endif
static void restoreP2pDnsmasqConfFile()
{
{
@@ -196,6 +202,7 @@ static void restoreP2pDnsmasqConfFile()
}
}
#if !NEW_WIFI_CONFIG
static void UninstallHostApd()
{
if (IsApdInstalled())
@@ -213,6 +220,7 @@ static void UninstallHostApd()
sysExec(SYSTEMCTL_BIN " start wpa_supplicant");
}
}
#endif
static void InstallP2p(const WifiDirectConfigSettings &settings)
{
@@ -299,7 +307,8 @@ static void InstallP2p(const WifiDirectConfigSettings &settings)
static void UninstallP2p();
void pipedal::SetWifiConfig(const WifiConfigSettings &settings)
#if !NEW_WIFI_CONFIG
static void SetHostapdWifiConfig(const WifiConfigSettings &settings)
{
char band;
if (!settings.enable_)
@@ -476,6 +485,25 @@ void pipedal::SetWifiConfig(const WifiConfigSettings &settings)
}
::sync();
}
#endif
#if NEW_WIFI_CONFIG
static void SetNetworkManagerWifiConfig(WifiConfigSettings &settings)
{
settings.Save();
}
#endif
void pipedal::SetWifiConfig(WifiConfigSettings &settings)
{
#if NEW_WIFI_CONFIG
SetNetworkManagerWifiConfig(settings);
#else
SetHostapdWifiConfig(const WifiConfigSettings &settings);
#endif
}
/*********************************************************************************
@@ -686,6 +714,7 @@ void pipedal::SetWifiDirectConfig(const WifiDirectConfigSettings &settings)
::sync();
}
void pipedal::OnWifiReinstall() {
#if ENABLE_WIFI_P2P // Do not enable P2P going forward.
WifiDirectConfigSettings settings;
settings.Load();
if (settings.enable_)
@@ -693,14 +722,30 @@ void pipedal::OnWifiReinstall() {
SetWifiDirectConfig(settings);
::sync();
}
#endif
#if NEW_WIFI_CONFIG
{
// no action required.
// pipedald will pick up the old settings at runtime.
}
#endif
}
void pipedal::OnWifiUninstall(bool preserveState)
{
// intaller hook
#if NEW_WIFI_CONFIG
{
// no action required.
// shutting down pipedald is sufficient.
}
#else
if (IsApdInstalled())
{
UninstallHostApd();
}
#endif
if (IsP2pInstalled())
{
WifiDirectConfigSettings settings;