Persist all configuration settings across upgrades. Restart wifi-p2p if neccessary.

This commit is contained in:
Robin Davies
2024-08-27 14:55:48 -04:00
parent 722ef456bc
commit 06ebfb0bce
15 changed files with 340 additions and 201 deletions
+35 -4
View File
@@ -9,11 +9,14 @@
#include "WifiRegs.hpp"
#include "ChannelInfo.hpp"
#include "DBusLog.hpp"
#include <sys/stat.h>
using namespace pipedal;
P2pSettings::P2pSettings(const std::filesystem::path&configDirectoryPath)
P2pSettings::P2pSettings(const std::filesystem::path&configDirectoryPath, const std::filesystem::path&varDirectoryPath = "/var/pipedal/config")
: configDirectoryPath(configDirectoryPath),
varDirectoryPath(varDirectoryPath)
{
this->configDirectoryPath = configDirectoryPath;
}
@@ -188,12 +191,40 @@ void P2pSettings::Load()
}
}
static void openWithPerms(
std::ofstream &f,
const std::filesystem::path &path,
std::filesystem::perms perms =
std::filesystem::perms::owner_read | std::filesystem::perms::owner_write |
std::filesystem::perms::group_read | std::filesystem::perms::group_write)
{
auto directory = path.parent_path();
std::filesystem::create_directories(directory);
// open and close to make an existing empty file.
// close it.
{
std::ofstream f;
f.open(path);
f.close();
}
// set the perms.
std::filesystem::permissions(
path,
perms,
std::filesystem::perm_options::replace);
// open for re3al.
f.open(path);
}
void P2pSettings::Save()
{
auto filename = config_filename();
try {
std::ofstream f(filename);
if (!f)
std::ofstream f;
openWithPerms(f,filename);
if (!f.is_open())
{
throw std::runtime_error("Can't write to file.");
}
+3 -2
View File
@@ -8,7 +8,7 @@
class P2pSettings {
// adapter between nm p2p settings, and legacy p2p
public:
P2pSettings(const std::filesystem::path&configDirectory = "/etc/pipedal/config");
P2pSettings(const std::filesystem::path&configDirectory = "/etc/pipedal/config", const std::filesystem::path&varDirectory = "/var/pipedal/config");
void Load();
void Save();
@@ -16,6 +16,7 @@ public:
private:
bool valid_ = false;
std::filesystem::path configDirectoryPath;
std::filesystem::path varDirectoryPath;
bool auth_changed_ = true;
std::vector<uint8_t> device_type_{
0x00,0x01, 0x00,0x50,0xF2,0x04, 0x00,0x02 /*"1-0050F204-2";*/
@@ -59,7 +60,7 @@ public:
};
std::filesystem::path config_filename() const {
// "/etc/pipedal/config/wpa_supplicant/wpa_supplicant-pipedal.conf"; }
return (configDirectoryPath / "NetworkManagerP2P.json").string();
return (varDirectoryPath / "NetworkManagerP2P.json").string();
};
const std::string& bssid() const { return bssid_; }