bool LanImpl::stop() { #ifndef NO_WIRELESS_LAN if ( type() & QtopiaNetwork::WirelessLAN ) roaming->activeNotification( false ); #endif switch (ifaceStatus ) { case QtopiaNetworkInterface::Pending: case QtopiaNetworkInterface::Demand: case QtopiaNetworkInterface::Up: break; case QtopiaNetworkInterface::Unknown: case QtopiaNetworkInterface::Unavailable: case QtopiaNetworkInterface::Down: default: updateTrigger( QtopiaNetworkInterface::UnknownError, tr("Interface is not running.") ); return true; } #ifndef NO_WIRELESS_LAN if ( type() & QtopiaNetwork::WirelessLAN ) { wlanRegProvider->setAccessPoint(); wlanRegProvider->notifyClients(); } #endif // ### stop eth0 QStringList args; args << "stop"; args << deviceName; thread.addScriptToRun( lanScript, args ); updateTrigger(); return true; }
bool DialupImpl::stop() { switch( ifaceStatus ) { case QtopiaNetworkInterface::Pending: case QtopiaNetworkInterface::Demand: case QtopiaNetworkInterface::Up: break; //case QtopiaNetworkInterface::Unknown: //case QtopiaNetworkInterface::Unavailable: //case QtopiaNetworkInterface::Down: default: updateTrigger( QtopiaNetworkInterface::UnknownError, tr("Device is not active.") ); return true; } const QtopiaNetwork::Type t = type(); if ( t & QtopiaNetwork::NamedModem || t & QtopiaNetwork::PCMCIA ) { QStringList args; args << "stop"; args << pppIface; thread.addScriptToRun( pppScript, args ); } else { #ifdef QTOPIA_CELL qLog(Network) << "stopping data call on phone line"; if ( ! dataCall.isNull() ) { dataCall.hangup(); } #endif } if ( tidStateUpdate ) { killTimer( tidStateUpdate ); tidStateUpdate = 0; state = Initialize; logIndex = 0; } pppIface = QString(); netSpace->setAttribute( "NetDevice", QString() ); ifaceStatus = QtopiaNetworkInterface::Down; #ifdef QTOPIA_CELL if ( t & QtopiaNetwork::PhoneModem ) //internal phone device pppdProcessBlocked = true; #endif status(); updateTrigger(); return true; }
bool DialupImpl::setDefaultGateway() { if ( pppIface.isEmpty() ) { updateTrigger( QtopiaNetworkInterface::UnknownError, tr("Cannot set default gateway.") ); qLog(Network) << "Cannot set default gateway"; return false; } QStringList params; params << "install"; params << "dns"; if ( configIface->property("Serial/UsePeerDNS").toString() == "n" ) { params << configIface->property("Properties/DNS_1").toString(); params << configIface->property("Properties/DNS_2").toString(); } thread.addScriptToRun( pppScript, params ); qLog(Network) << "Settings default gateway to" <<configIface->configFile(); QStringList args; args << "route"; args << pppIface; thread.addScriptToRun( pppScript, args ); return true; }
void BluetoothImpl::cleanup() { if ( ifaceStatus != QtopiaNetworkInterface::Unknown ) { ifaceStatus = QtopiaNetworkInterface::Unknown; netSpace->setAttribute( "State", ifaceStatus ); updateTrigger(); } else { return; } const QString peerName = configIface->property("Serial/PeerID").toString(); if ( peerName.isEmpty() ) return; //delete peer file qLog(Network) << "Deleting DUN peer file"; QFile::remove( "/etc/ppp/peers/"+peerName ); //delete chat files qLog(Network) << "Deleting connect chat script"; const QString path = Qtopia::applicationFileName("Network","chat"); QString chat = path + "/connect-" + peerName; qLog(Network) << QString("Deleting connect file (%1)").arg(chat); QFile::remove(chat); }
void TriggerObject::Update(double dt, bool* myKey) { updateTrigger(dt, myKey); //Actual update //Sprite animation switch (type) { case FIRE: { setState(FIRE); if (animationList[FIRE]->ended == true) { animationList[FIRE]->Reset(); if(this->getActive() == true) { my_sfx_man->play_fire(); } } if (mesh != animationList[FIRE]) { setMesh(animationList[FIRE]); } animationList[FIRE]->Update(dt); break; } } }
/* lan-network route <iface> [-gw <gateway-IP>] */ bool LanImpl::setDefaultGateway() { if ( deviceName.isEmpty() ) { updateTrigger( QtopiaNetworkInterface::UnknownError, tr("Cannot set default gateway.") ); qLog(Network) << "Cannot set default gateway"; return false; } qLog(Network) << "Settings default gateway to" <<configIface->configFile(); QStringList args; args << "route"; args << deviceName; const bool dhcp = configIface->property("Properties/DHCP").toString() != "n"; if ( !dhcp ) { QString gateway = configIface->property("Properties/GATEWAY").toString(); args << "-gw"; args << gateway; } thread.addScriptToRun( lanScript, args ); //new gateway may require new dns installDNS( dhcp ); return true; }
QtopiaNetworkInterface::Status LanImpl::status() { //don't change status - initialize has not been called yet if ( ifaceStatus == QtopiaNetworkInterface::Unknown) { return ifaceStatus; } QtopiaNetworkInterface::Status status = QtopiaNetworkInterface::Unavailable; if ( isAvailable() ) { status = QtopiaNetworkInterface::Down; if ( thread.remainingTasks() > 0 ) { //still some jobs to do -> don't do anything until they are done status = ifaceStatus; } else { switch( ifaceStatus ) { case QtopiaNetworkInterface::Demand: status = ifaceStatus; break; case QtopiaNetworkInterface::Pending: default: if ( isActive() ) status = QtopiaNetworkInterface::Up; break; } } } ifaceStatus = status; netSpace->setAttribute( "State", (int)ifaceStatus ); updateTrigger(); return ifaceStatus; }
void BluetoothImpl::initialize() { if ( !netSpace ) { //initialize the value space for this interface QByteArray path("/Network/Interfaces/"+ QByteArray::number(qHash(configIface->configFile())) ); netSpace = new QValueSpaceObject( path, this ); netSpace->setAttribute( QLatin1String("Config"), configIface->configFile() ); netSpace->setAttribute( QLatin1String("State"), QtopiaNetworkInterface::Unknown ); netSpace->setAttribute( QLatin1String("Error"), QtopiaNetworkInterface::NotInitialized ); netSpace->setAttribute( QLatin1String("ErrorString"), tr("Interface hasn't been initialized yet.") ); netSpace->setAttribute( QLatin1String("NetDevice"), QVariant() ); netSpace->setAttribute( QLatin1String("BtDevice"), QVariant() ); netSpace->setAttribute( QLatin1String("UpdateTrigger"), 0 ); } if ( !dialupDev ) { dialupDev = new BluetoothDialupDevice( this ); connect( dialupDev, SIGNAL(deviceStateChanged()), this, SLOT(updateState()) ); connect( dialupDev, SIGNAL(connectionEstablished()), this, SLOT(serialPortConnected()) ); } if ( isAvailable() ) { ifaceStatus = Down; } else { ifaceStatus = Unavailable; } netSpace->setAttribute( QLatin1String("State"), ifaceStatus ); updateTrigger(); }
bool BluetoothImpl::stop() { switch( ifaceStatus ) { case QtopiaNetworkInterface::Pending: case QtopiaNetworkInterface::Demand: case QtopiaNetworkInterface::Up: break; default: updateTrigger( QtopiaNetworkInterface::UnknownError, tr("Interface is not active.") ); return false; } //stop pppd QStringList args; args << "stop"; args << pppIface; thread.addScriptToRun( pppScript, args ); dialupDev->releaseDUNConnection(); if (session) { session->endSession(); delete session; session = 0; } if ( tidStateUpdate ) { killTimer( tidStateUpdate ); tidStateUpdate = 0; state = Initialize; logIndex = 0; } ifaceStatus = QtopiaNetworkInterface::Down; netSpace->setAttribute( "State", ifaceStatus ); pppIface = ""; netSpace->setAttribute( "NetDevice", QByteArray() ); updateTrigger(); return true; }
/*! This function is part of the startup procedure and is called once the rfcomm device has been created. */ void BluetoothImpl::serialPortConnected( ) { const QByteArray tty = dialupDev->rfcommDevice(); if ( tty.isEmpty() || !QFile::exists( tty ) ) { if ( !tty.isEmpty() ) { qLog(Network) << "Invalid rfcomm device:" << tty; dialupDev->releaseDUNConnection(); } else { qLog(Network) << "Empty rfcomm device"; } if (session) { session->endSession(); delete session; session = 0; } ifaceStatus = QtopiaNetworkInterface::Down; netSpace->setAttribute( "State", ifaceStatus ); updateTrigger(QtopiaNetworkInterface::UnknownError, tr("Cannot bind Bluetooth DUN to serial port.") ); status(); return; } const QString peerName = configIface->property("Serial/PeerID").toString(); QStringList params; if ( tty.startsWith("/dev/") ) params << tty.mid( 5 /*strlen("/dev/")*/ ); else params << tty; params << QLatin1String("updetach"); params << QLatin1String("debug"); //enable debugging output const QString logfile = Qtopia::tempDir() + "qpe-pppd-log-"+ peerName; params << "logfile"; params << logfile; QFile::remove( logfile ) ; params << "call"; params << peerName; qLog(Network) << "###################################"; qLog(Network) << "Starting ppp using " << tty; qLog(Network) << "using parameter:" << params.join(QString(" ") ); params.prepend( QLatin1String("start") ); thread.addScriptToRun( pppScript, params ); state = Initialize; logIndex = 0; tidStateUpdate = startTimer( 1000 ); }
void getInventoryItemFromScript(char *line) { char command[15], itemName[MAX_VALUE_LENGTH], entityName[MAX_VALUE_LENGTH], quiet[MAX_VALUE_LENGTH]; int quantity, success, failure, quantityToRemove, read; Entity *e, *item; read = sscanf(line, "%s \"%[^\"]\" %d %d %s %d %d %s", command, itemName, &quantity, &quantityToRemove, entityName, &success, &failure, quiet); if (read < 7) { showErrorAndExit("HAS_ITEM or REMOVE command has wrong number of arguments"); } e = getEntityByObjectiveName(entityName); if (e == NULL) { showErrorAndExit("Could not find Entity %s to give item %s to", entityName, itemName); } item = getInventoryItemByObjectiveName(itemName); if (item != NULL && (item->health >= quantity || quantity == 1)) { if (strcmpignorecase(command, "REMOVE") == 0) { item->health -= quantityToRemove; updateTrigger(itemName, quantityToRemove); updateGlobalTrigger(itemName, quantityToRemove); if (item->health <= 0 || quantityToRemove == -1) { item->health = 0; removeInventoryItemByObjectiveName(itemName); if (read == 7) { setInfoBoxMessage(90, 255, 255, 255, _("Removed %s"), _(itemName)); } } } e->health = success; } else { e->health = failure; } }
OctreeTriggerPlayer::~OctreeTriggerPlayer(void) { // 结束前也要更新 updateTrigger(); if(m_node) { m_node->detachObject(this); m_sceneMgr->getRootSceneNode()->removeAndDestroyChild(m_node->getName()); m_node = 0; } if(m_query) { m_sceneMgr->destroyQuery(m_query); m_query = 0; } }
bool BluetoothImpl::start( const QVariant /*options*/ ) { if ( ifaceStatus != QtopiaNetworkInterface::Down ) { switch ( ifaceStatus ) { case QtopiaNetworkInterface::Unknown: updateTrigger( QtopiaNetworkInterface::NotInitialized, tr("Interface hasn't been initialized yet.") ); break; case QtopiaNetworkInterface::Unavailable: updateTrigger( QtopiaNetworkInterface::NotAvailable, tr("Interface is not available.") ); break; case QtopiaNetworkInterface::Up: case QtopiaNetworkInterface::Pending: case QtopiaNetworkInterface::Demand: updateTrigger( QtopiaNetworkInterface::NotConnected, tr("Interface already started/active.") ); break; default: break; } qLog(Network) << "ppp interface cannot be started " <<configIface->configFile(); return false; } bool result = false; QBluetoothAddress addr( configIface->property(QLatin1String("Serial/PartnerDevice")).toString() ); if ( addr.isValid() ) { session = QCommDeviceSession::session(QBluetoothLocalDevice().deviceName().toLatin1()); if (!session) { updateTrigger( QtopiaNetworkInterface::UnknownError, tr("Bluetooth Session failed.") ); return false; } qLog(Network) << "Connecting to" << addr.toString(); dialupDev->connectToDUNService( addr ); result = true; ifaceStatus = QtopiaNetworkInterface::Pending; netSpace->setAttribute( "State", ifaceStatus ); updateTrigger(); } else { updateTrigger( QtopiaNetworkInterface::UnknownError, tr("No remote Bluetooth partner selected.") ); } return result; }
QtopiaNetworkInterface::Status BluetoothImpl::status() { if ( ifaceStatus == Unknown ) //not initialized return ifaceStatus; QtopiaNetworkInterface::Status status = Unavailable; if ( isAvailable() ) { status = Down; if ( ifaceStatus == Demand || ifaceStatus == Pending ) status = ifaceStatus; else if ( isActive() ) status = QtopiaNetworkInterface::Up; } ifaceStatus = status; netSpace->setAttribute( QLatin1String("State"), ifaceStatus ); updateTrigger(); return ifaceStatus; }
void LanImpl::cleanup() { if ( ifaceStatus != QtopiaNetworkInterface::Unknown ) { ifaceStatus = QtopiaNetworkInterface::Unknown; netSpace->setAttribute( "State", ifaceStatus ); updateTrigger(); } else { return; } QStringList params; params << "cleanup"; //no tr thread.addScriptToRun( lanScript, params ); //remove network device assigned to this config QString key = devToConfig->key( configIface->configFile() ); if ( !key.isEmpty() ) devToConfig->remove( key ); }
bool BluetoothImpl::setDefaultGateway() { if ( pppIface.isEmpty() ) { updateTrigger( QtopiaNetworkInterface::UnknownError, tr("Cannot set default gateway.") ); qLog(Network) << "Cannot set default gateway"; return false; } QStringList args; args << "route"; args << pppIface; thread.addScriptToRun( pppScript, args ); QStringList dns; dns << "install"; dns << "dns"; thread.addScriptToRun( pppScript, dns ); return true; }
void DialupImpl::cleanup() { if ( ifaceStatus != QtopiaNetworkInterface::Unknown ) { ifaceStatus = QtopiaNetworkInterface::Unknown; netSpace->setAttribute( "State", ifaceStatus ); updateTrigger(); } else { return; } //delete peer file qLog(Network) << "Deleting peer file"; QStringList params; params << "cleanup"; params << "peer"; const QString peerName = configIface->property("Serial/PeerID").toString(); if ( peerName.isEmpty() ) return; params << peerName; thread.addScriptToRun( pppScript, params ); //reversing to standard dns server qLog(Network) << "deinstalling DNS server"; params.clear(); params << "cleanup"; params << "dns"; thread.addScriptToRun( pppScript, params ); //delete chat files const QString path = Qtopia::applicationFileName("Network","chat"); QString chat = path + "/connect-" + peerName; qLog(Network) << QString("Deleting connect file (%1)").arg(chat); QFile::remove(chat); chat = path + "/disconnect-" + peerName; qLog(Network) << QString("Deleting disconnect file (%1)").arg(chat); QFile::remove(chat); //config file will be deleted by qtopia network server }
QtopiaNetworkInterface::Status DialupImpl::status() { if ( ifaceStatus == QtopiaNetworkInterface::Unknown) { return ifaceStatus; } QtopiaNetworkInterface::Status status = QtopiaNetworkInterface::Unavailable; if ( isAvailable() ) { status = QtopiaNetworkInterface::Down; if ( ifaceStatus == QtopiaNetworkInterface::Pending || ifaceStatus == QtopiaNetworkInterface::Demand ) // these states are updated by timerEvent status = ifaceStatus; else if ( isActive() ) status = QtopiaNetworkInterface::Up; } ifaceStatus = status; netSpace->setAttribute( "State", ifaceStatus ); updateTrigger(); return ifaceStatus; }
void LanImpl::initialize() { if ( !netSpace ) { QString path = QString("/Network/Interfaces/%1").arg( qHash( configIface->configFile() ) ); netSpace = new QValueSpaceObject( path, this ); netSpace->setAttribute( "Config", configIface->configFile() ); netSpace->setAttribute( "State", ifaceStatus ); netSpace->setAttribute( "ErrorString", tr("Interface hasn't been initialized yet.") ); netSpace->setAttribute( "Error", QtopiaNetworkInterface::NotInitialized ); netSpace->setAttribute( "NetDevice", QVariant() ); netSpace->setAttribute( "UpdateTrigger" , 0 ); } if ( isAvailable() ) { qLog(Network) << "LanImpl: Using network interface: " <<deviceName; if ( isActive() ) ifaceStatus = QtopiaNetworkInterface::Up; else ifaceStatus = QtopiaNetworkInterface::Down; } else { ifaceStatus = QtopiaNetworkInterface::Unavailable; qLog(Network) << "LanImpl: interface not available"; } netSpace->setAttribute( "State", ifaceStatus ); updateTrigger(); #ifndef NO_WIRELESS_LAN QtopiaNetwork::Type t = type(); if ( t & QtopiaNetwork::WirelessLAN ) { roaming = new RoamingMonitor( configIface, this ); connect( roaming, SIGNAL(changeNetwork()), this, SLOT(reconnectWLAN()) ); wlanRegProvider = new WlanRegistrationProvider( QString::number(qHash(configIface->configFile())), this ); wlanRegProvider->initialize(); } #endif }
void DialupImpl::initialize() { if ( !netSpace ) { const uint ident = qHash( configIface->configFile() ); QString path = QString("/Network/Interfaces/%1").arg(ident); netSpace = new QValueSpaceObject( path, this ); netSpace->setAttribute( "Config", configIface->configFile() ); netSpace->setAttribute( "State", QtopiaNetworkInterface::Unknown ); netSpace->setAttribute( "Error", QtopiaNetworkInterface::NotInitialized ); netSpace->setAttribute( "ErrorString", tr("Interface hasn't been initialized yet.") ); netSpace->setAttribute( "NetDevice", QVariant() ); netSpace->setAttribute( "UpdateTrigger", 0 ); } if ( isAvailable() ) { ifaceStatus = QtopiaNetworkInterface::Down; qLog(Network) << "DialupImpl: Using serial device: " << device(); } else { ifaceStatus = QtopiaNetworkInterface::Unavailable; qLog(Network) << "DialupImpl: interface not available"; } netSpace->setAttribute( "State", ifaceStatus ); updateTrigger(); #ifdef QTOPIA_CELL QtopiaNetwork::Type t = type(); if ( t & QtopiaNetwork::PhoneModem ) { //we cannot start an internal GPRS connection if we don't have a registered network //initiate monitoring of registration changes commManager = new QCommServiceManager( this ); connect( commManager, SIGNAL(servicesChanged()), this, SLOT(registrationStateChanged()) ); registrationStateChanged(); //ask for first update } #endif }
void PortamentoFilter::process() { updateTrigger(); updateReleased(); }
bool DialupImpl::start( const QVariant /*options*/ ) { if ( ifaceStatus != QtopiaNetworkInterface::Down ) { switch ( ifaceStatus ) { case QtopiaNetworkInterface::Unknown: updateTrigger( QtopiaNetworkInterface::NotInitialized, tr("Interface hasn't been initialized yet.") ); break; case QtopiaNetworkInterface::Unavailable: updateTrigger( QtopiaNetworkInterface::NotAvailable, tr("Interface is not available.") ); break; case QtopiaNetworkInterface::Up: case QtopiaNetworkInterface::Pending: case QtopiaNetworkInterface::Demand: updateTrigger( QtopiaNetworkInterface::NotConnected, tr("Interface already started/active.") ); break; default: break; } qLog(Network) << "ppp interface cannot be started " <<configIface->configFile(); return false; } QtopiaNetworkProperties prop = configIface->getProperties(); QStringList args; const bool demand = prop.value("Properties/Autostart").toString() == "y"; const QtopiaNetwork::Type t = type(); #ifdef QTOPIA_CELL if ( t & QtopiaNetwork::PhoneModem ) { if ( regState != QTelephony::RegistrationHome && regState != QTelephony::RegistrationRoaming ) { //we want to start the network but we don't have a network //registration yet. wait till registration is done then go ahead //and start iface qLog(Network) << "Cannot start dialup yet due to missing" << "network registration. try again later"; registrationStateChanged(); //ask for first update updateTrigger( QtopiaNetworkInterface::NotConnected, tr("Missing network registration. Try again later.") ); return false; } } #endif if ( t & QtopiaNetwork::NamedModem || t & QtopiaNetwork::PCMCIA ) { QString dev = device(); if ( dev.isEmpty() || dev == "internal") { qLog(Network) << "No external device"; updateTrigger( QtopiaNetworkInterface::NotConnected, tr("Missing external serial device.") ); return false; } if ( dev.startsWith("/dev/") ) dev = dev.mid(5); args << dev; args << "updetach"; } #ifdef QTOPIA_CELL else { args << "nodetach"; } #endif args << "debug"; args << "call"; const QString peerID = prop.value("Serial/PeerID").toString(); if ( peerID.isEmpty() ) { qLog(Network) << "Missing peer ID"; updateTrigger( QtopiaNetworkInterface::NotConnected, tr("Missing peer ID. Please reconfigure device.") ); return false; } args << peerID; QString password = prop.value("Properties/Password").toString(); if (!password.isEmpty()) { args << "password"; args << password; } const QString logfile = Qtopia::tempDir() + "qpe-pppd-log-"+peerID; args << "logfile"; args << logfile; QFile::remove( logfile ) ; if ( t & QtopiaNetwork::NamedModem || t & QtopiaNetwork::PCMCIA ) { qLog(Network) << "###################################"; qLog(Network) << "Starting ppp using external modem: " << args.join(" "); args.prepend("start"); //cmd for network script thread.addScriptToRun( pppScript, args ); } else { //QtopiaNetwork::PhoneModem #ifdef QTOPIA_CELL const QString path = Qtopia::applicationFileName("Network", "chat"); const QString connectF = path+"/connect-"+peerID; const QString disconnectF = path+"/disconnect-"+peerID; //Create a data call qLog(Network) << "###################################"; qLog(Network) << "Starting ppp using internal modem: " << args.join(" "); qLog(Network) << "connect: " << connectF; qLog(Network) << "disconnect: " << disconnectF; qLog(Network) << "demand dialing: " << (demand ? "yes" : "no"); QDialOptions pppd; pppd.setUseIpModule( true ); pppd.setIpProgramName( PPPD_BINARY ); pppd.setIpConnectScript( connectF ); pppd.setIpDisconnectScript( disconnectF ); pppd.setIpDemandDialing( demand ); pppd.setIpArgs( args ); //Make sure that an existing call is stopped. if ( !dataCall.isNull() ) { dataCall.hangup(); } if ( !callManager ) callManager = new QPhoneCallManager( this ); //Dial the new call. if ( callManager ) { dataCall = callManager->create( "IP" ); dataCall.connectNotification( this, SLOT(connectNotification(QPhoneCall,QPhoneCall::Notification,QString))); dataCall.connectStateChanged( this, SLOT(phoneCallStateChanged(QPhoneCall)) ); dataCall.dial( pppd ); } else { qLog(Network) << "No call manager created"; } #endif } state = Initialize; logIndex = 0; tidStateUpdate = startTimer( 1000 ); if ( demand ) ifaceStatus = QtopiaNetworkInterface::Demand; else ifaceStatus = QtopiaNetworkInterface::Pending; netSpace->setAttribute( "State", ifaceStatus ); updateTrigger(); delayedGatewayInstall = true; return true; }
void DialupImpl::timerEvent( QTimerEvent* /*e*/) { const QString peerID = configIface->property("Serial/PeerID").toString(); const QString logfile = Qtopia::tempDir() + "qpe-pppd-log-"+peerID; const bool demand = configIface->property("Properties/Autostart").toString() == "y"; if (state == Disappearing) { if ( tidStateUpdate ) killTimer( tidStateUpdate ); tidStateUpdate = 0; state = Initialize; logIndex = 0; updateState(); qLog(Network) << "Stopping ppp script monitor"; return; } QFile logf( logfile ); if ( logf.open(QIODevice::ReadOnly) ) { QString log = logf.readAll(); log.replace(QRegExp("\r"),""); if ( logIndex > log.length() ) logIndex = 0; switch ( state ) { case Initialize: { int i = 0; if ( log.indexOf(QRegExp("\nFailed"), logIndex)>=logIndex || log.indexOf(QRegExp("is locked by pid"), logIndex) >= logIndex || log.indexOf(QRegExp("Connect script failed"), logIndex) >= logIndex ) { state = Disappearing; ifaceStatus = QtopiaNetworkInterface::Unavailable; netSpace->setAttribute( "State", ifaceStatus ); updateTrigger( QtopiaNetworkInterface::UnknownError, tr("Connect chat failed.") ); qLog(Network) << "Connect chat failed"; return; } if ( log.indexOf(QRegExp("\nNO DIALTONE"), logIndex)>=logIndex || log.indexOf(QRegExp("\nNO CARRIER"), logIndex)>=logIndex || log.indexOf(QRegExp("\nERROR"), logIndex)>=logIndex || log.indexOf(QRegExp("\nBUSY"), logIndex)>=logIndex ) { ifaceStatus = QtopiaNetworkInterface::Unavailable; netSpace->setAttribute( "State", ifaceStatus ); updateTrigger( QtopiaNetworkInterface::UnknownError, tr("Connect chat not responding.") ); state = Disappearing; qLog(Network) << "Connect chat not responding"; } else if ( (i=log.indexOf(QRegExp("Using interface ppp.*\n"), logIndex))>= logIndex ) { //determine iface name; int end = log.indexOf(QRegExp("\n"), i); int begin = log.indexOf(QRegExp("ppp"), i); pppIface = log.mid(begin, end-begin); netSpace->setAttribute( "NetDevice", pppIface ); qLog(Network) << "using interface: " << pppIface; logIndex = end; if ( !demand ) state = Connect; } else if ( demand ) { if ( (i=log.indexOf(QRegExp("Starting link\n"), logIndex))>=logIndex ) { ifaceStatus = QtopiaNetworkInterface::Pending; netSpace->setAttribute( "State", ifaceStatus ); updateTrigger(); logIndex = i++; state = Connect; } } } break; case Connect: { int i = 0; if ( (i=log.indexOf(QRegExp("\nPAP authentication failed"), logIndex))>=logIndex || (i=log.indexOf(QRegExp("\nCHAP authentication failed"), logIndex))>=logIndex || (i=log.indexOf(QRegExp("\nConnection terminated."), logIndex)) >=logIndex) { state = Disappearing; pppIface = QString(); netSpace->setAttribute( "NetDevice", QString() ); ifaceStatus = QtopiaNetworkInterface::Unavailable; netSpace->setAttribute( "State", ifaceStatus ); updateTrigger( QtopiaNetworkInterface::UnknownError, tr("Authentication failed.") ); qLog(Network) << "Authentication failed"; } else if ( (i=log.indexOf(QRegExp("\nLocal IP address changed"), logIndex)) >= logIndex || (i=log.indexOf(QRegExp("\nlocal IP address"), logIndex)) >= logIndex ) { logIndex = i; ifaceStatus = QtopiaNetworkInterface::Up; netSpace->setAttribute( "State", ifaceStatus ); updateTrigger(); state = Monitoring; QtopiaNetwork::setDefaultGateway( configIface->configFile() ); } else if ( (i=log.indexOf(QRegExp("\nConnect script failed"), logIndex)) >= logIndex ) { logIndex = i; if ( demand ) { state = Initialize; ifaceStatus = QtopiaNetworkInterface::Demand; netSpace->setAttribute( "State", ifaceStatus ); updateTrigger(); } else { state = Disappearing; pppIface = QString(); netSpace->setAttribute( "NetDevice", QString() ); ifaceStatus = QtopiaNetworkInterface::Unavailable; netSpace->setAttribute( "State", ifaceStatus ); updateTrigger( QtopiaNetworkInterface::UnknownError, tr("Connect failed.") ); qLog(Network) << "Connect failed"; } } } break; case Monitoring: { int i; if ( (i=log.indexOf(QRegExp("\nConnection terminated"), logIndex)) >= logIndex ) { logIndex = i++; qLog(Network) << "Connection terminated"; if ( demand ) { state = Initialize; ifaceStatus = QtopiaNetworkInterface::Demand; netSpace->setAttribute( "State", ifaceStatus ); updateTrigger(); } else { pppIface = QString(); ifaceStatus = QtopiaNetworkInterface::Unavailable; netSpace->setAttribute( "NetDevice", QString() ); netSpace->setAttribute( "State", ifaceStatus ); state = Disappearing; updateTrigger(); QtopiaNetwork::unsetDefaultGateway( configIface->configFile() ); } } } break; default: break; } } }
bool LanImpl::start( const QVariant options ) { const QtopiaNetworkProperties prop = configIface->getProperties(); const bool dhcp = prop.value("Properties/DHCP").toString() != "n"; bool writeToSystem = prop.value("Info/WriteToSystem").toBool(); #ifndef NO_WIRELESS_LAN int netIndex = 0; QtopiaNetwork::Type t = type(); if ( t & QtopiaNetwork::WirelessLAN ) { QString essid = options.toString(); netIndex = roaming->selectWLAN( essid ); if (netIndex <= 0) { updateTrigger( QtopiaNetworkInterface::NotConnected, tr("No WLAN found in sourrounding area") ); qLog(Network) << "Invalid WLAN selected"; return false; } writeToSystem = true; //we always have to update the config since we change it very often roaming->activeNotification( true ); } #else Q_UNUSED( options ); #endif if ( ifaceStatus != QtopiaNetworkInterface::Down || deviceName.isEmpty() ) { switch ( ifaceStatus ) { case QtopiaNetworkInterface::Unknown: updateTrigger( QtopiaNetworkInterface::NotInitialized, tr("Interface hasn't been initialized yet.") ); break; case QtopiaNetworkInterface::Unavailable: updateTrigger( QtopiaNetworkInterface::NotAvailable, tr("Interface is not available.") ); break; case QtopiaNetworkInterface::Up: case QtopiaNetworkInterface::Pending: case QtopiaNetworkInterface::Demand: updateTrigger( QtopiaNetworkInterface::NotConnected, tr("Interface already started/active.") ); break; default: break; } qLog(Network) << "LAN interface cannot be started " << configIface->configFile(); return false; } if ( writeToSystem ) { qLog(Network) << "Installing new set of configuration for " << deviceName; QStringList params; params << "install"; params << deviceName; if ( dhcp ) { // ### install <iface> dhcp // dhcp takes care of everything params << "dhcp"; } else { // ### install <iface> static <ip> <netmask> <broadcast> <gateway> params << "static"; bool missingOption = false; QString temp = prop.value("Properties/IPADDR").toString(); if ( temp.isEmpty() ) { updateTrigger( QtopiaNetworkInterface::NotConnected, tr("IP address missing.") ); qLog(Network) << "IP address missing"; missingOption = true; } else { params << temp; } if ( missingOption ) return false; temp = prop.value("Properties/SUBNET").toString(); if ( temp.isEmpty() ) { qLog(Network) << "Subnet mask missing"; updateTrigger( QtopiaNetworkInterface::NotConnected, tr("Subnet mask missing.") ); missingOption = true; } else { params << temp; } if ( missingOption ) return false; QString ip = temp; //save ip in case we need it as gateway address temp = prop.value("Properties/BROADCAST").toString(); if ( temp.isEmpty() ) { updateTrigger( QtopiaNetworkInterface::NotConnected, tr("Broadcast address missing.") ); qLog(Network) << "Broadcast address missing"; missingOption = true; } else { params << temp; } if ( missingOption ) return false; temp = prop.value("Properties/GATEWAY").toString(); if ( temp.isEmpty() ) { qLog(Network) << "Gateway address missing. Using IP address."; params << ip; } else { params << temp; } } thread.addScriptToRun( lanScript, params ); #ifndef NO_WIRELESS_LAN if ( t & QtopiaNetwork::WirelessLAN ) { // ### install <iface> wireless // ### [-essid <ESSID>] [-mode <Master|Managed|Ad-Hoc>] // ### [-ap <AP>] [-bitrate <value>] [-nick <nickname>] [-channel <CHANNEL>] // ### [-authmode <open|shared> -multikey <defaultKey> <key1> <key2> <key3> <key4>] // ### [-authmode <open|shared> -phrase <passphrase> ] // ### [-authmode <none> -nokey ] // ### [-authmode <WPA-PSK> <password> <AES|TKIP> // ### [-authmode <WPA-EAP> <TTLS|PEAP> <client cert> <server cert> ] // ### [-authmode <WPA-EAP> <TLS> <identity> <password> ] // ### [-keylength <128|64> ] const QString keyPrefix = QString("WirelessNetworks/%1/").arg(netIndex); params.clear(); params << "install"; params << deviceName; params << "wireless"; QString temp = prop.value(keyPrefix+"WirelessMode").toString(); if ( !temp.isEmpty() ) { params << "-mode"; params << temp; } temp = prop.value(keyPrefix+"ESSID").toString(); if ( !temp.isEmpty() ) { params << "-essid"; params << Qtopia::shellQuote(temp); if ( t & QtopiaNetwork::WirelessLAN ) { wlanRegProvider->setAccessPoint( temp ); } } params << "-ap"; params << Qtopia::shellQuote( prop.value(keyPrefix+"AccessPoint").toString() ); temp = prop.value(keyPrefix+"BitRate").toString(); if ( !temp.isEmpty() ) { params << "-bitrate"; params << temp; } temp = prop.value(keyPrefix+"Nickname").toString(); if ( !temp.isEmpty() ) { params << "-nick"; params << Qtopia::shellQuote(temp); } temp = prop.value(keyPrefix+"CHANNEL").toString(); if ( !temp.isEmpty() ) { params << "-channel"; params << temp; } temp = prop.value(keyPrefix+"KeyLength", QString("128")).toString(); params << "-keylength"; params << temp; QString encryptMode = prop.value(keyPrefix+"Encryption", QString("open")).toString(); params << "-authmode"; params << encryptMode; if ( encryptMode == "open" || encryptMode == "shared" ) { const QString defaultKey = prop.value(keyPrefix+"SelectedKey").toString(); const QString pw = prop.value(keyPrefix+"PRIV_GENSTR").toString(); const bool isPassPhrase = defaultKey == "PP"; if ( isPassPhrase ) { params << "-phrase"; params << Qtopia::shellQuote(pw); } else { params << "-multikey"; params << defaultKey.right(1); for ( int i = 1; i<5; i++ ) { params << Qtopia::shellQuote( prop.value(keyPrefix+"WirelessKey_"+QString::number(i)).toString()); } } } else if ( encryptMode == QLatin1String("none") ) { params << "-nokey"; } else if ( encryptMode == QLatin1String("WPA-PSK") ) { params << Qtopia::shellQuote(prop.value(keyPrefix+QLatin1String("PRIV_GENSTR"), QLatin1String("")).toString()); params << prop.value(keyPrefix+QLatin1String("PSKAlgorithm"), QLatin1String("TKIP")).toString(); } else if ( encryptMode == QLatin1String("WPA-EAP") ) { temp = prop.value(keyPrefix+QLatin1String("WPAEnterprise"), QLatin1String("TLS")).toString(); params << temp; if ( temp == QLatin1String("TLS") ) { params << prop.value(keyPrefix+QLatin1String("EAPIdentity")).toString(); params << prop.value(keyPrefix+QLatin1String("EAPClientKeyPassword")).toString(); params << prop.value(keyPrefix+QLatin1String("EAPClientKey")).toString(); params << prop.value(keyPrefix+QLatin1String("EAPClientCert")).toString(); params << prop.value(keyPrefix+QLatin1String("EAPServerCert")).toString(); } else if ( temp == QLatin1String("TTLS") || temp == QLatin1String("PEAP") ) { params << prop.value(keyPrefix+QLatin1String("EAPIdentity")).toString(); params << prop.value(keyPrefix+QLatin1String("EAPIdentityPassword")).toString(); params << prop.value(keyPrefix+QLatin1String("EAPServerCert")).toString(); params << prop.value(keyPrefix+QLatin1String("EAPAuthentication")).toString(); params << prop.value(keyPrefix+QLatin1String("EAPAnonIdentity")).toString(); } else { qLog(Network) << QLatin1String("Unknown encryption algorithm for WPA Enterprise"); return false; } } else { qLog(Network) << QLatin1String("Invalid encryption for WLAN:") << encryptMode; return false; } thread.addScriptToRun( lanScript, params ); } #endif //Remove WriteToSystem value QtopiaNetworkProperties p; p.insert("Info/WriteToSystem", false); configIface->writeProperties( p ); } QStringList args; // ### start <iface> args << "start"; args << deviceName; thread.addScriptToRun( lanScript, args ); //we have to wait a bit until this interface is actually online //->then it can become the default gateway ->installs dns details as well ifaceStatus = QtopiaNetworkInterface::Pending; netSpace->setAttribute( "State", ifaceStatus ); updateTrigger(); delayedGatewayInstall = true; return true; }
void BluetoothImpl::timerEvent( QTimerEvent* /*e*/) { const QString peerID = configIface->property("Serial/PeerID").toString(); const QString logfile = Qtopia::tempDir() + "qpe-pppd-log-"+peerID; if (state == Disappearing) { if ( tidStateUpdate ) killTimer( tidStateUpdate ); tidStateUpdate = 0; state = Initialize; logIndex = 0; dialupDev->releaseDUNConnection(); if (session) { session->endSession(); delete session; session = 0; } updateState(); qLog(Network) << "Stopping ppp script monitor"; return; } QFile logf( logfile ); if ( logf.open(QIODevice::ReadOnly) ) { QString log = logf.readAll(); log.replace(QRegExp("\r"),""); if ( logIndex > log.length() ) logIndex = 0; switch ( state ) { case Initialize: { int i = 0; if ( log.indexOf(QRegExp("\nFailed"), logIndex)>=logIndex || log.indexOf(QRegExp("is locked by pid"), logIndex) >= logIndex || log.indexOf(QRegExp("Connect script failed"), logIndex) >= logIndex || log.indexOf(QRegExp("Connection refused"), logIndex) >= logIndex ) { state = Disappearing; ifaceStatus = QtopiaNetworkInterface::Unavailable; netSpace->setAttribute( "State", ifaceStatus ); updateTrigger( QtopiaNetworkInterface::UnknownError, tr("Connect chat failed.") ); qLog(Network) << "Connect chat failed"; return; } if ( log.indexOf(QRegExp("\nNO DIALTONE"), logIndex)>=logIndex || log.indexOf(QRegExp("\nNO CARRIER"), logIndex)>=logIndex || log.indexOf(QRegExp("\nERROR"), logIndex)>=logIndex || log.indexOf(QRegExp("\nBUSY"), logIndex)>=logIndex ) { ifaceStatus = QtopiaNetworkInterface::Unavailable; netSpace->setAttribute( "State", ifaceStatus ); updateTrigger( QtopiaNetworkInterface::UnknownError, tr("Connect chat not responding.") ); qLog(Network) << "Connect chat not responding"; state = Disappearing; } else if ( (i=log.indexOf(QRegExp("Using interface ppp.*\n"), logIndex))>= logIndex ) { //determine iface name; int end = log.indexOf(QRegExp("\n"), i); int begin = log.indexOf(QRegExp("ppp"), i); pppIface = log.mid(begin, end-begin).toLatin1(); netSpace->setAttribute( "NetDevice", pppIface ); qLog(Network) << "using interface: " << pppIface; logIndex = end; state = Connect; } } break; case Connect: { int i = 0; if ( (i=log.indexOf(QRegExp("\nPAP authentication failed"), logIndex))>=logIndex || (i=log.indexOf(QRegExp("\nCHAP authentication failed"), logIndex))>=logIndex || (i=log.indexOf(QRegExp("\nConnection terminated."), logIndex)) >=logIndex) { state = Disappearing; pppIface = QByteArray(); netSpace->setAttribute( "NetDevice", pppIface ); ifaceStatus = QtopiaNetworkInterface::Unavailable; netSpace->setAttribute( "State", ifaceStatus ); updateTrigger( QtopiaNetworkInterface::UnknownError, tr("Authentication failed.") ); qLog(Network) << "Authentication failed"; } else if ( (i=log.indexOf(QRegExp("\nLocal IP address changed"), logIndex)) >= logIndex || (i=log.indexOf(QRegExp("\nlocal IP address"), logIndex)) >= logIndex ) { logIndex = i; ifaceStatus = QtopiaNetworkInterface::Up; netSpace->setAttribute( "State", ifaceStatus ); updateTrigger(); state = Monitoring; QStringList dns; dns << "install"; dns << "dns"; thread.addScriptToRun( pppScript, dns ); } else if ( (i=log.indexOf(QRegExp("\nConnect script failed"), logIndex)) >= logIndex ) { logIndex = i; state = Disappearing; pppIface = QByteArray(); netSpace->setAttribute( "NetDevice", pppIface ); ifaceStatus = QtopiaNetworkInterface::Unavailable; netSpace->setAttribute( "State", ifaceStatus ); updateTrigger( QtopiaNetworkInterface::UnknownError, tr("Connect failed.") ); qLog(Network) << "Connect failed"; } } break; case Monitoring: { int i; if ( (i=log.indexOf(QRegExp("\nConnection terminated"), logIndex)) >= logIndex ) { logIndex = i++; qLog(Network) << "Connection terminated"; pppIface = QByteArray(); netSpace->setAttribute( "NetDevice", pppIface ); ifaceStatus = QtopiaNetworkInterface::Unavailable; netSpace->setAttribute( "State", ifaceStatus ); state = Disappearing; updateTrigger(); QtopiaNetwork::unsetDefaultGateway( configIface->configFile() ); } } break; default: break; } } }