summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/opietooth2/OTDevice.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/opietooth2/OTDevice.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTDevice.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/noncore/settings/networksettings2/opietooth2/OTDevice.cpp b/noncore/settings/networksettings2/opietooth2/OTDevice.cpp
index 62f17a0..c6f7d5e 100644
--- a/noncore/settings/networksettings2/opietooth2/OTDevice.cpp
+++ b/noncore/settings/networksettings2/opietooth2/OTDevice.cpp
@@ -1,256 +1,256 @@
1#include <qdir.h> 1#include <qdir.h>
2#include <qfileinfo.h> 2#include <qfileinfo.h>
3 3
4#include <bluezlib.h> 4#include <bluezlib.h>
5 5
6/* OPIE */ 6/* OPIE */
7#include <opie2/odevice.h> 7#include <opie2/odevice.h>
8#include <opie2/oprocess.h> 8#include <opie2/oprocess.h>
9#include <opie2/odebug.h> 9#include <opie2/odebug.h>
10 10
11#include <OTDevice.h> 11#include <OTDevice.h>
12 12
13using namespace Opie::Core; 13using namespace Opie::Core;
14using namespace Opietooth2; 14using namespace Opietooth2;
15using Opie::Core::OProcess; 15using Opie::Core::OProcess;
16 16
17OTDevice::OTDevice( OTGateway * _OT ) : QObject(0, "device") { 17OTDevice::OTDevice( OTGateway * _OT ) : QObject(0, "device") {
18 18
19 // initialize 19 // initialize
20 OT = _OT; 20 OT = _OT;
21 21
22 // detect bluetooth type 22 // detect bluetooth type
23 QString a, b; // fake 23 QString a, b; // fake
24 unsigned long c; // fake 24 unsigned long c; // fake
25 detectDeviceType( a, b, c ); 25 detectDeviceType( a, b, c );
26 26
27 if( needsAttach() ) { 27 if( needsAttach() ) {
28 // requires HCIATTACH 28 // requires HCIATTACH
29 // pid of hciattach 29 // pid of hciattach
30 m_hciattachPid = getPidOfHCIAttach(); 30 m_hciattachPid = getPidOfHCIAttach();
31 31
32 m_hciattach = 0; 32 m_hciattach = 0;
33 33
34 if( m_hciattachPid == 0 ) { 34 if( m_hciattachPid == 0 ) {
35 // no pid -> not attached 35 // no pid -> not attached
36 m_deviceNr = -1; 36 m_deviceNr = -1;
37 } else { 37 } else {
38 // system enabled 38 // system enabled
39 // currently no way to figure out which attach produce which 39 // currently no way to figure out which attach produce which
40 // hci 40 // hci
41 m_deviceNr = 0; 41 m_deviceNr = 0;
42 } 42 }
43 } else { 43 } else {
44 m_deviceNr = 0; 44 m_deviceNr = 0;
45 } 45 }
46} 46}
47 47
48OTDevice::~OTDevice(){ 48OTDevice::~OTDevice(){
49 if( needsAttach() && m_hciattach ) { 49 if( needsAttach() && m_hciattach ) {
50 // does not auto stop bluetooth 50 // does not auto stop bluetooth
51 m_hciattach->detach(); 51 m_hciattach->detach();
52 delete m_hciattach; 52 delete m_hciattach;
53 } 53 }
54} 54}
55 55
56bool OTDevice::attach(){ 56bool OTDevice::attach(){
57 57
58 if( needsAttach() && m_hciattachPid == 0 ) { 58 if( needsAttach() && m_hciattachPid == 0 ) {
59 QString Dev, Mode; 59 QString Dev, Mode;
60 unsigned long Spd; 60 unsigned long Spd;
61 61
62 detectDeviceType( Dev, Mode, Spd ); 62 detectDeviceType( Dev, Mode, Spd );
63 63
64 // not yet started 64 // not yet started
65 m_hciattach = new OProcess(); 65 m_hciattach = new OProcess();
66 *m_hciattach << "hciattach"; 66 *m_hciattach << "hciattach";
67 *m_hciattach << "-p"; // so that it prints its pid 67 *m_hciattach << "-p"; // so that it prints its pid
68 *m_hciattach << Dev 68 *m_hciattach << Dev
69 << Mode 69 << Mode
70 << QString().setNum(Spd); 70 << QString().setNum(Spd);
71 71
72 connect( m_hciattach, 72 connect( m_hciattach,
73 SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), 73 SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ),
74 this, SLOT 74 this, SLOT
75 (slotStdOut(Opie::Core::OProcess*,char*,int) ) ); 75 (slotStdOut(Opie::Core::OProcess*,char*,int) ) );
76 76
77 connect( m_hciattach, 77 connect( m_hciattach,
78 SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ), 78 SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ),
79 this, SLOT 79 this, SLOT
80 (slotStdErr(Opie::Core::OProcess*,char*,int) ) ); 80 (slotStdErr(Opie::Core::OProcess*,char*,int) ) );
81 81
82 // we need to start this in 'dontcare' mode because 82 // we need to start this in 'dontcare' mode because
83 // if qpe exists we want the hci to keep running 83 // if qpe exists we want the hci to keep running
84 if( ! m_hciattach->start( OProcess::DontCare, 84 if( ! m_hciattach->start( OProcess::DontCare,
85 OProcess::AllOutput 85 OProcess::AllOutput
86 ) ){ 86 ) ){
87 emit error( tr( "Could not start hciattach" ) ); 87 emit error( tr( "Could not start hciattach" ) );
88 delete m_hciattach; 88 delete m_hciattach;
89 m_hciattach = 0; 89 m_hciattach = 0;
90 return FALSE; 90 return FALSE;
91 } 91 }
92 } 92 }
93 93
94 return TRUE; 94 return TRUE;
95} 95}
96 96
97bool OTDevice::detach(){ 97bool OTDevice::detach(){
98 98
99 if( needsAttach() && m_hciattachPid ) { 99 if( needsAttach() && m_hciattachPid ) {
100 if( m_hciattach ) { 100 if( m_hciattach ) {
101 delete m_hciattach; 101 delete m_hciattach;
102 m_hciattach = 0; 102 m_hciattach = 0;
103 } 103 }
104 104
105 if( kill( m_hciattachPid, 9) < 0 ) { 105 if( kill( m_hciattachPid, 9) < 0 ) {
106 owarn << "could not stop " << errno << oendl; 106 odebug << "could not stop " << errno << oendl;
107 emit error( tr( "Could not stop process" ) ); 107 emit error( tr( "Could not stop process" ) );
108 return FALSE; 108 return FALSE;
109 } 109 }
110 m_hciattachPid = 0; 110 m_hciattachPid = 0;
111 emit isEnabled( m_deviceNr, 0 ); 111 emit isEnabled( m_deviceNr, 0 );
112 m_deviceNr = -1; 112 m_deviceNr = -1;
113 } 113 }
114 114
115 return TRUE; 115 return TRUE;
116} 116}
117 117
118bool OTDevice::isAttached()const{ 118bool OTDevice::isAttached()const{
119 return ! needsAttach() || m_hciattachPid != 0; 119 return ! needsAttach() || m_hciattachPid != 0;
120} 120}
121 121
122bool OTDevice::checkAttach(){ 122bool OTDevice::checkAttach(){
123 if( ! needsAttach() ) { 123 if( ! needsAttach() ) {
124 m_deviceNr = 0; 124 m_deviceNr = 0;
125 emit isEnabled( 0, 1 ); 125 emit isEnabled( 0, 1 );
126 return TRUE; 126 return TRUE;
127 } 127 }
128 128
129 if( m_hciattachPid ) { 129 if( m_hciattachPid ) {
130 QString S; 130 QString S;
131 S.setNum( m_hciattachPid ); 131 S.setNum( m_hciattachPid );
132 QDir D( "/proc" ); 132 QDir D( "/proc" );
133 if( !D.exists( S ) ) { 133 if( !D.exists( S ) ) {
134 // down 134 // down
135 m_hciattachPid = 0; 135 m_hciattachPid = 0;
136 emit isEnabled( m_deviceNr, 0 ); 136 emit isEnabled( m_deviceNr, 0 );
137 m_deviceNr = -1; 137 m_deviceNr = -1;
138 } 138 }
139 } else { 139 } else {
140 // check 140 // check
141 m_hciattachPid = getPidOfHCIAttach(); 141 m_hciattachPid = getPidOfHCIAttach();
142 if ( m_hciattachPid ) { 142 if ( m_hciattachPid ) {
143 m_deviceNr = 0; 143 m_deviceNr = 0;
144 emit isEnabled( m_deviceNr, 1 ); 144 emit isEnabled( m_deviceNr, 1 );
145 } 145 }
146 } 146 }
147 return m_hciattachPid != 0; 147 return m_hciattachPid != 0;
148} 148}
149 149
150void OTDevice::slotStdOut(OProcess* proc, char* , int ) { 150void OTDevice::slotStdOut(OProcess* proc, char* , int ) {
151 if( proc == m_hciattach ) { 151 if( proc == m_hciattach ) {
152 m_hciattach->detach(); 152 m_hciattach->detach();
153 153
154 // system enabled 154 // system enabled
155 // currently no way to figure out which attach produce which 155 // currently no way to figure out which attach produce which
156 // hci 156 // hci
157 if( m_deviceNr == -1 ) { 157 if( m_deviceNr == -1 ) {
158 m_deviceNr = 0; 158 m_deviceNr = 0;
159 emit isEnabled( m_deviceNr, 1 ); 159 emit isEnabled( m_deviceNr, 1 );
160 } 160 }
161 } 161 }
162} 162}
163 163
164void OTDevice::slotStdErr(OProcess* proc, char* chars, int len) { 164void OTDevice::slotStdErr(OProcess* proc, char* chars, int len) {
165 165
166 if(proc == m_hciattach && len >= 1 ){ 166 if(proc == m_hciattach && len >= 1 ){
167 // collect output 167 // collect output
168 QCString string( chars, len+1 ); // \0 == +1 168 QCString string( chars, len+1 ); // \0 == +1
169 QString m_output; 169 QString m_output;
170 m_output.append( string.data() ); 170 m_output.append( string.data() );
171 owarn << m_output << oendl; 171 odebug << m_output << oendl;
172 } 172 }
173} 173}
174 174
175pid_t OTDevice::getPidOfHCIAttach( void ) { 175pid_t OTDevice::getPidOfHCIAttach( void ) {
176 176
177 if( needsAttach() ) { 177 if( needsAttach() ) {
178 // not yet attached -> perhaps now ? 178 // not yet attached -> perhaps now ?
179 // load /proc dir and check if command name contains hciattach 179 // load /proc dir and check if command name contains hciattach
180 QRegExp R("[0-9]+"); 180 QRegExp R("[0-9]+");
181 QDir ProcDir( "/proc" ); 181 QDir ProcDir( "/proc" );
182 QFileInfo FI; 182 QFileInfo FI;
183 QStringList EL = ProcDir.entryList( QDir::Dirs ); 183 QStringList EL = ProcDir.entryList( QDir::Dirs );
184 184
185 // print it out 185 // print it out
186 for ( QStringList::Iterator it = EL.begin(); 186 for ( QStringList::Iterator it = EL.begin();
187 it != EL.end(); 187 it != EL.end();
188 ++it ) { 188 ++it ) {
189 if( R.match( (*it) ) >= 0 ) { 189 if( R.match( (*it) ) >= 0 ) {
190 // is pid 190 // is pid
191 191
192 // get command being executed 192 // get command being executed
193 FI.setFile( ProcDir.path()+"/"+ (*it) + "/exe" ); 193 FI.setFile( ProcDir.path()+"/"+ (*it) + "/exe" );
194 194
195 // get the link 195 // get the link
196 if( FI.readLink().right( 9 ) == "hciattach" ) { 196 if( FI.readLink().right( 9 ) == "hciattach" ) {
197 // this is hci attach process 197 // this is hci attach process
198 198
199 return (*it).toULong(); 199 return (*it).toULong();
200 break; 200 break;
201 } 201 }
202 } 202 }
203 } 203 }
204 } 204 }
205 205
206 return 0; 206 return 0;
207} 207}
208 208
209void OTDevice::detectDeviceType( QString & Device, 209void OTDevice::detectDeviceType( QString & Device,
210 QString & Mode, 210 QString & Mode,
211 unsigned long & Speed ) { 211 unsigned long & Speed ) {
212 212
213 // detect device type and determine parms 213 // detect device type and determine parms
214 owarn << "Detecting device" << oendl; 214 odebug << "Detecting device" << oendl;
215 switch ( ODevice::inst()->model() ) { 215 switch ( ODevice::inst()->model() ) {
216 case Model_iPAQ_H39xx: 216 case Model_iPAQ_H39xx:
217 Device = "/dev/tts/1"; 217 Device = "/dev/tts/1";
218 Mode = "bcsp"; 218 Mode = "bcsp";
219 Speed = 921600; 219 Speed = 921600;
220 NeedsAttach = 1; 220 NeedsAttach = 1;
221 break; 221 break;
222 222
223 case Model_iPAQ_H5xxx: 223 case Model_iPAQ_H5xxx:
224 Device = "/dev/tts/1"; 224 Device = "/dev/tts/1";
225 Mode = "any"; 225 Mode = "any";
226 Speed = 921600; 226 Speed = 921600;
227 NeedsAttach = 1; 227 NeedsAttach = 1;
228 break; 228 break;
229 229
230 case Model_GenuineIntel : 230 case Model_GenuineIntel :
231 Device = ""; 231 Device = "";
232 Mode = ""; 232 Mode = "";
233 Speed = 0; 233 Speed = 0;
234 NeedsAttach = 0; 234 NeedsAttach = 0;
235 break; 235 break;
236 236
237 default: 237 default:
238 Device = "/dev/ttySB0"; 238 Device = "/dev/ttySB0";
239 Mode = "bcsp"; 239 Mode = "bcsp";
240 Speed = 230400; 240 Speed = 230400;
241 NeedsAttach = 1; 241 NeedsAttach = 1;
242 break; 242 break;
243 } 243 }
244} 244}
245 245
246QString OTDevice::getRFCommDevicePattern( void ) { 246QString OTDevice::getRFCommDevicePattern( void ) {
247 247
248 QDir D( "/dev/bluetooth/rfcomm" ); 248 QDir D( "/dev/bluetooth/rfcomm" );
249 if( D.exists() ) { 249 if( D.exists() ) {
250 // devfs 250 // devfs
251 return QString( "/dev/bluetooth/rfcomm/%1" ); 251 return QString( "/dev/bluetooth/rfcomm/%1" );
252 } 252 }
253 253
254 // regular 'dev' directory 254 // regular 'dev' directory
255 return QString( "/dev/rfcomm%1" ); 255 return QString( "/dev/rfcomm%1" );
256} 256}