Commit 989d1d68 authored by Thomas Perl's avatar Thomas Perl

Merge pull request #43 from kananoja/master

[ssu] Use Wlan MAC address as the device UID if IMEI is not found.
parents 218b3536 dc1c3349
...@@ -281,11 +281,43 @@ ofonoGetImeis() ...@@ -281,11 +281,43 @@ ofonoGetImeis()
return result; return result;
} }
static QStringList
getWlanMacs()
{
// Based on QtSystems' qnetworkinfo_linux.cpp
QStringList result;
QStringList dirs = QDir(QLatin1String("/sys/class/net/"))
.entryList(QStringList() << QLatin1String("wlan*"));
foreach (const QString &dir, dirs) {
QFile carrier(QString("/sys/class/net/%1/address").arg(dir));
if (carrier.open(QIODevice::ReadOnly)) {
result.append(QString::fromLatin1(carrier.readAll().simplified().data()));
}
}
return result;
}
static QString
normalizeUid(const QString& uid)
{
// Normalize by stripping colons, dashes and making it lowercase
return uid.trimmed().replace(":", "").replace("-", "").toLower();
}
QString SsuDeviceInfo::deviceUid(){ QString SsuDeviceInfo::deviceUid(){
SsuLog *ssuLog = SsuLog::instance();
QStringList imeis = ofonoGetImeis(); QStringList imeis = ofonoGetImeis();
if (imeis.size() > 0) {
return imeis[0];
}
QStringList wlanMacs = getWlanMacs();
if (wlanMacs.size() > 0) {
return normalizeUid(wlanMacs[0]);
}
if (imeis.size() == 0) { ssuLog->print(LOG_WARNING, "Could not get IMEI(s) from ofono, nor WLAN mac, trying fallback");
qWarning() << "Could not get IMEI(s) from ofono, trying fallback";
// The fallback list is taken from QtSystems' qdeviceinfo_linux.cpp // The fallback list is taken from QtSystems' qdeviceinfo_linux.cpp
QStringList fallbackFiles; QStringList fallbackFiles;
...@@ -298,17 +330,12 @@ QString SsuDeviceInfo::deviceUid(){ ...@@ -298,17 +330,12 @@ QString SsuDeviceInfo::deviceUid(){
QFile machineId(filename); QFile machineId(filename);
if (machineId.open(QFile::ReadOnly | QFile::Text)) { if (machineId.open(QFile::ReadOnly | QFile::Text)) {
QTextStream in(&machineId); QTextStream in(&machineId);
return normalizeUid(in.readAll());
// Normalize by stripping colons, dashes and making it lowercase
return in.readAll().trimmed().replace(":", "").replace("-", "").toLower();
} }
} }
qCritical() << "Could not read fallback UID - returning empty string"; ssuLog->print(LOG_CRIT, "Could not read fallback UID - returning empty string");
return ""; return "";
}
return imeis[0];
} }
QStringList SsuDeviceInfo::disabledRepos(){ QStringList SsuDeviceInfo::disabledRepos(){
......
...@@ -54,7 +54,8 @@ class SsuDeviceInfo: public QObject { ...@@ -54,7 +54,8 @@ class SsuDeviceInfo: public QObject {
Q_INVOKABLE QString deviceModel(); Q_INVOKABLE QString deviceModel();
/** /**
* Calculate the device ID used in ssu requests * Calculate the device ID used in ssu requests
* @return QSystemDeviceInfo::imei(), if available, or QSystemDeviceInfo::uniqueDeviceID() * @return QSystemDeviceInfo::imei(), if available, or QNetworkInfo::macAddress(QNetworkInfo::WlanMode, 0),
* if available, or QSystemDeviceInfo::uniqueDeviceID()
*/ */
Q_INVOKABLE QString deviceUid(); Q_INVOKABLE QString deviceUid();
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment