Skip to content

Commit

Permalink
Implemented basic UI interaction for Client Mode, AP mode (both alrea…
Browse files Browse the repository at this point in the history
…dy configured and not already configured), and Wifi Off mode
  • Loading branch information
erinharrington-12 committed Nov 17, 2022
1 parent cc8ca05 commit b152929
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 107 deletions.
17 changes: 17 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/x86_64-linux-gnu/qt6/QtDBus"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"C_Cpp.errorSquiggles": "Disabled",
"files.associations": {
"chrono": "cpp",
"variant": "cpp"
}
}
41 changes: 21 additions & 20 deletions include/botui/Network.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,46 @@
class Network
{
public:
enum Security {
enum Security
{
None = 0,
Wep,
DynamicWep,
Wpa,
WpaEnterprise
};

enum Mode {

enum Mode
{
Unknown = 0,
AdHoc,
Infrastructure,
AP
};

Network();

void setAPPath(const QString& path);
const QString& apPath() const;
void setSsid(const QString& ssid);
const QString& ssid() const;
void setSecurity(const Security& security);
const Security& security() const;
void setAPPath(const QString &path);
const QString &apPath() const;

void setSsid(const QString &ssid);
const QString &ssid() const;

void setSecurity(const Security &security);
const Security &security() const;
QString securityString() const;
void setPassword(const QString& password);
const QString& password() const;

void setPassword(const QString &password);
const QString &password() const;

void setMode(const Mode &mode);
const Mode &mode() const;

void setStrength(const double &strength);
const double &strength() const;

bool isComplete() const;

private:
QString m_ssid;
Security m_security;
Expand All @@ -60,5 +62,4 @@ bool operator==(const Network &lhs, const Network &rhs);

QDebug operator<<(QDebug dbg, const Network &network);


#endif
48 changes: 28 additions & 20 deletions src/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,62 @@

Network::Network()
{

}

void Network::setAPPath(const QString& path)
void Network::setAPPath(const QString &path)
{
m_apPath = path;
}

const QString& Network::apPath() const
const QString &Network::apPath() const
{
return m_apPath;
}

void Network::setSsid(const QString& ssid)
void Network::setSsid(const QString &ssid)
{
m_ssid = ssid;
}

const QString& Network::ssid() const
const QString &Network::ssid() const
{
return m_ssid;
}

void Network::setSecurity(const Network::Security& security)
void Network::setSecurity(const Network::Security &security)
{
m_security = security;
}

const Network::Security& Network::security() const
const Network::Security &Network::security() const
{
return m_security;
}

QString Network::securityString() const
{
switch(m_security) {
case Network::None: return "None";
case Network::Wep: return "WEP";
case Network::DynamicWep: return "Dynamic WEP";
case Network::Wpa: return "WPA";
case Network::WpaEnterprise: return "WPA Enterprise";
switch (m_security)
{
case Network::None:
return "None";
case Network::Wep:
return "WEP";
case Network::DynamicWep:
return "Dynamic WEP";
case Network::Wpa:
return "WPA";
case Network::WpaEnterprise:
return "WPA Enterprise";
}
return "Unknown";
}

void Network::setPassword(const QString& password)
void Network::setPassword(const QString &password)
{
m_password = password;
}

const QString& Network::password() const
const QString &Network::password() const
{
return m_password;
}
Expand All @@ -81,7 +86,8 @@ const double &Network::strength() const

bool Network::isComplete() const
{
if(m_security == Network::None) return true;
if (m_security == Network::None)
return true;
return !m_password.isEmpty();
}

Expand All @@ -93,10 +99,12 @@ bool operator==(const Network &lhs, const Network &rhs)
QDebug operator<<(QDebug dbg, const Network &network)
{
dbg.nospace() << network.ssid() << "("
<< (network.mode() == Network::AP ? "ap" : "infrastructure")
<< ")" << " with ";

switch(network.security()) {
<< (network.mode() == Network::AP ? "ap" : "infrastructure")
<< ")"
<< " with ";

switch (network.security())
{
case Network::None:
dbg.nospace() << "no security";
return dbg.space();
Expand Down
73 changes: 34 additions & 39 deletions src/NetworkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,29 +177,30 @@ void NetworkManager::addNetwork(const Network &network)
{
APExist = true;
apPathConn = connectionPath;
APuuid = detail["connection"]["uuid"].toString();
//APuuid = detail["connection"]["uuid"].toString();
qDebug() << "AP Path Connection already exists";
break;
}
}
qDebug() << "APExist = " << APExist;
qDebug() << "UUID = " << APuuid;

apCon = createAPConfig();

if (APExist == false)
{ // if AP Config in Settings doesn't exist already

qDebug() << "AP Connection Config: " << apCon;
QDBusObjectPath apPathConn = settings.AddConnection(apCon);
if (m_device->activeConnection().path() != "")
{
QDBusObjectPath curCon = m_device->activeConnection();
m_nm->DeactivateConnection(curCon);
}

qDebug() << "AP Path" << apPathConn.path();
m_nm->ActivateConnection(apPathConn, devicePath, QDBusObjectPath("/"));
apPathConn = settings.AddConnection(apCon); // auto activates

QDBusObjectPath activeAccess = m_wifi->activeAccessPoint(); // active AP connection
}
else
{ // if AP Config in Settings DOES exist already
// apPathConn = settings.GetConnectionByUuid(APuuid);
qDebug() << "AP Path" << apPathConn.path();
// apPathConn = settings.AddConnection(apCon);
m_nm->ActivateConnection(settings.GetConnectionByUuid(APuuid), devicePath, QDBusObjectPath("/"));
m_nm->ActivateConnection(apPathConn, devicePath, QDBusObjectPath("/"));
}

// return;
Expand Down Expand Up @@ -255,7 +256,7 @@ NetworkList NetworkManager::networks() const
QDBusConnection::systemBus());

Connection details = conn.GetSettings().value();
qDebug() << details;

// This connection is not a wifi one. Skip.
if (!details.contains("802-11-wireless"))
continue;
Expand Down Expand Up @@ -306,7 +307,20 @@ bool NetworkManager::enableAP()
int ret = system("sudo /usr/bin/python /usr/bin/wifi_configurator.py &");
return (ret == 0);
#endif
Connection defaultAPConfig = createAPConfig();
Network APN = networkFromConnection(defaultAPConfig);
addNetwork(APN);
return true;
}

bool NetworkManager::disableAP()
{
#ifdef WALLABY
int ret = system("sudo ifconfig wlan0 down");
return (ret == 0);
#endif
QDBusObjectPath curCon = m_device->activeConnection();
m_nm->DeactivateConnection(curCon);
return true;
}

Expand All @@ -320,8 +334,8 @@ Connection NetworkManager::createAPConfig() const
apConfig["connection"]["uuid"] = QUuid::createUuid().toString().remove('{').remove('}');
// File name is just the SSID for now
apConfig["connection"]["id"] = "APName";
apConfig["connection"]["autoconnect"] = false;

// apConfig["connection"]["autoconnect"] = false;
apConfig["connection"]["interface-name"] = "wlo1";
// SSID
QByteArray tempCont;
QStringList qSList = {"ccmp"};
Expand All @@ -345,20 +359,10 @@ Connection NetworkManager::createAPConfig() const
// // WEP uses this key
// apConfig[NM_802_11_SECURITY_KEY]["password"] = "kipr4609";
// // WPA uses this one
// apConfig[NM_802_11_SECURITY_KEY]["psk"] = "kipr4609";

// // Finally, tell our configuration about the security
apConfig[NM_802_11_SECURITY_KEY]["psk"] = "kipr4609";

return apConfig;
}
bool NetworkManager::disableAP()
{
#ifdef WALLABY
int ret = system("sudo ifconfig wlan0 down");
return (ret == 0);
#endif
return true;
}

bool NetworkManager::isOn() const
{
Expand Down Expand Up @@ -390,13 +394,12 @@ NetworkList NetworkManager::accessPoints() const
{
if (!m_wifi)
return NetworkList();
QList<QDBusObjectPath> aps = m_wifi->GetAccessPoints();
QList<QDBusObjectPath> aps = m_wifi->GetAllAccessPoints();
NetworkList networks;
QList<Network> netList;
QList<QByteArray> netSSID;
foreach (const QDBusObjectPath &ap, aps)
{
// qDebug() << ap.path();
Network newNet = createAccessPoint(ap);
netList << newNet;
}
Expand Down Expand Up @@ -448,10 +451,6 @@ NetworkManager::NetworkManager()
NM_OBJECT "/Settings",
QDBusConnection::systemBus());

Connection defaultAPConfig = createAPConfig();
Network APN = networkFromConnection(defaultAPConfig);
addNetwork(APN);
// enableAP();
QDBusPendingReply<QList<QDBusObjectPath>> reply = m_nm->GetDevices();

if (reply.isError())
Expand Down Expand Up @@ -508,16 +507,12 @@ NetworkManager::NetworkManager()

requestScan();

foreach (const Network &nw, accessPoints())
{
qDebug() << nw;
}
// foreach (const Network &nw, accessPoints())
// {
// qDebug() << nw;
// }
}

// void NetworkManager::connectToWifi()
// {

// }
void NetworkManager::nmAccessPointAdded(const QDBusObjectPath &accessPoint)
{
Network network = createAccessPoint(accessPoint);
Expand Down
Loading

0 comments on commit b152929

Please sign in to comment.