Qt 4.8
Public Functions | Private Slots | Properties | List of all members
QNativeWifiEngine Class Reference

#include <qnativewifiengine.h>

Inheritance diagram for QNativeWifiEngine:
QBearerEngineImpl QBearerEngine QObject

Public Functions

bool available ()
 
QNetworkConfigurationManager::Capabilities capabilities () const
 
void connectToId (const QString &id)
 
QNetworkSessionPrivatecreateSessionBackend ()
 
QNetworkConfigurationPrivatePointer defaultConfiguration ()
 
void disconnectFromId (const QString &id)
 
QString getInterfaceFromId (const QString &id)
 
bool hasIdentifier (const QString &id)
 
Q_INVOKABLE void initialize ()
 
 QNativeWifiEngine (QObject *parent=0)
 
Q_INVOKABLE void requestUpdate ()
 
bool requiresPolling () const
 
QNetworkSession::State sessionStateForId (const QString &id)
 
 ~QNativeWifiEngine ()
 
- Public Functions inherited from QBearerEngineImpl
virtual quint64 bytesReceived (const QString &)
 
virtual quint64 bytesWritten (const QString &)
 
 QBearerEngineImpl (QObject *parent=0)
 
virtual quint64 startTime (const QString &)
 
 ~QBearerEngineImpl ()
 
- Public Functions inherited from QBearerEngine
bool configurationsInUse () const
 
 QBearerEngine (QObject *parent=0)
 
virtual ~QBearerEngine ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Private Slots

void closeHandle ()
 
void scanComplete ()
 

Properties

Qt::HANDLE handle
 

Additional Inherited Members

- Public Types inherited from QBearerEngineImpl
enum  ConnectionError { InterfaceLookupError = 0, ConnectError, OperationNotSupported, DisconnectionError }
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QBearerEngineImpl
void connectionError (const QString &id, QBearerEngineImpl::ConnectionError error)
 
- Signals inherited from QBearerEngine
void configurationAdded (QNetworkConfigurationPrivatePointer config)
 
void configurationChanged (QNetworkConfigurationPrivatePointer config)
 
void configurationRemoved (QNetworkConfigurationPrivatePointer config)
 
void updateCompleted ()
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
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 receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QBearerEngine
QHash< QString, QNetworkConfigurationPrivatePointeraccessPointConfigurations
 
QMutex mutex
 
QHash< QString, QNetworkConfigurationPrivatePointersnapConfigurations
 
QHash< QString, QNetworkConfigurationPrivatePointeruserChoiceConfigurations
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 67 of file qnativewifiengine.h.

Constructors and Destructors

◆ QNativeWifiEngine()

QNativeWifiEngine::QNativeWifiEngine ( QObject parent = 0)

Definition at line 93 of file qnativewifiengine.cpp.

94 : QBearerEngineImpl(parent), handle(INVALID_HANDLE_VALUE)
95 {
96  connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(closeHandle()));
97 }
QBearerEngineImpl(QObject *parent=0)
#define SLOT(a)
Definition: qobjectdefs.h:226
#define SIGNAL(a)
Definition: qobjectdefs.h:227
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...
Definition: qobject.cpp:2580
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.

◆ ~QNativeWifiEngine()

QNativeWifiEngine::~QNativeWifiEngine ( )

Definition at line 99 of file qnativewifiengine.cpp.

100 {
101  closeHandle();
102 }

Functions

◆ available()

bool QNativeWifiEngine::available ( )

Definition at line 577 of file qnativewifiengine.cpp.

Referenced by connectToId(), QNativeWifiEnginePlugin::create(), disconnectFromId(), getInterfaceFromId(), hasIdentifier(), requestUpdate(), and scanComplete().

578 {
579  if (handle != INVALID_HANDLE_VALUE)
580  return true;
581 
582  DWORD clientVersion;
583 
584  DWORD result = local_WlanOpenHandle(1, 0, &clientVersion, &handle);
585  if (result != ERROR_SUCCESS) {
586 #ifdef BEARER_MANAGEMENT_DEBUG
587  if (result != ERROR_SERVICE_NOT_ACTIVE)
588  qDebug("%s: WlanOpenHandle failed with error %ld\n", __FUNCTION__, result);
589 #endif
590 
591  return false;
592  }
593 
596  this, 0, 0);
597 #ifdef BEARER_MANAGEMENT_DEBUG
598  if (result != ERROR_SUCCESS)
599  qDebug("%s: WlanRegisterNotification failed with error %ld\n", __FUNCTION__, result);
600 #endif
601 
602  return handle != INVALID_HANDLE_VALUE;
603 }
WlanRegisterNotificationProto local_WlanRegisterNotification
WlanOpenHandleProto local_WlanOpenHandle
void(WINAPI * WLAN_NOTIFICATION_CALLBACK)(WLAN_NOTIFICATION_DATA *, PVOID)
Definition: platformdefs.h:289
Q_CORE_EXPORT void qDebug(const char *,...)
void qNotificationCallback(WLAN_NOTIFICATION_DATA *data, QNativeWifiEngine *d)
#define WLAN_NOTIFICATION_SOURCE_ALL
Definition: platformdefs.h:53

◆ capabilities()

QNetworkConfigurationManager::Capabilities QNativeWifiEngine::capabilities ( ) const
virtual

◆ closeHandle

void QNativeWifiEngine::closeHandle ( )
privateslot

Definition at line 605 of file qnativewifiengine.cpp.

Referenced by QNativeWifiEngine(), and ~QNativeWifiEngine().

606 {
607  if (handle != INVALID_HANDLE_VALUE) {
609  handle = INVALID_HANDLE_VALUE;
610  }
611 }
WlanCloseHandleProto local_WlanCloseHandle

◆ connectToId()

void QNativeWifiEngine::connectToId ( const QString id)
virtual

Implements QBearerEngineImpl.

Definition at line 364 of file qnativewifiengine.cpp.

365 {
366  QMutexLocker locker(&mutex);
367 
368  if (!available()) {
369  locker.unlock();
371  return;
372  }
373 
374  WLAN_INTERFACE_INFO_LIST *interfaceList;
375  DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList);
376  if (result != ERROR_SUCCESS) {
377 #ifdef BEARER_MANAGEMENT_DEBUG
378  qDebug("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result);
379 #endif
380  locker.unlock();
382  return;
383  }
384 
385  QString profile;
386 
387  for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) {
388  const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i];
389 
390  WLAN_AVAILABLE_NETWORK_LIST *networkList;
391  result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid,
392  3, 0, &networkList);
393  if (result != ERROR_SUCCESS) {
394 #ifdef BEARER_MANAGEMENT_DEBUG
395  qDebug("%s: WlanGetAvailableNetworkList failed with error %ld\n",
396  __FUNCTION__, result);
397 #endif
398  continue;
399  }
400 
401  for (unsigned int j = 0; j < networkList->dwNumberOfItems; ++j) {
402  WLAN_AVAILABLE_NETWORK &network = networkList->Network[j];
403 
404  profile = QString::fromWCharArray(network.strProfileName);
405 
406  if (qHash(QLatin1String("WLAN:") + profile) == id.toUInt())
407  break;
408  else
409  profile.clear();
410  }
411 
412  local_WlanFreeMemory(networkList);
413 
414  if (!profile.isEmpty()) {
415  WLAN_CONNECTION_PARAMETERS parameters;
417  parameters.strProfile = reinterpret_cast<LPCWSTR>(profile.utf16());
418  parameters.pDot11Ssid = 0;
419  parameters.pDesiredBssidList = 0;
420  parameters.dot11BssType = dot11_BSS_type_any;
421  parameters.dwFlags = 0;
422 
423  DWORD result = local_WlanConnect(handle, &interface.InterfaceGuid, &parameters, 0);
424  if (result != ERROR_SUCCESS) {
425 #ifdef BEARER_MANAGEMENT_DEBUG
426  qDebug("%s: WlanConnect failed with error %ld\n", __FUNCTION__, result);
427 #endif
428  locker.unlock();
430  locker.relock();
431  break;
432  }
433 
434  break;
435  }
436  }
437 
438  local_WlanFreeMemory(interfaceList);
439 
440  if (profile.isEmpty()) {
441  locker.unlock();
443  }
444 }
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...
Definition: qstring.cpp:1019
uint qHash(const QProcEnvKey &key)
Definition: qprocess_p.h:96
DOT11_BSS_TYPE dot11BssType
Definition: platformdefs.h:227
DOT11_BSSID_LIST * pDesiredBssidList
Definition: platformdefs.h:226
WCHAR strProfileName[WLAN_MAX_NAME_LENGTH]
Definition: platformdefs.h:156
WLAN_CONNECTION_MODE wlanConnectionMode
Definition: platformdefs.h:223
WlanConnectProto local_WlanConnect
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_CORE_EXPORT void qDebug(const char *,...)
WlanGetAvailableNetworkListProto local_WlanGetAvailableNetworkList
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define emit
Definition: qobjectdefs.h:76
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
void connectionError(const QString &id, QBearerEngineImpl::ConnectionError error)
WlanFreeMemoryProto local_WlanFreeMemory
WlanEnumInterfacesProto local_WlanEnumInterfaces
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ createSessionBackend()

QNetworkSessionPrivate * QNativeWifiEngine::createSessionBackend ( )
virtual

Implements QBearerEngine.

Definition at line 567 of file qnativewifiengine.cpp.

◆ defaultConfiguration()

QNetworkConfigurationPrivatePointer QNativeWifiEngine::defaultConfiguration ( )
virtual

Implements QBearerEngine.

Definition at line 572 of file qnativewifiengine.cpp.

573 {
575 }
QExplicitlySharedDataPointer< QNetworkConfigurationPrivate > QNetworkConfigurationPrivatePointer

◆ disconnectFromId()

void QNativeWifiEngine::disconnectFromId ( const QString id)
virtual

Implements QBearerEngineImpl.

Definition at line 446 of file qnativewifiengine.cpp.

447 {
448  QMutexLocker locker(&mutex);
449 
450  if (!available()) {
451  locker.unlock();
453  return;
454  }
455 
456  QString interface = getInterfaceFromId(id);
457 
458  if (interface.isEmpty()) {
459  locker.unlock();
461  return;
462  }
463 
464  QStringList split = interface.mid(1, interface.length() - 2).split('-');
465 
466  GUID guid;
467  guid.Data1 = split.at(0).toUInt(0, 16);
468  guid.Data2 = split.at(1).toUShort(0, 16);
469  guid.Data3 = split.at(2).toUShort(0, 16);
470  guid.Data4[0] = split.at(3).left(2).toUShort(0, 16);
471  guid.Data4[1] = split.at(3).right(2).toUShort(0, 16);
472  for (int i = 0; i < 6; ++i)
473  guid.Data4[i + 2] = split.at(4).mid(i*2, 2).toUShort(0, 16);
474 
475  DWORD result = local_WlanDisconnect(handle, &guid, 0);
476  if (result != ERROR_SUCCESS) {
477 #ifdef BEARER_MANAGEMENT_DEBUG
478  qDebug("%s: WlanDisconnect failed with error %ld\n", __FUNCTION__, result);
479 #endif
480  locker.unlock();
482  return;
483  }
484 }
WlanDisconnectProto local_WlanDisconnect
Definition: quuid.h:52
ulong Data1
Definition: quuid.h:54
ushort toUShort(bool *ok=0, int base=10) const
Returns the string converted to an unsigned short using base base, which is 10 by default and must be...
Definition: qstring.cpp:6180
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_CORE_EXPORT void qDebug(const char *,...)
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static void split(QT_FT_Vector *b)
QString right(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n rightmost characters of the string.
Definition: qstring.cpp:3682
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
uchar Data4[8]
Definition: quuid.h:57
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...
Definition: qstring.cpp:6120
ushort Data3
Definition: quuid.h:56
void connectionError(const QString &id, QBearerEngineImpl::ConnectionError error)
ushort Data2
Definition: quuid.h:55

◆ getInterfaceFromId()

QString QNativeWifiEngine::getInterfaceFromId ( const QString id)
virtual

Implements QBearerEngineImpl.

Definition at line 248 of file qnativewifiengine.cpp.

249 {
250  QMutexLocker locker(&mutex);
251 
252  if (!available())
253  return QString();
254 
255  // enumerate interfaces
256  WLAN_INTERFACE_INFO_LIST *interfaceList;
257  DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList);
258  if (result != ERROR_SUCCESS) {
259 #ifdef BEARER_MANAGEMENT_DEBUG
260  qDebug("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result);
261 #endif
262  return QString();
263  }
264 
265  for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) {
266  const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i];
267 
268  DWORD dataSize;
269  WLAN_CONNECTION_ATTRIBUTES *connectionAttributes;
270  result = local_WlanQueryInterface(handle, &interface.InterfaceGuid,
272  reinterpret_cast<PVOID *>(&connectionAttributes), 0);
273  if (result != ERROR_SUCCESS) {
274 #ifdef BEARER_MANAGEMENT_DEBUG
275  if (result != ERROR_INVALID_STATE)
276  qDebug("%s: WlanQueryInterface failed with error %ld\n", __FUNCTION__, result);
277 #endif
278 
279  continue;
280  }
281 
282  if (qHash(QLatin1String("WLAN:") +
283  QString::fromWCharArray(connectionAttributes->strProfileName)) == id.toUInt()) {
284  QString guid("{%1-%2-%3-%4%5-%6%7%8%9%10%11}");
285 
286  guid = guid.arg(interface.InterfaceGuid.Data1, 8, 16, QChar('0'));
287  guid = guid.arg(interface.InterfaceGuid.Data2, 4, 16, QChar('0'));
288  guid = guid.arg(interface.InterfaceGuid.Data3, 4, 16, QChar('0'));
289  for (int i = 0; i < 8; ++i)
290  guid = guid.arg(interface.InterfaceGuid.Data4[i], 2, 16, QChar('0'));
291 
292  local_WlanFreeMemory(connectionAttributes);
293  local_WlanFreeMemory(interfaceList);
294 
295  return guid.toUpper();
296  }
297 
298  local_WlanFreeMemory(connectionAttributes);
299  }
300 
301  local_WlanFreeMemory(interfaceList);
302 
303  return QString();
304 }
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...
Definition: qstring.cpp:1019
uint qHash(const QProcEnvKey &key)
Definition: qprocess_p.h:96
WlanQueryInterfaceProto local_WlanQueryInterface
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
WCHAR strProfileName[WLAN_MAX_NAME_LENGTH]
Definition: platformdefs.h:284
Q_CORE_EXPORT void qDebug(const char *,...)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
WlanFreeMemoryProto local_WlanFreeMemory
WlanEnumInterfacesProto local_WlanEnumInterfaces

◆ hasIdentifier()

bool QNativeWifiEngine::hasIdentifier ( const QString id)
virtual

Implements QBearerEngine.

Definition at line 306 of file qnativewifiengine.cpp.

307 {
308  QMutexLocker locker(&mutex);
309 
310  if (!available())
311  return false;
312 
313  // enumerate interfaces
314  WLAN_INTERFACE_INFO_LIST *interfaceList;
315  DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList);
316  if (result != ERROR_SUCCESS) {
317 #ifdef BEARER_MANAGEMENT_DEBUG
318  qDebug("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result);
319 #endif
320  return false;
321  }
322 
323  for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) {
324  const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i];
325 
326  WLAN_AVAILABLE_NETWORK_LIST *networkList;
327  result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid,
328  3, 0, &networkList);
329  if (result != ERROR_SUCCESS) {
330 #ifdef BEARER_MANAGEMENT_DEBUG
331  qDebug("%s: WlanGetAvailableNetworkList failed with error %ld\n",
332  __FUNCTION__, result);
333 #endif
334  continue;
335  }
336 
337  for (unsigned int j = 0; j < networkList->dwNumberOfItems; ++j) {
338  WLAN_AVAILABLE_NETWORK &network = networkList->Network[j];
339 
340  QString networkName;
341 
342  if (network.strProfileName[0] != 0) {
343  networkName = QString::fromWCharArray(network.strProfileName);
344  } else {
345  networkName = QByteArray(reinterpret_cast<char *>(network.dot11Ssid.ucSSID),
346  network.dot11Ssid.uSSIDLength);
347  }
348 
349  if (qHash(QLatin1String("WLAN:") + networkName) == id.toUInt()) {
350  local_WlanFreeMemory(networkList);
351  local_WlanFreeMemory(interfaceList);
352  return true;
353  }
354  }
355 
356  local_WlanFreeMemory(networkList);
357  }
358 
359  local_WlanFreeMemory(interfaceList);
360 
361  return false;
362 }
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...
Definition: qstring.cpp:1019
uint qHash(const QProcEnvKey &key)
Definition: qprocess_p.h:96
WCHAR strProfileName[WLAN_MAX_NAME_LENGTH]
Definition: platformdefs.h:156
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
UCHAR ucSSID[DOT11_SSID_MAX_LENGTH]
Definition: platformdefs.h:93
Q_CORE_EXPORT void qDebug(const char *,...)
WlanGetAvailableNetworkListProto local_WlanGetAvailableNetworkList
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
ULONG uSSIDLength
Definition: platformdefs.h:92
WlanFreeMemoryProto local_WlanFreeMemory
WlanEnumInterfacesProto local_WlanEnumInterfaces

◆ initialize()

void QNativeWifiEngine::initialize ( )

Definition at line 486 of file qnativewifiengine.cpp.

487 {
488  scanComplete();
489 }

◆ requestUpdate()

void QNativeWifiEngine::requestUpdate ( )

Definition at line 491 of file qnativewifiengine.cpp.

492 {
493  QMutexLocker locker(&mutex);
494 
495  if (!available()) {
496  locker.unlock();
498  return;
499  }
500 
501  // enumerate interfaces
502  WLAN_INTERFACE_INFO_LIST *interfaceList;
503  DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList);
504  if (result != ERROR_SUCCESS) {
505 #ifdef BEARER_MANAGEMENT_DEBUG
506  qDebug("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result);
507 #endif
508 
509  locker.unlock();
511 
512  return;
513  }
514 
515  bool requested = false;
516  for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) {
517  result = local_WlanScan(handle, &interfaceList->InterfaceInfo[i].InterfaceGuid, 0, 0, 0);
518  if (result != ERROR_SUCCESS) {
519 #ifdef BEARER_MANAGEMENT_DEBUG
520  qDebug("%s: WlanScan failed with error %ld\n", __FUNCTION__, result);
521 #endif
522  } else {
523  requested = true;
524  }
525  }
526 
527  local_WlanFreeMemory(interfaceList);
528 
529  if (!requested) {
530  locker.unlock();
532  }
533 }
void updateCompleted()
Q_CORE_EXPORT void qDebug(const char *,...)
#define emit
Definition: qobjectdefs.h:76
WLAN_INTERFACE_INFO InterfaceInfo[1]
Definition: platformdefs.h:88
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
WlanFreeMemoryProto local_WlanFreeMemory
WlanScanProto local_WlanScan
WlanEnumInterfacesProto local_WlanEnumInterfaces

◆ requiresPolling()

bool QNativeWifiEngine::requiresPolling ( ) const
virtual

Reimplemented from QBearerEngine.

Definition at line 613 of file qnativewifiengine.cpp.

614 {
615  // On Windows XP SP2 and SP3 only connection and disconnection notifications are available.
616  // We need to poll for changes in available wireless networks.
617  return true;
618 }

◆ scanComplete

void QNativeWifiEngine::scanComplete ( )
privateslot

Definition at line 104 of file qnativewifiengine.cpp.

Referenced by initialize().

105 {
106  QMutexLocker locker(&mutex);
107 
108  if (!available()) {
109  locker.unlock();
111  return;
112  }
113 
114  // enumerate interfaces
115  WLAN_INTERFACE_INFO_LIST *interfaceList;
116  DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList);
117  if (result != ERROR_SUCCESS) {
118 #ifdef BEARER_MANAGEMENT_DEBUG
119  qDebug("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result);
120 #endif
121 
122  locker.unlock();
124 
125  return;
126  }
127 
128  QStringList previous = accessPointConfigurations.keys();
129 
130  for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) {
131  const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i];
132 
133  WLAN_AVAILABLE_NETWORK_LIST *networkList;
134  result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid,
135  3, 0, &networkList);
136  if (result != ERROR_SUCCESS) {
137 #ifdef BEARER_MANAGEMENT_DEBUG
138  qDebug("%s: WlanGetAvailableNetworkList failed with error %ld\n",
139  __FUNCTION__, result);
140 #endif
141  continue;
142  }
143 
144  QStringList seenNetworks;
145 
146  for (unsigned int j = 0; j < networkList->dwNumberOfItems; ++j) {
147  WLAN_AVAILABLE_NETWORK &network = networkList->Network[j];
148 
149  QString networkName;
150 
151  if (network.strProfileName[0] != 0) {
152  networkName = QString::fromWCharArray(network.strProfileName);
153  } else {
154  networkName = QByteArray(reinterpret_cast<char *>(network.dot11Ssid.ucSSID),
155  network.dot11Ssid.uSSIDLength);
156  }
157 
158  const QString id = QString::number(qHash(QLatin1String("WLAN:") + networkName));
159 
160  previous.removeAll(id);
161 
162  QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined;
163 
166 
167  if (network.strProfileName[0] != 0) {
168  if (network.bNetworkConnectable) {
171  else
173  } else {
175  }
176  }
177 
178  if (seenNetworks.contains(networkName))
179  continue;
180  else
181  seenNetworks.append(networkName);
182 
183  if (accessPointConfigurations.contains(id)) {
185 
186  bool changed = false;
187 
188  ptr->mutex.lock();
189 
190  if (!ptr->isValid) {
191  ptr->isValid = true;
192  changed = true;
193  }
194 
195  if (ptr->name != networkName) {
196  ptr->name = networkName;
197  changed = true;
198  }
199 
200  if (ptr->state != state) {
201  ptr->state = state;
202  changed = true;
203  }
204 
205  ptr->mutex.unlock();
206 
207  if (changed) {
208  locker.unlock();
210  locker.relock();
211  }
212  } else {
214 
215  ptr->name = networkName;
216  ptr->isValid = true;
217  ptr->id = id;
218  ptr->state = state;
221 
222  accessPointConfigurations.insert(id, ptr);
223 
224  locker.unlock();
226  locker.relock();
227  }
228  }
229 
230  local_WlanFreeMemory(networkList);
231  }
232 
233  local_WlanFreeMemory(interfaceList);
234 
235  while (!previous.isEmpty()) {
237  accessPointConfigurations.take(previous.takeFirst());
238 
239  locker.unlock();
241  locker.relock();
242  }
243 
244  locker.unlock();
246 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
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...
Definition: qstring.cpp:1019
uint qHash(const QProcEnvKey &key)
Definition: qprocess_p.h:96
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
#define WLAN_AVAILABLE_NETWORK_CONNECTED
Definition: platformdefs.h:54
WCHAR strProfileName[WLAN_MAX_NAME_LENGTH]
Definition: platformdefs.h:156
QNetworkConfiguration::StateFlags state
void configurationChanged(QNetworkConfigurationPrivatePointer config)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void updateCompleted()
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define WLAN_AVAILABLE_NETWORK_HAS_PROFILE
Definition: platformdefs.h:55
The QString class provides a Unicode character string.
Definition: qstring.h:83
UCHAR ucSSID[DOT11_SSID_MAX_LENGTH]
Definition: platformdefs.h:93
QNetworkConfiguration::BearerType bearerType
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
Q_CORE_EXPORT void qDebug(const char *,...)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
WlanGetAvailableNetworkListProto local_WlanGetAvailableNetworkList
QHash< QString, QNetworkConfigurationPrivatePointer > accessPointConfigurations
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
#define emit
Definition: qobjectdefs.h:76
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
void configurationAdded(QNetworkConfigurationPrivatePointer config)
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
const T * ptr(const T &t)
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QNetworkConfiguration::Type type
void configurationRemoved(QNetworkConfigurationPrivatePointer config)
ULONG uSSIDLength
Definition: platformdefs.h:92
WlanFreeMemoryProto local_WlanFreeMemory
WlanEnumInterfacesProto local_WlanEnumInterfaces
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770

◆ sessionStateForId()

QNetworkSession::State QNativeWifiEngine::sessionStateForId ( const QString id)
virtual

Implements QBearerEngineImpl.

Definition at line 535 of file qnativewifiengine.cpp.

536 {
537  QMutexLocker locker(&mutex);
538 
540 
541  if (!ptr)
543 
544  if (!ptr->isValid) {
548  } else if ((ptr->state & QNetworkConfiguration::Discovered) ==
553  } else if ((ptr->state & QNetworkConfiguration::Undefined) ==
556  }
557 
559 }
QNetworkConfiguration::StateFlags state
QHash< QString, QNetworkConfigurationPrivatePointer > accessPointConfigurations
const T * ptr(const T &t)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

Properties

◆ handle

Qt::HANDLE QNativeWifiEngine::handle
private

The documentation for this class was generated from the following files: