43 #include "../qnetworksession_impl.h" 45 #include <QtNetwork/private/qnetworkconfiguration_p.h> 47 #include <QtCore/qthread.h> 48 #include <QtCore/qmutex.h> 49 #include <QtCore/qcoreapplication.h> 50 #include <QtCore/qstringlist.h> 52 #include <QtCore/qdebug.h> 54 #include "../platformdefs_win.h" 65 if (WSAStartup(MAKEWORD(2,0), &wsadata) != 0) {
66 qWarning(
"QBearerManagementAPI: WinSock v2.0 initialization failed.");
77 #ifdef BEARER_MANAGEMENT_DEBUG 78 static void printBlob(
NLA_BLOB *blob)
80 qDebug() <<
"==== BEGIN NLA_BLOB ====";
98 qDebug() <<
"802.1x Location";
102 qDebug() <<
"Connectivity";
111 qDebug() <<
"\tmachine name:" << blob->
data.
ICS.remote.machineName;
112 qDebug() <<
"\tshared adapter name:" << blob->
data.
ICS.remote.sharedAdapterName;
115 qDebug() <<
"UNKNOWN BLOB TYPE";
118 qDebug() <<
"===== END NLA_BLOB =====";
134 FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
135 if (handle == INVALID_HANDLE_VALUE)
141 &medium,
sizeof(medium), &bytesWritten, 0);
150 &physicalMedium,
sizeof(physicalMedium), &bytesWritten, 0);
163 switch (physicalMedium) {
171 #ifdef BEARER_MANAGEMENT_DEBUG 172 qDebug() <<
"Physical Medium" << physicalMedium;
178 #ifdef BEARER_MANAGEMENT_DEBUG 179 qDebug() << medium << physicalMedium;
206 void fetchConfigurations();
209 void networksChanged();
231 if (WSALookupServiceEnd(
handle) == SOCKET_ERROR) {
232 #ifdef BEARER_MANAGEMENT_DEBUG 233 qDebug(
"WSALookupServiceEnd error %d", WSAGetLastError());
249 return foundConfigurations;
258 if (WSALookupServiceEnd(
handle) == SOCKET_ERROR) {
259 #ifdef BEARER_MANAGEMENT_DEBUG 260 qDebug(
"WSALookupServiceEnd error %d", WSAGetLastError());
270 WSAEVENT changeEvent = WSACreateEvent();
271 if (changeEvent == WSA_INVALID_EVENT)
277 WSAQUERYSET qsRestrictions;
279 memset(&qsRestrictions, 0,
sizeof(qsRestrictions));
280 qsRestrictions.dwSize =
sizeof(qsRestrictions);
281 qsRestrictions.dwNameSpace =
NS_NLA;
288 int result = WSALookupServiceBegin(&qsRestrictions, LUP_RETURN_ALL, &
handle);
291 if (result == SOCKET_ERROR)
294 WSACOMPLETION completion;
295 WSAOVERLAPPED overlapped;
297 memset(&overlapped, 0,
sizeof(overlapped));
298 overlapped.hEvent = changeEvent;
300 memset(&completion, 0,
sizeof(completion));
301 completion.Type = NSP_NOTIFY_EVENT;
302 completion.Parameters.Event.lpOverlapped = &overlapped;
304 DWORD bytesReturned = 0;
305 result = WSANSPIoctl(
handle, SIO_NSP_NOTIFY_CHANGE, 0, 0, 0, 0,
306 &bytesReturned, &completion);
307 if (result == SOCKET_ERROR) {
308 if (WSAGetLastError() != WSA_IO_PENDING)
315 while (WaitForSingleObjectEx(changeEvent, WSA_INFINITE,
true) != WAIT_IO_COMPLETION &&
320 WaitForSingleObject(changeEvent, WSA_INFINITE);
325 result = WSALookupServiceEnd(
handle);
326 if (result == SOCKET_ERROR) {
335 WSACloseEvent(changeEvent);
354 #ifdef BEARER_MANAGEMENT_DEBUG 360 #ifdef BEARER_MANAGEMENT_DEBUG 361 qDebug(
"%s: unhandled header type NLA_RAW_DATA", __FUNCTION__);
367 engine->configurationInterface[cpPriv->
id.
toUInt()] =
372 #ifdef BEARER_MANAGEMENT_DEBUG 373 qDebug(
"%s: unhandled header type NLA_802_1X_LOCATION", __FUNCTION__);
377 #ifdef BEARER_MANAGEMENT_DEBUG 378 qDebug(
"%s: unhandled header type NLA_CONNECTIVITY", __FUNCTION__);
382 #ifdef BEARER_MANAGEMENT_DEBUG 383 qDebug(
"%s: unhandled header type NLA_ICS", __FUNCTION__);
387 #ifdef BEARER_MANAGEMENT_DEBUG 406 #ifdef BEARER_MANAGEMENT_DEBUG 407 qDebug() <<
"size:" << querySet->dwSize;
409 qDebug() <<
"service class id:" << querySet->lpServiceClassId;
410 qDebug() <<
"version:" << querySet->lpVersion;
412 qDebug() <<
"namespace:" << querySet->dwNameSpace;
413 qDebug() <<
"namespace provider id:" << querySet->lpNSProviderId;
415 qDebug() <<
"number of protocols:" << querySet->dwNumberOfProtocols;
416 qDebug() <<
"protocols:" << querySet->lpafpProtocols;
418 qDebug() <<
"number of cs addresses:" << querySet->dwNumberOfCsAddrs;
419 qDebug() <<
"cs addresses:" << querySet->lpcsaBuffer;
420 qDebug() <<
"output flags:" << querySet->dwOutputFlags;
423 if (querySet->lpBlob) {
424 #ifdef BEARER_MANAGEMENT_DEBUG 425 qDebug() <<
"blob size:" << querySet->lpBlob->cbSize;
426 qDebug() <<
"blob data:" << querySet->lpBlob->pBlobData;
431 NLA_BLOB *blob =
reinterpret_cast<NLA_BLOB *
>(querySet->lpBlob->pBlobData + offset);
432 DWORD nextOffset =
parseBlob(blob, cpPriv);
433 if (nextOffset == offset)
437 }
while (offset != 0 && offset < querySet->lpBlob->cbSize);
441 const QString interface = engine->getInterfaceFromId(cpPriv->id);
452 WSAQUERYSET qsRestrictions;
455 memset(&qsRestrictions, 0,
sizeof(qsRestrictions));
456 qsRestrictions.dwSize =
sizeof(qsRestrictions);
457 qsRestrictions.dwNameSpace =
NS_NLA;
459 int result = WSALookupServiceBegin(&qsRestrictions, LUP_RETURN_ALL | LUP_DEEP, &hLookup);
460 if (result == SOCKET_ERROR) {
466 char buffer[0x10000];
467 while (result == 0) {
468 DWORD bufferLength =
sizeof(buffer);
469 result = WSALookupServiceNext(hLookup, LUP_RETURN_ALL,
470 &bufferLength, reinterpret_cast<WSAQUERYSET *>(buffer));
472 if (result == SOCKET_ERROR)
478 foundConfigurations.
append(cpPriv);
482 result = WSALookupServiceEnd(hLookup);
483 if (result == SOCKET_ERROR) {
484 #ifdef BEARER_MANAGEMENT_DEBUG 485 qDebug(
"WSALookupServiceEnd error %d", WSAGetLastError());
516 while (!foundConfigurations.
isEmpty()) {
524 bool changed =
false;
648 #include "qnlaengine.moc" BearerType
Specifies the type of bearer used by a configuration.
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
uint qHash(const QProcEnvKey &key)
QMap< uint, QString > configurationInterface
void connectToId(const QString &id)
void updateConfigurations(QList< QNetworkConfigurationPrivate *> &configs)
#define QT_END_NAMESPACE
This macro expands to.
void lock()
Locks the mutex.
The QMutex class provides access serialization between threads.
QNetworkConfiguration::StateFlags state
void configurationChanged(QNetworkConfigurationPrivatePointer config)
void disconnectFromId(const QString &id)
QList< QNetworkConfigurationPrivate * > getConfigurations()
DWORD parseBlob(NLA_BLOB *blob, QNetworkConfigurationPrivate *cpPriv) const
QNetworkConfigurationPrivate * parseQuerySet(const WSAQUERYSET *querySet) const
void unlock()
Unlocks this mutex locker.
State
This enum describes the connectivity state of the session.
bool hasIdentifier(const QString &id)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
struct NLA_BLOB::@336::@340 ICS
The QObject class is the base class of all Qt objects.
static QNetworkConfiguration::BearerType qGetInterfaceType(const QString &interface)
QNetworkConfigurationManager::Capabilities capabilities() const
QNetworkSession::State sessionStateForId(const QString &id)
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
QList< QNetworkConfigurationPrivate * > fetchedConfigurations
void relock()
Relocks an unlocked mutex locker.
Q_CORE_EXPORT void qDebug(const char *,...)
void append(const T &t)
Inserts value at the end of the list.
#define QT_BEGIN_NAMESPACE
This macro expands to.
struct NLA_BLOB::@336::@337 interfaceData
QHash< QString, QNetworkConfigurationPrivatePointer > accessPointConfigurations
union NLA_BLOB::@336 data
T takeFirst()
Removes the first item in the list and returns it.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
const T value(const Key &key) const
Returns the value associated with the key key.
The QStringList class provides a list of strings.
void configurationAdded(QNetworkConfigurationPrivatePointer config)
Q_CORE_EXPORT void qWarning(const char *,...)
QNlaThread(QNlaEngine *parent=0)
QNetworkConfigurationPrivatePointer defaultConfiguration()
const T * ptr(const T &t)
void clear()
Removes all items from the list.
QNetworkSessionPrivate * createSessionBackend()
void unlock()
Unlocks the mutex.
struct NLA_BLOB::@335 header
virtual void run()
The starting point for the thread.
QString getInterfaceFromId(const QString &id)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
QExplicitlySharedDataPointer< QNetworkConfigurationPrivate > QNetworkConfigurationPrivatePointer
struct NLA_BLOB::@336::@338 locationData
QNetworkConfiguration::Type type
void fetchConfigurations()
void start(Priority=InheritPriority)
Begins execution of the thread by calling run().
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
QObject * parent() const
Returns a pointer to the parent object.
bool wait(unsigned long time=ULONG_MAX)
Blocks the thread until either of these conditions is met:
void configurationRemoved(QNetworkConfigurationPrivatePointer config)
uint toUInt(bool *ok=0, int base=10) const
Returns the string converted to an unsigned int using base base, which is 10 by default and must be b...
bool contains(const Key &key) const
Returns true if the map contains an item with key key; otherwise returns false.
Q_INVOKABLE void requestUpdate()
QFuture< T > run(Function function,...)
void connectionError(const QString &id, QBearerEngineImpl::ConnectionError error)
The QThread class provides a platform-independent way to manage threads.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
struct NLA_BLOB::@336::@339 connectivity
static QString fromUtf16(const ushort *, int size=-1)
Returns a QString initialized with the first size characters of the Unicode string unicode (ISO-10646...
The QList class is a template class that provides lists.
QNlaEngine(QObject *parent=0)
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.