summaryrefslogtreecommitdiff
path: root/noncore
Unidiff
Diffstat (limited to 'noncore') (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
@@ -18,13 +18,15 @@ using Opie::Security::MultiauthConfigWidget;
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
@@ -40,11 +42,27 @@ MultiauthConfigWidget * BluepingPlugin::configWidget(QWidget * parent) {
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() {
@@ -82,16 +100,16 @@ void BluepingPlugin::ping() {
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
@@ -137,15 +155,18 @@ int BluepingPlugin::authenticate() {
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;
@@ -165,13 +186,12 @@ int BluepingPlugin::authenticate() {
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()) );
@@ -179,6 +199,7 @@ int BluepingPlugin::authenticate() {
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 }
@@ -186,6 +207,7 @@ int BluepingPlugin::authenticate() {
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
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
@@ -74,9 +74,10 @@ class BluepingPlugin : public QObject, public Opie::Security::MultiauthPluginObj
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