Use BSSID instead of storing APInfo pointers internally

pull/1/head
Timothy Pearson 12 years ago
parent 083f3b3b04
commit 69038478eb

@ -49,12 +49,12 @@ TQValueList<WirelessNetwork> WirelessManager::getWirelessNetworks(TDENetworkDevi
// check if we have a network matching this AP
for (TQValueList<WirelessNetwork>::Iterator netIt = nets.begin(); netIt != nets.end(); ++netIt) {
if ((*netIt).contains(ap) ) {
if ((*netIt).contains(ap->BSSID) ) {
// we alread have a network where this AP belongs to
found = true;
// attach this ap to the network
(*netIt).addAP(ap);
(*netIt).addAP(ap->BSSID, (dev)?dev->uniqueID():TQString::null);
/* // FIXME active?
if (active_ap)
@ -70,7 +70,7 @@ TQValueList<WirelessNetwork> WirelessManager::getWirelessNetworks(TDENetworkDevi
if (!found) {
// create a new network-descriptor according to this ap
WirelessNetwork net(match);
net.addAP(ap);
net.addAP(ap->BSSID, (dev)?dev->uniqueID():TQString::null);
nets.append(net);
}
}

@ -48,7 +48,7 @@ class WirelessNetworkPrivate
bool active;
TQ_UINT32 match;
TQValueList<const TDENetworkWiFiAPInfo*> aps;
TQMap<TDEMACAddress,TQString> aps;
};
WirelessNetwork::WirelessNetwork(const WirelessNetwork& other)
@ -71,15 +71,35 @@ WirelessNetwork::~WirelessNetwork()
WirelessNetwork& WirelessNetwork::operator= (const WirelessNetwork& other)
{
if (d)
if (d) {
delete d;
}
d = new WirelessNetworkPrivate(*other.d);
return *this;
}
bool WirelessNetwork::contains (const TDENetworkWiFiAPInfo * const ap)
bool WirelessNetwork::contains(const TDEMACAddress ap)
{
if ( (d->match & MATCH_SSID) && getSsid() != ap->SSID) {
TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices();
TDEGlobalNetworkManager* nm = KGlobal::networkManager();
TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(d->aps[ap]));
TDENetworkWiFiAPInfo* apInfo = NULL;
if (dev) {
TDENetworkConnectionManager* deviceConnMan = dev->connectionManager();
apInfo = deviceConnMan->findAccessPointByBSSID(ap);
}
else if (d->aps[ap] == "") {
apInfo = nm->findAccessPointByBSSID(ap);
}
if (apInfo) {
if ( (d->match & MATCH_SSID) && (getSsid() != apInfo->SSID)) {
return false;
}
}
else {
// AP was not found in list
return false;
}
@ -87,10 +107,10 @@ bool WirelessNetwork::contains (const TDENetworkWiFiAPInfo * const ap)
return true;
}
bool WirelessNetwork::addAP(const TDENetworkWiFiAPInfo * const ap)
bool WirelessNetwork::addAP(const TDEMACAddress ap, const TQString dev)
{
if ( this->contains(ap) || d->aps.isEmpty()) {
d->aps.append(ap);
d->aps[ap] = dev;
return true;
}
return false;
@ -98,8 +118,26 @@ bool WirelessNetwork::addAP(const TDENetworkWiFiAPInfo * const ap)
const TQByteArray WirelessNetwork::getSsid() const
{
TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices();
TDEGlobalNetworkManager* nm = KGlobal::networkManager();
if ( !d->aps.isEmpty() ) {
return (*(d->aps.begin()))->SSID;
TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(d->aps.begin().data()));
TDENetworkWiFiAPInfo* apInfo = NULL;
if (dev) {
TDENetworkConnectionManager* deviceConnMan = dev->connectionManager();
apInfo = deviceConnMan->findAccessPointByBSSID(d->aps.begin().key());
}
else if (d->aps.begin().data() == "") {
apInfo = nm->findAccessPointByBSSID(d->aps.begin().key());
}
if (apInfo) {
return apInfo->SSID;
}
else {
return TQByteArray();
}
}
else {
return TQByteArray();
@ -108,8 +146,26 @@ const TQByteArray WirelessNetwork::getSsid() const
TQString WirelessNetwork::getDisplaySsid() const
{
TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices();
TDEGlobalNetworkManager* nm = KGlobal::networkManager();
if (!d->aps.isEmpty()) {
return (*(d->aps.begin()))->friendlySSID();
TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(d->aps.begin().data()));
TDENetworkWiFiAPInfo* apInfo = NULL;
if (dev) {
TDENetworkConnectionManager* deviceConnMan = dev->connectionManager();
apInfo = deviceConnMan->findAccessPointByBSSID(d->aps.begin().key());
}
else if (d->aps.begin().data() == "") {
apInfo = nm->findAccessPointByBSSID(d->aps.begin().key());
}
if (apInfo) {
return apInfo->friendlySSID();
}
else {
return TQString();
}
}
else {
return TQString();
@ -118,30 +174,75 @@ TQString WirelessNetwork::getDisplaySsid() const
TDENetworkWiFiAPFlags::TDENetworkWiFiAPFlags WirelessNetwork::getFlags() const
{
TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices();
TDEGlobalNetworkManager* nm = KGlobal::networkManager();
TDENetworkWiFiAPFlags::TDENetworkWiFiAPFlags flags = TDENetworkWiFiAPFlags::None;
for (TQValueList<const TDENetworkWiFiAPInfo*>::Iterator it = d->aps.begin(); it != d->aps.end(); ++it) {
flags |= ((*it)->wpaFlags & TDENetworkWiFiAPFlags::GeneralFlagsMask);
flags |= ((*it)->rsnFlags & TDENetworkWiFiAPFlags::GeneralFlagsMask);
for (TQMap<TDEMACAddress,TQString>::Iterator it = d->aps.begin(); it != d->aps.end(); ++it) {
TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(it.data()));
TDENetworkWiFiAPInfo* apInfo = NULL;
if (dev) {
TDENetworkConnectionManager* deviceConnMan = dev->connectionManager();
apInfo = deviceConnMan->findAccessPointByBSSID(it.key());
}
else if (it.data() == "") {
apInfo = nm->findAccessPointByBSSID(it.key());
}
if (apInfo) {
flags |= (apInfo->wpaFlags & TDENetworkWiFiAPFlags::GeneralFlagsMask);
flags |= (apInfo->rsnFlags & TDENetworkWiFiAPFlags::GeneralFlagsMask);
}
}
return flags;
}
TDENetworkWiFiAPFlags::TDENetworkWiFiAPFlags WirelessNetwork::getWpaFlags() const
{
TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices();
TDEGlobalNetworkManager* nm = KGlobal::networkManager();
TDENetworkWiFiAPFlags::TDENetworkWiFiAPFlags flags = TDENetworkWiFiAPFlags::None;
for (TQValueList<const TDENetworkWiFiAPInfo*>::Iterator it = d->aps.begin(); it != d->aps.end(); ++it)
for (TQMap<TDEMACAddress,TQString>::Iterator it = d->aps.begin(); it != d->aps.end(); ++it)
{
flags |= ((*it)->wpaFlags & TDENetworkWiFiAPFlags::EncryptionFlagsMask);
TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(it.data()));
TDENetworkWiFiAPInfo* apInfo = NULL;
if (dev) {
TDENetworkConnectionManager* deviceConnMan = dev->connectionManager();
apInfo = deviceConnMan->findAccessPointByBSSID(it.key());
}
else if (it.data() == "") {
apInfo = nm->findAccessPointByBSSID(it.key());
}
if (apInfo) {
flags |= (apInfo->wpaFlags & TDENetworkWiFiAPFlags::EncryptionFlagsMask);
}
}
return flags;
}
TDENetworkWiFiAPFlags::TDENetworkWiFiAPFlags WirelessNetwork::getRsnFlags() const
{
TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices();
TDEGlobalNetworkManager* nm = KGlobal::networkManager();
TDENetworkWiFiAPFlags::TDENetworkWiFiAPFlags flags = TDENetworkWiFiAPFlags::None;
for (TQValueList<const TDENetworkWiFiAPInfo*>::Iterator it = d->aps.begin(); it != d->aps.end(); ++it)
for (TQMap<TDEMACAddress,TQString>::Iterator it = d->aps.begin(); it != d->aps.end(); ++it)
{
flags |= ((*it)->rsnFlags & TDENetworkWiFiAPFlags::EncryptionFlagsMask);
TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(it.data()));
TDENetworkWiFiAPInfo* apInfo = NULL;
if (dev) {
TDENetworkConnectionManager* deviceConnMan = dev->connectionManager();
apInfo = deviceConnMan->findAccessPointByBSSID(it.key());
}
else if (it.data() == "") {
apInfo = nm->findAccessPointByBSSID(it.key());
}
if (apInfo) {
flags |= (apInfo->rsnFlags & TDENetworkWiFiAPFlags::EncryptionFlagsMask);
}
}
return flags;
}
@ -153,10 +254,25 @@ bool WirelessNetwork::isEncrypted() const
TQ_UINT8 WirelessNetwork::getStrength() const
{
TDEHardwareDevices* hwdevices = KGlobal::hardwareDevices();
TDEGlobalNetworkManager* nm = KGlobal::networkManager();
TQ_UINT8 strength = 0;
for (TQValueList<const TDENetworkWiFiAPInfo*>::Iterator it = d->aps.begin(); it != d->aps.end(); ++it) {
if (((*it)->signalQuality*100.0) > strength) {
strength = ((*it)->signalQuality*100.0);
for (TQMap<TDEMACAddress,TQString>::Iterator it = d->aps.begin(); it != d->aps.end(); ++it) {
TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(hwdevices->findByUniqueID(it.data()));
TDENetworkWiFiAPInfo* apInfo = NULL;
if (dev) {
TDENetworkConnectionManager* deviceConnMan = dev->connectionManager();
apInfo = deviceConnMan->findAccessPointByBSSID(it.key());
}
else if (it.data() == "") {
apInfo = nm->findAccessPointByBSSID(it.key());
}
if (apInfo) {
if ((apInfo->signalQuality*100.0) > strength) {
strength = (apInfo->signalQuality*100.0);
}
}
}
return strength;

@ -57,10 +57,10 @@ class WirelessNetwork
WirelessNetwork& operator= (const WirelessNetwork&);
// check if the AccessPoint represents the same net
bool contains(const TDENetworkWiFiAPInfo * const);
bool contains(const TDEMACAddress);
// add an AP to the Network
bool addAP(const TDENetworkWiFiAPInfo * const);
bool addAP(const TDEMACAddress, const TQString);
// combined flags of all APs
TDENetworkWiFiAPFlags::TDENetworkWiFiAPFlags getFlags() const;

Loading…
Cancel
Save