summaryrefslogtreecommitdiff
path: root/noncore/securityplugins
authorclem <clem>2004-08-05 22:55:35 (UTC)
committer clem <clem>2004-08-05 22:55:35 (UTC)
commit90ca457fbf420e31eed99c828a23e451bf8dc30c (patch) (unidiff)
treebb538c99c6157a3e431818594fea92584783fc90 /noncore/securityplugins
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 (limited to 'noncore/securityplugins') (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
@@ -17,15 +17,17 @@ using 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)
@@ -39,13 +41,29 @@ MultiauthConfigWidget * BluepingPlugin::configWidget(QWidget * parent) {
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);
@@ -81,18 +99,18 @@ void BluepingPlugin::ping() {
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/**
@@ -136,17 +154,20 @@ int BluepingPlugin::authenticate() {
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() ) {
@@ -164,29 +185,30 @@ int BluepingPlugin::authenticate() {
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
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
@@ -73,11 +73,12 @@ class BluepingPlugin : public QObject, public Opie::Security::MultiauthPluginObj
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