Wi-Fi Direct alpha
This commit is contained in:
@@ -156,7 +156,7 @@ void AvahiService::create_group(AvahiClient *c)
|
||||
if ((ret = avahi_entry_group_add_service(
|
||||
group,
|
||||
AVAHI_IF_UNSPEC,
|
||||
AVAHI_PROTO_UNSPEC,
|
||||
AVAHI_PROTO_INET, // IPv4 for now, until we figure out why dnsqmasq borks IPv6 routing.)
|
||||
(AvahiPublishFlags)0,
|
||||
name,
|
||||
PIPEDAL_SERVICE_TYPE,
|
||||
|
||||
+36
-21
@@ -3,6 +3,8 @@ cmake_minimum_required(VERSION 3.16.0)
|
||||
|
||||
set (CMAKE_INSTALL_PREFIX "/usr/")
|
||||
|
||||
set (USE_PCH 1)
|
||||
|
||||
include(FindPkgConfig)
|
||||
|
||||
|
||||
@@ -95,6 +97,7 @@ set (PIPEDAL_SOURCES
|
||||
P2pConfigFiles.hpp
|
||||
AvahiService.cpp AvahiService.hpp
|
||||
DeviceIdFile.cpp DeviceIdFile.hpp
|
||||
WriteTemplateFile.cpp WriteTemplateFile.hpp
|
||||
|
||||
StdErrorCapture.hpp StdErrorCapture.cpp
|
||||
Ipv6Helpers.cpp Ipv6Helpers.hpp
|
||||
@@ -152,30 +155,45 @@ set (PIPEDAL_SOURCES
|
||||
|
||||
)
|
||||
|
||||
|
||||
configure_file(config.hpp.in config.hpp)
|
||||
include_directories( ${pipedald_SOURCE_DIR}/. ../build/src)
|
||||
|
||||
set (PIPEDAL_INCLUDES
|
||||
${LV2DEV_INCLUDE_DIRS}
|
||||
${JACK_INCLUDE_DIRS} ${LILV_0_INCLUDE_DIRS} ${LIBNL3_INCLUDE_DIRS} ${LVDEV_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
set(PIPEDAL_LIBS libpipedald pthread atomic stdc++fs asound avahi-common avahi-client systemd
|
||||
${LILV_0_LIBRARIES} ${JACK_LIBRARIES} ${LIBNL3_LIBRARIES} )
|
||||
|
||||
|
||||
##########################
|
||||
|
||||
add_library(libpipedald STATIC ${PIPEDAL_SOURCES})
|
||||
|
||||
target_include_directories(libpipedald PRIVATE ${PIPEDAL_INCLUDES}
|
||||
)
|
||||
|
||||
if(${USE_PCH})
|
||||
target_precompile_headers(libpipedald PRIVATE pch.h)
|
||||
endif()
|
||||
|
||||
|
||||
#################################
|
||||
add_executable(pipedald ${PIPEDAL_SOURCES}
|
||||
add_executable(pipedald
|
||||
asan_options.cpp # disable leak checking for sanitize=address.
|
||||
main.cpp
|
||||
)
|
||||
target_include_directories(pipedald PRIVATE ${PIPEDAL_INCLUDES})
|
||||
|
||||
include_directories( ${pipedald_SOURCE_DIR}/. ../build/src)
|
||||
|
||||
target_precompile_headers(pipedald PRIVATE pch.h)
|
||||
|
||||
|
||||
target_include_directories(pipedald PRIVATE
|
||||
${LV2DEV_INCLUDE_DIRS}
|
||||
${JACK_INCLUDE_DIRS} ${LILV_0_INCLUDE_DIRS} ${LIBNL3_INCLUDE_DIRS} ${LVDEV_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(pipedald PRIVATE pthread atomic stdc++fs asound avahi-common avahi-client
|
||||
${LILV_0_LIBRARIES} ${JACK_LIBRARIES} ${LIBNL3_LIBRARIES} systemd SDBusCpp::sdbus-c++
|
||||
target_link_libraries(pipedald PRIVATE
|
||||
|
||||
${PIPEDAL_LIBS}
|
||||
)
|
||||
|
||||
#################################
|
||||
add_executable(pipedaltest ${PIPEDAL_SOURCES} testMain.cpp
|
||||
add_executable(pipedaltest testMain.cpp
|
||||
jsonTest.cpp
|
||||
AvahiServiceTest.cpp
|
||||
WifiChannelsTest.cpp
|
||||
@@ -192,20 +210,17 @@ add_executable(pipedaltest ${PIPEDAL_SOURCES} testMain.cpp
|
||||
MemDebug.hpp
|
||||
)
|
||||
|
||||
configure_file(config.hpp.in config.hpp)
|
||||
include_directories( ${pipedald_SOURCE_DIR}/. ../build/src)
|
||||
|
||||
if(${USE_PCH})
|
||||
target_precompile_headers(pipedaltest PRIVATE pch.h)
|
||||
endif()
|
||||
|
||||
|
||||
target_include_directories(pipedaltest PRIVATE
|
||||
.
|
||||
${LV2DEV_INCLUDE_DIRS}
|
||||
${JACK_INCLUDE_DIRS} ${LILV_0_INCLUDE_DIRS} ${LIBNL3_INCLUDE_DIRS}
|
||||
target_include_directories(pipedaltest PRIVATE ${PIPEDAL_INCLUDES}
|
||||
)
|
||||
|
||||
target_link_libraries(pipedaltest PRIVATE pthread atomic stdc++fs asound avahi-common avahi-client
|
||||
${LILV_0_LIBRARIES} ${JACK_LIBRARIES} ${LIBNL3_LIBRARIES} systemd SDBusCpp::sdbus-c++
|
||||
target_link_libraries(pipedaltest PRIVATE ${PIPEDAL_LIBS}
|
||||
)
|
||||
|
||||
|
||||
|
||||
+28
-3
@@ -48,7 +48,7 @@ static std::string trim(const std::string &value)
|
||||
size_t start = 0;
|
||||
size_t end = value.length();
|
||||
|
||||
while (start < end && ( value[start] == ' ' || value[start] == '\t'))
|
||||
while (start < end && (value[start] == ' ' || value[start] == '\t'))
|
||||
++start;
|
||||
|
||||
while (end > start && (value[end - 1] == ' ' || value[end - 1] == '\t'))
|
||||
@@ -96,11 +96,36 @@ static std::string unquote(const std::string &value)
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
}
|
||||
return value;
|
||||
}
|
||||
bool ConfigUtil::GetConfigLine(const std::string & filePath,const std::string & key, std::string *pValue)
|
||||
|
||||
std::string ConfigUtil::QuoteString(const std::string &value)
|
||||
{
|
||||
std::stringstream s;
|
||||
|
||||
s << '"';
|
||||
for (char c : value)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case '\n':
|
||||
break;
|
||||
case '"':
|
||||
s << "\\\"";
|
||||
break;
|
||||
case '\\':
|
||||
s << "\\\\";
|
||||
break;
|
||||
default:
|
||||
s << c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
s << '"';
|
||||
return s.str();
|
||||
}
|
||||
bool ConfigUtil::GetConfigLine(const std::string &filePath, const std::string &key, std::string *pValue)
|
||||
{
|
||||
|
||||
ifstream f;
|
||||
|
||||
@@ -30,5 +30,8 @@ namespace pipedal {
|
||||
class ConfigUtil {
|
||||
public:
|
||||
static bool GetConfigLine(const std::string & filePath,const std::string & key, std::string *pValue);
|
||||
|
||||
static std::string QuoteString(const std::string &value);
|
||||
|
||||
};
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace pipedal {
|
||||
|
||||
|
||||
@@ -678,11 +678,42 @@ void PiPedalModel::SetWifiConfigSettings(const WifiConfigSettings &wifiConfigSet
|
||||
delete[] t;
|
||||
}
|
||||
}
|
||||
void PiPedalModel::SetWifiDirectConfigSettings(const WifiDirectConfigSettings &wifiDirectConfigSettings)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> guard(mutex);
|
||||
|
||||
adminClient.SetWifiDirectConfig(wifiDirectConfigSettings);
|
||||
|
||||
this->storage.SetWifiDirectConfigSettings(wifiDirectConfigSettings);
|
||||
|
||||
{
|
||||
IPiPedalModelSubscriber **t = new IPiPedalModelSubscriber *[this->subscribers.size()];
|
||||
for (size_t i = 0; i < subscribers.size(); ++i)
|
||||
{
|
||||
t[i] = this->subscribers[i];
|
||||
}
|
||||
size_t n = this->subscribers.size();
|
||||
|
||||
WifiDirectConfigSettings tWifiDirectConfigSettings = storage.GetWifiDirectConfigSettings(); // (the passwordless version)
|
||||
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
{
|
||||
t[i]->OnWifiDirectConfigSettingsChanged(tWifiDirectConfigSettings);
|
||||
}
|
||||
delete[] t;
|
||||
}
|
||||
}
|
||||
|
||||
WifiConfigSettings PiPedalModel::GetWifiConfigSettings()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> guard(mutex);
|
||||
return this->storage.GetWifiConfigSettings();
|
||||
}
|
||||
WifiDirectConfigSettings PiPedalModel::GetWifiDirectConfigSettings()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> guard(mutex);
|
||||
return this->storage.GetWifiDirectConfigSettings();
|
||||
}
|
||||
|
||||
JackConfiguration PiPedalModel::GetJackConfiguration()
|
||||
{
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "PiPedalConfiguration.hpp"
|
||||
#include "JackServerSettings.hpp"
|
||||
#include "WifiConfigSettings.hpp"
|
||||
#include "WifiDirectConfigSettings.hpp"
|
||||
#include "AdminClient.hpp"
|
||||
|
||||
|
||||
@@ -62,6 +63,7 @@ public:
|
||||
virtual void OnNotifyMidiListener(int64_t clientHandle, bool isNote, uint8_t noteOrControl) = 0;
|
||||
virtual void OnNotifyAtomOutput(int64_t clientModel,uint64_t instanceId,const std::string&atomType, const std::string&atomJson) = 0;
|
||||
virtual void OnWifiConfigSettingsChanged(const WifiConfigSettings&wifiConfigSettings) = 0;
|
||||
virtual void OnWifiDirectConfigSettingsChanged(const WifiDirectConfigSettings&wifiDirectConfigSettings) = 0;
|
||||
virtual void OnGovernorSettingsChanged(const std::string &governor) = 0;
|
||||
virtual void OnFavoritesChanged(const std::map<std::string,bool> &favorites) = 0;
|
||||
virtual void Close() = 0;
|
||||
@@ -207,6 +209,9 @@ public:
|
||||
void SetWifiConfigSettings(const WifiConfigSettings&wifiConfigSettings);
|
||||
WifiConfigSettings GetWifiConfigSettings();
|
||||
|
||||
void SetWifiDirectConfigSettings(const WifiDirectConfigSettings&wifiConfigSettings);
|
||||
WifiDirectConfigSettings GetWifiDirectConfigSettings();
|
||||
|
||||
void SetGovernorSettings(const std::string& governor);
|
||||
GovernorSettings GetGovernorSettings();
|
||||
|
||||
|
||||
+27
-1
@@ -32,6 +32,7 @@
|
||||
|
||||
#include "AdminClient.hpp"
|
||||
#include "WifiConfigSettings.hpp"
|
||||
#include "WifiDirectConfigSettings.hpp"
|
||||
#include "WifiChannels.hpp"
|
||||
#include "SysExec.hpp"
|
||||
#include "PiPedalAlsa.hpp"
|
||||
@@ -812,6 +813,28 @@ public:
|
||||
this->Reply(replyTo, "getWifiConfigSettings", model.GetWifiConfigSettings());
|
||||
|
||||
}
|
||||
else if (message == "setWifiDirectConfigSettings") {
|
||||
WifiDirectConfigSettings wifiDirectConfigSettings;
|
||||
pReader->read(&wifiDirectConfigSettings);
|
||||
if (!GetAdminClient().CanUseShutdownClient())
|
||||
{
|
||||
throw PiPedalException("Can't change server settings when running interactively.");
|
||||
}
|
||||
std::string fromAddress = this->getFromAddress();
|
||||
if (!IsOnLocalSubnet(fromAddress))
|
||||
{
|
||||
throw PiPedalException("Permission denied. Not on local subnet.");
|
||||
}
|
||||
|
||||
|
||||
this->model.SetWifiDirectConfigSettings(wifiDirectConfigSettings);
|
||||
this->Reply(replyTo,"setWifiDirectConfigSettings");
|
||||
}
|
||||
else if (message == "getWifiDirectConfigSettings") {
|
||||
this->Reply(replyTo, "getWifiDirectConfigSettings", model.GetWifiDirectConfigSettings());
|
||||
|
||||
}
|
||||
|
||||
else if (message == "getGovernorSettings") {
|
||||
this->Reply(replyTo, "getGovernorSettings", model.GetGovernorSettings());
|
||||
|
||||
@@ -1462,10 +1485,13 @@ public:
|
||||
{
|
||||
Send("onJackServerSettingsChanged",jackServerSettings);
|
||||
}
|
||||
|
||||
virtual void OnWifiConfigSettingsChanged(const WifiConfigSettings&wifiConfigSettings) {
|
||||
Send("onWifiConfigSettingsChanged",wifiConfigSettings);
|
||||
}
|
||||
|
||||
virtual void OnWifiDirectConfigSettingsChanged(const WifiDirectConfigSettings&wifiConfigSettings) {
|
||||
Send("onWifiDirectConfigSettingsChanged",wifiConfigSettings);
|
||||
}
|
||||
virtual void OnGovernorSettingsChanged(const std::string& governor) {
|
||||
Send("onGovernorSettingsChanged",governor);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "json.hpp"
|
||||
#include "PiPedalException.hpp"
|
||||
#include <utility>
|
||||
#include <map>
|
||||
|
||||
namespace pipedal {
|
||||
|
||||
|
||||
+14
-69
@@ -390,8 +390,14 @@ void UninstallP2p()
|
||||
restoreP2pDhcpdConfFile();
|
||||
restoreP2pDnsmasqConfFile();
|
||||
|
||||
sysExec(SYSTEMCTL_BIN " enable wpa_supplicant");
|
||||
sysExec(SYSTEMCTL_BIN " start wpa_supplicant");
|
||||
|
||||
sysExec(SYSTEMCTL_BIN " restart dhcpcd");
|
||||
|
||||
WifiDirectConfigSettings wifiDirectConfigSettings;
|
||||
wifiDirectConfigSettings.Load();
|
||||
wifiDirectConfigSettings.enable_ = false;
|
||||
wifiDirectConfigSettings.Save();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,25 +414,7 @@ void pipedal::SetWifiDirectConfig(const WifiDirectConfigSettings &settings)
|
||||
else
|
||||
{
|
||||
|
||||
// ******************* pipedal_p2pd ******
|
||||
{
|
||||
// ${COUNTRY_CODE}
|
||||
//${PIN}
|
||||
// ${DEVICE_NAME}
|
||||
// ${WIFI_GROUP_FREQUENCY}
|
||||
// ${INSTANCE_ID_FILE} /var/pipedal/instance_id
|
||||
|
||||
std::map<string, string> map;
|
||||
map["COUNTRY_CODE"] = settings.countryCode_;
|
||||
map["PIN"] = settings.pin_;
|
||||
map["DEVICE_NAME"] = settings.hotspotName_;
|
||||
map["WIFI_GROUP_FREQUENCY"] = SS(ChannelToWifiFrequency(settings.channel_));
|
||||
map["INSTANCE_ID_FILE"] = DEVICE_GUID_FILE;
|
||||
|
||||
|
||||
WriteTemplateFile(map, PIPEDAL_P2PD_CONF_PATH);
|
||||
|
||||
}
|
||||
settings.Save();
|
||||
// ******************* device_uuid
|
||||
|
||||
DeviceIdFile deviceIdFile;
|
||||
@@ -436,51 +424,9 @@ void pipedal::SetWifiDirectConfig(const WifiDirectConfigSettings &settings)
|
||||
|
||||
// ******************** dsnmasq ******
|
||||
|
||||
std::filesystem::remove(DNSMASQ_P2P_PATH);
|
||||
std::filesystem::copy_file(DNSMASQ_P2P_SOURCE_PATH, DNSMASQ_P2P_PATH);
|
||||
|
||||
#if JUNK // copy into place instaead.
|
||||
std::filesystem::path dnsMasqPath(DNSMASQ_P2P_PATH);
|
||||
SystemConfigFile dnsMasq;
|
||||
|
||||
try
|
||||
{
|
||||
dnsMasq.Load(dnsMasqPath);
|
||||
}
|
||||
catch (const std::exception &)
|
||||
{
|
||||
// ignore.
|
||||
}
|
||||
// interface=p2p-wlan0-0
|
||||
// dhcp-range=172.24.0.3,172.24.0.127,1h
|
||||
// domain=local
|
||||
// address=/pipedal.local/172.24.0.1 # do this through DNS-SD?
|
||||
|
||||
// except-interface=eth0
|
||||
// except-interface=wlan0
|
||||
// except-interface=lo
|
||||
|
||||
|
||||
|
||||
dnsMasq.Set("interface", "p2p-wlan0-0", "Name of the Wi-Fi interface");
|
||||
dnsMasq.Set("listen-address", P2P_IP_ADDRESS);
|
||||
|
||||
dnsMasq.SetDefault("dhcp-range", P2P_IP_PREFIX ".3," P2P_IP_PREFIX ".127,1h", "dhcp configuration");
|
||||
dnsMasq.SetDefault("domain", "local");
|
||||
std::string strAddress = SS("/" << settings.mdnsName_ << ".local/" P2P_IP_PREFIX << ".2");
|
||||
dnsMasq.Set("address", strAddress);
|
||||
|
||||
dnsMasq.EraseLine("except-interface=eth0");
|
||||
dnsMasq.EraseLine("except-interface=wlan0");
|
||||
dnsMasq.EraseLine("except-interface=lo");
|
||||
|
||||
dnsMasq.AppendLine("except-interface=eth0");
|
||||
dnsMasq.AppendLine("except-interface=wlan0");
|
||||
dnsMasq.AppendLine("except-interface=lo");
|
||||
|
||||
dnsMasq.Save(dnsMasqPath);
|
||||
|
||||
#endif
|
||||
|
||||
// ****** dhcpd.conf ***/
|
||||
std::filesystem::path dhcpcdConfig("/etc/dhcpcd.conf");
|
||||
if (std::filesystem::exists(dhcpcdConfig))
|
||||
@@ -496,9 +442,9 @@ void pipedal::SetWifiDirectConfig(const WifiDirectConfigSettings &settings)
|
||||
|
||||
int line = dhcpcd.GetLineThatStartsWith("hostname");
|
||||
std::string hostNameLine;
|
||||
if (settings.mdnsName_ != "")
|
||||
if (false)
|
||||
{
|
||||
hostNameLine = "hostname " + settings.mdnsName_;
|
||||
// hostNameLine = "hostname " + settings.mdnsName_;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -559,19 +505,18 @@ void pipedal::SetWifiDirectConfig(const WifiDirectConfigSettings &settings)
|
||||
sysExec(SYSTEMCTL_BIN " enable dnsmasq");
|
||||
|
||||
sysExec(SYSTEMCTL_BIN " restart dhcpcd");
|
||||
sysExec(SYSTEMCTL_BIN " enable dhcpcd");
|
||||
|
||||
|
||||
sysExec(SYSTEMCTL_BIN " unmask pipedal_p2pd");
|
||||
cout << "."; cout.flush();
|
||||
if (sysExec(SYSTEMCTL_BIN " restart pipedal_p2pd") != 0)
|
||||
{
|
||||
throw PiPedalException("Unable to start the pipedal_p2pd.");
|
||||
throw PiPedalException("Unable to start the Wi-Fi Direct access point.");
|
||||
}
|
||||
|
||||
sysExec(SYSTEMCTL_BIN " enable pipedal_p2pd");
|
||||
|
||||
}
|
||||
cout << "Ready." << endl;
|
||||
}
|
||||
|
||||
void pipedal::OnWifiUninstall()
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <fstream>
|
||||
#include "Lv2Log.hpp"
|
||||
#include <map>
|
||||
#include <sys/stat.h>
|
||||
|
||||
using namespace pipedal;
|
||||
|
||||
@@ -167,12 +168,49 @@ void Storage::SetDataRoot(const std::filesystem::path& path)
|
||||
this->dataRoot = ResolveHomePath(path);
|
||||
}
|
||||
|
||||
static void CopyDirectory(const std::filesystem::path &source, const std::filesystem::path &destination)
|
||||
{
|
||||
for (auto &directoryEntry: std::filesystem::directory_iterator(source))
|
||||
{
|
||||
if (directoryEntry.is_regular_file())
|
||||
{
|
||||
std::filesystem::path sourceFile = directoryEntry.path();
|
||||
std::filesystem::path destFile = destination / sourceFile.filename();
|
||||
|
||||
std::filesystem::copy_file(sourceFile,destFile);
|
||||
chmod(destFile.c_str(),S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
void Storage::MaybeCopyDefaultPresets()
|
||||
{
|
||||
auto presetsDirectory = this->GetPresetsDirectory();
|
||||
|
||||
if (!std::filesystem::exists(presetsDirectory / "index.banks"))
|
||||
{
|
||||
CopyDirectory(this->configRoot / "default_presets" / "presets",
|
||||
presetsDirectory
|
||||
);
|
||||
}
|
||||
|
||||
auto pluginDirectory = this->GetPluginPresetsDirectory();
|
||||
if (!std::filesystem::exists(pluginDirectory / "index.json"))
|
||||
{
|
||||
CopyDirectory(this->configRoot / "default_presets" / "plugin_presets",
|
||||
pluginDirectory
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
void Storage::Initialize()
|
||||
{
|
||||
try
|
||||
{
|
||||
std::filesystem::create_directories(this->GetPresetsDirectory());
|
||||
std::filesystem::create_directories(this->GetPluginPresetsDirectory());
|
||||
|
||||
MaybeCopyDefaultPresets();
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
@@ -189,6 +227,7 @@ void Storage::Initialize()
|
||||
{
|
||||
}
|
||||
LoadWifiConfigSettings();
|
||||
LoadWifiDirectConfigSettings();
|
||||
LoadGovernorSettings();
|
||||
}
|
||||
|
||||
@@ -871,6 +910,21 @@ void Storage::SetWifiConfigSettings(const WifiConfigSettings & wifiConfigSetting
|
||||
}
|
||||
this->wifiConfigSettings = copyToStore;
|
||||
}
|
||||
|
||||
void Storage::SetWifiDirectConfigSettings(const WifiDirectConfigSettings & wifiDirectConfigSettings)
|
||||
{
|
||||
WifiDirectConfigSettings copyToSave = wifiDirectConfigSettings;
|
||||
copyToSave.rebootRequired_ = false;
|
||||
if (!copyToSave.enable_)
|
||||
{
|
||||
copyToSave.pinChanged_ = false;
|
||||
}
|
||||
|
||||
WifiDirectConfigSettings copyToStore = wifiDirectConfigSettings;
|
||||
copyToStore.pinChanged_ = false;
|
||||
this->wifiDirectConfigSettings = copyToStore;
|
||||
}
|
||||
|
||||
void Storage::LoadGovernorSettings()
|
||||
{
|
||||
std::filesystem::path path = this->dataRoot / GOVERNOR_SETTINGS_FILENAME;
|
||||
@@ -918,12 +972,27 @@ void Storage::LoadWifiConfigSettings()
|
||||
}
|
||||
this->wifiConfigSettings.valid_ = true;
|
||||
}
|
||||
void Storage::LoadWifiDirectConfigSettings()
|
||||
{
|
||||
|
||||
WifiDirectConfigSettings settings;
|
||||
settings.enable_ = false;
|
||||
settings.Load();
|
||||
settings.pinChanged_ = false;
|
||||
settings.valid_ = true;
|
||||
this->wifiDirectConfigSettings = settings;
|
||||
}
|
||||
|
||||
|
||||
|
||||
WifiConfigSettings Storage::GetWifiConfigSettings()
|
||||
{
|
||||
return this->wifiConfigSettings;
|
||||
}
|
||||
WifiDirectConfigSettings Storage::GetWifiDirectConfigSettings()
|
||||
{
|
||||
return this->wifiDirectConfigSettings;
|
||||
}
|
||||
|
||||
|
||||
void Storage::SaveCurrentPreset(const CurrentPreset ¤tPreset)
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "Banks.hpp"
|
||||
#include "JackConfiguration.hpp"
|
||||
#include "WifiConfigSettings.hpp"
|
||||
#include "WifiDirectConfigSettings.hpp"
|
||||
#include <map>
|
||||
|
||||
|
||||
@@ -51,6 +52,7 @@ private:
|
||||
PluginPresetIndex pluginPresetIndex;
|
||||
|
||||
private:
|
||||
void MaybeCopyDefaultPresets();
|
||||
static std::string SafeEncodeName(const std::string& name);
|
||||
static std::string SafeDecodeName(const std::string& name);
|
||||
std::filesystem::path GetPresetsDirectory() const;
|
||||
@@ -74,6 +76,7 @@ private:
|
||||
bool isJackChannelSelectionValid = false;
|
||||
JackChannelSelection jackChannelSelection;
|
||||
WifiConfigSettings wifiConfigSettings;
|
||||
WifiDirectConfigSettings wifiDirectConfigSettings;
|
||||
std::string governorSettings = "performance";
|
||||
public:
|
||||
Storage();
|
||||
@@ -89,6 +92,7 @@ public:
|
||||
|
||||
|
||||
void LoadWifiConfigSettings();
|
||||
void LoadWifiDirectConfigSettings();
|
||||
void LoadGovernorSettings();
|
||||
void LoadBank(int64_t instanceId);
|
||||
const PedalBoard& GetCurrentPreset();
|
||||
@@ -121,6 +125,10 @@ public:
|
||||
void SetWifiConfigSettings(const WifiConfigSettings & wifiConfigSettings);
|
||||
WifiConfigSettings GetWifiConfigSettings();
|
||||
|
||||
void SetWifiDirectConfigSettings(const WifiDirectConfigSettings & wifiDirectConfigSettings);
|
||||
WifiDirectConfigSettings GetWifiDirectConfigSettings();
|
||||
|
||||
|
||||
void SetGovernorSettings(const std::string & governor);
|
||||
std::string GetGovernorSettings() const;
|
||||
|
||||
|
||||
@@ -17,13 +17,17 @@
|
||||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#include "pch.h"
|
||||
// #include "pch.h"
|
||||
#include "WifiDirectConfigSettings.hpp"
|
||||
#include "P2pConfigFiles.hpp"
|
||||
|
||||
#include "WifiConfigSettings.hpp"
|
||||
#include <stdexcept>
|
||||
#include <random>
|
||||
#include "ConfigUtil.hpp"
|
||||
#include "DeviceIdFile.hpp"
|
||||
#include "WriteTemplateFile.hpp"
|
||||
#include "ss.hpp"
|
||||
|
||||
|
||||
using namespace pipedal;
|
||||
@@ -34,13 +38,12 @@ JSON_MAP_BEGIN(WifiDirectConfigSettings)
|
||||
JSON_MAP_REFERENCE(WifiDirectConfigSettings,rebootRequired)
|
||||
JSON_MAP_REFERENCE(WifiDirectConfigSettings,enable)
|
||||
JSON_MAP_REFERENCE(WifiDirectConfigSettings,hotspotName)
|
||||
JSON_MAP_REFERENCE(WifiDirectConfigSettings,hasPin)
|
||||
JSON_MAP_REFERENCE(WifiDirectConfigSettings,pinChanged)
|
||||
JSON_MAP_REFERENCE(WifiDirectConfigSettings,pin)
|
||||
JSON_MAP_REFERENCE(WifiDirectConfigSettings,countryCode)
|
||||
JSON_MAP_REFERENCE(WifiDirectConfigSettings,channel)
|
||||
JSON_MAP_REFERENCE(WifiDirectConfigSettings,mdnsName)
|
||||
JSON_MAP_END()
|
||||
|
||||
|
||||
static std::string MakePin()
|
||||
{
|
||||
std::random_device rand_dev;
|
||||
@@ -79,30 +82,8 @@ void WifiDirectConfigSettings::ParseArguments(const std::vector<std::string> &ar
|
||||
|
||||
if (arguments.size() == 0)
|
||||
{
|
||||
if (!ConfigUtil::GetConfigLine("/etc/pipedal/config/pipedal_p2pd.conf","country_code",&this->countryCode_))
|
||||
{
|
||||
throw invalid_argument("Default value for country code not found.");
|
||||
}
|
||||
if (!ConfigUtil::GetConfigLine("/etc/pipedal/config/pipedal_p2pd.conf","p2p_pin",&this->pin_))
|
||||
{
|
||||
throw invalid_argument("Default value for pin not found.");
|
||||
}
|
||||
if (!ConfigUtil::GetConfigLine("/etc/pipedal/config/pipedal_p2pd.conf","wifiGroupFrequency",&this->channel_))
|
||||
{
|
||||
throw invalid_argument("Default value for pin not found.");
|
||||
}
|
||||
try {
|
||||
DeviceIdFile deviceIdFile;
|
||||
deviceIdFile.Load();
|
||||
if (deviceIdFile.deviceName == "")
|
||||
{
|
||||
throw std::invalid_argument("");
|
||||
}
|
||||
this->hotspotName_ = deviceIdFile.deviceName;
|
||||
} catch (const std::exception &e)
|
||||
{
|
||||
throw std::invalid_argument("Default value for device name not found.");
|
||||
}
|
||||
Load();
|
||||
this->enable_ = true;
|
||||
} else {
|
||||
if (arguments.size() < 2 || arguments.size() > 4)
|
||||
{
|
||||
@@ -133,3 +114,63 @@ void WifiDirectConfigSettings::ParseArguments(const std::vector<std::string> &ar
|
||||
throw invalid_argument("Invalid channel.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WifiDirectConfigSettings::Save() const
|
||||
{
|
||||
// ******************* pipedal_p2pd ******
|
||||
{
|
||||
// ${COUNTRY_CODE}
|
||||
//${PIN}
|
||||
// ${DEVICE_NAME}
|
||||
// ${WIFI_GROUP_FREQUENCY}
|
||||
// ${INSTANCE_ID_FILE} /var/pipedal/instance_id
|
||||
|
||||
std::map<string, string> map;
|
||||
map["COUNTRY_CODE"] = this->countryCode_;
|
||||
map["PIN"] = this->pin_;
|
||||
map["DEVICE_NAME"] = ConfigUtil::QuoteString(this->hotspotName_);
|
||||
map["WIFI_CHANNEL"] = SS(this->channel_);
|
||||
map["ENABLED"] = this->enable_ ? "true": "false";
|
||||
map["WIFI_GROUP_FREQUENCY"] = SS(ChannelToWifiFrequency(this->channel_));
|
||||
map["INSTANCE_ID_FILE"] = DEVICE_GUID_FILE;
|
||||
|
||||
|
||||
WriteTemplateFile(map, PIPEDAL_P2PD_CONF_PATH);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
void WifiDirectConfigSettings::Load()
|
||||
{
|
||||
if (!ConfigUtil::GetConfigLine("/etc/pipedal/config/pipedal_p2pd.conf","p2p_device_name",&this->hotspotName_))
|
||||
{
|
||||
this->hotspotName_ = "PiPedal";
|
||||
}
|
||||
|
||||
if (!ConfigUtil::GetConfigLine("/etc/pipedal/config/pipedal_p2pd.conf","country_code",&this->countryCode_))
|
||||
{
|
||||
this->countryCode_ = "US";
|
||||
}
|
||||
if (!ConfigUtil::GetConfigLine("/etc/pipedal/config/pipedal_p2pd.conf","p2p_pin",&this->pin_))
|
||||
{
|
||||
this->pin_ = "12345678";
|
||||
}
|
||||
if (!ConfigUtil::GetConfigLine("/etc/pipedal/config/pipedal_p2pd.conf","wifiChannel",&this->channel_))
|
||||
{
|
||||
this->channel_ = "6";
|
||||
}
|
||||
try {
|
||||
DeviceIdFile deviceIdFile;
|
||||
deviceIdFile.Load();
|
||||
if (deviceIdFile.deviceName == "")
|
||||
{
|
||||
|
||||
}
|
||||
this->hotspotName_ = deviceIdFile.deviceName;
|
||||
} catch (const std::exception &e)
|
||||
{
|
||||
}
|
||||
this->valid_ = true;
|
||||
|
||||
}
|
||||
|
||||
@@ -35,11 +35,13 @@ namespace pipedal {
|
||||
bool enable_ = false;
|
||||
std::string countryCode_ = "US"; // iso 3661
|
||||
std::string hotspotName_ = "pipedal";
|
||||
std::string mdnsName_ = "pipedal";
|
||||
bool hasPin_ = false;
|
||||
bool pinChanged_ = false;
|
||||
std::string pin_;
|
||||
std::string channel_ = "g6";
|
||||
std::string channel_ = "6";
|
||||
|
||||
void ParseArguments(const std::vector<std::string> &arguments);
|
||||
void Save() const;
|
||||
void Load();
|
||||
|
||||
public:
|
||||
DECLARE_JSON_MAP(WifiDirectConfigSettings);
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include "PiPedalException.hpp"
|
||||
#include <map>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -30,12 +30,19 @@ template <typename T> class TypeDisplay;
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <string_view>
|
||||
|
||||
#include <mutex>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
|
||||
#include <fstream>
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#ifdef JUNK
|
||||
|
||||
#endif
|
||||
/*
|
||||
#include <lv2/lv2core.lv2/lv2.h>
|
||||
|
||||
|
||||
@@ -15,6 +15,11 @@ p2p_ssid_postfix=${DEVICE_NAME}
|
||||
# Should almost always be 2412 (ch1),2437 (ch6), or 2462 (ch11).
|
||||
wifiGroupFrequency=${WIFI_GROUP_FREQUENCY}
|
||||
|
||||
# UI use only. wifiGroupFrequency is authoritative
|
||||
wifiChannel=${WIFI_CHANNEL}
|
||||
|
||||
# UI use only. service state is authoritative.
|
||||
enabled=${ENABLED}
|
||||
# P2P Device info
|
||||
p2p_model_name=PiPedal
|
||||
p2p_model_number=1
|
||||
@@ -29,9 +34,6 @@ p2p_go_ht40=0
|
||||
p2p_go_vht=0
|
||||
p2p_go_he=0
|
||||
|
||||
# Ipv4 address for the P2P group interface
|
||||
p2p_ip_address=172.24.0.2/16
|
||||
|
||||
# File containing the globally-unique id that identifies the service on this machine
|
||||
# in this format: 0a6045b0-1753-4104-b3e4-b9713b9cc356
|
||||
service_guid_file=${INSTANCE_ID_FILE}
|
||||
|
||||
Reference in New Issue
Block a user