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,34 +281,61 @@ ofonoGetImeis() ...@@ -281,34 +281,61 @@ 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];
}
if (imeis.size() == 0) { QStringList wlanMacs = getWlanMacs();
qWarning() << "Could not get IMEI(s) from ofono, trying fallback"; if (wlanMacs.size() > 0) {
return normalizeUid(wlanMacs[0]);
}
// The fallback list is taken from QtSystems' qdeviceinfo_linux.cpp ssuLog->print(LOG_WARNING, "Could not get IMEI(s) from ofono, nor WLAN mac, trying fallback");
QStringList fallbackFiles;
fallbackFiles << "/sys/devices/virtual/dmi/id/product_uuid";
fallbackFiles << "/etc/machine-id";
fallbackFiles << "/etc/unique-id";
fallbackFiles << "/var/lib/dbus/machine-id";
foreach (const QString &filename, fallbackFiles) { // The fallback list is taken from QtSystems' qdeviceinfo_linux.cpp
QFile machineId(filename); QStringList fallbackFiles;
if (machineId.open(QFile::ReadOnly | QFile::Text)) { fallbackFiles << "/sys/devices/virtual/dmi/id/product_uuid";
QTextStream in(&machineId); fallbackFiles << "/etc/machine-id";
fallbackFiles << "/etc/unique-id";
fallbackFiles << "/var/lib/dbus/machine-id";
// Normalize by stripping colons, dashes and making it lowercase foreach (const QString &filename, fallbackFiles) {
return in.readAll().trimmed().replace(":", "").replace("-", "").toLower(); QFile machineId(filename);
} if (machineId.open(QFile::ReadOnly | QFile::Text)) {
QTextStream in(&machineId);
return normalizeUid(in.readAll());
} }
qCritical() << "Could not read fallback UID - returning empty string";
return "";
} }
return imeis[0]; ssuLog->print(LOG_CRIT, "Could not read fallback UID - returning empty string");
return "";
} }
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