-rw-r--r-- | noncore/securityplugins/blueping/bluepingplugin.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/noncore/securityplugins/blueping/bluepingplugin.cpp b/noncore/securityplugins/blueping/bluepingplugin.cpp index 1c514e5..05c26ba 100644 --- a/noncore/securityplugins/blueping/bluepingplugin.cpp +++ b/noncore/securityplugins/blueping/bluepingplugin.cpp | |||
@@ -1,225 +1,229 @@ | |||
1 | #include "bluepingplugin.h" | 1 | #include "bluepingplugin.h" |
2 | 2 | ||
3 | #include <opie2/oapplication.h> | 3 | #include <opie2/oapplication.h> |
4 | #include <opie2/odebug.h> | 4 | #include <opie2/odebug.h> |
5 | #include <opie2/odevice.h> | 5 | #include <opie2/odevice.h> |
6 | 6 | ||
7 | #include <qdialog.h> | 7 | #include <qdialog.h> |
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 | ||
14 | using namespace Opie::Core; | 14 | using namespace Opie::Core; |
15 | using Opie::Security::MultiauthPluginObject; | 15 | using Opie::Security::MultiauthPluginObject; |
16 | using Opie::Security::MultiauthConfigWidget; | 16 | using Opie::Security::MultiauthConfigWidget; |
17 | 17 | ||
18 | 18 | ||
19 | /// standard c'tor | 19 | /// standard c'tor |
20 | BluepingPlugin::BluepingPlugin() : MultiauthPluginObject(), m_ping(0), m_bluepingW(0), bluetoothWasOff(false) { | 20 | BluepingPlugin::BluepingPlugin() : MultiauthPluginObject(), m_ping(0), m_bluepingW(0), bluetoothWasOff(false) { |
21 | } | 21 | } |
22 | 22 | ||
23 | /// cleans m_ping and m_bluepingW if we need to | 23 | /// cleans m_ping and m_bluepingW if we need to |
24 | BluepingPlugin::~BluepingPlugin() { | 24 | BluepingPlugin::~BluepingPlugin() { |
25 | odebug << "closing Blueping plugin..." << oendl; | 25 | odebug << "closing Blueping plugin..." << oendl; |
26 | if (m_ping != 0) | 26 | if (m_ping != 0) |
27 | delete m_ping; | 27 | delete m_ping; |
28 | if (m_bluepingW != 0) | 28 | if (m_bluepingW != 0) |
29 | delete m_bluepingW; | 29 | delete m_bluepingW; |
30 | killBluetoothIfNecessary(); | 30 | killBluetoothIfNecessary(); |
31 | } | 31 | } |
32 | 32 | ||
33 | /// Simply return its name (Blueping plugin) | 33 | /// Simply return its name (Blueping plugin) |
34 | QString BluepingPlugin::pluginName() const { | 34 | QString BluepingPlugin::pluginName() const { |
35 | return "Blueping plugin"; | 35 | return "Blueping plugin"; |
36 | } | 36 | } |
37 | 37 | ||
38 | /// returns a BluepingConfigWidget | 38 | /// returns a BluepingConfigWidget |
39 | MultiauthConfigWidget * BluepingPlugin::configWidget(QWidget * parent) { | 39 | MultiauthConfigWidget * BluepingPlugin::configWidget(QWidget * parent) { |
40 | if (m_bluepingW == 0) | 40 | if (m_bluepingW == 0) |
41 | m_bluepingW = new BluepingConfigWidget(parent, "Blueping configuration widget"); | 41 | m_bluepingW = new BluepingConfigWidget(parent, "Blueping configuration widget"); |
42 | return m_bluepingW; | 42 | return m_bluepingW; |
43 | } | 43 | } |
44 | 44 | ||
45 | QString BluepingPlugin::pixmapNameWidget() const { | 45 | QString BluepingPlugin::pixmapNameWidget() const { |
46 | return "security/bluepingplugin"; | 46 | return "security/bluepingplugin"; |
47 | } | 47 | } |
48 | 48 | ||
49 | QString BluepingPlugin::pixmapNameConfig() const { | 49 | QString BluepingPlugin::pixmapNameConfig() const { |
50 | return "security/bluepingplugin"; | 50 | return "security/bluepingplugin"; |
51 | } | 51 | } |
52 | 52 | ||
53 | /// If Bluetooth was off before the plugin ran, we switch it off again | 53 | /// If Bluetooth was off before the plugin ran, we switch it off again |
54 | void BluepingPlugin::killBluetoothIfNecessary() { | 54 | void BluepingPlugin::killBluetoothIfNecessary() { |
55 | if (bluetoothWasOff) { | 55 | if (bluetoothWasOff) { |
56 | OProcess killB; | 56 | OProcess killB; |
57 | killB << "killall" << "hciattach"; | 57 | killB << "killall" << "hciattach"; |
58 | odebug << "killing Bluetooth... (since it was up only for Blueping)" << oendl; | 58 | odebug << "killing Bluetooth... (since it was up only for Blueping)" << oendl; |
59 | if ( !killB.start(OProcess::Block) ) { | 59 | if ( !killB.start(OProcess::Block) ) { |
60 | oerr << "could not kill bluetooth" << oendl; | 60 | oerr << "could not kill bluetooth" << oendl; |
61 | } | 61 | } |
62 | } else { | 62 | } else { |
63 | odebug << "keeping Bluetooth on" << oendl; | 63 | odebug << "keeping Bluetooth on" << oendl; |
64 | } | 64 | } |
65 | } | 65 | } |
66 | 66 | ||
67 | /// Emit the MultiauthPluginObject::Success emitCode | 67 | /// Emit the MultiauthPluginObject::Success emitCode |
68 | void BluepingPlugin::success() { | 68 | void BluepingPlugin::success() { |
69 | emit emitCode(MultiauthPluginObject::Success); | 69 | emit emitCode(MultiauthPluginObject::Success); |
70 | } | 70 | } |
71 | 71 | ||
72 | /// Emit the MultiauthPluginObject::Failure emitCode | 72 | /// Emit the MultiauthPluginObject::Failure emitCode |
73 | void BluepingPlugin::failure() { | 73 | void BluepingPlugin::failure() { |
74 | emit emitCode(MultiauthPluginObject::Failure); | 74 | emit emitCode(MultiauthPluginObject::Failure); |
75 | } | 75 | } |
76 | 76 | ||
77 | /// Emit the MultiauthPluginObject::Skip emitCode | 77 | /// Emit the MultiauthPluginObject::Skip emitCode |
78 | void BluepingPlugin::skip() { | 78 | void BluepingPlugin::skip() { |
79 | emit emitCode(MultiauthPluginObject::Skip); | 79 | emit emitCode(MultiauthPluginObject::Skip); |
80 | } | 80 | } |
81 | 81 | ||
82 | /// do the actual ping | 82 | /// do the actual ping |
83 | void BluepingPlugin::ping() { | 83 | void BluepingPlugin::ping() { |
84 | m_ping = new OProcess(); | 84 | m_ping = new OProcess(); |
85 | odebug << "pinging device: " << macToPing << oendl; | 85 | odebug << "pinging device: " << macToPing << oendl; |
86 | *m_ping << "l2ping" << "-c 1" << macToPing; | 86 | *m_ping << "l2ping" << "-c 1" << macToPing; |
87 | 87 | ||
88 | // starting to ping in the background | 88 | // starting to ping in the background |
89 | /// \todo as soon as ping is launched, check RSSI (signal strength) and check | 89 | /// \todo as soon as ping is launched, check RSSI (signal strength) and check |
90 | /// it's high enough, meaning the device is close enough? | 90 | /// it's high enough, meaning the device is close enough? |
91 | /// \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 |
92 | /// Opie suspend if l2ping timeouts? | 92 | /// Opie suspend if l2ping timeouts? |
93 | if ( !m_ping->start() ) { | 93 | if ( !m_ping->start() ) { |
94 | oerr << "could not start l2ping" << oendl; | 94 | oerr << "could not start l2ping" << oendl; |
95 | this->skip(); | 95 | this->skip(); |
96 | } | 96 | } |
97 | QObject::connect(m_ping, SIGNAL(processExited(Opie::Core::OProcess*)), | 97 | QObject::connect(m_ping, SIGNAL(processExited(Opie::Core::OProcess*)), |
98 | this, SLOT(pingFinished(Opie::Core::OProcess*)) ); | 98 | this, SLOT(pingFinished(Opie::Core::OProcess*)) ); |
99 | } | 99 | } |
100 | 100 | ||
101 | /// Deals with m_ping result | 101 | /// Deals with m_ping result |
102 | void BluepingPlugin::pingFinished(OProcess * ping) { | 102 | void BluepingPlugin::pingFinished(OProcess * ping) { |
103 | if ( ping->normalExit() && (ping->exitStatus() == 0) ) | 103 | if ( ping->normalExit() && (ping->exitStatus() == 0) ) |
104 | { | 104 | { |
105 | odebug << "Successful Bluetooth ping!" << oendl; | 105 | odebug << "Successful Bluetooth ping!" << oendl; |
106 | success(); | 106 | success(); |
107 | } | 107 | } |
108 | else | 108 | else |
109 | { | 109 | { |
110 | odebug << "Failed Bluetooth ping... (normalExit: " << ping->normalExit() << ", exitStatus: " << ping->exitStatus() << ")" << oendl; | 110 | odebug << "Failed Bluetooth ping... (normalExit: " << ping->normalExit() << ", exitStatus: " << ping->exitStatus() << ")" << oendl; |
111 | failure(); | 111 | failure(); |
112 | } | 112 | } |
113 | } | 113 | } |
114 | 114 | ||
115 | /// Make one authentication attempt with this plugin | 115 | /// Make one authentication attempt with this plugin |
116 | /** | 116 | /** |
117 | * (very simple "success" / "failure" buttons in a dialog) | 117 | * (very simple "success" / "failure" buttons in a dialog) |
118 | * \return The outcome code of this authentication | 118 | * \return The outcome code of this authentication |
119 | */ | 119 | */ |
120 | int BluepingPlugin::authenticate() { | 120 | int BluepingPlugin::authenticate() { |
121 | 121 | ||
122 | Config cfg("Security"); | 122 | Config cfg("Security"); |
123 | cfg.setGroup("BluepingPlugin"); | 123 | cfg.setGroup("BluepingPlugin"); |
124 | macToPing = cfg.readEntry("mac"); | 124 | macToPing = cfg.readEntry("mac"); |
125 | if (!macToPing.isEmpty()) | 125 | if (!macToPing.isEmpty()) |
126 | { | 126 | { |
127 | /* Standard, inescapable authentication dialog | 127 | /* Standard, inescapable authentication dialog |
128 | */ | 128 | */ |
129 | QDialog bluepingDialog(0, | 129 | QDialog bluepingDialog(0, |
130 | "Blueping dialog", | 130 | "Blueping dialog", |
131 | TRUE, | 131 | TRUE, |
132 | Qt::WStyle_NoBorder | Qt::WStyle_Customize | Qt::WStyle_StaysOnTop); | 132 | Qt::WStyle_NoBorder | Qt::WStyle_Customize | Qt::WStyle_StaysOnTop); |
133 | 133 | ||
134 | QRect desk = oApp->desktop()->geometry(); | 134 | QRect desk = oApp->desktop()->geometry(); |
135 | bluepingDialog.setGeometry( 0, 0, desk.width(), desk.height() ); | 135 | bluepingDialog.setGeometry( 0, 0, desk.width(), desk.height() ); |
136 | 136 | ||
137 | // Creation of the particular widgets of our Blueping user interface | 137 | // Creation of the particular widgets of our Blueping user interface |
138 | QVBoxLayout *layout = new QVBoxLayout(&bluepingDialog); | 138 | QVBoxLayout *layout = new QVBoxLayout(&bluepingDialog); |
139 | layout->setSpacing(11); | 139 | layout->setSpacing(11); |
140 | layout->setMargin(11); | 140 | layout->setMargin(11); |
141 | layout->setAlignment( Qt::AlignTop ); | 141 | layout->setAlignment( Qt::AlignTop ); |
142 | 142 | ||
143 | QLabel title("<center><h1>\"Blueping\" <br />plugin</h1></center>", &bluepingDialog); | 143 | QLabel title("<center><h1>\"Blueping\" <br />plugin</h1></center>", &bluepingDialog); |
144 | QLabel subTitle("<center><h2>Trying to reach your configured bluetooth device...</h2></center>", &bluepingDialog); | 144 | QLabel subTitle("<center><h2>Trying to reach your configured bluetooth device...</h2></center>", &bluepingDialog); |
145 | 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); |
146 | QPushButton pbSkip("Skip", &bluepingDialog); | 146 | QPushButton pbSkip("Skip", &bluepingDialog); |
147 | layout->addWidget(&title); | 147 | layout->addWidget(&title); |
148 | layout->addWidget(&subTitle); | 148 | layout->addWidget(&subTitle); |
149 | layout->addWidget(&subTitle2); | 149 | layout->addWidget(&subTitle2); |
150 | layout->addWidget(&pbSkip, 0, Qt::AlignHCenter); | 150 | layout->addWidget(&pbSkip, 0, Qt::AlignHCenter); |
151 | 151 | ||
152 | // connect the skip button to the skip signal emitting function | 152 | // connect the skip button to the skip signal emitting function |
153 | QObject::connect(&pbSkip, SIGNAL(clicked()), this, SLOT(skip())); | 153 | QObject::connect(&pbSkip, SIGNAL(clicked()), this, SLOT(skip())); |
154 | // 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 |
155 | QObject::connect(this, SIGNAL(emitCode(int)), &bluepingDialog, SLOT(done(int))); | 155 | QObject::connect(this, SIGNAL(emitCode(int)), &bluepingDialog, SLOT(done(int))); |
156 | 156 | ||
157 | 157 | ||
158 | 158 | ||
159 | /* let's start Bluetooth if it's not running | 159 | /* let's start Bluetooth if it's not running |
160 | */ | 160 | */ |
161 | OProcess checkB; | 161 | OProcess checkB; |
162 | checkB << "pidof" << "hciattach"; | 162 | checkB << "pidof" << "hciattach"; |
163 | odebug << "checking if Bluetooth is running..." << oendl; | 163 | odebug << "checking if Bluetooth is running..." << oendl; |
164 | // now we start bluetooth *only* if the previous command works, exits normally, and | 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) | 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) ) | 166 | if ( checkB.start(OProcess::Block) && checkB.normalExit() && (checkB.exitStatus() != 0) ) |
167 | { | 167 | { |
168 | // remember to switch off Bluetooth once we're finished... | 168 | // remember to switch off Bluetooth once we're finished... |
169 | bluetoothWasOff = true; | 169 | bluetoothWasOff = true; |
170 | odebug << "Bluetooth is not running, we must start it now" << oendl; | 170 | odebug << "Bluetooth is not running, we must start it now" << oendl; |
171 | 171 | ||
172 | OProcess startB; | 172 | OProcess startB; |
173 | switch ( ODevice::inst()->model() ) { | 173 | switch ( ODevice::inst()->model() ) { |
174 | case Model_iPAQ_H39xx: | 174 | case Model_iPAQ_H39xx: |
175 | startB << "/sbin/hciattach" << "/dev/tts/1" << "bcsp" << "921600"; | 175 | startB << "/sbin/hciattach" << "/dev/tts/1" << "bcsp" << "921600"; |
176 | break; | 176 | break; |
177 | 177 | ||
178 | case Model_iPAQ_H5xxx: | 178 | case Model_iPAQ_H5xxx: |
179 | startB << "/sbin/hciattach" << "/dev/tts/1" << "any" << "921600"; | 179 | startB << "/sbin/hciattach" << "/dev/tts/1" << "any" << "921600"; |
180 | break; | 180 | break; |
181 | 181 | ||
182 | case Model_MyPal_716: | ||
183 | startB << "/sbin/hciattach" << "/dev/ttyS1" << "bcsp" << "921600"; | ||
184 | break; | ||
185 | |||
182 | default: | 186 | default: |
183 | startB << "/sbin/hciattach" << "/dev/ttySB0" << "bcsp" << "230400"; | 187 | startB << "/sbin/hciattach" << "/dev/ttySB0" << "bcsp" << "230400"; |
184 | break; | 188 | break; |
185 | } // end switch on device models | 189 | } // end switch on device models |
186 | 190 | ||
187 | if ( !startB.start(OProcess::Block) ) { | 191 | if ( !startB.start(OProcess::Block) ) { |
188 | oerr << "could not start Bluetooth" << oendl; | 192 | oerr << "could not start Bluetooth" << oendl; |
189 | return MultiauthPluginObject::Skip; | 193 | return MultiauthPluginObject::Skip; |
190 | } | 194 | } |
191 | else | 195 | else |
192 | { | 196 | { |
193 | if ( (startB.normalExit()) && (startB.exitStatus() == 0) ) | 197 | if ( (startB.normalExit()) && (startB.exitStatus() == 0) ) |
194 | { | 198 | { |
195 | odebug << "hciattach exited normally, Bluetooth is probably on now, let's wait 500 ms and ping" << oendl; | 199 | odebug << "hciattach exited normally, Bluetooth is probably on now, let's wait 500 ms and ping" << oendl; |
196 | // 500 ms timer, so l2ping won't try to find a route before bluetooth has \em really started | 200 | // 500 ms timer, so l2ping won't try to find a route before bluetooth has \em really started |
197 | QTimer::singleShot( 500, this, SLOT(ping()) ); | 201 | QTimer::singleShot( 500, this, SLOT(ping()) ); |
198 | } | 202 | } |
199 | else | 203 | else |
200 | { | 204 | { |
201 | owarn << "hciattach exited anormally (normalExit: " << startB.normalExit() << ", exit status: " << startB.exitStatus() << ")" << oendl; | 205 | owarn << "hciattach exited anormally (normalExit: " << startB.normalExit() << ", exit status: " << startB.exitStatus() << ")" << oendl; |
202 | return MultiauthPluginObject::Skip; | 206 | return MultiauthPluginObject::Skip; |
203 | } // end if startB exited normaly | 207 | } // end if startB exited normaly |
204 | } // end if startBluetooth started | 208 | } // end if startBluetooth started |
205 | } | 209 | } |
206 | else | 210 | else |
207 | { | 211 | { |
208 | // we don't need to wait, since bluetooth has been started long enough ago | 212 | // 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; | 213 | odebug << "Bluetooth is already running, we can try to ping now" << oendl; |
210 | ping(); | 214 | ping(); |
211 | } // end if Bluetooth was off | 215 | } // end if Bluetooth was off |
212 | 216 | ||
213 | 217 | ||
214 | // start the dialog event loop, while the ping is starting (or will start soon) in the background | 218 | // start the dialog event loop, while the ping is starting (or will start soon) in the background |
215 | return bluepingDialog.exec(); | 219 | return bluepingDialog.exec(); |
216 | 220 | ||
217 | 221 | ||
218 | } | 222 | } |
219 | else | 223 | else |
220 | { | 224 | { |
221 | owarn << "No Bluetooth device has been set!" << oendl; | 225 | owarn << "No Bluetooth device has been set!" << oendl; |
222 | owarn << "We will consider it as a successful authentication though." << oendl; | 226 | owarn << "We will consider it as a successful authentication though." << oendl; |
223 | return MultiauthPluginObject::Success; | 227 | return MultiauthPluginObject::Success; |
224 | } // end if mac defined | 228 | } // end if mac defined |
225 | } | 229 | } |