diff options
Diffstat (limited to 'src/network/bearer/qnetworkconfiguration.cpp')
-rw-r--r-- | src/network/bearer/qnetworkconfiguration.cpp | 190 |
1 files changed, 189 insertions, 1 deletions
diff --git a/src/network/bearer/qnetworkconfiguration.cpp b/src/network/bearer/qnetworkconfiguration.cpp index 615ef21661..40381a04c0 100644 --- a/src/network/bearer/qnetworkconfiguration.cpp +++ b/src/network/bearer/qnetworkconfiguration.cpp @@ -41,6 +41,12 @@ #include "qnetworkconfiguration.h" #include "qnetworkconfiguration_p.h" +#include <QDebug> + +#ifdef Q_OS_BLACKBERRY +#include "private/qcore_unix_p.h" // qt_safe_open +#include <sys/pps.h> +#endif // Q_OS_BLACKBERRY QT_BEGIN_NAMESPACE @@ -193,13 +199,95 @@ QT_BEGIN_NAMESPACE \value BearerEthernet The configuration is for an Ethernet interfaces. \value BearerWLAN The configuration is for a Wireless LAN interface. \value Bearer2G The configuration is for a CSD, GPRS, HSCSD, EDGE or cdmaOne interface. + \value Bearer3G The configuration is for a 3G interface. + \value Bearer4G The configuration is for a 4G interface. \value BearerCDMA2000 The configuration is for CDMA interface. \value BearerWCDMA The configuration is for W-CDMA/UMTS interface. \value BearerHSPA The configuration is for High Speed Packet Access (HSPA) interface. \value BearerBluetooth The configuration is for a Bluetooth interface. \value BearerWiMAX The configuration is for a WiMAX interface. + \value BearerEVDO The configuration is for an EVDO (3G) interface. + \value BearerLTE The configuration is for a LTE (4G) interface. */ +#ifdef Q_OS_BLACKBERRY +static const char cellularStatusFile[] = "/pps/services/radioctrl/modem0/status_public"; + +#ifdef Q_OS_BLACKBERRY_TABLET +static bool pps_decoder_is_integer(pps_decoder_t *decoder, const char *name) +{ + return (pps_decoder_type(decoder, name) == PPS_TYPE_NUMBER); +} +#endif // Q_OS_BLACKBERRY_TABLET + +static QNetworkConfiguration::BearerType cellularStatus() +{ + QNetworkConfiguration::BearerType ret = QNetworkConfiguration::BearerUnknown; + + int cellularStatusFD; + if ((cellularStatusFD = qt_safe_open(cellularStatusFile, O_RDONLY)) == -1) { + qWarning() << Q_FUNC_INFO << "failed to open" << cellularStatusFile; + return ret; + } + char buf[2048]; + if (qt_safe_read(cellularStatusFD, &buf, sizeof(buf)) == -1) { + qWarning() << Q_FUNC_INFO << "read from PPS file failed:" << strerror(errno); + qt_safe_close(cellularStatusFD); + return ret; + } + pps_decoder_t ppsDecoder; + if (pps_decoder_initialize(&ppsDecoder, buf) != PPS_DECODER_OK) { + qWarning() << Q_FUNC_INFO << "failed to initialize PPS decoder"; + qt_safe_close(cellularStatusFD); + return ret; + } + pps_decoder_error_t err; + if ((err = pps_decoder_push(&ppsDecoder, 0)) != PPS_DECODER_OK) { + qWarning() << Q_FUNC_INFO << "pps_decoder_push failed" << err; + pps_decoder_cleanup(&ppsDecoder); + qt_safe_close(cellularStatusFD); + return ret; + } + if (!pps_decoder_is_integer(&ppsDecoder, "network_technology")) { + qWarning() << Q_FUNC_INFO << "field has not the expected data type"; + pps_decoder_cleanup(&ppsDecoder); + qt_safe_close(cellularStatusFD); + return ret; + } + int type; + if (!pps_decoder_get_int(&ppsDecoder, "network_technology", &type) + == PPS_DECODER_OK) { + qWarning() << Q_FUNC_INFO << "could not read bearer type from PPS"; + pps_decoder_cleanup(&ppsDecoder); + qt_safe_close(cellularStatusFD); + return ret; + } + switch (type) { + case 0: // 0 == NONE + break; // unhandled + case 1: // fallthrough, 1 == GSM + case 4: // 4 == CDMA_1X + ret = QNetworkConfiguration::Bearer2G; + break; + case 2: // 2 == UMTS + ret = QNetworkConfiguration::BearerWCDMA; + break; + case 8: // 8 == EVDO + ret = QNetworkConfiguration::BearerEVDO; + break; + case 16: // 16 == LTE + ret = QNetworkConfiguration::BearerLTE; + break; + default: + qWarning() << Q_FUNC_INFO << "unhandled bearer type" << type; + break; + } + pps_decoder_cleanup(&ppsDecoder); + qt_safe_close(cellularStatusFD); + return ret; +} +#endif // Q_OS_BLACKBERRY + /*! Constructs an invalid configuration object. @@ -412,6 +500,8 @@ QList<QNetworkConfiguration> QNetworkConfiguration::children() const function can be used to retrieve a textural type name for the bearer. An invalid network configuration always returns the BearerUnknown value. + + \sa bearerTypeName(), bearerTypeFamily() */ QNetworkConfiguration::BearerType QNetworkConfiguration::bearerType() const { @@ -420,10 +510,74 @@ QNetworkConfiguration::BearerType QNetworkConfiguration::bearerType() const QMutexLocker locker(&d->mutex); +#ifdef Q_OS_BLACKBERRY + // for cellular configurations, we need to determine the exact + // type right now, because it might have changed after the last scan + if (d->bearerType == QNetworkConfiguration::Bearer2G) { + QNetworkConfiguration::BearerType type = cellularStatus(); + // if reading the status failed for some reason, just + // fall back to 2G + return (type == QNetworkConfiguration::BearerUnknown) + ? QNetworkConfiguration::Bearer2G : type; + } +#endif // Q_OS_BLACKBERRY + return d->bearerType; } /*! + \since 5.2 + + Returns the bearer type family used by this network configuration. + The following table lists how bearerType() values map to + bearerTypeFamily() values: + + \table + \header + \li bearer type + \li bearer type family + \row + \li BearerUnknown, Bearer2G, BearerEthernet, BearerWLAN, + BearerBluetooth + \li (same type) + \row + \li BearerCDMA2000, BearerEVDO, BearerWCDMA, BearerHSPA, Bearer3G + \li Bearer3G + \row + \li BearerWiMAX, BearerLTE, Bearer4G + \li Bearer4G + \endtable + + An invalid network configuration always returns the BearerUnknown value. + + \sa bearerType(), bearerTypeName() +*/ +QNetworkConfiguration::BearerType QNetworkConfiguration::bearerTypeFamily() const +{ + QNetworkConfiguration::BearerType type = bearerType(); + switch (type) { + case QNetworkConfiguration::BearerUnknown: // fallthrough + case QNetworkConfiguration::Bearer2G: // fallthrough + case QNetworkConfiguration::BearerEthernet: // fallthrough + case QNetworkConfiguration::BearerWLAN: // fallthrough + case QNetworkConfiguration::BearerBluetooth: + return type; + case QNetworkConfiguration::BearerCDMA2000: // fallthrough + case QNetworkConfiguration::BearerEVDO: // fallthrough + case QNetworkConfiguration::BearerWCDMA: // fallthrough + case QNetworkConfiguration::BearerHSPA: // fallthrough + case QNetworkConfiguration::Bearer3G: + return QNetworkConfiguration::Bearer3G; + case QNetworkConfiguration::BearerWiMAX: // fallthrough + case QNetworkConfiguration::BearerLTE: // fallthrough + case QNetworkConfiguration::Bearer4G: + return QNetworkConfiguration::Bearer4G; + default: + qWarning() << "unknown bearer type" << type; + return QNetworkConfiguration::BearerUnknown; + } +} +/*! Returns the type of bearer used by this network configuration as a string. The string is not translated and therefore can not be shown to the user. The subsequent table @@ -450,6 +604,12 @@ QNetworkConfiguration::BearerType QNetworkConfiguration::bearerType() const \li Bearer2G \li 2G \row + \li Bearer3G + \li 3G + \row + \li Bearer4G + \li 4G + \row \li BearerCDMA2000 \li CDMA2000 \row @@ -464,13 +624,19 @@ QNetworkConfiguration::BearerType QNetworkConfiguration::bearerType() const \row \li BearerWiMAX \li WiMAX + \row + \li BearerEVDO + \li EVDO + \row + \li BearerLTE + \li LTE \endtable This function returns an empty string if this is an invalid configuration, a network configuration of type \l QNetworkConfiguration::ServiceNetwork or \l QNetworkConfiguration::UserChoice. - \sa bearerType() + \sa bearerType(), bearerTypeFamily() */ QString QNetworkConfiguration::bearerTypeName() const { @@ -489,7 +655,25 @@ QString QNetworkConfiguration::bearerTypeName() const case BearerWLAN: return QStringLiteral("WLAN"); case Bearer2G: +#ifdef Q_OS_BLACKBERRY + { + // for cellular configurations, we need to determine the exact + // type right now, because it might have changed after the last scan + QNetworkConfiguration::BearerType type = cellularStatus(); + if (type == QNetworkConfiguration::BearerWCDMA) { + return QStringLiteral("WCDMA"); + } else if (type == QNetworkConfiguration::BearerEVDO) { + return QStringLiteral("EVDO"); + }else if (type == QNetworkConfiguration::BearerLTE) { + return QStringLiteral("LTE"); + } + } +#endif // Q_OS_BLACKBERRY return QStringLiteral("2G"); + case Bearer3G: + return QStringLiteral("3G"); + case Bearer4G: + return QStringLiteral("4G"); case BearerCDMA2000: return QStringLiteral("CDMA2000"); case BearerWCDMA: @@ -500,6 +684,10 @@ QString QNetworkConfiguration::bearerTypeName() const return QStringLiteral("Bluetooth"); case BearerWiMAX: return QStringLiteral("WiMAX"); + case BearerEVDO: + return QStringLiteral("EVDO"); + case BearerLTE: + return QStringLiteral("LTE"); case BearerUnknown: break; } |