summaryrefslogtreecommitdiff
authorclem <clem>2004-08-05 22:55:35 (UTC)
committer clem <clem>2004-08-05 22:55:35 (UTC)
commit90ca457fbf420e31eed99c828a23e451bf8dc30c (patch) (side-by-side diff)
treebb538c99c6157a3e431818594fea92584783fc90
parent75286b93291026578a6352797c830787a9401055 (diff)
downloadopie-90ca457fbf420e31eed99c828a23e451bf8dc30c.zip
opie-90ca457fbf420e31eed99c828a23e451bf8dc30c.tar.gz
opie-90ca457fbf420e31eed99c828a23e451bf8dc30c.tar.bz2
Don't bother with killing bluetooth anymore, since our
/etc/suspend-scripts/S50bluetooth new script does that just when we need it. Also, don't forget to shut down Bluetooth when we started it ourselves and when the authentication is finished (skipped or successfull). Finally, there's more info in the debug output now.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/securityplugins/blueping/bluepingplugin.cpp86
-rw-r--r--noncore/securityplugins/blueping/bluepingplugin.h7
2 files changed, 58 insertions, 35 deletions
diff --git a/noncore/securityplugins/blueping/bluepingplugin.cpp b/noncore/securityplugins/blueping/bluepingplugin.cpp
index f5d9ad6..1c514e5 100644
--- a/noncore/securityplugins/blueping/bluepingplugin.cpp
+++ b/noncore/securityplugins/blueping/bluepingplugin.cpp
@@ -8,53 +8,71 @@
#include <qlayout.h>
#include <qhbox.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qtimer.h>
using namespace Opie::Core;
using Opie::Security::MultiauthPluginObject;
using Opie::Security::MultiauthConfigWidget;
/// standard c'tor
-BluepingPlugin::BluepingPlugin() : MultiauthPluginObject(), m_ping(0), m_bluepingW(0) {
- bluetoothAlreadyRestarted = false;
+BluepingPlugin::BluepingPlugin() : MultiauthPluginObject(), m_ping(0), m_bluepingW(0), bluetoothWasOff(false) {
}
-/// cleans m_ping if we need to
+/// cleans m_ping and m_bluepingW if we need to
BluepingPlugin::~BluepingPlugin() {
- delete m_ping;
+ odebug << "closing Blueping plugin..." << oendl;
+ if (m_ping != 0)
+ delete m_ping;
if (m_bluepingW != 0)
delete m_bluepingW;
+ killBluetoothIfNecessary();
}
/// Simply return its name (Blueping plugin)
QString BluepingPlugin::pluginName() const {
return "Blueping plugin";
}
/// returns a BluepingConfigWidget
MultiauthConfigWidget * BluepingPlugin::configWidget(QWidget * parent) {
if (m_bluepingW == 0)
m_bluepingW = new BluepingConfigWidget(parent, "Blueping configuration widget");
return m_bluepingW;
}
+
QString BluepingPlugin::pixmapNameWidget() const {
return "security/bluepingplugin";
}
+
QString BluepingPlugin::pixmapNameConfig() const {
return "security/bluepingplugin";
}
+/// If Bluetooth was off before the plugin ran, we switch it off again
+void BluepingPlugin::killBluetoothIfNecessary() {
+ if (bluetoothWasOff) {
+ OProcess killB;
+ killB << "killall" << "hciattach";
+ odebug << "killing Bluetooth... (since it was up only for Blueping)" << oendl;
+ if ( !killB.start(OProcess::Block) ) {
+ oerr << "could not kill bluetooth" << oendl;
+ }
+ } else {
+ odebug << "keeping Bluetooth on" << oendl;
+ }
+}
+
/// Emit the MultiauthPluginObject::Success emitCode
void BluepingPlugin::success() {
emit emitCode(MultiauthPluginObject::Success);
}
/// Emit the MultiauthPluginObject::Failure emitCode
void BluepingPlugin::failure() {
emit emitCode(MultiauthPluginObject::Failure);
}
/// Emit the MultiauthPluginObject::Skip emitCode
void BluepingPlugin::skip() {
@@ -72,36 +90,36 @@ void BluepingPlugin::ping() {
/// it's high enough, meaning the device is close enough?
/// \todo make it optionally pollable, so don't finish the ping and call
/// Opie suspend if l2ping timeouts?
if ( !m_ping->start() ) {
oerr << "could not start l2ping" << oendl;
this->skip();
}
QObject::connect(m_ping, SIGNAL(processExited(Opie::Core::OProcess*)),
this, SLOT(pingFinished(Opie::Core::OProcess*)) );
}
/// Deals with m_ping result
- void BluepingPlugin::pingFinished(OProcess * ping) {
- if ( ping->normalExit() && (ping->exitStatus() == 0) )
- {
- odebug << "Successful Bluetooth ping!" << oendl;
- success();
- }
- else
- {
- odebug << "Failed Bluetooth ping..." << oendl;
- failure();
- }
+void BluepingPlugin::pingFinished(OProcess * ping) {
+ if ( ping->normalExit() && (ping->exitStatus() == 0) )
+ {
+ odebug << "Successful Bluetooth ping!" << oendl;
+ success();
}
+ else
+ {
+ odebug << "Failed Bluetooth ping... (normalExit: " << ping->normalExit() << ", exitStatus: " << ping->exitStatus() << ")" << oendl;
+ failure();
+ }
+}
/// Make one authentication attempt with this plugin
/**
* (very simple "success" / "failure" buttons in a dialog)
* \return The outcome code of this authentication
*/
int BluepingPlugin::authenticate() {
Config cfg("Security");
cfg.setGroup("BluepingPlugin");
macToPing = cfg.readEntry("mac");
if (!macToPing.isEmpty())
@@ -127,75 +145,79 @@ int BluepingPlugin::authenticate() {
QLabel subTitle2("<center>You can skip this step and use another authentication way with the following button</center>", &bluepingDialog);
QPushButton pbSkip("Skip", &bluepingDialog);
layout->addWidget(&title);
layout->addWidget(&subTitle);
layout->addWidget(&subTitle2);
layout->addWidget(&pbSkip, 0, Qt::AlignHCenter);
// connect the skip button to the skip signal emitting function
QObject::connect(&pbSkip, SIGNAL(clicked()), this, SLOT(skip()));
// connect the signal emitting functions to the bluepingDialog done(int) finishing function
QObject::connect(this, SIGNAL(emitCode(int)), &bluepingDialog, SLOT(done(int)));
- // we can uncomment the following when testing
- //bluetoothAlreadyRestarted = true;
- if (!bluetoothAlreadyRestarted)
+
+
+ /* let's start Bluetooth if it's not running
+ */
+ OProcess checkB;
+ checkB << "pidof" << "hciattach";
+ odebug << "checking if Bluetooth is running..." << oendl;
+ // now we start bluetooth *only* if the previous command works, exits normally, and
+ // it returns a non-null exit code (which means hciattach is not running)
+ if ( checkB.start(OProcess::Block) && checkB.normalExit() && (checkB.exitStatus() != 0) )
{
- // we have just started or resumed the device, so Bluetooth has to be (re)started
- OProcess killB;
- killB << "killall" << "hciattach";
- odebug << "killing Bluetooth..." << oendl;
- if ( !killB.start(OProcess::Block) ) {
- oerr << "could not kill bluetooth" << oendl;
- }
+ // remember to switch off Bluetooth once we're finished...
+ bluetoothWasOff = true;
+ odebug << "Bluetooth is not running, we must start it now" << oendl;
OProcess startB;
switch ( ODevice::inst()->model() ) {
case Model_iPAQ_H39xx:
startB << "/sbin/hciattach" << "/dev/tts/1" << "bcsp" << "921600";
break;
case Model_iPAQ_H5xxx:
startB << "/sbin/hciattach" << "/dev/tts/1" << "any" << "921600";
break;
default:
startB << "/sbin/hciattach" << "/dev/ttySB0" << "bcsp" << "230400";
break;
} // end switch on device models
if ( !startB.start(OProcess::Block) ) {
- oerr << "could not (re)start bluetooth" << oendl;
+ oerr << "could not start Bluetooth" << oendl;
return MultiauthPluginObject::Skip;
}
else
{
- if ( startB.normalExit() && (startB.exitStatus() == 0) )
+ if ( (startB.normalExit()) && (startB.exitStatus() == 0) )
{
- odebug << "hciattach exited normally."<< oendl;
- bluetoothAlreadyRestarted = true;
+ odebug << "hciattach exited normally, Bluetooth is probably on now, let's wait 500 ms and ping" << oendl;
// 500 ms timer, so l2ping won't try to find a route before bluetooth has \em really started
QTimer::singleShot( 500, this, SLOT(ping()) );
}
else
{
- owarn << "hciattach exited anormally (error code: " << startB.exitStatus() << ")" << oendl;
- } // end if startBluetooth exit status == 0
+ owarn << "hciattach exited anormally (normalExit: " << startB.normalExit() << ", exit status: " << startB.exitStatus() << ")" << oendl;
+ return MultiauthPluginObject::Skip;
+ } // end if startB exited normaly
} // end if startBluetooth started
}
else
{
// we don't need to wait, since bluetooth has been started long enough ago
+ odebug << "Bluetooth is already running, we can try to ping now" << oendl;
ping();
- } // end if bluetooth not restarted
+ } // end if Bluetooth was off
// start the dialog event loop, while the ping is starting (or will start soon) in the background
return bluepingDialog.exec();
}
else
{
owarn << "No Bluetooth device has been set!" << oendl;
owarn << "We will consider it as a successful authentication though." << oendl;
return MultiauthPluginObject::Success;
diff --git a/noncore/securityplugins/blueping/bluepingplugin.h b/noncore/securityplugins/blueping/bluepingplugin.h
index b8d6734..56ff22d 100644
--- a/noncore/securityplugins/blueping/bluepingplugin.h
+++ b/noncore/securityplugins/blueping/bluepingplugin.h
@@ -64,20 +64,21 @@ class BluepingPlugin : public QObject, public Opie::Security::MultiauthPluginObj
signals:
/// Signal carrying the result code of this plugin
void emitCode(int resultCode);
private slots:
void success();
void failure();
void skip();
void ping();
void pingFinished(Opie::Core::OProcess * ping);
private:
- Opie::Core::OProcess *m_ping;
+ void killBluetoothIfNecessary();
+ Opie::Core::OProcess * m_ping;
+ Config * m_config;
BluepingConfigWidget * m_bluepingW;
- bool bluetoothAlreadyRestarted;
+ bool bluetoothWasOff;
QString macToPing;
-
};
#endif