qtmobility/src/bearer/qnmwifiengine_unix.cpp
branchRCL_3
changeset 1 5822d84012fb
parent 0 cfcbf08528c4
child 6 4203353e74ea
equal deleted inserted replaced
0:cfcbf08528c4 1:5822d84012fb
    73 //     connect(iface,SIGNAL(deviceRemoved(QDBusObjectPath)),
    73 //     connect(iface,SIGNAL(deviceRemoved(QDBusObjectPath)),
    74 //             this,SLOT(removeDevice(QDBusObjectPath)));
    74 //             this,SLOT(removeDevice(QDBusObjectPath)));
    75     connect(iface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)),
    75     connect(iface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)),
    76             this, SLOT(slotActivationFinished(QDBusPendingCallWatcher*)));
    76             this, SLOT(slotActivationFinished(QDBusPendingCallWatcher*)));
    77 
    77 
    78     QList<QDBusObjectPath> list = iface->getDevices();
    78     foreach (const QDBusObjectPath &path, iface->getDevices())
    79 
       
    80     foreach(QDBusObjectPath path, list) {
       
    81         addDevice(path);
    79         addDevice(path);
    82     }
       
    83 
    80 
    84     QStringList connectionServices;
    81     QStringList connectionServices;
    85     connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS;
    82     connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS;
    86     connectionServices << NM_DBUS_SERVICE_USER_SETTINGS;
    83     connectionServices << NM_DBUS_SERVICE_USER_SETTINGS;
    87     QNetworkManagerSettings *settingsiface;
    84     QNetworkManagerSettings *settingsiface;
    88     foreach (QString service, connectionServices) {
    85     foreach (const QString &service, connectionServices) {
    89         settingsiface = new QNetworkManagerSettings(service, this);
    86         settingsiface = new QNetworkManagerSettings(service, this);
    90         settingsiface->setConnections();
    87         settingsiface->setConnections();
    91         connect(settingsiface,SIGNAL(newConnection(QDBusObjectPath)),
    88         connect(settingsiface,SIGNAL(newConnection(QDBusObjectPath)),
    92                 this,(SLOT(newConnection(QDBusObjectPath))));
    89                 this,(SLOT(newConnection(QDBusObjectPath))));
    93     }
    90     }
   144     connectionServices << NM_DBUS_SERVICE_USER_SETTINGS;
   141     connectionServices << NM_DBUS_SERVICE_USER_SETTINGS;
   145 
   142 
   146     QString connPath;
   143     QString connPath;
   147 
   144 
   148     QScopedPointer<QNetworkManagerSettings> settingsiface;
   145     QScopedPointer<QNetworkManagerSettings> settingsiface;
   149     foreach (QString service, connectionServices) {
   146     foreach (const QString &service, connectionServices) {
   150         QString ident;
   147         QString ident;
   151         settingsiface.reset(new QNetworkManagerSettings(service));
   148         settingsiface.reset(new QNetworkManagerSettings(service));
   152         QList<QDBusObjectPath> list = settingsiface->listConnections();
       
   153 
   149 
   154         QNetworkManagerSettingsConnection *sysIface;
   150         QNetworkManagerSettingsConnection *sysIface;
   155         foreach(QDBusObjectPath path, list) { 
   151         foreach (const QDBusObjectPath &path, settingsiface->listConnections()) {
   156             ident = path.path();
   152             ident = path.path();
   157             bool addIt = false;
   153             bool addIt = false;
   158             QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate();
   154             QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate();
   159             sysIface = new QNetworkManagerSettingsConnection(service, path.path(), this);
   155             sysIface = new QNetworkManagerSettingsConnection(service, path.path(), this);
   160             sysIface->setConnections();
   156             sysIface->setConnections();
   216     }
   212     }
   217 }
   213 }
   218 
   214 
   219 void QNmWifiEngine::accessPointConnections()
   215 void QNmWifiEngine::accessPointConnections()
   220 {
   216 {
   221     QList<QDBusObjectPath> list = iface->getDevices();
       
   222     QScopedPointer<QNetworkManagerInterfaceDevice> devIface;
   217     QScopedPointer<QNetworkManagerInterfaceDevice> devIface;
   223     foreach(QDBusObjectPath path, list) {
   218     foreach (const QDBusObjectPath &path, iface->getDevices()) {
   224         devIface.reset(new QNetworkManagerInterfaceDevice(path.path()));
   219         devIface.reset(new QNetworkManagerInterfaceDevice(path.path()));
   225         if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) {
   220         if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) {
   226             QList<QString> apList = availableAccessPoints.uniqueKeys();
   221             const QList<QString> apList = availableAccessPoints.uniqueKeys();
   227 
   222 
   228             QList<QString>::const_iterator i;
   223             QList<QString>::const_iterator i;
   229             for (i = apList.constBegin(); i != apList.constEnd(); ++i) {
   224             for (i = apList.constBegin(); i != apList.constEnd(); ++i) {
   230                 QNetworkConfigurationPrivate* cpPriv;
   225                 QNetworkConfigurationPrivate* cpPriv;
   231                 cpPriv = addAccessPoint( devIface->connectionInterface()->path(), availableAccessPoints[*i]);
   226                 cpPriv = addAccessPoint( devIface->connectionInterface()->path(), availableAccessPoints[*i]);
   254 
   249 
   255 QString QNmWifiEngine::bearerName(const QString &id)
   250 QString QNmWifiEngine::bearerName(const QString &id)
   256 {
   251 {
   257     QString interface = getInterfaceFromId(id);
   252     QString interface = getInterfaceFromId(id);
   258     QScopedPointer<QNetworkManagerInterfaceDevice> devIface;
   253     QScopedPointer<QNetworkManagerInterfaceDevice> devIface;
   259     QList<QDBusObjectPath> list = iface->getDevices();
   254     foreach (const QDBusObjectPath &path, iface->getDevices()) {
   260     foreach(QDBusObjectPath path, list) {
       
   261         devIface.reset(new QNetworkManagerInterfaceDevice(path.path()));
   255         devIface.reset(new QNetworkManagerInterfaceDevice(path.path()));
   262 
   256 
   263         if(interface == devIface->networkInterface().name()) {
   257         if(interface == devIface->networkInterface().name()) {
   264 
   258 
   265             switch(devIface->deviceType()) {
   259             switch(devIface->deviceType()) {
   353     QStringList connectionServices;
   347     QStringList connectionServices;
   354     connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS;
   348     connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS;
   355     connectionServices << NM_DBUS_SERVICE_USER_SETTINGS;
   349     connectionServices << NM_DBUS_SERVICE_USER_SETTINGS;
   356 
   350 
   357     QScopedPointer<QNetworkManagerSettings> settingsiface;
   351     QScopedPointer<QNetworkManagerSettings> settingsiface;
   358     foreach (QString service, connectionServices) {
   352     foreach (const QString &service, connectionServices) {
   359         settingsiface.reset(new QNetworkManagerSettings(service));
   353         settingsiface.reset(new QNetworkManagerSettings(service));
   360         QList<QDBusObjectPath> list = settingsiface->listConnections();
   354         foreach (const QDBusObjectPath &path, settingsiface->listConnections()) {
   361         foreach(QDBusObjectPath path, list) {
       
   362             QNetworkManagerSettingsConnection sysIface(service, path.path());
   355             QNetworkManagerSettingsConnection sysIface(service, path.path());
   363             knownSsids << sysIface.getSsid();
   356             knownSsids << sysIface.getSsid();
   364         }
   357         }
   365     }
   358     }
   366 }
   359 }
   368 void QNmWifiEngine::updateActiveConnectionsPaths()
   361 void QNmWifiEngine::updateActiveConnectionsPaths()
   369 { //need to know which connection paths are currently active/connected
   362 { //need to know which connection paths are currently active/connected
   370     QScopedPointer<QNetworkManagerInterface> dbIface;
   363     QScopedPointer<QNetworkManagerInterface> dbIface;
   371     activeConnectionPaths.clear();
   364     activeConnectionPaths.clear();
   372     dbIface.reset(new QNetworkManagerInterface);
   365     dbIface.reset(new QNetworkManagerInterface);
   373     QList <QDBusObjectPath> connections = dbIface->activeConnections();
   366     foreach (const QDBusObjectPath &conpath, dbIface->activeConnections())
   374     foreach(QDBusObjectPath conpath, connections) {
   367         activeConnectionPaths << conpath.path();
   375            activeConnectionPaths << conpath.path();
       
   376        }
       
   377 }
   368 }
   378 
   369 
   379 QNetworkConfigurationPrivate * QNmWifiEngine::addAccessPoint( const QString &iPath, QDBusObjectPath path)
   370 QNetworkConfigurationPrivate * QNmWifiEngine::addAccessPoint( const QString &iPath, QDBusObjectPath path)
   380 {
   371 {
   381 
   372 
   460 
   451 
   461 QString QNmWifiEngine::getActiveConnectionPath(const QString &id)
   452 QString QNmWifiEngine::getActiveConnectionPath(const QString &id)
   462 {
   453 {
   463     QStringList connectionSettings = getConnectionPathForId(id);
   454     QStringList connectionSettings = getConnectionPathForId(id);
   464     QNetworkManagerInterface ifaceD;
   455     QNetworkManagerInterface ifaceD;
   465     QList<QDBusObjectPath> connections = ifaceD.activeConnections();
       
   466     QScopedPointer<QNetworkManagerConnectionActive> conDetailsD;
   456     QScopedPointer<QNetworkManagerConnectionActive> conDetailsD;
   467     foreach(QDBusObjectPath path, connections) {
   457     foreach (const QDBusObjectPath &path, ifaceD.activeConnections()) {
   468         conDetailsD.reset(new QNetworkManagerConnectionActive( path.path()));
   458         conDetailsD.reset(new QNetworkManagerConnectionActive( path.path()));
   469         if(conDetailsD->connection().path() == connectionSettings.at(1)
   459         if(conDetailsD->connection().path() == connectionSettings.at(1)
   470             && conDetailsD->serviceName() == connectionSettings.at(0))
   460             && conDetailsD->serviceName() == connectionSettings.at(0))
   471             return path.path();
   461             return path.path();
   472     }
   462     }
   621 
   611 
   622     if(!aconpath.isEmpty()) {
   612     if(!aconpath.isEmpty()) {
   623         //active connection
   613         //active connection
   624         QNetworkManagerConnectionActive aConn(aconpath);
   614         QNetworkManagerConnectionActive aConn(aconpath);
   625 
   615 
   626         QList <QDBusObjectPath> devs = aConn.devices();
       
   627 
       
   628         QScopedPointer<QNetworkManagerInterfaceDevice> ifaceDevice;
   616         QScopedPointer<QNetworkManagerInterfaceDevice> ifaceDevice;
   629         QScopedPointer<QNetworkManagerInterfaceDeviceWired> devWiredIface;
   617         QScopedPointer<QNetworkManagerInterfaceDeviceWired> devWiredIface;
   630         foreach(QDBusObjectPath dev, devs) {
   618         foreach (const QDBusObjectPath &dev, aConn.devices()) {
   631             ifaceDevice.reset(new QNetworkManagerInterfaceDevice(dev.path()));
   619             ifaceDevice.reset(new QNetworkManagerInterfaceDevice(dev.path()));
   632 
   620 
   633             if(ifaceDevice->deviceType() == DEVICE_TYPE_802_3_ETHERNET) {
   621             if(ifaceDevice->deviceType() == DEVICE_TYPE_802_3_ETHERNET) {
   634 
   622 
   635                 if(isAddressOfConnection(id, ifaceDevice->ip4Address())) {
   623                 if(isAddressOfConnection(id, ifaceDevice->ip4Address())) {
   661             if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) {
   649             if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) {
   662                 QString ssid = sysIface->getSsid();
   650                 QString ssid = sysIface->getSsid();
   663                 bool ok = false;
   651                 bool ok = false;
   664 
   652 
   665                 if(knownSsids.contains(ssid, Qt::CaseSensitive)) {
   653                 if(knownSsids.contains(ssid, Qt::CaseSensitive)) {
   666                     foreach(QString onessid, knownSsids) {
   654                     foreach (const QString &onessid, knownSsids) {
   667                         if(onessid == ssid && availableAccessPoints.contains(ssid)) {
   655                         if(onessid == ssid && availableAccessPoints.contains(ssid)) {
   668                             ok = true;
   656                             ok = true;
   669                             break;
   657                             break;
   670                         }
   658                         }
   671                     }
   659                     }
   691     }
   679     }
   692 
   680 
   693     QScopedPointer<QNetworkManagerConnectionActive> aConn;
   681     QScopedPointer<QNetworkManagerConnectionActive> aConn;
   694     aConn.reset(new QNetworkManagerConnectionActive(aConPath));
   682     aConn.reset(new QNetworkManagerConnectionActive(aConPath));
   695     QScopedPointer<QNetworkManagerInterfaceDevice> ifaceDevice;
   683     QScopedPointer<QNetworkManagerInterfaceDevice> ifaceDevice;
   696     QList<QDBusObjectPath> devices = aConn->devices();
   684     foreach (const QDBusObjectPath &device, aConn->devices()) {
   697     foreach(QDBusObjectPath device, devices) {
       
   698         ifaceDevice.reset(new QNetworkManagerInterfaceDevice(device.path()));
   685         ifaceDevice.reset(new QNetworkManagerInterfaceDevice(device.path()));
   699         if(ifaceDevice->ip4Address() == ipaddress) {
   686         if(ifaceDevice->ip4Address() == ipaddress) {
   700             return true;
   687             return true;
   701         }
   688         }
   702     }
   689     }
   709     QStringList conIdPath = getConnectionPathForId(id);
   696     QStringList conIdPath = getConnectionPathForId(id);
   710 
   697 
   711     QNetworkInterface interface;
   698     QNetworkInterface interface;
   712     QScopedPointer<QNetworkManagerConnectionActive> aConn;
   699     QScopedPointer<QNetworkManagerConnectionActive> aConn;
   713 
   700 
   714     foreach(QString conpath, activeConnectionPaths) {
   701     foreach (const QString &conpath, activeConnectionPaths) {
   715         aConn.reset(new QNetworkManagerConnectionActive(conpath));
   702         aConn.reset(new QNetworkManagerConnectionActive(conpath));
   716         if(aConn->connection().path() == conIdPath.at(1)
   703         if(aConn->connection().path() == conIdPath.at(1)
   717             && aConn->serviceName() == conIdPath.at(0)) {
   704             && aConn->serviceName() == conIdPath.at(0)) {
   718 
   705 
   719             QList <QDBusObjectPath> devs = aConn->devices();
   706             QList <QDBusObjectPath> devs = aConn->devices();
   721             return ifaceDevice.networkInterface();
   708             return ifaceDevice.networkInterface();
   722         }
   709         }
   723     }
   710     }
   724 
   711 
   725     //try guessing
   712     //try guessing
   726     QList<QDBusObjectPath> list = iface->getDevices();
       
   727     QScopedPointer<QNetworkManagerInterfaceDevice> devIface;
   713     QScopedPointer<QNetworkManagerInterfaceDevice> devIface;
   728     foreach(QDBusObjectPath path, list) {
   714     foreach (const QDBusObjectPath &path, iface->getDevices()) {
   729         devIface.reset(new QNetworkManagerInterfaceDevice(path.path()));
   715         devIface.reset(new QNetworkManagerInterfaceDevice(path.path()));
   730         if(devIface->deviceType() == type ) {
   716         if(devIface->deviceType() == type ) {
   731             if(devIface->state() ==  NM_DEVICE_STATE_DISCONNECTED) {
   717             if(devIface->state() ==  NM_DEVICE_STATE_DISCONNECTED) {
   732                 return devIface->networkInterface();
   718                 return devIface->networkInterface();
   733             }
   719             }
   791 }
   777 }
   792 
   778 
   793 void QNmWifiEngine::scanForAccessPoints()
   779 void QNmWifiEngine::scanForAccessPoints()
   794 {
   780 {
   795     availableAccessPoints.clear();
   781     availableAccessPoints.clear();
   796     QList<QDBusObjectPath> list = iface->getDevices();
       
   797 
   782 
   798     QScopedPointer<QNetworkManagerInterfaceDevice> devIface;
   783     QScopedPointer<QNetworkManagerInterfaceDevice> devIface;
   799     QScopedPointer<QNetworkManagerInterfaceDeviceWireless> devWirelessIface;
   784     QScopedPointer<QNetworkManagerInterfaceDeviceWireless> devWirelessIface;
   800     QScopedPointer<QNetworkManagerInterfaceAccessPoint> accessPointIface;
   785     QScopedPointer<QNetworkManagerInterfaceAccessPoint> accessPointIface;
   801     foreach(QDBusObjectPath path, list) {
   786     foreach (const QDBusObjectPath &path, iface->getDevices()) {
   802         devIface.reset(new QNetworkManagerInterfaceDevice(path.path()));
   787         devIface.reset(new QNetworkManagerInterfaceDevice(path.path()));
   803 
   788 
   804         if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) {
   789         if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) {
   805 
   790 
   806             devWirelessIface.reset(new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()));
   791             devWirelessIface.reset(new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()));
   807             ////////////// AccessPoints
   792             ////////////// AccessPoints
   808             QList<QDBusObjectPath> apList = devWirelessIface->getAccessPoints();
   793 
   809 
   794             foreach (const QDBusObjectPath &path, devWirelessIface->getAccessPoints()) {
   810             foreach(QDBusObjectPath path, apList) {
       
   811                 accessPointIface.reset(new QNetworkManagerInterfaceAccessPoint(path.path()));
   795                 accessPointIface.reset(new QNetworkManagerInterfaceAccessPoint(path.path()));
   812                 QString ssid = accessPointIface->ssid();
   796                 const QString ssid = accessPointIface->ssid();
   813                 availableAccessPoints.insert(ssid, path);
   797                 availableAccessPoints.insert(ssid, path);
   814             }
   798             }
   815         }
   799         }
   816     }
   800     }
   817 }
   801 }
   818 
   802 
   819 QString QNmWifiEngine::deviceConnectionPath(const QString &mac)
   803 QString QNmWifiEngine::deviceConnectionPath(const QString &mac)
   820 {
   804 {
   821     QString newMac = mac;
   805     QString newMac = mac.toLower();
   822     newMac = newMac.replace(":","_").toLower();
   806     newMac.replace(QLatin1Char(':'), QLatin1Char('_'));
   823     //device object path might not contain just mac address
   807     //device object path might not contain just mac address
   824     //might contain extra numbers on the end. thanks HAL
   808     //might contain extra numbers on the end. thanks HAL
   825     foreach(QString device, devicePaths) {
   809     foreach (const QString &device, devicePaths) {
   826         if(device.contains(newMac)) {
   810         if(device.contains(newMac)) {
   827             newMac = device;
   811             newMac = device;
   828             break;
   812             break;
   829         }
   813         }
   830     }
   814     }
   835 {
   819 {
   836     QStringList connectionServices;
   820     QStringList connectionServices;
   837     connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS;
   821     connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS;
   838     connectionServices << NM_DBUS_SERVICE_USER_SETTINGS;
   822     connectionServices << NM_DBUS_SERVICE_USER_SETTINGS;
   839     QScopedPointer<QNetworkManagerSettings> settingsiface;
   823     QScopedPointer<QNetworkManagerSettings> settingsiface;
   840     foreach (QString service, connectionServices) {
   824     foreach (const QString &service, connectionServices) {
   841         settingsiface.reset(new QNetworkManagerSettings(service));
   825         settingsiface.reset(new QNetworkManagerSettings(service));
   842         QList<QDBusObjectPath> list = settingsiface->listConnections();
       
   843         QScopedPointer<QNetworkManagerSettingsConnection> sysIface;
   826         QScopedPointer<QNetworkManagerSettingsConnection> sysIface;
   844         foreach(QDBusObjectPath path, list) {
   827         foreach (const QDBusObjectPath &path, settingsiface->listConnections()) {
   845             sysIface.reset(new QNetworkManagerSettingsConnection(service, path.path()));
   828             sysIface.reset(new QNetworkManagerSettingsConnection(service, path.path()));
   846             if(sysIface->getUuid() == uuid)
   829             if(sysIface->getUuid() == uuid)
   847                 return QStringList() << service << sysIface->connectionInterface()->path();
   830                 return QStringList() << service << sysIface->connectionInterface()->path();
   848         }
   831         }
   849     }
   832     }