summaryrefslogtreecommitdiff
authorclem <clem>2004-08-05 22:55:35 (UTC)
committer clem <clem>2004-08-05 22:55:35 (UTC)
commit90ca457fbf420e31eed99c828a23e451bf8dc30c (patch) (unidiff)
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 @@
8#include <qlayout.h> 8#include <qlayout.h>
9#include <qhbox.h> 9#include <qhbox.h>
10#include <qlabel.h> 10#include <qlabel.h>
11#include <qpushbutton.h> 11#include <qpushbutton.h>
12#include <qtimer.h> 12#include <qtimer.h>
13 13
14using namespace Opie::Core; 14using namespace Opie::Core;
15using Opie::Security::MultiauthPluginObject; 15using Opie::Security::MultiauthPluginObject;
16using Opie::Security::MultiauthConfigWidget; 16using Opie::Security::MultiauthConfigWidget;
17 17
18 18
19/// standard c'tor 19/// standard c'tor
20BluepingPlugin::BluepingPlugin() : MultiauthPluginObject(), m_ping(0), m_bluepingW(0) { 20BluepingPlugin::BluepingPlugin() : MultiauthPluginObject(), m_ping(0), m_bluepingW(0), bluetoothWasOff(false) {
21 bluetoothAlreadyRestarted = false;
22} 21}
23 22
24/// cleans m_ping if we need to 23/// cleans m_ping and m_bluepingW if we need to
25BluepingPlugin::~BluepingPlugin() { 24BluepingPlugin::~BluepingPlugin() {
26 delete m_ping; 25 odebug << "closing Blueping plugin..." << oendl;
26 if (m_ping != 0)
27 delete m_ping;
27 if (m_bluepingW != 0) 28 if (m_bluepingW != 0)
28 delete m_bluepingW; 29 delete m_bluepingW;
30 killBluetoothIfNecessary();
29} 31}
30 32
31/// Simply return its name (Blueping plugin) 33/// Simply return its name (Blueping plugin)
32QString BluepingPlugin::pluginName() const { 34QString BluepingPlugin::pluginName() const {
33 return "Blueping plugin"; 35 return "Blueping plugin";
34} 36}
35 37
36/// returns a BluepingConfigWidget 38/// returns a BluepingConfigWidget
37MultiauthConfigWidget * BluepingPlugin::configWidget(QWidget * parent) { 39MultiauthConfigWidget * BluepingPlugin::configWidget(QWidget * parent) {
38 if (m_bluepingW == 0) 40 if (m_bluepingW == 0)
39 m_bluepingW = new BluepingConfigWidget(parent, "Blueping configuration widget"); 41 m_bluepingW = new BluepingConfigWidget(parent, "Blueping configuration widget");
40 return m_bluepingW; 42 return m_bluepingW;
41} 43}
44
42QString BluepingPlugin::pixmapNameWidget() const { 45QString BluepingPlugin::pixmapNameWidget() const {
43 return "security/bluepingplugin"; 46 return "security/bluepingplugin";
44} 47}
48
45QString BluepingPlugin::pixmapNameConfig() const { 49QString BluepingPlugin::pixmapNameConfig() const {
46 return "security/bluepingplugin"; 50 return "security/bluepingplugin";
47} 51}
48 52
53/// If Bluetooth was off before the plugin ran, we switch it off again
54void BluepingPlugin::killBluetoothIfNecessary() {
55 if (bluetoothWasOff) {
56 OProcess killB;
57 killB << "killall" << "hciattach";
58 odebug << "killing Bluetooth... (since it was up only for Blueping)" << oendl;
59 if ( !killB.start(OProcess::Block) ) {
60 oerr << "could not kill bluetooth" << oendl;
61 }
62 } else {
63 odebug << "keeping Bluetooth on" << oendl;
64 }
65}
66
49/// Emit the MultiauthPluginObject::Success emitCode 67/// Emit the MultiauthPluginObject::Success emitCode
50void BluepingPlugin::success() { 68void BluepingPlugin::success() {
51 emit emitCode(MultiauthPluginObject::Success); 69 emit emitCode(MultiauthPluginObject::Success);
52} 70}
53 71
54/// Emit the MultiauthPluginObject::Failure emitCode 72/// Emit the MultiauthPluginObject::Failure emitCode
55void BluepingPlugin::failure() { 73void BluepingPlugin::failure() {
56 emit emitCode(MultiauthPluginObject::Failure); 74 emit emitCode(MultiauthPluginObject::Failure);
57} 75}
58 76
59/// Emit the MultiauthPluginObject::Skip emitCode 77/// Emit the MultiauthPluginObject::Skip emitCode
60void BluepingPlugin::skip() { 78void BluepingPlugin::skip() {
@@ -72,36 +90,36 @@ void BluepingPlugin::ping() {
72 /// it's high enough, meaning the device is close enough? 90 /// it's high enough, meaning the device is close enough?
73 /// \todo make it optionally pollable, so don't finish the ping and call 91 /// \todo make it optionally pollable, so don't finish the ping and call
74 /// Opie suspend if l2ping timeouts? 92 /// Opie suspend if l2ping timeouts?
75 if ( !m_ping->start() ) { 93 if ( !m_ping->start() ) {
76 oerr << "could not start l2ping" << oendl; 94 oerr << "could not start l2ping" << oendl;
77 this->skip(); 95 this->skip();
78 } 96 }
79 QObject::connect(m_ping, SIGNAL(processExited(Opie::Core::OProcess*)), 97 QObject::connect(m_ping, SIGNAL(processExited(Opie::Core::OProcess*)),
80 this, SLOT(pingFinished(Opie::Core::OProcess*)) ); 98 this, SLOT(pingFinished(Opie::Core::OProcess*)) );
81} 99}
82 100
83/// Deals with m_ping result 101/// Deals with m_ping result
84 void BluepingPlugin::pingFinished(OProcess * ping) { 102void BluepingPlugin::pingFinished(OProcess * ping) {
85 if ( ping->normalExit() && (ping->exitStatus() == 0) ) 103 if ( ping->normalExit() && (ping->exitStatus() == 0) )
86 { 104 {
87 odebug << "Successful Bluetooth ping!" << oendl; 105 odebug << "Successful Bluetooth ping!" << oendl;
88 success(); 106 success();
89 }
90 else
91 {
92 odebug << "Failed Bluetooth ping..." << oendl;
93 failure();
94 }
95 } 107 }
108 else
109 {
110 odebug << "Failed Bluetooth ping... (normalExit: " << ping->normalExit() << ", exitStatus: " << ping->exitStatus() << ")" << oendl;
111 failure();
112 }
113}
96 114
97/// Make one authentication attempt with this plugin 115/// Make one authentication attempt with this plugin
98/** 116/**
99 * (very simple "success" / "failure" buttons in a dialog) 117 * (very simple "success" / "failure" buttons in a dialog)
100 * \return The outcome code of this authentication 118 * \return The outcome code of this authentication
101 */ 119 */
102int BluepingPlugin::authenticate() { 120int BluepingPlugin::authenticate() {
103 121
104 Config cfg("Security"); 122 Config cfg("Security");
105 cfg.setGroup("BluepingPlugin"); 123 cfg.setGroup("BluepingPlugin");
106 macToPing = cfg.readEntry("mac"); 124 macToPing = cfg.readEntry("mac");
107 if (!macToPing.isEmpty()) 125 if (!macToPing.isEmpty())
@@ -127,75 +145,79 @@ int BluepingPlugin::authenticate() {
127 QLabel subTitle2("<center>You can skip this step and use another authentication way with the following button</center>", &bluepingDialog); 145 QLabel subTitle2("<center>You can skip this step and use another authentication way with the following button</center>", &bluepingDialog);
128 QPushButton pbSkip("Skip", &bluepingDialog); 146 QPushButton pbSkip("Skip", &bluepingDialog);
129 layout->addWidget(&title); 147 layout->addWidget(&title);
130 layout->addWidget(&subTitle); 148 layout->addWidget(&subTitle);
131 layout->addWidget(&subTitle2); 149 layout->addWidget(&subTitle2);
132 layout->addWidget(&pbSkip, 0, Qt::AlignHCenter); 150 layout->addWidget(&pbSkip, 0, Qt::AlignHCenter);
133 151
134 // connect the skip button to the skip signal emitting function 152 // connect the skip button to the skip signal emitting function
135 QObject::connect(&pbSkip, SIGNAL(clicked()), this, SLOT(skip())); 153 QObject::connect(&pbSkip, SIGNAL(clicked()), this, SLOT(skip()));
136 // connect the signal emitting functions to the bluepingDialog done(int) finishing function 154 // connect the signal emitting functions to the bluepingDialog done(int) finishing function
137 QObject::connect(this, SIGNAL(emitCode(int)), &bluepingDialog, SLOT(done(int))); 155 QObject::connect(this, SIGNAL(emitCode(int)), &bluepingDialog, SLOT(done(int)));
138 156
139 // we can uncomment the following when testing 157
140 //bluetoothAlreadyRestarted = true; 158
141 if (!bluetoothAlreadyRestarted) 159 /* let's start Bluetooth if it's not running
160 */
161 OProcess checkB;
162 checkB << "pidof" << "hciattach";
163 odebug << "checking if Bluetooth is running..." << oendl;
164 // now we start bluetooth *only* if the previous command works, exits normally, and
165 // it returns a non-null exit code (which means hciattach is not running)
166 if ( checkB.start(OProcess::Block) && checkB.normalExit() && (checkB.exitStatus() != 0) )
142 { 167 {
143 // we have just started or resumed the device, so Bluetooth has to be (re)started 168 // remember to switch off Bluetooth once we're finished...
144 OProcess killB; 169 bluetoothWasOff = true;
145 killB << "killall" << "hciattach"; 170 odebug << "Bluetooth is not running, we must start it now" << oendl;
146 odebug << "killing Bluetooth..." << oendl;
147 if ( !killB.start(OProcess::Block) ) {
148 oerr << "could not kill bluetooth" << oendl;
149 }
150 171
151 OProcess startB; 172 OProcess startB;
152 switch ( ODevice::inst()->model() ) { 173 switch ( ODevice::inst()->model() ) {
153 case Model_iPAQ_H39xx: 174 case Model_iPAQ_H39xx:
154 startB << "/sbin/hciattach" << "/dev/tts/1" << "bcsp" << "921600"; 175 startB << "/sbin/hciattach" << "/dev/tts/1" << "bcsp" << "921600";
155 break; 176 break;
156 177
157 case Model_iPAQ_H5xxx: 178 case Model_iPAQ_H5xxx:
158 startB << "/sbin/hciattach" << "/dev/tts/1" << "any" << "921600"; 179 startB << "/sbin/hciattach" << "/dev/tts/1" << "any" << "921600";
159 break; 180 break;
160 181
161 default: 182 default:
162 startB << "/sbin/hciattach" << "/dev/ttySB0" << "bcsp" << "230400"; 183 startB << "/sbin/hciattach" << "/dev/ttySB0" << "bcsp" << "230400";
163 break; 184 break;
164 } // end switch on device models 185 } // end switch on device models
165 186
166 if ( !startB.start(OProcess::Block) ) { 187 if ( !startB.start(OProcess::Block) ) {
167 oerr << "could not (re)start bluetooth" << oendl; 188 oerr << "could not start Bluetooth" << oendl;
168 return MultiauthPluginObject::Skip; 189 return MultiauthPluginObject::Skip;
169 } 190 }
170 else 191 else
171 { 192 {
172 if ( startB.normalExit() && (startB.exitStatus() == 0) ) 193 if ( (startB.normalExit()) && (startB.exitStatus() == 0) )
173 { 194 {
174 odebug << "hciattach exited normally."<< oendl; 195 odebug << "hciattach exited normally, Bluetooth is probably on now, let's wait 500 ms and ping" << oendl;
175 bluetoothAlreadyRestarted = true;
176 // 500 ms timer, so l2ping won't try to find a route before bluetooth has \em really started 196 // 500 ms timer, so l2ping won't try to find a route before bluetooth has \em really started
177 QTimer::singleShot( 500, this, SLOT(ping()) ); 197 QTimer::singleShot( 500, this, SLOT(ping()) );
178 } 198 }
179 else 199 else
180 { 200 {
181 owarn << "hciattach exited anormally (error code: " << startB.exitStatus() << ")" << oendl; 201 owarn << "hciattach exited anormally (normalExit: " << startB.normalExit() << ", exit status: " << startB.exitStatus() << ")" << oendl;
182 } // end if startBluetooth exit status == 0 202 return MultiauthPluginObject::Skip;
203 } // end if startB exited normaly
183 } // end if startBluetooth started 204 } // end if startBluetooth started
184 } 205 }
185 else 206 else
186 { 207 {
187 // we don't need to wait, since bluetooth has been started long enough ago 208 // we don't need to wait, since bluetooth has been started long enough ago
209 odebug << "Bluetooth is already running, we can try to ping now" << oendl;
188 ping(); 210 ping();
189 } // end if bluetooth not restarted 211 } // end if Bluetooth was off
190 212
191 213
192 // start the dialog event loop, while the ping is starting (or will start soon) in the background 214 // start the dialog event loop, while the ping is starting (or will start soon) in the background
193 return bluepingDialog.exec(); 215 return bluepingDialog.exec();
194 216
195 217
196 } 218 }
197 else 219 else
198 { 220 {
199 owarn << "No Bluetooth device has been set!" << oendl; 221 owarn << "No Bluetooth device has been set!" << oendl;
200 owarn << "We will consider it as a successful authentication though." << oendl; 222 owarn << "We will consider it as a successful authentication though." << oendl;
201 return MultiauthPluginObject::Success; 223 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
64 signals: 64 signals:
65 /// Signal carrying the result code of this plugin 65 /// Signal carrying the result code of this plugin
66 void emitCode(int resultCode); 66 void emitCode(int resultCode);
67 67
68 private slots: 68 private slots:
69 void success(); 69 void success();
70 void failure(); 70 void failure();
71 void skip(); 71 void skip();
72 void ping(); 72 void ping();
73 void pingFinished(Opie::Core::OProcess * ping); 73 void pingFinished(Opie::Core::OProcess * ping);
74 74
75 private: 75 private:
76 Opie::Core::OProcess *m_ping; 76 void killBluetoothIfNecessary();
77 Opie::Core::OProcess * m_ping;
78 Config * m_config;
77 BluepingConfigWidget * m_bluepingW; 79 BluepingConfigWidget * m_bluepingW;
78 bool bluetoothAlreadyRestarted; 80 bool bluetoothWasOff;
79 QString macToPing; 81 QString macToPing;
80
81}; 82};
82 83
83#endif 84#endif