summaryrefslogtreecommitdiffstats
path: root/knetworkmanager-0.8/src/knetworkmanager-wireless_manager.cpp
blob: c77d2ad872655ab6a6391758b5db3b4c9defc673 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/***************************************************************************
 *
 * knetworkmanager-wireless_manager.cpp - A NetworkManager frontend for KDE
 *
 * Copyright (C) 2005, 2006 Novell, Inc.
 *
 * Author: Helmut Schaa       <hschaa@suse.de>, <helmut.schaa@gmx.de>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 **************************************************************************/

// other includes
#include <time.h>

// QT DBus
#include <tqdbusobjectpath.h>

// KNM includes
#include "knetworkmanager-wireless_manager.h"
#include "knetworkmanager-wireless_device.h"
#include "knetworkmanager-wireless_network.h"
#include "knetworkmanager-accesspoint.h"
#include "knetworkmanager-connection_store.h"
#include "knetworkmanager-wireless_connection.h"
#include "knetworkmanager-connection_setting_info.h"
#include "knetworkmanager-connection_setting_wireless.h"
#include "knetworkmanager-connection_setting_wireless_security.h"
#include "knetworkmanager-nm_proxy.h"
#include "knetworkmanager-devicestore.h"

#if !defined(NM_CHECK_VERSION)
#define NM_CHECK_VERSION(x,y,z) 0
#endif

TQValueList<WirelessNetwork> WirelessManager::getWirelessNetworks(WirelessDevice* dev, TQ_UINT32 match)
{
	TQValueList<WirelessNetwork> nets;
	TQValueList<AccessPoint*> aps;
	// fetch all APs
	aps = WirelessManager::getAccessPoints(dev);
	
	// now group the APs together according to their security settings
	for (TQValueList<AccessPoint*>::Iterator apit = aps.begin(); apit != aps.end(); ++apit)
	{
		bool found = false;

		// no hidden APs
		AccessPoint * ap = *apit;
		if ( ap ) {
			if (!ap->isValid())
				continue;

			if (ap->getSsid().count() == 0)
				continue;

			// check if we have a network matching this AP
			for (TQValueList<WirelessNetwork>::Iterator netIt = nets.begin(); netIt != nets.end(); ++netIt)
			{
				if ((*netIt).contains(ap) )
				{
					// we alread have a network where this AP belongs to
					found = true;

					// attach this ap to the network
					(*netIt).addAP(ap);

					/*				// FIXME active?
									if (active_ap)
									{
					// here is the active_ap
					if (!(*net).getActive() && ((*ap) == *active_ap))
					(*net).setActive(true);
					}*/
					break;
				}
			}

			if (!found)
			{
				// create a new network-descriptor according to this ap
				WirelessNetwork net(match);
				net.addAP(ap);
				nets.append(net);
			}
		}
	}	
	return nets;
}

TQValueList<AccessPoint*> WirelessManager::getAccessPoints(WirelessDevice* dev)
{
	// build up AP list depending on one device or on all devices
	if (dev) {
		return dev->accessPoints();
	}
	else {
		TQValueList<AccessPoint *> aps;
		DeviceStore* store = DeviceStore::getInstance();
		if (store)
		{
#if NM_CHECK_VERSION(0,8,992)
			TQValueList<Device*> devs = store->getDevices(NM_DEVICE_TYPE_WIFI);
#else
			TQValueList<Device*> devs = store->getDevices(DEVICE_TYPE_802_11_WIRELESS);
#endif
			for (TQValueList<Device*>::Iterator it = devs.begin(); it != devs.end(); ++it)
			{
				WirelessDevice* wdev = dynamic_cast<WirelessDevice*>(*it);
				if (!wdev)
					continue;
				// add all APs from this device
				aps +=wdev->accessPoints();
			}
		}
		return aps;
	}
}

TQValueList<WirelessConnection*> WirelessManager::getWirelessConnections()
{
	TQValueList<WirelessConnection*> conns;
	ConnectionStore* store = ConnectionStore::getInstance();

	// get all wireless connections
	TQValueList<Connection*> connections = store->getConnections(NM_SETTING_WIRELESS_SETTING_NAME);
	for (TQValueList<Connection*>::Iterator it = connections.begin(); it != connections.end(); ++it)
	{
		// cast to WirelessConnection*
		WirelessConnection* wireless_conn = dynamic_cast<WirelessConnection*>(*it);
		if (!wireless_conn)
			continue;
		conns.append(wireless_conn);
	}
    return conns;
}

TQValueList<AccessPoint*> WirelessManager::getAccessPointsForEssid(TQByteArray essid, WirelessDevice* dev)
{
	// build up AP list depending on one device or on all devices
	if (dev)
		return dev->accessPointsForEssid(essid);
	else
	{
        TQValueList<AccessPoint*> aps;
		DeviceStore* store = DeviceStore::getInstance();
		if (store)
		{
#if NM_CHECK_VERSION(0,8,992)
			TQValueList<Device*> devs = store->getDevices(NM_DEVICE_TYPE_WIFI);
#else
			TQValueList<Device*> devs = store->getDevices(DEVICE_TYPE_802_11_WIRELESS);
#endif
			for (TQValueList<Device*>::Iterator it = devs.begin(); it != devs.end(); ++it)
			{
				WirelessDevice* wdev = dynamic_cast<WirelessDevice*>(*it);
				if (!wdev)
					continue;
				// add all APs from this device
				aps += wdev->accessPointsForEssid(essid);
			}
		}
        return aps;
	}
}