src/plugins/bearer/nla/qnlaengine.cpp
changeset 37 758a864f9613
parent 30 5dc02b23752f
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
   117 
   117 
   118     qDebug() << "===== END NLA_BLOB =====";
   118     qDebug() << "===== END NLA_BLOB =====";
   119 }
   119 }
   120 #endif
   120 #endif
   121 
   121 
   122 static QString qGetInterfaceType(const QString &interface)
   122 static QNetworkConfiguration::BearerType qGetInterfaceType(const QString &interface)
   123 {
   123 {
   124 #ifdef Q_OS_WINCE
   124 #ifdef Q_OS_WINCE
   125     Q_UNUSED(interface)
   125     Q_UNUSED(interface)
   126 #else
   126 #else
   127     unsigned long oid;
   127     unsigned long oid;
   128     DWORD bytesWritten;
   128     DWORD bytesWritten;
   129 
   129 
   130     NDIS_MEDIUM medium;
   130     NDIS_MEDIUM medium;
   131     NDIS_PHYSICAL_MEDIUM physicalMedium;
   131     NDIS_PHYSICAL_MEDIUM physicalMedium;
   132 
   132 
   133     HANDLE handle = CreateFile((TCHAR *)QString(QLatin1String("\\\\.\\%1")).arg(interface).utf16(),
   133     HANDLE handle = CreateFile((TCHAR *)QString::fromLatin1("\\\\.\\%1").arg(interface).utf16(), 0,
   134                                0, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
   134                                FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
   135     if (handle == INVALID_HANDLE_VALUE)
   135     if (handle == INVALID_HANDLE_VALUE)
   136         return QLatin1String("Unknown");
   136         return QNetworkConfiguration::BearerUnknown;
   137 
   137 
   138     oid = OID_GEN_MEDIA_SUPPORTED;
   138     oid = OID_GEN_MEDIA_SUPPORTED;
   139     bytesWritten = 0;
   139     bytesWritten = 0;
   140     bool result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid),
   140     bool result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid),
   141                                   &medium, sizeof(medium), &bytesWritten, 0);
   141                                   &medium, sizeof(medium), &bytesWritten, 0);
   142     if (!result) {
   142     if (!result) {
   143         CloseHandle(handle);
   143         CloseHandle(handle);
   144         return QLatin1String("Unknown");
   144         return QNetworkConfiguration::BearerUnknown;
   145     }
   145     }
   146 
   146 
   147     oid = OID_GEN_PHYSICAL_MEDIUM;
   147     oid = OID_GEN_PHYSICAL_MEDIUM;
   148     bytesWritten = 0;
   148     bytesWritten = 0;
   149     result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid),
   149     result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid),
   150                              &physicalMedium, sizeof(physicalMedium), &bytesWritten, 0);
   150                              &physicalMedium, sizeof(physicalMedium), &bytesWritten, 0);
   151     if (!result) {
   151     if (!result) {
   152         CloseHandle(handle);
   152         CloseHandle(handle);
   153 
   153 
   154         if (medium == NdisMedium802_3)
   154         if (medium == NdisMedium802_3)
   155             return QLatin1String("Ethernet");
   155             return QNetworkConfiguration::BearerEthernet;
   156         else
   156         else
   157             return QLatin1String("Unknown");
   157             return QNetworkConfiguration::BearerUnknown;
   158     }
   158     }
   159 
   159 
   160     CloseHandle(handle);
   160     CloseHandle(handle);
   161 
   161 
   162     if (medium == NdisMedium802_3) {
   162     if (medium == NdisMedium802_3) {
   163         switch (physicalMedium) {
   163         switch (physicalMedium) {
   164         case NdisPhysicalMediumWirelessLan:
   164         case NdisPhysicalMediumWirelessLan:
   165             return QLatin1String("WLAN");
   165             return QNetworkConfiguration::BearerWLAN;
   166         case NdisPhysicalMediumBluetooth:
   166         case NdisPhysicalMediumBluetooth:
   167             return QLatin1String("Bluetooth");
   167             return QNetworkConfiguration::BearerBluetooth;
   168         case NdisPhysicalMediumWiMax:
   168         case NdisPhysicalMediumWiMax:
   169             return QLatin1String("WiMAX");
   169             return QNetworkConfiguration::BearerWiMAX;
   170         default:
   170         default:
   171 #ifdef BEARER_MANAGEMENT_DEBUG
   171 #ifdef BEARER_MANAGEMENT_DEBUG
   172             qDebug() << "Physical Medium" << physicalMedium;
   172             qDebug() << "Physical Medium" << physicalMedium;
   173 #endif
   173 #endif
   174             return QLatin1String("Ethernet");
   174             return QNetworkConfiguration::BearerEthernet;
   175         }
   175         }
   176     }
   176     }
   177 
   177 
   178 #ifdef BEARER_MANAGEMENT_DEBUG
   178 #ifdef BEARER_MANAGEMENT_DEBUG
   179     qDebug() << medium << physicalMedium;
   179     qDebug() << medium << physicalMedium;
   180 #endif
   180 #endif
   181 
   181 
   182 #endif
   182 #endif
   183 
   183 
   184     return QLatin1String("Unknown");
   184     return QNetworkConfiguration::BearerUnknown;
   185 }
   185 }
   186 
   186 
   187 class QNlaThread : public QThread
   187 class QNlaThread : public QThread
   188 {
   188 {
   189     Q_OBJECT
   189     Q_OBJECT
   372 #ifdef BEARER_MANAGEMENT_DEBUG
   372 #ifdef BEARER_MANAGEMENT_DEBUG
   373         qDebug("%s: unhandled header type NLA_802_1X_LOCATION", __FUNCTION__);
   373         qDebug("%s: unhandled header type NLA_802_1X_LOCATION", __FUNCTION__);
   374 #endif
   374 #endif
   375         break;
   375         break;
   376     case NLA_CONNECTIVITY:
   376     case NLA_CONNECTIVITY:
   377         if (blob->data.connectivity.internet == NLA_INTERNET_YES)
   377 #ifdef BEARER_MANAGEMENT_DEBUG
   378             cpPriv->internet = true;
   378         qDebug("%s: unhandled header type NLA_CONNECTIVITY", __FUNCTION__);
   379         else
   379 #endif
   380             cpPriv->internet = false;
       
   381         break;
   380         break;
   382     case NLA_ICS:
   381     case NLA_ICS:
   383 #ifdef BEARER_MANAGEMENT_DEBUG
   382 #ifdef BEARER_MANAGEMENT_DEBUG
   384         qDebug("%s: unhandled header type NLA_ICS", __FUNCTION__);
   383         qDebug("%s: unhandled header type NLA_ICS", __FUNCTION__);
   385 #endif
   384 #endif
   436             else
   435             else
   437                 offset = nextOffset;
   436                 offset = nextOffset;
   438         } while (offset != 0 && offset < querySet->lpBlob->cbSize);
   437         } while (offset != 0 && offset < querySet->lpBlob->cbSize);
   439     }
   438     }
   440 
   439 
   441     if (QNlaEngine *engine = qobject_cast<QNlaEngine *>(parent()))
   440     if (QNlaEngine *engine = qobject_cast<QNlaEngine *>(parent())) {
   442         cpPriv->bearer = engine->bearerName(cpPriv->id);
   441         const QString interface = engine->getInterfaceFromId(cpPriv->id);
       
   442         cpPriv->bearerType = qGetInterfaceType(interface);
       
   443     }
   443 
   444 
   444     return cpPriv;
   445     return cpPriv;
   445 }
   446 }
   446 
   447 
   447 void QNlaThread::fetchConfigurations()
   448 void QNlaThread::fetchConfigurations()
   582 bool QNlaEngine::hasIdentifier(const QString &id)
   583 bool QNlaEngine::hasIdentifier(const QString &id)
   583 {
   584 {
   584     QMutexLocker locker(&mutex);
   585     QMutexLocker locker(&mutex);
   585 
   586 
   586     return configurationInterface.contains(id.toUInt());
   587     return configurationInterface.contains(id.toUInt());
   587 }
       
   588 
       
   589 QString QNlaEngine::bearerName(const QString &id)
       
   590 {
       
   591     QString interface = getInterfaceFromId(id);
       
   592 
       
   593     if (interface.isEmpty())
       
   594         return QString();
       
   595 
       
   596     return qGetInterfaceType(interface);
       
   597 }
   588 }
   598 
   589 
   599 void QNlaEngine::connectToId(const QString &id)
   590 void QNlaEngine::connectToId(const QString &id)
   600 {
   591 {
   601     emit connectionError(id, OperationNotSupported);
   592     emit connectionError(id, OperationNotSupported);